ReactOS 0.4.15-dev-7924-g5949c20
mdevobj.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Support for meta devices
5 * FILE: win32ss/gdi/eng/mdevobj.c
6 * PROGRAMER: Hervé Poussineau
7 */
8
9#include <win32k.h>
10#define NDEBUG
11#include <debug.h>
13
14PMDEVOBJ gpmdev = NULL; /* FIXME: should be stored in gpDispInfo->pmdev */
15
16VOID
18 _Inout_ PMDEVOBJ pmdev)
19{
20 ULONG i;
21
22 for (i = 0; i < pmdev->cDev; i++)
23 {
24 PDEVOBJ_vEnableDisplay(pmdev->dev[i].ppdev);
25 }
26}
27
28BOOL
30 _Inout_ PMDEVOBJ pmdev)
31{
33 ULONG i, j;
34
35 for (i = 0; i < pmdev->cDev; i++)
36 {
37 if (!PDEVOBJ_bDisableDisplay(pmdev->dev[i].ppdev))
38 {
40 break;
41 }
42 }
43
44 if (!bSuccess)
45 {
46 /* Failed to disable all PDEVs. Reenable those we have disabled */
47 for (j = 0; j < i; j++)
48 {
49 PDEVOBJ_vEnableDisplay(pmdev->dev[i].ppdev);
50 }
51 }
52
53 return bSuccess;
54}
55
58 _In_opt_ PUNICODE_STRING pustrDeviceName,
60{
61 PMDEVOBJ pmdev = NULL;
62 PPDEVOBJ ppdev;
63 PGRAPHICS_DEVICE pGraphicsDevice;
64 DEVMODEW dmDefault;
65 PDEVMODEW localPdm;
66 ULONG iDevNum = 0;
67 ULONG dwAccelerationLevel = 0;
68
69 TRACE("MDEVOBJ_Create('%wZ' '%dx%dx%d (%d Hz)')\n",
70 pustrDeviceName,
71 pdm ? pdm->dmPelsWidth : 0,
72 pdm ? pdm->dmPelsHeight : 0,
73 pdm ? pdm->dmBitsPerPel : 0,
74 pdm ? pdm->dmDisplayFrequency : 0);
75
76 pmdev = ExAllocatePoolZero(PagedPool, sizeof(MDEVOBJ) + sizeof(MDEVDISPLAY), GDITAG_MDEV);
77 if (!pmdev)
78 {
79 ERR("Failed to allocate memory for MDEV\n");
80 return NULL;
81 }
82
83 pmdev->cDev = 0;
84
85 while (TRUE)
86 {
87 /* Get the right graphics devices: either the specified one, or all of them (one after one) */
88 if (pustrDeviceName)
89 pGraphicsDevice = (iDevNum == 0) ? EngpFindGraphicsDevice(pustrDeviceName, 0) : NULL;
90 else
91 pGraphicsDevice = EngpFindGraphicsDevice(NULL, iDevNum);
92 iDevNum++;
93
94 if (!pGraphicsDevice)
95 {
96 TRACE("Done enumeration of graphic devices (DeviceName '%wZ' iDevNum %d)\n", pustrDeviceName, iDevNum);
97 break;
98 }
99
100 if (!pdm)
101 {
102 /* No settings requested. Provide nothing and LDEVOBJ_bProbeAndCaptureDevmode
103 * will read default settings from registry */
104 RtlZeroMemory(&dmDefault, sizeof(dmDefault));
105 dmDefault.dmSize = sizeof(dmDefault);
106 }
107
108 dwAccelerationLevel = EngpGetDisplayDriverAccelerationLevel(pGraphicsDevice);
109
110 /* Get or create a PDEV for these settings */
111 if (LDEVOBJ_bProbeAndCaptureDevmode(pGraphicsDevice, pdm ? pdm : &dmDefault, &localPdm, !pdm))
112 {
113 ppdev = PDEVOBJ_Create(pGraphicsDevice, localPdm, dwAccelerationLevel, LDEV_DEVICE_DISPLAY);
114 }
115 else
116 {
117 ppdev = NULL;
118 }
119
120 if (ppdev)
121 {
122 /* Great. We have a found a matching PDEV. Store it in MDEV */
123 if (pmdev->cDev >= 1)
124 {
125 /* We have to reallocate MDEV to add space for the new display */
126 PMDEVOBJ pmdevBigger = ExAllocatePoolZero(PagedPool, sizeof(MDEVOBJ) + (pmdev->cDev + 1) * sizeof(MDEVDISPLAY), GDITAG_MDEV);
127 if (!pmdevBigger)
128 {
129 WARN("Failed to allocate memory for MDEV. Skipping display '%S'\n", pGraphicsDevice->szWinDeviceName);
130 continue;
131 }
132 else
133 {
134 /* Copy existing data */
135 RtlCopyMemory(pmdevBigger, pmdev, sizeof(MDEVOBJ) + pmdev->cDev * sizeof(MDEVDISPLAY));
137 pmdev = pmdevBigger;
138 }
139 }
140
141 TRACE("Adding '%S' to MDEV %p\n", pGraphicsDevice->szWinDeviceName, pmdev);
142 PDEVOBJ_vReference(ppdev);
143 pmdev->dev[pmdev->cDev].ppdev = ppdev;
144 pmdev->cDev++;
145 }
146 else
147 {
148 WARN("Failed to add '%S' to MDEV %p\n", pGraphicsDevice->szWinDeviceName, pmdev);
149 }
150 }
151
152 if (pmdev->cDev == 0)
153 {
154 TRACE("Failed to add any device to MDEV. Returning NULL\n");
155 MDEVOBJ_vDestroy(pmdev);
156 return NULL;
157 }
158
159 TRACE("Returning new MDEV %p with %d devices\n", pmdev, pmdev->cDev);
160 return pmdev;
161}
162
163VOID
165 _Inout_ PMDEVOBJ pmdev)
166{
167 ULONG i;
168
169 for (i = 0; i < pmdev->cDev; i++)
170 {
171 PDEVOBJ_vRelease(pmdev->dev[i].ppdev);
172 }
173
174 if (pmdev->cDev > 1)
175 PDEVOBJ_vRelease(pmdev->ppdevGlobal);
176
178}
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:103
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define PagedPool
Definition: env_spec_w32.h:308
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
BOOL LDEVOBJ_bProbeAndCaptureDevmode(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW RequestedMode, _Out_ PDEVMODEW *pSelectedMode, _In_ BOOL bSearchClosestMode)
Definition: ldevobj.c:737
@ LDEV_DEVICE_DISPLAY
Definition: ldevobj.h:8
VOID MDEVOBJ_vDestroy(_Inout_ PMDEVOBJ pmdev)
Definition: mdevobj.c:164
PMDEVOBJ gpmdev
Definition: mdevobj.c:14
PMDEVOBJ MDEVOBJ_Create(_In_opt_ PUNICODE_STRING pustrDeviceName, _In_opt_ PDEVMODEW pdm)
Definition: mdevobj.c:57
BOOL MDEVOBJ_bDisable(_Inout_ PMDEVOBJ pmdev)
Definition: mdevobj.c:29
VOID MDEVOBJ_vEnable(_Inout_ PMDEVOBJ pmdev)
Definition: mdevobj.c:17
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define _Inout_
Definition: ms_sal.h:378
#define _In_opt_
Definition: ms_sal.h:309
BOOL PDEVOBJ_bDisableDisplay(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:412
PPDEVOBJ PDEVOBJ_Create(_In_opt_ PGRAPHICS_DEVICE pGraphicsDevice, _In_opt_ PDEVMODEW pdm, _In_ ULONG dwAccelerationLevel, _In_ ULONG ldevtype)
Definition: pdevobj.c:467
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:105
VOID PDEVOBJ_vEnableDisplay(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:392
FORCEINLINE VOID PDEVOBJ_vReference(_In_ PPDEVOBJ ppdev)
Definition: pdevobj.h:160
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
PPDEVOBJ ppdev
Definition: mdevobj.h:10
ULONG cDev
Definition: mdevobj.h:15
MDEVDISPLAY dev[0]
Definition: mdevobj.h:17
WORD dmSize
Definition: wingdi.h:1620
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
DWORD EngpGetDisplayDriverAccelerationLevel(_In_ PGRAPHICS_DEVICE pGraphicsDevice)
Definition: device.c:400
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:641
#define GDITAG_MDEV
Definition: tags.h:74