VirtualBox

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


Ignore:
Timestamp:
Jan 22, 2008 2:11:06 PM (17 years ago)
Author:
vboxsync
Message:

Mac OS X: Added realtime preview of the vm output in the dock icon.

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

Legend:

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

    r5999 r6443  
    250250class QImage;
    251251class QPixmap;
     252class VBoxFrameBuffer;
    252253CGImageRef DarwinQImageToCGImage (const QImage *aImage);
    253254CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap);
    254255CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource);
    255256CGImageRef DarwinCreateDockBadge (const char *aSource);
     257CGImageRef DarwinCreateDockPreview(VBoxFrameBuffer *aFrameBuffer);
    256258#endif /* Q_WS_MAC */
    257259
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r6441 r6443  
    1919#include "VBoxConsoleView.h"
    2020#include "VBoxConsoleWnd.h"
     21#include "VBoxUtils.h"
    2122
    2223#include "VBoxFrameBuffer.h"
     
    27842785            /* delegate the paint function to the VBoxFrameBuffer interface */
    27852786            mFrameBuf->paintEvent (pe);
     2787#ifdef Q_WS_MAC
     2788            /* Update the dock icon if we are in the running state */
     2789            if(isRunning())
     2790                SetApplicationDockTileImage(::DarwinCreateDockPreview(mFrameBuf));
     2791#endif
     2792
    27862793            return;
    27872794        }
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp

    r5999 r6443  
    1818
    1919#include "VBoxUtils.h"
     20#include "VBoxFrameBuffer.h"
    2021#include <qimage.h>
    2122#include <qpixmap.h>
     
    125126}
    126127
     128/**
     129 * Creates a dock preview image.
     130 *
     131 * Use this method to create a 128x128 preview image of the vm window.
     132 *
     133 * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
     134 * @param   aFrameBuffer    The source name.
     135 */
     136CGImageRef DarwinCreateDockPreview(VBoxFrameBuffer *aFrameBuffer)
     137{
     138    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     139    /* Create the image copy of the framebuffer */
     140    CGDataProviderRef dp = CGDataProviderCreateWithData(aFrameBuffer, aFrameBuffer->address(), aFrameBuffer->bitsPerPixel() / 8 * aFrameBuffer->width() * aFrameBuffer->height() , NULL);
     141    CGImageRef ir = CGImageCreate(aFrameBuffer->width(), aFrameBuffer->height(), 8, 32, aFrameBuffer->bytesPerLine(), cs,
     142                                  kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0 /*decode */, 0 /* shouldInterpolate */,
     143                                  kCGRenderingIntentDefault);
     144
     145    Assert(cs);
     146    Assert(dp);
     147    Assert(ir);
     148    /* Calc the size of the dock icon image and fit it into 128x128 */
     149    int targetWidth = 128;
     150    int targetHeight = 128;
     151    float aspect = static_cast<float>(aFrameBuffer->width()) / aFrameBuffer->height();
     152    CGRect rect;
     153    if(aspect > 1.0)
     154    {
     155      rect.origin.x = 0;
     156      rect.origin.y = (targetHeight-targetHeight/aspect)/2;
     157      rect.size.width = targetWidth;
     158      rect.size.height = targetHeight/aspect;
     159    }else
     160    {
     161      rect.origin.x = (targetWidth-targetWidth*aspect)/2;
     162      rect.origin.y = 0;
     163      rect.size.width = targetWidth*aspect;
     164      rect.size.height = targetHeight;
     165    }
     166    /* Create a bitmap context to draw on */
     167    int bitmapBytesPerRow = (targetWidth * 4);
     168    int bitmapByteCount = (bitmapBytesPerRow * targetHeight);
     169    void *bitmapData = malloc(bitmapByteCount);
     170    CGImageRef dockImage = NULL;
     171    if (bitmapData)
     172    {
     173      CGContextRef context = CGBitmapContextCreate(bitmapData, targetWidth, targetHeight, 8, bitmapBytesPerRow, cs, kCGImageAlphaPremultipliedLast);
     174      /* Draw on the bitmap */
     175      CGContextDrawImage(context, rect, ir);
     176      /* Create the preview image ref from the bitmap */
     177      dockImage = CGBitmapContextCreateImage(context);
     178      CGContextRelease(context);
     179      free(bitmapData);
     180    }
     181    CGColorSpaceRelease(cs);
     182    CGDataProviderRelease(dp);
     183    CGImageRelease(ir);
     184
     185    Assert (dockImage);
     186    return dockImage;
     187}
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