VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp@ 87979

Last change on this file since 87979 was 87110, checked in by vboxsync, 4 years ago

3D/VMSVGA: Ignore a surface in case of inconsistent parameters, bugref:9880

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.8 KB
Line 
1/* $Id: DevVGA-SVGA3d.cpp 87110 2020-12-21 13:29:10Z vboxsync $ */
2/** @file
3 * DevSVGA3d - VMWare SVGA device, 3D parts - Common core code.
4 */
5
6/*
7 * Copyright (C) 2013-2020 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
23#include <VBox/vmm/pdmdev.h>
24#include <iprt/errcore.h>
25#include <VBox/log.h>
26
27#include <iprt/assert.h>
28#include <iprt/mem.h>
29
30#include <VBox/vmm/pgm.h> /* required by DevVGA.h */
31#include <VBoxVideo.h> /* required by DevVGA.h */
32
33/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
34#include "DevVGA.h"
35
36#include "DevVGA-SVGA.h"
37#include "DevVGA-SVGA3d.h"
38#define VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
39#include "DevVGA-SVGA3d-internal.h"
40
41
42
43/**
44 * Implements the SVGA_3D_CMD_SURFACE_DEFINE_V2 and SVGA_3D_CMD_SURFACE_DEFINE
45 * commands (fifo).
46 *
47 * @returns VBox status code (currently ignored).
48 * @param pThisCC The VGA/VMSVGA state for ring-3.
49 * @param sid The ID of the surface to (re-)define.
50 * @param surfaceFlags .
51 * @param format .
52 * @param multisampleCount .
53 * @param autogenFilter .
54 * @param numMipLevels .
55 * @param pMipLevel0Size .
56 */
57int vmsvga3dSurfaceDefine(PVGASTATECC pThisCC, uint32_t sid, SVGA3dSurface1Flags surfaceFlags, SVGA3dSurfaceFormat format,
58 uint32_t multisampleCount, SVGA3dTextureFilter autogenFilter,
59 uint32_t numMipLevels, SVGA3dSize const *pMipLevel0Size)
60{
61 PVMSVGA3DSURFACE pSurface;
62 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
63 AssertReturn(pState, VERR_INVALID_STATE);
64
65 LogFunc(("sid=%u surfaceFlags=%#x format=%s (%#x) multiSampleCount=%d autogenFilter=%d, numMipLevels=%d size=(%dx%dx%d)\n",
66 sid, surfaceFlags, vmsvgaLookupEnum((int)format, &g_SVGA3dSurfaceFormat2String), format, multisampleCount, autogenFilter,
67 numMipLevels, pMipLevel0Size->width, pMipLevel0Size->height, pMipLevel0Size->depth));
68
69 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
70 AssertReturn(numMipLevels >= 1, VERR_INVALID_PARAMETER);
71
72 if (sid >= pState->cSurfaces)
73 {
74 /* Grow the array. */
75 uint32_t cNew = RT_ALIGN(sid + 15, 16);
76 void *pvNew = RTMemRealloc(pState->papSurfaces, sizeof(pState->papSurfaces[0]) * cNew);
77 AssertReturn(pvNew, VERR_NO_MEMORY);
78 pState->papSurfaces = (PVMSVGA3DSURFACE *)pvNew;
79 while (pState->cSurfaces < cNew)
80 {
81 pSurface = (PVMSVGA3DSURFACE)RTMemAllocZ(sizeof(*pSurface));
82 AssertReturn(pSurface, VERR_NO_MEMORY);
83 pSurface->id = SVGA3D_INVALID_ID;
84 pState->papSurfaces[pState->cSurfaces++] = pSurface;
85 }
86 }
87 pSurface = pState->papSurfaces[sid];
88
89 /* If one already exists with this id, then destroy it now. */
90 if (pSurface->id != SVGA3D_INVALID_ID)
91 vmsvga3dSurfaceDestroy(pThisCC, sid);
92
93 RT_ZERO(*pSurface);
94 pSurface->id = SVGA3D_INVALID_ID; /* Keep this value until the surface init completes */
95#ifdef VMSVGA3D_OPENGL
96 pSurface->idWeakContextAssociation = SVGA3D_INVALID_ID;
97 pSurface->oglId.buffer = OPENGL_INVALID_ID;
98#elif defined(VMSVGA3D_DX)
99 // pSurface->pBackendSurface = NULL;
100#else /* VMSVGA3D_DIRECT3D */
101 pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
102 pSurface->hSharedObject = NULL;
103 pSurface->pSharedObjectTree = NULL;
104#endif
105
106 /** @todo This 'switch' and the sufraceFlags tweaks should not be necessary.
107 * The actual surface type will be figured out when the surface is actually used later.
108 * The backends code must be reviewed for unnecessary dependencies on the surfaceFlags value.
109 */
110 /* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
111 * In some case we'll have to wait until the surface is used to create the D3D object.
112 */
113 switch (format)
114 {
115 case SVGA3D_Z_D32:
116 case SVGA3D_Z_D16:
117 case SVGA3D_Z_D24S8:
118 case SVGA3D_Z_D15S1:
119 case SVGA3D_Z_D24X8:
120 case SVGA3D_Z_DF16:
121 case SVGA3D_Z_DF24:
122 case SVGA3D_Z_D24S8_INT:
123 Assert(surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL);
124 surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
125 break;
126
127 /* Texture compression formats */
128 case SVGA3D_DXT1:
129 case SVGA3D_DXT2:
130 case SVGA3D_DXT3:
131 case SVGA3D_DXT4:
132 case SVGA3D_DXT5:
133 /* Bump-map formats */
134 case SVGA3D_BUMPU8V8:
135 case SVGA3D_BUMPL6V5U5:
136 case SVGA3D_BUMPX8L8V8U8:
137 case SVGA3D_V8U8:
138 case SVGA3D_Q8W8V8U8:
139 case SVGA3D_CxV8U8:
140 case SVGA3D_X8L8V8U8:
141 case SVGA3D_A2W10V10U10:
142 case SVGA3D_V16U16:
143 /* Typical render target formats; we should allow render target buffers to be used as textures. */
144 case SVGA3D_X8R8G8B8:
145 case SVGA3D_A8R8G8B8:
146 case SVGA3D_R5G6B5:
147 case SVGA3D_X1R5G5B5:
148 case SVGA3D_A1R5G5B5:
149 case SVGA3D_A4R4G4B4:
150 Assert(surfaceFlags & (SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_SCREENTARGET));
151 surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
152 break;
153
154 case SVGA3D_LUMINANCE8:
155 case SVGA3D_LUMINANCE4_ALPHA4:
156 case SVGA3D_LUMINANCE16:
157 case SVGA3D_LUMINANCE8_ALPHA8:
158 case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
159 case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
160 case SVGA3D_A2R10G10B10:
161 case SVGA3D_ALPHA8:
162 case SVGA3D_R_S10E5:
163 case SVGA3D_R_S23E8:
164 case SVGA3D_RG_S10E5:
165 case SVGA3D_RG_S23E8:
166 case SVGA3D_G16R16:
167 case SVGA3D_A16B16G16R16:
168 case SVGA3D_UYVY:
169 case SVGA3D_YUY2:
170 case SVGA3D_NV12:
171 case SVGA3D_FORMAT_DEAD2: /* Old SVGA3D_AYUV */
172 case SVGA3D_ATI1:
173 case SVGA3D_ATI2:
174 break;
175
176 /*
177 * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
178 * the most efficient format to use when creating new surfaces
179 * expressly for index or vertex data.
180 */
181 case SVGA3D_BUFFER:
182 break;
183
184 default:
185 break;
186 }
187
188 pSurface->surfaceFlags = surfaceFlags;
189 pSurface->format = format;
190 /* cFaces is 6 for a cubemaps and 1 otherwise. */
191 pSurface->cFaces = (uint32_t)((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1);
192 pSurface->cLevels = numMipLevels;
193 pSurface->multiSampleCount = multisampleCount;
194 pSurface->autogenFilter = autogenFilter;
195 Assert(autogenFilter != SVGA3D_TEX_FILTER_FLATCUBIC);
196 Assert(autogenFilter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
197 pSurface->paMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(numMipLevels * pSurface->cFaces * sizeof(VMSVGA3DMIPMAPLEVEL));
198 AssertReturn(pSurface->paMipmapLevels, VERR_NO_MEMORY);
199
200 pSurface->cbBlock = vmsvga3dSurfaceFormatSize(format, &pSurface->cxBlock, &pSurface->cyBlock);
201 AssertReturn(pSurface->cbBlock, VERR_INVALID_PARAMETER);
202
203 /** @todo cbMemRemaining = value of SVGA_REG_MOB_MAX_SIZE */
204 uint32_t cbMemRemaining = SVGA3D_MAX_SURFACE_MEM_SIZE; /* Do not allow more than this for a surface. */
205 SVGA3dSize mipmapSize = *pMipLevel0Size;
206 int rc = VINF_SUCCESS;
207
208 for (uint32_t i = 0; i < numMipLevels; ++i)
209 {
210 for (uint32_t iFace = 0; iFace < pSurface->cFaces; ++iFace)
211 {
212 uint32_t const iMipmap = iFace * numMipLevels + i;
213 LogFunc(("[%d] face %d mip level %d (%d,%d,%d) cbBlock=%#x block %dx%d\n",
214 iMipmap, iFace, i, mipmapSize.width, mipmapSize.height, mipmapSize.depth,
215 pSurface->cbBlock, pSurface->cxBlock, pSurface->cyBlock));
216
217 uint32_t cBlocksX;
218 uint32_t cBlocksY;
219 if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
220 {
221 cBlocksX = mipmapSize.width;
222 cBlocksY = mipmapSize.height;
223 }
224 else
225 {
226 cBlocksX = mipmapSize.width / pSurface->cxBlock;
227 if (mipmapSize.width % pSurface->cxBlock)
228 ++cBlocksX;
229 cBlocksY = mipmapSize.height / pSurface->cyBlock;
230 if (mipmapSize.height % pSurface->cyBlock)
231 ++cBlocksY;
232 }
233
234 AssertBreakStmt(cBlocksX > 0 && cBlocksY > 0 && mipmapSize.depth > 0, rc = VERR_INVALID_PARAMETER);
235
236 const uint32_t cMaxBlocksX = cbMemRemaining / pSurface->cbBlock;
237 AssertBreakStmt(cBlocksX < cMaxBlocksX, rc = VERR_INVALID_PARAMETER);
238
239 const uint32_t cbSurfacePitch = pSurface->cbBlock * cBlocksX;
240 LogFunc(("cbSurfacePitch=0x%x\n", cbSurfacePitch));
241
242 const uint32_t cMaxBlocksY = cbMemRemaining / cbSurfacePitch;
243 AssertBreakStmt(cBlocksY < cMaxBlocksY, rc = VERR_INVALID_PARAMETER);
244
245 const uint32_t cbSurfacePlane = cbSurfacePitch * cBlocksY;
246
247 const uint32_t cMaxDepth = cbMemRemaining / cbSurfacePlane;
248 AssertBreakStmt(mipmapSize.depth < cMaxDepth, rc = VERR_INVALID_PARAMETER);
249
250 const uint32_t cbSurface = cbSurfacePlane * mipmapSize.depth;
251
252 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iMipmap];
253 pMipmapLevel->mipmapSize = mipmapSize;
254 pMipmapLevel->cBlocksX = cBlocksX;
255 pMipmapLevel->cBlocksY = cBlocksY;
256 pMipmapLevel->cBlocks = cBlocksX * cBlocksY * mipmapSize.depth;
257 pMipmapLevel->cbSurfacePitch = cbSurfacePitch;
258 pMipmapLevel->cbSurfacePlane = cbSurfacePlane;
259 pMipmapLevel->cbSurface = cbSurface;
260 pMipmapLevel->pSurfaceData = NULL;
261
262 cbMemRemaining -= cbSurface;
263 }
264
265 AssertRCBreak(rc);
266
267 mipmapSize.width >>= 1;
268 if (mipmapSize.width == 0) mipmapSize.width = 1;
269 mipmapSize.height >>= 1;
270 if (mipmapSize.height == 0) mipmapSize.height = 1;
271 mipmapSize.depth >>= 1;
272 if (mipmapSize.depth == 0) mipmapSize.depth = 1;
273 }
274
275 AssertLogRelRCReturnStmt(rc, RTMemFree(pSurface->paMipmapLevels), rc);
276
277#ifdef VMSVGA3D_DIRECT3D
278 /* Translate the format and usage flags to D3D. */
279 pSurface->d3dfmtRequested = vmsvga3dSurfaceFormat2D3D(format);
280 pSurface->formatD3D = D3D9GetActualFormat(pState, pSurface->d3dfmtRequested);
281 pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount);
282 pSurface->fUsageD3D = 0;
283 if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC)
284 pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC;
285 if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)
286 pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET;
287 if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
288 pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;
289 if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY)
290 pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY;
291 if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)
292 pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;
293 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
294 /* pSurface->u.pSurface = NULL; */
295 /* pSurface->bounce.pTexture = NULL; */
296 /* pSurface->emulated.pTexture = NULL; */
297#elif defined(VMSVGA3D_DX)
298 /* Nothing, because all backend specific data reside in pSurface->pBackendSurface. */
299#else
300 /* pSurface->fEmulated = false; */
301 /* pSurface->idEmulated = OPENGL_INVALID_ID; */
302 vmsvga3dSurfaceFormat2OGL(pSurface, format);
303#endif
304
305 LogFunc(("surface hint(s):%s%s%s%s%s%s\n",
306 (surfaceFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER) ? " SVGA3D_SURFACE_HINT_INDEXBUFFER" : "",
307 (surfaceFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER) ? " SVGA3D_SURFACE_HINT_VERTEXBUFFER" : "",
308 (surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? " SVGA3D_SURFACE_HINT_TEXTURE" : "",
309 (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) ? " SVGA3D_SURFACE_HINT_DEPTHSTENCIL" : "",
310 (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET) ? " SVGA3D_SURFACE_HINT_RENDERTARGET" : "",
311 (surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? " SVGA3D_SURFACE_CUBEMAP" : ""
312 ));
313
314 Assert(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface));
315
316 /* Allocate buffer to hold the surface data until we can move it into a D3D object */
317 for (uint32_t i = 0; i < numMipLevels * pSurface->cFaces; ++i)
318 {
319 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];
320 pMipmapLevel->pSurfaceData = RTMemAllocZ(pMipmapLevel->cbSurface);
321 AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
322 }
323
324 pSurface->id = sid;
325 return VINF_SUCCESS;
326}
327
328
329/**
330 * Implements the SVGA_3D_CMD_SURFACE_DESTROY command (fifo).
331 *
332 * @returns VBox status code (currently ignored).
333 * @param pThisCC The VGA/VMSVGA state for ring-3.
334 * @param sid The ID of the surface to destroy.
335 */
336int vmsvga3dSurfaceDestroy(PVGASTATECC pThisCC, uint32_t sid)
337{
338 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
339 AssertReturn(pState, VERR_NO_MEMORY);
340
341 PVMSVGA3DSURFACE pSurface;
342 int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
343 AssertRCReturn(rc, rc);
344
345 LogFunc(("sid=%u\n", sid));
346
347 /* Check all contexts if this surface is used as a render target or active texture. */
348 for (uint32_t cid = 0; cid < pState->cContexts; cid++)
349 {
350 PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
351 if (pContext->id == cid)
352 {
353 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); ++i)
354 if (pContext->aSidActiveTextures[i] == sid)
355 pContext->aSidActiveTextures[i] = SVGA3D_INVALID_ID;
356 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); ++i)
357 if (pContext->state.aRenderTargets[i] == sid)
358 pContext->state.aRenderTargets[i] = SVGA3D_INVALID_ID;
359 }
360 }
361
362 vmsvga3dBackSurfaceDestroy(pState, pSurface);
363
364 if (pSurface->paMipmapLevels)
365 {
366 for (uint32_t i = 0; i < pSurface->cLevels * pSurface->cFaces; ++i)
367 RTMemFreeZ(pSurface->paMipmapLevels[i].pSurfaceData, pSurface->paMipmapLevels[i].cbSurface);
368 RTMemFree(pSurface->paMipmapLevels);
369 }
370
371 memset(pSurface, 0, sizeof(*pSurface));
372 pSurface->id = SVGA3D_INVALID_ID;
373
374 return VINF_SUCCESS;
375}
376
377
378/**
379 * Implements the SVGA_3D_CMD_SURFACE_STRETCHBLT command (fifo).
380 *
381 * @returns VBox status code (currently ignored).
382 * @param pThis The shared VGA/VMSVGA state.
383 * @param pThisCC The VGA/VMSVGA state for ring-3.
384 * @param pDstSfcImg
385 * @param pDstBox
386 * @param pSrcSfcImg
387 * @param pSrcBox
388 * @param enmMode
389 */
390int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pDstSfcImg, SVGA3dBox const *pDstBox,
391 SVGA3dSurfaceImageId const *pSrcSfcImg, SVGA3dBox const *pSrcBox, SVGA3dStretchBltMode enmMode)
392{
393 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
394 AssertReturn(pState, VERR_NO_MEMORY);
395
396 int rc;
397
398 uint32_t const sidSrc = pSrcSfcImg->sid;
399 PVMSVGA3DSURFACE pSrcSurface;
400 rc = vmsvga3dSurfaceFromSid(pState, sidSrc, &pSrcSurface);
401 AssertRCReturn(rc, rc);
402
403 uint32_t const sidDst = pDstSfcImg->sid;
404 PVMSVGA3DSURFACE pDstSurface;
405 rc = vmsvga3dSurfaceFromSid(pState, sidDst, &pDstSurface);
406 AssertRCReturn(rc, rc);
407
408 AssertReturn(pSrcSfcImg->face < pSrcSurface->cFaces, VERR_INVALID_PARAMETER);
409 AssertReturn(pSrcSfcImg->mipmap < pSrcSurface->cLevels, VERR_INVALID_PARAMETER);
410 AssertReturn(pDstSfcImg->face < pDstSurface->cFaces, VERR_INVALID_PARAMETER);
411 AssertReturn(pDstSfcImg->mipmap < pDstSurface->cLevels, VERR_INVALID_PARAMETER);
412
413 PVMSVGA3DCONTEXT pContext;
414#ifdef VMSVGA3D_OPENGL
415 LogFunc(("src sid=%u (%d,%d)(%d,%d) dest sid=%u (%d,%d)(%d,%d) mode=%x\n",
416 sidSrc, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
417 sidDst, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
418 pContext = &pState->SharedCtx;
419 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
420#else
421 LogFunc(("src sid=%u cid=%u (%d,%d)(%d,%d) dest sid=%u cid=%u (%d,%d)(%d,%d) mode=%x\n",
422 sidSrc, pSrcSurface->idAssociatedContext, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
423 sidDst, pDstSurface->idAssociatedContext, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
424
425 uint32_t cid = pDstSurface->idAssociatedContext;
426 if (cid == SVGA3D_INVALID_ID)
427 cid = pSrcSurface->idAssociatedContext;
428
429 /* At least one of surfaces must be in hardware. */
430 AssertReturn(cid != SVGA3D_INVALID_ID, VERR_INVALID_PARAMETER);
431
432 rc = vmsvga3dContextFromCid(pState, cid, &pContext);
433 AssertRCReturn(rc, rc);
434#endif
435
436 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSrcSurface))
437 {
438 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
439 LogFunc(("unknown src sid=%u type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->surfaceFlags, pSrcSurface->format));
440 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface);
441 AssertRCReturn(rc, rc);
442 }
443
444 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pDstSurface))
445 {
446 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
447 LogFunc(("unknown dest sid=%u type=%d format=%d -> create texture\n", sidDst, pDstSurface->surfaceFlags, pDstSurface->format));
448 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface);
449 AssertRCReturn(rc, rc);
450 }
451
452 PVMSVGA3DMIPMAPLEVEL pSrcMipmapLevel;
453 rc = vmsvga3dMipmapLevel(pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &pSrcMipmapLevel);
454 AssertRCReturn(rc, rc);
455
456 PVMSVGA3DMIPMAPLEVEL pDstMipmapLevel;
457 rc = vmsvga3dMipmapLevel(pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &pDstMipmapLevel);
458 AssertRCReturn(rc, rc);
459
460 SVGA3dBox clipSrcBox = *pSrcBox;
461 SVGA3dBox clipDstBox = *pDstBox;
462 vmsvgaR3ClipBox(&pSrcMipmapLevel->mipmapSize, &clipSrcBox);
463 vmsvgaR3ClipBox(&pDstMipmapLevel->mipmapSize, &clipDstBox);
464
465 return vmsvga3dBackSurfaceStretchBlt(pThis, pState,
466 pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &clipDstBox,
467 pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &clipSrcBox,
468 enmMode, pContext);
469}
470
471/**
472 * Implements the SVGA_3D_CMD_SURFACE_DMA command (fifo).
473 *
474 * @returns VBox status code (currently ignored).
475 * @param pThis The shared VGA/VMSVGA instance data.
476 * @param pThisCC The VGA/VMSVGA state for ring-3.
477 * @param guest .
478 * @param host .
479 * @param transfer .
480 * @param cCopyBoxes .
481 * @param paBoxes .
482 */
483int vmsvga3dSurfaceDMA(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAGuestImage guest, SVGA3dSurfaceImageId host,
484 SVGA3dTransferType transfer, uint32_t cCopyBoxes, SVGA3dCopyBox *paBoxes)
485{
486 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
487 AssertReturn(pState, VERR_NO_MEMORY);
488
489 PVMSVGA3DSURFACE pSurface;
490 int rc = vmsvga3dSurfaceFromSid(pState, host.sid, &pSurface);
491 AssertRCReturn(rc, rc);
492
493 LogFunc(("%sguestptr gmr=%x offset=%x pitch=%x host sid=%u face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n",
494 (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",
495 guest.ptr.gmrId, guest.ptr.offset, guest.pitch,
496 host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
497
498 PVMSVGA3DMIPMAPLEVEL pMipLevel;
499 rc = vmsvga3dMipmapLevel(pSurface, host.face, host.mipmap, &pMipLevel);
500 AssertRCReturn(rc, rc);
501
502 PVMSVGA3DCONTEXT pContext = NULL;
503 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
504 {
505 /*
506 * Not realized in host hardware/library yet, we have to work with
507 * the copy of the data we've got in VMSVGA3DMIMAPLEVEL::pSurfaceData.
508 */
509 AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR);
510 }
511 else
512 {
513#ifdef VMSVGA3D_DIRECT3D
514 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
515 vmsvga3dSurfaceFlush(pSurface);
516#elif defined(VMSVGA3D_DX)
517 /** @todo */
518#else /* VMSVGA3D_OPENGL */
519 pContext = &pState->SharedCtx;
520 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
521#endif
522 }
523
524 /* SVGA_3D_CMD_SURFACE_DMA:
525 * "define the 'source' in each copyBox as the guest image and the
526 * 'destination' as the host image, regardless of transfer direction."
527 */
528 for (uint32_t i = 0; i < cCopyBoxes; ++i)
529 {
530 Log(("Copy box (%s) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
531 VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface) ? "hw" : "mem",
532 i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
533
534 /* Apparently we're supposed to clip it (gmr test sample) */
535
536 /* The copybox's "dest" is coords in the host surface. Verify them against the surface's mipmap size. */
537 SVGA3dBox hostBox;
538 hostBox.x = paBoxes[i].x;
539 hostBox.y = paBoxes[i].y;
540 hostBox.z = paBoxes[i].z;
541 hostBox.w = paBoxes[i].w;
542 hostBox.h = paBoxes[i].h;
543 hostBox.d = paBoxes[i].d;
544 vmsvgaR3ClipBox(&pMipLevel->mipmapSize, &hostBox);
545
546 if ( !hostBox.w
547 || !hostBox.h
548 || !hostBox.d)
549 {
550 Log(("Skip empty box\n"));
551 continue;
552 }
553 RT_UNTRUSTED_VALIDATED_FENCE();
554
555 /* Adjust the guest, i.e. "src", point.
556 * Do not try to verify them here because vmsvgaR3GmrTransfer takes care of this.
557 */
558 uint32_t const srcx = paBoxes[i].srcx + (hostBox.x - paBoxes[i].x);
559 uint32_t const srcy = paBoxes[i].srcy + (hostBox.y - paBoxes[i].y);
560 uint32_t const srcz = paBoxes[i].srcz + (hostBox.z - paBoxes[i].z);
561
562 /* Calculate offsets of the image blocks for the transfer. */
563 uint32_t u32HostBlockX;
564 uint32_t u32HostBlockY;
565 uint32_t u32GuestBlockX;
566 uint32_t u32GuestBlockY;
567 uint32_t cBlocksX;
568 uint32_t cBlocksY;
569 if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
570 {
571 u32HostBlockX = hostBox.x;
572 u32HostBlockY = hostBox.y;
573
574 u32GuestBlockX = srcx;
575 u32GuestBlockY = srcy;
576
577 cBlocksX = hostBox.w;
578 cBlocksY = hostBox.h;
579 }
580 else
581 {
582 /* Pixels to blocks. */
583 u32HostBlockX = hostBox.x / pSurface->cxBlock;
584 u32HostBlockY = hostBox.y / pSurface->cyBlock;
585 Assert(u32HostBlockX * pSurface->cxBlock == hostBox.x);
586 Assert(u32HostBlockY * pSurface->cyBlock == hostBox.y);
587
588 u32GuestBlockX = srcx / pSurface->cxBlock;
589 u32GuestBlockY = srcy / pSurface->cyBlock;
590 Assert(u32GuestBlockX * pSurface->cxBlock == srcx);
591 Assert(u32GuestBlockY * pSurface->cyBlock == srcy);
592
593 cBlocksX = (hostBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
594 cBlocksY = (hostBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
595 }
596
597 uint32_t cbGuestPitch = guest.pitch;
598 if (cbGuestPitch == 0)
599 {
600 /* Host must "assume image is tightly packed". Our surfaces are. */
601 cbGuestPitch = pMipLevel->cbSurfacePitch;
602 }
603 else
604 {
605 /* vmsvgaR3GmrTransfer will verify the value, just check it is sane. */
606 AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
607 RT_UNTRUSTED_VALIDATED_FENCE();
608 }
609
610 /* srcx, srcy and srcz values are used to calculate the guest offset.
611 * The offset will be verified by vmsvgaR3GmrTransfer, so just check for overflows here.
612 */
613 AssertReturn(srcz < UINT32_MAX / pMipLevel->mipmapSize.height / cbGuestPitch, VERR_INVALID_PARAMETER);
614 AssertReturn(u32GuestBlockY < UINT32_MAX / cbGuestPitch, VERR_INVALID_PARAMETER);
615 AssertReturn(u32GuestBlockX < UINT32_MAX / pSurface->cbBlock, VERR_INVALID_PARAMETER);
616 RT_UNTRUSTED_VALIDATED_FENCE();
617
618 if ( !VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface)
619 || VMSVGA3DSURFACE_NEEDS_DATA(pSurface))
620 {
621 uint64_t uGuestOffset = u32GuestBlockX * pSurface->cbBlock +
622 u32GuestBlockY * cbGuestPitch +
623 srcz * pMipLevel->mipmapSize.height * cbGuestPitch;
624 AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
625
626 /* vmsvga3dSurfaceDefine verifies the surface dimensions and clipBox is within them. */
627 uint32_t uHostOffset = u32HostBlockX * pSurface->cbBlock +
628 u32HostBlockY * pMipLevel->cbSurfacePitch +
629 hostBox.z * pMipLevel->cbSurfacePlane;
630 AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
631
632 for (uint32_t z = 0; z < hostBox.d; ++z)
633 {
634 rc = vmsvgaR3GmrTransfer(pThis,
635 pThisCC,
636 transfer,
637 (uint8_t *)pMipLevel->pSurfaceData,
638 pMipLevel->cbSurface,
639 uHostOffset,
640 (int32_t)pMipLevel->cbSurfacePitch,
641 guest.ptr,
642 (uint32_t)uGuestOffset,
643 cbGuestPitch,
644 cBlocksX * pSurface->cbBlock,
645 cBlocksY);
646 AssertRC(rc);
647
648 Log4(("first line [z=%d] (updated at offset 0x%x):\n%.*Rhxd\n",
649 z, uHostOffset, pMipLevel->cbSurfacePitch, pMipLevel->pSurfaceData));
650
651 uHostOffset += pMipLevel->cbSurfacePlane;
652 uGuestOffset += pMipLevel->mipmapSize.height * cbGuestPitch;
653 AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
654 }
655 }
656
657 if (VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
658 {
659 SVGA3dCopyBox clipBox;
660 clipBox.x = hostBox.x;
661 clipBox.y = hostBox.y;
662 clipBox.z = hostBox.z;
663 clipBox.w = hostBox.w;
664 clipBox.h = hostBox.h;
665 clipBox.d = hostBox.d;
666 clipBox.srcx = srcx;
667 clipBox.srcy = srcy;
668 clipBox.srcz = srcz;
669 rc = vmsvga3dBackSurfaceDMACopyBox(pThis, pThisCC, pState, pSurface, pMipLevel, host.face, host.mipmap,
670 guest.ptr, cbGuestPitch, transfer,
671 &clipBox, pContext, rc, i);
672 AssertRC(rc);
673 }
674 }
675
676 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
677 {
678 pMipLevel->fDirty = true;
679 pSurface->fDirty = true;
680 }
681
682 return rc;
683}
684
685static int vmsvga3dQueryWriteResult(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAGuestPtr guestResult,
686 SVGA3dQueryState enmState, uint32_t u32Result)
687{
688 SVGA3dQueryResult queryResult;
689 queryResult.totalSize = sizeof(queryResult); /* Set by guest before query is ended. */
690 queryResult.state = enmState; /* Set by host or guest. See SVGA3dQueryState. */
691 queryResult.result32 = u32Result;
692
693 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_READ_HOST_VRAM,
694 (uint8_t *)&queryResult, sizeof(queryResult), 0, sizeof(queryResult),
695 guestResult, 0, sizeof(queryResult), sizeof(queryResult), 1);
696 AssertRC(rc);
697 return rc;
698}
699
700int vmsvga3dQueryBegin(PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type)
701{
702 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
703 AssertReturn(pState, VERR_NO_MEMORY);
704
705 LogFunc(("cid=%u type=%d\n", cid, type));
706
707 PVMSVGA3DCONTEXT pContext;
708 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
709 AssertRCReturn(rc, rc);
710
711 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
712 {
713 VMSVGA3DQUERY *p = &pContext->occlusion;
714 if (!VMSVGA3DQUERY_EXISTS(p))
715 {
716 /* Lazy creation of the query object. */
717 rc = vmsvga3dOcclusionQueryCreate(pState, pContext);
718 AssertRCReturn(rc, rc);
719 }
720
721 rc = vmsvga3dOcclusionQueryBegin(pState, pContext);
722 AssertRCReturn(rc, rc);
723
724 p->enmQueryState = VMSVGA3DQUERYSTATE_BUILDING;
725 p->u32QueryResult = 0;
726
727 return VINF_SUCCESS;
728 }
729
730 /* Nothing else for VGPU9. */
731 AssertFailedReturn(VERR_NOT_IMPLEMENTED);
732}
733
734int vmsvga3dQueryEnd(PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
735{
736 RT_NOREF(guestResult);
737 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
738 AssertReturn(pState, VERR_NO_MEMORY);
739
740 LogFunc(("cid=%u type=%d guestResult %d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
741
742 PVMSVGA3DCONTEXT pContext;
743 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
744 AssertRCReturn(rc, rc);
745
746 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
747 {
748 VMSVGA3DQUERY *p = &pContext->occlusion;
749 Assert(p->enmQueryState == VMSVGA3DQUERYSTATE_BUILDING);
750 AssertMsgReturn(VMSVGA3DQUERY_EXISTS(p), ("Query is NULL\n"), VERR_INTERNAL_ERROR);
751
752 rc = vmsvga3dOcclusionQueryEnd(pState, pContext);
753 AssertRCReturn(rc, rc);
754
755 p->enmQueryState = VMSVGA3DQUERYSTATE_ISSUED;
756
757 /* Do not touch guestResult, because the guest will call WaitForQuery. */
758 return VINF_SUCCESS;
759 }
760
761 /* Nothing else for VGPU9. */
762 AssertFailedReturn(VERR_NOT_IMPLEMENTED);
763}
764
765int vmsvga3dQueryWait(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
766{
767 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
768 AssertReturn(pState, VERR_NO_MEMORY);
769
770 LogFunc(("cid=%u type=%d guestResult GMR%d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
771
772 PVMSVGA3DCONTEXT pContext;
773 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
774 AssertRCReturn(rc, rc);
775
776 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
777 {
778 VMSVGA3DQUERY *p = &pContext->occlusion;
779 if (VMSVGA3DQUERY_EXISTS(p))
780 {
781 if (p->enmQueryState == VMSVGA3DQUERYSTATE_ISSUED)
782 {
783 /* Only if not already in SIGNALED state,
784 * i.e. not a second read from the guest or after restoring saved state.
785 */
786 uint32_t u32Pixels = 0;
787 rc = vmsvga3dOcclusionQueryGetData(pState, pContext, &u32Pixels);
788 if (RT_SUCCESS(rc))
789 {
790 p->enmQueryState = VMSVGA3DQUERYSTATE_SIGNALED;
791 p->u32QueryResult += u32Pixels; /* += because it might contain partial result from saved state. */
792 }
793 }
794
795 if (RT_SUCCESS(rc))
796 {
797 /* Return data to the guest. */
798 vmsvga3dQueryWriteResult(pThis, pThisCC, guestResult, SVGA3D_QUERYSTATE_SUCCEEDED, p->u32QueryResult);
799 return VINF_SUCCESS;
800 }
801 }
802 else
803 {
804 AssertMsgFailed(("GetData Query is NULL\n"));
805 }
806
807 rc = VERR_INTERNAL_ERROR;
808 }
809 else
810 {
811 rc = VERR_NOT_IMPLEMENTED;
812 }
813
814 vmsvga3dQueryWriteResult(pThis, pThisCC, guestResult, SVGA3D_QUERYSTATE_FAILED, 0);
815 AssertFailedReturn(rc);
816}
817
818int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t idDstScreen, SVGASignedRect destRect,
819 SVGA3dSurfaceImageId srcImage, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
820{
821 /* Requires SVGA_FIFO_CAP_SCREEN_OBJECT support */
822 LogFunc(("dest=%d (%d,%d)(%d,%d) sid=%u (face=%d, mipmap=%d) (%d,%d)(%d,%d) cRects=%d\n",
823 idDstScreen, destRect.left, destRect.top, destRect.right, destRect.bottom, srcImage.sid, srcImage.face, srcImage.mipmap,
824 srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, cRects));
825 for (uint32_t i = 0; i < cRects; i++)
826 {
827 LogFunc(("clipping rect %d (%d,%d)(%d,%d)\n", i, pRect[i].left, pRect[i].top, pRect[i].right, pRect[i].bottom));
828 }
829
830 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, idDstScreen);
831 AssertReturn(pScreen, VERR_INTERNAL_ERROR);
832
833 /* vmwgfx driver does not always initialize srcImage.mipmap and srcImage.face. They are assumed to be zero. */
834 SVGA3dSurfaceImageId src;
835 src.sid = srcImage.sid;
836 src.mipmap = 0;
837 src.face = 0;
838
839 if (pScreen->pHwScreen)
840 {
841 /* Use the backend accelerated method, if available. */
842 int rc = vmsvga3dBackSurfaceBlitToScreen(pThisCC, pScreen,
843 destRect, src, srcRect, cRects, pRect);
844 if (rc == VINF_SUCCESS)
845 {
846 return VINF_SUCCESS;
847 }
848 }
849
850 /** @todo scaling */
851 AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
852
853 SVGA3dCopyBox box;
854 SVGAGuestImage dest;
855
856 box.srcz = 0;
857 box.z = 0;
858 box.d = 1;
859
860 dest.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
861 dest.ptr.offset = pScreen->offVRAM;
862 dest.pitch = pScreen->cbPitch;
863
864 if (cRects == 0)
865 {
866 /* easy case; no clipping */
867
868 /* SVGA_3D_CMD_SURFACE_DMA:
869 * 'define the "source" in each copyBox as the guest image and the
870 * "destination" as the host image, regardless of transfer direction.'
871 *
872 * Since the BlitToScreen operation transfers from a host surface to the guest VRAM,
873 * it must set the copyBox "source" to the guest destination coords and
874 * the copyBox "destination" to the host surface source coords.
875 */
876 /* Host image. */
877 box.x = srcRect.left;
878 box.y = srcRect.top;
879 box.w = srcRect.right - srcRect.left;
880 box.h = srcRect.bottom - srcRect.top;
881 /* Guest image. */
882 box.srcx = destRect.left;
883 box.srcy = destRect.top;
884
885 int rc = vmsvga3dSurfaceDMA(pThis, pThisCC, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
886 AssertRCReturn(rc, rc);
887
888 /* Update the guest image, which is at box.src. */
889 vmsvgaR3UpdateScreen(pThisCC, pScreen, box.srcx, box.srcy, box.w, box.h);
890 }
891 else
892 {
893 /** @todo merge into one SurfaceDMA call */
894 for (uint32_t i = 0; i < cRects; i++)
895 {
896 /* "The clip rectangle coordinates are measured
897 * relative to the top-left corner of destRect."
898 * Therefore they are relative to the top-left corner of srcRect as well.
899 */
900
901 /* Host image. See 'SVGA_3D_CMD_SURFACE_DMA:' comment in the 'if' branch. */
902 box.x = srcRect.left + pRect[i].left;
903 box.y = srcRect.top + pRect[i].top;
904 box.w = pRect[i].right - pRect[i].left;
905 box.h = pRect[i].bottom - pRect[i].top;
906 /* Guest image. The target screen memory is currently in the guest VRAM. */
907 box.srcx = destRect.left + pRect[i].left;
908 box.srcy = destRect.top + pRect[i].top;
909
910 int rc = vmsvga3dSurfaceDMA(pThis, pThisCC, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
911 AssertRCReturn(rc, rc);
912
913 /* Update the guest image, which is at box.src. */
914 vmsvgaR3UpdateScreen(pThisCC, pScreen, box.srcx, box.srcy, box.w, box.h);
915 }
916 }
917
918 return VINF_SUCCESS;
919}
920
921int vmsvga3dCommandPresent(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t sid, uint32_t cRects, SVGA3dCopyRect *pRect)
922{
923 /* Deprecated according to svga3d_reg.h. */
924 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
925 AssertReturn(pState, VERR_NO_MEMORY);
926
927 PVMSVGA3DSURFACE pSurface;
928 int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
929 AssertRCReturn(rc, rc);
930
931 /** @todo Detect screen from coords? Or split rect to screens? */
932 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
933 AssertReturn(pScreen, VERR_INTERNAL_ERROR);
934
935 /* If there are no recangles specified, just grab a screenful. */
936 SVGA3dCopyRect DummyRect;
937 if (cRects != 0)
938 { /* likely */ }
939 else
940 {
941 /** @todo Find the usecase for this or check what the original device does.
942 * The original code was doing some scaling based on the surface
943 * size... */
944 AssertMsgFailed(("No rects to present. Who is doing that and what do they actually expect?\n"));
945 DummyRect.x = DummyRect.srcx = 0;
946 DummyRect.y = DummyRect.srcy = 0;
947 DummyRect.w = pScreen->cWidth;
948 DummyRect.h = pScreen->cHeight;
949 cRects = 1;
950 pRect = &DummyRect;
951 }
952
953 uint32_t i;
954 for (i = 0; i < cRects; ++i)
955 {
956 uint32_t idDstScreen = 0; /** @todo Use virtual coords: SVGA_ID_INVALID. */
957 SVGASignedRect destRect;
958 destRect.left = pRect[i].x;
959 destRect.top = pRect[i].y;
960 destRect.right = pRect[i].x + pRect[i].w;
961 destRect.bottom = pRect[i].y + pRect[i].h;
962
963 SVGA3dSurfaceImageId src;
964 src.sid = sid;
965 src.face = 0;
966 src.mipmap = 0;
967
968 SVGASignedRect srcRect;
969 srcRect.left = pRect[i].srcx;
970 srcRect.top = pRect[i].srcy;
971 srcRect.right = pRect[i].srcx + pRect[i].w;
972 srcRect.bottom = pRect[i].srcy + pRect[i].h;
973
974 /* Entire rect. */
975 rc = vmsvga3dSurfaceBlitToScreen(pThis, pThisCC, idDstScreen, destRect, src, srcRect, 0, NULL);
976 AssertRCReturn(rc, rc);
977 }
978
979 return VINF_SUCCESS;
980}
981
982int vmsvga3dDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen)
983{
984 if (pScreen->pHwScreen)
985 {
986 vmsvga3dBackDestroyScreen(pThisCC, pScreen);
987 }
988
989 int rc = vmsvga3dBackDefineScreen(pThis, pThisCC, pScreen);
990 if (RT_SUCCESS(rc))
991 {
992 LogRelMax(1, ("VMSVGA: using accelerated graphics output\n"));
993 }
994 return rc;
995}
996
997int vmsvga3dDestroyScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen)
998{
999 return vmsvga3dBackDestroyScreen(pThisCC, pScreen);
1000}
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