VirtualBox

Changeset 3761 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 22, 2007 10:43:14 AM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
23084
Message:

Main/Frontends: Cleaned up IFramebuffer interface.

Location:
trunk/src/VBox/Frontends
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxBFE/DisplayImpl.cpp

    r3670 r3761  
    308308 *
    309309 * @returns COM status code
    310  * @param colorDepth Address of result variable.
    311  */
    312 uint32_t VMDisplay::getColorDepth()
     310 * @param bitsPerPixel Address of result variable.
     311 */
     312uint32_t VMDisplay::getBitsPerPixel()
    313313{
    314314    Assert(mpDrv);
     
    409409        mFramebuffer->getAddress ((uintptr_t *)&mpDrv->Connector.pu8Data);
    410410        mFramebuffer->getLineSize ((ULONG*)&mpDrv->Connector.cbScanline);
    411         mFramebuffer->getColorDepth ((ULONG*)&mpDrv->Connector.cBits);
     411        mFramebuffer->getBitsPerPixel ((ULONG*)&mpDrv->Connector.cBits);
    412412        mFramebuffer->getWidth ((ULONG*)&mpDrv->Connector.cx);
    413413        mFramebuffer->getHeight ((ULONG*)&mpDrv->Connector.cy);
     
    426426    {
    427427        mFramebuffer->getAddress ((uintptr_t *)&mpDrv->Connector.pu8Data);
    428         mFramebuffer->getColorDepth ((ULONG*)&mpDrv->Connector.cBits);
     428        mFramebuffer->getBitsPerPixel ((ULONG*)&mpDrv->Connector.cBits);
    429429        mpDrv->pUpPort->pfnSetRenderVRAM (mpDrv->pUpPort,
    430430                                          !!(mpDrv->Connector.pu8Data != (uint8_t*)~0UL));
     
    824824}
    825825
    826 void VMDisplay::SetVideoModeHint(ULONG aWidth, ULONG aHeight, ULONG aColorDepth, ULONG aDisplay)
     826void VMDisplay::SetVideoModeHint(ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel, ULONG aDisplay)
    827827{
    828828    PPDMIVMMDEVPORT pVMMDevPort = gVMMDev->getVMMDevPort ();
    829829
    830830    if (pVMMDevPort)
    831         pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, aWidth, aHeight, aColorDepth, aDisplay);
     831        pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, aWidth, aHeight, aBitsPerPixel, aDisplay);
    832832}
    833833
  • trunk/src/VBox/Frontends/VBoxBFE/DisplayImpl.h

    r3110 r3761  
    4747
    4848    void updatePointerShape(bool fVisible, bool fAlpha, uint32_t xHot, uint32_t yHot, uint32_t width, uint32_t height, void *pShape);
    49     void SetVideoModeHint(ULONG aWidth, ULONG aHeight, ULONG aColorDepth, ULONG aDisplay);
     49    void SetVideoModeHint(ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel, ULONG aDisplay);
    5050
    5151    static const PDMDRVREG  DrvReg;
     
    5353    uint32_t getWidth();
    5454    uint32_t getHeight();
    55     uint32_t getColorDepth();
     55    uint32_t getBitsPerPixel();
    5656
    5757    STDMETHODIMP RegisterExternalFramebuffer(Framebuffer *Framebuffer);
  • trunk/src/VBox/Frontends/VBoxBFE/Framebuffer.h

    r3576 r3761  
    4242    virtual HRESULT Unlock() = 0;
    4343    virtual HRESULT getAddress(uintptr_t *address) = 0;
    44     virtual HRESULT getColorDepth(ULONG *colorDepth) = 0;
     44    virtual HRESULT getBitsPerPixel(ULONG *bitsPerPixel) = 0;
    4545    virtual HRESULT getLineSize(ULONG *lineSize) = 0;
    4646    virtual HRESULT NotifyUpdate(ULONG x, ULONG y,
  • trunk/src/VBox/Frontends/VBoxBFE/SDLFramebuffer.cpp

    r3701 r3761  
    185185 *
    186186 * @returns COM status code
    187  * @param   colorDepth Address of result variable
    188  */
    189 HRESULT SDLFramebuffer::getColorDepth(ULONG *colorDepth)
    190 {
    191     LogFlow(("SDLFramebuffer::GetColorDepth\n"));
    192 
    193     if (!colorDepth)
     187 * @param   bitsPerPixel Address of result variable
     188 */
     189HRESULT SDLFramebuffer::getBitsPerPixel(ULONG *bitsPerPixel)
     190{
     191    LogFlow(("SDLFramebuffer::GetBitsPerPixel\n"));
     192
     193    if (!bitsPerPixel)
    194194        return E_INVALIDARG;
    195     *colorDepth = (ULONG)(mScreen ? mScreen->format->BitsPerPixel : 0);
     195    *bitsPerPixel = (ULONG)(mScreen ? mScreen->format->BitsPerPixel : 0);
    196196    return S_OK;
    197197}
  • trunk/src/VBox/Frontends/VBoxBFE/SDLFramebuffer.h

    r3669 r3761  
    4848    virtual HRESULT Unlock();
    4949    virtual HRESULT getAddress(uintptr_t *address);
    50     virtual HRESULT getColorDepth(ULONG *colorDepth);
     50    virtual HRESULT getBitsPerPixel(ULONG *bitsPerPixel);
    5151    virtual HRESULT getLineSize(ULONG *lineSize);
    5252    virtual HRESULT NotifyUpdate(ULONG x, ULONG y,
  • trunk/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp

    r3670 r3761  
    729729    if (g_u32VRamSizeMB * _1M >=   gFramebuffer->getHostXres()
    730730                          * gFramebuffer->getHostYres()
    731                           * (gDisplay->getColorDepth() / 8))
     731                          * (gDisplay->getBitsPerPixel() / 8))
    732732        gDisplay->SetVideoModeHint(gFramebuffer->getHostXres(), gFramebuffer->getHostYres(), 0, 0);
    733733#endif
  • trunk/src/VBox/Frontends/VBoxFB/Framebuffer.cpp

    r3614 r3761  
    4242    }
    4343    fbSurfaceLocked = 0;
    44     uint32_t colorDepth;
    45     GetColorDepth(&colorDepth);
    46     fbPitch = fbWidth * (colorDepth / 8);
     44    uint32_t bitsPerPixel;
     45    GetBitsPerPixel(&bitsPerPixel);
     46    fbPitch = fbWidth * (bitsPerPixel / 8);
    4747}
    4848
     
    138138}
    139139
    140 NS_IMETHODIMP VBoxDirectFB::GetColorDepth(uint32_t *colorDepth)
    141 {
    142     if (!colorDepth)
     140NS_IMETHODIMP VBoxDirectFB::GetBitsPerPixel(uint32_t *bitsPerPixel)
     141{
     142    if (!bitsPerPixel)
    143143        return NS_ERROR_INVALID_POINTER;
    144144    DFBSurfacePixelFormat pixelFormat;
     
    147147    {
    148148        case DSPF_RGB16:
    149             *colorDepth = 16;
     149            *bitsPerPixel = 16;
    150150            break;
    151151        case DSPF_RGB24:
    152             *colorDepth = 24;
     152            *bitsPerPixel = 24;
    153153            break;
    154154        case DSPF_RGB32:
    155             *colorDepth = 32;
     155            *bitsPerPixel = 32;
    156156            break;
    157157        default:
    158158            // not good! @@@AH do something!
    159             *colorDepth = 16;
    160     }
    161     return NS_OK;
    162 }
    163 
    164 NS_IMETHODIMP VBoxDirectFB::GetLineSize(uint32_t *lineSize)
    165 {
    166     if (!lineSize)
    167         return NS_ERROR_INVALID_POINTER;
    168     *lineSize = fbPitch;
    169     return NS_OK;
    170 }
    171 
    172 NS_IMETHODIMP VBoxDirectFB::COMGETTER(PixelFormat) (FramebufferPixelFormat_T *pixelFormat)
    173 {
    174     if (!lineSize)
    175         return NS_ERROR_INVALID_POINTER;
    176     *pixelFormat = FramebufferPixelFormat_PixelFormatOpaque;
     159            *bitsPerPixel = 16;
     160    }
     161    return NS_OK;
     162}
     163
     164NS_IMETHODIMP VBoxDirectFB::GetBytesPerLine(uint32_t *bytesPerLine)
     165{
     166    if (!bytesPerLine)
     167        return NS_ERROR_INVALID_POINTER;
     168    *bytesPerLine = fbPitch;
     169    return NS_OK;
     170}
     171
     172NS_IMETHODIMP VBoxDirectFB::COMGETTER(PixelFormat) (ULONG *pixelFormat)
     173{
     174    if (!pixelFormat)
     175        return NS_ERROR_INVALID_POINTER;
     176    *pixelFormat = FramebufferPixelFormat_FOURCC_RGB;
     177    return NS_OK;
     178}
     179
     180NS_IMETHODIMP VBoxDirectFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM)
     181{
     182    if (!usesGuestVRAM)
     183        return NS_ERROR_INVALID_POINTER;
     184    *usesGuestVRAM = FALSE;
    177185    return NS_OK;
    178186}
     
    213221}
    214222
    215 NS_IMETHODIMP VBoxDirectFB::RequestResize(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, uint32_t vram, uint32_t lineSize, uint32_t w, uint32_t h,
    216                                            PRBool *finished)
     223NS_IMETHODIMP VBoxDirectFB::RequestResize(ULONG aScreenId, ULONG pixelFormat, uint32_t vram,
     224                                          uint32_t bitsPerPixel, uint32_t bytesPerLine,
     225                                          uint32_t w, uint32_t h,
     226                                          PRBool *finished)
    217227{
    218228    uint32_t needsLocking = fbSurfaceLocked;
    219     uint32_t colorDepth;
    220 
    221     GetColorDepth(&colorDepth);
     229    uint32_t bitsPerPixel;
     230
     231    GetBitsPerPixel(&bitsPerPixel);
    222232    printf("RequestResize: w = %d, h = %d, fbSurfaceLocked = %d\n", w, h, fbSurfaceLocked);
    223233
     
    250260    {
    251261        // we adopt to the guest resolution or the next higher that is available
    252         int32_t bestMode = getBestVideoMode(w, h, colorDepth);
     262        int32_t bestMode = getBestVideoMode(w, h, bitsPerPixel);
    253263        if (bestMode == -1)
    254264        {
     
    260270        // does the mode differ from what we wanted?
    261271        if ((videoModes[bestMode].width != w) || (videoModes[bestMode].height != h) ||
    262             (videoModes[bestMode].bpp != colorDepth))
     272            (videoModes[bestMode].bpp != bitsPerPixel))
    263273        {
    264274            printf("The mode does not fit exactly!\n");
  • trunk/src/VBox/Frontends/VBoxFB/Framebuffer.h

    r3153 r3761  
    3939    NS_IMETHOD Unlock();
    4040    NS_IMETHOD GetAddress(uint32_t *address);
    41     NS_IMETHOD GetColorDepth(uint32_t *colorDepth);
    42     NS_IMETHOD GetLineSize(uint32_t *lineSize);
    43     NS_IMETHOD GetPixelFormat(FramebufferPixelFormat_T *pixelFormat);
     41    NS_IMETHOD GetBitsPerPixel(uint32_t *bitsPerPixel);
     42    NS_IMETHOD GetBytesPerLine(uint32_t *bytesPerLine);
     43    NS_IMETHOD GetPixelFormat(ULONG *pixelFormat);
     44    NS_IMETHOD GetUsesGuestVRAM(BOOL *usesGuestVRAM);
    4445    NS_IMETHOD NotifyUpdate(uint32_t x, uint32_t y,
    4546                           uint32_t w, uint32_t h, PRBool *finished);
    46     NS_IMETHOD RequestResize(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, uint32_t vram, uint32_t lineSize, uint32_t w, uint32_t h,
     47    NS_IMETHOD RequestResize(ULONG aScreenId, ULONG pixelFormat, uint32_t vram,
     48                             uint32_t bitsPerPixel, uint32_t bytesPerLine,
     49                             uint32_t w, uint32_t h,
    4750                             PRBool *finished);
    4851private:
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r3730 r3761  
    11231123        CHECK_ERROR_RET(display, COMGETTER(Width)(&xRes), rc);
    11241124        CHECK_ERROR_RET(display, COMGETTER(Height)(&yRes), rc);
    1125         CHECK_ERROR_RET(display, COMGETTER(ColorDepth)(&bpp), rc);
     1125        CHECK_ERROR_RET(display, COMGETTER(BitsPerPixel)(&bpp), rc);
    11261126        RTPrintf("Video mode:      %dx%dx%d\n", xRes, yRes, bpp);
    11271127    }
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp

    r3669 r3761  
    108108    mGuestYRes      = 480;
    109109    mPixelFormat    = FramebufferPixelFormat_PixelFormatOpaque;
     110    mUsesGuestVRAM  = FALSE;
    110111    mPtrVRAM        = NULL;
    111     mLineSize       = 0;
     112    mBitsPerPixel   = 0;
     113    mBytesPerLine   = 0;
    112114#ifdef VBOX_SECURELABEL
    113115    mLabelFont      = NULL;
     
    296298 *
    297299 * @returns COM status code
    298  * @param   colorDepth Address of result variable
    299  */
    300 STDMETHODIMP VBoxSDLFB::COMGETTER(ColorDepth)(ULONG *colorDepth)
    301 {
    302     LogFlow(("VBoxSDLFB::GetColorDepth\n"));
    303     if (!colorDepth)
     300 * @param   bitsPerPixel Address of result variable
     301 */
     302STDMETHODIMP VBoxSDLFB::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
     303{
     304    LogFlow(("VBoxSDLFB::GetBitsPerPixel\n"));
     305    if (!bitsPerPixel)
    304306        return E_INVALIDARG;
    305307    /* get the information directly from the surface in use */
    306308    Assert(mSurfVRAM);
    307     *colorDepth = (ULONG)(mSurfVRAM ? mSurfVRAM->format->BitsPerPixel : 0);
     309    *bitsPerPixel = (ULONG)(mSurfVRAM ? mSurfVRAM->format->BitsPerPixel : 0);
    308310    return S_OK;
    309311}
     
    315317 * @param   lineSize Address of result variable.
    316318 */
    317 STDMETHODIMP VBoxSDLFB::COMGETTER(LineSize)(ULONG *lineSize)
    318 {
    319     LogFlow(("VBoxSDLFB::GetLineSize\n"));
    320     if (!lineSize)
     319STDMETHODIMP VBoxSDLFB::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
     320{
     321    LogFlow(("VBoxSDLFB::GetBytesPerLine\n"));
     322    if (!bytesPerLine)
    321323        return E_INVALIDARG;
    322324    /* get the information directly from the surface */
    323325    Assert(mSurfVRAM);
    324     *lineSize = (ULONG)(mSurfVRAM ? mSurfVRAM->pitch : 0);
    325     return S_OK;
    326 }
    327 
    328 STDMETHODIMP VBoxSDLFB::COMGETTER(PixelFormat) (FramebufferPixelFormat_T *pixelFormat)
     326    *bytesPerLine = (ULONG)(mSurfVRAM ? mSurfVRAM->pitch : 0);
     327    return S_OK;
     328}
     329
     330STDMETHODIMP VBoxSDLFB::COMGETTER(PixelFormat) (ULONG *pixelFormat)
    329331{
    330332    if (!pixelFormat)
    331333        return E_POINTER;
    332334    *pixelFormat = mPixelFormat;
     335    return S_OK;
     336}
     337
     338STDMETHODIMP VBoxSDLFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM)
     339{
     340    if (!usesGuestVRAM)
     341        return E_POINTER;
     342    *usesGuestVRAM = mUsesGuestVRAM;
    333343    return S_OK;
    334344}
     
    425435 * @param   pixelFormat The requested pixel format.
    426436 * @param   vram        Pointer to the guest VRAM buffer (can be NULL).
    427  * @param   lineSize    Size of a scanline in bytes.
     437 * @param   bitsPerPixel Color depth in bits.
     438 * @param   bytesPerLine Size of a scanline in bytes.
    428439 * @param   w           New display width in pixels.
    429440 * @param   h           New display height in pixels.
     
    434445 *                      continuing with display updates.
    435446 */
    436 STDMETHODIMP VBoxSDLFB::RequestResize(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, BYTE *vram,
    437                                       ULONG lineSize, ULONG w, ULONG h, BOOL *finished)
    438 {
    439     LogFlow(("VBoxSDLFB::RequestResize: w = %d, h = %d, pixelFormat: %d, vram = %p, lineSize = %d\n",
    440              w, h, pixelFormat, vram, lineSize));
     447STDMETHODIMP VBoxSDLFB::RequestResize(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
     448                                      ULONG bitsPerPixel, ULONG bytesPerLine,
     449                                      ULONG w, ULONG h, BOOL *finished)
     450{
     451    LogFlowFunc (("w=%d, h=%d, pixelFormat=0x%08lX, vram=%p, "
     452                  "bpp=%d, bpl=%d\n",
     453                  w, h, pixelFormat, vram, bitsPerPixel, bytesPerLine));
    441454
    442455    /*
     
    450463        return E_FAIL;
    451464    }
     465
    452466    mGuestXRes   = w;
    453467    mGuestYRes   = h;
    454468    mPixelFormat = pixelFormat;
    455469    mPtrVRAM     = vram;
    456     mLineSize    = lineSize;
     470    mBitsPerPixel = bitsPerPixel;
     471    mBytesPerLine = bytesPerLine;
     472    mUsesGuestVRAM = FALSE; /* yet */
    457473
    458474    SDL_Event event;
     
    610626void VBoxSDLFB::resizeGuest()
    611627{
    612     LogFlow(("VBoxSDL::resizeGuest() mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes));
    613     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    614 
    615     int      cBitsPerPixel = 32;
     628    LogFlowFunc (("mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes));
     629    AssertMsg(mSdlNativeThread == RTThreadNativeSelf(),
     630              ("Wrong thread! SDL is not threadsafe!\n"));
     631
    616632    uint32_t Rmask, Gmask, Bmask, Amask = 0;
    617633
    618     /* pixel characteristics, default to fallback 32bpp format */
    619     if (mPixelFormat == FramebufferPixelFormat_PixelFormatRGB16)
    620         cBitsPerPixel = 16;
    621     else if (mPixelFormat == FramebufferPixelFormat_PixelFormatRGB24)
    622         cBitsPerPixel = 24;
    623 
    624     switch (cBitsPerPixel)
     634    mUsesGuestVRAM = FALSE;
     635
     636    /* pixel characteristics. if we don't support the format directly, we will
     637     * fallback to the indirect 32bpp buffer (mUsesGuestVRAM will remain
     638     * FALSE) */
     639    if (mPixelFormat == FramebufferPixelFormat_FOURCC_RGB)
     640    {
     641        switch (mBitsPerPixel)
     642        {
     643            case 16:
     644            case 24:
     645            case 32:
     646                mUsesGuestVRAM = TRUE;
     647                break;
     648            default:
     649                /* the fallback buffer is always 32bpp */
     650                mBitsPerPixel = 32;
     651                mBytesPerLine = mGuestXRes * 4;
     652                break;
     653        }
     654    }
     655    else
     656    {
     657        /* the fallback buffer is always RGB, 32bpp */
     658        mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
     659        mBitsPerPixel = 32;
     660        mBytesPerLine = mGuestXRes * 4;
     661    }
     662
     663    switch (mBitsPerPixel)
    625664    {
    626665        case 16: Rmask = 0x0000F800; Gmask = 0x000007E0; Bmask = 0x0000001F; break;
     
    636675
    637676    /* is the guest in a linear framebuffer mode we support? */
    638     if (mPixelFormat != FramebufferPixelFormat_PixelFormatOpaque)
    639     {
     677    if (mUsesGuestVRAM)
     678    {
     679
    640680        /* Create a source surface from guest VRAM. */
    641         mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, cBitsPerPixel,
    642                                              mLineSize, Rmask, Gmask, Bmask, Amask);
     681        mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, mBitsPerPixel,
     682                                             mBytesPerLine, Rmask, Gmask, Bmask, Amask);
    643683    }
    644684    else
    645685    {
    646686        /* Create a software surface for which SDL allocates the RAM */
    647         mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, cBitsPerPixel,
     687        mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, mBitsPerPixel,
    648688                                         Rmask, Gmask, Bmask, Amask);
    649689    }
     
    11561196 * @param   lineSize Address of result buffer.
    11571197 */
    1158 STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(LineSize)(ULONG *lineSize)
    1159 {
    1160     LogFlow(("VBoxSDLFBOverlay::GetLineSize\n"));
    1161     if (!lineSize)
    1162         return E_INVALIDARG;
    1163     *lineSize = mOverlayBits->pitch;
     1198STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
     1199{
     1200    LogFlow(("VBoxSDLFBOverlay::GetBytesPerLine\n"));
     1201    if (!bytesPerLine)
     1202        return E_INVALIDARG;
     1203    *bytesPerLine = mOverlayBits->pitch;
    11641204    return S_OK;
    11651205}
     
    12511291 *
    12521292 * @returns COM status code
    1253  * @param   colorDepth Address of result buffer.
    1254  */
    1255 STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(ColorDepth)(ULONG *colorDepth)
    1256 {
    1257     LogFlow(("VBoxSDLFBOverlay::GetColorDepth\n"));
    1258     if (!colorDepth)
    1259         return E_INVALIDARG;
    1260     *colorDepth = 32;
    1261     return S_OK;
    1262 }
    1263 
    1264 /**
    1265  * Returns the current pixel format.  In fact, this is always RGB32.
     1293 * @param   bitsPerPixel Address of result buffer.
     1294 */
     1295STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
     1296{
     1297    LogFlow(("VBoxSDLFBOverlay::GetBitsPerPixel\n"));
     1298    if (!bitsPerPixel)
     1299        return E_INVALIDARG;
     1300    *bitsPerPixel = 32;
     1301    return S_OK;
     1302}
     1303
     1304/**
     1305 * Returns the current pixel format.  In fact, this is always RGB.
    12661306 *
    12671307 * @returns COM status code
    12681308 * @param   pixelFormat Address of result buffer.
    12691309 */
    1270 STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(PixelFormat)(FramebufferPixelFormat_T *pixelFormat)
     1310STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(PixelFormat)(ULONG *pixelFormat)
    12711311{
    12721312    LogFlow(("VBoxSDLFBOverlay::GetPixelFormat\n"));
    12731313    if (!pixelFormat)
    12741314        return E_INVALIDARG;
    1275     *pixelFormat = FramebufferPixelFormat_PixelFormatRGB32;
     1315    *pixelFormat = FramebufferPixelFormat_FOURCC_RGB;
     1316    return S_OK;
     1317}
     1318
     1319/**
     1320 * Returns whether the guest VRAM is used directly.  In fact, this is always FALSE.
     1321 *
     1322 * @returns COM status code
     1323 * @param   usesGuestVRAM Address of result buffer.
     1324 */
     1325STDMETHODIMP VBoxSDLFBOverlay::COMGETTER(UsesGuestVRAM)(BOOL *usesGuestVRAM)
     1326{
     1327    LogFlow(("VBoxSDLFBOverlay::GetUsesGuestVRAM\n"));
     1328    if (!usesGuestVRAM)
     1329        return E_INVALIDARG;
     1330    *usesGuestVRAM = FALSE;
    12761331    return S_OK;
    12771332}
     
    13791434 * @retval  finished    Set if the operation has completed.
    13801435 */
    1381 STDMETHODIMP VBoxSDLFBOverlay::RequestResize(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat,
    1382                                              ULONG vram, ULONG lineSize, ULONG w,
    1383                                              ULONG h, BOOL *finished)
    1384 {
    1385     AssertReturn(pixelFormat == FramebufferPixelFormat_PixelFormatRGB32, E_INVALIDARG);
     1436STDMETHODIMP VBoxSDLFBOverlay::RequestResize(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
     1437                                             ULONG bitsPerPixel, ULONG bytesPerLine,
     1438                                             ULONG w, ULONG h, BOOL *finished)
     1439{
     1440    AssertReturn(pixelFormat == FramebufferPixelFormat_FOURCC_RGB, E_INVALIDARG);
    13861441    AssertReturn(vram == 0, E_INVALIDARG);
     1442    AssertReturn(bitsPerPixel == 32, E_INVALIDARG);
    13871443    mOverlayWidth = w;
    13881444    mOverlayHeight = h;
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.h

    r3669 r3761  
    9090    STDMETHOD(Unlock)();
    9191    STDMETHOD(COMGETTER(Address))(BYTE **address);
    92     STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
    93     STDMETHOD(COMGETTER(LineSize))(ULONG *lineSize);
    94     STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
     92    STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
     93    STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
     94    STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
     95    STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
    9596    STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
    9697    STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
     
    9899    STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
    99100                            ULONG w, ULONG h, BOOL *finished);
    100     STDMETHOD(RequestResize)(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, BYTE *vram,
    101                              ULONG lineSize, ULONG w, ULONG h, BOOL *finished);
     101    STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
     102                             ULONG bitsPerPixel, ULONG bytesPerLine,
     103                             ULONG w, ULONG h, BOOL *finished);
    102104    STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
    103105    STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
     
    185187
    186188    BYTE *mPtrVRAM;
    187     ULONG mLineSize;
    188     FramebufferPixelFormat_T mPixelFormat;
     189    ULONG mBitsPerPixel;
     190    ULONG mBytesPerLine;
     191    ULONG mPixelFormat;
     192    BOOL mUsesGuestVRAM;
    189193
    190194    /** the application Icon */
     
    242246    STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
    243247    STDMETHOD(COMGETTER(Address))(ULONG *address);
    244     STDMETHOD(COMGETTER(LineSize))(ULONG *lineSize);
     248    STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
    245249
    246250    /* These are not used, or return standard values. */
    247     STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
    248     STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
     251    STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
     252    STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
     253    STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
    249254    STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
    250255    STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
     
    255260    STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
    256261                            ULONG w, ULONG h, BOOL *finished);
    257     STDMETHOD(RequestResize)(ULONG aScreenId, FramebufferPixelFormat_T pixelFormat, ULONG vram,
    258                              ULONG lineSize, ULONG w, ULONG h, BOOL *finished);
     262    STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
     263                             ULONG bitsPerPixel, ULONG bytesPerLine,
     264                             ULONG w, ULONG h, BOOL *finished);
    259265    STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
    260266                                  BOOL *supported);
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h

    r3674 r3761  
    7373{
    7474public:
    75     VBoxResizeEvent (FramebufferPixelFormat_T f, uchar *v, unsigned l, int w, int h) :
    76         QEvent ((QEvent::Type) VBoxDefs::ResizeEventType), fmt (f), vr (v), lsz (l), wdt (w), hgt (h) {}
    77     FramebufferPixelFormat_T  pixelFormat() { return fmt; }
    78     uchar *vram() { return vr; }
    79     unsigned lineSize() { return lsz; }
    80     int width() { return wdt; }
    81     int height() { return hgt; }
    82 private:
    83     FramebufferPixelFormat_T fmt;
    84     uchar *vr;
    85     unsigned lsz;
    86     int wdt;
    87     int hgt;
     75
     76    VBoxResizeEvent (ulong aPixelFormat, uchar *aVRAM,
     77                     ulong aBitsPerPixel, ulong aBytesPerLine,
     78                     ulong aWidth, ulong aHeight) :
     79        QEvent ((QEvent::Type) VBoxDefs::ResizeEventType),
     80            mPixelFormat (aPixelFormat), mVRAM (aVRAM), mBitsPerPixel (aBitsPerPixel),
     81        mBytesPerLine (aBytesPerLine), mWidth (aWidth), mHeight (aHeight) {}
     82    ulong pixelFormat() { return mPixelFormat; }
     83    uchar *VRAM() { return mVRAM; }
     84    ulong bitsPerPixel() { return mBitsPerPixel; }
     85    ulong bytesPerLine() { return mBytesPerLine; }
     86    ulong width() { return mWidth; }
     87    ulong height() { return mHeight; }
     88
     89private:
     90
     91    ulong mPixelFormat;
     92    uchar *mVRAM;
     93    ulong mBitsPerPixel;
     94    ulong mBytesPerLine;
     95    ulong mWidth;
     96    ulong mHeight;
    8897};
    8998
     
    145154    bool rc = pm.convertFromImage (QImage (addr,
    146155                                           display.GetWidth(), display.GetHeight(),
    147                                            display.GetColorDepth(),
     156                                           display.GetBitsPerPixel(),
    148157                                           0, 0, QImage::LittleEndian));
    149158    AssertMsg (rc, ("convertFromImage() must always return true"));
     
    157166
    158167/////////////////////////////////////////////////////////////////////////////
    159 
    160 /* Framebuffer render mode */
    161 typedef enum
    162 {
    163     RenderModeNormal     = 0,
    164     RenderModeSeamless   = 1,
    165     RenderModeHostWindow = 2
    166 } FramebufferRenderMode;
    167168
    168169/**
     
    198199
    199200#if defined (Q_OS_WIN32)
    200     STDMETHOD_(ULONG, AddRef)() {
     201
     202    STDMETHOD_(ULONG, AddRef)()
     203    {
    201204        return ::InterlockedIncrement (&refcnt);
    202205    }
     206
    203207    STDMETHOD_(ULONG, Release)()
    204208    {
     
    208212        return cnt;
    209213    }
     214
    210215    STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
    211216    {
     
    223228        return E_NOINTERFACE;
    224229    }
     230
    225231#endif
    226232
     
    229235    STDMETHOD(COMGETTER(Width)) (ULONG *aWidth);
    230236    STDMETHOD(COMGETTER(Height)) (ULONG *aHeight);
    231     STDMETHOD(COMGETTER(ColorDepth)) (ULONG *aColorDepth);
    232     STDMETHOD(COMGETTER(LineSize)) (ULONG *aLineSize);
    233     STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *aPixelFormat);
     237    STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *aBitsPerPixel);
     238    STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *aBytesPerLine);
     239    STDMETHOD(COMGETTER(PixelFormat)) (ULONG *aPixelFormat);
     240    STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *aUsesGuestVRAM);
    234241    STDMETHOD(COMGETTER(HeightReduction)) (ULONG *aHeightReduction);
    235242    STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
    236     STDMETHOD(COMGETTER(RenderMode)) (FramebufferRenderMode *renderMode);
    237     STDMETHOD(COMSETTER(RenderMode)) (FramebufferRenderMode  renderMode);
    238243
    239244    STDMETHOD(Lock)();
    240245    STDMETHOD(Unlock)();
    241246
    242     STDMETHOD(RequestResize) (ULONG aScreenId, FramebufferPixelFormat_T aPixelFormat,
    243                               BYTE *aVRAM, ULONG aLineSize,
     247    STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
     248                              BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
    244249                              ULONG aWidth, ULONG aHeight,
    245250                              BOOL *aFinished);
     
    257262    STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
    258263
    259     // Helper functions
    260     int width() { return mWdt; }
    261     int height() { return mHgt; }
    262 
    263     virtual FramebufferPixelFormat_T pixelFormat()
    264     {
    265         return FramebufferPixelFormat_PixelFormatOpaque;
     264    ulong width() { return mWdt; }
     265    ulong height() { return mHgt; }
     266
     267    virtual ulong pixelFormat()
     268    {
     269        return FramebufferPixelFormat_FOURCC_RGB;
     270    }
     271
     272    virtual bool usesGuestVRAM()
     273    {
     274        return false;
    266275    }
    267276
     
    270279
    271280    virtual uchar *address() = 0;
    272     virtual int colorDepth() = 0;
    273     virtual int lineSize() = 0;
     281    virtual ulong bitsPerPixel() = 0;
     282    virtual ulong bytesPerLine() = 0;
    274283
    275284    /**
     
    302311    int mHgt;
    303312
    304     /* Framebuffer render mode */
    305     FramebufferRenderMode mRenderMode;
    306 
    307313#if defined (Q_OS_WIN32)
    308314private:
     
    325331                             BOOL *aFinished);
    326332
     333    ulong pixelFormat() { return mPixelFormat; }
     334    bool usesGuestVRAM() { return mUsesGuestVRAM; }
     335
    327336    uchar *address() { return mImg.bits(); }
    328     int colorDepth() { return mImg.depth(); }
    329     int lineSize() { return mImg.bytesPerLine(); }
     337    ulong bitsPerPixel() { return mImg.depth(); }
     338    ulong bytesPerLine() { return mImg.bytesPerLine(); }
    330339
    331340    void paintEvent (QPaintEvent *pe);
     
    336345    QPixmap mPM;
    337346    QImage mImg;
     347    ulong mPixelFormat;
     348    bool mUsesGuestVRAM;
    338349};
    339350
     
    357368    uchar *address()
    358369    {
    359         if (mSurfVRAM)
    360         {
    361             return (uchar*) (mScreen ? (uintptr_t) mSurfVRAM->pixels : 0);
    362         }
    363         else
    364         {
    365             return (uchar*) (mScreen ? (uintptr_t) mScreen->pixels : 0);
    366         }
    367     }
    368 
    369     int colorDepth()
    370     {
    371         SDL_Surface *surf = mSurfVRAM ? mSurfVRAM: mScreen;
     370        SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
     371        return surf ? (uchar *) (uintptr_t) mScreen->pixels : 0;
     372    }
     373
     374    ulong bitsPerPixel()
     375    {
     376        SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
    372377        return surf ? surf->format->BitsPerPixel : 0;
    373378    }
    374379
    375     int lineSize()
    376     {
    377         SDL_Surface *surf = mSurfVRAM ? mSurfVRAM: mScreen;
     380    ulong bytesPerLine()
     381    {
     382        SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
    378383        return surf ? surf->pitch : 0;
    379384    }
    380385
    381     FramebufferPixelFormat_T pixelFormat()
     386    ulong pixelFormat()
    382387    {
    383388        return mPixelFormat;
     389    }
     390
     391    bool usesGuestVRAM()
     392    {
     393        return mSurfVRAM != NULL;
    384394    }
    385395
     
    392402    SDL_Surface *mSurfVRAM;
    393403
    394     uchar *mPtrVRAM;
    395     ULONG mLineSize;
    396     FramebufferPixelFormat_T mPixelFormat;
     404    ulong mPixelFormat;
    397405};
    398406
     
    414422                             BOOL *aFinished);
    415423
    416     uchar *address() { return (uchar *)mSurfaceDesc.lpSurface; }
    417     int colorDepth() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
    418     int lineSize() { return mSurfaceDesc.lPitch; }
    419 
    420     FramebufferPixelFormat_T pixelFormat() { return mPixelFormat; };
     424    uchar *address() { return (uchar *) mSurfaceDesc.lpSurface; }
     425    ulong bitsPerPixel() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
     426    ulong bytesPerLine() { return (ulong) mSurfaceDesc.lPitch; }
     427
     428    ulong pixelFormat() { return mPixelFormat; };
     429
     430    bool usesGuestVRAM() { return mUsesGuestVRAM; }
    421431
    422432    void paintEvent (QPaintEvent *pe);
     
    425435
    426436private:
     437
    427438    void releaseObjects();
    428439
    429     void setupSurface (FramebufferPixelFormat_T pixelFormat, uchar *pvVRAM, ULONG lineSize, ULONG w, ULONG h);
    430     void recreateSurface (FramebufferPixelFormat_T pixelFormat, uchar *pvVRAM, ULONG lineSize, ULONG w, ULONG h);
    431     void deleteSurface ();
     440    bool createSurface (ULONG aPixelFormat, uchar *pvVRAM,
     441                        ULONG aBitsPerPixel, ULONG aBytesPerLine,
     442                        ULONG aWidth, ULONG aHeight);
     443    void deleteSurface();
    432444    void drawRect (ULONG x, ULONG y, ULONG w, ULONG h);
    433445    void getWindowPosition (void);
     
    439451    LPDIRECTDRAWSURFACE7 mPrimarySurface;
    440452
    441     FramebufferPixelFormat_T mPixelFormat;
    442 
    443     BOOL mGuestVRAMSurface;
     453    ulong mPixelFormat;
     454
     455    bool mUsesGuestVRAM;
    444456
    445457    int mWndX;
    446458    int mWndY;
    447459
    448     BOOL mSynchronousUpdates;
     460    bool mSynchronousUpdates;
    449461};
    450462
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBDDRAW.cpp

    r3611 r3761  
    138138    mSurface (NULL),
    139139    mPrimarySurface (NULL),
    140     mPixelFormat (FramebufferPixelFormat_PixelFormatOpaque),
    141     mGuestVRAMSurface (FALSE),
     140    mPixelFormat (FramebufferPixelFormat_FOURCC_RGB),
     141    mUsesGuestVRAM (false),
    142142    mWndX (0),
    143143    mWndY (0),
    144     mSynchronousUpdates (TRUE)
     144    mSynchronousUpdates (true)
    145145{
    146146    memset (&mSurfaceDesc, 0, sizeof (mSurfaceDesc));
    147147
    148     LOGDDRAW(("DDRAW: Creating\n"));
     148    LOGDDRAW (("DDRAW: Creating\n"));
    149149
    150150    /* Release all created objects if something will go wrong. */
     
    167167                VBoxResizeEvent *re =
    168168                    new VBoxResizeEvent (FramebufferPixelFormat_PixelFormatOpaque,
    169                                          NULL, 0, 640, 480);
     169                                         NULL, 0, 0, 640, 480);
    170170
    171171                if (re)
     
    246246void VBoxDDRAWFrameBuffer::paintEvent (QPaintEvent *pe)
    247247{
    248     LOGDDRAW(("DDRAW: paintEvent %d,%d %dx%d\n", pe->rect().x(), pe->rect().y(), pe->rect().width(), pe->rect().height()));
    249 
    250     drawRect (pe->rect().x(), pe->rect().y(), pe->rect().width(), pe->rect().height());
     248    LOGDDRAW (("DDRAW: paintEvent %d,%d %dx%d\n",
     249               pe->rect().x(), pe->rect().y(),
     250               pe->rect().width(), pe->rect().height()));
     251
     252    drawRect (pe->rect().x(), pe->rect().y(),
     253              pe->rect().width(), pe->rect().height());
    251254}
    252255
    253256void VBoxDDRAWFrameBuffer::resizeEvent (VBoxResizeEvent *re)
    254257{
    255     LOGDDRAW(("DDRAW: resizeEvent %d, %p, %d %dx%d\n", re->pixelFormat (), re->vram (), re->lineSize (), re->width(), re->height()));
     258    LOGDDRAW (("DDRAW: resizeEvent %d, %p, %d %d %dx%d\n",
     259               re->pixelFormat(), re->VRAM(), re->bitsPerPixel(),
     260               re->bytesPerLine(), re->width(), re->height()));
    256261
    257262    VBoxFrameBuffer::resizeEvent (re);
    258263
    259     setupSurface (re->pixelFormat (), re->vram (), re->lineSize (), re->width(), re->height());
    260 
    261     getWindowPosition ();
     264    bool ok = createSurface (re->pixelFormat(), re->VRAM (), re->bitsPerPixel(),
     265                             re->bytesPerLine (), re->width(), re->height());
     266    if (!ok && re->pixelFormat() != FramebufferPixelFormat_PixelFormatOpaque)
     267    {
     268        /* try to create a fallback surface with indirect buffer
     269         * (only if haven't done so already) */
     270        ok = createSurface (FramebufferPixelFormat_PixelFormatOpaque,
     271                            NULL, 0, 0, re->width(), re->height());
     272    }
     273
     274    Assert (ok);
     275
     276    getWindowPosition();
    262277
    263278    mView->setBackgroundMode (Qt::NoBackground);
     
    266281void VBoxDDRAWFrameBuffer::moveEvent (QMoveEvent *me)
    267282{
    268     getWindowPosition ();
    269 }
    270 
     283    getWindowPosition();
     284}
    271285
    272286/*
     
    274288 */
    275289
    276 /* Setups a surface with requested format or a default surface if
    277  * requested format is not supportred.
    278  * Assigns VBoxDDRAWFrameBuffer::mSurface to the new surface
    279  * and VBoxDDRAWFrameBuffer::mPixelFormat to format of the created surface.
    280  */
    281 void VBoxDDRAWFrameBuffer::setupSurface (FramebufferPixelFormat_T pixelFormat, uchar *pvVRAM, ULONG lineSize, ULONG w, ULONG h)
    282 {
    283     /* Check requested pixel format. */
    284     switch (pixelFormat)
    285     {
    286         case FramebufferPixelFormat_PixelFormatRGB32:
    287         case FramebufferPixelFormat_PixelFormatRGB24:
    288         case FramebufferPixelFormat_PixelFormatRGB16:
    289         {
    290             /* Supported formats. Do nothing. */
    291             Assert(lineSize >= w);
    292         } break;
    293 
    294         default:
    295         {
    296             /* Unsupported format leads to use of the default format. */
    297             pixelFormat = FramebufferPixelFormat_PixelFormatOpaque;
    298         }
    299     }
    300 
    301     recreateSurface (pixelFormat, pvVRAM, lineSize, w, h);
    302 
    303     if (!mSurface && pixelFormat != FramebufferPixelFormat_PixelFormatOpaque)
    304     {
    305         /* Unable to create a new surface. Try to create a default format surface. */
    306         pixelFormat = FramebufferPixelFormat_PixelFormatOpaque;
    307         recreateSurface (pixelFormat, NULL, 0, w, h);
    308     }
    309 
    310     mPixelFormat = pixelFormat;
    311 }
    312 
    313 /* Deletes existing and creates a new surface with requested format.
    314  * Assigns VBoxDDRAWFrameBuffer::mSurface to the new surface if
    315  * the requested format is supported and the surface was successfully created.
    316  */
    317 void VBoxDDRAWFrameBuffer::recreateSurface (FramebufferPixelFormat_T pixelFormat, uchar *pvVRAM, ULONG lineSize, ULONG w, ULONG h)
    318 {
    319     HRESULT rc;
    320 
    321     deleteSurface ();
     290/**
     291 * Creates a new surface in the requested format.
     292 * On success, returns @c true and assigns the created surface to mSurface
     293 * and its definition to mSurfaceDesc. On failure, returns @c false.
     294 *
     295 * If @a aPixelFormat is other than FramebufferPixelFormat_PixelFormatOpaque,
     296 * then the method will attempt to attach @a aVRAM directly to the created
     297 * surface. If this fails, the caller may call this method again with
     298 * @a aPixelFormat set to FramebufferPixelFormat_PixelFormatOpaque to try
     299 * setting up an indirect fallback buffer for the surface. This opeartion may
     300 * theoretically also fail.
     301 *
     302 * @note Deletes the existing surface before attemting to create a new one.
     303 */
     304bool VBoxDDRAWFrameBuffer::createSurface (ULONG aPixelFormat, uchar *aVRAM,
     305                                          ULONG aBitsPerPixel, ULONG aBytesPerLine,
     306                                          ULONG aWidth, ULONG aHeight)
     307{
     308    deleteSurface();
    322309
    323310    DDSURFACEDESC2 sd;
     
    331318
    332319    sd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
    333     sd.dwWidth = w;
    334     sd.dwHeight = h;
    335 
    336     if (pixelFormat == FramebufferPixelFormat_PixelFormatOpaque)
    337     {
    338         /* Default format is a 32 bpp surface. */
    339         sd.lPitch = sd.dwWidth * 4;
    340     }
    341     else
    342     {
    343         sd.lPitch = lineSize;
    344     }
     320    sd.dwWidth = aWidth;
     321    sd.dwHeight = aHeight;
    345322
    346323    /* Setup the desired pixel format on the surface. */
     
    349326    sd.ddpfPixelFormat.dwFlags = DDPF_RGB;
    350327
    351     switch (pixelFormat)
    352     {
    353         case FramebufferPixelFormat_PixelFormatOpaque:
    354         case FramebufferPixelFormat_PixelFormatRGB32:
    355         {
    356             sd.ddpfPixelFormat.dwRGBBitCount = 32;
    357             sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
    358             sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
    359             sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
    360         } break;
    361 
    362         case FramebufferPixelFormat_PixelFormatRGB24:
    363         {
    364             sd.ddpfPixelFormat.dwRGBBitCount = 24;
    365             sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
    366             sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
    367             sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
    368         } break;
    369 
    370         case FramebufferPixelFormat_PixelFormatRGB16:
    371         {
    372             sd.ddpfPixelFormat.dwRGBBitCount = 16;
    373             sd.ddpfPixelFormat.dwRBitMask = 0xF800;
    374             sd.ddpfPixelFormat.dwGBitMask = 0x07E0;
    375             sd.ddpfPixelFormat.dwBBitMask = 0x001F;
    376         } break;
    377     }
    378 
    379     /* Allocate surface memory. */
    380     if (pvVRAM != NULL && pixelFormat != FramebufferPixelFormat_PixelFormatOpaque)
    381     {
    382         sd.lpSurface = pvVRAM;
    383         mGuestVRAMSurface = TRUE;
     328    if (aPixelFormat == FramebufferPixelFormat_FOURCC_RGB)
     329    {
     330        /* Try to use the guest VRAM directly */
     331
     332        switch (aBitsPerPixel)
     333        {
     334            case 32:
     335                sd.ddpfPixelFormat.dwRGBBitCount = 32;
     336                sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     337                sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     338                sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
     339                break;
     340            case 24:
     341                sd.ddpfPixelFormat.dwRGBBitCount = 24;
     342                sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     343                sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     344                sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
     345                break;
     346            case 16:
     347                sd.ddpfPixelFormat.dwRGBBitCount = 16;
     348                sd.ddpfPixelFormat.dwRBitMask = 0xF800;
     349                sd.ddpfPixelFormat.dwGBitMask = 0x07E0;
     350                sd.ddpfPixelFormat.dwBBitMask = 0x001F;
     351                break;
     352            default:
     353                /* we don't directly support any other color depth */               
     354                return false;
     355        }
     356
     357        sd.lPitch = (LONG) aBytesPerLine;
     358
     359        sd.lpSurface = aVRAM;
     360        mUsesGuestVRAM = true;
     361
     362        mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
    384363    }
    385364    else
    386     {
     365    if (aPixelFormat != FramebufferPixelFormat_PixelFormatOpaque)
     366    {
     367        /* we don't directly support any other pixel format */               
     368        return false;
     369    }
     370    else
     371    {
     372        /* for the Opaque format, we use the indirect memory buffer as a
     373         * 32 bpp surface. */
     374
     375        sd.ddpfPixelFormat.dwRGBBitCount = 32;
     376        sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     377        sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     378        sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
     379
     380        sd.lPitch = sd.dwWidth * 4;
     381
     382        /* Allocate the memory buffer for the surface */
    387383        sd.lpSurface = RTMemAlloc (sd.lPitch * sd.dwHeight);
    388     }
    389 
    390     if (!sd.lpSurface)
    391     {
    392         LOGDDRAW(("DDRAW: could not allocate memory for surface.\n"));
    393         return;
    394     }
    395 
    396     rc = mDDRAW->CreateSurface (&sd, &mSurface, NULL);
     384        if (sd.lpSurface == NULL)
     385        {
     386            LOGDDRAW (("DDRAW: could not allocate memory for surface.\n"));
     387            return false;
     388        }
     389        mUsesGuestVRAM = false;
     390
     391        mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
     392    }
     393
     394    /* create the surface */
     395    HRESULT rc = mDDRAW->CreateSurface (&sd, &mSurface, NULL);
    397396
    398397    if (rc != DD_OK)
    399398    {
    400         LOGDDRAW(("DDRAW: Could not create DirectDraw surface rc = 0x%08X\n", rc));
    401     }
    402     else
    403     {
    404         /* Initialize the surface description. It will be used to obtain address, lineSize and bpp. */
    405         mSurfaceDesc = sd;
    406 
    407         LOGDDRAW(("DDRAW: Created %s surface: format = %d, address = %p\n",
    408                   mGuestVRAMSurface ? "GuestVRAM": "system memory",
    409                   pixelFormat, address ()));
    410     }
    411 
    412     if (rc != DD_OK)
    413     {
    414         deleteSurface ();
    415     }
    416     else
    417     {
    418         if (!mGuestVRAMSurface)
    419         {
    420             /* Clear just created surface. */
    421             memset (this->address (), 0, this->lineSize () * this->height ());
    422         }
    423     }
     399        LOGDDRAW (("DDRAW: Could not create DirectDraw surface, rc=0x%08X\n", rc));
     400        deleteSurface();
     401        return false;
     402    }
     403   
     404    /* Initialize the surface description member. It will be used to obtain
     405     * address, bpp and bpl. */
     406    mSurfaceDesc = sd;
     407   
     408    LOGDDRAW(("DDRAW: Created %s surface: format = %d, address = %p\n",
     409              mUsesGuestVRAM ? "GuestVRAM": "system memory",
     410              aPixelFormat, address ()));
     411
     412    if (!mUsesGuestVRAM)
     413    {
     414        /* Clear just created surface. */
     415        memset (address(), 0, bytesPerLine() * height());
     416    }
     417
     418    return true;
    424419}
    425420
     
    431426        mSurface = NULL;
    432427
    433         if (!mGuestVRAMSurface)
     428        if (!mUsesGuestVRAM)
    434429        {
    435430            RTMemFree (mSurfaceDesc.lpSurface);
     
    437432
    438433        memset (&mSurfaceDesc, '\0', sizeof (mSurfaceDesc));
    439         mGuestVRAMSurface = FALSE;
    440     }
    441 }
    442 
    443 /* Draw a rectangular area of guest screen DDRAW surface onto the
     434        mUsesGuestVRAM = false;
     435    }
     436}
     437
     438/**
     439 * Draws a rectangular area of guest screen DDRAW surface onto the
    444440 * host screen primary surface.
    445441 */
    446442void VBoxDDRAWFrameBuffer::drawRect (ULONG x, ULONG y, ULONG w, ULONG h)
    447443{
    448     LOGDDRAW(("DDRAW: drawRect: %d,%d, %dx%d\n", x, y, w, h));
     444    LOGDDRAW (("DDRAW: drawRect: %d,%d, %dx%d\n", x, y, w, h));
    449445
    450446    if (mSurface && w > 0 && h > 0)
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFrameBuffer.cpp

    r3747 r3761  
    4949{
    5050    AssertMsg (mView, ("VBoxConsoleView must not be null\n"));
    51 
    52     /* Default framebuffer render mode is normal (draw the entire framebuffer) */
    53     mRenderMode = RenderModeNormal;
    5451}
    5552
     
    8683}
    8784
    88 STDMETHODIMP VBoxFrameBuffer::COMGETTER(ColorDepth) (ULONG *aColorDepth)
    89 {
    90     if (!aColorDepth)
    91         return E_POINTER;
    92     *aColorDepth = (ULONG) colorDepth();
    93     return S_OK;
    94 }
    95 
    96 STDMETHODIMP VBoxFrameBuffer::COMGETTER(LineSize) (ULONG *aLineSize)
    97 {
    98     if (!aLineSize)
    99         return E_POINTER;
    100     *aLineSize = (ULONG) lineSize();
     85STDMETHODIMP VBoxFrameBuffer::COMGETTER(BitsPerPixel) (ULONG *aBitsPerPixel)
     86{
     87    if (!aBitsPerPixel)
     88        return E_POINTER;
     89    *aBitsPerPixel = bitsPerPixel();
     90    return S_OK;
     91}
     92
     93STDMETHODIMP VBoxFrameBuffer::COMGETTER(BytesPerLine) (ULONG *aBytesPerLine)
     94{
     95    if (!aBytesPerLine)
     96        return E_POINTER;
     97    *aBytesPerLine = bytesPerLine();
    10198    return S_OK;
    10299}
    103100
    104101STDMETHODIMP VBoxFrameBuffer::COMGETTER(PixelFormat) (
    105     FramebufferPixelFormat_T *aPixelFormat)
     102    ULONG *aPixelFormat)
    106103{
    107104    if (!aPixelFormat)
    108105        return E_POINTER;
    109106    *aPixelFormat = pixelFormat();
     107    return S_OK;
     108}
     109
     110STDMETHODIMP VBoxFrameBuffer::COMGETTER(UsesGuestVRAM) (
     111    BOOL *aUsesGuestVRAM)
     112{
     113    if (!aUsesGuestVRAM)
     114        return E_POINTER;
     115    *aUsesGuestVRAM = usesGuestVRAM();
    110116    return S_OK;
    111117}
     
    129135}
    130136
    131 /**
    132  * Return the current framebuffer render mode
    133  *
    134  * @returns COM status code
    135  * @param   renderMode  framebuffer render mode
    136  */
    137 STDMETHODIMP VBoxFrameBuffer::COMGETTER(RenderMode) (FramebufferRenderMode *renderMode)
    138 {
    139     if (!renderMode)
    140         return E_POINTER;
    141     *renderMode = mRenderMode;
    142     return S_OK;
    143 }
    144 
    145 /**
    146  * Change the current framebuffer render mode
    147  *
    148  * @returns COM status code
    149  * @param   renderMode  framebuffer render mode
    150  */
    151 STDMETHODIMP VBoxFrameBuffer::COMSETTER(RenderMode) (FramebufferRenderMode renderMode)
    152 {
    153     if (!renderMode)
    154         return E_POINTER;
    155     mRenderMode = renderMode;
    156     return S_OK;
    157 }
    158 
    159137STDMETHODIMP VBoxFrameBuffer::Lock()
    160138{
     
    170148
    171149/** @note This method is called on EMT from under this object's lock */
    172 STDMETHODIMP VBoxFrameBuffer::RequestResize (ULONG aScreenId, FramebufferPixelFormat_T aPixelFormat,
    173                                              BYTE *aVRAM, ULONG aLineSize,
     150STDMETHODIMP VBoxFrameBuffer::RequestResize (ULONG aScreenId, ULONG aPixelFormat,
     151                                             BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
    174152                                             ULONG aWidth, ULONG aHeight,
    175153                                             BOOL *aFinished)
    176154{
    177155    QApplication::postEvent (mView,
    178                              new VBoxResizeEvent (aPixelFormat, aVRAM,
    179                                                   aLineSize, aWidth, aHeight));
     156                             new VBoxResizeEvent (aPixelFormat, aVRAM, aBitsPerPixel,
     157                                                  aBytesPerLine, aWidth, aHeight));
    180158
    181159#ifdef DEBUG_sunlover
    182     Log(("VBoxFrameBuffer::RequestResize: pixelFormat %d, vram %p, lineSize %d, w %d, h %d\n",
    183           aPixelFormat, aVRAM, aLineSize, aWidth, aHeight));
     160    LogFlowFunc (("pixelFormat=%d, vram=%p, bpp=%d, bpl=%d, w=%d, h=%d\n",
     161          aPixelFormat, aVRAM, aBitsPerPixel, aBytesPerLine, aWidth, aHeight));
    184162#endif /* DEBUG_sunlover */
    185163
     
    316294{
    317295    resizeEvent (new VBoxResizeEvent (FramebufferPixelFormat_PixelFormatOpaque,
    318                                       NULL, 0, 640, 480));
     296                                      NULL, 0, 0, 640, 480));
    319297}
    320298
     
    349327        return;
    350328
    351 //    LogFlowFunc (("%d,%d-%d,%d (img: %d,%d)\n",
    352 //                  r.x(), r.y(), r.width(), r.height(),
    353 //                  img.width(), img.height()));
     329#if 0
     330    LogFlowFunc (("%dx%d-%dx%d (img=%dx%d)\n",
     331                  r.x(), r.y(), r.width(), r.height(),
     332                  img.width(), img.height()));
     333#endif
    354334
    355335    FRAMEBUF_DEBUG_START (xxx);
     
    385365void VBoxQImageFrameBuffer::resizeEvent (VBoxResizeEvent *re)
    386366{
     367#if 0
     368    LogFlowFunc (("fmt=%d, vram=%p, bpp=%d, bpl=%d, width=%d, height=%d\n",
     369                  re->pixelFormat(), re->VRAM(),
     370                  re->bitsPerPixel(), re->bytesPerLine(),
     371                  re->width(), re->height()));
     372#endif
     373
    387374    mWdt = re->width();
    388375    mHgt = re->height();
    389376
    390377    mImg = QImage (mWdt, mHgt, 32, 0, QImage::LittleEndian);
     378    mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
     379    mUsesGuestVRAM = false;
    391380}
    392381
     
    409398{
    410399    mScreen = NULL;
    411     mPixelFormat = FramebufferPixelFormat_PixelFormatOpaque;
    412     mPtrVRAM = NULL;
     400    mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
    413401    mSurfVRAM = NULL;
    414     mLineSize = 0;
    415402
    416403    resizeEvent (new VBoxResizeEvent (FramebufferPixelFormat_PixelFormatOpaque,
    417                                       NULL, 0, 640, 480));
     404                                      NULL, 0, 0, 640, 480));
    418405}
    419406
     
    422409    if (mSurfVRAM)
    423410    {
    424         SDL_FreeSurface(mSurfVRAM);
     411        SDL_FreeSurface (mSurfVRAM);
    425412        mSurfVRAM = NULL;
    426413    }
     
    470457}
    471458
    472 void VBoxSDLFrameBuffer::resizeEvent( VBoxResizeEvent *re )
     459void VBoxSDLFrameBuffer::resizeEvent (VBoxResizeEvent *re)
    473460{
    474461    mWdt = re->width();
     
    492479     */
    493480    static char sdlHack[64];
    494     sprintf (sdlHack, "SDL_WINDOWID=0x%lx", mView->viewport()->winId());
     481    LogFlowFunc (("Using client window 0x%08lX to initialize SDL\n",
     482                  mView->viewport()->winId()));
     483    /* Note: SDL_WINDOWID must be decimal (not hex) to work on Win32 */
     484    sprintf (sdlHack, "SDL_WINDOWID=%lu", mView->viewport()->winId());
    495485    putenv (sdlHack);
    496486    int rc = SDL_InitSubSystem (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
    497     AssertMsg (rc == 0, ("SDL initialization failed!\n"));
     487    AssertMsg (rc == 0, ("SDL initialization failed: %s\n", SDL_GetError()));
    498488    NOREF(rc);
    499489
     
    506496    LogFlowFunc (("Setting SDL video mode to %d x %d\n", mWdt, mHgt));
    507497
    508     mPixelFormat = re->pixelFormat();
    509     mPtrVRAM = re->vram();
    510     mLineSize = re->lineSize();
    511 
    512     int bitsPerPixel = 0;
     498    bool fallback = false;
    513499
    514500    Uint32 Rmask = 0;
    515501    Uint32 Gmask = 0;
    516502    Uint32 Bmask = 0;
    517     Uint32 Amask = 0;
    518 
    519     switch (mPixelFormat)
    520     {
    521         case FramebufferPixelFormat_PixelFormatRGB32:
     503   
     504    if (re->pixelFormat() == FramebufferPixelFormat_FOURCC_RGB)
     505    {
     506        switch (re->bitsPerPixel())
    522507        {
    523             bitsPerPixel = 32;
    524             Rmask = 0x00FF0000;
    525             Gmask = 0x0000FF00;
    526             Bmask = 0x000000FF;
    527         } break;
    528 
    529         case FramebufferPixelFormat_PixelFormatRGB24:
     508            case 32:
     509                Rmask = 0x00FF0000;
     510                Gmask = 0x0000FF00;
     511                Bmask = 0x000000FF;
     512                break;
     513            case 24:
     514                Rmask = 0x00FF0000;
     515                Gmask = 0x0000FF00;
     516                Bmask = 0x000000FF;
     517                break;
     518            case 16:
     519                Rmask = 0xF800;
     520                Gmask = 0x07E0;
     521                Bmask = 0x001F;
     522            default:
     523                /* Unsupported format leads to the indirect buffer */
     524                fallback = true;
     525                break;
     526        }
     527
     528        if (!fallback)
    530529        {
    531             bitsPerPixel = 24;
    532             Rmask = 0x00FF0000;
    533             Gmask = 0x0000FF00;
    534             Bmask = 0x000000FF;
    535         } break;
    536 
    537         case FramebufferPixelFormat_PixelFormatRGB16:
    538         {
    539             bitsPerPixel = 16;
    540             Rmask = 0xF800;
    541             Gmask = 0x07E0;
    542             Bmask = 0x001F;
    543         } break;
    544 
    545         default:
    546         {
    547             /* Unsupported format leads to use of the default format. */
    548             mPixelFormat = FramebufferPixelFormat_PixelFormatOpaque;
     530            /* Create a source surface from guest VRAM. */
     531            mSurfVRAM = SDL_CreateRGBSurfaceFrom(re->VRAM(), mWdt, mHgt,
     532                                                 re->bitsPerPixel(),
     533                                                 re->bytesPerLine(),
     534                                                 Rmask, Gmask, Bmask, 0);
     535            LogFlowFunc (("Created VRAM surface %p\n", mSurfVRAM));
     536            if (mSurfVRAM == NULL)
     537                fallback = true;
    549538        }
    550539    }
    551 
    552     if (mPixelFormat != FramebufferPixelFormat_PixelFormatOpaque)
    553     {
    554         /* Create a source surface from guest VRAM. */
    555         mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mWdt, mHgt, bitsPerPixel,
    556                                              mLineSize, Rmask, Gmask, Bmask, Amask);
    557         LogFlowFunc (("Created VRAM surface %p\n", mSurfVRAM));
    558     }
     540    else
     541    {
     542        /* Unsupported format leads to the indirect buffer */
     543        fallback = true;
     544    }
     545
     546    /* Pixel format is RGB in any case */
     547    mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
    559548
    560549    mScreen = SDL_SetVideoMode (mWdt, mHgt, 0,
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