VirtualBox

Changeset 50371 in vbox for trunk


Ignore:
Timestamp:
Feb 7, 2014 9:59:02 PM (11 years ago)
Author:
vboxsync
Message:

crOpenGL: screenshot bugfixes, some more to follow

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_vreg.h

    r50316 r50371  
    4949
    5050#ifndef IN_RING0
     51#define CR_FLOAT_RCAST(_t, _v) ((_t)((float)(_v) + 0.5))
     52
    5153DECLINLINE(void) VBoxRectStretch(PRTRECT pRect, float xStretch, float yStretch)
    5254{
    53     pRect->xLeft = (int32_t)(pRect->xLeft * xStretch);
    54     pRect->yTop = (int32_t)(pRect->yTop * yStretch);
    55     pRect->xRight = (int32_t)(pRect->xRight * xStretch);
    56     pRect->yBottom = (int32_t)(pRect->yBottom * yStretch);
     55    pRect->xLeft = CR_FLOAT_RCAST(int32_t, pRect->xLeft * xStretch);
     56    pRect->yTop = CR_FLOAT_RCAST(int32_t, pRect->yTop * yStretch);
     57    pRect->xRight = CR_FLOAT_RCAST(int32_t, pRect->xRight * xStretch);
     58    pRect->yBottom = CR_FLOAT_RCAST(int32_t, pRect->yBottom * yStretch);
    5759}
    5860
  • trunk/src/VBox/GuestHost/OpenGL/util/bmpscale.cpp

    r50365 r50371  
    6161}
    6262
    63 DECLINLINE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color, int w)
     63DECLINLINE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color, int cbLine)
    6464{
    65     *(int32_t *)(im + y * w * 4 + x * 4) = color;
     65    *(int32_t *)(im + y * cbLine + x * 4) = color;
    6666}
    6767
     
    190190               gdTrueColorAlpha ((int) red,
    191191                         (int) green,
    192                          (int) blue, (int) alpha), dstW);
     192                         (int) blue, (int) alpha), dstW * 4);
    193193    }
    194194    }
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp

    r50364 r50371  
    241241}
    242242
    243 static void crFbBltImg(void *pvSrc, const RTRECT *pSrcDataRect, bool fSrcInvert, const RTRECT *pCopyRect, const RTPOINT *pDstDataPoint, CR_BLITTER_IMG *pDst)
    244 {
    245     int32_t cbSrcPitch = (pSrcDataRect->xRight - pSrcDataRect->xLeft) * 4;
    246     int32_t srcX = pCopyRect->xLeft - pSrcDataRect->xLeft;
    247     int32_t srcY = pCopyRect->yTop - pSrcDataRect->yTop;
     243static void crFbBltImg(const CR_BLITTER_IMG *pSrc, const RTPOINT *pSrcDataPoint, bool fSrcInvert, const RTRECT *pCopyRect, const RTPOINT *pDstDataPoint, CR_BLITTER_IMG *pDst)
     244{
     245    int32_t srcX = pCopyRect->xLeft - pSrcDataPoint->x;
     246    int32_t srcY = pCopyRect->yTop - pSrcDataPoint->y;
    248247    Assert(srcX >= 0);
    249248    Assert(srcY >= 0);
    250     Assert(srcX < pSrcDataRect->xRight - pSrcDataRect->xLeft);
    251     Assert(srcY < pSrcDataRect->yBottom - pSrcDataRect->yTop);
    252 
    253     uint32_t cbDstPitch = pDst->pitch;
     249    Assert(srcX < pSrc->width);
     250    Assert(srcY < pSrc->height);
     251
    254252    int32_t dstX = pCopyRect->xLeft - pDstDataPoint->x;
    255253    int32_t dstY = pCopyRect->yTop - pDstDataPoint->y;
     
    257255    Assert(dstY >= 0);
    258256
    259     uint8_t *pu8Src = ((uint8_t*)pvSrc) + cbSrcPitch * (!fSrcInvert ? srcY : pSrcDataRect->yBottom - pSrcDataRect->yTop - srcY - 1) + srcX * 4;
    260     uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + cbDstPitch * dstY + dstX * 4;
    261     if (fSrcInvert)
    262         cbSrcPitch = -cbSrcPitch;
    263 
    264     crFbBltMem(pu8Src, cbSrcPitch, pu8Dst, cbDstPitch, pCopyRect->xRight - pCopyRect->xLeft, pCopyRect->yBottom - pCopyRect->yTop);
    265 }
    266 
    267 static void crFbBltImgStretched(void *pvSrc, const RTRECT *pSrcDataRect, bool fSrcInvert, const RTRECT *pCopyRect, const RTPOINT *pDstDataPoint, float strX, float strY, CR_BLITTER_IMG *pDst)
    268 {
    269     int32_t cbSrcPitch = (pSrcDataRect->xRight - pSrcDataRect->xLeft) * 4;
    270     int32_t srcX = pCopyRect->xLeft - pSrcDataRect->xLeft;
    271     int32_t srcY = pCopyRect->yTop - pSrcDataRect->yTop;
     257    uint8_t *pu8Src = ((uint8_t*)pSrc->pvData) + pSrc->pitch * (!fSrcInvert ? srcY : pSrc->height - srcY - 1) + srcX * 4;
     258    uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + pDst->pitch * dstY + dstX * 4;
     259
     260    crFbBltMem(pu8Src, fSrcInvert ? -pSrc->pitch : pSrc->pitch, pu8Dst, pDst->pitch, pCopyRect->xRight - pCopyRect->xLeft, pCopyRect->yBottom - pCopyRect->yTop);
     261}
     262
     263static void crFbBltImgStretched(const CR_BLITTER_IMG *pSrc, const RTPOINT *pSrcDataPoint, bool fSrcInvert, const RTRECT *pCopyRect, const RTPOINT *pDstDataPoint, float strX, float strY, CR_BLITTER_IMG *pDst)
     264{
     265    int32_t srcX = pCopyRect->xLeft - pSrcDataPoint->x;
     266    int32_t srcY = pCopyRect->yTop - pSrcDataPoint->y;
    272267    Assert(srcX >= 0);
    273268    Assert(srcY >= 0);
    274     Assert(srcX < pSrcDataRect->xRight - pSrcDataRect->xLeft);
    275     Assert(srcY < pSrcDataRect->yBottom - pSrcDataRect->yTop);
    276 
    277     int32_t cbDstPitch = (int32_t)pDst->pitch;
    278     int32_t dstX = static_cast<uint32_t>(strX * pCopyRect->xLeft - pDstDataPoint->x);
    279     int32_t dstY = static_cast<uint32_t>(strY * pCopyRect->yTop - pDstDataPoint->y);
     269    Assert(srcX < pSrc->width);
     270    Assert(srcY < pSrc->height);
     271
     272    int32_t dstX = CR_FLOAT_RCAST(int32_t, strX * (pCopyRect->xLeft - pDstDataPoint->x));
     273    int32_t dstY = CR_FLOAT_RCAST(int32_t, strY * (pCopyRect->yTop - pDstDataPoint->y));
    280274    Assert(dstX >= 0);
    281275    Assert(dstY >= 0);
    282276
    283     uint8_t *pu8Src = ((uint8_t*)pvSrc) + cbSrcPitch * (!fSrcInvert ? srcY : pSrcDataRect->yBottom - pSrcDataRect->yTop - srcY - 1) + srcX * 4;
    284     uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + cbDstPitch * dstY + dstX * 4;
    285     if (fSrcInvert)
    286         cbSrcPitch = -cbSrcPitch;
    287 
    288     int srcW = pCopyRect->xRight - pCopyRect->xLeft;
    289     int srcH = pCopyRect->yBottom - pCopyRect->yTop;
    290     int dstW = static_cast<uint32_t>(strX * srcW);
    291     int dstH = static_cast<uint32_t>(strY * srcH);
    292 
    293     CrBmpScale32(pu8Dst, cbDstPitch,
    294                             dstW, dstH,
    295                             pu8Src,
    296                             cbSrcPitch,
    297                             srcW, srcH);
    298 }
    299 
     277    uint8_t *pu8Src = ((uint8_t*)pSrc->pvData) + pSrc->pitch * (!fSrcInvert ? srcY : pSrc->height - srcY - 1) + srcX * 4;
     278    uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + pDst->pitch * dstY + dstX * 4;
     279
     280    CrBmpScale32(pu8Dst, pDst->pitch,
     281                        CR_FLOAT_RCAST(int32_t, strX * pCopyRect->xRight - pCopyRect->xLeft),
     282                        CR_FLOAT_RCAST(int32_t, strY * pCopyRect->yBottom - pCopyRect->yTop),
     283                        pu8Src,
     284                        fSrcInvert ? -pSrc->pitch : pSrc->pitch,
     285                        pCopyRect->xRight - pCopyRect->xLeft, pCopyRect->yBottom - pCopyRect->yTop);
     286}
     287
     288static void crFbImgFromScreenVram(const VBVAINFOSCREEN *pScreen, void *pvVram, CR_BLITTER_IMG *pImg)
     289{
     290    pImg->pvData = pvVram;
     291    pImg->cbData = pScreen->u32LineSize * pScreen->u32Height;
     292    pImg->enmFormat = GL_BGRA;
     293    pImg->width = pScreen->u32Width;
     294    pImg->height = pScreen->u32Height;
     295    pImg->bpp = pScreen->u16BitsPerPixel;
     296    pImg->pitch = pScreen->u32LineSize;
     297}
     298
     299static void crFbImgFromFb(HCR_FRAMEBUFFER hFb, CR_BLITTER_IMG *pImg)
     300{
     301    const VBVAINFOSCREEN *pScreen = CrFbGetScreenInfo(hFb);
     302    void *pvVram = CrFbGetVRAM(hFb);
     303    crFbImgFromScreenVram(pScreen, pvVram, pImg);
     304}
    300305
    301306static int crFbBltGetContentsDirect(HCR_FRAMEBUFFER hFb, const RTRECT *pSrcRect, uint32_t cRects, const RTRECT *pRects, CR_BLITTER_IMG *pImg)
     
    311316    float strY = ((float)pImg->height) / (pSrcRect->yBottom - pSrcRect->yTop);
    312317
     318    RTPOINT StretchedSrcPoint;
     319    StretchedSrcPoint.x = CR_FLOAT_RCAST(int32_t, strX * SrcPoint.x);
     320    StretchedSrcPoint.y = CR_FLOAT_RCAST(int32_t, strY * SrcPoint.y);
     321
     322    RTPOINT ZeroPoint = {0, 0};
     323
    313324    VBoxVrListInit(&List);
    314325    int rc = VBoxVrListRectsAdd(&List, 1, CrVrScrCompositorRectGet(&hFb->Compositor), NULL);
     
    342353
    343354        uint32_t width, height;
    344         RTRECT SrcRect;
     355        RTPOINT StretchedEntryPoint;
    345356
    346357        for (uint32_t i = 0; i < cRects; ++i)
     
    409420                    const VBOXVR_TEXTURE *pVrTex = CrTdTexGet(pTex);
    410421
    411                     width = static_cast<uint32_t>(strX * pVrTex->width);
    412                     height = static_cast<uint32_t>(strY * pVrTex->height);
    413                     VBoxRectStretched(CrVrScrCompositorEntryRectGet(pEntry), strX, strY, &SrcRect);
     422                    width = CR_FLOAT_RCAST(uint32_t, strX * pVrTex->width);
     423                    height = CR_FLOAT_RCAST(uint32_t, strY * pVrTex->height);
     424                    StretchedEntryPoint.x = CR_FLOAT_RCAST(int32_t, strX * CrVrScrCompositorEntryRectGet(pEntry)->xLeft);
     425                    StretchedEntryPoint.y = CR_FLOAT_RCAST(int32_t, strY * CrVrScrCompositorEntryRectGet(pEntry)->yTop);
    414426                }
    415427
     
    423435                bool fInvert = !(CrVrScrCompositorEntryFlagsGet(pEntry) & CRBLT_F_INVERT_SRC_YCOORDS);
    424436
    425                 crFbBltImg(pSrcImg->pvData, &SrcRect, fInvert, &Intersection, &SrcPoint, pImg);
     437                crFbBltImg(pSrcImg, &StretchedEntryPoint, fInvert, &Intersection, &StretchedSrcPoint, pImg);
    426438
    427439                CrTdBltDataReleaseStretched(pTex, pSrcImg);
     
    460472        RTPOINT Pos = {0};
    461473        const RTRECT *pCompRect = CrVrScrCompositorRectGet(&hFb->Compositor);
    462         uint32_t fbPitch = (pCompRect->xRight - pCompRect->xLeft) * 4;
     474
     475        uint32_t fbWidth = (pCompRect->xRight - pCompRect->xLeft);
    463476        uint32_t fbHeight = pCompRect->yBottom - pCompRect->yTop;
    464477
    465         uint32_t dstPitch = static_cast<uint32_t>(strX * fbPitch);
    466         uint32_t dstHeight = static_cast<uint32_t>(strY * fbHeight);
    467 
    468         bool fStretch = fbPitch != dstPitch || fbHeight != dstHeight;
     478        uint32_t stretchedWidth = CR_FLOAT_RCAST(uint32_t, strX * fbWidth);
     479        uint32_t stretchedHeight = CR_FLOAT_RCAST(uint32_t, strY * fbHeight);
     480
     481        CR_BLITTER_IMG FbImg;
     482
     483        bool fStretch = fbWidth != stretchedWidth || fbHeight != stretchedHeight;
     484
     485        crFbImgFromFb(hFb, &FbImg);
    469486
    470487        for (uint32_t i = 0; i < cRects; ++i)
     
    480497
    481498                if (!fStretch)
    482                     crFbBltImg(hFb->pvVram, pCompRect, false, &Intersection, &SrcPoint, pImg);
     499                    crFbBltImg(&FbImg, &ZeroPoint, false, &Intersection, &SrcPoint, pImg);
    483500                else
    484                     crFbBltImgStretched(hFb->pvVram, pCompRect, false, &Intersection, &SrcPoint, strX, strY, pImg);
     501                    crFbBltImgStretched(&FbImg, &ZeroPoint, false, &Intersection, &SrcPoint, strX, strY, pImg);
    485502            }
    486503        }
     
    44274444                Rect.yBottom = Rect.yTop + pScreen->u32Height;
    44284445                CR_BLITTER_IMG Img;
    4429                 Img.pvData = pu8Buf;
    4430                 Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
    4431                 Img.enmFormat = GL_BGRA;
    4432                 Img.width = pScreen->u32Width;
    4433                 Img.height = pScreen->u32Height;
    4434                 Img.bpp = pScreen->u16BitsPerPixel;
    4435                 Img.pitch = pScreen->u32LineSize;
     4446                crFbImgFromScreenVram(pScreen, pu8Buf, &Img);
    44364447                int rc = CrFbBltGetContents(hFb, &Rect, cRects, pRects, &Img);
    44374448                if (!RT_SUCCESS(rc))
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette