VirtualBox

Changeset 902 in vbox


Ignore:
Timestamp:
Feb 14, 2007 1:35:27 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
18622
Message:

Main: Restored r18598 + fixes (don't call OnStateChange on new callback registration, free old shape memory before allocating it again!).

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r887 r902  
    306306    AssertReturn (mAudioSniffer, E_FAIL);
    307307
     308    memset (&mCallbackData, 0, sizeof (mCallbackData));   
     309   
    308310    /* Confirm a successful initialization when it's the case */
    309311    autoInitSpan.setSucceeded();
     
    419421    unconst (mMachine).setNull();
    420422
    421     // Release all callbacks. Do this after uninitializing the components,
    422     // as some of them are well-behaved and unregister their callbacks.
    423     // These would trigger error messages complaining about trying to
    424     // unregister a non-registered callback.
     423    /* Release all callbacks. Do this after uninitializing the components,
     424     * as some of them are well-behaved and unregister their callbacks.
     425     * These would trigger error messages complaining about trying to
     426     * unregister a non-registered callback. */
    425427    mCallbacks.clear();
     428
     429    /* dynamically allocated members of mCallbackData are uninitialized
     430     * at the end of powerDown() */
     431    Assert (!mCallbackData.mpsc.valid && mCallbackData.mpsc.shape == NULL);
     432    Assert (!mCallbackData.mcc.valid);
     433    Assert (!mCallbackData.klc.valid);
    426434
    427435    LogFlowThisFuncLeave();
     
    23552363    mCallbacks.push_back (CallbackList::value_type (aCallback));
    23562364
    2357 #if 0
    2358     /* @todo dmik please implement this.
    2359      * Inform the callback about the current status, because the new callback
    2360      * must know at least the current mouse capabilities and the pointer shape.
    2361      */
    2362     aCallback->OnMousePointerShapeChange (mCallbacksStatus.pointerShape.fVisible,
    2363                                           mCallbackStatus.pointerShape.fAlpha,
    2364                                           mCallbackStatus.pointerShape.xHot,
    2365                                           mCallbackStatus.pointerShape.yHot,
    2366                                           mCallbackStatus.pointerShape.width,
    2367                                           mCallbackStatus.pointerShape.height,
    2368                                           mCallbackStatus.pointerShape.pShape);
    2369     aCallback->OnMouseCapabilityChange (mCallbackStatus.mouseCapability.supportsAbsolute,
    2370                                         mCallbackStatus.mouseCapability.needsHostCursor);
    2371     aCallback->OnStateChange (mCallbackStatus.machineState);
     2365    /* Inform the callback about the current status (for example, the new
     2366     * callback must know the current mouse capabilities and the pointer
     2367     * shape in order to properly integrate the mouse pointer). */
     2368
     2369    if (mCallbackData.mpsc.valid)
     2370        aCallback->OnMousePointerShapeChange (mCallbackData.mpsc.visible,
     2371                                              mCallbackData.mpsc.alpha,
     2372                                              mCallbackData.mpsc.xHot,
     2373                                              mCallbackData.mpsc.yHot,
     2374                                              mCallbackData.mpsc.width,
     2375                                              mCallbackData.mpsc.height,
     2376                                              mCallbackData.mpsc.shape);
     2377    if (mCallbackData.mcc.valid)
     2378        aCallback->OnMouseCapabilityChange (mCallbackData.mcc.supportsAbsolute,
     2379                                            mCallbackData.mcc.needsHostCursor);
     2380
    23722381    aCallback->OnAdditionsStateChange();
    2373     aCallback->OnKeyboardLedsChange(mCallbackStatus.keyboardLeds.fNumLock,
    2374                                     mCallbackStatus.keyboardLeds.fCapsLock,
    2375                                     mCallbackStatus.keyboardLeds.fScrollLock);
    2376 #endif
     2382
     2383    if (mCallbackData.klc.valid)
     2384        aCallback->OnKeyboardLedsChange (mCallbackData.klc.numLock,
     2385                                         mCallbackData.klc.capsLock,
     2386                                         mCallbackData.klc.scrollLock);
     2387
     2388    /* Note: we don't call OnStateChange for new callbacks because the
     2389     * machine state is a) not actually changed on callback registration
     2390     * and b) can be always queried from Console. */
    23772391
    23782392    return S_OK;
     
    32643278
    32653279/**
    3266  *  @note Locks this object for reading.
     3280 *  @note Locks this object for writing.
    32673281 */
    32683282void Console::onMousePointerShapeChange(bool fVisible, bool fAlpha,
     
    32713285                                        void *pShape)
    32723286{
     3287    LogFlowThisFuncEnter();
    32733288    LogFlowThisFunc (("fVisible=%d, fAlpha=%d, xHot = %d, yHot = %d, width=%d, "
    32743289                      "height=%d, shape=%p\n",
    32753290                      fVisible, fAlpha, xHot, yHot, width, height, pShape));
    32763291
    3277     AutoReaderLock alock (this);
     3292    AutoCaller autoCaller (this);
     3293    AssertComRCReturnVoid (autoCaller.rc());
     3294
     3295    /* We need a write lock because we alter the cached callback data */
     3296    AutoLock alock (this);
     3297
     3298    /* Save the callback arguments */
     3299    mCallbackData.mpsc.visible = fVisible;
     3300    mCallbackData.mpsc.alpha = fAlpha;
     3301    mCallbackData.mpsc.xHot = xHot;
     3302    mCallbackData.mpsc.yHot = yHot;
     3303    mCallbackData.mpsc.width = width;
     3304    mCallbackData.mpsc.height = height;
     3305
     3306    mCallbackData.mpsc.valid = false;
     3307
     3308    if (pShape != NULL)
     3309    {
     3310        size_t cb = (width + 7) / 8 * height; /* size of the AND mask */
     3311        cb += ((cb + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
     3312        /* try to reuse the old shape buffer if the size is the same */
     3313        if (!mCallbackData.mpsc.valid)
     3314            mCallbackData.mpsc.shape = NULL;
     3315        else
     3316        if (mCallbackData.mpsc.shape != NULL && mCallbackData.mpsc.shapeSize != cb)
     3317        {
     3318            RTMemFree (mCallbackData.mpsc.shape);
     3319            mCallbackData.mpsc.shape = NULL;
     3320        }
     3321        if (mCallbackData.mpsc.shape == NULL)
     3322        {
     3323            mCallbackData.mpsc.shape = (BYTE *) RTMemAllocZ (cb);
     3324            AssertReturnVoid (mCallbackData.mpsc.shape);
     3325        }
     3326        mCallbackData.mpsc.shapeSize = cb;
     3327        memcpy (mCallbackData.mpsc.shape, pShape, cb);
     3328    }
     3329    else
     3330    {
     3331        if (mCallbackData.mpsc.valid && mCallbackData.mpsc.shape != NULL)
     3332            RTMemFree (mCallbackData.mpsc.shape);
     3333        mCallbackData.mpsc.shape = NULL;
     3334        mCallbackData.mpsc.shapeSize = 0;
     3335    }
     3336
     3337    mCallbackData.mpsc.valid = true;
    32783338
    32793339    CallbackList::iterator it = mCallbacks.begin();
     
    32813341        (*it++)->OnMousePointerShapeChange (fVisible, fAlpha, xHot, yHot,
    32823342                                            width, height, (BYTE *) pShape);
     3343
     3344    LogFlowThisFuncLeave();
    32833345}
    32843346
    32853347/**
    3286  *  @note Locks this object for reading.
     3348 *  @note Locks this object for writing.
    32873349 */
    32883350void Console::onMouseCapabilityChange (BOOL supportsAbsolute, BOOL needsHostCursor)
     
    32943356    AssertComRCReturnVoid (autoCaller.rc());
    32953357
    3296     AutoReaderLock alock (this);
    3297 
     3358    /* We need a write lock because we alter the cached callback data */
     3359    AutoLock alock (this);
     3360
     3361    /* save the callback arguments */
     3362    mCallbackData.mcc.supportsAbsolute = supportsAbsolute;
     3363    mCallbackData.mcc.needsHostCursor = needsHostCursor;
     3364    mCallbackData.mcc.valid = true;
     3365   
    32983366    CallbackList::iterator it = mCallbacks.begin();
    32993367    while (it != mCallbacks.end())
     
    33523420
    33533421/**
    3354  *  @note Locks this object for reading.
     3422 *  @note Locks this object for writing.
    33553423 */
    33563424void Console::onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock)
     
    33593427    AssertComRCReturnVoid (autoCaller.rc());
    33603428
    3361     AutoReaderLock alock (this);
     3429    /* We need a write lock because we alter the cached callback data */
     3430    AutoLock alock (this);
     3431
     3432    /* save the callback arguments */
     3433    mCallbackData.klc.numLock = fNumLock;
     3434    mCallbackData.klc.capsLock = fCapsLock;
     3435    mCallbackData.klc.scrollLock = fScrollLock;
     3436    mCallbackData.klc.valid = true;
    33623437
    33633438    CallbackList::iterator it = mCallbacks.begin();
     
    36573732        mVMDestroying = false;
    36583733
     3734    if (SUCCEEDED (rc))
     3735    {
     3736        /* uninit dynamically allocated members of mCallbackData */
     3737        if (mCallbackData.mpsc.valid)
     3738        {
     3739            if (mCallbackData.mpsc.shape != NULL)
     3740                RTMemFree (mCallbackData.mpsc.shape);
     3741        }
     3742        memset (&mCallbackData, 0, sizeof (mCallbackData));   
     3743    }
     3744   
    36593745    LogFlowThisFuncLeave();
    36603746    return rc;
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r887 r902  
    478478    bool mVMStateChangeCallbackDisabled;
    479479
    480     // local state value
     480    /* Local machine state value */
    481481    MachineState_T mMachineState;
    482482
     
    484484    CallbackList mCallbacks;
    485485
     486    struct
     487    {
     488        /** OnMousePointerShapeChange() cache */
     489        struct
     490        {
     491            bool valid;
     492            bool visible;
     493            bool alpha;
     494            uint32_t xHot;
     495            uint32_t yHot;
     496            uint32_t width;
     497            uint32_t height;
     498            BYTE *shape;
     499            size_t shapeSize;
     500        }
     501        mpsc;
     502
     503        /** OnMouseCapabilityChange() cache */
     504        struct
     505        {
     506            bool valid;
     507            BOOL supportsAbsolute;
     508            BOOL needsHostCursor;
     509        }
     510        mcc;
     511
     512        /** OnKeyboardLedsChange() cache */
     513        struct
     514        {
     515            bool valid;
     516            bool numLock;
     517            bool capsLock;
     518            bool scrollLock;
     519        }
     520        klc;
     521    }
     522    mCallbackData;
     523   
    486524    friend struct VMTask;
    487525};
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