VirtualBox

Changeset 41215 in vbox


Ignore:
Timestamp:
May 8, 2012 6:00:42 PM (13 years ago)
Author:
vboxsync
Message:

Frontends/VBoxSDL: clean up framebuffer implementation in a COM-compatible fashion

Location:
trunk/src/VBox/Frontends/VBoxSDL
Files:
3 edited

Legend:

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

    r41002 r41215  
    7575//
    7676
    77 /**
    78  * SDL framebuffer constructor. It is called from the main
     77HRESULT VBoxSDLFB::FinalConstruct()
     78{
     79    return S_OK;
     80}
     81
     82/**
     83 * SDL framebuffer init method. It is called from the main
    7984 * (i.e. SDL) thread. Therefore it is safe to use SDL calls
    8085 * here.
     86 * @returns COM status code
    8187 * @param fFullscreen    flag whether we start in fullscreen mode
    8288 * @param fResizable     flag whether the SDL window should be resizable
     
    8793 * @param iFixedHeight   fixed SDL height (-1 means not set)
    8894 */
    89 VBoxSDLFB::VBoxSDLFB(uint32_t uScreenId,
    90                      bool fFullscreen, bool fResizable, bool fShowSDLConfig,
    91                      bool fKeepHostRes, uint32_t u32FixedWidth,
    92                      uint32_t u32FixedHeight, uint32_t u32FixedBPP)
     95HRESULT VBoxSDLFB::init(uint32_t uScreenId,
     96                        bool fFullscreen, bool fResizable, bool fShowSDLConfig,
     97                        bool fKeepHostRes, uint32_t u32FixedWidth,
     98                        uint32_t u32FixedHeight, uint32_t u32FixedBPP)
    9399{
    94100    int rc;
    95     LogFlow(("VBoxSDLFB::VBoxSDLFB\n"));
    96 
    97 #if defined (RT_OS_WINDOWS)
    98     refcnt = 0;
    99 #endif
     101    LogFlow(("VBoxSDLFB::init\n"));
    100102
    101103    mScreenId       = uScreenId;
     
    138140    Assert(mScreen);
    139141    mfInitialized = true;
    140 }
    141 
    142 VBoxSDLFB::~VBoxSDLFB()
    143 {
    144     LogFlow(("VBoxSDLFB::~VBoxSDLFB\n"));
     142
     143    return S_OK;
     144}
     145
     146void VBoxSDLFB::FinalRelease()
     147{
     148    uninit();
     149}
     150
     151void VBoxSDLFB::uninit()
     152{
     153    LogFlow(("VBoxSDLFB::uninit\n"));
    145154    if (mSurfVRAM)
    146155    {
     
    160169}
    161170
    162 bool VBoxSDLFB::init(bool fShowSDLConfig)
     171bool VBoxSDLFB::initSDL(bool fShowSDLConfig)
    163172{
    164173    LogFlow(("VBoxSDLFB::init\n"));
     
    240249 * @remarks must be called from the SDL thread!
    241250 */
    242 void VBoxSDLFB::uninit()
     251void VBoxSDLFB::uninitSDL()
    243252{
    244253    if (gfSdlInitialized)
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.h

    r41201 r41215  
    4343
    4444class VBoxSDLFB :
     45    public CComObjectRootEx<CComMultiThreadModelNoCS>,
    4546    VBOX_SCRIPTABLE_IMPL(IFramebuffer)
    4647{
    4748public:
    48     VBoxSDLFB(uint32_t uScreenId,
    49               bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
    50               bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
    51               uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
    52     virtual ~VBoxSDLFB();
    53 
    54     static bool init(bool fShowSDLConfig);
    55     static void uninit();
    56 
    57 #ifdef RT_OS_WINDOWS
    58     STDMETHOD_(ULONG, AddRef)()
    59     {
    60         return ::InterlockedIncrement (&refcnt);
    61     }
    62     STDMETHOD_(ULONG, Release)()
    63     {
    64         long cnt = ::InterlockedDecrement (&refcnt);
    65         if (cnt == 0)
    66             delete this;
    67         return cnt;
    68     }
    69 #endif
     49    DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
     50
     51    DECLARE_PROTECT_FINAL_CONSTRUCT()
     52
     53    VBoxSDLFB() { /* empty */ }
     54    ~VBoxSDLFB() { /* empty */ }
     55
     56    HRESULT FinalConstruct();
     57    void FinalRelease();
     58
     59    HRESULT init(uint32_t uScreenId,
     60                 bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
     61                 bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
     62                 uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
     63    void uninit();
     64
     65    static bool initSDL(bool fShowSDLConfig);
     66    static void uninitSDL();
    7067
    7168    BEGIN_COM_MAP(VBoxSDLFB)
    72         VBOX_DEFAULT_INTERFACE_ENTRIES(IFramebuffer)
     69        VBOX_MINIMAL_INTERFACE_ENTRIES(IFramebuffer)
    7370    END_COM_MAP()
    7471
     
    188185    /** secure label offset from the top of the secure label */
    189186    uint32_t mLabelOffs;
    190 
    191 #endif
    192 #ifdef RT_OS_WINDOWS
    193     long refcnt;
    194 #endif
     187#endif
     188
    195189    SDL_Surface *mSurfVRAM;
    196190
     
    204198
    205199class VBoxSDLFBOverlay :
    206     public IFramebufferOverlay
     200    public CComObjectRootEx<CComMultiThreadModelNoCS>,
     201    VBOX_SCRIPTABLE_IMPL(IFramebufferOverlay)
    207202{
    208203public:
     204    DECLARE_NOT_AGGREGATABLE(VBoxSDLFBOverlay)
     205
    209206    VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
    210207                     VBoxSDLFB *aParent);
    211208    virtual ~VBoxSDLFBOverlay();
    212209
    213 #ifdef RT_OS_WINDOWS
    214     STDMETHOD_(ULONG, AddRef)()
    215     {
    216         return ::InterlockedIncrement (&refcnt);
    217     }
    218     STDMETHOD_(ULONG, Release)()
    219     {
    220         long cnt = ::InterlockedDecrement (&refcnt);
    221         if (cnt == 0)
    222             delete this;
    223         return cnt;
    224     }
    225 #endif
    226 
    227210    BEGIN_COM_MAP(VBoxSDLFBOverlay)
    228         VBOX_DEFAULT_INTERFACE_ENTRIES(IFramebuffer)
     211        VBOX_MINIMAL_INTERFACE_ENTRIES(IFramebufferOverlay)
    229212    END_COM_MAP()
    230213
     
    277260    /** Additional SDL surface used for combining the framebuffer and the overlay */
    278261    SDL_Surface *mBlendedBits;
    279 #ifdef RT_OS_WINDOWS
    280     long refcnt;
    281 #endif
    282262};
    283263
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r41120 r41215  
    203203
    204204static ULONG       gcMonitors = 1;
    205 static VBoxSDLFB  *gpFramebuffer[64];
     205static ComObjPtr<VBoxSDLFB>  gpFramebuffer[64];
    206206static SDL_Cursor *gpDefaultCursor = NULL;
    207207#ifdef VBOXSDL_WITH_X11
     
    17801780
    17811781    /* static initialization of the SDL stuff */
    1782     if (!VBoxSDLFB::init(fShowSDLConfig))
     1782    if (!VBoxSDLFB::initSDL(fShowSDLConfig))
    17831783        goto leave;
    17841784
     
    17901790    {
    17911791        // create our SDL framebuffer instance
    1792         gpFramebuffer[i] = new VBoxSDLFB(i, fFullscreen, fResizable, fShowSDLConfig, false,
    1793                                          fixedWidth, fixedHeight, fixedBPP);
    1794 
    1795         if (!gpFramebuffer[i])
     1792        rc = gpFramebuffer[i].createObject();
     1793        if (SUCCEEDED(rc))
     1794            rc = gpFramebuffer[i]->init(i, fFullscreen, fResizable, fShowSDLConfig, false,
     1795                                        fixedWidth, fixedHeight, fixedBPP);
     1796
     1797        if (FAILED(rc) || !gpFramebuffer[i])
    17961798        {
    17971799            RTPrintf("Error: could not create framebuffer object!\n");
     
    28702872    }
    28712873
    2872     VBoxSDLFB::uninit();
     2874    VBoxSDLFB::uninitSDL();
    28732875
    28742876#ifdef VBOX_SECURELABEL
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