ReactOS  0.4.15-dev-1397-g19779b3
surface.c File Reference
#include "framebufacc.h"
Include dependency graph for surface.c:

Go to the source code of this file.

Functions

BOOL InitSurface (PPDEV ppdev, BOOL bForcemapping)
 
HSURF APIENTRY DrvEnableSurface (IN DHPDEV dhpdev)
 
VOID APIENTRY DrvDisableSurface (IN DHPDEV dhpdev)
 
BOOL APIENTRY DrvAssertMode (IN DHPDEV dhpdev, IN BOOL bEnable)
 

Function Documentation

◆ DrvAssertMode()

BOOL APIENTRY DrvAssertMode ( IN DHPDEV  dhpdev,
IN BOOL  bEnable 
)

Definition at line 270 of file surface.c.

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 TRUE
Definition: types.h:120
HDEV hDevEng
Definition: framebuf.h:36
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
#define FALSE
Definition: types.h:117
HANDLE hDriver
Definition: framebuf.h:35
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
PVOID pRealVideoMem
Definition: framebufacc.h:87
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
struct _PDEV * PPDEV
Definition: framebuf.h:33
ULONG dwHooks
Definition: framebufacc.h:40
HSURF hSurfEng
Definition: framebuf.h:37
BOOL InitSurface(PPDEV ppdev, BOOL bForcemapping)
Definition: surface.c:25
_In_ BOOL bEnable
Definition: winddi.h:3426
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

◆ DrvDisableSurface()

VOID APIENTRY DrvDisableSurface ( IN DHPDEV  dhpdev)

Definition at line 229 of file surface.c.

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 }
#define EngFreeMem
Definition: polytest.cpp:56
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
PVOID RequestedVirtualAddress
Definition: ntddvdeo.h:274
PVOID pVideoMemCache
Definition: framebufacc.h:86
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:179
PVOID pRealVideoMem
Definition: framebufacc.h:87
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _PDEV * PPDEV
Definition: framebuf.h:33
HSURF hSurfEng
Definition: framebuf.h:37
BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:564
#define NULL
Definition: types.h:112

◆ DrvEnableSurface()

HSURF APIENTRY DrvEnableSurface ( IN DHPDEV  dhpdev)

Definition at line 143 of file surface.c.

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 }
#define BMF_24BPP
Definition: winddi.h:359
PALETTEENTRY * PaletteEntries
Definition: framebuf.h:49
ULONG ScreenHeight
Definition: framebuf.h:40
#define BMF_32BPP
Definition: winddi.h:360
#define TRUE
Definition: types.h:120
DWORD iDitherFormat
Definition: framebuf.h:61
#define BMF_TOPDOWN
Definition: winddi.h:1180
HDEV hDevEng
Definition: framebuf.h:36
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
LONG y
Definition: windef.h:330
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
HBITMAP APIENTRY EngCreateBitmap(_In_ SIZEL sizl, _In_ LONG lWidth, _In_ ULONG iFormat, _In_ ULONG fl, _In_opt_ PVOID pvBits)
Definition: surface.c:306
BYTE BitsPerPixel
Definition: framebuf.h:42
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 HOOK_TEXTOUT
Definition: winddi.h:1423
#define HOOK_BITBLT
Definition: winddi.h:1420
LONG x
Definition: windef.h:329
Definition: xlate.c:10
struct _PDEV * PPDEV
Definition: framebuf.h:33
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
#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
ULONG ScreenWidth
Definition: framebuf.h:39

◆ InitSurface()

BOOL InitSurface ( PPDEV  ppdev,
BOOL  bForcemapping 
)

Definition at line 25 of file surface.c.

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 }
VIDEO_POINTER_CAPABILITIES PointerCapabilities
Definition: driver.h:44
struct _VIDEO_POINTER_ATTRIBUTES VIDEO_POINTER_ATTRIBUTES
#define VIDEO_MODE_COLOR_POINTER
Definition: ntddvdeo.h:455
#define TRUE
Definition: types.h:120
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:104
PVOID RequestedVirtualAddress
Definition: ntddvdeo.h:274
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:152
#define ALLOC_TAG
Definition: btrfs_drv.h:91
#define FALSE
Definition: types.h:117
HANDLE hDriver
Definition: framebuf.h:35
PVOID pVideoMemCache
Definition: framebufacc.h:86
ULONG VideoMemSize
Definition: framebufacc.h:90
PVOID pRealVideoMem
Definition: framebufacc.h:87
ULONG PointerAttributesSize
Definition: framebufacc.h:64
ULONG ModeIndex
Definition: framebuf.h:38
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
unsigned char UCHAR
Definition: xmlstorage.h:181
PVOID ScreenPtr
Definition: framebuf.h:47
PVIDEO_POINTER_ATTRIBUTES pPointerAttributes
Definition: driver.h:45
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by DrvAssertMode(), and DrvEnableSurface().