diff --git a/widget/src/cocoa/nsClipboard.mm b/widget/src/cocoa/nsClipboard.mm index c6c2b6ffa223..18ca3f169eba 100644 --- a/widget/src/cocoa/nsClipboard.mm +++ b/widget/src/cocoa/nsClipboard.mm @@ -451,8 +451,15 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable) continue; } + nsRefPtr frame; + rv = image->CopyFrame( imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE, + getter_AddRefs(frame)); + if (NS_FAILED(rv) || !frame) { + continue; + } CGImageRef imageRef = NULL; - nsresult rv = nsCocoaUtils::CreateCGImageFromImageContainer(image, imgIContainer::FRAME_CURRENT, &imageRef); + nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &imageRef); if (NS_FAILED(rv) || !imageRef) { continue; } diff --git a/widget/src/cocoa/nsCocoaUtils.h b/widget/src/cocoa/nsCocoaUtils.h index b5c613ec389d..0777afc497f0 100644 --- a/widget/src/cocoa/nsCocoaUtils.h +++ b/widget/src/cocoa/nsCocoaUtils.h @@ -138,12 +138,11 @@ class nsCocoaUtils /** Creates a CGImageRef from a frame contained in an imgIContainer. Copies the pixel data from the indicated frame of the imgIContainer into a new CGImageRef. The caller owns the CGImageRef. - @param aImage the image to extract a frame from - @param aWhichFrame the frame to extract (see imgIContainer FRAME_*) + @param aFrame the frame to convert @param aResult the resulting CGImageRef @return NS_OK if the conversion worked, NS_ERROR_FAILURE otherwise */ - static nsresult CreateCGImageFromImageContainer(imgIContainer *aImage, PRUint32 aWhichFrame, CGImageRef *aResult); + static nsresult CreateCGImageFromSurface(gfxImageSurface *aFrame, CGImageRef *aResult); /** Creates a Cocoa NSImage from a CGImageRef. Copies the pixel data from the CGImageRef into a new NSImage. diff --git a/widget/src/cocoa/nsCocoaUtils.mm b/widget/src/cocoa/nsCocoaUtils.mm index b8a5196ec0c1..8d270018de63 100644 --- a/widget/src/cocoa/nsCocoaUtils.mm +++ b/widget/src/cocoa/nsCocoaUtils.mm @@ -245,19 +245,12 @@ void nsCocoaUtils::CleanUpAfterNativeAppModalDialog() NS_OBJC_END_TRY_ABORT_BLOCK; } -nsresult nsCocoaUtils::CreateCGImageFromImageContainer(imgIContainer *aImage, PRUint32 aWhichFrame, CGImageRef *aResult) +nsresult nsCocoaUtils::CreateCGImageFromSurface(gfxImageSurface *aFrame, CGImageRef *aResult) { - nsRefPtr frame; - nsresult rv = aImage->CopyFrame(aWhichFrame, - imgIContainer::FLAG_SYNC_DECODE, - getter_AddRefs(frame)); - if (NS_FAILED(rv) || !frame) { - return NS_ERROR_FAILURE; - } - PRInt32 width = frame->Width(); - PRInt32 stride = frame->Stride(); - PRInt32 height = frame->Height(); + PRInt32 width = aFrame->Width(); + PRInt32 stride = aFrame->Stride(); + PRInt32 height = aFrame->Height(); if ((stride % 4 != 0) || (height < 1) || (width < 1)) { return NS_ERROR_FAILURE; } @@ -266,7 +259,7 @@ nsresult nsCocoaUtils::CreateCGImageFromImageContainer(imgIContainer *aImage, PR // the alpha ordering and endianness of the machine so we don't have to // touch the bits ourselves. CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(NULL, - frame->Data(), + aFrame->Data(), stride * height, NULL); CGColorSpaceRef colorSpace = ::CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); @@ -311,8 +304,15 @@ nsresult nsCocoaUtils::CreateNSImageFromCGImage(CGImageRef aInputImage, NSImage nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, PRUint32 aWhichFrame, NSImage **aResult) { + nsRefPtr frame; + nsresult rv = aImage->CopyFrame(aWhichFrame, + imgIContainer::FLAG_SYNC_DECODE, + getter_AddRefs(frame)); + if (NS_FAILED(rv) || !frame) { + return NS_ERROR_FAILURE; + } CGImageRef imageRef = NULL; - nsresult rv = nsCocoaUtils::CreateCGImageFromImageContainer(aImage, aWhichFrame, &imageRef); + rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &imageRef); if (NS_FAILED(rv) || !imageRef) { return NS_ERROR_FAILURE; } diff --git a/widget/src/cocoa/nsMenuItemIconX.mm b/widget/src/cocoa/nsMenuItemIconX.mm index 831447fe5691..8ddba74f634c 100644 --- a/widget/src/cocoa/nsMenuItemIconX.mm +++ b/widget/src/cocoa/nsMenuItemIconX.mm @@ -439,10 +439,16 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest, mImageRegionRect.SetRect(0, 0, origWidth, origHeight); } + nsRefPtr frame; + nsresult rv = imageContainer->CopyFrame( imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE, + getter_AddRefs(frame)); + if (NS_FAILED(rv) || !frame) { + [mNativeMenuItem setImage:nil]; + return NS_ERROR_FAILURE; + } CGImageRef origImage = NULL; - nsresult rv = nsCocoaUtils::CreateCGImageFromImageContainer(imageContainer, - imgIContainer::FRAME_CURRENT, - &origImage); + rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &origImage); if (NS_FAILED(rv) || !origImage) { [mNativeMenuItem setImage:nil]; return NS_ERROR_FAILURE; @@ -487,6 +493,7 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest, return NS_ERROR_FAILURE; } CGRect iconRect = ::CGRectMake(0, 0, kIconWidth, kIconHeight); + ::CGContextClearRect(bitmapContext, iconRect); ::CGContextDrawImage(bitmapContext, iconRect, finalImage); CGImageRef iconImage = ::CGBitmapContextCreateImage(bitmapContext);