VirtualBox

Changeset 36685 in vbox


Ignore:
Timestamp:
Apr 15, 2011 1:35:27 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
71192
Message:

Additions/x11/seamless: replaced std::map with RTAVLU32TREE

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp

    r36672 r36685  
    263263}
    264264
     265DECLCALLBACK(int) VBoxGuestWinFree(VBoxGuestWinInfo *pInfo, void *pvParam)
     266{
     267    Display *pDisplay = (Display *)pvParam;
     268
     269    XShapeSelectInput(pDisplay, pInfo->Core.Key, 0);
     270    delete pInfo;
     271    return VINF_SUCCESS;
     272}
    265273
    266274/**
     
    271279    /* We use post-increment in the operation to prevent the iterator from being invalidated. */
    272280    LogRelFlowFunc(("\n"));
    273     for (VBoxGuestWindowList::iterator it = mGuestWindows.begin(); it != mGuestWindows.end();
    274                  mGuestWindows.removeWindow(it++))
    275     {
    276         XShapeSelectInput(mDisplay, it->first, 0);
    277     }
     281    mGuestWindows.detachAll(VBoxGuestWinFree, mDisplay);
    278282    LogRelFlowFunc(("returning\n"));
    279283}
     
    325329{
    326330    LogRelFlowFunc(("\n"));
    327     VBoxGuestWindowList::iterator iter;
    328 
    329     iter = mGuestWindows.find(hWin);
    330     if (iter != mGuestWindows.end())
     331    VBoxGuestWinInfo *pInfo = mGuestWindows.find(hWin);
     332    if (pInfo)
    331333    {
    332334        XWindowAttributes winAttrib;
     
    334336        if (!XGetWindowAttributes(mDisplay, hWin, &winAttrib))
    335337            return;
    336         iter->second->mX = winAttrib.x;
    337         iter->second->mY = winAttrib.y;
    338         iter->second->mWidth = winAttrib.width;
    339         iter->second->mHeight = winAttrib.height;
    340         if (iter->second->mhasShape)
     338        pInfo->mX = winAttrib.x;
     339        pInfo->mY = winAttrib.y;
     340        pInfo->mWidth = winAttrib.width;
     341        pInfo->mHeight = winAttrib.height;
     342        if (pInfo->mhasShape)
    341343        {
    342344            XRectangle *pRects;
     
    347349            if (!pRects)
    348350                cRects = 0;
    349             if (iter->second->mpRects)
    350                 XFree(iter->second->mpRects);
    351             iter->second->mcRects = cRects;
    352             iter->second->mpRects = pRects;
     351            if (pInfo->mpRects)
     352                XFree(pInfo->mpRects);
     353            pInfo->mcRects = cRects;
     354            pInfo->mpRects = pRects;
    353355        }
    354356        mChanged = true;
     
    365367{
    366368    LogRelFlowFunc(("\n"));
    367     VBoxGuestWindowList::iterator iter;
    368 
    369     iter = mGuestWindows.find(hWin);
    370     if (mGuestWindows.end() == iter)
     369    VBoxGuestWinInfo *pInfo = mGuestWindows.find(hWin);
     370    if (!pInfo)
    371371    {
    372372        addClientWindow(hWin);
     
    385385{
    386386    LogRelFlowFunc(("\n"));
    387     VBoxGuestWindowList::iterator iter;
    388 
    389     iter = mGuestWindows.find(hWin);
    390     if (iter != mGuestWindows.end())
     387    VBoxGuestWinInfo *pInfo = mGuestWindows.find(hWin);
     388    if (pInfo)
    391389    {
    392390        XRectangle *pRects;
     
    397395        if (!pRects)
    398396            cRects = 0;
    399         iter->second->mhasShape = true;
    400         if (iter->second->mpRects)
    401             XFree(iter->second->mpRects);
    402         iter->second->mcRects = cRects;
    403         iter->second->mpRects = pRects;
     397        pInfo->mhasShape = true;
     398        if (pInfo->mpRects)
     399            XFree(pInfo->mpRects);
     400        pInfo->mcRects = cRects;
     401        pInfo->mpRects = pRects;
    404402        mChanged = true;
    405403    }
     
    415413{
    416414    LogRelFlowFunc(("\n"));
    417     VBoxGuestWindowList::iterator iter;
    418 
    419     iter = mGuestWindows.find(hWin);
    420     if (mGuestWindows.end() != iter)
    421     {
    422         mGuestWindows.removeWindow(iter);
    423         mChanged = true;
    424     }
    425     LogRelFlowFunc(("returning\n"));
     415    VBoxGuestWinFree(mGuestWindows.removeWindow(hWin), NULL);
     416    LogRelFlowFunc(("returning\n"));
     417}
     418
     419DECLCALLBACK(int) getRectsCallback(VBoxGuestWinInfo *pInfo,
     420                                   std::vector<RTRECT> *pRects)
     421{
     422    if (pInfo->mhasShape)
     423    {
     424        for (int i = 0; i < pInfo->mcRects; ++i)
     425        {
     426            RTRECT rect;
     427            rect.xLeft   =   pInfo->mX
     428                            + pInfo->mpRects[i].x;
     429            rect.yBottom =   pInfo->mY
     430                            + pInfo->mpRects[i].y
     431                            + pInfo->mpRects[i].height;
     432            rect.xRight  =   pInfo->mX
     433                            + pInfo->mpRects[i].x
     434                            + pInfo->mpRects[i].width;
     435            rect.yTop    =   pInfo->mY
     436                            + pInfo->mpRects[i].y;
     437            pRects->push_back(rect);
     438        }
     439    }
     440    else
     441    {
     442        RTRECT rect;
     443        rect.xLeft   =  pInfo->mX;
     444        rect.yBottom =  pInfo->mY
     445                      + pInfo->mHeight;
     446        rect.xRight  =  pInfo->mX
     447                      + pInfo->mWidth;
     448        rect.yTop    =  pInfo->mY;
     449        pRects->push_back(rect);
     450    }
     451    return VINF_SUCCESS;
    426452}
    427453
     
    437463    if (0 != mcRects)
    438464    {
    439             apRects.get()->reserve(mcRects * 2);
    440     }
    441     for (VBoxGuestWindowList::iterator it = mGuestWindows.begin();
    442          it != mGuestWindows.end(); ++it)
    443     {
    444         if (it->second->mhasShape)
    445         {
    446             for (int i = 0; i < it->second->mcRects; ++i)
    447             {
    448                 RTRECT rect;
    449                 rect.xLeft   =   it->second->mX
    450                                 + it->second->mpRects[i].x;
    451                 rect.yBottom =   it->second->mY
    452                                 + it->second->mpRects[i].y
    453                                 + it->second->mpRects[i].height;
    454                 rect.xRight  =   it->second->mX
    455                                 + it->second->mpRects[i].x
    456                                 + it->second->mpRects[i].width;
    457                 rect.yTop    =   it->second->mY
    458                                 + it->second->mpRects[i].y;
    459                 apRects.get()->push_back(rect);
    460             }
    461             cRects += it->second->mcRects;
    462         }
    463         else
    464         {
    465             RTRECT rect;
    466             rect.xLeft   =  it->second->mX;
    467             rect.yBottom =  it->second->mY
    468                           + it->second->mHeight;
    469             rect.xRight  =  it->second->mX
    470                           + it->second->mWidth;
    471             rect.yTop    =  it->second->mY;
    472             apRects.get()->push_back(rect);
    473             ++cRects;
    474         }
    475     }
    476     mcRects = cRects;
     465        apRects.get()->reserve(mcRects * 2);
     466    }
     467    mGuestWindows.doWithAll((PVBOXGUESTWINCALLBACK)getRectsCallback,
     468                            apRects.get());
     469    mcRects = apRects->size();
    477470    LogRelFlowFunc(("returning\n"));
    478471    return apRects;
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h

    r36662 r36685  
    2121
    2222#include <VBox/log.h>
     23#include <iprt/avl.h>
    2324
    2425#include "seamless-guest.h"
     
    2829#include <X11/extensions/shape.h>
    2930
    30 #include <map>
    3131#include <vector>
    3232
     
    4141struct VBoxGuestWinInfo {
    4242public:
     43    /** Header structure for insertion into an AVL tree */
     44    AVLU32NODECORE Core;
    4345    /** Is the window currently mapped? */
    4446    bool mhasShape;
     
    7274};
    7375
     76/** Callback type used for "DoWithAll" calls */
     77typedef DECLCALLBACK(int) VBOXGUESTWINCALLBACK(VBoxGuestWinInfo *, void *);
     78/** Pointer to VBOXGUESTWINCALLBACK */
     79typedef VBOXGUESTWINCALLBACK *PVBOXGUESTWINCALLBACK;
     80
     81DECLCALLBACK(int) inline VBoxGuestWinCleanup(VBoxGuestWinInfo *pInfo, void *)
     82{
     83    delete pInfo;
     84    return VINF_SUCCESS;
     85}
     86
    7487/**
    75  * This class is just a wrapper around a map of structures containing information about
    76  * the windows on the guest system.  It has a function for adding a structure (see addWindow),
    77  * for removing it by window handle (see removeWindow) and an iterator for
    78  * going through the list.
     88 * This class is just a wrapper around a map of structures containing
     89 * information about the windows on the guest system.  It has a function for
     90 * adding a structure (see addWindow) and one for removing it by window
     91 * handle (see removeWindow).
    7992 */
    8093class VBoxGuestWindowList
     
    8699
    87100    // Private class members
    88     std::map<Window, VBoxGuestWinInfo *> mWindows;
     101    AVLU32TREE mWindows;
    89102
    90103public:
    91     // Just proxy iterators to map::iterator
    92     typedef std::map<Window, VBoxGuestWinInfo *>::const_iterator const_iterator;
    93     typedef std::map<Window, VBoxGuestWinInfo *>::iterator iterator;
    94 
    95104    // Constructor
    96     VBoxGuestWindowList(void) {}
     105    VBoxGuestWindowList(void) : mWindows(NULL) {}
    97106    // Destructor
    98107    ~VBoxGuestWindowList()
    99108    {
    100         /* We use post-increment in the operation to prevent the iterator from being invalidated. */
    101         try
    102         {
    103             for (iterator it = begin(); it != end(); removeWindow(it++))
    104                 ;
    105         }
    106         catch(...) {}
     109        /** @todo having this inside the container class hard codes that the
     110         *        elements have to be allocated with the "new" operator, and
     111         *        I don't see a need to require this. */
     112        doWithAll(VBoxGuestWinCleanup, NULL);
    107113    }
    108114
    109115    // Standard operations
    110     const_iterator begin() const { return mWindows.begin(); }
    111     iterator begin() { return mWindows.begin(); }
    112     const_iterator end() const { return mWindows.end(); }
    113     iterator end() { return mWindows.end(); }
    114     const_iterator find(Window win) const { return mWindows.find(win); }
    115     iterator find(Window win) { return mWindows.find(win); }
    116 
    117     void addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
     116    VBoxGuestWinInfo *find(Window hWin)
     117    {
     118        return (VBoxGuestWinInfo *)RTAvlU32Get(&mWindows, hWin);
     119    }
     120
     121    void detachAll(PVBOXGUESTWINCALLBACK pCallback, void *pvParam)
     122    {
     123        RTAvlU32Destroy(&mWindows, (PAVLU32CALLBACK)pCallback, pvParam);
     124    }
     125
     126    int doWithAll(PVBOXGUESTWINCALLBACK pCallback, void *pvParam)
     127    {
     128        return RTAvlU32DoWithAll(&mWindows, 1, (PAVLU32CALLBACK)pCallback,
     129                                 pvParam);
     130    }
     131
     132    bool addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
    118133                   XRectangle *pRects)
    119134    {
     
    121136        VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects,
    122137                                                       pRects);
    123         mWindows.insert(std::pair<Window, VBoxGuestWinInfo *>(hWin, pInfo));
     138        pInfo->Core.Key = hWin;
    124139        LogRelFlowFunc(("returning\n"));
    125     }
    126 
    127     void removeWindow(iterator it)
     140        return RTAvlU32Insert(&mWindows, &pInfo->Core);
     141    }
     142
     143    VBoxGuestWinInfo *removeWindow(Window hWin)
    128144    {
    129145        LogRelFlowFunc(("called\n"));
    130         delete it->second;
    131         mWindows.erase(it);
    132     }
    133 
    134     void removeWindow(Window hWin)
    135     {
    136         LogRelFlowFunc(("called\n"));
    137         removeWindow(find(hWin));
     146        return (VBoxGuestWinInfo *)RTAvlU32Remove(&mWindows, hWin);
    138147    }
    139148};
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