Ejemplo n.º 1
0
LOCAL TBOOL
fb_init(WINDISPLAY *mod, TTAGITEM *tags)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
// 	mod->fbd_OpenTags = tags;

	for (;;)
	{
		TTAGITEM tags[2];

		tags[0].tti_Tag = TTask_UserData;
		tags[0].tti_Value = (TTAG) mod;
		tags[1].tti_Tag = TTAG_DONE;

		mod->fbd_Task = TCreateTask(&mod->fbd_Module.tmd_Handle.thn_Hook,
			tags);
		if (mod->fbd_Task == TNULL) break;

		mod->fbd_CmdPort = TGetUserPort(mod->fbd_Task);
		mod->fbd_CmdPortSignal = TGetPortSignal(mod->fbd_CmdPort);

		return TTRUE;
	}

	fb_exit(mod);
	return TFALSE;
}
Ejemplo n.º 2
0
static void rfb_runtask(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	struct rfb_Display *mod = TGetTaskData(task);
	struct TVRequest *req;
	TUINT sig = 0;

	TTIME intt = { 20000 };
	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt, *pwaitt;

	TAPTR cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT imsgportsignal = TGetPortSignal(mod->rfb_RndIMsgPort);
	TUINT waitsigs = cmdportsignal | imsgportsignal | TTASK_SIG_ABORT;

	TDBPRINTF(TDB_INFO, ("RawFB device context running\n"));

	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);

	do
	{
		if (sig & cmdportsignal)
		{
			TBOOL checkrect = mod->rfb_Flags & RFBFL_PTR_VISIBLE;
			TINT arec[4];

			while ((req = TGetMsg(cmdport)))
			{
				if (checkrect)
				{
					TINT res = rfb_cmdrectaffected(mod, req, arec, TTRUE);

					if (res < 0 || (res > 0 &&
							REGION_OVERLAPRECT(mod->rfb_PtrBackBuffer.rect,
								arec)))
					{
						rfb_restoreptrbg(mod);
						checkrect = TFALSE;
					}
				}
				rfb_docmd(mod, req);
				TReplyMsg(req);
			}
		}

		if (mod->rfb_Flags & RFBFL_SHOWPTR)
			rfb_drawpointer(mod);

		/* check if time interval has expired: */
		TGetSystemTime(&nowt);

		/* do interval timers */
		if (mod->rfb_NumInterval > 0)
		{
			if (TCmpTime(&nowt, &nextt) >= 0)
			{
				/* expired; send intervals: */
				TLock(mod->rfb_InstanceLock);
				struct TNode *next, 
					*node = mod->rfb_VisualList.tlh_Head.tln_Succ;

				for (; (next = node->tln_Succ); node = next)
				{
					struct rfb_Window *v = (struct rfb_Window *) node;
					TIMSG *imsg;

					if ((v->rfbw_InputMask & TITYPE_INTERVAL) &&
						rfb_getimsg(mod, v, &imsg, TITYPE_INTERVAL))
						TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
				}
				TUnlock(mod->rfb_InstanceLock);
				TAddTime(&nextt, &intt);
			}

			/* calculate new wait time: */
			waitt = nextt;
			TSubTime(&waitt, &nowt);
			if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > 20000)
			{
				nextt = nowt;
				TAddTime(&nextt, &intt);
				waitt = nextt;
				TSubTime(&waitt, &nowt);
			}
			pwaitt = &waitt;
		}
		else
			pwaitt = TNULL;

#if defined(ENABLE_LINUXFB)
		rfb_linux_wait(mod, pwaitt);
		sig = TSetSignal(0, waitsigs);
#else
		sig = TWaitTime(pwaitt, waitsigs);
#endif

		if (sig & imsgportsignal)
			rfb_processevent(mod);

	} while (!(sig & TTASK_SIG_ABORT));

	TDBPRINTF(TDB_INFO, ("RawFB device context closedown\n"));

	rfb_exittask(mod);
}
Ejemplo n.º 3
0
static void rfb_runtask(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	RFBDISPLAY *mod = TGetTaskData(task);
	struct TVRequest *req;
	TUINT sig;

	TTIME intt = { RAWFB_INTERVAL_MICROS };
	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt;
	
	TAPTR cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT imsgportsignal = TGetPortSignal(mod->rfb_RndIMsgPort);
	
	TDBPRINTF(TDB_INFO,("RawFB device context running\n"));
	
	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);
	
	do
	{
		/* process input messages: */
		rfb_processevent(mod);
		
		/* do draw commands: */
		while ((req = TGetMsg(cmdport)))
		{
			rfb_docmd(mod, req);
			TReplyMsg(req);
		}
		
		/* check if time interval has expired: */
		TGetSystemTime(&nowt);
		if (TCmpTime(&nowt, &nextt) > 0)
		{
			/* expired; send intervals: */
			TLock(mod->rfb_InstanceLock);
			
			struct TNode *next, *node = mod->rfb_VisualList.tlh_Head;
			for (; (next = node->tln_Succ); node = next)
			{
				RFBWINDOW *v = (RFBWINDOW *) node;
				TIMSG *imsg;
				if ((v->rfbw_InputMask & TITYPE_INTERVAL) &&
					rfb_getimsg(mod, v, &imsg, TITYPE_INTERVAL))
					TPutMsg(v->rfbw_IMsgPort, TNULL, imsg);
			}
			
			TUnlock(mod->rfb_InstanceLock);
			TAddTime(&nextt, &intt);
		}

		/* calculate new wait time: */
		waitt = nextt;
		TGetSystemTime(&nowt);
		TSubTime(&waitt, &nowt);
		
		if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > RAWFB_INTERVAL_MICROS)
		{
			/* something's wrong with the clock, recalculate */
			TDBPRINTF(TDB_INFO,("clock problem: %lld\n", waitt.tdt_Int64));
			nextt = nowt;
			TAddTime(&nextt, &intt);
			waitt = nextt;
			TSubTime(&waitt, &nowt);
		}
		
		sig = TWaitTime(&waitt, 
			cmdportsignal | imsgportsignal | TTASK_SIG_ABORT);
		
	} while (!(sig & TTASK_SIG_ABORT));
	
	TDBPRINTF(TDB_INFO,("RawFB device context closedown\n"));
	
	rfb_exittask(mod);
}
Ejemplo n.º 4
0
LOCAL void x11_taskfunc(struct TTask *task)
{
	TAPTR TExecBase = TGetExecBase(task);
	struct X11Display *inst = TGetTaskData(task);
	TUINT sig = 0;
	fd_set rset;
	struct TVRequest *req;
	TIMSG *imsg;
	char buf[256];
	struct timeval tv, *ptv;
	struct TMsgPort *cmdport = TGetUserPort(task);
	TUINT cmdportsignal = TGetPortSignal(cmdport);
	TUINT ireplysignal = TGetPortSignal(inst->x11_IReplyPort);
	TUINT waitsigs = cmdportsignal | ireplysignal | TTASK_SIG_ABORT;

	/* interval time: 1/50s: */
	TTIME intt = { 20000 };

	/* next absolute time to send interval message: */
	TTIME nextt;
	TTIME waitt, nowt;

	TDBPRINTF(TDB_INFO, ("Device instance running\n"));

	TGetSystemTime(&nowt);
	nextt = nowt;
	TAddTime(&nextt, &intt);

	do
	{
		if (sig & ireplysignal)
		{
			while ((imsg = TGetMsg(inst->x11_IReplyPort)))
			{
				/* returned input message */
				if (imsg->timsg_Type == TITYPE_REQSELECTION)
				{
					XSelectionEvent *reply =
						(XSelectionEvent *) imsg->timsg_Requestor;
					struct TTagItem *replytags =
						(struct TTagItem *) imsg->timsg_ReplyData;
					size_t len =
						TGetTag(replytags, TIMsgReply_UTF8SelectionLen, 0);
					TUINT8 *xdata = (TUINT8 *) TGetTag(replytags,
						TIMsgReply_UTF8Selection, TNULL);

					XChangeProperty(inst->x11_Display, reply->requestor,
						reply->property, XA_ATOM, 8, PropModeReplace,
						(unsigned char *) xdata, len);
					XSendEvent(inst->x11_Display, reply->requestor, 0,
						NoEventMask, (XEvent *) reply);
					XSync(inst->x11_Display, False);
					TFree((TAPTR) imsg->timsg_Requestor);
					TFree(xdata);
					/* reqselect roundtrip ended */
				}
				TFree(imsg);
			}
		}

		if (sig & cmdportsignal)
		{
			while (inst->x11_RequestInProgress == TNULL &&
				(req = TGetMsg(cmdport)))
			{
				x11_docmd(inst, req);
				if (inst->x11_RequestInProgress)
					break;
				TReplyMsg(req);
			}
		}

		XFlush(inst->x11_Display);

		FD_ZERO(&rset);
		FD_SET(inst->x11_fd_display, &rset);
		FD_SET(inst->x11_fd_sigpipe_read, &rset);

		TGetSystemTime(&nowt);

		if (inst->x11_NumInterval > 0 || inst->x11_RequestInProgress)
		{
			if (TCmpTime(&nowt, &nextt) >= 0)
			{
				/* expired; send interval: */
				struct TNode *next, *node = inst->x11_vlist.tlh_Head.tln_Succ;

				for (; (next = node->tln_Succ); node = next)
				{
					struct X11Window *v = (struct X11Window *) node;
					TIMSG *imsg;

					if ((v->eventmask & TITYPE_INTERVAL) &&
						x11_getimsg(inst, v, &imsg, TITYPE_INTERVAL))
						TPutMsg(v->imsgport, TNULL, imsg);
				}
				TAddTime(&nextt, &intt);
			}

			/* calculate new wait time: */
			waitt = nextt;
			TSubTime(&waitt, &nowt);
			if (waitt.tdt_Int64 <= 0 || waitt.tdt_Int64 > 20000)
			{
				nextt = nowt;
				TAddTime(&nextt, &intt);
				waitt = nextt;
				TSubTime(&waitt, &nowt);
			}
			tv.tv_sec = waitt.tdt_Int64 / 1000000;
			tv.tv_usec = waitt.tdt_Int64 % 1000000;
			ptv = &tv;
		}
		else
			ptv = NULL;

		/* wait for display, signal fd and timeout: */
		if (select(inst->x11_fd_max, &rset, NULL, NULL, ptv) > 0)
		{
			int nbytes;

			/* consume signal: */
			if (FD_ISSET(inst->x11_fd_sigpipe_read, &rset))
			{
				ioctl(inst->x11_fd_sigpipe_read, FIONREAD, &nbytes);
				if (nbytes > 0)
					if (read(inst->x11_fd_sigpipe_read, buf,
							TMIN(sizeof(buf), (size_t) nbytes)) != nbytes)
						TDBPRINTF(TDB_ERROR,
							("could not read wakeup signal\n"));
			}
		}

		/* process input messages: */
		x11_processevent(inst);

		/* send out input messages to owners: */
		x11_sendimessages(inst);

		/* get signal state: */
		sig = TSetSignal(0, waitsigs);

	}
	while (!(sig & TTASK_SIG_ABORT));

	TDBPRINTF(TDB_INFO, ("Device instance exit\n"));

	x11_exitinstance(inst);
}