Simple Directmedia Layer
at main 78 lines 2.7 kB view raw
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_VIDEO_DRIVER_DUMMY 24 25#include "../SDL_sysvideo.h" 26#include "../../SDL_properties_c.h" 27#include "SDL_nullframebuffer_c.h" 28 29#define DUMMY_SURFACE "SDL.internal.window.surface" 30 31 32bool SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) 33{ 34 SDL_Surface *surface; 35 const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888; 36 int w, h; 37 38 // Create a new framebuffer 39 SDL_GetWindowSizeInPixels(window, &w, &h); 40 surface = SDL_CreateSurface(w, h, surface_format); 41 if (!surface) { 42 return false; 43 } 44 45 // Save the info and return! 46 SDL_SetSurfaceProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE, surface); 47 *format = surface_format; 48 *pixels = surface->pixels; 49 *pitch = surface->pitch; 50 return true; 51} 52 53bool SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) 54{ 55 static int frame_number; 56 SDL_Surface *surface; 57 58 surface = (SDL_Surface *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE, NULL); 59 if (!surface) { 60 return SDL_SetError("Couldn't find dummy surface for window"); 61 } 62 63 // Send the data to the display 64 if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DUMMY_SAVE_FRAMES, false)) { 65 char file[128]; 66 (void)SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIu32 "-%8.8d.bmp", 67 SDL_GetWindowID(window), ++frame_number); 68 SDL_SaveBMP(surface, file); 69 } 70 return true; 71} 72 73void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) 74{ 75 SDL_ClearProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE); 76} 77 78#endif // SDL_VIDEO_DRIVER_DUMMY