src/video/riscos/SDL_wimppoll.c
changeset 955 d74fbf56f2f6
parent 769 b8d311d90021
child 1035 974ba6ae0fa3
equal deleted inserted replaced
954:3acd16ea0180 955:d74fbf56f2f6
    41 
    41 
    42 #include "kernel.h"
    42 #include "kernel.h"
    43 #include "swis.h"
    43 #include "swis.h"
    44 #include "unixlib/os.h"
    44 #include "unixlib/os.h"
    45 
    45 
       
    46 #ifndef DISABLE_THREADS
       
    47 #include <pthread.h>
       
    48 #endif
       
    49 
    46 /* Local functions */
    50 /* Local functions */
    47 void WIMP_Poll(_THIS, int waitTime);
    51 void WIMP_Poll(_THIS, int waitTime);
    48 void WIMP_SetFocus(int win);
    52 void WIMP_SetFocus(int win);
    49 
    53 
    50 /* SDL_riscossprite functions */
    54 /* SDL_riscossprite functions */
    54 
    58 
    55 
    59 
    56 extern void WIMP_PollMouse(_THIS);
    60 extern void WIMP_PollMouse(_THIS);
    57 extern void RISCOS_PollKeyboard();
    61 extern void RISCOS_PollKeyboard();
    58 
    62 
       
    63 #ifdef DISABLE_THREADS
    59 extern void DRenderer_FillBuffers();
    64 extern void DRenderer_FillBuffers();
    60 
    65 
    61 /* Timer running function */
    66 /* Timer running function */
    62 extern void RISCOS_CheckTimer();
    67 extern void RISCOS_CheckTimer();
       
    68 
       
    69 #else
       
    70 extern int riscos_using_threads;
       
    71 #endif
    63 
    72 
    64 /* Mouse cursor handling */
    73 /* Mouse cursor handling */
    65 extern void WIMP_ReshowCursor(_THIS);
    74 extern void WIMP_ReshowCursor(_THIS);
    66 
    75 
    67 int hasFocus = 0;
    76 int hasFocus = 0;
    73 void WIMP_PumpEvents(_THIS)
    82 void WIMP_PumpEvents(_THIS)
    74 {
    83 {
    75 	WIMP_Poll(this, 0);
    84 	WIMP_Poll(this, 0);
    76 	if (hasFocus) RISCOS_PollKeyboard();
    85 	if (hasFocus) RISCOS_PollKeyboard();
    77 	if (mouseInWindow) WIMP_PollMouse(this);
    86 	if (mouseInWindow) WIMP_PollMouse(this);
       
    87 #ifdef DISABLE_THREADS
    78 	DRenderer_FillBuffers();
    88 	DRenderer_FillBuffers();
    79 	if (SDL_timer_running) RISCOS_CheckTimer();
    89 	if (SDL_timer_running) RISCOS_CheckTimer();
       
    90 #endif
    80 }
    91 }
    81 
    92 
    82 
    93 
    83 void WIMP_Poll(_THIS, int waitTime)
    94 void WIMP_Poll(_THIS, int waitTime)
    84 {
    95 {
    98 		waitTime += regs.r[0];
   109 		waitTime += regs.r[0];
    99     }
   110     }
   100 
   111 
   101     while (doPoll)
   112     while (doPoll)
   102     {
   113     {
       
   114 #ifndef DISABLE_THREADS
       
   115        /* Stop thread callbacks while program is paged out */
       
   116        if (riscos_using_threads) __pthread_stop_ticker();
       
   117 #endif
       
   118 
   103         if (waitTime <= 0)
   119         if (waitTime <= 0)
   104         {
   120         {
   105         	regs.r[0] = pollMask; /* Poll Mask */
   121         	regs.r[0] = pollMask; /* Poll Mask */
   106         	 /* For no wait time mask out null event so we wait until something happens */
   122         	/* For no wait time mask out null event so we wait until something happens */
   107         	if (waitTime < 0) regs.r[0] |= 1;
   123         	if (waitTime < 0) regs.r[0] |= 1;
   108         	regs.r[1] = (int)message;
   124         	regs.r[1] = (int)message;
   109         	_kernel_swi(Wimp_Poll, &regs, &regs);
   125         	_kernel_swi(Wimp_Poll, &regs, &regs);
   110         } else
   126         } else
   111         {
   127         {
   114         	regs.r[2] = waitTime;
   130         	regs.r[2] = waitTime;
   115         	_kernel_swi(Wimp_PollIdle, &regs, &regs);
   131         	_kernel_swi(Wimp_PollIdle, &regs, &regs);
   116         }
   132         }
   117 
   133 
   118 		/* Flag to specify if we post a SDL_SysWMEvent */
   134 		/* Flag to specify if we post a SDL_SysWMEvent */
   119 		sysEvent = 0;
   135 	sysEvent = 0;
   120         
   136         
   121         code = (unsigned int)regs.r[0];
   137         code = (unsigned int)regs.r[0];
   122 
   138 
   123 		switch(code)
   139 	switch(code)
   124 		{
   140 	{
   125 		case 0:  /* Null Event - drop out for standard processing*/
   141         case 0:  /* Null Event - drop out for standard processing*/
   126 		   doPoll = 0;
   142 	   doPoll = 0;
   127 		   break;
   143 	   break;
   128 
   144 
   129 		case 1:     /* Redraw window */
   145 	case 1:     /* Redraw window */
   130         	_kernel_swi(Wimp_RedrawWindow, &regs,&regs);
   146            _kernel_swi(Wimp_RedrawWindow, &regs,&regs);
   131 			if (message[0] == sdlWindow)
   147 	   if (message[0] == sdlWindow)
   132 			{
   148 	   {
   133         		while (regs.r[0])
   149                  while (regs.r[0])
   134         		{
   150                  {
   135         			WIMP_PlotSprite(this, message[1], message[2]);
   151            	    WIMP_PlotSprite(this, message[1], message[2]);
   136         			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
   152            	    _kernel_swi(Wimp_GetRectangle, &regs, &regs);
   137         		}
   153                  }
   138 			} else
   154 	   } else
   139 			{
   155 	  {
   140 				/* TODO: Currently we just eat them - we may need to pass them on */
   156 	/* TODO: Currently we just eat them - we may need to pass them on */
   141         		while (regs.r[0])
   157         	while (regs.r[0])
   142         		{
   158         	{
   143         			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
   159                         _kernel_swi(Wimp_GetRectangle, &regs, &regs);
   144         		}
   160         	}
   145 			}
   161 	  }
   146         	break;
   162           break;
   147         	
   163         	
   148 		case 2:		/* Open window */
   164 		case 2:		/* Open window */
   149 		   if ( resizeOnOpen && message[0] == sdlWindow)
   165 		   if ( resizeOnOpen && message[0] == sdlWindow)
   150 		   {
   166 		   {
   151 		      /* Ensure window is correct size */
   167 		      /* Ensure window is correct size */
   275 			memcpy(wmmsg.pollBlock, message, 64 * sizeof(int));
   291 			memcpy(wmmsg.pollBlock, message, 64 * sizeof(int));
   276 
   292 
   277 			/* Fall out of polling loop if message is successfully posted */
   293 			/* Fall out of polling loop if message is successfully posted */
   278 			if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
   294 			if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
   279 		}
   295 		}
   280 
   296 #ifndef DISABLE_THREADS
       
   297 		if (riscos_using_threads)
       
   298 		{
       
   299                    /* Restart ticker here so other thread can not interfere
       
   300                       with the Redraw processing */
       
   301 		   if (riscos_using_threads) __pthread_start_ticker();
       
   302                    /* Give other threads a better chance of running */
       
   303 		   pthread_yield();
       
   304 		}
       
   305 #endif
   281     }
   306     }
   282 }
   307 }
   283 
   308 
   284 /* Set focus to specified window */
   309 /* Set focus to specified window */
   285 void WIMP_SetFocus(int win)
   310 void WIMP_SetFocus(int win)
   301 {
   326 {
   302 	if (current_video && current_video->hidden->window_handle)
   327 	if (current_video && current_video->hidden->window_handle)
   303 	{
   328 	{
   304 		WIMP_Poll(current_video, 0);
   329 		WIMP_Poll(current_video, 0);
   305 	}
   330 	}
       
   331 #ifdef DISABLE_THREADS
   306 	/* Keep sound buffers running */
   332 	/* Keep sound buffers running */
   307 	DRenderer_FillBuffers();
   333 	DRenderer_FillBuffers();
   308 	if (SDL_timer_running) RISCOS_CheckTimer();
   334 	if (SDL_timer_running) RISCOS_CheckTimer();
       
   335 #endif
   309 }
   336 }