+ NSImage *sourceImage;
+ if(useMask)
+ {
+ sourceImage = [m_cocoaNSImage copy];
+ // Apply the mask to the copied image
+ NSBitmapImageRep *maskRep = m_selectedBitmap.GetMask()->GetNSBitmapImageRep();
+ NSImage *maskImage = [[NSImage alloc] initWithSize:[maskRep size]];
+ [maskImage addRepresentation:maskRep];
+ [sourceImage lockFocus];
+ [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn];
+ [sourceImage unlockFocus];
+ [maskImage release];
+ }
+ else
+ { // retain the m_cocoaNSImage so it has the same ownership as the copy done in the other case.
+ sourceImage = [m_cocoaNSImage retain];
+ }
+ NSCompositingOperation drawingOp;
+ switch(logicalFunc)
+ {
+ case wxCOPY:
+ // Even if not using the mask, the image might have an alpha channel
+ // so always use NSCompositeSourceOver. If the image is fully opaque
+ // it works out the same as NSCompositeCopy.
+ drawingOp = NSCompositeSourceOver;
+ break;
+ // FIXME: implement more raster ops
+ default:
+ wxLogDebug(wxT("wxCocoa does not support blitting with raster operation %d."), logicalFunc);
+ // Just use the default operation.
+ drawingOp = NSCompositeCopy;
+ }
+
+ wxLogTrace(wxTRACE_COCOA,wxT("[m_cocoaNSImage isFlipped]=%d"), [m_cocoaNSImage isFlipped]);
+ [sourceImage drawAtPoint: NSMakePoint(0,0)