1 /*===========================================================================*/
3 /* Mesa-3.0 DirectX 6 Driver */
7 /* http://www.altsoftware.com/ */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
12 /*===========================================================================*/
13 /* Local only functions. */
14 /*===========================================================================*/
15 static int CountTrailingZeros( DWORD dwMask );
16 /*===========================================================================*/
17 /* This function is used to get the pointer to the surface and the pitch for*/
18 /* the scanline rendering functions. */
19 /*===========================================================================*/
21 /*===========================================================================*/
22 extern "C" DDSURFACEDESC2 *LockHAL( PMESAD3DSHARED pShared, BOOL bBack )
24 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
25 static DDSURFACEDESC2 ddsd2;
28 DPF(( DBG_FUNC, "LockHAL();" ));
30 /* Set the request structure up first. */
31 memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) );
32 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
34 /* Make sure we have enough info. */
37 rc = pHAL->lpDDSRender->Lock( NULL, &ddsd2, DDLOCK_WAIT, NULL );
40 RIP( pHAL, "Lock (RENDER) ->", ErrorStringD3D(rc) );
46 /*===========================================================================*/
47 /* This is just a simple wrapper. I probably don't need to do any error */
48 /* checking as the Lock must have worked inorder to get here... */
49 /*===========================================================================*/
51 /*===========================================================================*/
52 extern "C" void UnlockHAL( PMESAD3DSHARED pShared, BOOL bBack )
54 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
57 DPF(( DBG_FUNC, "UnlockHAL();" ));
59 /* Make sure we have enough info. */
62 rc = pHAL->lpDDSRender->Unlock( NULL );
65 RIP( pHAL, "Unlock (RENDER) ->", ErrorStringD3D(rc) );
69 /*===========================================================================*/
70 /* This function will track the main/Primary window that will be used as the*/
71 /* target for the Blt in SwapBuffers. As a side effect the call will check */
72 /* to see if the primary surface is the same size and position as the screen.*/
73 /* If they are the same size we will call it fullscreen... */
74 /*===========================================================================*/
76 /*===========================================================================*/
77 extern "C" void UpdateScreenPosHAL( PMESAD3DSHARED pShared )
79 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
81 DWORD dwWidth, dwHeight;
83 DPF(( DBG_FUNC, "UpdateScreenPosHAL();" ));
85 /* Make sure we have enough info. */
88 /* Update the windows screen position. */
89 GetClientRect( pShared->hwnd, &pShared->rectW );
91 ClientToScreen( pShared->hwnd, &pt );
92 OffsetRect( &pShared->rectW, pt.x, pt.y);
94 /* Compare the primary to the screen. */
95 dwWidth = GetSystemMetrics( SM_CXSCREEN );
96 dwHeight = GetSystemMetrics( SM_CYSCREEN );
97 if ( (pShared->rectW.left > 0) || (pShared->rectW.top > 0) ||
98 (pShared->rectW.right > dwWidth) || (pShared->rectW.bottom > dwHeight) )
99 pShared->bWindow = TRUE;
101 pShared->bWindow = FALSE;
104 /*===========================================================================*/
105 /* This function will fill in the pixel info structure defined in D3Dshared.*/
106 /* Basicly it will take a DirectDraw pixelformat structure and make scaling */
107 /* values that will convert from 8bit channels to whatever the supplied ddpf */
108 /* uses. Also we will generate shift values that will be used to get move */
109 /* each component of the pixel into place. */
110 /* I have now added a special case for a 1bit alpha channel. If I find a 1b*/
111 /* alpha then I will set the scale to -1.0 which should be unique. Later I */
112 /* can check the alpha scale value too see if its -1.0 and thus handle it. I*/
113 /* was finding that the case was not working tom my advantage so this is my */
114 /* HACK for the day. As a TODO I should work on this... */
115 /*===========================================================================*/
117 /*===========================================================================*/
118 void Solve8BitChannelPixelFormat( DDPIXELFORMAT *pddpf, PPIXELINFO pPixel )
120 DPF(( DBG_FUNC, "Solve8BitChannelPixelFromat();" ));
122 memset( pPixel, 0, sizeof(PPIXELINFO) );
124 /* Check too see if the color space is valid in the PF. */
125 if ( pddpf->dwFlags & DDPF_RGB )
127 /* Solve the red stuff. */
128 pPixel->dwRMask = pddpf->dwRBitMask;
129 pPixel->rShift = CountTrailingZeros( pPixel->dwRMask );
130 pPixel->rScale = (float)0.00392156 * (float)(pPixel->dwRMask >> pPixel->rShift);
132 /* Solve the green thingy's. */
133 pPixel->dwGMask = pddpf->dwGBitMask;
134 pPixel->gShift = CountTrailingZeros( pPixel->dwGMask );
135 pPixel->gScale = (float)0.00392156 * (float)(pPixel->dwGMask >> pPixel->gShift);
137 /* Solve the blues. */
138 pPixel->dwBMask = pddpf->dwBBitMask;
139 pPixel->bShift = CountTrailingZeros( pddpf->dwBBitMask );
140 pPixel->bScale = (float)0.00392156 * (float)(pddpf->dwBBitMask >> pPixel->bShift);
143 /* Do the alpha channel if there is one. */
144 if ( pddpf->dwFlags & DDPF_ALPHAPIXELS )
146 pPixel->dwAMask = pddpf->dwRGBAlphaBitMask;
147 pPixel->aShift = CountTrailingZeros( pPixel->dwAMask );
149 /* Special case a 1bit alpha. */
150 if ( (pPixel->dwAMask >> pPixel->aShift) == 1 )
151 pPixel->aScale = -1.0;
153 pPixel->aScale = (float)0.00392156 * (float)(pPixel->dwAMask >> pPixel->aShift);
156 /* Get the size of the pixel in bytes. Should work as dwRGBBitCount is in a union. */
157 pPixel->cb = pddpf->dwRGBBitCount / 8;
159 /*===========================================================================*/
161 /*===========================================================================*/
162 /* RETURN: number of contiguous zeros starting from the right. */
163 /*===========================================================================*/
164 static int CountTrailingZeros( DWORD dwMask )
171 /* Can't take credit for this one! */
172 Mask = dwMask & -(int)dwMask;
173 return ((Mask & 0xFFFF0000)!=0) << 4
174 | ((Mask & 0xFF00FF00)!=0) << 3
175 | ((Mask & 0xF0F0F0F0)!=0) << 2
176 | ((Mask & 0xCCCCCCCC)!=0) << 1
177 | ((Mask & 0xAAAAAAAA)!=0);
179 /*===========================================================================*/
180 /* This function will convert the DDraw error code to its macro string. The*/
181 /* returned pointer is static so you need not worry about memory managemnet */
182 /* but the error message gets written over from call to call... */
183 /*===========================================================================*/
184 /* RETURN: pointer to the single static buffer that hold the error message. */
185 /*===========================================================================*/
186 char *ErrorStringD3D( HRESULT hr )
188 static char errorString[128];
192 case DDERR_ALREADYINITIALIZED:
193 strcpy( errorString, "DDERR_ALREADYINITIALIZED" );
196 case DDERR_CANNOTATTACHSURFACE:
197 strcpy( errorString, "DDERR_CANNOTATTACHSURFACE" );
200 case DDERR_CANNOTDETACHSURFACE:
201 strcpy( errorString, "DDERR_CANNOTDETACHSURFACE" );
204 case DDERR_CURRENTLYNOTAVAIL:
205 strcpy( errorString, "DDERR_CURRENTLYNOTAVAIL" );
208 case DDERR_EXCEPTION:
209 strcpy( errorString, "DDERR_EXCEPTION" );
213 strcpy( errorString, "DDERR_GENERIC" );
216 case DDERR_HEIGHTALIGN:
217 strcpy( errorString, "DDERR_HEIGHTALIGN" );
220 case DDERR_INCOMPATIBLEPRIMARY:
221 strcpy( errorString, "DDERR_INCOMPATIBLEPRIMARY" );
224 case DDERR_INVALIDCAPS:
225 strcpy( errorString, "DDERR_INVALIDCAPS" );
228 case DDERR_INVALIDCLIPLIST:
229 strcpy( errorString, "DDERR_INVALIDCLIPLIST" );
232 case DDERR_INVALIDMODE:
233 strcpy( errorString, "DDERR_INVALIDMODE" );
236 case DDERR_INVALIDOBJECT:
237 strcpy( errorString, "DDERR_INVALIDOBJECT" );
240 case DDERR_INVALIDPARAMS:
241 strcpy( errorString, "DDERR_INVALIDPARAMS" );
244 case DDERR_INVALIDPIXELFORMAT:
245 strcpy( errorString, "DDERR_INVALIDPIXELFORMAT" );
248 case DDERR_INVALIDRECT:
249 strcpy( errorString, "DDERR_INVALIDRECT" );
252 case DDERR_LOCKEDSURFACES:
253 strcpy( errorString, "DDERR_LOCKEDSURFACES" );
257 strcpy( errorString, "DDERR_NO3D" );
260 case DDERR_NOALPHAHW:
261 strcpy( errorString, "DDERR_NOALPHAHW" );
264 case DDERR_NOCLIPLIST:
265 strcpy( errorString, "DDERR_NOCLIPLIST" );
268 case DDERR_NOCOLORCONVHW:
269 strcpy( errorString, "DDERR_NOCOLORCONVHW" );
272 case DDERR_NOCOOPERATIVELEVELSET:
273 strcpy( errorString, "DDERR_NOCOOPERATIVELEVELSET" );
276 case DDERR_NOCOLORKEY:
277 strcpy( errorString, "DDERR_NOCOLORKEY" );
280 case DDERR_NOCOLORKEYHW:
281 strcpy( errorString, "DDERR_NOCOLORKEYHW" );
284 case DDERR_NODIRECTDRAWSUPPORT:
285 strcpy( errorString, "DDERR_NODIRECTDRAWSUPPORT" );
288 case DDERR_NOEXCLUSIVEMODE:
289 strcpy( errorString, "DDERR_NOEXCLUSIVEMODE" );
293 strcpy( errorString, "DDERR_NOFLIPHW" );
297 strcpy( errorString, "DDERR_NOGDI" );
300 case DDERR_NOMIRRORHW:
301 strcpy( errorString, "DDERR_NOMIRRORHW" );
305 strcpy( errorString, "DDERR_NOTFOUND" );
308 case DDERR_NOOVERLAYHW:
309 strcpy( errorString, "DDERR_NOOVERLAYHW" );
312 case DDERR_OVERLAPPINGRECTS:
313 strcpy( errorString, "DDERR_OVERLAPPINGRECTS" );
316 case DDERR_NORASTEROPHW:
317 strcpy( errorString, "DDERR_NORASTEROPHW" );
320 case DDERR_NOROTATIONHW:
321 strcpy( errorString, "DDERR_NOROTATIONHW" );
324 case DDERR_NOSTRETCHHW:
325 strcpy( errorString, "DDERR_NOSTRETCHHW" );
328 case DDERR_NOT4BITCOLOR:
329 strcpy( errorString, "DDERR_NOT4BITCOLOR" );
332 case DDERR_NOT4BITCOLORINDEX:
333 strcpy( errorString, "DDERR_NOT4BITCOLORINDEX" );
336 case DDERR_NOT8BITCOLOR:
337 strcpy( errorString, "DDERR_NOT8BITCOLOR" );
340 case DDERR_NOTEXTUREHW:
341 strcpy( errorString, "DDERR_NOTEXTUREHW" );
344 case DDERR_NOVSYNCHW:
345 strcpy( errorString, "DDERR_NOVSYNCHW" );
348 case DDERR_NOZBUFFERHW:
349 strcpy( errorString, "DDERR_NOZBUFFERHW" );
352 case DDERR_NOZOVERLAYHW:
353 strcpy( errorString, "DDERR_NOZOVERLAYHW" );
356 case DDERR_OUTOFCAPS:
357 strcpy( errorString, "DDERR_OUTOFCAPS" );
360 case DDERR_OUTOFMEMORY:
361 strcpy( errorString, "DDERR_OUTOFMEMORY" );
364 case DDERR_OUTOFVIDEOMEMORY:
365 strcpy( errorString, "DDERR_OUTOFVIDEOMEMORY" );
368 case DDERR_OVERLAYCANTCLIP:
369 strcpy( errorString, "DDERR_OVERLAYCANTCLIP" );
372 case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
373 strcpy( errorString, "DDERR_OVERLAYCOLORKEYONLYONEACTIVE" );
376 case DDERR_PALETTEBUSY:
377 strcpy( errorString, "DDERR_PALETTEBUSY" );
380 case DDERR_COLORKEYNOTSET:
381 strcpy( errorString, "DDERR_COLORKEYNOTSET" );
384 case DDERR_SURFACEALREADYATTACHED:
385 strcpy( errorString, "DDERR_SURFACEALREADYATTACHED" );
388 case DDERR_SURFACEALREADYDEPENDENT:
389 strcpy( errorString, "DDERR_SURFACEALREADYDEPENDENT" );
392 case DDERR_SURFACEBUSY:
393 strcpy( errorString, "DDERR_SURFACEBUSY" );
396 case DDERR_CANTLOCKSURFACE:
397 strcpy( errorString, "DDERR_CANTLOCKSURFACE" );
400 case DDERR_SURFACEISOBSCURED:
401 strcpy( errorString, "DDERR_SURFACEISOBSCURED" );
404 case DDERR_SURFACELOST:
405 strcpy( errorString, "DDERR_SURFACELOST" );
408 case DDERR_SURFACENOTATTACHED:
409 strcpy( errorString, "DDERR_SURFACENOTATTACHED" );
412 case DDERR_TOOBIGHEIGHT:
413 strcpy( errorString, "DDERR_TOOBIGHEIGHT" );
416 case DDERR_TOOBIGSIZE:
417 strcpy( errorString, "DDERR_TOOBIGSIZE" );
420 case DDERR_TOOBIGWIDTH:
421 strcpy( errorString, "DDERR_TOOBIGWIDTH" );
424 case DDERR_UNSUPPORTED:
425 strcpy( errorString, "DDERR_UNSUPPORTED" );
428 case DDERR_UNSUPPORTEDFORMAT:
429 strcpy( errorString, "DDERR_UNSUPPORTEDFORMAT" );
432 case DDERR_UNSUPPORTEDMASK:
433 strcpy( errorString, "DDERR_UNSUPPORTEDMASK" );
436 case DDERR_INVALIDSTREAM:
437 strcpy( errorString, "DDERR_INVALIDSTREAM" );
440 case DDERR_VERTICALBLANKINPROGRESS:
441 strcpy( errorString, "DDERR_VERTICALBLANKINPROGRESS" );
444 case DDERR_WASSTILLDRAWING:
445 strcpy( errorString, "DDERR_WASSTILLDRAWING" );
449 strcpy( errorString, "DDERR_XALIGN" );
452 case DDERR_INVALIDDIRECTDRAWGUID:
453 strcpy( errorString, "DDERR_INVALIDDIRECTDRAWGUID" );
456 case DDERR_DIRECTDRAWALREADYCREATED:
457 strcpy( errorString, "DDERR_DIRECTDRAWALREADYCREATED" );
460 case DDERR_NODIRECTDRAWHW:
461 strcpy( errorString, "DDERR_NODIRECTDRAWHW" );
464 case DDERR_PRIMARYSURFACEALREADYEXISTS:
465 strcpy( errorString, "DDERR_PRIMARYSURFACEALREADYEXISTS" );
468 case DDERR_NOEMULATION:
469 strcpy( errorString, "DDERR_NOEMULATION" );
472 case DDERR_REGIONTOOSMALL:
473 strcpy( errorString, "DDERR_REGIONTOOSMALL" );
476 case DDERR_CLIPPERISUSINGHWND:
477 strcpy( errorString, "DDERR_CLIPPERISUSINGHWND" );
480 case DDERR_NOCLIPPERATTACHED:
481 strcpy( errorString, "DDERR_NOCLIPPERATTACHED" );
485 strcpy( errorString, "DDERR_NOHWND" );
488 case DDERR_HWNDSUBCLASSED:
489 strcpy( errorString, "DDERR_HWNDSUBCLASSED" );
492 case DDERR_HWNDALREADYSET:
493 strcpy( errorString, "DDERR_HWNDALREADYSET" );
496 case DDERR_NOPALETTEATTACHED:
497 strcpy( errorString, "DDERR_NOPALETTEATTACHED" );
500 case DDERR_NOPALETTEHW:
501 strcpy( errorString, "DDERR_NOPALETTEHW" );
504 case DDERR_BLTFASTCANTCLIP:
505 strcpy( errorString, "DDERR_BLTFASTCANTCLIP" );
509 strcpy( errorString, "DDERR_NOBLTHW" );
512 case DDERR_NODDROPSHW:
513 strcpy( errorString, "DDERR_NODDROPSHW" );
516 case DDERR_OVERLAYNOTVISIBLE:
517 strcpy( errorString, "DDERR_OVERLAYNOTVISIBLE" );
520 case DDERR_NOOVERLAYDEST:
521 strcpy( errorString, "DDERR_NOOVERLAYDEST" );
524 case DDERR_INVALIDPOSITION:
525 strcpy( errorString, "DDERR_INVALIDPOSITION" );
528 case DDERR_NOTAOVERLAYSURFACE:
529 strcpy( errorString, "DDERR_NOTAOVERLAYSURFACE" );
532 case DDERR_EXCLUSIVEMODEALREADYSET:
533 strcpy( errorString, "DDERR_EXCLUSIVEMODEALREADYSET" );
536 case DDERR_NOTFLIPPABLE:
537 strcpy( errorString, "DDERR_NOTFLIPPABLE" );
540 case DDERR_CANTDUPLICATE:
541 strcpy( errorString, "DDERR_CANTDUPLICATE" );
544 case DDERR_NOTLOCKED:
545 strcpy( errorString, "DDERR_NOTLOCKED" );
548 case DDERR_CANTCREATEDC:
549 strcpy( errorString, "DDERR_CANTCREATEDC" );
553 strcpy( errorString, "DDERR_NODC" );
556 case DDERR_WRONGMODE:
557 strcpy( errorString, "DDERR_WRONGMODE" );
560 case DDERR_IMPLICITLYCREATED:
561 strcpy( errorString, "DDERR_IMPLICITLYCREATED" );
564 case DDERR_NOTPALETTIZED:
565 strcpy( errorString, "DDERR_NOTPALETTIZED" );
568 case DDERR_UNSUPPORTEDMODE:
569 strcpy( errorString, "DDERR_UNSUPPORTEDMODE" );
572 case DDERR_NOMIPMAPHW:
573 strcpy( errorString, "DDERR_NOMIPMAPHW" );
576 case DDERR_INVALIDSURFACETYPE:
577 strcpy( errorString, "DDERR_INVALIDSURFACETYPE" );
580 case DDERR_NOOPTIMIZEHW:
581 strcpy( errorString, "DDERR_NOOPTIMIZEHW" );
584 case DDERR_NOTLOADED:
585 strcpy( errorString, "DDERR_NOTLOADED" );
588 case DDERR_NOFOCUSWINDOW:
589 strcpy( errorString, "DDERR_NOFOCUSWINDOW" );
592 case DDERR_DCALREADYCREATED:
593 strcpy( errorString, "DDERR_DCALREADYCREATED" );
596 case DDERR_NONONLOCALVIDMEM:
597 strcpy( errorString, "DDERR_NONONLOCALVIDMEM" );
600 case DDERR_CANTPAGELOCK:
601 strcpy( errorString, "DDERR_CANTPAGELOCK" );
604 case DDERR_CANTPAGEUNLOCK:
605 strcpy( errorString, "DDERR_CANTPAGEUNLOCK" );
608 case DDERR_NOTPAGELOCKED:
609 strcpy( errorString, "DDERR_NOTPAGELOCKED" );
613 strcpy( errorString, "DDERR_MOREDATA" );
617 strcpy( errorString, "DDERR_EXPIRED" );
620 case DDERR_VIDEONOTACTIVE:
621 strcpy( errorString, "DDERR_VIDEONOTACTIVE" );
624 case DDERR_DEVICEDOESNTOWNSURFACE:
625 strcpy( errorString, "DDERR_DEVICEDOESNTOWNSURFACE" );
628 case DDERR_NOTINITIALIZED:
629 strcpy( errorString, "DDERR_NOTINITIALIZED" );
633 strcpy( errorString, "<unknown error code>" );
637 return &errorString[0];