directfb: Updated render backend to new internal API.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 02 Dec 2018 02:33:06 -0500
changeset 12442695bf801d4ba
parent 12441 2e2cff8a14b6
child 12443 0e07e768840f
directfb: Updated render backend to new internal API.

Totally untested, beyond it now compiles again. Probably needs some fixes.

Fixes Bugzilla #4405.
src/video/directfb/SDL_DirectFB_render.c
     1.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sat Dec 01 16:31:56 2018 -0500
     1.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sun Dec 02 02:33:06 2018 -0500
     1.3 @@ -50,96 +50,8 @@
     1.4  
     1.5  
     1.6  #define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
     1.7 -
     1.8 -
     1.9 -/* DirectFB renderer implementation */
    1.10 -
    1.11 -static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
    1.12 -                                             Uint32 flags);
    1.13 -static void DirectFB_ActivateRenderer(SDL_Renderer * renderer);
    1.14 -static int DirectFB_CreateTexture(SDL_Renderer * renderer,
    1.15 -                                  SDL_Texture * texture);
    1.16 -static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
    1.17 -                                       SDL_Texture * texture,
    1.18 -                                       void **pixels, int *pitch);
    1.19 -static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
    1.20 -                                      SDL_Texture * texture,
    1.21 -                                      const SDL_Color * colors,
    1.22 -                                      int firstcolor, int ncolors);
    1.23 -static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
    1.24 -                                      SDL_Texture * texture,
    1.25 -                                      SDL_Color * colors,
    1.26 -                                      int firstcolor, int ncolors);
    1.27 -static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
    1.28 -                                       SDL_Texture * texture);
    1.29 -static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
    1.30 -                                       SDL_Texture * texture);
    1.31 -static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
    1.32 -                                        SDL_Texture * texture);
    1.33 -static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
    1.34 -                                        SDL_Texture * texture);
    1.35 -static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
    1.36 -                                  SDL_Texture * texture,
    1.37 -                                  const SDL_Rect * rect,
    1.38 -                                  const void *pixels, int pitch);
    1.39 -static int DirectFB_LockTexture(SDL_Renderer * renderer,
    1.40 -                                SDL_Texture * texture,
    1.41 -                                const SDL_Rect * rect,
    1.42 -                                void **pixels, int *pitch);
    1.43 -static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
    1.44 -                                   SDL_Texture * texture);
    1.45 -static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
    1.46 -                                  SDL_Texture * texture, int numrects,
    1.47 -                                  const SDL_Rect * rects);
    1.48 -static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
    1.49 -static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
    1.50 -                                const SDL_FPoint * points, int count);
    1.51 -static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
    1.52 -                               const SDL_FPoint * points, int count);
    1.53 -static int DirectFB_RenderDrawRects(SDL_Renderer * renderer,
    1.54 -        const SDL_Rect ** rects, int count);
    1.55 -static int DirectFB_RenderFillRects(SDL_Renderer * renderer,
    1.56 -        const SDL_FRect * rects, int count);
    1.57 -static int DirectFB_RenderCopy(SDL_Renderer * renderer,
    1.58 -                               SDL_Texture * texture,
    1.59 -                               const SDL_Rect * srcrect,
    1.60 -                               const SDL_FRect * dstrect);
    1.61 -static void DirectFB_RenderPresent(SDL_Renderer * renderer);
    1.62 -static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
    1.63 -                                    SDL_Texture * texture);
    1.64 -static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
    1.65 -static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    1.66 -                     Uint32 format, void * pixels, int pitch);
    1.67 -static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    1.68 -                      Uint32 format, const void * pixels, int pitch);
    1.69 -static int DirectFB_UpdateViewport(SDL_Renderer * renderer);
    1.70 -static int DirectFB_UpdateClipRect(SDL_Renderer * renderer);
    1.71 -static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
    1.72 -
    1.73 -static int PrepareDraw(SDL_Renderer * renderer);
    1.74 -
    1.75 -
    1.76  #define SDL_DFB_WINDOWSURFACE(win)  IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface;
    1.77  
    1.78 -SDL_RenderDriver DirectFB_RenderDriver = {
    1.79 -    DirectFB_CreateRenderer,
    1.80 -    {
    1.81 -     "directfb",
    1.82 -     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
    1.83 -     /* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
    1.84 -      SDL_TEXTUREMODULATE_ALPHA),
    1.85 -      (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
    1.86 -      SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
    1.87 -     (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST |
    1.88 -      SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST), */
    1.89 -     0,
    1.90 -     {
    1.91 -             /* formats filled in later */
    1.92 -     },
    1.93 -     0,
    1.94 -     0}
    1.95 -};
    1.96 -
    1.97  typedef struct
    1.98  {
    1.99      SDL_Window *window;
   1.100 @@ -292,34 +204,36 @@
   1.101  }
   1.102  
   1.103  static int
   1.104 -DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
   1.105 +PrepareDraw(SDL_Renderer * renderer, const SDL_RenderCommand *cmd)
   1.106  {
   1.107 -#if USE_DISPLAY_PALETTE
   1.108 -    DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
   1.109 -    SDL_DFB_WINDOWSURFACE(data->window);
   1.110 -    IDirectFBPalette *surfpal;
   1.111 +    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.112 +    IDirectFBSurface *destsurf = data->target;
   1.113 +    Uint8 r = cmd->data.draw.r;
   1.114 +    Uint8 g = cmd->data.draw.g;
   1.115 +    Uint8 b = cmd->data.draw.b;
   1.116 +    Uint8 a = cmd->data.draw.a;
   1.117  
   1.118 -    int i;
   1.119 -    int ncolors;
   1.120 -    DFBColor entries[256];
   1.121 +    SetBlendMode(data, cmd->data.draw.blend, NULL);
   1.122 +    SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags));
   1.123  
   1.124 -    SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal));
   1.125 +    switch (renderer->blendMode) {
   1.126 +    case SDL_BLENDMODE_NONE:
   1.127 +    /* case SDL_BLENDMODE_MASK: */
   1.128 +    case SDL_BLENDMODE_BLEND:
   1.129 +        break;
   1.130 +    case SDL_BLENDMODE_ADD:
   1.131 +    case SDL_BLENDMODE_MOD:
   1.132 +        r = ((int) r * (int) a) / 255;
   1.133 +        g = ((int) g * (int) a) / 255;
   1.134 +        b = ((int) b * (int) a) / 255;
   1.135 +        a = 255;
   1.136 +        break;
   1.137 +    case SDL_BLENDMODE_INVALID: break;
   1.138 +    }
   1.139  
   1.140 -    /* FIXME: number of colors */
   1.141 -    ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
   1.142 -
   1.143 -    for (i = 0; i < ncolors; ++i) {
   1.144 -        entries[i].r = palette->colors[i].r;
   1.145 -        entries[i].g = palette->colors[i].g;
   1.146 -        entries[i].b = palette->colors[i].b;
   1.147 -        entries[i].a = palette->colors[i].a;
   1.148 -    }
   1.149 -    SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
   1.150 +    SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, r, g, b, a));
   1.151      return 0;
   1.152    error:
   1.153 -#else
   1.154 -    SDL_Unsupported();
   1.155 -#endif
   1.156      return -1;
   1.157  }
   1.158  
   1.159 @@ -336,133 +250,16 @@
   1.160     }
   1.161  }
   1.162  
   1.163 -static int
   1.164 -DirectFB_RenderClear(SDL_Renderer * renderer)
   1.165 -{
   1.166 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.167 -    IDirectFBSurface *destsurf = data->target;
   1.168 -
   1.169 -    DirectFB_ActivateRenderer(renderer);
   1.170 -
   1.171 -    PrepareDraw(renderer);
   1.172 -
   1.173 -    destsurf->Clear(destsurf, renderer->r, renderer->g, renderer->b, renderer->a);
   1.174 -
   1.175 -    return 0;
   1.176 -}
   1.177 -
   1.178 -SDL_Renderer *
   1.179 -DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
   1.180 -{
   1.181 -    IDirectFBSurface *winsurf = get_dfb_surface(window);
   1.182 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
   1.183 -    SDL_Renderer *renderer = NULL;
   1.184 -    DirectFB_RenderData *data = NULL;
   1.185 -    DFBSurfaceCapabilities scaps;
   1.186 -
   1.187 -    if (!winsurf) {
   1.188 -        return NULL;
   1.189 -    }
   1.190 -
   1.191 -    SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer));
   1.192 -    SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
   1.193 -
   1.194 -    renderer->WindowEvent = DirectFB_WindowEvent;
   1.195 -    renderer->CreateTexture = DirectFB_CreateTexture;
   1.196 -    renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
   1.197 -    renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
   1.198 -    renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
   1.199 -    renderer->UpdateTexture = DirectFB_UpdateTexture;
   1.200 -    renderer->LockTexture = DirectFB_LockTexture;
   1.201 -    renderer->RenderClear = DirectFB_RenderClear;
   1.202 -    renderer->UnlockTexture = DirectFB_UnlockTexture;
   1.203 -    renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
   1.204 -    renderer->RenderDrawLines = DirectFB_RenderDrawLines;
   1.205 -    /* SetDrawColor - no needed */
   1.206 -    renderer->RenderFillRects = DirectFB_RenderFillRects;
   1.207 -
   1.208 -    renderer->RenderCopy = DirectFB_RenderCopy;
   1.209 -    renderer->RenderPresent = DirectFB_RenderPresent;
   1.210 -
   1.211 -    /* FIXME: Yet to be tested */
   1.212 -    renderer->RenderReadPixels = DirectFB_RenderReadPixels;
   1.213 -    /* renderer->RenderWritePixels = DirectFB_RenderWritePixels; */
   1.214 -
   1.215 -    renderer->DestroyTexture = DirectFB_DestroyTexture;
   1.216 -    renderer->DestroyRenderer = DirectFB_DestroyRenderer;
   1.217 -    renderer->UpdateViewport = DirectFB_UpdateViewport;
   1.218 -    renderer->UpdateClipRect = DirectFB_UpdateClipRect;
   1.219 -    renderer->SetRenderTarget = DirectFB_SetRenderTarget;
   1.220 -
   1.221 -#if 0
   1.222 -    renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
   1.223 -    renderer->SetTexturePalette = DirectFB_SetTexturePalette;
   1.224 -    renderer->GetTexturePalette = DirectFB_GetTexturePalette;
   1.225 -    renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
   1.226 -    renderer->DirtyTexture = DirectFB_DirtyTexture;
   1.227 -    renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
   1.228 -    renderer->RenderDrawRects = DirectFB_RenderDrawRects;
   1.229 -#endif
   1.230 -
   1.231 -    renderer->info = DirectFB_RenderDriver.info;
   1.232 -    renderer->window = window;      /* SDL window */
   1.233 -    renderer->driverdata = data;
   1.234 -
   1.235 -    renderer->info.flags =
   1.236 -        SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
   1.237 -
   1.238 -    data->window = window;
   1.239 -    data->target = winsurf;
   1.240 -
   1.241 -    data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
   1.242 -
   1.243 -    if (flags & SDL_RENDERER_PRESENTVSYNC) {
   1.244 -        data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC;
   1.245 -        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   1.246 -    } else
   1.247 -        data->flipflags |= DSFLIP_ONSYNC;
   1.248 -
   1.249 -    SDL_DFB_CHECKERR(winsurf->GetCapabilities(winsurf, &scaps));
   1.250 -
   1.251 -#if 0
   1.252 -    if (scaps & DSCAPS_DOUBLE)
   1.253 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   1.254 -    else if (scaps & DSCAPS_TRIPLE)
   1.255 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
   1.256 -    else
   1.257 -        renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   1.258 -#endif
   1.259 -
   1.260 -    DirectFB_SetSupportedPixelFormats(&renderer->info);
   1.261 -
   1.262 -#if 0
   1.263 -    /* Set up a palette watch on the display palette */
   1.264 -    if (display-> palette) {
   1.265 -        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
   1.266 -    }
   1.267 -#endif
   1.268 -
   1.269 -    return renderer;
   1.270 -
   1.271 -  error:
   1.272 -    SDL_DFB_FREE(renderer);
   1.273 -    SDL_DFB_FREE(data);
   1.274 -    return NULL;
   1.275 -}
   1.276 -
   1.277  static void
   1.278  DirectFB_ActivateRenderer(SDL_Renderer * renderer)
   1.279  {
   1.280      SDL_DFB_RENDERERDATA(renderer);
   1.281 -    SDL_Window *window = renderer->window;
   1.282 -    SDL_DFB_WINDOWDATA(window);
   1.283  
   1.284      if (renddata->size_changed /* || windata->wm_needs_redraw */) {
   1.285          renddata->size_changed = SDL_FALSE;
   1.286      }
   1.287  }
   1.288  
   1.289 -
   1.290  static int
   1.291  DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
   1.292  {
   1.293 @@ -614,127 +411,6 @@
   1.294      return -1;
   1.295  }
   1.296  
   1.297 -static int
   1.298 -DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
   1.299 -                            SDL_Texture * texture, void **pixels, int *pitch)
   1.300 -{
   1.301 -    DirectFB_TextureData *texturedata =
   1.302 -        (DirectFB_TextureData *) texture->driverdata;
   1.303 -
   1.304 -    if (texturedata->display) {
   1.305 -        return -1;
   1.306 -    } else {
   1.307 -        *pixels = texturedata->pixels;
   1.308 -        *pitch = texturedata->pitch;
   1.309 -    }
   1.310 -    return 0;
   1.311 -}
   1.312 -
   1.313 -static int
   1.314 -DirectFB_SetTexturePalette(SDL_Renderer * renderer,
   1.315 -                           SDL_Texture * texture,
   1.316 -                           const SDL_Color * colors, int firstcolor,
   1.317 -                           int ncolors)
   1.318 -{
   1.319 -    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   1.320 -    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   1.321 -        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   1.322 -        DFBColor entries[256];
   1.323 -        int i;
   1.324 -
   1.325 -        if (ncolors > 256)
   1.326 -            ncolors = 256;
   1.327 -
   1.328 -        for (i = 0; i < ncolors; ++i) {
   1.329 -            entries[i].r = colors[i].r;
   1.330 -            entries[i].g = colors[i].g;
   1.331 -            entries[i].b = colors[i].b;
   1.332 -            entries[i].a = 0xff;
   1.333 -        }
   1.334 -        SDL_DFB_CHECKERR(data->
   1.335 -                         palette->SetEntries(data->palette, entries, ncolors, firstcolor));
   1.336 -        return 0;
   1.337 -    } else {
   1.338 -        return SDL_SetError("YUV textures don't have a palette");
   1.339 -    }
   1.340 -  error:
   1.341 -    return -1;
   1.342 -}
   1.343 -
   1.344 -static int
   1.345 -DirectFB_GetTexturePalette(SDL_Renderer * renderer,
   1.346 -                           SDL_Texture * texture, SDL_Color * colors,
   1.347 -                           int firstcolor, int ncolors)
   1.348 -{
   1.349 -    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
   1.350 -
   1.351 -    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   1.352 -        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   1.353 -        DFBColor entries[256];
   1.354 -        int i;
   1.355 -
   1.356 -        SDL_DFB_CHECKERR(data->
   1.357 -                         palette->GetEntries(data->palette, entries, ncolors,
   1.358 -                                             firstcolor));
   1.359 -
   1.360 -        for (i = 0; i < ncolors; ++i) {
   1.361 -            colors[i].r = entries[i].r;
   1.362 -            colors[i].g = entries[i].g;
   1.363 -            colors[i].b = entries[i].b;
   1.364 -            colors[i].a = SDL_ALPHA_OPAQUE;
   1.365 -        }
   1.366 -        return 0;
   1.367 -    } else {
   1.368 -        return SDL_SetError("YUV textures don't have a palette");
   1.369 -    }
   1.370 -  error:
   1.371 -    return -1;
   1.372 -}
   1.373 -
   1.374 -static int
   1.375 -DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   1.376 -{
   1.377 -    return 0;
   1.378 -}
   1.379 -
   1.380 -static int
   1.381 -DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   1.382 -{
   1.383 -    return 0;
   1.384 -}
   1.385 -
   1.386 -static int
   1.387 -DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   1.388 -{
   1.389 -    switch (texture->blendMode) {
   1.390 -    case SDL_BLENDMODE_NONE:
   1.391 -    /* case SDL_BLENDMODE_MASK: */
   1.392 -    case SDL_BLENDMODE_BLEND:
   1.393 -    case SDL_BLENDMODE_ADD:
   1.394 -    case SDL_BLENDMODE_MOD:
   1.395 -        return 0;
   1.396 -    default:
   1.397 -        texture->blendMode = SDL_BLENDMODE_NONE;
   1.398 -        return SDL_Unsupported();
   1.399 -    }
   1.400 -}
   1.401 -
   1.402 -static int
   1.403 -DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
   1.404 -{
   1.405 -    switch (renderer->blendMode) {
   1.406 -    case SDL_BLENDMODE_NONE:
   1.407 -    /* case SDL_BLENDMODE_MASK: */
   1.408 -    case SDL_BLENDMODE_BLEND:
   1.409 -    case SDL_BLENDMODE_ADD:
   1.410 -    case SDL_BLENDMODE_MOD:
   1.411 -        return 0;
   1.412 -    default:
   1.413 -        renderer->blendMode = SDL_BLENDMODE_NONE;
   1.414 -        return SDL_Unsupported();
   1.415 -    }
   1.416 -}
   1.417 -
   1.418  #if 0
   1.419  static int
   1.420  DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   1.421 @@ -906,262 +582,238 @@
   1.422  
   1.423  
   1.424  static int
   1.425 -PrepareDraw(SDL_Renderer * renderer)
   1.426 +DirectFB_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
   1.427  {
   1.428 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.429 -    IDirectFBSurface *destsurf = data->target;
   1.430 +    return 0;  /* nothing to do in this backend. */
   1.431 +}
   1.432  
   1.433 -    Uint8 r, g, b, a;
   1.434 +static int
   1.435 +DirectFB_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
   1.436 +{
   1.437 +    const size_t len = count * sizeof (SDL_FPoint);
   1.438 +    SDL_FPoint *verts = (SDL_FPoint *) SDL_AllocateRenderVertices(renderer, len, 0, &cmd->data.draw.first);
   1.439  
   1.440 -    r = renderer->r;
   1.441 -    g = renderer->g;
   1.442 -    b = renderer->b;
   1.443 -    a = renderer->a;
   1.444 -
   1.445 -    SetBlendMode(data, renderer->blendMode, NULL);
   1.446 -    SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags));
   1.447 -
   1.448 -    switch (renderer->blendMode) {
   1.449 -    case SDL_BLENDMODE_NONE:
   1.450 -    /* case SDL_BLENDMODE_MASK: */
   1.451 -    case SDL_BLENDMODE_BLEND:
   1.452 -        break;
   1.453 -    case SDL_BLENDMODE_ADD:
   1.454 -    case SDL_BLENDMODE_MOD:
   1.455 -        r = ((int) r * (int) a) / 255;
   1.456 -        g = ((int) g * (int) a) / 255;
   1.457 -        b = ((int) b * (int) a) / 255;
   1.458 -        a = 255;
   1.459 -        break;
   1.460 +    if (!verts) {
   1.461 +        return -1;
   1.462      }
   1.463  
   1.464 -    SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, r, g, b, a));
   1.465 +    cmd->data.draw.count = count;
   1.466 +    SDL_memcpy(verts, points, len);
   1.467      return 0;
   1.468 -  error:
   1.469 -    return -1;
   1.470  }
   1.471  
   1.472 -static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
   1.473 -                                const SDL_FPoint * points, int count)
   1.474 +static int
   1.475 +DirectFB_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
   1.476  {
   1.477 +    const size_t len = count * sizeof (SDL_FRect);
   1.478 +    SDL_FRect *verts = (SDL_FRect *) SDL_AllocateRenderVertices(renderer, len, 0, &cmd->data.draw.first);
   1.479 +
   1.480 +    if (!verts) {
   1.481 +        return -1;
   1.482 +    }
   1.483 +
   1.484 +    cmd->data.draw.count = count;
   1.485 +    SDL_memcpy(verts, rects, count);
   1.486 +    return 0;
   1.487 +}
   1.488 +
   1.489 +static int
   1.490 +DirectFB_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
   1.491 +             const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   1.492 +{
   1.493 +    DFBRectangle *verts = (DFBRectangle *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (DFBRectangle), 0, &cmd->data.draw.first);
   1.494 +
   1.495 +    if (!verts) {
   1.496 +        return -1;
   1.497 +    }
   1.498 +
   1.499 +    cmd->data.draw.count = 1;
   1.500 +
   1.501 +    SDLtoDFBRect(srcrect, verts++);
   1.502 +    SDLtoDFBRect_Float(dstrect, verts);
   1.503 +
   1.504 +    return 0;
   1.505 +}
   1.506 +
   1.507 +static int
   1.508 +DirectFB_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
   1.509 +               const SDL_Rect * srcrect, const SDL_FRect * dstrect,
   1.510 +               const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
   1.511 +{
   1.512 +    return SDL_Unsupported();
   1.513 +}
   1.514 +
   1.515 +
   1.516 +static int
   1.517 +DirectFB_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
   1.518 +{
   1.519 +    /* !!! FIXME: there are probably some good optimization wins in here if someone wants to look it over. */
   1.520      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.521      IDirectFBSurface *destsurf = data->target;
   1.522      DFBRegion clip_region;
   1.523 -    int i;
   1.524 +    size_t i;
   1.525  
   1.526      DirectFB_ActivateRenderer(renderer);
   1.527  
   1.528 -    PrepareDraw(renderer);
   1.529 -    destsurf->GetClip(destsurf, &clip_region);
   1.530 -    for (i=0; i < count; i++) {
   1.531 -        int x = points[i].x + clip_region.x1;
   1.532 -        int y = points[i].y + clip_region.y1;
   1.533 -        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y));
   1.534 -    }
   1.535 -    return 0;
   1.536 -  error:
   1.537 -    return -1;
   1.538 -}
   1.539 +    SDL_zero(clip_region);  /* in theory, this always gets set before use. */
   1.540  
   1.541 -static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
   1.542 -                               const SDL_FPoint * points, int count)
   1.543 -{
   1.544 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.545 -    IDirectFBSurface *destsurf = data->target;
   1.546 -    DFBRegion clip_region;
   1.547 -    int i;
   1.548 +    while (cmd) {
   1.549 +        switch (cmd->command) {
   1.550 +            case SDL_RENDERCMD_SETDRAWCOLOR:
   1.551 +                break;  /* not used here */
   1.552  
   1.553 -    DirectFB_ActivateRenderer(renderer);
   1.554 +            case SDL_RENDERCMD_SETVIEWPORT: {
   1.555 +                const SDL_Rect *viewport = &cmd->data.viewport.rect;
   1.556 +                clip_region.x1 = viewport->x;
   1.557 +                clip_region.y1 = viewport->y;
   1.558 +                clip_region.x2 = clip_region.x1 + viewport->w - 1;
   1.559 +                clip_region.y2 = clip_region.y1 + viewport->h - 1;
   1.560 +                destsurf->SetClip(destsurf, &clip_region);
   1.561 +                break;
   1.562 +            }
   1.563  
   1.564 -    PrepareDraw(renderer);
   1.565 -    /* Use antialiasing when available */
   1.566 +            case SDL_RENDERCMD_SETCLIPRECT: {
   1.567 +                /* !!! FIXME: how does this SetClip interact with the one in SETVIEWPORT? */
   1.568 +                if (cmd->data.cliprect.enabled) {
   1.569 +                    const SDL_Rect *rect = &cmd->data.cliprect.rect;
   1.570 +                    clip_region.x1 = rect->x;
   1.571 +                    clip_region.x2 = rect->x + rect->w;
   1.572 +                    clip_region.y1 = rect->y;
   1.573 +                    clip_region.y2 = rect->y + rect->h;
   1.574 +                    destsurf->SetClip(destsurf, &clip_region);
   1.575 +                }
   1.576 +                break;
   1.577 +            }
   1.578 +
   1.579 +            case SDL_RENDERCMD_CLEAR: {
   1.580 +                const Uint8 r = cmd->data.color.r;
   1.581 +                const Uint8 g = cmd->data.color.g;
   1.582 +                const Uint8 b = cmd->data.color.b;
   1.583 +                const Uint8 a = cmd->data.color.a;
   1.584 +                destsurf->Clear(destsurf, r, g, b, a);
   1.585 +                break;
   1.586 +            }
   1.587 +
   1.588 +            case SDL_RENDERCMD_DRAW_POINTS: {
   1.589 +                const size_t count = cmd->data.draw.count;
   1.590 +                const SDL_FPoint *points = (SDL_FPoint *) (((Uint8 *) vertices) + cmd->data.draw.first);
   1.591 +                PrepareDraw(renderer, cmd);
   1.592 +                for (i = 0; i < count; i++) {
   1.593 +                    const int x = points[i].x + clip_region.x1;
   1.594 +                    const int y = points[i].y + clip_region.y1;
   1.595 +                    destsurf->DrawLine(destsurf, x, y, x, y);
   1.596 +                }
   1.597 +                break;
   1.598 +            }
   1.599 +
   1.600 +            case SDL_RENDERCMD_DRAW_LINES: {
   1.601 +                const SDL_FPoint *points = (SDL_FPoint *) (((Uint8 *) vertices) + cmd->data.draw.first);
   1.602 +                const size_t count = cmd->data.draw.count;
   1.603 +
   1.604 +                PrepareDraw(renderer, cmd);
   1.605 +
   1.606 +                #if (DFB_VERSION_ATLEAST(1,2,0))  /* !!! FIXME: should this be set once, somewhere else? */
   1.607 +                destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS);
   1.608 +                #endif
   1.609 +
   1.610 +                for (i = 0; i < count - 1; i++) {
   1.611 +                    const int x1 = points[i].x + clip_region.x1;
   1.612 +                    const int y1 = points[i].y + clip_region.y1;
   1.613 +                    const int x2 = points[i + 1].x + clip_region.x1;
   1.614 +                    const int y2 = points[i + 1].y + clip_region.y1;
   1.615 +                    destsurf->DrawLine(destsurf, x1, y1, x2, y2);
   1.616 +                }
   1.617 +                break;
   1.618 +            }
   1.619 +
   1.620 +            case SDL_RENDERCMD_FILL_RECTS: {
   1.621 +                const SDL_FRect *rects = (SDL_FRect *) (((Uint8 *) vertices) + cmd->data.draw.first);
   1.622 +                const size_t count = cmd->data.draw.count;
   1.623 +
   1.624 +                PrepareDraw(renderer, cmd);
   1.625 +
   1.626 +                for (i = 0; i < count; i++, rects++) {
   1.627 +                    destsurf->FillRectangle(destsurf, rects->x + clip_region.x1, rects->y + clip_region.y1, rects->w, rects->h);
   1.628 +                }
   1.629 +                break;
   1.630 +            }
   1.631 +
   1.632 +            case SDL_RENDERCMD_COPY: {
   1.633 +                SDL_Texture *texture = cmd->data.draw.texture;
   1.634 +                const Uint8 r = cmd->data.draw.r;
   1.635 +                const Uint8 g = cmd->data.draw.g;
   1.636 +                const Uint8 b = cmd->data.draw.b;
   1.637 +                const Uint8 a = cmd->data.draw.a;
   1.638 +                DFBRectangle *verts = (DFBRectangle *) (((Uint8 *) vertices) + cmd->data.draw.first);
   1.639 +                DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata;
   1.640 +                DFBRectangle *sr = verts++;
   1.641 +                DFBRectangle *dr = verts;
   1.642 +
   1.643 +                dr->x += clip_region.x1;
   1.644 +                dr->y += clip_region.y1;
   1.645 +
   1.646 +                if (texturedata->display) {
   1.647 +                    int px, py;
   1.648 +                    SDL_Window *window = renderer->window;
   1.649 +                    IDirectFBWindow *dfbwin = get_dfb_window(window);
   1.650 +                    SDL_DFB_WINDOWDATA(window);
   1.651 +                    SDL_VideoDisplay *display = texturedata->display;
   1.652 +                    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   1.653 +
   1.654 +                    dispdata->vidlayer->SetSourceRectangle(dispdata->vidlayer, sr->x, sr->y, sr->w, sr->h);
   1.655 +                    dfbwin->GetPosition(dfbwin, &px, &py);
   1.656 +                    px += windata->client.x;
   1.657 +                    py += windata->client.y;
   1.658 +                    dispdata->vidlayer->SetScreenRectangle(dispdata->vidlayer, px + dr->x, py + dr->y, dr->w, dr->h);
   1.659 +                } else {
   1.660 +                    DFBSurfaceBlittingFlags flags = 0;
   1.661 +                    if (texturedata->isDirty) {
   1.662 +                        const SDL_Rect rect = { 0, 0, texture->w, texture->h };
   1.663 +                        DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
   1.664 +                    }
   1.665 +
   1.666 +                    if (a != 0xFF) {
   1.667 +                        flags |= DSBLIT_BLEND_COLORALPHA;
   1.668 +                    }
   1.669 +
   1.670 +                    if ((r & g & b) != 0xFF) {
   1.671 +                        flags |= DSBLIT_COLORIZE;
   1.672 +                    }
   1.673 +
   1.674 +                    destsurf->SetColor(destsurf, r, g, b, a);
   1.675 +
   1.676 +                    /* ???? flags |= DSBLIT_SRC_PREMULTCOLOR; */
   1.677 +
   1.678 +                    SetBlendMode(data, texture->blendMode, texturedata);
   1.679 +
   1.680 +                    destsurf->SetBlittingFlags(destsurf, data->blitFlags | flags);
   1.681 +
   1.682  #if (DFB_VERSION_ATLEAST(1,2,0))
   1.683 -    SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS));
   1.684 +                    destsurf->SetRenderOptions(destsurf, texturedata->render_options);
   1.685  #endif
   1.686  
   1.687 -    destsurf->GetClip(destsurf, &clip_region);
   1.688 -    for (i=0; i < count - 1; i++) {
   1.689 -        int x1 = points[i].x + clip_region.x1;
   1.690 -        int y1 = points[i].y + clip_region.y1;
   1.691 -        int x2 = points[i + 1].x + clip_region.x1;
   1.692 -        int y2 = points[i + 1].y + clip_region.y1;
   1.693 -        SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2));
   1.694 +                    if (sr->w == dr->w && sr->h == dr->h) {
   1.695 +                        destsurf->Blit(destsurf, texturedata->surface, sr, dr->x, dr->y);
   1.696 +                    } else {
   1.697 +                        destsurf->StretchBlit(destsurf, texturedata->surface, sr, dr);
   1.698 +                    }
   1.699 +                }
   1.700 +                break;
   1.701 +            }
   1.702 +
   1.703 +            case SDL_RENDERCMD_COPY_EX:
   1.704 +                break;  /* unsupported */
   1.705 +
   1.706 +            case SDL_RENDERCMD_NO_OP:
   1.707 +                break;
   1.708 +        }
   1.709 +
   1.710 +        cmd = cmd->next;
   1.711      }
   1.712  
   1.713      return 0;
   1.714 -  error:
   1.715 -    return -1;
   1.716  }
   1.717  
   1.718 -static int
   1.719 -DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
   1.720 -{
   1.721 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.722 -    IDirectFBSurface *destsurf = data->target;
   1.723 -    DFBRegion clip_region;
   1.724 -    int i;
   1.725 -
   1.726 -    DirectFB_ActivateRenderer(renderer);
   1.727 -
   1.728 -    PrepareDraw(renderer);
   1.729 -
   1.730 -    destsurf->GetClip(destsurf, &clip_region);
   1.731 -    for (i=0; i<count; i++) {
   1.732 -        SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h};
   1.733 -        dst.x += clip_region.x1;
   1.734 -        dst.y += clip_region.y1;
   1.735 -        SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y,
   1.736 -                dst.w, dst.h));
   1.737 -    }
   1.738 -
   1.739 -    return 0;
   1.740 -  error:
   1.741 -    return -1;
   1.742 -}
   1.743 -
   1.744 -static int
   1.745 -DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
   1.746 -{
   1.747 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.748 -    IDirectFBSurface *destsurf = data->target;
   1.749 -    DFBRegion clip_region;
   1.750 -    int i;
   1.751 -
   1.752 -    DirectFB_ActivateRenderer(renderer);
   1.753 -
   1.754 -    PrepareDraw(renderer);
   1.755 -
   1.756 -    destsurf->GetClip(destsurf, &clip_region);
   1.757 -    for (i=0; i<count; i++) {
   1.758 -        SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};
   1.759 -        dst.x += clip_region.x1;
   1.760 -        dst.y += clip_region.y1;
   1.761 -        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y,
   1.762 -                dst.w, dst.h));
   1.763 -    }
   1.764 -
   1.765 -    return 0;
   1.766 -  error:
   1.767 -    return -1;
   1.768 -}
   1.769 -
   1.770 -static int
   1.771 -DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.772 -                    const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   1.773 -{
   1.774 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.775 -    IDirectFBSurface *destsurf = data->target;
   1.776 -    DirectFB_TextureData *texturedata =
   1.777 -        (DirectFB_TextureData *) texture->driverdata;
   1.778 -    Uint8 alpha, r, g, b;
   1.779 -    DFBRegion clip_region;
   1.780 -    DFBRectangle sr, dr;
   1.781 -
   1.782 -    DirectFB_ActivateRenderer(renderer);
   1.783 -
   1.784 -    SDLtoDFBRect(srcrect, &sr);
   1.785 -    SDLtoDFBRect_Float(dstrect, &dr);
   1.786 -
   1.787 -    destsurf->GetClip(destsurf, &clip_region);
   1.788 -    dr.x += clip_region.x1;
   1.789 -    dr.y += clip_region.y1;
   1.790 -
   1.791 -    if (texturedata->display) {
   1.792 -        int px, py;
   1.793 -        SDL_Window *window = renderer->window;
   1.794 -        IDirectFBWindow *dfbwin = get_dfb_window(window);
   1.795 -        SDL_DFB_WINDOWDATA(window);
   1.796 -        SDL_VideoDisplay *display = texturedata->display;
   1.797 -        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   1.798 -
   1.799 -        SDL_DFB_CHECKERR(dispdata->
   1.800 -                         vidlayer->SetSourceRectangle(dispdata->vidlayer,
   1.801 -                                                      sr.x, sr.y, sr.w, sr.h));
   1.802 -        dfbwin->GetPosition(dfbwin, &px, &py);
   1.803 -        px += windata->client.x;
   1.804 -        py += windata->client.y;
   1.805 -        SDL_DFB_CHECKERR(dispdata->
   1.806 -                         vidlayer->SetScreenRectangle(dispdata->vidlayer,
   1.807 -                                                      px + dr.x,
   1.808 -                                                      py + dr.y,
   1.809 -                                                      dr.w,
   1.810 -                                                      dr.h));
   1.811 -    } else {
   1.812 -        DFBSurfaceBlittingFlags flags = 0;
   1.813 -
   1.814 -#if 0
   1.815 -        if (texturedata->dirty.list) {
   1.816 -            SDL_DirtyRect *dirty;
   1.817 -            void *pixels;
   1.818 -            int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
   1.819 -            int pitch = texturedata->pitch;
   1.820 -
   1.821 -            for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
   1.822 -                SDL_Rect *rect = &dirty->rect;
   1.823 -                pixels =
   1.824 -                    (void *) ((Uint8 *) texturedata->pixels +
   1.825 -                              rect->y * pitch + rect->x * bpp);
   1.826 -                DirectFB_UpdateTexture(renderer, texture, rect,
   1.827 -                                       pixels,
   1.828 -                                       texturedata->pitch);
   1.829 -            }
   1.830 -            SDL_ClearDirtyRects(&texturedata->dirty);
   1.831 -        }
   1.832 -#endif
   1.833 -        if (texturedata->isDirty)
   1.834 -        {
   1.835 -            SDL_Rect rect;
   1.836 -
   1.837 -            rect.x = 0;
   1.838 -            rect.y = 0;
   1.839 -            rect.w = texture->w;
   1.840 -            rect.h = texture->h;
   1.841 -
   1.842 -            DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
   1.843 -        }
   1.844 -
   1.845 -        alpha = r = g = b = 0xff;
   1.846 -        if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){
   1.847 -            alpha = texture->a;
   1.848 -            flags |= DSBLIT_BLEND_COLORALPHA;
   1.849 -        }
   1.850 -
   1.851 -        if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
   1.852 -            r = texture->r;
   1.853 -            g = texture->g;
   1.854 -            b = texture->b;
   1.855 -            flags |= DSBLIT_COLORIZE;
   1.856 -        }
   1.857 -        SDL_DFB_CHECKERR(destsurf->
   1.858 -                         SetColor(destsurf, r, g, b, alpha));
   1.859 -
   1.860 -        /* ???? flags |= DSBLIT_SRC_PREMULTCOLOR; */
   1.861 -
   1.862 -        SetBlendMode(data, texture->blendMode, texturedata);
   1.863 -
   1.864 -        SDL_DFB_CHECKERR(destsurf->SetBlittingFlags(destsurf,
   1.865 -                                                    data->blitFlags | flags));
   1.866 -
   1.867 -#if (DFB_VERSION_ATLEAST(1,2,0))
   1.868 -        SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf,
   1.869 -                                                    texturedata->
   1.870 -                                                    render_options));
   1.871 -#endif
   1.872 -
   1.873 -        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   1.874 -            SDL_DFB_CHECKERR(destsurf->Blit(destsurf,
   1.875 -                                            texturedata->surface,
   1.876 -                                            &sr, dr.x, dr.y));
   1.877 -        } else {
   1.878 -            SDL_DFB_CHECKERR(destsurf->StretchBlit(destsurf,
   1.879 -                                                   texturedata->surface,
   1.880 -                                                   &sr, &dr));
   1.881 -        }
   1.882 -    }
   1.883 -    return 0;
   1.884 -  error:
   1.885 -    return -1;
   1.886 -}
   1.887  
   1.888  static void
   1.889  DirectFB_RenderPresent(SDL_Renderer * renderer)
   1.890 @@ -1226,8 +878,8 @@
   1.891  DirectFB_DestroyRenderer(SDL_Renderer * renderer)
   1.892  {
   1.893      DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.894 +#if 0
   1.895      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(data->window);
   1.896 -#if 0
   1.897      if (display->palette) {
   1.898          SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data);
   1.899      }
   1.900 @@ -1238,44 +890,6 @@
   1.901  }
   1.902  
   1.903  static int
   1.904 -DirectFB_UpdateViewport(SDL_Renderer * renderer)
   1.905 -{
   1.906 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.907 -    IDirectFBSurface *winsurf = data->target;
   1.908 -    DFBRegion dreg;
   1.909 -
   1.910 -    dreg.x1 = renderer->viewport.x;
   1.911 -    dreg.y1 = renderer->viewport.y;
   1.912 -    dreg.x2 = dreg.x1 + renderer->viewport.w - 1;
   1.913 -    dreg.y2 = dreg.y1 + renderer->viewport.h - 1;
   1.914 -
   1.915 -    winsurf->SetClip(winsurf, &dreg);
   1.916 -    return 0;
   1.917 -}
   1.918 -
   1.919 -static int
   1.920 -DirectFB_UpdateClipRect(SDL_Renderer * renderer)
   1.921 -{
   1.922 -    const SDL_Rect *rect = &renderer->clip_rect;
   1.923 -    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   1.924 -    IDirectFBSurface *destsurf = get_dfb_surface(data->window);
   1.925 -    DFBRegion region;
   1.926 -
   1.927 -    if (!SDL_RectEmpty(rect)) {
   1.928 -        region.x1 = rect->x;
   1.929 -        region.x2 = rect->x + rect->w;
   1.930 -        region.y1 = rect->y;
   1.931 -        region.y2 = rect->y + rect->h;
   1.932 -        SDL_DFB_CHECKERR(destsurf->SetClip(destsurf, &region));
   1.933 -    } else {
   1.934 -        SDL_DFB_CHECKERR(destsurf->SetClip(destsurf, NULL));
   1.935 -    }
   1.936 -    return 0;
   1.937 -  error:
   1.938 -    return -1;
   1.939 -}
   1.940 -
   1.941 -static int
   1.942  DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.943                       Uint32 format, void * pixels, int pitch)
   1.944  {
   1.945 @@ -1330,6 +944,112 @@
   1.946  }
   1.947  #endif
   1.948  
   1.949 +
   1.950 +SDL_Renderer *
   1.951 +DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
   1.952 +{
   1.953 +    IDirectFBSurface *winsurf = get_dfb_surface(window);
   1.954 +    /*SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);*/
   1.955 +    SDL_Renderer *renderer = NULL;
   1.956 +    DirectFB_RenderData *data = NULL;
   1.957 +    DFBSurfaceCapabilities scaps;
   1.958 +
   1.959 +    if (!winsurf) {
   1.960 +        return NULL;
   1.961 +    }
   1.962 +
   1.963 +    SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer));
   1.964 +    SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
   1.965 +
   1.966 +    renderer->WindowEvent = DirectFB_WindowEvent;
   1.967 +    renderer->CreateTexture = DirectFB_CreateTexture;
   1.968 +    renderer->UpdateTexture = DirectFB_UpdateTexture;
   1.969 +    renderer->LockTexture = DirectFB_LockTexture;
   1.970 +    renderer->UnlockTexture = DirectFB_UnlockTexture;
   1.971 +    renderer->QueueSetViewport = DirectFB_QueueSetViewport;
   1.972 +    renderer->QueueSetDrawColor = DirectFB_QueueSetViewport;  /* SetViewport and SetDrawColor are (currently) no-ops. */
   1.973 +    renderer->QueueDrawPoints = DirectFB_QueueDrawPoints;
   1.974 +    renderer->QueueDrawLines = DirectFB_QueueDrawPoints;  /* lines and points queue vertices the same way. */
   1.975 +    renderer->QueueFillRects = DirectFB_QueueFillRects;
   1.976 +    renderer->QueueCopy = DirectFB_QueueCopy;
   1.977 +    renderer->QueueCopyEx = DirectFB_QueueCopyEx;
   1.978 +    renderer->RunCommandQueue = DirectFB_RunCommandQueue;
   1.979 +    renderer->RenderPresent = DirectFB_RenderPresent;
   1.980 +
   1.981 +    /* FIXME: Yet to be tested */
   1.982 +    renderer->RenderReadPixels = DirectFB_RenderReadPixels;
   1.983 +    /* renderer->RenderWritePixels = DirectFB_RenderWritePixels; */
   1.984 +
   1.985 +    renderer->DestroyTexture = DirectFB_DestroyTexture;
   1.986 +    renderer->DestroyRenderer = DirectFB_DestroyRenderer;
   1.987 +    renderer->SetRenderTarget = DirectFB_SetRenderTarget;
   1.988 +
   1.989 +    renderer->info = DirectFB_RenderDriver.info;
   1.990 +    renderer->window = window;      /* SDL window */
   1.991 +    renderer->driverdata = data;
   1.992 +
   1.993 +    renderer->info.flags =
   1.994 +        SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
   1.995 +
   1.996 +    data->window = window;
   1.997 +    data->target = winsurf;
   1.998 +
   1.999 +    data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
  1.1000 +
  1.1001 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  1.1002 +        data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC;
  1.1003 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  1.1004 +    } else
  1.1005 +        data->flipflags |= DSFLIP_ONSYNC;
  1.1006 +
  1.1007 +    SDL_DFB_CHECKERR(winsurf->GetCapabilities(winsurf, &scaps));
  1.1008 +
  1.1009 +#if 0
  1.1010 +    if (scaps & DSCAPS_DOUBLE)
  1.1011 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
  1.1012 +    else if (scaps & DSCAPS_TRIPLE)
  1.1013 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
  1.1014 +    else
  1.1015 +        renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
  1.1016 +#endif
  1.1017 +
  1.1018 +    DirectFB_SetSupportedPixelFormats(&renderer->info);
  1.1019 +
  1.1020 +#if 0
  1.1021 +    /* Set up a palette watch on the display palette */
  1.1022 +    if (display-> palette) {
  1.1023 +        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
  1.1024 +    }
  1.1025 +#endif
  1.1026 +
  1.1027 +    return renderer;
  1.1028 +
  1.1029 +  error:
  1.1030 +    SDL_DFB_FREE(renderer);
  1.1031 +    SDL_DFB_FREE(data);
  1.1032 +    return NULL;
  1.1033 +}
  1.1034 +
  1.1035 +
  1.1036 +SDL_RenderDriver DirectFB_RenderDriver = {
  1.1037 +    DirectFB_CreateRenderer,
  1.1038 +    {
  1.1039 +     "directfb",
  1.1040 +     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
  1.1041 +     /* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
  1.1042 +      SDL_TEXTUREMODULATE_ALPHA),
  1.1043 +      (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
  1.1044 +      SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
  1.1045 +     (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST |
  1.1046 +      SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST), */
  1.1047 +     0,
  1.1048 +     {
  1.1049 +             /* formats filled in later */
  1.1050 +     },
  1.1051 +     0,
  1.1052 +     0}
  1.1053 +};
  1.1054 +
  1.1055  #endif /* SDL_VIDEO_DRIVER_DIRECTFB */
  1.1056  
  1.1057  /* vi: set ts=4 sw=4 expandtab: */