comparison src/video/fbcon/SDL_fbmatrox.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 3dc008dc229d
children 5a9c36a45db1
comparison
equal deleted inserted replaced
105:2136ea8953f9 106:63ec24e0575f
29 #include "SDL_video.h" 29 #include "SDL_video.h"
30 #include "SDL_blit.h" 30 #include "SDL_blit.h"
31 #include "SDL_fbmatrox.h" 31 #include "SDL_fbmatrox.h"
32 #include "matrox_mmio.h" 32 #include "matrox_mmio.h"
33 33
34
35 static int LockHWSurface(_THIS, SDL_Surface *surface)
36 {
37 if ( surface == SDL_VideoSurface ) {
38 mga_waitidle();
39 }
40 return(0);
41 }
42 static void UnlockHWSurface(_THIS, SDL_Surface *surface)
43 {
44 return;
45 }
46 34
47 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */ 35 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */
48 static void WaitVBL(_THIS) 36 static void WaitVBL(_THIS)
49 { 37 {
50 int count; 38 int count;
58 /* wait until we're past the start */ 46 /* wait until we're past the start */
59 count = mga_in32(0x1E20) + 2; 47 count = mga_in32(0x1E20) + 2;
60 while ( mga_in32(0x1E20) < count ) 48 while ( mga_in32(0x1E20) < count )
61 ; 49 ;
62 } 50 }
51 static void WaitIdle(_THIS)
52 {
53 mga_waitidle();
54 }
63 55
64 /* Sets video mem colorkey and accelerated blit function */ 56 /* Sets video mem colorkey and accelerated blit function */
65 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) 57 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
66 { 58 {
67 return(0); 59 return(0);
89 color |= (color<<16); 81 color |= (color<<16);
90 break; 82 break;
91 } 83 }
92 84
93 /* Set up the X/Y base coordinates */ 85 /* Set up the X/Y base coordinates */
94 dstX = 0; 86 FB_dst_to_xy(this, dst, &dstX, &dstY);
95 dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch;
96 87
97 /* Adjust for the current rectangle */ 88 /* Adjust for the current rectangle */
98 dstX += rect->x; 89 dstX += rect->x;
99 dstY += rect->y; 90 dstY += rect->y;
100 91
102 fxbndry = (dstX | ((dstX+rect->w) << 16)); 93 fxbndry = (dstX | ((dstX+rect->w) << 16));
103 94
104 /* Set up the Y boundaries */ 95 /* Set up the Y boundaries */
105 ydstlen = (rect->h | (dstY << 16)); 96 ydstlen = (rect->h | (dstY << 16));
106 97
107 #if 0 /* This old way doesn't work on the Matrox G450 */
108 /* Set up for color fill operation */
109 fillop = MGADWG_TRAP | MGADWG_SOLID |
110 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO |
111 MGADWG_BFCOL | MGADWG_BLK;
112
113 /* Execute the operations! */
114 mga_wait(4);
115 mga_out32(MGAREG_FCOL, color);
116 mga_out32(MGAREG_FXBNDRY, fxbndry);
117 mga_out32(MGAREG_YDSTLEN, ydstlen);
118 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, fillop);
119 #else
120 /* Set up for color fill operation */ 98 /* Set up for color fill operation */
121 fillop = MGADWG_TRAP | MGADWG_SOLID | 99 fillop = MGADWG_TRAP | MGADWG_SOLID |
122 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO; 100 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO;
123 101
124 /* Execute the operations! */ 102 /* Execute the operations! */
125 mga_wait(5); 103 mga_wait(5);
126 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE); 104 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE);
127 mga_out32(MGAREG_FCOL, color); 105 mga_out32(MGAREG_FCOL, color);
128 mga_out32(MGAREG_FXBNDRY, fxbndry); 106 mga_out32(MGAREG_FXBNDRY, fxbndry);
129 mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen); 107 mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen);
130 #endif 108
109 FB_AddBusySurface(dst);
131 110
132 return(0); 111 return(0);
133 } 112 }
134 113
135 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, 114 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
136 SDL_Surface *dst, SDL_Rect *dstrect) 115 SDL_Surface *dst, SDL_Rect *dstrect)
137 { 116 {
138 SDL_VideoDevice *this; 117 SDL_VideoDevice *this;
139 int bpp; 118 int pitch, w, h;
140 int srcX, srcY; 119 int srcX, srcY;
141 int dstX, dstY; 120 int dstX, dstY;
142 Uint32 sign; 121 Uint32 sign;
143 Uint32 sstart, sstop; 122 Uint32 start, stop;
144 int sskip; 123 int skip;
145 Uint32 blitop; 124 Uint32 blitop;
146 125
147 /* FIXME: For now, only blit to display surface */ 126 /* FIXME: For now, only blit to display surface */
148 if ( dst->pitch != SDL_VideoSurface->pitch ) { 127 if ( dst->pitch != SDL_VideoSurface->pitch ) {
149 return(src->map->sw_blit(src, srcrect, dst, dstrect)); 128 return(src->map->sw_blit(src, srcrect, dst, dstrect));
150 } 129 }
151 130
152 /* Calculate source and destination base coordinates (in pixels) */ 131 /* Calculate source and destination base coordinates (in pixels) */
153 this = current_video; 132 this = current_video;
154 srcX= 0; /* FIXME: Calculate this from memory offset */ 133 w = dstrect->w;
155 srcY = ((char *)src->pixels - mapped_mem) / SDL_VideoSurface->pitch; 134 h = dstrect->h;
156 dstX = 0; /* FIXME: Calculate this from memory offset */ 135 FB_dst_to_xy(this, src, &srcX, &srcY);
157 dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch; 136 FB_dst_to_xy(this, dst, &dstX, &dstY);
158 137
159 /* Adjust for the current blit rectangles */ 138 /* Adjust for the current blit rectangles */
160 srcX += srcrect->x; 139 srcX += srcrect->x;
161 srcY += srcrect->y; 140 srcY += srcrect->y;
162 dstX += dstrect->x; 141 dstX += dstrect->x;
163 dstY += dstrect->y; 142 dstY += dstrect->y;
143 pitch = dst->pitch/dst->format->BytesPerPixel;
164 144
165 /* Set up the blit direction (sign) flags */ 145 /* Set up the blit direction (sign) flags */
166 sign = 0; 146 sign = 0;
167 if ( srcX < dstX ) { 147 if ( srcX < dstX ) {
168 sign |= 1; 148 sign |= 1;
169 } 149 }
170 if ( srcY < dstY ) { 150 if ( srcY < dstY ) {
171 sign |= 4; 151 sign |= 4;
152 srcY += (h - 1);
153 dstY += (h - 1);
172 } 154 }
173 155
174 /* Set up the blit source row start, end, and skip (in pixels) */ 156 /* Set up the blit source row start, end, and skip (in pixels) */
175 bpp = src->format->BytesPerPixel; 157 stop = start = (srcY * pitch) + srcX;
176 sstop = sstart = ((srcY * SDL_VideoSurface->pitch)/bpp) + srcX;
177 if ( srcX < dstX ) { 158 if ( srcX < dstX ) {
178 sstart += (dstrect->w - 1); 159 start += (w - 1);
179 } else { 160 } else {
180 sstop += (dstrect->w - 1); 161 stop += (w - 1);
181 } 162 }
182 sskip = src->pitch/bpp;
183 if ( srcY < dstY ) { 163 if ( srcY < dstY ) {
184 sskip = -sskip; 164 skip = -pitch;
165 } else {
166 skip = pitch;
185 } 167 }
186 168
187 /* Set up the blit operation */ 169 /* Set up the blit operation */
188 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { 170 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
189 Uint32 colorkey; 171 Uint32 colorkey;
207 blitop = MGADWG_BFCOL | MGADWG_BITBLT | 189 blitop = MGADWG_BFCOL | MGADWG_BITBLT |
208 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16); 190 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16);
209 } 191 }
210 mga_wait(7); 192 mga_wait(7);
211 mga_out32(MGAREG_SGN, sign); 193 mga_out32(MGAREG_SGN, sign);
212 mga_out32(MGAREG_AR3, sstart); 194 mga_out32(MGAREG_AR3, start);
213 mga_out32(MGAREG_AR0, sstop); 195 mga_out32(MGAREG_AR0, stop);
214 mga_out32(MGAREG_AR5, sskip); 196 mga_out32(MGAREG_AR5, skip);
215 mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + dstrect->w-1) << 16))); 197 mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + w-1) << 16)));
216 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | dstrect->h); 198 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h);
217 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop); 199 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop);
200
201 FB_AddBusySurface(src);
202 FB_AddBusySurface(dst);
218 203
219 return(0); 204 return(0);
220 } 205 }
221 206
222 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) 207 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
248 233
249 void FB_MatroxAccel(_THIS, __u32 card) 234 void FB_MatroxAccel(_THIS, __u32 card)
250 { 235 {
251 /* We have hardware accelerated surface functions */ 236 /* We have hardware accelerated surface functions */
252 this->CheckHWBlit = CheckHWBlit; 237 this->CheckHWBlit = CheckHWBlit;
253 this->LockHWSurface = LockHWSurface;
254 this->UnlockHWSurface = UnlockHWSurface;
255 wait_vbl = WaitVBL; 238 wait_vbl = WaitVBL;
239 wait_idle = WaitIdle;
256 240
257 /* The Matrox has an accelerated color fill */ 241 /* The Matrox has an accelerated color fill */
258 this->info.blit_fill = 1; 242 this->info.blit_fill = 1;
259 this->FillHWRect = FillHWRect; 243 this->FillHWRect = FillHWRect;
260 244