-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblt32.c
354 lines (303 loc) · 10.6 KB
/
blt32.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/******************************************************************************
* Copyright (c) 2023 Jaroslav Hensl *
* *
* Permission is hereby granted, free of charge, to any person *
* obtaining a copy of this software and associated documentation *
* files (the "Software"), to deal in the Software without *
* restriction, including without limitation the rights to use, *
* copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, *
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
* OTHER DEALINGS IN THE SOFTWARE. *
* *
******************************************************************************/
#include <windows.h>
#include <ddraw.h>
#include <ddrawi.h>
#include <stdint.h>
#include "ddrawi_ddk.h"
#include "vmdahal32.h"
#include "vmhal9x.h"
#include "rop3.h"
#include "transblt.h"
#include "fill.h"
#include "nocrt.h"
/*
* Blt32
*
* 32-bit blit routine.
*/
DDENTRY_FPUSAVE(Blt32, LPDDHAL_BLTDATA, pbd)
{
TRACE_ENTRY
VMDAHAL_t *ddhal = GetHAL(pbd->lpDD);
DWORD dwFlags; // For specifying the type of blit
DWORD dwFillColor; // Used to specify the RGB color to fill with
DWORD dwColorKey; // Holds our color key for a transparent blit
#ifdef TRACE_ON
DWORD dwDstOffset; // offset to beginning of destination surface
#endif
long dwDstWidth; // width of destination surface (in pixels)
long dwDstHeight; // height of destination surface (in rows)
#ifdef TRACE_ON
DWORD dwSrcOffset; // offset to the beginning of source surface
#endif
long dwSrcWidth; // width of source surface (in pixels)
long dwSrcHeight; // height of source surface (in rows)
LPDDRAWI_DDRAWSURFACE_LCL srcx; // local pointer to source surface
LPDDRAWI_DDRAWSURFACE_LCL dstx; // local pointer to destination surface
LPDDRAWI_DDRAWSURFACE_GBL src; // global pointer to source surface
LPDDRAWI_DDRAWSURFACE_GBL dst; // global pointer to destination surface
BOOL isInFront = FALSE; // destination is front surface
dstx = pbd->lpDDDestSurface; // destination surface
dst = dstx->lpGbl; // destination data
dwFlags = pbd->dwFlags;
if(dwFlags & (DDBLT_ZBUFFER | DDBLT_ZBUFFERDESTCONSTOVERRIDE |
DDBLT_ZBUFFERDESTOVERRIDE | DDBLT_ZBUFFERSRCCONSTOVERRIDE |
DDBLT_ZBUFFERSRCOVERRIDE))
{
return DDHAL_DRIVER_NOTHANDLED;
}
isInFront = IsInFront(ddhal, (void*)dst->fpVidMem);
/* remove cursor before blit */
if(isInFront)
{
FBHDA_access_begin(0);
}
/*
* NOTES:
*
* Everything you need is in pdb->bltFX .
* Look at pdb->dwFlags to determine what kind of blit you are doing,
* DDBLT_xxxx are the flags.
*
* COLORKEY NOTES:
*
* ColorKey ALWAY comes in BLTFX. You don't have to look it up in
* the surface.
*/
/*
* is a flip in pending on our destination surface? If so, pass
* ddrval return value and exit
*/
// JH: flip is always synchronous
/*
* If async, then only work if blitter isn't busy
* This should probably be a little more specific to each call, but
* this is pretty close
*/
// JH: blit is always synchronous
/*
* get offset, width, and height for destination
*/
#ifdef TRACE_ON
dwDstOffset = GetOffset(ddhal, (void*)dst->fpVidMem);
#endif
dwDstWidth = pbd->rDest.right - pbd->rDest.left;
dwDstHeight = pbd->rDest.bottom - pbd->rDest.top;
/*
* Handle ROPs such as copy, transparent blits and colorfills
*/
if(dwFlags & DDBLT_ROP)
{
uint8_t rop3_code = (pbd->bltFX.dwROP >> 16) & 0xFF;
srcx = pbd->lpDDSrcSurface;
src = srcx->lpGbl;
#ifdef TRACE_ON
dwSrcOffset = GetOffset(ddhal, (void*)src->fpVidMem);
#endif
dwSrcWidth = pbd->rSrc.right - pbd->rSrc.left;
dwSrcHeight = pbd->rSrc.bottom - pbd->rSrc.top;
dwColorKey = pbd->bltFX.ddckSrcColorkey.dwColorSpaceLowValue;
if(IsInFront(ddhal, (void*)src->fpVidMem) && !isInFront)
{
FBHDA_access_begin(0);
isInFront = TRUE;
}
#ifdef D3DHAL
SurfaceFromMesa(srcx, FALSE);
#endif
/* check if need stretch */
if(dwDstWidth != dwSrcWidth ||
dwDstHeight != dwSrcHeight ||
dwSrcWidth < 0 ||
dwDstHeight < 0)
{
stretchBltRect srect;
srect.mirrorx = 0;
srect.mirrory = 0;
srect.srx = pbd->rSrc.left;
srect.sry = pbd->rSrc.top;
if(dwSrcWidth < 0)
{
srect.srw = -dwSrcWidth;
srect.mirrorx ^= 1;
}
else
{
srect.srw = dwSrcWidth;
}
if(dwSrcHeight < 0)
{
srect.srh = -dwSrcHeight;
srect.mirrory ^= 1;
}
else
{
srect.srh = dwSrcHeight;
}
srect.drx = pbd->rDest.left;
srect.dry = pbd->rDest.top;
if(dwDstWidth < 0)
{
srect.drw = -dwDstWidth;
srect.mirrorx ^= 1;
}
else
{
srect.drw = dwDstWidth;
}
if(dwDstHeight < 0)
{
srect.drh = -dwDstHeight;
srect.mirrory ^= 1;
}
else
{
srect.drh = dwDstHeight;
}
srect.spitch = src->lPitch;
srect.dpitch = dst->lPitch;
/*
srect.sw = srect.dw = ddhal->pFBHDA32->width;
srect.sh = srect.dh = ddhal->pFBHDA32->height;
*/
srect.sw = src->wWidth;
srect.dw = src->wHeight;
srect.sh = dst->wWidth;
srect.dh = dst->wHeight;
if (rop3_code == (SRCCOPY >> 16) && (dwFlags & DDBLT_KEYSRCOVERRIDE))
{
TRACE("Blt: transstretchblt: w = %l -> %l, h = %l -> %l",
dwSrcWidth, dwDstWidth, dwSrcHeight, dwDstHeight);
transstretchblt(ddhal->pFBHDA32->bpp,
(void*)src->fpVidMem, (void*)dst->fpVidMem, dwColorKey, &srect);
}
else
{
TRACE("Blt: stretchrop3: w = %l -> %l, h = %l -> %l",
dwSrcWidth, dwDstWidth, dwSrcHeight, dwDstHeight);
stretchrop3(ddhal->pFBHDA32->bpp, rop3_code,
(void*)src->fpVidMem, (void*)dst->fpVidMem, dwColorKey, &srect);
}
TOPIC("DEPTHCONV", "Blt32 - ROP stretch");
}
else /* ROP 1:1 pixels */
{
DWORD spitch = src->lPitch;
DWORD dpitch = dst->lPitch;
if (rop3_code == (SRCCOPY >> 16) && (dwFlags & DDBLT_KEYSRCOVERRIDE))
{
TRACE("Blt: transblt from %08X %dx%d -> %08X %dx%dx%d key=%08X",
dwSrcOffset, dwSrcWidth, dwSrcHeight, dwDstOffset, dwDstWidth, dwDstHeight, ddhal->pFBHDA32->bpp, dwColorKey);
transblt(ddhal->pFBHDA32->bpp, (void*)src->fpVidMem, (void*)dst->fpVidMem, dwColorKey,
pbd->rSrc.left, pbd->rSrc.top, pbd->rDest.left, pbd->rDest.top, dwSrcWidth, dwSrcHeight, spitch, dpitch);
}
else if(rop3_code == (SRCCOPY >> 16) &&
spitch == dpitch &&
pbd->rSrc.left == 0 && pbd->rSrc.top == 0 &&
pbd->rDest.left == 0 && pbd->rDest.top == 0 &&
pbd->rSrc.right == dwSrcWidth &&
pbd->rSrc.bottom == dwSrcHeight
)
{
TRACE("Blt: full surface copy");
fill_memcpy((void*)dst->fpVidMem, (void*)src->fpVidMem, spitch*dwSrcHeight);
}
else
{
TRACE("Blt: rop3 (%02X) from %08X %dx%d (pitch: %d) -> %08X %dx%d (pitch: %d)",
rop3_code, src->fpVidMem, dwSrcWidth, dwSrcHeight, spitch, dst->fpVidMem, dwDstWidth, dwDstHeight, dpitch);
TRACE("Rect: %dx%d (%dx%d)|pitch %d -> %dx%d|pitch %d|flags %X",
pbd->rSrc.left, pbd->rSrc.top, dwSrcWidth, dwSrcHeight, spitch,
pbd->rDest.left, pbd->rDest.top, dpitch, dwFlags);
rop3(ddhal->pFBHDA32->bpp, rop3_code, (void*)src->fpVidMem, (void*)dst->fpVidMem, dwColorKey,
pbd->rSrc.left, pbd->rSrc.top, pbd->rDest.left, pbd->rDest.top, dwSrcWidth, dwSrcHeight, spitch, dpitch);
}
} /* nostrech copy */
TOPIC("DEPTHCONV", "Blt32 - ROP 1:1");
#ifdef D3DHAL
SurfaceToMesa(dstx, FALSE);
#endif
}
else if (dwFlags & (DDBLT_COLORFILL | DDBLT_DEPTHFILL))
{
DWORD bpp = ddhal->pFBHDA32->bpp;
if(dstx->dwFlags & DDRAWISURF_HASPIXELFORMAT)
{
bpp = dst->ddpfSurface.dwRGBBitCount;
}
TOPIC("GL", "Blt BPP: %d", bpp);
dwFillColor = pbd->bltFX.dwFillColor;
if(dwFlags & DDBLT_DEPTHFILL)
{
dwFillColor = pbd->bltFX.dwFillDepth;
}
TOPIC("GL", "Blt: rop3 (F0)");
TRACE("Blt: rop3 (F0) %08X %dx%d", dwFillColor, dwDstWidth, dwDstHeight);
if(pbd->rDest.left == 0 && pbd->rDest.top == 0 &&
pbd->rDest.right == dwDstWidth &&
pbd->rDest.bottom == dwDstHeight)
{
// we don't need read GL FB here - it'll be overwritten
fill((void*)dst->fpVidMem, dst->lPitch*dwDstHeight, bpp, dwFillColor);
}
else
{
rop3(bpp, 0xF0, (void*)dst->fpVidMem, (void*)dst->fpVidMem, dwFillColor,
pbd->rDest.left, pbd->rDest.top, pbd->rDest.left, pbd->rDest.top, dwDstWidth, dwDstHeight, dst->lPitch, dst->lPitch);
}
SurfaceZToMesa(dstx, dwFillColor);
TOPIC("DEPTHCONV", "Blt32 - DDBLT_COLORFILL | DDBLT_DEPTHFILL");
#ifdef D3DHAL
SurfaceToMesa(dstx, FALSE);
#endif
}
else
{
if(isInFront)
{
FBHDA_access_end(0);
}
// This is where you would handle extra ROPs
WARN("invalid BLR %X", dwFlags);
return DDHAL_DRIVER_NOTHANDLED;
// we couldn't handle the blt, pass it on to HEL
}
if(isInFront)
{
FBHDA_access_end(0);
}
TRACE("BLT32 done");
pbd->ddRVal = DD_OK; // pass the return value
return DDHAL_DRIVER_HANDLED; // Blt successful, exit function
} /* Blt32 */
DDENTRY(GetBltStatus32, LPDDHAL_GETBLTSTATUSDATA, pbd)
{
TRACE_ENTRY
/* we do nothing async yet, so return always success */
pbd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
} /* GetFlipStatus32 */