PageRenderTime 43ms CodeModel.GetById 15ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/project/jni/sdl-1.3/src/video/directfb/SDL_DirectFB_video.c

https://github.com/aichunyu/FFPlayer
C | 423 lines | 304 code | 81 blank | 38 comment | 27 complexity | 7d787a4d385aa141b261fb27fd87cb65 MD5 | raw file
  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#include "SDL_config.h"
 22
 23#if SDL_VIDEO_DRIVER_DIRECTFB
 24
 25#include "SDL_DirectFB_video.h"
 26
 27#include "SDL_DirectFB_events.h"
 28/*
 29 * #include "SDL_DirectFB_keyboard.h"
 30 */
 31#include "SDL_DirectFB_modes.h"
 32#include "SDL_DirectFB_mouse.h"
 33#include "SDL_DirectFB_opengl.h"
 34#include "SDL_DirectFB_window.h"
 35#include "SDL_DirectFB_WM.h"
 36
 37
 38#include "SDL_config.h"
 39
 40/* DirectFB video driver implementation.
 41*/
 42
 43#include <fcntl.h>
 44#include <unistd.h>
 45#include <sys/mman.h>
 46
 47#include <directfb.h>
 48#include <directfb_version.h>
 49#include <directfb_strings.h>
 50
 51#include "SDL_video.h"
 52#include "SDL_mouse.h"
 53#include "../SDL_sysvideo.h"
 54#include "../SDL_pixels_c.h"
 55#include "../../events/SDL_events_c.h"
 56#include "SDL_DirectFB_video.h"
 57#include "SDL_DirectFB_events.h"
 58#include "SDL_DirectFB_render.h"
 59#include "SDL_DirectFB_mouse.h"
 60#include "SDL_DirectFB_shape.h"
 61
 62
 63#include "SDL_DirectFB_dyn.h"
 64
 65/* Initialization/Query functions */
 66static int DirectFB_VideoInit(_THIS);
 67static void DirectFB_VideoQuit(_THIS);
 68
 69static int DirectFB_Available(void);
 70static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
 71
 72VideoBootStrap DirectFB_bootstrap = {
 73    "directfb", "DirectFB",
 74    DirectFB_Available, DirectFB_CreateDevice
 75};
 76
 77static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
 78static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
 79static const DirectFBAccelerationMaskNames(acceleration_mask);
 80
 81/* DirectFB driver bootstrap functions */
 82
 83static int
 84DirectFB_Available(void)
 85{
 86    if (!SDL_DirectFB_LoadLibrary())
 87        return 0;
 88    SDL_DirectFB_UnLoadLibrary();
 89    return 1;
 90}
 91
 92static void
 93DirectFB_DeleteDevice(SDL_VideoDevice * device)
 94{
 95    SDL_DirectFB_UnLoadLibrary();
 96    SDL_DFB_FREE(device->driverdata);
 97    SDL_DFB_FREE(device);
 98}
 99
100static SDL_VideoDevice *
101DirectFB_CreateDevice(int devindex)
102{
103    SDL_VideoDevice *device;
104
105    if (!SDL_DirectFB_LoadLibrary())
106        return NULL;
107
108    /* Initialize all variables that we clean on shutdown */
109    SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice));
110
111    /* Set the function pointers */
112
113    /* Set the function pointers */
114    device->VideoInit = DirectFB_VideoInit;
115    device->VideoQuit = DirectFB_VideoQuit;
116    device->GetDisplayModes = DirectFB_GetDisplayModes;
117    device->SetDisplayMode = DirectFB_SetDisplayMode;
118    device->PumpEvents = DirectFB_PumpEventsWindow;
119    device->CreateWindow = DirectFB_CreateWindow;
120    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
121    device->SetWindowTitle = DirectFB_SetWindowTitle;
122    device->SetWindowIcon = DirectFB_SetWindowIcon;
123    device->SetWindowPosition = DirectFB_SetWindowPosition;
124    device->SetWindowSize = DirectFB_SetWindowSize;
125    device->ShowWindow = DirectFB_ShowWindow;
126    device->HideWindow = DirectFB_HideWindow;
127    device->RaiseWindow = DirectFB_RaiseWindow;
128    device->MaximizeWindow = DirectFB_MaximizeWindow;
129    device->MinimizeWindow = DirectFB_MinimizeWindow;
130    device->RestoreWindow = DirectFB_RestoreWindow;
131    device->SetWindowGrab = DirectFB_SetWindowGrab;
132    device->DestroyWindow = DirectFB_DestroyWindow;
133    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
134
135#if SDL_DIRECTFB_OPENGL
136    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
137    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
138    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
139
140    device->GL_CreateContext = DirectFB_GL_CreateContext;
141    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
142    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
143    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
144    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
145
146#endif
147
148	/* Shaped window support */
149	device->shape_driver.CreateShaper = DirectFB_CreateShaper;
150	device->shape_driver.SetWindowShape = DirectFB_SetWindowShape;
151	device->shape_driver.ResizeWindowShape = DirectFB_ResizeWindowShape;
152	
153    device->free = DirectFB_DeleteDevice;
154    
155    return device;
156  error:
157    if (device)
158        free(device);
159    return (0);
160}
161
162static void
163DirectFB_DeviceInformation(IDirectFB * dfb)
164{
165    DFBGraphicsDeviceDescription desc;
166    int n;
167
168    dfb->GetDeviceDescription(dfb, &desc);
169
170    SDL_DFB_LOG( "DirectFB Device Information");
171    SDL_DFB_LOG( "===========================");
172    SDL_DFB_LOG( "Name:           %s", desc.name);
173    SDL_DFB_LOG( "Vendor:         %s", desc.vendor);
174    SDL_DFB_LOG( "Driver Name:    %s", desc.driver.name);
175    SDL_DFB_LOG( "Driver Vendor:  %s", desc.driver.vendor);
176    SDL_DFB_LOG( "Driver Version: %d.%d", desc.driver.major,
177            desc.driver.minor);
178
179    SDL_DFB_LOG( "Video memoory:  %d", desc.video_memory);
180
181    SDL_DFB_LOG( "Blitting flags:");
182    for (n = 0; blitting_flags[n].flag; n++) {
183        if (desc.blitting_flags & blitting_flags[n].flag)
184            SDL_DFB_LOG( "    %s", blitting_flags[n].name);
185    }
186
187    SDL_DFB_LOG( "Drawing flags:");
188    for (n = 0; drawing_flags[n].flag; n++) {
189        if (desc.drawing_flags & drawing_flags[n].flag)
190            SDL_DFB_LOG( "    %s", drawing_flags[n].name);
191    }
192
193
194    SDL_DFB_LOG( "Acceleration flags:");
195    for (n = 0; acceleration_mask[n].mask; n++) {
196        if (desc.acceleration_mask & acceleration_mask[n].mask)
197            SDL_DFB_LOG( "    %s", acceleration_mask[n].name);
198    }
199
200
201}
202
203static int readBoolEnv(const char *env_name, int def_val)
204{
205    char *stemp;
206
207    stemp = SDL_getenv(env_name);
208    if (stemp)
209        return atoi(stemp);
210    else
211        return def_val;
212}
213
214static int
215DirectFB_VideoInit(_THIS)
216{
217    IDirectFB *dfb = NULL;
218    DFB_DeviceData *devdata = NULL;
219    DFBResult ret;
220
221    SDL_DFB_ALLOC_CLEAR(devdata, sizeof(*devdata));
222
223    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
224
225    /* avoid switching to the framebuffer when we
226     * are running X11 */
227    ret = readBoolEnv(DFBENV_USE_X11_CHECK , 1);
228    if (ret) {
229        if (SDL_getenv("DISPLAY"))
230            DirectFBSetOption("system", "x11");
231        else
232            DirectFBSetOption("disable-module", "x11input");
233    }
234
235	/* FIXME: Reenable as default once multi kbd/mouse interface is sorted out */
236	devdata->use_linux_input = readBoolEnv(DFBENV_USE_LINUX_INPUT, 0);       /* default: on */
237
238    if (!devdata->use_linux_input)
239    {
240		SDL_DFB_LOG("Disabling linxu input\n");    
241        DirectFBSetOption("disable-module", "linux_input");
242    }
243    
244    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
245
246    DirectFB_DeviceInformation(dfb);
247    
248    devdata->use_yuv_underlays = readBoolEnv(DFBENV_USE_YUV_UNDERLAY, 0);     /* default: off */
249    devdata->use_yuv_direct = readBoolEnv(DFBENV_USE_YUV_DIRECT, 0);      /* default is off! */
250
251    /* Create global Eventbuffer for axis events */
252    if (devdata->use_linux_input) {
253        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
254                                                     DFB_TRUE,
255                                                     &devdata->events));
256    } else {
257        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES
258                                                     /*DICAPS_ALL */ ,
259                                                     DFB_TRUE,
260                                                     &devdata->events));
261    }
262
263    /* simple window manager support */
264    devdata->has_own_wm = readBoolEnv(DFBENV_USE_WM, 0);
265
266    devdata->initialized = 1;
267
268    devdata->dfb = dfb;
269    devdata->firstwin = NULL;
270    devdata->grabbed_window = NULL;
271
272    _this->driverdata = devdata;
273
274    DirectFB_InitModes(_this);
275
276#if SDL_DIRECTFB_OPENGL
277    DirectFB_GL_Initialize(_this);
278#endif
279
280    DirectFB_InitMouse(_this);
281    DirectFB_InitKeyboard(_this);
282
283    return 0;
284
285
286  error:
287    SDL_DFB_FREE(devdata);
288    SDL_DFB_RELEASE(dfb);
289    return -1;
290}
291
292static void
293DirectFB_VideoQuit(_THIS)
294{
295    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
296
297    DirectFB_QuitModes(_this);
298    DirectFB_QuitKeyboard(_this);
299    DirectFB_QuitMouse(_this);
300
301    devdata->events->Reset(devdata->events);
302    SDL_DFB_RELEASE(devdata->events);
303    SDL_DFB_RELEASE(devdata->dfb);
304
305#if SDL_DIRECTFB_OPENGL
306    DirectFB_GL_Shutdown(_this);
307#endif
308
309    devdata->initialized = 0;
310}
311
312/* DirectFB driver general support functions */
313
314static const struct {
315    DFBSurfacePixelFormat dfb;
316    Uint32 sdl;
317} pixelformat_tab[] = 
318{
319    { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 },             /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
320    { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 },            /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
321    { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 },             /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
322    { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 },            /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
323    { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 },        /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
324    { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 },        /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
325    { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 },              /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
326    { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 },            /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
327    { DSPF_YV12, SDL_PIXELFORMAT_YV12 },                /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
328    { DSPF_I420,SDL_PIXELFORMAT_IYUV },                 /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
329    { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
330    { DSPF_UYVY, SDL_PIXELFORMAT_UYVY },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
331    { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 },            /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
332#if (ENABLE_LUT8)
333    { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 },              /* 8 bit LUT (8 bit color and alpha lookup from palette) */
334#endif
335
336#if (DFB_VERSION_ATLEAST(1,2,0))
337    { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 },            /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
338#else
339    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
340#endif
341
342    /* Pfff ... nonmatching formats follow */    
343    
344    { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN },           /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
345 	{ DSPF_A8, SDL_PIXELFORMAT_UNKNOWN },               /* 	8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
346 	{ DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN },            /* 	32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
347 	{ DSPF_A1, SDL_PIXELFORMAT_UNKNOWN },               /* 	1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
348 	{ DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
349 	{ DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN },             /* 	16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
350 	{ DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
351 	{ DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
352 	{ DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
353 	{ DSPF_A4, SDL_PIXELFORMAT_UNKNOWN },               /* 	4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
354 	{ DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN },         /* 	1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
355 	{ DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN },         /* 	6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
356 	{ DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN },            /* 	6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
357 	{ DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN },             /* 	2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
358
359#if (DFB_VERSION_ATLEAST(1,3,0))
360 	{ DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN },         /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
361#endif
362
363#if (DFB_VERSION_ATLEAST(1,4,3))
364 	{ DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
365 	{ DSPF_YUV444P, SDL_PIXELFORMAT_UNKNOWN },          /* 	24 bit full YUV planar (8 bit Y plane followed by an 8 bit Cb and an 8 bit Cr plane) */
366 	{ DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN },         /* 	24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
367 	{ DSPF_AVYU, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0) */
368 	{ DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN },              /* 	24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0)  */
369#endif
370 	
371    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
372    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
373    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB }, 
374    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
375    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
376    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
377    { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
378    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
379    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
380    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
381    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
382    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
383    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
384    { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU },                        /**< Packed mode: Y0+V0+Y1+U0 (1 pla	*/
385};
386
387Uint32
388DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
389{
390    int i;
391    
392    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
393        if (pixelformat_tab[i].dfb == pixelformat)
394        {
395            return pixelformat_tab[i].sdl;
396        }
397    return SDL_PIXELFORMAT_UNKNOWN;
398}
399
400DFBSurfacePixelFormat
401DirectFB_SDLToDFBPixelFormat(Uint32 format)
402{
403    int i;
404    
405    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
406        if (pixelformat_tab[i].sdl == format)
407        {
408            return pixelformat_tab[i].dfb;
409        }
410    return DSPF_UNKNOWN;
411}
412
413void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo* ri)
414{
415	int i, j;
416
417    for (i=0, j=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
418    	if (pixelformat_tab[i].sdl != SDL_PIXELFORMAT_UNKNOWN)
419    		ri->texture_formats[j++] = pixelformat_tab[i].sdl;
420    ri->num_texture_formats = j;
421}
422
423#endif /* SDL_VIDEO_DRIVER_DIRECTFB */