shithub: cstory

Download patch

ref: 2bcab6adee8517e0414126db4026df323b1eabed
parent: 30ea89d3fa8035d29d60b9ac7cafa875e7ffeb89
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Sep 14 19:26:55 EDT 2020

Change software renderer sub-backend API

No more locking

--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -35,7 +35,7 @@
 {
 	if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
 	{
-		framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
+		framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch);
 		framebuffer.width = screen_width;
 		framebuffer.height = screen_height;
 
@@ -56,11 +56,10 @@
 
 void RenderBackend_DrawScreen(void)
 {
-	WindowBackend_Software_UnlockFramebuffer();
-
 	WindowBackend_Software_Display();
 
-	framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
+	// Backends may use double-buffering, so fetch a new framebuffer just in case
+	framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch);
 }
 
 RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
--- a/src/Backends/Rendering/Window/Software.h
+++ b/src/Backends/Rendering/Window/Software.h
@@ -4,7 +4,6 @@
 
 bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
 void WindowBackend_Software_DestroyWindow(void);
-unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
-void WindowBackend_Software_UnlockFramebuffer(void);
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch);
 void WindowBackend_Software_Display(void);
 void WindowBackend_Software_HandleWindowResize(size_t width, size_t height);
--- a/src/Backends/Rendering/Window/Software/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/Software/GLFW3.cpp
@@ -95,16 +95,11 @@
 	glfwDestroyWindow(window);
 }
 
-unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
 {
 	*pitch = framebuffer_width * 3;
 
 	return framebuffer;
-}
-
-void WindowBackend_Software_UnlockFramebuffer(void)
-{
-	// Nothing to do here
 }
 
 void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Window/Software/Null.cpp
+++ b/src/Backends/Rendering/Window/Software/Null.cpp
@@ -28,16 +28,11 @@
 	free(framebuffer);
 }
 
-unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
 {
 	*pitch = framebuffer_pitch;
 
 	return framebuffer;
-}
-
-void WindowBackend_Software_UnlockFramebuffer(void)
-{
-	// Nothing to do here
 }
 
 void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Window/Software/SDL2.cpp
+++ b/src/Backends/Rendering/Window/Software/SDL2.cpp
@@ -32,6 +32,8 @@
 
 			if (framebuffer_sdlsurface != NULL)
 			{
+				SDL_LockSurface(framebuffer_sdlsurface); // If this errors then oh dear
+
 				Backend_PostWindowCreation();
 
 				return true;
@@ -64,25 +66,21 @@
 	SDL_DestroyWindow(window);
 }
 
-unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
 {
-	if (SDL_LockSurface(framebuffer_sdlsurface) < 0)
-		return NULL;
-
 	*pitch = framebuffer_sdlsurface->pitch;
 
 	return (unsigned char*)framebuffer_sdlsurface->pixels;
 }
 
-void WindowBackend_Software_UnlockFramebuffer(void)
+void WindowBackend_Software_Display(void)
 {
 	SDL_UnlockSurface(framebuffer_sdlsurface);
-}
 
-void WindowBackend_Software_Display(void)
-{
 	if (SDL_BlitSurface(framebuffer_sdlsurface, NULL, window_sdlsurface, NULL) < 0)
 		Backend_PrintError("Couldn't blit framebuffer surface to window surface: %s", SDL_GetError());
+
+	SDL_LockSurface(framebuffer_sdlsurface); // If this errors then oh dear
 
 	if (SDL_UpdateWindowSurface(window) < 0)
 		Backend_PrintError("Couldn't copy window surface to the screen: %s", SDL_GetError());
--- a/src/Backends/Rendering/Window/Software/WiiU.cpp
+++ b/src/Backends/Rendering/Window/Software/WiiU.cpp
@@ -206,16 +206,11 @@
 	free(fake_framebuffer);
 }
 
-unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
 {
 	*pitch = fake_framebuffer_width * 3;
 
 	return fake_framebuffer;
-}
-
-void WindowBackend_Software_UnlockFramebuffer(void)
-{
-	// Nothing to do here
 }
 
 ATTRIBUTE_HOT void WindowBackend_Software_Display(void)