comparison src/video/directfb/SDL_DirectFB_video.c @ 2721:e82a0e3e9b0e

Date: Sun, 20 Jul 2008 22:34:37 +0200 From: Couriersud Subject: Updated DirectFB driver for SDL1.3 please find attached a patch for an updated directfb driver for SDL1.3. It does now - properly supported the new input api. - send unicode text events - support directfb windows - support multiple screens - support hardware YUV scaling for the first YUV texture created. - support hardware scaling for textures. - properly interpret streaming access - support software opengl if one manages to install the mesa directfb driver (broken/not broken in mesa svn) Within bugzilla (http://bugzilla.libsdl.org/show_bug.cgi?id=603) there is another patch which fixes a crash due to GL context creation. Kind regards, couriersud
author Sam Lantinga <slouken@libsdl.org>
date Tue, 26 Aug 2008 02:32:45 +0000
parents 1e690901ecd7
children 91f1706b27be
comparison
equal deleted inserted replaced
2720:4eb759edddf5 2721:e82a0e3e9b0e
21 21
22 SDL1.3 implementation by couriersud@arcor.de 22 SDL1.3 implementation by couriersud@arcor.de
23 23
24 */ 24 */
25 25
26 /* TODO: Various
27 * Add Mouse support from 1.2 directfb driver
28 * - Interface is defined in SDL_Mouse.c.h
29 * - Default Cursor automatically created
30 */
31 26
32 #include "SDL_config.h" 27 #include "SDL_config.h"
33 28
34 /* DirectFB video driver implementation. 29 /* DirectFB video driver implementation.
35 */ 30 */
139 #else 134 #else
140 device->SetDisplayGammaRamp = NULL; 135 device->SetDisplayGammaRamp = NULL;
141 device->GetDisplayGammaRamp = NULL; 136 device->GetDisplayGammaRamp = NULL;
142 #endif 137 #endif
143 device->PumpEvents = DirectFB_PumpEventsWindow; 138 device->PumpEvents = DirectFB_PumpEventsWindow;
144
145 device->CreateWindow = DirectFB_CreateWindow; 139 device->CreateWindow = DirectFB_CreateWindow;
146 device->CreateWindowFrom = DirectFB_CreateWindowFrom; 140 device->CreateWindowFrom = DirectFB_CreateWindowFrom;
147 device->SetWindowTitle = DirectFB_SetWindowTitle; 141 device->SetWindowTitle = DirectFB_SetWindowTitle;
148 device->SetWindowPosition = DirectFB_SetWindowPosition; 142 device->SetWindowPosition = DirectFB_SetWindowPosition;
149 device->SetWindowSize = DirectFB_SetWindowSize; 143 device->SetWindowSize = DirectFB_SetWindowSize;
297 291
298 SDL_VideoDisplay display; 292 SDL_VideoDisplay display;
299 DFB_DisplayData *dispdata; 293 DFB_DisplayData *dispdata;
300 DFB_DeviceData *devdata; 294 DFB_DeviceData *devdata;
301 SDL_DisplayMode mode; 295 SDL_DisplayMode mode;
302 SDL_Keyboard keyboard;
303 int i; 296 int i;
304 DFBResult ret; 297 DFBResult ret;
305 int tcw[DFB_MAX_SCREENS]; 298 int tcw[DFB_MAX_SCREENS];
306 int tch[DFB_MAX_SCREENS]; 299 int tch[DFB_MAX_SCREENS];
307
308 SDL_zero(keyboard);
309 300
310 SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL)); 301 SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
311 SDL_DFB_CHECKERR(DirectFBCreate(&dfb)); 302 SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
312 303
313 SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata)); 304 SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
323 SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen)); 314 SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
324 315
325 devdata->aux = i; 316 devdata->aux = i;
326 SDL_DFB_CHECKERR(screen-> 317 SDL_DFB_CHECKERR(screen->
327 EnumDisplayLayers(screen, &cbLayers, devdata)); 318 EnumDisplayLayers(screen, &cbLayers, devdata));
319 #if (DIRECTFB_MAJOR_VERSION >= 1)
328 screen->GetSize(screen, &tcw[i], &tch[i]); 320 screen->GetSize(screen, &tcw[i], &tch[i]);
321 #else
322 /* FIXME: this is only used to center windows
323 * Should be done otherwise, e.g. get surface from layer
324 */
325 tcw[i] = 800;
326 tch[i] = 600;
327 #endif
329 screen->Release(screen); 328 screen->Release(screen);
330 } 329 }
331 330
332 /* Query card capabilities */ 331 /* Query card capabilities */
333 332
367 dispdata->ch = tch[i]; 366 dispdata->ch = tch[i];
368 367
369 /* YUV - Video layer */ 368 /* YUV - Video layer */
370 369
371 dispdata->vidID = devdata->vidlayer[i]; 370 dispdata->vidID = devdata->vidlayer[i];
371 dispdata->vidIDinuse = 0;
372 372
373 SDL_zero(display); 373 SDL_zero(display);
374 374
375 display.desktop_mode = mode; 375 display.desktop_mode = mode;
376 display.current_mode = mode; 376 display.current_mode = mode;
398 _this->gl_data->gl_context = NULL; 398 _this->gl_data->gl_context = NULL;
399 #endif 399 #endif
400 400
401 DirectFB_AddRenderDriver(_this); 401 DirectFB_AddRenderDriver(_this);
402 DirectFB_InitMouse(_this); 402 DirectFB_InitMouse(_this);
403 DirectFB_InitKeyboard(_this);
403 //devdata->mouse = SDL_AddMouse(&mouse, -1); 404 //devdata->mouse = SDL_AddMouse(&mouse, -1);
404 devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
405 DirectFB_InitOSKeymap(_this);
406 405
407 return 0; 406 return 0;
408 407
409 408
410 error: 409 error:
450 dispdata->modelist = NULL; 449 dispdata->modelist = NULL;
451 } 450 }
452 // Done by core 451 // Done by core
453 //SDL_free(dispdata); 452 //SDL_free(dispdata);
454 } 453 }
455
456 //SDL_DFB_RELEASE(devdata->eventbuffer);
457 454
458 SDL_DFB_RELEASE(devdata->dfb); 455 SDL_DFB_RELEASE(devdata->dfb);
459 456
460 SDL_DelMouse(devdata->mouse); 457 SDL_DelMouse(devdata->mouse);
461 SDL_DelKeyboard(devdata->keyboard); 458 SDL_DelKeyboard(devdata->keyboard);
577 SDL_DFB_DEVICEDATA(_this); 574 SDL_DFB_DEVICEDATA(_this);
578 DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata; 575 DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
579 DFBDisplayLayerConfig config, rconfig; 576 DFBDisplayLayerConfig config, rconfig;
580 DFBDisplayLayerConfigFlags fail = 0; 577 DFBDisplayLayerConfigFlags fail = 0;
581 DFBResult ret; 578 DFBResult ret;
579 DFB_WindowData *win;
582 580
583 SDL_DFB_CHECKERR(data->layer-> 581 SDL_DFB_CHECKERR(data->layer->
584 SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE)); 582 SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
585 583
586 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config)); 584 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
587 config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_BUFFERMODE; 585 config.flags = DLCONF_WIDTH | DLCONF_HEIGHT; // | DLCONF_BUFFERMODE;
588 if (mode->format != SDL_PIXELFORMAT_UNKNOWN) { 586 if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
589 config.flags |= DLCONF_PIXELFORMAT; 587 config.flags |= DLCONF_PIXELFORMAT;
590 config.pixelformat = SDLToDFBPixelFormat(mode->format); 588 config.pixelformat = SDLToDFBPixelFormat(mode->format);
591 data->pixelformat = config.pixelformat; 589 data->pixelformat = config.pixelformat;
592 } 590 }
593 config.width = mode->w; 591 config.width = mode->w;
594 config.height = mode->h; 592 config.height = mode->h;
595 593
596 config.buffermode = DLBM_BACKVIDEO; 594 //config.buffermode = DLBM_BACKVIDEO;
597 595
598 //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer); 596 //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
599 597
600 data->layer->TestConfiguration(data->layer, &config, &fail); 598 data->layer->TestConfiguration(data->layer, &config, &fail);
601 if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) { 599 if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) {
612 /* Double check */ 610 /* Double check */
613 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig)); 611 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
614 612
615 if ((config.width != rconfig.width) || 613 if ((config.width != rconfig.width) ||
616 (config.height != rconfig.height) || 614 (config.height != rconfig.height) ||
617 (config.pixelformat != rconfig.pixelformat)) { 615 ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
616 && (config.pixelformat != rconfig.pixelformat))) {
618 SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h, 617 SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
619 mode->format); 618 mode->format);
620 return -1; 619 return -1;
621 } 620 }
621
622 data->pixelformat = rconfig.pixelformat;
623 data->cw = config.width;
624 data->ch = config.height;
625 SDL_CurrentDisplay.current_mode = *mode;
626
627 /*
628 * FIXME: video mode switch is currently broken
629 *
630 * DirectFB 1.2.0-rc1 even has a broken cursor after a switch
631 * The following code needs to be revisited whether it is still
632 * needed once the switch works again.
633 */
634
635 win = devdata->firstwin;
636
637 while (win) {
638 SDL_DFB_RELEASE(win->surface);
639 SDL_DFB_CHECKERR(win->window->GetSurface(win->window, &win->surface));
640 win = win->next;
641 }
642
622 643
623 return 0; 644 return 0;
624 error: 645 error:
625 return -1; 646 return -1;
626 } 647 }
678 x = 0; 699 x = 0;
679 y = 0; 700 y = 0;
680 } 701 }
681 702
682 desc.flags = 703 desc.flags =
683 DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_PIXELFORMAT | 704 DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS */ | DWDESC_PIXELFORMAT
705 |
684 DWDESC_SURFACE_CAPS; 706 DWDESC_SURFACE_CAPS;
707
708 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
709 /* Needed for 1.2 */
710 desc.flags |= DWDESC_POSX | DWDESC_POSY;
711 desc.posx = x;
712 desc.posy = y;
713 #else
685 if (!(window->flags & SDL_WINDOW_FULLSCREEN) 714 if (!(window->flags & SDL_WINDOW_FULLSCREEN)
686 && window->x != SDL_WINDOWPOS_UNDEFINED 715 && window->x != SDL_WINDOWPOS_UNDEFINED
687 && window->y != SDL_WINDOWPOS_UNDEFINED) { 716 && window->y != SDL_WINDOWPOS_UNDEFINED) {
688 desc.flags |= DWDESC_POSX | DWDESC_POSY; 717 desc.flags |= DWDESC_POSX | DWDESC_POSY;
689 desc.posx = x; 718 desc.posx = x;
690 desc.posy = y; 719 desc.posy = y;
691 } 720 }
721 #endif
692 722
693 desc.width = window->w; 723 desc.width = window->w;
694 desc.height = window->h; 724 desc.height = window->h;
695 desc.pixelformat = dispdata->pixelformat; 725 desc.pixelformat = dispdata->pixelformat;
696 desc.caps = 0; //DWCAPS_DOUBLEBUFFER; 726 desc.caps = 0; // DWCAPS_DOUBLEBUFFER;
697 desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE; //| DSCAPS_PREMULTIPLIED; 727 desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
698 728
699 /* Create the window. */ 729 /* Create the window. */
700 SDL_DFB_CHECKERR(dispdata->layer-> 730 SDL_DFB_CHECKERR(dispdata->layer->
701 CreateWindow(dispdata->layer, &desc, &windata->window)); 731 CreateWindow(dispdata->layer, &desc, &windata->window));
702 732
788 DirectFB_SetWindowPosition(_THIS, SDL_Window * window) 818 DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
789 { 819 {
790 SDL_DFB_DEVICEDATA(_this); 820 SDL_DFB_DEVICEDATA(_this);
791 SDL_DFB_WINDOWDATA(window); 821 SDL_DFB_WINDOWDATA(window);
792 SDL_DFB_DISPLAYDATA(_this, window); 822 SDL_DFB_DISPLAYDATA(_this, window);
793 823 int x, y;
794 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) 824
795 windata->window->MoveTo(windata->window, window->x, window->y); 825 if (window->y == SDL_WINDOWPOS_UNDEFINED)
826 y = 0;
827 else
828 y = window->y;
829
830 if (window->x == SDL_WINDOWPOS_UNDEFINED)
831 x = 0;
832 else
833 x = window->x;
834
835 if (window->flags & SDL_WINDOW_FULLSCREEN) {
836 x = 0;
837 y = 0;
838 }
839 //if (!(window->flags & SDL_WINDOW_FULLSCREEN))
840 windata->window->MoveTo(windata->window, x, y);
796 } 841 }
797 842
798 static void 843 static void
799 DirectFB_SetWindowSize(_THIS, SDL_Window * window) 844 DirectFB_SetWindowSize(_THIS, SDL_Window * window)
800 { 845 {
801 SDL_DFB_DEVICEDATA(_this); 846 int ret;
802 SDL_DFB_WINDOWDATA(window); 847 SDL_DFB_DEVICEDATA(_this);
803 SDL_DFB_DISPLAYDATA(_this, window); 848 SDL_DFB_WINDOWDATA(window);
804 849 SDL_DFB_DISPLAYDATA(_this, window);
805 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) 850
806 windata->window->Resize(windata->window, window->w, window->h); 851 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
807 } 852 int ch, cw;
853
854 // SDL_DFB_DEBUG("Resize %d %d %d %d\n", cw, ch, window->w, window->h);
855 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
856 SDL_DFB_CHECKERR(windata->window->
857 ResizeSurface(windata->window, window->w,
858 window->h));
859 #else
860 SDL_DFB_CHECKERR(windata->window->
861 Resize(windata->window, window->w, window->h));
862 #endif
863 SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h)); /* if a window manager should have decided otherwise */
864 }
865 error:
866 return;
867 }
868
808 static void 869 static void
809 DirectFB_ShowWindow(_THIS, SDL_Window * window) 870 DirectFB_ShowWindow(_THIS, SDL_Window * window)
810 { 871 {
811 SDL_DFB_DEVICEDATA(_this); 872 SDL_DFB_DEVICEDATA(_this);
812 SDL_DFB_WINDOWDATA(window); 873 SDL_DFB_WINDOWDATA(window);