OSDN Git Service

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