@@ -980,6 +980,7 @@ static SDL_Window *VideoWindow20 = NULL;
980
980
static SDL_Renderer * VideoRenderer20 = NULL ;
981
981
static SDL_mutex * VideoRendererLock = NULL ;
982
982
static SDL_Texture * VideoTexture20 = NULL ;
983
+ static SDL12_Surface VideoSurface12Location ;
983
984
static SDL12_Surface * VideoSurface12 = NULL ;
984
985
static SDL_Palette * VideoPhysicalPalette20 = NULL ;
985
986
static Uint32 VideoSurfacePresentTicks = 0 ;
@@ -4714,7 +4715,7 @@ EventFilter20to12(void *data, SDL_Event *event20)
4714
4715
}
4715
4716
4716
4717
case SDL_MOUSEMOTION :
4717
- if (!VideoSurface12 ) {
4718
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
4718
4719
return 1 ; /* we don't have a screen surface yet? Don't send this on to the app. */
4719
4720
}
4720
4721
@@ -5569,11 +5570,9 @@ EndVidModeCreate(void)
5569
5570
VideoPhysicalPalette20 = NULL ;
5570
5571
}
5571
5572
if (VideoSurface12 ) {
5572
- SDL12_Surface * screen12 = VideoSurface12 ;
5573
5573
SDL20_free (VideoSurface12 -> pixels );
5574
5574
VideoSurface12 -> pixels = NULL ;
5575
- VideoSurface12 = NULL ; /* SDL_FreeSurface will ignore the screen surface, so NULL the global variable out. */
5576
- SDL_FreeSurface (screen12 );
5575
+ FreeSurfaceContents (VideoSurface12 );
5577
5576
}
5578
5577
if (VideoConvertSurface20 ) {
5579
5578
SDL20_FreeSurface (VideoConvertSurface20 );
@@ -5607,16 +5606,27 @@ EndVidModeCreate(void)
5607
5606
return NULL ;
5608
5607
}
5609
5608
5610
-
5611
- static SDL12_Surface *
5612
- CreateSurface12WithFormat ( const int w , const int h , const Uint32 fmt )
5609
+ /* Essentially the same as SDL_CreateRGBSurface, but in-place */
5610
+ static void
5611
+ CreateVideoSurface ( const Uint32 fmt )
5613
5612
{
5614
5613
Uint32 rmask , gmask , bmask , amask ;
5615
5614
int bpp ;
5615
+ SDL_Surface * surface20 ;
5616
+
5616
5617
if (!SDL20_PixelFormatEnumToMasks (fmt , & bpp , & rmask , & gmask , & bmask , & amask )) {
5617
- return NULL ;
5618
+ return ;
5618
5619
}
5619
- return SDL_CreateRGBSurface (0 , w , h , bpp , rmask , gmask , bmask , amask );
5620
+
5621
+ SDL20_zerop (VideoSurface12 );
5622
+ surface20 = CreateRGBSurface (0 , 0 , 0 , bpp , rmask , gmask , bmask , amask );
5623
+
5624
+ if (!Surface20to12InPlace (surface20 , VideoSurface12 )) {
5625
+ FreeSurfaceContents (VideoSurface12 );
5626
+ return ;
5627
+ }
5628
+
5629
+ Surface12SetMasks (VideoSurface12 , rmask , gmask , bmask , amask );
5620
5630
}
5621
5631
5622
5632
static SDL_Surface *
@@ -5953,6 +5963,8 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
5953
5963
int scaled_height = height ;
5954
5964
const char * fromwin_env = NULL ;
5955
5965
5966
+ VideoSurface12 = & VideoSurface12Location ;
5967
+
5956
5968
if (flags12 & SDL12_OPENGL ) {
5957
5969
/* For now we default GL scaling to ENABLED. If an app breaks or is linked directly
5958
5970
to glBindFramebuffer, they'll need to turn it off with this environment variable.
@@ -6042,11 +6054,11 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
6042
6054
default : SDL20_SetError ("Unsupported bits-per-pixel" ); return NULL ;
6043
6055
}
6044
6056
6045
- SDL_assert ((VideoSurface12 != NULL ) == (VideoWindow20 != NULL ));
6057
+ SDL_assert ((VideoSurface12 -> surface20 != NULL ) == (VideoWindow20 != NULL ));
6046
6058
6047
- if (VideoSurface12 && ((VideoSurface12 -> flags & SDL12_OPENGL ) != (flags12 & SDL12_OPENGL ))) {
6059
+ if (VideoSurface12 -> surface20 && ((VideoSurface12 -> flags & SDL12_OPENGL ) != (flags12 & SDL12_OPENGL ))) {
6048
6060
EndVidModeCreate (); /* rebuild the window if moving to/from a GL context */
6049
- } else if (VideoSurface12 && (VideoSurface12 -> surface20 -> format -> format != appfmt )) {
6061
+ } else if (VideoSurface12 -> surface20 && (VideoSurface12 -> surface20 -> format -> format != appfmt )) {
6050
6062
EndVidModeCreate (); /* rebuild the window if changing pixel format */
6051
6063
} else if (VideoGLContext20 ) {
6052
6064
/* SDL 1.2 (infuriatingly!) destroys the GL context on each resize in some cases, on various platforms. Try to match that. */
@@ -6188,11 +6200,11 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
6188
6200
SDL20_SetWindowResizable (VideoWindow20 , (flags12 & SDL12_RESIZABLE ) ? SDL_TRUE : SDL_FALSE );
6189
6201
}
6190
6202
6191
- if (VideoSurface12 ) {
6203
+ if (VideoSurface12 -> surface20 ) {
6192
6204
SDL20_free (VideoSurface12 -> pixels );
6193
6205
} else {
6194
- VideoSurface12 = CreateSurface12WithFormat ( 0 , 0 , appfmt );
6195
- if (!VideoSurface12 ) {
6206
+ CreateVideoSurface ( appfmt );
6207
+ if (!VideoSurface12 -> surface20 ) {
6196
6208
return EndVidModeCreate ();
6197
6209
}
6198
6210
}
@@ -6708,7 +6720,7 @@ DECLSPEC12 SDL12_Surface * SDLCALL
6708
6720
SDL_DisplayFormat (SDL12_Surface * surface12 )
6709
6721
{
6710
6722
const Uint32 flags = surface12 -> flags & (SDL12_SRCCOLORKEY |SDL12_SRCALPHA |SDL12_RLEACCELOK );
6711
- if (!VideoSurface12 ) {
6723
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
6712
6724
SDL20_SetError ("No video mode has been set" );
6713
6725
return NULL ;
6714
6726
}
@@ -6724,7 +6736,7 @@ SDL_DisplayFormatAlpha(SDL12_Surface *surface12)
6724
6736
SDL_PixelFormat * fmt20 = NULL ;
6725
6737
SDL12_PixelFormat fmt12 ;
6726
6738
6727
- if (!VideoSurface12 ) {
6739
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
6728
6740
SDL20_SetError ("No video mode has been set" );
6729
6741
return NULL ;
6730
6742
}
@@ -7309,7 +7321,7 @@ static void
7309
7321
HandleInputGrab (SDL12_GrabMode mode )
7310
7322
{
7311
7323
/* SDL 1.2 always grabbed input if the video mode was fullscreen. */
7312
- const SDL_bool isfullscreen = (VideoSurface12 && (VideoSurface12 -> flags & SDL12_FULLSCREEN )) ? SDL_TRUE : SDL_FALSE ;
7324
+ const SDL_bool isfullscreen = (VideoSurface12 && VideoSurface12 -> surface20 && (VideoSurface12 -> flags & SDL12_FULLSCREEN )) ? SDL_TRUE : SDL_FALSE ;
7313
7325
const SDL_bool wantgrab = (isfullscreen || (mode == SDL12_GRAB_ON )) ? SDL_TRUE : SDL_FALSE ;
7314
7326
if (VideoWindowGrabbed != wantgrab ) {
7315
7327
if (VideoWindow20 ) {
0 commit comments