src/video/directfb/SDL_DirectFB_video.h
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 30 Oct 2016 21:01:33 +0100
changeset 10563 e3d84016cb79
parent 9998 f67cf37e9cd4
child 10737 3406a0f8b041
permissions -rw-r--r--
Fixed outdated info in README.
slouken@167
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
slouken@167
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@167
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@167
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@167
    20
*/
slouken@5199
    21
icculus@8093
    22
#include "../../SDL_internal.h"
slouken@167
    23
slouken@167
    24
#ifndef _SDL_DirectFB_video_h
slouken@167
    25
#define _SDL_DirectFB_video_h
slouken@167
    26
slouken@167
    27
#include <directfb.h>
slouken@2226
    28
#include <directfb_version.h>
slouken@2226
    29
slouken@5199
    30
#include "../SDL_sysvideo.h"
slouken@5199
    31
#include "SDL_scancode.h"
slouken@5199
    32
#include "SDL_render.h"
slouken@2226
    33
slouken@6986
    34
#include "SDL_log.h"
slouken@6986
    35
slouken@7191
    36
#define DFB_VERSIONNUM(X, Y, Z)                     \
slouken@7191
    37
    ((X)*1000 + (Y)*100 + (Z))
couriersud@3037
    38
couriersud@3037
    39
#define DFB_COMPILEDVERSION \
slouken@7191
    40
    DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
slouken@2226
    41
couriersud@3037
    42
#define DFB_VERSION_ATLEAST(X, Y, Z) \
slouken@7191
    43
    (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
couriersud@3037
    44
couriersud@3037
    45
#if (DFB_VERSION_ATLEAST(1,0,0))
slouken@5488
    46
#ifdef SDL_VIDEO_OPENGL
slouken@3040
    47
#define SDL_DIRECTFB_OPENGL 1
slouken@5488
    48
#endif
couriersud@3037
    49
#else
slouken@3040
    50
#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
slouken@2226
    51
#endif
slouken@2226
    52
slouken@5199
    53
/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
slouken@7191
    54
 * in case we see this again ...
slouken@5199
    55
 */
slouken@5199
    56
slouken@7191
    57
#define USE_MULTI_API   (0)
slouken@5199
    58
slouken@5199
    59
/* Support for LUT8/INDEX8 pixel format.
slouken@5199
    60
 * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
slouken@5199
    61
 * occurred.
slouken@5199
    62
 */
slouken@5199
    63
slouken@5199
    64
#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
slouken@7191
    65
#define ENABLE_LUT8     (0)
slouken@5199
    66
#else
slouken@7191
    67
#define ENABLE_LUT8     (1)
slouken@2226
    68
#endif
slouken@167
    69
slouken@5199
    70
#define DIRECTFB_DEBUG 1
slouken@167
    71
slouken@7191
    72
#define DFBENV_USE_YUV_UNDERLAY     "SDL_DIRECTFB_YUV_UNDERLAY"     /* Default: off */
slouken@7191
    73
#define DFBENV_USE_YUV_DIRECT       "SDL_DIRECTFB_YUV_DIRECT"       /* Default: off */
slouken@7191
    74
#define DFBENV_USE_X11_CHECK        "SDL_DIRECTFB_X11_CHECK"        /* Default: on  */
slouken@7191
    75
#define DFBENV_USE_LINUX_INPUT      "SDL_DIRECTFB_LINUX_INPUT"      /* Default: on  */
slouken@7191
    76
#define DFBENV_USE_WM               "SDL_DIRECTFB_WM"       /* Default: off  */
slouken@2226
    77
slouken@4636
    78
#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
slouken@7719
    79
#define SDL_DFB_FREE(x) do { SDL_free((x)); (x) = NULL; } while (0)
couriersud@3038
    80
#define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
slouken@2226
    81
slouken@2226
    82
#define SDL_DFB_CONTEXT "SDL_DirectFB"
slouken@2226
    83
slouken@6986
    84
#define SDL_DFB_ERR(x...) SDL_LogError(SDL_LOG_CATEGORY_ERROR, x)
slouken@5199
    85
slouken@5199
    86
#if (DIRECTFB_DEBUG)
slouken@6986
    87
#define SDL_DFB_LOG(x...) SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, x)
slouken@5199
    88
slouken@6986
    89
#define SDL_DFB_DEBUG(x...) SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, x)
slouken@5199
    90
slouken@7860
    91
static SDL_INLINE DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
slouken@7191
    92
    if (ret != DFB_OK) {
slouken@7191
    93
        SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
slouken@7191
    94
        SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
slouken@7191
    95
    }
slouken@7191
    96
    return ret;
slouken@4636
    97
}
slouken@4636
    98
slouken@5199
    99
#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
slouken@5199
   100
#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
slouken@4636
   101
slouken@5199
   102
#else
slouken@4636
   103
slouken@5199
   104
#define SDL_DFB_CHECK(x...) x
slouken@5199
   105
#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
slouken@5199
   106
#define SDL_DFB_LOG(x...) do {} while (0)
slouken@5199
   107
#define SDL_DFB_DEBUG(x...) do {} while (0)
slouken@2226
   108
slouken@5199
   109
#endif
slouken@5199
   110
slouken@2226
   111
slouken@2226
   112
#define SDL_DFB_CALLOC(r, n, s) \
slouken@5199
   113
     do {                                           \
slouken@5199
   114
          r = SDL_calloc (n, s);                    \
slouken@5199
   115
          if (!(r)) {                               \
slouken@7191
   116
               SDL_DFB_ERR("Out of memory");        \
slouken@5199
   117
               SDL_OutOfMemory();                   \
slouken@7191
   118
               goto error;                          \
slouken@5199
   119
          }                                         \
slouken@2226
   120
     } while (0)
slouken@167
   121
slouken@5199
   122
#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
slouken@5199
   123
slouken@167
   124
/* Private display data */
slouken@167
   125
couriersud@3023
   126
#define SDL_DFB_DEVICEDATA(dev)  DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
slouken@2226
   127
slouken@2226
   128
#define DFB_MAX_SCREENS 10
slouken@2226
   129
slouken@5199
   130
typedef struct _DFB_KeyboardData DFB_KeyboardData;
slouken@5199
   131
struct _DFB_KeyboardData
slouken@5199
   132
{
slouken@7191
   133
    const SDL_Scancode  *map;       /* keyboard scancode map */
slouken@7191
   134
    int             map_size;   /* size of map */
slouken@7191
   135
    int             map_adjust; /* index adjust */
slouken@7191
   136
    int             is_generic; /* generic keyboard */
slouken@5199
   137
    int id;
slouken@5199
   138
};
slouken@5199
   139
slouken@2226
   140
typedef struct _DFB_DeviceData DFB_DeviceData;
slouken@2226
   141
struct _DFB_DeviceData
slouken@167
   142
{
slouken@1895
   143
    int initialized;
slouken@167
   144
slouken@7191
   145
    IDirectFB           *dfb;
slouken@7191
   146
    int                 num_mice;
slouken@7191
   147
    int                 mouse_id[0x100];
slouken@7191
   148
    int                 num_keyboard;
slouken@7191
   149
    DFB_KeyboardData    keyboard[10];
slouken@7191
   150
    SDL_Window          *firstwin;
icculus@728
   151
slouken@7191
   152
    int                 use_yuv_underlays;
slouken@7191
   153
    int                 use_yuv_direct;
slouken@7191
   154
    int                 use_linux_input;
slouken@7191
   155
    int                 has_own_wm;
slouken@5199
   156
slouken@2226
   157
slouken@7191
   158
    /* window grab */
slouken@7191
   159
    SDL_Window          *grabbed_window;
slouken@167
   160
slouken@2737
   161
    /* global events */
slouken@2737
   162
    IDirectFBEventBuffer *events;
slouken@2226
   163
};
slouken@478
   164
slouken@5199
   165
Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
slouken@5199
   166
DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
slouken@5199
   167
void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
slouken@5199
   168
slouken@5199
   169
slouken@167
   170
#endif /* _SDL_DirectFB_video_h */