VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispDriverDDraw.cpp@ 80748

Last change on this file since 80748 was 80748, checked in by vboxsync, 5 years ago

Additions/WINNT/Graphics: Lots of compilation fixes if VBOX_WITH_VIDEOHWACCE and/or VBOX_WITH_MESA3D is not defined.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: VBoxDispDriverDDraw.cpp 80748 2019-09-12 09:44:16Z vboxsync $ */
2/** @file
3 * VBox XPDM Display driver interface functions related to DirectDraw
4 */
5
6/*
7 * Copyright (C) 2011-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "VBoxDisp.h"
19#include "VBoxDispDDraw.h"
20
21static void VBoxDispGetDDHalInfo(PVBOXDISPDEV pDev, DD_HALINFO *pHalInfo)
22{
23 memset(pHalInfo, 0, sizeof(DD_HALINFO));
24 pHalInfo->dwSize = sizeof(DD_HALINFO);
25
26 /* memory info */
27
28 pHalInfo->vmiData.fpPrimary = pDev->layout.offFramebuffer;
29 /*pHalInfo->vmiData.dwFlags /*unused*/
30 pHalInfo->vmiData.dwDisplayWidth = pDev->mode.ulWidth;
31 pHalInfo->vmiData.dwDisplayHeight = pDev->mode.ulHeight;
32 pHalInfo->vmiData.lDisplayPitch = pDev->mode.lScanlineStride;
33
34 pHalInfo->vmiData.ddpfDisplay.dwSize = sizeof(DDPIXELFORMAT);
35 pHalInfo->vmiData.ddpfDisplay.dwFlags = DDPF_RGB;
36 if (pDev->surface.ulFormat == BMF_8BPP)
37 {
38 pHalInfo->vmiData.ddpfDisplay.dwFlags |= DDPF_PALETTEINDEXED8;
39 }
40 pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount = pDev->mode.ulBitsPerPel;
41 pHalInfo->vmiData.ddpfDisplay.dwRBitMask = pDev->mode.flMaskR;
42 pHalInfo->vmiData.ddpfDisplay.dwGBitMask = pDev->mode.flMaskG;
43 pHalInfo->vmiData.ddpfDisplay.dwBBitMask = pDev->mode.flMaskB;
44
45 pHalInfo->vmiData.dwOffscreenAlign = 4;
46 pHalInfo->vmiData.dwTextureAlign = 4;
47 pHalInfo->vmiData.dwZBufferAlign = 4;
48 pHalInfo->vmiData.dwOverlayAlign = 4;
49
50 pHalInfo->vmiData.pvPrimary = pDev->memInfo.FrameBufferBase;
51
52 /* caps */
53
54 pHalInfo->ddCaps.dwSize = sizeof(DDNTCORECAPS);
55 pHalInfo->ddCaps.dwCaps2 = DDCAPS2_WIDESURFACES;
56 pHalInfo->ddCaps.dwVidMemTotal = pDev->layout.cbDDrawHeap;
57 pHalInfo->ddCaps.dwVidMemFree = pDev->layout.cbDDrawHeap;
58 pHalInfo->ddCaps.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
59
60}
61
62/* Called to get supported DirectDraw caps */
63BOOL APIENTRY
64VBoxDispDrvGetDirectDrawInfo(DHPDEV dhpdev, DD_HALINFO *pHalInfo, DWORD *pdwNumHeaps,
65 VIDEOMEMORY *pvmList, DWORD *pdwNumFourCCCodes, DWORD *pdwFourCC)
66{
67 PVBOXDISPDEV pDev = (PVBOXDISPDEV)dhpdev;
68 LOGF_ENTER();
69
70 VBoxDispGetDDHalInfo(pDev, pHalInfo);
71
72#ifdef VBOX_WITH_VIDEOHWACCEL
73 int rc;
74
75 if (!pvmList && !pdwFourCC) /* first call */
76 {
77 rc = VBoxDispVHWAInitHostInfo1(pDev);
78 VBOX_WARNRC_NOBP(rc);
79 }
80
81 if (pDev->vhwa.bEnabled)
82 {
83 rc = VBoxDispVHWAUpdateDDHalInfo(pDev, pHalInfo);
84 VBOX_WARNRC(rc);
85
86 pDev->vhwa.bEnabled = RT_SUCCESS(rc);
87 }
88#else
89 RT_NOREF(pdwFourCC);
90#endif
91
92 /* we could only have 1 heap, so it's not really a list */
93 if (pvmList && pDev->layout.cbDDrawHeap>0)
94 {
95 pvmList->dwFlags = VIDMEM_ISLINEAR;
96 pvmList->fpStart = pDev->layout.offDDrawHeap;
97 pvmList->fpEnd = pDev->layout.offDDrawHeap + pDev->layout.cbDDrawHeap - 1;
98#ifdef VBOX_WITH_VIDEOHWACCEL
99 if (pDev->vhwa.bEnabled)
100 {
101 pvmList->ddsCaps.dwCaps = 0;
102 }
103 else
104#endif
105 {
106 pvmList->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
107 }
108 pvmList->ddsCapsAlt.dwCaps = 0;
109
110 }
111
112 /* Always report number of heaps and supported FourCC's*/
113 *pdwNumHeaps = (pDev->layout.cbDDrawHeap>0) ? 1:0;
114
115#ifndef VBOX_WITH_VIDEOHWACCEL
116 *pdwNumFourCCCodes = 0;
117#else
118 if (pDev->vhwa.bEnabled)
119 {
120 *pdwNumFourCCCodes = pDev->vhwa.numFourCC;
121 if (pdwFourCC && pDev->vhwa.numFourCC)
122 {
123 rc = VBoxDispVHWAInitHostInfo2(pDev, pdwFourCC);
124 VBOX_WARNRC(rc);
125
126 if (RT_FAILURE(rc))
127 {
128 *pdwNumFourCCCodes = 0;
129 pDev->vhwa.numFourCC = 0;
130 }
131 }
132
133 pHalInfo->GetDriverInfo = VBoxDispDDGetDriverInfo;
134 pHalInfo->dwFlags |= DDHALINFO_GETDRIVERINFOSET;
135 }
136#endif
137
138 LOGF_LEAVE();
139 return TRUE;
140}
141
142BOOL APIENTRY
143VBoxDispDrvEnableDirectDraw(DHPDEV dhpdev, DD_CALLBACKS *pCallBacks, DD_SURFACECALLBACKS *pSurfaceCallBacks,
144 DD_PALETTECALLBACKS *pPaletteCallBacks)
145{
146 LOGF_ENTER();
147
148 pCallBacks->dwSize = sizeof(DD_CALLBACKS);
149 pCallBacks->CreateSurface = VBoxDispDDCreateSurface;
150 pCallBacks->CanCreateSurface = VBoxDispDDCanCreateSurface;
151 pCallBacks->MapMemory = VBoxDispDDMapMemory;
152 pCallBacks->dwFlags = DDHAL_CB32_CREATESURFACE|DDHAL_CB32_CANCREATESURFACE|DDHAL_CB32_MAPMEMORY;
153
154 pSurfaceCallBacks->dwSize = sizeof(DD_SURFACECALLBACKS);
155 pSurfaceCallBacks->Lock = VBoxDispDDLock;
156 pSurfaceCallBacks->Unlock = VBoxDispDDUnlock;
157 pSurfaceCallBacks->dwFlags = DDHAL_SURFCB32_LOCK|DDHAL_SURFCB32_UNLOCK;
158
159 pPaletteCallBacks->dwSize = sizeof(DD_PALETTECALLBACKS);
160 pPaletteCallBacks->dwFlags = 0;
161
162#ifdef VBOX_WITH_VIDEOHWACCEL
163 PVBOXDISPDEV pDev = (PVBOXDISPDEV)dhpdev;
164
165 if (pDev->vhwa.bEnabled)
166 {
167 pSurfaceCallBacks->DestroySurface = VBoxDispDDDestroySurface;
168 pSurfaceCallBacks->Flip = VBoxDispDDFlip;
169 pSurfaceCallBacks->GetFlipStatus = VBoxDispDDGetFlipStatus;
170 pSurfaceCallBacks->Blt = VBoxDispDDBlt;
171 pSurfaceCallBacks->GetBltStatus = VBoxDispDDGetBltStatus;
172 pSurfaceCallBacks->SetColorKey = VBoxDispDDSetColorKey;
173 pSurfaceCallBacks->dwFlags |= DDHAL_SURFCB32_DESTROYSURFACE|
174 DDHAL_SURFCB32_FLIP|DDHAL_SURFCB32_GETFLIPSTATUS|
175 DDHAL_SURFCB32_BLT|DDHAL_SURFCB32_GETBLTSTATUS|
176 DDHAL_SURFCB32_SETCOLORKEY;
177
178 if(pDev->vhwa.caps & VBOXVHWA_CAPS_OVERLAY)
179 {
180 pSurfaceCallBacks->UpdateOverlay = VBoxDispDDUpdateOverlay;
181 pSurfaceCallBacks->SetOverlayPosition = VBoxDispDDSetOverlayPosition;
182 pSurfaceCallBacks->dwFlags |= DDHAL_SURFCB32_UPDATEOVERLAY|DDHAL_SURFCB32_SETOVERLAYPOSITION;
183 }
184 }
185#else
186 RT_NOREF(dhpdev);
187#endif
188
189 LOGF_LEAVE();
190 return TRUE;
191}
192
193VOID APIENTRY VBoxDispDrvDisableDirectDraw(DHPDEV dhpdev)
194{
195 RT_NOREF(dhpdev);
196 LOGF_ENTER();
197 LOGF_LEAVE();
198 return;
199}
200
201HBITMAP APIENTRY VBoxDispDrvDeriveSurface(DD_DIRECTDRAW_GLOBAL *pDirectDraw, DD_SURFACE_LOCAL *pSurface)
202{
203 PVBOXDISPDEV pDev = (PVBOXDISPDEV)pDirectDraw->dhpdev;
204 LOGF_ENTER();
205
206 if (pSurface->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM)
207 {
208 WARN(("Can't derive surface DDSCAPS_NONLOCALVIDMEM"));
209 return NULL;
210 }
211
212 if (pSurface->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
213 {
214 WARN(("Can't derive surface DDSCAPS2_TEXTUREMANAGE"));
215 return NULL;
216 }
217
218 if (pSurface->lpGbl->ddpfSurface.dwRGBBitCount != pDev->mode.ulBitsPerPel)
219 {
220 WARN(("Can't derive surface with different bpp"));
221 return NULL;
222 }
223
224 Assert(pDev->surface.hSurface);
225
226 /* Create GDI managed bitmap, which resides in our DDraw heap memory */
227 HBITMAP hBitmap;
228 SIZEL size;
229
230 size.cx = pDev->mode.ulWidth;
231 size.cy = pDev->mode.ulHeight;
232
233 hBitmap = EngCreateBitmap(size, pSurface->lpGbl->lPitch, pDev->surface.ulFormat,
234 pDev->mode.lScanlineStride>0 ? BMF_TOPDOWN:0,
235 (PBYTE)pDev->memInfo.VideoRamBase + pSurface->lpGbl->fpVidMem);
236
237 if (!hBitmap)
238 {
239 WARN(("EngCreateBitmap failed"));
240 return 0;
241 }
242
243 if (pSurface->lpGbl->fpVidMem == 0)
244 {
245 /* Screen surface, mark it so it will be recognized by the driver.
246 * so the driver will be called on any operations on the surface
247 * (required for VBVA and VRDP).
248 */
249 SURFOBJ *pso;
250
251 if (!EngAssociateSurface((HSURF)hBitmap, pDev->hDevGDI, pDev->flDrawingHooks))
252 {
253 WARN(("EngAssociateSurface failed"));
254 EngDeleteSurface((HSURF)hBitmap);
255 return NULL;
256 }
257
258 pso = EngLockSurface((HSURF)hBitmap);
259 if (!pso)
260 {
261 WARN(("EngLockSurface failed"));
262 EngDeleteSurface((HSURF)hBitmap);
263 return NULL;
264 }
265
266 pso->dhpdev = (DHPDEV)pDev;
267 EngUnlockSurface(pso);
268 }
269
270 LOGF_LEAVE();
271 return hBitmap;
272}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette