changeset 3451:a65f7b3a2524

Implemented SDL_RenderReadPixels()/SDL_RenderWritePixels() for the dummy renderer. This is helpful to validate the automated test suite, since this renderer is super simple and should always pass tests.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 18 Nov 2009 09:20:01 +0000
parents 173199bce642
children 1f1a41879fe4
files src/video/dummy/SDL_nullrender.c
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/dummy/SDL_nullrender.c	Wed Nov 18 09:17:29 2009 +0000
+++ b/src/video/dummy/SDL_nullrender.c	Wed Nov 18 09:20:01 2009 +0000
@@ -40,6 +40,14 @@
                                 SDL_Texture * texture,
                                 const SDL_Rect * srcrect,
                                 const SDL_Rect * dstrect);
+static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
+                                      const SDL_Rect * rect,
+                                      Uint32 format,
+                                      void * pixels, int pitch);
+static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
+                                       const SDL_Rect * rect,
+                                       Uint32 format,
+                                       const void * pixels, int pitch);
 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
 
@@ -95,6 +103,8 @@
     renderer->RenderLine = SDL_DUMMY_RenderLine;
     renderer->RenderFill = SDL_DUMMY_RenderFill;
     renderer->RenderCopy = SDL_DUMMY_RenderCopy;
+    renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
+    renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
     renderer->RenderPresent = SDL_DUMMY_RenderPresent;
     renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
     renderer->info.name = SDL_DUMMY_RenderDriver.info.name;
@@ -225,6 +235,46 @@
     }
 }
 
+static int
+SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+                           Uint32 format, void * pixels, int pitch)
+{
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_Surface *screen = data->screens[data->current_screen];
+    Uint32 screen_format = display->current_mode.format;
+    Uint8 *screen_pixels = (Uint8 *) screen->pixels +
+                            rect->y * screen->pitch +
+                            rect->x * screen->format->BytesPerPixel;
+    int screen_pitch = screen->pitch;
+
+    return SDL_ConvertPixels(rect->w, rect->h,
+                             screen_format, screen_pixels, screen_pitch,
+                             format, pixels, pitch);
+}
+
+static int
+SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+                            Uint32 format, const void * pixels, int pitch)
+{
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_Surface *screen = data->screens[data->current_screen];
+    Uint32 screen_format = display->current_mode.format;
+    Uint8 *screen_pixels = (Uint8 *) screen->pixels +
+                            rect->y * screen->pitch +
+                            rect->x * screen->format->BytesPerPixel;
+    int screen_pitch = screen->pitch;
+
+    return SDL_ConvertPixels(rect->w, rect->h,
+                             format, pixels, pitch,
+                             screen_format, screen_pixels, screen_pitch);
+}
+
 static void
 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
 {