2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI Driver Surace Functions
5 * FILE: subsys/win32k/eng/surface.c
6 * PROGRAMER: Jason Filby
9 * 9/11/2000: Updated to handle real pixel packed bitmaps (UPDATE TO DATE COMPLETED)
11 * - Create a GDI bitmap with all formats, perform all drawing operations on them, render to VGA surface
12 * refer to \test\microwin\src\engine\devdraw.c for info on correct pixel plotting for various formats
15 #include <ddk/winddi.h>
16 #include <win32k/dc.h>
17 #include <include/dib.h>
18 #include <include/object.h>
19 #include <include/paint.h>
23 #include <win32k/debug1.h>
25 INT
BitsPerFormat(ULONG Format
)
29 case BMF_1BPP
: return 1;
31 case BMF_4RLE
: return 4;
33 case BMF_8RLE
: return 8;
34 case BMF_16BPP
: return 16;
35 case BMF_24BPP
: return 24;
36 case BMF_32BPP
: return 32;
41 ULONG
BitmapFormat(WORD Bits
, DWORD Compression
)
48 case 1: return BMF_1BPP
;
49 case 4: return BMF_4BPP
;
50 case 8: return BMF_8BPP
;
51 case 16: return BMF_16BPP
;
52 case 24: return BMF_24BPP
;
53 case 32: return BMF_32BPP
;
56 case BI_RLE4
: return BMF_4RLE
;
57 case BI_RLE8
: return BMF_8RLE
;
63 VOID
InitializeHooks(SURFGDI
*SurfGDI
)
65 SurfGDI
->BitBlt
= NULL
;
66 SurfGDI
->CopyBits
= NULL
;
67 SurfGDI
->CreateDeviceBitmap
= NULL
;
68 SurfGDI
->SetPalette
= NULL
;
69 SurfGDI
->TransparentBlt
= NULL
;
73 EngCreateDeviceBitmap(IN DHSURF dhsurf
,
80 NewBitmap
= EngCreateBitmap(Size
, DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
)), Format
, 0, NULL
);
81 SurfObj
= (PVOID
)AccessUserObject((ULONG
)NewBitmap
);
82 SurfObj
->dhpdev
= dhsurf
;
88 EngCreateBitmap(IN SIZEL Size
,
99 NewBitmap
= (PVOID
)CreateGDIHandle(sizeof(SURFGDI
), sizeof(SURFOBJ
));
100 if( !ValidEngHandle( NewBitmap
) )
103 SurfObj
= (SURFOBJ
*) AccessUserObject( NewBitmap
);
104 SurfGDI
= (SURFGDI
*) AccessInternalObject( NewBitmap
);
108 InitializeHooks(SurfGDI
);
110 SurfGDI
->BitsPerPixel
= BitsPerFormat(Format
);
111 SurfObj
->lDelta
= Width
;
112 SurfObj
->cjBits
= SurfObj
->lDelta
* Size
.cy
;
116 SurfObj
->pvBits
= Bits
;
119 if(Flags
& BMF_USERMEM
)
121 SurfObj
->pvBits
= EngAllocUserMem(SurfObj
->cjBits
, 0);
123 if(Flags
& BMF_NOZEROINIT
)
125 SurfObj
->pvBits
= EngAllocMem(0, SurfObj
->cjBits
, 0);
127 SurfObj
->pvBits
= EngAllocMem(FL_ZERO_MEMORY
, SurfObj
->cjBits
, 0);
132 SurfObj
->dhsurf
= 0; // device managed surface
134 SurfObj
->sizlBitmap
= Size
;
135 SurfObj
->iBitmapFormat
= Format
;
136 SurfObj
->iType
= STYPE_BITMAP
;
138 // Use flags to determine bitmap type -- TOP_DOWN or whatever
144 EngCreateDeviceSurface(IN DHSURF dhsurf
,
152 NewSurface
= (HSURF
)CreateGDIHandle(sizeof( SURFGDI
), sizeof( SURFOBJ
));
153 if( !ValidEngHandle( NewSurface
) )
156 SurfObj
= (SURFOBJ
*) AccessUserObject( NewSurface
);
157 SurfGDI
= (SURFGDI
*) AccessInternalObject( NewSurface
);
161 InitializeHooks(SurfGDI
);
163 SurfGDI
->BitsPerPixel
= BitsPerFormat(Format
);
164 SurfObj
->dhsurf
= dhsurf
;
165 SurfObj
->hsurf
= dhsurf
; // FIXME: Is this correct??
166 SurfObj
->sizlBitmap
= Size
;
167 SurfObj
->iBitmapFormat
= Format
;
168 SurfObj
->lDelta
= DIB_GetDIBWidthBytes(Size
.cx
, BitsPerFormat(Format
));
169 SurfObj
->iType
= STYPE_DEVICE
;
174 PFN
DriverFunction(DRVENABLEDATA
*DED
, ULONG DriverFunc
)
178 for(i
=0; i
<DED
->c
; i
++)
180 if(DED
->pdrvfn
[i
].iFunc
== DriverFunc
)
181 return DED
->pdrvfn
[i
].pfn
;
187 EngAssociateSurface(IN HSURF Surface
,
195 Device
= (GDIDEVICE
*)Dev
;
197 SurfGDI
= (PVOID
)AccessInternalObject((ULONG
)Surface
);
198 SurfObj
= (PVOID
)AccessUserObject((ULONG
)Surface
);
200 // Associate the hdev
203 // Hook up specified functions
204 if(Hooks
& HOOK_BITBLT
) SurfGDI
->BitBlt
= Device
->DriverFunctions
.BitBlt
;
205 if(Hooks
& HOOK_TRANSPARENTBLT
) SurfGDI
->TransparentBlt
= Device
->DriverFunctions
.TransparentBlt
;
206 if(Hooks
& HOOK_STRETCHBLT
) SurfGDI
->StretchBlt
= (PFN_StretchBlt
)Device
->DriverFunctions
.StretchBlt
;
207 if(Hooks
& HOOK_TEXTOUT
) SurfGDI
->TextOut
= Device
->DriverFunctions
.TextOut
;
208 if(Hooks
& HOOK_PAINT
) SurfGDI
->Paint
= Device
->DriverFunctions
.Paint
;
209 if(Hooks
& HOOK_STROKEPATH
) SurfGDI
->StrokePath
= Device
->DriverFunctions
.StrokePath
;
210 if(Hooks
& HOOK_FILLPATH
) SurfGDI
->FillPath
= Device
->DriverFunctions
.FillPath
;
211 if(Hooks
& HOOK_STROKEANDFILLPATH
) SurfGDI
->StrokeAndFillPath
= Device
->DriverFunctions
.StrokeAndFillPath
;
212 if(Hooks
& HOOK_LINETO
) SurfGDI
->LineTo
= Device
->DriverFunctions
.LineTo
;
213 if(Hooks
& HOOK_COPYBITS
) SurfGDI
->CopyBits
= Device
->DriverFunctions
.CopyBits
;
214 if(Hooks
& HOOK_SYNCHRONIZE
) SurfGDI
->Synchronize
= Device
->DriverFunctions
.Synchronize
;
215 if(Hooks
& HOOK_SYNCHRONIZEACCESS
) SurfGDI
->SynchronizeAccess
= TRUE
;
217 SurfGDI
->CreateDeviceBitmap
= Device
->DriverFunctions
.CreateDeviceBitmap
;
218 SurfGDI
->SetPalette
= Device
->DriverFunctions
.SetPalette
;
219 SurfGDI
->MovePointer
= Device
->DriverFunctions
.MovePointer
;
220 SurfGDI
->SetPointerShape
= (PFN_SetPointerShape
)Device
->DriverFunctions
.SetPointerShape
;
226 EngDeleteSurface(IN HSURF Surface
)
228 FreeGDIHandle((ULONG
)Surface
);
233 EngEraseSurface(SURFOBJ
*Surface
,
237 return FillSolid(Surface
, Rect
, iColor
);
241 EngLockSurface(IN HSURF Surface
)
243 // FIXME: Call GDI_LockObject (see subsys/win32k/objects/gdi.c)
244 return (SURFOBJ
*)AccessUserObject((ULONG
)Surface
);
248 EngUnlockSurface(IN SURFOBJ
*Surface
)
250 // FIXME: Call GDI_UnlockObject