VIDEO: Changed SDL2 vid_draw implementation to perform all texture references in the event processing thread

This commit is contained in:
Mark Pizzolato 2015-02-04 04:53:23 -08:00
parent 42df753b7d
commit cd4da419bb

View file

@ -64,8 +64,9 @@ char vid_release_key[64] = "Ctrl-Right-Shift";
#define EVENT_CLOSE 2 /* close event for SDL */
#define EVENT_CURSOR 3 /* new cursor for SDL */
#define EVENT_WARP 4 /* warp mouse position for SDL */
#define EVENT_OPEN 5 /* vid_open request */
#define EVENT_EXIT 6 /* program exit */
#define EVENT_DRAW 5 /* draw/blit region for SDL */
#define EVENT_OPEN 6 /* vid_open request */
#define EVENT_EXIT 7 /* program exit */
#define MAX_EVENTS 20 /* max events in queue */
typedef struct {
@ -158,7 +159,7 @@ main_argv = argv;
#if SDL_MAJOR_VERSION == 1
vid_main_thread_handle = SDL_CreateThread (main_thread , NULL);
#else
vid_main_thread_handle = SDL_CreateThread (main_thread , "simh-main-thread", NULL);
vid_main_thread_handle = SDL_CreateThread (main_thread , "simh-main", NULL);
#endif
while (1) {
int status = SDL_WaitEvent (&event);
@ -361,17 +362,21 @@ pixels = (uint32 *)vid_image->pixels;
for (i = 0; i < h; i++)
memcpy (pixels + ((i + y) * vid_width) + x, buf + w*i, w*sizeof(*pixels));
#else
SDL_Rect vid_dst;
vid_dst.x = x;
vid_dst.y = y;
vid_dst.w = w;
vid_dst.h = h;
SDL_Event user_event;
SDL_Rect *vid_dst;
sim_debug (SIM_VID_DBG_VIDEO, vid_dev, "vid_draw(%d, %d, %d, %d)\n", x, y, w, h);
if (SDL_UpdateTexture(vid_texture, &vid_dst, buf, w*sizeof(*buf)))
sim_printf ("%s: vid_draw() - SDL_UpdateTexture error: %s\n", sim_dname(vid_dev), SDL_GetError());
vid_dst = (SDL_Rect *)malloc (sizeof(*vid_dst));
vid_dst->x = x;
vid_dst->y = y;
vid_dst->w = w;
vid_dst->h = h;
user_event.type = SDL_USEREVENT;
user_event.user.code = EVENT_DRAW;
user_event.user.data1 = (void *)vid_dst;
user_event.user.data2 = (void *)buf;
SDL_PushEvent (&user_event);
#endif
}
@ -1104,6 +1109,20 @@ SDL_WarpMouseInWindow (NULL, vid_cursor_x, vid_cursor_y);
SDL_PumpEvents ();
}
void vid_draw_region (SDL_UserEvent *event)
{
SDL_Rect *vid_dst = (SDL_Rect *)event->data1;
uint32 *buf = (uint32 *)event->data2;
sim_debug (SIM_VID_DBG_VIDEO, vid_dev, "Draw Region Event: (%d,%d,%d,%d)\n", vid_dst->x, vid_dst->x, vid_dst->w, vid_dst->h);
if (SDL_UpdateTexture(vid_texture, vid_dst, buf, vid_dst->w*sizeof(*buf)))
sim_printf ("%s: vid_draw() - SDL_UpdateTexture error: %s\n", sim_dname(vid_dev), SDL_GetError());
free (vid_dst);
event->data1 = NULL;
}
int vid_video_events (void)
{
SDL_Event event;
@ -1371,8 +1390,9 @@ while (vid_active) {
break;
#endif
case SDL_USEREVENT:
/* There are 4 user events generated */
/* There are 5 user events generated */
/* EVENT_REDRAW to update the display */
/* EVENT_DRAW to update a region in the display texture */
/* EVENT_CURSOR to change the current cursor */
/* EVENT_WARP to warp the cursor position */
/* EVENT_CLOSE to wake up this thread and let */
@ -1407,6 +1427,10 @@ if (0) while (SDL_PeepEvents (&event, 1, SDL_GETEVENT, SD
if (event.user.code == EVENT_CLOSE) {
event.user.code = 0; /* Mark as done */
}
if (event.user.code == EVENT_DRAW) {
vid_draw_region ((SDL_UserEvent*)&event);
event.user.code = 0; /* Mark as done */
}
if (event.user.code != 0) {
sim_printf ("vid_thread(): Unexpected user event code: %d\n", event.user.code);
}
@ -1498,6 +1522,9 @@ t_stat vid_show_video (FILE* st, UNIT* uptr, int32 val, void* desc)
int i;
fprintf (st, "Video support using SDL: %s\n", vid_version());
#if defined (SDL_MAIN_AVAILABLE)
fprintf (st, " SDL Events being processed on the main process thread\n");
#endif
if (!vid_active) {
#if !defined (SDL_MAIN_AVAILABLE)
SDL_Init(SDL_INIT_VIDEO);