Fixed bug 1751 - Direcftb renderer viewport behaviour differs from API description.
authorSam Lantinga <slouken@libsdl.org>
Sun, 10 Mar 2013 21:10:10 -0700
changeset 6995 7c87aa0a189f
parent 6994 06f368666c6f
child 6996 bc0fd5bced25
Fixed bug 1751 - Direcftb renderer viewport behaviour differs from API description. tomaszewski.p According to API description: SDL_RenderSetViewport - Use this function to set the drawing area for rendering on the current target. DirectFB renderer in DirectFB_UpdateViewport function just sets clip on surface, instead of moving drawing area. Attached patch uses set clip rectangle to move {x,y} coordinates during draw and blit operations to be compatible with API description.
src/video/directfb/SDL_DirectFB_render.c
--- a/src/video/directfb/SDL_DirectFB_render.c	Sun Mar 10 16:28:20 2013 -0700
+++ b/src/video/directfb/SDL_DirectFB_render.c	Sun Mar 10 21:10:10 2013 -0700
@@ -953,13 +953,18 @@
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     IDirectFBSurface *destsurf = data->target;
+    DFBRegion clip_region;
     int i;
 
     DirectFB_ActivateRenderer(renderer);
 
     PrepareDraw(renderer);
-    for (i=0; i < count; i++)
-        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y));
+    destsurf->GetClip(destsurf, &clip_region);
+    for (i=0; i < count; i++) {
+        int x = points[i].x + clip_region.x1;
+        int y = points[i].y + clip_region.y1;
+        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y));
+    }
     return 0;
   error:
     return -1;
@@ -970,6 +975,7 @@
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     IDirectFBSurface *destsurf = data->target;
+    DFBRegion clip_region;
     int i;
 
     DirectFB_ActivateRenderer(renderer);
@@ -980,8 +986,14 @@
     SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS));
 #endif
 
-    for (i=0; i < count - 1; i++)
-        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y));
+    destsurf->GetClip(destsurf, &clip_region);
+    for (i=0; i < count - 1; i++) {
+        int x1 = points[i].x + clip_region.x1;
+        int y1 = points[i].y + clip_region.y1;
+        int x2 = points[i + 1].x + clip_region.x1;
+        int y2 = points[i + 1].y + clip_region.y1;
+        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2));
+    }
 
     return 0;
   error:
@@ -993,15 +1005,21 @@
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     IDirectFBSurface *destsurf = data->target;
+    DFBRegion clip_region;
     int i;
 
     DirectFB_ActivateRenderer(renderer);
 
     PrepareDraw(renderer);
 
-    for (i=0; i<count; i++)
-        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
-                rects[i]->w, rects[i]->h));
+    destsurf->GetClip(destsurf, &clip_region);
+    for (i=0; i<count; i++) {
+        SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h};
+        dst.x += clip_region.x1;
+        dst.y += clip_region.y1;
+        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y,
+                dst.w, dst.h));
+    }
 
     return 0;
   error:
@@ -1013,15 +1031,21 @@
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     IDirectFBSurface *destsurf = data->target;
+    DFBRegion clip_region;
     int i;
 
     DirectFB_ActivateRenderer(renderer);
 
     PrepareDraw(renderer);
 
-    for (i=0; i<count; i++)
-        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i].x, rects[i].y,
-                rects[i].w, rects[i].h));
+    destsurf->GetClip(destsurf, &clip_region);
+    for (i=0; i<count; i++) {
+        SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};        
+        dst.x += clip_region.x1;
+        dst.y += clip_region.y1;
+        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y,
+                dst.w, dst.h));
+    }
 
     return 0;
   error:
@@ -1037,6 +1061,7 @@
     DirectFB_TextureData *texturedata =
         (DirectFB_TextureData *) texture->driverdata;
     Uint8 alpha, r, g, b;
+    DFBRegion clip_region;
     DFBRectangle sr, dr;
 
     DirectFB_ActivateRenderer(renderer);
@@ -1044,6 +1069,10 @@
     SDLtoDFBRect(srcrect, &sr);
     SDLtoDFBRect_Float(dstrect, &dr);
 
+    destsurf->GetClip(destsurf, &clip_region);
+    dr.x += clip_region.x1;
+    dr.y += clip_region.y1;
+
     if (texturedata->display) {
         int px, py;
         SDL_Window *window = renderer->window;
@@ -1098,9 +1127,6 @@
             DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
         }
 
-        SDLtoDFBRect(srcrect, &sr);
-        SDLtoDFBRect_Float(dstrect, &dr);
-
         alpha = r = g = b = 0xff;
         if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){
             alpha = texture->a;