src/video/directfb/SDL_DirectFB_video.c
changeset 728 5446a009107a
parent 546 0009aadb3d01
child 732 d18e2b224d0e
     1.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Wed Oct 01 07:52:33 2003 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Fri Oct 03 18:26:39 2003 +0000
     1.3 @@ -18,6 +18,10 @@
     1.4  
     1.5  	Sam Lantinga
     1.6  	slouken@libsdl.org
     1.7 +
     1.8 +	MGA CRTC2 support by Thomas Jarosch - tomj@simonv.com
     1.9 +	CRTC2 support is inspired by mplayer's dfbmga driver
    1.10 +	written by Ville Syrj��<syrjala@sci.fi>
    1.11  */
    1.12  
    1.13  #ifdef SAVE_RCSID
    1.14 @@ -372,6 +376,9 @@
    1.15    IDirectFBDisplayLayer   *layer  = NULL;
    1.16    IDirectFBEventBuffer    *events = NULL;
    1.17  
    1.18 +  HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL;
    1.19 +  HIDDEN->enable_mga_crtc2 = 0;
    1.20 +  HIDDEN->mga_crtc2_stretch_overscan = 1;
    1.21  
    1.22    ret = DirectFBInit (NULL, NULL);
    1.23    if (ret)
    1.24 @@ -449,12 +456,93 @@
    1.25    HIDDEN->layer       = layer;
    1.26    HIDDEN->eventbuffer = events;
    1.27  
    1.28 +  if (getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
    1.29 +    HIDDEN->enable_mga_crtc2 = 1;
    1.30 +  
    1.31 +  if (HIDDEN->enable_mga_crtc2)
    1.32 +    {
    1.33 +      ret = dfb->GetDisplayLayer (dfb, 2, &HIDDEN->c2layer);
    1.34 +      if (ret)
    1.35 +        {
    1.36 +          SetDirectFBerror ("dfb->GetDisplayLayer(CRTC2)", ret);
    1.37 +          goto error;
    1.38 +        }
    1.39 +
    1.40 +      ret = HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer, DLSCL_EXCLUSIVE);
    1.41 +      if (ret)
    1.42 +        {
    1.43 +          SetDirectFBerror ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
    1.44 +          goto error;
    1.45 +        }
    1.46 + 
    1.47 +      ret = HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer, DLSCL_EXCLUSIVE);
    1.48 +      if (ret)
    1.49 +        {
    1.50 +          SetDirectFBerror ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
    1.51 +          goto error;
    1.52 +        }
    1.53 +
    1.54 +      HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
    1.55 +
    1.56 +      /* Init the surface here as it got a fixed size */
    1.57 +      DFBDisplayLayerConfig      dlc;
    1.58 +      DFBDisplayLayerConfigFlags failed;
    1.59 +    
    1.60 +      dlc.flags      = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE | DLCONF_OPTIONS;
    1.61 +      dlc.buffermode = DLBM_BACKVIDEO;
    1.62 +      dlc.options    = DLOP_FLICKER_FILTERING;
    1.63 +      dlc.pixelformat = DSPF_RGB32;
    1.64 +      
    1.65 +      ret = HIDDEN->c2layer->TestConfiguration( HIDDEN->c2layer, &dlc, &failed );
    1.66 +      if (ret)
    1.67 +        {
    1.68 +          SetDirectFBerror ("c2layer->TestConfiguration", ret);
    1.69 +          goto error;
    1.70 +        }
    1.71 +    
    1.72 +      ret = HIDDEN->c2layer->SetConfiguration( HIDDEN->c2layer, &dlc );
    1.73 +      if (ret)
    1.74 +        {
    1.75 +          SetDirectFBerror ("c2layer->SetConfiguration", ret);
    1.76 +          goto error;
    1.77 +        }
    1.78 +    
    1.79 +      ret = HIDDEN->c2layer->GetSurface( HIDDEN->c2layer, &HIDDEN->c2frame );
    1.80 +      if (ret)
    1.81 +        {
    1.82 +          SetDirectFBerror ("c2layer->GetSurface", ret);
    1.83 +          goto error;
    1.84 +        }
    1.85 +
    1.86 +      HIDDEN->c2framesize.x = 0;
    1.87 +      HIDDEN->c2framesize.y = 0;
    1.88 +      HIDDEN->c2frame->GetSize( HIDDEN->c2frame, &HIDDEN->c2framesize.w, &HIDDEN->c2framesize.h);
    1.89 +
    1.90 +      HIDDEN->c2frame->SetBlittingFlags( HIDDEN->c2frame, DSBLIT_NOFX );
    1.91 +      HIDDEN->c2frame->SetColor( HIDDEN->c2frame, 0, 0, 0, 0xff );
    1.92 +    
    1.93 +      /* Clear CRTC2 */
    1.94 +      HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
    1.95 +      HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
    1.96 +      HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
    1.97 +      HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
    1.98 +      HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
    1.99 +
   1.100 +      HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
   1.101 +    }
   1.102 +
   1.103    return 0;
   1.104  
   1.105   error:
   1.106    if (events)
   1.107      events->Release (events);
   1.108    
   1.109 +  if (HIDDEN->c2frame)
   1.110 +    HIDDEN->c2frame->Release (HIDDEN->c2frame);
   1.111 +
   1.112 +  if (HIDDEN->c2layer)
   1.113 +    HIDDEN->c2layer->Release (HIDDEN->c2layer);
   1.114 +
   1.115    if (layer)
   1.116      layer->Release (layer);
   1.117  
   1.118 @@ -515,7 +603,7 @@
   1.119    if (flags & SDL_FULLSCREEN)
   1.120      {
   1.121        ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
   1.122 -      if (ret)
   1.123 +      if (ret && !HIDDEN->enable_mga_crtc2)
   1.124          {
   1.125            DirectFBError ("dfb->SetCooperativeLevel", ret);
   1.126            flags &= ~SDL_FULLSCREEN;
   1.127 @@ -589,6 +677,73 @@
   1.128  
   1.129    current->hwdata->surface = surface;
   1.130  
   1.131 +  /* MGA CRTC2 stuff */
   1.132 +  if (HIDDEN->enable_mga_crtc2)
   1.133 +    {
   1.134 +      /* no stretching if c2ssize == c2framesize */
   1.135 +      HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0;
   1.136 +      HIDDEN->c2ssize.w = width;
   1.137 +      HIDDEN->c2ssize.h = height;
   1.138 +
   1.139 +      HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0;
   1.140 +      HIDDEN->c2dsize.w = width;
   1.141 +      HIDDEN->c2dsize.h = height;
   1.142 +
   1.143 +      HIDDEN->mga_crtc2_stretch = 0;
   1.144 +
   1.145 +      if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
   1.146 +        {
   1.147 +          /* don't stretch slightly smaller/larger images */
   1.148 +          if (width < HIDDEN->c2framesize.w*0.95 && height < HIDDEN->c2framesize.w*0.95)
   1.149 +            {
   1.150 +              while (HIDDEN->c2dsize.w < HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && HIDDEN->c2dsize.h < HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
   1.151 +                {
   1.152 +                   HIDDEN->c2dsize.w+=4;
   1.153 +                   HIDDEN->c2dsize.h+=3;
   1.154 +                }
   1.155 +
   1.156 +              /* one step down */
   1.157 +              HIDDEN->c2dsize.w-=4;
   1.158 +              HIDDEN->c2dsize.h-=3;
   1.159 +
   1.160 +              #ifdef DIRECTFB_CRTC2_DEBUG
   1.161 +              printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
   1.162 +              #endif
   1.163 +
   1.164 +              HIDDEN->mga_crtc2_stretch = 1;
   1.165 +            } 
   1.166 +          else if (width > HIDDEN->c2framesize.w*0.95 && height > HIDDEN->c2framesize.w*0.95)
   1.167 +            {
   1.168 +              while (HIDDEN->c2dsize.w > HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || HIDDEN->c2dsize.h > HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
   1.169 +                {
   1.170 +                  HIDDEN->c2dsize.w-=4;
   1.171 +                  HIDDEN->c2dsize.h-=3;
   1.172 +                }
   1.173 +              
   1.174 +              #ifdef DIRECTFB_CRTC2_DEBUG
   1.175 +              printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
   1.176 +              #endif
   1.177 +
   1.178 +              HIDDEN->mga_crtc2_stretch = 1;
   1.179 +            }
   1.180 +        }
   1.181 +
   1.182 +      /* Panning */
   1.183 +      if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
   1.184 +        HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w)  / 2;
   1.185 +      else
   1.186 +        HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w)  / 2;
   1.187 +
   1.188 +      if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h)
   1.189 +        HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h)  / 2;
   1.190 +      else
   1.191 +        HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h)  / 2;
   1.192 +
   1.193 +      #ifdef DIRECTFB_CRTC2_DEBUG
   1.194 +      printf("CTRC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
   1.195 +      #endif
   1.196 +   }
   1.197 +
   1.198    return current;
   1.199  }
   1.200  
   1.201 @@ -732,7 +887,19 @@
   1.202  
   1.203  static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
   1.204  {
   1.205 -  return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
   1.206 +  if (HIDDEN->enable_mga_crtc2)
   1.207 +    {
   1.208 +       int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0);
   1.209 +       if (HIDDEN->mga_crtc2_stretch)
   1.210 +         HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
   1.211 +       else
   1.212 +         HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
   1.213 +     
   1.214 +       HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
   1.215 +       return rtn;
   1.216 +    } 
   1.217 +  else 
   1.218 +     return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
   1.219  }
   1.220  
   1.221  static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface)
   1.222 @@ -763,6 +930,15 @@
   1.223  
   1.224  static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
   1.225  {
   1.226 +  if (HIDDEN->enable_mga_crtc2)
   1.227 +    {
   1.228 +       if (HIDDEN->mga_crtc2_stretch)
   1.229 +         HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); 
   1.230 +       else
   1.231 +         HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 
   1.232 +
   1.233 +       HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
   1.234 +    }
   1.235  }
   1.236  
   1.237  static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
   1.238 @@ -808,7 +984,19 @@
   1.239      }
   1.240  
   1.241    if (region_valid)
   1.242 -    surface->Flip (surface, &region, DSFLIP_WAITFORSYNC);
   1.243 +    {
   1.244 +      if (HIDDEN->enable_mga_crtc2)
   1.245 +        {
   1.246 +          if (HIDDEN->mga_crtc2_stretch)
   1.247 +            HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
   1.248 +          else
   1.249 +            HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 
   1.250 +      
   1.251 +          HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
   1.252 +        }
   1.253 +      else 
   1.254 +        surface->Flip (surface, &region, DSFLIP_WAITFORSYNC);
   1.255 +    }
   1.256  }
   1.257  
   1.258  int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   1.259 @@ -855,6 +1043,12 @@
   1.260    if (surface)
   1.261      surface->Release (surface);
   1.262  
   1.263 +  if (HIDDEN->c2frame)
   1.264 +    {
   1.265 +      HIDDEN->c2frame->Release (HIDDEN->c2frame);
   1.266 +      HIDDEN->c2frame = NULL;
   1.267 +    }
   1.268 +
   1.269    this->screen->hwdata->surface = NULL;
   1.270    this->screen->hwdata->palette = NULL;
   1.271  
   1.272 @@ -864,6 +1058,12 @@
   1.273        HIDDEN->eventbuffer = NULL;
   1.274      }
   1.275  
   1.276 +  if (HIDDEN->c2layer)
   1.277 +    {
   1.278 +      HIDDEN->c2layer->Release (HIDDEN->c2layer);
   1.279 +      HIDDEN->c2layer = NULL;
   1.280 +    }
   1.281 +
   1.282    if (HIDDEN->layer)
   1.283      {
   1.284        HIDDEN->layer->Release (HIDDEN->layer);