Changeset 57504 in vbox for trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
- Timestamp:
- Aug 23, 2015 11:09:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r57503 r57504 2640 2640 pSurface = pState->papSurfaces[sid]; 2641 2641 2642 /** @todo stricter checks for associated context */2643 2642 Log(("vmsvga3dCommandPresent: sid=%x cRects=%d\n", sid, cRects)); 2644 2643 for (uint32_t i=0; i < cRects; i++) … … 2650 2649 VMSVGA3D_CLEAR_GL_ERRORS(); 2651 2650 2651 #if 0 /* Can't make sense of this. SVGA3dCopyRect doesn't allow scaling. non-blit-cube path change to not use it. */ 2652 2652 /* 2653 2653 * Source surface different size? … … 2660 2660 float yMultiplier = (float)pSurface->pMipmapLevels[0].size.height / (float)pThis->svga.uHeight; 2661 2661 2662 LogFlow(("size (%d vs %d) (%d vs %d) multiplier (%d,%d)/100\n", pSurface->pMipmapLevels[0].size.width, pThis->svga.uWidth, 2663 pSurface->pMipmapLevels[0].size.height, pThis->svga.uHeight, (int)(xMultiplier * 100.0), (int)(yMultiplier * 100.0))); 2662 LogFlow(("size (%d vs %d, %d vs %d) multiplier (" FLOAT_FMT_STR ", " FLOAT_FMT_STR ")\n", 2663 pSurface->pMipmapLevels[0].size.width, pThis->svga.uWidth, 2664 pSurface->pMipmapLevels[0].size.height, pThis->svga.uHeight, 2665 FLOAT_FMT_ARGS(xMultiplier), FLOAT_FMT_ARGS(yMultiplier) )); 2664 2666 2665 2667 srcViewPort.x = (uint32_t)((float)pThis->svga.viewport.x * xMultiplier); … … 2680 2682 SrcViewPortRect.yBottom = srcViewPort.y; 2681 2683 SrcViewPortRect.yTop = srcViewPort.y + srcViewPort.cy; 2682 2683 2684 #ifndef RT_OS_DARWIN /* blit-cube fails in this path... */ 2684 #endif 2685 2686 2687 #if 0//ndef RT_OS_DARWIN /* blit-cube fails in this path... */ 2685 2688 /* 2686 2689 * Note! this path is slightly faster than the glBlitFrameBuffer path below. … … 2838 2841 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2839 2842 2843 2844 /* If there are no recangles specified, just grab a viewport worth bits. */ 2845 # if 1 2846 VMSVGAVIEWPORT const DstViewport = pThis->svga.viewport; 2847 # else 2848 VMSVGAVIEWPORT const DstViewport = { 0, 0, pThis->svga.uWidth, pThis->svga.uHeight, pThis->svga.uWidth, pThis->svga.uHeight }; 2849 # endif 2850 SVGA3dCopyRect DummyRect; 2851 if (cRects != 0) 2852 { /* likely */ } 2853 else 2854 { 2855 /** @todo Find the usecase for this or check what the original device does. 2856 * The original code was doing some scaling based on the surface 2857 * size... */ 2858 # ifdef DEBUG_bird 2859 AssertMsgFailed(("No rects to present. Who is doing that and what do they actually expect?\n")); 2860 # endif 2861 cRects = 1; 2862 pRect = &DummyRect; 2863 DummyRect.x = DummyRect.srcx = DstViewport.x; 2864 DummyRect.y = DummyRect.srcy = DstViewport.y; 2865 DummyRect.w = DstViewport.cx; 2866 DummyRect.h = DstViewport.cy; 2867 } 2868 2840 2869 /* Blit the surface rectangle(s) to the back buffer. */ 2841 if (cRects == 0) 2842 2843 { 2844 Log(("view port (%d,%d)(%d,%d)\n", srcViewPort.x, srcViewPort.y, srcViewPort.cx, srcViewPort.cy)); 2845 pState->ext.glBlitFramebuffer(srcViewPort.x, 2846 srcViewPort.y, 2847 srcViewPort.x + srcViewPort.cx, /* exclusive. */ 2848 srcViewPort.y + srcViewPort.cy, /* exclusive. (reverse to flip the image) */ 2849 0, 2850 pThis->svga.viewport.cy, /* exclusive. */ 2851 pThis->svga.viewport.cx, /* exclusive. */ 2852 0, 2853 GL_COLOR_BUFFER_BIT, 2854 GL_LINEAR); 2855 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 2856 } 2857 else 2858 { 2859 for (uint32_t i = 0; i < cRects; i++) 2860 { 2861 # ifdef RT_OS_DARWIN 2862 /* This works better... */ 2863 RTRECT SrcRect; 2864 SrcRect.xLeft = pRect[i].srcx; 2865 SrcRect.xRight = pRect[i].srcx + pRect[i].w; 2866 SrcRect.yBottom = pRect[i].srcy; 2867 SrcRect.yTop = pRect[i].srcy + pRect[i].h; 2868 RTRECT DstRect; /* y flipped wrt source */ 2869 DstRect.xLeft = pRect[i].x; 2870 DstRect.xRight = pRect[i].x + pRect[i].w; 2871 DstRect.yBottom = pRect[i].y + pRect[i].h; 2872 DstRect.yTop = pRect[i].y; 2873 2874 if (SrcRect.xLeft < SrcViewPortRect.xLeft) 2870 uint32_t const cxSurface = pSurface->pMipmapLevels[0].size.width; 2871 uint32_t const cySurface = pSurface->pMipmapLevels[0].size.height; 2872 for (uint32_t i = 0; i < cRects; i++) 2873 { 2874 SVGA3dCopyRect ClippedRect = pRect[i]; 2875 2876 /* Do some sanity checking and limit width and height, all so we 2877 don't need to think about wrap-arounds below. */ 2878 if (RT_LIKELY( ClippedRect.w 2879 && ClippedRect.x < VMSVGA_MAX_X 2880 && ClippedRect.srcx < VMSVGA_MAX_X 2881 && ClippedRect.h 2882 && ClippedRect.y < VMSVGA_MAX_Y 2883 && ClippedRect.srcy < VMSVGA_MAX_Y 2884 )) 2885 { /* likely */ } 2886 else 2887 continue; 2888 2889 if (RT_LIKELY(ClippedRect.w < VMSVGA_MAX_Y)) 2890 { /* likely */ } 2891 else 2892 ClippedRect.w = VMSVGA_MAX_Y; 2893 if (RT_LIKELY(ClippedRect.w < VMSVGA_MAX_Y)) 2894 { /* likely */ } 2895 else 2896 ClippedRect.w = VMSVGA_MAX_Y; 2897 2898 2899 /* Source surface clipping (paranoia). */ 2900 if (RT_LIKELY(ClippedRect.srcx < cxSurface)) 2901 { /* likely */ } 2902 else 2903 continue; 2904 if (RT_LIKELY(ClippedRect.srcx + ClippedRect.w <= cxSurface)) 2905 { /* likely */ } 2906 else 2907 { 2908 AssertFailed(); /* remove if annoying. */ 2909 ClippedRect.w = cxSurface - ClippedRect.srcx; 2910 } 2911 2912 if (RT_LIKELY(ClippedRect.srcy < cySurface)) 2913 { /* likely */ } 2914 else 2915 continue; 2916 if (RT_LIKELY(ClippedRect.srcy + ClippedRect.h <= cySurface)) 2917 { /* likely */ } 2918 else 2919 { 2920 AssertFailed(); /* remove if annoying. */ 2921 ClippedRect.h = cySurface - ClippedRect.srcy; 2922 } 2923 2924 2925 /* Destination viewport clipping. */ 2926 if (ClippedRect.x >= DstViewport.x) 2927 { 2928 if (ClippedRect.x + ClippedRect.w <= DstViewport.xRight) 2929 { /* typical */ } 2930 else if (ClippedRect.x < DstViewport.xRight) 2931 ClippedRect.w = DstViewport.xRight - ClippedRect.x; 2932 else 2933 continue; 2934 } 2935 else 2936 { 2937 uint32_t cxAdjust = DstViewport.x - ClippedRect.x; 2938 if (cxAdjust < ClippedRect.w) 2875 2939 { 2876 DstRect.xLeft += SrcViewPortRect.xLeft - SrcRect.xLeft; 2877 SrcRect.xLeft = SrcViewPortRect.xLeft; 2940 ClippedRect.w -= cxAdjust; 2941 ClippedRect.x += cxAdjust; 2942 ClippedRect.srcx += cxAdjust; 2878 2943 } 2879 else if (SrcRect.xLeft >= SrcViewPortRect.xRight)2944 else 2880 2945 continue; 2881 2946 2882 if (SrcRect.xRight > SrcViewPortRect.xRight) 2947 if (ClippedRect.x + ClippedRect.w <= DstViewport.xRight) 2948 { /* typical */ } 2949 else 2950 ClippedRect.w = DstViewport.xRight - ClippedRect.x; 2951 } 2952 2953 if (ClippedRect.y >= DstViewport.y) 2954 { 2955 if (ClippedRect.y + ClippedRect.h <= DstViewport.yBottom) 2956 { /* typical */ } 2957 else if (ClippedRect.y < DstViewport.yBottom) 2958 ClippedRect.h = DstViewport.yBottom - ClippedRect.y; 2959 else 2960 continue; 2961 } 2962 else 2963 { 2964 uint32_t cyAdjust = DstViewport.y - ClippedRect.y; 2965 if (cyAdjust < ClippedRect.h) 2883 2966 { 2884 DstRect.xRight -= SrcViewPortRect.xRight - SrcRect.xRight; 2885 SrcRect.xRight = SrcViewPortRect.xRight; 2967 ClippedRect.h -= cyAdjust; 2968 ClippedRect.y += cyAdjust; 2969 ClippedRect.srcy += cyAdjust; 2886 2970 } 2887 else if (SrcRect.xRight <= SrcViewPortRect.xLeft)2971 else 2888 2972 continue; 2889 2973 2890 if (SrcRect.xRight <= SrcRect.xLeft) 2891 continue; 2892 2893 if (SrcRect.yBottom < SrcViewPortRect.yBottom) 2894 { 2895 DstRect.yTop += SrcViewPortRect.yBottom - SrcRect.yBottom; 2896 SrcRect.yBottom = SrcViewPortRect.yBottom; 2897 } 2898 else if (SrcRect.yBottom >= SrcViewPortRect.yTop) 2899 continue; 2900 2901 if (SrcRect.yTop > SrcViewPortRect.yTop) 2902 { 2903 DstRect.yBottom -= SrcViewPortRect.yTop - SrcRect.yTop; 2904 SrcRect.yTop = SrcViewPortRect.yTop; 2905 } 2906 else if (SrcRect.yTop <= SrcViewPortRect.yBottom) 2907 continue; 2908 2909 if (SrcRect.yTop <= SrcRect.yBottom) 2910 continue; 2911 2912 Log(("SrcRect: (%d,%d)(%d,%d) DstRect: (%d,%d)(%d,%d)\n", 2913 SrcRect.xLeft, SrcRect.yBottom, SrcRect.xRight, SrcRect.yTop, 2914 DstRect.xLeft, DstRect.yBottom, DstRect.xRight, DstRect.yTop)); 2915 pState->ext.glBlitFramebuffer(SrcRect.xLeft, SrcRect.yBottom, SrcRect.xRight, SrcRect.yTop, 2916 DstRect.xLeft, DstRect.yBottom, DstRect.xRight, DstRect.yTop, 2917 GL_COLOR_BUFFER_BIT, GL_LINEAR); 2918 2919 # else 2920 if ( pRect[i].x + pRect[i].w <= pThis->svga.viewport.x 2921 || pThis->svga.viewport.x + pThis->svga.viewport.cx <= pRect[i].x 2922 || pRect[i].y + pRect[i].h <= pThis->svga.viewport.y 2923 || pThis->svga.viewport.y + pThis->svga.viewport.cy <= pRect[i].y) 2924 { 2925 /* Intersection is empty; skip */ 2926 continue; 2927 } 2928 pState->ext.glBlitFramebuffer(RT_MAX(pRect[i].srcx, srcViewPort.x), 2929 pSurface->pMipmapLevels[0].size.width - RT_MAX(pRect[i].srcy, srcViewPort.y), /* exclusive. (reverse to flip the image) */ 2930 RT_MIN(pRect[i].srcx + pRect[i].w, srcViewPort.x + srcViewPort.cx), /* exclusive. */ 2931 pSurface->pMipmapLevels[0].size.width - RT_MIN(pRect[i].srcy + pRect[i].h, srcViewPort.y + srcViewPort.cy), 2932 RT_MAX(pRect[i].x, pThis->svga.viewport.x) - pThis->svga.viewport.x, 2933 pThis->svga.uHeight - (RT_MIN(pRect[i].y + pRect[i].h, pThis->svga.viewport.y + pThis->svga.viewport.cy) - pThis->svga.viewport.y), /* exclusive. */ 2934 RT_MIN(pRect[i].x + pRect[i].w, pThis->svga.viewport.x + pThis->svga.viewport.cx) - pThis->svga.viewport.x, /* exclusive. */ 2935 pThis->svga.uHeight - (RT_MAX(pRect[i].y, pThis->svga.viewport.y) - pThis->svga.viewport.y), 2936 GL_COLOR_BUFFER_BIT, 2937 GL_LINEAR); 2938 # endif 2939 } 2940 } 2941 2942 #endif 2943 #ifndef RT_OS_DARWIN /* darwin: postponed till after buffer swap. */ 2944 /* Reset the frame buffer association - see below. */ 2945 VMSVGA3D_ASSERT_GL_CALL(pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer), pState, pContext); 2974 if (ClippedRect.y + ClippedRect.h <= DstViewport.yBottom) 2975 { /* typical */ } 2976 else 2977 ClippedRect.h = DstViewport.yBottom - ClippedRect.y; 2978 } 2979 2980 2981 /* Do the blitting. */ 2982 RTRECT SrcRect; 2983 SrcRect.xLeft = ClippedRect.srcx; 2984 SrcRect.xRight = ClippedRect.srcx + ClippedRect.w; 2985 SrcRect.yBottom = ClippedRect.srcy; 2986 SrcRect.yTop = ClippedRect.srcy + ClippedRect.h; 2987 RTRECT DstRect; /* y flipped wrt source */ 2988 DstRect.xLeft = ClippedRect.x; 2989 DstRect.xRight = ClippedRect.x + ClippedRect.w; 2990 DstRect.yBottom = ClippedRect.y + ClippedRect.h; 2991 DstRect.yTop = ClippedRect.y; 2992 2993 Log(("SrcRect: (%d,%d)(%d,%d) DstRect: (%d,%d)(%d,%d)\n", 2994 SrcRect.xLeft, SrcRect.yBottom, SrcRect.xRight, SrcRect.yTop, 2995 DstRect.xLeft, DstRect.yBottom, DstRect.xRight, DstRect.yTop)); 2996 pState->ext.glBlitFramebuffer(SrcRect.xLeft, SrcRect.yBottom, SrcRect.xRight, SrcRect.yTop, 2997 DstRect.xLeft - DstViewport.x, 2998 DstRect.yBottom - DstViewport.y, 2999 DstRect.xRight - DstViewport.x, 3000 DstRect.yTop - DstViewport.y, 3001 GL_COLOR_BUFFER_BIT, GL_LINEAR); 3002 } 3003 2946 3004 #endif 2947 3005 … … 2965 3023 #endif 2966 3024 2967 #if defined(RT_OS_DARWIN)2968 3025 /* 2969 3026 * Now we can reset the frame buffer association. Doing it earlier means no … … 2971 3028 */ 2972 3029 VMSVGA3D_ASSERT_GL_CALL(pState->ext.glBindFramebuffer(GL_FRAMEBUFFER, pContext->idFramebuffer), pState, pContext); 2973 #endif2974 3030 return VINF_SUCCESS; 2975 3031 }
Note:
See TracChangeset
for help on using the changeset viewer.