comparison src/video/fbcon/SDL_fb3dfx.c @ 1895:c121d94672cb

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