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
34 #include <ddk/winddi.h>
35 #include <win32k/dc.h>
36 #include <win32k/gdiobj.h>
37 #include <include/dib.h>
38 #include <include/object.h>
39 #include <include/paint.h>
41 #include "../dib/dib.h"
44 #include <win32k/debug1.h>
46 INT FASTCALL BitsPerFormat(ULONG Format)
50 case BMF_1BPP: return 1;
52 case BMF_4RLE: return 4;
54 case BMF_8RLE: return 8;
55 case BMF_16BPP: return 16;
56 case BMF_24BPP: return 24;
57 case BMF_32BPP: return 32;
62 ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression)
69 case 1: return BMF_1BPP;
70 case 4: return BMF_4BPP;
71 case 8: return BMF_8BPP;
72 case 16: return BMF_16BPP;
73 case 24: return BMF_24BPP;
74 case 32: return BMF_32BPP;
77 case BI_RLE4: return BMF_4RLE;
78 case BI_RLE8: return BMF_8RLE;
84 static VOID Dummy_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
89 static VOID Dummy_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
94 static VOID Dummy_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
99 static BOOLEAN Dummy_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
100 SURFGDI *DestGDI, SURFGDI *SourceGDI,
101 PRECTL DestRect, POINTL *SourcePoint,
102 PBRUSHOBJ BrushObj, POINTL* BrushOrign,
103 XLATEOBJ *ColorTranslation, ULONG Rop4)
108 #define SURF_METHOD(c,n) DIB_##c##_##n
109 #define SET_SURFGDI(c)\
110 SurfGDI->DIB_PutPixel=SURF_METHOD(c,PutPixel);\
111 SurfGDI->DIB_HLine=SURF_METHOD(c,HLine);\
112 SurfGDI->DIB_VLine=SURF_METHOD(c,VLine);\
113 SurfGDI->DIB_BitBlt=SURF_METHOD(c,BitBlt);
115 VOID FASTCALL InitializeFuncs(SURFGDI *SurfGDI, ULONG BitmapFormat)
117 SurfGDI->BitBlt = NULL;
118 SurfGDI->CopyBits = NULL;
119 SurfGDI->CreateDeviceBitmap = NULL;
120 SurfGDI->SetPalette = NULL;
121 SurfGDI->TransparentBlt = NULL;
125 case BMF_1BPP: SET_SURFGDI(1BPP) break;
126 case BMF_4BPP: SET_SURFGDI(4BPP) break;
127 case BMF_8BPP: SET_SURFGDI(8BPP) break;
128 case BMF_16BPP: SET_SURFGDI(16BPP) break;
129 case BMF_24BPP: SET_SURFGDI(24BPP) break;
130 case BMF_32BPP: SET_SURFGDI(32BPP) break;
133 /* Not supported yet, fall through to unrecognized case */
135 DPRINT1("InitializeFuncs: unsupported DIB format %d\n",
138 SurfGDI->DIB_PutPixel = Dummy_PutPixel;
139 SurfGDI->DIB_HLine = Dummy_HLine;
140 SurfGDI->DIB_VLine = Dummy_VLine;
141 SurfGDI->DIB_BitBlt = Dummy_BitBlt;
150 EngCreateDeviceBitmap(IN DHSURF dhsurf,
157 NewBitmap = EngCreateBitmap(Size, DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(Format)), Format, 0, NULL);
158 SurfObj = (PVOID)AccessUserObject((ULONG)NewBitmap);
159 SurfObj->dhpdev = dhsurf;
168 EngCreateBitmap(IN SIZEL Size,
178 NewBitmap = (PVOID)CreateGDIHandle(sizeof(SURFGDI), sizeof(SURFOBJ));
179 if( !ValidEngHandle( NewBitmap ) )
182 SurfObj = (SURFOBJ*) AccessUserObject( (ULONG) NewBitmap );
183 SurfGDI = (SURFGDI*) AccessInternalObject( (ULONG) NewBitmap );
187 SurfGDI->BitsPerPixel = BitsPerFormat(Format);
188 SurfObj->lDelta = Width;
189 SurfObj->cjBits = SurfObj->lDelta * Size.cy;
193 SurfObj->pvBits = Bits;
196 if(Flags & BMF_USERMEM)
198 SurfObj->pvBits = EngAllocUserMem(SurfObj->cjBits, 0);
200 if(Flags & BMF_NOZEROINIT)
202 SurfObj->pvBits = EngAllocMem(0, SurfObj->cjBits, 0);
204 SurfObj->pvBits = EngAllocMem(FL_ZERO_MEMORY, SurfObj->cjBits, 0);
209 SurfObj->dhsurf = 0; // device managed surface
211 SurfObj->sizlBitmap = Size;
212 SurfObj->iBitmapFormat = Format;
213 SurfObj->iType = STYPE_BITMAP;
214 SurfObj->fjBitmap = Flags & (BMF_TOPDOWN | BMF_NOZEROINIT);
215 SurfObj->pvScan0 = SurfObj->pvBits;
217 InitializeFuncs(SurfGDI, Format);
219 // Use flags to determine bitmap type -- TOP_DOWN or whatever
228 EngCreateDeviceSurface(IN DHSURF dhsurf,
236 NewSurface = (HSURF)CreateGDIHandle(sizeof( SURFGDI ), sizeof( SURFOBJ ));
237 if( !ValidEngHandle( NewSurface ) )
240 SurfObj = (SURFOBJ*) AccessUserObject( (ULONG) NewSurface );
241 SurfGDI = (SURFGDI*) AccessInternalObject( (ULONG) NewSurface );
245 SurfGDI->BitsPerPixel = BitsPerFormat(Format);
246 SurfObj->dhsurf = dhsurf;
247 SurfObj->hsurf = dhsurf; // FIXME: Is this correct??
248 SurfObj->sizlBitmap = Size;
249 SurfObj->iBitmapFormat = Format;
250 SurfObj->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(Format));
251 SurfObj->iType = STYPE_DEVICE;
253 InitializeFuncs(SurfGDI, Format);
258 PFN FASTCALL DriverFunction(DRVENABLEDATA *DED, ULONG DriverFunc)
262 for(i=0; i<DED->c; i++)
264 if(DED->pdrvfn[i].iFunc == DriverFunc)
265 return DED->pdrvfn[i].pfn;
274 EngAssociateSurface(IN HSURF Surface,
282 Device = (GDIDEVICE*)Dev;
284 SurfGDI = (PVOID)AccessInternalObject((ULONG)Surface);
285 SurfObj = (PVOID)AccessUserObject((ULONG)Surface);
287 // Associate the hdev
290 // Hook up specified functions
291 if(Hooks & HOOK_BITBLT) SurfGDI->BitBlt = Device->DriverFunctions.BitBlt;
292 if(Hooks & HOOK_TRANSPARENTBLT) SurfGDI->TransparentBlt = Device->DriverFunctions.TransparentBlt;
293 if(Hooks & HOOK_STRETCHBLT) SurfGDI->StretchBlt = (PFN_StretchBlt)Device->DriverFunctions.StretchBlt;
294 if(Hooks & HOOK_TEXTOUT) SurfGDI->TextOut = Device->DriverFunctions.TextOut;
295 if(Hooks & HOOK_PAINT) SurfGDI->Paint = Device->DriverFunctions.Paint;
296 if(Hooks & HOOK_STROKEPATH) SurfGDI->StrokePath = Device->DriverFunctions.StrokePath;
297 if(Hooks & HOOK_FILLPATH) SurfGDI->FillPath = Device->DriverFunctions.FillPath;
298 if(Hooks & HOOK_STROKEANDFILLPATH) SurfGDI->StrokeAndFillPath = Device->DriverFunctions.StrokeAndFillPath;
299 if(Hooks & HOOK_LINETO) SurfGDI->LineTo = Device->DriverFunctions.LineTo;
300 if(Hooks & HOOK_COPYBITS) SurfGDI->CopyBits = Device->DriverFunctions.CopyBits;
301 if(Hooks & HOOK_SYNCHRONIZE) SurfGDI->Synchronize = Device->DriverFunctions.Synchronize;
302 if(Hooks & HOOK_SYNCHRONIZEACCESS) SurfGDI->SynchronizeAccess = TRUE;
304 SurfGDI->CreateDeviceBitmap = Device->DriverFunctions.CreateDeviceBitmap;
305 SurfGDI->SetPalette = Device->DriverFunctions.SetPalette;
306 SurfGDI->MovePointer = Device->DriverFunctions.MovePointer;
307 SurfGDI->SetPointerShape = (PFN_SetPointerShape)Device->DriverFunctions.SetPointerShape;
316 EngDeleteSurface(IN HSURF Surface)
318 FreeGDIHandle((ULONG)Surface);
326 EngEraseSurface(SURFOBJ *Surface,
330 return FillSolid(Surface, Rect, iColor);
337 EngLockSurface(IN HSURF Surface)
340 * FIXME - don't know if GDIOBJ_LockObj's return value is a SURFOBJ or not...
341 * also, what is HSURF's correct magic #?
344 GDIOBJ_LockObj ( Surface, GDI_OBJECT_TYPE_DONTCARE );
346 return (SURFOBJ*)AccessUserObject((ULONG)Surface);
353 EngUnlockSurface(IN SURFOBJ *Surface)
356 * FIXME what is HSURF's correct magic #?
359 GDIOBJ_UnlockObj ( Surface->hsurf, GDI_OBJECT_TYPE_DONTCARE );