src/video/fbcon/SDL_fbriva.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.
slouken@133
     1
/*
slouken@1312
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@133
     4
slouken@1312
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1312
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@133
     9
slouken@1312
    10
    This library is distributed in the hope that it will be useful,
slouken@1312
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1312
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@133
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@133
    18
slouken@1312
    19
    Sam Lantinga
slouken@1312
    20
    slouken@libsdl.org
slouken@1312
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@133
    23
slouken@133
    24
#include "SDL_video.h"
slouken@1361
    25
#include "../SDL_blit.h"
slouken@133
    26
#include "SDL_fbriva.h"
slouken@133
    27
#include "riva_mmio.h"
slouken@133
    28
#include "riva_regs.h"
slouken@133
    29
slouken@133
    30
slouken@133
    31
static int FifoEmptyCount = 0;
slouken@133
    32
static int FifoFreeCount = 0;
slouken@133
    33
slouken@133
    34
/* Wait for vertical retrace */
slouken@1895
    35
static void
slouken@1895
    36
WaitVBL(_THIS)
slouken@133
    37
{
slouken@1895
    38
    volatile Uint8 *port = (Uint8 *) (mapped_io + PCIO_OFFSET + 0x3DA);
slouken@133
    39
slouken@1895
    40
    while ((*port & 0x08));
slouken@1895
    41
    while (!(*port & 0x08));
slouken@133
    42
}
slouken@1895
    43
static void
slouken@1895
    44
NV3WaitIdle(_THIS)
slouken@133
    45
{
slouken@1895
    46
    RivaRop *Rop = (RivaRop *) (mapped_io + ROP_OFFSET);
slouken@1895
    47
    while ((Rop->FifoFree < FifoEmptyCount) ||
slouken@1895
    48
           (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01));
slouken@133
    49
}
slouken@1895
    50
static void
slouken@1895
    51
NV4WaitIdle(_THIS)
slouken@133
    52
{
slouken@1895
    53
    RivaRop *Rop = (RivaRop *) (mapped_io + ROP_OFFSET);
slouken@1895
    54
    while ((Rop->FifoFree < FifoEmptyCount) ||
slouken@1895
    55
           (*(mapped_io + PGRAPH_OFFSET + 0x00000700) & 0x01));
slouken@133
    56
}
slouken@133
    57
slouken@1895
    58
#if 0                           /* Not yet implemented? */
slouken@133
    59
/* Sets video mem colorkey and accelerated blit function */
slouken@1895
    60
static int
slouken@1895
    61
SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
slouken@133
    62
{
slouken@1895
    63
    return (0);
slouken@133
    64
}
slouken@133
    65
slouken@133
    66
/* Sets per surface hardware alpha value */
slouken@1895
    67
static int
slouken@1895
    68
SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 value)
slouken@133
    69
{
slouken@1895
    70
    return (0);
slouken@133
    71
}
slouken@1022
    72
#endif /* Not yet implemented */
slouken@133
    73
slouken@1895
    74
static int
slouken@1895
    75
FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
slouken@133
    76
{
slouken@1895
    77
    int dstX, dstY;
slouken@1895
    78
    int dstW, dstH;
slouken@1895
    79
    RivaBitmap *Bitmap = (RivaBitmap *) (mapped_io + BITMAP_OFFSET);
slouken@133
    80
slouken@1895
    81
    /* Don't blit to the display surface when switched away */
slouken@1895
    82
    if (switched_away) {
slouken@1895
    83
        return -2;              /* no hardware access */
slouken@1895
    84
    }
slouken@1895
    85
    if (dst == this->screen) {
slouken@1895
    86
        SDL_mutexP(hw_lock);
slouken@1895
    87
    }
slouken@133
    88
slouken@1895
    89
    /* Set up the X/Y base coordinates */
slouken@1895
    90
    dstW = rect->w;
slouken@1895
    91
    dstH = rect->h;
slouken@1895
    92
    FB_dst_to_xy(this, dst, &dstX, &dstY);
slouken@133
    93
slouken@1895
    94
    /* Adjust for the current rectangle */
slouken@1895
    95
    dstX += rect->x;
slouken@1895
    96
    dstY += rect->y;
slouken@133
    97
slouken@1895
    98
    RIVA_FIFO_FREE(Bitmap, 1);
slouken@1895
    99
    Bitmap->Color1A = color;
slouken@133
   100
slouken@1895
   101
    RIVA_FIFO_FREE(Bitmap, 2);
slouken@1895
   102
    Bitmap->UnclippedRectangle[0].TopLeft = (dstX << 16) | dstY;
slouken@1895
   103
    Bitmap->UnclippedRectangle[0].WidthHeight = (dstW << 16) | dstH;
slouken@133
   104
slouken@1895
   105
    FB_AddBusySurface(dst);
slouken@133
   106
slouken@1895
   107
    if (dst == this->screen) {
slouken@1895
   108
        SDL_mutexV(hw_lock);
slouken@1895
   109
    }
slouken@1895
   110
    return (0);
slouken@133
   111
}
slouken@133
   112
slouken@1895
   113
static int
slouken@1895
   114
HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
slouken@1895
   115
            SDL_Surface * dst, SDL_Rect * dstrect)
slouken@133
   116
{
slouken@1895
   117
    SDL_VideoDevice *this = current_video;
slouken@1895
   118
    int srcX, srcY;
slouken@1895
   119
    int dstX, dstY;
slouken@1895
   120
    int dstW, dstH;
slouken@1895
   121
    RivaScreenBlt *Blt = (RivaScreenBlt *) (mapped_io + BLT_OFFSET);
slouken@133
   122
slouken@1895
   123
    /* FIXME: For now, only blit to display surface */
slouken@1895
   124
    if (dst->pitch != SDL_VideoSurface->pitch) {
slouken@1895
   125
        return (src->map->sw_blit(src, srcrect, dst, dstrect));
slouken@1895
   126
    }
slouken@133
   127
slouken@1895
   128
    /* Don't blit to the display surface when switched away */
slouken@1895
   129
    if (switched_away) {
slouken@1895
   130
        return -2;              /* no hardware access */
slouken@1895
   131
    }
slouken@1895
   132
    if (dst == this->screen) {
slouken@1895
   133
        SDL_mutexP(hw_lock);
slouken@1895
   134
    }
slouken@133
   135
slouken@1895
   136
    /* Calculate source and destination base coordinates (in pixels) */
slouken@1895
   137
    dstW = dstrect->w;
slouken@1895
   138
    dstH = dstrect->h;
slouken@1895
   139
    FB_dst_to_xy(this, src, &srcX, &srcY);
slouken@1895
   140
    FB_dst_to_xy(this, dst, &dstX, &dstY);
slouken@133
   141
slouken@1895
   142
    /* Adjust for the current blit rectangles */
slouken@1895
   143
    srcX += srcrect->x;
slouken@1895
   144
    srcY += srcrect->y;
slouken@1895
   145
    dstX += dstrect->x;
slouken@1895
   146
    dstY += dstrect->y;
slouken@133
   147
slouken@1895
   148
    RIVA_FIFO_FREE(Blt, 3);
slouken@1895
   149
    Blt->TopLeftSrc = (srcY << 16) | srcX;
slouken@1895
   150
    Blt->TopLeftDst = (dstY << 16) | dstX;
slouken@1895
   151
    Blt->WidthHeight = (dstH << 16) | dstW;
slouken@133
   152
slouken@1895
   153
    FB_AddBusySurface(src);
slouken@1895
   154
    FB_AddBusySurface(dst);
slouken@133
   155
slouken@1895
   156
    if (dst == this->screen) {
slouken@1895
   157
        SDL_mutexV(hw_lock);
slouken@1895
   158
    }
slouken@1895
   159
    return (0);
slouken@133
   160
}
slouken@133
   161
slouken@1895
   162
static int
slouken@1895
   163
CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
slouken@133
   164
{
slouken@1895
   165
    int accelerated;
slouken@133
   166
slouken@1895
   167
    /* Set initial acceleration on */
slouken@1895
   168
    src->flags |= SDL_HWACCEL;
slouken@133
   169
slouken@1895
   170
    /* Set the surface attributes */
slouken@1895
   171
    if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1895
   172
        if (!this->info.blit_hw_A) {
slouken@1895
   173
            src->flags &= ~SDL_HWACCEL;
slouken@1895
   174
        }
slouken@1895
   175
    }
slouken@1895
   176
    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1895
   177
        if (!this->info.blit_hw_CC) {
slouken@1895
   178
            src->flags &= ~SDL_HWACCEL;
slouken@1895
   179
        }
slouken@1895
   180
    }
slouken@133
   181
slouken@1895
   182
    /* Check to see if final surface blit is accelerated */
slouken@1895
   183
    accelerated = !!(src->flags & SDL_HWACCEL);
slouken@1895
   184
    if (accelerated) {
slouken@1895
   185
        src->map->hw_blit = HWAccelBlit;
slouken@1895
   186
    }
slouken@1895
   187
    return (accelerated);
slouken@133
   188
}
slouken@133
   189
slouken@1895
   190
void
slouken@1895
   191
FB_RivaAccel(_THIS, __u32 card)
slouken@133
   192
{
slouken@1895
   193
    RivaRop *Rop = (RivaRop *) (mapped_io + ROP_OFFSET);
slouken@133
   194
slouken@1895
   195
    /* We have hardware accelerated surface functions */
slouken@1895
   196
    this->CheckHWBlit = CheckHWBlit;
slouken@1895
   197
    wait_vbl = WaitVBL;
slouken@1895
   198
    switch (card) {
slouken@1895
   199
    case FB_ACCEL_NV3:
slouken@1895
   200
        wait_idle = NV3WaitIdle;
slouken@1895
   201
        break;
slouken@1895
   202
    case FB_ACCEL_NV4:
slouken@1895
   203
        wait_idle = NV4WaitIdle;
slouken@1895
   204
        break;
slouken@1895
   205
    default:
slouken@1895
   206
        /* Hmm... FIXME */
slouken@1895
   207
        break;
slouken@1895
   208
    }
slouken@1895
   209
    FifoEmptyCount = Rop->FifoFree;
slouken@133
   210
slouken@1895
   211
    /* The Riva has an accelerated color fill */
slouken@1895
   212
    this->info.blit_fill = 1;
slouken@1895
   213
    this->FillHWRect = FillHWRect;
slouken@133
   214
slouken@1895
   215
    /* The Riva has accelerated normal and colorkey blits. */
slouken@1895
   216
    this->info.blit_hw = 1;
slouken@1895
   217
#if 0                           /* Not yet implemented? */
slouken@1895
   218
    this->info.blit_hw_CC = 1;
slouken@1895
   219
    this->SetHWColorKey = SetHWColorKey;
slouken@133
   220
#endif
slouken@133
   221
slouken@1895
   222
#if 0                           /* Not yet implemented? */
slouken@1895
   223
    /* The Riva has an accelerated alpha blit */
slouken@1895
   224
    this->info.blit_hw_A = 1;
slouken@1895
   225
    this->SetHWAlpha = SetHWAlpha;
slouken@133
   226
#endif
slouken@133
   227
}
slouken@1895
   228
slouken@1895
   229
/* vi: set ts=4 sw=4 expandtab: */