Changeset 34571 in vbox for trunk/src/VBox/HostServices/SharedOpenGL
- Timestamp:
- Dec 1, 2010 1:45:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp
r34182 r34571 73 73 static const char* gszVBoxOGLSSMMagic = "***OpenGL state data***"; 74 74 75 typedef struct _CRVBOXSVCBUFFER_t { 76 uint32_t uiId; 77 uint32_t uiSize; 78 void* pData; 79 _CRVBOXSVCBUFFER_t *pNext, *pPrev; 80 } CRVBOXSVCBUFFER_t; 81 82 static CRVBOXSVCBUFFER_t *g_pCRVBoxSVCBuffers = NULL; 83 static uint32_t g_CRVBoxSVCBufferID = 0; 84 75 85 static DECLCALLBACK(int) svcUnload (void *) 76 86 { … … 129 139 rc = crVBoxServerSaveState(pSSM); 130 140 AssertRCReturn(rc, rc); 141 142 /* Save svc buffers info */ 143 { 144 CRVBOXSVCBUFFER_t *pBuffer = g_pCRVBoxSVCBuffers; 145 146 rc = SSMR3PutU32(pSSM, g_CRVBoxSVCBufferID); 147 AssertRCReturn(rc, rc); 148 149 while (pBuffer) 150 { 151 rc = SSMR3PutU32(pSSM, pBuffer->uiId); 152 AssertRCReturn(rc, rc); 153 154 rc = SSMR3PutU32(pSSM, pBuffer->uiSize); 155 AssertRCReturn(rc, rc); 156 157 rc = SSMR3PutMem(pSSM, pBuffer->pData, pBuffer->uiSize); 158 AssertRCReturn(rc, rc); 159 160 pBuffer = pBuffer->pNext; 161 } 162 163 rc = SSMR3PutU32(pSSM, 0); 164 AssertRCReturn(rc, rc); 165 } 131 166 132 167 /* End */ … … 159 194 160 195 /* The state itself */ 196 #if SHCROGL_SSM_VERSION==24 197 if (ui32==23) 198 { 199 rc = crVBoxServerLoadState(pSSM, 24); 200 } 201 else 202 #endif 161 203 rc = crVBoxServerLoadState(pSSM, ui32); 162 204 … … 190 232 } 191 233 AssertRCReturn(rc, rc); 234 235 /* Load svc buffers info */ 236 if (ui32>=24) 237 { 238 uint32_t uiId; 239 240 rc = SSMR3GetU32(pSSM, &g_CRVBoxSVCBufferID); 241 AssertRCReturn(rc, rc); 242 243 rc = SSMR3GetU32(pSSM, &uiId); 244 AssertRCReturn(rc, rc); 245 246 while (uiId) 247 { 248 CRVBOXSVCBUFFER_t *pBuffer = (CRVBOXSVCBUFFER_t *) RTMemAlloc(sizeof(CRVBOXSVCBUFFER_t)); 249 if (!pBuffer) 250 { 251 return VERR_NO_MEMORY; 252 } 253 pBuffer->uiId = uiId; 254 255 rc = SSMR3GetU32(pSSM, &pBuffer->uiSize); 256 AssertRCReturn(rc, rc); 257 258 pBuffer->pData = RTMemAlloc(pBuffer->uiSize); 259 if (!pBuffer->pData) 260 { 261 RTMemFree(pBuffer); 262 return VERR_NO_MEMORY; 263 } 264 265 rc = SSMR3GetMem(pSSM, pBuffer->pData, pBuffer->uiSize); 266 AssertRCReturn(rc, rc); 267 268 pBuffer->pNext = g_pCRVBoxSVCBuffers; 269 pBuffer->pPrev = NULL; 270 if (g_pCRVBoxSVCBuffers) 271 { 272 g_pCRVBoxSVCBuffers->pPrev = pBuffer; 273 } 274 g_pCRVBoxSVCBuffers = pBuffer; 275 276 rc = SSMR3GetU32(pSSM, &uiId); 277 AssertRCReturn(rc, rc); 278 } 279 } 192 280 193 281 /* End of data */ … … 247 335 CHECK_ERROR(g_pConsole, COMGETTER(Display)(pDisplay.asOutParam())); 248 336 CHECK_ERROR(pDisplay, DrawToScreen(screenId, (BYTE*)data, x, y, w, h)); 337 } 338 339 static CRVBOXSVCBUFFER_t* svcGetBuffer(uint32_t iBuffer, uint32_t cbBufferSize) 340 { 341 CRVBOXSVCBUFFER_t* pBuffer; 342 343 if (iBuffer) 344 { 345 pBuffer = g_pCRVBoxSVCBuffers; 346 while (pBuffer) 347 { 348 if (pBuffer->uiId == iBuffer) 349 { 350 return pBuffer; 351 } 352 pBuffer = pBuffer->pNext; 353 } 354 return NULL; 355 } 356 else /*allocate new buffer*/ 357 { 358 pBuffer = (CRVBOXSVCBUFFER_t*) RTMemAlloc(sizeof(CRVBOXSVCBUFFER_t)); 359 if (pBuffer) 360 { 361 pBuffer->pData = RTMemAlloc(cbBufferSize); 362 if (!pBuffer->pData) 363 { 364 LogRel(("SHARED_CROPENGL svcGetBuffer: not enough memory (%d)\n", cbBufferSize)); 365 RTMemFree(pBuffer); 366 return NULL; 367 } 368 pBuffer->uiId = ++g_CRVBoxSVCBufferID; 369 if (!pBuffer->uiId) 370 { 371 pBuffer->uiId = ++g_CRVBoxSVCBufferID; 372 } 373 Assert(pBuffer->uiId); 374 pBuffer->uiSize = cbBufferSize; 375 pBuffer->pPrev = NULL; 376 pBuffer->pNext = g_pCRVBoxSVCBuffers; 377 if (g_pCRVBoxSVCBuffers) 378 { 379 g_pCRVBoxSVCBuffers->pPrev = pBuffer; 380 } 381 g_pCRVBoxSVCBuffers = pBuffer; 382 } 383 else 384 { 385 LogRel(("SHARED_CROPENGL svcGetBuffer: not enough memory (%d)\n", sizeof(CRVBOXSVCBUFFER_t))); 386 } 387 return pBuffer; 388 } 389 } 390 391 static void svcFreeBuffer(CRVBOXSVCBUFFER_t* pBuffer) 392 { 393 Assert(pBuffer); 394 395 if (pBuffer->pPrev) 396 { 397 pBuffer->pPrev->pNext = pBuffer->pNext; 398 } 399 else 400 { 401 Assert(pBuffer==g_pCRVBoxSVCBuffers); 402 g_pCRVBoxSVCBuffers = pBuffer->pNext; 403 } 404 405 if (pBuffer->pNext) 406 { 407 pBuffer->pNext->pPrev = pBuffer->pPrev; 408 } 409 410 RTMemFree(pBuffer->pData); 411 RTMemFree(pBuffer); 249 412 } 250 413 … … 484 647 /* Execute the function. */ 485 648 rc = crVBoxServerClientSetPID(u32ClientID, pid); 649 } 650 651 break; 652 } 653 654 case SHCRGL_GUEST_FN_WRITE_BUFFER: 655 { 656 Log(("svcCall: SHCRGL_GUEST_FN_WRITE_BUFFER\n")); 657 /* Verify parameter count and types. */ 658 if (cParms != SHCRGL_CPARMS_WRITE_BUFFER) 659 { 660 rc = VERR_INVALID_PARAMETER; 661 } 662 else 663 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /*iBufferID*/ 664 || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /*cbBufferSize*/ 665 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /*ui32Offset*/ 666 || paParms[3].type != VBOX_HGCM_SVC_PARM_PTR /*pBuffer*/ 667 ) 668 { 669 rc = VERR_INVALID_PARAMETER; 670 } 671 else 672 { 673 /* Fetch parameters. */ 674 uint32_t iBuffer = paParms[0].u.uint32; 675 uint32_t cbBufferSize = paParms[1].u.uint32; 676 uint32_t ui32Offset = paParms[2].u.uint32; 677 uint8_t *pBuffer = (uint8_t *)paParms[3].u.pointer.addr; 678 uint32_t cbBuffer = paParms[3].u.pointer.size; 679 680 /* Execute the function. */ 681 CRVBOXSVCBUFFER_t *pSvcBuffer = svcGetBuffer(iBuffer, cbBufferSize); 682 if (!pSvcBuffer || ui32Offset+cbBuffer>cbBufferSize) 683 { 684 rc = VERR_INVALID_PARAMETER; 685 } 686 else 687 { 688 memcpy((void*)((uintptr_t)pSvcBuffer->pData+ui32Offset), pBuffer, cbBuffer); 689 690 /* Return the buffer id */ 691 paParms[0].u.uint32 = pSvcBuffer->uiId; 692 } 693 } 694 695 break; 696 } 697 698 case SHCRGL_GUEST_FN_WRITE_READ_BUFFERED: 699 { 700 Log(("svcCall: SHCRGL_GUEST_FN_WRITE_READ_BUFFERED\n")); 701 702 /* Verify parameter count and types. */ 703 if (cParms != SHCRGL_CPARMS_WRITE_READ_BUFFERED) 704 { 705 rc = VERR_INVALID_PARAMETER; 706 } 707 else 708 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* iBufferID */ 709 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* pWriteback */ 710 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* cbWriteback */ 711 || !paParms[0].u.uint32 /*iBufferID can't be 0 here*/ 712 ) 713 { 714 rc = VERR_INVALID_PARAMETER; 715 } 716 else 717 { 718 /* Fetch parameters. */ 719 uint32_t iBuffer = paParms[0].u.uint32; 720 uint8_t *pWriteback = (uint8_t *)paParms[1].u.pointer.addr; 721 uint32_t cbWriteback = paParms[1].u.pointer.size; 722 723 CRVBOXSVCBUFFER_t *pSvcBuffer = svcGetBuffer(iBuffer, 0); 724 if (!pSvcBuffer) 725 { 726 LogRel(("SHARED_CROPENGL svcCall(WRITE_READ_BUFFERED): invalid buffer (%d)\n", iBuffer)); 727 rc = VERR_INVALID_PARAMETER; 728 break; 729 } 730 731 uint8_t *pBuffer = (uint8_t *)pSvcBuffer->pData; 732 uint32_t cbBuffer = pSvcBuffer->uiSize; 733 734 /* Execute the function. */ 735 rc = crVBoxServerClientWrite(u32ClientID, pBuffer, cbBuffer); 736 if (!RT_SUCCESS(rc)) 737 { 738 Assert(VERR_NOT_SUPPORTED==rc); 739 svcClientVersionUnsupported(0, 0); 740 } 741 742 rc = crVBoxServerClientRead(u32ClientID, pWriteback, &cbWriteback); 743 744 if (RT_SUCCESS(rc)) 745 { 746 /* Update parameters.*/ 747 paParms[1].u.pointer.size = cbWriteback; 748 } 749 /* Return the required buffer size always */ 750 paParms[2].u.uint32 = cbWriteback; 751 752 svcFreeBuffer(pSvcBuffer); 486 753 } 487 754
Note:
See TracChangeset
for help on using the changeset viewer.