src/video/directfb/SDL_DirectFB_render.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 26 Nov 2008 21:59:35 +0000
changeset 2791 8133d1d278da
parent 2737 140a7edcf2bd
child 2859 99210400e8b9
permissions -rw-r--r--
Date: Wed, 26 Nov 2008 19:50:31 +0100
From: Couriersud
Subject: LPGL and closed-source license / Re: [Bug 607] Texture palette not up

Permission granted to release code under both LPGL and closed-source
commercial license.

Please find attached a minor patch fixing vsync handling in the directfb
driver and containing a small update to README.directfb
slouken@2226
     1
/*
slouken@2226
     2
    SDL - Simple DirectMedia Layer
slouken@2226
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@2226
     4
slouken@2226
     5
    This library is free software; you can redistribute it and/or
slouken@2226
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2226
     7
    License as published by the Free Software Foundation; either
slouken@2226
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2226
     9
slouken@2226
    10
    This library is distributed in the hope that it will be useful,
slouken@2226
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2226
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2226
    13
    Lesser General Public License for more details.
slouken@2226
    14
slouken@2226
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2226
    16
    License along with this library; if not, write to the Free Software
slouken@2226
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2226
    18
slouken@2226
    19
    Sam Lantinga
slouken@2226
    20
    slouken@libsdl.org
slouken@2226
    21
    
slouken@2226
    22
    SDL1.3 implementation by couriersud@arcor.de
slouken@2226
    23
    
slouken@2226
    24
*/
slouken@2226
    25
#include "SDL_config.h"
slouken@2226
    26
slouken@2226
    27
#include "SDL_DirectFB_video.h"
slouken@2226
    28
#include "SDL_DirectFB_render.h"
slouken@2226
    29
#include "../SDL_rect_c.h"
slouken@2226
    30
#include "../SDL_yuv_sw_c.h"
slouken@2226
    31
slouken@2737
    32
/* the following is not yet tested ... */
slouken@2737
    33
#define USE_DISPLAY_PALETTE			(0)
slouken@2737
    34
slouken@2226
    35
/* GDI renderer implementation */
slouken@2226
    36
slouken@2226
    37
static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
slouken@2226
    38
                                             Uint32 flags);
slouken@2226
    39
static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer);
slouken@2737
    40
static int DirectFB_ActivateRenderer(SDL_Renderer * renderer);
slouken@2226
    41
static int DirectFB_CreateTexture(SDL_Renderer * renderer,
slouken@2226
    42
                                  SDL_Texture * texture);
slouken@2226
    43
static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
slouken@2226
    44
                                       SDL_Texture * texture, void **pixels,
slouken@2226
    45
                                       int *pitch);
slouken@2226
    46
static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
slouken@2226
    47
                                      SDL_Texture * texture,
slouken@2226
    48
                                      const SDL_Color * colors,
slouken@2226
    49
                                      int firstcolor, int ncolors);
slouken@2226
    50
static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
slouken@2226
    51
                                      SDL_Texture * texture,
slouken@2226
    52
                                      SDL_Color * colors, int firstcolor,
slouken@2226
    53
                                      int ncolors);
slouken@2226
    54
static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
slouken@2226
    55
                                       SDL_Texture * texture);
slouken@2226
    56
static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
slouken@2226
    57
                                       SDL_Texture * texture);
slouken@2226
    58
static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
slouken@2226
    59
                                        SDL_Texture * texture);
slouken@2226
    60
static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
slouken@2226
    61
                                        SDL_Texture * texture);
slouken@2226
    62
static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
slouken@2226
    63
                                  SDL_Texture * texture,
slouken@2226
    64
                                  const SDL_Rect * rect, const void *pixels,
slouken@2226
    65
                                  int pitch);
slouken@2226
    66
static int DirectFB_LockTexture(SDL_Renderer * renderer,
slouken@2226
    67
                                SDL_Texture * texture, const SDL_Rect * rect,
slouken@2226
    68
                                int markDirty, void **pixels, int *pitch);
slouken@2226
    69
static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
slouken@2226
    70
                                   SDL_Texture * texture);
slouken@2226
    71
static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
slouken@2226
    72
                                  SDL_Texture * texture, int numrects,
slouken@2226
    73
                                  const SDL_Rect * rects);
slouken@2226
    74
static int DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
slouken@2226
    75
                               Uint8 b, Uint8 a, const SDL_Rect * rect);
slouken@2226
    76
static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
    77
                               const SDL_Rect * srcrect,
slouken@2226
    78
                               const SDL_Rect * dstrect);
slouken@2226
    79
static void DirectFB_RenderPresent(SDL_Renderer * renderer);
slouken@2226
    80
static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
slouken@2226
    81
                                    SDL_Texture * texture);
slouken@2226
    82
static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
slouken@2226
    83
slouken@2226
    84
SDL_RenderDriver DirectFB_RenderDriver = {
slouken@2226
    85
    DirectFB_CreateRenderer,
slouken@2226
    86
    {
slouken@2226
    87
     "directfb",
slouken@2226
    88
     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
slouken@2226
    89
      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
slouken@2791
    90
      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD |
slouken@2791
    91
      SDL_RENDERER_ACCELERATED),
slouken@2226
    92
     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
slouken@2226
    93
      SDL_TEXTUREMODULATE_ALPHA),
slouken@2226
    94
     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
slouken@2721
    95
      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
slouken@2721
    96
      SDL_TEXTUREBLENDMODE_MOD),
slouken@2737
    97
     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
slouken@2737
    98
      SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
slouken@2226
    99
     14,
slouken@2226
   100
     {
slouken@2737
   101
      SDL_PIXELFORMAT_INDEX4LSB,
slouken@2226
   102
      SDL_PIXELFORMAT_INDEX8,
slouken@2226
   103
      SDL_PIXELFORMAT_RGB332,
slouken@2226
   104
      SDL_PIXELFORMAT_RGB555,
slouken@2226
   105
      SDL_PIXELFORMAT_RGB565,
slouken@2226
   106
      SDL_PIXELFORMAT_RGB888,
slouken@2226
   107
      SDL_PIXELFORMAT_ARGB8888,
slouken@2226
   108
      SDL_PIXELFORMAT_ARGB4444,
slouken@2226
   109
      SDL_PIXELFORMAT_ARGB1555,
slouken@2226
   110
      SDL_PIXELFORMAT_RGB24,
slouken@2226
   111
      SDL_PIXELFORMAT_YV12,
slouken@2226
   112
      SDL_PIXELFORMAT_IYUV,
slouken@2226
   113
      SDL_PIXELFORMAT_YUY2,
slouken@2226
   114
      SDL_PIXELFORMAT_UYVY},
slouken@2226
   115
     0,
slouken@2226
   116
     0}
slouken@2226
   117
};
slouken@2226
   118
slouken@2226
   119
typedef struct
slouken@2226
   120
{
slouken@2226
   121
    IDirectFBSurface *surface;
slouken@2226
   122
    DFBSurfaceFlipFlags flipflags;
slouken@2226
   123
    int isyuvdirect;
slouken@2737
   124
    int size_changed;
slouken@2226
   125
} DirectFB_RenderData;
slouken@2226
   126
slouken@2226
   127
typedef struct
slouken@2226
   128
{
slouken@2226
   129
    IDirectFBSurface *surface;
slouken@2226
   130
    Uint32 format;
slouken@2226
   131
    void *pixels;
slouken@2226
   132
    int pitch;
slouken@2226
   133
    IDirectFBPalette *palette;
slouken@2737
   134
    SDL_VideoDisplay *display;
slouken@2737
   135
    SDL_DirtyRectList dirty;
slouken@2737
   136
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
slouken@2737
   137
    DFBSurfaceRenderOptions render_options;
slouken@2737
   138
#endif
slouken@2226
   139
} DirectFB_TextureData;
slouken@2226
   140
slouken@2737
   141
static __inline__ void
slouken@2737
   142
SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
slouken@2737
   143
{
slouken@2737
   144
    dr->x = sr->x;
slouken@2737
   145
    dr->y = sr->y;
slouken@2737
   146
    dr->h = sr->h;
slouken@2737
   147
    dr->w = sr->w;
slouken@2737
   148
}
slouken@2737
   149
slouken@2226
   150
void
slouken@2226
   151
DirectFB_AddRenderDriver(_THIS)
slouken@2226
   152
{
slouken@2226
   153
    int i;
slouken@2226
   154
    for (i = 0; i < _this->num_displays; i++)
slouken@2226
   155
        SDL_AddRenderDriver(i, &DirectFB_RenderDriver);
slouken@2226
   156
}
slouken@2226
   157
slouken@2737
   158
static int
slouken@2737
   159
DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
slouken@2737
   160
{
slouken@2737
   161
#if USE_DISPLAY_PALETTE
slouken@2737
   162
    DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
slouken@2737
   163
    IDirectFBPalette *surfpal;
slouken@2737
   164
slouken@2737
   165
    int ret;
slouken@2737
   166
    int i;
slouken@2737
   167
    int ncolors;
slouken@2737
   168
    DFBColor entries[256];
slouken@2737
   169
slouken@2737
   170
    SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &surfpal));
slouken@2737
   171
slouken@2737
   172
    /* FIXME: number of colors */
slouken@2737
   173
    ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
slouken@2737
   174
slouken@2737
   175
    for (i = 0; i < ncolors; ++i) {
slouken@2737
   176
        entries[i].r = palette->colors[i].r;
slouken@2737
   177
        entries[i].g = palette->colors[i].g;
slouken@2737
   178
        entries[i].b = palette->colors[i].b;
slouken@2737
   179
        entries[i].a = palette->colors[i].unused;
slouken@2737
   180
    }
slouken@2737
   181
    SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
slouken@2737
   182
    return 0;
slouken@2737
   183
  error:
slouken@2737
   184
#endif
slouken@2737
   185
    return -1;
slouken@2737
   186
}
slouken@2737
   187
slouken@2737
   188
slouken@2226
   189
SDL_Renderer *
slouken@2226
   190
DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@2226
   191
{
slouken@2226
   192
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   193
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@2226
   194
    SDL_Renderer *renderer = NULL;
slouken@2226
   195
    DirectFB_RenderData *data = NULL;
slouken@2226
   196
    DFBResult ret;
slouken@2226
   197
    DFBSurfaceCapabilities scaps;
slouken@2226
   198
    char *p;
slouken@2226
   199
slouken@2226
   200
    SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer));
slouken@2226
   201
    SDL_DFB_CALLOC(data, 1, sizeof(*data));
slouken@2226
   202
slouken@2226
   203
    renderer->DisplayModeChanged = DirectFB_DisplayModeChanged;
slouken@2737
   204
    renderer->ActivateRenderer = DirectFB_ActivateRenderer;
slouken@2226
   205
    renderer->CreateTexture = DirectFB_CreateTexture;
slouken@2226
   206
    renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
slouken@2226
   207
    renderer->SetTexturePalette = DirectFB_SetTexturePalette;
slouken@2226
   208
    renderer->GetTexturePalette = DirectFB_GetTexturePalette;
slouken@2226
   209
    renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
slouken@2226
   210
    renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
slouken@2226
   211
    renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
slouken@2226
   212
    renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
slouken@2226
   213
    renderer->UpdateTexture = DirectFB_UpdateTexture;
slouken@2226
   214
    renderer->LockTexture = DirectFB_LockTexture;
slouken@2226
   215
    renderer->UnlockTexture = DirectFB_UnlockTexture;
slouken@2226
   216
    renderer->DirtyTexture = DirectFB_DirtyTexture;
slouken@2226
   217
    renderer->RenderFill = DirectFB_RenderFill;
slouken@2226
   218
    renderer->RenderCopy = DirectFB_RenderCopy;
slouken@2226
   219
    renderer->RenderPresent = DirectFB_RenderPresent;
slouken@2226
   220
    renderer->DestroyTexture = DirectFB_DestroyTexture;
slouken@2226
   221
    renderer->DestroyRenderer = DirectFB_DestroyRenderer;
slouken@2226
   222
    renderer->info = DirectFB_RenderDriver.info;
slouken@2721
   223
    renderer->window = window->id;      /* SDL window id */
slouken@2226
   224
    renderer->driverdata = data;
slouken@2226
   225
slouken@2226
   226
    renderer->info.flags =
slouken@2226
   227
        SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD;
slouken@2226
   228
slouken@2226
   229
    data->surface = windata->surface;
slouken@2737
   230
    data->surface->AddRef(data->surface);
slouken@2737
   231
slouken@2737
   232
    data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
slouken@2226
   233
slouken@2226
   234
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@2791
   235
        data->flipflags |= DSFLIP_WAITFORSYNC;
slouken@2226
   236
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@2791
   237
    } else
slouken@2791
   238
        data->flipflags |= DSFLIP_ONSYNC;
slouken@2226
   239
slouken@2737
   240
    SDL_DFB_CHECKERR(data->surface->GetCapabilities(data->surface, &scaps));
slouken@2226
   241
    if (scaps & DSCAPS_DOUBLE)
slouken@2226
   242
        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
slouken@2226
   243
    else if (scaps & DSCAPS_TRIPLE)
slouken@2226
   244
        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
slouken@2226
   245
    else
slouken@2226
   246
        renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
slouken@2226
   247
slouken@2737
   248
    data->isyuvdirect = 0;      /* default is off! */
slouken@2737
   249
    p = getenv(DFBENV_USE_YUV_DIRECT);
slouken@2226
   250
    if (p)
slouken@2226
   251
        data->isyuvdirect = atoi(p);
slouken@2226
   252
slouken@2737
   253
    /* Set up a palette watch on the display palette */
slouken@2737
   254
    if (display->palette) {
slouken@2737
   255
        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
slouken@2737
   256
    }
slouken@2737
   257
slouken@2226
   258
    return renderer;
slouken@2226
   259
slouken@2226
   260
  error:
slouken@2226
   261
    SDL_DFB_FREE(renderer);
slouken@2226
   262
    SDL_DFB_FREE(data);
slouken@2226
   263
    return NULL;
slouken@2226
   264
}
slouken@2226
   265
slouken@2226
   266
static DFBSurfacePixelFormat
slouken@2226
   267
SDLToDFBPixelFormat(Uint32 format)
slouken@2226
   268
{
slouken@2226
   269
    switch (format) {
slouken@2226
   270
    case SDL_PIXELFORMAT_INDEX4LSB:
slouken@2226
   271
        return DSPF_ALUT44;
slouken@2226
   272
    case SDL_PIXELFORMAT_INDEX8:
slouken@2226
   273
        return DSPF_LUT8;
slouken@2226
   274
    case SDL_PIXELFORMAT_RGB332:
slouken@2226
   275
        return DSPF_RGB332;
slouken@2226
   276
    case SDL_PIXELFORMAT_RGB555:
slouken@2226
   277
        return DSPF_ARGB1555;
slouken@2226
   278
    case SDL_PIXELFORMAT_ARGB4444:
slouken@2226
   279
        return DSPF_ARGB4444;
slouken@2226
   280
    case SDL_PIXELFORMAT_ARGB1555:
slouken@2226
   281
        return DSPF_ARGB1555;
slouken@2226
   282
    case SDL_PIXELFORMAT_RGB565:
slouken@2226
   283
        return DSPF_RGB16;
slouken@2226
   284
    case SDL_PIXELFORMAT_RGB24:
slouken@2226
   285
        return DSPF_RGB24;
slouken@2226
   286
    case SDL_PIXELFORMAT_RGB888:
slouken@2226
   287
        return DSPF_RGB32;
slouken@2226
   288
    case SDL_PIXELFORMAT_ARGB8888:
slouken@2226
   289
        return DSPF_ARGB;
slouken@2226
   290
    case SDL_PIXELFORMAT_YV12:
slouken@2226
   291
        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
slouken@2226
   292
    case SDL_PIXELFORMAT_IYUV:
slouken@2226
   293
        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
slouken@2226
   294
    case SDL_PIXELFORMAT_YUY2:
slouken@2226
   295
        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
slouken@2226
   296
    case SDL_PIXELFORMAT_UYVY:
slouken@2226
   297
        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
slouken@2226
   298
    case SDL_PIXELFORMAT_YVYU:
slouken@2226
   299
        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
slouken@2226
   300
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@2226
   301
        return DSPF_UNKNOWN;
slouken@2226
   302
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@2226
   303
        return DSPF_UNKNOWN;
slouken@2226
   304
    case SDL_PIXELFORMAT_INDEX4MSB:
slouken@2226
   305
        return DSPF_UNKNOWN;
slouken@2226
   306
    case SDL_PIXELFORMAT_RGB444:
slouken@2226
   307
        return DSPF_UNKNOWN;
slouken@2226
   308
    case SDL_PIXELFORMAT_BGR24:
slouken@2226
   309
        return DSPF_UNKNOWN;
slouken@2226
   310
    case SDL_PIXELFORMAT_BGR888:
slouken@2226
   311
        return DSPF_UNKNOWN;
slouken@2226
   312
    case SDL_PIXELFORMAT_RGBA8888:
slouken@2226
   313
        return DSPF_UNKNOWN;
slouken@2226
   314
    case SDL_PIXELFORMAT_ABGR8888:
slouken@2226
   315
        return DSPF_UNKNOWN;
slouken@2226
   316
    case SDL_PIXELFORMAT_BGRA8888:
slouken@2226
   317
        return DSPF_UNKNOWN;
slouken@2226
   318
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@2226
   319
        return DSPF_UNKNOWN;
slouken@2226
   320
    default:
slouken@2226
   321
        return DSPF_UNKNOWN;
slouken@2226
   322
    }
slouken@2226
   323
}
slouken@2226
   324
slouken@2226
   325
static int
slouken@2737
   326
DirectFB_ActivateRenderer(SDL_Renderer * renderer)
slouken@2226
   327
{
slouken@2226
   328
    SDL_DFB_RENDERERDATA(renderer);
slouken@2226
   329
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@2226
   330
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   331
slouken@2737
   332
    if (renddata->size_changed) {
slouken@2737
   333
        int cw, ch;
slouken@2737
   334
        int ret;
slouken@2737
   335
slouken@2737
   336
        SDL_DFB_CHECKERR(windata->surface->
slouken@2737
   337
                         GetSize(windata->surface, &cw, &ch));
slouken@2737
   338
        if (cw != window->w || ch != window->h)
slouken@2737
   339
            SDL_DFB_CHECKERR(windata->window->
slouken@2737
   340
                             ResizeSurface(windata->window, window->w,
slouken@2737
   341
                                           window->h));
slouken@2737
   342
    }
slouken@2226
   343
    return 0;
slouken@2226
   344
  error:
slouken@2226
   345
    return -1;
slouken@2226
   346
}
slouken@2226
   347
slouken@2226
   348
static int
slouken@2737
   349
DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
slouken@2737
   350
{
slouken@2737
   351
    SDL_DFB_RENDERERDATA(renderer);
slouken@2737
   352
slouken@2737
   353
    renddata->size_changed = SDL_TRUE;
slouken@2737
   354
    return 0;
slouken@2737
   355
}
slouken@2737
   356
slouken@2737
   357
static int
slouken@2721
   358
DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2721
   359
{
slouken@2721
   360
    SDL_DFB_RENDERERDATA(renderer);
slouken@2721
   361
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@2721
   362
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@2721
   363
    SDL_DFB_DEVICEDATA(display->device);
slouken@2721
   364
    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
slouken@2721
   365
    DirectFB_TextureData *data = texture->driverdata;
slouken@2721
   366
    DFBDisplayLayerConfig layconf;
slouken@2721
   367
    int ret;
slouken@2721
   368
slouken@2721
   369
    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
slouken@2721
   370
        && (!dispdata->vidIDinuse)
slouken@2721
   371
        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
slouken@2737
   372
        layconf.flags =
slouken@2737
   373
            DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
slouken@2737
   374
            DLCONF_SURFACE_CAPS;
slouken@2721
   375
        layconf.width = texture->w;
slouken@2721
   376
        layconf.height = texture->h;
slouken@2721
   377
        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
slouken@2737
   378
        layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
slouken@2721
   379
slouken@2721
   380
        SDL_DFB_CHECKERR(devdata->dfb->
slouken@2721
   381
                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
slouken@2737
   382
                                         &dispdata->vidlayer));
slouken@2737
   383
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   384
                         SetCooperativeLevel(dispdata->vidlayer,
slouken@2721
   385
                                             DLSCL_EXCLUSIVE));
slouken@2737
   386
slouken@2737
   387
        if (devdata->use_yuv_underlays) {
slouken@2737
   388
            ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
slouken@2737
   389
            if (ret != DFB_OK)
slouken@2737
   390
                SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
slouken@2737
   391
        }
slouken@2737
   392
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   393
                         SetConfiguration(dispdata->vidlayer, &layconf));
slouken@2737
   394
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   395
                         GetSurface(dispdata->vidlayer, &data->surface));
slouken@2721
   396
        dispdata->vidIDinuse = 1;
slouken@2737
   397
        data->display = display;
slouken@2721
   398
        return 0;
slouken@2721
   399
    }
slouken@2721
   400
    return 1;
slouken@2721
   401
  error:
slouken@2737
   402
    if (dispdata->vidlayer) {
slouken@2721
   403
        SDL_DFB_RELEASE(data->surface);
slouken@2737
   404
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   405
                         SetCooperativeLevel(dispdata->vidlayer,
slouken@2721
   406
                                             DLSCL_ADMINISTRATIVE));
slouken@2737
   407
        SDL_DFB_RELEASE(dispdata->vidlayer);
slouken@2721
   408
    }
slouken@2721
   409
    return 1;
slouken@2721
   410
}
slouken@2721
   411
slouken@2721
   412
static int
slouken@2226
   413
DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   414
{
slouken@2226
   415
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@2226
   416
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@2226
   417
    SDL_DFB_DEVICEDATA(display->device);
slouken@2226
   418
    DirectFB_TextureData *data;
slouken@2226
   419
    DFBResult ret;
slouken@2226
   420
    DFBSurfaceDescription dsc;
slouken@2226
   421
slouken@2226
   422
    SDL_DFB_CALLOC(data, 1, sizeof(*data));
slouken@2226
   423
    texture->driverdata = data;
slouken@2226
   424
slouken@2226
   425
    data->format = texture->format;
slouken@2226
   426
    data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
slouken@2226
   427
slouken@2721
   428
    if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
slouken@2226
   429
        /* fill surface description */
slouken@2226
   430
        dsc.flags =
slouken@2226
   431
            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
slouken@2226
   432
        dsc.width = texture->w;
slouken@2226
   433
        dsc.height = texture->h;
slouken@2721
   434
        /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
slouken@2226
   435
         * No DSCAPS_SYSTEMONLY either - let dfb decide
slouken@2721
   436
         * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
slouken@2737
   437
         * Depends on other settings as well. Let dfb decide.
slouken@2226
   438
         */
slouken@2721
   439
        dsc.caps = DSCAPS_PREMULTIPLIED;
slouken@2737
   440
#if 0
slouken@2721
   441
        if (texture->access == SDL_TEXTUREACCESS_STREAMING)
slouken@2721
   442
            dsc.caps |= DSCAPS_SYSTEMONLY;
slouken@2721
   443
        else
slouken@2721
   444
            dsc.caps |= DSCAPS_VIDEOONLY;
slouken@2737
   445
#endif
slouken@2226
   446
slouken@2226
   447
        /* find the right pixelformat */
slouken@2226
   448
slouken@2226
   449
        dsc.pixelformat = SDLToDFBPixelFormat(data->format);
slouken@2226
   450
        if (dsc.pixelformat == DSPF_UNKNOWN) {
slouken@2226
   451
            SDL_SetError("Unknown pixel format %d\n", data->format);
slouken@2226
   452
            goto error;
slouken@2226
   453
        }
slouken@2226
   454
slouken@2226
   455
        data->pixels = NULL;
slouken@2226
   456
slouken@2226
   457
        /* Create the surface */
slouken@2226
   458
        SDL_DFB_CHECKERR(devdata->dfb->
slouken@2226
   459
                         CreateSurface(devdata->dfb, &dsc, &data->surface));
slouken@2226
   460
        if (SDL_ISPIXELFORMAT_INDEXED(data->format)
slouken@2226
   461
            && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
slouken@2226
   462
            SDL_DFB_CHECKERR(data->surface->
slouken@2226
   463
                             GetPalette(data->surface, &data->palette));
slouken@2226
   464
        }
slouken@2226
   465
slouken@2226
   466
    }
slouken@2737
   467
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
slouken@2737
   468
    data->render_options = DSRO_NONE;
slouken@2737
   469
#endif
slouken@2737
   470
slouken@2737
   471
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
slouken@2737
   472
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
slouken@2737
   473
        SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
slouken@2737
   474
    }
slouken@2737
   475
slouken@2226
   476
    return 0;
slouken@2226
   477
slouken@2226
   478
  error:
slouken@2226
   479
    SDL_DFB_RELEASE(data->palette);
slouken@2226
   480
    SDL_DFB_RELEASE(data->surface);
slouken@2226
   481
    SDL_DFB_FREE(texture->driverdata);
slouken@2226
   482
    return -1;
slouken@2226
   483
}
slouken@2226
   484
slouken@2226
   485
static int
slouken@2226
   486
DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   487
                            void **pixels, int *pitch)
slouken@2226
   488
{
slouken@2737
   489
    DirectFB_TextureData *texturedata =
slouken@2737
   490
        (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   491
slouken@2737
   492
    if (texturedata->display) {
slouken@2737
   493
        return -1;
slouken@2737
   494
    } else {
slouken@2737
   495
        *pixels = texturedata->pixels;
slouken@2737
   496
        *pitch = texturedata->pitch;
slouken@2737
   497
    }
slouken@2737
   498
    return 0;
slouken@2226
   499
}
slouken@2226
   500
slouken@2226
   501
static int
slouken@2226
   502
DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   503
                           const SDL_Color * colors, int firstcolor,
slouken@2226
   504
                           int ncolors)
slouken@2226
   505
{
slouken@2226
   506
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   507
    DFBResult ret;
slouken@2226
   508
slouken@2226
   509
    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
slouken@2226
   510
        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
slouken@2226
   511
        DFBColor entries[256];
slouken@2226
   512
        int i;
slouken@2226
   513
slouken@2226
   514
        for (i = 0; i < ncolors; ++i) {
slouken@2226
   515
            entries[i].r = colors[i].r;
slouken@2226
   516
            entries[i].g = colors[i].g;
slouken@2226
   517
            entries[i].b = colors[i].b;
slouken@2226
   518
            entries[i].a = 0xFF;
slouken@2226
   519
        }
slouken@2226
   520
        SDL_DFB_CHECKERR(data->palette->
slouken@2226
   521
                         SetEntries(data->palette, entries, ncolors,
slouken@2226
   522
                                    firstcolor));
slouken@2226
   523
        return 0;
slouken@2226
   524
    } else {
slouken@2226
   525
        SDL_SetError("YUV textures don't have a palette");
slouken@2226
   526
        return -1;
slouken@2226
   527
    }
slouken@2226
   528
  error:
slouken@2226
   529
    return -1;
slouken@2226
   530
}
slouken@2226
   531
slouken@2226
   532
static int
slouken@2226
   533
DirectFB_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   534
                           SDL_Color * colors, int firstcolor, int ncolors)
slouken@2226
   535
{
slouken@2226
   536
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   537
    DFBResult ret;
slouken@2226
   538
slouken@2226
   539
    if (SDL_ISPIXELFORMAT_INDEXED(data->format)
slouken@2226
   540
        && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
slouken@2226
   541
        DFBColor entries[256];
slouken@2226
   542
        int i;
slouken@2226
   543
slouken@2226
   544
        SDL_DFB_CHECKERR(data->palette->
slouken@2226
   545
                         GetEntries(data->palette, entries, ncolors,
slouken@2226
   546
                                    firstcolor));
slouken@2226
   547
slouken@2226
   548
        for (i = 0; i < ncolors; ++i) {
slouken@2226
   549
            colors[i].r = entries[i].r;
slouken@2226
   550
            colors[i].g = entries[i].g;
slouken@2226
   551
            colors[i].b = entries[i].b;
slouken@2737
   552
            colors->unused = SDL_ALPHA_OPAQUE;
slouken@2226
   553
        }
slouken@2226
   554
        return 0;
slouken@2226
   555
    } else {
slouken@2226
   556
        SDL_SetError("YUV textures don't have a palette");
slouken@2226
   557
        return -1;
slouken@2226
   558
    }
slouken@2226
   559
  error:
slouken@2226
   560
    return -1;
slouken@2226
   561
}
slouken@2226
   562
slouken@2226
   563
static int
slouken@2226
   564
DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   565
{
slouken@2226
   566
    return 0;
slouken@2226
   567
}
slouken@2226
   568
slouken@2226
   569
static int
slouken@2226
   570
DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   571
{
slouken@2226
   572
    return 0;
slouken@2226
   573
}
slouken@2226
   574
slouken@2226
   575
static int
slouken@2226
   576
DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   577
{
slouken@2226
   578
    switch (texture->blendMode) {
slouken@2226
   579
    case SDL_TEXTUREBLENDMODE_NONE:
slouken@2226
   580
    case SDL_TEXTUREBLENDMODE_MASK:
slouken@2226
   581
    case SDL_TEXTUREBLENDMODE_BLEND:
slouken@2721
   582
    case SDL_TEXTUREBLENDMODE_ADD:
slouken@2226
   583
    case SDL_TEXTUREBLENDMODE_MOD:
slouken@2226
   584
        return 0;
slouken@2226
   585
    default:
slouken@2226
   586
        SDL_Unsupported();
slouken@2226
   587
        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
slouken@2226
   588
        return -1;
slouken@2226
   589
    }
slouken@2226
   590
}
slouken@2226
   591
slouken@2226
   592
static int
slouken@2226
   593
DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   594
{
slouken@2737
   595
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
slouken@2737
   596
slouken@2737
   597
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2737
   598
slouken@2226
   599
    switch (texture->scaleMode) {
slouken@2226
   600
    case SDL_TEXTURESCALEMODE_NONE:
slouken@2226
   601
    case SDL_TEXTURESCALEMODE_FAST:
slouken@2737
   602
        data->render_options = DSRO_NONE;
slouken@2737
   603
        break;
slouken@2226
   604
    case SDL_TEXTURESCALEMODE_SLOW:
slouken@2737
   605
        data->render_options = DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE;
slouken@2737
   606
        break;
slouken@2226
   607
    case SDL_TEXTURESCALEMODE_BEST:
slouken@2737
   608
        data->render_options =
slouken@2737
   609
            DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS;
slouken@2737
   610
        break;
slouken@2226
   611
    default:
slouken@2226
   612
        SDL_Unsupported();
slouken@2737
   613
        data->render_options = DSRO_NONE;
slouken@2226
   614
        texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
slouken@2226
   615
        return -1;
slouken@2226
   616
    }
slouken@2737
   617
#endif
slouken@2226
   618
    return 0;
slouken@2226
   619
}
slouken@2226
   620
slouken@2226
   621
static int
slouken@2226
   622
DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   623
                       const SDL_Rect * rect, const void *pixels, int pitch)
slouken@2226
   624
{
slouken@2226
   625
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2241
   626
    DFBResult ret;
slouken@2241
   627
    Uint8 *dpixels;
slouken@2244
   628
    int dpitch;
slouken@2241
   629
    Uint8 *src, *dst;
slouken@2241
   630
    int row;
slouken@2241
   631
    size_t length;
slouken@2226
   632
slouken@2241
   633
    SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
slouken@2721
   634
                                         DSLF_WRITE | DSLF_READ,
slouken@2721
   635
                                         ((void **) &dpixels), &dpitch));
slouken@2241
   636
    src = (Uint8 *) pixels;
slouken@2241
   637
    dst =
slouken@2241
   638
        (Uint8 *) dpixels + rect->y * dpitch +
slouken@2241
   639
        rect->x * SDL_BYTESPERPIXEL(texture->format);
slouken@2241
   640
    length = rect->w * SDL_BYTESPERPIXEL(texture->format);
slouken@2241
   641
    for (row = 0; row < rect->h; ++row) {
slouken@2241
   642
        SDL_memcpy(dst, src, length);
slouken@2241
   643
        src += pitch;
slouken@2241
   644
        dst += dpitch;
slouken@2241
   645
    }
slouken@2244
   646
    SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
slouken@2241
   647
    return 0;
slouken@2244
   648
  error:
slouken@2244
   649
    return 1;
slouken@2226
   650
slouken@2226
   651
}
slouken@2226
   652
slouken@2226
   653
static int
slouken@2226
   654
DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   655
                     const SDL_Rect * rect, int markDirty, void **pixels,
slouken@2226
   656
                     int *pitch)
slouken@2226
   657
{
slouken@2737
   658
    DirectFB_TextureData *texturedata =
slouken@2737
   659
        (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   660
    DFBResult ret;
slouken@2226
   661
slouken@2737
   662
    if (markDirty) {
slouken@2737
   663
        SDL_AddDirtyRect(&texturedata->dirty, rect);
slouken@2226
   664
    }
slouken@2226
   665
slouken@2737
   666
    if (texturedata->display) {
slouken@2737
   667
        void *fdata;
slouken@2737
   668
        int fpitch;
slouken@2226
   669
slouken@2737
   670
        SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
slouken@2737
   671
                                                    DSLF_WRITE | DSLF_READ,
slouken@2737
   672
                                                    &fdata, &fpitch));
slouken@2737
   673
        *pitch = fpitch;
slouken@2737
   674
        *pixels = fdata;
slouken@2737
   675
    } else {
slouken@2737
   676
        *pixels =
slouken@2737
   677
            (void *) ((Uint8 *) texturedata->pixels +
slouken@2737
   678
                      rect->y * texturedata->pitch +
slouken@2737
   679
                      rect->x * SDL_BYTESPERPIXEL(texture->format));
slouken@2737
   680
        *pitch = texturedata->pitch;
slouken@2737
   681
    }
slouken@2226
   682
    return 0;
slouken@2737
   683
slouken@2226
   684
  error:
slouken@2226
   685
    return -1;
slouken@2226
   686
}
slouken@2226
   687
slouken@2226
   688
static void
slouken@2226
   689
DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   690
{
slouken@2737
   691
    DirectFB_TextureData *texturedata =
slouken@2737
   692
        (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   693
slouken@2737
   694
    if (texturedata->display) {
slouken@2737
   695
        texturedata->surface->Unlock(texturedata->surface);
slouken@2737
   696
        texturedata->pixels = NULL;
slouken@2737
   697
    }
slouken@2226
   698
}
slouken@2226
   699
slouken@2226
   700
static void
slouken@2226
   701
DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   702
                      int numrects, const SDL_Rect * rects)
slouken@2226
   703
{
slouken@2737
   704
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2737
   705
    int i;
slouken@2737
   706
slouken@2737
   707
    for (i = 0; i < numrects; ++i) {
slouken@2737
   708
        SDL_AddDirtyRect(&data->dirty, &rects[i]);
slouken@2737
   709
    }
slouken@2226
   710
}
slouken@2226
   711
slouken@2226
   712
static int
slouken@2226
   713
DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
slouken@2226
   714
                    Uint8 a, const SDL_Rect * rect)
slouken@2226
   715
{
slouken@2226
   716
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
slouken@2226
   717
    DFBResult ret;
slouken@2226
   718
slouken@2226
   719
    SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
slouken@2226
   720
    SDL_DFB_CHECKERR(data->surface->
slouken@2226
   721
                     FillRectangle(data->surface, rect->x, rect->y, rect->w,
slouken@2226
   722
                                   rect->h));
slouken@2226
   723
slouken@2226
   724
    return 0;
slouken@2226
   725
  error:
slouken@2226
   726
    return -1;
slouken@2226
   727
}
slouken@2226
   728
slouken@2226
   729
static int
slouken@2226
   730
DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@2226
   731
                    const SDL_Rect * srcrect, const SDL_Rect * dstrect)
slouken@2226
   732
{
slouken@2226
   733
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
slouken@2226
   734
    DirectFB_TextureData *texturedata =
slouken@2226
   735
        (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   736
    DFBResult ret;
slouken@2226
   737
slouken@2737
   738
    if (texturedata->display) {
slouken@2226
   739
        int px, py;
slouken@2226
   740
        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@2737
   741
        SDL_DFB_WINDOWDATA(window);
slouken@2737
   742
        SDL_VideoDisplay *display = texturedata->display;
slouken@2226
   743
        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
slouken@2226
   744
slouken@2737
   745
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   746
                         SetSourceRectangle(dispdata->vidlayer, srcrect->x,
slouken@2226
   747
                                            srcrect->y, srcrect->w,
slouken@2226
   748
                                            srcrect->h));
slouken@2226
   749
        windata->window->GetPosition(windata->window, &px, &py);
slouken@2737
   750
        SDL_DFB_CHECKERR(dispdata->vidlayer->
slouken@2737
   751
                         SetScreenRectangle(dispdata->vidlayer,
slouken@2226
   752
                                            px + dstrect->x, py + dstrect->y,
slouken@2226
   753
                                            dstrect->w, dstrect->h));
slouken@2226
   754
    } else {
slouken@2226
   755
        DFBRectangle sr, dr;
slouken@2226
   756
        DFBSurfaceBlittingFlags flags = 0;
slouken@2226
   757
slouken@2737
   758
        if (texturedata->dirty.list) {
slouken@2737
   759
            SDL_DirtyRect *dirty;
slouken@2737
   760
            void *pixels;
slouken@2737
   761
            int bpp = SDL_BYTESPERPIXEL(texture->format);
slouken@2737
   762
            int pitch = texturedata->pitch;
slouken@2226
   763
slouken@2737
   764
            for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
slouken@2737
   765
                SDL_Rect *rect = &dirty->rect;
slouken@2737
   766
                pixels =
slouken@2737
   767
                    (void *) ((Uint8 *) texturedata->pixels +
slouken@2737
   768
                              rect->y * pitch + rect->x * bpp);
slouken@2737
   769
                DirectFB_UpdateTexture(renderer, texture, rect,
slouken@2737
   770
                                       texturedata->pixels,
slouken@2737
   771
                                       texturedata->pitch);
slouken@2737
   772
            }
slouken@2737
   773
            SDL_ClearDirtyRects(&texturedata->dirty);
slouken@2737
   774
        }
slouken@2737
   775
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
slouken@2737
   776
        SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface,
slouken@2737
   777
                                                         texturedata->
slouken@2737
   778
                                                         render_options));
slouken@2737
   779
#endif
slouken@2737
   780
slouken@2737
   781
        SDLtoDFBRect(srcrect, &sr);
slouken@2737
   782
        SDLtoDFBRect(dstrect, &dr);
slouken@2226
   783
slouken@2226
   784
        if (texture->
slouken@2226
   785
            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
slouken@2226
   786
        {
slouken@2721
   787
            Uint8 alpha = 0xFF;
slouken@2721
   788
            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
slouken@2226
   789
                alpha = texture->a;
slouken@2721
   790
                flags |= DSBLIT_SRC_PREMULTCOLOR;
slouken@2721
   791
                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
slouken@2721
   792
                                                         0xFF, 0xFF, alpha));
slouken@2721
   793
            }
slouken@2721
   794
            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
slouken@2226
   795
                SDL_DFB_CHECKERR(data->surface->
slouken@2226
   796
                                 SetColor(data->surface, texture->r,
slouken@2226
   797
                                          texture->g, texture->b, alpha));
slouken@2721
   798
                /* Only works together .... */
slouken@2721
   799
                flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
slouken@2721
   800
            }
slouken@2226
   801
        }
slouken@2226
   802
slouken@2721
   803
        switch (texture->blendMode) {
slouken@2722
   804
        case SDL_TEXTUREBLENDMODE_NONE:
slouken@2737
   805
                                       /**< No blending */
slouken@2721
   806
            flags |= DSBLIT_NOFX;
slouken@2721
   807
            data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
slouken@2721
   808
            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
slouken@2721
   809
            break;
slouken@2722
   810
        case SDL_TEXTUREBLENDMODE_MASK:
slouken@2226
   811
            flags |= DSBLIT_BLEND_ALPHACHANNEL;
slouken@2721
   812
            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
slouken@2721
   813
            data->surface->SetDstBlendFunction(data->surface,
slouken@2721
   814
                                               DSBF_INVSRCALPHA);
slouken@2721
   815
            break;
slouken@2722
   816
        case SDL_TEXTUREBLENDMODE_BLEND:
slouken@2721
   817
            flags |= DSBLIT_BLEND_ALPHACHANNEL;
slouken@2721
   818
            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
slouken@2721
   819
            data->surface->SetDstBlendFunction(data->surface,
slouken@2721
   820
                                               DSBF_INVSRCALPHA);
slouken@2721
   821
            break;
slouken@2722
   822
        case SDL_TEXTUREBLENDMODE_ADD:
slouken@2721
   823
            flags |= DSBLIT_BLEND_ALPHACHANNEL;
slouken@2721
   824
            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
slouken@2721
   825
            data->surface->SetDstBlendFunction(data->surface, DSBF_ONE);
slouken@2721
   826
            break;
slouken@2722
   827
        case SDL_TEXTUREBLENDMODE_MOD:
slouken@2721
   828
            flags |= DSBLIT_BLEND_ALPHACHANNEL;
slouken@2721
   829
            data->surface->SetSrcBlendFunction(data->surface, DSBF_DESTCOLOR);
slouken@2721
   830
            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
slouken@2721
   831
            break;
slouken@2226
   832
        }
slouken@2721
   833
slouken@2226
   834
        SDL_DFB_CHECKERR(data->surface->
slouken@2226
   835
                         SetBlittingFlags(data->surface, flags));
slouken@2737
   836
slouken@2226
   837
        if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
slouken@2226
   838
            SDL_DFB_CHECKERR(data->surface->
slouken@2737
   839
                             Blit(data->surface, texturedata->surface,
slouken@2737
   840
                                  &sr, dr.x, dr.y));
slouken@2226
   841
        } else {
slouken@2226
   842
            SDL_DFB_CHECKERR(data->surface->
slouken@2226
   843
                             StretchBlit(data->surface, texturedata->surface,
slouken@2226
   844
                                         &sr, &dr));
slouken@2226
   845
        }
slouken@2226
   846
    }
slouken@2226
   847
    return 0;
slouken@2226
   848
  error:
slouken@2226
   849
    return -1;
slouken@2226
   850
}
slouken@2226
   851
slouken@2226
   852
static void
slouken@2226
   853
DirectFB_RenderPresent(SDL_Renderer * renderer)
slouken@2226
   854
{
slouken@2226
   855
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
slouken@2226
   856
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@2226
   857
slouken@2226
   858
    DFBRectangle sr;
slouken@2226
   859
    DFBResult ret;
slouken@2226
   860
slouken@2226
   861
    sr.x = 0;
slouken@2226
   862
    sr.y = 0;
slouken@2226
   863
    sr.w = window->w;
slouken@2226
   864
    sr.h = window->h;
slouken@2226
   865
slouken@2226
   866
    /* Send the data to the display */
slouken@2226
   867
    SDL_DFB_CHECKERR(data->surface->
slouken@2791
   868
                     Flip(data->surface, NULL, data->flipflags));
slouken@2226
   869
slouken@2226
   870
    return;
slouken@2226
   871
  error:
slouken@2226
   872
    return;
slouken@2226
   873
}
slouken@2226
   874
slouken@2226
   875
static void
slouken@2226
   876
DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@2226
   877
{
slouken@2226
   878
    DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
slouken@2226
   879
slouken@2226
   880
    if (!data) {
slouken@2226
   881
        return;
slouken@2226
   882
    }
slouken@2226
   883
    SDL_DFB_RELEASE(data->palette);
slouken@2226
   884
    SDL_DFB_RELEASE(data->surface);
slouken@2721
   885
    if (data->display) {
slouken@2737
   886
        DFB_DisplayData *dispdata =
slouken@2737
   887
            (DFB_DisplayData *) data->display->driverdata;
slouken@2737
   888
        dispdata->vidIDinuse = 0;
slouken@2737
   889
        dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
slouken@2737
   890
                                                DLSCL_ADMINISTRATIVE);
slouken@2737
   891
        SDL_DFB_RELEASE(dispdata->vidlayer);
slouken@2721
   892
    }
slouken@2737
   893
    SDL_FreeDirtyRects(&data->dirty);
slouken@2737
   894
    SDL_DFB_FREE(data->pixels);
slouken@2226
   895
    SDL_free(data);
slouken@2226
   896
    texture->driverdata = NULL;
slouken@2226
   897
}
slouken@2226
   898
slouken@2226
   899
static void
slouken@2226
   900
DirectFB_DestroyRenderer(SDL_Renderer * renderer)
slouken@2226
   901
{
slouken@2226
   902
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
slouken@2226
   903
slouken@2226
   904
    if (data) {
slouken@2737
   905
        SDL_DFB_RELEASE(data->surface);
slouken@2226
   906
        SDL_free(data);
slouken@2226
   907
    }
slouken@2226
   908
    SDL_free(renderer);
slouken@2226
   909
}
slouken@2226
   910
slouken@2226
   911
/* vi: set ts=4 sw=4 expandtab: */