ReactOS  0.4.15-dev-1397-g19779b3
surface.c
Go to the documentation of this file.
1 /*
2  * ReactOS Generic Framebuffer acclations display driver
3  *
4  * Copyright (C) 2004 Filip Navara
5  * Copyright (C) 2007 Magnus Olsen
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #include "framebufacc.h"
23 
24 BOOL
26  BOOL bForcemapping)
27 {
28  VIDEO_MEMORY VideoMemory;
29  VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
30  ULONG returnedDataLength;
31  ULONG RemappingNeeded = 0;
32  ULONG PointerMaxWidth = 0;
33  ULONG PointerMaxHeight = 0;
34 
35  /*
36  * Set video mode of our adapter.
37  */
38 
39  if (EngDeviceIoControl(ppdev->hDriver,
41  &(ppdev->ModeIndex),
42  sizeof(ULONG),
43  &RemappingNeeded,
44  sizeof(ULONG),
45  &returnedDataLength))
46  {
47  return FALSE;
48  }
49 
50  /* Check if mapping is need it */
51  if ((!bForcemapping) &&
52  (!RemappingNeeded))
53  {
54  return TRUE;
55  }
56 
57 
58  /*
59  * Map the framebuffer into our memory.
60  */
61 
62  VideoMemory.RequestedVirtualAddress = NULL;
63  if (EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_MAP_VIDEO_MEMORY,
64  &VideoMemory, sizeof(VIDEO_MEMORY),
65  &VideoMemoryInfo, sizeof(VIDEO_MEMORY_INFORMATION),
66  &returnedDataLength))
67  {
68  return FALSE;
69  }
70 
71  /*
72  * Save the real video memory
73  */
74  ppdev->pRealVideoMem = VideoMemoryInfo.FrameBufferBase;
75  ppdev->VideoMemSize = VideoMemoryInfo.VideoRamLength;
76 
77 
78  /*
79  * Video memory cached
80  *
81  * We maby should only ask max 8MB as cached ?, think of the video ram length is 256MB
82  */
83 
84  ppdev->pVideoMemCache = NULL;
85 #ifdef EXPERIMENTAL_ACC_SUPPORT
86 
87  ppdev->pVideoMemCache = EngAllocMem(0, (ULONG)VideoMemoryInfo.VideoRamLength, ALLOC_TAG);
88  if (ppdev->pVideoMemCache == NULL)
89  {
90  /* cached off for no avail system memory */
91  ppdev->ScreenPtr = VideoMemoryInfo.FrameBufferBase;
92  }
93  else
94 
95 #endif
96  {
97  /* cached on, system memory is avail */
98  ppdev->ScreenPtr = ppdev->pRealVideoMem;
99  }
100 
101  /* hw mouse pointer support */
102  PointerMaxHeight = ppdev->PointerCapabilities.MaxHeight;
103  PointerMaxWidth = ppdev->PointerCapabilities.MaxWidth * sizeof(ULONG);
105  {
106  PointerMaxWidth = (ppdev->PointerCapabilities.MaxWidth + 7) / 8;
107  }
108 
109  ppdev->PointerAttributesSize = sizeof(VIDEO_POINTER_ATTRIBUTES) + ((sizeof(UCHAR) * PointerMaxWidth * PointerMaxHeight) << 1);
110 
112 
113  if (ppdev->pPointerAttributes != NULL)
114  {
116  ppdev->pPointerAttributes->WidthInBytes = PointerMaxWidth;
118  ppdev->pPointerAttributes->Height = PointerMaxHeight;
119  ppdev->pPointerAttributes->Column = 0;
120  ppdev->pPointerAttributes->Row = 0;
121  ppdev->pPointerAttributes->Enable = 0;
122  }
123  else
124  {
125  /* no hw mouse was avail */
126  ppdev->PointerAttributesSize = 0;
127  }
128 
129  return TRUE;
130 }
131 
132 /*
133  * DrvEnableSurface
134  *
135  * Create engine bitmap around frame buffer and set the video mode requested
136  * when PDEV was initialized.
137  *
138  * Status
139  * @implemented
140  */
141 
144  IN DHPDEV dhpdev)
145 {
146  PPDEV ppdev = (PPDEV)dhpdev;
147  HSURF hSurface;
148  ULONG BitmapType;
149  SIZEL ScreenSize;
150 
151 
152  /* Setup surface and force the mapping */
153  if (!InitSurface(ppdev, TRUE))
154  {
155  return FALSE;
156  }
157 
158  /* Rest the desktop vitual position */
159  ppdev->ScreenOffsetXY.x = 0;
160  ppdev->ScreenOffsetXY.y = 0;
161 
162 
163  switch (ppdev->BitsPerPixel)
164  {
165  case 8:
166  IntSetPalette(dhpdev, ppdev->PaletteEntries, 0, 256);
167  BitmapType = BMF_8BPP;
168  break;
169 
170  case 16:
171  BitmapType = BMF_16BPP;
172  break;
173 
174  case 24:
175  BitmapType = BMF_24BPP;
176  break;
177 
178  case 32:
179  BitmapType = BMF_32BPP;
180  break;
181 
182  default:
183  return FALSE;
184  }
185 
186  ppdev->iDitherFormat = BitmapType;
187 
188  ScreenSize.cx = ppdev->ScreenWidth;
189  ScreenSize.cy = ppdev->ScreenHeight;
190 
191  hSurface = (HSURF)EngCreateBitmap(ScreenSize, ppdev->ScreenDelta, BitmapType,
192  (ppdev->ScreenDelta > 0) ? BMF_TOPDOWN : 0,
193  ppdev->ScreenPtr);
194  if (hSurface == NULL)
195  {
196  return FALSE;
197  }
198 
199  /* Which api we hooking to */
201 
202  /*
203  * Associate the surface with our device.
204  */
205 
206 
207  if (!EngAssociateSurface(hSurface, ppdev->hDevEng, ppdev->dwHooks))
208  {
209  EngDeleteSurface(hSurface);
210  return FALSE;
211  }
212 
213  ppdev->hSurfEng = hSurface;
214 
215  return hSurface;
216 }
217 
218 /*
219  * DrvDisableSurface
220  *
221  * Used by GDI to notify a driver that the surface created by DrvEnableSurface
222  * for the current device is no longer needed.
223  *
224  * Status
225  * @implemented
226  */
227 
230  IN DHPDEV dhpdev)
231 {
232  DWORD ulTemp;
233  VIDEO_MEMORY VideoMemory;
234  PPDEV ppdev = (PPDEV)dhpdev;
235 
236  EngDeleteSurface(ppdev->hSurfEng);
237  ppdev->hSurfEng = NULL;
238 
239 
240  /* Free the video memory cache */
241  if (ppdev->pVideoMemCache)
242  {
243  EngFreeMem(ppdev->pVideoMemCache);
244  }
245 
246  /*
247  * Unmap the framebuffer.
248  */
249 
250  VideoMemory.RequestedVirtualAddress = ppdev->pRealVideoMem;
251  EngDeviceIoControl(((PPDEV)dhpdev)->hDriver, IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
252  &VideoMemory, sizeof(VIDEO_MEMORY), NULL, 0, &ulTemp);
253 
254  ppdev->pRealVideoMem = NULL;
255  ppdev->pVideoMemCache = NULL;
256 
257 }
258 
259 /*
260  * DrvAssertMode
261  *
262  * Sets the mode of the specified physical device to either the mode specified
263  * when the PDEV was initialized or to the default mode of the hardware.
264  *
265  * Status
266  * @implemented
267  */
268 
271  IN DHPDEV dhpdev,
272  IN BOOL bEnable)
273 {
274  PPDEV ppdev = (PPDEV)dhpdev;
275  ULONG ulTemp;
276  BOOLEAN Result = TRUE;
277 
278  if (bEnable)
279  {
280  PVOID pRealVideoMem = ppdev->pRealVideoMem;
281 
282  /* Setup surface and remapping if it need it */
283  if (!InitSurface(ppdev, FALSE))
284  {
285  Result = FALSE;
286  }
287  else
288  {
289  /* Check if we got same surface or not */
290  if (pRealVideoMem != ppdev->pRealVideoMem)
291  {
292  PVOID pVideoMem= NULL;
293 
294  if (ppdev->pVideoMemCache == NULL)
295  {
296  pVideoMem = ppdev->pRealVideoMem;
297  }
298  else
299  {
300  pVideoMem = ppdev->pVideoMemCache;
301  }
302 
303  Result = !EngModifySurface(ppdev->hSurfEng, ppdev->hDevEng,
304  ppdev->dwHooks | HOOK_SYNCHRONIZE,
305  0, (DHSURF)ppdev, pVideoMem,
306  ppdev->ScreenDelta, NULL);
307  }
308 
309  /* if the pRealVideoMem == ppdev->pRealVideoMem are
310  * the Result is then TRUE
311  */
312  }
313 
314  }
315  else
316  {
317  /*
318  * Call the miniport driver to reset the device to a known state.
319  */
320 
321  Result = !EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_RESET_DEVICE,
322  NULL, 0, NULL, 0, &ulTemp);
323  }
324 
325  return Result;
326 }
#define BMF_24BPP
Definition: winddi.h:359
PALETTEENTRY * PaletteEntries
Definition: framebuf.h:49
VOID APIENTRY DrvDisableSurface(IN DHPDEV dhpdev)
Definition: surface.c:133
#define IN
Definition: typedefs.h:39
VIDEO_POINTER_CAPABILITIES PointerCapabilities
Definition: driver.h:44
struct _VIDEO_POINTER_ATTRIBUTES VIDEO_POINTER_ATTRIBUTES
ULONG ScreenHeight
Definition: framebuf.h:40
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
#define VIDEO_MODE_COLOR_POINTER
Definition: ntddvdeo.h:455
#define BMF_32BPP
Definition: winddi.h:360
#define TRUE
Definition: types.h:120
#define EngFreeMem
Definition: polytest.cpp:56
DWORD iDitherFormat
Definition: framebuf.h:61
#define BMF_TOPDOWN
Definition: winddi.h:1180
HDEV hDevEng
Definition: framebuf.h:36
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
POINTL ScreenOffsetXY
Definition: framebufacc.h:55
BOOL APIENTRY IntSetPalette(IN DHPDEV dhpdev, IN PPALETTEENTRY ppalent, IN ULONG iStart, IN ULONG cColors)
Definition: palette.c:110
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:104
PVOID RequestedVirtualAddress
Definition: ntddvdeo.h:274
HSURF APIENTRY DrvEnableSurface(IN DHPDEV dhpdev)
Definition: surface.c:34
LONG y
Definition: windef.h:330
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:152
#define ALLOC_TAG
Definition: btrfs_drv.h:91
BOOL APIENTRY EngAssociateSurface(_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks)
Definition: surface.c:428
#define HOOK_FILLPATH
Definition: winddi.h:1426
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
HBITMAP APIENTRY EngCreateBitmap(_In_ SIZEL sizl, _In_ LONG lWidth, _In_ ULONG iFormat, _In_ ULONG fl, _In_opt_ PVOID pvBits)
Definition: surface.c:306
HANDLE hDriver
Definition: framebuf.h:35
BYTE BitsPerPixel
Definition: framebuf.h:42
PVOID pVideoMemCache
Definition: framebufacc.h:86
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LONG cx
Definition: windef.h:334
#define HOOK_LINETO
Definition: winddi.h:1428
#define BMF_16BPP
Definition: winddi.h:358
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:179
ULONG VideoMemSize
Definition: framebufacc.h:90
#define HOOK_TEXTOUT
Definition: winddi.h:1423
PVOID pRealVideoMem
Definition: framebufacc.h:87
ULONG PointerAttributesSize
Definition: framebufacc.h:64
#define HOOK_BITBLT
Definition: winddi.h:1420
BOOL APIENTRY DrvAssertMode(IN DHPDEV dhpdev, IN BOOL bEnable)
Definition: surface.c:168
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG x
Definition: windef.h:329
Definition: xlate.c:10
ULONG ModeIndex
Definition: framebuf.h:38
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
struct _PDEV * PPDEV
Definition: framebuf.h:33
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG dwHooks
Definition: framebufacc.h:40
PVOID ScreenPtr
Definition: framebuf.h:47
HSURF hSurfEng
Definition: framebuf.h:37
BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:564
#define HOOK_COPYBITS
Definition: winddi.h:1429
BOOL InitSurface(PPDEV ppdev, BOOL bForcemapping)
Definition: surface.c:25
_In_ BOOL bEnable
Definition: winddi.h:3426
PVIDEO_POINTER_ATTRIBUTES pPointerAttributes
Definition: driver.h:45
BOOL APIENTRY EngModifySurface(_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks, _In_ FLONG flSurface, _In_ DHSURF dhsurf, _In_ PVOID pvScan0, _In_ LONG lDelta, _Reserved_ PVOID pvReserved)
Definition: surface.c:468
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define HOOK_STROKEPATH
Definition: winddi.h:1425
LONG cy
Definition: windef.h:335
ULONG ScreenDelta
Definition: framebuf.h:41
#define APIENTRY
Definition: api.h:79
ULONG ScreenWidth
Definition: framebuf.h:39