Commit 052351db authored by Sam Lantinga's avatar Sam Lantinga

Added a way to get a framebuffer interface for a window, and also a way to...

Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
The software renderer has been re-routed to use the framebuffer interface, which makes it possible to have software rendering available even on simple ports.
parent 657d4fd1
......@@ -642,14 +642,6 @@
RelativePath="..\..\src\SDL.c"
>
</File>
<File
RelativePath="..\..\src\video\SDL_alphamult.c"
>
</File>
<File
RelativePath="..\..\src\video\SDL_alphamult.h"
>
</File>
<File
RelativePath="..\..\src\SDL_assert.c"
>
......@@ -687,19 +679,27 @@
>
</File>
<File
RelativePath="..\..\src\video\SDL_blendfillrect.c"
RelativePath="..\..\src\render\software\SDL_blendfillrect.c"
>
</File>
<File
RelativePath="..\..\src\render\software\SDL_blendfillrect.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_blendline.c"
RelativePath="..\..\src\render\software\SDL_blendline.c"
>
</File>
<File
RelativePath="..\..\src\video\SDL_blendpoint.c"
RelativePath="..\..\src\render\software\SDL_blendline.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_blendrect.c"
RelativePath="..\..\src\render\software\SDL_blendpoint.c"
>
</File>
<File
RelativePath="..\..\src\render\software\SDL_blendpoint.h"
>
</File>
<File
......@@ -794,20 +794,28 @@
RelativePath="..\..\src\audio\disk\SDL_diskaudio.h"
>
</File>
<File
RelativePath="..\..\src\render\software\SDL_draw.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_draw.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_drawline.c"
RelativePath="..\..\src\render\software\SDL_drawline.c"
>
</File>
<File
RelativePath="..\..\src\render\software\SDL_drawline.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_drawpoint.c"
RelativePath="..\..\src\render\software\SDL_drawpoint.c"
>
</File>
<File
RelativePath="..\..\src\video\SDL_drawrect.c"
RelativePath="..\..\src\render\software\SDL_drawpoint.h"
>
</File>
<File
......@@ -962,6 +970,14 @@
RelativePath="..\..\src\video\dummy\SDL_nullevents_c.h"
>
</File>
<File
RelativePath="..\..\src\video\dummy\SDL_nullframebuffer.c"
>
</File>
<File
RelativePath="..\..\src\video\dummy\SDL_nullframebuffer_c.h"
>
</File>
<File
RelativePath="..\..\src\video\dummy\SDL_nullvideo.c"
>
......@@ -1010,6 +1026,10 @@
RelativePath="..\..\src\render\software\SDL_renderer_sw.c"
>
</File>
<File
RelativePath="..\..\src\render\software\SDL_renderer_sw_c.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_RLEaccel.c"
>
......
......@@ -285,10 +285,17 @@ echo #define SDL_REVISION "hg-0:baadf00d" &gt;"$(ProjectDir)\..\..\include\SDL_r
<ClInclude Include="..\..\src\render\mmx.h" />
<ClInclude Include="..\..\src\render\SDL_sysrender.h" />
<ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
<ClInclude Include="..\..\src\video\SDL_alphamult.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
<ClInclude Include="..\..\src\audio\SDL_audiodev_c.h" />
<ClInclude Include="..\..\src\audio\SDL_audiomem.h" />
<ClInclude Include="..\..\src\render\software\SDL_blendfillrect.h" />
<ClInclude Include="..\..\src\render\software\SDL_blendline.h" />
<ClInclude Include="..\..\src\render\software\SDL_blendpoint.h" />
<ClInclude Include="..\..\src\render\software\SDL_draw.h" />
<ClInclude Include="..\..\src\render\software\SDL_drawline.h" />
<ClInclude Include="..\..\src\render\software\SDL_drawpoint.h" />
<ClInclude Include="..\..\src\render\software\SDL_renderer_sw_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
<ClInclude Include="..\..\src\video\SDL_blit.h" />
<ClInclude Include="..\..\src\video\SDL_blit_auto.h" />
<ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
......@@ -296,7 +303,6 @@ echo #define SDL_REVISION "hg-0:baadf00d" &gt;"$(ProjectDir)\..\..\include\SDL_r
<ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
<ClInclude Include="..\..\src\audio\windib\SDL_dibaudio.h" />
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
<ClInclude Include="..\..\src\video\SDL_draw.h" />
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
<ClInclude Include="..\..\src\audio\windx5\SDL_dx5audio.h" />
<ClInclude Include="..\..\src\SDL_error_c.h" />
......@@ -367,9 +373,13 @@ echo #define SDL_REVISION "hg-0:baadf00d" &gt;"$(ProjectDir)\..\..\include\SDL_r
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
<ClCompile Include="..\..\src\render\software\SDL_blendfillrect.c" />
<ClCompile Include="..\..\src\render\software\SDL_blendline.c" />
<ClCompile Include="..\..\src\render\software\SDL_blendpoint.c" />
<ClCompile Include="..\..\src\render\software\SDL_drawline.c" />
<ClCompile Include="..\..\src\render\software\SDL_drawpoint.c" />
<ClCompile Include="..\..\src\render\software\SDL_renderer_sw.c" />
<ClCompile Include="..\..\src\SDL.c" />
<ClCompile Include="..\..\src\video\SDL_alphamult.c" />
<ClCompile Include="..\..\src\SDL_assert.c" />
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
......@@ -377,10 +387,7 @@ echo #define SDL_REVISION "hg-0:baadf00d" &gt;"$(ProjectDir)\..\..\include\SDL_r
<ClCompile Include="..\..\src\audio\SDL_audiocvt.c" />
<ClCompile Include="..\..\src\audio\SDL_audiodev.c" />
<ClCompile Include="..\..\src\audio\SDL_audiotypecvt.c" />
<ClCompile Include="..\..\src\video\SDL_blendfillrect.c" />
<ClCompile Include="..\..\src\video\SDL_blendline.c" />
<ClCompile Include="..\..\src\video\SDL_blendpoint.c" />
<ClCompile Include="..\..\src\video\SDL_blendrect.c" />
<ClCompile Include="..\..\src\video\dummy\SDL_nullframebuffer.c" />
<ClCompile Include="..\..\src\video\SDL_blit.c" />
<ClCompile Include="..\..\src\video\SDL_blit_0.c" />
<ClCompile Include="..\..\src\video\SDL_blit_1.c" />
......@@ -396,9 +403,6 @@ echo #define SDL_REVISION "hg-0:baadf00d" &gt;"$(ProjectDir)\..\..\include\SDL_r
<ClCompile Include="..\..\src\video\SDL_shape.c" />
<ClCompile Include="..\..\src\audio\windib\SDL_dibaudio.c" />
<ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" />
<ClCompile Include="..\..\src\video\SDL_drawline.c" />
<ClCompile Include="..\..\src\video\SDL_drawpoint.c" />
<ClCompile Include="..\..\src\video\SDL_drawrect.c" />
<ClCompile Include="..\..\src\audio\dummy\SDL_dummyaudio.c" />
<ClCompile Include="..\..\src\audio\windx5\SDL_dx5audio.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_dxjoystick.c" />
......
This diff is collapsed.
......@@ -154,12 +154,25 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
*
* \return A valid rendering context or NULL if there was an error.
*
* \sa SDL_CreateSoftwareRenderer()
* \sa SDL_GetRendererInfo()
* \sa SDL_DestroyRenderer()
*/
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
int index, Uint32 flags);
/**
* \brief Create a 2D software rendering context for a surface.
*
* \param surface The surface where rendering is done.
*
* \return A valid rendering context or NULL if there was an error.
*
* \sa SDL_CreateRenderer()
* \sa SDL_DestroyRenderer()
*/
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
/**
* \brief Get information about a rendering context.
*/
......
......@@ -607,6 +607,40 @@ extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
int fullscreen);
/**
* \brief Get an SDL surface associated with the window.
*
* \return A surface in the optimal format for the window, or NULL on error.
*
* \note You may not combine this with 3D or the rendering API on this window.
*
* \sa SDL_UpdateWindowSurface()
* \sa SDL_UpdateWindowSurfaceRects()
*/
extern DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window * window);
/**
* \brief Copy the window surface to the screen.
*
* \return 0 on success, or -1 on error.
*
* \sa SDL_GetWindowSurface()
* \sa SDL_UpdateWindowSurfaceRects()
*/
extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
/**
* \brief Copy a number of rectangles on the window surface to the screen.
*
* \return 0 on success, or -1 on error.
*
* \sa SDL_GetWindowSurface()
* \sa SDL_UpdateWindowSurfaceRect()
*/
extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
int numrects,
SDL_Rect * rects);
/**
* \brief Set a window's input grab mode.
*
......
......@@ -106,6 +106,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
}
window->w = data1;
window->h = data2;
SDL_OnWindowResized(window);
break;
case SDL_WINDOWEVENT_MINIMIZED:
if (window->flags & SDL_WINDOW_MINIMIZED) {
......
......@@ -26,6 +26,7 @@
#include "SDL_render.h"
#include "SDL_sysrender.h"
#include "../video/SDL_pixels_c.h"
#include "software/SDL_renderer_sw_c.h"
#define CHECK_RENDERER_MAGIC(renderer, retval) \
......@@ -137,12 +138,19 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
if (renderer) {
renderer->magic = &renderer_magic;
renderer->window = window;
SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
}
return renderer;
}
SDL_Renderer *
SDL_CreateSoftwareRenderer(SDL_Surface * surface)
{
return SW_CreateRendererForSurface(surface);
}
int
SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
{
......
......@@ -327,7 +327,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->DestroyTexture = D3D_DestroyTexture;
renderer->DestroyRenderer = D3D_DestroyRenderer;
renderer->info = D3D_RenderDriver.info;
renderer->window = window;
renderer->driverdata = data;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
......
......@@ -209,7 +209,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->DestroyTexture = GL_DestroyTexture;
renderer->DestroyRenderer = GL_DestroyRenderer;
renderer->info = GL_RenderDriver.info;
renderer->window = window;
renderer->driverdata = data;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
......
......@@ -202,7 +202,6 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->DestroyTexture = GLES_DestroyTexture;
renderer->DestroyRenderer = GLES_DestroyRenderer;
renderer->info = GL_ES_RenderDriver.info;
renderer->window = window;
renderer->driverdata = data;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
......
......@@ -23,6 +23,7 @@
#include "SDL_draw.h"
#include "SDL_blendline.h"
#include "SDL_blendpoint.h"
static void
......
......@@ -23,6 +23,7 @@
#include "SDL_draw.h"
#include "SDL_drawline.h"
#include "SDL_drawpoint.h"
static void
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -80,6 +80,8 @@ struct SDL_Window
SDL_DisplayMode fullscreen_mode;
SDL_Surface *surface;
SDL_WindowShaper *shaper;
SDL_WindowUserData *data;
......@@ -190,7 +192,10 @@ struct SDL_VideoDevice
void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*SetWindowGrab) (_THIS, SDL_Window * window);
void (*DestroyWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
/* * * */
/*
* Shaped-window functions
......@@ -344,6 +349,7 @@ extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern void SDL_OnWindowShown(SDL_Window * window);
extern void SDL_OnWindowHidden(SDL_Window * window);
extern void SDL_OnWindowResized(SDL_Window * window);
extern void SDL_OnWindowMinimized(SDL_Window * window);
extern void SDL_OnWindowRestored(SDL_Window * window);
extern void SDL_OnWindowFocusGained(SDL_Window * window);
......
......@@ -95,6 +95,130 @@ static SDL_VideoDevice *_this = NULL;
/* Various local functions */
static void SDL_UpdateWindowGrab(SDL_Window * window);
/* Support for framebuffer emulation using an accelerated renderer */
#define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
typedef struct {
SDL_Renderer *renderer;
SDL_Texture *texture;
void *pixels;
int pitch;
} SDL_WindowTextureData;
static int
SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_WindowTextureData *data;
SDL_Renderer *renderer;
SDL_RendererInfo info;
Uint32 i;
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
if (!data) {
data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
if (!data) {
SDL_OutOfMemory();
return -1;
}
SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
}
renderer = data->renderer;
if (!renderer) {
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
return -1;
}
data->renderer = renderer;
}
/* Free any old texture and pixel data */
if (data->texture) {
SDL_DestroyTexture(data->texture);
data->texture = NULL;
}
if (data->pixels) {
SDL_free(data->pixels);
data->pixels = NULL;
}
if (SDL_GetRendererInfo(renderer, &info) < 0) {
return -1;
}
/* Find the first format without an alpha channel */
*format = info.texture_formats[0];
for (i = 0; i < info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
*format = info.texture_formats[i];
break;
}
}
data->texture = SDL_CreateTexture(renderer, *format,
SDL_TEXTUREACCESS_STREAMING,
window->w, window->h);
if (!data->texture) {
return -1;
}
/* Create framebuffer data */
data->pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
data->pixels = SDL_malloc(window->h * data->pitch);
if (!data->pixels) {
SDL_OutOfMemory();
return -1;
}
*pixels = data->pixels;
*pitch = data->pitch;
return 0;
}
static int
SDL_UpdateWindowTexture(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
{
SDL_WindowTextureData *data;
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
if (!data || !data->texture) {
SDL_SetError("No window texture data");
return -1;
}
if (SDL_UpdateTexture(data->texture, NULL, data->pixels, data->pitch) < 0) {
return -1;
}
if (SDL_RenderCopy(data->renderer, data->texture, NULL, NULL) < 0) {
return -1;
}
SDL_RenderPresent(data->renderer);
return 0;
}
static void
SDL_DestroyWindowTexture(_THIS, SDL_Window * window)
{
SDL_WindowTextureData *data;
data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
if (!data) {
return;
}
if (data->texture) {
SDL_DestroyTexture(data->texture);
}
if (data->renderer) {
SDL_DestroyRenderer(data->renderer);
}
if (data->pixels) {
SDL_free(data->pixels);
}
SDL_free(data);
}
static int
cmpmodes(const void *A, const void *B)
{
......@@ -228,6 +352,7 @@ SDL_VideoInit(const char *driver_name)
SDL_VideoQuit();
return -1;
}
/* Make sure some displays were added */
if (_this->num_displays == 0) {
SDL_SetError("The video driver did not add any displays");
......@@ -235,6 +360,13 @@ SDL_VideoInit(const char *driver_name)
return (-1);
}
/* Add the renderer framebuffer emulation if needed */
if (!_this->CreateWindowFramebuffer) {
_this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
_this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
_this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
}
/* We're ready to go! */
return 0;
}
......@@ -1216,6 +1348,69 @@ SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen)
return 0;
}
static SDL_Surface *
SDL_CreateWindowFramebuffer(SDL_Window * window)
{
Uint32 format;
void *pixels;
int pitch;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!_this->CreateWindowFramebuffer || !_this->UpdateWindowFramebuffer) {
return NULL;
}
if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) {
return NULL;
}
if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return NULL;
}
return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
}
SDL_Surface *
SDL_GetWindowSurface(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, NULL);
if (!window->surface) {
window->surface = SDL_CreateWindowFramebuffer(window);
}
return window->surface;
}
int
SDL_UpdateWindowSurface(SDL_Window * window)
{
SDL_Rect full_rect;
CHECK_WINDOW_MAGIC(window, -1);
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = window->w;
full_rect.h = window->h;
return SDL_UpdateWindowSurfaceRects(window, 1, &full_rect);
}
int
SDL_UpdateWindowSurfaceRects(SDL_Window * window,
int numrects, SDL_Rect * rects)
{
CHECK_WINDOW_MAGIC(window, -1);
if (!window->surface) {
SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
return -1;
}
return _this->UpdateWindowFramebuffer(_this, window, numrects, rects);
}
void
SDL_SetWindowGrab(SDL_Window * window, int mode)
{
......@@ -1261,6 +1456,15 @@ SDL_OnWindowHidden(SDL_Window * window)
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}
void
SDL_OnWindowResized(SDL_Window * window)
{
if (window->surface) {
SDL_FreeSurface(window->surface);
window->surface = NULL;
}
}
void
SDL_OnWindowMinimized(SDL_Window * window)
{
......@@ -1336,6 +1540,9 @@ SDL_DestroyWindow(SDL_Window * window)
/* Restore video mode, etc. */
SDL_UpdateFullscreenMode(window, SDL_FALSE);
if (_this->DestroyWindowFramebuffer) {
_this->DestroyWindowFramebuffer(_this, window);
}
if (_this->DestroyWindow) {
_this->DestroyWindow(_this, window);
}
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "../SDL_sysvideo.h"
#define DUMMY_SURFACE "_SDL_DummySurface"
int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
int w, h;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
/* Free the old framebuffer surface */
surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
if (surface) {
SDL_FreeSurface(surface);
}
/* Create a new one */
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
SDL_GetWindowSize(window, &w, &h);
surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
if (!surface) {
return -1;
}
/* Save the info and return! */
SDL_SetWindowData(window, DUMMY_SURFACE, surface);
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
return 0;
}
int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
{
static int frame_number;
SDL_Surface *surface;
surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
if (!surface) {
SDL_SetError("Couldn't find dummy surface for window");
return -1;
}
/* Send the data to the display */
if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}
return 0;
}
void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
{
SDL_Surface *surface;
surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
if (surface) {
SDL_FreeSurface(surface);
}
}
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -44,6 +44,7 @@
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
#include "SDL_nullframebuffer_c.h"
#define DUMMYVID_DRIVER_NAME "dummy"
......@@ -91,6 +92,9 @@ DUMMY_CreateDevice(int devindex)
device->VideoQuit = DUMMY_VideoQuit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->PumpEvents = DUMMY_PumpEvents;
device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
device->free = DUMMY_DeleteDevice;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment