src/video/fbcon/SDL_fb3dfx.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@0
     1
/*
slouken@1312
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     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@0
     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@0
    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@0
    18
slouken@1312
    19
    Sam Lantinga
slouken@1312
    20
    slouken@libsdl.org
slouken@1312
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
#include "SDL_video.h"
slouken@1361
    25
#include "../SDL_blit.h"
slouken@0
    26
#include "SDL_fb3dfx.h"
slouken@0
    27
#include "3dfx_mmio.h"
slouken@0
    28
slouken@0
    29
slouken@0
    30
/* Wait for vertical retrace */
slouken@1895
    31
static void
slouken@1895
    32
WaitVBL(_THIS)
slouken@0
    33
{
slouken@1895
    34
    /* find start of retrace */
slouken@1895
    35
    tdfx_waitidle();
slouken@1895
    36
    while ((tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE);
slouken@1895
    37
    /* wait until we're past the start */
slouken@1895
    38
    while ((tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0);
slouken@0
    39
}
slouken@1895
    40
static void
slouken@1895
    41
WaitIdle(_THIS)
slouken@106
    42
{
slouken@1895
    43
    tdfx_waitidle();
slouken@106
    44
}
slouken@0
    45
slouken@0
    46
/* Sets video mem colorkey and accelerated blit function */
slouken@1895
    47
static int
slouken@1895
    48
SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
slouken@0
    49
{
slouken@1895
    50
    return (0);
slouken@0
    51
}
slouken@0
    52
slouken@1895
    53
static int
slouken@1895
    54
FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
slouken@0
    55
{
slouken@1895
    56
    int bpp;
slouken@1895
    57
    char *dst_base;
slouken@1895
    58
    Uint32 format;
slouken@1895
    59
    int dstX, dstY;
slouken@0
    60
slouken@1895
    61
    /* Don't blit to the display surface when switched away */
slouken@1895
    62
    if (switched_away) {
slouken@1895
    63
        return -2;              /* no hardware access */
slouken@1895
    64
    }
slouken@1895
    65
    if (dst == this->screen) {
slouken@1895
    66
        SDL_mutexP(hw_lock);
slouken@1895
    67
    }
slouken@0
    68
slouken@1895
    69
    /* Set the destination pixel format */
slouken@1895
    70
    dst_base = (char *) ((char *) dst->pixels - mapped_mem);
slouken@1895
    71
    bpp = dst->format->BitsPerPixel;
slouken@1895
    72
    format = dst->pitch | ((bpp + ((bpp == 8) ? 0 : 8)) << 13);
slouken@1895
    73
slouken@1895
    74
    /* Calculate source and destination base coordinates */
slouken@1895
    75
    dstX = rect->x;
slouken@1895
    76
    dstY = rect->y;
slouken@0
    77
slouken@1895
    78
    /* Execute the fill command */
slouken@1895
    79
    tdfx_wait(6);
slouken@1895
    80
    tdfx_out32(DSTBASE, (Uint32) dst_base);
slouken@1895
    81
    tdfx_out32(DSTFORMAT, format);
slouken@1895
    82
    tdfx_out32(COLORFORE, color);
slouken@1895
    83
    tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT);
slouken@1895
    84
    tdfx_out32(DSTSIZE, rect->w | (rect->h << 16));
slouken@1895
    85
    tdfx_out32(LAUNCH_2D, dstX | (dstY << 16));
slouken@106
    86
slouken@1895
    87
    FB_AddBusySurface(dst);
slouken@106
    88
slouken@1895
    89
    if (dst == this->screen) {
slouken@1895
    90
        SDL_mutexV(hw_lock);
slouken@1895
    91
    }
slouken@1895
    92
    return (0);
slouken@0
    93
}
slouken@0
    94
slouken@1895
    95
static int
slouken@1895
    96
HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
slouken@1895
    97
            SDL_Surface * dst, SDL_Rect * dstrect)
slouken@0
    98
{
slouken@1895
    99
    SDL_VideoDevice *this = current_video;
slouken@1895
   100
    int bpp;
slouken@1895
   101
    Uint32 src_format;
slouken@1895
   102
    Uint32 dst_format;
slouken@1895
   103
    char *src_base;
slouken@1895
   104
    char *dst_base;
slouken@1895
   105
    int srcX, srcY;
slouken@1895
   106
    int dstX, dstY;
slouken@1895
   107
    Uint32 blitop;
slouken@1895
   108
    Uint32 use_colorkey;
slouken@0
   109
slouken@1895
   110
    /* Don't blit to the display surface when switched away */
slouken@1895
   111
    if (switched_away) {
slouken@1895
   112
        return -2;              /* no hardware access */
slouken@1895
   113
    }
slouken@1895
   114
    if (dst == this->screen) {
slouken@1895
   115
        SDL_mutexP(hw_lock);
slouken@1895
   116
    }
slouken@109
   117
slouken@1895
   118
    /* Set the source and destination pixel format */
slouken@1895
   119
    src_base = (char *) ((char *) src->pixels - mapped_mem);
slouken@1895
   120
    bpp = src->format->BitsPerPixel;
slouken@1895
   121
    src_format = src->pitch | ((bpp + ((bpp == 8) ? 0 : 8)) << 13);
slouken@1895
   122
    dst_base = (char *) ((char *) dst->pixels - mapped_mem);
slouken@1895
   123
    bpp = dst->format->BitsPerPixel;
slouken@1895
   124
    dst_format = dst->pitch | ((bpp + ((bpp == 8) ? 0 : 8)) << 13);
slouken@0
   125
slouken@1895
   126
    srcX = srcrect->x;
slouken@1895
   127
    srcY = srcrect->y;
slouken@1895
   128
    dstX = dstrect->x;
slouken@1895
   129
    dstY = dstrect->y;
slouken@0
   130
slouken@1895
   131
    /* Assemble the blit operation */
slouken@1895
   132
    blitop = COMMAND_2D_BITBLT | (0xCC << 24);
slouken@1895
   133
    if (srcX <= dstX) {
slouken@1895
   134
        blitop |= BIT(14);
slouken@1895
   135
        srcX += (dstrect->w - 1);
slouken@1895
   136
        dstX += (dstrect->w - 1);
slouken@1895
   137
    }
slouken@1895
   138
    if (srcY <= dstY) {
slouken@1895
   139
        blitop |= BIT(15);
slouken@1895
   140
        srcY += (dstrect->h - 1);
slouken@1895
   141
        dstY += (dstrect->h - 1);
slouken@1895
   142
    }
slouken@0
   143
slouken@1895
   144
    /* Perform the blit! */
slouken@1895
   145
    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1895
   146
        tdfx_wait(3);
slouken@1895
   147
        tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey);
slouken@1895
   148
        tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey);
slouken@1895
   149
        tdfx_out32(ROP_2D, 0xAA00);
slouken@1895
   150
        use_colorkey = 1;
slouken@1895
   151
    } else {
slouken@1895
   152
        use_colorkey = 0;
slouken@1895
   153
    }
slouken@1895
   154
    tdfx_wait(9);
slouken@1895
   155
    tdfx_out32(SRCBASE, (Uint32) src_base);
slouken@1895
   156
    tdfx_out32(SRCFORMAT, src_format);
slouken@1895
   157
    tdfx_out32(DSTBASE, (Uint32) dst_base);
slouken@1895
   158
    tdfx_out32(DSTFORMAT, src_format);
slouken@1895
   159
    tdfx_out32(COMMAND_2D, blitop);
slouken@1895
   160
    tdfx_out32(COMMANDEXTRA_2D, use_colorkey);
slouken@1895
   161
    tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16));
slouken@1895
   162
    tdfx_out32(DSTXY, dstX | (dstY << 16));
slouken@1895
   163
    tdfx_out32(LAUNCH_2D, srcX | (srcY << 16));
slouken@0
   164
slouken@1895
   165
    FB_AddBusySurface(src);
slouken@1895
   166
    FB_AddBusySurface(dst);
slouken@106
   167
slouken@1895
   168
    if (dst == this->screen) {
slouken@1895
   169
        SDL_mutexV(hw_lock);
slouken@1895
   170
    }
slouken@1895
   171
    return (0);
slouken@0
   172
}
slouken@0
   173
slouken@1895
   174
static int
slouken@1895
   175
CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
slouken@0
   176
{
slouken@1895
   177
    int accelerated;
slouken@0
   178
slouken@1895
   179
    /* Set initial acceleration on */
slouken@1895
   180
    src->flags |= SDL_HWACCEL;
slouken@0
   181
slouken@1895
   182
    /* Set the surface attributes */
slouken@1895
   183
    if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1895
   184
        if (!this->info.blit_hw_A) {
slouken@1895
   185
            src->flags &= ~SDL_HWACCEL;
slouken@1895
   186
        }
slouken@1895
   187
    }
slouken@1895
   188
    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1895
   189
        if (!this->info.blit_hw_CC) {
slouken@1895
   190
            src->flags &= ~SDL_HWACCEL;
slouken@1895
   191
        }
slouken@1895
   192
    }
slouken@0
   193
slouken@1895
   194
    /* Check to see if final surface blit is accelerated */
slouken@1895
   195
    accelerated = !!(src->flags & SDL_HWACCEL);
slouken@1895
   196
    if (accelerated) {
slouken@1895
   197
        src->map->hw_blit = HWAccelBlit;
slouken@1895
   198
    }
slouken@1895
   199
    return (accelerated);
slouken@0
   200
}
slouken@0
   201
slouken@1895
   202
void
slouken@1895
   203
FB_3DfxAccel(_THIS, __u32 card)
slouken@0
   204
{
slouken@1895
   205
    /* We have hardware accelerated surface functions */
slouken@1895
   206
    this->CheckHWBlit = CheckHWBlit;
slouken@1895
   207
    wait_vbl = WaitVBL;
slouken@1895
   208
    wait_idle = WaitIdle;
slouken@1895
   209
slouken@1895
   210
    /* Reset the 3Dfx controller */
slouken@1895
   211
    tdfx_out32(BRESERROR0, 0);
slouken@1895
   212
    tdfx_out32(BRESERROR1, 0);
slouken@0
   213
slouken@1895
   214
    /* The 3Dfx has an accelerated color fill */
slouken@1895
   215
    this->info.blit_fill = 1;
slouken@1895
   216
    this->FillHWRect = FillHWRect;
slouken@0
   217
slouken@1895
   218
    /* The 3Dfx has accelerated normal and colorkey blits */
slouken@1895
   219
    this->info.blit_hw = 1;
slouken@1895
   220
    this->info.blit_hw_CC = 1;
slouken@1895
   221
    this->SetHWColorKey = SetHWColorKey;
slouken@1895
   222
}
slouken@0
   223
slouken@1895
   224
/* vi: set ts=4 sw=4 expandtab: */