VirtualBox

Ignore:
Timestamp:
Jun 9, 2009 12:40:36 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48381
Message:

VBoxSDL: made it compile with SDL1.3 to support multiple guest monitors (disabled)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp

    r19844 r20433  
    6666}
    6767#endif /* VBOX_SECURELABEL */
     68
     69static SDL_Surface *gWMIcon;                    /**< the application icon */
     70static RTNATIVETHREAD gSdlNativeThread;         /**< the SDL thread */
    6871
    6972//
     
    8386 * @param iFixedHeight   fixed SDL height (-1 means not set)
    8487 */
    85 VBoxSDLFB::VBoxSDLFB(bool fFullscreen, bool fResizable, bool fShowSDLConfig,
     88VBoxSDLFB::VBoxSDLFB(uint32_t uScreenId,
     89                     bool fFullscreen, bool fResizable, bool fShowSDLConfig,
    8690                     bool fKeepHostRes, uint32_t u32FixedWidth,
    8791                     uint32_t u32FixedHeight, uint32_t u32FixedBPP)
     
    9498#endif
    9599
     100    mScreenId       = uScreenId;
    96101    mScreen         = NULL;
     102#ifdef VBOX_WITH_SDL13
     103    mWindow         = 0;
     104    mTexture        = 0;
     105#endif
    97106    mSurfVRAM       = NULL;
    98107    mfInitialized   = false;
     
    105114    mFixedSDLHeight = u32FixedHeight;
    106115    mFixedSDLBPP    = u32FixedBPP;
    107     mDefaultSDLBPP  = 32;
    108116    mCenterXOffset  = 0;
    109117    mCenterYOffset  = 0;
     
    122130    mLabelOffs      = 0;
    123131#endif
    124     mWMIcon         = NULL;
    125 
    126     /* memorize the thread that inited us, that's the SDL thread */
    127     mSdlNativeThread = RTThreadNativeSelf();
    128132
    129133    rc = RTCritSectInit(&mUpdateLock);
    130134    AssertMsg(rc == VINF_SUCCESS, ("Error from RTCritSectInit!\n"));
     135
     136    resizeGuest();
     137    Assert(mScreen);
     138    mfInitialized = true;
     139}
     140
     141VBoxSDLFB::~VBoxSDLFB()
     142{
     143    LogFlow(("VBoxSDLFB::~VBoxSDLFB\n"));
     144    if (mSurfVRAM)
     145    {
     146        SDL_FreeSurface(mSurfVRAM);
     147        mSurfVRAM = NULL;
     148    }
     149    mScreen = NULL;
     150
     151#ifdef VBOX_SECURELABEL
     152    if (mLabelFont)
     153        pTTF_CloseFont(mLabelFont);
     154    if (pTTF_Quit)
     155        pTTF_Quit();
     156#endif
     157
     158    RTCritSectDelete(&mUpdateLock);
     159}
     160
     161void VBoxSDLFB::init(bool fShowSDLConfig)
     162{
     163    LogFlow(("VBoxSDLFB::init\n"));
     164
     165    /* memorize the thread that inited us, that's the SDL thread */
     166    gSdlNativeThread = RTThreadNativeSelf();
    131167
    132168#ifdef RT_OS_WINDOWS
     
    143179    RTEnvSet("SDL_VIDEO_X11_DGAMOUSE", "0");
    144180#endif
    145     rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
     181    int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
    146182    if (rc != 0)
    147183    {
     
    154190    if (videoInfo)
    155191    {
    156         switch (videoInfo->vfmt->BitsPerPixel)
    157         {
    158             case 16: mDefaultSDLBPP = 16; break;
    159             case 24: mDefaultSDLBPP = 24; break;
    160             default:
    161             case 32: mDefaultSDLBPP = 32; break;
    162         }
    163 
    164192        /* output what SDL is capable of */
    165         if (mfShowSDLConfig)
     193        if (fShowSDLConfig)
    166194            RTPrintf("SDL capabilities:\n"
    167195                     "  Hardware surface support:                    %s\n"
     
    193221    if (12320 == g_cbIco64x01)
    194222    {
    195         mWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0);
     223        gWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0);
    196224        /** @todo make it as simple as possible. No PNM interpreter here... */
    197         if (mWMIcon)
     225        if (gWMIcon)
    198226        {
    199             memcpy(mWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32);
    200             SDL_WM_SetIcon(mWMIcon, NULL);
     227            memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32);
     228            SDL_WM_SetIcon(gWMIcon, NULL);
    201229        }
    202230    }
    203 
    204     resizeGuest();
    205     Assert(mScreen);
    206     mfInitialized = true;
    207 }
    208 
    209 VBoxSDLFB::~VBoxSDLFB()
    210 {
    211     LogFlow(("VBoxSDLFB::~VBoxSDLFB\n"));
    212     RTCritSectDelete(&mUpdateLock);
    213 }
    214 
     231}
     232
     233/**
     234 * Terminate SDL
     235 *
     236 * @remarks must be called from the SDL thread!
     237 */
     238void VBoxSDLFB::uninit()
     239{
     240    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
     241    SDL_QuitSubSystem(SDL_INIT_VIDEO);
     242    if (gWMIcon)
     243    {
     244        SDL_FreeSurface(gWMIcon);
     245        gWMIcon = NULL;
     246    }
     247}
    215248
    216249/**
     
    280313        return E_INVALIDARG;
    281314
    282     if (mSurfVRAM)
    283     {
    284         *address = (BYTE *) mSurfVRAM->pixels;
    285     }
    286     else
     315    if (!mSurfVRAM)
    287316    {
    288317        /* That's actually rather bad. */
     
    290319        return E_FAIL;
    291320    }
     321
     322    *address = (BYTE *) mSurfVRAM->pixels;
    292323    LogFlow(("VBoxSDL::GetAddress returning %p\n", *address));
    293324    return S_OK;
     
    425456    SDL_Event event;
    426457    event.type       = SDL_USEREVENT;
     458    event.user.code  = mScreenId;
    427459    event.user.type  = SDL_USER_EVENT_UPDATERECT;
    428460    // 16 bit is enough for coordinates
     
    502534    event.type       = SDL_USEREVENT;
    503535    event.user.type  = SDL_USER_EVENT_RESIZE;
     536    event.user.code  = mScreenId;
    504537
    505538    /* Try multiple times if necessary */
     
    593626{
    594627    LogFlowFunc (("mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes));
    595     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(),
     628    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(),
    596629              ("Wrong thread! SDL is not threadsafe!\n"));
    597630
     
    643676    if (mUsesGuestVRAM)
    644677    {
    645 
    646678        /* Create a source surface from guest VRAM. */
    647679        mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, mBitsPerPixel,
    648680                                             mBytesPerLine, Rmask, Gmask, Bmask, Amask);
     681        LogRel(("mSurfVRAM from guest %d x %d\n", mGuestXRes,  mGuestYRes));
    649682    }
    650683    else
     
    653686        mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, mBitsPerPixel,
    654687                                         Rmask, Gmask, Bmask, Amask);
     688        LogRel(("mSurfVRAM from SDL %d x %d\n", mGuestXRes,  mGuestYRes));
    655689    }
    656690    LogFlow(("VBoxSDL:: created VRAM surface %p\n", mSurfVRAM));
     
    751785    mTopOffset = 0;
    752786
     787#if defined(VBOX_WITH_SDL13)
     788    int sdlWindowFlags = SDL_WINDOW_SHOWN;
     789    if (mfResizable)
     790        sdlWindowFlags |= SDL_WINDOW_RESIZABLE;
     791    if (!mWindow)
     792    {
     793        SDL_DisplayMode desktop_mode;
     794        int x = 40 + mScreenId * 20;
     795        int y = 40 + mScreenId * 15;
     796
     797        SDL_GetDesktopDisplayMode(&desktop_mode);
     798        /* create new window */
     799       
     800        char szTitle[64];
     801        RTStrPrintf(szTitle, sizeof(szTitle), "SDL window %d", mScreenId);
     802        mWindow = SDL_CreateWindow(szTitle, x, y,
     803                                   newWidth, newHeight, sdlWindowFlags);
     804        if (SDL_CreateRenderer(mWindow, -1,
     805                               SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD) < 0)
     806            AssertReleaseFailed();
     807
     808        SDL_GetRendererInfo(&mRenderInfo);
     809
     810        mTexture = SDL_CreateTexture(desktop_mode.format,
     811                                     SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight);
     812        if (!mTexture)
     813            AssertReleaseFailed();
     814    }
     815    else
     816    {
     817        int w, h;
     818        uint32_t format;
     819        int access;
     820
     821        /* resize current window */
     822        SDL_GetWindowSize(mWindow, &w, &h);
     823
     824        if (w != (int)newWidth || h != (int)newHeight)
     825            SDL_SetWindowSize(mWindow, newWidth, newHeight);
     826
     827        SDL_QueryTexture(mTexture, &format, &access, &w, &h);
     828        SDL_SelectRenderer(mWindow);
     829        SDL_DestroyTexture(mTexture);
     830        mTexture = SDL_CreateTexture(format, access, newWidth, newHeight);
     831        if (!mTexture)
     832            AssertReleaseFailed();
     833    }
     834
     835    void *pixels;
     836    int pitch;
     837    int w, h, bpp;
     838    uint32_t Rmask, Gmask, Bmask, Amask;
     839    uint32_t format;
     840
     841    if (SDL_QueryTexture(mTexture, &format, NULL, &w, &h) < 0)
     842        AssertReleaseFailed();
     843
     844    if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask))
     845        AssertReleaseFailed();
     846
     847    if (SDL_QueryTexturePixels(mTexture, &pixels, &pitch) == 0)
     848    {
     849        mScreen = SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch,
     850                                           Rmask, Gmask, Bmask, Amask);
     851    }
     852    else
     853    {
     854        mScreen = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
     855        AssertReleaseFailed();
     856    }
     857
     858    SDL_SetClipRect(mScreen, NULL);
     859
     860#else
    753861    /*
    754862     * Now set the screen resolution and get the surface pointer
     
    756864     */
    757865    mScreen = SDL_SetVideoMode(newWidth, newHeight, 0, sdlFlags);
     866#endif
    758867#ifdef VBOX_SECURELABEL
    759868    /*
     
    816925{
    817926#ifdef VBOXSDL_WITH_X11
    818     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
     927    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    819928#endif
    820929    Assert(mScreen);
     
    822931    if (!mScreen || !mSurfVRAM)
    823932        return;
    824 
     933   
    825934    /* the source and destination rectangles */
    826935    SDL_Rect srcRect;
     
    880989    dstRect.h = RT_MAX(0, h - yCutoffGuest);
    881990
    882     //RTPrintf("y = %d h = %d mapped to srcY %d srcH %d mapped to dstY = %d dstH %d (guestrel: %d, mLabelHeight: %d, mTopOffset: %d)\n",
    883     //         y, h, srcRect.y, srcRect.h, dstRect.y, dstRect.h, fGuestRelative, mLabelHeight, mTopOffset);
    884 
    885991    /*
    886992     * Now we just blit
     
    888994    SDL_BlitSurface(mSurfVRAM, &srcRect, mScreen, &dstRect);
    889995    /* hardware surfaces don't need update notifications */
     996#if defined(VBOX_WITH_SDL13)
     997    AssertRelease(mScreen->flags & SDL_PREALLOC);
     998    SDL_SelectRenderer(mWindow);
     999    SDL_DirtyTexture(mTexture, 1, &dstRect);
     1000    AssertRelease(mRenderInfo.flags & SDL_RENDERER_PRESENTCOPY);
     1001    SDL_RenderCopy(mTexture, &dstRect, &dstRect);
     1002    SDL_RenderPresent();
     1003#else
    8901004    if ((mScreen->flags & SDL_HWSURFACE) == 0)
    8911005        SDL_UpdateRect(mScreen, dstRect.x, dstRect.y, dstRect.w, dstRect.h);
     1006#endif
    8921007
    8931008#ifdef VBOX_SECURELABEL
     
    9041019void VBoxSDLFB::repaint()
    9051020{
    906     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
     1021    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    9071022    LogFlow(("VBoxSDLFB::repaint\n"));
    9081023    update(0, 0, mScreen->w, mScreen->h, false /* fGuestRelative */);
    9091024}
    9101025
    911 bool VBoxSDLFB::getFullscreen()
    912 {
    913     LogFlow(("VBoxSDLFB::getFullscreen\n"));
    914     return mfFullscreen;
    915 }
    916 
    9171026/**
    9181027 * Toggle fullscreen mode
     
    9221031void VBoxSDLFB::setFullscreen(bool fFullscreen)
    9231032{
    924     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
     1033    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    9251034    LogFlow(("VBoxSDLFB::SetFullscreen: fullscreen: %d\n", fFullscreen));
    9261035    mfFullscreen = fFullscreen;
     
    9651074}
    9661075
    967 /**
    968  * Returns the current x offset of the start of the guest screen
    969  *
    970  * @returns current x offset in pixels
    971  */
    972 int VBoxSDLFB::getXOffset()
    973 {
    974     /* there can only be an offset for centering */
    975     return mCenterXOffset;
    976 }
    977 
    978 /**
    979  * Returns the current y offset of the start of the guest screen
    980  *
    981  * @returns current y offset in pixels
    982  */
    983 int VBoxSDLFB::getYOffset()
    984 {
    985     /* we might have a top offset and a center offset */
    986     return mTopOffset + mCenterYOffset;
    987 }
    988 
    9891076#ifdef VBOX_SECURELABEL
    9901077/**
     
    10511138{
    10521139#ifdef VBOXSDL_WITH_X11
    1053     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
     1140    AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    10541141#endif
    10551142    /* only when the function is present */
     
    10861173}
    10871174#endif /* VBOX_SECURELABEL */
    1088 
    1089 /**
    1090  * Terminate SDL
    1091  *
    1092  * @remarks must be called from the SDL thread!
    1093  */
    1094 void VBoxSDLFB::uninit()
    1095 {
    1096     AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    1097     if (mSurfVRAM)
    1098     {
    1099         SDL_FreeSurface(mSurfVRAM);
    1100         mSurfVRAM = NULL;
    1101     }
    1102     SDL_QuitSubSystem(SDL_INIT_VIDEO);
    1103 #ifdef VBOX_SECURELABEL
    1104     if (mLabelFont)
    1105         pTTF_CloseFont(mLabelFont);
    1106     if (pTTF_Quit)
    1107         pTTF_Quit();
    1108 #endif
    1109     mScreen = NULL;
    1110     if (mWMIcon)
    1111     {
    1112         SDL_FreeSurface(mWMIcon);
    1113         mWMIcon = NULL;
    1114     }
    1115 }
    11161175
    11171176// IFramebufferOverlay
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