Changeset 6443 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 22, 2008 2:11:06 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils.h
r5999 r6443 250 250 class QImage; 251 251 class QPixmap; 252 class VBoxFrameBuffer; 252 253 CGImageRef DarwinQImageToCGImage (const QImage *aImage); 253 254 CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap); 254 255 CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource); 255 256 CGImageRef DarwinCreateDockBadge (const char *aSource); 257 CGImageRef DarwinCreateDockPreview(VBoxFrameBuffer *aFrameBuffer); 256 258 #endif /* Q_WS_MAC */ 257 259 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
r6441 r6443 19 19 #include "VBoxConsoleView.h" 20 20 #include "VBoxConsoleWnd.h" 21 #include "VBoxUtils.h" 21 22 22 23 #include "VBoxFrameBuffer.h" … … 2784 2785 /* delegate the paint function to the VBoxFrameBuffer interface */ 2785 2786 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 2786 2793 return; 2787 2794 } -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp
r5999 r6443 18 18 19 19 #include "VBoxUtils.h" 20 #include "VBoxFrameBuffer.h" 20 21 #include <qimage.h> 21 22 #include <qpixmap.h> … … 125 126 } 126 127 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 */ 136 CGImageRef 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.