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 
36 };
37 
38 /*
39  * DrvEnableDriver
40  *
41  * Initial driver entry point exported by the driver DLL. It fills in a
42  * DRVENABLEDATA structure with the driver's DDI version number and the
43  * calling addresses of all DDI functions supported by the driver.
44  *
45  * Status
46  *    @implemented
47  */
48 
49 BOOL APIENTRY
50 DrvEnableDriver(
51    ULONG iEngineVersion,
52    ULONG cj,
53    PDRVENABLEDATA pded)
54 {
55    if (cj >= sizeof(DRVENABLEDATA))
56    {
57       pded->c = sizeof(DrvFunctionTable) / sizeof(DRVFN);
58       pded->pdrvfn = DrvFunctionTable;
59       pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
60       return TRUE;
61    }
62    else
63    {
64       return FALSE;
65    }
66 }
67 
68 /*
69  * DrvEnablePDEV
70  *
71  * Returns a description of the physical device's characteristics to GDI.
72  *
73  * Status
74  *    @implemented
75  */
76 
77 DHPDEV APIENTRY
78 DrvEnablePDEV(
79    IN DEVMODEW *pdm,
80    IN LPWSTR pwszLogAddress,
81    IN ULONG cPat,
82    OUT HSURF *phsurfPatterns,
83    IN ULONG cjCaps,
84    OUT ULONG *pdevcaps,
85    IN ULONG cjDevInfo,
86    OUT DEVINFO *pdi,
87    IN HDEV hdev,
88    IN LPWSTR pwszDeviceName,
89    IN HANDLE hDriver)
90 {
91    PPDEV ppdev;
92    GDIINFO GdiInfo;
93    DEVINFO DevInfo;
94 
95    ppdev = EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
96    if (ppdev == NULL)
97    {
98       return NULL;
99    }
100 
101    ppdev->hDriver = hDriver;
102 
103    if (!IntInitScreenInfo(ppdev, pdm, &GdiInfo, &DevInfo))
104    {
105       EngFreeMem(ppdev);
106       return NULL;
107    }
108 
109    if (!IntInitDefaultPalette(ppdev, &DevInfo))
110    {
111       EngFreeMem(ppdev);
112       return NULL;
113    }
114 
115    memcpy(pdi, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
116    memcpy(pdevcaps, &GdiInfo, min(sizeof(GDIINFO), cjCaps));
117 
118    return (DHPDEV)ppdev;
119 }
120 
121 /*
122  * DrvCompletePDEV
123  *
124  * Stores the GDI handle (hdev) of the physical device in dhpdev. The driver
125  * should retain this handle for use when calling GDI services.
126  *
127  * Status
128  *    @implemented
129  */
130 
131 VOID APIENTRY
132 DrvCompletePDEV(
133    IN DHPDEV dhpdev,
134    IN HDEV hdev)
135 {
136    ((PPDEV)dhpdev)->hDevEng = hdev;
137 }
138 
139 /*
140  * DrvDisablePDEV
141  *
142  * Release the resources allocated in DrvEnablePDEV.  If a surface has been
143  * enabled DrvDisableSurface will have already been called.
144  *
145  * Status
146  *    @implemented
147  */
148 
149 VOID APIENTRY
150 DrvDisablePDEV(
151    IN DHPDEV dhpdev)
152 {
153    if (((PPDEV)dhpdev)->DefaultPalette)
154    {
155       EngDeletePalette(((PPDEV)dhpdev)->DefaultPalette);
156    }
157 
158    if (((PPDEV)dhpdev)->PaletteEntries != NULL)
159    {
160       EngFreeMem(((PPDEV)dhpdev)->PaletteEntries);
161    }
162 
163    EngFreeMem(dhpdev);
164 }
165