1 /*
2  * ReactOS Generic Framebuffer display driver
3  *
4  * Copyright (C) 2004 Filip Navara
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "framebuf.h"
22 
23 static DRVFN DrvFunctionTable[] =
24 {
25    {INDEX_DrvEnablePDEV, (PFN)DrvEnablePDEV},
26    {INDEX_DrvCompletePDEV, (PFN)DrvCompletePDEV},
27    {INDEX_DrvDisablePDEV, (PFN)DrvDisablePDEV},
28    {INDEX_DrvEnableSurface, (PFN)DrvEnableSurface},
29    {INDEX_DrvDisableSurface, (PFN)DrvDisableSurface},
30    {INDEX_DrvAssertMode, (PFN)DrvAssertMode},
31    {INDEX_DrvGetModes, (PFN)DrvGetModes},
32    {INDEX_DrvSetPalette, (PFN)DrvSetPalette},
33    {INDEX_DrvSetPointerShape, (PFN)DrvSetPointerShape},
34    {INDEX_DrvMovePointer, (PFN)DrvMovePointer},
35    {INDEX_DrvEnableDirectDraw, (PFN)DrvEnableDirectDraw},
36    {INDEX_DrvDisableDirectDraw, (PFN)DrvDisableDirectDraw},
37 
38 };
39 
40 /*
41  * DrvEnableDirectDraw
42  */
43 
44 BOOL APIENTRY
45 DrvEnableDirectDraw(
46     DHPDEV dhpdev,
47     DD_CALLBACKS *pCallbacks,
48     DD_SURFACECALLBACKS *pSurfaceCallbacks,
49     DD_PALETTECALLBACKS *pPaletteCallbacks)
50 {
51     RtlZeroMemory(pCallbacks, sizeof(*pCallbacks));
52     RtlZeroMemory(pSurfaceCallbacks, sizeof(*pSurfaceCallbacks));
53     RtlZeroMemory(pPaletteCallbacks, sizeof(*pPaletteCallbacks));
54 
55     pCallbacks->dwSize = sizeof(*pCallbacks);
56     pSurfaceCallbacks->dwSize = sizeof(*pSurfaceCallbacks);
57     pPaletteCallbacks->dwSize = sizeof(*pPaletteCallbacks);
58 
59     /* We don't support any optional callback */
60 
61     return TRUE;
62 }
63 
64 /*
65  * DrvDisableDirectDraw
66  */
67 
68 VOID APIENTRY
69 DrvDisableDirectDraw(
70     DHPDEV dhpdev)
71 {
72 }
73 
74 /*
75  * DrvEnableDriver
76  *
77  * Initial driver entry point exported by the driver DLL. It fills in a
78  * DRVENABLEDATA structure with the driver's DDI version number and the
79  * calling addresses of all DDI functions supported by the driver.
80  *
81  * Status
82  *    @implemented
83  */
84 
85 BOOL APIENTRY
86 DrvEnableDriver(
87    ULONG iEngineVersion,
88    ULONG cj,
89    PDRVENABLEDATA pded)
90 {
91    if (cj >= sizeof(DRVENABLEDATA))
92    {
93       pded->c = sizeof(DrvFunctionTable) / sizeof(DRVFN);
94       pded->pdrvfn = DrvFunctionTable;
95       pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
96       return TRUE;
97    }
98    else
99    {
100       return FALSE;
101    }
102 }
103 
104 /*
105  * DrvEnablePDEV
106  *
107  * Returns a description of the physical device's characteristics to GDI.
108  *
109  * Status
110  *    @implemented
111  */
112 
113 DHPDEV APIENTRY
114 DrvEnablePDEV(
115    IN DEVMODEW *pdm,
116    IN LPWSTR pwszLogAddress,
117    IN ULONG cPat,
118    OUT HSURF *phsurfPatterns,
119    IN ULONG cjCaps,
120    OUT ULONG *pdevcaps,
121    IN ULONG cjDevInfo,
122    OUT DEVINFO *pdi,
123    IN HDEV hdev,
124    IN LPWSTR pwszDeviceName,
125    IN HANDLE hDriver)
126 {
127    PPDEV ppdev;
128    GDIINFO GdiInfo;
129    DEVINFO DevInfo;
130 
131    ppdev = EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
132    if (ppdev == NULL)
133    {
134       return NULL;
135    }
136 
137    ppdev->hDriver = hDriver;
138 
139    if (!IntInitScreenInfo(ppdev, pdm, &GdiInfo, &DevInfo))
140    {
141       EngFreeMem(ppdev);
142       return NULL;
143    }
144 
145    if (!IntInitDefaultPalette(ppdev, &DevInfo))
146    {
147       EngFreeMem(ppdev);
148       return NULL;
149    }
150 
151    memcpy(pdi, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
152    memcpy(pdevcaps, &GdiInfo, min(sizeof(GDIINFO), cjCaps));
153 
154    return (DHPDEV)ppdev;
155 }
156 
157 /*
158  * DrvCompletePDEV
159  *
160  * Stores the GDI handle (hdev) of the physical device in dhpdev. The driver
161  * should retain this handle for use when calling GDI services.
162  *
163  * Status
164  *    @implemented
165  */
166 
167 VOID APIENTRY
168 DrvCompletePDEV(
169    IN DHPDEV dhpdev,
170    IN HDEV hdev)
171 {
172    ((PPDEV)dhpdev)->hDevEng = hdev;
173 }
174 
175 /*
176  * DrvDisablePDEV
177  *
178  * Release the resources allocated in DrvEnablePDEV.  If a surface has been
179  * enabled DrvDisableSurface will have already been called.
180  *
181  * Status
182  *    @implemented
183  */
184 
185 VOID APIENTRY
186 DrvDisablePDEV(
187    IN DHPDEV dhpdev)
188 {
189    if (((PPDEV)dhpdev)->DefaultPalette)
190    {
191       EngDeletePalette(((PPDEV)dhpdev)->DefaultPalette);
192    }
193 
194    if (((PPDEV)dhpdev)->PaletteEntries != NULL)
195    {
196       EngFreeMem(((PPDEV)dhpdev)->PaletteEntries);
197    }
198 
199    EngFreeMem(dhpdev);
200 }
201