Changeset 45526 in vbox for trunk/src/VBox/HostServices/SharedOpenGL/render
- Timestamp:
- Apr 12, 2013 4:48:28 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r45148 r45526 26 26 #include <iprt/mem.h> 27 27 #include <iprt/time.h> 28 #include <iprt/assert.h> 28 29 29 30 #include <cr_vreg.h> 31 #include <cr_error.h> 32 #include <cr_blitter.h> 30 33 31 34 #include "renderspu.h" … … 87 90 # define DEBUG_MSG(text) \ 88 91 printf text 92 # define DEBUG_WARN(text) do { \ 93 crWarning text ; \ 94 Assert(0); \ 95 } while (0) 89 96 #else 90 97 # define DEBUG_MSG(text) \ 91 98 do {} while (0) 99 # define DEBUG_WARN(text) do { \ 100 crWarning text ; \ 101 } while (0) 92 102 #endif 93 103 … … 314 324 NSPoint m_RootShift; 315 325 326 CR_BLITTER *m_pBlitter; 316 327 WindowInfo *m_pWinInfo; 317 328 bool m_fNeedViewportUpdate; … … 347 358 - (void)vboxPresentToViewCS:(PVBOXVR_SCR_COMPOSITOR)pCompositor; 348 359 - (void)presentComposition:(PVBOXVR_SCR_COMPOSITOR_ENTRY)pChangedEntry; 360 - (void)vboxBlitterSyncWindow; 349 361 350 362 - (void)clearVisibleRegions; … … 741 753 m_Size = NSMakeSize(1, 1); 742 754 m_RootShift = NSZeroPoint; 755 m_pBlitter = nil; 743 756 m_pWinInfo = pWinInfo; 744 757 m_fNeedViewportUpdate = true; … … 771 784 772 785 m_pSharedGLCtx = nil; 786 787 CrBltTerm(m_pBlitter); 788 789 m_pBlitter = nil; 773 790 } 774 791 … … 893 910 - (void)updateViewportCS 894 911 { 895 NSRect r;896 897 912 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self)); 898 913 … … 901 916 [m_pSharedGLCtx update]; 902 917 903 r = [self frame]; 904 /* Setup all matrices */ 905 glMatrixMode(GL_PROJECTION); 906 glLoadIdentity(); 907 glViewport(0, 0, r.size.width, r.size.height); 908 glOrtho(0, r.size.width, 0, r.size.height, -1, 1); 909 DEBUG_MSG_1(("OVIW(%p): frame[%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.x, (int)r.size.width, (int)r.size.height)); 910 DEBUG_MSG_1(("OVIW(%p): m_Pos(%i,%i) m_Size(%i,%i)\n", (void*)self, (int)m_Pos.x, (int)m_Pos.y, (int)m_Size.width, (int)m_Size.height)); 911 DEBUG_MSG_1(("OVIW(%p): m_RootShift(%i, %i)\n", (void*)self, (int)m_RootShift.x, (int)m_RootShift.y)); 912 glMatrixMode(GL_TEXTURE); 913 glLoadIdentity(); 914 glMatrixMode(GL_MODELVIEW); 915 glLoadIdentity(); 916 918 [self vboxBlitterSyncWindow]; 919 917 920 /* Clear background to transparent */ 918 921 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); … … 1076 1079 if (pCompositor) 1077 1080 { 1078 /* Create a shared context out of the main context. Use the same pixel format. */ 1079 m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx]; 1080 1081 /* Set the new context as non opaque */ 1082 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1083 /* Set this view as the drawable for the new context */ 1084 [m_pSharedGLCtx setView: self]; 1085 m_fNeedViewportUpdate = true; 1081 Assert(!m_pBlitter); 1082 m_pBlitter = RTMemAlloc(sizeof (*m_pBlitter)); 1083 if (m_pBlitter) 1084 { 1085 int rc = CrBltInit(m_pBlitter, NULL, false, false, render_spu.blitterDispatch); 1086 if (RT_SUCCESS(rc)) 1087 { 1088 DEBUG_MSG(("blitter created successfully for view 0x%p\n", (void*)self)); 1089 } 1090 else 1091 { 1092 DEBUG_WARN(("CrBltInit failed, rc %d", rc)); 1093 RTMemFree(m_pBlitter); 1094 m_pBlitter = NULL; 1095 } 1096 } 1097 else 1098 { 1099 DEBUG_WARN(("m_pBlitter allocation failed")); 1100 } 1101 1102 if (m_pBlitter) 1103 { 1104 /* Create a shared context out of the main context. Use the same pixel format. */ 1105 m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx]; 1106 1107 /* Set the new context as non opaque */ 1108 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1109 /* Set this view as the drawable for the new context */ 1110 [m_pSharedGLCtx setView: self]; 1111 m_fNeedViewportUpdate = true; 1112 } 1086 1113 #ifdef CR_RENDER_FORCE_PRESENT_MAIN_THREAD 1087 1114 renderspuVBoxCompositorRelease(m_pWinInfo); … … 1230 1257 { 1231 1258 uint32_t i; 1259 int rc = CrBltEnter(m_pBlitter, NULL, NULL); 1260 if (RT_SUCCESS(rc)) 1261 { 1262 for (i = 0; i < cRegions; ++i) 1263 { 1264 const RTRECT * pSrcRect = &paSrcRegions[i]; 1265 const RTRECT * pDstRect = &paDstRegions[i]; 1266 RTRECT SrcRect, DstRect; 1267 if (m_RootShift.x) 1268 { 1269 DstRect.xLeft = pDstRect->xLeft - m_RootShift.x; 1270 DstRect.yTop = pDstRect->yTop; 1271 DstRect.xRight = pDstRect->xRight - m_RootShift.x; 1272 DstRect.yBottom = pDstRect->yBottom; 1273 pDstRect = &DstRect; 1274 } 1232 1275 1233 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1234 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pEntry->Tex.target, pEntry->Tex.hwid, 0); 1235 glReadBuffer(GL_COLOR_ATTACHMENT0); 1276 if (m_RootShift.y) 1277 { 1278 SrcRect.xLeft = pSrcRect->xLeft; 1279 SrcRect.yTop = pSrcRect->yTop - m_RootShift.y; 1280 SrcRect.xRight = pSrcRect->xRight; 1281 SrcRect.yBottom = pSrcRect->yBottom - m_RootShift.y; 1282 pSrcRect = &SrcRect; 1283 } 1236 1284 1237 for (i = 0; i < cRegions; ++i) 1285 CrBltBlitTexMural(m_pBlitter, &pEntry->Tex, pSrcRect, pDstRect, 1, CRBLT_F_LINEAR | CRBLT_F_INVERT_YCOORDS); 1286 } 1287 CrBltLeave(m_pBlitter); 1288 } 1289 else 1238 1290 { 1239 const RTRECT * pSrcRect = &paSrcRegions[i]; 1240 const RTRECT * pDstRect = &paDstRegions[i]; 1241 GLint srcY1 = r.size.height - pSrcRect->yTop; 1242 GLint srcY2 = r.size.height - pSrcRect->yBottom; 1243 GLint dstY1 = r.size.height - pDstRect->yTop; 1244 GLint dstY2 = r.size.height - pDstRect->yBottom; 1245 1246 glBlitFramebufferEXT(pSrcRect->xLeft, srcY1 + m_RootShift.y, 1247 pSrcRect->xRight, srcY2 + m_RootShift.y, 1248 pDstRect->xLeft - m_RootShift.x, dstY1, 1249 pDstRect->xRight - m_RootShift.x, dstY2, 1250 GL_COLOR_BUFFER_BIT, GL_LINEAR); 1291 DEBUG_WARN(("CrBltEnter failed rc %d", rc)); 1251 1292 } 1252 1293 } … … 1268 1309 { 1269 1310 [self vboxTryDraw]; 1311 } 1312 1313 - (void)vboxBlitterSyncWindow 1314 { 1315 CR_BLITTER_WINDOW WinInfo; 1316 NSRect r; 1317 1318 if (!m_pBlitter) 1319 return; 1320 1321 memset(&WinInfo, 0, sizeof (WinInfo)); 1322 1323 r = [self frame]; 1324 WinInfo.width = r.size.width; 1325 WinInfo.height = r.size.height; 1326 1327 CrBltMuralSetCurrent(m_pBlitter, &WinInfo); 1328 CrBltCheckUpdateViewport(m_pBlitter); 1270 1329 } 1271 1330 … … 1321 1380 { 1322 1381 uint32_t i; 1382 int rc = CrBltEnter(m_pBlitter, NULL, NULL); 1383 if (RT_SUCCESS(rc)) 1384 { 1385 for (i = 0; i < cRegions; ++i) 1386 { 1387 const RTRECT * pSrcRect = &paSrcRegions[i]; 1388 const RTRECT * pDstRect = &paDstRegions[i]; 1389 RTRECT SrcRect, DstRect; 1390 /*if (m_RootShift.x)*/ 1391 { 1392 DstRect.xLeft = pDstRect->xLeft * m_FBOThumbScaleX; 1393 DstRect.yTop = (r.size.height - pDstRect->yTop) * m_FBOThumbScaleY; 1394 DstRect.xRight = pDstRect->xRight * m_FBOThumbScaleX; 1395 DstRect.yBottom = (r.size.height - pDstRect->yBottom) * m_FBOThumbScaleY; 1396 pDstRect = &DstRect; 1397 } 1323 1398 1324 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1325 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pEntry->Tex.target, pEntry->Tex.hwid, 0); 1326 glReadBuffer(GL_COLOR_ATTACHMENT0); 1399 if (m_RootShift.y) 1400 { 1401 SrcRect.xLeft = pSrcRect->xLeft; 1402 SrcRect.yTop = pSrcRect->yTop - m_RootShift.y; 1403 SrcRect.xRight = pSrcRect->xRight; 1404 SrcRect.yBottom = pSrcRect->yBottom - m_RootShift.y; 1405 pSrcRect = &SrcRect; 1406 } 1327 1407 1328 for (i = 0; i < cRegions; ++i) 1408 CrBltBlitTexMural(m_pBlitter, &pEntry->Tex, pSrcRect, pDstRect, 1, CRBLT_F_LINEAR | CRBLT_F_INVERT_SRC_YCOORDS); 1409 } 1410 CrBltLeave(m_pBlitter); 1411 } 1412 else 1329 1413 { 1330 const RTRECT * pSrcRect = &paSrcRegions[i]; 1331 const RTRECT * pDstRect = &paDstRegions[i]; 1332 GLint srcY1 = r.size.height - pSrcRect->yTop; 1333 GLint srcY2 = r.size.height - pSrcRect->yBottom; 1334 GLint dstY1 = r.size.height - pDstRect->yTop; 1335 GLint dstY2 = r.size.height - pDstRect->yBottom; 1336 1337 1338 glBlitFramebufferEXT(pSrcRect->xLeft, srcY1 + m_RootShift.y, 1339 pSrcRect->xRight, srcY2 + m_RootShift.y, 1340 pDstRect->xLeft * m_FBOThumbScaleX, dstY1 * m_FBOThumbScaleY, 1341 pDstRect->xRight * m_FBOThumbScaleX, dstY2 * m_FBOThumbScaleY, 1342 GL_COLOR_BUFFER_BIT, GL_LINEAR); 1414 DEBUG_WARN(("CrBltEnter failed rc %d", rc)); 1343 1415 } 1344 1416 }
Note:
See TracChangeset
for help on using the changeset viewer.