CarbonDockIconPreview.cpp revision 416817daa142e9bb7eaf14a1b10577978a5e691b
b736c553dbde2c3b2533c93c57d9b7f07714371cvboxsync * CarbonDockIconPreview class implementation
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * available from http://www.virtualbox.org. This file is free software;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * General Public License (GPL) as published by the Free Software
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * additional information or have any questions.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/* VBox includes */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncCGContextRef darwinBeginCGContextForApplicationDockTile (void);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncvoid darwinEndCGContextForApplicationDockTile (CGContextRef aContext);
d544fe535c163a24bf8cd831b39264da292b8adfvboxsyncvoid darwinOverlayApplicationDockTileImage (CGImageRef pImage);
d544fe535c163a24bf8cd831b39264da292b8adfvboxsyncvoid darwinDrawMainWindow (NativeWindowRef pMainWin, CGContextRef aContext);
174e1d5b2d6b6d7c92271d7fcc070c6d0cc92312vboxsync/* Import private function to capture the window content of any given window. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncCG_EXTERN CGSWindowID GetNativeWindowFromWindowRef(WindowRef ref);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncCG_EXTERN CGSConnectionID CGSMainConnectionID(void);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncCG_EXTERN void CGContextCopyWindowCaptureContentsToRect(CGContextRef c, CGRect dstRect, CGSConnectionID connection, CGSWindowID window, int zero);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncCarbonDockIconPreview::CarbonDockIconPreview (VBoxConsoleWnd *aMainWnd, const QPixmap& aOverlayImage)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync : AbstractDockIconPreview (aMainWnd, aOverlayImage)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync , AbstractDockIconPreviewHelper (aMainWnd, aOverlayImage)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Remove all previously set tile images */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Four bytes per color */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync int bitmapBytesPerRow = mDockIconRect.size.width * 4;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync int bitmapByteCount = bitmapBytesPerRow * mDockIconRect.size.height;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGContextRef context = CGBitmapContextCreate (mBitmapData,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Clear the background to be transparent */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGContextSetBlendMode (context, kCGBlendModeNormal);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Draw the state image & the overlay image */
9474d83dcac691984017f8255821b95ec7642804vboxsync /* Flush the content */
9474d83dcac691984017f8255821b95ec7642804vboxsync /* Create a image out of the bitmap context */
9474d83dcac691984017f8255821b95ec7642804vboxsync CGImageRef overlayImage = CGBitmapContextCreateImage (context);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Update the dock overlay icon */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Release the temp image */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncvoid CarbonDockIconPreview::updateDockPreview (CGImageRef aVMImage)
9474d83dcac691984017f8255821b95ec7642804vboxsync /* Create the context to draw on */
9474d83dcac691984017f8255821b95ec7642804vboxsync CGContextRef context = BeginCGContextForApplicationDockTile ();
9474d83dcac691984017f8255821b95ec7642804vboxsync /* This flush updates the dock icon */
9474d83dcac691984017f8255821b95ec7642804vboxsyncvoid CarbonDockIconPreview::updateDockPreview (VBoxFrameBuffer *aFrameBuffer)
9474d83dcac691984017f8255821b95ec7642804vboxsync AbstractDockIconPreview::updateDockPreview (aFrameBuffer);
9474d83dcac691984017f8255821b95ec7642804vboxsyncvoid CarbonDockIconPreview::updateDockPreviewImpl (CGContextRef aContext, CGImageRef aVMImage)
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Initialize all dependent images in the case it wasn't done already */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Clear the background to be transparent */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync CGContextSetBlendMode (aContext, kCGBlendModeNormal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync CGContextClearRect (aContext, flipRect (mDockIconRect));
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Draw the monitor as the background */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync CGContextDrawImage (aContext, flipRect (mMonitorRect), mDockMonitor);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Calculate the size of the dock icon image and fit it into 128x128 */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync float aspect = static_cast <float> (CGImageGetWidth (aVMImage)) / CGImageGetHeight (aVMImage);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Draw the VM content */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGContextDrawImage (aContext, flipRect (iconRect), aVMImage);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync// darwinDrawMainWindow(darwinToNativeWindow (mMainWnd), aContext);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#if 0 // ndef QT_MAC_USE_COCOA
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Process the content of any external OpenGL window. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync WindowGroupContentOptions wgco = kWindowGroupContentsReturnWindows | kWindowGroupContentsRecurse | kWindowGroupContentsVisible;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync float a1 = iconRect.size.width / static_cast <float> (CGImageGetWidth (aVMImage));
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync float a2 = iconRect.size.height / static_cast <float> (CGImageGetHeight (aVMImage));
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync HIRect mainRect = CGRectMake (tmpR.left, tmpR.top, tmpR.right-tmpR.left, tmpR.bottom-tmpR.top);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Iterate over every window in the returned window group. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync for (ItemCount i = 0; i <= c; ++i)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync OSStatus status = GetIndexedWindow (g, i, wgco, &wc);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Skip the main window */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Check that the class is of type overlay window */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync rect.origin.x = iconRect.origin.x + (tmpR1.left - mainRect.origin.x) * a1;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync rect.origin.y = iconRect.origin.y + (tmpR1.top - mainRect.origin.y) * a2;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* This is a big, bad hack. The following functions aren't
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * documented nor official supported by apple. But its the only way
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * to capture the OpenGL content of a window without fiddling
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * around with gPixelRead or something like that. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGSWindowID wid = GetNativeWindowFromWindowRef (wc);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGContextCopyWindowCaptureContentsToRect(aContext, flipRect (rect), CGSMainConnectionID(), wid, 0);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#endif /* QT_MAC_USE_COCOA */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Draw the glossy overlay */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync CGContextDrawImage (aContext, flipRect (mMonitorRect), mDockMonitorGlossy);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /* Draw the state image & the overlay image */