src/video/fbcon/SDL_fbmatrox.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 1895 c121d94672cb
child 2698 e1da92da346c
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     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.
     9 
    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.
    14 
    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
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_video.h"
    25 #include "../SDL_blit.h"
    26 #include "SDL_fbmatrox.h"
    27 #include "matrox_mmio.h"
    28 
    29 
    30 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */
    31 static void
    32 WaitVBL(_THIS)
    33 {
    34     int count;
    35 
    36     /* find start of retrace */
    37     mga_waitidle();
    38     while ((mga_in8(0x1FDA) & 0x08));
    39     while (!(mga_in8(0x1FDA) & 0x08));
    40     /* wait until we're past the start */
    41     count = mga_in32(0x1E20) + 2;
    42     while (mga_in32(0x1E20) < count);
    43 }
    44 static void
    45 WaitIdle(_THIS)
    46 {
    47     mga_waitidle();
    48 }
    49 
    50 /* Sets video mem colorkey and accelerated blit function */
    51 static int
    52 SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
    53 {
    54     return (0);
    55 }
    56 
    57 /* Sets per surface hardware alpha value */
    58 #if 0
    59 static int
    60 SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 value)
    61 {
    62     return (0);
    63 }
    64 #endif
    65 
    66 static int
    67 FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
    68 {
    69     int dstX, dstY;
    70     Uint32 fxbndry;
    71     Uint32 ydstlen;
    72     Uint32 fillop;
    73 
    74     /* Don't blit to the display surface when switched away */
    75     if (switched_away) {
    76         return -2;              /* no hardware access */
    77     }
    78     if (dst == this->screen) {
    79         SDL_mutexP(hw_lock);
    80     }
    81 
    82     switch (dst->format->BytesPerPixel) {
    83     case 1:
    84         color |= (color << 8);
    85     case 2:
    86         color |= (color << 16);
    87         break;
    88     }
    89 
    90     /* Set up the X/Y base coordinates */
    91     FB_dst_to_xy(this, dst, &dstX, &dstY);
    92 
    93     /* Adjust for the current rectangle */
    94     dstX += rect->x;
    95     dstY += rect->y;
    96 
    97     /* Set up the X boundaries */
    98     fxbndry = (dstX | ((dstX + rect->w) << 16));
    99 
   100     /* Set up the Y boundaries */
   101     ydstlen = (rect->h | (dstY << 16));
   102 
   103     /* Set up for color fill operation */
   104     fillop = MGADWG_TRAP | MGADWG_SOLID |
   105         MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO;
   106 
   107     /* Execute the operations! */
   108     mga_wait(5);
   109     mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE);
   110     mga_out32(MGAREG_FCOL, color);
   111     mga_out32(MGAREG_FXBNDRY, fxbndry);
   112     mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen);
   113 
   114     FB_AddBusySurface(dst);
   115 
   116     if (dst == this->screen) {
   117         SDL_mutexV(hw_lock);
   118     }
   119     return (0);
   120 }
   121 
   122 static int
   123 HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
   124             SDL_Surface * dst, SDL_Rect * dstrect)
   125 {
   126     SDL_VideoDevice *this = current_video;
   127     int pitch, w, h;
   128     int srcX, srcY;
   129     int dstX, dstY;
   130     Uint32 sign;
   131     Uint32 start, stop;
   132     int skip;
   133     Uint32 blitop;
   134 
   135     /* FIXME: For now, only blit to display surface */
   136     if (dst->pitch != SDL_VideoSurface->pitch) {
   137         return (src->map->sw_blit(src, srcrect, dst, dstrect));
   138     }
   139 
   140     /* Don't blit to the display surface when switched away */
   141     if (switched_away) {
   142         return -2;              /* no hardware access */
   143     }
   144     if (dst == this->screen) {
   145         SDL_mutexP(hw_lock);
   146     }
   147 
   148     /* Calculate source and destination base coordinates (in pixels) */
   149     w = dstrect->w;
   150     h = dstrect->h;
   151     FB_dst_to_xy(this, src, &srcX, &srcY);
   152     FB_dst_to_xy(this, dst, &dstX, &dstY);
   153 
   154     /* Adjust for the current blit rectangles */
   155     srcX += srcrect->x;
   156     srcY += srcrect->y;
   157     dstX += dstrect->x;
   158     dstY += dstrect->y;
   159     pitch = dst->pitch / dst->format->BytesPerPixel;
   160 
   161     /* Set up the blit direction (sign) flags */
   162     sign = 0;
   163     if (srcX < dstX) {
   164         sign |= 1;
   165     }
   166     if (srcY < dstY) {
   167         sign |= 4;
   168         srcY += (h - 1);
   169         dstY += (h - 1);
   170     }
   171 
   172     /* Set up the blit source row start, end, and skip (in pixels) */
   173     stop = start = (srcY * pitch) + srcX;
   174     if (srcX < dstX) {
   175         start += (w - 1);
   176     } else {
   177         stop += (w - 1);
   178     }
   179     if (srcY < dstY) {
   180         skip = -pitch;
   181     } else {
   182         skip = pitch;
   183     }
   184 
   185     /* Set up the blit operation */
   186     if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   187         Uint32 colorkey;
   188 
   189         blitop = MGADWG_BFCOL | MGADWG_BITBLT |
   190             MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) | MGADWG_TRANSC;
   191 
   192         colorkey = src->format->colorkey;
   193         switch (dst->format->BytesPerPixel) {
   194         case 1:
   195             colorkey |= (colorkey << 8);
   196         case 2:
   197             colorkey |= (colorkey << 16);
   198             break;
   199         }
   200         mga_wait(2);
   201         mga_out32(MGAREG_FCOL, colorkey);
   202         mga_out32(MGAREG_BCOL, 0xFFFFFFFF);
   203     } else {
   204         blitop = MGADWG_BFCOL | MGADWG_BITBLT |
   205             MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16);
   206     }
   207     mga_wait(7);
   208     mga_out32(MGAREG_SGN, sign);
   209     mga_out32(MGAREG_AR3, start);
   210     mga_out32(MGAREG_AR0, stop);
   211     mga_out32(MGAREG_AR5, skip);
   212     mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + w - 1) << 16)));
   213     mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h);
   214     mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop);
   215 
   216     FB_AddBusySurface(src);
   217     FB_AddBusySurface(dst);
   218 
   219     if (dst == this->screen) {
   220         SDL_mutexV(hw_lock);
   221     }
   222     return (0);
   223 }
   224 
   225 static int
   226 CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
   227 {
   228     int accelerated;
   229 
   230     /* Set initial acceleration on */
   231     src->flags |= SDL_HWACCEL;
   232 
   233     /* Set the surface attributes */
   234     if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   235         if (!this->info.blit_hw_A) {
   236             src->flags &= ~SDL_HWACCEL;
   237         }
   238     }
   239     if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   240         if (!this->info.blit_hw_CC) {
   241             src->flags &= ~SDL_HWACCEL;
   242         }
   243     }
   244 
   245     /* Check to see if final surface blit is accelerated */
   246     accelerated = !!(src->flags & SDL_HWACCEL);
   247     if (accelerated) {
   248         src->map->hw_blit = HWAccelBlit;
   249     }
   250     return (accelerated);
   251 }
   252 
   253 void
   254 FB_MatroxAccel(_THIS, __u32 card)
   255 {
   256     /* We have hardware accelerated surface functions */
   257     this->CheckHWBlit = CheckHWBlit;
   258     wait_vbl = WaitVBL;
   259     wait_idle = WaitIdle;
   260 
   261     /* The Matrox has an accelerated color fill */
   262     this->info.blit_fill = 1;
   263     this->FillHWRect = FillHWRect;
   264 
   265     /* The Matrox has accelerated normal and colorkey blits. */
   266     this->info.blit_hw = 1;
   267     /* The Millenium I appears to do the colorkey test a word
   268        at a time, and the transparency is intverted. (?)
   269      */
   270     if (card != FB_ACCEL_MATROX_MGA2064W) {
   271         this->info.blit_hw_CC = 1;
   272         this->SetHWColorKey = SetHWColorKey;
   273     }
   274 #if 0                           /* Not yet implemented? */
   275     /* The Matrox G200/G400 has an accelerated alpha blit */
   276     if ((card == FB_ACCEL_MATROX_MGAG200)
   277         || (card == FB_ACCEL_MATROX_MGAG400)) {
   278         this->info.blit_hw_A = 1;
   279         this->SetHWAlpha = SetHWAlpha;
   280     }
   281 #endif
   282 }
   283 
   284 /* vi: set ts=4 sw=4 expandtab: */