| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <string.h> | 
|---|
| 3 | #include <memory.h> | 
|---|
| 4 | #define mmioFOURCC( ch0, ch1, ch2, ch3 )                         \ | 
|---|
| 5 | ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \ | 
|---|
| 6 | ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) ) | 
|---|
| 7 | #include <fourcc.h> | 
|---|
| 8 | #define INITGUID | 
|---|
| 9 | #include "os2ddraw.h" | 
|---|
| 10 | #include "os2clipper.h" | 
|---|
| 11 | #include "os2palette.h" | 
|---|
| 12 | #include "os2surface.h" | 
|---|
| 13 | #include "rectangle.h" | 
|---|
| 14 | #define _OS2WIN_H | 
|---|
| 15 | #define FAR | 
|---|
| 16 | #include "misc.h" | 
|---|
| 17 | #include "asmutil.h" | 
|---|
| 18 | #include <winerror.h> | 
|---|
| 19 | #include <os2win.h> | 
|---|
| 20 | #ifndef __WATCOMC__ | 
|---|
| 21 | #include <builtin.h> | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | extern FOURCC  SupportedFourCCs[]; | 
|---|
| 25 | // ToDo: Move the following 2 defines in the right WINE headers. | 
|---|
| 26 | BYTE DefaultPalette[] = { 0x00,0x00,0x00,   // 0 | 
|---|
| 27 | 0x80,0x00,0x00,   // 1 | 
|---|
| 28 | 0x00,0x80,0x00,   // 2 | 
|---|
| 29 | 0x80,0x80,0x00,   // 3 | 
|---|
| 30 | 0x00,0x00,0x80,   // 4 | 
|---|
| 31 | 0x80,0x00,0x80,   // 5 | 
|---|
| 32 | 0x00,0x80,0x80,   // 6 | 
|---|
| 33 | 0xC0,0xC0,0xC0,   // 7 | 
|---|
| 34 | 0xC0,0xDC,0xC0,   // 8 | 
|---|
| 35 | 0xA6,0xCA,0xF0,   // 9 | 
|---|
| 36 | 0x04,0x04,0x04,   // 10 | 
|---|
| 37 | 0x08,0x08,0x08,   // 11 | 
|---|
| 38 | 0x0C,0x0C,0x0C,   // 12 | 
|---|
| 39 | 0x11,0x11,0x11,   // 13 | 
|---|
| 40 | 0x16,0x16,0x16,   // 14 | 
|---|
| 41 | 0x1C,0x1C,0x1C,   // 15 | 
|---|
| 42 | 0x22,0x22,0x22,   // 16 | 
|---|
| 43 | 0x29,0x29,0x29,   // 17 | 
|---|
| 44 | 0x55,0x55,0x55,   // 18 | 
|---|
| 45 | 0x4D,0x4D,0x4D, | 
|---|
| 46 | 0x42,0x42,0x42, | 
|---|
| 47 | 0x39,0x39,0x39, | 
|---|
| 48 | 0x81,0x81,0x81, | 
|---|
| 49 | 0x81,0x00,0x00, | 
|---|
| 50 | 0x00,0x81,0x00, | 
|---|
| 51 | 0x81,0x81,0x00, | 
|---|
| 52 | 0x00,0x00,0x81, | 
|---|
| 53 | 0x81,0x00,0x81, | 
|---|
| 54 | 0x00,0x81,0x81, | 
|---|
| 55 | 0x33,0x00,0x00, | 
|---|
| 56 | 0x66,0x00,0x00, | 
|---|
| 57 | 0x99,0x00,0x00, | 
|---|
| 58 | 0xCC,0x00,0x00, | 
|---|
| 59 | 0x00,0x33,0x00, | 
|---|
| 60 | 0x33,0x33,0x00, | 
|---|
| 61 | 0x66,0x33,0x00, | 
|---|
| 62 | 0x99,0x33,0x00, | 
|---|
| 63 | 0xCC,0x33,0x00, | 
|---|
| 64 | 0xFF,0x33,0x00, | 
|---|
| 65 | 0x00,0x66,0x00, | 
|---|
| 66 | 0x33,0x66,0x00, | 
|---|
| 67 | 0x66,0x66,0x00, | 
|---|
| 68 | 0x99,0x66,0x00, | 
|---|
| 69 | 0xCC,0x66,0x00, | 
|---|
| 70 | 0xFF,0x66,0x00, | 
|---|
| 71 | 0x00,0x99,0x00, | 
|---|
| 72 | 0x33,0x99,0x00, | 
|---|
| 73 | 0x66,0x99,0x00, | 
|---|
| 74 | 0x99,0x99,0x00, | 
|---|
| 75 | 0xCC,0x99,0x00, | 
|---|
| 76 | 0xFF,0x99,0x00, | 
|---|
| 77 | 0x00,0xCC,0x00, | 
|---|
| 78 | 0x33,0xCC,0x00, | 
|---|
| 79 | 0x66,0xCC,0x00, | 
|---|
| 80 | 0x99,0xCC,0x00, | 
|---|
| 81 | 0xCC,0xCC,0x00, | 
|---|
| 82 | 0xFF,0xCC,0x00, | 
|---|
| 83 | 0x66,0xFF,0x00, | 
|---|
| 84 | 0x99,0xFF,0x00, | 
|---|
| 85 | 0xCC,0xFF,0x00, | 
|---|
| 86 | 0x00,0x00,0x33, | 
|---|
| 87 | 0x33,0x00,0x33, | 
|---|
| 88 | 0x66,0x00,0x33, | 
|---|
| 89 | 0x99,0x00,0x33, | 
|---|
| 90 | 0xCC,0x00,0x33, | 
|---|
| 91 | 0xFF,0x00,0x33, | 
|---|
| 92 | 0x00,0x33,0x33, | 
|---|
| 93 | 0x33,0x33,0x33, | 
|---|
| 94 | 0x66,0x33,0x33, | 
|---|
| 95 | 0x99,0x33,0x33, | 
|---|
| 96 | 0xCC,0x33,0x33, | 
|---|
| 97 | 0xFF,0x33,0x33, | 
|---|
| 98 | 0x00,0x66,0x33, | 
|---|
| 99 | 0x33,0x66,0x33, | 
|---|
| 100 | 0x66,0x66,0x33, | 
|---|
| 101 | 0x99,0x66,0x33, | 
|---|
| 102 | 0xCC,0x66,0x33, | 
|---|
| 103 | 0xFF,0x66,0x33, | 
|---|
| 104 | 0x00,0x99,0x33, | 
|---|
| 105 | 0x33,0x99,0x33, | 
|---|
| 106 | 0x66,0x99,0x33, | 
|---|
| 107 | 0x99,0x99,0x33, | 
|---|
| 108 | 0xCC,0x99,0x33, | 
|---|
| 109 | 0xFF,0x99,0x33, | 
|---|
| 110 | 0x00,0xCC,0x33, | 
|---|
| 111 | 0x33,0xCC,0x33, | 
|---|
| 112 | 0x66,0xCC,0x33, | 
|---|
| 113 | 0x99,0xCC,0x33, | 
|---|
| 114 | 0xCC,0xCC,0x33, | 
|---|
| 115 | 0xFF,0xCC,0x33, | 
|---|
| 116 | 0x33,0xFF,0x33, | 
|---|
| 117 | 0x66,0xFF,0x33, | 
|---|
| 118 | 0x99,0xFF,0x33, | 
|---|
| 119 | 0xCC,0xFF,0x33, | 
|---|
| 120 | 0xFF,0xFF,0x33, | 
|---|
| 121 | 0x00,0x00,0x66, | 
|---|
| 122 | 0x33,0x00,0x66, | 
|---|
| 123 | 0x66,0x00,0x66, | 
|---|
| 124 | 0x99,0x00,0x66, | 
|---|
| 125 | 0xCC,0x00,0x66, | 
|---|
| 126 | 0xFF,0x00,0x66, | 
|---|
| 127 | 0x00,0x33,0x66, | 
|---|
| 128 | 0x33,0x33,0x66, | 
|---|
| 129 | 0x66,0x33,0x66, | 
|---|
| 130 | 0x99,0x33,0x66, | 
|---|
| 131 | 0xCC,0x33,0x66, | 
|---|
| 132 | 0xFF,0x33,0x66, | 
|---|
| 133 | 0x00,0x66,0x66, | 
|---|
| 134 | 0x33,0x66,0x66, | 
|---|
| 135 | 0x66,0x66,0x66, | 
|---|
| 136 | 0x99,0x66,0x66, | 
|---|
| 137 | 0xCC,0x66,0x66, | 
|---|
| 138 | 0x00,0x99,0x66, | 
|---|
| 139 | 0x33,0x99,0x66, | 
|---|
| 140 | 0x66,0x99,0x66, | 
|---|
| 141 | 0x99,0x99,0x66, | 
|---|
| 142 | 0xCC,0x99,0x66, | 
|---|
| 143 | 0xFF,0x99,0x66, | 
|---|
| 144 | 0x00,0xCC,0x66, | 
|---|
| 145 | 0x33,0xCC,0x66, | 
|---|
| 146 | 0x99,0xCC,0x66, | 
|---|
| 147 | 0xCC,0xCC,0x66, | 
|---|
| 148 | 0xFF,0xCC,0x66, | 
|---|
| 149 | 0x00,0xFF,0x66, | 
|---|
| 150 | 0x33,0xFF,0x66, | 
|---|
| 151 | 0x99,0xFF,0x66, | 
|---|
| 152 | 0xCC,0xFF,0x66, | 
|---|
| 153 | 0xFF,0x00,0xCC, | 
|---|
| 154 | 0xCC,0x00,0xFF, | 
|---|
| 155 | 0x00,0x99,0x99, | 
|---|
| 156 | 0x99,0x33,0x99, | 
|---|
| 157 | 0x99,0x00,0x99, | 
|---|
| 158 | 0xCC,0x00,0x99, | 
|---|
| 159 | 0x00,0x00,0x99, | 
|---|
| 160 | 0x33,0x33,0x99, | 
|---|
| 161 | 0x66,0x00,0x99, | 
|---|
| 162 | 0xCC,0x33,0x99, | 
|---|
| 163 | 0xFF,0x00,0x99, | 
|---|
| 164 | 0x00,0x66,0x99, | 
|---|
| 165 | 0x33,0x33,0x99, | 
|---|
| 166 | 0x33,0x66,0x99, | 
|---|
| 167 | 0x66,0x33,0x99, | 
|---|
| 168 | 0x99,0x33,0x99, | 
|---|
| 169 | 0xCC,0x66,0x99, | 
|---|
| 170 | 0xFF,0x33,0x99, | 
|---|
| 171 | 0x33,0x99,0x99, | 
|---|
| 172 | 0x66,0x99,0x99, | 
|---|
| 173 | 0x99,0x99,0x99, | 
|---|
| 174 | 0xCC,0x99,0x99, | 
|---|
| 175 | 0xFF,0x99,0x99, | 
|---|
| 176 | 0x00,0xCC,0x99, | 
|---|
| 177 | 0x33,0xCC,0x99, | 
|---|
| 178 | 0x66,0xCC,0x66, | 
|---|
| 179 | 0x99,0xCC,0x99, | 
|---|
| 180 | 0xCC,0xCC,0x99, | 
|---|
| 181 | 0xFF,0xCC,0x99, | 
|---|
| 182 | 0x00,0xFF,0x99, | 
|---|
| 183 | 0x33,0xFF,0x99, | 
|---|
| 184 | 0x66,0xCC,0x99, | 
|---|
| 185 | 0x99,0xFF,0x99, | 
|---|
| 186 | 0xCC,0xFF,0x99, | 
|---|
| 187 | 0xFF,0xFF,0x99, | 
|---|
| 188 | 0x00,0x00,0xCC, | 
|---|
| 189 | 0x33,0x00,0x99, | 
|---|
| 190 | 0x66,0x00,0xCC, | 
|---|
| 191 | 0x99,0x00,0xCC, | 
|---|
| 192 | 0xCC,0x00,0xCC, | 
|---|
| 193 | 0x00,0x33,0x99, | 
|---|
| 194 | 0x33,0x33,0xCC, | 
|---|
| 195 | 0x66,0x33,0xCC, | 
|---|
| 196 | 0x99,0x33,0xCC, | 
|---|
| 197 | 0xCC,0x33,0xCC, | 
|---|
| 198 | 0xFF,0x33,0xCC, | 
|---|
| 199 | 0x00,0x66,0xCC, | 
|---|
| 200 | 0x33,0x66,0xCC, | 
|---|
| 201 | 0x66,0x66,0x99, | 
|---|
| 202 | 0x99,0x66,0xCC, | 
|---|
| 203 | 0xCC,0x66,0xCC, | 
|---|
| 204 | 0xFF,0x66,0x99, | 
|---|
| 205 | 0x00,0x99,0xCC, | 
|---|
| 206 | 0x33,0x99,0xCC, | 
|---|
| 207 | 0x66,0x99,0xCC, | 
|---|
| 208 | 0x99,0x99,0xCC, | 
|---|
| 209 | 0xCC,0x99,0xCC, | 
|---|
| 210 | 0xFF,0x99,0xCC, | 
|---|
| 211 | 0x00,0xCC,0xCC, | 
|---|
| 212 | 0x33,0xCC,0xCC, | 
|---|
| 213 | 0x66,0xCC,0xCC, | 
|---|
| 214 | 0x99,0xCC,0xCC, | 
|---|
| 215 | 0xCC,0xCC,0xCC, | 
|---|
| 216 | 0xFF,0xCC,0xCC, | 
|---|
| 217 | 0x00,0xFF,0xCC, | 
|---|
| 218 | 0x33,0xFF,0xCC, | 
|---|
| 219 | 0x66,0xFF,0x99, | 
|---|
| 220 | 0x99,0xFF,0xCC, | 
|---|
| 221 | 0xCC,0xFF,0xCC, | 
|---|
| 222 | 0xFF,0xFF,0xCC, | 
|---|
| 223 | 0x33,0x00,0xCC, | 
|---|
| 224 | 0x66,0x00,0xFF, | 
|---|
| 225 | 0x99,0x00,0xFF, | 
|---|
| 226 | 0x00,0x33,0xCC, | 
|---|
| 227 | 0x33,0x33,0xFF, | 
|---|
| 228 | 0x66,0x33,0xFF, | 
|---|
| 229 | 0x99,0x33,0xFF, | 
|---|
| 230 | 0xCC,0x33,0xFF, | 
|---|
| 231 | 0xFF,0x33,0xFF, | 
|---|
| 232 | 0x00,0x66,0xFF, | 
|---|
| 233 | 0x33,0x66,0xFF, | 
|---|
| 234 | 0x66,0x66,0xCC, | 
|---|
| 235 | 0x99,0x66,0xFF, | 
|---|
| 236 | 0xCC,0x66,0xFF, | 
|---|
| 237 | 0xFF,0x66,0xCC, | 
|---|
| 238 | 0x00,0x99,0xFF, | 
|---|
| 239 | 0x33,0x99,0xFF, | 
|---|
| 240 | 0x66,0x99,0xFF, | 
|---|
| 241 | 0x99,0x99,0xFF, | 
|---|
| 242 | 0xCC,0x99,0xFF, | 
|---|
| 243 | 0xFF,0x99,0xFF, | 
|---|
| 244 | 0x00,0xCC,0xFF, | 
|---|
| 245 | 0x33,0xCC,0xFF, | 
|---|
| 246 | 0x66,0xCC,0xFF, | 
|---|
| 247 | 0x99,0xCC,0xFF, | 
|---|
| 248 | 0xCC,0xCC,0xFF, | 
|---|
| 249 | 0xFF,0xCC,0xFF, | 
|---|
| 250 | 0x33,0xFF,0xFF, | 
|---|
| 251 | 0x66,0xFF,0xCC, | 
|---|
| 252 | 0x99,0xFF,0xFF, | 
|---|
| 253 | 0xCC,0xFF,0xFF, | 
|---|
| 254 | 0xFF,0x66,0x66, | 
|---|
| 255 | 0x66,0xFF,0x66, | 
|---|
| 256 | 0xFF,0xFF,0x66, | 
|---|
| 257 | 0x66,0x66,0xFF, | 
|---|
| 258 | 0xFF,0x66,0xFF, | 
|---|
| 259 | 0x66,0xFF,0xFF, | 
|---|
| 260 | 0xC1,0xC1,0xC1, | 
|---|
| 261 | 0x5F,0x5F,0x5F, | 
|---|
| 262 | 0x77,0x77,0x77, | 
|---|
| 263 | 0x86,0x86,0x86, | 
|---|
| 264 | 0x96,0x96,0x96, | 
|---|
| 265 | 0xCB,0xCB,0xCB, | 
|---|
| 266 | 0xB2,0xB2,0xB2, | 
|---|
| 267 | 0xD7,0xD7,0xD7, | 
|---|
| 268 | 0xDD,0xDD,0xDD, | 
|---|
| 269 | 0xE3,0xE3,0xE3, | 
|---|
| 270 | 0xEA,0xEA,0xEA, | 
|---|
| 271 | 0xF1,0xF1,0xF1, | 
|---|
| 272 | 0xF8,0xF8,0xF8, | 
|---|
| 273 | 0xFF,0xFB,0xF0, | 
|---|
| 274 | 0xA0,0xA0,0xA4, | 
|---|
| 275 | 0x80,0x80,0x80, | 
|---|
| 276 | 0xFF,0x00,0x00, | 
|---|
| 277 | 0x00,0xFF,0x00, | 
|---|
| 278 | 0xFF,0xFF,0x00, | 
|---|
| 279 | 0x00,0x00,0xFF, | 
|---|
| 280 | 0xFF,0x00,0xFF, | 
|---|
| 281 | //                          0x00,0xFF,0xFF, | 
|---|
| 282 | 0xFF,0xFF,0xFF}; | 
|---|
| 283 |  | 
|---|
| 284 | WORD wDefaultPalete16[256]; | 
|---|
| 285 | BOOL fPalInit=FALSE; | 
|---|
| 286 |  | 
|---|
| 287 | #define CBM_CREATEDIB   0x02L   /* create DIB bitmap */ | 
|---|
| 288 | #define BI_BITFIELDS  0x03L | 
|---|
| 289 | #ifdef DEBUG | 
|---|
| 290 |  | 
|---|
| 291 | // ****************************************************************************** | 
|---|
| 292 | // *    internal helper functions from WINE | 
|---|
| 293 | // * | 
|---|
| 294 |  | 
|---|
| 295 | static void _dump_DDBLTFX(DWORD flagmask) { | 
|---|
| 296 | int  i; | 
|---|
| 297 | const struct { | 
|---|
| 298 | DWORD  mask; | 
|---|
| 299 | char  *name; | 
|---|
| 300 | } flags[] = { | 
|---|
| 301 | #define FE(x) { x, #x}, | 
|---|
| 302 | FE(DDBLTFX_ARITHSTRETCHY) | 
|---|
| 303 | FE(DDBLTFX_MIRRORLEFTRIGHT) | 
|---|
| 304 | FE(DDBLTFX_MIRRORUPDOWN) | 
|---|
| 305 | FE(DDBLTFX_NOTEARING) | 
|---|
| 306 | FE(DDBLTFX_ROTATE180) | 
|---|
| 307 | FE(DDBLTFX_ROTATE270) | 
|---|
| 308 | FE(DDBLTFX_ROTATE90) | 
|---|
| 309 | FE(DDBLTFX_ZBUFFERRANGE) | 
|---|
| 310 | FE(DDBLTFX_ZBUFFERBASEDEST) | 
|---|
| 311 | }; | 
|---|
| 312 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 313 | if (flags[i].mask & flagmask) { | 
|---|
| 314 | WriteLog("%s ",flags[i].name); | 
|---|
| 315 | }; | 
|---|
| 316 | WriteLog("\n"); | 
|---|
| 317 |  | 
|---|
| 318 | } | 
|---|
| 319 |  | 
|---|
| 320 | static void _dump_DDBLTFAST(DWORD flagmask) { | 
|---|
| 321 | int  i; | 
|---|
| 322 | const struct { | 
|---|
| 323 | DWORD  mask; | 
|---|
| 324 | char  *name; | 
|---|
| 325 | } flags[] = { | 
|---|
| 326 | #define FE(x) { x, #x}, | 
|---|
| 327 | FE(DDBLTFAST_NOCOLORKEY) | 
|---|
| 328 | FE(DDBLTFAST_SRCCOLORKEY) | 
|---|
| 329 | FE(DDBLTFAST_DESTCOLORKEY) | 
|---|
| 330 | FE(DDBLTFAST_WAIT) | 
|---|
| 331 | }; | 
|---|
| 332 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 333 | if (flags[i].mask & flagmask) | 
|---|
| 334 | WriteLog("%s ",flags[i].name); | 
|---|
| 335 | WriteLog("\n"); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | static void _dump_DDBLT(DWORD flagmask) { | 
|---|
| 339 | int  i; | 
|---|
| 340 | const struct { | 
|---|
| 341 | DWORD  mask; | 
|---|
| 342 | char  *name; | 
|---|
| 343 | } flags[] = { | 
|---|
| 344 | #define FE(x) { x, #x}, | 
|---|
| 345 | FE(DDBLT_ALPHADEST) | 
|---|
| 346 | FE(DDBLT_ALPHADESTCONSTOVERRIDE) | 
|---|
| 347 | FE(DDBLT_ALPHADESTNEG) | 
|---|
| 348 | FE(DDBLT_ALPHADESTSURFACEOVERRIDE) | 
|---|
| 349 | FE(DDBLT_ALPHAEDGEBLEND) | 
|---|
| 350 | FE(DDBLT_ALPHASRC) | 
|---|
| 351 | FE(DDBLT_ALPHASRCCONSTOVERRIDE) | 
|---|
| 352 | FE(DDBLT_ALPHASRCNEG) | 
|---|
| 353 | FE(DDBLT_ALPHASRCSURFACEOVERRIDE) | 
|---|
| 354 | FE(DDBLT_ASYNC) | 
|---|
| 355 | FE(DDBLT_COLORFILL) | 
|---|
| 356 | FE(DDBLT_DDFX) | 
|---|
| 357 | FE(DDBLT_DDROPS) | 
|---|
| 358 | FE(DDBLT_KEYDEST) | 
|---|
| 359 | FE(DDBLT_KEYDESTOVERRIDE) | 
|---|
| 360 | FE(DDBLT_KEYSRC) | 
|---|
| 361 | FE(DDBLT_KEYSRCOVERRIDE) | 
|---|
| 362 | FE(DDBLT_ROP) | 
|---|
| 363 | FE(DDBLT_ROTATIONANGLE) | 
|---|
| 364 | FE(DDBLT_ZBUFFER) | 
|---|
| 365 | FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE) | 
|---|
| 366 | FE(DDBLT_ZBUFFERDESTOVERRIDE) | 
|---|
| 367 | FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE) | 
|---|
| 368 | FE(DDBLT_ZBUFFERSRCOVERRIDE) | 
|---|
| 369 | FE(DDBLT_WAIT) | 
|---|
| 370 | FE(DDBLT_DEPTHFILL) | 
|---|
| 371 | }; | 
|---|
| 372 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 373 | if (flags[i].mask & flagmask) | 
|---|
| 374 | WriteLog("%s ",flags[i].name); | 
|---|
| 375 | WriteLog("\n"); | 
|---|
| 376 | } | 
|---|
| 377 |  | 
|---|
| 378 | static void _dump_DDSCAPS(DWORD flagmask) { | 
|---|
| 379 | int  i; | 
|---|
| 380 | const struct { | 
|---|
| 381 | DWORD  mask; | 
|---|
| 382 | char  *name; | 
|---|
| 383 | } flags[] = { | 
|---|
| 384 | #define FE(x) { x, #x}, | 
|---|
| 385 | FE(DDSCAPS_RESERVED1) | 
|---|
| 386 | FE(DDSCAPS_ALPHA) | 
|---|
| 387 | FE(DDSCAPS_BACKBUFFER) | 
|---|
| 388 | FE(DDSCAPS_COMPLEX) | 
|---|
| 389 | FE(DDSCAPS_FLIP) | 
|---|
| 390 | FE(DDSCAPS_FRONTBUFFER) | 
|---|
| 391 | FE(DDSCAPS_OFFSCREENPLAIN) | 
|---|
| 392 | FE(DDSCAPS_OVERLAY) | 
|---|
| 393 | FE(DDSCAPS_PALETTE) | 
|---|
| 394 | FE(DDSCAPS_PRIMARYSURFACE) | 
|---|
| 395 | FE(DDSCAPS_PRIMARYSURFACELEFT) | 
|---|
| 396 | FE(DDSCAPS_SYSTEMMEMORY) | 
|---|
| 397 | FE(DDSCAPS_TEXTURE) | 
|---|
| 398 | FE(DDSCAPS_3DDEVICE) | 
|---|
| 399 | FE(DDSCAPS_VIDEOMEMORY) | 
|---|
| 400 | FE(DDSCAPS_VISIBLE) | 
|---|
| 401 | FE(DDSCAPS_WRITEONLY) | 
|---|
| 402 | FE(DDSCAPS_ZBUFFER) | 
|---|
| 403 | FE(DDSCAPS_OWNDC) | 
|---|
| 404 | FE(DDSCAPS_LIVEVIDEO) | 
|---|
| 405 | FE(DDSCAPS_HWCODEC) | 
|---|
| 406 | FE(DDSCAPS_MODEX) | 
|---|
| 407 | FE(DDSCAPS_MIPMAP) | 
|---|
| 408 | FE(DDSCAPS_RESERVED2) | 
|---|
| 409 | FE(DDSCAPS_ALLOCONLOAD) | 
|---|
| 410 | FE(DDSCAPS_VIDEOPORT) | 
|---|
| 411 | FE(DDSCAPS_LOCALVIDMEM) | 
|---|
| 412 | FE(DDSCAPS_NONLOCALVIDMEM) | 
|---|
| 413 | FE(DDSCAPS_STANDARDVGAMODE) | 
|---|
| 414 | FE(DDSCAPS_OPTIMIZED) | 
|---|
| 415 | }; | 
|---|
| 416 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 417 | if (flags[i].mask & flagmask) | 
|---|
| 418 | WriteLog("%s ",flags[i].name); | 
|---|
| 419 | WriteLog("\n"); | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | static void _dump_DDSCAPS2(DWORD flagmask) { | 
|---|
| 423 | int  i; | 
|---|
| 424 | const struct { | 
|---|
| 425 | DWORD  mask; | 
|---|
| 426 | char  *name; | 
|---|
| 427 | } flags[] = { | 
|---|
| 428 | #define FE(x) { x, #x}, | 
|---|
| 429 | FE(DDSCAPS2_HARDWAREDEINTERLACE) | 
|---|
| 430 | FE(DDSCAPS2_HINTANTIALIASING) | 
|---|
| 431 | FE(DDSCAPS2_HINTDYNAMIC) | 
|---|
| 432 | FE(DDSCAPS2_HINTSTATIC) | 
|---|
| 433 | FE(DDSCAPS2_OPAQUE) | 
|---|
| 434 | FE(DDSCAPS2_TEXTUREMANAGE) | 
|---|
| 435 | }; | 
|---|
| 436 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 437 | if (flags[i].mask & flagmask) | 
|---|
| 438 | WriteLog("%s ",flags[i].name); | 
|---|
| 439 | WriteLog("\n"); | 
|---|
| 440 | } | 
|---|
| 441 |  | 
|---|
| 442 |  | 
|---|
| 443 | static void _dump_DDSD(DWORD flagmask) { | 
|---|
| 444 | int  i; | 
|---|
| 445 | const struct { | 
|---|
| 446 | DWORD  mask; | 
|---|
| 447 | char  *name; | 
|---|
| 448 | } flags[] = { | 
|---|
| 449 | FE(DDSD_CAPS) | 
|---|
| 450 | FE(DDSD_HEIGHT) | 
|---|
| 451 | FE(DDSD_WIDTH) | 
|---|
| 452 | FE(DDSD_PITCH) | 
|---|
| 453 | FE(DDSD_BACKBUFFERCOUNT) | 
|---|
| 454 | FE(DDSD_ZBUFFERBITDEPTH) | 
|---|
| 455 | FE(DDSD_ALPHABITDEPTH) | 
|---|
| 456 | FE(DDSD_PIXELFORMAT) | 
|---|
| 457 | FE(DDSD_CKDESTOVERLAY) | 
|---|
| 458 | FE(DDSD_CKDESTBLT) | 
|---|
| 459 | FE(DDSD_CKSRCOVERLAY) | 
|---|
| 460 | FE(DDSD_CKSRCBLT) | 
|---|
| 461 | FE(DDSD_MIPMAPCOUNT) | 
|---|
| 462 | FE(DDSD_REFRESHRATE) | 
|---|
| 463 | FE(DDSD_LINEARSIZE) | 
|---|
| 464 | FE(DDSD_LPSURFACE) | 
|---|
| 465 | FE(DDSD_TEXTURESTAGE) | 
|---|
| 466 | }; | 
|---|
| 467 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 468 | if (flags[i].mask & flagmask) | 
|---|
| 469 | WriteLog("%s ",flags[i].name); | 
|---|
| 470 | WriteLog("\n"); | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 | static void _dump_DDCOLORKEY(DWORD flagmask) { | 
|---|
| 474 | int  i; | 
|---|
| 475 | const struct { | 
|---|
| 476 | DWORD  mask; | 
|---|
| 477 | char  *name; | 
|---|
| 478 | } flags[] = { | 
|---|
| 479 | #define FE(x) { x, #x}, | 
|---|
| 480 | FE(DDPF_ALPHAPIXELS) | 
|---|
| 481 | FE(DDPF_ALPHA) | 
|---|
| 482 | FE(DDPF_FOURCC) | 
|---|
| 483 | FE(DDPF_PALETTEINDEXED4) | 
|---|
| 484 | FE(DDPF_PALETTEINDEXEDTO8) | 
|---|
| 485 | FE(DDPF_PALETTEINDEXED8) | 
|---|
| 486 | FE(DDPF_RGB) | 
|---|
| 487 | FE(DDPF_COMPRESSED) | 
|---|
| 488 | FE(DDPF_RGBTOYUV) | 
|---|
| 489 | FE(DDPF_YUV) | 
|---|
| 490 | FE(DDPF_ZBUFFER) | 
|---|
| 491 | FE(DDPF_PALETTEINDEXED1) | 
|---|
| 492 | FE(DDPF_PALETTEINDEXED2) | 
|---|
| 493 | FE(DDPF_ZPIXELS) | 
|---|
| 494 | }; | 
|---|
| 495 | for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++) | 
|---|
| 496 | if (flags[i].mask & flagmask) | 
|---|
| 497 | WriteLog("%s ",flags[i].name); | 
|---|
| 498 | WriteLog("\n"); | 
|---|
| 499 | } | 
|---|
| 500 |  | 
|---|
| 501 | static void _dump_pixelformat(LPDDPIXELFORMAT pf) { | 
|---|
| 502 | _dump_DDCOLORKEY(pf->dwFlags); | 
|---|
| 503 | WriteLog("dwFourCC : %ld\n", pf->dwFourCC); | 
|---|
| 504 | WriteLog("RBG bit cbout : %ld\n", pf->dwRGBBitCount); | 
|---|
| 505 | WriteLog("Masks : R %08lx  G %08lx  B %08lx  A %08lx\n", | 
|---|
| 506 | pf->dwRBitMask, pf->dwGBitMask, pf->dwBBitMask, pf->dwRGBAlphaBitMask); | 
|---|
| 507 | } | 
|---|
| 508 |  | 
|---|
| 509 | // End of Internal Helpers | 
|---|
| 510 | #endif | 
|---|
| 511 |  | 
|---|
| 512 | //****************************************************************************** | 
|---|
| 513 | //****************************************************************************** | 
|---|
| 514 | OS2IDirectDrawSurface::OS2IDirectDrawSurface(OS2IDirectDraw *lpDirectDraw, | 
|---|
| 515 | LPDDSURFACEDESC2 lpDDSurfaceDesc, BOOL Implicit, BOOL Mainchain) : | 
|---|
| 516 | Referenced(0), lastError(DD_OK), | 
|---|
| 517 | diveBufNr(-1), lpClipper(NULL), | 
|---|
| 518 | lpPalette(NULL), lpDraw(NULL), | 
|---|
| 519 | fLocked(FALSE), hdcImage(NULL), | 
|---|
| 520 | hbmImage(NULL), | 
|---|
| 521 | pFrameBuffer(NULL),Updated(FALSE), | 
|---|
| 522 | fOverlayValid(FALSE), | 
|---|
| 523 | BackBuffer(NULL),FrontBuffer(NULL) | 
|---|
| 524 |  | 
|---|
| 525 | { | 
|---|
| 526 | ULONG rc; | 
|---|
| 527 | DWORD i; | 
|---|
| 528 | DIVE_CAPS dCaps; | 
|---|
| 529 | DDSURFACEDESC2 ComplexSurfaceDesc; | 
|---|
| 530 | OS2IDirectDrawSurface *AttachedSurface; | 
|---|
| 531 | OS2IDirectDrawSurface *MipMapSurface; | 
|---|
| 532 |  | 
|---|
| 533 | lpVtbl                     = &Vtbl; | 
|---|
| 534 | Vtbl.AddRef                = SurfAddRef; | 
|---|
| 535 | Vtbl.Release               = SurfRelease; | 
|---|
| 536 | Vtbl.QueryInterface        = SurfQueryInterface; | 
|---|
| 537 | Vtbl.AddAttachedSurface    = SurfAddAttachedSurface4; | 
|---|
| 538 | Vtbl.AddOverlayDirtyRect   = SurfAddOverlayDirtyRect; | 
|---|
| 539 | Vtbl.Blt                   = SurfBlt4; | 
|---|
| 540 | Vtbl.BltBatch              = SurfBltBatch; | 
|---|
| 541 | Vtbl.BltFast               = SurfBltFast4; | 
|---|
| 542 | Vtbl.DeleteAttachedSurface = SurfDeleteAttachedSurface4; | 
|---|
| 543 | Vtbl.EnumAttachedSurfaces  = SurfEnumAttachedSurfaces4; | 
|---|
| 544 | Vtbl.EnumOverlayZOrders    = SurfEnumOverlayZOrders4; | 
|---|
| 545 | Vtbl.Flip                  = SurfFlip4; | 
|---|
| 546 | Vtbl.GetAttachedSurface    = SurfGetAttachedSurface4; | 
|---|
| 547 | Vtbl.GetBltStatus          = SurfGetBltStatus; | 
|---|
| 548 | Vtbl.GetCaps               = SurfGetCaps4; | 
|---|
| 549 | Vtbl.GetClipper            = SurfGetClipper; | 
|---|
| 550 | Vtbl.GetColorKey           = SurfGetColorKey; | 
|---|
| 551 | Vtbl.GetDC                 = SurfGetDC; | 
|---|
| 552 | Vtbl.GetFlipStatus         = SurfGetFlipStatus; | 
|---|
| 553 | Vtbl.GetOverlayPosition    = SurfGetOverlayPosition; | 
|---|
| 554 | Vtbl.GetPalette            = SurfGetPalette; | 
|---|
| 555 | Vtbl.GetPixelFormat        = SurfGetPixelFormat; | 
|---|
| 556 | Vtbl.GetSurfaceDesc        = SurfGetSurfaceDesc4; | 
|---|
| 557 | Vtbl.Initialize            = SurfInitialize4; | 
|---|
| 558 | Vtbl.IsLost                = SurfIsLost; | 
|---|
| 559 | Vtbl.Lock                  = SurfLock4; | 
|---|
| 560 | Vtbl.ReleaseDC             = SurfReleaseDC; | 
|---|
| 561 | Vtbl.Restore               = SurfRestore; | 
|---|
| 562 | Vtbl.SetClipper            = SurfSetClipper; | 
|---|
| 563 | Vtbl.SetColorKey           = SurfSetColorKey; | 
|---|
| 564 | Vtbl.SetOverlayPosition    = SurfSetOverlayPosition; | 
|---|
| 565 | Vtbl.SetPalette            = SurfSetPalette; | 
|---|
| 566 | Vtbl.Unlock                = SurfUnlock4; | 
|---|
| 567 | Vtbl.UpdateOverlay         = SurfUpdateOverlay4; | 
|---|
| 568 | Vtbl.UpdateOverlayDisplay  = SurfUpdateOverlayDisplay; | 
|---|
| 569 | Vtbl.UpdateOverlayZOrder   = SurfUpdateOverlayZOrder4; | 
|---|
| 570 | Vtbl.GetDDInterface        = SurfGetDDInterface; | 
|---|
| 571 | Vtbl.PageLock              = SurfPageLock; | 
|---|
| 572 | Vtbl.PageUnlock            = SurfPageUnlock; | 
|---|
| 573 | Vtbl.SetSurfaceDesc        = SurfSetSurfaceDesc4; | 
|---|
| 574 | Vtbl.SetPrivateData        = SurfSetPrivateData; | 
|---|
| 575 | Vtbl.GetPrivateData        = SurfGetPrivateData; | 
|---|
| 576 | Vtbl.FreePrivateData       = SurfFreePrivateData; | 
|---|
| 577 | Vtbl.ChangeUniquenessValue = SurfChangeUniquenessValue; | 
|---|
| 578 | Vtbl.GetUniquenessValue    = SurfGetUniquenessValue; | 
|---|
| 579 | lpDraw                     = lpDirectDraw; | 
|---|
| 580 | lpDraw->Vtbl.AddRef(lpDraw); | 
|---|
| 581 |  | 
|---|
| 582 | ImplicitSurface = Implicit; | 
|---|
| 583 |  | 
|---|
| 584 | hDive                      = lpDirectDraw->GetDiveInstance(); | 
|---|
| 585 | hDiveCC                    = lpDirectDraw->GetCCDiveInstance(); | 
|---|
| 586 | surfaceType                = DDSCAPS_OFFSCREENPLAIN; | 
|---|
| 587 | memcpy((char *)&DDSurfaceDesc, (char *)lpDDSurfaceDesc, sizeof(DDSURFACEDESC2)); | 
|---|
| 588 |  | 
|---|
| 589 | if(lpDraw->dCaps.ulDepth != 15) | 
|---|
| 590 | { | 
|---|
| 591 | if(lpDraw->dCaps.ulDepth >= 8) | 
|---|
| 592 | dwBytesPPDive = lpDraw->dCaps.ulDepth >> 3; | 
|---|
| 593 | else | 
|---|
| 594 | dwBytesPPDive = 1; // not sure if this is the case | 
|---|
| 595 | } | 
|---|
| 596 | else | 
|---|
| 597 | dwBytesPPDive = 2; // 2 bytes for 15Bit | 
|---|
| 598 |  | 
|---|
| 599 | // Setting up Cursors for handling attached Surfaces | 
|---|
| 600 |  | 
|---|
| 601 | DPA_SurfaceMipMaps = DPA_Create(8); | 
|---|
| 602 | if(NULL==DPA_SurfaceMipMaps) | 
|---|
| 603 | { | 
|---|
| 604 | #ifdef DEBUG | 
|---|
| 605 | WriteLog("Internal : Error creating DPA for MipMaps\n"); | 
|---|
| 606 | #endif | 
|---|
| 607 | lastError = DDERR_OUTOFMEMORY ; | 
|---|
| 608 | return; | 
|---|
| 609 | } | 
|---|
| 610 |  | 
|---|
| 611 | DPA_SurfaceAttached = DPA_Create(8); | 
|---|
| 612 | if(NULL==DPA_SurfaceAttached) | 
|---|
| 613 | { | 
|---|
| 614 | #ifdef DEBUG | 
|---|
| 615 | WriteLog("Internal : Error creating DPA for attached surfaces\n"); | 
|---|
| 616 | #endif | 
|---|
| 617 | lastError = DDERR_OUTOFMEMORY ; | 
|---|
| 618 | return; | 
|---|
| 619 | } | 
|---|
| 620 |  | 
|---|
| 621 | DPA_LockedRects = DPA_Create(8); | 
|---|
| 622 | if(NULL==DPA_LockedRects) | 
|---|
| 623 | { | 
|---|
| 624 | #ifdef DEBUG | 
|---|
| 625 | WriteLog("Internal : Error creating DPA for Locked Rectangles\n"); | 
|---|
| 626 | #endif | 
|---|
| 627 | lastError = DDERR_OUTOFMEMORY ; | 
|---|
| 628 | return; | 
|---|
| 629 | } | 
|---|
| 630 |  | 
|---|
| 631 | DPA_SurfacePrivateData = DPA_Create(8); | 
|---|
| 632 | if(NULL==DPA_SurfacePrivateData) | 
|---|
| 633 | { | 
|---|
| 634 | #ifdef DEBUG | 
|---|
| 635 | WriteLog("Internal : Error creating DPA for priva surface Data\n"); | 
|---|
| 636 | #endif | 
|---|
| 637 | lastError = DDERR_OUTOFMEMORY ; | 
|---|
| 638 | return; | 
|---|
| 639 | } | 
|---|
| 640 |  | 
|---|
| 641 | if( lpDDSurfaceDesc->dwFlags & DDSD_CAPS ) | 
|---|
| 642 | { | 
|---|
| 643 | // First check if we want to create a primary surface while the ddraw object already has one | 
|---|
| 644 | surfaceType = lpDDSurfaceDesc->ddsCaps.dwCaps; | 
|---|
| 645 |  | 
|---|
| 646 | if( surfaceType & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 647 | { | 
|---|
| 648 | #ifdef DEBUG | 
|---|
| 649 | WriteLog("Primary surface!\n"); | 
|---|
| 650 | #endif | 
|---|
| 651 |  | 
|---|
| 652 | if( lpDraw->HasPrimarySurface()) | 
|---|
| 653 | { | 
|---|
| 654 | #ifdef DEBUG | 
|---|
| 655 | WriteLog("Primary surface already exits!\n"); | 
|---|
| 656 | #endif | 
|---|
| 657 | lastError = DDERR_PRIMARYSURFACEALREADYEXISTS; | 
|---|
| 658 | return; | 
|---|
| 659 | } | 
|---|
| 660 |  | 
|---|
| 661 | if( (lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) || | 
|---|
| 662 | (lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)  || | 
|---|
| 663 | (lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) | 
|---|
| 664 | ) | 
|---|
| 665 | { | 
|---|
| 666 | // Dx doc says passing width,height etc. for primary surface in not permitted!! | 
|---|
| 667 | WriteLog("Invalid parameters\n\n"); | 
|---|
| 668 | lastError = DDERR_INVALIDPARAMS; | 
|---|
| 669 | return; | 
|---|
| 670 | } | 
|---|
| 671 |  | 
|---|
| 672 | // Check if OS/2 is running in the requested colormode | 
|---|
| 673 |  | 
|---|
| 674 | diveBufNr    = DIVE_BUFFER_SCREEN; | 
|---|
| 675 | if( lpDraw->dCaps.ulDepth == lpDraw->GetScreenBpp() ) | 
|---|
| 676 | { | 
|---|
| 677 | WriteLog("DirectScreenAccess possible\n"); | 
|---|
| 678 |  | 
|---|
| 679 | // Yes so direct access to framebuffer is possible | 
|---|
| 680 |  | 
|---|
| 681 | pFrameBuffer = lpDraw->GetFrameBuffer(); | 
|---|
| 682 | pDiveBuffer  = pFrameBuffer; | 
|---|
| 683 | dwPitchDB    = lpDraw->dCaps.ulScanLineBytes; | 
|---|
| 684 | dwPitchFB    = dwPitchDB; | 
|---|
| 685 | DDSurfaceDesc.lPitch = dwPitchDB; | 
|---|
| 686 | } | 
|---|
| 687 | else | 
|---|
| 688 | { | 
|---|
| 689 | // No so we create a virtual framebuffer which the program can access | 
|---|
| 690 | // and blit to the real framebuffer on Unlock to do color conversion | 
|---|
| 691 |  | 
|---|
| 692 | WriteLog( "Need Color conversation %d => %d Bit\n", | 
|---|
| 693 | lpDraw->GetScreenBpp(), | 
|---|
| 694 | lpDraw->dCaps.ulDepth | 
|---|
| 695 | ); | 
|---|
| 696 |  | 
|---|
| 697 | dwPitchFB = (lpDraw->GetScreenWidth() * lpDraw->GetScreenBpp() +7) & ~7; | 
|---|
| 698 | DDSurfaceDesc.lPitch = dwPitchFB; | 
|---|
| 699 |  | 
|---|
| 700 | // 24 byte more to enable alignment and speed up blitting | 
|---|
| 701 |  | 
|---|
| 702 | pFBreal = (char*)malloc( lpDraw->GetScreenHeight() * dwPitchFB + 24); | 
|---|
| 703 | pFrameBuffer = (char*)(((int)pFBreal + 7) & ~7); // align to QWORD | 
|---|
| 704 |  | 
|---|
| 705 | // DiveBuffer points to real framebuffer | 
|---|
| 706 | dwPitchDB    = lpDraw->dCaps.ulScanLineBytes; | 
|---|
| 707 | pDiveBuffer = lpDraw->GetFrameBuffer(); | 
|---|
| 708 |  | 
|---|
| 709 | } | 
|---|
| 710 |  | 
|---|
| 711 | // Update passed in and local Surface description | 
|---|
| 712 |  | 
|---|
| 713 | #ifdef DEBUG | 
|---|
| 714 | WriteLog("Setting up Surface\n"); | 
|---|
| 715 | #endif | 
|---|
| 716 | DDSurfaceDesc.dwFlags     |= DDSD_WIDTH | DDSD_HEIGHT | | 
|---|
| 717 | DDSD_PITCH | DDSD_LPSURFACE | | 
|---|
| 718 | DDSD_PIXELFORMAT; | 
|---|
| 719 | DDSurfaceDesc.dwHeight     = lpDraw->GetScreenHeight(); | 
|---|
| 720 | DDSurfaceDesc.dwWidth      = lpDraw->GetScreenWidth(); | 
|---|
| 721 | DDSurfaceDesc.lpSurface    = pFrameBuffer; | 
|---|
| 722 | lpDDSurfaceDesc->dwFlags   = DDSurfaceDesc.dwFlags; | 
|---|
| 723 | lpDDSurfaceDesc->dwHeight  = DDSurfaceDesc.dwHeight; | 
|---|
| 724 | lpDDSurfaceDesc->dwWidth   = DDSurfaceDesc.dwWidth; | 
|---|
| 725 | lpDDSurfaceDesc->lpSurface = pFrameBuffer; | 
|---|
| 726 | lpDDSurfaceDesc->lPitch    = DDSurfaceDesc.lPitch; | 
|---|
| 727 |  | 
|---|
| 728 | lpDDSurfaceDesc->ddsCaps.dwCaps |= DDSCAPS_VISIBLE; | 
|---|
| 729 | DDSurfaceDesc.ddsCaps.dwCaps    |= DDSCAPS_VISIBLE; | 
|---|
| 730 | lpDraw->SetPrimarySurface(TRUE); | 
|---|
| 731 | lpDDSurfaceDesc->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); | 
|---|
| 732 | lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC(); | 
|---|
| 733 | lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = lpDraw->GetScreenBpp(); | 
|---|
| 734 | DDSurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); | 
|---|
| 735 | DDSurfaceDesc.ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC(); | 
|---|
| 736 | DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = lpDraw->GetScreenBpp(); | 
|---|
| 737 |  | 
|---|
| 738 | switch(DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 739 | { | 
|---|
| 740 | case 4: | 
|---|
| 741 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB; | 
|---|
| 742 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB; | 
|---|
| 743 | break; | 
|---|
| 744 | case 8: | 
|---|
| 745 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB; | 
|---|
| 746 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB; | 
|---|
| 747 | break; | 
|---|
| 748 | case 16: | 
|---|
| 749 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 750 | lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800; | 
|---|
| 751 | lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0; | 
|---|
| 752 | lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F; | 
|---|
| 753 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 754 | DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x0000F800; | 
|---|
| 755 | DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x000007E0; | 
|---|
| 756 | DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x0000001F; | 
|---|
| 757 | break; | 
|---|
| 758 | case 24: | 
|---|
| 759 | case 32: | 
|---|
| 760 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 761 | lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000; | 
|---|
| 762 | lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00; | 
|---|
| 763 | lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF; | 
|---|
| 764 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 765 | DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x00FF0000; | 
|---|
| 766 | DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x0000FF00; | 
|---|
| 767 | DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x000000FF; | 
|---|
| 768 | break; | 
|---|
| 769 | default: | 
|---|
| 770 | // Remove the Pixelformat flag | 
|---|
| 771 | lpDDSurfaceDesc->dwFlags &= ~DDSD_PIXELFORMAT; | 
|---|
| 772 | DDSurfaceDesc.dwFlags    &= ~DDSD_PIXELFORMAT; | 
|---|
| 773 | #ifdef DEBUG | 
|---|
| 774 | WriteLog("Unexpected BitDepth : %d\n",lpDraw->GetScreenBpp()); | 
|---|
| 775 | #endif | 
|---|
| 776 | break; | 
|---|
| 777 | } // end switch | 
|---|
| 778 |  | 
|---|
| 779 | #ifdef DEBUG | 
|---|
| 780 | WriteLog("Surface set up, checking other Caps\n"); | 
|---|
| 781 | #endif | 
|---|
| 782 |  | 
|---|
| 783 | if( DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_COMPLEX) | 
|---|
| 784 | { | 
|---|
| 785 | #ifdef DEBUG | 
|---|
| 786 | WriteLog("Complex Surface\n"); | 
|---|
| 787 | #endif | 
|---|
| 788 |  | 
|---|
| 789 | if(lpDDSurfaceDesc->dwFlags & DDSD_BACKBUFFERCOUNT) | 
|---|
| 790 | { | 
|---|
| 791 | #ifdef DEBUG | 
|---|
| 792 | WriteLog("Backbuffer # = %d\n",lpDDSurfaceDesc->dwBackBufferCount); | 
|---|
| 793 | #endif | 
|---|
| 794 | memset( &ComplexSurfaceDesc, | 
|---|
| 795 | 0, | 
|---|
| 796 | sizeof(DDSURFACEDESC2)); | 
|---|
| 797 |  | 
|---|
| 798 | ComplexSurfaceDesc.dwSize  = sizeof(DDSURFACEDESC2); | 
|---|
| 799 | ComplexSurfaceDesc.dwFlags = DDSD_CAPS | | 
|---|
| 800 | DDSD_WIDTH | | 
|---|
| 801 | DDSD_HEIGHT | | 
|---|
| 802 | DDSD_PIXELFORMAT; | 
|---|
| 803 | ComplexSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_FLIP; | 
|---|
| 804 | ComplexSurfaceDesc.dwHeight = DDSurfaceDesc.dwHeight; | 
|---|
| 805 | ComplexSurfaceDesc.dwWidth = DDSurfaceDesc.dwWidth; | 
|---|
| 806 | ComplexSurfaceDesc.ddpfPixelFormat.dwFlags = DDSurfaceDesc.ddpfPixelFormat.dwFlags; | 
|---|
| 807 | ComplexSurfaceDesc.ddpfPixelFormat.dwRBitMask = DDSurfaceDesc.ddpfPixelFormat.dwRBitMask; | 
|---|
| 808 | ComplexSurfaceDesc.ddpfPixelFormat.dwGBitMask = DDSurfaceDesc.ddpfPixelFormat.dwGBitMask; | 
|---|
| 809 | ComplexSurfaceDesc.ddpfPixelFormat.dwBBitMask = DDSurfaceDesc.ddpfPixelFormat.dwBBitMask; | 
|---|
| 810 | ComplexSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; | 
|---|
| 811 |  | 
|---|
| 812 | if(lpDDSurfaceDesc->dwBackBufferCount>1) | 
|---|
| 813 | { | 
|---|
| 814 | ComplexSurfaceDesc.dwFlags |=DDSD_BACKBUFFERCOUNT; | 
|---|
| 815 | ComplexSurfaceDesc.dwBackBufferCount = lpDDSurfaceDesc->dwBackBufferCount -1; | 
|---|
| 816 | ComplexSurfaceDesc.ddsCaps.dwCaps|= DDSCAPS_COMPLEX; | 
|---|
| 817 | } | 
|---|
| 818 |  | 
|---|
| 819 | BackBuffer = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE, TRUE); | 
|---|
| 820 |  | 
|---|
| 821 | if (BackBuffer->GetLastError()==DD_OK) | 
|---|
| 822 | { | 
|---|
| 823 | WriteLog("created backbuffer"); | 
|---|
| 824 | // Our Primary Buffer is also the frontbuffer of a flipchain | 
|---|
| 825 | DDSurfaceDesc.ddsCaps.dwCaps    |= DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP; | 
|---|
| 826 | lpDDSurfaceDesc->ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP; | 
|---|
| 827 | BackBuffer->SetFrontBuffer(this); | 
|---|
| 828 | } | 
|---|
| 829 | else | 
|---|
| 830 | { | 
|---|
| 831 | WriteLog("Error creating backbuffer"); | 
|---|
| 832 | } | 
|---|
| 833 | } | 
|---|
| 834 | else | 
|---|
| 835 | { | 
|---|
| 836 | #ifdef DEBUG | 
|---|
| 837 | WriteLog("Unsupported Complex Surface\n"); | 
|---|
| 838 | _dump_DDSCAPS(lpDDSurfaceDesc->dwFlags); | 
|---|
| 839 | #endif | 
|---|
| 840 | lastError = DDERR_OUTOFMEMORY; | 
|---|
| 841 | return; | 
|---|
| 842 | } //endif Backbuffer | 
|---|
| 843 | } // endif DDSCAPS_COMPLEX | 
|---|
| 844 |  | 
|---|
| 845 | width  = DDSurfaceDesc.dwWidth; | 
|---|
| 846 | height = DDSurfaceDesc.dwHeight; | 
|---|
| 847 |  | 
|---|
| 848 | lpDraw->pPrimSurf = this; | 
|---|
| 849 |  | 
|---|
| 850 | lastError = DD_OK; | 
|---|
| 851 | return; | 
|---|
| 852 | } // endif  DDSCAPS_PRIMARYSURFACE | 
|---|
| 853 |  | 
|---|
| 854 | // | 
|---|
| 855 | // ToDo : Do better calulation of Bitmap Size to support the compressed Bitmaps in Dx6 | 
|---|
| 856 | // | 
|---|
| 857 |  | 
|---|
| 858 | if( (DDSurfaceDesc.dwFlags & DDSD_HEIGHT) && | 
|---|
| 859 | (DDSurfaceDesc.dwFlags & DDSD_WIDTH) | 
|---|
| 860 | ) | 
|---|
| 861 |  | 
|---|
| 862 | { | 
|---|
| 863 | DWORD dwBpp; | 
|---|
| 864 | DWORD dwCaps; | 
|---|
| 865 | WriteLog( " Requested Size %dx%d\n", | 
|---|
| 866 | DDSurfaceDesc.dwWidth, | 
|---|
| 867 | DDSurfaceDesc.dwHeight); | 
|---|
| 868 |  | 
|---|
| 869 | if(DDSurfaceDesc.dwFlags & DDSD_PIXELFORMAT)         // Pixelformat passed in ? | 
|---|
| 870 | { | 
|---|
| 871 | WriteLog(" Pixelformat requested :"); | 
|---|
| 872 | // YES use it | 
|---|
| 873 | if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_RGB) | 
|---|
| 874 | { | 
|---|
| 875 | dwBpp = DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; | 
|---|
| 876 | } | 
|---|
| 877 | else | 
|---|
| 878 | { | 
|---|
| 879 | if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) | 
|---|
| 880 | dwBpp = 8; | 
|---|
| 881 | if(DDSurfaceDesc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4) | 
|---|
| 882 | dwBpp = 4; | 
|---|
| 883 | } | 
|---|
| 884 | } | 
|---|
| 885 | else | 
|---|
| 886 | { | 
|---|
| 887 | WriteLog(" Use Screen Format :"); | 
|---|
| 888 | dwBpp = lpDraw->GetScreenBpp(); // No use Screenformat | 
|---|
| 889 | lpDDSurfaceDesc->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); | 
|---|
| 890 | lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC(); | 
|---|
| 891 | lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = dwBpp; | 
|---|
| 892 | DDSurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); | 
|---|
| 893 | DDSurfaceDesc.ddpfPixelFormat.dwFourCC = (DWORD) lpDraw->GetScreenFourCC(); | 
|---|
| 894 | DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount = dwBpp; | 
|---|
| 895 | switch(DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 896 | { | 
|---|
| 897 | case 4: | 
|---|
| 898 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB; | 
|---|
| 899 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB; | 
|---|
| 900 | break; | 
|---|
| 901 | case 8: | 
|---|
| 902 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB; | 
|---|
| 903 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_FOURCC | DDPF_RGB; | 
|---|
| 904 | break; | 
|---|
| 905 | case 16: | 
|---|
| 906 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 907 | lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800; | 
|---|
| 908 | lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0; | 
|---|
| 909 | lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F; | 
|---|
| 910 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 911 | DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x0000F800; | 
|---|
| 912 | DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x000007E0; | 
|---|
| 913 | DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x0000001F; | 
|---|
| 914 | break; | 
|---|
| 915 | case 24: | 
|---|
| 916 | case 32: | 
|---|
| 917 | lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 918 | lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000; | 
|---|
| 919 | lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00; | 
|---|
| 920 | lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF; | 
|---|
| 921 | DDSurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC | DDPF_RGB; | 
|---|
| 922 | DDSurfaceDesc.ddpfPixelFormat.dwRBitMask = 0x00FF0000; | 
|---|
| 923 | DDSurfaceDesc.ddpfPixelFormat.dwGBitMask = 0x0000FF00; | 
|---|
| 924 | DDSurfaceDesc.ddpfPixelFormat.dwBBitMask = 0x000000FF; | 
|---|
| 925 | break; | 
|---|
| 926 | default: | 
|---|
| 927 | // Remove the Pixelformat flag | 
|---|
| 928 | lpDDSurfaceDesc->dwFlags &= ~DDSD_PIXELFORMAT; | 
|---|
| 929 | DDSurfaceDesc.dwFlags    &= ~DDSD_PIXELFORMAT; | 
|---|
| 930 | #ifdef DEBUG | 
|---|
| 931 | WriteLog("Unexpected BitDepth : %d\n",lpDraw->GetScreenBpp()); | 
|---|
| 932 | #endif | 
|---|
| 933 | break; | 
|---|
| 934 | } // end switch | 
|---|
| 935 |  | 
|---|
| 936 | } | 
|---|
| 937 |  | 
|---|
| 938 | WriteLog("%d Bits\n",dwBpp); | 
|---|
| 939 |  | 
|---|
| 940 | // three possible situaltions | 
|---|
| 941 | // 1. User supplied pointer to surface -> use it | 
|---|
| 942 | // 2. Delayed allocation of a texture -> don't alloc | 
|---|
| 943 | // 3. Normal allocation | 
|---|
| 944 | // After this check for complex flag. | 
|---|
| 945 |  | 
|---|
| 946 | dwCaps = DDSurfaceDesc.ddsCaps.dwCaps; | 
|---|
| 947 |  | 
|---|
| 948 | if(DDSurfaceDesc.dwFlags & DDSD_LPSURFACE) | 
|---|
| 949 | { | 
|---|
| 950 | // 1. | 
|---|
| 951 |  | 
|---|
| 952 | WriteLog(" Usersupplied Surface\n"); | 
|---|
| 953 |  | 
|---|
| 954 | if(NULL==DDSurfaceDesc.lpSurface) | 
|---|
| 955 | { | 
|---|
| 956 | // pointer is NULL! Stupid user ;) | 
|---|
| 957 | lastError = DDERR_INVALIDPARAMS; | 
|---|
| 958 | return; | 
|---|
| 959 | } | 
|---|
| 960 |  | 
|---|
| 961 | // User allocated the Buffer for the surface so we don't have to | 
|---|
| 962 |  | 
|---|
| 963 | Updated = TRUE; // Set Flag to indicate User supplied buffer so we don't free it | 
|---|
| 964 |  | 
|---|
| 965 | // As we allready copied the surface description we are done if the # of colors | 
|---|
| 966 | // of the surface is the same then the screen | 
|---|
| 967 |  | 
|---|
| 968 | pFrameBuffer = (char*)DDSurfaceDesc.lpSurface; | 
|---|
| 969 | diveBufNr    = -1; | 
|---|
| 970 | dwPitchFB    = DDSurfaceDesc.lPitch; | 
|---|
| 971 |  | 
|---|
| 972 | if( lpDraw->dCaps.ulDepth  == dwBpp ) | 
|---|
| 973 | { | 
|---|
| 974 | // Yes No Colorconversion is needed so point to the same buffer | 
|---|
| 975 | dwPitchDB    = dwPitchFB; | 
|---|
| 976 | pDiveBuffer  = pFrameBuffer; | 
|---|
| 977 | } | 
|---|
| 978 | else | 
|---|
| 979 | { | 
|---|
| 980 | // No so we must create the Divebuffer to do the color conversion | 
|---|
| 981 | // and blit to the real framebuffer on Unlock to do color conversion | 
|---|
| 982 |  | 
|---|
| 983 | dwPitchDB = (lpDDSurfaceDesc->dwWidth * dwBytesPPDive +7) & ~7; | 
|---|
| 984 |  | 
|---|
| 985 | // 24 byte more to enable alignment and speed up blitting | 
|---|
| 986 |  | 
|---|
| 987 | pDBreal = (char*)malloc( lpDDSurfaceDesc->dwHeight * dwPitchDB + 24); | 
|---|
| 988 | pDiveBuffer = (char*)(((int)pDBreal + 7) & ~7); // align to QWORD | 
|---|
| 989 |  | 
|---|
| 990 | // Not sure if that is ok but we need this for translation | 
|---|
| 991 | // I hope no game uses YUV or such a crap | 
|---|
| 992 |  | 
|---|
| 993 | DDSurfaceDesc.ddpfPixelFormat.dwFourCC = SupportedFourCCs[dwBpp>>3]; | 
|---|
| 994 | } | 
|---|
| 995 |  | 
|---|
| 996 | } | 
|---|
| 997 | else | 
|---|
| 998 | { | 
|---|
| 999 |  | 
|---|
| 1000 | if(dwCaps & DDSCAPS_ALLOCONLOAD) | 
|---|
| 1001 | { | 
|---|
| 1002 | // 2. | 
|---|
| 1003 |  | 
|---|
| 1004 | WriteLog(" Alloc on Load Texture?!\n"); | 
|---|
| 1005 |  | 
|---|
| 1006 | dwCaps &= ~DDSCAPS_ALLOCONLOAD; // remove flag | 
|---|
| 1007 |  | 
|---|
| 1008 | // only allow this flag for textures | 
|---|
| 1009 | if(!dwCaps & DDSCAPS_TEXTURE) | 
|---|
| 1010 | { | 
|---|
| 1011 | lastError = DDERR_INVALIDPARAMS; | 
|---|
| 1012 | return; | 
|---|
| 1013 | } | 
|---|
| 1014 |  | 
|---|
| 1015 | dwCaps &= ~DDSCAPS_TEXTURE; // remove flag | 
|---|
| 1016 | pFrameBuffer = NULL; | 
|---|
| 1017 | pDiveBuffer  = NULL; | 
|---|
| 1018 |  | 
|---|
| 1019 | // This surface isn't allocated yet, but when the texture is loaded | 
|---|
| 1020 | #ifdef DEBUG | 
|---|
| 1021 | WriteLog("Warning : Delayed memory allocation on request\n"); | 
|---|
| 1022 | #endif | 
|---|
| 1023 | DDSurfaceDesc.lpSurface = NULL; | 
|---|
| 1024 | lpDDSurfaceDesc->lpSurface = NULL; | 
|---|
| 1025 | } | 
|---|
| 1026 | else | 
|---|
| 1027 | { | 
|---|
| 1028 | // 3. | 
|---|
| 1029 |  | 
|---|
| 1030 | WriteLog(" Alloc now!\n"); | 
|---|
| 1031 |  | 
|---|
| 1032 | lpDDSurfaceDesc->dwFlags  |= DDSD_PITCH|DDSD_LPSURFACE; | 
|---|
| 1033 | DDSurfaceDesc.dwFlags      = lpDDSurfaceDesc->dwFlags; | 
|---|
| 1034 |  | 
|---|
| 1035 | dwPitchFB = lpDDSurfaceDesc->dwWidth * (dwBpp<8?1:dwBpp/8); | 
|---|
| 1036 | dwPitchFB = (dwPitchFB +7) & ~7;  // Align on QWords | 
|---|
| 1037 | DDSurfaceDesc.lPitch    = dwPitchFB; | 
|---|
| 1038 | lpDDSurfaceDesc->lPitch = dwPitchFB; | 
|---|
| 1039 |  | 
|---|
| 1040 | #ifdef DEBUG | 
|---|
| 1041 | if(dwBpp<8) | 
|---|
| 1042 | { | 
|---|
| 1043 | WriteLog("1 or 4 Bit Surface encountered may not work !"); | 
|---|
| 1044 | } | 
|---|
| 1045 | #endif | 
|---|
| 1046 |  | 
|---|
| 1047 |  | 
|---|
| 1048 | // 24 byte more to enable alignment and speed up blitting | 
|---|
| 1049 |  | 
|---|
| 1050 | pFBreal = (char*)malloc( lpDDSurfaceDesc->dwHeight * dwPitchFB + 24); | 
|---|
| 1051 |  | 
|---|
| 1052 | if(NULL==pFBreal) | 
|---|
| 1053 | { | 
|---|
| 1054 | lastError = DDERR_OUTOFMEMORY; | 
|---|
| 1055 | return; | 
|---|
| 1056 | } | 
|---|
| 1057 |  | 
|---|
| 1058 | pFrameBuffer = (char*)(((int)pFBreal + 7) & ~7); // align to QWORD | 
|---|
| 1059 |  | 
|---|
| 1060 | WriteLog( " Framebuffer @ %08X QWAligned @ %08X with a Pitch of %d\n", | 
|---|
| 1061 | pFBreal, pFrameBuffer, dwPitchFB); | 
|---|
| 1062 |  | 
|---|
| 1063 | lpDDSurfaceDesc->lpSurface = pFrameBuffer; | 
|---|
| 1064 | DDSurfaceDesc.lpSurface    = pFrameBuffer; | 
|---|
| 1065 |  | 
|---|
| 1066 |  | 
|---|
| 1067 | if( (lpDraw->dCaps.ulDepth ) == dwBpp ) | 
|---|
| 1068 | { | 
|---|
| 1069 | WriteLog(" No CC_Buffer needed\n"); | 
|---|
| 1070 | // Yes => No Colorconversion is needed so point to the same buffer | 
|---|
| 1071 | pDiveBuffer  = pFrameBuffer; | 
|---|
| 1072 | } | 
|---|
| 1073 | else | 
|---|
| 1074 | { | 
|---|
| 1075 | WriteLog(" Alloc CCBuf "); | 
|---|
| 1076 | dwPitchDB = (lpDDSurfaceDesc->dwWidth * (lpDraw->dCaps.ulDepth/8) +7) & ~7; | 
|---|
| 1077 | if(Mainchain) | 
|---|
| 1078 | { | 
|---|
| 1079 | WriteLog("with DIVE\n"); | 
|---|
| 1080 | // This surface is part of flipchain with the primary surface use dive to assoc memory | 
|---|
| 1081 | pDiveBuffer = (char*)malloc( lpDDSurfaceDesc->dwHeight * | 
|---|
| 1082 | dwPitchDB); | 
|---|
| 1083 | diveBufNr = 0; | 
|---|
| 1084 | rc = DiveAllocImageBuffer( hDive, | 
|---|
| 1085 | &diveBufNr, | 
|---|
| 1086 | lpDraw->dCaps.fccColorEncoding, | 
|---|
| 1087 | lpDDSurfaceDesc->dwWidth, | 
|---|
| 1088 | lpDDSurfaceDesc->dwHeight, | 
|---|
| 1089 | dwPitchDB, | 
|---|
| 1090 | (PBYTE)pDiveBuffer); | 
|---|
| 1091 | WriteLog("rc = 0x%08X\n",rc); | 
|---|
| 1092 | } | 
|---|
| 1093 | else | 
|---|
| 1094 | { | 
|---|
| 1095 | WriteLog( "with malloc (%dx%d) Pitch %d ", | 
|---|
| 1096 | lpDDSurfaceDesc->dwHeight, | 
|---|
| 1097 | lpDDSurfaceDesc->dwWidth, | 
|---|
| 1098 | dwPitchDB); | 
|---|
| 1099 | // No so we must create the Divebuffer to do the colortranslation | 
|---|
| 1100 | // and blit to the real framebuffer on Unlock to do color conversion | 
|---|
| 1101 | pDiveBuffer = (char*)malloc( lpDDSurfaceDesc->dwHeight * | 
|---|
| 1102 | dwPitchDB); | 
|---|
| 1103 | } | 
|---|
| 1104 | WriteLog( "  @ %08X\n", pDiveBuffer); | 
|---|
| 1105 | } | 
|---|
| 1106 |  | 
|---|
| 1107 | }  // end of 3rd case | 
|---|
| 1108 | } // End of alloc surfaces | 
|---|
| 1109 |  | 
|---|
| 1110 | width  = DDSurfaceDesc.dwWidth; | 
|---|
| 1111 | height = DDSurfaceDesc.dwHeight; | 
|---|
| 1112 |  | 
|---|
| 1113 | if( dwCaps & DDSCAPS_COMPLEX) | 
|---|
| 1114 | { | 
|---|
| 1115 | // remove the flag | 
|---|
| 1116 | dwCaps &= ~DDSCAPS_COMPLEX; | 
|---|
| 1117 | #ifdef DEBUG | 
|---|
| 1118 | WriteLog("Complex Surface\n"); | 
|---|
| 1119 | #endif | 
|---|
| 1120 |  | 
|---|
| 1121 | if(lpDDSurfaceDesc->dwFlags & DDSD_BACKBUFFERCOUNT) | 
|---|
| 1122 | { | 
|---|
| 1123 | lpDDSurfaceDesc->dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 
|---|
| 1124 | #ifdef DEBUG | 
|---|
| 1125 | WriteLog("Backbuffer # = %d\n",lpDDSurfaceDesc->dwBackBufferCount); | 
|---|
| 1126 | #endif | 
|---|
| 1127 | memcpy(&ComplexSurfaceDesc,lpDDSurfaceDesc,sizeof(DDSURFACEDESC2)); | 
|---|
| 1128 | ComplexSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP;        // set flip | 
|---|
| 1129 | ComplexSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER; // remove backbuffer | 
|---|
| 1130 |  | 
|---|
| 1131 | if(ComplexSurfaceDesc.dwBackBufferCount>1) | 
|---|
| 1132 | { | 
|---|
| 1133 | ComplexSurfaceDesc.dwBackBufferCount--; | 
|---|
| 1134 | } | 
|---|
| 1135 | else | 
|---|
| 1136 | { | 
|---|
| 1137 | ComplexSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 
|---|
| 1138 | ComplexSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX; | 
|---|
| 1139 | } | 
|---|
| 1140 |  | 
|---|
| 1141 | BackBuffer = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE, Mainchain); | 
|---|
| 1142 | if (BackBuffer->GetLastError()==DD_OK) | 
|---|
| 1143 | { | 
|---|
| 1144 | DDSurfaceDesc.dwFlags |= DDSCAPS_FLIP; | 
|---|
| 1145 | BackBuffer->SetFrontBuffer(this); | 
|---|
| 1146 | } | 
|---|
| 1147 |  | 
|---|
| 1148 | } | 
|---|
| 1149 |  | 
|---|
| 1150 | // MipMap Surfaces are handled here | 
|---|
| 1151 | if( (lpDDSurfaceDesc->dwFlags & DDSD_MIPMAPCOUNT) && | 
|---|
| 1152 | (dwCaps & DDSCAPS_TEXTURE) && | 
|---|
| 1153 | (dwCaps & DDSCAPS_MIPMAP) ) | 
|---|
| 1154 | { | 
|---|
| 1155 | dwCaps &= ~ (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP); | 
|---|
| 1156 |  | 
|---|
| 1157 | lpDDSurfaceDesc->dwFlags &= ~DDSD_MIPMAPCOUNT; | 
|---|
| 1158 | #ifdef DEBUG | 
|---|
| 1159 | WriteLog("Mipmpa # = %d\n",lpDDSurfaceDesc->dwMipMapCount); | 
|---|
| 1160 | #endif | 
|---|
| 1161 | memcpy(&ComplexSurfaceDesc,lpDDSurfaceDesc,sizeof(DDSURFACEDESC2)); | 
|---|
| 1162 | ComplexSurfaceDesc.dwMipMapCount = 0; | 
|---|
| 1163 |  | 
|---|
| 1164 | for(int i =0; i < lpDDSurfaceDesc->dwMipMapCount; i++) | 
|---|
| 1165 | { | 
|---|
| 1166 | #ifdef DEBUG | 
|---|
| 1167 | WriteLog("Creating MipMap %d\n",i); | 
|---|
| 1168 | #endif | 
|---|
| 1169 | // Mpmaps shirnk by 2 | 
|---|
| 1170 | ComplexSurfaceDesc.dwWidth  /= 2; | 
|---|
| 1171 | ComplexSurfaceDesc.dwHeight /= 2; | 
|---|
| 1172 |  | 
|---|
| 1173 | MipMapSurface = new OS2IDirectDrawSurface(lpDraw, &ComplexSurfaceDesc, TRUE); | 
|---|
| 1174 |  | 
|---|
| 1175 | DPA_InsertPtr( DPA_SurfaceMipMaps, | 
|---|
| 1176 | DPA_GetPtrCount(DPA_SurfaceMipMaps), | 
|---|
| 1177 | MipMapSurface); | 
|---|
| 1178 |  | 
|---|
| 1179 | if(MipMapSurface->GetLastError() != DD_OK) | 
|---|
| 1180 | { | 
|---|
| 1181 | lastError = MipMapSurface->GetLastError(); | 
|---|
| 1182 | #ifdef DEBUG | 
|---|
| 1183 | WriteLog("Attached surface creation returned error %d\n",lastError); | 
|---|
| 1184 | #endif | 
|---|
| 1185 | return; | 
|---|
| 1186 | } // Endif Errorcheck | 
|---|
| 1187 | } //End for(i =0; i < lpDDSurfaceDesc->dwMipMapCount; i++) | 
|---|
| 1188 | } // End of MipMaps | 
|---|
| 1189 |  | 
|---|
| 1190 | #ifdef DEBUG | 
|---|
| 1191 | if(lpDDSurfaceDesc->dwFlags) | 
|---|
| 1192 | WriteLog("Unsupported Complex Surface\n"); | 
|---|
| 1193 | #endif | 
|---|
| 1194 | } // Endif DDSCAPS_COMPLEX | 
|---|
| 1195 | } | 
|---|
| 1196 | else | 
|---|
| 1197 | { | 
|---|
| 1198 | lastError = DDERR_INVALIDPARAMS; | 
|---|
| 1199 | } | 
|---|
| 1200 | } // Endif DDCAPS is valid | 
|---|
| 1201 | else | 
|---|
| 1202 | { | 
|---|
| 1203 | WriteLog("CAPS not valid\n"); | 
|---|
| 1204 | lastError = DDERR_INVALIDPARAMS; | 
|---|
| 1205 | } | 
|---|
| 1206 | #ifdef DEBUG | 
|---|
| 1207 | WriteLog("Buf %X Screen Caps (%d,%d), bitcount %d\n\n", this, lpDraw->GetScreenHeight(), lpDraw->GetScreenWidth(), | 
|---|
| 1208 | lpDraw->dCaps.ulDepth); | 
|---|
| 1209 | if(DD_OK!=lastError) | 
|---|
| 1210 | { | 
|---|
| 1211 | WriteLog("Some Error Check Flags\n"); | 
|---|
| 1212 | _dump_DDSCAPS(lpDDSurfaceDesc->dwFlags); | 
|---|
| 1213 | } | 
|---|
| 1214 | #endif | 
|---|
| 1215 | } | 
|---|
| 1216 | //****************************************************************************** | 
|---|
| 1217 | //****************************************************************************** | 
|---|
| 1218 | HRESULT OS2IDirectDrawSurface::ColorFill(LPRECT lpDestRect,DWORD dwFillColor) | 
|---|
| 1219 | { | 
|---|
| 1220 |  | 
|---|
| 1221 | int i,j, FillWidth, FillHeight; | 
|---|
| 1222 | char *pLine, *pFillPos; | 
|---|
| 1223 |  | 
|---|
| 1224 | DWORD *pColor, dwColor,y; | 
|---|
| 1225 | DWORD *pPal24; | 
|---|
| 1226 | WORD  *pPal16; | 
|---|
| 1227 | #ifdef DEBUG | 
|---|
| 1228 | WriteLog("ColorFill with %08X\n", dwFillColor); | 
|---|
| 1229 | #endif | 
|---|
| 1230 |  | 
|---|
| 1231 | if(NULL!=lpDestRect) | 
|---|
| 1232 | { | 
|---|
| 1233 | #ifdef DEBUG | 
|---|
| 1234 | WriteLog("Fill only Rect(%d,%d)(%d,%d)\n", lpDestRect->left, lpDestRect->top, | 
|---|
| 1235 | lpDestRect->right, lpDestRect->bottom); | 
|---|
| 1236 | #endif | 
|---|
| 1237 | FillWidth  = lpDestRect->right - lpDestRect->left; | 
|---|
| 1238 | FillHeight = lpDestRect->bottom - lpDestRect->top -1; | 
|---|
| 1239 | pLine = pDiveBuffer + | 
|---|
| 1240 | (lpDestRect->top*dwPitchDB) + | 
|---|
| 1241 | (lpDestRect->left*dwBytesPPDive); | 
|---|
| 1242 | } | 
|---|
| 1243 | else | 
|---|
| 1244 | { | 
|---|
| 1245 | WriteLog("Fill all at addr "); | 
|---|
| 1246 | FillWidth  = width; | 
|---|
| 1247 | FillHeight = height -1; | 
|---|
| 1248 | pLine = pDiveBuffer; | 
|---|
| 1249 | } | 
|---|
| 1250 | WriteLog("0x%08X (%d/%d) at\n", pLine,FillWidth,FillHeight); | 
|---|
| 1251 |  | 
|---|
| 1252 | if(pDiveBuffer!=pFrameBuffer) | 
|---|
| 1253 | { | 
|---|
| 1254 | if( (NULL== lpDraw->pPrimSurf) || | 
|---|
| 1255 | (NULL== ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette) ) | 
|---|
| 1256 | { | 
|---|
| 1257 | if(!fPalInit) | 
|---|
| 1258 | { | 
|---|
| 1259 | for(DWORD i=0;i<256;i++) | 
|---|
| 1260 | { | 
|---|
| 1261 | wDefaultPalete16[i] = (DefaultPalette[i*3+2]>>3) + | 
|---|
| 1262 | ((DefaultPalette[i*3+1]>>2) <<5) + | 
|---|
| 1263 | ((DefaultPalette[i*3]>>3) << 11); | 
|---|
| 1264 | WriteLog( " # %d : RGB=%02X/%02X/%02X => %04X\n", | 
|---|
| 1265 | i, | 
|---|
| 1266 | DefaultPalette[i*3], | 
|---|
| 1267 | DefaultPalette[i*3+1], | 
|---|
| 1268 | DefaultPalette[i*3+2], | 
|---|
| 1269 | wDefaultPalete16[i]); | 
|---|
| 1270 | // aPal24[i] = (lpColorTable[i].peBlue <<8) + | 
|---|
| 1271 | //             (lpColorTable[i].peGreen<<16) + | 
|---|
| 1272 | //             (lpColorTable[i].peRed<<24); | 
|---|
| 1273 | } | 
|---|
| 1274 | fPalInit = TRUE; | 
|---|
| 1275 | } | 
|---|
| 1276 | pPal16 = &wDefaultPalete16[0]; | 
|---|
| 1277 | } | 
|---|
| 1278 | else | 
|---|
| 1279 | { | 
|---|
| 1280 | pPal16 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal16; | 
|---|
| 1281 | pPal24 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal24; | 
|---|
| 1282 | } | 
|---|
| 1283 | } | 
|---|
| 1284 |  | 
|---|
| 1285 | switch(dwBytesPPDive) | 
|---|
| 1286 | { | 
|---|
| 1287 | case 1: | 
|---|
| 1288 | WriteLog("8 Bit\n"); | 
|---|
| 1289 | dwColor = (dwFillColor<<24) + (dwFillColor<<16) + | 
|---|
| 1290 | (dwFillColor<<8)  + (dwFillColor); | 
|---|
| 1291 | for(i=0,pColor = (DWORD*)pLine;i<(FillWidth/4);i++) | 
|---|
| 1292 | pColor[i] = dwColor; | 
|---|
| 1293 | if(FillWidth % 4) | 
|---|
| 1294 | { | 
|---|
| 1295 | pFillPos = (char*) (&pColor[i-1]); | 
|---|
| 1296 | for(i=0;i<FillWidth % 4;i++) | 
|---|
| 1297 | pFillPos[i] = (UCHAR) dwColor; | 
|---|
| 1298 | } | 
|---|
| 1299 | break; | 
|---|
| 1300 | case 2: | 
|---|
| 1301 | WriteLog("16 Bit\n"); | 
|---|
| 1302 | if(pDiveBuffer!=pFrameBuffer) | 
|---|
| 1303 | { | 
|---|
| 1304 | if(8==lpDraw->GetScreenBpp()) | 
|---|
| 1305 | dwFillColor = pPal16[dwFillColor]; | 
|---|
| 1306 | } | 
|---|
| 1307 | dwColor = (dwFillColor<<16) + (dwFillColor); | 
|---|
| 1308 | WriteLog("Fill with 0x%08X\n",dwColor); | 
|---|
| 1309 | for(i=0,pColor = (DWORD*)pLine;i<(FillWidth/2);i++) | 
|---|
| 1310 | pColor[i] = dwColor; | 
|---|
| 1311 | if(FillWidth % 2) | 
|---|
| 1312 | { | 
|---|
| 1313 | pFillPos = (char*)(&pColor[i-1]); | 
|---|
| 1314 | *((USHORT*)pFillPos) = (USHORT)dwColor; | 
|---|
| 1315 | } | 
|---|
| 1316 | break; | 
|---|
| 1317 | case 3: | 
|---|
| 1318 | WriteLog("24 Bit\n"); | 
|---|
| 1319 |  | 
|---|
| 1320 | dwColor = (dwFillColor<<8); | 
|---|
| 1321 | for(i=0 ; i<FillWidth ; i++) | 
|---|
| 1322 | { | 
|---|
| 1323 | char* pColor = (char*)pLine+(i*3); | 
|---|
| 1324 | *pColor = dwColor; | 
|---|
| 1325 | } | 
|---|
| 1326 | break; | 
|---|
| 1327 | case 4: | 
|---|
| 1328 | WriteLog("32 Bit\n"); | 
|---|
| 1329 | dwColor = dwFillColor; | 
|---|
| 1330 | for(i=0,pColor = (DWORD*)pLine;i<FillWidth;i++) | 
|---|
| 1331 | pColor[i] = dwColor; | 
|---|
| 1332 | break; | 
|---|
| 1333 | default: | 
|---|
| 1334 | #ifdef DEBUG | 
|---|
| 1335 | WriteLog("Unexpected Bitdepth\n"); | 
|---|
| 1336 | #endif | 
|---|
| 1337 | return DDERR_GENERIC; | 
|---|
| 1338 | } // end switch(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 1339 |  | 
|---|
| 1340 |  | 
|---|
| 1341 | pFillPos = pLine + dwPitchDB; | 
|---|
| 1342 | FillWidth = FillWidth*dwBytesPPDive;; | 
|---|
| 1343 | for( y=0;y<FillHeight;y++,pFillPos+=dwPitchDB) | 
|---|
| 1344 | { | 
|---|
| 1345 | #ifdef USE_ASM | 
|---|
| 1346 | // ToDo get the loop into an asm function as well to speed up filling | 
|---|
| 1347 | // maybe remove the creation of the first fill line in an all asm | 
|---|
| 1348 | // function and use MMX regs to set 8 bytes | 
|---|
| 1349 | MemFlip(pFillPos,pLine,FillWidth); | 
|---|
| 1350 | #else | 
|---|
| 1351 | memcpy(pFillPos,pLine,FillWidth); | 
|---|
| 1352 | #endif | 
|---|
| 1353 | } | 
|---|
| 1354 |  | 
|---|
| 1355 | return(DD_OK); | 
|---|
| 1356 |  | 
|---|
| 1357 | #if 0 // rest of old code for resuse/move to a function to get closest syscolor | 
|---|
| 1358 | // for colorconversion modes color fills | 
|---|
| 1359 | else | 
|---|
| 1360 | { | 
|---|
| 1361 | // Yeah! Color conversion needed ;) | 
|---|
| 1362 | #ifdef DEBUG | 
|---|
| 1363 | WriteLog("Color converion ! Urks, may not work \n"); | 
|---|
| 1364 | #endif | 
|---|
| 1365 |  | 
|---|
| 1366 | switch(dest->lpDraw->dCaps.ulDepth) | 
|---|
| 1367 | { | 
|---|
| 1368 | case 8:  // 256 Mode bad thing as programm wants to run in a higher mode might look ugly | 
|---|
| 1369 | GetSystemPaletteEntries(GetDC(HWND_DESKTOP),0,255,&SysPal[1]); | 
|---|
| 1370 | pLogPal->palVersion = 0; | 
|---|
| 1371 | pLogPal->palNumEntries = 256; | 
|---|
| 1372 |  | 
|---|
| 1373 | hPal = CreatePalette(pLogPal); | 
|---|
| 1374 | if(hPal!=NULL) | 
|---|
| 1375 | { | 
|---|
| 1376 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==16) | 
|---|
| 1377 | { | 
|---|
| 1378 | ulColor = ((lpDDBltFx->dwFillColor & 0x0000001F) <<3) + | 
|---|
| 1379 | ((lpDDBltFx->dwFillColor & 0x000007E0) <<5) + | 
|---|
| 1380 | ((lpDDBltFx->dwFillColor & 0x0000F800) <<8); | 
|---|
| 1381 | } | 
|---|
| 1382 | else | 
|---|
| 1383 | ulColor = lpDDBltFx->dwFillColor; | 
|---|
| 1384 |  | 
|---|
| 1385 | ulColor = GetNearestPaletteIndex(hPal,ulColor); | 
|---|
| 1386 | ulColor = (ulColor & 0x000000FF) + ((ulColor & 0x000000FF) << 8) + | 
|---|
| 1387 | ((ulColor & 0x000000FF) << 16) + ((ulColor & 0x000000FF) << 24); | 
|---|
| 1388 | } | 
|---|
| 1389 | else | 
|---|
| 1390 | { | 
|---|
| 1391 | #ifdef DEBUG | 
|---|
| 1392 | WriteLog("Error creating Palette default to 0"); | 
|---|
| 1393 | #endif | 
|---|
| 1394 | ulColor = 0; | 
|---|
| 1395 | } | 
|---|
| 1396 | for(i=0,(char*)pColor = ScanLine;i<(FillWidth/4)+1;i++) | 
|---|
| 1397 | *(pColor+i) = ulColor; | 
|---|
| 1398 | break; | 
|---|
| 1399 | case 16: | 
|---|
| 1400 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==8) | 
|---|
| 1401 | { | 
|---|
| 1402 | if(lpDDBltFx->dwFillColor > 255) | 
|---|
| 1403 | return DDERR_INVALIDPARAMS; | 
|---|
| 1404 |  | 
|---|
| 1405 | if(dest->lpPalette!=NULL) | 
|---|
| 1406 | dest->lpPalette->lpVtbl->GetEntries(dest->lpPalette,0,0,256,(LPPALETTEENTRY)&SysPal); | 
|---|
| 1407 | else | 
|---|
| 1408 | GetSystemPaletteEntries(GetDC(HWND_DESKTOP),0,255,(PPALETTEENTRY)&SysPal); | 
|---|
| 1409 |  | 
|---|
| 1410 | SysPal[lpDDBltFx->dwFillColor].peBlue  >>3; | 
|---|
| 1411 | SysPal[lpDDBltFx->dwFillColor].peGreen >>2; | 
|---|
| 1412 | SysPal[lpDDBltFx->dwFillColor].peRed   >>3; | 
|---|
| 1413 | ulColor = ULONG(SysPal[lpDDBltFx->dwFillColor].peRed) << 11 + | 
|---|
| 1414 | ULONG(SysPal[lpDDBltFx->dwFillColor].peGreen) << 5 + | 
|---|
| 1415 | ULONG(SysPal[lpDDBltFx->dwFillColor].peBlue); | 
|---|
| 1416 | } | 
|---|
| 1417 | else | 
|---|
| 1418 | { | 
|---|
| 1419 | ulColor = (lpDDBltFx->dwFillColor & 0x000000FF)>>3 + | 
|---|
| 1420 | (((lpDDBltFx->dwFillColor & 0x0000FF00)>>5) & 0x000007E0) + | 
|---|
| 1421 | (((lpDDBltFx->dwFillColor & 0x00FF0000)>>8) & 0x0000F800); | 
|---|
| 1422 | } | 
|---|
| 1423 | ulColor += ulColor << 16; | 
|---|
| 1424 | for(i=0,(char*)pColor = ScanLine;i<(FillWidth/2)+1;i++) | 
|---|
| 1425 | *(pColor+i) = ulColor; | 
|---|
| 1426 | break; | 
|---|
| 1427 | case 24: | 
|---|
| 1428 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==8) | 
|---|
| 1429 | { | 
|---|
| 1430 | if(lpDDBltFx->dwFillColor > 255) | 
|---|
| 1431 | return DDERR_INVALIDPARAMS; | 
|---|
| 1432 |  | 
|---|
| 1433 | if(dest->lpPalette!=NULL) | 
|---|
| 1434 | dest->lpPalette->lpVtbl->GetEntries(dest->lpPalette,0,0,256,(LPPALETTEENTRY)&SysPal); | 
|---|
| 1435 | else | 
|---|
| 1436 | GetSystemPaletteEntries(GetDC(HWND_DESKTOP),0,255,(PPALETTEENTRY)&SysPal); | 
|---|
| 1437 |  | 
|---|
| 1438 | ulColor = ULONG(SysPal[lpDDBltFx->dwFillColor].peRed) <<24 + | 
|---|
| 1439 | ULONG(SysPal[lpDDBltFx->dwFillColor].peGreen) <<16 + | 
|---|
| 1440 | ULONG(SysPal[lpDDBltFx->dwFillColor].peBlue) <<8; | 
|---|
| 1441 | } | 
|---|
| 1442 | else | 
|---|
| 1443 | { | 
|---|
| 1444 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==16) | 
|---|
| 1445 | { | 
|---|
| 1446 | ulColor = ((lpDDBltFx->dwFillColor & 0x0000001F) <<11) + | 
|---|
| 1447 | ((lpDDBltFx->dwFillColor & 0x000007E0) <<13) + | 
|---|
| 1448 | ((lpDDBltFx->dwFillColor & 0x0000F800) <<18); | 
|---|
| 1449 | } | 
|---|
| 1450 | else | 
|---|
| 1451 | ulColor = lpDDBltFx->dwFillColor << 8 ; | 
|---|
| 1452 | } | 
|---|
| 1453 |  | 
|---|
| 1454 | for(i=0;i<FillWidth;i++) | 
|---|
| 1455 | { | 
|---|
| 1456 | char* pColor = (char*)Scanline+(i*3); | 
|---|
| 1457 | *pColor = ulColor; | 
|---|
| 1458 | } | 
|---|
| 1459 | break; | 
|---|
| 1460 | case 32: | 
|---|
| 1461 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==8) | 
|---|
| 1462 | { | 
|---|
| 1463 | if(lpDDBltFx->dwFillColor > 255) | 
|---|
| 1464 | return DDERR_INVALIDPARAMS; | 
|---|
| 1465 |  | 
|---|
| 1466 | if(dest->lpPalette!=NULL) | 
|---|
| 1467 | dest->lpPalette->lpVtbl->GetEntries(dest->lpPalette,0,0,256,(LPPALETTEENTRY)&SysPal); | 
|---|
| 1468 | else | 
|---|
| 1469 | GetSystemPaletteEntries(GetDC(HWND_DESKTOP),0,255,(PPALETTEENTRY)&SysPal); | 
|---|
| 1470 |  | 
|---|
| 1471 | ulColor = ULONG(SysPal[lpDDBltFx->dwFillColor].peRed) <<16 + | 
|---|
| 1472 | ULONG(SysPal[lpDDBltFx->dwFillColor].peGreen) <<8 + | 
|---|
| 1473 | ULONG(SysPal[lpDDBltFx->dwFillColor].peBlue); | 
|---|
| 1474 | } | 
|---|
| 1475 | else | 
|---|
| 1476 | { | 
|---|
| 1477 | if(dest->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount==16) | 
|---|
| 1478 | { | 
|---|
| 1479 | ulColor = ((lpDDBltFx->dwFillColor & 0x0000001F) <<3) + | 
|---|
| 1480 | ((lpDDBltFx->dwFillColor & 0x000007E0) <<5) + | 
|---|
| 1481 | ((lpDDBltFx->dwFillColor & 0x0000F800) <<8); | 
|---|
| 1482 | } | 
|---|
| 1483 | else | 
|---|
| 1484 | ulColor = lpDDBltFx->dwFillColor & 0x00FFFFFF; | 
|---|
| 1485 | } | 
|---|
| 1486 |  | 
|---|
| 1487 | for(i=0,(char*)pColor = ScanLine;i<(FillWidth/4);i++) | 
|---|
| 1488 | *(pColor+i) = ulColor; | 
|---|
| 1489 | break; | 
|---|
| 1490 | default: | 
|---|
| 1491 | #ifdef DEBUG | 
|---|
| 1492 | WriteLog("Unexpected Bitdepth\n"); | 
|---|
| 1493 | #endif | 
|---|
| 1494 | return DDERR_GENERIC; | 
|---|
| 1495 | } // end switch (dest->lpDraw->dCaps.ulDepth) | 
|---|
| 1496 | }// end of Scanline setup | 
|---|
| 1497 | #endif | 
|---|
| 1498 |  | 
|---|
| 1499 | } | 
|---|
| 1500 | //****************************************************************************** | 
|---|
| 1501 | //****************************************************************************** | 
|---|
| 1502 | void OS2IDirectDrawSurface::ColorConversion(LPRECT lpRect) | 
|---|
| 1503 | { | 
|---|
| 1504 | char *pSrc,*pDst,*pSLine,*pDLine; | 
|---|
| 1505 | DWORD CCwidth,CCheight,x,y; | 
|---|
| 1506 | DWORD *pPal24; | 
|---|
| 1507 | WORD  *pPal16; | 
|---|
| 1508 |  | 
|---|
| 1509 | if( (NULL== lpDraw->pPrimSurf) || | 
|---|
| 1510 | (NULL== ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette) ) | 
|---|
| 1511 | { | 
|---|
| 1512 | if(!fPalInit) | 
|---|
| 1513 | { | 
|---|
| 1514 | for(DWORD i=0;i<256;i++) | 
|---|
| 1515 | { | 
|---|
| 1516 | wDefaultPalete16[i] = (DefaultPalette[i*3+2]>>3) + | 
|---|
| 1517 | ((DefaultPalette[i*3+1]>>2) <<5) + | 
|---|
| 1518 | ((DefaultPalette[i*3]>>3) << 11); | 
|---|
| 1519 | WriteLog( " # %d : RGB=%02X/%02X/%02X => %04X\n", | 
|---|
| 1520 | i, | 
|---|
| 1521 | DefaultPalette[i*3], | 
|---|
| 1522 | DefaultPalette[i*3+1], | 
|---|
| 1523 | DefaultPalette[i*3+2], | 
|---|
| 1524 | wDefaultPalete16[i]); | 
|---|
| 1525 | // aPal24[i] = (lpColorTable[i].peBlue <<8) + | 
|---|
| 1526 | //             (lpColorTable[i].peGreen<<16) + | 
|---|
| 1527 | //             (lpColorTable[i].peRed<<24); | 
|---|
| 1528 | } | 
|---|
| 1529 | fPalInit = TRUE; | 
|---|
| 1530 | } | 
|---|
| 1531 | pPal16 = &wDefaultPalete16[0]; | 
|---|
| 1532 | } | 
|---|
| 1533 | else | 
|---|
| 1534 | { | 
|---|
| 1535 | pPal16 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal16; | 
|---|
| 1536 | pPal24 = ((OS2IDirectDrawSurface*)lpDraw->pPrimSurf)->lpPalette->aPal24; | 
|---|
| 1537 | } | 
|---|
| 1538 |  | 
|---|
| 1539 | if(NULL==lpRect) | 
|---|
| 1540 | { | 
|---|
| 1541 | pSrc = pFrameBuffer; | 
|---|
| 1542 | pDst = pDiveBuffer; | 
|---|
| 1543 | CCwidth  = width; | 
|---|
| 1544 | CCheight = height; | 
|---|
| 1545 | } | 
|---|
| 1546 | else | 
|---|
| 1547 | { | 
|---|
| 1548 | // ToDo: Check why the top/bottom values come in swaped here | 
|---|
| 1549 | // for now simply reverse them with the following 3 lines | 
|---|
| 1550 | y = lpRect->top; | 
|---|
| 1551 | lpRect->top = lpRect->bottom; | 
|---|
| 1552 | lpRect->bottom = y; | 
|---|
| 1553 | // end of hack | 
|---|
| 1554 | pSrc = pFrameBuffer + | 
|---|
| 1555 | (lpRect->top * dwPitchFB) + | 
|---|
| 1556 | (lpRect->left* (lpDraw->dCaps.ulDepth/8)); | 
|---|
| 1557 | pDst = pDiveBuffer + | 
|---|
| 1558 | (lpRect->top * dwPitchDB) + | 
|---|
| 1559 | (lpRect->left* dwBytesPPDive); | 
|---|
| 1560 | CCwidth  = lpRect->right - lpRect->left; | 
|---|
| 1561 | CCheight = lpRect->bottom - lpRect->top; | 
|---|
| 1562 |  | 
|---|
| 1563 | } | 
|---|
| 1564 |  | 
|---|
| 1565 | WriteLog( "H: %d W: %d\n SRC @ %08X\n DST @ %08X\n", | 
|---|
| 1566 | CCheight, CCwidth, pSrc,pDst); | 
|---|
| 1567 |  | 
|---|
| 1568 | pSLine = pSrc; | 
|---|
| 1569 | pDLine = pDst; | 
|---|
| 1570 |  | 
|---|
| 1571 | switch(lpDraw->dCaps.ulDepth) | 
|---|
| 1572 | { | 
|---|
| 1573 | case 8: | 
|---|
| 1574 | WriteLog(" 8Bit target CC not implemented\n"); | 
|---|
| 1575 | break; | 
|---|
| 1576 | case 15: | 
|---|
| 1577 | WriteLog(" 15 Bit not implemented using 16bit might look ugly\n"); | 
|---|
| 1578 | case 16: | 
|---|
| 1579 | if(8==lpDraw->GetScreenBpp()) | 
|---|
| 1580 | { | 
|---|
| 1581 | WriteLog("8->16Bit CC\n"); | 
|---|
| 1582 | for(y=0;CCheight;CCheight--,y++) | 
|---|
| 1583 | { | 
|---|
| 1584 | for(x=0;x<width;x++) | 
|---|
| 1585 | { | 
|---|
| 1586 | *((WORD*)pDLine) = pPal16[pSLine[x]]; | 
|---|
| 1587 | } | 
|---|
| 1588 | pSLine += dwPitchFB; | 
|---|
| 1589 | pDLine += dwPitchDB; | 
|---|
| 1590 | } | 
|---|
| 1591 | } | 
|---|
| 1592 | else | 
|---|
| 1593 | { | 
|---|
| 1594 | WriteLog("%d ->16Bit Not implemented",lpDraw->GetScreenBpp()); | 
|---|
| 1595 | } | 
|---|
| 1596 | break; | 
|---|
| 1597 | case 24: | 
|---|
| 1598 | if(8==lpDraw->GetScreenBpp()) | 
|---|
| 1599 | { | 
|---|
| 1600 | WriteLog("8->24Bit CC"); | 
|---|
| 1601 | } | 
|---|
| 1602 | else | 
|---|
| 1603 | { | 
|---|
| 1604 | WriteLog("%d ->24Bit Not implemented",lpDraw->GetScreenBpp()); | 
|---|
| 1605 | } | 
|---|
| 1606 | break; | 
|---|
| 1607 | case 32: | 
|---|
| 1608 | if(8==lpDraw->GetScreenBpp()) | 
|---|
| 1609 | { | 
|---|
| 1610 | WriteLog("8->32Bit CC"); | 
|---|
| 1611 | } | 
|---|
| 1612 | else | 
|---|
| 1613 | { | 
|---|
| 1614 | WriteLog("%d ->32Bit Not implemented",lpDraw->GetScreenBpp()); | 
|---|
| 1615 | } | 
|---|
| 1616 | break; | 
|---|
| 1617 | default: | 
|---|
| 1618 | #ifdef DEBUG | 
|---|
| 1619 | WriteLog( "Unexpected Screen Bitdepth %d\n", | 
|---|
| 1620 | lpDraw->dCaps.ulDepth); | 
|---|
| 1621 | #endif | 
|---|
| 1622 | break; | 
|---|
| 1623 | } | 
|---|
| 1624 |  | 
|---|
| 1625 | /* | 
|---|
| 1626 | SETUP_BLITTER sBlt; | 
|---|
| 1627 | ULONG ulDN1, ulDN2; | 
|---|
| 1628 | ULONG rc; | 
|---|
| 1629 | ulDN1 = ulDN2 = 0; | 
|---|
| 1630 |  | 
|---|
| 1631 | memset(&sBlt,0,sizeof(sBlt)); | 
|---|
| 1632 | sBlt.ulStructLen = sizeof(sBlt); | 
|---|
| 1633 | sBlt.fccSrcColorFormat = (FOURCC) DDSurfaceDesc.ddpfPixelFormat.dwFourCC; | 
|---|
| 1634 | if (NULL!=lpRect) | 
|---|
| 1635 | { | 
|---|
| 1636 | sBlt.ulSrcWidth        = lpRect->right - lpRect->left; | 
|---|
| 1637 | sBlt.ulSrcHeight       = lpRect->top   - lpRect->bottom; | 
|---|
| 1638 | sBlt.ulSrcPosX         = lpRect->left; | 
|---|
| 1639 | sBlt.ulSrcPosY         = height - lpRect->top; | 
|---|
| 1640 | } | 
|---|
| 1641 | else | 
|---|
| 1642 | { | 
|---|
| 1643 | sBlt.ulSrcWidth        = width; | 
|---|
| 1644 | sBlt.ulSrcHeight       = height; | 
|---|
| 1645 | sBlt.ulSrcPosX         = 0; | 
|---|
| 1646 | sBlt.ulSrcPosY         = 0; | 
|---|
| 1647 | } | 
|---|
| 1648 | sBlt.fccDstColorFormat = FOURCC_SCRN; | 
|---|
| 1649 | sBlt.ulDstWidth        = sBlt.ulSrcWidth; | 
|---|
| 1650 | sBlt.ulDstHeight       = sBlt.ulSrcHeight; | 
|---|
| 1651 | sBlt.lDstPosX          = sBlt.ulSrcPosX; | 
|---|
| 1652 | sBlt.lDstPosY          = sBlt.ulSrcPosY; | 
|---|
| 1653 | sBlt.ulNumDstRects     = DIVE_FULLY_VISIBLE; | 
|---|
| 1654 |  | 
|---|
| 1655 | WriteLog( "Colorconversion:\n FCC SRC %08X\n FCC DST %08X\n", | 
|---|
| 1656 | sBlt.fccSrcColorFormat, | 
|---|
| 1657 | sBlt.fccDstColorFormat ); | 
|---|
| 1658 |  | 
|---|
| 1659 | rc = DiveAllocImageBuffer( hDiveCC, | 
|---|
| 1660 | &ulDN1, | 
|---|
| 1661 | sBlt.fccSrcColorFormat, | 
|---|
| 1662 | width, | 
|---|
| 1663 | height, | 
|---|
| 1664 | dwPitchFB, | 
|---|
| 1665 | (PBYTE)pFrameBuffer); | 
|---|
| 1666 | WriteLog("AllocDiveSrc Buffer rc= 0x%08X\n",rc); | 
|---|
| 1667 |  | 
|---|
| 1668 | rc = DiveAllocImageBuffer( hDiveCC, | 
|---|
| 1669 | &ulDN2, | 
|---|
| 1670 | sBlt.fccDstColorFormat, | 
|---|
| 1671 | width, | 
|---|
| 1672 | height, | 
|---|
| 1673 | dwPitchDB, | 
|---|
| 1674 | (PBYTE)pDiveBuffer); | 
|---|
| 1675 | WriteLog("AllocDiveDst Buffer rc= 0x%08X\n",rc); | 
|---|
| 1676 |  | 
|---|
| 1677 | rc = DiveSetupBlitter( hDiveCC, | 
|---|
| 1678 | &sBlt); | 
|---|
| 1679 | WriteLog("SetupBlitter rc= %X\n",rc); | 
|---|
| 1680 |  | 
|---|
| 1681 | rc = DiveBlitImage( hDiveCC, | 
|---|
| 1682 | ulDN1, | 
|---|
| 1683 | ulDN2); | 
|---|
| 1684 |  | 
|---|
| 1685 | WriteLog("Blit rc= %X\n",rc); | 
|---|
| 1686 |  | 
|---|
| 1687 | rc = DiveFreeImageBuffer( hDiveCC, | 
|---|
| 1688 | ulDN1); | 
|---|
| 1689 | WriteLog("Free Src rc= %X\n",rc); | 
|---|
| 1690 |  | 
|---|
| 1691 | rc = DiveFreeImageBuffer( hDiveCC, | 
|---|
| 1692 | ulDN2); | 
|---|
| 1693 |  | 
|---|
| 1694 | WriteLog("Free dst rc= %X\n",rc); | 
|---|
| 1695 | */ | 
|---|
| 1696 | } | 
|---|
| 1697 | //****************************************************************************** | 
|---|
| 1698 | //****************************************************************************** | 
|---|
| 1699 | // Internal callbacks uses by destructor | 
|---|
| 1700 | int  DestroyRects(LPVOID lpItem, DWORD dwRes) | 
|---|
| 1701 | { | 
|---|
| 1702 | DDRectangle *pItem = (DDRectangle*) lpItem; | 
|---|
| 1703 | delete(pItem); | 
|---|
| 1704 | return 1; | 
|---|
| 1705 | } | 
|---|
| 1706 |  | 
|---|
| 1707 | int ReleaseSurfaces(LPVOID lpItem, DWORD dwRes) | 
|---|
| 1708 | { | 
|---|
| 1709 | OS2IDirectDrawSurface *pSurf; | 
|---|
| 1710 | pSurf = (OS2IDirectDrawSurface *)lpItem; | 
|---|
| 1711 | pSurf->Vtbl.Release(pSurf); | 
|---|
| 1712 | return 1; | 
|---|
| 1713 | } | 
|---|
| 1714 | //****************************************************************************** | 
|---|
| 1715 | //****************************************************************************** | 
|---|
| 1716 |  | 
|---|
| 1717 | OS2IDirectDrawSurface::~OS2IDirectDrawSurface() | 
|---|
| 1718 | { | 
|---|
| 1719 | OS2IDirectDrawSurface  *AttachedSurface; | 
|---|
| 1720 |  | 
|---|
| 1721 |  | 
|---|
| 1722 | if(DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 1723 | { | 
|---|
| 1724 | lpDraw->SetPrimarySurface(FALSE); | 
|---|
| 1725 | if(lpPalette) | 
|---|
| 1726 | lpPalette->RestorePhysPalette(); | 
|---|
| 1727 | } | 
|---|
| 1728 | else | 
|---|
| 1729 | { | 
|---|
| 1730 | if( diveBufNr != -1) | 
|---|
| 1731 | { | 
|---|
| 1732 | if(fLocked) | 
|---|
| 1733 | DiveEndImageBufferAccess(hDive, diveBufNr); | 
|---|
| 1734 | DiveFreeImageBuffer(hDive, diveBufNr); | 
|---|
| 1735 | } | 
|---|
| 1736 | else | 
|---|
| 1737 | { | 
|---|
| 1738 | // Memory Surfaces | 
|---|
| 1739 | if (!Updated)  // check for user handled buffer | 
|---|
| 1740 | free(DDSurfaceDesc.lpSurface); | 
|---|
| 1741 | } | 
|---|
| 1742 |  | 
|---|
| 1743 |  | 
|---|
| 1744 | fLocked = FALSE; | 
|---|
| 1745 | diveBufNr = -1; | 
|---|
| 1746 | } | 
|---|
| 1747 |  | 
|---|
| 1748 | // Free the translation buffer | 
|---|
| 1749 | if(pFrameBuffer != pDiveBuffer) | 
|---|
| 1750 | free(pDiveBuffer); | 
|---|
| 1751 |  | 
|---|
| 1752 | // Clear the list of locked rectangles | 
|---|
| 1753 | if (DPA_GetPtrCount(DPA_LockedRects)>0) | 
|---|
| 1754 | { | 
|---|
| 1755 | DPA_DestroyCallback( DPA_LockedRects, | 
|---|
| 1756 | (DPAENUMPROC)DestroyRects, | 
|---|
| 1757 | 0); | 
|---|
| 1758 | } | 
|---|
| 1759 |  | 
|---|
| 1760 | if(lpClipper) | 
|---|
| 1761 | { | 
|---|
| 1762 | lpClipper->Vtbl.Release((IDirectDrawClipper*)lpClipper); | 
|---|
| 1763 | lpClipper = NULL; | 
|---|
| 1764 | } | 
|---|
| 1765 |  | 
|---|
| 1766 | if(lpPalette) | 
|---|
| 1767 | { | 
|---|
| 1768 | lpPalette->Vtbl.Release((IDirectDrawPalette*)lpPalette); | 
|---|
| 1769 | lpPalette = NULL; | 
|---|
| 1770 | } | 
|---|
| 1771 |  | 
|---|
| 1772 | if(hbmImage) | 
|---|
| 1773 | DeleteObject(hbmImage); | 
|---|
| 1774 |  | 
|---|
| 1775 | if(hdcImage) | 
|---|
| 1776 | DeleteDC(hdcImage); | 
|---|
| 1777 |  | 
|---|
| 1778 | if (NULL!=BackBuffer) | 
|---|
| 1779 | BackBuffer->Vtbl.Release(AttachedSurface); | 
|---|
| 1780 |  | 
|---|
| 1781 | if (DPA_GetPtrCount(DPA_SurfaceMipMaps)>0) | 
|---|
| 1782 | { | 
|---|
| 1783 | DPA_DestroyCallback( DPA_SurfaceMipMaps, | 
|---|
| 1784 | (DPAENUMPROC)ReleaseSurfaces, | 
|---|
| 1785 | 0); | 
|---|
| 1786 | } | 
|---|
| 1787 |  | 
|---|
| 1788 | if (DPA_GetPtrCount(DPA_SurfaceAttached)>0) | 
|---|
| 1789 | { | 
|---|
| 1790 | DPA_DestroyCallback( DPA_SurfaceAttached, | 
|---|
| 1791 | (DPAENUMPROC)ReleaseSurfaces, | 
|---|
| 1792 | 0); | 
|---|
| 1793 | } | 
|---|
| 1794 |  | 
|---|
| 1795 | lpDraw->Vtbl.Release(lpDraw); | 
|---|
| 1796 |  | 
|---|
| 1797 | } | 
|---|
| 1798 | //****************************************************************************** | 
|---|
| 1799 | //****************************************************************************** | 
|---|
| 1800 | inline  void OS2IDirectDrawSurface::SetFrontBuffer( OS2IDirectDrawSurface* NewFBuffer) | 
|---|
| 1801 | { | 
|---|
| 1802 | FrontBuffer = NewFBuffer; | 
|---|
| 1803 | if (NULL==NewFBuffer) | 
|---|
| 1804 | { | 
|---|
| 1805 |  | 
|---|
| 1806 | WriteLog("Remove Frontbuffer\n"); | 
|---|
| 1807 |  | 
|---|
| 1808 | // The real Frontbuffer was removed check if I'm now the one | 
|---|
| 1809 | if(NULL!=BackBuffer) | 
|---|
| 1810 | { | 
|---|
| 1811 | WriteLog("We have the a backbuffer so we're the Frontbuffer\n"); | 
|---|
| 1812 | NextFlip = BackBuffer; | 
|---|
| 1813 | DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER; | 
|---|
| 1814 | DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_FRONTBUFFER; | 
|---|
| 1815 | BackBuffer->SetFrontBuffer(this); | 
|---|
| 1816 | } | 
|---|
| 1817 | else | 
|---|
| 1818 | { | 
|---|
| 1819 | // Flipchain is destroyed | 
|---|
| 1820 | WriteLog("No longer part of a flipchain\n"); | 
|---|
| 1821 | DDSurfaceDesc.ddsCaps.dwCaps &= ~(DDSCAPS_BACKBUFFER | DDSCAPS_FLIP); | 
|---|
| 1822 | } | 
|---|
| 1823 | } | 
|---|
| 1824 | else | 
|---|
| 1825 | { | 
|---|
| 1826 | WriteLog("Set new Frontbuffer to 0x%08X\n",NewFBuffer); | 
|---|
| 1827 | if(NULL==NewFBuffer->GetFrontBuffer()) | 
|---|
| 1828 | { | 
|---|
| 1829 | WriteLog("We're the 1st backbuffer\n"); | 
|---|
| 1830 | DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_BACKBUFFER | DDSCAPS_FLIP; | 
|---|
| 1831 | FrontBuffer->NextFlip = this; | 
|---|
| 1832 | } | 
|---|
| 1833 | else | 
|---|
| 1834 | { | 
|---|
| 1835 | WriteLog("We are oe of many buffers\n"); | 
|---|
| 1836 | DDSurfaceDesc.ddsCaps.dwCaps &=  ~DDSCAPS_BACKBUFFER ; | 
|---|
| 1837 | DDSurfaceDesc.ddsCaps.dwCaps |=  DDSCAPS_FLIP; | 
|---|
| 1838 | } | 
|---|
| 1839 |  | 
|---|
| 1840 | if(NULL!=BackBuffer) | 
|---|
| 1841 | BackBuffer->SetFrontBuffer(this); | 
|---|
| 1842 |  | 
|---|
| 1843 | DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; | 
|---|
| 1844 | } | 
|---|
| 1845 | } | 
|---|
| 1846 | //****************************************************************************** | 
|---|
| 1847 | //****************************************************************************** | 
|---|
| 1848 | HRESULT __stdcall SurfQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj) | 
|---|
| 1849 | { | 
|---|
| 1850 | // ToDo: Add Interface handling for D3D Textures | 
|---|
| 1851 |  | 
|---|
| 1852 | #ifdef DEBUG | 
|---|
| 1853 | WriteLog("OS2IDirectDrawSurface::SurfQueryInterface\n"); | 
|---|
| 1854 | #endif | 
|---|
| 1855 |  | 
|---|
| 1856 | *ppvObj = NULL; | 
|---|
| 1857 |  | 
|---|
| 1858 | if(!IsEqualGUID(riid, IID_IDirectDrawSurface) && | 
|---|
| 1859 | !IsEqualGUID(riid, IID_IDirectDrawSurface2)) | 
|---|
| 1860 | //&& !IsEqualGUID(riid, IID_IUnknown)) | 
|---|
| 1861 | return E_NOINTERFACE; | 
|---|
| 1862 |  | 
|---|
| 1863 | *ppvObj = This; | 
|---|
| 1864 |  | 
|---|
| 1865 | SurfAddRef(This); | 
|---|
| 1866 |  | 
|---|
| 1867 | return(DD_OK); | 
|---|
| 1868 | } | 
|---|
| 1869 | //****************************************************************************** | 
|---|
| 1870 | //****************************************************************************** | 
|---|
| 1871 | ULONG __stdcall SurfAddRef(THIS This) | 
|---|
| 1872 | { | 
|---|
| 1873 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 1874 |  | 
|---|
| 1875 | #ifdef DEBUG | 
|---|
| 1876 | WriteLog("OS2IDirectDrawSurface::SurfAddRef %d\n", me->Referenced+1); | 
|---|
| 1877 | #endif | 
|---|
| 1878 |  | 
|---|
| 1879 | return ++me->Referenced; | 
|---|
| 1880 | } | 
|---|
| 1881 | //****************************************************************************** | 
|---|
| 1882 | //****************************************************************************** | 
|---|
| 1883 | ULONG __stdcall SurfRelease(THIS This) | 
|---|
| 1884 | { | 
|---|
| 1885 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 1886 |  | 
|---|
| 1887 | #ifdef DEBUG | 
|---|
| 1888 | WriteLog("OS2IDirectDrawSurface::SurfRelease %d\n", me->Referenced-1); | 
|---|
| 1889 | WriteLog("OS2IDirectDrawSurface::Surface %X\n", me); | 
|---|
| 1890 | #endif | 
|---|
| 1891 | if(me->Referenced) | 
|---|
| 1892 | { | 
|---|
| 1893 | me->Referenced--; | 
|---|
| 1894 | if(me->Referenced == 0) | 
|---|
| 1895 | { | 
|---|
| 1896 | delete( me); | 
|---|
| 1897 | #ifndef __WATCOMC__ | 
|---|
| 1898 | //_interrupt(3); | 
|---|
| 1899 | #endif | 
|---|
| 1900 | return(0); | 
|---|
| 1901 | } | 
|---|
| 1902 | else | 
|---|
| 1903 | return me->Referenced; | 
|---|
| 1904 | } | 
|---|
| 1905 | else | 
|---|
| 1906 | return(0); | 
|---|
| 1907 | } | 
|---|
| 1908 | //****************************************************************************** | 
|---|
| 1909 | //****************************************************************************** | 
|---|
| 1910 | HRESULT __stdcall SurfAddAttachedSurface(THIS This, LPDIRECTDRAWSURFACE2 lpDDSurface) | 
|---|
| 1911 | { | 
|---|
| 1912 |  | 
|---|
| 1913 | #ifdef DEBUG | 
|---|
| 1914 | WriteLog("SurfAddAttachedSurface\n"); | 
|---|
| 1915 | #endif | 
|---|
| 1916 | return SurfAddAttachedSurface4(This, (LPDIRECTDRAWSURFACE4)lpDDSurface); | 
|---|
| 1917 | } | 
|---|
| 1918 | //****************************************************************************** | 
|---|
| 1919 | //****************************************************************************** | 
|---|
| 1920 | HRESULT __stdcall SurfAddAttachedSurface4(THIS This, LPDIRECTDRAWSURFACE4 lpDDSurface) | 
|---|
| 1921 | { | 
|---|
| 1922 | OS2IDirectDrawSurface *AttachedSurface; | 
|---|
| 1923 | OS2IDirectDrawSurface *BBCursor; | 
|---|
| 1924 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 1925 | int rc; | 
|---|
| 1926 |  | 
|---|
| 1927 | #ifdef DEBUG | 
|---|
| 1928 | WriteLog("SurfAddAttachedSurface4\n"); | 
|---|
| 1929 | #endif | 
|---|
| 1930 |  | 
|---|
| 1931 | if (NULL==lpDDSurface) | 
|---|
| 1932 | return DDERR_INVALIDPARAMS; | 
|---|
| 1933 |  | 
|---|
| 1934 | AttachedSurface = (OS2IDirectDrawSurface*) lpDDSurface; | 
|---|
| 1935 |  | 
|---|
| 1936 | if(AttachedSurface->IsImplicitSurface()) | 
|---|
| 1937 | { | 
|---|
| 1938 | #ifdef DEBUG | 
|---|
| 1939 | WriteLog("Internal : Can't attach an implicit created surface to an other surface\n"); | 
|---|
| 1940 | #endif | 
|---|
| 1941 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 1942 | } | 
|---|
| 1943 |  | 
|---|
| 1944 | if(This == AttachedSurface) | 
|---|
| 1945 | { | 
|---|
| 1946 | #ifdef DEBUG | 
|---|
| 1947 | WriteLog("Can't attach an surface to itself\n"); | 
|---|
| 1948 | #endif | 
|---|
| 1949 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 1950 | } | 
|---|
| 1951 |  | 
|---|
| 1952 | if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) | 
|---|
| 1953 | { | 
|---|
| 1954 | if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) | 
|---|
| 1955 | { | 
|---|
| 1956 | if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) | 
|---|
| 1957 | { | 
|---|
| 1958 | rc = DPA_InsertPtr( me->DPA_SurfaceMipMaps, | 
|---|
| 1959 | DPA_GetPtrCount(me->DPA_SurfaceMipMaps), | 
|---|
| 1960 | AttachedSurface); | 
|---|
| 1961 |  | 
|---|
| 1962 | if( rc>=0) | 
|---|
| 1963 | { | 
|---|
| 1964 | me->DDSurfaceDesc.dwFlags |= DDSD_MIPMAPCOUNT; | 
|---|
| 1965 | me->DDSurfaceDesc.dwMipMapCount++; | 
|---|
| 1966 |  | 
|---|
| 1967 | AttachedSurface->Vtbl.AddRef(AttachedSurface); | 
|---|
| 1968 | } | 
|---|
| 1969 | else | 
|---|
| 1970 | { | 
|---|
| 1971 | #ifdef DEBUG | 
|---|
| 1972 | WriteLog("Internal : Error attaching to MipMap\n"); | 
|---|
| 1973 | #endif | 
|---|
| 1974 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 1975 | } | 
|---|
| 1976 | } | 
|---|
| 1977 | else | 
|---|
| 1978 | { | 
|---|
| 1979 | #ifdef DEBUG | 
|---|
| 1980 | WriteLog("Target Surface isn't a MipMap\n"); | 
|---|
| 1981 | #endif | 
|---|
| 1982 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 1983 | } | 
|---|
| 1984 | } | 
|---|
| 1985 | else | 
|---|
| 1986 | { | 
|---|
| 1987 | rc = DPA_InsertPtr( me->DPA_SurfaceAttached, | 
|---|
| 1988 | DPA_GetPtrCount(me->DPA_SurfaceAttached), | 
|---|
| 1989 | AttachedSurface); | 
|---|
| 1990 |  | 
|---|
| 1991 | if(rc>=0) | 
|---|
| 1992 | { | 
|---|
| 1993 | AttachedSurface->Vtbl.AddRef(AttachedSurface); | 
|---|
| 1994 | } | 
|---|
| 1995 | else | 
|---|
| 1996 | { | 
|---|
| 1997 | #ifdef DEBUG | 
|---|
| 1998 | WriteLog("Internal : Error attaching to general Set\n"); | 
|---|
| 1999 | #endif | 
|---|
| 2000 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2001 | } | 
|---|
| 2002 | } | 
|---|
| 2003 | } // endif DDSCAPS_TEXTURE | 
|---|
| 2004 | else | 
|---|
| 2005 | { | 
|---|
| 2006 | if( (AttachedSurface->DDSurfaceDesc.dwWidth != me->DDSurfaceDesc.dwWidth) | 
|---|
| 2007 | || (AttachedSurface->DDSurfaceDesc.dwHeight != me->DDSurfaceDesc.dwHeight) | 
|---|
| 2008 | //    || (AttachedSurface->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount != | 
|---|
| 2009 | //        me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 2010 | ) | 
|---|
| 2011 | { | 
|---|
| 2012 | #ifdef DEBUG | 
|---|
| 2013 | WriteLog("Surfaces don't have same dimensions\n"); | 
|---|
| 2014 | #endif | 
|---|
| 2015 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2016 | } | 
|---|
| 2017 | else | 
|---|
| 2018 | { | 
|---|
| 2019 | if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER) | 
|---|
| 2020 | { | 
|---|
| 2021 | if( (AttachedSurface->GetFrontBuffer()!=NULL) || (AttachedSurface->BackBuffer!= NULL)) | 
|---|
| 2022 | { | 
|---|
| 2023 | #ifdef DEBUG | 
|---|
| 2024 | WriteLog("Surfaces already has a front/backbuffer\n"); | 
|---|
| 2025 | #endif | 
|---|
| 2026 | return(DDERR_SURFACEALREADYATTACHED); | 
|---|
| 2027 | } | 
|---|
| 2028 |  | 
|---|
| 2029 | if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) | 
|---|
| 2030 | { | 
|---|
| 2031 | if(NULL!=me->BackBuffer) | 
|---|
| 2032 | { | 
|---|
| 2033 | BBCursor = me->BackBuffer; | 
|---|
| 2034 | while(NULL!=BBCursor) | 
|---|
| 2035 | { | 
|---|
| 2036 | BBCursor->DDSurfaceDesc.dwFlags |= DDSD_BACKBUFFERCOUNT; | 
|---|
| 2037 | BBCursor->DDSurfaceDesc.dwBackBufferCount++; | 
|---|
| 2038 | BBCursor->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP; | 
|---|
| 2039 | BBCursor = BBCursor->BackBuffer; | 
|---|
| 2040 | } | 
|---|
| 2041 | BBCursor->BackBuffer = AttachedSurface; | 
|---|
| 2042 | AttachedSurface->SetFrontBuffer(BBCursor); | 
|---|
| 2043 | } | 
|---|
| 2044 | else | 
|---|
| 2045 | { | 
|---|
| 2046 | me->BackBuffer = AttachedSurface; | 
|---|
| 2047 | AttachedSurface->SetFrontBuffer(me); | 
|---|
| 2048 | } | 
|---|
| 2049 | me->DDSurfaceDesc.dwFlags |= DDSD_BACKBUFFERCOUNT; | 
|---|
| 2050 | me->DDSurfaceDesc.dwBackBufferCount++; | 
|---|
| 2051 | me->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP; | 
|---|
| 2052 |  | 
|---|
| 2053 | AttachedSurface->Vtbl.AddRef(AttachedSurface); | 
|---|
| 2054 | return (DD_OK); | 
|---|
| 2055 | } | 
|---|
| 2056 | else | 
|---|
| 2057 | { | 
|---|
| 2058 | #ifdef DEBUG | 
|---|
| 2059 | WriteLog("Can't attach backbuffer to anything but a frontbuffer\n"); | 
|---|
| 2060 | #endif | 
|---|
| 2061 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2062 | } | 
|---|
| 2063 | } | 
|---|
| 2064 | else | 
|---|
| 2065 | { | 
|---|
| 2066 | if(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) | 
|---|
| 2067 | { | 
|---|
| 2068 | if(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) | 
|---|
| 2069 | { | 
|---|
| 2070 | if( DPA_InsertPtr( me->DPA_SurfaceMipMaps, | 
|---|
| 2071 | DPA_GetPtrCount(me->DPA_SurfaceMipMaps), | 
|---|
| 2072 | AttachedSurface) >=0) | 
|---|
| 2073 | { | 
|---|
| 2074 | me->DDSurfaceDesc.dwFlags |= DDSD_MIPMAPCOUNT; | 
|---|
| 2075 | me->DDSurfaceDesc.dwMipMapCount++; | 
|---|
| 2076 | me->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER; | 
|---|
| 2077 |  | 
|---|
| 2078 | AttachedSurface->Vtbl.AddRef(AttachedSurface); | 
|---|
| 2079 | } | 
|---|
| 2080 | else | 
|---|
| 2081 | { | 
|---|
| 2082 | #ifdef DEBUG | 
|---|
| 2083 | WriteLog("Internal : Error attaching to MipMap\n"); | 
|---|
| 2084 | #endif | 
|---|
| 2085 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2086 | } | 
|---|
| 2087 | } | 
|---|
| 2088 | else | 
|---|
| 2089 | { | 
|---|
| 2090 | #ifdef DEBUG | 
|---|
| 2091 | WriteLog("Tagget Surface isn't a MipMap\n"); | 
|---|
| 2092 | #endif | 
|---|
| 2093 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2094 | } | 
|---|
| 2095 | } | 
|---|
| 2096 | else | 
|---|
| 2097 | { | 
|---|
| 2098 | if( DPA_InsertPtr( me->DPA_SurfaceAttached, | 
|---|
| 2099 | DPA_GetPtrCount(me->DPA_SurfaceAttached), | 
|---|
| 2100 | AttachedSurface) >=0) | 
|---|
| 2101 | { | 
|---|
| 2102 | AttachedSurface->Vtbl.AddRef(AttachedSurface); | 
|---|
| 2103 | } | 
|---|
| 2104 | else | 
|---|
| 2105 | { | 
|---|
| 2106 | #ifdef DEBUG | 
|---|
| 2107 | WriteLog("Internal : Error attaching to general Set\n"); | 
|---|
| 2108 | #endif | 
|---|
| 2109 | return(DDERR_CANNOTATTACHSURFACE); | 
|---|
| 2110 | } | 
|---|
| 2111 | } | 
|---|
| 2112 | }// End if not DDSCAPS_BACKBUFFER | 
|---|
| 2113 | } | 
|---|
| 2114 | } | 
|---|
| 2115 | WriteLog("Surface attached\n"); | 
|---|
| 2116 | return(DD_OK); | 
|---|
| 2117 | } | 
|---|
| 2118 | //****************************************************************************** | 
|---|
| 2119 | //****************************************************************************** | 
|---|
| 2120 | HRESULT __stdcall SurfAddOverlayDirtyRect(THIS, LPRECT) | 
|---|
| 2121 | { | 
|---|
| 2122 | #ifdef DEBUG | 
|---|
| 2123 | WriteLog("SurfAddOverlayDirtyRect Not implemented by M$ in V 6.0! \n"); | 
|---|
| 2124 | #endif | 
|---|
| 2125 |  | 
|---|
| 2126 | return(DD_OK); | 
|---|
| 2127 | } | 
|---|
| 2128 | //****************************************************************************** | 
|---|
| 2129 | //****************************************************************************** | 
|---|
| 2130 | HRESULT __stdcall SurfBlt(THIS This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE2 lpDDSrcSurface, | 
|---|
| 2131 | LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx) | 
|---|
| 2132 | { | 
|---|
| 2133 | return SurfBlt4( This, | 
|---|
| 2134 | lpDestRect, | 
|---|
| 2135 | (LPDIRECTDRAWSURFACE4)lpDDSrcSurface, | 
|---|
| 2136 | lpSrcRect, | 
|---|
| 2137 | dwFlags, | 
|---|
| 2138 | lpDDBltFx); | 
|---|
| 2139 | } | 
|---|
| 2140 | //****************************************************************************** | 
|---|
| 2141 | //****************************************************************************** | 
|---|
| 2142 | HRESULT __stdcall SurfBlt4(THIS This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE4 lpDDSrcSurface, | 
|---|
| 2143 | LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx) | 
|---|
| 2144 | { | 
|---|
| 2145 | // We have determine between 3 different blit senarios. | 
|---|
| 2146 | // 1. Blitting between Divebuffers (Front/Backbuffer and primary surface) | 
|---|
| 2147 | // 2. Blitting between memory and Divebuffers (Front/Backbuffer and primary surface). | 
|---|
| 2148 | // 3. Blitting between memory buffers. | 
|---|
| 2149 | // 1 and 3 are easy. DiveBlitImage or memcpy will do the job for non transparent blits | 
|---|
| 2150 | // 2 is now also easy as we do colorconverion via Dive after each unlocking of a surface | 
|---|
| 2151 | // The advantage is that we don't have to call DiveSetupBlitter each time. The Blitter will be | 
|---|
| 2152 | // setup only when the screen resolution is changed by ddraw. I guess we should see a big performance | 
|---|
| 2153 | // increase by doing it this way, unless the software blits directly from memory to the primary surface) | 
|---|
| 2154 | // But even then this could be faster as the SetupBlitter call is timeconsumeing and DIVE does emulate | 
|---|
| 2155 | // the blit in SW anyway as there is no interface in the driver to blit with HW support from the sysmem. | 
|---|
| 2156 |  | 
|---|
| 2157 | OS2IDirectDrawSurface *dest = (OS2IDirectDrawSurface *)This; | 
|---|
| 2158 | OS2IDirectDrawSurface *src  = (OS2IDirectDrawSurface *)lpDDSrcSurface; | 
|---|
| 2159 |  | 
|---|
| 2160 | HRESULT                rc; | 
|---|
| 2161 | ULONG                  ulColor, *pColor; | 
|---|
| 2162 | RECTL                  cliprect; | 
|---|
| 2163 |  | 
|---|
| 2164 | int                    x, y, i, j, BlitWidth, BlitHeight; | 
|---|
| 2165 | PALETTEENTRY           SysPal[257]; | 
|---|
| 2166 | PLOGPALETTE            pLogPal = (PLOGPALETTE) SysPal; | 
|---|
| 2167 | char                   *pBltPos, *pSrcPos; | 
|---|
| 2168 | DDSURFACEDESC2         DestSurfaceDesc, SrcSurfaceDesc; | 
|---|
| 2169 | DDRectangle             *pIRectDest,*pIRectSrc,*pIRectTest; | 
|---|
| 2170 | RECTL                  DestRect, SrcRect; | 
|---|
| 2171 | BOOL Found; | 
|---|
| 2172 | DWORD dwSrcColor, dwDestColor; | 
|---|
| 2173 |  | 
|---|
| 2174 | #ifdef DEBUG | 
|---|
| 2175 | if ( (NULL!=lpDestRect)&& (NULL!=lpSrcRect)) | 
|---|
| 2176 | WriteLog("SurfBlt4 to (%d,%d)(%d,%d) at %08X from (%d,%d)(%d,%d) at %08X\n", lpDestRect->left, lpDestRect->top, | 
|---|
| 2177 | lpDestRect->right, lpDestRect->bottom, dest, lpSrcRect->left, lpSrcRect->top, | 
|---|
| 2178 | lpSrcRect->right, lpSrcRect->bottom, src); | 
|---|
| 2179 |  | 
|---|
| 2180 | _dump_DDBLT(dwFlags); | 
|---|
| 2181 | #endif | 
|---|
| 2182 |  | 
|---|
| 2183 |  | 
|---|
| 2184 | if (NULL!=lpDestRect) | 
|---|
| 2185 | { | 
|---|
| 2186 | pIRectDest = new DDRectangle( lpDestRect->top, | 
|---|
| 2187 | lpDestRect->left, | 
|---|
| 2188 | lpDestRect->bottom, | 
|---|
| 2189 | lpDestRect->right); | 
|---|
| 2190 | memcpy(&DestRect,lpDestRect,sizeof(RECTL) ); | 
|---|
| 2191 | } | 
|---|
| 2192 | else | 
|---|
| 2193 | { | 
|---|
| 2194 | pIRectDest = new DDRectangle( 0, 0, dest->height, dest->width); | 
|---|
| 2195 | DestRect.top    = 0; | 
|---|
| 2196 | DestRect.left   = 0; | 
|---|
| 2197 | DestRect.bottom = dest->height; | 
|---|
| 2198 | DestRect.right  = dest->width; | 
|---|
| 2199 | } | 
|---|
| 2200 |  | 
|---|
| 2201 | if(dest->fLocked) | 
|---|
| 2202 | { | 
|---|
| 2203 | if (NULL==lpDestRect) | 
|---|
| 2204 | { | 
|---|
| 2205 | // If anything is locked we can't blit to the complete surface as | 
|---|
| 2206 | // a part is locked | 
|---|
| 2207 | Found = TRUE; | 
|---|
| 2208 | } | 
|---|
| 2209 | else | 
|---|
| 2210 | { | 
|---|
| 2211 | // If the dest Rectangle intersects with any of the locked rectangles | 
|---|
| 2212 | // we can't blit to it | 
|---|
| 2213 |  | 
|---|
| 2214 | Found = FALSE; | 
|---|
| 2215 | i=0; | 
|---|
| 2216 | while( (i<DPA_GetPtrCount(dest->DPA_LockedRects))  && !Found) | 
|---|
| 2217 | { | 
|---|
| 2218 | pIRectTest = (DDRectangle*) DPA_FastGetPtr(dest->DPA_LockedRects,i); | 
|---|
| 2219 | Found = pIRectDest->intersects(*pIRectTest); | 
|---|
| 2220 | i++; | 
|---|
| 2221 | } | 
|---|
| 2222 |  | 
|---|
| 2223 | } | 
|---|
| 2224 |  | 
|---|
| 2225 | if (Found) | 
|---|
| 2226 | { | 
|---|
| 2227 | delete pIRectDest; | 
|---|
| 2228 | #ifdef DEBUG | 
|---|
| 2229 | WriteLog("Blt: Dest Surface partly locked\n"); | 
|---|
| 2230 | #endif | 
|---|
| 2231 | return(DDERR_SURFACEBUSY); | 
|---|
| 2232 | } | 
|---|
| 2233 | } | 
|---|
| 2234 |  | 
|---|
| 2235 | DestSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2); | 
|---|
| 2236 | SrcSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2); | 
|---|
| 2237 |  | 
|---|
| 2238 | // First check the simple first | 
|---|
| 2239 |  | 
|---|
| 2240 | dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC); // FIXME: can't handle right now | 
|---|
| 2241 |  | 
|---|
| 2242 | if(dwFlags & DDBLT_COLORFILL) | 
|---|
| 2243 | { | 
|---|
| 2244 | WriteLog("ColorFill\n"); | 
|---|
| 2245 | if((NULL==lpDDBltFx)||(lpDDBltFx->dwSize!=sizeof(DDBLTFX)) ) | 
|---|
| 2246 | return DDERR_INVALIDPARAMS; | 
|---|
| 2247 |  | 
|---|
| 2248 | // ToDo : as we fill the DiveBuffer check if we need to convert the | 
|---|
| 2249 | // specified color | 
|---|
| 2250 |  | 
|---|
| 2251 | dest->ColorFill(lpDestRect,lpDDBltFx->dwFillColor); | 
|---|
| 2252 |  | 
|---|
| 2253 | return(DD_OK); // according to the M$ DDK only one flag shall/can be set. | 
|---|
| 2254 | } // end of colorfill | 
|---|
| 2255 |  | 
|---|
| 2256 | if (dwFlags & DDBLT_DEPTHFILL) | 
|---|
| 2257 | { | 
|---|
| 2258 | WriteLog("DepthFill\n"); | 
|---|
| 2259 | #ifdef USE_OPENGL | 
|---|
| 2260 | GLboolean ztest; | 
|---|
| 2261 | // Todo support more than one Z-Buffer | 
|---|
| 2262 | // Clears the screen | 
|---|
| 2263 | WriteLog("Filling depth buffer with %ld\n", lpbltfx->b.dwFillDepth); | 
|---|
| 2264 | glClearDepth(lpDDBltFx->b.dwFillDepth / 65535.0); // We suppose a 16 bit Z Buffer | 
|---|
| 2265 | glGetBooleanv(GL_DEPTH_TEST, &ztest); | 
|---|
| 2266 | glDepthMask(GL_TRUE); // Enables Z writing to be sure to delete also the Z buffer | 
|---|
| 2267 | glClear(GL_DEPTH_BUFFER_BIT); | 
|---|
| 2268 | glDepthMask(ztest); | 
|---|
| 2269 |  | 
|---|
| 2270 | return (DD_OK); | 
|---|
| 2271 | #endif // USE_OPENGL | 
|---|
| 2272 | } | 
|---|
| 2273 |  | 
|---|
| 2274 | if(dwFlags & DDBLT_ROP) | 
|---|
| 2275 | { | 
|---|
| 2276 | // HEL and we only support the following ROPS | 
|---|
| 2277 | // SRC_COPY | 
|---|
| 2278 | // BLACKNESS | 
|---|
| 2279 | // WHITENESS | 
|---|
| 2280 | // | 
|---|
| 2281 | if(lpDDBltFx->dwROP & SRCCOPY) | 
|---|
| 2282 | dwFlags = 0;  // srccopy is a normal fast blt | 
|---|
| 2283 | else | 
|---|
| 2284 | { | 
|---|
| 2285 | if(lpDDBltFx->dwROP & BLACKNESS) | 
|---|
| 2286 | { | 
|---|
| 2287 | if(1==dest->dwBytesPPDive) | 
|---|
| 2288 | { | 
|---|
| 2289 | // ToDo: Realy implement code to get the correct index for black in 8 Bitmode | 
|---|
| 2290 | dest->ColorFill(lpDestRect, 0 ); | 
|---|
| 2291 | } | 
|---|
| 2292 | else | 
|---|
| 2293 | dest->ColorFill(lpDestRect, 0); | 
|---|
| 2294 | return DD_OK; | 
|---|
| 2295 | } | 
|---|
| 2296 |  | 
|---|
| 2297 | if(lpDDBltFx->dwROP & WHITENESS) | 
|---|
| 2298 | { | 
|---|
| 2299 | if(1==dest->dwBytesPPDive) | 
|---|
| 2300 | { | 
|---|
| 2301 | // ToDo: Realy implement code to get the correct index for black in 8 Bitmode | 
|---|
| 2302 | dest->ColorFill(lpDestRect, 0xFFFFFFFF ); | 
|---|
| 2303 | } | 
|---|
| 2304 | else | 
|---|
| 2305 | dest->ColorFill(lpDestRect, 0xFFFFFFFF); | 
|---|
| 2306 | return DD_OK; | 
|---|
| 2307 | } | 
|---|
| 2308 |  | 
|---|
| 2309 | return DDERR_NORASTEROPHW; | 
|---|
| 2310 | } | 
|---|
| 2311 | } | 
|---|
| 2312 |  | 
|---|
| 2313 | if(NULL==src) | 
|---|
| 2314 | { | 
|---|
| 2315 | #ifdef DEBUG | 
|---|
| 2316 | WriteLog("Unsupported sourceless FX operation. Flags = 0x%04X\n",dwFlags); | 
|---|
| 2317 | #endif | 
|---|
| 2318 | return DD_OK; | 
|---|
| 2319 | } | 
|---|
| 2320 |  | 
|---|
| 2321 | if (NULL!=lpSrcRect) | 
|---|
| 2322 | { | 
|---|
| 2323 | pIRectSrc = new DDRectangle( lpSrcRect->top, | 
|---|
| 2324 | lpSrcRect->left, | 
|---|
| 2325 | lpSrcRect->bottom, | 
|---|
| 2326 | lpSrcRect->right); | 
|---|
| 2327 | memcpy(&SrcRect,lpSrcRect,sizeof(RECTL) ); | 
|---|
| 2328 | } | 
|---|
| 2329 | else | 
|---|
| 2330 | { | 
|---|
| 2331 | pIRectSrc = new DDRectangle( 0, 0, src->height, src->width); | 
|---|
| 2332 | SrcRect.top    = 0; | 
|---|
| 2333 | SrcRect.left   = 0; | 
|---|
| 2334 | SrcRect.bottom = src->height; | 
|---|
| 2335 | SrcRect.right  = src->width; | 
|---|
| 2336 | } | 
|---|
| 2337 |  | 
|---|
| 2338 | if(src->fLocked) | 
|---|
| 2339 | { | 
|---|
| 2340 | if (NULL==lpSrcRect) | 
|---|
| 2341 | { | 
|---|
| 2342 | // If anything is locked we can't blit from the complete surface as | 
|---|
| 2343 | // a part is locked | 
|---|
| 2344 | Found = TRUE; | 
|---|
| 2345 | } | 
|---|
| 2346 | else | 
|---|
| 2347 | { | 
|---|
| 2348 | // If the src Rectangle intersects with any of the locked rectangles of the | 
|---|
| 2349 | // source surface we can't blit from it | 
|---|
| 2350 |  | 
|---|
| 2351 | Found = FALSE; | 
|---|
| 2352 | i=0; | 
|---|
| 2353 |  | 
|---|
| 2354 | while((i<DPA_GetPtrCount(src->DPA_LockedRects) ) && !Found) | 
|---|
| 2355 | { | 
|---|
| 2356 | pIRectTest = (DDRectangle*) DPA_FastGetPtr(src->DPA_LockedRects,i); | 
|---|
| 2357 | Found = pIRectDest->intersects(*pIRectTest); | 
|---|
| 2358 | i++; | 
|---|
| 2359 | } | 
|---|
| 2360 |  | 
|---|
| 2361 | } | 
|---|
| 2362 |  | 
|---|
| 2363 | if (Found) | 
|---|
| 2364 | { | 
|---|
| 2365 | delete pIRectSrc; | 
|---|
| 2366 | #ifdef DEBUG | 
|---|
| 2367 | WriteLog("Blt: Src Surface partly locked\n"); | 
|---|
| 2368 | #endif | 
|---|
| 2369 | return(DDERR_SURFACEBUSY); | 
|---|
| 2370 | } | 
|---|
| 2371 | } | 
|---|
| 2372 |  | 
|---|
| 2373 | if( ( (NULL==lpDestRect) && (NULL!=lpSrcRect) ) || | 
|---|
| 2374 | ( (NULL==lpSrcRect) && (NULL!=lpDestRect) ) ) | 
|---|
| 2375 | { | 
|---|
| 2376 | #ifdef DEBUG | 
|---|
| 2377 | WriteLog("Blitting with scaleing\n Not supported.\n"); | 
|---|
| 2378 | #endif | 
|---|
| 2379 | return DDERR_NOSTRETCHHW; | 
|---|
| 2380 | } | 
|---|
| 2381 |  | 
|---|
| 2382 | if( ( pIRectDest->width()  != pIRectSrc->width() ) || | 
|---|
| 2383 | ( pIRectDest->height() != pIRectSrc->height() ) | 
|---|
| 2384 | ) | 
|---|
| 2385 | { | 
|---|
| 2386 | // Stretching not supported | 
|---|
| 2387 | WriteLog("No stretched blits\n"); | 
|---|
| 2388 |  | 
|---|
| 2389 | return DDERR_NOSTRETCHHW; | 
|---|
| 2390 | } | 
|---|
| 2391 |  | 
|---|
| 2392 | if (dest->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 2393 | { | 
|---|
| 2394 | WriteLog("Dest is Primary Surface\n"); | 
|---|
| 2395 | if(src->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 2396 | { | 
|---|
| 2397 | // special Type 1 : Bliting between parts of the screen | 
|---|
| 2398 |  | 
|---|
| 2399 | WriteLog("Src is Primary Surface\n"); | 
|---|
| 2400 |  | 
|---|
| 2401 | if( *pIRectDest == *pIRectSrc) | 
|---|
| 2402 | return DD_OK; // rects are the same => no blit needed | 
|---|
| 2403 |  | 
|---|
| 2404 | // Todo: might add transparent blits but I don't think they are used here, so later! | 
|---|
| 2405 |  | 
|---|
| 2406 | MoveRects( dest->pDiveBuffer, | 
|---|
| 2407 | (LPRECT)&DestRect, | 
|---|
| 2408 | (LPRECT)&SrcRect, | 
|---|
| 2409 | dest->dwBytesPPDive, | 
|---|
| 2410 | dest->dwPitchDB); | 
|---|
| 2411 |  | 
|---|
| 2412 | // End of Special Type 1 blitting on the screen | 
|---|
| 2413 | } | 
|---|
| 2414 | else | 
|---|
| 2415 | { | 
|---|
| 2416 | if( src->diveBufNr>0) | 
|---|
| 2417 | { | 
|---|
| 2418 |  | 
|---|
| 2419 | if( (NULL==lpSrcRect)&&( NULL== lpDestRect)) | 
|---|
| 2420 | { | 
|---|
| 2421 | // No Rectangles so use Dive to blit everything | 
|---|
| 2422 | // ToDo : Implement transparent blitting but that seams more | 
|---|
| 2423 | //        inportant for partial blits. | 
|---|
| 2424 | //        If we do this later we could skip this check and don't | 
|---|
| 2425 | //        use Dive .This keeps our simpler and smaler | 
|---|
| 2426 | // | 
|---|
| 2427 | DiveBlitImage(dest->hDive, src->diveBufNr, dest->diveBufNr); | 
|---|
| 2428 |  | 
|---|
| 2429 | } | 
|---|
| 2430 | } | 
|---|
| 2431 |  | 
|---|
| 2432 | // Everything else we do yourselfs | 
|---|
| 2433 | // Type 2 Sysmem to Primarysurface ca also be handled by this | 
|---|
| 2434 |  | 
|---|
| 2435 | pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) + | 
|---|
| 2436 | (DestRect.left * dest->dwBytesPPDive); | 
|---|
| 2437 |  | 
|---|
| 2438 | pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) + | 
|---|
| 2439 | (SrcRect.left * src->dwBytesPPDive); | 
|---|
| 2440 |  | 
|---|
| 2441 | BlitHeight = pIRectDest->height(); | 
|---|
| 2442 | BlitWidth = pIRectDest->width(); | 
|---|
| 2443 |  | 
|---|
| 2444 | if(!dwFlags) | 
|---|
| 2445 | { | 
|---|
| 2446 | BlitWidth *= dest->dwBytesPPDive; | 
|---|
| 2447 |  | 
|---|
| 2448 | #ifdef USE_ASM | 
|---|
| 2449 | BltRec(pBltPos, pSrcPos, BlitWidth, BlitHeight, | 
|---|
| 2450 | dest->dwPitchDB, | 
|---|
| 2451 | src->dwPitchDB); | 
|---|
| 2452 | #else | 
|---|
| 2453 | // Solid Blit | 
|---|
| 2454 | while(1) | 
|---|
| 2455 | { | 
|---|
| 2456 | memcpy(pBltPos,pSrcPos,BlitWidth); | 
|---|
| 2457 | pBltPos += dest->dwPitchDB; | 
|---|
| 2458 | pSrcPos += src->dwPitchDB; | 
|---|
| 2459 | if(! (--BlitHeight)) | 
|---|
| 2460 | break; | 
|---|
| 2461 | } | 
|---|
| 2462 | #endif | 
|---|
| 2463 | } | 
|---|
| 2464 | else | 
|---|
| 2465 | { | 
|---|
| 2466 | // Transparent Blit | 
|---|
| 2467 | if( (dwFlags &DDBLT_KEYSRC) || (dwFlags & DDBLT_KEYSRCOVERRIDE) ) | 
|---|
| 2468 | { | 
|---|
| 2469 | WriteLog("Transparent src blit not done yet for primary!!"); | 
|---|
| 2470 | } | 
|---|
| 2471 | else | 
|---|
| 2472 | { | 
|---|
| 2473 | WriteLog("Unhandled Flags Destination colorkey ? 0x%04X",dwFlags); | 
|---|
| 2474 | } | 
|---|
| 2475 | } | 
|---|
| 2476 | } // end of handling blitting to primary | 
|---|
| 2477 | }  // end of target primary surface | 
|---|
| 2478 | else | 
|---|
| 2479 | { | 
|---|
| 2480 | if(0==src->diveBufNr) | 
|---|
| 2481 | { | 
|---|
| 2482 | // copy from the screen to a buffer | 
|---|
| 2483 |  | 
|---|
| 2484 | if( (NULL==lpDestRect) && | 
|---|
| 2485 | (NULL==lpSrcRect) && | 
|---|
| 2486 | (dest->diveBufNr>0) ) | 
|---|
| 2487 | { | 
|---|
| 2488 | // Blitting everything from frontbuffer to a Divebuffer | 
|---|
| 2489 | // ToDo: Might should add checking for flags here | 
|---|
| 2490 | DiveBlitImage(dest->hDive, src->diveBufNr, dest->diveBufNr); | 
|---|
| 2491 | } | 
|---|
| 2492 | else | 
|---|
| 2493 | { | 
|---|
| 2494 | // DIVE => DIVE  or Mem => Dive | 
|---|
| 2495 | // or a rectangle from streen to a buffer can be handelt in the same way | 
|---|
| 2496 | pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) + | 
|---|
| 2497 | (DestRect.left * dest->dwBytesPPDive); | 
|---|
| 2498 |  | 
|---|
| 2499 | pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) + | 
|---|
| 2500 | (SrcRect.left * src->dwBytesPPDive); | 
|---|
| 2501 |  | 
|---|
| 2502 | BlitHeight = pIRectDest->height(); | 
|---|
| 2503 | BlitWidth = pIRectDest->width(); | 
|---|
| 2504 |  | 
|---|
| 2505 | // Check for transparent blit | 
|---|
| 2506 | if(!dwFlags) | 
|---|
| 2507 | { | 
|---|
| 2508 | BlitWidth *= dest->dwBytesPPDive; | 
|---|
| 2509 |  | 
|---|
| 2510 | #ifdef USE_ASM | 
|---|
| 2511 | BltRec(pBltPos, pSrcPos, BlitWidth, BlitHeight, | 
|---|
| 2512 | dest->dwPitchDB, | 
|---|
| 2513 | src->dwPitchDB); | 
|---|
| 2514 | #else | 
|---|
| 2515 | // Solid Blit | 
|---|
| 2516 | while(1) | 
|---|
| 2517 | { | 
|---|
| 2518 | memcpy(pBltPos,pSrcPos,BlitWidth); | 
|---|
| 2519 | pBltPos += dest->dwPitchDB; | 
|---|
| 2520 | pSrcPos += src->dwPitchDB; | 
|---|
| 2521 | if(! (--BlitHeight)) | 
|---|
| 2522 | break; | 
|---|
| 2523 | } | 
|---|
| 2524 | #endif | 
|---|
| 2525 | } | 
|---|
| 2526 | else | 
|---|
| 2527 | { | 
|---|
| 2528 | WriteLog("Transblt not done yet"); | 
|---|
| 2529 | if(dwFlags & DDBLT_KEYSRC) | 
|---|
| 2530 | { | 
|---|
| 2531 | if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_SRCBLT)) | 
|---|
| 2532 | { | 
|---|
| 2533 | } | 
|---|
| 2534 | } | 
|---|
| 2535 | else | 
|---|
| 2536 | { | 
|---|
| 2537 | if(dwFlags & DDBLT_KEYSRCOVERRIDE) | 
|---|
| 2538 | { | 
|---|
| 2539 | } | 
|---|
| 2540 | else | 
|---|
| 2541 | { | 
|---|
| 2542 | } | 
|---|
| 2543 | } | 
|---|
| 2544 | } | 
|---|
| 2545 | } | 
|---|
| 2546 | } // end handling source screen | 
|---|
| 2547 | else | 
|---|
| 2548 | { | 
|---|
| 2549 | // DIVE => DIVE  or Mem => Dive can be handelt in the same way | 
|---|
| 2550 |  | 
|---|
| 2551 | if( (src->pDiveBuffer == dest->pDiveBuffer) && | 
|---|
| 2552 | (pIRectDest->intersects(*pIRectSrc) ) ) | 
|---|
| 2553 | { | 
|---|
| 2554 | // Overlapping rects  on the same surface ? | 
|---|
| 2555 |  | 
|---|
| 2556 | // ToDo : Maybe implement all the fancy blit flags here too ? ;) | 
|---|
| 2557 |  | 
|---|
| 2558 | MoveRects( dest->pDiveBuffer, | 
|---|
| 2559 | (LPRECT)&DestRect, | 
|---|
| 2560 | (LPRECT)&SrcRect, | 
|---|
| 2561 | dest->dwBytesPPDive, | 
|---|
| 2562 | dest->dwPitchDB); | 
|---|
| 2563 |  | 
|---|
| 2564 | return DD_OK; | 
|---|
| 2565 | } | 
|---|
| 2566 |  | 
|---|
| 2567 | pBltPos = (char*) dest->pDiveBuffer + (DestRect.top * dest->dwPitchDB) + | 
|---|
| 2568 | (DestRect.left * dest->dwBytesPPDive); | 
|---|
| 2569 |  | 
|---|
| 2570 | pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) + | 
|---|
| 2571 | (SrcRect.left * src->dwBytesPPDive); | 
|---|
| 2572 |  | 
|---|
| 2573 | BlitHeight = pIRectDest->height(); | 
|---|
| 2574 | BlitWidth = pIRectDest->width(); | 
|---|
| 2575 |  | 
|---|
| 2576 | // Check for transparent blit | 
|---|
| 2577 | if(!dwFlags) | 
|---|
| 2578 | { | 
|---|
| 2579 | BlitWidth *= dest->dwBytesPPDive; | 
|---|
| 2580 |  | 
|---|
| 2581 | #ifdef USE_ASM | 
|---|
| 2582 | BltRec(pBltPos, pSrcPos, BlitWidth, BlitHeight, | 
|---|
| 2583 | dest->dwPitchDB, | 
|---|
| 2584 | src->dwPitchDB); | 
|---|
| 2585 | #else | 
|---|
| 2586 | // Solid Blit | 
|---|
| 2587 | while(1) | 
|---|
| 2588 | { | 
|---|
| 2589 | memcpy(pBltPos,pSrcPos,BlitWidth); | 
|---|
| 2590 | pBltPos += dest->dwPitchDB; | 
|---|
| 2591 | pSrcPos += src->dwPitchDB; | 
|---|
| 2592 | if(! (--BlitHeight)) | 
|---|
| 2593 | break; | 
|---|
| 2594 | } | 
|---|
| 2595 | #endif | 
|---|
| 2596 | } | 
|---|
| 2597 | else | 
|---|
| 2598 | { | 
|---|
| 2599 | DWORD dwPitch = dest->dwPitchDB; | 
|---|
| 2600 |  | 
|---|
| 2601 | if(dwFlags &DDBLT_ROTATIONANGLE) | 
|---|
| 2602 | { | 
|---|
| 2603 | return DDERR_NOROTATIONHW; | 
|---|
| 2604 | } | 
|---|
| 2605 |  | 
|---|
| 2606 | if(dwFlags & DDBLT_DDFX) | 
|---|
| 2607 | { | 
|---|
| 2608 | DWORD dwFx; | 
|---|
| 2609 | DWORD dwSrcColor, dwDestColor; | 
|---|
| 2610 |  | 
|---|
| 2611 | dwFlags &= ~DDBLT_DDFX; // remove the handled flag | 
|---|
| 2612 |  | 
|---|
| 2613 | if( NULL==lpDDBltFx) | 
|---|
| 2614 | return DDERR_INVALIDPARAMS; | 
|---|
| 2615 |  | 
|---|
| 2616 | dwFx = lpDDBltFx->dwDDFX; | 
|---|
| 2617 |  | 
|---|
| 2618 | // Remove unsupported Flags | 
|---|
| 2619 | dwFx &= ~(DDBLTFX_ARITHSTRETCHY |    // Not streach support | 
|---|
| 2620 | DDBLTFX_ZBUFFERBASEDEST |  // All ZBuffer flags are not | 
|---|
| 2621 | DDBLTFX_ZBUFFERRANGE |     // implementet in M$ Dx 6 | 
|---|
| 2622 | DDBLTFX_NOTEARING );       // No sync with VRetrace yet | 
|---|
| 2623 |  | 
|---|
| 2624 | if(dwFx & DDBLTFX_ROTATE180) | 
|---|
| 2625 | { | 
|---|
| 2626 | // 180 degree turn is a mix of a flip up/down and one left/right | 
|---|
| 2627 | dwFx |= (DDBLTFX_MIRRORUPDOWN | DDBLTFX_MIRRORLEFTRIGHT); | 
|---|
| 2628 | dwFx &= ~DDBLTFX_ROTATE180; // remove handled flag | 
|---|
| 2629 | } | 
|---|
| 2630 | if(dwFx & DDBLTFX_MIRRORUPDOWN) | 
|---|
| 2631 | { | 
|---|
| 2632 | // switching the the direction can be integrated with other flags | 
|---|
| 2633 | dwPitch = -dwPitch; | 
|---|
| 2634 | pBltPos = (char*) dest->pDiveBuffer + | 
|---|
| 2635 | ((DestRect.top +BlitHeight)* dest->dwPitchDB) + | 
|---|
| 2636 | (DestRect.left * dest->dwBytesPPDive); | 
|---|
| 2637 |  | 
|---|
| 2638 | dwFx &= ~DDBLTFX_MIRRORUPDOWN;  // remove handled flag | 
|---|
| 2639 | } | 
|---|
| 2640 |  | 
|---|
| 2641 | if(dwFx & DDBLTFX_MIRRORLEFTRIGHT) | 
|---|
| 2642 | { | 
|---|
| 2643 | // 180 degree turn or a LR Mirroring | 
|---|
| 2644 | // don't support any other dwFlags like transparent at the moment | 
|---|
| 2645 |  | 
|---|
| 2646 | switch(dest->dwBytesPPDive) | 
|---|
| 2647 | { | 
|---|
| 2648 | case 1: | 
|---|
| 2649 | while(BlitHeight--) | 
|---|
| 2650 | { | 
|---|
| 2651 | x = BlitWidth; | 
|---|
| 2652 | while(x) | 
|---|
| 2653 | { | 
|---|
| 2654 | pBltPos[BlitWidth-x] = pSrcPos[x]; | 
|---|
| 2655 | x--; | 
|---|
| 2656 | } | 
|---|
| 2657 | pBltPos += dwPitch; | 
|---|
| 2658 | pSrcPos += src->dwPitchDB; | 
|---|
| 2659 | } | 
|---|
| 2660 | break; | 
|---|
| 2661 | case 2: | 
|---|
| 2662 | while(BlitHeight--) | 
|---|
| 2663 | { | 
|---|
| 2664 | x = BlitWidth; | 
|---|
| 2665 | while(x) | 
|---|
| 2666 | { | 
|---|
| 2667 | ((USHORT*)pBltPos)[BlitWidth-x] = ((USHORT*)pSrcPos)[x]; | 
|---|
| 2668 | x--; | 
|---|
| 2669 | } | 
|---|
| 2670 | pBltPos += dwPitch; | 
|---|
| 2671 | pSrcPos += src->dwPitchDB; | 
|---|
| 2672 | } | 
|---|
| 2673 | break; | 
|---|
| 2674 | case 3: | 
|---|
| 2675 | BlitWidth *= 3; | 
|---|
| 2676 | while(BlitHeight--) | 
|---|
| 2677 | { | 
|---|
| 2678 | x = BlitWidth; | 
|---|
| 2679 | while(x) | 
|---|
| 2680 | { | 
|---|
| 2681 | pBltPos[BlitWidth-x] = pSrcPos[x-2]; | 
|---|
| 2682 | x--; | 
|---|
| 2683 | pBltPos[BlitWidth-x] = pSrcPos[x]; | 
|---|
| 2684 | x--; | 
|---|
| 2685 | pBltPos[BlitWidth-x] = pSrcPos[x+2]; | 
|---|
| 2686 | x--; | 
|---|
| 2687 | } | 
|---|
| 2688 | pBltPos += dwPitch; | 
|---|
| 2689 | pSrcPos += src->dwPitchDB; | 
|---|
| 2690 | } | 
|---|
| 2691 | break; | 
|---|
| 2692 | case 4: | 
|---|
| 2693 | while(BlitHeight--) | 
|---|
| 2694 | { | 
|---|
| 2695 | x = BlitWidth; | 
|---|
| 2696 | while(x) | 
|---|
| 2697 | { | 
|---|
| 2698 | ((DWORD*)pBltPos)[BlitWidth-x] = ((DWORD*)pSrcPos)[x]; | 
|---|
| 2699 | x--; | 
|---|
| 2700 | } | 
|---|
| 2701 | pBltPos += dwPitch; | 
|---|
| 2702 | pSrcPos += src->dwPitchDB; | 
|---|
| 2703 | } | 
|---|
| 2704 | break; | 
|---|
| 2705 | }  // end switch | 
|---|
| 2706 | dest->lpVtbl->ChangeUniquenessValue(dest); | 
|---|
| 2707 | return DD_OK; | 
|---|
| 2708 | } | 
|---|
| 2709 |  | 
|---|
| 2710 | #ifdef DEBUG | 
|---|
| 2711 | if(dwFx) | 
|---|
| 2712 | _dump_DDBLTFX(dwFx); | 
|---|
| 2713 | #endif | 
|---|
| 2714 | // We ignore unhandled flags at the moment | 
|---|
| 2715 | } | 
|---|
| 2716 |  | 
|---|
| 2717 | if( (dwFlags & DDBLT_KEYSRC) | | 
|---|
| 2718 | (dwFlags & DDBLT_KEYSRCOVERRIDE) ) | 
|---|
| 2719 | { | 
|---|
| 2720 | if(dwFlags & DDBLT_KEYSRCOVERRIDE) | 
|---|
| 2721 | { | 
|---|
| 2722 |  | 
|---|
| 2723 | if( NULL==lpDDBltFx) | 
|---|
| 2724 | return DDERR_INVALIDPARAMS; | 
|---|
| 2725 |  | 
|---|
| 2726 | dwFlags &= ~DDBLT_KEYSRCOVERRIDE; | 
|---|
| 2727 |  | 
|---|
| 2728 | // We work like the HEL and test only the low value | 
|---|
| 2729 | dwSrcColor = lpDDBltFx->ddckSrcColorkey.dwColorSpaceLowValue; | 
|---|
| 2730 |  | 
|---|
| 2731 | } | 
|---|
| 2732 | else | 
|---|
| 2733 | { | 
|---|
| 2734 |  | 
|---|
| 2735 | dwFlags &= ~DDBLT_KEYSRC; | 
|---|
| 2736 |  | 
|---|
| 2737 | // Not sure if that is OK maybe check if one is set ? | 
|---|
| 2738 | // if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_SRCBLT)) return DDERR_WRONGPARAM;? | 
|---|
| 2739 |  | 
|---|
| 2740 | dwSrcColor = src->DDSurfaceDesc.ddckCKSrcBlt.dwColorSpaceLowValue; | 
|---|
| 2741 | } | 
|---|
| 2742 |  | 
|---|
| 2743 | // ToDo : We currently indicate that we don't support | 
|---|
| 2744 | // DDBLT_KEYDEST but HEL does change that! | 
|---|
| 2745 | // also add this key in the get/setColorKey functions | 
|---|
| 2746 |  | 
|---|
| 2747 | if( (dwFlags & DDBLT_KEYDEST) | | 
|---|
| 2748 | (dwFlags & DDBLT_KEYDESTOVERRIDE) ) | 
|---|
| 2749 | { | 
|---|
| 2750 | // Source and dest color keying SLOW!!! | 
|---|
| 2751 | if(dwFlags & DDBLT_KEYDESTOVERRIDE) | 
|---|
| 2752 | { | 
|---|
| 2753 | if( NULL==lpDDBltFx) | 
|---|
| 2754 | return DDERR_INVALIDPARAMS; | 
|---|
| 2755 |  | 
|---|
| 2756 | dwFlags &= ~DDBLT_KEYDESTOVERRIDE; | 
|---|
| 2757 |  | 
|---|
| 2758 | // We work like the HEL and test only the low value | 
|---|
| 2759 | dwDestColor = lpDDBltFx->ddckDestColorkey.dwColorSpaceLowValue; | 
|---|
| 2760 |  | 
|---|
| 2761 | } | 
|---|
| 2762 | else | 
|---|
| 2763 | { | 
|---|
| 2764 |  | 
|---|
| 2765 | dwFlags &= ~DDBLT_KEYDEST; | 
|---|
| 2766 |  | 
|---|
| 2767 | // Not sure if that is OK maybe check if one is set ? | 
|---|
| 2768 | // if(!(Dest->DDSurfaceDesc.dwFlags & DDCKEY_DESTBLT)) return DDERR_WRONGPARAM;? | 
|---|
| 2769 |  | 
|---|
| 2770 | dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue; | 
|---|
| 2771 | } | 
|---|
| 2772 |  | 
|---|
| 2773 | // This will be be slow maybe move to ASM ? | 
|---|
| 2774 | // using MMX should be much faster | 
|---|
| 2775 | switch(dest->dwBytesPPDive) | 
|---|
| 2776 | { | 
|---|
| 2777 | case 1: | 
|---|
| 2778 | while(BlitHeight--) | 
|---|
| 2779 | { | 
|---|
| 2780 | x = 0; | 
|---|
| 2781 | while(x<BlitWidth) | 
|---|
| 2782 | { | 
|---|
| 2783 | if(pSrcPos[x] != (char) dwSrcColor) | 
|---|
| 2784 | { | 
|---|
| 2785 | if(pBltPos[x] != (char) dwDestColor) | 
|---|
| 2786 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 2787 | } | 
|---|
| 2788 | x++; | 
|---|
| 2789 | } | 
|---|
| 2790 | pBltPos += dwPitch; | 
|---|
| 2791 | pSrcPos += src->dwPitchDB; | 
|---|
| 2792 | } | 
|---|
| 2793 | break; | 
|---|
| 2794 | case 2: | 
|---|
| 2795 | while(BlitHeight--) | 
|---|
| 2796 | { | 
|---|
| 2797 | x = 0; | 
|---|
| 2798 | while(x<BlitWidth) | 
|---|
| 2799 | { | 
|---|
| 2800 | if(((USHORT*)pSrcPos)[x] != (USHORT) dwSrcColor) | 
|---|
| 2801 | { | 
|---|
| 2802 | if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor) | 
|---|
| 2803 | ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x]; | 
|---|
| 2804 | } | 
|---|
| 2805 | x++; | 
|---|
| 2806 | } | 
|---|
| 2807 | pBltPos += dwPitch; | 
|---|
| 2808 | pSrcPos += src->dwPitchDB; | 
|---|
| 2809 | } | 
|---|
| 2810 | break; | 
|---|
| 2811 | case 3: | 
|---|
| 2812 | { | 
|---|
| 2813 | char *pSC, *pDC; | 
|---|
| 2814 | pSC = (char*)&dwSrcColor; | 
|---|
| 2815 | pDC = (char*)&dwDestColor; | 
|---|
| 2816 | BlitWidth *=3; | 
|---|
| 2817 |  | 
|---|
| 2818 | while(BlitHeight--) | 
|---|
| 2819 | { | 
|---|
| 2820 | x = 0; | 
|---|
| 2821 |  | 
|---|
| 2822 | while(x<BlitWidth) | 
|---|
| 2823 | { | 
|---|
| 2824 | if( (pSrcPos[x]   != pSC[1]) && | 
|---|
| 2825 | (pSrcPos[x+1] != pSC[2]) && | 
|---|
| 2826 | (pSrcPos[x+2] != pSC[3]) | 
|---|
| 2827 | ) | 
|---|
| 2828 | { | 
|---|
| 2829 | if( (pBltPos[x]   != pDC[1]) && | 
|---|
| 2830 | (pBltPos[x+1] != pDC[2]) && | 
|---|
| 2831 | (pBltPos[x+2] != pDC[3]) | 
|---|
| 2832 | ) | 
|---|
| 2833 | { | 
|---|
| 2834 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 2835 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 2836 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 2837 | } | 
|---|
| 2838 | } | 
|---|
| 2839 | x +=3; | 
|---|
| 2840 | } | 
|---|
| 2841 | pBltPos += dwPitch; | 
|---|
| 2842 | pSrcPos += src->dwPitchDB; | 
|---|
| 2843 | } | 
|---|
| 2844 | break; | 
|---|
| 2845 | } | 
|---|
| 2846 | case 4: | 
|---|
| 2847 | while(BlitHeight--) | 
|---|
| 2848 | { | 
|---|
| 2849 | x = 0; | 
|---|
| 2850 | while(x<BlitWidth) | 
|---|
| 2851 | { | 
|---|
| 2852 | if(((DWORD*)pSrcPos)[x] != dwSrcColor) | 
|---|
| 2853 | { | 
|---|
| 2854 | if(((DWORD*)pBltPos)[x] != dwDestColor) | 
|---|
| 2855 | ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x]; | 
|---|
| 2856 | } | 
|---|
| 2857 | x++; | 
|---|
| 2858 | } | 
|---|
| 2859 | pBltPos += dwPitch; | 
|---|
| 2860 | pSrcPos += src->dwPitchDB; | 
|---|
| 2861 | } | 
|---|
| 2862 | break; | 
|---|
| 2863 | }  // End switch | 
|---|
| 2864 | } | 
|---|
| 2865 | else | 
|---|
| 2866 | { | 
|---|
| 2867 | // Only Source colorkey | 
|---|
| 2868 | } | 
|---|
| 2869 | dest->lpVtbl->ChangeUniquenessValue(dest); | 
|---|
| 2870 | return DD_OK; | 
|---|
| 2871 | } | 
|---|
| 2872 |  | 
|---|
| 2873 | if( (dwFlags & DDBLT_KEYDEST) | | 
|---|
| 2874 | (dwFlags & DDBLT_KEYDESTOVERRIDE) ) | 
|---|
| 2875 | { | 
|---|
| 2876 | // Dest color keying SLOW!!! | 
|---|
| 2877 | if(dwFlags & DDBLT_KEYSRCOVERRIDE) | 
|---|
| 2878 | { | 
|---|
| 2879 | if( NULL==lpDDBltFx) | 
|---|
| 2880 | return DDERR_INVALIDPARAMS; | 
|---|
| 2881 |  | 
|---|
| 2882 | dwFlags &= ~DDBLT_KEYSRCOVERRIDE; | 
|---|
| 2883 |  | 
|---|
| 2884 | // We work like the HEL and test only the low value | 
|---|
| 2885 | dwDestColor = lpDDBltFx->ddckDestColorkey.dwColorSpaceLowValue; | 
|---|
| 2886 |  | 
|---|
| 2887 | } | 
|---|
| 2888 | else | 
|---|
| 2889 | { | 
|---|
| 2890 |  | 
|---|
| 2891 | dwFlags &= ~DDBLT_KEYDEST; | 
|---|
| 2892 |  | 
|---|
| 2893 | // Not sure if that is OK maybe check if one is set ? | 
|---|
| 2894 | // if(!(src->DDSurfaceDesc.dwFlags & DDCKEY_DESTBLT)) return DDERR_WRONGPARAM;? | 
|---|
| 2895 |  | 
|---|
| 2896 | dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue; | 
|---|
| 2897 | } | 
|---|
| 2898 |  | 
|---|
| 2899 | // This will be be slow maybe move to ASM ? | 
|---|
| 2900 | // using MMX should be much faster | 
|---|
| 2901 | switch(dest->dwBytesPPDive) | 
|---|
| 2902 | { | 
|---|
| 2903 | case 1: | 
|---|
| 2904 | while(BlitHeight--) | 
|---|
| 2905 | { | 
|---|
| 2906 | x = 0; | 
|---|
| 2907 | while(x<BlitWidth) | 
|---|
| 2908 | { | 
|---|
| 2909 | if(pBltPos[x] != (char) dwDestColor) | 
|---|
| 2910 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 2911 | x++; | 
|---|
| 2912 | } | 
|---|
| 2913 | pBltPos += dwPitch; | 
|---|
| 2914 | pSrcPos += src->dwPitchDB; | 
|---|
| 2915 | } | 
|---|
| 2916 | break; | 
|---|
| 2917 | case 2: | 
|---|
| 2918 | while(BlitHeight--) | 
|---|
| 2919 | { | 
|---|
| 2920 | x = 0; | 
|---|
| 2921 | while(x<BlitWidth) | 
|---|
| 2922 | { | 
|---|
| 2923 | if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor) | 
|---|
| 2924 | ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x]; | 
|---|
| 2925 | x++; | 
|---|
| 2926 | } | 
|---|
| 2927 | pBltPos += dwPitch; | 
|---|
| 2928 | pSrcPos += src->dwPitchDB; | 
|---|
| 2929 | } | 
|---|
| 2930 | break; | 
|---|
| 2931 | case 3: | 
|---|
| 2932 | { | 
|---|
| 2933 | char *pSC, *pDC; | 
|---|
| 2934 | pSC = (char*)&dwSrcColor; | 
|---|
| 2935 | pDC = (char*)&dwDestColor; | 
|---|
| 2936 | BlitWidth *=3; | 
|---|
| 2937 |  | 
|---|
| 2938 | while(BlitHeight--) | 
|---|
| 2939 | { | 
|---|
| 2940 | x = 0; | 
|---|
| 2941 |  | 
|---|
| 2942 | while(x<BlitWidth) | 
|---|
| 2943 | { | 
|---|
| 2944 | if( (pBltPos[x]   != pDC[1]) && | 
|---|
| 2945 | (pBltPos[x+1] != pDC[2]) && | 
|---|
| 2946 | (pBltPos[x+2] != pDC[3]) | 
|---|
| 2947 | ) | 
|---|
| 2948 | { | 
|---|
| 2949 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 2950 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 2951 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 2952 | } | 
|---|
| 2953 | x +=3; | 
|---|
| 2954 | } | 
|---|
| 2955 | pBltPos += dwPitch; | 
|---|
| 2956 | pSrcPos += src->dwPitchDB; | 
|---|
| 2957 | } | 
|---|
| 2958 | break; | 
|---|
| 2959 | } | 
|---|
| 2960 | case 4: | 
|---|
| 2961 | while(BlitHeight--) | 
|---|
| 2962 | { | 
|---|
| 2963 | x = 0; | 
|---|
| 2964 | while(x<BlitWidth) | 
|---|
| 2965 | { | 
|---|
| 2966 | if( ((DWORD*)pBltPos)[x] != dwDestColor) | 
|---|
| 2967 | ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x]; | 
|---|
| 2968 | x++; | 
|---|
| 2969 | } | 
|---|
| 2970 | pBltPos += dwPitch; | 
|---|
| 2971 | pSrcPos += src->dwPitchDB; | 
|---|
| 2972 | } | 
|---|
| 2973 | break; | 
|---|
| 2974 | }  // End switch | 
|---|
| 2975 | } // End of Dest ColorKey | 
|---|
| 2976 |  | 
|---|
| 2977 |  | 
|---|
| 2978 | }// end  handling dwFlags | 
|---|
| 2979 | } // End handling source not Framebuffer | 
|---|
| 2980 |  | 
|---|
| 2981 | }// end handling destination not framebuffer | 
|---|
| 2982 |  | 
|---|
| 2983 | dest->lpVtbl->ChangeUniquenessValue(dest); | 
|---|
| 2984 | return(DD_OK); | 
|---|
| 2985 | } | 
|---|
| 2986 | //****************************************************************************** | 
|---|
| 2987 | //****************************************************************************** | 
|---|
| 2988 | HRESULT __stdcall SurfBltBatch(THIS, LPDDBLTBATCH, DWORD, DWORD ) | 
|---|
| 2989 | { | 
|---|
| 2990 | #ifdef DEBUG | 
|---|
| 2991 | WriteLog("SurfBltBatch Not implemented by M$\n"); | 
|---|
| 2992 | #endif | 
|---|
| 2993 |  | 
|---|
| 2994 | return(DD_OK); | 
|---|
| 2995 | } | 
|---|
| 2996 | //****************************************************************************** | 
|---|
| 2997 | //****************************************************************************** | 
|---|
| 2998 | HRESULT __stdcall SurfBltFast(THIS, DWORD,DWORD,LPDIRECTDRAWSURFACE2, LPRECT,DWORD) | 
|---|
| 2999 | { | 
|---|
| 3000 | #ifdef DEBUG | 
|---|
| 3001 | WriteLog("SurfBltFast NIY\n"); | 
|---|
| 3002 | #endif | 
|---|
| 3003 |  | 
|---|
| 3004 | return(DD_OK); | 
|---|
| 3005 | } | 
|---|
| 3006 | //****************************************************************************** | 
|---|
| 3007 | //****************************************************************************** | 
|---|
| 3008 | HRESULT __stdcall SurfBltFast4( THIS This, | 
|---|
| 3009 | DWORD dwX, | 
|---|
| 3010 | DWORD dwY, | 
|---|
| 3011 | LPDIRECTDRAWSURFACE4 lpDDSrcSurface, | 
|---|
| 3012 | LPRECT lpSrcRect, | 
|---|
| 3013 | DWORD dwTrans) | 
|---|
| 3014 | { | 
|---|
| 3015 | OS2IDirectDrawSurface *dest = (OS2IDirectDrawSurface *)This; | 
|---|
| 3016 | OS2IDirectDrawSurface *src  = (OS2IDirectDrawSurface *)lpDDSrcSurface; | 
|---|
| 3017 | RECTL SrcRect; | 
|---|
| 3018 | char *pBltPos, *pSrcPos; | 
|---|
| 3019 | DWORD dwDestColor, dwSrcColor, BlitWidth, BlitHeight,x,y; | 
|---|
| 3020 |  | 
|---|
| 3021 | #ifdef DEBUG | 
|---|
| 3022 | WriteLog("SurfBltFast4 %08X at(%d/%d) onto %08X with flags %08X\n",src, dwX,dwY, dest, dwTrans); | 
|---|
| 3023 | #endif | 
|---|
| 3024 |  | 
|---|
| 3025 | if( (NULL==lpDDSrcSurface) || | 
|---|
| 3026 | (dwX<0) || (dwY<0) || | 
|---|
| 3027 | (dwX>dest->width) || | 
|---|
| 3028 | (dwY>dest->height)) | 
|---|
| 3029 | { | 
|---|
| 3030 | WriteLog("Invalid Parameters %08X, %d %d", lpDDSrcSurface ,dest->width , dest->height); | 
|---|
| 3031 | return DDERR_INVALIDPARAMS; | 
|---|
| 3032 | } | 
|---|
| 3033 |  | 
|---|
| 3034 | if (NULL!=lpSrcRect) | 
|---|
| 3035 | { | 
|---|
| 3036 | memcpy(&SrcRect,lpSrcRect,sizeof(RECTL) ); | 
|---|
| 3037 | } | 
|---|
| 3038 | else | 
|---|
| 3039 | { | 
|---|
| 3040 | SrcRect.top    = 0; | 
|---|
| 3041 | SrcRect.left   = 0; | 
|---|
| 3042 | SrcRect.bottom = src->height; | 
|---|
| 3043 | SrcRect.right  = src->width; | 
|---|
| 3044 | } | 
|---|
| 3045 |  | 
|---|
| 3046 | // Todo: Test for locked src/dest | 
|---|
| 3047 |  | 
|---|
| 3048 | pBltPos = (char*) dest->pDiveBuffer + (dwY * dest->dwPitchDB) + | 
|---|
| 3049 | (dwX * dest->dwBytesPPDive); | 
|---|
| 3050 |  | 
|---|
| 3051 | pSrcPos = (char*) src->pDiveBuffer + (SrcRect.top * src->dwPitchDB) + | 
|---|
| 3052 | (SrcRect.left * src->dwBytesPPDive); | 
|---|
| 3053 |  | 
|---|
| 3054 | BlitHeight = SrcRect.bottom - SrcRect.top; | 
|---|
| 3055 | BlitWidth  = (SrcRect.right - SrcRect.left) * src->dwBytesPPDive; | 
|---|
| 3056 |  | 
|---|
| 3057 | // Remove unsupported wait flag | 
|---|
| 3058 | dwTrans &= ~DDBLTFAST_WAIT; | 
|---|
| 3059 |  | 
|---|
| 3060 | if(DDBLTFAST_NOCOLORKEY == dwTrans ) | 
|---|
| 3061 | { | 
|---|
| 3062 | WriteLog("Solid Blit"); | 
|---|
| 3063 | #ifdef USE_ASM | 
|---|
| 3064 | BltRec(pBltPos, pSrcPos, BlitWidth, BlitHeight, | 
|---|
| 3065 | dest->dwPitchDB, | 
|---|
| 3066 | src->dwPitchDB); | 
|---|
| 3067 | #else | 
|---|
| 3068 | // Solid Blit | 
|---|
| 3069 | while(1) | 
|---|
| 3070 | { | 
|---|
| 3071 | memcpy(pBltPos,pSrcPos,BlitWidth); | 
|---|
| 3072 | pBltPos += dest->dwPitchDB; | 
|---|
| 3073 | pSrcPos += src->dwPitchDB; | 
|---|
| 3074 | if(! (--BlitHeight)) | 
|---|
| 3075 | break; | 
|---|
| 3076 | } | 
|---|
| 3077 | #endif | 
|---|
| 3078 |  | 
|---|
| 3079 | } | 
|---|
| 3080 | else | 
|---|
| 3081 | { | 
|---|
| 3082 | WriteLog("TransBlit\n"); | 
|---|
| 3083 |  | 
|---|
| 3084 | if(dwTrans & DDBLTFAST_SRCCOLORKEY) | 
|---|
| 3085 | { | 
|---|
| 3086 | WriteLog("Trans SRC\n"); | 
|---|
| 3087 | // transparent source | 
|---|
| 3088 | dwSrcColor = src->DDSurfaceDesc.ddckCKSrcBlt.dwColorSpaceLowValue; | 
|---|
| 3089 | if(dwTrans & DDBLTFAST_DESTCOLORKEY) | 
|---|
| 3090 | { | 
|---|
| 3091 | WriteLog("And Dest Colorkey"); | 
|---|
| 3092 | dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue; | 
|---|
| 3093 | // Source and dest colorkeying | 
|---|
| 3094 | switch(dest->dwBytesPPDive) | 
|---|
| 3095 | { | 
|---|
| 3096 | case 1: | 
|---|
| 3097 | while(BlitHeight--) | 
|---|
| 3098 | { | 
|---|
| 3099 | x = 0; | 
|---|
| 3100 | while(x<BlitWidth) | 
|---|
| 3101 | { | 
|---|
| 3102 | if(pSrcPos[x] != (char) dwSrcColor) | 
|---|
| 3103 | { | 
|---|
| 3104 | if(pBltPos[x] != (char) dwDestColor) | 
|---|
| 3105 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 3106 | } | 
|---|
| 3107 | x++; | 
|---|
| 3108 | } | 
|---|
| 3109 | pBltPos += dest->dwPitchDB; | 
|---|
| 3110 | pSrcPos += src->dwPitchDB; | 
|---|
| 3111 | } | 
|---|
| 3112 | break; | 
|---|
| 3113 | case 2: | 
|---|
| 3114 | while(BlitHeight--) | 
|---|
| 3115 | { | 
|---|
| 3116 | x = 0; | 
|---|
| 3117 | while(x<BlitWidth) | 
|---|
| 3118 | { | 
|---|
| 3119 | if(((USHORT*)pSrcPos)[x] != (USHORT) dwSrcColor) | 
|---|
| 3120 | { | 
|---|
| 3121 | if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor) | 
|---|
| 3122 | ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x]; | 
|---|
| 3123 | } | 
|---|
| 3124 | x++; | 
|---|
| 3125 | } | 
|---|
| 3126 | pBltPos += dest->dwPitchDB; | 
|---|
| 3127 | pSrcPos += src->dwPitchDB; | 
|---|
| 3128 | } | 
|---|
| 3129 | break; | 
|---|
| 3130 | case 3: | 
|---|
| 3131 | { | 
|---|
| 3132 | char *pSC, *pDC; | 
|---|
| 3133 | pSC = (char*)&dwSrcColor; | 
|---|
| 3134 | pDC = (char*)&dwDestColor; | 
|---|
| 3135 | BlitWidth *=3; | 
|---|
| 3136 |  | 
|---|
| 3137 | while(BlitHeight--) | 
|---|
| 3138 | { | 
|---|
| 3139 | x = 0; | 
|---|
| 3140 |  | 
|---|
| 3141 | while(x<BlitWidth) | 
|---|
| 3142 | { | 
|---|
| 3143 | if( (pSrcPos[x]   != pSC[1]) && | 
|---|
| 3144 | (pSrcPos[x+1] != pSC[2]) && | 
|---|
| 3145 | (pSrcPos[x+2] != pSC[3]) | 
|---|
| 3146 | ) | 
|---|
| 3147 | { | 
|---|
| 3148 | if( (pBltPos[x]   != pDC[1]) && | 
|---|
| 3149 | (pBltPos[x+1] != pDC[2]) && | 
|---|
| 3150 | (pBltPos[x+2] != pDC[3]) | 
|---|
| 3151 | ) | 
|---|
| 3152 | { | 
|---|
| 3153 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 3154 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 3155 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 3156 | } | 
|---|
| 3157 | } | 
|---|
| 3158 | x +=3; | 
|---|
| 3159 | } | 
|---|
| 3160 | pBltPos += dest->dwPitchDB; | 
|---|
| 3161 | pSrcPos += src->dwPitchDB; | 
|---|
| 3162 | } | 
|---|
| 3163 | break; | 
|---|
| 3164 | } | 
|---|
| 3165 | case 4: | 
|---|
| 3166 | while(BlitHeight--) | 
|---|
| 3167 | { | 
|---|
| 3168 | x = 0; | 
|---|
| 3169 | while(x<BlitWidth) | 
|---|
| 3170 | { | 
|---|
| 3171 | if(((DWORD*)pSrcPos)[x] != dwSrcColor) | 
|---|
| 3172 | { | 
|---|
| 3173 | if(((DWORD*)pBltPos)[x] != dwDestColor) | 
|---|
| 3174 | ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x]; | 
|---|
| 3175 | } | 
|---|
| 3176 | x++; | 
|---|
| 3177 | } | 
|---|
| 3178 | pBltPos += dest->dwPitchDB; | 
|---|
| 3179 | pSrcPos += src->dwPitchDB; | 
|---|
| 3180 | } | 
|---|
| 3181 | break; | 
|---|
| 3182 | }  // End switch | 
|---|
| 3183 | } | 
|---|
| 3184 | else | 
|---|
| 3185 | { | 
|---|
| 3186 | // This MMX detection should be moved into OS2Draw | 
|---|
| 3187 | // and into the surface constructor a setup for blitting pointers | 
|---|
| 3188 | WriteLog("Only Src ColorKey"); | 
|---|
| 3189 | switch(dest->dwBytesPPDive) | 
|---|
| 3190 | { | 
|---|
| 3191 | case 1: | 
|---|
| 3192 | if(CPUHasMMX()) | 
|---|
| 3193 | while(BlitHeight--) | 
|---|
| 3194 | { | 
|---|
| 3195 | BlitColorKey8MMX((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth); | 
|---|
| 3196 | pBltPos += dest->dwPitchDB; | 
|---|
| 3197 | pSrcPos += src->dwPitchDB; | 
|---|
| 3198 | } | 
|---|
| 3199 | else | 
|---|
| 3200 | while(BlitHeight--) | 
|---|
| 3201 | { | 
|---|
| 3202 | BlitColorKey8((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth); | 
|---|
| 3203 | pBltPos += dest->dwPitchDB; | 
|---|
| 3204 | pSrcPos += src->dwPitchDB; | 
|---|
| 3205 | } | 
|---|
| 3206 | break; | 
|---|
| 3207 | case 2: | 
|---|
| 3208 |  | 
|---|
| 3209 | if(CPUHasMMX()) | 
|---|
| 3210 | while(BlitHeight--) | 
|---|
| 3211 | { | 
|---|
| 3212 | BlitColorKey16MMX((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth); | 
|---|
| 3213 | pBltPos += dest->dwPitchDB; | 
|---|
| 3214 | pSrcPos += src->dwPitchDB; | 
|---|
| 3215 | } | 
|---|
| 3216 | else | 
|---|
| 3217 | while(BlitHeight--) | 
|---|
| 3218 | { | 
|---|
| 3219 | BlitColorKey16((PBYTE)pBltPos,(PBYTE)pSrcPos,dwSrcColor,BlitWidth); | 
|---|
| 3220 | pBltPos += dest->dwPitchDB; | 
|---|
| 3221 | pSrcPos += src->dwPitchDB; | 
|---|
| 3222 | } | 
|---|
| 3223 | break; | 
|---|
| 3224 | case 3: | 
|---|
| 3225 | char *pSC; | 
|---|
| 3226 | pSC = (char*)&dwSrcColor; | 
|---|
| 3227 | BlitWidth *=3; | 
|---|
| 3228 |  | 
|---|
| 3229 | while(BlitHeight--) | 
|---|
| 3230 | { | 
|---|
| 3231 | x = 0; | 
|---|
| 3232 |  | 
|---|
| 3233 | while(x<BlitWidth) | 
|---|
| 3234 | { | 
|---|
| 3235 | if( (pSrcPos[x]   != pSC[1]) && | 
|---|
| 3236 | (pSrcPos[x+1] != pSC[2]) && | 
|---|
| 3237 | (pSrcPos[x+2] != pSC[3]) | 
|---|
| 3238 | ) | 
|---|
| 3239 | { | 
|---|
| 3240 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 3241 | pBltPos[x+1] = pSrcPos[x+1]; | 
|---|
| 3242 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 3243 | } | 
|---|
| 3244 | x +=3; | 
|---|
| 3245 | } | 
|---|
| 3246 | pBltPos += dest->dwPitchDB; | 
|---|
| 3247 | pSrcPos += src->dwPitchDB; | 
|---|
| 3248 | } | 
|---|
| 3249 | break; | 
|---|
| 3250 | case 4: | 
|---|
| 3251 | break; | 
|---|
| 3252 | } | 
|---|
| 3253 | } | 
|---|
| 3254 | } | 
|---|
| 3255 | else | 
|---|
| 3256 | { | 
|---|
| 3257 | if(dwTrans & DDBLTFAST_DESTCOLORKEY) | 
|---|
| 3258 | { | 
|---|
| 3259 | WriteLog("DestColorKey\n"); | 
|---|
| 3260 |  | 
|---|
| 3261 | dwDestColor = dest->DDSurfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue; | 
|---|
| 3262 | switch(dest->dwBytesPPDive) | 
|---|
| 3263 | { | 
|---|
| 3264 | case 1: | 
|---|
| 3265 | while(BlitHeight--) | 
|---|
| 3266 | { | 
|---|
| 3267 | x = 0; | 
|---|
| 3268 | while(x<BlitWidth) | 
|---|
| 3269 | { | 
|---|
| 3270 | if(pBltPos[x] != (char) dwDestColor) | 
|---|
| 3271 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 3272 | x++; | 
|---|
| 3273 | } | 
|---|
| 3274 | pBltPos += dest->dwPitchDB; | 
|---|
| 3275 | pSrcPos += src->dwPitchDB; | 
|---|
| 3276 | } | 
|---|
| 3277 | break; | 
|---|
| 3278 | case 2: | 
|---|
| 3279 | while(BlitHeight--) | 
|---|
| 3280 | { | 
|---|
| 3281 | x = 0; | 
|---|
| 3282 | while(x<BlitWidth) | 
|---|
| 3283 | { | 
|---|
| 3284 | if(((USHORT*)pBltPos)[x] != (USHORT) dwDestColor) | 
|---|
| 3285 | ((USHORT*)pBltPos)[x] = ((USHORT*)pSrcPos)[x]; | 
|---|
| 3286 | x++; | 
|---|
| 3287 | } | 
|---|
| 3288 | pBltPos += dest->dwPitchDB; | 
|---|
| 3289 | pSrcPos += src->dwPitchDB; | 
|---|
| 3290 | } | 
|---|
| 3291 | break; | 
|---|
| 3292 | case 3: | 
|---|
| 3293 | { | 
|---|
| 3294 | char *pSC, *pDC; | 
|---|
| 3295 | pSC = (char*)&dwSrcColor; | 
|---|
| 3296 | pDC = (char*)&dwDestColor; | 
|---|
| 3297 | BlitWidth *=3; | 
|---|
| 3298 |  | 
|---|
| 3299 | while(BlitHeight--) | 
|---|
| 3300 | { | 
|---|
| 3301 | x = 0; | 
|---|
| 3302 |  | 
|---|
| 3303 | while(x<BlitWidth) | 
|---|
| 3304 | { | 
|---|
| 3305 | if( (pBltPos[x]   != pDC[1]) && | 
|---|
| 3306 | (pBltPos[x+1] != pDC[2]) && | 
|---|
| 3307 | (pBltPos[x+2] != pDC[3]) | 
|---|
| 3308 | ) | 
|---|
| 3309 | { | 
|---|
| 3310 | pBltPos[x] = pSrcPos[x]; | 
|---|
| 3311 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 3312 | pBltPos[x+1] = pSrcPos[x+2]; | 
|---|
| 3313 | } | 
|---|
| 3314 | x +=3; | 
|---|
| 3315 | } | 
|---|
| 3316 | pBltPos += dest->dwPitchDB; | 
|---|
| 3317 | pSrcPos += src->dwPitchDB; | 
|---|
| 3318 | } | 
|---|
| 3319 | break; | 
|---|
| 3320 | } | 
|---|
| 3321 | case 4: | 
|---|
| 3322 | while(BlitHeight--) | 
|---|
| 3323 | { | 
|---|
| 3324 | x = 0; | 
|---|
| 3325 | while(x<BlitWidth) | 
|---|
| 3326 | { | 
|---|
| 3327 | if(((DWORD*)pBltPos)[x] != dwDestColor) | 
|---|
| 3328 | ((DWORD*)pBltPos)[x] = ((DWORD*)pSrcPos)[x]; | 
|---|
| 3329 | x++; | 
|---|
| 3330 | } | 
|---|
| 3331 | pBltPos += dest->dwPitchDB; | 
|---|
| 3332 | pSrcPos += src->dwPitchDB; | 
|---|
| 3333 | } | 
|---|
| 3334 | break; | 
|---|
| 3335 | }  // End switch | 
|---|
| 3336 | } | 
|---|
| 3337 | else | 
|---|
| 3338 | { | 
|---|
| 3339 | WriteLog("Unexpected Flags"); | 
|---|
| 3340 | } | 
|---|
| 3341 | } | 
|---|
| 3342 | } | 
|---|
| 3343 | dest->lpVtbl->ChangeUniquenessValue(dest); | 
|---|
| 3344 |  | 
|---|
| 3345 |  | 
|---|
| 3346 | return(DD_OK); | 
|---|
| 3347 | } | 
|---|
| 3348 | //****************************************************************************** | 
|---|
| 3349 | //****************************************************************************** | 
|---|
| 3350 | HRESULT __stdcall SurfDeleteAttachedSurface(THIS This, DWORD dwFlags, LPDIRECTDRAWSURFACE2 lpDDSurface) | 
|---|
| 3351 | { | 
|---|
| 3352 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3353 | #ifdef DEBUG | 
|---|
| 3354 | WriteLog("SurfDeleteAttachedSurface\n"); | 
|---|
| 3355 | #endif | 
|---|
| 3356 |  | 
|---|
| 3357 | return(SurfDeleteAttachedSurface4(me, dwFlags, (LPDIRECTDRAWSURFACE4)lpDDSurface)); | 
|---|
| 3358 | } | 
|---|
| 3359 | //****************************************************************************** | 
|---|
| 3360 | //****************************************************************************** | 
|---|
| 3361 | HRESULT __stdcall SurfDeleteAttachedSurface4(THIS This, DWORD dwFlags , LPDIRECTDRAWSURFACE4 lpDDSurface) | 
|---|
| 3362 | { | 
|---|
| 3363 |  | 
|---|
| 3364 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3365 | OS2IDirectDrawSurface *AttachedSurface; | 
|---|
| 3366 | OS2IDirectDrawSurface *SurfaceCursor; | 
|---|
| 3367 | int i; | 
|---|
| 3368 |  | 
|---|
| 3369 | BOOL Found = FALSE; | 
|---|
| 3370 | #ifdef DEBUG | 
|---|
| 3371 | WriteLog("SurfDeleteAttachedSurface\n"); | 
|---|
| 3372 | #endif | 
|---|
| 3373 |  | 
|---|
| 3374 | if((0!=dwFlags)||(NULL==lpDDSurface)) | 
|---|
| 3375 | return(DDERR_INVALIDPARAMS); | 
|---|
| 3376 |  | 
|---|
| 3377 | AttachedSurface = (OS2IDirectDrawSurface*) lpDDSurface; | 
|---|
| 3378 | if (AttachedSurface->IsImplicitSurface()) | 
|---|
| 3379 | return (DDERR_CANNOTDETACHSURFACE); | 
|---|
| 3380 |  | 
|---|
| 3381 | if ( (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & ( DDSCAPS_FLIP | DDSCAPS_BACKBUFFER)) && | 
|---|
| 3382 | !(AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) ) | 
|---|
| 3383 | { | 
|---|
| 3384 | // Surface seams to be a backbuffer in a flipchain search it | 
|---|
| 3385 |  | 
|---|
| 3386 | // Goto top of list | 
|---|
| 3387 | if(me->FrontBuffer!=NULL) | 
|---|
| 3388 | { | 
|---|
| 3389 | SurfaceCursor = me->FrontBuffer; | 
|---|
| 3390 | while(SurfaceCursor->GetFrontBuffer()!=NULL) | 
|---|
| 3391 | SurfaceCursor = SurfaceCursor->GetFrontBuffer(); | 
|---|
| 3392 | } | 
|---|
| 3393 | else | 
|---|
| 3394 | SurfaceCursor = me; | 
|---|
| 3395 |  | 
|---|
| 3396 | // now iterrate through the list skip first in list as we don't remove the frontbuffer | 
|---|
| 3397 |  | 
|---|
| 3398 | SurfaceCursor = SurfaceCursor->BackBuffer; | 
|---|
| 3399 | while((SurfaceCursor!= AttachedSurface)&&(SurfaceCursor!=NULL)) | 
|---|
| 3400 | SurfaceCursor = SurfaceCursor->BackBuffer; | 
|---|
| 3401 |  | 
|---|
| 3402 | if(SurfaceCursor!=NULL) | 
|---|
| 3403 | { | 
|---|
| 3404 | Found = TRUE; | 
|---|
| 3405 | // remove the Surface from the list | 
|---|
| 3406 | SurfaceCursor->FrontBuffer->BackBuffer = SurfaceCursor->BackBuffer; | 
|---|
| 3407 | if(SurfaceCursor->BackBuffer!=NULL) | 
|---|
| 3408 | { | 
|---|
| 3409 | SurfaceCursor->BackBuffer->SetFrontBuffer(SurfaceCursor->FrontBuffer); | 
|---|
| 3410 |  | 
|---|
| 3411 | } | 
|---|
| 3412 | else | 
|---|
| 3413 | { | 
|---|
| 3414 | // we were the last buffer in the list have we been the only backbuffer? | 
|---|
| 3415 | if(SurfaceCursor->FrontBuffer->FrontBuffer == NULL) | 
|---|
| 3416 | { | 
|---|
| 3417 | // Yepp so "destroy" the flipchain | 
|---|
| 3418 | SurfaceCursor->FrontBuffer->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP; | 
|---|
| 3419 | SurfaceCursor->FrontBuffer->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 
|---|
| 3420 | } | 
|---|
| 3421 | } | 
|---|
| 3422 | // decrement the backbuffer count of all buffers in the chain in front of us | 
|---|
| 3423 | while(SurfaceCursor->GetFrontBuffer()!=NULL) | 
|---|
| 3424 | { | 
|---|
| 3425 | SurfaceCursor = SurfaceCursor->GetFrontBuffer(); | 
|---|
| 3426 | SurfaceCursor->DDSurfaceDesc.dwBackBufferCount-- ; | 
|---|
| 3427 | } | 
|---|
| 3428 |  | 
|---|
| 3429 | AttachedSurface->DDSurfaceDesc.dwBackBufferCount = 0; | 
|---|
| 3430 | AttachedSurface->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 
|---|
| 3431 | AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP; | 
|---|
| 3432 | AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER; // Set this flag as adding to the chain removed it | 
|---|
| 3433 | AttachedSurface->lpVtbl->Release(AttachedSurface); | 
|---|
| 3434 |  | 
|---|
| 3435 | } | 
|---|
| 3436 | } //endif delete back/frontbuffers | 
|---|
| 3437 |  | 
|---|
| 3438 | if ( (!Found) && (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps & ( DDSCAPS_FLIP & DDSCAPS_FRONTBUFFER)) ) | 
|---|
| 3439 | { | 
|---|
| 3440 | // seams like someone wants a new frontbuffer | 
|---|
| 3441 |  | 
|---|
| 3442 | // Goto top of list | 
|---|
| 3443 |  | 
|---|
| 3444 | if(me->FrontBuffer!=NULL) | 
|---|
| 3445 | { | 
|---|
| 3446 | SurfaceCursor = me->FrontBuffer; | 
|---|
| 3447 | while(SurfaceCursor->GetFrontBuffer()!=NULL) | 
|---|
| 3448 | SurfaceCursor = SurfaceCursor->GetFrontBuffer(); | 
|---|
| 3449 | } | 
|---|
| 3450 | else | 
|---|
| 3451 | SurfaceCursor = me; | 
|---|
| 3452 |  | 
|---|
| 3453 | if(SurfaceCursor == AttachedSurface) | 
|---|
| 3454 | { | 
|---|
| 3455 | Found = TRUE; | 
|---|
| 3456 | SurfaceCursor->BackBuffer->SetFrontBuffer(NULL); | 
|---|
| 3457 | AttachedSurface->DDSurfaceDesc.dwBackBufferCount = 0; | 
|---|
| 3458 | AttachedSurface->DDSurfaceDesc.dwFlags &= ~DDSD_BACKBUFFERCOUNT; | 
|---|
| 3459 | AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP; | 
|---|
| 3460 | AttachedSurface->lpVtbl->Release(AttachedSurface); | 
|---|
| 3461 | } | 
|---|
| 3462 |  | 
|---|
| 3463 | } | 
|---|
| 3464 |  | 
|---|
| 3465 |  | 
|---|
| 3466 | if ( (!Found) && (AttachedSurface->DDSurfaceDesc.ddsCaps.dwCaps &  DDSCAPS_MIPMAP ) ) | 
|---|
| 3467 | { | 
|---|
| 3468 | // Surface seams to be a mipmap | 
|---|
| 3469 | i = 0; | 
|---|
| 3470 | while((DPA_GetPtrCount(me->DPA_SurfaceMipMaps)>i ) && !Found) | 
|---|
| 3471 | { | 
|---|
| 3472 | if (DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i) == AttachedSurface) | 
|---|
| 3473 | { | 
|---|
| 3474 | Found = TRUE; | 
|---|
| 3475 | DPA_DeletePtr(me->DPA_SurfaceMipMaps,i); | 
|---|
| 3476 | AttachedSurface->lpVtbl->Release(AttachedSurface); | 
|---|
| 3477 | // adjust our info | 
|---|
| 3478 | me->DDSurfaceDesc.dwMipMapCount-- ; | 
|---|
| 3479 | if (!me->DDSurfaceDesc.dwMipMapCount) | 
|---|
| 3480 | { | 
|---|
| 3481 | me->DDSurfaceDesc.dwFlags &= ~DDSD_MIPMAPCOUNT; | 
|---|
| 3482 | } | 
|---|
| 3483 | } | 
|---|
| 3484 | i++; | 
|---|
| 3485 | } | 
|---|
| 3486 | } | 
|---|
| 3487 |  | 
|---|
| 3488 | if(!Found) | 
|---|
| 3489 | { | 
|---|
| 3490 | // Surface seams to be an attached one | 
|---|
| 3491 | i = 0; | 
|---|
| 3492 | while((DPA_GetPtrCount(me->DPA_SurfaceAttached)>i ) && !Found) | 
|---|
| 3493 | { | 
|---|
| 3494 | if (DPA_FastGetPtr(me->DPA_SurfaceAttached,i) == AttachedSurface) | 
|---|
| 3495 | { | 
|---|
| 3496 | Found = TRUE; | 
|---|
| 3497 | DPA_DeletePtr(me->DPA_SurfaceAttached,i); | 
|---|
| 3498 | AttachedSurface->lpVtbl->Release(AttachedSurface); | 
|---|
| 3499 | } | 
|---|
| 3500 | i++; | 
|---|
| 3501 | } | 
|---|
| 3502 | } | 
|---|
| 3503 |  | 
|---|
| 3504 |  | 
|---|
| 3505 | return(Found?DD_OK:DDERR_SURFACENOTATTACHED); | 
|---|
| 3506 | } | 
|---|
| 3507 | //****************************************************************************** | 
|---|
| 3508 | //****************************************************************************** | 
|---|
| 3509 | HRESULT __stdcall SurfEnumAttachedSurfaces(THIS This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpCallBack) | 
|---|
| 3510 | { | 
|---|
| 3511 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3512 | #ifdef DEBUG | 
|---|
| 3513 | WriteLog("SurfEnumAttachedSurfaces\n"); | 
|---|
| 3514 | #endif | 
|---|
| 3515 |  | 
|---|
| 3516 | return(SurfEnumAttachedSurfaces4(me,lpContext, (LPDDENUMSURFACESCALLBACK2) lpCallBack)); | 
|---|
| 3517 | } | 
|---|
| 3518 | //****************************************************************************** | 
|---|
| 3519 | //****************************************************************************** | 
|---|
| 3520 | HRESULT __stdcall SurfEnumAttachedSurfaces4(THIS This, LPVOID lpContext ,LPDDENUMSURFACESCALLBACK2 lpCallBack) | 
|---|
| 3521 | { | 
|---|
| 3522 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3523 | OS2IDirectDrawSurface *EnumSurface; | 
|---|
| 3524 | DDSURFACEDESC2         EnumDesc; | 
|---|
| 3525 | int i,count; | 
|---|
| 3526 | HRESULT rc; | 
|---|
| 3527 |  | 
|---|
| 3528 | #ifdef DEBUG | 
|---|
| 3529 | WriteLog("SurfEnumAttachedSurfaces\n"); | 
|---|
| 3530 | #endif | 
|---|
| 3531 | if (NULL==lpCallBack) | 
|---|
| 3532 | return (DDERR_INVALIDPARAMS); | 
|---|
| 3533 |  | 
|---|
| 3534 | rc = DDENUMRET_OK; | 
|---|
| 3535 |  | 
|---|
| 3536 |  | 
|---|
| 3537 | if(me->BackBuffer != NULL) | 
|---|
| 3538 | { | 
|---|
| 3539 | memcpy(&EnumDesc,&(me->DDSurfaceDesc),sizeof(DDSURFACEDESC2)); | 
|---|
| 3540 | rc = lpCallBack((LPDIRECTDRAWSURFACE4)me->BackBuffer,&EnumDesc,lpContext); | 
|---|
| 3541 | } | 
|---|
| 3542 |  | 
|---|
| 3543 | count = DPA_GetPtrCount(me->DPA_SurfaceMipMaps); | 
|---|
| 3544 |  | 
|---|
| 3545 | if(count>0) | 
|---|
| 3546 | { | 
|---|
| 3547 | i=0; | 
|---|
| 3548 | while( (DDENUMRET_OK == rc) && i<count ) | 
|---|
| 3549 | { | 
|---|
| 3550 | EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i); | 
|---|
| 3551 | memcpy( &EnumDesc, | 
|---|
| 3552 | &(EnumSurface->DDSurfaceDesc), | 
|---|
| 3553 | sizeof(DDSURFACEDESC2)); | 
|---|
| 3554 | // Calling back into WIN32 app so we had to reset FS | 
|---|
| 3555 | rc = lpCallBack((LPDIRECTDRAWSURFACE4)EnumSurface,&EnumDesc,lpContext); | 
|---|
| 3556 | i++; | 
|---|
| 3557 | } | 
|---|
| 3558 | } | 
|---|
| 3559 |  | 
|---|
| 3560 | count = DPA_GetPtrCount(me->DPA_SurfaceAttached); | 
|---|
| 3561 |  | 
|---|
| 3562 | if(count>0) | 
|---|
| 3563 | { | 
|---|
| 3564 | i=0; | 
|---|
| 3565 | while( (DDENUMRET_OK == rc) && i<count ) | 
|---|
| 3566 | { | 
|---|
| 3567 | EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceAttached,i); | 
|---|
| 3568 | memcpy( &EnumDesc, | 
|---|
| 3569 | &(EnumSurface->DDSurfaceDesc), | 
|---|
| 3570 | sizeof(DDSURFACEDESC2)); | 
|---|
| 3571 | rc = lpCallBack((LPDIRECTDRAWSURFACE4)EnumSurface,&EnumDesc,lpContext); | 
|---|
| 3572 | i++; | 
|---|
| 3573 | } | 
|---|
| 3574 | } | 
|---|
| 3575 |  | 
|---|
| 3576 | return(DD_OK); | 
|---|
| 3577 | } | 
|---|
| 3578 | //****************************************************************************** | 
|---|
| 3579 | //****************************************************************************** | 
|---|
| 3580 | HRESULT __stdcall SurfEnumOverlayZOrders(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) | 
|---|
| 3581 | { | 
|---|
| 3582 | #ifdef DEBUG | 
|---|
| 3583 | WriteLog("SurfEnumOverlayZOrders\n"); | 
|---|
| 3584 | #endif | 
|---|
| 3585 |  | 
|---|
| 3586 | return(DD_OK); | 
|---|
| 3587 | } | 
|---|
| 3588 | //****************************************************************************** | 
|---|
| 3589 | //****************************************************************************** | 
|---|
| 3590 | HRESULT __stdcall SurfEnumOverlayZOrders4(THIS, DWORD,LPVOID,LPDDENUMSURFACESCALLBACK2) | 
|---|
| 3591 | { | 
|---|
| 3592 | #ifdef DEBUG | 
|---|
| 3593 | WriteLog("SurfEnumOverlayZOrders\n"); | 
|---|
| 3594 | #endif | 
|---|
| 3595 |  | 
|---|
| 3596 | return(DD_OK); | 
|---|
| 3597 | } | 
|---|
| 3598 | //****************************************************************************** | 
|---|
| 3599 | //****************************************************************************** | 
|---|
| 3600 | HRESULT __stdcall SurfFlip(THIS This, LPDIRECTDRAWSURFACE2 lpDDSurf, DWORD dwFlags) | 
|---|
| 3601 | { | 
|---|
| 3602 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3603 | #ifdef DEBUG | 
|---|
| 3604 | WriteLog("SurfFlip\n"); | 
|---|
| 3605 | #endif | 
|---|
| 3606 |  | 
|---|
| 3607 | return(SurfFlip4(me, (LPDIRECTDRAWSURFACE4) lpDDSurf, dwFlags)); | 
|---|
| 3608 | } | 
|---|
| 3609 | //****************************************************************************** | 
|---|
| 3610 | //****************************************************************************** | 
|---|
| 3611 | HRESULT __stdcall SurfFlip4(THIS This, LPDIRECTDRAWSURFACE4 lpDDSurf, DWORD dwFlags) | 
|---|
| 3612 | { | 
|---|
| 3613 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3614 | OS2IDirectDrawSurface *FlipSurface; | 
|---|
| 3615 | OS2IDirectDrawSurface *FlipCursor; | 
|---|
| 3616 | LPVOID Data; | 
|---|
| 3617 | char *pcrFB,*pcFB,*pcrDB,*pcDB; | 
|---|
| 3618 | ULONG rc; | 
|---|
| 3619 |  | 
|---|
| 3620 | #ifdef DEBUG | 
|---|
| 3621 | WriteLog("SurfFlip4\n"); | 
|---|
| 3622 | #endif | 
|---|
| 3623 | if(!((me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) && | 
|---|
| 3624 | (me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_FLIP)) | 
|---|
| 3625 | ) | 
|---|
| 3626 | { | 
|---|
| 3627 | #ifdef DEBUG | 
|---|
| 3628 | WriteLog("Flip called on none Frontbuffer/Flip surface\n Flags:\n"); | 
|---|
| 3629 | _dump_DDSCAPS(me->DDSurfaceDesc.ddsCaps.dwCaps); | 
|---|
| 3630 | WriteLog("\n"); | 
|---|
| 3631 | #endif | 
|---|
| 3632 | return(DDERR_NOTFLIPPABLE); | 
|---|
| 3633 | } | 
|---|
| 3634 |  | 
|---|
| 3635 | if(NULL!=lpDDSurf) | 
|---|
| 3636 | { | 
|---|
| 3637 | #ifdef DEBUG | 
|---|
| 3638 | WriteLog("Check if Surface is in Flipchain!\n"); | 
|---|
| 3639 | #endif | 
|---|
| 3640 |  | 
|---|
| 3641 | // We got an override surface check if it is in the flipchain | 
|---|
| 3642 | FlipSurface = (OS2IDirectDrawSurface*) lpDDSurf; | 
|---|
| 3643 | FlipCursor = me->BackBuffer; | 
|---|
| 3644 | while((NULL!=FlipCursor)&&(FlipCursor!=FlipSurface)) | 
|---|
| 3645 | { | 
|---|
| 3646 | FlipCursor = FlipCursor->BackBuffer; | 
|---|
| 3647 | } | 
|---|
| 3648 |  | 
|---|
| 3649 | if(FlipCursor!=FlipSurface) | 
|---|
| 3650 | { | 
|---|
| 3651 | #ifdef DEBUG | 
|---|
| 3652 | WriteLog("Surface not in Flipchain!\n"); | 
|---|
| 3653 | #endif | 
|---|
| 3654 | return (DDERR_INVALIDPARAMS); // Not sure if the returnvalue is right | 
|---|
| 3655 | } | 
|---|
| 3656 | } | 
|---|
| 3657 | else | 
|---|
| 3658 | { | 
|---|
| 3659 | FlipSurface = me->NextFlip; // Take the next Surface in the Flipchain | 
|---|
| 3660 | #ifdef DEBUG | 
|---|
| 3661 | WriteLog("Next Surface @ 0x%08X\n",FlipSurface); | 
|---|
| 3662 | #endif | 
|---|
| 3663 | } | 
|---|
| 3664 |  | 
|---|
| 3665 | if((me->fLocked)||(FlipSurface->fLocked)) | 
|---|
| 3666 | { | 
|---|
| 3667 | #ifdef DEBUG | 
|---|
| 3668 | WriteLog("Locked surface(s) Dest %d Src %d\n",me->fLocked,FlipSurface->fLocked); | 
|---|
| 3669 | #endif | 
|---|
| 3670 | return(DDERR_SURFACEBUSY); | 
|---|
| 3671 | } | 
|---|
| 3672 |  | 
|---|
| 3673 | if(-1 != me->diveBufNr) | 
|---|
| 3674 | { | 
|---|
| 3675 | #ifdef DEBUG | 
|---|
| 3676 | WriteLog("DIVE Flipchain"); | 
|---|
| 3677 | #endif | 
|---|
| 3678 |  | 
|---|
| 3679 | // we got some DIVE surfaces | 
|---|
| 3680 | // On Dive Buffers More then Double buffering won't get any perf. gain | 
|---|
| 3681 | // as we have to move all the data to the Frontbuffer and can't simply exchange the pointers | 
|---|
| 3682 | // Doulebuffering should work best. | 
|---|
| 3683 |  | 
|---|
| 3684 | rc = DiveBlitImage(me->hDive, FlipSurface->diveBufNr, me->diveBufNr); | 
|---|
| 3685 |  | 
|---|
| 3686 | #ifdef DEBUG | 
|---|
| 3687 | WriteLog("DiveBlitImage rc = 0x%08X\n"); | 
|---|
| 3688 | #endif | 
|---|
| 3689 |  | 
|---|
| 3690 | if(NULL==lpDDSurf) | 
|---|
| 3691 | { | 
|---|
| 3692 | // advance in the flipchain if no valid override surface was passed in | 
|---|
| 3693 | me->NextFlip = FlipSurface->BackBuffer!=NULL?FlipSurface->BackBuffer:me->BackBuffer; | 
|---|
| 3694 | } | 
|---|
| 3695 | } | 
|---|
| 3696 | else | 
|---|
| 3697 | { | 
|---|
| 3698 | #ifdef DEBUG | 
|---|
| 3699 | WriteLog("Memory Flipchain"); | 
|---|
| 3700 | #endif | 
|---|
| 3701 | // Memory Flipchain | 
|---|
| 3702 | // | 
|---|
| 3703 | // ToDo : Check what happens to src/dest colorkeys etc do the move also ? | 
|---|
| 3704 | // | 
|---|
| 3705 | // We only change the memory pointer to the buffers no need to copy all the data | 
|---|
| 3706 | // So the NextFlip is here allways the Backbuffer so we won't advance this | 
|---|
| 3707 | // | 
|---|
| 3708 | // Sample  (triple buffering) :               Before Flip    After Flip | 
|---|
| 3709 | //                               Buffer:      FB  BB  TB     FB  BB  TB | 
|---|
| 3710 | //                               Memory:      11  22  33     22  33  11 | 
|---|
| 3711 | // | 
|---|
| 3712 |  | 
|---|
| 3713 | Data  = me->DDSurfaceDesc.lpSurface; | 
|---|
| 3714 | pcrFB = me->pFBreal; | 
|---|
| 3715 | pcFB  = me->pFrameBuffer; | 
|---|
| 3716 | pcrDB = me->pDBreal; | 
|---|
| 3717 | pcDB  = me->pDiveBuffer; | 
|---|
| 3718 | me->DDSurfaceDesc.lpSurface = FlipSurface->DDSurfaceDesc.lpSurface; | 
|---|
| 3719 | me->pFBreal                 = FlipSurface->pFBreal; | 
|---|
| 3720 | me->pFrameBuffer            = FlipSurface->pFrameBuffer; | 
|---|
| 3721 | me->pDBreal                 = FlipSurface->pDBreal; | 
|---|
| 3722 | me->pDiveBuffer             = FlipSurface->pDiveBuffer; | 
|---|
| 3723 |  | 
|---|
| 3724 | if(NULL==lpDDSurf) | 
|---|
| 3725 | { | 
|---|
| 3726 | while(NULL!=FlipSurface->BackBuffer) | 
|---|
| 3727 | { | 
|---|
| 3728 | FlipSurface->DDSurfaceDesc.lpSurface = FlipSurface->BackBuffer->DDSurfaceDesc.lpSurface; | 
|---|
| 3729 | FlipSurface->pFBreal                 = FlipSurface->BackBuffer->pFBreal; | 
|---|
| 3730 | FlipSurface->pFrameBuffer            = FlipSurface->BackBuffer->pFrameBuffer; | 
|---|
| 3731 | FlipSurface->pDBreal                 = FlipSurface->BackBuffer->pDBreal; | 
|---|
| 3732 | FlipSurface->pDiveBuffer             = FlipSurface->BackBuffer->pDiveBuffer; | 
|---|
| 3733 | FlipSurface = FlipSurface->BackBuffer; | 
|---|
| 3734 | } | 
|---|
| 3735 | } | 
|---|
| 3736 | FlipSurface->DDSurfaceDesc.lpSurface = Data; | 
|---|
| 3737 | FlipSurface->pFBreal                 = pcrFB; | 
|---|
| 3738 | FlipSurface->pFrameBuffer            = pcFB; | 
|---|
| 3739 | FlipSurface->pDBreal                 = pcrDB; | 
|---|
| 3740 | FlipSurface->pDiveBuffer             = pcDB; | 
|---|
| 3741 | } | 
|---|
| 3742 |  | 
|---|
| 3743 | return(DD_OK); | 
|---|
| 3744 | } | 
|---|
| 3745 | //****************************************************************************** | 
|---|
| 3746 | //****************************************************************************** | 
|---|
| 3747 | HRESULT __stdcall SurfGetAttachedSurface(THIS This, LPDDSCAPS lpDDCaps, | 
|---|
| 3748 | LPDIRECTDRAWSURFACE2 FAR * lpDDSurf) | 
|---|
| 3749 | { | 
|---|
| 3750 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3751 | #ifdef DEBUG | 
|---|
| 3752 | WriteLog("SurfGetAttachedSurface\n"); | 
|---|
| 3753 | #endif | 
|---|
| 3754 |  | 
|---|
| 3755 | return(SurfGetAttachedSurface4(me, (LPDDSCAPS2)lpDDCaps , (LPDIRECTDRAWSURFACE4*)lpDDSurf)); | 
|---|
| 3756 | } | 
|---|
| 3757 | //****************************************************************************** | 
|---|
| 3758 | //****************************************************************************** | 
|---|
| 3759 | HRESULT __stdcall SurfGetAttachedSurface4(THIS This, LPDDSCAPS2 lpDDCaps, | 
|---|
| 3760 | LPDIRECTDRAWSURFACE4 FAR * lpDDSurf) | 
|---|
| 3761 | { | 
|---|
| 3762 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3763 | OS2IDirectDrawSurface *EnumSurface = NULL; | 
|---|
| 3764 | OS2IDirectDrawSurface *AttachedSurface = NULL; | 
|---|
| 3765 | HRESULT rc; | 
|---|
| 3766 | int i; | 
|---|
| 3767 |  | 
|---|
| 3768 | #ifdef DEBUG | 
|---|
| 3769 | WriteLog("SurfGetAttachedSurface4\n>Requested Caps: "); | 
|---|
| 3770 | _dump_DDSCAPS(lpDDCaps->dwCaps); | 
|---|
| 3771 | WriteLog("\n"); | 
|---|
| 3772 | #endif | 
|---|
| 3773 |  | 
|---|
| 3774 | if( (NULL==lpDDCaps)||(NULL==lpDDSurf)) | 
|---|
| 3775 | { | 
|---|
| 3776 | WriteLog("Invalid params\n\n"); | 
|---|
| 3777 | return (DDERR_INVALIDPARAMS); | 
|---|
| 3778 | } | 
|---|
| 3779 |  | 
|---|
| 3780 |  | 
|---|
| 3781 | rc = DD_OK; | 
|---|
| 3782 |  | 
|---|
| 3783 | if( (me->BackBuffer!=NULL) && | 
|---|
| 3784 | (me->BackBuffer->DDSurfaceDesc.ddsCaps.dwCaps & lpDDCaps->dwCaps) ) | 
|---|
| 3785 | { | 
|---|
| 3786 | WriteLog("Return Backbuffer\n"); | 
|---|
| 3787 | AttachedSurface = me->BackBuffer; | 
|---|
| 3788 | } | 
|---|
| 3789 |  | 
|---|
| 3790 | if(DPA_GetPtrCount(me->DPA_SurfaceMipMaps)>0) | 
|---|
| 3791 | { | 
|---|
| 3792 | i=0; | 
|---|
| 3793 | while( i<DPA_GetPtrCount(me->DPA_SurfaceMipMaps) ) | 
|---|
| 3794 | { | 
|---|
| 3795 | EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceMipMaps,i); | 
|---|
| 3796 | if(EnumSurface->DDSurfaceDesc.ddsCaps.dwCaps == lpDDCaps->dwCaps) | 
|---|
| 3797 | { | 
|---|
| 3798 | if(NULL==AttachedSurface) | 
|---|
| 3799 | AttachedSurface = EnumSurface; | 
|---|
| 3800 | else | 
|---|
| 3801 | rc = DDERR_NOTFOUND; // Not sure if this is the right return value, | 
|---|
| 3802 | // but function must fail if more then one surface fits | 
|---|
| 3803 |  | 
|---|
| 3804 | } | 
|---|
| 3805 | i++; | 
|---|
| 3806 | } | 
|---|
| 3807 | } | 
|---|
| 3808 |  | 
|---|
| 3809 | if(DPA_GetPtrCount(me->DPA_SurfaceAttached)>0) | 
|---|
| 3810 | { | 
|---|
| 3811 | i=0; | 
|---|
| 3812 | while( i<DPA_GetPtrCount(me->DPA_SurfaceAttached) ) | 
|---|
| 3813 | { | 
|---|
| 3814 | EnumSurface = (OS2IDirectDrawSurface*) DPA_FastGetPtr(me->DPA_SurfaceAttached,i); | 
|---|
| 3815 | if(EnumSurface->DDSurfaceDesc.ddsCaps.dwCaps == lpDDCaps->dwCaps) | 
|---|
| 3816 | { | 
|---|
| 3817 | if(NULL==AttachedSurface) | 
|---|
| 3818 | AttachedSurface = EnumSurface; | 
|---|
| 3819 | else | 
|---|
| 3820 | rc = DDERR_NOTFOUND; // Not sure if this is the right return value, | 
|---|
| 3821 | // but function must fail if more then one surface fits | 
|---|
| 3822 |  | 
|---|
| 3823 | } | 
|---|
| 3824 | i++; | 
|---|
| 3825 | } | 
|---|
| 3826 | } | 
|---|
| 3827 |  | 
|---|
| 3828 | if( (DD_OK==rc) && | 
|---|
| 3829 | (NULL!=AttachedSurface) ) | 
|---|
| 3830 | { | 
|---|
| 3831 | *lpDDSurf = (IDirectDrawSurface4*)AttachedSurface; | 
|---|
| 3832 | // not sure but as we returned an reference rains usage count | 
|---|
| 3833 | AttachedSurface->lpVtbl->AddRef(AttachedSurface); | 
|---|
| 3834 | } | 
|---|
| 3835 | else | 
|---|
| 3836 | { | 
|---|
| 3837 | *lpDDSurf = NULL; | 
|---|
| 3838 | rc = DDERR_NOTFOUND; | 
|---|
| 3839 | } | 
|---|
| 3840 |  | 
|---|
| 3841 |  | 
|---|
| 3842 | return rc; | 
|---|
| 3843 | } | 
|---|
| 3844 | //****************************************************************************** | 
|---|
| 3845 | //****************************************************************************** | 
|---|
| 3846 | HRESULT __stdcall SurfGetBltStatus(THIS This, DWORD) | 
|---|
| 3847 | { | 
|---|
| 3848 | #ifdef DEBUG | 
|---|
| 3849 | WriteLog("SurfGetBltStatus\n"); | 
|---|
| 3850 | #endif | 
|---|
| 3851 |  | 
|---|
| 3852 | return(DD_OK); | 
|---|
| 3853 | } | 
|---|
| 3854 | //****************************************************************************** | 
|---|
| 3855 | //****************************************************************************** | 
|---|
| 3856 | HRESULT __stdcall SurfGetCaps(THIS This, LPDDSCAPS lpDDCaps) | 
|---|
| 3857 | { | 
|---|
| 3858 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3859 |  | 
|---|
| 3860 | #ifdef DEBUG | 
|---|
| 3861 | WriteLog("SurfGetCaps\n"); | 
|---|
| 3862 | #endif | 
|---|
| 3863 |  | 
|---|
| 3864 | if(NULL==lpDDCaps) | 
|---|
| 3865 | return(DDERR_INVALIDPARAMS); | 
|---|
| 3866 |  | 
|---|
| 3867 | lpDDCaps->dwCaps = me->DDSurfaceDesc.ddsCaps.dwCaps; | 
|---|
| 3868 | #ifdef DEBUG | 
|---|
| 3869 | _dump_DDSCAPS(lpDDCaps->dwCaps); | 
|---|
| 3870 | #endif | 
|---|
| 3871 | return(DD_OK); | 
|---|
| 3872 | } | 
|---|
| 3873 | //****************************************************************************** | 
|---|
| 3874 | //****************************************************************************** | 
|---|
| 3875 | HRESULT __stdcall SurfGetCaps4(THIS This, LPDDSCAPS2 lpDDCaps) | 
|---|
| 3876 | { | 
|---|
| 3877 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3878 | #ifdef DEBUG | 
|---|
| 3879 | WriteLog("SurfGetCaps4\n"); | 
|---|
| 3880 | #endif | 
|---|
| 3881 |  | 
|---|
| 3882 | if(NULL==lpDDCaps) | 
|---|
| 3883 | return(DDERR_INVALIDPARAMS); | 
|---|
| 3884 |  | 
|---|
| 3885 | memcpy(lpDDCaps, &(me->DDSurfaceDesc.ddsCaps), sizeof(DDSCAPS2) ); | 
|---|
| 3886 | #ifdef DEBUG | 
|---|
| 3887 | _dump_DDSCAPS(lpDDCaps->dwCaps); | 
|---|
| 3888 | _dump_DDSCAPS2(lpDDCaps->dwCaps2); | 
|---|
| 3889 |  | 
|---|
| 3890 | #endif | 
|---|
| 3891 |  | 
|---|
| 3892 | return(DD_OK); | 
|---|
| 3893 | } | 
|---|
| 3894 | //****************************************************************************** | 
|---|
| 3895 | //****************************************************************************** | 
|---|
| 3896 | HRESULT __stdcall SurfGetClipper(THIS This, LPDIRECTDRAWCLIPPER FAR *lplpClipper) | 
|---|
| 3897 | { | 
|---|
| 3898 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3899 |  | 
|---|
| 3900 | #ifdef DEBUG | 
|---|
| 3901 | WriteLog("SurfGetClipper\n"); | 
|---|
| 3902 | #endif | 
|---|
| 3903 |  | 
|---|
| 3904 | if(me->lpClipper) | 
|---|
| 3905 | { | 
|---|
| 3906 | *lplpClipper = (LPDIRECTDRAWCLIPPER) me->lpClipper; | 
|---|
| 3907 | return(DD_OK); | 
|---|
| 3908 | } | 
|---|
| 3909 | else | 
|---|
| 3910 | return(DDERR_NOCLIPPERATTACHED); | 
|---|
| 3911 | } | 
|---|
| 3912 | //****************************************************************************** | 
|---|
| 3913 | //****************************************************************************** | 
|---|
| 3914 | HRESULT __stdcall SurfGetColorKey(THIS This, DWORD dwFlags, LPDDCOLORKEY lpDDColKey) | 
|---|
| 3915 | { | 
|---|
| 3916 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3917 |  | 
|---|
| 3918 | #ifdef DEBUG | 
|---|
| 3919 | WriteLog("SurfGetColorKey\n"); | 
|---|
| 3920 | #endif | 
|---|
| 3921 |  | 
|---|
| 3922 | if ((0==dwFlags) || (NULL==lpDDColKey)) | 
|---|
| 3923 | return (DDERR_INVALIDPARAMS); | 
|---|
| 3924 |  | 
|---|
| 3925 | // as we report only src colorkey in the caps return error on all others flags | 
|---|
| 3926 | if( (DDCKEY_DESTBLT|DDCKEY_DESTOVERLAY|DDCKEY_SRCOVERLAY) & dwFlags) | 
|---|
| 3927 | return(DDERR_UNSUPPORTED); | 
|---|
| 3928 |  | 
|---|
| 3929 | if(me->DDSurfaceDesc.dwFlags & dwFlags) | 
|---|
| 3930 | { | 
|---|
| 3931 | if(DDCKEY_SRCBLT & dwFlags) | 
|---|
| 3932 | { | 
|---|
| 3933 | memcpy(lpDDColKey,&(me->DDSurfaceDesc.ddckCKSrcBlt),sizeof(DDCOLORKEY) ); | 
|---|
| 3934 | } | 
|---|
| 3935 | else | 
|---|
| 3936 | return (DDERR_INVALIDPARAMS); // some other flags where set => error | 
|---|
| 3937 | } | 
|---|
| 3938 | else | 
|---|
| 3939 | return(DDERR_NOCOLORKEY); // surface doesn't have a color key set | 
|---|
| 3940 |  | 
|---|
| 3941 | return (DD_OK); | 
|---|
| 3942 | } | 
|---|
| 3943 | //****************************************************************************** | 
|---|
| 3944 | //****************************************************************************** | 
|---|
| 3945 | HRESULT __stdcall SurfGetDC(THIS This, HDC FAR *hdc) | 
|---|
| 3946 | { | 
|---|
| 3947 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 3948 | DDSURFACEDESC2        LockedSurfaceDesc; | 
|---|
| 3949 | HRESULT rc; | 
|---|
| 3950 | BITMAP bmpSurface; | 
|---|
| 3951 | struct | 
|---|
| 3952 | { | 
|---|
| 3953 | BITMAPINFOHEADER  bmiHead; | 
|---|
| 3954 | RGBQUAD           bmiCols[256]; | 
|---|
| 3955 | } BitmapInfo; | 
|---|
| 3956 |  | 
|---|
| 3957 | #ifdef DEBUG | 
|---|
| 3958 | WriteLog("SurfGetDC\n"); | 
|---|
| 3959 | #endif | 
|---|
| 3960 |  | 
|---|
| 3961 | if (NULL==hdc) | 
|---|
| 3962 | return(DDERR_INVALIDPARAMS); | 
|---|
| 3963 |  | 
|---|
| 3964 | LockedSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2); | 
|---|
| 3965 |  | 
|---|
| 3966 | if(DD_OK != me->Vtbl.Lock(me,NULL,&LockedSurfaceDesc,0,0)) | 
|---|
| 3967 | { | 
|---|
| 3968 | return(DDERR_DCALREADYCREATED); | 
|---|
| 3969 | } | 
|---|
| 3970 |  | 
|---|
| 3971 | rc = DD_OK; | 
|---|
| 3972 |  | 
|---|
| 3973 | if(me->hdcImage == NULL) | 
|---|
| 3974 | { | 
|---|
| 3975 | // Create a Device context | 
|---|
| 3976 | me->hdcImage = CreateCompatibleDC(NULL); | 
|---|
| 3977 | if(me->hdcImage == NULL) | 
|---|
| 3978 | { | 
|---|
| 3979 | #ifdef DEBUG | 
|---|
| 3980 | WriteLog("Can't create compatible DC!\n"); | 
|---|
| 3981 | #endif | 
|---|
| 3982 | me->Vtbl.Unlock(me,NULL); | 
|---|
| 3983 | rc = DDERR_GENERIC; | 
|---|
| 3984 | } | 
|---|
| 3985 | } | 
|---|
| 3986 |  | 
|---|
| 3987 | if( (DD_OK==rc) && | 
|---|
| 3988 | (me->hbmImage == NULL) ) | 
|---|
| 3989 | { | 
|---|
| 3990 | WriteLog( "Trying to create Bitmap (%d/%d) at %d Bit\n", | 
|---|
| 3991 | LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3), | 
|---|
| 3992 | LockedSurfaceDesc.dwHeight, | 
|---|
| 3993 | LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount | 
|---|
| 3994 | ); | 
|---|
| 3995 | #if 0 | 
|---|
| 3996 | memset(&BitmapInfo, 0, sizeof(BitmapInfo)); | 
|---|
| 3997 | BitmapInfo.bmiHead.biSize   = sizeof(BITMAPINFOHEADER); | 
|---|
| 3998 | BitmapInfo.bmiHead.biWidth  = LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3); | 
|---|
| 3999 | BitmapInfo.bmiHead.biHeight = LockedSurfaceDesc.dwHeight; | 
|---|
| 4000 | BitmapInfo.bmiHead.biPlanes = 1; | 
|---|
| 4001 | BitmapInfo.bmiHead.biBitCount    = LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; | 
|---|
| 4002 | #else | 
|---|
| 4003 | bmpSurface.bmType       = 0; | 
|---|
| 4004 | bmpSurface.bmWidth      = LockedSurfaceDesc.dwWidth; | 
|---|
| 4005 | bmpSurface.bmHeight     = LockedSurfaceDesc.dwHeight; | 
|---|
| 4006 | bmpSurface.bmWidthBytes = LockedSurfaceDesc.lPitch; | 
|---|
| 4007 | bmpSurface.bmPlanes     = 1; | 
|---|
| 4008 | bmpSurface.bmBits       = LockedSurfaceDesc.lpSurface; | 
|---|
| 4009 | #endif | 
|---|
| 4010 | switch(LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4011 | { | 
|---|
| 4012 | case 1: | 
|---|
| 4013 | case 4: | 
|---|
| 4014 | WriteLog("1/4 Bit Not yet supported\n"); | 
|---|
| 4015 | break; | 
|---|
| 4016 | case 8: | 
|---|
| 4017 | #if 0 | 
|---|
| 4018 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4019 | GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]); | 
|---|
| 4020 | me->hbmImage = CreateDIBitmap( me->hdcImage, | 
|---|
| 4021 | NULL, | 
|---|
| 4022 | CBM_CREATEDIB, | 
|---|
| 4023 | LockedSurfaceDesc.lpSurface, | 
|---|
| 4024 | (PBITMAPINFO)&BitmapInfo, | 
|---|
| 4025 | DIB_RGB_COLORS); | 
|---|
| 4026 | #else | 
|---|
| 4027 | bmpSurface.bmBitsPixel  = 8; | 
|---|
| 4028 | me->hbmImage = CreateBitmapIndirect( &bmpSurface); | 
|---|
| 4029 | #endif | 
|---|
| 4030 | break; | 
|---|
| 4031 | case 16: | 
|---|
| 4032 | case 32: | 
|---|
| 4033 | WriteLog("16/32 Bit not supported by OS/2"); | 
|---|
| 4034 | break; | 
|---|
| 4035 | case 24: | 
|---|
| 4036 | #if 0 | 
|---|
| 4037 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4038 | me->hbmImage = CreateDIBitmap( me->hdcImage, | 
|---|
| 4039 | NULL, | 
|---|
| 4040 | CBM_CREATEDIB, | 
|---|
| 4041 | LockedSurfaceDesc.lpSurface, | 
|---|
| 4042 | (PBITMAPINFO)&BitmapInfo, | 
|---|
| 4043 | DIB_RGB_COLORS); | 
|---|
| 4044 | #else | 
|---|
| 4045 | bmpSurface.bmBitsPixel  = 24; | 
|---|
| 4046 | me->hbmImage = CreateBitmapIndirect( &bmpSurface); | 
|---|
| 4047 | #endif | 
|---|
| 4048 | break; | 
|---|
| 4049 | default: | 
|---|
| 4050 | #ifdef DEBUG | 
|---|
| 4051 | WriteLog( "Unexptected BitCount %d \n", | 
|---|
| 4052 | LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount); | 
|---|
| 4053 | #endif | 
|---|
| 4054 | me->hbmImage=NULL; | 
|---|
| 4055 | } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4056 |  | 
|---|
| 4057 | if(me->hbmImage == NULL) | 
|---|
| 4058 | { | 
|---|
| 4059 | #ifdef DEBUG | 
|---|
| 4060 | WriteLog("Can't create bitmap!\n"); | 
|---|
| 4061 | #endif | 
|---|
| 4062 | DeleteDC(me->hdcImage); | 
|---|
| 4063 | me->hdcImage = NULL; | 
|---|
| 4064 | me->Vtbl.Unlock(me,NULL); | 
|---|
| 4065 | rc = DDERR_GENERIC; | 
|---|
| 4066 | } | 
|---|
| 4067 | } | 
|---|
| 4068 | else | 
|---|
| 4069 | { | 
|---|
| 4070 | if( (DD_OK==rc) && | 
|---|
| 4071 | (me->dwLastDCUnique != me->dwUniqueValue) ) | 
|---|
| 4072 | { | 
|---|
| 4073 | #ifdef DEBUG | 
|---|
| 4074 | WriteLog("The Surface was locked/unlocked after the last DC was created =>Update Bitmap!\n"); | 
|---|
| 4075 | #endif | 
|---|
| 4076 |  | 
|---|
| 4077 | memset(&BitmapInfo,0, sizeof(BitmapInfo)); | 
|---|
| 4078 | BitmapInfo.bmiHead.biSize     = sizeof(BITMAPINFOHEADER); | 
|---|
| 4079 | BitmapInfo.bmiHead.biWidth    = LockedSurfaceDesc.lPitch/ (LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3); | 
|---|
| 4080 | BitmapInfo.bmiHead.biHeight   = LockedSurfaceDesc.dwHeight; | 
|---|
| 4081 | BitmapInfo.bmiHead.biPlanes   = 1; | 
|---|
| 4082 | BitmapInfo.bmiHead.biBitCount = LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; | 
|---|
| 4083 |  | 
|---|
| 4084 | switch(LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4085 | { | 
|---|
| 4086 | case 1: | 
|---|
| 4087 | case 4: | 
|---|
| 4088 | case 8: | 
|---|
| 4089 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4090 | GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]); | 
|---|
| 4091 | SetDIBits(me->hdcImage, me->hbmImage, 0, LockedSurfaceDesc.dwHeight, | 
|---|
| 4092 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS); | 
|---|
| 4093 | break; | 
|---|
| 4094 | case 16: | 
|---|
| 4095 | case 32: | 
|---|
| 4096 | BitmapInfo.bmiHead.biCompression = BI_BITFIELDS; | 
|---|
| 4097 | BitmapInfo.bmiHead.biClrUsed     = 3; | 
|---|
| 4098 | *((DWORD *) &(BitmapInfo.bmiCols[0])) = me->DDSurfaceDesc.ddpfPixelFormat.dwRBitMask; | 
|---|
| 4099 | *((DWORD *) &(BitmapInfo.bmiCols[1])) = me->DDSurfaceDesc.ddpfPixelFormat.dwGBitMask; | 
|---|
| 4100 | *((DWORD *) &(BitmapInfo.bmiCols[2])) = me->DDSurfaceDesc.ddpfPixelFormat.dwBBitMask; | 
|---|
| 4101 | SetDIBits(me->hdcImage, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4102 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS); | 
|---|
| 4103 | break; | 
|---|
| 4104 | case 24: | 
|---|
| 4105 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4106 | SetDIBits(me->hdcImage, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4107 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS); | 
|---|
| 4108 | break; | 
|---|
| 4109 | default: | 
|---|
| 4110 | #ifdef DEBUG | 
|---|
| 4111 | WriteLog("Unexptected BitCount %d => Bitmap not updated!\n",LockedSurfaceDesc.ddpfPixelFormat.dwRGBBitCount); | 
|---|
| 4112 | #endif | 
|---|
| 4113 | break; | 
|---|
| 4114 | } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4115 |  | 
|---|
| 4116 | } | 
|---|
| 4117 | } | 
|---|
| 4118 |  | 
|---|
| 4119 | // Allways select the bitmap into the DC! No matter if the old or a new one | 
|---|
| 4120 |  | 
|---|
| 4121 | if(DD_OK==rc) | 
|---|
| 4122 | { | 
|---|
| 4123 | if((me->hgdiOld = SelectObject(me->hdcImage, me->hbmImage)) == NULL) | 
|---|
| 4124 | { | 
|---|
| 4125 | #ifdef DEBUG | 
|---|
| 4126 | WriteLog("Can't select bitmap into dc!\n"); | 
|---|
| 4127 | #endif | 
|---|
| 4128 | DeleteDC(me->hdcImage); | 
|---|
| 4129 | me->hdcImage = NULL; | 
|---|
| 4130 | DeleteObject(me->hbmImage); | 
|---|
| 4131 | me->hbmImage = NULL; | 
|---|
| 4132 | me->Vtbl.Unlock(me,NULL); | 
|---|
| 4133 | rc = DDERR_GENERIC; | 
|---|
| 4134 | } | 
|---|
| 4135 | else | 
|---|
| 4136 | { | 
|---|
| 4137 | *hdc = me->hdcImage; | 
|---|
| 4138 | } | 
|---|
| 4139 | } | 
|---|
| 4140 |  | 
|---|
| 4141 | return rc; | 
|---|
| 4142 | } | 
|---|
| 4143 | //****************************************************************************** | 
|---|
| 4144 | //****************************************************************************** | 
|---|
| 4145 | HRESULT __stdcall SurfGetFlipStatus(THIS This, DWORD dwFlags) | 
|---|
| 4146 | { | 
|---|
| 4147 | #ifdef DEBUG | 
|---|
| 4148 | WriteLog("SurfGetFlipStatus\n"); | 
|---|
| 4149 | #endif | 
|---|
| 4150 |  | 
|---|
| 4151 | if( (DDGFS_CANFLIP!=dwFlags) && (DDGFS_ISFLIPDONE!=dwFlags) ) | 
|---|
| 4152 | return DDERR_INVALIDPARAMS; | 
|---|
| 4153 |  | 
|---|
| 4154 | return(DD_OK); | 
|---|
| 4155 | } | 
|---|
| 4156 | //****************************************************************************** | 
|---|
| 4157 | //****************************************************************************** | 
|---|
| 4158 | HRESULT __stdcall SurfGetOverlayPosition(THIS This, LPLONG lplX, LPLONG lplY) | 
|---|
| 4159 | { | 
|---|
| 4160 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4161 | #ifdef DEBUG | 
|---|
| 4162 | WriteLog("SurfGetOverlayPosition\n"); | 
|---|
| 4163 | #endif | 
|---|
| 4164 |  | 
|---|
| 4165 | // Maybe simply return dderr_notsupported as we retun a max overlay value of 0 in the caps ? | 
|---|
| 4166 |  | 
|---|
| 4167 | if( (NULL==lplX) || (NULL==lplY)) | 
|---|
| 4168 | return DDERR_INVALIDPARAMS; | 
|---|
| 4169 |  | 
|---|
| 4170 | if(!(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_OVERLAY)) | 
|---|
| 4171 | return DDERR_NOTAOVERLAYSURFACE; | 
|---|
| 4172 |  | 
|---|
| 4173 | if(!(me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_VISIBLE)) | 
|---|
| 4174 | return DDERR_OVERLAYNOTVISIBLE; | 
|---|
| 4175 |  | 
|---|
| 4176 | if(!me->fOverlayValid) | 
|---|
| 4177 | return DDERR_NOOVERLAYDEST; | 
|---|
| 4178 |  | 
|---|
| 4179 | *lplX = me->lOverlayX; | 
|---|
| 4180 | *lplY = me->lOverlayY; | 
|---|
| 4181 |  | 
|---|
| 4182 | return(DD_OK); | 
|---|
| 4183 | } | 
|---|
| 4184 | //****************************************************************************** | 
|---|
| 4185 | //****************************************************************************** | 
|---|
| 4186 | HRESULT __stdcall SurfGetPalette(THIS This, LPDIRECTDRAWPALETTE FAR *lplpPalette) | 
|---|
| 4187 | { | 
|---|
| 4188 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4189 |  | 
|---|
| 4190 | #ifdef DEBUG | 
|---|
| 4191 | WriteLog("SurfGetPalette\n"); | 
|---|
| 4192 | #endif | 
|---|
| 4193 |  | 
|---|
| 4194 | if(me->lpPalette) | 
|---|
| 4195 | { | 
|---|
| 4196 | *lplpPalette = (LPDIRECTDRAWPALETTE)me->lpPalette; | 
|---|
| 4197 | return(DD_OK); | 
|---|
| 4198 | } | 
|---|
| 4199 | else | 
|---|
| 4200 | return(DDERR_NOPALETTEATTACHED); | 
|---|
| 4201 | } | 
|---|
| 4202 | //****************************************************************************** | 
|---|
| 4203 | //****************************************************************************** | 
|---|
| 4204 | HRESULT __stdcall SurfGetPixelFormat(THIS This, LPDDPIXELFORMAT lpPixelFormat) | 
|---|
| 4205 | { | 
|---|
| 4206 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4207 |  | 
|---|
| 4208 | #ifdef DEBUG | 
|---|
| 4209 | WriteLog("SurfGetPixelFormat\n"); | 
|---|
| 4210 | #endif | 
|---|
| 4211 |  | 
|---|
| 4212 | if(NULL==lpPixelFormat) | 
|---|
| 4213 | return DDERR_INVALIDPARAMS; | 
|---|
| 4214 |  | 
|---|
| 4215 | memcpy( (char*)lpPixelFormat, | 
|---|
| 4216 | (char*)&(me->DDSurfaceDesc.ddpfPixelFormat), | 
|---|
| 4217 | sizeof(DDPIXELFORMAT)); | 
|---|
| 4218 |  | 
|---|
| 4219 | return(DD_OK); | 
|---|
| 4220 | } | 
|---|
| 4221 | //****************************************************************************** | 
|---|
| 4222 | //****************************************************************************** | 
|---|
| 4223 | HRESULT __stdcall SurfGetSurfaceDesc(THIS This, LPDDSURFACEDESC lpSurface) | 
|---|
| 4224 | { | 
|---|
| 4225 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4226 |  | 
|---|
| 4227 | #ifdef DEBUG | 
|---|
| 4228 | WriteLog("SurfGetSurfaceDesc\n"); | 
|---|
| 4229 | #endif | 
|---|
| 4230 |  | 
|---|
| 4231 | if((lpSurface == NULL)||(lpSurface->dwSize != sizeof(DDSURFACEDESC)) ) | 
|---|
| 4232 | return(DDERR_INVALIDPARAMS); | 
|---|
| 4233 |  | 
|---|
| 4234 | memcpy( (char *)lpSurface, | 
|---|
| 4235 | (char *)&me->DDSurfaceDesc, | 
|---|
| 4236 | sizeof(DDSURFACEDESC)); | 
|---|
| 4237 |  | 
|---|
| 4238 | return(DD_OK); | 
|---|
| 4239 | } | 
|---|
| 4240 | //****************************************************************************** | 
|---|
| 4241 | //****************************************************************************** | 
|---|
| 4242 | HRESULT __stdcall SurfGetSurfaceDesc4(THIS This, LPDDSURFACEDESC2 lpSurface) | 
|---|
| 4243 | { | 
|---|
| 4244 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4245 |  | 
|---|
| 4246 | #ifdef DEBUG | 
|---|
| 4247 | WriteLog("SurfGetSurfaceDesc4\n"); | 
|---|
| 4248 | #endif | 
|---|
| 4249 |  | 
|---|
| 4250 | if((lpSurface == NULL)||(lpSurface->dwSize != sizeof(DDSURFACEDESC2)) ) | 
|---|
| 4251 | return(DDERR_INVALIDPARAMS); | 
|---|
| 4252 |  | 
|---|
| 4253 | memcpy( (char *)lpSurface, | 
|---|
| 4254 | (char *)&me->DDSurfaceDesc, | 
|---|
| 4255 | sizeof(DDSURFACEDESC2)); | 
|---|
| 4256 |  | 
|---|
| 4257 | return(DD_OK); | 
|---|
| 4258 | } | 
|---|
| 4259 | //****************************************************************************** | 
|---|
| 4260 | //****************************************************************************** | 
|---|
| 4261 | HRESULT __stdcall SurfInitialize(THIS, LPDIRECTDRAW, LPDDSURFACEDESC) | 
|---|
| 4262 | { | 
|---|
| 4263 | #ifdef DEBUG | 
|---|
| 4264 | WriteLog("SurfInitialize\n"); | 
|---|
| 4265 | #endif | 
|---|
| 4266 |  | 
|---|
| 4267 | return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc | 
|---|
| 4268 | } | 
|---|
| 4269 | //****************************************************************************** | 
|---|
| 4270 | //****************************************************************************** | 
|---|
| 4271 | HRESULT __stdcall SurfInitialize4(THIS, LPDIRECTDRAW, LPDDSURFACEDESC2) | 
|---|
| 4272 | { | 
|---|
| 4273 | #ifdef DEBUG | 
|---|
| 4274 | WriteLog("SurfInitialize\n"); | 
|---|
| 4275 | #endif | 
|---|
| 4276 |  | 
|---|
| 4277 | return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc | 
|---|
| 4278 | } | 
|---|
| 4279 | //****************************************************************************** | 
|---|
| 4280 | //****************************************************************************** | 
|---|
| 4281 | HRESULT __stdcall SurfIsLost(THIS) | 
|---|
| 4282 | { | 
|---|
| 4283 | // We don't loose any surface ;) | 
|---|
| 4284 | // But we might shoud check for primary and/or Dive Buffers as I don't know | 
|---|
| 4285 | // if  they are preserved if switching to a FS DOS/OS2 session | 
|---|
| 4286 | // | 
|---|
| 4287 | #ifdef DEBUG | 
|---|
| 4288 | WriteLog("SurfIsLost\n"); | 
|---|
| 4289 | #endif | 
|---|
| 4290 |  | 
|---|
| 4291 | return(DD_OK); | 
|---|
| 4292 | } | 
|---|
| 4293 | //****************************************************************************** | 
|---|
| 4294 | //****************************************************************************** | 
|---|
| 4295 | HRESULT __stdcall SurfLock( THIS This, | 
|---|
| 4296 | LPRECT lpRect, | 
|---|
| 4297 | LPDDSURFACEDESC lpSurfaceDesc, | 
|---|
| 4298 | DWORD dwFlags, | 
|---|
| 4299 | HANDLE hEvent) | 
|---|
| 4300 | { | 
|---|
| 4301 | DDSURFACEDESC2 SurfaceDesc4; | 
|---|
| 4302 | HRESULT rc; | 
|---|
| 4303 |  | 
|---|
| 4304 | #ifdef DEBUG | 
|---|
| 4305 | WriteLog("SurfLock %d %08X %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent); | 
|---|
| 4306 | #endif | 
|---|
| 4307 |  | 
|---|
| 4308 | if((NULL==lpSurfaceDesc)||(NULL!=hEvent)) | 
|---|
| 4309 | return DDERR_INVALIDPARAMS; | 
|---|
| 4310 |  | 
|---|
| 4311 | if(lpSurfaceDesc->dwSize != sizeof(DDSURFACEDESC)) | 
|---|
| 4312 | return DDERR_INVALIDPARAMS; | 
|---|
| 4313 |  | 
|---|
| 4314 | SurfaceDesc4.dwSize = sizeof(DDSURFACEDESC2); | 
|---|
| 4315 |  | 
|---|
| 4316 | rc = SurfLock4( This, | 
|---|
| 4317 | lpRect, | 
|---|
| 4318 | &SurfaceDesc4, | 
|---|
| 4319 | dwFlags, | 
|---|
| 4320 | hEvent); | 
|---|
| 4321 | if (DD_OK==rc) | 
|---|
| 4322 | { | 
|---|
| 4323 | memcpy( (char*)lpSurfaceDesc, | 
|---|
| 4324 | (char*)&SurfaceDesc4, | 
|---|
| 4325 | sizeof(DDSURFACEDESC) ); | 
|---|
| 4326 | } | 
|---|
| 4327 |  | 
|---|
| 4328 | return(rc); | 
|---|
| 4329 | } | 
|---|
| 4330 | //****************************************************************************** | 
|---|
| 4331 | //****************************************************************************** | 
|---|
| 4332 | HRESULT __stdcall SurfLock4( THIS This, | 
|---|
| 4333 | LPRECT lpRect, | 
|---|
| 4334 | LPDDSURFACEDESC2 lpSurfaceDesc, | 
|---|
| 4335 | DWORD dwFlags, | 
|---|
| 4336 | HANDLE hEvent) | 
|---|
| 4337 | { | 
|---|
| 4338 |  | 
|---|
| 4339 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4340 | int i; | 
|---|
| 4341 |  | 
|---|
| 4342 | BOOL Found; | 
|---|
| 4343 | ULONG  nrScanLines; | 
|---|
| 4344 | char *pBuffer; | 
|---|
| 4345 | DDRectangle *pIRectCurrent,*pIRectNew; | 
|---|
| 4346 | static int times = 0; | 
|---|
| 4347 | HRESULT rc; | 
|---|
| 4348 |  | 
|---|
| 4349 | #ifdef DEBUG | 
|---|
| 4350 | WriteLog("SurfLock4 %08X %08X %d %d\n", (int)lpRect, (int)lpSurfaceDesc, dwFlags, hEvent); | 
|---|
| 4351 | #endif | 
|---|
| 4352 |  | 
|---|
| 4353 | if( (NULL==lpSurfaceDesc) || | 
|---|
| 4354 | (NULL!=hEvent) | 
|---|
| 4355 | ) | 
|---|
| 4356 | return DDERR_INVALIDPARAMS; | 
|---|
| 4357 |  | 
|---|
| 4358 |  | 
|---|
| 4359 | if (NULL!=lpRect) | 
|---|
| 4360 | pIRectNew = new DDRectangle( lpRect->left, lpRect->top, lpRect->bottom, lpRect->right ); | 
|---|
| 4361 | else | 
|---|
| 4362 | pIRectNew = new DDRectangle( 0, 0, me->height, me->width); | 
|---|
| 4363 |  | 
|---|
| 4364 | // ToDo : the lockchecking should be done in a critcal seq. | 
|---|
| 4365 | WriteLog( "Lock Rectangle (%d/%d) x (%d/%d)\n", | 
|---|
| 4366 | pIRectNew->Top(), | 
|---|
| 4367 | pIRectNew->Left(), | 
|---|
| 4368 | pIRectNew->Bottom(), | 
|---|
| 4369 | pIRectNew->Right() ); | 
|---|
| 4370 |  | 
|---|
| 4371 | rc = DD_OK; | 
|---|
| 4372 |  | 
|---|
| 4373 | if(me->fLocked) | 
|---|
| 4374 | { | 
|---|
| 4375 | if (NULL==lpRect) | 
|---|
| 4376 | { | 
|---|
| 4377 | // If anything is locked we can't locke the complete surface | 
|---|
| 4378 | WriteLog("Surface has locked Rectangles, and we want to complete lock it\n"); | 
|---|
| 4379 | Found = TRUE; | 
|---|
| 4380 | } | 
|---|
| 4381 | else | 
|---|
| 4382 | { | 
|---|
| 4383 | // If the new Rectangle intersects with any of the already locked rectangles it can't | 
|---|
| 4384 | // be locked so check for this | 
|---|
| 4385 |  | 
|---|
| 4386 | WriteLog("Surface has locked Rectangles, check if the overlap\n"); | 
|---|
| 4387 |  | 
|---|
| 4388 | i=0; | 
|---|
| 4389 | Found = FALSE; | 
|---|
| 4390 |  | 
|---|
| 4391 | while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found) | 
|---|
| 4392 | { | 
|---|
| 4393 | pIRectCurrent = (DDRectangle*) DPA_FastGetPtr(me->DPA_LockedRects,i); | 
|---|
| 4394 | WriteLog( "Test with Rectangle (%d/%d) x (%d/%d)\n", | 
|---|
| 4395 | pIRectCurrent->Top(), | 
|---|
| 4396 | pIRectCurrent->Left(), | 
|---|
| 4397 | pIRectCurrent->Bottom(), | 
|---|
| 4398 | pIRectCurrent->Right() ); | 
|---|
| 4399 | Found = pIRectCurrent->intersects(*pIRectNew); | 
|---|
| 4400 | i++; | 
|---|
| 4401 | } | 
|---|
| 4402 |  | 
|---|
| 4403 | } | 
|---|
| 4404 |  | 
|---|
| 4405 | if (Found) | 
|---|
| 4406 | { | 
|---|
| 4407 | delete pIRectNew; | 
|---|
| 4408 | #ifdef DEBUG | 
|---|
| 4409 | WriteLog("SurfLock4: Surface already locked\n\n"); | 
|---|
| 4410 | #endif | 
|---|
| 4411 | rc = DDERR_SURFACEBUSY; | 
|---|
| 4412 | } | 
|---|
| 4413 |  | 
|---|
| 4414 | } | 
|---|
| 4415 |  | 
|---|
| 4416 | if(DD_OK == rc) | 
|---|
| 4417 | { | 
|---|
| 4418 | memcpy((char *)lpSurfaceDesc, (char *)&me->DDSurfaceDesc, sizeof(DDSURFACEDESC2)); | 
|---|
| 4419 |  | 
|---|
| 4420 | if(lpRect != NULL) | 
|---|
| 4421 | { | 
|---|
| 4422 | lpSurfaceDesc->lpSurface =  (LPVOID)((char*)me->pFrameBuffer + | 
|---|
| 4423 | (lpRect->top * me->dwPitchFB) + | 
|---|
| 4424 | (lpRect->left * (lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount>>3))); | 
|---|
| 4425 | #ifdef DEBUG | 
|---|
| 4426 | WriteLog("SurfLock4 %08X (x,y) = (%d,%d)\n\n", lpSurfaceDesc->lpSurface, lpRect->top, lpRect->left); | 
|---|
| 4427 | #endif | 
|---|
| 4428 | } | 
|---|
| 4429 | else | 
|---|
| 4430 | { | 
|---|
| 4431 | #ifdef DEBUG | 
|---|
| 4432 | WriteLog("SurfLock4 %08X \n\n", lpSurfaceDesc->lpSurface); | 
|---|
| 4433 | #endif | 
|---|
| 4434 | } | 
|---|
| 4435 | // Add the rectangle to the list of locked rectangles | 
|---|
| 4436 |  | 
|---|
| 4437 | pIRectNew->SetMemPtr(lpSurfaceDesc->lpSurface); | 
|---|
| 4438 |  | 
|---|
| 4439 | DPA_InsertPtr( me->DPA_LockedRects, | 
|---|
| 4440 | DPA_GetPtrCount(me->DPA_LockedRects), | 
|---|
| 4441 | pIRectNew); | 
|---|
| 4442 |  | 
|---|
| 4443 | me->fLocked = TRUE; | 
|---|
| 4444 | } | 
|---|
| 4445 |  | 
|---|
| 4446 |  | 
|---|
| 4447 | return rc; | 
|---|
| 4448 | } | 
|---|
| 4449 | //****************************************************************************** | 
|---|
| 4450 | //****************************************************************************** | 
|---|
| 4451 | HRESULT __stdcall SurfReleaseDC(THIS This, HDC hdc) | 
|---|
| 4452 | { | 
|---|
| 4453 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4454 | struct | 
|---|
| 4455 | { | 
|---|
| 4456 | BITMAPINFOHEADER  bmiHead; | 
|---|
| 4457 | RGBQUAD           bmiCols[256]; | 
|---|
| 4458 | } BitmapInfo; | 
|---|
| 4459 | BITMAP bmpData; | 
|---|
| 4460 | char szError[256]; | 
|---|
| 4461 | int i,rc; | 
|---|
| 4462 |  | 
|---|
| 4463 | #ifdef DEBUG | 
|---|
| 4464 | WriteLog("SurfReleaseDC\n"); | 
|---|
| 4465 | #endif | 
|---|
| 4466 |  | 
|---|
| 4467 | if(hdc != me->hdcImage) | 
|---|
| 4468 | return(DDERR_INVALIDOBJECT); | 
|---|
| 4469 |  | 
|---|
| 4470 | #if 1 | 
|---|
| 4471 | //unselect our bitmap | 
|---|
| 4472 | SelectObject(me->hdcImage, me->hgdiOld); | 
|---|
| 4473 | memset(&BitmapInfo,0, sizeof(BitmapInfo)); | 
|---|
| 4474 | BitmapInfo.bmiHead.biSize     = sizeof(BITMAPINFOHEADER); | 
|---|
| 4475 | BitmapInfo.bmiHead.biWidth    = me->DDSurfaceDesc.lPitch/ (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount>>3); | 
|---|
| 4476 | BitmapInfo.bmiHead.biHeight   = me->DDSurfaceDesc.dwHeight; | 
|---|
| 4477 | BitmapInfo.bmiHead.biPlanes   = 1; | 
|---|
| 4478 | BitmapInfo.bmiHead.biBitCount = 0; // me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; | 
|---|
| 4479 |  | 
|---|
| 4480 | switch(me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4481 | { | 
|---|
| 4482 | case 1: | 
|---|
| 4483 | case 4: | 
|---|
| 4484 | case 8: | 
|---|
| 4485 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4486 | //GetSystemPaletteEntries(me->hdcImage,0,255,(PPALETTEENTRY)&BitmapInfo.bmiCols[0]); | 
|---|
| 4487 | rc = GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4488 | NULL,(PBITMAPINFO)&BitmapInfo,DIB_PAL_COLORS); | 
|---|
| 4489 | WriteLog( "GetDIBits rc=%d\n Size   :%d\n Width  :%d\n Height :%d\n" | 
|---|
| 4490 | " Planes :%d\n BitCount :%d\nLastEror = %d\n", | 
|---|
| 4491 | rc, | 
|---|
| 4492 | BitmapInfo.bmiHead.biSize, | 
|---|
| 4493 | BitmapInfo.bmiHead.biWidth, | 
|---|
| 4494 | BitmapInfo.bmiHead.biHeight, | 
|---|
| 4495 | BitmapInfo.bmiHead.biPlanes, | 
|---|
| 4496 | BitmapInfo.bmiHead.biBitCount, | 
|---|
| 4497 | GetLastError()); | 
|---|
| 4498 | /* | 
|---|
| 4499 | rc = GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4500 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_PAL_COLORS); | 
|---|
| 4501 | WriteLog( "GetDIBits rc=%d\n LastEror = %d\n", | 
|---|
| 4502 | rc, | 
|---|
| 4503 | GetLastError()); | 
|---|
| 4504 | */ | 
|---|
| 4505 | break; | 
|---|
| 4506 | case 16: | 
|---|
| 4507 | case 32: | 
|---|
| 4508 | BitmapInfo.bmiHead.biCompression = BI_BITFIELDS; | 
|---|
| 4509 | BitmapInfo.bmiHead.biClrUsed     = 3; | 
|---|
| 4510 | *((DWORD *) &(BitmapInfo.bmiCols[0])) = me->DDSurfaceDesc.ddpfPixelFormat.dwRBitMask; | 
|---|
| 4511 | *((DWORD *) &(BitmapInfo.bmiCols[1])) = me->DDSurfaceDesc.ddpfPixelFormat.dwGBitMask; | 
|---|
| 4512 | *((DWORD *) &(BitmapInfo.bmiCols[2])) = me->DDSurfaceDesc.ddpfPixelFormat.dwBBitMask; | 
|---|
| 4513 | GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4514 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS); | 
|---|
| 4515 | break; | 
|---|
| 4516 | case 24: | 
|---|
| 4517 | BitmapInfo.bmiHead.biCompression = BI_RGB; | 
|---|
| 4518 | GetDIBits(hdc, me->hbmImage, 0, me->DDSurfaceDesc.dwHeight, | 
|---|
| 4519 | me->DDSurfaceDesc.lpSurface,(PBITMAPINFO)&BitmapInfo,DIB_RGB_COLORS); | 
|---|
| 4520 | break; | 
|---|
| 4521 | default: | 
|---|
| 4522 | #ifdef DEBUG | 
|---|
| 4523 | WriteLog("Unexptected BitCount %d => Surface unlocked but no data copied back\n",me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount); | 
|---|
| 4524 | #endif | 
|---|
| 4525 | // we might could keep the surface locked and return an error but this is more "safe" | 
|---|
| 4526 | break; | 
|---|
| 4527 | } // end switch (me->DDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount) | 
|---|
| 4528 | #else | 
|---|
| 4529 |  | 
|---|
| 4530 | rc = GetObjectA( me->hbmImage, | 
|---|
| 4531 | sizeof(BITMAP), | 
|---|
| 4532 | &bmpData); | 
|---|
| 4533 | WriteLog( "GetObject returned rc=%d\n BitmapInfo:\n Size:(%dx%d)\n Pitch: %d\n Bits %d\n @mem %08X", | 
|---|
| 4534 | rc, | 
|---|
| 4535 | bmpData.bmWidth, bmpData.bmHeight, | 
|---|
| 4536 | bmpData.bmWidthBytes, | 
|---|
| 4537 | bmpData.bmBitsPixel, | 
|---|
| 4538 | bmpData.bmBits); | 
|---|
| 4539 | #endif | 
|---|
| 4540 | me->Vtbl.Unlock(me,NULL); | 
|---|
| 4541 | me->dwLastDCUnique = me->dwUniqueValue; // Store this to see if the surface was locked after we released the DC | 
|---|
| 4542 |  | 
|---|
| 4543 | return(DD_OK); | 
|---|
| 4544 | } | 
|---|
| 4545 | //****************************************************************************** | 
|---|
| 4546 | //****************************************************************************** | 
|---|
| 4547 | HRESULT __stdcall SurfRestore(THIS) | 
|---|
| 4548 | { | 
|---|
| 4549 | #ifdef DEBUG | 
|---|
| 4550 | WriteLog("SurfRestore\n"); | 
|---|
| 4551 | #endif | 
|---|
| 4552 |  | 
|---|
| 4553 | return(DD_OK); | 
|---|
| 4554 | } | 
|---|
| 4555 | //****************************************************************************** | 
|---|
| 4556 | //****************************************************************************** | 
|---|
| 4557 | HRESULT __stdcall SurfSetClipper(THIS This, LPDIRECTDRAWCLIPPER lpClipper) | 
|---|
| 4558 | { | 
|---|
| 4559 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4560 |  | 
|---|
| 4561 | #ifdef DEBUG | 
|---|
| 4562 | WriteLog("SurfSetClipper\n"); | 
|---|
| 4563 | #endif | 
|---|
| 4564 |  | 
|---|
| 4565 | if(lpClipper == NULL) | 
|---|
| 4566 | { | 
|---|
| 4567 | //deattach surface | 
|---|
| 4568 | if(me->lpClipper) | 
|---|
| 4569 | { | 
|---|
| 4570 | me->lpClipper->Vtbl.Release((IDirectDrawClipper*)me->lpClipper); | 
|---|
| 4571 | me->lpClipper = NULL; | 
|---|
| 4572 | return(DD_OK); | 
|---|
| 4573 | } | 
|---|
| 4574 | else | 
|---|
| 4575 | return(DDERR_NOCLIPPERATTACHED); | 
|---|
| 4576 | } | 
|---|
| 4577 |  | 
|---|
| 4578 | if(lpClipper == (LPDIRECTDRAWCLIPPER)me->lpClipper) | 
|---|
| 4579 | return(DD_OK);  //already attached | 
|---|
| 4580 |  | 
|---|
| 4581 | if(me->lpClipper != NULL) | 
|---|
| 4582 | { | 
|---|
| 4583 | me->lpClipper->Vtbl.Release((IDirectDrawClipper*)me->lpClipper);  //attach other surface | 
|---|
| 4584 | return(DD_OK); | 
|---|
| 4585 | } | 
|---|
| 4586 |  | 
|---|
| 4587 | me->lpClipper = (OS2IDirectDrawClipper *)lpClipper; | 
|---|
| 4588 | me->lpClipper->Vtbl.AddRef((IDirectDrawClipper*)me->lpClipper); | 
|---|
| 4589 |  | 
|---|
| 4590 | return(DD_OK); | 
|---|
| 4591 | } | 
|---|
| 4592 | //****************************************************************************** | 
|---|
| 4593 | //****************************************************************************** | 
|---|
| 4594 | HRESULT __stdcall SurfSetColorKey(THIS  This, DWORD dwFlags, LPDDCOLORKEY lpDDColKey) | 
|---|
| 4595 | { | 
|---|
| 4596 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4597 | HRESULT rc; | 
|---|
| 4598 | #ifdef DEBUG | 
|---|
| 4599 | WriteLog("SurfSetColorKey\n"); | 
|---|
| 4600 | #endif | 
|---|
| 4601 |  | 
|---|
| 4602 | if (0==dwFlags) | 
|---|
| 4603 | return (DDERR_INVALIDPARAMS); | 
|---|
| 4604 |  | 
|---|
| 4605 | // as we report only src colorkey in the caps return error on all others flags | 
|---|
| 4606 | if( (DDCKEY_DESTBLT|DDCKEY_DESTOVERLAY|DDCKEY_SRCOVERLAY|DDCKEY_COLORSPACE) & dwFlags) | 
|---|
| 4607 | return(DDERR_UNSUPPORTED); | 
|---|
| 4608 |  | 
|---|
| 4609 | if(DDCKEY_SRCBLT & dwFlags) | 
|---|
| 4610 | { | 
|---|
| 4611 | me->lpVtbl->ChangeUniquenessValue(me); // we changed somethin so change this value | 
|---|
| 4612 | if(NULL!=lpDDColKey) | 
|---|
| 4613 | { | 
|---|
| 4614 | memcpy(&(me->DDSurfaceDesc.ddckCKSrcBlt), lpDDColKey, sizeof(DDCOLORKEY) ); | 
|---|
| 4615 | me->DDSurfaceDesc.dwFlags |= DDCKEY_SRCBLT; | 
|---|
| 4616 |  | 
|---|
| 4617 | // ToDo: Generate a maskbitmap for transparent blitting here | 
|---|
| 4618 | } | 
|---|
| 4619 | else | 
|---|
| 4620 | { | 
|---|
| 4621 | memset(&(me->DDSurfaceDesc.ddckCKSrcBlt), 0, sizeof(DDCOLORKEY) ); | 
|---|
| 4622 | me->DDSurfaceDesc.dwFlags &= ~DDCKEY_SRCBLT; | 
|---|
| 4623 | } | 
|---|
| 4624 | rc = DD_OK; | 
|---|
| 4625 | } | 
|---|
| 4626 | else | 
|---|
| 4627 | rc = DDERR_INVALIDPARAMS; // some other flags where set => error | 
|---|
| 4628 |  | 
|---|
| 4629 | return rc; | 
|---|
| 4630 | } | 
|---|
| 4631 | //****************************************************************************** | 
|---|
| 4632 | //****************************************************************************** | 
|---|
| 4633 | HRESULT __stdcall SurfSetOverlayPosition(THIS This, LONG lX, LONG lY) | 
|---|
| 4634 | { | 
|---|
| 4635 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4636 |  | 
|---|
| 4637 | #ifdef DEBUG | 
|---|
| 4638 | WriteLog("SurfSetOverlayPosition\n"); | 
|---|
| 4639 | #endif | 
|---|
| 4640 |  | 
|---|
| 4641 | if( (me->DDSurfaceDesc.dwFlags & DDSD_CAPS) && | 
|---|
| 4642 | (me->DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_OVERLAY) ) | 
|---|
| 4643 | { | 
|---|
| 4644 | if(me->fOverlayValid) | 
|---|
| 4645 | return(DDERR_NOOVERLAYDEST); | 
|---|
| 4646 |  | 
|---|
| 4647 | if(!(me->DDSurfaceDesc.dwFlags & DDSCAPS_VISIBLE)) | 
|---|
| 4648 | return(DDERR_OVERLAYNOTVISIBLE); | 
|---|
| 4649 |  | 
|---|
| 4650 | // ToDo: If we implement alignment restricions to the Overlay position | 
|---|
| 4651 | // check if the new values are OK otherwiese return DDERR_INVALIDPOSITION | 
|---|
| 4652 |  | 
|---|
| 4653 | me->lOverlayX = lX; | 
|---|
| 4654 | me->lOverlayY = lY; | 
|---|
| 4655 | return(DD_OK); | 
|---|
| 4656 | } | 
|---|
| 4657 |  | 
|---|
| 4658 | return(DDERR_NOTAOVERLAYSURFACE); | 
|---|
| 4659 | } | 
|---|
| 4660 | //****************************************************************************** | 
|---|
| 4661 | //****************************************************************************** | 
|---|
| 4662 | HRESULT __stdcall SurfSetPalette(THIS This, LPDIRECTDRAWPALETTE lpPalette) | 
|---|
| 4663 | { | 
|---|
| 4664 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4665 |  | 
|---|
| 4666 | #ifdef DEBUG | 
|---|
| 4667 | WriteLog("SurfSetPalette\n"); | 
|---|
| 4668 | #endif | 
|---|
| 4669 |  | 
|---|
| 4670 | if(lpPalette == NULL) | 
|---|
| 4671 | { | 
|---|
| 4672 | //deattach palette | 
|---|
| 4673 | if(me->lpPalette) | 
|---|
| 4674 | { | 
|---|
| 4675 | // If removed from a primary surface notify | 
|---|
| 4676 | // palette that it is no longer attached to the | 
|---|
| 4677 | // primary surface => doesn't modify physical palette | 
|---|
| 4678 | if(me->surfaceType & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 4679 | { | 
|---|
| 4680 | me->lpPalette->SetIsPrimary(FALSE); | 
|---|
| 4681 | } | 
|---|
| 4682 | me->lpPalette->Vtbl.Release((IDirectDrawPalette*)me->lpPalette); | 
|---|
| 4683 | me->lpPalette = NULL; | 
|---|
| 4684 | return(DD_OK); | 
|---|
| 4685 | } | 
|---|
| 4686 | else | 
|---|
| 4687 | return(DDERR_NOPALETTEATTACHED); | 
|---|
| 4688 | } | 
|---|
| 4689 |  | 
|---|
| 4690 | if(lpPalette == (LPDIRECTDRAWPALETTE)me->lpPalette) | 
|---|
| 4691 | return(DD_OK);  //already attached | 
|---|
| 4692 |  | 
|---|
| 4693 | if(me->lpPalette != NULL) | 
|---|
| 4694 | { | 
|---|
| 4695 | me->lpPalette->Vtbl.Release((IDirectDrawPalette*)me->lpPalette);  //attach other palette | 
|---|
| 4696 | return(DD_OK); | 
|---|
| 4697 | } | 
|---|
| 4698 | me->lpPalette = (OS2IDirectDrawPalette *)lpPalette; | 
|---|
| 4699 | me->lpPalette->Vtbl.AddRef((IDirectDrawPalette*)me->lpPalette); | 
|---|
| 4700 |  | 
|---|
| 4701 | // If Attached to a primary surface notify | 
|---|
| 4702 | // palette that it is attached to the primary surface | 
|---|
| 4703 | //  => It does modify physical palette. | 
|---|
| 4704 | // This is important as an palette can be attached to | 
|---|
| 4705 | // multiple surfaces. If one is the primary surface | 
|---|
| 4706 | // changes done to it via any surface must result in | 
|---|
| 4707 | // changes in the phys pal. | 
|---|
| 4708 |  | 
|---|
| 4709 | if(me->surfaceType & DDSCAPS_PRIMARYSURFACE) | 
|---|
| 4710 | { | 
|---|
| 4711 | me->lpPalette->SetIsPrimary(TRUE); | 
|---|
| 4712 | } | 
|---|
| 4713 | me->lpVtbl->ChangeUniquenessValue(me); | 
|---|
| 4714 |  | 
|---|
| 4715 | return(DD_OK); | 
|---|
| 4716 | } | 
|---|
| 4717 | //****************************************************************************** | 
|---|
| 4718 | //****************************************************************************** | 
|---|
| 4719 | HRESULT __stdcall SurfUnlock(THIS This, LPVOID lpSurfaceData) | 
|---|
| 4720 | { | 
|---|
| 4721 |  | 
|---|
| 4722 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4723 | int i; | 
|---|
| 4724 | DDRectangle *pIRectUnlock, *pIRectEnum; | 
|---|
| 4725 | BOOL Found = FALSE; | 
|---|
| 4726 | OS2RECTL CCRect; | 
|---|
| 4727 | HRESULT rc; | 
|---|
| 4728 |  | 
|---|
| 4729 | #ifdef DEBUG | 
|---|
| 4730 | WriteLog("SurfUnlock at %08X\n",lpSurfaceData); | 
|---|
| 4731 | #endif | 
|---|
| 4732 |  | 
|---|
| 4733 | if(me->fLocked == FALSE) | 
|---|
| 4734 | { | 
|---|
| 4735 | #ifdef DEBUG | 
|---|
| 4736 | WriteLog("Surface not locked!\n"); | 
|---|
| 4737 | #endif | 
|---|
| 4738 | return(DDERR_NOTLOCKED); | 
|---|
| 4739 | } | 
|---|
| 4740 |  | 
|---|
| 4741 | #ifdef DEBUG | 
|---|
| 4742 | WriteLog("Start Emuneration of Locked Rects\n"); | 
|---|
| 4743 | #endif | 
|---|
| 4744 |  | 
|---|
| 4745 | i=0; | 
|---|
| 4746 | if(NULL!=lpSurfaceData) | 
|---|
| 4747 | { | 
|---|
| 4748 | WriteLog("Buffer Pointer Compare"); | 
|---|
| 4749 |  | 
|---|
| 4750 | // We got a pinter to the surface memory so we must search for | 
|---|
| 4751 | // this pointer in the locked rects DPA to unlock the right rect. | 
|---|
| 4752 |  | 
|---|
| 4753 | while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found) | 
|---|
| 4754 | { | 
|---|
| 4755 | pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i); | 
|---|
| 4756 | WriteLog( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n", | 
|---|
| 4757 | i, | 
|---|
| 4758 | pIRectEnum->Top(), | 
|---|
| 4759 | pIRectEnum->Left(), | 
|---|
| 4760 | pIRectEnum->Bottom(), | 
|---|
| 4761 | pIRectEnum->Right(), | 
|---|
| 4762 | pIRectEnum->GetMemPtr() ); | 
|---|
| 4763 |  | 
|---|
| 4764 | Found = ( pIRectEnum->GetMemPtr() == lpSurfaceData); | 
|---|
| 4765 | if(!Found) | 
|---|
| 4766 | { | 
|---|
| 4767 | #ifdef DEBUG | 
|---|
| 4768 | WriteLog("Not Found, try Next rect\n"); | 
|---|
| 4769 | #endif | 
|---|
| 4770 | i++; | 
|---|
| 4771 | } | 
|---|
| 4772 | #ifdef DEBUG | 
|---|
| 4773 | else | 
|---|
| 4774 | { | 
|---|
| 4775 | WriteLog("Found Rect\n"); | 
|---|
| 4776 | } | 
|---|
| 4777 | #endif | 
|---|
| 4778 | } | 
|---|
| 4779 | } | 
|---|
| 4780 | else | 
|---|
| 4781 | { | 
|---|
| 4782 | // If a NULL pointer was passed in the SW tries to unlock the | 
|---|
| 4783 | // complete surface so we must compare the rects. | 
|---|
| 4784 | WriteLog("Rectangle compare"); | 
|---|
| 4785 |  | 
|---|
| 4786 | pIRectUnlock = new DDRectangle( 0, 0, me->height, me->width); | 
|---|
| 4787 |  | 
|---|
| 4788 | while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found) | 
|---|
| 4789 | { | 
|---|
| 4790 | pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i); | 
|---|
| 4791 | WriteLog( "Test with Rectangle %d (%d/%d) x (%d/%d) Mem at %08X\n", | 
|---|
| 4792 | i, | 
|---|
| 4793 | pIRectEnum->Top(), | 
|---|
| 4794 | pIRectEnum->Left(), | 
|---|
| 4795 | pIRectEnum->Bottom(), | 
|---|
| 4796 | pIRectEnum->Right(), | 
|---|
| 4797 | pIRectEnum->GetMemPtr() ); | 
|---|
| 4798 |  | 
|---|
| 4799 | Found = (*pIRectEnum == *pIRectUnlock); | 
|---|
| 4800 | if(!Found) | 
|---|
| 4801 | { | 
|---|
| 4802 | #ifdef DEBUG | 
|---|
| 4803 | WriteLog("Not Found, try Next rect\n"); | 
|---|
| 4804 | #endif | 
|---|
| 4805 | i++; | 
|---|
| 4806 | } | 
|---|
| 4807 | #ifdef DEBUG | 
|---|
| 4808 | else | 
|---|
| 4809 | { | 
|---|
| 4810 | WriteLog("Found Rect\n"); | 
|---|
| 4811 | } | 
|---|
| 4812 | #endif | 
|---|
| 4813 | } | 
|---|
| 4814 | delete pIRectUnlock; | 
|---|
| 4815 | } | 
|---|
| 4816 |  | 
|---|
| 4817 | if(!Found) | 
|---|
| 4818 | { | 
|---|
| 4819 | #ifdef DEBUG | 
|---|
| 4820 | WriteLog("Rectangle not locked, wrong Rect!\n\n"); | 
|---|
| 4821 | #endif | 
|---|
| 4822 | rc = DDERR_INVALIDRECT; | 
|---|
| 4823 | } | 
|---|
| 4824 | else | 
|---|
| 4825 | { | 
|---|
| 4826 | #ifdef DEBUG | 
|---|
| 4827 | WriteLog("Remove Rect %d from Seq.\n",i); | 
|---|
| 4828 | #endif | 
|---|
| 4829 |  | 
|---|
| 4830 | DPA_DeletePtr(me->DPA_LockedRects,i); | 
|---|
| 4831 |  | 
|---|
| 4832 | #ifdef DEBUG | 
|---|
| 4833 | WriteLog("Test if locked Rects main\n"); | 
|---|
| 4834 | #endif | 
|---|
| 4835 |  | 
|---|
| 4836 | if(0==DPA_GetPtrCount(me->DPA_LockedRects))  // Do we have unlocked last rectangle | 
|---|
| 4837 | { | 
|---|
| 4838 | #ifdef DEBUG | 
|---|
| 4839 | WriteLog("No Locked Rects left for surface\n"); | 
|---|
| 4840 | #endif | 
|---|
| 4841 | me->fLocked = FALSE; | 
|---|
| 4842 | } | 
|---|
| 4843 | #ifdef DEBUG | 
|---|
| 4844 | else | 
|---|
| 4845 | WriteLog( "%d Rects in Seq\n", | 
|---|
| 4846 | DPA_GetPtrCount(me->DPA_LockedRects)); | 
|---|
| 4847 | #endif | 
|---|
| 4848 |  | 
|---|
| 4849 | if(me->pFrameBuffer != me->pDiveBuffer) | 
|---|
| 4850 | { | 
|---|
| 4851 | #ifdef DEBUG | 
|---|
| 4852 | WriteLog( "ColorConversion Needed %08X != %08X\n", | 
|---|
| 4853 | me->pFrameBuffer, | 
|---|
| 4854 | me->pDiveBuffer); | 
|---|
| 4855 | #endif | 
|---|
| 4856 | if(NULL!=lpSurfaceData) | 
|---|
| 4857 | { | 
|---|
| 4858 | CCRect.yTop    = pIRectEnum->Top(); | 
|---|
| 4859 | CCRect.xLeft   = pIRectEnum->Left(); | 
|---|
| 4860 | CCRect.xRight  = pIRectEnum->Right(); | 
|---|
| 4861 | CCRect.yBottom = pIRectEnum->Bottom(); | 
|---|
| 4862 |  | 
|---|
| 4863 | me->ColorConversion( (LPRECT)&CCRect); | 
|---|
| 4864 | } | 
|---|
| 4865 | else | 
|---|
| 4866 | { | 
|---|
| 4867 | me->ColorConversion(NULL); | 
|---|
| 4868 | } | 
|---|
| 4869 | } | 
|---|
| 4870 | #ifdef DEBUG | 
|---|
| 4871 | else | 
|---|
| 4872 | WriteLog( "No ColorConversion Needed"); | 
|---|
| 4873 | #endif | 
|---|
| 4874 |  | 
|---|
| 4875 | // delete tne DDRectobject of the found rectangle | 
|---|
| 4876 | delete pIRectEnum; | 
|---|
| 4877 |  | 
|---|
| 4878 | me->lpVtbl->ChangeUniquenessValue(me); | 
|---|
| 4879 |  | 
|---|
| 4880 | WriteLog("Unlock OK\n\n"); | 
|---|
| 4881 |  | 
|---|
| 4882 | rc = DD_OK; | 
|---|
| 4883 | } | 
|---|
| 4884 |  | 
|---|
| 4885 | return rc; | 
|---|
| 4886 | } | 
|---|
| 4887 | //****************************************************************************** | 
|---|
| 4888 | //****************************************************************************** | 
|---|
| 4889 | HRESULT __stdcall SurfUnlock4(THIS This, LPRECT lpSurfaceRect) | 
|---|
| 4890 | { | 
|---|
| 4891 | // MS changed the parameter from LPVOID to LPRECT with DX6 | 
|---|
| 4892 | // as DX-6 allways returns a DDSurface4 on create surface this | 
|---|
| 4893 | // is a problem i not NULL is passed in. | 
|---|
| 4894 | // Solution We first test with the pointer ns assuming a rectangle | 
|---|
| 4895 | // if we don't find a rect Which is very likely if we get a pointer | 
|---|
| 4896 | // SurfaceMemory we call SurfUnlock and test for the pointer there. | 
|---|
| 4897 |  | 
|---|
| 4898 |  | 
|---|
| 4899 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 4900 | int i; | 
|---|
| 4901 | DDRectangle *pIRectUnlock, *pIRectEnum; | 
|---|
| 4902 | BOOL Found = FALSE; | 
|---|
| 4903 | HRESULT rc; | 
|---|
| 4904 |  | 
|---|
| 4905 | #ifdef DEBUG | 
|---|
| 4906 | WriteLog("SurfUnlock4\n"); | 
|---|
| 4907 | #endif | 
|---|
| 4908 |  | 
|---|
| 4909 | if(me->fLocked == FALSE) | 
|---|
| 4910 | { | 
|---|
| 4911 | #ifdef DEBUG | 
|---|
| 4912 | WriteLog("Surface not locked!\n"); | 
|---|
| 4913 | #endif | 
|---|
| 4914 | return(DDERR_NOTLOCKED); | 
|---|
| 4915 | } | 
|---|
| 4916 |  | 
|---|
| 4917 | if(NULL!=lpSurfaceRect) | 
|---|
| 4918 | { | 
|---|
| 4919 | WriteLog("Unlock rectangle\n"); | 
|---|
| 4920 | pIRectUnlock = new DDRectangle( lpSurfaceRect->top, | 
|---|
| 4921 | lpSurfaceRect->left, | 
|---|
| 4922 | lpSurfaceRect->bottom, | 
|---|
| 4923 | lpSurfaceRect->right); | 
|---|
| 4924 | } | 
|---|
| 4925 | else | 
|---|
| 4926 | { | 
|---|
| 4927 | WriteLog("Unlock complete surface\n"); | 
|---|
| 4928 | pIRectUnlock = new DDRectangle( 0, 0, me->height, me->width); | 
|---|
| 4929 | } | 
|---|
| 4930 |  | 
|---|
| 4931 | WriteLog( "Try to Unlock Rectangle (%d/%d) x (%d/%d)\n", | 
|---|
| 4932 | pIRectUnlock->Top(), | 
|---|
| 4933 | pIRectUnlock->Left(), | 
|---|
| 4934 | pIRectUnlock->Bottom(), | 
|---|
| 4935 | pIRectUnlock->Right() ); | 
|---|
| 4936 |  | 
|---|
| 4937 | #ifdef DEBUG | 
|---|
| 4938 | WriteLog("Start Emuneration of Locked Rects\n"); | 
|---|
| 4939 | #endif | 
|---|
| 4940 |  | 
|---|
| 4941 | i=0; | 
|---|
| 4942 | while(i<DPA_GetPtrCount(me->DPA_LockedRects) && !Found) | 
|---|
| 4943 | { | 
|---|
| 4944 | pIRectEnum = (DDRectangle*)DPA_FastGetPtr(me->DPA_LockedRects,i); | 
|---|
| 4945 | WriteLog( "Test with Rectangle (%d/%d) x (%d/%d)\n", | 
|---|
| 4946 | pIRectEnum->Top(), | 
|---|
| 4947 | pIRectEnum->Left(), | 
|---|
| 4948 | pIRectEnum->Bottom(), | 
|---|
| 4949 | pIRectEnum->Right() ); | 
|---|
| 4950 |  | 
|---|
| 4951 | Found = (*pIRectEnum == *pIRectUnlock); | 
|---|
| 4952 | if(!Found) | 
|---|
| 4953 | { | 
|---|
| 4954 | #ifdef DEBUG | 
|---|
| 4955 | WriteLog("Not Found, try Next rect\n"); | 
|---|
| 4956 | #endif | 
|---|
| 4957 | i++; | 
|---|
| 4958 | } | 
|---|
| 4959 | #ifdef DEBUG | 
|---|
| 4960 | else | 
|---|
| 4961 | { | 
|---|
| 4962 | WriteLog("Found Rect\n"); | 
|---|
| 4963 | } | 
|---|
| 4964 | #endif | 
|---|
| 4965 | } | 
|---|
| 4966 |  | 
|---|
| 4967 | if(!Found) | 
|---|
| 4968 | { | 
|---|
| 4969 |  | 
|---|
| 4970 | if(NULL==lpSurfaceRect) | 
|---|
| 4971 | { | 
|---|
| 4972 | #ifdef DEBUG | 
|---|
| 4973 | WriteLog("Rectangle not locked, wrong Rect!\n\n"); | 
|---|
| 4974 | #endif | 
|---|
| 4975 | return(DDERR_INVALIDRECT); | 
|---|
| 4976 | } | 
|---|
| 4977 | else | 
|---|
| 4978 | rc = SurfUnlock(This, (LPVOID)lpSurfaceRect); | 
|---|
| 4979 | } | 
|---|
| 4980 | else | 
|---|
| 4981 | { | 
|---|
| 4982 | #ifdef DEBUG | 
|---|
| 4983 | WriteLog("Remove Rect from Seq.\n"); | 
|---|
| 4984 | #endif | 
|---|
| 4985 |  | 
|---|
| 4986 | DPA_DeletePtr(me->DPA_LockedRects,i); | 
|---|
| 4987 |  | 
|---|
| 4988 | if(0==DPA_GetPtrCount(me->DPA_LockedRects))  // Do we have unlocked last rectangle | 
|---|
| 4989 | { | 
|---|
| 4990 | #ifdef DEBUG | 
|---|
| 4991 | WriteLog("No Locked Rects left for surface\n"); | 
|---|
| 4992 | #endif | 
|---|
| 4993 | me->fLocked = FALSE; | 
|---|
| 4994 | } | 
|---|
| 4995 |  | 
|---|
| 4996 | if(me->pFrameBuffer != me->pDiveBuffer) | 
|---|
| 4997 | { | 
|---|
| 4998 | #ifdef DEBUG | 
|---|
| 4999 | WriteLog( "ColorConversion Needed %08X != %08X\n", | 
|---|
| 5000 | me->pFrameBuffer, | 
|---|
| 5001 | me->pDiveBuffer); | 
|---|
| 5002 | #endif | 
|---|
| 5003 | me->ColorConversion(lpSurfaceRect); | 
|---|
| 5004 | } | 
|---|
| 5005 |  | 
|---|
| 5006 | me->lpVtbl->ChangeUniquenessValue(me); | 
|---|
| 5007 |  | 
|---|
| 5008 | WriteLog("Unlock OK\n\n"); | 
|---|
| 5009 | rc = DD_OK; | 
|---|
| 5010 | } | 
|---|
| 5011 |  | 
|---|
| 5012 | return rc; | 
|---|
| 5013 | } | 
|---|
| 5014 | //****************************************************************************** | 
|---|
| 5015 | //****************************************************************************** | 
|---|
| 5016 | HRESULT __stdcall SurfUpdateOverlay(THIS This, LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX) | 
|---|
| 5017 | { | 
|---|
| 5018 | #ifdef DEBUG | 
|---|
| 5019 | WriteLog("SurfUpdateOverlay\n"); | 
|---|
| 5020 | #endif | 
|---|
| 5021 | return(DD_OK); | 
|---|
| 5022 | } | 
|---|
| 5023 | //****************************************************************************** | 
|---|
| 5024 | //****************************************************************************** | 
|---|
| 5025 | HRESULT __stdcall SurfUpdateOverlay4(THIS, LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX) | 
|---|
| 5026 | { | 
|---|
| 5027 | #ifdef DEBUG | 
|---|
| 5028 | WriteLog("SurfUpdateOverlay\n"); | 
|---|
| 5029 | #endif | 
|---|
| 5030 | return(DD_OK); | 
|---|
| 5031 | } | 
|---|
| 5032 | //****************************************************************************** | 
|---|
| 5033 | //****************************************************************************** | 
|---|
| 5034 | HRESULT __stdcall SurfUpdateOverlayDisplay(THIS, DWORD) | 
|---|
| 5035 | { | 
|---|
| 5036 | #ifdef DEBUG | 
|---|
| 5037 | WriteLog("SurfUpdateOverlayDisplay\n"); | 
|---|
| 5038 | #endif | 
|---|
| 5039 | return(DD_OK); | 
|---|
| 5040 | } | 
|---|
| 5041 | //****************************************************************************** | 
|---|
| 5042 | //****************************************************************************** | 
|---|
| 5043 | HRESULT __stdcall SurfUpdateOverlayZOrder(THIS, DWORD, LPDIRECTDRAWSURFACE2) | 
|---|
| 5044 | { | 
|---|
| 5045 | #ifdef DEBUG | 
|---|
| 5046 | WriteLog("SurfUpdateOverlayZOrder\n"); | 
|---|
| 5047 | #endif | 
|---|
| 5048 | return(DD_OK); | 
|---|
| 5049 | } | 
|---|
| 5050 | //****************************************************************************** | 
|---|
| 5051 | //****************************************************************************** | 
|---|
| 5052 | HRESULT __stdcall SurfUpdateOverlayZOrder4(THIS, DWORD, LPDIRECTDRAWSURFACE4) | 
|---|
| 5053 | { | 
|---|
| 5054 | #ifdef DEBUG | 
|---|
| 5055 | WriteLog("SurfUpdateOverlayZOrder4\n"); | 
|---|
| 5056 | #endif | 
|---|
| 5057 | return(DD_OK); | 
|---|
| 5058 | } | 
|---|
| 5059 | //****************************************************************************** | 
|---|
| 5060 | //****************************************************************************** | 
|---|
| 5061 | HRESULT __stdcall SurfGetDDInterface(THIS This, LPVOID FAR *lplpDirectDraw) | 
|---|
| 5062 | { | 
|---|
| 5063 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5064 |  | 
|---|
| 5065 | #ifdef DEBUG | 
|---|
| 5066 | WriteLog("SurfGetDDInterface\n"); | 
|---|
| 5067 | #endif | 
|---|
| 5068 | *lplpDirectDraw = (LPVOID FAR *)me->lpDraw; | 
|---|
| 5069 | return(DD_OK); | 
|---|
| 5070 | } | 
|---|
| 5071 | //****************************************************************************** | 
|---|
| 5072 | //****************************************************************************** | 
|---|
| 5073 | HRESULT __stdcall SurfPageLock(THIS, DWORD) | 
|---|
| 5074 | { | 
|---|
| 5075 | // Only used for DMA memory access | 
|---|
| 5076 | // If we implement this for the None dive buffers with a pdd the we must change | 
|---|
| 5077 | // from malloc to DosAllocMem and use OBJ_TILE flag | 
|---|
| 5078 | #ifdef DEBUG | 
|---|
| 5079 | WriteLog("SurfPageLock\n"); | 
|---|
| 5080 | #endif | 
|---|
| 5081 | return(DD_OK); | 
|---|
| 5082 | } | 
|---|
| 5083 | //****************************************************************************** | 
|---|
| 5084 | //****************************************************************************** | 
|---|
| 5085 | HRESULT __stdcall SurfPageUnlock(THIS, DWORD) | 
|---|
| 5086 | { | 
|---|
| 5087 | #ifdef DEBUG | 
|---|
| 5088 | WriteLog("SurfPageUnlock\n"); | 
|---|
| 5089 | #endif | 
|---|
| 5090 | return(DD_OK); | 
|---|
| 5091 | } | 
|---|
| 5092 | //****************************************************************************** | 
|---|
| 5093 | //****************************************************************************** | 
|---|
| 5094 | // V3 Interface Functions | 
|---|
| 5095 |  | 
|---|
| 5096 | HRESULT __stdcall SurfSetSurfaceDesc(THIS This, LPDDSURFACEDESC lpSurfDesc, DWORD dwFlags) | 
|---|
| 5097 | { | 
|---|
| 5098 | #ifdef DEBUG | 
|---|
| 5099 | WriteLog("SurfSetSurfaceDesc\n"); | 
|---|
| 5100 | #endif | 
|---|
| 5101 |  | 
|---|
| 5102 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5103 | if ( (NULL==lpSurfDesc) || (dwFlags!=0) ) | 
|---|
| 5104 | return DDERR_INVALIDPARAMS; | 
|---|
| 5105 |  | 
|---|
| 5106 | // Is this ok ? Not sure if Front/BackBuffer should be handled like the Primary one. | 
|---|
| 5107 | //  if ( ( DDSCAPS_PRIMARYSURFACE == me->DDSurfaceDesc.ddsCaps.dwCaps) || | 
|---|
| 5108 | //       ( DDSCAPS_FRONTBUFFER == me->DDSurfaceDesc.ddsCaps.dwCaps) || | 
|---|
| 5109 | //       ( DDSCAPS_BACKBUFFER  == me->DDSurfaceDesc.ddsCaps.dwCaps) ) | 
|---|
| 5110 | if(-1==me->diveBufNr) | 
|---|
| 5111 | return DDERR_INVALIDSURFACETYPE; // only work for system alloced surfaces | 
|---|
| 5112 |  | 
|---|
| 5113 | if (!me->Updated) | 
|---|
| 5114 | { | 
|---|
| 5115 | me->Updated = TRUE; | 
|---|
| 5116 | // free our allocated Memory | 
|---|
| 5117 | if(me->DDSurfaceDesc.dwFlags & DDSD_LPSURFACE) | 
|---|
| 5118 | free(me->DDSurfaceDesc.lpSurface); | 
|---|
| 5119 | } | 
|---|
| 5120 | me->lpVtbl->ChangeUniquenessValue(me); | 
|---|
| 5121 | memcpy((char *)&(me->DDSurfaceDesc), (char *)lpSurfDesc, sizeof(DDSURFACEDESC)); | 
|---|
| 5122 |  | 
|---|
| 5123 | return DD_OK; | 
|---|
| 5124 | } | 
|---|
| 5125 | //****************************************************************************** | 
|---|
| 5126 | //****************************************************************************** | 
|---|
| 5127 | HRESULT __stdcall SurfSetSurfaceDesc4(THIS This, LPDDSURFACEDESC2 lpSurfDesc, DWORD dwFlags) | 
|---|
| 5128 | { | 
|---|
| 5129 | #ifdef DEBUG | 
|---|
| 5130 | WriteLog("SurfSetSurfaceDesc4\n"); | 
|---|
| 5131 | #endif | 
|---|
| 5132 |  | 
|---|
| 5133 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5134 | if ( (NULL==lpSurfDesc) || (dwFlags!=0) ) | 
|---|
| 5135 | return DDERR_INVALIDPARAMS; | 
|---|
| 5136 |  | 
|---|
| 5137 | // Is this ok ? Not sure if Front/BackBuffer should be handled like the Primary one. | 
|---|
| 5138 | //  if ( ( DDSCAPS_PRIMARYSURFACE == me->DDSurfaceDesc.ddsCaps.dwCaps) || | 
|---|
| 5139 | //       ( DDSCAPS_FRONTBUFFER == me->DDSurfaceDesc.ddsCaps.dwCaps) || | 
|---|
| 5140 | //       ( DDSCAPS_BACKBUFFER  == me->DDSurfaceDesc.ddsCaps.dwCaps) ) | 
|---|
| 5141 | if(-1==me->diveBufNr) | 
|---|
| 5142 | return DDERR_INVALIDSURFACETYPE; // only work for system alloced surfaces | 
|---|
| 5143 |  | 
|---|
| 5144 | if (!me->Updated) | 
|---|
| 5145 | { | 
|---|
| 5146 | me->Updated = TRUE; | 
|---|
| 5147 | // free our allocated Memory | 
|---|
| 5148 | if(me->DDSurfaceDesc.dwFlags & DDSD_LPSURFACE) | 
|---|
| 5149 | free(me->DDSurfaceDesc.lpSurface); | 
|---|
| 5150 | } | 
|---|
| 5151 | me->lpVtbl->ChangeUniquenessValue(me); | 
|---|
| 5152 | memcpy((char *)&(me->DDSurfaceDesc), (char *)lpSurfDesc, sizeof(DDSURFACEDESC2)); | 
|---|
| 5153 |  | 
|---|
| 5154 | return DD_OK; | 
|---|
| 5155 | } | 
|---|
| 5156 | //****************************************************************************** | 
|---|
| 5157 | //****************************************************************************** | 
|---|
| 5158 | // V4 Interface Functions | 
|---|
| 5159 |  | 
|---|
| 5160 | HRESULT __stdcall SurfSetPrivateData(THIS This, REFGUID refGUID, LPVOID lpData, | 
|---|
| 5161 | DWORD dwDataSize, DWORD dwFlags) | 
|---|
| 5162 | { | 
|---|
| 5163 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5164 | int i; | 
|---|
| 5165 | PSURFPRIVATEDATA pSData; | 
|---|
| 5166 | void *pBuffer; | 
|---|
| 5167 | BOOL bFound = FALSE; | 
|---|
| 5168 | HRESULT rc; | 
|---|
| 5169 |  | 
|---|
| 5170 | #ifdef DEBUG | 
|---|
| 5171 | WriteLog("SurfSetPrivateData\n"); | 
|---|
| 5172 | #endif | 
|---|
| 5173 |  | 
|---|
| 5174 | if(NULL==me) | 
|---|
| 5175 | return(DDERR_INVALIDOBJECT); | 
|---|
| 5176 |  | 
|---|
| 5177 | if((NULL==lpData)||(0==dwDataSize)|| | 
|---|
| 5178 | (dwFlags & ~(DDSPD_IUNKNOWNPOINTER|DDSPD_VOLATILE))) | 
|---|
| 5179 | return(DDERR_INVALIDPARAMS); | 
|---|
| 5180 |  | 
|---|
| 5181 | // first check if the refGUID is stored as then the content will be updated | 
|---|
| 5182 | if( DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0 ) | 
|---|
| 5183 | { | 
|---|
| 5184 | i=0; | 
|---|
| 5185 | while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound) | 
|---|
| 5186 | { | 
|---|
| 5187 | pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i); | 
|---|
| 5188 |  | 
|---|
| 5189 | if (IsEqualGUID(pSData->guidTag,refGUID)) | 
|---|
| 5190 | bFound = TRUE; | 
|---|
| 5191 |  | 
|---|
| 5192 | i++; | 
|---|
| 5193 | } | 
|---|
| 5194 | } | 
|---|
| 5195 |  | 
|---|
| 5196 | if(bFound) | 
|---|
| 5197 | { | 
|---|
| 5198 | // update Private Data | 
|---|
| 5199 |  | 
|---|
| 5200 | if (!pSData->isValid) | 
|---|
| 5201 | { | 
|---|
| 5202 | // Current data is invalid we need to update/allocate | 
|---|
| 5203 |  | 
|---|
| 5204 | if(dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5205 | { | 
|---|
| 5206 | pSData->pData = lpData; | 
|---|
| 5207 | pSData->dwSize = 4; | 
|---|
| 5208 | pSData->dwFlags = dwFlags; | 
|---|
| 5209 | pSData->isValid = TRUE; | 
|---|
| 5210 | ((OS2IDirectDrawSurface *) lpData)->lpVtbl->AddRef(lpData); | 
|---|
| 5211 | } | 
|---|
| 5212 | else | 
|---|
| 5213 | { | 
|---|
| 5214 | pSData->pData = malloc(dwDataSize); | 
|---|
| 5215 | if(NULL!=pSData->pData) | 
|---|
| 5216 | { | 
|---|
| 5217 | memcpy(pSData->pData,lpData,dwDataSize); | 
|---|
| 5218 | pSData->dwSize  = dwDataSize; | 
|---|
| 5219 | pSData->dwFlags = dwFlags; | 
|---|
| 5220 | pSData->isValid = TRUE; | 
|---|
| 5221 | } | 
|---|
| 5222 | else | 
|---|
| 5223 | { | 
|---|
| 5224 | delete pSData; | 
|---|
| 5225 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5226 | } | 
|---|
| 5227 | } | 
|---|
| 5228 | } | 
|---|
| 5229 | else | 
|---|
| 5230 | { | 
|---|
| 5231 | if(pSData->dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5232 | { | 
|---|
| 5233 | if(dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5234 | { | 
|---|
| 5235 | if(pSData->pData != lpData) | 
|---|
| 5236 | { | 
|---|
| 5237 | // Change of IUNKOWNPOINTER => release old and add ref to new one | 
|---|
| 5238 | ((OS2IDirectDrawSurface *)pSData->pData)->lpVtbl->Release(pSData->pData); | 
|---|
| 5239 | ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData); | 
|---|
| 5240 | pSData->pData = lpData; | 
|---|
| 5241 | } | 
|---|
| 5242 | pSData->dwFlags = dwFlags; // Update the flags, size is the same | 
|---|
| 5243 | } | 
|---|
| 5244 | else | 
|---|
| 5245 | { | 
|---|
| 5246 | // Replace IUNKOWN through data | 
|---|
| 5247 | pBuffer = malloc(dwDataSize); // get new buffer first | 
|---|
| 5248 | if(NULL!=pBuffer) | 
|---|
| 5249 | { | 
|---|
| 5250 | // release old ref and copy data | 
|---|
| 5251 | ((OS2IDirectDrawSurface *)pSData->pData)->lpVtbl->Release(pSData->pData); | 
|---|
| 5252 | memcpy(pBuffer,lpData,dwDataSize); | 
|---|
| 5253 | pSData->pData = pBuffer; | 
|---|
| 5254 | pSData->dwSize = dwDataSize; // Update the size | 
|---|
| 5255 | pSData->dwFlags = dwFlags;   // Update the flags | 
|---|
| 5256 | } | 
|---|
| 5257 | else | 
|---|
| 5258 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5259 | } | 
|---|
| 5260 | } | 
|---|
| 5261 | else | 
|---|
| 5262 | { | 
|---|
| 5263 | if(dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5264 | { | 
|---|
| 5265 | // Change of data to IUNKOWNPOINTER => free old memory and add ref to new one | 
|---|
| 5266 | free(pSData->pData); | 
|---|
| 5267 | ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData); | 
|---|
| 5268 | pSData->pData = lpData; | 
|---|
| 5269 | pSData->dwSize = dwDataSize; // Update the size | 
|---|
| 5270 | pSData->dwFlags = dwFlags;   // Update the flags | 
|---|
| 5271 | } | 
|---|
| 5272 | else | 
|---|
| 5273 | { | 
|---|
| 5274 | //  Update/Replace data | 
|---|
| 5275 | if(pSData->dwSize!=dwDataSize) | 
|---|
| 5276 | pBuffer = realloc(pSData->pData,dwDataSize); // update buffer to new size | 
|---|
| 5277 | else | 
|---|
| 5278 | pBuffer = pSData->pData; | 
|---|
| 5279 |  | 
|---|
| 5280 | if(NULL!=pBuffer) | 
|---|
| 5281 | { | 
|---|
| 5282 | // release old ref and copy data | 
|---|
| 5283 | memcpy(pBuffer,lpData,dwDataSize); | 
|---|
| 5284 | pSData->pData = pBuffer; | 
|---|
| 5285 | pSData->dwSize = dwDataSize; // Update the size | 
|---|
| 5286 | pSData->dwFlags = dwFlags;   // Update the flags | 
|---|
| 5287 | } | 
|---|
| 5288 | else | 
|---|
| 5289 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5290 | } | 
|---|
| 5291 | } | 
|---|
| 5292 | } | 
|---|
| 5293 | } | 
|---|
| 5294 | else | 
|---|
| 5295 | { | 
|---|
| 5296 | // New data | 
|---|
| 5297 |  | 
|---|
| 5298 | pSData = new(SURFPRIVATEDATA); | 
|---|
| 5299 | if (NULL!=pSData) | 
|---|
| 5300 | { | 
|---|
| 5301 | if(dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5302 | { | 
|---|
| 5303 | memcpy(&(pSData->guidTag),&refGUID,sizeof(GUID)); | 
|---|
| 5304 | pSData->pData = lpData; | 
|---|
| 5305 | pSData->dwSize = 4; | 
|---|
| 5306 | pSData->dwFlags = dwFlags; | 
|---|
| 5307 | pSData->isValid = TRUE; | 
|---|
| 5308 | ((OS2IDirectDrawSurface *)lpData)->lpVtbl->AddRef(lpData); | 
|---|
| 5309 | } | 
|---|
| 5310 | else | 
|---|
| 5311 | { | 
|---|
| 5312 | pSData->pData = malloc(dwDataSize); | 
|---|
| 5313 | if(NULL!=pSData->pData) | 
|---|
| 5314 | { | 
|---|
| 5315 | memcpy(&(pSData->guidTag),&refGUID,sizeof(GUID)); | 
|---|
| 5316 | memcpy(pSData->pData,lpData,dwDataSize); | 
|---|
| 5317 | pSData->dwSize  = dwDataSize; | 
|---|
| 5318 | pSData->dwFlags = dwFlags; | 
|---|
| 5319 | pSData->isValid = TRUE; | 
|---|
| 5320 |  | 
|---|
| 5321 | if( DPA_InsertPtr( me->DPA_SurfacePrivateData, | 
|---|
| 5322 | DPA_GetPtrCount(me->DPA_SurfacePrivateData), | 
|---|
| 5323 | pSData) <0) | 
|---|
| 5324 | { | 
|---|
| 5325 | delete(pSData); | 
|---|
| 5326 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5327 | } | 
|---|
| 5328 | } | 
|---|
| 5329 | else | 
|---|
| 5330 | { | 
|---|
| 5331 | delete(pSData); | 
|---|
| 5332 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5333 | } | 
|---|
| 5334 | } | 
|---|
| 5335 |  | 
|---|
| 5336 | } | 
|---|
| 5337 | else | 
|---|
| 5338 | rc = DDERR_OUTOFMEMORY; | 
|---|
| 5339 | } | 
|---|
| 5340 |  | 
|---|
| 5341 | return rc; | 
|---|
| 5342 | } | 
|---|
| 5343 | //****************************************************************************** | 
|---|
| 5344 | //****************************************************************************** | 
|---|
| 5345 | HRESULT __stdcall SurfGetPrivateData(THIS This, REFGUID refGUID, LPVOID lpData, LPDWORD lpDataSize) | 
|---|
| 5346 | { | 
|---|
| 5347 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5348 | int i; | 
|---|
| 5349 | PSURFPRIVATEDATA pSData; | 
|---|
| 5350 | HRESULT rc; | 
|---|
| 5351 | BOOL bFound = FALSE; | 
|---|
| 5352 |  | 
|---|
| 5353 | #ifdef DEBUG | 
|---|
| 5354 | WriteLog("SurfGetPrivateData\n"); | 
|---|
| 5355 | #endif | 
|---|
| 5356 |  | 
|---|
| 5357 | if(NULL==me) | 
|---|
| 5358 | return(DDERR_INVALIDOBJECT); | 
|---|
| 5359 |  | 
|---|
| 5360 | if((NULL==lpData)||(NULL==lpDataSize)) | 
|---|
| 5361 | return(DDERR_INVALIDPARAMS); | 
|---|
| 5362 |  | 
|---|
| 5363 | if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0) | 
|---|
| 5364 | { | 
|---|
| 5365 | i=0; | 
|---|
| 5366 | while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound) | 
|---|
| 5367 | { | 
|---|
| 5368 | pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i); | 
|---|
| 5369 |  | 
|---|
| 5370 | if (IsEqualGUID(pSData->guidTag,refGUID)) | 
|---|
| 5371 | bFound = TRUE; | 
|---|
| 5372 |  | 
|---|
| 5373 | i++; | 
|---|
| 5374 | } | 
|---|
| 5375 | } | 
|---|
| 5376 |  | 
|---|
| 5377 | if(bFound) | 
|---|
| 5378 | { | 
|---|
| 5379 | if(!pSData->isValid) | 
|---|
| 5380 | { | 
|---|
| 5381 | rc =DDERR_EXPIRED; | 
|---|
| 5382 | } | 
|---|
| 5383 | else | 
|---|
| 5384 | { | 
|---|
| 5385 | if(pSData->dwSize > *lpDataSize) | 
|---|
| 5386 | { | 
|---|
| 5387 | // Buffer to small return needed Size | 
|---|
| 5388 | *lpDataSize = pSData->dwSize; | 
|---|
| 5389 | rc = DDERR_MOREDATA; | 
|---|
| 5390 | } | 
|---|
| 5391 | else | 
|---|
| 5392 | { | 
|---|
| 5393 | memcpy(lpData,pSData->pData,pSData->dwSize); | 
|---|
| 5394 | rc = DD_OK; | 
|---|
| 5395 | } | 
|---|
| 5396 | } | 
|---|
| 5397 | } | 
|---|
| 5398 | else | 
|---|
| 5399 | rc = DDERR_NOTFOUND; | 
|---|
| 5400 |  | 
|---|
| 5401 |  | 
|---|
| 5402 | return rc; | 
|---|
| 5403 | } | 
|---|
| 5404 | //****************************************************************************** | 
|---|
| 5405 | //****************************************************************************** | 
|---|
| 5406 | HRESULT __stdcall SurfFreePrivateData(THIS This, REFGUID refGUID) | 
|---|
| 5407 | { | 
|---|
| 5408 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5409 | int i; | 
|---|
| 5410 | PSURFPRIVATEDATA pSData; | 
|---|
| 5411 | BOOL bFound = FALSE; | 
|---|
| 5412 |  | 
|---|
| 5413 | #ifdef DEBUG | 
|---|
| 5414 | WriteLog("SurfFreePrivateData\n"); | 
|---|
| 5415 | #endif | 
|---|
| 5416 |  | 
|---|
| 5417 | if(NULL==me) | 
|---|
| 5418 | return(DDERR_INVALIDOBJECT); | 
|---|
| 5419 |  | 
|---|
| 5420 | if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0) | 
|---|
| 5421 | { | 
|---|
| 5422 | i=0; | 
|---|
| 5423 | while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData) && !bFound) | 
|---|
| 5424 | { | 
|---|
| 5425 | pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i); | 
|---|
| 5426 |  | 
|---|
| 5427 | if (IsEqualGUID(pSData->guidTag,refGUID)) | 
|---|
| 5428 | { | 
|---|
| 5429 | bFound = TRUE; | 
|---|
| 5430 |  | 
|---|
| 5431 | if(pSData->isValid) | 
|---|
| 5432 | { | 
|---|
| 5433 | // delete the data if valid | 
|---|
| 5434 | if (pSData->dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5435 | { | 
|---|
| 5436 | // pointer to com stored so calll its release | 
|---|
| 5437 | ((OS2IDirectDrawSurface *) pSData->pData)->lpVtbl->Release(pSData->pData); | 
|---|
| 5438 | } | 
|---|
| 5439 | else | 
|---|
| 5440 | { | 
|---|
| 5441 | // Free allocated data | 
|---|
| 5442 | free( pSData->pData); | 
|---|
| 5443 | } | 
|---|
| 5444 | } | 
|---|
| 5445 | // Now remove the entry from the list | 
|---|
| 5446 | DPA_DeletePtr(me->DPA_SurfacePrivateData,i); | 
|---|
| 5447 | } | 
|---|
| 5448 | i++; | 
|---|
| 5449 | } | 
|---|
| 5450 | } | 
|---|
| 5451 |  | 
|---|
| 5452 | return (bFound?DD_OK:DDERR_NOTFOUND); | 
|---|
| 5453 | } | 
|---|
| 5454 | //****************************************************************************** | 
|---|
| 5455 | //****************************************************************************** | 
|---|
| 5456 | HRESULT __stdcall SurfGetUniquenessValue(THIS This, LPDWORD lpValue) | 
|---|
| 5457 | { | 
|---|
| 5458 | #ifdef DEBUG | 
|---|
| 5459 | WriteLog("SurfGetUniquenessValue\n"); | 
|---|
| 5460 | #endif | 
|---|
| 5461 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5462 | if (NULL==lpValue) | 
|---|
| 5463 | return DDERR_INVALIDPARAMS; | 
|---|
| 5464 |  | 
|---|
| 5465 | *lpValue = me->dwUniqueValue; | 
|---|
| 5466 | return DD_OK; | 
|---|
| 5467 | } | 
|---|
| 5468 | //****************************************************************************** | 
|---|
| 5469 | //****************************************************************************** | 
|---|
| 5470 | HRESULT __stdcall SurfChangeUniquenessValue(THIS This) | 
|---|
| 5471 | { | 
|---|
| 5472 | OS2IDirectDrawSurface *me = (OS2IDirectDrawSurface *)This; | 
|---|
| 5473 | int i; | 
|---|
| 5474 | PSURFPRIVATEDATA pSData; | 
|---|
| 5475 |  | 
|---|
| 5476 |  | 
|---|
| 5477 | #ifdef DEBUG | 
|---|
| 5478 | WriteLog("SurfChangeUniquenessValue\n"); | 
|---|
| 5479 | #endif | 
|---|
| 5480 | me->dwUniqueValue++; | 
|---|
| 5481 |  | 
|---|
| 5482 | if(DPA_GetPtrCount(me->DPA_SurfacePrivateData)>0) | 
|---|
| 5483 | { | 
|---|
| 5484 | i=0; | 
|---|
| 5485 | while(i<DPA_GetPtrCount(me->DPA_SurfacePrivateData)) | 
|---|
| 5486 | { | 
|---|
| 5487 | pSData = (PSURFPRIVATEDATA) DPA_FastGetPtr(me->DPA_SurfacePrivateData,i); | 
|---|
| 5488 | if (pSData->dwFlags & DDSPD_VOLATILE) | 
|---|
| 5489 | { | 
|---|
| 5490 | // Data becomes unvalid after a Surface change | 
|---|
| 5491 | if (pSData->dwFlags & DDSPD_IUNKNOWNPOINTER) | 
|---|
| 5492 | { | 
|---|
| 5493 | // pointer to com stored so call its release | 
|---|
| 5494 | ((OS2IDirectDrawSurface *) pSData->pData)->lpVtbl->Release(pSData->pData); | 
|---|
| 5495 | } | 
|---|
| 5496 | else | 
|---|
| 5497 | { | 
|---|
| 5498 | // Free allocated data | 
|---|
| 5499 | free( pSData->pData); | 
|---|
| 5500 | } | 
|---|
| 5501 | pSData->pData = NULL; | 
|---|
| 5502 | pSData->isValid = FALSE; // set flag to invalid | 
|---|
| 5503 | } | 
|---|
| 5504 | i++; | 
|---|
| 5505 | } | 
|---|
| 5506 | } | 
|---|
| 5507 |  | 
|---|
| 5508 | return (DD_OK); | 
|---|
| 5509 | } | 
|---|
| 5510 |  | 
|---|
| 5511 | //****************************************************************************** | 
|---|
| 5512 | // | 
|---|
| 5513 | //  Purpose function copies one part of the bitmap inside the same bitmap | 
|---|
| 5514 | // | 
|---|
| 5515 | //****************************************************************************** | 
|---|
| 5516 |  | 
|---|
| 5517 | void __cdecl MoveRects(char* pBuffer, LPRECT lpDestRect, LPRECT lpSrcRect, int bpp, LONG lPitch) | 
|---|
| 5518 | { | 
|---|
| 5519 |  | 
|---|
| 5520 | char *pBltPos, *pSrcPos; | 
|---|
| 5521 | int BlitWidth,BlitHeight; | 
|---|
| 5522 | static char Scanline[6400];  // sufficient for 1600 at 32 bit | 
|---|
| 5523 |  | 
|---|
| 5524 | // Bridge, we may got a problem ;) | 
|---|
| 5525 | // Check for Overlapping Rects | 
|---|
| 5526 |  | 
|---|
| 5527 | pBltPos = pBuffer; | 
|---|
| 5528 | pSrcPos = pBuffer; | 
|---|
| 5529 |  | 
|---|
| 5530 | if(lpDestRect->top <= lpSrcRect->top) | 
|---|
| 5531 | { | 
|---|
| 5532 | //  +-------+     +-------+      +-------+ | 
|---|
| 5533 | //  |S      |     |S      |      |S      |  +---+---+---+ | 
|---|
| 5534 | //  |   +---|---+ +-------+  +---|---+   |  |S/D|D/S|   | | 
|---|
| 5535 | //  |   | D |   | | D     |  | D |   |   |  |   |   |   | | 
|---|
| 5536 | //  +-------+   | +-------+  |   +-------+  |   |   |   | | 
|---|
| 5537 | //      |       | |       |  |       |      +---+---+---+ | 
|---|
| 5538 | //      +-------+ +-------+  +-------+ | 
|---|
| 5539 | // | 
|---|
| 5540 | // We got one of the above cases (or no overlapping) so copy from bottom up | 
|---|
| 5541 |  | 
|---|
| 5542 | pBltPos += (lpDestRect->left * bpp) + lPitch * lpDestRect->top; | 
|---|
| 5543 | pSrcPos += (lpSrcRect->left * bpp)  + lPitch * (lpSrcRect->bottom-1); | 
|---|
| 5544 | BlitHeight = lpDestRect->bottom - lpDestRect->top; | 
|---|
| 5545 | BlitWidth  = (lpDestRect->right - lpDestRect->left) * bpp; | 
|---|
| 5546 |  | 
|---|
| 5547 | while(1) | 
|---|
| 5548 | { | 
|---|
| 5549 | memcpy(Scanline,pSrcPos,BlitWidth); | 
|---|
| 5550 | memcpy(pBltPos,Scanline,BlitWidth); | 
|---|
| 5551 | pBltPos += lPitch; | 
|---|
| 5552 | pSrcPos -= lPitch; | 
|---|
| 5553 | if(! (--BlitHeight)) | 
|---|
| 5554 | break; | 
|---|
| 5555 | } | 
|---|
| 5556 | } | 
|---|
| 5557 | else | 
|---|
| 5558 | { | 
|---|
| 5559 | //  +-------+     +-------+      +-------+ | 
|---|
| 5560 | //  | D     |     | D     |      | D     | | 
|---|
| 5561 | //  |   +---|---+ +-------+  +---|---+   | | 
|---|
| 5562 | //  |   |S  |   | |S      |  |S  |   |   | | 
|---|
| 5563 | //  +-------+   | +-------+  |   +-------+ | 
|---|
| 5564 | //      |       | |       |  |       | | 
|---|
| 5565 | //      +-------+ +-------+  +-------+ | 
|---|
| 5566 | // | 
|---|
| 5567 | // We got one of the above cases so copy top down | 
|---|
| 5568 |  | 
|---|
| 5569 | pBltPos += (lpDestRect->left * bpp) + lPitch * lpDestRect->top; | 
|---|
| 5570 | pSrcPos += (lpSrcRect->left  * bpp) + lPitch * lpSrcRect->top; | 
|---|
| 5571 | BlitHeight = lpDestRect->bottom - lpDestRect->top; | 
|---|
| 5572 | BlitWidth  = (lpDestRect->right - lpDestRect->left) * bpp; | 
|---|
| 5573 |  | 
|---|
| 5574 | while(1) | 
|---|
| 5575 | { | 
|---|
| 5576 | memcpy(Scanline,pSrcPos,BlitWidth); | 
|---|
| 5577 | memcpy(pBltPos,Scanline,BlitWidth); | 
|---|
| 5578 | pBltPos += lPitch; | 
|---|
| 5579 | pSrcPos += lPitch; | 
|---|
| 5580 | if(! (--BlitHeight)) | 
|---|
| 5581 | break; | 
|---|
| 5582 | } | 
|---|
| 5583 | } | 
|---|
| 5584 |  | 
|---|
| 5585 | } | 
|---|
| 5586 |  | 
|---|
| 5587 | //****************************************************************************** | 
|---|
| 5588 | // | 
|---|
| 5589 | //  Purpose : Do a blit using the precalced Transbuffer | 
|---|
| 5590 | //            That is the only way to do fast blits if a colorrange is used | 
|---|
| 5591 | //            and we can find totally transparent lines and don't blit them | 
|---|
| 5592 | //            and detect if the part of the line is transparent | 
|---|
| 5593 | // | 
|---|
| 5594 | //            Idea for a kind of mask buffer | 
|---|
| 5595 | //            Format of Transparentbuffer (each line): | 
|---|
| 5596 | //            the first DWORD contains 2 WORDS with Offset of First Non transparent | 
|---|
| 5597 | //            pixel in the low word and the last non transparent pixel in a row in | 
|---|
| 5598 | //            the high word. => 0 = line totally transparent! | 
|---|
| 5599 | //            This limits the max supported width to 2^16 but I thing this is enougth | 
|---|
| 5600 | //            The size per line is 1+((Width+31) & ~31) DWORDS => each Bit represents | 
|---|
| 5601 | //            1 pixel | 
|---|
| 5602 | // | 
|---|
| 5603 | //            TransparentBufferCreate(lpDDSurfaceDesc->dwWidth, lpDDSurfaceDesc->dwHeight); | 
|---|
| 5604 | // | 
|---|
| 5605 | //          Layout of a DWORD: | 
|---|
| 5606 | //             UUVVWWXX  dword is processed LS Byte FIRST ... | 
|---|
| 5607 | //             Each bit in a byte stands for one pixel. MS Bit First | 
|---|
| 5608 | // | 
|---|
| 5609 | //          example: Bitmap (16x5) (X= opaque, . = Transparent) | 
|---|
| 5610 | //                   ...XX...XX....XX | 
|---|
| 5611 | //                   ..XXXX....XXXX.. | 
|---|
| 5612 | //                   ................ | 
|---|
| 5613 | //                   .........XXXXXX. | 
|---|
| 5614 | //                   ...XX...X......X | 
|---|
| 5615 | // | 
|---|
| 5616 | //                   Transparent buffer (2DWORDS) per line | 
|---|
| 5617 | // | 
|---|
| 5618 | //         0x00100003, 0x0000C318 | 
|---|
| 5619 | //         0x000E0002, 0x00003C3C | 
|---|
| 5620 | //         0x00000000, 0x00000000 | 
|---|
| 5621 | //         0x000F000A, 0x00007E00 | 
|---|
| 5622 | //         0x00100003, 0x00008118 | 
|---|
| 5623 | //****************************************************************************** | 
|---|
| 5624 |  | 
|---|
| 5625 | void __cdecl TransSRCBlit8(LPDDSURFACEDESC2 pDestDesc, LPDDSURFACEDESC2 pSrcDesc,  char *pAlpha, LPRECT lpSrcRect) | 
|---|
| 5626 | { | 
|---|
| 5627 | DWORD *pdwTLine; // pointer to the transparent buffer | 
|---|
| 5628 | DWORD dwTLineLen;      // # of DWORDS in each tBuffer line | 
|---|
| 5629 | DWORD dwTLineStart;     // # DWORD in which the first transinfo is | 
|---|
| 5630 | DWORD dwTDWStart;       // byte in which the firs transinfo is | 
|---|
| 5631 | DWORD dwTrans;          // current transparentvalue | 
|---|
| 5632 | DWORD BlitWidth; | 
|---|
| 5633 | dwTLineLen = 1 + ((pSrcDesc->dwWidth + 31) & ~31); | 
|---|
| 5634 | pdwTLine = (DWORD*)pAlpha + (dwTLineLen* lpSrcRect->top); | 
|---|
| 5635 | dwTLineStart = 1+(lpSrcRect->left/32); | 
|---|
| 5636 | dwTDWStart   = (lpSrcRect->left+8)/8; | 
|---|
| 5637 | } | 
|---|
| 5638 |  | 
|---|
| 5639 |  | 
|---|