Skip to content

Commit

Permalink
Actually, just force the renderer to be SDL_DOUBLEBUF for now.
Browse files Browse the repository at this point in the history
If this ends up being a problem, the dirty rect code is in revision control.
  • Loading branch information
icculus committed Feb 18, 2019
1 parent 95a9698 commit 54c81e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 59 deletions.
62 changes: 4 additions & 58 deletions src/SDL12_compat.c
Expand Up @@ -441,8 +441,6 @@ static SDL_Texture *VideoTexture20 = NULL;
static SDL12_Surface *VideoSurface12 = NULL;
static SDL_Surface *VideoConvertSurface20 = NULL;
static SDL_GLContext *VideoGLContext20 = NULL;
static int VideoNumDirtyRects = 0;
static SDL_Rect VideoDirtyRects[16];
static char *WindowTitle = NULL;
static char *WindowIconTitle = NULL;
static SDL12_Surface *VideoIcon12;
Expand Down Expand Up @@ -922,25 +920,12 @@ SDL_VideoDriverName(char *namebuf, int maxlen)
return GetDriverName(SDL20_GetCurrentVideoDriver(), namebuf, maxlen);
}

static void PresentScreen(void);

DECLSPEC void SDLCALL
SDL_PumpEvents(void)
{
/* catch things that want to do dirty rectangles but ignore DOUBLEBUF.
Since we have to compose the whole scene at once, catch it in here. */
if (VideoSurface12 && VideoNumDirtyRects) {
PresentScreen();
}
SDL20_PumpEvents();
}

DECLSPEC int SDLCALL
SDL_PollEvent(SDL12_Event *event12)
{
EventQueueType *next;

SDL_PumpEvents(); /* this will run our filter and build our 1.2 queue. */
SDL20_PumpEvents(); /* this will run our filter and build our 1.2 queue. */

if (EventQueueHead == NULL)
return 0; /* no events at the moment. */
Expand Down Expand Up @@ -1870,8 +1855,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
}
}

VideoNumDirtyRects = 0;

VideoSurface12->surface20->flags |= SDL_PREALLOC;
VideoSurface12->flags |= SDL12_PREALLOC;
VideoSurface12->pixels = VideoSurface12->surface20->pixels = NULL;
Expand Down Expand Up @@ -1939,6 +1922,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
}

VideoSurface12->flags &= ~SDL12_OPENGL;
VideoSurface12->flags |= SDL12_DOUBLEBUF;
VideoSurface12->surface20->pixels = SDL20_malloc(height * VideoSurface12->pitch);
VideoSurface12->pixels = VideoSurface12->surface20->pixels;
if (!VideoSurface12->pixels) {
Expand Down Expand Up @@ -2031,13 +2015,8 @@ PresentScreen(void)
{
void *pixels = NULL;
int pitch = 0;
int i;

SDL_assert(VideoSurface12 != NULL);
SDL_assert(VideoNumDirtyRects > 0); /* only called internally from places that add rects */
SDL_assert(VideoNumDirtyRects <= SDL_arraysize(VideoDirtyRects));

FIXME("Maybe lock a subset of the texture if only one dirty rectangle?");

if (SDL20_LockTexture(VideoTexture20, NULL, &pixels, &pitch) < 0) {
return; /* oh well */
Expand All @@ -2046,58 +2025,26 @@ PresentScreen(void)
FIXME("Maybe lock texture always, until present, if no conversion needed?");
VideoConvertSurface20->pixels = pixels;
VideoConvertSurface20->pitch = pitch;

for (i = 0; i < VideoNumDirtyRects; i++) {
SDL20_UpperBlit(VideoSurface12->surface20, &VideoDirtyRects[i], VideoConvertSurface20, &VideoDirtyRects[i]);
}

SDL20_UpperBlit(VideoSurface12->surface20, NULL, VideoConvertSurface20, NULL);
VideoConvertSurface20->pixels = NULL;
VideoConvertSurface20->pitch = 0;
VideoNumDirtyRects = 0;

SDL20_UnlockTexture(VideoTexture20);
SDL20_RenderCopy(VideoRenderer20, VideoTexture20, NULL, NULL);
SDL20_RenderPresent(VideoRenderer20);
}

static void
AddDirtyRect(const SDL_Rect *r)
{
const int sw = VideoSurface12->w;
const int sh = VideoSurface12->h;
FIXME("Clip against the surface geometry");
if (r == NULL) {
VideoNumDirtyRects = -1; /* NULL == "replace whole screen" */
} else if ((r->x <= 0) && (r->y <= 0) && (r->w >= VideoSurface12->w) && (r->h >= VideoSurface12->h)) {
VideoNumDirtyRects = -1; /* this rect covers whole screen */
} else if (VideoNumDirtyRects >= SDL_arraysize(VideoDirtyRects)) {
VideoNumDirtyRects = -1; /* too many rects, just do it all */
} else if ((r->x >= sw) || (r->y >= sh)) {
return; /* nothing to do */
} else if (VideoNumDirtyRects >= 0) {
FIXME("Clip against other rectangles?");
SDL_memcpy(&VideoDirtyRects[VideoNumDirtyRects], r, sizeof (*r));
VideoNumDirtyRects++;
}
}

DECLSPEC void SDLCALL
SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL_Rect *rects)
{
int i;

/* strangely, SDL 1.2 doesn't check if surface12 is NULL before touching it */
/* (UpdateRect, singular, does...) */
if (surface12->flags & SDL12_OPENGL) {
SDL20_SetError("Use SDL_GL_SwapBuffers() on OpenGL surfaces");
return;
}

if (surface12 == VideoSurface12) {
for (i = 0; i < numrects; i++) {
AddDirtyRect(&rects[i]);
}
}
/* everything else is marked SDL12_DOUBLEBUF and is a no-op here. */
}

DECLSPEC void SDLCALL
Expand All @@ -2121,7 +2068,6 @@ SDL_Flip(SDL12_Surface *surface12)
}

if (surface12 == VideoSurface12) {
AddDirtyRect(NULL);
PresentScreen();
}

Expand Down
2 changes: 1 addition & 1 deletion src/SDL20_syms.h
Expand Up @@ -52,7 +52,7 @@ SDL20_SYM(const char *,GetCurrentVideoDriver,(void),(),return)

SDL20_SYM(SDL_assert_state,ReportAssertion,(SDL_assert_data *a,const char *b,const char *c, int d),(a,b,c,d),return)

SDL20_SYM(void,PumpEvents,(void),(),)
SDL20_SYM_PASSTHROUGH(void,PumpEvents,(void),(),)
SDL20_SYM(void,SetEventFilter,(SDL_EventFilter a, void *b),(a,b),)

SDL20_SYM(int,GetNumDisplayModes,(int a),(a),return)
Expand Down

0 comments on commit 54c81e1

Please sign in to comment.