2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: GDI Driver Surace Functions
24 * FILE: subsys/win32k/eng/surface.c
25 * PROGRAMER: Jason Filby
28 * 9/11/2000: Updated to handle real pixel packed bitmaps (UPDATE TO DATE COMPLETED)
30 * - Create a GDI bitmap with all formats, perform all drawing operations on them, render to VGA surface
31 * refer to \test\microwin\src\engine\devdraw.c for info on correct pixel plotting for various formats
37 RLE_EOL
= 0, /* End of line */
38 RLE_END
= 1, /* End of bitmap */
39 RLE_DELTA
= 2 /* Delta */
42 INT FASTCALL
BitsPerFormat(ULONG Format
)
46 case BMF_1BPP
: return 1;
48 case BMF_4RLE
: return 4;
50 case BMF_8RLE
: return 8;
51 case BMF_16BPP
: return 16;
52 case BMF_24BPP
: return 24;
53 case BMF_32BPP
: return 32;
58 ULONG FASTCALL
BitmapFormat(WORD Bits
, DWORD Compression
)
66 case 1: return BMF_1BPP
;
67 case 4: return BMF_4BPP
;
68 case 8: return BMF_8BPP
;
69 case 16: return BMF_16BPP
;
70 case 24: return BMF_24BPP
;
71 case 32: return BMF_32BPP
;
75 case BI_RLE4
: return BMF_4RLE
;
76 case BI_RLE8
: return BMF_8RLE
;
86 EngCreateDeviceBitmap(IN DHSURF dhsurf
,
93 NewBitmap
= EngCreateBitmap(Size
, DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
)), Format
, 0, NULL
);
94 SurfObj
= EngLockSurface((HSURF
)NewBitmap
);
95 SurfObj
->dhsurf
= dhsurf
;
96 EngUnlockSurface(SurfObj
);
101 VOID
Decompress4bpp(SIZEL Size
, BYTE
*CompressedBits
, BYTE
*UncompressedBits
, LONG Delta
)
107 int width
= ((Size
.cx
+1)/2);
108 int height
= Size
.cy
- 1;
109 BYTE
*begin
= CompressedBits
;
110 BYTE
*bits
= CompressedBits
;
114 length
= *bits
++ / 2;
120 if (x
>= width
) break;
121 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
146 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
151 if ((bits
- begin
) & 1)
158 VOID
Decompress8bpp(SIZEL Size
, BYTE
*CompressedBits
, BYTE
*UncompressedBits
, LONG Delta
)
165 int height
= Size
.cy
- 1;
166 BYTE
*begin
= CompressedBits
;
167 BYTE
*bits
= CompressedBits
;
177 if (x
>= width
) break;
178 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
202 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
207 if ((bits
- begin
) & 1)
215 IntCreateBitmap(IN SIZEL Size
,
223 BITMAPOBJ
*BitmapObj
;
224 PVOID UncompressedBits
;
225 ULONG UncompressedFormat
;
230 NewBitmap
= BITMAPOBJ_AllocBitmap();
231 if (NewBitmap
== NULL
)
234 BitmapObj
= BITMAPOBJ_LockBitmap(NewBitmap
);
235 SurfObj
= &BitmapObj
->SurfObj
;
237 if (Format
== BMF_4RLE
)
239 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(BMF_4BPP
));
240 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
241 UncompressedFormat
= BMF_4BPP
;
242 UncompressedBits
= EngAllocMem(FL_ZERO_MEMORY
, SurfObj
->cjBits
, 0);
243 Decompress4bpp(Size
, (BYTE
*)Bits
, (BYTE
*)UncompressedBits
, SurfObj
->lDelta
);
245 else if (Format
== BMF_8RLE
)
247 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(BMF_8BPP
));
248 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
249 UncompressedFormat
= BMF_8BPP
;
250 UncompressedBits
= EngAllocMem(FL_ZERO_MEMORY
, SurfObj
->cjBits
, 0);
251 Decompress8bpp(Size
, (BYTE
*)Bits
, (BYTE
*)UncompressedBits
, SurfObj
->lDelta
);
255 SurfObj
->lDelta
= abs(Width
);
256 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
257 UncompressedBits
= Bits
;
258 UncompressedFormat
= Format
;
261 if (UncompressedBits
!= NULL
)
263 SurfObj
->pvBits
= UncompressedBits
;
267 if (SurfObj
->cjBits
== 0)
269 SurfObj
->pvBits
= NULL
;
273 if (0 != (Flags
& BMF_USERMEM
))
275 SurfObj
->pvBits
= EngAllocUserMem(SurfObj
->cjBits
, 0);
279 SurfObj
->pvBits
= EngAllocMem(0 != (Flags
& BMF_NOZEROINIT
) ? 0 : FL_ZERO_MEMORY
,
282 if (SurfObj
->pvBits
== NULL
)
284 BITMAPOBJ_UnlockBitmap(NewBitmap
);
285 BITMAPOBJ_FreeBitmap(NewBitmap
);
292 if (0 == (Flags
& BMF_TOPDOWN
))
294 SurfObj
->pvScan0
= (PVOID
) ((ULONG_PTR
) SurfObj
->pvBits
+ SurfObj
->cjBits
- SurfObj
->lDelta
);
295 SurfObj
->lDelta
= - SurfObj
->lDelta
;
299 SurfObj
->pvScan0
= SurfObj
->pvBits
;
302 SurfObj
->dhsurf
= 0; /* device managed surface */
303 SurfObj
->hsurf
= (HSURF
)NewBitmap
;
304 SurfObj
->dhpdev
= NULL
;
305 SurfObj
->hdev
= NULL
;
306 SurfObj
->sizlBitmap
= Size
;
307 SurfObj
->iBitmapFormat
= UncompressedFormat
;
308 SurfObj
->iType
= STYPE_BITMAP
;
309 SurfObj
->fjBitmap
= Flags
& (BMF_TOPDOWN
| BMF_NOZEROINIT
);
312 BitmapObj
->flHooks
= 0;
313 BitmapObj
->flFlags
= 0;
314 BitmapObj
->dimension
.cx
= 0;
315 BitmapObj
->dimension
.cy
= 0;
316 BitmapObj
->dib
= NULL
;
318 BITMAPOBJ_UnlockBitmap(NewBitmap
);
327 EngCreateBitmap(IN SIZEL Size
,
335 NewBitmap
= IntCreateBitmap(Size
, Width
, Format
, Flags
, Bits
);
339 GDIOBJ_SetOwnership(NewBitmap
, NULL
);
348 EngCreateDeviceSurface(IN DHSURF dhsurf
,
354 BITMAPOBJ
*BitmapObj
;
356 NewSurface
= (HSURF
)BITMAPOBJ_AllocBitmap();
357 if (NewSurface
== NULL
)
360 GDIOBJ_SetOwnership(NewSurface
, NULL
);
362 BitmapObj
= BITMAPOBJ_LockBitmap(NewSurface
);
363 SurfObj
= &BitmapObj
->SurfObj
;
365 SurfObj
->dhsurf
= dhsurf
;
366 SurfObj
->hsurf
= NewSurface
;
367 SurfObj
->sizlBitmap
= Size
;
368 SurfObj
->iBitmapFormat
= Format
;
369 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
));
370 SurfObj
->iType
= STYPE_DEVICE
;
373 BitmapObj
->flHooks
= 0;
375 BITMAPOBJ_UnlockBitmap(NewSurface
);
380 PFN FASTCALL
DriverFunction(DRVENABLEDATA
*DED
, ULONG DriverFunc
)
384 for(i
=0; i
<DED
->c
; i
++)
386 if(DED
->pdrvfn
[i
].iFunc
== DriverFunc
)
387 return DED
->pdrvfn
[i
].pfn
;
396 EngAssociateSurface(IN HSURF Surface
,
401 BITMAPOBJ
*BitmapObj
;
404 Device
= (GDIDEVICE
*)Dev
;
406 BitmapObj
= BITMAPOBJ_LockBitmap(Surface
);
408 SurfObj
= &BitmapObj
->SurfObj
;
410 /* Associate the hdev */
412 SurfObj
->dhpdev
= Device
->PDev
;
414 /* Hook up specified functions */
415 BitmapObj
->flHooks
= Hooks
;
417 BITMAPOBJ_UnlockBitmap(Surface
);
438 pso
= EngLockSurface(hsurf
);
444 if (!EngAssociateSurface(hsurf
, hdev
, flHooks
))
446 EngUnlockSurface(pso
);
451 pso
->dhsurf
= dhsurf
;
452 pso
->lDelta
= lDelta
;
453 pso
->pvScan0
= pvScan0
;
455 EngUnlockSurface(pso
);
464 EngDeleteSurface(IN HSURF Surface
)
466 GDIOBJ_SetOwnership(Surface
, PsGetCurrentProcess());
467 BITMAPOBJ_FreeBitmap(Surface
);
475 EngEraseSurface(SURFOBJ
*Surface
,
481 return FillSolid(Surface
, Rect
, iColor
);
488 EngLockSurface(IN HSURF Surface
)
490 BITMAPOBJ
*bmp
= (BITMAPOBJ
*)BITMAPOBJ_LockBitmap(Surface
);
493 return &bmp
->SurfObj
;
503 EngUnlockSurface(IN SURFOBJ
*Surface
)
506 BITMAPOBJ_UnlockBitmap (Surface
->hsurf
);