VirtualBox

Ignore:
Timestamp:
Feb 7, 2014 2:11:50 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92115
Message:

crOpenGL: screenshot support; a bit of performance for video recording

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.cpp

    r50313 r50364  
    658658}
    659659
    660 DECLEXPORT(int) crServerVBoxScreenshotGet(uint32_t u32Screen, CR_SCREENSHOT *pScreenshot)
     660DECLEXPORT(void) crServerVBoxScreenshotRelease(CR_SCREENSHOT *pScreenshot)
     661{
     662    if (pScreenshot->fDataAllocated)
     663    {
     664        RTMemFree(pScreenshot->Img.pvData);
     665        pScreenshot->fDataAllocated = 0;
     666    }
     667}
     668
     669DECLEXPORT(int) crServerVBoxScreenshotGet(uint32_t u32Screen, uint32_t width, uint32_t height, uint32_t pitch, void *pvBuffer, CR_SCREENSHOT *pScreenshot)
    661670{
    662671    HCR_FRAMEBUFFER hFb = CrPMgrFbGetEnabled(u32Screen);
     
    666675    const VBVAINFOSCREEN *pScreen = CrFbGetScreenInfo(hFb);
    667676
    668     if (CrFbHas3DData(hFb))
    669     {
    670         RTPOINT Pos = {0, 0};
     677    if (!width)
     678        width = pScreen->u32Width;
     679    if (!height)
     680        height = pScreen->u32Height;
     681    if (!pitch)
     682        pitch = pScreen->u32LineSize;
     683
     684    if (CrFbHas3DData(hFb)
     685            || pScreen->u32Width != width
     686            || pScreen->u32Height != height
     687            || pScreen->u32LineSize != pitch
     688            || pScreen->u16BitsPerPixel != 32)
     689    {
    671690        RTRECT Rect;
    672691
    673692        pScreenshot->Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
    674         pScreenshot->Img.pvData = RTMemAlloc(pScreenshot->Img.cbData);
    675         if (!pScreenshot->Img.pvData)
    676         {
    677             WARN(("RTMemAlloc failed"));
    678             return VERR_NO_MEMORY;
     693        if (!pvBuffer)
     694        {
     695            pScreenshot->Img.pvData = RTMemAlloc(pScreenshot->Img.cbData);
     696            if (!pScreenshot->Img.pvData)
     697            {
     698                WARN(("RTMemAlloc failed"));
     699                return VERR_NO_MEMORY;
     700            }
     701            pScreenshot->fDataAllocated = 1;
     702        }
     703        else
     704        {
     705            pScreenshot->Img.pvData = pvBuffer;
     706            pScreenshot->fDataAllocated = 0;
     707        }
     708
     709        pScreenshot->Img.enmFormat = GL_BGRA;
     710        pScreenshot->Img.width = width;
     711        pScreenshot->Img.height = height;
     712        pScreenshot->Img.bpp = 32;
     713        pScreenshot->Img.pitch = pitch;
     714        Rect.xLeft = 0;
     715        Rect.yTop = 0;
     716        Rect.xRight = pScreen->u32Width;
     717        Rect.yBottom = pScreen->u32Height;
     718        int rc = CrFbBltGetContents(hFb, &Rect, 1, &Rect, &pScreenshot->Img);
     719        if (!RT_SUCCESS(rc))
     720        {
     721            WARN(("CrFbBltGetContents failed %d", rc));
     722            crServerVBoxScreenshotRelease(pScreenshot);
     723            return rc;
     724        }
     725    }
     726    else
     727    {
     728        pScreenshot->Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
     729        if (!pvBuffer)
     730            pScreenshot->Img.pvData = CrFbGetVRAM(hFb);
     731        else
     732        {
     733            pScreenshot->Img.pvData = pvBuffer;
     734            memcpy(pvBuffer, CrFbGetVRAM(hFb), pScreenshot->Img.cbData);
    679735        }
    680736        pScreenshot->Img.enmFormat = GL_BGRA;
     
    683739        pScreenshot->Img.bpp = pScreen->u16BitsPerPixel;
    684740        pScreenshot->Img.pitch = pScreen->u32LineSize;
    685         Rect.xLeft = 0;
    686         Rect.yTop = 0;
    687         Rect.xRight = pScreenshot->Img.width;
    688         Rect.yBottom = pScreenshot->Img.height;
    689         int rc = CrFbBltGetContents(hFb, &Pos, 1, &Rect, &pScreenshot->Img);
    690         if (!RT_SUCCESS(rc))
    691         {
    692             WARN(("CrFbBltGetContents failed %d", rc));
    693             RTMemFree(pScreenshot->Img.pvData);
    694             return rc;
    695         }
    696         pScreenshot->fDataIsFbDirect = 0;
    697     }
    698     else
    699     {
    700         pScreenshot->Img.pvData = CrFbGetVRAM(hFb);
    701         pScreenshot->Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
    702         pScreenshot->Img.enmFormat = GL_BGRA;
    703         pScreenshot->Img.width = pScreen->u32Width;
    704         pScreenshot->Img.height = pScreen->u32Height;
    705         pScreenshot->Img.bpp = pScreen->u16BitsPerPixel;
    706         pScreenshot->Img.pitch = pScreen->u32LineSize;
    707 
    708         pScreenshot->fDataIsFbDirect = 1;
     741
     742        pScreenshot->fDataAllocated = 0;
    709743    }
    710744
     
    712746
    713747    return VINF_SUCCESS;
    714 }
    715 
    716 DECLEXPORT(void) crServerVBoxScreenshotRelease(CR_SCREENSHOT *pScreenshot)
    717 {
    718     if (!pScreenshot->fDataIsFbDirect)
    719     {
    720         RTMemFree(pScreenshot->Img.pvData);
    721         pScreenshot->fDataIsFbDirect = 1;
    722     }
    723748}
    724749
Note: See TracChangeset for help on using the changeset viewer.

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