Fixed bug 1751 - Direcftb renderer viewport behaviour differs from API description.
authorSam Lantinga
Sun, 10 Mar 2013 21:10:10 -0700
changeset 69957c87aa0a189f
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
     1.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sun Mar 10 16:28:20 2013 -0700
     1.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sun Mar 10 21:10:10 2013 -0700
     1.3 @@ -953,13 +953,18 @@
     1.4  {
     1.5      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     1.6      IDirectFBSurface *destsurf = data->target;
     1.7 +    DFBRegion clip_region;
     1.8      int i;
     1.9  
    1.10      DirectFB_ActivateRenderer(renderer);
    1.11  
    1.12      PrepareDraw(renderer);
    1.13 -    for (i=0; i < count; i++)
    1.14 -        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y));
    1.15 +    destsurf->GetClip(destsurf, &clip_region);
    1.16 +    for (i=0; i < count; i++) {
    1.17 +        int x = points[i].x + clip_region.x1;
    1.18 +        int y = points[i].y + clip_region.y1;
    1.19 +        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y));
    1.20 +    }
    1.21      return 0;
    1.22    error:
    1.23      return -1;
    1.24 @@ -970,6 +975,7 @@
    1.25  {
    1.26      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
    1.27      IDirectFBSurface *destsurf = data->target;
    1.28 +    DFBRegion clip_region;
    1.29      int i;
    1.30  
    1.31      DirectFB_ActivateRenderer(renderer);
    1.32 @@ -980,8 +986,14 @@
    1.33      SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS));
    1.34  #endif
    1.35  
    1.36 -    for (i=0; i < count - 1; i++)
    1.37 -        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y));
    1.38 +    destsurf->GetClip(destsurf, &clip_region);
    1.39 +    for (i=0; i < count - 1; i++) {
    1.40 +        int x1 = points[i].x + clip_region.x1;
    1.41 +        int y1 = points[i].y + clip_region.y1;
    1.42 +        int x2 = points[i + 1].x + clip_region.x1;
    1.43 +        int y2 = points[i + 1].y + clip_region.y1;
    1.44 +        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2));
    1.45 +    }
    1.46  
    1.47      return 0;
    1.48    error:
    1.49 @@ -993,15 +1005,21 @@
    1.50  {
    1.51      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
    1.52      IDirectFBSurface *destsurf = data->target;
    1.53 +    DFBRegion clip_region;
    1.54      int i;
    1.55  
    1.56      DirectFB_ActivateRenderer(renderer);
    1.57  
    1.58      PrepareDraw(renderer);
    1.59  
    1.60 -    for (i=0; i<count; i++)
    1.61 -        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
    1.62 -                rects[i]->w, rects[i]->h));
    1.63 +    destsurf->GetClip(destsurf, &clip_region);
    1.64 +    for (i=0; i<count; i++) {
    1.65 +        SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h};
    1.66 +        dst.x += clip_region.x1;
    1.67 +        dst.y += clip_region.y1;
    1.68 +        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y,
    1.69 +                dst.w, dst.h));
    1.70 +    }
    1.71  
    1.72      return 0;
    1.73    error:
    1.74 @@ -1013,15 +1031,21 @@
    1.75  {
    1.76      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
    1.77      IDirectFBSurface *destsurf = data->target;
    1.78 +    DFBRegion clip_region;
    1.79      int i;
    1.80  
    1.81      DirectFB_ActivateRenderer(renderer);
    1.82  
    1.83      PrepareDraw(renderer);
    1.84  
    1.85 -    for (i=0; i<count; i++)
    1.86 -        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i].x, rects[i].y,
    1.87 -                rects[i].w, rects[i].h));
    1.88 +    destsurf->GetClip(destsurf, &clip_region);
    1.89 +    for (i=0; i<count; i++) {
    1.90 +        SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};        
    1.91 +        dst.x += clip_region.x1;
    1.92 +        dst.y += clip_region.y1;
    1.93 +        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y,
    1.94 +                dst.w, dst.h));
    1.95 +    }
    1.96  
    1.97      return 0;
    1.98    error:
    1.99 @@ -1037,6 +1061,7 @@
   1.100      DirectFB_TextureData *texturedata =
   1.101          (DirectFB_TextureData *) texture->driverdata;
   1.102      Uint8 alpha, r, g, b;
   1.103 +    DFBRegion clip_region;
   1.104      DFBRectangle sr, dr;
   1.105  
   1.106      DirectFB_ActivateRenderer(renderer);
   1.107 @@ -1044,6 +1069,10 @@
   1.108      SDLtoDFBRect(srcrect, &sr);
   1.109      SDLtoDFBRect_Float(dstrect, &dr);
   1.110  
   1.111 +    destsurf->GetClip(destsurf, &clip_region);
   1.112 +    dr.x += clip_region.x1;
   1.113 +    dr.y += clip_region.y1;
   1.114 +
   1.115      if (texturedata->display) {
   1.116          int px, py;
   1.117          SDL_Window *window = renderer->window;
   1.118 @@ -1098,9 +1127,6 @@
   1.119              DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
   1.120          }
   1.121  
   1.122 -        SDLtoDFBRect(srcrect, &sr);
   1.123 -        SDLtoDFBRect_Float(dstrect, &dr);
   1.124 -
   1.125          alpha = r = g = b = 0xff;
   1.126          if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){
   1.127              alpha = texture->a;