comparison src/video/fbcon/SDL_fbriva.c @ 133:5d4bafca35cd

Added support for hardware accelerated NVidia driver on framebuffer console Still missing colorkey and alpha blit support
author Sam Lantinga <slouken@libsdl.org>
date Tue, 31 Jul 2001 20:08:51 +0000
parents
children f1550e1c4916
comparison
equal deleted inserted replaced
132:2604a7be65af 133:5d4bafca35cd
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 #include "SDL_types.h"
29 #include "SDL_video.h"
30 #include "SDL_blit.h"
31 #include "SDL_fbriva.h"
32 #include "riva_mmio.h"
33 #include "riva_regs.h"
34
35 #define PGRAPH_OFFSET 0x00400000
36 #define FIFO_OFFSET 0x00800000
37 #define ROP_OFFSET FIFO_OFFSET+0x00000000
38 #define CLIP_OFFSET FIFO_OFFSET+0x00002000
39 #define PATT_OFFSET FIFO_OFFSET+0x00004000
40 #define PIXMAP_OFFSET FIFO_OFFSET+0x00006000
41 #define BLT_OFFSET FIFO_OFFSET+0x00008000
42 #define BITMAP_OFFSET FIFO_OFFSET+0x0000A000
43 #define LINE_OFFSET FIFO_OFFSET+0x0000C000
44 #define TRI03_OFFSET FIFO_OFFSET+0x0000E000
45 #define PCIO_OFFSET 0x00601000
46
47 static int FifoEmptyCount = 0;
48 static int FifoFreeCount = 0;
49
50 /* Wait for vertical retrace */
51 static void WaitVBL(_THIS)
52 {
53 volatile Uint8 *port = (Uint8 *)(mapped_io + PCIO_OFFSET + 0x3DA);
54
55 while ( (*port & 0x08) )
56 ;
57 while ( !(*port & 0x08) )
58 ;
59 }
60 static void NV3WaitIdle(_THIS)
61 {
62 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
63 while ( (Rop->FifoFree < FifoEmptyCount) ||
64 (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01) )
65 ;
66 }
67 static void NV4WaitIdle(_THIS)
68 {
69 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
70 while ( (Rop->FifoFree < FifoEmptyCount) ||
71 (*(mapped_io + PGRAPH_OFFSET + 0x00000700) & 0x01) )
72 ;
73 }
74
75 /* Sets video mem colorkey and accelerated blit function */
76 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
77 {
78 return(0);
79 }
80
81 /* Sets per surface hardware alpha value */
82 static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value)
83 {
84 return(0);
85 }
86
87 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
88 {
89 int dstX, dstY;
90 int dstW, dstH;
91 RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);
92
93 /* Don't blit to the display surface when switched away */
94 if ( dst == this->screen ) {
95 SDL_mutexP(hw_lock);
96 }
97
98 /* Set up the X/Y base coordinates */
99 dstW = rect->w;
100 dstH = rect->h;
101 FB_dst_to_xy(this, dst, &dstX, &dstY);
102
103 /* Adjust for the current rectangle */
104 dstX += rect->x;
105 dstY += rect->y;
106
107 RIVA_FIFO_FREE(Bitmap, 1);
108 Bitmap->Color1A = color;
109
110 RIVA_FIFO_FREE(Bitmap, 2);
111 Bitmap->UnclippedRectangle[0].TopLeft = (dstX << 16) | dstY;
112 Bitmap->UnclippedRectangle[0].WidthHeight = (dstW << 16) | dstH;
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 HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
123 SDL_Surface *dst, SDL_Rect *dstrect)
124 {
125 SDL_VideoDevice *this = current_video;
126 int srcX, srcY;
127 int dstX, dstY;
128 int dstW, dstH;
129 RivaScreenBlt *Blt = (RivaScreenBlt *)(mapped_io + BLT_OFFSET);
130
131 /* FIXME: For now, only blit to display surface */
132 if ( dst->pitch != SDL_VideoSurface->pitch ) {
133 return(src->map->sw_blit(src, srcrect, dst, dstrect));
134 }
135
136 /* Don't blit to the display surface when switched away */
137 if ( dst == this->screen ) {
138 SDL_mutexP(hw_lock);
139 }
140
141 /* Calculate source and destination base coordinates (in pixels) */
142 dstW = dstrect->w;
143 dstH = dstrect->h;
144 FB_dst_to_xy(this, src, &srcX, &srcY);
145 FB_dst_to_xy(this, dst, &dstX, &dstY);
146
147 /* Adjust for the current blit rectangles */
148 srcX += srcrect->x;
149 srcY += srcrect->y;
150 dstX += dstrect->x;
151 dstY += dstrect->y;
152
153 RIVA_FIFO_FREE(Blt, 3);
154 Blt->TopLeftSrc = (srcY << 16) | srcX;
155 Blt->TopLeftDst = (dstY << 16) | dstX;
156 Blt->WidthHeight = (dstH << 16) | dstW;
157
158 FB_AddBusySurface(src);
159 FB_AddBusySurface(dst);
160
161 if ( dst == this->screen ) {
162 SDL_mutexV(hw_lock);
163 }
164 return(0);
165 }
166
167 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
168 {
169 int accelerated;
170
171 /* Set initial acceleration on */
172 src->flags |= SDL_HWACCEL;
173
174 /* Set the surface attributes */
175 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
176 if ( ! this->info.blit_hw_A ) {
177 src->flags &= ~SDL_HWACCEL;
178 }
179 }
180 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
181 if ( ! this->info.blit_hw_CC ) {
182 src->flags &= ~SDL_HWACCEL;
183 }
184 }
185
186 /* Check to see if final surface blit is accelerated */
187 accelerated = !!(src->flags & SDL_HWACCEL);
188 if ( accelerated ) {
189 src->map->hw_blit = HWAccelBlit;
190 }
191 return(accelerated);
192 }
193
194 void FB_RivaAccel(_THIS, __u32 card)
195 {
196 RivaRop *Rop = (RivaRop *)(mapped_io + ROP_OFFSET);
197
198 /* We have hardware accelerated surface functions */
199 this->CheckHWBlit = CheckHWBlit;
200 wait_vbl = WaitVBL;
201 switch (card) {
202 case FB_ACCEL_NV3:
203 wait_idle = NV3WaitIdle;
204 break;
205 case FB_ACCEL_NV4:
206 wait_idle = NV4WaitIdle;
207 break;
208 default:
209 /* Hmm... FIXME */
210 break;
211 }
212 FifoEmptyCount = Rop->FifoFree;
213
214 /* The Riva has an accelerated color fill */
215 this->info.blit_fill = 1;
216 this->FillHWRect = FillHWRect;
217
218 /* The Riva has accelerated normal and colorkey blits. */
219 this->info.blit_hw = 1;
220 #if 0 /* Not yet implemented? */
221 this->info.blit_hw_CC = 1;
222 this->SetHWColorKey = SetHWColorKey;
223 #endif
224
225 #if 0 /* Not yet implemented? */
226 /* The Riva has an accelerated alpha blit */
227 this->info.blit_hw_A = 1;
228 this->SetHWAlpha = SetHWAlpha;
229 #endif
230 }