Changeset 22813 in vbox
- Timestamp:
- Sep 7, 2009 2:27:59 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp
r22313 r22813 22 22 #include "VBoxUtils-darwin.h" 23 23 24 #include <iprt/ assert.h>24 #include <iprt/mem.h> 25 25 26 26 #include <QApplication> … … 222 222 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap) 223 223 { 224 return aPixmap->toMacCGImageRef(); 224 /* It seems Qt releases the memory to an returned CGImageRef when the 225 * associated QPixmap is destroyed. This shouldn't happen as long a 226 * CGImageRef has a retrain count. As a workaround we make a real copy. */ 227 int bitmapBytesPerRow = aPixmap->width() * 4; 228 int bitmapByteCount = (bitmapBytesPerRow * aPixmap->height()); 229 /* Create a memory block for the temporary image. It is initialized by zero 230 * which means black & zero alpha. */ 231 void *pBitmapData = RTMemAllocZ (bitmapByteCount); 232 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); 233 /* Create a context to paint on */ 234 CGContextRef ctx = CGBitmapContextCreate (pBitmapData, 235 aPixmap->width(), 236 aPixmap->height(), 237 8, 238 bitmapBytesPerRow, 239 cs, 240 kCGImageAlphaPremultipliedFirst); 241 /* Get the CGImageRef from Qt */ 242 CGImageRef qtPixmap = aPixmap->toMacCGImageRef(); 243 /* Draw the image from Qt & convert the context back to a new CGImageRef. */ 244 CGContextDrawImage (ctx, CGRectMake (0, 0, aPixmap->width(), aPixmap->height()), qtPixmap); 245 CGImageRef newImage = CGBitmapContextCreateImage (ctx); 246 /* Now release all used resources */ 247 CGImageRelease (qtPixmap); 248 CGContextRelease (ctx); 249 CGColorSpaceRelease (cs); 250 RTMemFree (pBitmapData); 251 252 /* Return the new CGImageRef */ 253 return newImage; 225 254 } 226 255
Note:
See TracChangeset
for help on using the changeset viewer.