Changeset 82151 in webkit
- Timestamp:
- Mar 28, 2011 1:45:58 PM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r82150 r82151 1 2011-03-28 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 CGImageRefs must hold a strong reference to underlying data 6 https://bugs.webkit.org/show_bug.cgi?id=57263 7 <rdar://problem/9146179> 8 9 Make paintBitmapContext use CGBitmapContextCreateImage, which creates a copy-on-write copy 10 of the bitmap data. Also, add ShareableBitmap::makeCGImageCopy which does the same thing, and 11 ShareableBitmap::makeCGImage in the cases where we know that the ShareableBitmap data will never change. 12 13 * Platform/cg/CGUtilities.cpp: 14 (WebKit::paintImage): 15 Factor image painting code out into a separate function. 16 17 (WebKit::paintBitmapContext): 18 Call paintImage. 19 20 * Shared/API/c/cg/WKImageCG.cpp: 21 (WKImagemakeCGImage): 22 Use ShareableBitmap::makeCGImageCopy. 23 24 * Shared/ShareableBitmap.h: 25 * Shared/cg/ShareableBitmapCG.cpp: 26 (WebKit::ShareableBitmap::createGraphicsContext): 27 (WebKit::ShareableBitmap::paint): 28 (WebKit::ShareableBitmap::makeCGImageCopy): 29 (WebKit::ShareableBitmap::makeCGImage): 30 (WebKit::ShareableBitmap::releaseBitmapContextData): 31 (WebKit::ShareableBitmap::releaseDataProviderData): 32 Add makeCGImage and makeCGImageCopy. 33 34 * Shared/cg/WebCoreArgumentCodersCG.cpp: 35 (CoreIPC::createImage): 36 Use ShareableBitmap::makeCGImage. 37 38 * UIProcess/API/mac/PageClientImpl.mm: 39 (WebKit::PageClientImpl::setDragImage): 40 Use ShareableBitmap::makeCGImage and plug a CGImageRef leak. 41 1 42 2011-03-28 Alexey Proskuryakov <ap@apple.com> 2 43 -
trunk/Source/WebKit2/Platform/cg/CGUtilities.cpp
r76916 r82151 30 30 31 31 namespace WebKit { 32 33 void paint BitmapContext(CGContextRef context, CGContextRef bitmapContext, CGPoint destination, CGRect source)32 33 void paintImage(CGContextRef context, CGImageRef image, CGPoint destination, CGRect source) 34 34 { 35 void* bitmapData = CGBitmapContextGetData(bitmapContext);36 ASSERT(bitmapData);37 38 size_t imageWidth = CGBitmapContextGetWidth(bitmapContext);39 size_t imageHeight = CGBitmapContextGetHeight(bitmapContext);40 41 size_t bytesPerRow = CGBitmapContextGetBytesPerRow(bitmapContext);42 43 RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithData(0, bitmapData, bytesPerRow * imageHeight, 0));44 RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(imageWidth, imageHeight,45 CGBitmapContextGetBitsPerComponent(bitmapContext),46 CGBitmapContextGetBitsPerPixel(bitmapContext),47 bytesPerRow,48 CGBitmapContextGetColorSpace(bitmapContext),49 CGBitmapContextGetBitmapInfo(bitmapContext),50 dataProvider.get(), 0, false, kCGRenderingIntentDefault));51 52 35 CGContextSaveGState(context); 53 36 … … 55 38 CGContextScaleCTM(context, 1, -1); 56 39 40 size_t imageHeight = CGImageGetHeight(image); 41 size_t imageWidth = CGImageGetWidth(image); 42 57 43 CGFloat destX = destination.x - source.origin.x; 58 44 CGFloat destY = -static_cast<CGFloat>(imageHeight) - destination.y + source.origin.y; 59 45 60 CGContextDrawImage(context, CGRectMake(destX, destY, imageWidth, imageHeight), image .get());46 CGContextDrawImage(context, CGRectMake(destX, destY, imageWidth, imageHeight), image); 61 47 CGContextRestoreGState(context); 62 48 } 63 49 50 void paintBitmapContext(CGContextRef context, CGContextRef bitmapContext, CGPoint destination, CGRect source) 51 { 52 RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(bitmapContext)); 53 paintImage(context, image.get(), destination, source); 54 } 55 64 56 } // namespace WebKit 65 57 -
trunk/Source/WebKit2/Platform/cg/CGUtilities.h
r75962 r82151 29 29 namespace WebKit { 30 30 31 void paintImage(CGContextRef, CGImageRef, CGPoint destination, CGRect source); 31 32 void paintBitmapContext(CGContextRef, CGContextRef bitmapContext, CGPoint destination, CGRect source); 32 33 -
trunk/Source/WebKit2/Shared/API/c/cg/WKImageCG.cpp
r81087 r82151 37 37 CGImageRef WKImageCreateCGImage(WKImageRef imageRef) 38 38 { 39 OwnPtr<GraphicsContext> sourceContext = toImpl(imageRef)->bitmap()->createGraphicsContext(); 40 return CGBitmapContextCreateImage(sourceContext->platformContext()); 39 return toImpl(imageRef)->bitmap()->makeCGImageCopy().leakRef(); 41 40 } 42 41 -
trunk/Source/WebKit2/Shared/ShareableBitmap.h
r80917 r82151 33 33 #include <wtf/RefCounted.h> 34 34 #include <wtf/RefPtr.h> 35 36 #if PLATFORM(MAC) 37 #include <wtf/RetainPtr.h> 38 #endif 35 39 36 40 namespace WebCore { … … 72 76 bool isBackedBySharedMemory() const { return m_sharedMemory; } 73 77 78 #if PLATFORM(CG) 79 // This creates a copied CGImageRef (most likely a copy-on-write) of the shareable bitmap. 80 RetainPtr<CGImageRef> makeCGImageCopy(); 81 82 // This creates a CGImageRef that directly references the shared bitmap data. 83 // This is only safe to use when we know that the contents of the shareable bitmap won't change. 84 RetainPtr<CGImageRef> makeCGImage(); 85 #endif 86 74 87 private: 75 88 ShareableBitmap(const WebCore::IntSize&, void*); … … 78 91 static size_t numBytesForSize(const WebCore::IntSize& size) { return size.width() * size.height() * 4; } 79 92 80 static void releaseData(void* typelessBitmap, void* typelessData); 81 93 #if PLATFORM(CG) 94 static void releaseBitmapContextData(void* typelessBitmap, void* typelessData); 95 static void releaseDataProviderData(void* typelessBitmap, const void* typelessData, size_t); 96 #endif 97 82 98 void* data() const; 83 99 size_t sizeInBytes() const { return numBytesForSize(m_size); } -
trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp
r79652 r82151 39 39 RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); 40 40 41 ref(); // Balanced by deref in release Data.41 ref(); // Balanced by deref in releaseBitmapContextData. 42 42 RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreateWithData(data(), 43 43 m_size.width(), m_size.height(), 8, m_size.width() * 4, colorSpace.get(), 44 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, release Data, this));44 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, releaseBitmapContextData, this)); 45 45 46 46 // We want the origin to be in the top left corner so we flip the backing store context. … … 53 53 void ShareableBitmap::paint(WebCore::GraphicsContext& context, const IntPoint& dstPoint, const IntRect& srcRect) 54 54 { 55 paint BitmapContext(context.platformContext(), createGraphicsContext()->platformContext(), dstPoint, srcRect);55 paintImage(context.platformContext(), makeCGImageCopy().get(), dstPoint, srcRect); 56 56 } 57 57 58 void ShareableBitmap::releaseData(void* typelessBitmap, void* typelessData) 58 RetainPtr<CGImageRef> ShareableBitmap::makeCGImageCopy() 59 { 60 OwnPtr<GraphicsContext> graphicsContext = createGraphicsContext(); 61 RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(graphicsContext->platformContext())); 62 return image; 63 } 64 65 RetainPtr<CGImageRef> ShareableBitmap::makeCGImage() 66 { 67 ref(); // Balanced by deref in releaseDataProviderData. 68 RetainPtr<CGDataProvider> dataProvider(AdoptCF, CGDataProviderCreateWithData(this, data(), sizeInBytes(), releaseDataProviderData)); 69 70 RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); 71 RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_size.width() * 4, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, dataProvider.get(), 0, false, kCGRenderingIntentDefault)); 72 return image; 73 } 74 75 void ShareableBitmap::releaseBitmapContextData(void* typelessBitmap, void* typelessData) 59 76 { 60 77 ShareableBitmap* bitmap = static_cast<ShareableBitmap*>(typelessBitmap); … … 63 80 } 64 81 82 void ShareableBitmap::releaseDataProviderData(void* typelessBitmap, const void* typelessData, size_t) 83 { 84 ShareableBitmap* bitmap = static_cast<ShareableBitmap*>(typelessBitmap); 85 ASSERT_UNUSED(typelessData, bitmap->data() == typelessData); 86 bitmap->deref(); // Balanced by ref in createCGImage. 87 } 88 65 89 } // namespace WebKit -
trunk/Source/WebKit2/Shared/cg/WebCoreArgumentCodersCG.cpp
r79652 r82151 37 37 RefPtr<Image> createImage(ShareableBitmap* bitmap) 38 38 { 39 RetainPtr<CGImageRef> platformImage (AdoptCF, CGBitmapContextCreateImage(bitmap->createGraphicsContext()->platformContext()));39 RetainPtr<CGImageRef> platformImage = bitmap->makeCGImage(); 40 40 if (!platformImage) 41 41 return 0; -
trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
r81890 r82151 300 300 void PageClientImpl::setDragImage(const IntPoint& clientPosition, const IntSize& imageSize, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag) 301 301 { 302 OwnPtr<GraphicsContext> graphicsContext = dragImage->createGraphicsContext(); 303 RetainPtr<NSImage> dragNSImage(AdoptNS, [[NSImage alloc] initWithCGImage:CGBitmapContextCreateImage(graphicsContext->platformContext()) size:imageSize]); 302 RetainPtr<CGImageRef> dragCGImage = dragImage->makeCGImage(); 303 RetainPtr<NSImage> dragNSImage(AdoptNS, [[NSImage alloc] initWithCGImage:dragCGImage.get() size:imageSize]); 304 304 305 [m_wkView _setDragImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag]; 305 306 }
Note: See TracChangeset
for help on using the changeset viewer.