Re: [hatari-devel] Open Hatari in big window

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 3/31/20 10:49 PM, th.huth@xxxxxxxxx wrote:
Am 29.03.2020 01:54 schrieb Eero Tamminen:
On 3/28/20 9:17 PM, th.huth@xxxxxxxxx wrote:
1st patch: Did you check with sizeof(CNF_STRUCT) that this really makes a difference? Otherwise just drop the patch, please.

CNF_SOUND size isn't changed, it's 4112 with both, so I dropped that
part of the patch.

CNF_SCREEN size decreases, so I left that:
- SDL2: 64 -> 56
- SDL1: 56 -> 48

Ok, fine for me, I think it should be OK to commit this.

Pushed.


Please also do not separate pfmt from rm, gm and bm.

Format is needed to re-create the texture, but
red, green & blue are needed only for surface
creation.

Are you saying that I should re-create also
surface whenever scale factor is changed, although
that is redundant?

No. Could you just simply pass pfmt as parameter to Screen_SetTextureScale, please?

main.c::Main_EventHandler() needs to call that on window resizes, and it doesn't know anything about format.

Would separate function providing both masks & format for given bitdepth be any better?

(See attached patch.)


	- Eero
diff --git a/src/screen.c b/src/screen.c
index 77f2f55e..725265e4 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -312,7 +312,31 @@ static void Screen_FreeSDL2Resources(void)
 	}
 }
 
-/*
+/**
+ * Return format for given bit-depth, and set R/G/B masks to match
+ * that format. Exit on unknown bitdepths
+ */
+static int bit_format(int depth, int *rm, int *gm, int *bm)
+{
+	if (depth == 16)
+	{
+		*rm = 0xF800;
+		*gm = 0x07E0;
+		*bm = 0x001F;
+		return SDL_PIXELFORMAT_RGB565;
+	}
+	if (depth == 32)
+	{
+		*rm = 0x00FF0000;
+		*gm = 0x0000FF00;
+		*bm = 0x000000FF;
+		return SDL_PIXELFORMAT_RGB888;
+	}
+	fprintf(stderr, "ERROR: unknown bitdepth %d requested, exiting...\n", depth);
+	exit(1);
+}
+
+/**
  * Create window backing texture when needed, with suitable scaling
  * quality.
  *
@@ -334,8 +358,8 @@ void Screen_SetTextureScale(int width, int height, int win_width, int win_height
 {
 	static char prev_quality = '0';
 	float scale_w, scale_h, scale;
+	int pfmt, dummy;
 	char quality;
-	int pfmt;
 
 	if (!(bUseSdlRenderer && sdlRenderer))
 		return;
@@ -366,11 +390,7 @@ void Screen_SetTextureScale(int width, int height, int win_width, int win_height
 			sdlTexture = NULL;
 		}
 
-		if (sdlscrn->format->BitsPerPixel == 16)
-			pfmt = SDL_PIXELFORMAT_RGB565;
-		else
-			pfmt = SDL_PIXELFORMAT_RGB888;
-
+		pfmt = bit_format(sdlscrn->format->BitsPerPixel, &dummy, &dummy, &dummy);
 		sdlTexture = SDL_CreateTexture(sdlRenderer, pfmt,
 					       SDL_TEXTUREACCESS_STREAMING,
 					       width, height);
@@ -524,18 +544,7 @@ bool Screen_SetSDLVideoSize(int width, int height, int bitdepth, bool bForceChan
 		else
 			SDL_RenderSetScale(sdlRenderer, scale, scale);
 
-		if (bitdepth == 16)
-		{
-			rm = 0xF800;
-			gm = 0x07E0;
-			bm = 0x001F;
-		}
-		else
-		{
-			rm = 0x00FF0000;
-			gm = 0x0000FF00;
-			bm = 0x000000FF;
-		}
+		bit_format(bitdepth, &rm, &gm, &bm);
 		sdlscrn = SDL_CreateRGBSurface(0, width, height, bitdepth,
 		                               rm, gm, bm, 0);
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/