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.
19 /* $Id: surface.c,v 1.46 2004/12/14 04:55:43 royce Exp $
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
)
65 case 1: return BMF_1BPP
;
66 case 4: return BMF_4BPP
;
67 case 8: return BMF_8BPP
;
68 case 16: return BMF_16BPP
;
69 case 24: return BMF_24BPP
;
70 case 32: return BMF_32BPP
;
74 case BI_RLE4
: return BMF_4RLE
;
75 case BI_RLE8
: return BMF_8RLE
;
85 EngCreateDeviceBitmap(IN DHSURF dhsurf
,
92 NewBitmap
= EngCreateBitmap(Size
, DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
)), Format
, 0, NULL
);
93 SurfObj
= EngLockSurface((HSURF
)NewBitmap
);
94 SurfObj
->dhsurf
= dhsurf
;
95 EngUnlockSurface(SurfObj
);
100 VOID
Decompress4bpp(SIZEL Size
, BYTE
*CompressedBits
, BYTE
*UncompressedBits
, LONG Delta
)
106 int width
= ((Size
.cx
+1)/2);
107 int height
= Size
.cy
- 1;
108 BYTE
*begin
= CompressedBits
;
109 BYTE
*bits
= CompressedBits
;
113 length
= *bits
++ / 2;
119 if (x
>= width
) break;
120 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
145 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
150 if ((bits
- begin
) & 1)
157 VOID
Decompress8bpp(SIZEL Size
, BYTE
*CompressedBits
, BYTE
*UncompressedBits
, LONG Delta
)
164 int height
= Size
.cy
- 1;
165 BYTE
*begin
= CompressedBits
;
166 BYTE
*bits
= CompressedBits
;
176 if (x
>= width
) break;
177 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
201 temp
= UncompressedBits
+ (((height
- y
) * Delta
) + x
);
206 if ((bits
- begin
) & 1)
214 IntCreateBitmap(IN SIZEL Size
,
222 BITMAPOBJ
*BitmapObj
;
223 PVOID UncompressedBits
;
224 ULONG UncompressedFormat
;
229 NewBitmap
= BITMAPOBJ_AllocBitmap();
230 if (NewBitmap
== NULL
)
233 BitmapObj
= BITMAPOBJ_LockBitmap(NewBitmap
);
234 SurfObj
= &BitmapObj
->SurfObj
;
236 if (Format
== BMF_4RLE
)
238 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(BMF_4BPP
));
239 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
240 UncompressedFormat
= BMF_4BPP
;
241 UncompressedBits
= EngAllocMem(FL_ZERO_MEMORY
, SurfObj
->cjBits
, 0);
242 Decompress4bpp(Size
, (BYTE
*)Bits
, (BYTE
*)UncompressedBits
, SurfObj
->lDelta
);
244 else if (Format
== BMF_8RLE
)
246 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(BMF_8BPP
));
247 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
248 UncompressedFormat
= BMF_8BPP
;
249 UncompressedBits
= EngAllocMem(FL_ZERO_MEMORY
, SurfObj
->cjBits
, 0);
250 Decompress8bpp(Size
, (BYTE
*)Bits
, (BYTE
*)UncompressedBits
, SurfObj
->lDelta
);
254 SurfObj
->lDelta
= abs(Width
);
255 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
256 UncompressedBits
= Bits
;
257 UncompressedFormat
= Format
;
260 if (UncompressedBits
!= NULL
)
262 SurfObj
->pvBits
= UncompressedBits
;
266 if (SurfObj
->cjBits
== 0)
268 SurfObj
->pvBits
= NULL
;
272 if (0 != (Flags
& BMF_USERMEM
))
274 SurfObj
->pvBits
= EngAllocUserMem(SurfObj
->cjBits
, 0);
278 SurfObj
->pvBits
= EngAllocMem(0 != (Flags
& BMF_NOZEROINIT
) ? 0 : FL_ZERO_MEMORY
,
281 if (SurfObj
->pvBits
== NULL
)
283 BITMAPOBJ_UnlockBitmap(NewBitmap
);
284 BITMAPOBJ_FreeBitmap(NewBitmap
);
291 if (0 == (Flags
& BMF_TOPDOWN
))
293 SurfObj
->pvScan0
= (PVOID
) ((ULONG_PTR
) SurfObj
->pvBits
+ SurfObj
->cjBits
- SurfObj
->lDelta
);
294 SurfObj
->lDelta
= - SurfObj
->lDelta
;
298 SurfObj
->pvScan0
= SurfObj
->pvBits
;
301 SurfObj
->dhsurf
= 0; /* device managed surface */
302 SurfObj
->hsurf
= (HSURF
)NewBitmap
;
303 SurfObj
->dhpdev
= NULL
;
304 SurfObj
->hdev
= NULL
;
305 SurfObj
->sizlBitmap
= Size
;
306 SurfObj
->iBitmapFormat
= UncompressedFormat
;
307 SurfObj
->iType
= STYPE_BITMAP
;
308 SurfObj
->fjBitmap
= Flags
& (BMF_TOPDOWN
| BMF_NOZEROINIT
);
311 BitmapObj
->flHooks
= 0;
312 BitmapObj
->flFlags
= 0;
313 BitmapObj
->dimension
.cx
= 0;
314 BitmapObj
->dimension
.cy
= 0;
315 BitmapObj
->dib
= NULL
;
317 BITMAPOBJ_UnlockBitmap(NewBitmap
);
326 EngCreateBitmap(IN SIZEL Size
,
334 NewBitmap
= IntCreateBitmap(Size
, Width
, Format
, Flags
, Bits
);
335 GDIOBJ_SetOwnership(NewBitmap
, NULL
);
344 EngCreateDeviceSurface(IN DHSURF dhsurf
,
350 BITMAPOBJ
*BitmapObj
;
352 NewSurface
= (HSURF
)BITMAPOBJ_AllocBitmap();
353 if (NewSurface
== NULL
)
356 GDIOBJ_SetOwnership(NewSurface
, NULL
);
358 BitmapObj
= BITMAPOBJ_LockBitmap(NewSurface
);
359 SurfObj
= &BitmapObj
->SurfObj
;
361 SurfObj
->dhsurf
= dhsurf
;
362 SurfObj
->hsurf
= NewSurface
;
363 SurfObj
->sizlBitmap
= Size
;
364 SurfObj
->iBitmapFormat
= Format
;
365 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
));
366 SurfObj
->iType
= STYPE_DEVICE
;
369 BitmapObj
->flHooks
= 0;
371 BITMAPOBJ_UnlockBitmap(NewSurface
);
376 PFN FASTCALL
DriverFunction(DRVENABLEDATA
*DED
, ULONG DriverFunc
)
380 for(i
=0; i
<DED
->c
; i
++)
382 if(DED
->pdrvfn
[i
].iFunc
== DriverFunc
)
383 return DED
->pdrvfn
[i
].pfn
;
392 EngAssociateSurface(IN HSURF Surface
,
397 BITMAPOBJ
*BitmapObj
;
400 Device
= (GDIDEVICE
*)Dev
;
402 BitmapObj
= BITMAPOBJ_LockBitmap(Surface
);
404 SurfObj
= &BitmapObj
->SurfObj
;
406 /* Associate the hdev */
408 SurfObj
->dhpdev
= Device
->PDev
;
410 /* Hook up specified functions */
411 BitmapObj
->flHooks
= Hooks
;
413 BITMAPOBJ_UnlockBitmap(Surface
);
434 pso
= EngLockSurface(hsurf
);
440 if (!EngAssociateSurface(hsurf
, hdev
, flHooks
))
442 EngUnlockSurface(pso
);
447 pso
->dhsurf
= dhsurf
;
448 pso
->lDelta
= lDelta
;
449 pso
->pvScan0
= pvScan0
;
451 EngUnlockSurface(pso
);
460 EngDeleteSurface(IN HSURF Surface
)
462 GDIOBJ_SetOwnership(Surface
, PsGetCurrentProcess());
463 BITMAPOBJ_FreeBitmap(Surface
);
471 EngEraseSurface(SURFOBJ
*Surface
,
477 return FillSolid(Surface
, Rect
, iColor
);
484 EngLockSurface(IN HSURF Surface
)
486 BITMAPOBJ
*bmp
= (BITMAPOBJ
*)BITMAPOBJ_LockBitmap(Surface
);
489 return &bmp
->SurfObj
;
499 EngUnlockSurface(IN SURFOBJ
*Surface
)
502 BITMAPOBJ_UnlockBitmap (Surface
->hsurf
);