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