VirtualBox

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


Ignore:
Timestamp:
Jul 17, 2014 7:57:07 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: make UIFramebuffer a (XP)COM object.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp

    r51667 r52086  
    41474147}
    41484148
    4149 VBoxQGLOverlay::VBoxQGLOverlay (QWidget *pViewport,QObject *pPostEventObject,  CSession * aSession, uint32_t id)
     4149VBoxQGLOverlay::VBoxQGLOverlay ()
    41504150    : mpOverlayWgt (NULL),
    4151       mpViewport (pViewport),
     4151      mpViewport (NULL),
    41524152      mGlOn (false),
    41534153      mOverlayWidgetVisible (false),
     
    41574157      mNeedOverlayRepaint (false),
    41584158      mNeedSetVisible (false),
    4159       mCmdPipe (pPostEventObject),
    4160       mSettings (*aSession),
    4161       mpSession(aSession),
     4159      mCmdPipe (),
     4160      mSettings (),
     4161      mpSession(),
    41624162      mpShareWgt (NULL),
    4163       m_id(id)
     4163      m_id(0)
    41644164{
    41654165    /* postpone the gl widget initialization to avoid conflict with 3D on Mac */
     4166}
     4167
     4168void VBoxQGLOverlay::init(QWidget *pViewport, QObject *pPostEventObject,  CSession * aSession, uint32_t id)
     4169{
     4170    mpViewport = pViewport;
     4171    mpSession = aSession;
     4172    m_id = id;
     4173    mSettings.init(*aSession);
     4174    mCmdPipe.init(pPostEventObject);
    41664175}
    41674176
     
    49484957}
    49494958
    4950 VBoxVHWACommandElementProcessor::VBoxVHWACommandElementProcessor(QObject *pNotifyObject) :
    4951     m_pNotifyObject(pNotifyObject),
     4959VBoxVHWACommandElementProcessor::VBoxVHWACommandElementProcessor() :
     4960    m_pNotifyObject(NULL),
    49524961    mpCurCmd(NULL),
    49534962    mbResetting(false),
     
    49604969
    49614970    m_pCmdEntryCache = new VBoxVHWAEntriesCache;
     4971}
     4972
     4973void VBoxVHWACommandElementProcessor::init(QObject *pNotifyObject)
     4974{
     4975    m_pNotifyObject = pNotifyObject;
    49624976}
    49634977
     
    57755789}
    57765790
    5777 VBoxVHWASettings::VBoxVHWASettings (CSession &session)
     5791VBoxVHWASettings::VBoxVHWASettings ()
     5792{
     5793}
     5794
     5795void VBoxVHWASettings::init(CSession &session)
    57785796{
    57795797    const QString strMachineID = session.GetMachine().GetId();
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h

    r51493 r52086  
    3232#include "UIDefs.h"
    3333#include "VBoxFBOverlayCommon.h"
     34#include "runtime/UIFrameBuffer.h"
     35#include "runtime/UIMachineView.h"
    3436
    3537/* COM includes: */
     
    8486{
    8587public:
    86     VBoxVHWASettings (CSession &session);
     88    VBoxVHWASettings ();
     89    void init(CSession &session);
    8790
    8891    int fourccEnabledCount() const { return mFourccEnabledCount; }
     
    13111314{
    13121315public:
    1313     VBoxVHWACommandElementProcessor(QObject *pNotifyObject);
     1316    VBoxVHWACommandElementProcessor();
     1317    void init(QObject *pNotifyObject);
    13141318    ~VBoxVHWACommandElementProcessor();
    13151319    void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
     
    16731677{
    16741678public:
    1675     VBoxQGLOverlay(QWidget *pViewport, QObject *pPostEventObject, CSession * aSession, uint32_t id);
     1679    VBoxQGLOverlay();
     1680    void init(QWidget *pViewport, QObject *pPostEventObject, CSession * aSession, uint32_t id);
    16761681    ~VBoxQGLOverlay()
    16771682    {
     
    18191824};
    18201825
    1821 /* this additional class V is to workaround the [VBox|UI] duplication,
    1822  * @todo: remove it once VBox stuff is removed */
    1823 template <class T, class V>
    1824 class VBoxOverlayFrameBuffer : public T
    1825 {
    1826 public:
    1827     VBoxOverlayFrameBuffer (V *pView, CSession * aSession, uint32_t id)
    1828         : T (pView),
    1829           mOverlay(pView->viewport(), pView, aSession, id),
    1830           mpView (pView)
    1831     {
     1826class VBoxOverlayFrameBuffer : public UIFrameBuffer
     1827{
     1828public:
     1829    VBoxOverlayFrameBuffer()
     1830    {
     1831    }
     1832
     1833    HRESULT init(UIMachineView *pView, CSession * aSession, uint32_t id)
     1834    {
     1835        mpView = pView;
     1836        UIFrameBuffer::init(mpView);
     1837        mOverlay.init(mpView->viewport(), mpView, aSession, id),
    18321838        /* sync with framebuffer */
    18331839        mOverlay.onResizeEventPostprocess (VBoxFBSizeInfo(this), QPoint(mpView->contentsX(), mpView->contentsY()));
     1840        return S_OK;
    18341841    }
    18351842
     
    18371844    {
    18381845        int rc;
    1839         T::lock();
     1846        UIFrameBuffer::lock();
    18401847        /* Make sure frame-buffer is used: */
    1841         if (T::m_fUnused)
     1848        if (UIFrameBuffer::m_fUnused)
    18421849        {
    18431850            LogRel2(("ProcessVHWACommand: Postponed!\n"));
    18441851            /* Unlock access to frame-buffer: */
    1845             T::unlock();
     1852            UIFrameBuffer::unlock();
    18461853            /* tell client to pend ProcessVHWACommand */
    18471854            return E_ACCESSDENIED;
    18481855        }
    18491856        rc = mOverlay.onVHWACommand ((struct VBOXVHWACMD*)pCommand);
    1850         T::unlock();
     1857        UIFrameBuffer::unlock();
    18511858        if (rc == VINF_CALLBACK_RETURN)
    18521859            return S_OK;
     
    18671874    {
    18681875        HRESULT hr = S_OK;
    1869         T::lock();
     1876        UIFrameBuffer::lock();
    18701877        /* Make sure frame-buffer is used: */
    1871         if (T::m_fUnused)
     1878        if (UIFrameBuffer::m_fUnused)
    18721879        {
    18731880            LogRel2(("NotifyUpdate: Ignored!\n"));
    18741881            mOverlay.onNotifyUpdateIgnore (aX, aY, aW, aH);
    18751882            /* Unlock access to frame-buffer: */
    1876             T::unlock();
     1883            UIFrameBuffer::unlock();
    18771884            /*can we actually ignore the notify update?*/
    18781885            /* Ignore NotifyUpdate: */
     
    18811888
    18821889        if (!mOverlay.onNotifyUpdate (aX, aY, aW, aH))
    1883             hr = T::NotifyUpdate (aX, aY, aW, aH);
    1884         T::unlock();
     1890            hr = UIFrameBuffer::NotifyUpdate (aX, aY, aW, aH);
     1891        UIFrameBuffer::unlock();
    18851892        return hr;
    18861893    }
     
    18881895    void resizeEvent(int iWidth, int iHeight)
    18891896    {
    1890         T::resizeEvent(iWidth, iHeight);
     1897        UIFrameBuffer::resizeEvent(iWidth, iHeight);
    18911898        mOverlay.onResizeEventPostprocess(VBoxFBSizeInfo(this),
    18921899                QPoint(mpView->contentsX(), mpView->contentsY()));
     
    18961903    {
    18971904        mOverlay.onViewportResized (re);
    1898         T::viewportResized (re);
     1905        UIFrameBuffer::viewportResized (re);
    18991906    }
    19001907
     
    19021909    {
    19031910        mOverlay.onViewportScrolled (QPoint(mpView->contentsX(), mpView->contentsY()));
    1904         T::viewportScrolled (dx, dy);
    1905     }
    1906 
    1907     void setView(V * pView)
     1911        UIFrameBuffer::viewportScrolled (dx, dy);
     1912    }
     1913
     1914    void setView(UIMachineView * pView)
    19081915    {
    19091916        /* lock to ensure we do not collide with the EMT thread passing commands to us */
    1910         T::lock();
    1911         T::setView(pView);
     1917        UIFrameBuffer::lock();
     1918        UIFrameBuffer::setView(pView);
    19121919        mpView = pView;
    19131920        mOverlay.updateAttachment(pView ? pView->viewport() : NULL, pView);
    1914         T::unlock();
     1921        UIFrameBuffer::unlock();
    19151922    }
    19161923
    19171924private:
    19181925    VBoxQGLOverlay mOverlay;
    1919     V *mpView;
     1926    UIMachineView *mpView;
    19201927};
    19211928
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp

    r51747 r52086  
    4747#endif /* !Q_WS_WIN */
    4848
    49 UIFrameBuffer::UIFrameBuffer(UIMachineView *pMachineView)
     49UIFrameBuffer::UIFrameBuffer()
    5050    : m_iWidth(0), m_iHeight(0)
    51     , m_pMachineView(pMachineView)
     51    , m_pMachineView(NULL)
    5252    , m_iWinId(0)
    5353    , m_fUpdatesAllowed(true)
    5454    , m_fUnused(false)
    5555    , m_fAutoEnabled(false)
    56 #ifdef Q_OS_WIN
    57     , m_iRefCnt(0)
    58 #endif /* Q_OS_WIN */
    5956    , m_hiDPIOptimizationType(HiDPIOptimizationType_None)
    6057    , m_dBackingScaleFactor(1.0)
    6158{
     59}
     60
     61HRESULT UIFrameBuffer::init(UIMachineView *pMachineView)
     62{
     63    LogRel2(("UIFrameBuffer::init %p\n", this));
     64
    6265    /* Assign mahine-view: */
    63     AssertMsg(m_pMachineView, ("UIMachineView must not be NULL\n"));
     66    m_pMachineView = pMachineView;
    6467    /* Cache window ID: */
    6568    m_iWinId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
     
    7578    /* Resize frame-buffer to default size: */
    7679    resizeEvent(640, 480);
     80
     81#ifdef Q_OS_WIN
     82    CoCreateFreeThreadedMarshaler(this, &m_pUnkMarshaler.p);
     83#endif /* Q_OS_WIN */
     84    return S_OK;
    7785}
    7886
    7987UIFrameBuffer::~UIFrameBuffer()
    8088{
     89    LogRel2(("UIFrameBuffer::~UIFrameBuffer %p\n", this));
     90
    8191    /* Disconnect handlers: */
    8292    if (m_pMachineView)
     
    8595    /* Deinitialize critical-section: */
    8696    RTCritSectDelete(&m_critSect);
     97}
     98
     99HRESULT UIFrameBuffer::FinalConstruct()
     100{
     101    return 0;
     102}
     103
     104void UIFrameBuffer::FinalRelease()
     105{
     106    return;
    87107}
    88108
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h

    r51693 r52086  
    3838
    3939/** Common IFramebuffer implementation used to maintain VM display video memory. */
    40 class UIFrameBuffer : public QObject, VBOX_SCRIPTABLE_IMPL(IFramebuffer)
     40class ATL_NO_VTABLE UIFrameBuffer :
     41    public QObject,
     42    public CComObjectRootEx<CComMultiThreadModel>,
     43    VBOX_SCRIPTABLE_IMPL(IFramebuffer)
    4144{
    4245    Q_OBJECT;
     
    5558public:
    5659
    57     /** Frame-buffer constructor.
    58       * @param pMachineView defines machine-view this frame-buffer is bounded to. */
    59     UIFrameBuffer(UIMachineView *pMachineView);
     60    /** Frame-buffer constructor. */
     61    UIFrameBuffer();
    6062    /** Frame-buffer destructor. */
    6163    ~UIFrameBuffer();
     64
     65    /** Frame-buffer initialization.
     66      * @param pMachineView defines machine-view this frame-buffer is bounded to. */
     67    HRESULT init(UIMachineView *pMachineView);
    6268
    6369    /** Assigns machine-view frame-buffer will be bounded to.
     
    7783    void setAutoEnabled(bool fAutoEnabled) { m_fAutoEnabled = fAutoEnabled; }
    7884
    79     NS_DECL_ISUPPORTS
    80 
    81 #ifdef Q_OS_WIN
    82     /** Windows: Increments reference-counter. */
    83     STDMETHOD_(ULONG, AddRef)()
    84     {
    85         return ::InterlockedIncrement(&m_iRefCnt);
    86     }
    87 
    88     /** Windows: Decrements reference-counter. */
    89     STDMETHOD_(ULONG, Release)()
    90     {
    91         long iCounter = ::InterlockedDecrement(&m_iRefCnt);
    92         if (iCounter == 0)
    93             delete this;
    94         return iCounter;
    95     }
    96 #endif /* Q_OS_WIN */
    97 
    98     VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
     85    DECLARE_NOT_AGGREGATABLE(UIFrameBuffer)
     86
     87    DECLARE_PROTECT_FINAL_CONSTRUCT()
     88
     89    BEGIN_COM_MAP(UIFrameBuffer)
     90        COM_INTERFACE_ENTRY(IFramebuffer)
     91        COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
     92        COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
     93    END_COM_MAP()
     94
     95    HRESULT FinalConstruct();
     96    void FinalRelease();
    9997
    10098    /* IFramebuffer COM methods: */
     
    269267    /** RTCRITSECT object to protect frame-buffer access. */
    270268    mutable RTCRITSECT m_critSect;
    271 
    272 #ifdef Q_OS_WIN
    273     /** Windows: Holds the reference counter. */
    274     long m_iRefCnt;
    275 #endif /* Q_OS_WIN */
    276269
    277270    /** @name Scaled mode related variables.
     
    306299    double m_dBackingScaleFactor;
    307300    /** @} */
     301
     302private:
     303
     304#ifdef Q_OS_WIN
     305     CComPtr <IUnknown> m_pUnkMarshaler;
     306#endif /* Q_OS_WIN */
    308307};
    309308
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r51666 r52086  
    379379        LogRelFlow(("UIMachineView::prepareFrameBuffer: Start EMT callbacks accepting for screen: %d.\n", screenId()));
    380380        pFrameBuffer->setMarkAsUnused(false);
    381         uisession()->setFrameBuffer(screenId(), pFrameBuffer);
     381        m_pFrameBuffer = pFrameBuffer;
    382382    }
    383383    else
     
    386386        if (m_fAccelerate2DVideo)
    387387        {
    388             /** these two additional template args is a workaround to
    389              * this [VBox|UI] duplication
    390              * @todo: they are to be removed once VBox stuff is gone */
    391             pFrameBuffer = new VBoxOverlayFrameBuffer<UIFrameBuffer, UIMachineView>(this, &session(), (uint32_t)screenId());
     388            ComObjPtr<VBoxOverlayFrameBuffer> pOFB;
     389            pOFB.createObject();
     390            pOFB->init(this, &session(), (uint32_t)screenId());
     391            m_pFrameBuffer = pOFB;
    392392        }
    393393        else
    394             pFrameBuffer = new UIFrameBuffer(this);
     394        {
     395            m_pFrameBuffer.createObject();
     396            m_pFrameBuffer->init(this);
     397        }
    395398# else /* VBOX_WITH_VIDEOHWACCEL */
    396         pFrameBuffer = new UIFrameBuffer(this);
     399        m_pFrameBuffer.createObject();
     400        m_pFrameBuffer->init(this);
    397401# endif /* !VBOX_WITH_VIDEOHWACCEL */
    398         pFrameBuffer->setHiDPIOptimizationType(uisession()->hiDPIOptimizationType());
    399         uisession()->setFrameBuffer(screenId(), pFrameBuffer);
    400     }
    401     m_pFrameBuffer = pFrameBuffer;
     402        m_pFrameBuffer->setHiDPIOptimizationType(uisession()->hiDPIOptimizationType());
     403
     404        uisession()->setFrameBuffer(screenId(), m_pFrameBuffer);
     405    }
    402406
    403407    /* If frame-buffer was prepared: */
     
    407411        CDisplay display = session().GetConsole().GetDisplay();
    408412        Assert(!display.isNull());
    409         CFramebuffer fb(NULL);
    410         /* Check if the framebuffer is already assigned;
    411          * in this case we do not need to re-assign it neither do we need to AddRef. */
    412         fb = display.QueryFramebuffer(m_uScreenId);
    413         if (fb.raw() != m_pFrameBuffer) /* <-this will evaluate to true iff no framebuffer is yet assigned */
    414         {
    415             m_pFrameBuffer->AddRef();
    416         }
     413        CFramebuffer fb = display.QueryFramebuffer(m_uScreenId);
    417414        /* Always perform AttachFramebuffer to ensure 3D gets notified: */
    418415        if (!fb.isNull())
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r51558 r52086  
    226226    UIMachineWindow *m_pMachineWindow;
    227227    ulong m_uScreenId;
    228     UIFrameBuffer *m_pFrameBuffer;
     228    ComObjPtr<UIFrameBuffer> m_pFrameBuffer;
    229229    KMachineState m_previousState;
    230230    /** HACK: when switching out of fullscreen or seamless we wish to override
     
    260260    friend class UIMachineLogic;
    261261    friend class UIFrameBuffer;
    262     template<class, class> friend class VBoxOverlayFrameBuffer;
     262    friend class VBoxOverlayFrameBuffer;
    263263};
    264264
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r51811 r52086  
    12071207            display.DetachFramebuffer(i);
    12081208            /* Release framebuffer reference: */
    1209             pFb->Release();
     1209            m_frameBufferVector[i].setNull();
    12101210        }
    12111211    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r52014 r52086  
    359359
    360360    /* Frame-buffers vector: */
    361     QVector<UIFrameBuffer*> m_frameBufferVector;
     361    QVector<ComObjPtr<UIFrameBuffer>> m_frameBufferVector;
    362362
    363363    /* Common variables: */
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