Changeset 48325 in vbox for trunk/src/VBox/HostServices/SharedOpenGL/render
- Timestamp:
- Sep 5, 2013 7:45:51 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r48291 r48325 32 32 #include <cr_error.h> 33 33 #include <cr_blitter.h> 34 #ifdef VBOX_WITH_CRDUMPER_THUMBNAIL 35 # include <cr_pixeldata.h> 36 #endif 37 34 38 35 39 #include "renderspu.h" … … 326 330 327 331 /** This is necessary for clipping on the root window */ 328 NSPoint m_RootShift; 332 NSRect m_RootRect; 333 float m_yInvRootOffset; 329 334 330 335 CR_BLITTER *m_pBlitter; … … 756 761 m_Pos = NSZeroPoint; 757 762 m_Size = NSMakeSize(1, 1); 758 m_RootShift = NSZeroPoint; 763 m_RootRect = NSMakeRect(0, 0, m_Size.width, m_Size.height); 764 m_yInvRootOffset = 0; 759 765 m_pBlitter = nil; 760 766 m_pWinInfo = pWinInfo; … … 916 922 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self)); 917 923 918 { 919 /* Update the viewport for our OpenGL view */ 920 [m_pSharedGLCtx update]; 921 922 [self vboxBlitterSyncWindow]; 924 /* Update the viewport for our OpenGL view */ 925 [m_pSharedGLCtx update]; 926 927 [self vboxBlitterSyncWindow]; 923 928 924 /* Clear background to transparent */ 925 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 926 } 927 } 929 /* Clear background to transparent */ 930 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);} 928 931 929 932 - (void)reshapeLocked … … 956 959 newFrame = NSIntersectionRect(parentFrame, childFrame); 957 960 961 DEBUG_MSG(("[%#p]: parentFrame pos[%f : %f] size[%f : %f]\n", 962 (void*)self, 963 parentFrame.origin.x, parentFrame.origin.y, 964 parentFrame.size.width, parentFrame.size.height)); 965 DEBUG_MSG(("[%#p]: childFrame pos[%f : %f] size[%f : %f]\n", 966 (void*)self, 967 childFrame.origin.x, childFrame.origin.y, 968 childFrame.size.width, childFrame.size.height)); 969 970 DEBUG_MSG(("[%#p]: newFrame pos[%f : %f] size[%f : %f]\n", 971 (void*)self, 972 newFrame.origin.x, newFrame.origin.y, 973 newFrame.size.width, newFrame.size.height)); 974 958 975 /* Later we have to correct the texture position in the case the window is 959 * out of the parents window frame. So save the shift values for later use. */ 960 if (parentFrame.origin.x > childFrame.origin.x) 961 m_RootShift.x = parentFrame.origin.x - childFrame.origin.x; 962 else 963 m_RootShift.x = 0; 964 if (parentFrame.origin.y > childFrame.origin.y) 965 m_RootShift.y = parentFrame.origin.y - childFrame.origin.y; 966 else 967 m_RootShift.y = 0; 968 976 * out of the parents window frame. So save the shift values for later use. */ 977 m_RootRect.origin.x = newFrame.origin.x - childFrame.origin.x; 978 m_RootRect.origin.y = childFrame.size.height + childFrame.origin.y - (newFrame.size.height + newFrame.origin.y); 979 m_RootRect.size = newFrame.size; 980 m_yInvRootOffset = newFrame.origin.y - childFrame.origin.y; 981 982 DEBUG_MSG(("[%#p]: m_RootRect pos[%f : %f] size[%f : %f]\n", 983 (void*)self, 984 m_RootRect.origin.x, m_RootRect.origin.y, 985 m_RootRect.size.width, m_RootRect.size.height)); 986 987 969 988 /* 970 989 NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView]; … … 1271 1290 /* Render FBO content to the dock tile when necessary. */ 1272 1291 [self vboxPresentToDockTileCS:pCompositor]; 1273 1292 /* change to #if 0 to see thumbnail image */ 1293 #if 1 1274 1294 [self vboxPresentToViewCS:pCompositor]; 1295 #else 1296 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1297 [m_pSharedGLCtx flushBuffer]; 1298 #endif 1299 1275 1300 } 1276 1301 } 1277 1302 1303 DECLINLINE(void) vboxNSRectToRect(const NSRect *pR, RTRECT *pRect) 1304 { 1305 pRect->xLeft = (int)pR->origin.x; 1306 pRect->yTop = (int)pR->origin.y; 1307 pRect->xRight = (int)(pR->origin.x + pR->size.width); 1308 pRect->yBottom = (int)(pR->origin.y + pR->size.height); 1309 } 1310 1311 DECLINLINE(void) vboxNSRectToRectUnstretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch) 1312 { 1313 pRect->xLeft = (int)(pR->origin.x / xStretch); 1314 pRect->yTop = (int)(pR->origin.y / yStretch); 1315 pRect->xRight = (int)((pR->origin.x + pR->size.width) / xStretch); 1316 pRect->yBottom = (int)((pR->origin.y + pR->size.height) / yStretch); 1317 } 1318 1319 DECLINLINE(void) vboxNSRectToRectStretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch) 1320 { 1321 pRect->xLeft = (int)(pR->origin.x * xStretch); 1322 pRect->yTop = (int)(pR->origin.y * yStretch); 1323 pRect->xRight = (int)((pR->origin.x + pR->size.width) * xStretch); 1324 pRect->yBottom = (int)((pR->origin.y + pR->size.height) * yStretch); 1325 } 1326 1278 1327 - (void)vboxPresentToViewCS:(PVBOXVR_SCR_COMPOSITOR)pCompositor 1279 1328 { 1280 1329 NSRect r = [self frame]; 1330 float xStretch, yStretch; 1281 1331 DEBUG_MSG(("OVIW(%p): rF2V frame: [%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height)); 1282 1332 … … 1292 1342 /* Clear background to transparent */ 1293 1343 glClear(GL_COLOR_BUFFER_BIT); 1344 1345 CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch); 1294 1346 1295 1347 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) … … 1309 1361 const RTRECT * pSrcRect = &paSrcRegions[i]; 1310 1362 const RTRECT * pDstRect = &paDstRegions[i]; 1311 RTRECT SrcRect, DstRect; 1312 if (m_RootShift.x) 1313 { 1314 DstRect.xLeft = pDstRect->xLeft - m_RootShift.x; 1315 DstRect.yTop = pDstRect->yTop; 1316 DstRect.xRight = pDstRect->xRight - m_RootShift.x; 1317 DstRect.yBottom = pDstRect->yBottom; 1318 pDstRect = &DstRect; 1319 } 1363 RTRECT SrcRect, DstRect, RestrictSrcRect, RestrictDstRect; 1320 1364 1321 if (m_RootShift.y) 1322 { 1323 SrcRect.xLeft = pSrcRect->xLeft; 1324 SrcRect.yTop = pSrcRect->yTop - m_RootShift.y; 1325 SrcRect.xRight = pSrcRect->xRight; 1326 SrcRect.yBottom = pSrcRect->yBottom - m_RootShift.y; 1327 pSrcRect = &SrcRect; 1328 } 1365 vboxNSRectToRect(&m_RootRect, &RestrictDstRect); 1366 VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect); 1367 1368 if (VBoxRectIsZero(&DstRect)) 1369 continue; 1370 1371 VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop); 1372 1373 vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch); 1374 VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect); 1375 1376 if (VBoxRectIsZero(&SrcRect)) 1377 continue; 1378 1379 pSrcRect = &SrcRect; 1380 pDstRect = &DstRect; 1329 1381 1330 1382 CrBltBlitTexMural(m_pBlitter, true, &pEntry->Tex, pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA); … … 1370 1422 WinInfo.height = r.size.height; 1371 1423 1424 Assert(WinInfo.width = m_RootRect.size.width); 1425 Assert(WinInfo.height = m_RootRect.size.height); 1426 1427 CrBltMuralSetCurrent(m_pBlitter, NULL); 1428 1372 1429 CrBltMuralSetCurrent(m_pBlitter, &WinInfo); 1373 1430 CrBltCheckUpdateViewport(m_pBlitter); 1374 1431 } 1375 1432 1433 #ifdef VBOX_WITH_CRDUMPER_THUMBNAIL 1434 static int g_cVBoxTgaCtr = 0; 1435 #endif 1376 1436 - (void)vboxPresentToDockTileCS:(PVBOXVR_SCR_COMPOSITOR)pCompositor 1377 1437 { … … 1380 1440 GLint i = 0; 1381 1441 NSDockTile *pDT = nil; 1442 float xStretch, yStretch; 1382 1443 1383 1444 if ([m_DockTileView thumbBitmap] != nil) … … 1416 1477 rr = [m_DockTileView frame]; 1417 1478 1479 CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch); 1480 1418 1481 CrVrScrCompositorIterInit(pCompositor, &CIter); 1419 1482 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) … … 1433 1496 const RTRECT * pSrcRect = &paSrcRegions[i]; 1434 1497 const RTRECT * pDstRect = &paDstRegions[i]; 1435 RTRECT SrcRect, DstRect; 1436 /*if (m_RootShift.x)*/ 1437 { 1438 DstRect.xLeft = pDstRect->xLeft * m_FBOThumbScaleX; 1439 DstRect.yTop = (r.size.height - pDstRect->yTop) * m_FBOThumbScaleY; 1440 DstRect.xRight = pDstRect->xRight * m_FBOThumbScaleX; 1441 DstRect.yBottom = (r.size.height - pDstRect->yBottom) * m_FBOThumbScaleY; 1442 pDstRect = &DstRect; 1443 } 1498 RTRECT SrcRect, DstRect, RestrictSrcRect, RestrictDstRect; 1444 1499 1445 if (m_RootShift.y) 1446 { 1447 SrcRect.xLeft = pSrcRect->xLeft; 1448 SrcRect.yTop = pSrcRect->yTop - m_RootShift.y; 1449 SrcRect.xRight = pSrcRect->xRight; 1450 SrcRect.yBottom = pSrcRect->yBottom - m_RootShift.y; 1451 pSrcRect = &SrcRect; 1452 } 1500 vboxNSRectToRect(&m_RootRect, &RestrictDstRect); 1501 VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect); 1502 1503 VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop); 1504 1505 VBoxRectStretch(&DstRect, m_FBOThumbScaleX, m_FBOThumbScaleY); 1453 1506 1454 CrBltBlitTexMural(m_pBlitter, true, &pEntry->Tex, pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA); 1507 if (VBoxRectIsZero(&DstRect)) 1508 continue; 1509 1510 vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch); 1511 VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect); 1512 1513 if (VBoxRectIsZero(&SrcRect)) 1514 continue; 1515 1516 pSrcRect = &SrcRect; 1517 pDstRect = &DstRect; 1518 1519 CrBltBlitTexMural(m_pBlitter, true, &pEntry->Tex, pSrcRect, pDstRect, 1, fFlags); 1455 1520 } 1456 1521 CrBltLeave(m_pBlitter); … … 1476 1541 * is updated currently. */ 1477 1542 [m_DockTileView lock]; 1478 glReadPixels(0, 0, rr.size.width, rr.size.height,1543 glReadPixels(0, m_RootRect.size.height - rr.size.height, rr.size.width, rr.size.height, 1479 1544 GL_BGRA, 1480 1545 GL_UNSIGNED_INT_8_8_8_8, 1481 1546 [[m_DockTileView thumbBitmap] bitmapData]); 1482 1547 [m_DockTileView unlock]; 1548 1549 #ifdef VBOX_WITH_CRDUMPER_THUMBNAIL 1550 ++g_cVBoxTgaCtr; 1551 crDumpNamedTGAF((GLint)rr.size.width, (GLint)rr.size.height, 1552 [[m_DockTileView thumbBitmap] bitmapData], "/Users/leo/vboxdumps/dump%d.tga", g_cVBoxTgaCtr); 1553 #endif 1483 1554 1484 1555 pDT = [[NSApplication sharedApplication] dockTile]; … … 1550 1621 { 1551 1622 NSRect dockFrame = [pView frame]; 1623 /* todo: this is not correct, we should use framebuffer size here, while parent view frame size may differ in case of scrolling */ 1552 1624 NSRect parentFrame = [m_pParentView frame]; 1553 1625 1554 1626 m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width; 1555 1627 m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height; 1556 newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_ RootShift.y) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY));1628 newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_yInvRootOffset) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY)); 1557 1629 /* 1558 1630 NSRect newFrame = NSMakeRect ((int)roundf(m_Pos.x * m_FBOThumbScaleX), (int)roundf(dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (int)roundf(m_Size.width * m_FBOThumbScaleX), (int)roundf(m_Size.height * m_FBOThumbScaleY));
Note:
See TracChangeset
for help on using the changeset viewer.