VirtualBox

Changeset 31718 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 17, 2010 10:18:05 AM (14 years ago)
Author:
vboxsync
Message:

Main: PNG screenshoting API

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

Legend:

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

    r31279 r31718  
    250250
    251251static int displayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
    252                           uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG)
     252                          uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
     253                          uint8_t fLimitSize)
    253254{
    254255    int rc = VINF_SUCCESS;
     
    259260    uint32_t volatile cyBitmap = 0; /* gcc setjmp warning */
    260261
    261     if (cx < kMaxSizePNG && cy < kMaxSizePNG)
     262    if (!fLimitSize || (cx < kMaxSizePNG && cy < kMaxSizePNG))
    262263    {
    263264        /* Save unscaled screenshot. */
     
    448449            /* Prepare a small thumbnail and a PNG screenshot. */
    449450            displayMakeThumbnail(pu8Data, cx, cy, &pu8Thumbnail, &cbThumbnail, &cxThumbnail, &cyThumbnail);
    450             displayMakePNG(pu8Data, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG);
     451            displayMakePNG(pu8Data, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 1);
    451452
    452453            /* This can be called from any thread. */
     
    26032604
    26042605        com::SafeArray<BYTE> screenData (cbData);
    2605         for (unsigned i = 0; i < cbData; i++)
    2606             screenData[i] = pu8Data[i];
     2606        screenData.initFrom(pu8Data, cbData);
    26072607        screenData.detachTo(ComSafeArrayOutArg(aScreenData));
    26082608    }
     
    26202620    return rc;
    26212621}
     2622
     2623STDMETHODIMP Display::TakeScreenShotPNGToArray (ULONG aScreenId, ULONG width, ULONG height,
     2624                                             ComSafeArrayOut(BYTE, aScreenData))
     2625{
     2626    LogFlowFuncEnter();
     2627    LogFlowFunc (("width=%d, height=%d\n",
     2628                  width, height));
     2629
     2630    CheckComArgOutSafeArrayPointerValid(aScreenData);
     2631    CheckComArgExpr(width, width != 0);
     2632    CheckComArgExpr(height, height != 0);
     2633
     2634    AutoCaller autoCaller(this);
     2635    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2636
     2637    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     2638
     2639    CHECK_CONSOLE_DRV (mpDrv);
     2640
     2641    Console::SafeVMPtr pVM(mParent);
     2642    if (FAILED(pVM.rc())) return pVM.rc();
     2643
     2644    HRESULT rc = S_OK;
     2645
     2646    LogFlowFunc (("Sending SCREENSHOT request\n"));
     2647
     2648    /* Leave lock because other thread (EMT) is called and it may initiate a resize
     2649     * which also needs lock.
     2650     *
     2651     * This method does not need the lock anymore.
     2652     */
     2653    alock.leave();
     2654
     2655    size_t cbData = width * 4 * height;
     2656    uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbData);
     2657
     2658    if (!pu8Data)
     2659        return E_OUTOFMEMORY;
     2660
     2661#ifdef VBOX_WITH_OLD_VBVA_LOCK
     2662    int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
     2663#else
     2664    int vrc = displayTakeScreenshot(pVM, mpDrv, pu8Data, width, height);
     2665#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
     2666
     2667    if (RT_SUCCESS(vrc))
     2668    {
     2669        uint8_t *pu8PNG = NULL;
     2670        uint32_t cbPNG = 0;
     2671        uint32_t cxPNG = 0;
     2672        uint32_t cyPNG = 0;
     2673
     2674        displayMakePNG(pu8Data, width, height, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
     2675
     2676        com::SafeArray<BYTE> screenData (cbPNG);
     2677        screenData.initFrom(pu8PNG, cbPNG);
     2678        RTMemFree(pu8PNG);
     2679
     2680        screenData.detachTo(ComSafeArrayOutArg(aScreenData));
     2681    }
     2682    else if (vrc == VERR_NOT_IMPLEMENTED)
     2683        rc = setError(E_NOTIMPL,
     2684                      tr("This feature is not implemented"));
     2685    else
     2686        rc = setError(VBOX_E_IPRT_ERROR,
     2687                      tr("Could not take a screenshot (%Rrc)"), vrc);
     2688
     2689    RTMemFree(pu8Data);
     2690
     2691    LogFlowFunc (("rc=%08X\n", rc));
     2692    LogFlowFuncLeave();
     2693    return rc;
     2694}
     2695
    26222696
    26232697#ifdef VBOX_WITH_OLD_VBVA_LOCK
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31698 r31718  
    1070210702  <interface
    1070310703     name="IDisplay" extends="$unknown"
    10704      uuid="1fa79e39-0cc9-4ab3-9df3-ed3e96b42496"
     10704     uuid="09EED313-CD56-4D06-BD56-FAC0F716B5DD"
    1070510705     wsmap="managed"
    1070610706     >
     
    1081810818        for scriptable languages not allowed to manipulate with addresses
    1081910819        directly.
     10820
     10821        <result name="E_NOTIMPL">
     10822          Feature not implemented.
     10823        </result>
     10824        <result name="VBOX_E_IPRT_ERROR">
     10825          Could not take a screenshot.
     10826        </result>
     10827      </desc>
     10828      <param name="screenId" type="unsigned long" dir="in">
     10829        <desc>
     10830          Monitor to take screenshot from.
     10831        </desc>
     10832      </param>
     10833      <param name="width" type="unsigned long" dir="in">
     10834        <desc>
     10835          Desired image width.
     10836        </desc>
     10837      </param>
     10838      <param name="height" type="unsigned long" dir="in">
     10839        <desc>
     10840          Desired image height.
     10841        </desc>
     10842      </param>
     10843      <param name="screenData" type="octet" dir="return" safearray="yes">
     10844        <desc>
     10845          Array with resulting screen data.
     10846        </desc>
     10847      </param>
     10848    </method>
     10849
     10850     <method name="takeScreenShotPNGToArray">
     10851      <desc>
     10852        Takes a guest screen shot of the requested size and returns it as
     10853        PNG image in array.
    1082010854
    1082110855        <result name="E_NOTIMPL">
  • trunk/src/VBox/Main/include/DisplayImpl.h

    r31279 r31718  
    155155    STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
    156156    STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
     157    STDMETHOD(TakeScreenShotPNGToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
    157158    STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
    158159    STDMETHOD(InvalidateAndUpdate)();
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