Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fb3dfx.c @ 106:63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Fixed matrox blit bug where src Y less than dst Y
Fixed hardware surface init when no resolution change
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Fri, 13 Jul 2001 10:19:51 +0000 |
parents | 74212992fb08 |
children | 5a9c36a45db1 |
rev | line source |
---|---|
0 | 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_fb3dfx.h" | |
32 #include "3dfx_mmio.h" | |
33 | |
34 | |
35 /* Wait for vertical retrace */ | |
36 static void WaitVBL(_THIS) | |
37 { | |
38 /* find start of retrace */ | |
39 tdfx_waitidle(); | |
40 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE ) | |
41 ; | |
42 /* wait until we're past the start */ | |
43 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0 ) | |
44 ; | |
45 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
46 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
47 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
48 tdfx_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
49 } |
0 | 50 |
51 /* Sets video mem colorkey and accelerated blit function */ | |
52 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
53 { | |
54 return(0); | |
55 } | |
56 | |
57 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
58 { | |
59 int bpp; | |
60 char *dst_base; | |
61 Uint32 format; | |
62 int dstX, dstY; | |
63 | |
64 /* Set the destination pixel format */ | |
65 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
66 bpp = dst->format->BitsPerPixel; | |
67 format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
68 | |
69 /* Calculate source and destination base coordinates */ | |
70 dstX = rect->x; | |
71 dstY = rect->y; | |
72 | |
73 /* Execute the fill command */ | |
74 tdfx_wait(6); | |
75 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
76 tdfx_out32(DSTFORMAT, format); | |
77 tdfx_out32(COLORFORE, color); | |
78 tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT); | |
79 tdfx_out32(DSTSIZE, rect->w | (rect->h << 16)); | |
80 tdfx_out32(LAUNCH_2D, dstX | (dstY << 16)); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
82 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
83 |
0 | 84 return(0); |
85 } | |
86 | |
87 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
88 SDL_Surface *dst, SDL_Rect *dstrect) | |
89 { | |
90 SDL_VideoDevice *this; | |
91 int bpp; | |
92 Uint32 src_format; | |
93 Uint32 dst_format; | |
94 char *src_base; | |
95 char *dst_base; | |
96 int srcX, srcY; | |
97 int dstX, dstY; | |
98 Uint32 blitop; | |
99 Uint32 use_colorkey; | |
100 | |
101 /* Set the source and destination pixel format */ | |
102 this = current_video; | |
103 src_base = (char *)((char *)src->pixels - mapped_mem); | |
104 bpp = src->format->BitsPerPixel; | |
105 src_format = src->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
106 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
107 bpp = dst->format->BitsPerPixel; | |
108 dst_format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
109 | |
110 srcX = srcrect->x; | |
111 srcY = srcrect->y; | |
112 dstX = dstrect->x; | |
113 dstY = dstrect->y; | |
114 | |
115 /* Assemble the blit operation */ | |
116 blitop = COMMAND_2D_BITBLT | (0xCC << 24); | |
117 if ( srcX <= dstX ) { | |
118 blitop |= BIT(14); | |
119 srcX += (dstrect->w - 1); | |
120 dstX += (dstrect->w - 1); | |
121 } | |
122 if ( srcY <= dstY ) { | |
123 blitop |= BIT(15); | |
124 srcY += (dstrect->h - 1); | |
125 dstY += (dstrect->h - 1); | |
126 } | |
127 | |
128 /* Perform the blit! */ | |
129 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
130 tdfx_wait(3); | |
131 tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey); | |
132 tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey); | |
133 tdfx_out32(ROP_2D, 0xAA00); | |
134 use_colorkey = 1; | |
135 } else { | |
136 use_colorkey = 0; | |
137 } | |
138 tdfx_wait(9); | |
139 tdfx_out32(SRCBASE, (Uint32)src_base); | |
140 tdfx_out32(SRCFORMAT, src_format); | |
141 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
142 tdfx_out32(DSTFORMAT, src_format); | |
143 tdfx_out32(COMMAND_2D, blitop); | |
144 tdfx_out32(COMMANDEXTRA_2D, use_colorkey); | |
145 tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16)); | |
146 tdfx_out32(DSTXY, dstX | (dstY << 16)); | |
147 tdfx_out32(LAUNCH_2D, srcX | (srcY << 16)); | |
148 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
149 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
150 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
151 |
0 | 152 return(0); |
153 } | |
154 | |
155 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
156 { | |
157 int accelerated; | |
158 | |
159 /* Set initial acceleration on */ | |
160 src->flags |= SDL_HWACCEL; | |
161 | |
162 /* Set the surface attributes */ | |
163 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
164 if ( ! this->info.blit_hw_A ) { | |
165 src->flags &= ~SDL_HWACCEL; | |
166 } | |
167 } | |
168 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
169 if ( ! this->info.blit_hw_CC ) { | |
170 src->flags &= ~SDL_HWACCEL; | |
171 } | |
172 } | |
173 | |
174 /* Check to see if final surface blit is accelerated */ | |
175 accelerated = !!(src->flags & SDL_HWACCEL); | |
176 if ( accelerated ) { | |
177 src->map->hw_blit = HWAccelBlit; | |
178 } | |
179 return(accelerated); | |
180 } | |
181 | |
182 void FB_3DfxAccel(_THIS, __u32 card) | |
183 { | |
184 /* We have hardware accelerated surface functions */ | |
185 this->CheckHWBlit = CheckHWBlit; | |
186 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
187 wait_idle = WaitIdle; |
0 | 188 |
189 /* Reset the 3Dfx controller */ | |
190 tdfx_out32(BRESERROR0, 0); | |
191 tdfx_out32(BRESERROR1, 0); | |
192 | |
193 /* The 3Dfx has an accelerated color fill */ | |
194 this->info.blit_fill = 1; | |
195 this->FillHWRect = FillHWRect; | |
196 | |
197 /* The 3Dfx has accelerated normal and colorkey blits */ | |
198 this->info.blit_hw = 1; | |
199 this->info.blit_hw_CC = 1; | |
200 this->SetHWColorKey = SetHWColorKey; | |
201 } |