Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 MGA CRTC2 support by Thomas Jarosch - tomj@simonv.com
23 CRTC2 support is inspired by mplayer's dfbmga driver
24 written by Ville Syrj��<syrjala@sci.fi>
27 /* DirectFB video driver implementation.
38 #include <directfb_version.h>
41 #include "SDL_error.h"
42 #include "SDL_video.h"
43 #include "SDL_mouse.h"
44 #include "SDL_sysvideo.h"
45 #include "SDL_pixels_c.h"
46 #include "SDL_events_c.h"
47 #include "SDL_DirectFB_video.h"
48 #include "SDL_DirectFB_events.h"
49 #include "SDL_DirectFB_yuv.h"
51 /* The implementation dependent data for the window manager cursor */
57 /* Initialization/Query functions */
58 static int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat);
59 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
60 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
61 static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
63 static void DirectFB_VideoQuit(_THIS);
65 /* Hardware surface functions */
66 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface);
67 static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
68 static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface);
69 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface);
70 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface);
71 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
72 static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
73 SDL_Surface *dst, SDL_Rect *dstrect);
74 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
75 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
76 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface);
77 static int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor);
79 /* Various screen update functions available */
80 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
81 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects);
83 /* This is the rect EnumModes2 uses */
84 struct DirectFBEnumRect {
86 struct DirectFBEnumRect* next;
89 static struct DirectFBEnumRect *enumlist = NULL;
92 /* DirectFB driver bootstrap functions */
94 static int DirectFB_Available(void)
99 static void DirectFB_DeleteDevice(SDL_VideoDevice *device)
101 free(device->hidden);
105 static SDL_VideoDevice *DirectFB_CreateDevice(int devindex)
107 SDL_VideoDevice *device;
109 /* Initialize all variables that we clean on shutdown */
110 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
113 memset (device, 0, (sizeof *device));
114 device->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof (*device->hidden));
116 if (device == NULL || device->hidden == NULL)
125 memset (device->hidden, 0, sizeof (*device->hidden));
127 /* Set the function pointers */
128 device->VideoInit = DirectFB_VideoInit;
129 device->ListModes = DirectFB_ListModes;
130 device->SetVideoMode = DirectFB_SetVideoMode;
131 device->SetColors = DirectFB_SetColors;
132 device->UpdateRects = NULL;
133 device->CreateYUVOverlay = DirectFB_CreateYUVOverlay;
134 device->VideoQuit = DirectFB_VideoQuit;
135 device->AllocHWSurface = DirectFB_AllocHWSurface;
136 device->CheckHWBlit = DirectFB_CheckHWBlit;
137 device->FillHWRect = DirectFB_FillHWRect;
138 device->SetHWColorKey = DirectFB_SetHWColorKey;
139 device->SetHWAlpha = DirectFB_SetHWAlpha;
140 device->LockHWSurface = DirectFB_LockHWSurface;
141 device->UnlockHWSurface = DirectFB_UnlockHWSurface;
142 device->FlipHWSurface = DirectFB_FlipHWSurface;
143 device->FreeHWSurface = DirectFB_FreeHWSurface;
144 device->ShowWMCursor = DirectFB_ShowWMCursor;
145 device->SetCaption = NULL;
146 device->SetIcon = NULL;
147 device->IconifyWindow = NULL;
148 device->GrabInput = NULL;
149 device->GetWMInfo = NULL;
150 device->InitOSKeymap = DirectFB_InitOSKeymap;
151 device->PumpEvents = DirectFB_PumpEvents;
153 device->free = DirectFB_DeleteDevice;
158 VideoBootStrap DirectFB_bootstrap = {
159 "directfb", "DirectFB",
160 DirectFB_Available, DirectFB_CreateDevice
163 static DFBSurfacePixelFormat GetFormatForBpp (int bpp, IDirectFBDisplayLayer *layer)
165 DFBDisplayLayerConfig dlc;
166 int bytes = (bpp + 7) / 8;
168 layer->GetConfiguration (layer, &dlc);
170 if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
171 return dlc.pixelformat;
188 static DFBEnumerationResult EnumModesCallback (int width,
193 SDL_VideoDevice *this = (SDL_VideoDevice *)data;
194 struct DirectFBEnumRect *enumrect;
198 enumrect = calloc(1, sizeof(struct DirectFBEnumRect));
202 return DFENUM_CANCEL;
205 enumrect->r.w = (Uint16)width;
206 enumrect->r.h = (Uint16)height;
207 enumrect->next = enumlist;
214 struct private_hwdata {
215 IDirectFBSurface *surface;
216 IDirectFBPalette *palette;
219 void SetDirectFBerror (const char *function, DFBResult code)
221 const char *error = DirectFBErrorString (code);
224 SDL_SetError("%s: %s", function, error);
226 SDL_SetError("Unknown error code from %s", function);
229 static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
231 if (format->Rmask && format->Gmask && format->Bmask)
233 switch (format->BitsPerPixel)
239 if (format->Rmask == 0xF800 &&
240 format->Gmask == 0x07E0 &&
241 format->Bmask == 0x001F)
246 if (format->Rmask == 0x7C00 &&
247 format->Gmask == 0x03E0 &&
248 format->Bmask == 0x001F)
249 return DSPF_ARGB1555;
253 if (format->Rmask == 0xFF0000 &&
254 format->Gmask == 0x00FF00 &&
255 format->Bmask == 0x0000FF)
260 if (format->Rmask == 0xFF0000 &&
261 format->Gmask == 0x00FF00 &&
262 format->Bmask == 0x0000FF)
264 if (format->Amask == 0xFF000000)
274 switch (format->BitsPerPixel)
279 return DSPF_ARGB1555;
292 static SDL_Palette *AllocatePalette(int size)
294 SDL_Palette *palette;
297 palette = calloc (1, sizeof(SDL_Palette));
304 colors = calloc (size, sizeof(SDL_Color));
311 palette->ncolors = size;
312 palette->colors = colors;
317 static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
319 format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
320 format->BitsPerPixel = format->BytesPerPixel = 0;
325 format->Amask = 0x000000FF;
329 format->Rmask = 0x00007C00;
330 format->Gmask = 0x000003E0;
331 format->Bmask = 0x0000001F;
335 format->Rmask = 0x0000F800;
336 format->Gmask = 0x000007E0;
337 format->Bmask = 0x0000001F;
341 format->Amask = 0; /* apps don't seem to like that: 0xFF000000; */
345 format->Rmask = 0x00FF0000;
346 format->Gmask = 0x0000FF00;
347 format->Bmask = 0x000000FF;
351 format->Rmask = 0x000000FF;
352 format->Gmask = 0x000000FF;
353 format->Bmask = 0x000000FF;
355 if (!format->palette)
356 format->palette = AllocatePalette(256);
360 fprintf (stderr, "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n", pixelformat);
364 format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
365 format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
371 int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
375 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
376 DFBCardCapabilities caps;
378 DFBGraphicsDeviceDescription caps;
380 DFBDisplayLayerConfig dlc;
381 struct DirectFBEnumRect *rect;
382 IDirectFB *dfb = NULL;
383 IDirectFBDisplayLayer *layer = NULL;
384 IDirectFBEventBuffer *events = NULL;
386 HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL;
387 HIDDEN->enable_mga_crtc2 = 0;
388 HIDDEN->mga_crtc2_stretch_overscan = 1;
390 ret = DirectFBInit (NULL, NULL);
393 SetDirectFBerror ("DirectFBInit", ret);
397 ret = DirectFBCreate (&dfb);
400 SetDirectFBerror ("DirectFBCreate", ret);
404 ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
407 SetDirectFBerror ("dfb->GetDisplayLayer", ret);
411 ret = dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events);
414 SetDirectFBerror ("dfb->CreateEventBuffer", ret);
418 layer->EnableCursor (layer, 1);
420 /* Query layer configuration to determine the current mode and pixelformat */
421 layer->GetConfiguration (layer, &dlc);
423 /* If current format is not supported use LUT8 as the default */
424 if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
425 DFBToSDLPixelFormat (DSPF_LUT8, vformat);
427 /* Enumerate the available fullscreen modes */
428 ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
431 SetDirectFBerror ("dfb->EnumVideoModes", ret);
435 HIDDEN->modelist = calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
436 if (!HIDDEN->modelist)
442 for (i = 0, rect = enumlist; rect; ++i, rect = rect->next )
444 HIDDEN->modelist[i] = &rect->r;
447 HIDDEN->modelist[i] = NULL;
450 /* Query card capabilities to get the video memory size */
451 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
452 dfb->GetCardCapabilities (dfb, &caps);
454 dfb->GetDeviceDescription (dfb, &caps);
457 this->info.wm_available = 1;
458 this->info.hw_available = 1;
459 this->info.blit_hw = 1;
460 this->info.blit_hw_CC = 1;
461 this->info.blit_hw_A = 1;
462 this->info.blit_fill = 1;
463 this->info.video_mem = caps.video_memory / 1024;
465 HIDDEN->initialized = 1;
467 HIDDEN->layer = layer;
468 HIDDEN->eventbuffer = events;
470 if (getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
471 HIDDEN->enable_mga_crtc2 = 1;
473 if (HIDDEN->enable_mga_crtc2)
475 DFBDisplayLayerConfig dlc;
476 DFBDisplayLayerConfigFlags failed;
478 ret = dfb->GetDisplayLayer (dfb, 2, &HIDDEN->c2layer);
481 SetDirectFBerror ("dfb->GetDisplayLayer(CRTC2)", ret);
485 ret = HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer, DLSCL_EXCLUSIVE);
488 SetDirectFBerror ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
492 ret = HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer, DLSCL_EXCLUSIVE);
495 SetDirectFBerror ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
499 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
501 /* Init the surface here as it got a fixed size */
502 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
503 dlc.buffermode = DLBM_BACKVIDEO;
504 dlc.pixelformat = DSPF_RGB32;
506 ret = HIDDEN->c2layer->TestConfiguration( HIDDEN->c2layer, &dlc, &failed );
509 SetDirectFBerror ("c2layer->TestConfiguration", ret);
513 ret = HIDDEN->c2layer->SetConfiguration( HIDDEN->c2layer, &dlc );
516 SetDirectFBerror ("c2layer->SetConfiguration", ret);
520 ret = HIDDEN->c2layer->GetSurface( HIDDEN->c2layer, &HIDDEN->c2frame );
523 SetDirectFBerror ("c2layer->GetSurface", ret);
527 HIDDEN->c2framesize.x = 0;
528 HIDDEN->c2framesize.y = 0;
529 HIDDEN->c2frame->GetSize( HIDDEN->c2frame, &HIDDEN->c2framesize.w, &HIDDEN->c2framesize.h);
531 HIDDEN->c2frame->SetBlittingFlags( HIDDEN->c2frame, DSBLIT_NOFX );
532 HIDDEN->c2frame->SetColor( HIDDEN->c2frame, 0, 0, 0, 0xff );
535 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
536 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
537 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
538 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
539 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
541 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
543 /* Check if overscan is possibly set */
544 if (getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
547 if (sscanf(getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
548 if (overscan > 0 && overscan < 2)
549 HIDDEN->mga_crtc2_stretch_overscan = overscan;
552 #ifdef DIRECTFB_CRTC2_DEBUG
553 printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
561 events->Release (events);
564 HIDDEN->c2frame->Release (HIDDEN->c2frame);
567 HIDDEN->c2layer->Release (HIDDEN->c2layer);
570 layer->Release (layer);
578 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
580 if (flags & SDL_FULLSCREEN)
581 return HIDDEN->modelist;
583 if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
584 return (SDL_Rect**) -1;
589 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
592 DFBSurfaceDescription dsc;
593 DFBSurfacePixelFormat pixelformat;
594 IDirectFBSurface *surface;
596 fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
597 width, height, bpp, flags);
599 flags |= SDL_FULLSCREEN;
601 /* Release previous primary surface */
602 if (current->hwdata && current->hwdata->surface)
604 current->hwdata->surface->Release (current->hwdata->surface);
605 current->hwdata->surface = NULL;
607 /* And its palette if present */
608 if (current->hwdata->palette)
610 current->hwdata->palette->Release (current->hwdata->palette);
611 current->hwdata->palette = NULL;
614 else if (!current->hwdata)
616 /* Allocate the hardware acceleration data */
617 current->hwdata = (struct private_hwdata *) calloc (1, sizeof(*current->hwdata));
618 if (!current->hwdata)
625 /* Set cooperative level depending on flag SDL_FULLSCREEN */
626 if (flags & SDL_FULLSCREEN)
628 ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
629 if (ret && !HIDDEN->enable_mga_crtc2)
631 DirectFBError ("dfb->SetCooperativeLevel", ret);
632 flags &= ~SDL_FULLSCREEN;
636 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
639 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
642 if (flags & SDL_FULLSCREEN)
644 flags &= ~SDL_FULLSCREEN;
645 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
646 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
651 SetDirectFBerror ("dfb->SetVideoMode", ret);
656 /* Create primary surface */
657 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
658 dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
659 dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
661 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
662 if (ret && (flags & SDL_DOUBLEBUF))
664 /* Try without double buffering */
665 dsc.caps &= ~DSCAPS_FLIPPING;
666 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
670 SetDirectFBerror ("dfb->CreateSurface", ret);
676 current->flags = SDL_HWSURFACE | SDL_PREALLOC;
678 if (flags & SDL_FULLSCREEN)
680 current->flags |= SDL_FULLSCREEN;
681 this->UpdateRects = DirectFB_DirectUpdate;
684 this->UpdateRects = DirectFB_WindowedUpdate;
686 if (dsc.caps & DSCAPS_FLIPPING)
687 current->flags |= SDL_DOUBLEBUF;
689 surface->GetPixelFormat (surface, &pixelformat);
691 DFBToSDLPixelFormat (pixelformat, current->format);
693 /* Get the surface palette (if supported) */
694 if (DFB_PIXELFORMAT_IS_INDEXED( pixelformat ))
696 surface->GetPalette (surface, ¤t->hwdata->palette);
698 current->flags |= SDL_HWPALETTE;
701 current->hwdata->surface = surface;
703 /* MGA CRTC2 stuff */
704 if (HIDDEN->enable_mga_crtc2)
706 /* no stretching if c2ssize == c2framesize */
707 HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0;
708 HIDDEN->c2ssize.w = width;
709 HIDDEN->c2ssize.h = height;
711 HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0;
712 HIDDEN->c2dsize.w = width;
713 HIDDEN->c2dsize.h = height;
715 HIDDEN->mga_crtc2_stretch = 0;
717 if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
719 /* Normally assume a picture aspect ratio of 4:3 */
720 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
722 for (i = 1; i < 20; i++)
724 for (j = 1; j < 10; j++)
726 if ((float)width/(float)i*(float)j == height)
738 #ifdef DIRECTFB_CRTC2_DEBUG
739 printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
740 printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
743 /* don't stretch only slightly smaller/larger images */
744 if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
746 while ((float)HIDDEN->c2dsize.w < (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && (float)HIDDEN->c2dsize.h < (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
748 HIDDEN->c2dsize.w+=zoom_aspect_x;
749 HIDDEN->c2dsize.h+=zoom_aspect_y;
753 HIDDEN->c2dsize.w-=zoom_aspect_x;
754 HIDDEN->c2dsize.h-=zoom_aspect_y;
756 #ifdef DIRECTFB_CRTC2_DEBUG
757 printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
760 HIDDEN->mga_crtc2_stretch = 1;
762 else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95)
764 while ((float)HIDDEN->c2dsize.w > (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || (float)HIDDEN->c2dsize.h > (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
766 HIDDEN->c2dsize.w-=zoom_aspect_x;
767 HIDDEN->c2dsize.h-=zoom_aspect_y;
770 #ifdef DIRECTFB_CRTC2_DEBUG
771 printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
774 HIDDEN->mga_crtc2_stretch = 1;
776 #ifdef DIRECTFB_CRTC2_DEBUG
777 printf("Not stretching image\n");
782 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
783 HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2;
785 HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2;
787 if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h)
788 HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2;
790 HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
792 #ifdef DIRECTFB_CRTC2_DEBUG
793 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
801 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface)
804 DFBSurfaceDescription dsc;
806 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
807 surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/
809 if (surface->w < 8 || surface->h < 8)
812 /* fill surface description */
813 dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
814 dsc.width = surface->w;
815 dsc.height = surface->h;
816 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
818 /* find the right pixelformat */
819 dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
820 if (dsc.pixelformat == DSPF_UNKNOWN)
823 /* Allocate the hardware acceleration data */
824 surface->hwdata = (struct private_hwdata *) calloc (1, sizeof(*surface->hwdata));
825 if (surface->hwdata == NULL)
831 /* Create the surface */
832 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface);
835 SetDirectFBerror ("dfb->CreateSurface", ret);
836 free (surface->hwdata);
837 surface->hwdata = NULL;
841 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
846 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface)
848 if (surface->hwdata && HIDDEN->initialized)
850 surface->hwdata->surface->Release (surface->hwdata->surface);
851 free (surface->hwdata);
852 surface->hwdata = NULL;
856 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
858 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
859 src->hwdata, dst->hwdata);*/
861 if (!src->hwdata || !dst->hwdata)
864 src->flags |= SDL_HWACCEL;
865 src->map->hw_blit = DirectFB_HWAccelBlit;
870 static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
871 SDL_Surface *dst, SDL_Rect *dstrect)
873 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
875 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
876 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
878 IDirectFBSurface *surface = dst->hwdata->surface;
880 if (src->flags & SDL_SRCCOLORKEY)
882 flags |= DSBLIT_SRC_COLORKEY;
883 DirectFB_SetHWColorKey (NULL, src, src->format->colorkey);
886 if (src->flags & SDL_SRCALPHA)
888 flags |= DSBLIT_BLEND_COLORALPHA;
889 surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha);
892 surface->SetBlittingFlags (surface, flags);
894 if (sr.w == dr.w && sr.h == dr.h)
895 surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y);
897 surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr);
902 static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
904 SDL_PixelFormat *fmt = dst->format;
905 IDirectFBSurface *surface = dst->hwdata->surface;
908 surface->SetColor (surface,
909 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
910 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
911 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF);
912 surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h);
917 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key)
919 SDL_PixelFormat *fmt = src->format;
920 IDirectFBSurface *surface = src->hwdata->surface;
922 if (fmt->BitsPerPixel == 8)
923 surface->SetSrcColorKeyIndex (surface, key);
926 surface->SetSrcColorKey (surface,
927 (key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
928 (key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
929 (key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift));
934 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
939 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
941 if (HIDDEN->enable_mga_crtc2)
943 int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0);
944 if (HIDDEN->mga_crtc2_stretch)
945 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
947 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
949 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
953 return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
956 static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface)
962 ret = surface->hwdata->surface->Lock (surface->hwdata->surface,
963 DSLF_WRITE, &data, &pitch);
966 SetDirectFBerror ("surface->Lock", ret);
970 surface->pixels = data;
971 surface->pitch = pitch;
976 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface)
978 surface->hwdata->surface->Unlock (surface->hwdata->surface);
979 surface->pixels = NULL;
982 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
984 if (HIDDEN->enable_mga_crtc2)
986 if (HIDDEN->mga_crtc2_stretch)
987 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
989 HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
991 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
995 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
999 int region_valid = 0;
1000 IDirectFBSurface *surface = this->screen->hwdata->surface;
1002 for (i=0; i<numrects; ++i)
1006 if ( ! rects[i].w ) /* Clipped? */
1009 x2 = rects[i].x + rects[i].w - 1;
1010 y2 = rects[i].y + rects[i].h - 1;
1014 if (rects[i].x < region.x1)
1015 region.x1 = rects[i].x;
1017 if (rects[i].y < region.y1)
1018 region.y1 = rects[i].y;
1028 region.x1 = rects[i].x;
1029 region.y1 = rects[i].y;
1039 if (HIDDEN->enable_mga_crtc2)
1041 if (HIDDEN->mga_crtc2_stretch)
1042 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
1044 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
1046 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
1049 surface->Flip (surface, ®ion, DSFLIP_WAITFORSYNC);
1053 int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
1055 IDirectFBPalette *palette = this->screen->hwdata->palette;
1060 if (firstcolor > 255)
1063 if (firstcolor + ncolors > 256)
1064 ncolors = 256 - firstcolor;
1069 DFBColor entries[ncolors];
1071 for (i=0; i<ncolors; i++)
1073 entries[i].a = 0xff;
1074 entries[i].r = colors[i].r;
1075 entries[i].g = colors[i].g;
1076 entries[i].b = colors[i].b;
1079 palette->SetEntries (palette, entries, ncolors, firstcolor);
1085 void DirectFB_VideoQuit(_THIS)
1087 struct DirectFBEnumRect *rect = enumlist;
1089 if (this->screen->hwdata)
1091 IDirectFBSurface *surface = this->screen->hwdata->surface;
1092 IDirectFBPalette *palette = this->screen->hwdata->palette;
1095 palette->Release (palette);
1098 surface->Release (surface);
1100 this->screen->hwdata->surface = NULL;
1101 this->screen->hwdata->palette = NULL;
1104 if (HIDDEN->c2frame)
1106 HIDDEN->c2frame->Release (HIDDEN->c2frame);
1107 HIDDEN->c2frame = NULL;
1110 if (HIDDEN->eventbuffer)
1112 HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer);
1113 HIDDEN->eventbuffer = NULL;
1116 if (HIDDEN->c2layer)
1118 HIDDEN->c2layer->Release (HIDDEN->c2layer);
1119 HIDDEN->c2layer = NULL;
1124 HIDDEN->layer->Release (HIDDEN->layer);
1125 HIDDEN->layer = NULL;
1130 HIDDEN->dfb->Release (HIDDEN->dfb);
1134 /* Free video mode list */
1135 if (HIDDEN->modelist)
1137 free (HIDDEN->modelist);
1138 HIDDEN->modelist = NULL;
1141 /* Free mode enumeration list */
1144 struct DirectFBEnumRect *next = rect->next;
1150 HIDDEN->initialized = 0;
1154 int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor)
1156 /* We can only hide or show the default cursor */
1157 if ( cursor == NULL )
1159 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00);
1163 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF);
1168 void DirectFB_FinalQuit(void)