VirtualBox

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


Ignore:
Timestamp:
Feb 1, 2008 3:14:02 PM (17 years ago)
Author:
vboxsync
Message:

Mac OS X: We can acquire a cgcontext from the dock icon which means we can
draw directly on the dock icon. So an extra image as temporary buffer is no
longer required.

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

Legend:

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

    r6715 r6721  
    255255CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource);
    256256CGImageRef DarwinCreateDockBadge (const char *aSource);
    257 CGImageRef DarwinCreateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
    258 CGImageRef DarwinCreateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
     257void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
     258void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
    259259OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
    260260#endif /* Q_WS_MAC */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r6715 r6721  
    29392939                    CGImageRef ir =
    29402940                        static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef();
    2941                     SetApplicationDockTileImage (
    2942                         ::DarwinCreateDockPreview (ir, mVirtualBoxLogo));
     2941                    ::DarwinUpdateDockPreview (ir, mVirtualBoxLogo);
    29432942                }
    29442943                else
    29452944# endif
    2946                     SetApplicationDockTileImage (
    2947                         ::DarwinCreateDockPreview (mFrameBuf, mVirtualBoxLogo));
     2945                    ::DarwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
    29482946            }
    29492947#endif
     
    29592957
    29602958#ifdef Q_WS_MAC
    2961         SetApplicationDockTileImage (
    2962             ::DarwinCreateDockPreview (DarwinQPixmapToCGImage (&mPausedShot),
    2963                                        mVirtualBoxLogo,
    2964                                        mMainWnd->dockImageState()));
     2959        ::DarwinUpdateDockPreview (DarwinQPixmapToCGImage (&mPausedShot),
     2960                                   mVirtualBoxLogo,
     2961                                   mMainWnd->dockImageState());
    29652962#endif
    29662963    }
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp

    r6720 r6721  
    128128
    129129/**
    130  * Creates a dock preview image.
    131  *
    132  * This method is a callback that creates a 128x128 preview image of the VM window.
    133  *
    134  * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
     130 * Updates the dock preview image.
     131 *
     132 * This method is a callback that updates the 128x128 preview image of the VM window in the dock.
     133 *
    135134 * @param   aVMImage   the vm screen as a CGImageRef
    136135 * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
    137136 * @param   aStateImage   an optional state overlay image to add at the center of the icon
    138137 */
    139 CGImageRef DarwinCreateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage)
     138void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage)
    140139{
    141140    Assert (aVMImage);
     
    163162                                  (targetHeight - scaledHeight) / 2.0,
    164163                                  scaledWidth, scaledHeight);
    165     /* Create a bitmap context to draw on */
    166     CGImageRef dockImage = NULL;
    167     int bitmapBytesPerRow = targetWidth * 4;
    168     int bitmapByteCount = bitmapBytesPerRow * targetHeight;
    169     void *bitmapData = RTMemAlloc (bitmapByteCount);
    170     if (bitmapData)
    171     {
    172         CGContextRef context = CGBitmapContextCreate (bitmapData, targetWidth, targetHeight, 8, bitmapBytesPerRow, cs, kCGImageAlphaPremultipliedLast);
    173         /* rounded corners */
     164    /* Create the context to draw on */
     165    CGContextRef context = BeginCGContextForApplicationDockTile();
     166    Assert (context);
     167    /* Clear the background */
     168    CGContextClearRect (context, CGRectMake (0, 0, 128, 128));
     169    /* rounded corners */
    174170//        CGContextSetLineJoin (context, kCGLineJoinRound);
    175171//        CGContextSetShadow (context, CGSizeMake (10, 5), 1);
    176172//        CGContextSetAllowsAntialiasing (context, true);
    177         /* some little boarder */
    178         iconRect = CGRectInset (iconRect, 1, 1);
    179         /* gray stroke */
    180         CGContextSetRGBStrokeColor (context, 225.0/255.0, 218.0/255.0, 211.0/255.0, 1);
    181         iconRect = CGRectInset (iconRect, 6, 6);
    182         CGContextStrokeRectWithWidth (context, iconRect, 12);
    183         iconRect = CGRectInset (iconRect, 5, 5);
    184         /* black stroke */
    185         CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 1.0);
    186         CGContextStrokeRectWithWidth (context, iconRect, 2);
    187         /* vm content */
    188         iconRect = CGRectInset (iconRect, 1, 1);
    189         CGContextDrawImage (context, iconRect, aVMImage);
    190         /* the state image at center */
    191         if (aStateImage)
    192         {
    193             CGRect stateRect = CGRectMake ((targetWidth - CGImageGetWidth (aStateImage)) / 2.0, (targetHeight - CGImageGetHeight (aStateImage)) / 2.0, CGImageGetWidth (aStateImage), CGImageGetHeight (aStateImage));
    194             CGContextDrawImage (context, stateRect, aStateImage);
    195         }
    196         /* the overlay image at bottom/right */
    197         if (aOverlayImage)
    198         {
    199             CGRect overlayRect = CGRectMake (targetWidth - CGImageGetWidth (aOverlayImage), 0, CGImageGetWidth (aOverlayImage), CGImageGetHeight (aOverlayImage));
    200             CGContextDrawImage (context, overlayRect, aOverlayImage);
    201         }
    202         /* Create the preview image ref from the bitmap */
    203         dockImage = CGBitmapContextCreateImage (context);
    204         CGContextRelease (context);
    205         RTMemFree (bitmapData);
    206     }
     173    /* some little boarder */
     174    iconRect = CGRectInset (iconRect, 1, 1);
     175    /* gray stroke */
     176    CGContextSetRGBStrokeColor (context, 225.0/255.0, 218.0/255.0, 211.0/255.0, 1);
     177    iconRect = CGRectInset (iconRect, 6, 6);
     178    CGContextStrokeRectWithWidth (context, iconRect, 12);
     179    iconRect = CGRectInset (iconRect, 5, 5);
     180    /* black stroke */
     181    CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 1.0);
     182    CGContextStrokeRectWithWidth (context, iconRect, 2);
     183    /* vm content */
     184    iconRect = CGRectInset (iconRect, 1, 1);
     185    CGContextDrawImage (context, iconRect, aVMImage);
     186    /* the state image at center */
     187    if (aStateImage)
     188    {
     189        CGRect stateRect = CGRectMake ((targetWidth - CGImageGetWidth (aStateImage)) / 2.0,
     190                                       (targetHeight - CGImageGetHeight (aStateImage)) / 2.0,
     191                                       CGImageGetWidth (aStateImage),
     192                                       CGImageGetHeight (aStateImage));
     193        CGContextDrawImage (context, stateRect, aStateImage);
     194    }
     195    /* the overlay image at bottom/right */
     196    if (aOverlayImage)
     197    {
     198        CGRect overlayRect = CGRectMake (targetWidth - CGImageGetWidth (aOverlayImage),
     199                                         0,
     200                                         CGImageGetWidth (aOverlayImage),
     201                                         CGImageGetHeight (aOverlayImage));
     202        CGContextDrawImage (context, overlayRect, aOverlayImage);
     203    }
     204    /* This flush updates the dock icon */
     205    CGContextFlush (context);
     206    EndCGContextForApplicationDockTile (context);
    207207
    208208    CGColorSpaceRelease (cs);
    209 
    210     Assert (dockImage);
    211     return dockImage;
    212 }
    213 
    214 /**
    215  * Creates a dock preview image.
    216  *
    217  * This method is a callback that creates a 128x128 preview image of the VM window.
    218  *
    219  * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
     209}
     210
     211/**
     212 * Updates the dock preview image.
     213 *
     214 * This method is a callback that updates the 128x128 preview image of the VM window in the dock.
     215 *
    220216 * @param   aFrameBuffer    The guest frame buffer.
    221217 * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
    222218 */
    223 CGImageRef DarwinCreateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
     219void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
    224220{
    225221    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     
    231227                                   kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0, false,
    232228                                   kCGRenderingIntentDefault);
    233     /* Create the preview icon */
    234     CGImageRef dockImage = DarwinCreateDockPreview (ir, aOverlayImage);
     229    /* Update the dock preview icon */
     230    ::DarwinUpdateDockPreview (ir, aOverlayImage);
    235231    /* Release the temp data and image */
    236232    CGDataProviderRelease (dp);
    237233    CGImageRelease (ir);
    238234    CGColorSpaceRelease (cs);
    239 
    240     return dockImage;
    241235}
    242236
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