VirtualBox

Changeset 24405 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 5, 2009 5:17:12 PM (15 years ago)
Author:
vboxsync
Message:

Put screenshot to saved state (incomplete and disabled).

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/DisplayImpl.cpp

    r24373 r24405  
    113113/////////////////////////////////////////////////////////////////////////////
    114114
     115#define sSSMDisplayScreenshotVer 0x00010001
    115116#define sSSMDisplayVer 0x00010001
     117
     118/**
     119 * Save thumbnail and screenshot of the guest screen.
     120 */
     121static int displayMakeThumbnail(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
     122                                uint8_t **ppu8Thumbnail, uint32_t *pcbThumbnail, uint32_t *pcxThumbnail, uint32_t *pcyThumbnail)
     123{
     124    int rc = VINF_SUCCESS;
     125
     126    uint8_t *pu8Thumbnail = NULL;
     127    size_t cbThumbnail = 0;
     128    uint32_t cxThumbnail = 0;
     129    uint32_t cyThumbnail = 0;
     130
     131    if (cx > cy)
     132    {
     133        cxThumbnail = 64;
     134        cyThumbnail = (64 * cy) / cx;
     135    }
     136    else
     137    {
     138        cyThumbnail = 64;
     139        cxThumbnail = (64 * cx) / cy;
     140    }
     141
     142    LogFlowFunc(("%dx%d -> %dx%d\n", cx, cy, cxThumbnail, cyThumbnail));
     143
     144    cbThumbnail = cxThumbnail * 4 * cyThumbnail;
     145    pu8Thumbnail = (uint8_t *)RTMemAlloc(cbThumbnail);
     146
     147    if (pu8Thumbnail)
     148    {
     149        uint8_t *dst = pu8Thumbnail;
     150        uint8_t *src = pu8Data;
     151        int dstX = 0;
     152        int dstY = 0;
     153        int srcX = 0;
     154        int srcY = 0;
     155        int dstW = cxThumbnail;
     156        int dstH = cyThumbnail;
     157        int srcW = cx;
     158        int srcH = cy;
     159        gdImageCopyResampled (dst,
     160                              src,
     161                              dstX, dstY,
     162                              srcX, srcY,
     163                              dstW, dstH, srcW, srcH);
     164
     165        *ppu8Thumbnail = pu8Thumbnail;
     166        *pcbThumbnail = cbThumbnail;
     167        *pcxThumbnail = cxThumbnail;
     168        *pcyThumbnail = cyThumbnail;
     169    }
     170    else
     171    {
     172        rc = VERR_NO_MEMORY;
     173    }
     174
     175    return rc;
     176}
     177
     178static int displayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
     179                          uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG)
     180{
     181    int rc = VINF_SUCCESS;
     182    return rc;
     183}
     184
     185DECLCALLBACK(void)
     186Display::displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser)
     187{
     188    Display *that = static_cast<Display*>(pvUser);
     189
     190    /* 32bpp small image with maximum dimension = 64 pixels. */
     191    uint8_t *pu8Thumbnail = NULL;
     192    size_t cbThumbnail = 0;
     193    uint32_t cxThumbnail = 0;
     194    uint32_t cyThumbnail = 0;
     195
     196    /* PNG screenshot with maximum dimension = 1024 pixels. */
     197    uint8_t *pu8PNG = NULL;
     198    size_t cbPNG = 0;
     199    uint32_t cxPNG = 0;
     200    uint32_t cyPNG = 0;
     201
     202    Console::SafeVMPtr pVM (that->mParent);
     203    if (SUCCEEDED(pVM.rc()))
     204    {
     205        /* Query RGB bitmap. */
     206        uint8_t *pu8Data = NULL;
     207        size_t cbData = 0;
     208        uint32_t cx = 0;
     209        uint32_t cy = 0;
     210
     211        /* @todo pfnTakeScreenshot is probably callable from any thread, because it uses the VGA device lock. */
     212        int rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)that->mpDrv->pUpPort->pfnTakeScreenshot, 5,
     213                                 that->mpDrv->pUpPort, &pu8Data, &cbData, &cx, &cy);
     214
     215        if (RT_SUCCESS(rc))
     216        {
     217            /* Prepare a small thumbnail and a PNG screenshot. */
     218            displayMakeThumbnail(pu8Data, cx, cy, &pu8Thumbnail, &cbThumbnail, &cxThumbnail, &cyThumbnail);
     219            displayMakePNG(pu8Data, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG);
     220
     221            /* This can be called from any thread. */
     222            that->mpDrv->pUpPort->pfnFreeScreenshot (that->mpDrv->pUpPort, pu8Data);
     223        }
     224    }
     225    else
     226    {
     227        LogFunc(("Failed to get VM pointer 0x%x\n", pVM.rc()));
     228    }
     229
     230    /* Regardless of rc, save what is available */
     231
     232    SSMR3PutU32(pSSM, cbThumbnail);
     233
     234    if (cbThumbnail)
     235    {
     236        SSMR3PutU32(pSSM, cxThumbnail);
     237        SSMR3PutU32(pSSM, cyThumbnail);
     238        SSMR3PutMem(pSSM, pu8Thumbnail, cbThumbnail);
     239    }
     240
     241    SSMR3PutU32(pSSM, cbPNG);
     242
     243    if (cbPNG)
     244    {
     245        SSMR3PutU32(pSSM, cxPNG);
     246        SSMR3PutU32(pSSM, cyPNG);
     247        SSMR3PutMem(pSSM, pu8PNG, cbPNG);
     248    }
     249
     250    RTMemFree(pu8PNG);
     251    RTMemFree(pu8Thumbnail);
     252}
    116253
    117254/**
     
    278415                               NULL, displaySSMLoad, NULL, this);
    279416    AssertRCReturn(rc, rc);
     417
     418#if 0
     419    rc = SSMR3RegisterExternal(pVM, "DisplayScreenshot", 0 /*uInstance*/, sSSMDisplayScreenshotVer, 0 /*cbGuess*/,
     420                               NULL, NULL, NULL,
     421                               NULL, displaySSMSaveScreenshot, NULL,
     422                               NULL, NULL, NULL, this);
     423
     424    AssertRCReturn(rc, rc);
     425#endif
     426
    280427    return VINF_SUCCESS;
    281428}
  • trunk/src/VBox/Main/include/DisplayImpl.h

    r24373 r24405  
    298298    static DECLCALLBACK(void)   displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
    299299    static DECLCALLBACK(int)    displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
     300    static DECLCALLBACK(void)   displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
    300301
    301302    const ComObjPtr<Console, ComWeakRef> mParent;
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