VirtualBox

Changeset 6794 in vbox


Ignore:
Timestamp:
Feb 4, 2008 5:45:03 PM (17 years ago)
Author:
vboxsync
Message:

A quick implementation sketch of a solution to the SetVisibleRegion? vs. paintEvent race again.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h

    r6725 r6794  
    509509    ulong mPixelFormat;
    510510    CGImageRef mImage;
    511 #if 1
    512     CGRect *mRegionRects;
    513     ULONG mRegionCount;
    514 #else
    515511    typedef struct
    516512    {
     
    520516        ULONG used;
    521517        /** Variable sized array of the rectangle that makes up the region. */
    522         CGRECT rcts[1];
     518        CGRect rcts[1];
    523519    } RegionRects;
    524520    /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
     
    536532     * This is operated with atomic cmpxchg and atomic xchg. */
    537533    RegionRects volatile *mRegionUnused;
    538 #endif
    539534};
    540535
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp

    r6725 r6794  
    2121#include "VBoxFrameBuffer.h"
    2222#include "VBoxConsoleView.h"
     23#include "VBoxProblemReporter.h"
     24#include "VBoxGlobal.h"
    2325/* Needed for checking against seamless mode */
    2426#include "VBoxConsoleWnd.h"
     
    4143    mPixelFormat(FramebufferPixelFormat_FOURCC_RGB),
    4244    mImage(NULL),
    43 #if 1
    44     mRegionRects(NULL),
    45     mRegionCount(0)
    46 #else
    4745    mRegion (NULL),
    4846    mRegionUnused (NULL)
    49 #endif
    5047{
    5148    Log (("Quartz2D: Creating\n"));
     
    8885     * ASMAtomic(Cmp)XchgPtr and a struct { cAllocated; cRects; aRects[1]; }
    8986     * *mRegion, *mUnusedRegion; should suffice (and permit you to reuse allocations). */
    90 #if 1
    91     RTMemFree (mRegionRects);
    92     mRegionCount = 0;
    93     mRegionRects = static_cast <CGRect*> (RTMemAlloc (sizeof (CGRect) * aCount));
    94 #else
    95     RegionRects *rgnRcts = (RegionRects *) ASMAtomicXchgPtr (&mRegionUnused, NULL);
     87    RegionRects *rgnRcts = (RegionRects *) ASMAtomicXchgPtr ((void * volatile *) &mRegionUnused, NULL);
    9688    if (rgnRcts && rgnRcts->allocated < aCount)
    9789    {
     
    10395        ULONG allocated = RT_ALIGN_32 (aCount + 1, 32);
    10496        allocated = RT_MAX (128, allocated);
    105         rgnRcts = (RegionRects *) RTMemAlloc (RT_OFFSETOF (RgionRects, rcts[allocated]));
     97        rgnRcts = (RegionRects *) RTMemAlloc (RT_OFFSETOF (RegionRects, rcts[allocated]));
    10698        if (!rgnRcts)
    107             return E_NOMEM;
     99            return E_OUTOFMEMORY;
    108100        rgnRcts->allocated = allocated;
    109101    }
    110102    rgnRcts->used = 0;
    111 #endif
    112103
    113104    QRegion reg;
     
    135126            continue;
    136127
    137 #if 1
    138         mRegionRects[mRegionCount].origin.x = rect.x();
    139         mRegionRects[mRegionCount].origin.y = rect.y();
    140         mRegionRects[mRegionCount].size.width = rect.width();
    141         mRegionRects[mRegionCount].size.height = rect.height();
    142 //        printf ("Region rect[%d - %d]: %d %d %d %d\n", mRegionCount, aCount, rect.x(), rect.y(), rect.height(), rect.width());
    143         ++mRegionCount;
    144 #else
    145128        CGRect *cgRct = &rgnRcts->rcts[rgnRcts->used];
    146129        cgRct->origin.x = rect.x();
     
    150133//        printf ("Region rect[%d - %d]: %d %d %d %d\n", rgnRcts->used, aCount, rect.x(), rect.y(), rect.height(), rect.width());
    151134        rgnRcts->used++;
    152 #endif
    153135    }
    154136//    printf ("..................................\n");
     
    163145    return S_OK;
    164146}
    165 
    166 /* Saved for later optimization */
    167 //#define BEST_BYTE_ALIGNMENT 16
    168 //#define COMPUTE_BEST_BYTES_PER_ROW (bpr)    ( ( (bpr) + (BEST_BYTE_ALIGNMENT-1) ) & ~(BEST_BYTE_ALIGNMENT-1) )
    169 //CGImageRef createImageFromImageInRect(CGImageRef* img, const QRect& rect)
    170 //{
    171 //    const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
    172 //    const QMacPixmapData *pmData = static_cast<const QMacPixmapData*>(pm.data);
    173 //    quint32 *pantherData = pmData->pixels + (sy * pm.width() + sx);
    174 //
    175 //    QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, pantherData, sw*sh*sizeof(uint), 0);
    176 //
    177 //
    178 //    CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, mBitmapData, bitmapByteCount, NULL);
    179 //    mImage = CGImageCreate(mWdt, mHgt, 8, 32, bitmapBytesPerRow, cs,
    180 //                           kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0, 0,
    181 //                           kCGRenderingIntentDefault);
    182 //
    183 //    CGDataProviderRef dp = CGDataProviderCreateWithData(aFrameBuffer, aFrameBuffer->address(), aFrameBuffer->bitsPerPixel() / 8 * aFrameBuffer->width() * aFrameBuffer->height() , NULL);
    184 //    image = CGImageCreate(sw, sh, 8, 32, pm.width() * sizeof(uint),
    185 //                          macGenericColorSpace(),
    186 //                          kCGImageAlphaPremultipliedFirst, provider, 0, 0,
    187 //                          kCGRenderingIntentDefault);
    188 //}
    189147
    190148void VBoxQuartz2DFrameBuffer::paintEvent (QPaintEvent *pe)
     
    234192        GetPortBounds (GetWindowPort (window), &winRect);
    235193        CGContextClearRect (ctx, CGRectMake (winRect.left, winRect.top, winRect.right - winRect.left, winRect.bottom - winRect.top));
    236 #if 1
    237         if (mRegionRects && mRegionCount > 0)
    238 #else
    239         RegionRects *rgnRcts = (RegionRects *) ASMAtomicXchgPtr (&mRegion, NULL);
     194//        ASMAtomicXchgPtr ((void * volatile *) &mRegion, &mRegionUnused);
     195        RegionRects *rgnRcts = (RegionRects *) ASMAtomicXchgPtr ((void * volatile *) &mRegion, NULL);
    240196        if (rgnRcts)
    241 #endif
    242197        {
    243198            /* Save state for display fliping */
     
    249204             * SetVisibleRegion. */
    250205            CGContextBeginPath (ctx);
    251 #if 1
    252             CGContextAddRects (ctx, mRegionRects, mRegionCount);
    253 #else
    254             CGContextAddRects (ctx, rgnRects->rcts, rgnRects->used);
    255             if (    !ASMAtomicCmpXchgPtr (&mRegion, rgnRects, NULL)
    256                 &&  !ASMAtomicCmpXchgPtr (&mRegionUnused, rgnRects, NULL))
    257                 RTMemFree(rgnRects);
    258 #endif
     206            CGContextAddRects (ctx, rgnRcts->rcts, rgnRcts->used);
     207            if (    !ASMAtomicCmpXchgPtr ((void * volatile *) &mRegion, rgnRcts, NULL)
     208                &&  !ASMAtomicCmpXchgPtr ((void * volatile *) &mRegionUnused, rgnRcts, NULL))
     209            RTMemFree(rgnRcts);
    259210            /* Restore the context state. Note that the
    260211             * current path isn't destroyed. */
     
    331282    mHgt = re->height();
    332283
     284    bool remind = false;
     285
    333286    /* We need a color space in any case */
    334287    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     
    351304    else
    352305    {
     306        remind = true;
    353307//        printf ("No VRAM\n");
    354         /* Create the memory we need for our image copy */
    355         int bitmapBytesPerRow = (mWdt * 4);
     308        /* Create the memory we need for our image copy
     309         * Read somewhere that an alignment of 16 is
     310         * best for optimal performance. So why not. */
     311//        int bitmapBytesPerRow = RT_ALIGN (mWdt * 4, 16);
     312        int bitmapBytesPerRow = mWdt * 4;
    356313        int bitmapByteCount = (bitmapBytesPerRow * mHgt);
    357314        mBitmapData = RTMemAlloc (bitmapByteCount);
     
    364321    }
    365322    CGColorSpaceRelease (cs);
     323
     324//    if (remind)
     325//    {
     326//        class RemindEvent : public VBoxAsyncEvent
     327//        {
     328//            ulong mRealBPP;
     329//        public:
     330//            RemindEvent (ulong aRealBPP)
     331//                : mRealBPP (aRealBPP) {}
     332//            void handle()
     333//            {
     334//                vboxProblem().remindAboutWrongColorDepth (mRealBPP, 32);
     335//            }
     336//        };
     337//        (new RemindEvent (re->bitsPerPixel()))->post();
     338//    }
    366339}
    367340
     
    378351        mBitmapData = NULL;
    379352    }
    380 #if 1
    381     if (mRegionRects)
    382     {
    383         RTMemFree (mRegionRects);
    384         mRegionRects = NULL;
    385         mRegionCount = 0;
    386     }
    387 #else
    388353    if (mRegion)
    389354    {
    390         RTMemFree (mRegion)
     355        RTMemFree ((void *) mRegion);
    391356        mRegion = NULL;
    392357    }
    393358    if (mRegionUnused)
    394359    {
    395         RTMemFree (mRegionUnused)
     360        RTMemFree ((void *) mRegionUnused);
    396361        mRegionUnused = NULL;
    397362    }
    398 #endif
    399363}
    400364
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