@@ -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 ;
@@ -4689,7 +4690,7 @@ EventFilter20to12(void *data, SDL_Event *event20)
4689
4690
}
4690
4691
4691
4692
case SDL_MOUSEMOTION :
4692
- if (!VideoSurface12 ) {
4693
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
4693
4694
return 1 ; /* we don't have a screen surface yet? Don't send this on to the app. */
4694
4695
}
4695
4696
@@ -5541,11 +5542,9 @@ EndVidModeCreate(void)
5541
5542
VideoPhysicalPalette20 = NULL ;
5542
5543
}
5543
5544
if (VideoSurface12 ) {
5544
- SDL12_Surface * screen12 = VideoSurface12 ;
5545
5545
SDL20_free (VideoSurface12 -> pixels );
5546
5546
VideoSurface12 -> pixels = NULL ;
5547
- VideoSurface12 = NULL ; /* SDL_FreeSurface will ignore the screen surface, so NULL the global variable out. */
5548
- SDL_FreeSurface (screen12 );
5547
+ FreeSurfaceContents (VideoSurface12 );
5549
5548
}
5550
5549
if (VideoConvertSurface20 ) {
5551
5550
SDL20_FreeSurface (VideoConvertSurface20 );
@@ -5579,16 +5578,27 @@ EndVidModeCreate(void)
5579
5578
return NULL ;
5580
5579
}
5581
5580
5582
-
5583
- static SDL12_Surface *
5584
- CreateSurface12WithFormat ( const int w , const int h , const Uint32 fmt )
5581
+ /* Essentially the same as SDL_CreateRGBSurface, but in-place */
5582
+ static void
5583
+ CreateVideoSurface ( const Uint32 fmt )
5585
5584
{
5586
5585
Uint32 rmask , gmask , bmask , amask ;
5587
5586
int bpp ;
5587
+ SDL_Surface * surface20 ;
5588
+
5588
5589
if (!SDL20_PixelFormatEnumToMasks (fmt , & bpp , & rmask , & gmask , & bmask , & amask )) {
5589
- return NULL ;
5590
+ return ;
5590
5591
}
5591
- return SDL_CreateRGBSurface (0 , w , h , bpp , rmask , gmask , bmask , amask );
5592
+
5593
+ SDL20_zerop (VideoSurface12 );
5594
+ surface20 = CreateRGBSurface (0 , 0 , 0 , bpp , rmask , gmask , bmask , amask );
5595
+
5596
+ if (!Surface20to12InPlace (surface20 , VideoSurface12 )) {
5597
+ FreeSurfaceContents (VideoSurface12 );
5598
+ return ;
5599
+ }
5600
+
5601
+ Surface12SetMasks (VideoSurface12 , rmask , gmask , bmask , amask );
5592
5602
}
5593
5603
5594
5604
static SDL_Surface *
@@ -5925,6 +5935,8 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
5925
5935
int scaled_height = height ;
5926
5936
const char * fromwin_env = NULL ;
5927
5937
5938
+ VideoSurface12 = & VideoSurface12Location ;
5939
+
5928
5940
if (flags12 & SDL12_OPENGL ) {
5929
5941
/* For now we default GL scaling to ENABLED. If an app breaks or is linked directly
5930
5942
to glBindFramebuffer, they'll need to turn it off with this environment variable.
@@ -6014,11 +6026,11 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
6014
6026
default : SDL20_SetError ("Unsupported bits-per-pixel" ); return NULL ;
6015
6027
}
6016
6028
6017
- SDL_assert ((VideoSurface12 != NULL ) == (VideoWindow20 != NULL ));
6029
+ SDL_assert ((VideoSurface12 -> surface20 != NULL ) == (VideoWindow20 != NULL ));
6018
6030
6019
- if (VideoSurface12 && ((VideoSurface12 -> flags & SDL12_OPENGL ) != (flags12 & SDL12_OPENGL ))) {
6031
+ if (VideoSurface12 -> surface20 && ((VideoSurface12 -> flags & SDL12_OPENGL ) != (flags12 & SDL12_OPENGL ))) {
6020
6032
EndVidModeCreate (); /* rebuild the window if moving to/from a GL context */
6021
- } else if (VideoSurface12 && (VideoSurface12 -> surface20 -> format -> format != appfmt )) {
6033
+ } else if (VideoSurface12 -> surface20 && (VideoSurface12 -> surface20 -> format -> format != appfmt )) {
6022
6034
EndVidModeCreate (); /* rebuild the window if changing pixel format */
6023
6035
} else if (VideoGLContext20 ) {
6024
6036
/* SDL 1.2 (infuriatingly!) destroys the GL context on each resize in some cases, on various platforms. Try to match that. */
@@ -6160,11 +6172,11 @@ SetVideoModeImpl(int width, int height, int bpp, Uint32 flags12)
6160
6172
SDL20_SetWindowResizable (VideoWindow20 , (flags12 & SDL12_RESIZABLE ) ? SDL_TRUE : SDL_FALSE );
6161
6173
}
6162
6174
6163
- if (VideoSurface12 ) {
6175
+ if (VideoSurface12 -> surface20 ) {
6164
6176
SDL20_free (VideoSurface12 -> pixels );
6165
6177
} else {
6166
- VideoSurface12 = CreateSurface12WithFormat ( 0 , 0 , appfmt );
6167
- if (!VideoSurface12 ) {
6178
+ CreateVideoSurface ( appfmt );
6179
+ if (!VideoSurface12 -> surface20 ) {
6168
6180
return EndVidModeCreate ();
6169
6181
}
6170
6182
}
@@ -6680,7 +6692,7 @@ DECLSPEC12 SDL12_Surface * SDLCALL
6680
6692
SDL_DisplayFormat (SDL12_Surface * surface12 )
6681
6693
{
6682
6694
const Uint32 flags = surface12 -> flags & (SDL12_SRCCOLORKEY |SDL12_SRCALPHA |SDL12_RLEACCELOK );
6683
- if (!VideoSurface12 ) {
6695
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
6684
6696
SDL20_SetError ("No video mode has been set" );
6685
6697
return NULL ;
6686
6698
}
@@ -6696,7 +6708,7 @@ SDL_DisplayFormatAlpha(SDL12_Surface *surface12)
6696
6708
SDL_PixelFormat * fmt20 = NULL ;
6697
6709
SDL12_PixelFormat fmt12 ;
6698
6710
6699
- if (!VideoSurface12 ) {
6711
+ if (!VideoSurface12 || ! VideoSurface12 -> surface20 ) {
6700
6712
SDL20_SetError ("No video mode has been set" );
6701
6713
return NULL ;
6702
6714
}
@@ -7281,7 +7293,7 @@ static void
7281
7293
HandleInputGrab (SDL12_GrabMode mode )
7282
7294
{
7283
7295
/* SDL 1.2 always grabbed input if the video mode was fullscreen. */
7284
- const SDL_bool isfullscreen = (VideoSurface12 && (VideoSurface12 -> flags & SDL12_FULLSCREEN )) ? SDL_TRUE : SDL_FALSE ;
7296
+ const SDL_bool isfullscreen = (VideoSurface12 && VideoSurface12 -> surface20 && (VideoSurface12 -> flags & SDL12_FULLSCREEN )) ? SDL_TRUE : SDL_FALSE ;
7285
7297
const SDL_bool wantgrab = (isfullscreen || (mode == SDL12_GRAB_ON )) ? SDL_TRUE : SDL_FALSE ;
7286
7298
if (VideoWindowGrabbed != wantgrab ) {
7287
7299
if (VideoWindow20 ) {
0 commit comments