Move the BitmapImage platform dependent code to a new file named NativeImage[CG|Cairo...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 01:06:47 +0000 (01:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 01:06:47 +0000 (01:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158684

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2016-09-08
Reviewed by Simon Fraser.

Source/WebCore:

This is a refactoring patch. It moves the BitmapImage platform dependent
code from BitmapImage to NativeImage[CG|Cairo].cpp. The new APIs are
responsible of drawing a NativeImagePtr and answering some metadata queries.

No new tests -- Code refactoring, no behavior change.

* PlatformAppleWin.cmake:
* PlatformEfl.cmake:
* PlatformGTK.cmake:
* PlatformMac.cmake:
* PlatformWinCairo.cmake:
* WebCore.xcodeproj/project.pbxproj:
* loader/cache/MemoryCache.h:
* loader/icon/IconDatabaseBase.h:
* page/mac/TextIndicatorWindow.mm:
(-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
(createContentCrossfadeAnimation):
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::destroyDecodedData):
(WebCore::BitmapImage::destroyDecodedDataIfNecessary):
(WebCore::BitmapImage::dataChanged):
(WebCore::BitmapImage::ensureFrameAtIndexIsCached):
(WebCore::BitmapImage::frameImageAtIndex):
(WebCore::BitmapImage::nativeImage):
(WebCore::BitmapImage::nativeImageForCurrentFrame):
(WebCore::BitmapImage::nativeImageOfSize):
(WebCore::BitmapImage::framesNativeImages):
(WebCore::BitmapImage::frameIsCompleteAtIndex):
(WebCore::BitmapImage::frameDurationAtIndex):
(WebCore::BitmapImage::frameHasAlphaAtIndex):
(WebCore::BitmapImage::frameOrientationAtIndex):
(WebCore::BitmapImage::singlePixelSolidColor):
(WebCore::BitmapImage::draw):
(WebCore::BitmapImage::drawPattern):
(WebCore::BitmapImage::canAnimate):
(WebCore::BitmapImage::clearTimer):
(WebCore::BitmapImage::startTimer):
(WebCore::BitmapImage::stopAnimation):
(WebCore::BitmapImage::resetAnimation):
(WebCore::BitmapImage::hasSingleSecurityOrigin): Deleted.
(WebCore::BitmapImage::filenameExtension): Deleted.
(WebCore::BitmapImage::ensureFrameIsCached): Deleted.
* platform/graphics/BitmapImage.h:
(WebCore::FrameData::FrameData):
m_hasAlpha can be initialized with false because it is accessed only in
BitmapImage::frameHasAlphaAtIndex() and it is guarded by m_haveMetadata.
Both m_haveMetadata and m_hasAlpha are set in BitmapImage constructor
and in BitmapImage::cacheFrame().

(WebCore::FrameData::~FrameData):
(WebCore::FrameData::clear):
* platform/graphics/Icon.h:
* platform/graphics/Image.h:
(WebCore::Image::nativeImage):
(WebCore::Image::nativeImageOfSize):
(WebCore::Image::framesNativeImages):
(WebCore::Image::orientationForCurrentFrame): Deleted.
(WebCore::Image::getCGImageRef): Deleted.
(WebCore::Image::getFirstCGImageRefOfSize): Deleted.
(WebCore::Image::getCGImageArray): Deleted.
* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::calculateMaximumSubsamplingLevel):
(WebCore::ImageSource::size):
(WebCore::ImageSource::sizeRespectingOrientation):
* platform/graphics/ImageSource.h:
* platform/graphics/MediaPlayer.h:
* platform/graphics/NativeImage.h: Added.
* platform/graphics/NativeImagePtr.h: Removed.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage):
* platform/graphics/cairo/BitmapImageCairo.cpp: Removed.
* platform/graphics/cairo/NativeImageCairo.cpp: Added.
(WebCore::nativeImageSize):
(WebCore::nativeImageHasAlpha):
(WebCore::nativeImageSinglePixelSolidColor):
(WebCore::subsamplingScale):
(WebCore::drawNativeImage):
(WebCore::clearNativeImageSubImages):
* platform/graphics/cg/BitmapImageCG.cpp: Removed.
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoder::size):
* platform/graphics/cg/ImageDecoderCG.h:
* platform/graphics/cg/NativeImageCG.cpp: Added.
(WebCore::nativeImageSize):
(WebCore::nativeImageHasAlpha):
(WebCore::nativeImageSinglePixelSolidColor):
(WebCore::subsamplingScale):
(WebCore::drawNativeImage):
(WebCore::clearNativeImageSubImages):
* platform/graphics/cg/PatternCG.cpp:
(WebCore::Pattern::createPlatformPattern):
* platform/graphics/cocoa/TextTrackRepresentationCocoa.mm:
(TextTrackRepresentationCocoa::update):
* platform/graphics/mac/ImageMac.mm:
(WebCore::BitmapImage::getTIFFRepresentation):
* platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
(WebCore::MockRealtimeVideoSourceMac::updatePlatformLayer):
(WebCore::MockRealtimeVideoSourceMac::updateSampleBuffer):
* platform/win/DragImageCGWin.cpp:
(WebCore::createDragImageFromImage):

Source/WebKit/mac:

* DOM/DOM.mm:
(-[DOMNode getPreviewSnapshotImage:andRects:]):
* Misc/WebCache.mm:
(+[WebCache imageForURL:]):
Replace BitmapImage::getCGImageRef() with BitmapImage::nativeImage().

Source/WebKit2:

* UIProcess/API/C/cg/WKIconDatabaseCG.cpp:
(WKIconDatabaseTryGetCGImageForURL):
(WKIconDatabaseTryCopyCGImageArrayForURL):
It was the only place in the code which uses BitmapImage::getCGImageArray().
Call BitmapImage::framesNativeImages() instead and form the returned
Vector<NativeImagePtr> build the CFArrayRef.

* UIProcess/WebIconDatabase.h:
Include "NativeImage.h" instead of "NativeImagePtr.h".

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _presentationSnapshotForPreviewItemController:]):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::isAlmostSolidColor):
Call BitmapImage::getCGImageRef() instead of calling BitmapImage::nativeImage().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205682 268f45cc-cd09-0410-ab3c-d52691b4dbfc

38 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformAppleWin.cmake
Source/WebCore/PlatformEfl.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/PlatformMac.cmake
Source/WebCore/PlatformWinCairo.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/cache/MemoryCache.h
Source/WebCore/loader/icon/IconDatabaseBase.h
Source/WebCore/page/mac/TextIndicatorWindow.mm
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/BitmapImage.h
Source/WebCore/platform/graphics/Icon.h
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/ImageSource.cpp
Source/WebCore/platform/graphics/ImageSource.h
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/NativeImage.h [moved from Source/WebCore/platform/graphics/NativeImagePtr.h with 71% similarity]
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp [deleted file]
Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp [deleted file]
Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp
Source/WebCore/platform/graphics/cg/ImageDecoderCG.h
Source/WebCore/platform/graphics/cg/NativeImageCG.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/cg/PatternCG.cpp
Source/WebCore/platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
Source/WebCore/platform/graphics/mac/ImageMac.mm
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
Source/WebCore/platform/win/DragImageCGWin.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOM.mm
Source/WebKit/mac/Misc/WebCache.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/cg/WKIconDatabaseCG.cpp
Source/WebKit2/UIProcess/WebIconDatabase.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/Plugins/PluginView.cpp

index 71d741a..4f54e84 100644 (file)
@@ -1,3 +1,112 @@
+2016-09-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Move the BitmapImage platform dependent code to a new file named NativeImage[CG|Cairo].cpp
+        https://bugs.webkit.org/show_bug.cgi?id=158684
+
+        Reviewed by Simon Fraser.
+
+        This is a refactoring patch. It moves the BitmapImage platform dependent
+        code from BitmapImage to NativeImage[CG|Cairo].cpp. The new APIs are
+        responsible of drawing a NativeImagePtr and answering some metadata queries.
+
+        No new tests -- Code refactoring, no behavior change.
+
+        * PlatformAppleWin.cmake:
+        * PlatformEfl.cmake:
+        * PlatformGTK.cmake:
+        * PlatformMac.cmake:
+        * PlatformWinCairo.cmake:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/cache/MemoryCache.h:
+        * loader/icon/IconDatabaseBase.h:
+        * page/mac/TextIndicatorWindow.mm:
+        (-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
+        (createContentCrossfadeAnimation):
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::BitmapImage):
+        (WebCore::BitmapImage::destroyDecodedData):
+        (WebCore::BitmapImage::destroyDecodedDataIfNecessary):
+        (WebCore::BitmapImage::dataChanged):
+        (WebCore::BitmapImage::ensureFrameAtIndexIsCached):
+        (WebCore::BitmapImage::frameImageAtIndex):
+        (WebCore::BitmapImage::nativeImage):
+        (WebCore::BitmapImage::nativeImageForCurrentFrame):
+        (WebCore::BitmapImage::nativeImageOfSize):
+        (WebCore::BitmapImage::framesNativeImages):
+        (WebCore::BitmapImage::frameIsCompleteAtIndex):
+        (WebCore::BitmapImage::frameDurationAtIndex):
+        (WebCore::BitmapImage::frameHasAlphaAtIndex):
+        (WebCore::BitmapImage::frameOrientationAtIndex):
+        (WebCore::BitmapImage::singlePixelSolidColor):
+        (WebCore::BitmapImage::draw):
+        (WebCore::BitmapImage::drawPattern):
+        (WebCore::BitmapImage::canAnimate):
+        (WebCore::BitmapImage::clearTimer):
+        (WebCore::BitmapImage::startTimer):
+        (WebCore::BitmapImage::stopAnimation):
+        (WebCore::BitmapImage::resetAnimation):
+        (WebCore::BitmapImage::hasSingleSecurityOrigin): Deleted.
+        (WebCore::BitmapImage::filenameExtension): Deleted.
+        (WebCore::BitmapImage::ensureFrameIsCached): Deleted.
+        * platform/graphics/BitmapImage.h:
+        (WebCore::FrameData::FrameData):
+        m_hasAlpha can be initialized with false because it is accessed only in
+        BitmapImage::frameHasAlphaAtIndex() and it is guarded by m_haveMetadata.
+        Both m_haveMetadata and m_hasAlpha are set in BitmapImage constructor
+        and in BitmapImage::cacheFrame().
+        
+        (WebCore::FrameData::~FrameData):
+        (WebCore::FrameData::clear):
+        * platform/graphics/Icon.h:
+        * platform/graphics/Image.h:
+        (WebCore::Image::nativeImage):
+        (WebCore::Image::nativeImageOfSize):
+        (WebCore::Image::framesNativeImages):
+        (WebCore::Image::orientationForCurrentFrame): Deleted.
+        (WebCore::Image::getCGImageRef): Deleted.
+        (WebCore::Image::getFirstCGImageRefOfSize): Deleted.
+        (WebCore::Image::getCGImageArray): Deleted.
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::calculateMaximumSubsamplingLevel):
+        (WebCore::ImageSource::size):
+        (WebCore::ImageSource::sizeRespectingOrientation):
+        * platform/graphics/ImageSource.h:
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/NativeImage.h: Added.
+        * platform/graphics/NativeImagePtr.h: Removed.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage):
+        * platform/graphics/cairo/BitmapImageCairo.cpp: Removed.
+        * platform/graphics/cairo/NativeImageCairo.cpp: Added.
+        (WebCore::nativeImageSize):
+        (WebCore::nativeImageHasAlpha):
+        (WebCore::nativeImageSinglePixelSolidColor):
+        (WebCore::subsamplingScale):
+        (WebCore::drawNativeImage):
+        (WebCore::clearNativeImageSubImages):
+        * platform/graphics/cg/BitmapImageCG.cpp: Removed.
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoder::size):
+        * platform/graphics/cg/ImageDecoderCG.h:
+        * platform/graphics/cg/NativeImageCG.cpp: Added.
+        (WebCore::nativeImageSize):
+        (WebCore::nativeImageHasAlpha):
+        (WebCore::nativeImageSinglePixelSolidColor):
+        (WebCore::subsamplingScale):
+        (WebCore::drawNativeImage):
+        (WebCore::clearNativeImageSubImages):
+        * platform/graphics/cg/PatternCG.cpp:
+        (WebCore::Pattern::createPlatformPattern):
+        * platform/graphics/cocoa/TextTrackRepresentationCocoa.mm:
+        (TextTrackRepresentationCocoa::update):
+        * platform/graphics/mac/ImageMac.mm:
+        (WebCore::BitmapImage::getTIFFRepresentation):
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
+        (WebCore::MockRealtimeVideoSourceMac::updatePlatformLayer):
+        (WebCore::MockRealtimeVideoSourceMac::updateSampleBuffer):
+        * platform/win/DragImageCGWin.cpp:
+        (WebCore::createDragImageFromImage):
+
 2016-09-08  Alex Christensen  <achristensen@webkit.org>
 
         URLParser: Parsing empty URLs with a base URL should return the base URL
index a6e4c25..aee5a25 100644 (file)
@@ -55,7 +55,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/ca/win/WebTiledBackingLayerWin.cpp
     platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp
 
-    platform/graphics/cg/BitmapImageCG.cpp
     platform/graphics/cg/ColorCG.cpp
     platform/graphics/cg/FloatPointCG.cpp
     platform/graphics/cg/FloatRectCG.cpp
@@ -72,6 +71,7 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cg/IntPointCG.cpp
     platform/graphics/cg/IntRectCG.cpp
     platform/graphics/cg/IntSizeCG.cpp
+    platform/graphics/cg/NativeImageCG.cpp
     platform/graphics/cg/PDFDocumentImage.cpp
     platform/graphics/cg/PathCG.cpp
     platform/graphics/cg/PatternCG.cpp
index bd0ba40..0201052 100644 (file)
@@ -126,7 +126,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/PlatformDisplay.cpp
 
     platform/graphics/cairo/BackingStoreBackendCairoImpl.cpp
-    platform/graphics/cairo/BitmapImageCairo.cpp
     platform/graphics/cairo/CairoUtilities.cpp
     platform/graphics/cairo/FontCairo.cpp
     platform/graphics/cairo/FontCairoHarfbuzzNG.cpp
@@ -135,6 +134,7 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cairo/ImageBufferCairo.cpp
     platform/graphics/cairo/ImageCairo.cpp
     platform/graphics/cairo/IntRectCairo.cpp
+    platform/graphics/cairo/NativeImageCairo.cpp
     platform/graphics/cairo/PathCairo.cpp
     platform/graphics/cairo/PatternCairo.cpp
     platform/graphics/cairo/PlatformContextCairo.cpp
index f21fc04..8a37887 100644 (file)
@@ -105,7 +105,6 @@ list(APPEND WebCore_SOURCES
 
     platform/graphics/cairo/BackingStoreBackendCairoImpl.cpp
     platform/graphics/cairo/BackingStoreBackendCairoX11.cpp
-    platform/graphics/cairo/BitmapImageCairo.cpp
     platform/graphics/cairo/CairoUtilities.cpp
     platform/graphics/cairo/FloatRectCairo.cpp
     platform/graphics/cairo/FontCairo.cpp
@@ -116,6 +115,7 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cairo/ImageBufferCairo.cpp
     platform/graphics/cairo/ImageCairo.cpp
     platform/graphics/cairo/IntRectCairo.cpp
+    platform/graphics/cairo/NativeImageCairo.cpp
     platform/graphics/cairo/PathCairo.cpp
     platform/graphics/cairo/PatternCairo.cpp
     platform/graphics/cairo/PlatformContextCairo.cpp
index d2e66a3..4a8f862 100644 (file)
@@ -385,7 +385,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/ca/cocoa/WebSystemBackdropLayer.mm
     platform/graphics/ca/cocoa/WebTiledBackingLayer.mm
 
-    platform/graphics/cg/BitmapImageCG.cpp
     platform/graphics/cg/ColorCG.cpp
     platform/graphics/cg/FloatPointCG.cpp
     platform/graphics/cg/FloatRectCG.cpp
@@ -402,6 +401,7 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cg/IntPointCG.cpp
     platform/graphics/cg/IntRectCG.cpp
     platform/graphics/cg/IntSizeCG.cpp
+    platform/graphics/cg/NativeImageCG.cpp
     platform/graphics/cg/PDFDocumentImage.cpp
     platform/graphics/cg/PathCG.cpp
     platform/graphics/cg/PatternCG.cpp
index 957e88c..b843b4c 100644 (file)
@@ -21,7 +21,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/GLContext.cpp
     platform/graphics/PlatformDisplay.cpp
 
-    platform/graphics/cairo/BitmapImageCairo.cpp
     platform/graphics/cairo/CairoUtilities.cpp
     platform/graphics/cairo/FloatRectCairo.cpp
     platform/graphics/cairo/FontCairo.cpp
@@ -31,6 +30,7 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cairo/ImageBufferCairo.cpp
     platform/graphics/cairo/ImageCairo.cpp
     platform/graphics/cairo/IntRectCairo.cpp
+    platform/graphics/cairo/NativeImageCairo.cpp
     platform/graphics/cairo/PathCairo.cpp
     platform/graphics/cairo/PatternCairo.cpp
     platform/graphics/cairo/PlatformContextCairo.cpp
index bc6c272..009c064 100644 (file)
                375CD232119D43C800A2A859 /* Hyphenation.h in Headers */ = {isa = PBXBuildFile; fileRef = 375CD231119D43C800A2A859 /* Hyphenation.h */; };
                376DCCE113B4F966002EBEFC /* TextRun.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 376DCCE013B4F966002EBEFC /* TextRun.cpp */; };
                3774ABA50FA21EB400AD7DE9 /* OverlapTestRequestClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */; };
+               377A3A9015EFCE9B0059F5C7 /* NativeImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377A3A8F15EFCE9A0059F5C7 /* NativeImageCG.cpp */; };
                37919C230B7D188600A56998 /* PositionIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37919C210B7D188600A56998 /* PositionIterator.cpp */; };
                37919C240B7D188600A56998 /* PositionIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 37919C220B7D188600A56998 /* PositionIterator.h */; settings = {ATTRIBUTES = (); }; };
                3792917A1985EF3900F4B661 /* CredentialBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 379291781985EF3900F4B661 /* CredentialBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
                555B87EC1CAAF0AB00349425 /* ImageDecoderCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */; };
                555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */; };
+               55A336F71D8209F40022C4C7 /* NativeImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 55A336F61D8209F40022C4C7 /* NativeImage.h */; };
                5709E8CD1D413D47003244AC /* WebKitSubtleCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5709E8CA1D413CE3003244AC /* WebKitSubtleCrypto.cpp */; };
                5709E8CE1D413D5B003244AC /* JSWebKitSubtleCryptoCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF8F661807460800132674 /* JSWebKitSubtleCryptoCustom.cpp */; };
                5709E8CF1D413D9A003244AC /* WebKitSubtleCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 5709E8CB1D413CE3003244AC /* WebKitSubtleCrypto.h */; };
                65FEA86909833ADE00BED4AB /* Page.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65FEA86809833ADE00BED4AB /* Page.cpp */; };
                69A6CBAC1C6BE42C00B836E9 /* AccessibilitySVGElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 697101071C6BE1550018C7F1 /* AccessibilitySVGElement.cpp */; };
                69A6CBAD1C6BE42C00B836E9 /* AccessibilitySVGElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 697101081C6BE1550018C7F1 /* AccessibilitySVGElement.h */; };
-               6B3480940EEF50D400AC1B41 /* NativeImagePtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3480920EEF50D400AC1B41 /* NativeImagePtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               6B3480940EEF50D400AC1B41 /* NativeImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3480920EEF50D400AC1B41 /* NativeImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6B693A2E1C51A82E00B03BEF /* ResourceLoadObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B693A2D1C51A82E00B03BEF /* ResourceLoadObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6B693A341C51A95D00B03BEF /* ResourceLoadObserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B693A331C51A95D00B03BEF /* ResourceLoadObserver.cpp */; };
                6C4C96DE1AD4483500365A50 /* JSReadableStreamDefaultController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6C4C96DA1AD4483500365A50 /* JSReadableStreamDefaultController.cpp */; };
                376DCCE013B4F966002EBEFC /* TextRun.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextRun.cpp; sourceTree = "<group>"; };
                3772B09516535856000A49CA /* PopupOpeningObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PopupOpeningObserver.h; sourceTree = "<group>"; };
                3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverlapTestRequestClient.h; sourceTree = "<group>"; };
-               377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitmapImageCG.cpp; sourceTree = "<group>"; };
+               377A3A8F15EFCE9A0059F5C7 /* NativeImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NativeImageCG.cpp; sourceTree = "<group>"; };
                37919C210B7D188600A56998 /* PositionIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PositionIterator.cpp; sourceTree = "<group>"; };
                37919C220B7D188600A56998 /* PositionIterator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PositionIterator.h; sourceTree = "<group>"; };
                379291781985EF3900F4B661 /* CredentialBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CredentialBase.h; sourceTree = "<group>"; };
                550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageDecoderCG.cpp; sourceTree = "<group>"; };
                555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageDecoderCG.h; sourceTree = "<group>"; };
+               55A336F61D8209F40022C4C7 /* NativeImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeImage.h; sourceTree = "<group>"; };
                55D408F71A7C631800C78450 /* SVGImageClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGImageClients.h; sourceTree = "<group>"; };
                5709E8CA1D413CE3003244AC /* WebKitSubtleCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitSubtleCrypto.cpp; sourceTree = "<group>"; };
                5709E8CB1D413CE3003244AC /* WebKitSubtleCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitSubtleCrypto.h; sourceTree = "<group>"; };
                65FEA86809833ADE00BED4AB /* Page.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Page.cpp; sourceTree = "<group>"; };
                697101071C6BE1550018C7F1 /* AccessibilitySVGElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilitySVGElement.cpp; sourceTree = "<group>"; };
                697101081C6BE1550018C7F1 /* AccessibilitySVGElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilitySVGElement.h; sourceTree = "<group>"; };
-               6B3480920EEF50D400AC1B41 /* NativeImagePtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NativeImagePtr.h; sourceTree = "<group>"; };
+               6B3480920EEF50D400AC1B41 /* NativeImage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NativeImage.h; sourceTree = "<group>"; };
                6B693A2D1C51A82E00B03BEF /* ResourceLoadObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadObserver.h; sourceTree = "<group>"; };
                6B693A331C51A95D00B03BEF /* ResourceLoadObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadObserver.cpp; sourceTree = "<group>"; };
                6C4C96DA1AD4483500365A50 /* JSReadableStreamDefaultController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamDefaultController.cpp; sourceTree = "<group>"; };
                B27535290B053814002CE64F /* cg */ = {
                        isa = PBXGroup;
                        children = (
-                               377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */,
                                0FCF33230F2B9715004B6795 /* ColorCG.cpp */,
                                B275352B0B053814002CE64F /* FloatPointCG.cpp */,
                                B275352C0B053814002CE64F /* FloatRectCG.cpp */,
                                A80A38FD0E50CC8200A25EBC /* PatternCG.cpp */,
                                B27535360B053814002CE64F /* PDFDocumentImage.cpp */,
                                B27535370B053814002CE64F /* PDFDocumentImage.h */,
+                               377A3A8F15EFCE9A0059F5C7 /* NativeImageCG.cpp */,
                                1FC40FB81655C5910040F29E /* SubimageCacheWithTimer.cpp */,
                                1FC40FB71655C5910040F29E /* SubimageCacheWithTimer.h */,
                                B275352A0B053814002CE64F /* TransformationMatrixCG.cpp */,
                                CDDC1E7918A952F30027A9D4 /* MediaSourcePrivateClient.h */,
                                314BE3A41B3103FB00141982 /* NamedImageGeneratedImage.cpp */,
                                314BE3A51B3103FB00141982 /* NamedImageGeneratedImage.h */,
-                               6B3480920EEF50D400AC1B41 /* NativeImagePtr.h */,
+                               6B3480920EEF50D400AC1B41 /* NativeImage.h */,
                                B27535520B053814002CE64F /* Path.cpp */,
                                B27535530B053814002CE64F /* Path.h */,
                                A88DD4880B4629B000C02990 /* PathTraversalState.cpp */,
                                501BAAA813950E2C00F7ACEB /* WindRule.h */,
                                379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
                                379919951200DDF400EA041C /* WOFFFileFormat.h */,
+                               55A336F61D8209F40022C4C7 /* NativeImage.h */,
                        );
                        path = graphics;
                        sourceTree = "<group>";
                                314BE3A71B3103FB00141982 /* NamedImageGeneratedImage.h in Headers */,
                                A81872230977D3C0005826D9 /* NamedNodeMap.h in Headers */,
                                A818721E0977D3C0005826D9 /* NameNodeList.h in Headers */,
-                               6B3480940EEF50D400AC1B41 /* NativeImagePtr.h in Headers */,
+                               6B3480940EEF50D400AC1B41 /* NativeImage.h in Headers */,
                                83B2D1751B8BCD6A00A02E47 /* NativeNodeFilter.h in Headers */,
                                E10B9B6C0B747599003ED890 /* NativeXPathNSResolver.h in Headers */,
                                93CCF0270AF6C52900018E89 /* NavigationAction.h in Headers */,
                                1A569D150D7E2B82007C3983 /* objc_instance.h in Headers */,
                                1A569D170D7E2B82007C3983 /* objc_runtime.h in Headers */,
                                1A569D190D7E2B82007C3983 /* objc_utility.h in Headers */,
+                               55A336F71D8209F40022C4C7 /* NativeImage.h in Headers */,
                                E16982551134629D00894115 /* ObjCRuntimeObject.h in Headers */,
                                7E5D7A77161D3F8F00896C34 /* OESElementIndexUint.h in Headers */,
                                9001774112E0347800648462 /* OESStandardDerivatives.h in Headers */,
                                FDC54F041399B0DA008D9117 /* BiquadFilterNode.cpp in Sources */,
                                FD31602612B0267600C1A359 /* BiquadProcessor.cpp in Sources */,
                                A89943290B42338800D7C802 /* BitmapImage.cpp in Sources */,
-                               377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */,
+                               377A3A9015EFCE9B0059F5C7 /* NativeImageCG.cpp in Sources */,
                                1AFFC4541D5E81CB00267A66 /* BlacklistUpdater.mm in Sources */,
                                976D6C78122B8A3D001FD1F7 /* Blob.cpp in Sources */,
                                2EDEF1F3121B0EFC00726DB2 /* BlobData.cpp in Sources */,
index 6be1747..0774948 100644 (file)
@@ -25,7 +25,7 @@
 #ifndef Cache_h
 #define Cache_h
 
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include "SecurityOriginHash.h"
 #include "SessionID.h"
 #include "Timer.h"
index 544cbac..78603b4 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef IconDatabaseBase_h
 #define IconDatabaseBase_h
 
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PassRefPtr.h>
index 364a9a8..a74da85 100644 (file)
@@ -162,9 +162,9 @@ static bool indicatorWantsManualAnimation(const TextIndicator& indicator)
     contentsImageLogicalSize.scale(1 / _textIndicator->contentImageScaleFactor());
     RetainPtr<CGImageRef> contentsImage;
     if (indicatorWantsContentCrossfade(*_textIndicator))
-        contentsImage = _textIndicator->contentImageWithHighlight()->getCGImageRef();
+        contentsImage = _textIndicator->contentImageWithHighlight()->nativeImage();
     else
-        contentsImage = _textIndicator->contentImage()->getCGImageRef();
+        contentsImage = _textIndicator->contentImage()->nativeImage();
 
     RetainPtr<NSMutableArray> bounceLayers = adoptNS([[NSMutableArray alloc] init]);
 
@@ -265,7 +265,7 @@ static RetainPtr<CAKeyframeAnimation> createBounceAnimation(CFTimeInterval durat
 static RetainPtr<CABasicAnimation> createContentCrossfadeAnimation(CFTimeInterval duration, TextIndicator& textIndicator)
 {
     RetainPtr<CABasicAnimation> crossfadeAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];
-    RetainPtr<CGImageRef> contentsImage = textIndicator.contentImage()->getCGImageRef();
+    RetainPtr<CGImageRef> contentsImage = textIndicator.contentImage()->nativeImage();
     [crossfadeAnimation setToValue:(id)contentsImage.get()];
     [crossfadeAnimation setFillMode:kCAFillModeForwards];
     [crossfadeAnimation setRemovedOnCompletion:NO];
index 46d9870..0ee4858 100644 (file)
@@ -70,11 +70,11 @@ BitmapImage::BitmapImage(NativeImagePtr&& image, ImageObserver* observer)
 {
     // Since we don't have a decoder, we can't figure out the image orientation.
     // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
-    m_sizeRespectingOrientation = m_size = NativeImage::size(image);
+    m_sizeRespectingOrientation = m_size = nativeImageSize(image);
     m_decodedSize = m_size.area() * 4;
-    
+
     m_frames.grow(1);
-    m_frames[0].m_hasAlpha = NativeImage::hasAlpha(image);
+    m_frames[0].m_hasAlpha = nativeImageHasAlpha(image);
     m_frames[0].m_haveMetadata = true;
     m_frames[0].m_image = WTFMove(image);
 }
@@ -85,18 +85,6 @@ BitmapImage::~BitmapImage()
     stopAnimation();
 }
 
-void BitmapImage::clearTimer()
-{
-    m_frameTimer = nullptr;
-}
-
-void BitmapImage::startTimer(double delay)
-{
-    ASSERT(!m_frameTimer);
-    m_frameTimer = std::make_unique<Timer>(*this, &BitmapImage::advanceAnimation);
-    m_frameTimer->startOneShot(delay);
-}
-
 bool BitmapImage::haveFrameImageAtIndex(size_t index)
 {
     if (index >= frameCount())
@@ -108,11 +96,6 @@ bool BitmapImage::haveFrameImageAtIndex(size_t index)
     return m_frames[index].m_image;
 }
 
-bool BitmapImage::hasSingleSecurityOrigin() const
-{
-    return true;
-}
-
 void BitmapImage::destroyDecodedData(bool destroyAll)
 {
     unsigned frameBytesCleared = 0;
@@ -125,9 +108,7 @@ void BitmapImage::destroyDecodedData(bool destroyAll)
         // The underlying frame isn't actually changing (we're just trying to
         // save the memory for the framebuffer data), so we don't need to clear
         // the metadata.
-        unsigned frameBytes = m_frames[i].m_frameBytes;
-        if (m_frames[i].clear(false))
-            frameBytesCleared += frameBytes;
+        frameBytesCleared += m_frames[i].clear(false);
     }
 
     m_source.clear(destroyAll, clearBeforeFrame, data(), m_allDataReceived);
@@ -150,8 +131,8 @@ void BitmapImage::destroyDecodedDataIfNecessary(bool destroyAll)
         return;
 
     unsigned allFrameBytes = 0;
-    for (size_t i = 0; i < m_frames.size(); ++i)
-        allFrameBytes += m_frames[i].usedFrameBytes();
+    for (auto& frame : m_frames)
+        allFrameBytes += frame.usedFrameBytes();
 
     if (allFrameBytes > largeAnimationCutoff) {
         LOG(Images, "BitmapImage %p destroyDecodedDataIfNecessary destroyingData: allFrameBytes=%u cutoff=%u", this, allFrameBytes, largeAnimationCutoff);
@@ -288,21 +269,19 @@ bool BitmapImage::dataChanged(bool allDataReceived)
     // frame affected by appending new data here. Thus we have to clear all the
     // incomplete frames to be safe.
     unsigned frameBytesCleared = 0;
-    for (size_t i = 0; i < m_frames.size(); ++i) {
+    for (auto& frame : m_frames) {
         // NOTE: Don't call frameIsCompleteAtIndex() here, that will try to
         // decode any uncached (i.e. never-decoded or
         // cleared-on-a-previous-pass) frames!
-        unsigned frameBytes = m_frames[i].m_frameBytes;
-        if (m_frames[i].m_haveMetadata && !m_frames[i].m_isComplete)
-            frameBytesCleared += (m_frames[i].clear(true) ? frameBytes : 0);
+        if (frame.m_haveMetadata && !frame.m_isComplete)
+            frameBytesCleared += frame.clear(true);
     }
     destroyMetadataAndNotify(frameBytesCleared, ClearedSource::No);
 #else
     // FIXME: why is this different for iOS?
     int deltaBytes = 0;
     if (!m_frames.isEmpty()) {
-        int bytes = m_frames[m_frames.size() - 1].m_frameBytes;
-        if (m_frames[m_frames.size() - 1].clear(true)) {
+        if (int bytes = m_frames[m_frames.size() - 1].clear(true)) {
             deltaBytes += bytes;
             deltaBytes += m_decodedPropertiesSize;
             m_decodedPropertiesSize = 0;
@@ -337,11 +316,6 @@ bool BitmapImage::dataChanged(bool allDataReceived)
     return isSizeAvailable();
 }
 
-String BitmapImage::filenameExtension() const
-{
-    return m_source.filenameExtension();
-}
-
 size_t BitmapImage::frameCount()
 {
     if (!m_haveFrameCount) {
@@ -366,7 +340,7 @@ bool BitmapImage::isSizeAvailable()
     return m_sizeAvailable;
 }
 
-bool BitmapImage::ensureFrameIsCached(size_t index, ImageFrameCaching frameCaching)
+bool BitmapImage::ensureFrameAtIndexIsCached(size_t index, ImageFrameCaching frameCaching)
 {
     if (index >= frameCount())
         return false;
@@ -394,8 +368,7 @@ NativeImagePtr BitmapImage::frameImageAtIndex(size_t index, float presentationSc
         LOG(Images, "  subsamplingLevel was %d, resampling", m_frames[index].m_subsamplingLevel);
 
         // If the image is already cached, but at too small a size, re-decode a larger version.
-        int sizeChange = -m_frames[index].m_frameBytes;
-        m_frames[index].clear(true);
+        int sizeChange = -m_frames[index].clear(true);
         invalidatePlatformData();
         m_decodedSize += sizeChange;
         if (imageObserver())
@@ -408,10 +381,49 @@ NativeImagePtr BitmapImage::frameImageAtIndex(size_t index, float presentationSc
 
     return m_frames[index].m_image;
 }
+    
+NativeImagePtr BitmapImage::nativeImage()
+{
+    return frameImageAtIndex(0);
+}
+
+NativeImagePtr BitmapImage::nativeImageForCurrentFrame()
+{
+    return frameImageAtIndex(m_currentFrame);
+}
+    
+#if USE(CG)
+NativeImagePtr BitmapImage::nativeImageOfSize(const IntSize& size)
+{
+    size_t count = frameCount();
+    
+    for (size_t i = 0; i < count; ++i) {
+        auto image = frameImageAtIndex(i);
+        if (image && nativeImageSize(image) == size)
+            return image;
+    }
+    
+    // Fallback to the first frame image if we can't find the right size
+    return frameImageAtIndex(0);
+}
+    
+Vector<NativeImagePtr> BitmapImage::framesNativeImages()
+{
+    Vector<NativeImagePtr> images;
+    size_t count = frameCount();
+    
+    for (size_t i = 0; i < count; ++i) {
+        if (auto image = frameImageAtIndex(i))
+            images.append(image);
+    }
+    
+    return images;
+}
+#endif
 
 bool BitmapImage::frameIsCompleteAtIndex(size_t index)
 {
-    if (!ensureFrameIsCached(index, CacheMetadataOnly))
+    if (!ensureFrameAtIndexIsCached(index, CacheMetadataOnly))
         return false;
 
     return m_frames[index].m_isComplete;
@@ -419,20 +431,15 @@ bool BitmapImage::frameIsCompleteAtIndex(size_t index)
 
 float BitmapImage::frameDurationAtIndex(size_t index)
 {
-    if (!ensureFrameIsCached(index, CacheMetadataOnly))
+    if (!ensureFrameAtIndexIsCached(index, CacheMetadataOnly))
         return 0;
 
     return m_frames[index].m_duration;
 }
 
-NativeImagePtr BitmapImage::nativeImageForCurrentFrame()
-{
-    return frameImageAtIndex(currentFrame());
-}
-
 bool BitmapImage::frameHasAlphaAtIndex(size_t index)
 {
-    if (!ensureFrameIsCached(index, CacheMetadataOnly))
+    if (!ensureFrameAtIndexIsCached(index, CacheMetadataOnly))
         return true;
 
     if (m_frames[index].m_haveMetadata)
@@ -448,7 +455,7 @@ bool BitmapImage::currentFrameKnownToBeOpaque()
 
 ImageOrientation BitmapImage::frameOrientationAtIndex(size_t index)
 {
-    if (!ensureFrameIsCached(index, CacheMetadataOnly))
+    if (!ensureFrameAtIndexIsCached(index, CacheMetadataOnly))
         return ImageOrientation();
 
     if (m_frames[index].m_haveMetadata)
@@ -457,6 +464,32 @@ ImageOrientation BitmapImage::frameOrientationAtIndex(size_t index)
     return m_source.orientationAtIndex(index);
 }
 
+Color BitmapImage::singlePixelSolidColor()
+{
+    // If the image size is not available yet or if the image will be animating don't use the solid color optimization.
+    if (frameCount() != 1)
+        return Color();
+
+    if (m_solidColor)
+        return m_solidColor.value();
+
+    // If the frame image is not loaded, first use the decoder to get the size of the image.
+    if (!haveFrameImageAtIndex(0) && m_source.frameSizeAtIndex(0) != IntSize(1, 1)) {
+        m_solidColor = Color();
+        return m_solidColor.value();
+    }
+
+    // Cache the frame image. The size will be calculated from the NativeImagePtr.
+    if (!ensureFrameAtIndexIsCached(0))
+        return Color();
+
+    ASSERT(m_frames.size());
+    m_solidColor = nativeImageSinglePixelSolidColor(m_frames[0].m_image);
+    
+    ASSERT(m_solidColor);
+    return m_solidColor.value();
+}
+
 #if !ASSERT_DISABLED
 bool BitmapImage::notSolidColor()
 {
@@ -478,11 +511,93 @@ int BitmapImage::repetitionCount(bool imageKnownToBeComplete)
     return m_repetitionCount;
 }
 
+void BitmapImage::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode mode, ImageOrientationDescription description)
+{
+    if (destRect.isEmpty() || srcRect.isEmpty())
+        return;
+
+#if PLATFORM(IOS)
+    startAnimation(DoNotCatchUp);
+#else
+    startAnimation();
+#endif
+
+    Color color = singlePixelSolidColor();
+    if (color.isValid()) {
+        fillWithSolidColor(context, destRect, color, op);
+        return;
+    }
+
+    auto image = frameImageAtIndex(m_currentFrame, subsamplingScale(context, destRect, srcRect));
+    if (!image) // If it's too early we won't have an image yet.
+        return;
+
+    ImageOrientation orientation(description.imageOrientation());
+    if (description.respectImageOrientation() == RespectImageOrientation)
+        orientation = frameOrientationAtIndex(m_currentFrame);
+
+    drawNativeImage(image, context, destRect, srcRect, m_size, op, mode, orientation);
+
+    if (imageObserver())
+        imageObserver()->didDraw(this);
+}
+    
+void BitmapImage::drawPattern(GraphicsContext& ctxt, const FloatRect& tileRect, const AffineTransform& transform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
+{
+    if (tileRect.isEmpty())
+        return;
+
+    if (!ctxt.drawLuminanceMask()) {
+        Image::drawPattern(ctxt, tileRect, transform, phase, spacing, op, destRect, blendMode);
+        return;
+    }
+
+    if (!m_cachedImage) {
+        auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(tileRect.size()), ColorSpaceSRGB, ctxt);
+        if (!buffer)
+            return;
+
+        ImageObserver* observer = imageObserver();
+
+        // Temporarily reset image observer, we don't want to receive any changeInRect() calls due to this relayout.
+        setImageObserver(nullptr);
+
+        draw(buffer->context(), tileRect, tileRect, op, blendMode, ImageOrientationDescription());
+
+        setImageObserver(observer);
+        buffer->convertToLuminanceMask();
+
+        m_cachedImage = buffer->copyImage(DontCopyBackingStore, Unscaled);
+        if (!m_cachedImage)
+            return;
+    }
+    
+    ctxt.setDrawLuminanceMask(false);
+    m_cachedImage->drawPattern(ctxt, tileRect, transform, phase, spacing, op, destRect, blendMode);
+}
+
 bool BitmapImage::shouldAnimate()
 {
     return (repetitionCount(false) != cAnimationNone && !m_animationFinished && imageObserver());
 }
 
+bool BitmapImage::canAnimate()
+{
+    return shouldAnimate() && frameCount() > 1;
+}
+
+void BitmapImage::clearTimer()
+{
+    m_frameTimer = nullptr;
+}
+
+void BitmapImage::startTimer(double delay)
+{
+    ASSERT(!m_frameTimer);
+    m_frameTimer = std::make_unique<Timer>(*this, &BitmapImage::advanceAnimation);
+    m_frameTimer->startOneShot(delay);
+}
+
 void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary)
 {
     if (m_frameTimer || !shouldAnimate() || frameCount() <= 1)
@@ -580,60 +695,6 @@ void BitmapImage::startAnimation(CatchUpAnimation catchUpIfNecessary)
     startTimer(0);
 }
 
-void BitmapImage::stopAnimation()
-{
-    // This timer is used to animate all occurrences of this image. Don't invalidate
-    // the timer unless all renderers have stopped drawing.
-    clearTimer();
-}
-
-void BitmapImage::resetAnimation()
-{
-    stopAnimation();
-    m_currentFrame = 0;
-    m_repetitionsComplete = 0;
-    m_desiredFrameStartTime = 0;
-    m_animationFinished = false;
-    
-    // For extremely large animations, when the animation is reset, we just throw everything away.
-    destroyDecodedDataIfNecessary(true);
-}
-
-void BitmapImage::drawPattern(GraphicsContext& ctxt, const FloatRect& tileRect, const AffineTransform& transform,
-    const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
-{
-    if (tileRect.isEmpty())
-        return;
-
-    if (!ctxt.drawLuminanceMask()) {
-        Image::drawPattern(ctxt, tileRect, transform, phase, spacing, op, destRect, blendMode);
-        return;
-    }
-    if (!m_cachedImage) {
-        auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(tileRect.size()), ColorSpaceSRGB, ctxt);
-        if (!buffer)
-            return;
-
-        ImageObserver* observer = imageObserver();
-
-        // Temporarily reset image observer, we don't want to receive any changeInRect() calls due to this relayout.
-        setImageObserver(nullptr);
-
-        draw(buffer->context(), tileRect, tileRect, op, blendMode, ImageOrientationDescription());
-
-        setImageObserver(observer);
-        buffer->convertToLuminanceMask();
-
-        m_cachedImage = buffer->copyImage(DontCopyBackingStore, Unscaled);
-        if (!m_cachedImage)
-            return;
-    }
-
-    ctxt.setDrawLuminanceMask(false);
-    m_cachedImage->drawPattern(ctxt, tileRect, transform, phase, spacing, op, destRect, blendMode);
-}
-
-
 void BitmapImage::advanceAnimation()
 {
     internalAdvanceAnimation();
@@ -683,35 +744,23 @@ bool BitmapImage::internalAdvanceAnimation(AnimationAdvancement advancement)
     return advancedAnimation;
 }
 
-Color BitmapImage::singlePixelSolidColor()
+void BitmapImage::stopAnimation()
 {
-    // If the image size is not available yet or if the image will be animating don't use the solid color optimization.
-    if (frameCount() != 1)
-        return Color();
-    
-    if (m_solidColor)
-        return m_solidColor.value();
-
-    // If the frame image is not loaded, first use the decoder to get the size of the image.
-    if (!haveFrameImageAtIndex(0) && m_source.frameSizeAtIndex(0, 0) != IntSize(1, 1)) {
-        m_solidColor = Color();
-        return m_solidColor.value();
-    }
-
-    // Cache the frame image. The size will be calculated from the NativeImagePtr.
-    if (!ensureFrameIsCached(0))
-        return Color();
-    
-    ASSERT(m_frames.size());
-    m_solidColor = NativeImage::singlePixelSolidColor(m_frames[0].m_image.get());
-    
-    ASSERT(m_solidColor);
-    return m_solidColor.value();
+    // This timer is used to animate all occurrences of this image. Don't invalidate
+    // the timer unless all renderers have stopped drawing.
+    clearTimer();
 }
-    
-bool BitmapImage::canAnimate()
+
+void BitmapImage::resetAnimation()
 {
-    return shouldAnimate() && frameCount() > 1;
+    stopAnimation();
+    m_currentFrame = 0;
+    m_repetitionsComplete = 0;
+    m_desiredFrameStartTime = 0;
+    m_animationFinished = false;
+
+    // For extremely large animations, when the animation is reset, we just throw everything away.
+    destroyDecodedDataIfNecessary(true);
 }
 
 void BitmapImage::dump(TextStream& ts) const
index 0758929..e088212 100644 (file)
@@ -47,25 +47,9 @@ typedef struct HBITMAP__ *HBITMAP;
 #endif
 
 namespace WebCore {
-    struct FrameData;
-}
-
-namespace WTF {
-    template<> struct VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {
-        static const bool canInitializeWithMemset = false; // Not all FrameData members initialize to 0.
-    };
-}
-
-namespace WebCore {
 
 class Timer;
 
-namespace NativeImage {
-    IntSize size(const NativeImagePtr&);
-    bool hasAlpha(const NativeImagePtr&);
-    Color singlePixelSolidColor(const NativeImagePtr&);
-}
-
 // ================================================
 // FrameData Class
 // ================================================
@@ -75,24 +59,33 @@ public:
     FrameData()
         : m_haveMetadata(false)
         , m_isComplete(false)
-        , m_hasAlpha(true)
+        , m_hasAlpha(false)
     {
     }
 
     ~FrameData()
-    { 
-        clear(true);
+    {
+        clearNativeImageSubImages(m_image);
     }
 
-    // Clear the cached image data on the frame, and (optionally) the metadata.
-    // Returns whether there was cached image data to clear.
-    bool clear(bool clearMetadata);
+    unsigned clear(bool clearMetadata)
+    {
+        unsigned frameBytes = usedFrameBytes();
+        
+        if (clearMetadata)
+            m_haveMetadata = false;
+
+        m_subsamplingLevel = DefaultSubsamplingLevel;
+        m_image = nullptr;
+
+        return frameBytes;
+    }
     
     unsigned usedFrameBytes() const { return m_image ? m_frameBytes : 0; }
 
     NativeImagePtr m_image;
     ImageOrientation m_orientation { DefaultImageOrientation };
-    SubsamplingLevel m_subsamplingLevel { 0 };
+    SubsamplingLevel m_subsamplingLevel { DefaultSubsamplingLevel };
     float m_duration { 0 };
     bool m_haveMetadata : 1;
     bool m_isComplete : 1;
@@ -105,10 +98,6 @@ public:
 // =================================================
 
 class BitmapImage final : public Image {
-    friend class GeneratedImage;
-    friend class CrossfadeGeneratedImage;
-    friend class GradientImage;
-    friend class GraphicsContext;
 public:
     static Ref<BitmapImage> create(NativeImagePtr&& nativeImage, ImageObserver* observer = nullptr)
     {
@@ -123,7 +112,7 @@ public:
 #endif
     virtual ~BitmapImage();
     
-    bool hasSingleSecurityOrigin() const override;
+    bool hasSingleSecurityOrigin() const override { return true; }
 
     // FloatSize due to override.
     FloatSize size() const override;
@@ -134,7 +123,7 @@ public:
     unsigned decodedSize() const { return m_decodedSize; }
 
     bool dataChanged(bool allDataReceived) override;
-    String filenameExtension() const override;
+    String filenameExtension() const override { return m_source.filenameExtension(); }
 
     // It may look unusual that there is no start animation call as public API. This is because
     // we start and stop animating lazily. Animation begins whenever someone draws the image. It will
@@ -155,12 +144,6 @@ public:
     CFDataRef getTIFFRepresentation() override;
 #endif
 
-#if USE(CG)
-    WEBCORE_EXPORT CGImageRef getCGImageRef() override;
-    CGImageRef getFirstCGImageRefOfSize(const IntSize&) override;
-    RetainPtr<CFArrayRef> getCGImageArray() override;
-#endif
-
 #if PLATFORM(WIN)
     bool getHBITMAP(HBITMAP) override;
     bool getHBITMAPOfSize(HBITMAP, const IntSize*) override;
@@ -174,7 +157,12 @@ public:
     Evas_Object* getEvasObject(Evas*) override;
 #endif
 
+    WEBCORE_EXPORT NativeImagePtr nativeImage() override;
     NativeImagePtr nativeImageForCurrentFrame() override;
+#if USE(CG)
+    NativeImagePtr nativeImageOfSize(const IntSize&) override;
+    Vector<NativeImagePtr> framesNativeImages() override;
+#endif
     ImageOrientation orientationForCurrentFrame() override { return frameOrientationAtIndex(currentFrame()); }
 
     bool currentFrameKnownToBeOpaque() override;
@@ -215,7 +203,6 @@ protected:
     size_t frameCount();
 
     NativeImagePtr frameImageAtIndex(size_t, float presentationScaleHint = 1);
-    NativeImagePtr copyUnscaledFrameImageAtIndex(size_t);
 
     bool haveFrameImageAtIndex(size_t);
 
@@ -229,7 +216,7 @@ protected:
     void cacheFrame(size_t index, SubsamplingLevel, ImageFrameCaching = CacheMetadataAndFrame);
 
     // Called before accessing m_frames[index] for info without decoding. Returns false on index out of bounds.
-    bool ensureFrameIsCached(size_t index, ImageFrameCaching = CacheMetadataAndFrame);
+    bool ensureFrameAtIndexIsCached(size_t index, ImageFrameCaching = CacheMetadataAndFrame);
 
     // Called to invalidate cached data. When |destroyAll| is true, we wipe out
     // the entire frame buffer cache and tell the image source to destroy
index c07825c..4914b01 100644 (file)
@@ -28,7 +28,7 @@
 #include <wtf/Vector.h>
 
 #if PLATFORM(IOS)
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include <CoreGraphics/CoreGraphics.h>
 #elif PLATFORM(MAC)
 OBJC_CLASS NSImage;
index 7a29992..23649fc 100644 (file)
@@ -32,7 +32,7 @@
 #include "FloatSize.h"
 #include "GraphicsTypes.h"
 #include "ImageOrientation.h"
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include <wtf/Optional.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -137,8 +137,11 @@ public:
 
     enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile };
 
+    virtual NativeImagePtr nativeImage() { return nullptr; }
+    virtual NativeImagePtr nativeImageOfSize(const IntSize&) { return nullptr; }
     virtual NativeImagePtr nativeImageForCurrentFrame() { return nullptr; }
     virtual ImageOrientation orientationForCurrentFrame() { return ImageOrientation(); }
+    virtual Vector<NativeImagePtr> framesNativeImages() { return { }; }
 
     // Accessors for native image formats.
 
@@ -150,12 +153,6 @@ public:
     virtual CFDataRef getTIFFRepresentation() { return nullptr; }
 #endif
 
-#if USE(CG)
-    virtual CGImageRef getCGImageRef() { return nullptr; }
-    virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&) { return nullptr; }
-    virtual RetainPtr<CFArrayRef> getCGImageArray() { return nullptr; }
-#endif
-
 #if PLATFORM(WIN)
     virtual bool getHBITMAP(HBITMAP) { return false; }
     virtual bool getHBITMAPOfSize(HBITMAP, const IntSize*) { return false; }
index ddd8a55..d6f7bf5 100644 (file)
@@ -94,20 +94,19 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
 SubsamplingLevel ImageSource::calculateMaximumSubsamplingLevel() const
 {
     if (!m_allowSubsampling || !allowSubsamplingOfFrameAtIndex(0))
-        return 0;
+        return DefaultSubsamplingLevel;
     
     // FIXME: this value was chosen to be appropriate for iOS since the image
     // subsampling is only enabled by default on iOS. Choose a different value
     // if image subsampling is enabled on other platform.
     const int maximumImageAreaBeforeSubsampling = 5 * 1024 * 1024;
-    const SubsamplingLevel maxSubsamplingLevel = 3;
-    
-    for (SubsamplingLevel level = 0; level < maxSubsamplingLevel; ++level) {
+
+    for (SubsamplingLevel level = MinSubsamplingLevel; level < MaxSubsamplingLevel; ++level) {
         if (frameSizeAtIndex(0, level).area() < maximumImageAreaBeforeSubsampling)
             return level;
     }
     
-    return maxSubsamplingLevel;
+    return MaxSubsamplingLevel;
 }
 
 void ImageSource::updateMetadata()
@@ -148,12 +147,12 @@ bool ImageSource::isSizeAvailable() const
 
 IntSize ImageSource::size() const
 {
-    return frameSizeAtIndex(0, 0);
+    return frameSizeAtIndex(0, DefaultSubsamplingLevel);
 }
 
 IntSize ImageSource::sizeRespectingOrientation() const
 {
-    return frameSizeAtIndex(0, 0, RespectImageOrientation);
+    return frameSizeAtIndex(0, DefaultSubsamplingLevel, RespectImageOrientation);
 }
 
 size_t ImageSource::frameCount()
index 4dbe908..252ec3a 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "ImageOrientation.h"
 #include "IntPoint.h"
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include "TextStream.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
@@ -62,7 +62,14 @@ const int cAnimationLoopInfinite = -1;
 const int cAnimationNone = -2;
 
 // SubsamplingLevel. 0 is no subsampling, 1 is half dimensions on each axis etc.
-typedef short SubsamplingLevel;
+using SubsamplingLevel = int;
+
+enum : SubsamplingLevel {
+    NilSubsamplingLevel = -1,
+    MinSubsamplingLevel = 0,
+    MaxSubsamplingLevel = 3,
+    DefaultSubsamplingLevel = MinSubsamplingLevel
+};
 
 class ImageSource {
     WTF_MAKE_NONCOPYABLE(ImageSource);
@@ -130,18 +137,18 @@ public:
     bool allowSubsamplingOfFrameAtIndex(size_t) const;
     
     // Size of optionally subsampled frame.
-    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
+    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
     
     // Return the number of bytes in the decoded frame. If the frame is not yet
     // decoded then return 0.
-    unsigned frameBytesAtIndex(size_t, SubsamplingLevel = 0) const;
+    unsigned frameBytesAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel) const;
     
     float frameDurationAtIndex(size_t);
     ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
     
     // Callers should not call this after calling clear() with a higher index;
     // see comments on clear() above.
-    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
+    NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel);
     
 private:
     void clearFrameBufferCache(size_t);
@@ -153,7 +160,7 @@ private:
     
     bool m_needsUpdateMetadata { false };
     size_t m_frameCount { 0 };
-    Optional<SubsamplingLevel> m_maximumSubsamplingLevel { 0 };
+    Optional<SubsamplingLevel> m_maximumSubsamplingLevel { DefaultSubsamplingLevel };
 
     // The default value of m_allowSubsampling should be the same as defaultImageSubsamplingEnabled in Settings.cpp
 #if PLATFORM(IOS)
index 21467fc..76e4deb 100644 (file)
@@ -36,7 +36,7 @@
 #include "URL.h"
 #include "LayoutRect.h"
 #include "MediaPlayerEnums.h"
-#include "NativeImagePtr.h"
+#include "NativeImage.h"
 #include "PlatformLayer.h"
 #include "PlatformMediaResourceLoader.h"
 #include "PlatformMediaSession.h"
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2005, 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2016 Apple Inc.  All rights reserved.
  * Copyright (C) 2007-2008 Torch Mobile, Inc.
  * Copyright (C) 2012 Company 100 Inc.
  *
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef NativeImagePtr_h
-#define NativeImagePtr_h
+#pragma once
+
+#include "GraphicsTypes.h"
+#include "ImageOrientation.h"
 
 #if USE(CG)
 #include <wtf/RetainPtr.h>
@@ -39,6 +41,11 @@ typedef struct CGImage* CGImageRef;
 
 namespace WebCore {
 
+class Color;
+class FloatRect;
+class IntSize;
+class GraphicsContext;
+
 #if USE(CG)
 typedef RetainPtr<CGImageRef> NativeImagePtr;
 #elif USE(CAIRO)
@@ -47,6 +54,13 @@ typedef RefPtr<cairo_surface_t> NativeImagePtr;
 typedef RefPtr<SharedBitmap> NativeImagePtr;
 #endif
 
-}
+IntSize nativeImageSize(const NativeImagePtr&);
+bool nativeImageHasAlpha(const NativeImagePtr&);
+Color nativeImageSinglePixelSolidColor(const NativeImagePtr&);
 
-#endif
+float subsamplingScale(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect);
+
+void drawNativeImage(const NativeImagePtr&, GraphicsContext&, const FloatRect&, const FloatRect&, const IntSize&, CompositeOperator, BlendMode, const ImageOrientation&);
+void clearNativeImageSubImages(const NativeImagePtr&);
+    
+}
index 3f565e8..ccf9ddf 100644 (file)
@@ -297,7 +297,7 @@ void MediaPlayerPrivateMediaStreamAVFObjC::updatePausedImage()
     if (!image)
         return;
 
-    m_pausedImage = image->getCGImageRef();
+    m_pausedImage = image->nativeImage();
     ASSERT(m_pausedImage);
 }
 
diff --git a/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp b/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp
deleted file mode 100644 (file)
index 17722be..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006 Apple Inc.  All rights reserved.
- * Copyright (C) 2007 Alp Toker <alp@atoker.com>
- * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "BitmapImage.h"
-
-#if USE(CAIRO)
-
-#include "CairoUtilities.h"
-#include "ImageObserver.h"
-#include "PlatformContextCairo.h"
-#include "Timer.h"
-#include <cairo.h>
-
-namespace WebCore {
-
-namespace NativeImage {
-
-IntSize size(const RefPtr<cairo_surface_t>& image)
-{
-    return cairoSurfaceSize(image.get());
-}
-
-bool hasAlpha(const RefPtr<cairo_surface_t>& image)
-{
-    return cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
-}
-
-Color singlePixelSolidColor(const RefPtr<cairo_surface_t>& image)
-{
-    ASSERT(image);
-    
-    if (NativeImage::size(image) != IntSize(1, 1))
-        return Color();
-
-    if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
-        return Color();
-
-    RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
-    return colorFromPremultipliedARGB(*pixel);
-}
-
-}
-
-void BitmapImage::draw(GraphicsContext& context, const FloatRect& dst, const FloatRect& src, CompositeOperator op,
-    BlendMode blendMode, ImageOrientationDescription description)
-{
-    if (!dst.width() || !dst.height() || !src.width() || !src.height())
-        return;
-
-    startAnimation();
-
-    auto surface = frameImageAtIndex(m_currentFrame);
-    if (!surface) // If it's too early we won't have an image yet.
-        return;
-
-    Color color = singlePixelSolidColor();
-    if (color.isValid()) {
-        fillWithSolidColor(context, dst, color, op);
-        return;
-    }
-
-    context.save();
-
-    // Set the compositing operation.
-    if (op == CompositeSourceOver && blendMode == BlendModeNormal && !frameHasAlphaAtIndex(m_currentFrame))
-        context.setCompositeOperation(CompositeCopy);
-    else
-        context.setCompositeOperation(op, blendMode);
-
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
-    IntSize scaledSize = cairoSurfaceSize(surface.get());
-    FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(src, scaledSize);
-#else
-    FloatRect adjustedSrcRect(src);
-#endif
-
-    ImageOrientation frameOrientation(description.imageOrientation());
-    if (description.respectImageOrientation() == RespectImageOrientation)
-        frameOrientation = frameOrientationAtIndex(m_currentFrame);
-
-    FloatRect dstRect = dst;
-
-    if (frameOrientation != DefaultImageOrientation) {
-        // ImageOrientation expects the origin to be at (0, 0).
-        context.translate(dstRect.x(), dstRect.y());
-        dstRect.setLocation(FloatPoint());
-        context.concatCTM(frameOrientation.transformFromDefault(dstRect.size()));
-        if (frameOrientation.usesWidthAsHeight()) {
-            // The destination rectangle will have it's width and height already reversed for the orientation of
-            // the image, as it was needed for page layout, so we need to reverse it back here.
-            dstRect = FloatRect(dstRect.x(), dstRect.y(), dstRect.height(), dstRect.width());
-        }
-    }
-
-    context.platformContext()->drawSurfaceToContext(surface.get(), dstRect, adjustedSrcRect, context);
-
-    context.restore();
-
-    if (imageObserver())
-        imageObserver()->didDraw(this);
-}
-
-bool FrameData::clear(bool clearMetadata)
-{
-    if (clearMetadata)
-        m_haveMetadata = false;
-
-    if (m_image) {
-        m_image = nullptr;
-        return true;
-    }
-    return false;
-}
-
-} // namespace WebCore
-
-#endif // USE(CAIRO)
diff --git a/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp b/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp
new file mode 100644 (file)
index 0000000..65d5556
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NativeImage.h"
+
+#if USE(CAIRO)
+
+#include "CairoUtilities.h"
+#include "PlatformContextCairo.h"
+#include <cairo.h>
+
+namespace WebCore {
+
+IntSize nativeImageSize(const NativeImagePtr& image)
+{
+    return image ? cairoSurfaceSize(image.get()) : IntSize();
+}
+
+bool nativeImageHasAlpha(const NativeImagePtr& image)
+{
+    return !image || cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
+}
+
+Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
+{
+    if (!image || nativeImageSize(image) != IntSize(1, 1))
+        return Color();
+
+    if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
+        return Color();
+
+    RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
+    return colorFromPremultipliedARGB(*pixel);
+}
+
+float subsamplingScale(GraphicsContext&, const FloatRect&, const FloatRect&)
+{
+    return 1;
+}
+
+void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
+{
+    context.save();
+    
+    // Set the compositing operation.
+    if (op == CompositeSourceOver && mode == BlendModeNormal && !nativeImageHasAlpha(image))
+        context.setCompositeOperation(CompositeCopy);
+    else
+        context.setCompositeOperation(op, mode);
+        
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+    IntSize scaledSize = nativeImageSize(image);
+    FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(srcRect, scaledSize);
+#else
+    FloatRect adjustedSrcRect(srcRect);
+#endif
+        
+    FloatRect adjustedDestRect = destRect;
+        
+    if (orientation != DefaultImageOrientation) {
+        // ImageOrientation expects the origin to be at (0, 0).
+        context.translate(destRect.x(), destRect.y());
+        adjustedDestRect.setLocation(FloatPoint());
+        context.concatCTM(orientation.transformFromDefault(adjustedDestRect.size()));
+        if (orientation.usesWidthAsHeight()) {
+            // The destination rectangle will have it's width and height already reversed for the orientation of
+            // the image, as it was needed for page layout, so we need to reverse it back here.
+            adjustedDestRect.setSize(adjustedDestRect.size().transposedSize());
+        }
+    }
+
+    context.platformContext()->drawSurfaceToContext(image.get(), adjustedDestRect, adjustedSrcRect, context);
+    context.restore();
+}
+
+void clearNativeImageSubImages(const NativeImagePtr&)
+{
+}
+
+} // namespace WebCore
+
+#endif // USE(CAIRO)
diff --git a/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp b/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp
deleted file mode 100644 (file)
index 03c81a1..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "config.h"
-#include "BitmapImage.h"
-
-#if USE(CG)
-
-#include "CoreGraphicsSPI.h"
-#include "FloatConversion.h"
-#include "GeometryUtilities.h"
-#include "GraphicsContextCG.h"
-#include "ImageObserver.h"
-#include "SubimageCacheWithTimer.h"
-#include <wtf/RetainPtr.h>
-
-#if USE(APPKIT)
-#include <ApplicationServices/ApplicationServices.h>
-#endif
-
-#if PLATFORM(COCOA)
-#include "WebCoreSystemInterface.h"
-#endif
-
-#if PLATFORM(WIN)
-#include <WebKitSystemInterface/WebKitSystemInterface.h>
-#endif
-
-namespace WebCore {
-
-namespace NativeImage {
-
-IntSize size(const RetainPtr<CGImageRef>& image)
-{
-    ASSERT(image);
-    return IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
-}
-
-bool hasAlpha(const RetainPtr<CGImageRef>&)
-{
-    // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
-    return true;
-}
-    
-Color singlePixelSolidColor(const RetainPtr<CGImageRef>& image)
-{
-    ASSERT(image);
-    
-    if (NativeImage::size(image) != IntSize(1, 1))
-        return Color();
-    
-    unsigned char pixel[4]; // RGBA
-    auto bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(),
-        kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
-
-    if (!bitmapContext)
-        return Color();
-    
-    CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
-    CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, 1, 1), image.get());
-    
-    if (!pixel[3])
-        return Color(0, 0, 0, 0);
-
-    return Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
-}
-
-}
-
-bool FrameData::clear(bool clearMetadata)
-{
-    if (clearMetadata)
-        m_haveMetadata = false;
-
-    m_subsamplingLevel = 0;
-
-    if (m_image) {
-#if CACHE_SUBIMAGES
-        subimageCache().clearImage(m_image.get());
-#endif
-        m_image = nullptr;
-        return true;
-    }
-    return false;
-}
-
-CGImageRef BitmapImage::getCGImageRef()
-{
-    return frameImageAtIndex(0).get();
-}
-
-CGImageRef BitmapImage::getFirstCGImageRefOfSize(const IntSize& size)
-{
-    size_t count = frameCount();
-    for (size_t i = 0; i < count; ++i) {
-        CGImageRef cgImage = frameImageAtIndex(i).get();
-        if (cgImage && IntSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)) == size)
-            return cgImage;
-    }
-
-    // Fallback to the default CGImageRef if we can't find the right size
-    return getCGImageRef();
-}
-
-RetainPtr<CFArrayRef> BitmapImage::getCGImageArray()
-{
-    size_t count = frameCount();
-    if (!count)
-        return nullptr;
-    
-    CFMutableArrayRef array = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks);
-    for (size_t i = 0; i < count; ++i) {
-        if (CGImageRef currFrame = frameImageAtIndex(i).get())
-            CFArrayAppendValue(array, currFrame);
-    }
-    return adoptCF(array);
-}
-
-void BitmapImage::draw(GraphicsContext& ctxt, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription description)
-{
-#if PLATFORM(IOS)
-    startAnimation(DoNotCatchUp);
-#else
-    startAnimation();
-#endif
-
-    RetainPtr<CGImageRef> image;
-    // Never use subsampled images for drawing into PDF contexts.
-    if (wkCGContextIsPDFContext(ctxt.platformContext()))
-        image = copyUnscaledFrameImageAtIndex(m_currentFrame);
-    else {
-        CGRect transformedDestinationRect = CGRectApplyAffineTransform(destRect, CGContextGetCTM(ctxt.platformContext()));
-        float subsamplingScale = std::min<float>(1, std::max(transformedDestinationRect.size.width / srcRect.width(), transformedDestinationRect.size.height / srcRect.height()));
-
-        image = frameImageAtIndex(m_currentFrame, subsamplingScale);
-    }
-
-    if (!image) // If it's too early we won't have an image yet.
-        return;
-    
-    Color color = singlePixelSolidColor();
-    if (color.isValid()) {
-        fillWithSolidColor(ctxt, destRect, color, compositeOp);
-        return;
-    }
-
-    // Subsampling may have given us an image that is smaller than size().
-    IntSize imageSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
-    
-    // srcRect is in the coordinates of the unsubsampled image, so we have to map it to the subsampled image.
-    FloatRect scaledSrcRect = srcRect;
-    if (imageSize != m_size) {
-        FloatRect originalImageBounds(FloatPoint(), m_size);
-        FloatRect subsampledImageBounds(FloatPoint(), imageSize);
-        scaledSrcRect = mapRect(srcRect, originalImageBounds, subsampledImageBounds);
-    }
-    
-    ImageOrientation orientation;
-    if (description.respectImageOrientation() == RespectImageOrientation)
-        orientation = frameOrientationAtIndex(m_currentFrame);
-
-    ctxt.drawNativeImage(image, imageSize, destRect, scaledSrcRect, compositeOp, blendMode, orientation);
-
-    if (imageObserver())
-        imageObserver()->didDraw(this);
-}
-
-RetainPtr<CGImageRef> BitmapImage::copyUnscaledFrameImageAtIndex(size_t index)
-{
-    if (index >= frameCount())
-        return nullptr;
-
-    if (index >= m_frames.size() || !m_frames[index].m_image)
-        cacheFrame(index, 0);
-
-    if (!m_frames[index].m_subsamplingLevel)
-        return m_frames[index].m_image;
-
-    return m_source.createFrameImageAtIndex(index);
-}
-
-}
-
-#endif // USE(CG)
index 3d7774c..a8c6d63 100644 (file)
@@ -157,7 +157,7 @@ bool ImageDecoder::isSizeAvailable() const
 IntSize ImageDecoder::size() const
 {
     if (m_size.isEmpty())
-        m_size = frameSizeAtIndex(0, 0);
+        m_size = frameSizeAtIndex(0);
     return m_size;
 }
 
index e83c1b7..5d8de24 100644 (file)
@@ -57,7 +57,7 @@ public:
     int repetitionCount() const;
     Optional<IntPoint> hotSpot() const;
     
-    IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const;
+    IntSize frameSizeAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel) const;
     bool frameIsCompleteAtIndex(size_t) const;
     ImageOrientation orientationAtIndex(size_t) const;
     
diff --git a/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp b/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp
new file mode 100644 (file)
index 0000000..570384e
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NativeImage.h"
+
+#if USE(CG)
+
+#include "Color.h"
+#include "CoreGraphicsSPI.h"
+#include "FloatRect.h"
+#include "GeometryUtilities.h"
+#include "GraphicsContextCG.h"
+#include "IntSize.h"
+#include "SubimageCacheWithTimer.h"
+
+#if PLATFORM(WIN)
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
+#endif
+
+namespace WebCore {
+
+IntSize nativeImageSize(const NativeImagePtr& image)
+{
+    return image ? IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get())) : IntSize();
+}
+
+bool nativeImageHasAlpha(const NativeImagePtr&)
+{
+    // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
+    return true;
+}
+
+Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
+{
+    if (!image || nativeImageSize(image) != IntSize(1, 1))
+        return Color();
+
+    unsigned char pixel[4]; // RGBA
+    auto bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
+
+    if (!bitmapContext)
+        return Color();
+
+    CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
+    CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, 1, 1), image.get());
+
+    if (!pixel[3])
+        return Color(0, 0, 0, 0);
+
+    return Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
+}
+
+float subsamplingScale(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect)
+{
+    // Never use subsampled images for drawing into PDF contexts.
+    if (wkCGContextIsPDFContext(context.platformContext()))
+        return 1;
+
+    CGRect transformedDestinationRect = CGRectApplyAffineTransform(destRect, CGContextGetCTM(context.platformContext()));
+    return std::min<float>(1, std::max(transformedDestinationRect.size.width / srcRect.width(), transformedDestinationRect.size.height / srcRect.height()));
+}
+
+void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
+{
+    // Subsampling may have given us an image that is smaller than size().
+    IntSize subsampledImageSize = nativeImageSize(image);
+
+    // srcRect is in the coordinates of the unsubsampled image, so we have to map it to the subsampled image.
+    FloatRect adjustedSrcRect = srcRect;
+    if (subsampledImageSize != srcSize)
+        adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize));
+
+    context.drawNativeImage(image, subsampledImageSize, destRect, adjustedSrcRect, op, mode, orientation);
+}
+
+void clearNativeImageSubImages(const NativeImagePtr& image)
+{
+#if CACHE_SUBIMAGES
+    if (image)
+        subimageCache().clearImage(image.get());
+#endif
+}
+
+}
+
+#endif // USE(CG)
index b428d50..3daa139 100644 (file)
@@ -72,7 +72,7 @@ CGPatternRef Pattern::createPlatformPattern(const AffineTransform& userSpaceTran
     // If we're repeating in both directions, we can use image-backed patterns
     // instead of custom patterns, and avoid tiling-edge pixel cracks.
     if (m_repeatX && m_repeatY)
-        return wkCGPatternCreateWithImageAndTransform(tileImage()->getCGImageRef(), patternTransform, wkPatternTilingConstantSpacing);
+        return wkCGPatternCreateWithImageAndTransform(tileImage()->nativeImage().get(), patternTransform, wkPatternTilingConstantSpacing);
 
     // If FLT_MAX should also be used for xStep or yStep, nothing is rendered. Using fractions of FLT_MAX also
     // result in nothing being rendered.
@@ -83,7 +83,7 @@ CGPatternRef Pattern::createPlatformPattern(const AffineTransform& userSpaceTran
     CGFloat yStep = m_repeatY ? tileRect.height() : (1 << 22);
 
     // The pattern will release the CGImageRef when it's done rendering in patternReleaseCallback
-    CGImageRef platformImage = CGImageRetain(tileImage()->getCGImageRef());
+    CGImageRef platformImage = tileImage()->nativeImage().leakRef();
 
     const CGPatternCallbacks patternCallbacks = { 0, patternCallback, patternReleaseCallback };
     return CGPatternCreate(platformImage, tileRect, patternTransform, xStep, yStep, kCGPatternTilingConstantSpacing, TRUE, &patternCallbacks);
index 89720d1..4476fc5 100644 (file)
@@ -129,7 +129,7 @@ TextTrackRepresentationCocoa::~TextTrackRepresentationCocoa()
 void TextTrackRepresentationCocoa::update()
 {
     if (auto representation = m_client.createTextTrackRepresentationImage())
-        [m_layer.get() setContents:(id)representation->getCGImageRef()];
+        [m_layer.get() setContents:(id)representation->nativeImage().get()];
 }
 
 void TextTrackRepresentationCocoa::setContentScale(float scale)
index 1c87741..b5ef4c1 100644 (file)
@@ -79,31 +79,22 @@ CFDataRef BitmapImage::getTIFFRepresentation()
     if (m_tiffRep)
         return m_tiffRep.get();
 
-    unsigned numFrames = frameCount();
+    auto nativeImages = this->framesNativeImages();
 
-    // If numFrames is zero, we know for certain this image doesn't have valid data
+    // If framesImages.size() is zero, we know for certain this image doesn't have valid data
     // Even though the call to CGImageDestinationCreateWithData will fail and we'll handle it gracefully,
     // in certain circumstances that call will spam the console with an error message
-    if (!numFrames)
-        return 0;
-
-    Vector<CGImageRef> images;
-    for (unsigned i = 0; i < numFrames; ++i ) {
-        CGImageRef cgImage = frameImageAtIndex(i).get();
-        if (cgImage)
-            images.append(cgImage);
-    }
-
-    unsigned numValidFrames = images.size();
+    if (!nativeImages.size())
+        return nullptr;
 
     RetainPtr<CFMutableDataRef> data = adoptCF(CFDataCreateMutable(0, 0));
-    RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData(data.get(), kUTTypeTIFF, numValidFrames, 0));
+    RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData(data.get(), kUTTypeTIFF, nativeImages.size(), 0));
 
     if (!destination)
-        return 0;
+        return nullptr;
 
-    for (unsigned i = 0; i < numValidFrames; ++i)
-        CGImageDestinationAddImage(destination.get(), images[i], 0);
+    for (auto nativeImage : nativeImages)
+        CGImageDestinationAddImage(destination.get(), nativeImage.get(), 0);
 
     CGImageDestinationFinalize(destination.get());
 
index 7c932e5..493513c 100644 (file)
@@ -142,7 +142,7 @@ void MockRealtimeVideoSourceMac::updatePlatformLayer() const
         if (!image)
             break;
 
-        m_previewImage = image->getCGImageRef();
+        m_previewImage = image->nativeImage();
         if (!m_previewImage)
             break;
 
@@ -154,7 +154,7 @@ void MockRealtimeVideoSourceMac::updatePlatformLayer() const
 
 void MockRealtimeVideoSourceMac::updateSampleBuffer()
 {
-    auto pixelBuffer = pixelBufferFromCGImage(imageBuffer()->copyImage()->getCGImageRef());
+    auto pixelBuffer = pixelBufferFromCGImage(imageBuffer()->copyImage()->nativeImage().get());
     auto sampleBuffer = CMSampleBufferFromPixelBuffer(pixelBuffer.get());
     
     mediaDataUpdated(MediaSampleAVFObjC::create(sampleBuffer.get()));
index 36cd651..4b4e377 100644 (file)
@@ -136,9 +136,9 @@ DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
     CGContextScaleCTM(drawContext, 1, -1);
     CGContextSetFillColor(drawContext, white);
     CGContextFillRect(drawContext, rect);
-    if (auto srcImage = img->getCGImageRef()) {
+    if (auto srcImage = img->nativeImage()) {
         CGContextSetBlendMode(drawContext, kCGBlendModeNormal);
-        CGContextDrawImage(drawContext, rect, srcImage);
+        CGContextDrawImage(drawContext, rect, srcImage.get());
     }
     CGContextRelease(drawContext);
 
index 05fd20a..06890e9 100644 (file)
@@ -1,3 +1,16 @@
+2016-09-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Move the BitmapImage platform dependent code to a new file named NativeImage[CG|Cairo].cpp
+        https://bugs.webkit.org/show_bug.cgi?id=158684
+
+        Reviewed by Simon Fraser.
+
+        * DOM/DOM.mm:
+        (-[DOMNode getPreviewSnapshotImage:andRects:]):
+        * Misc/WebCache.mm:
+        (+[WebCache imageForURL:]):
+        Replace BitmapImage::getCGImageRef() with BitmapImage::nativeImage().
+
 2016-09-07  Joseph Pecoraro  <pecoraro@apple.com>
 
         [Mac] Address some clang static analyzer warnings in WebKit
index a151454..c7dcd20 100644 (file)
@@ -561,7 +561,7 @@ id <DOMEventTarget> kit(EventTarget* eventTarget)
 
     if (textIndicator) {
         if (Image* image = textIndicator->contentImage())
-            *cgImage = (CGImageRef)CFAutorelease(CGImageRetain(image->getCGImageRef()));
+            *cgImage = image->nativeImage().autorelease();
     }
 
     RetainPtr<NSMutableArray> rectArray = adoptNS([[NSMutableArray alloc] init]);
index b659d6d..7c5ed21 100644 (file)
     WebCore::CachedImage& cachedImage = downcast<WebCore::CachedImage>(*cachedResource);
     if (!cachedImage.hasImage())
         return nullptr;
-    return cachedImage.image()->getCGImageRef();
+    return cachedImage.image()->nativeImage().get();
 }
 
 #endif // PLATFORM(IOS)
index 381eac6..7978eb0 100644 (file)
@@ -1,3 +1,26 @@
+2016-09-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Move the BitmapImage platform dependent code to a new file named NativeImage[CG|Cairo].cpp
+        https://bugs.webkit.org/show_bug.cgi?id=158684
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/C/cg/WKIconDatabaseCG.cpp:
+        (WKIconDatabaseTryGetCGImageForURL):
+        (WKIconDatabaseTryCopyCGImageArrayForURL):
+        It was the only place in the code which uses BitmapImage::getCGImageArray().
+        Call BitmapImage::framesNativeImages() instead and form the returned
+        Vector<NativeImagePtr> build the CFArrayRef.
+
+        * UIProcess/WebIconDatabase.h:
+        Include "NativeImage.h" instead of "NativeImagePtr.h".
+        
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _presentationSnapshotForPreviewItemController:]):
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::isAlmostSolidColor):
+        Call BitmapImage::getCGImageRef() instead of calling BitmapImage::nativeImage().
+
 2016-09-08  Zan Dobersek  <zdobersek@igalia.com>
 
         Move webkit2gtk.pc.in, webkit2gtk-web-extension.pc.in files under Source/WebKit2/gtk/
index 0f6de7a..3056336 100644 (file)
@@ -37,12 +37,23 @@ using namespace WebCore;
 CGImageRef WKIconDatabaseTryGetCGImageForURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef urlRef, WKSize size)
 {
     Image* image = toImpl(iconDatabaseRef)->imageForPageURL(toWTFString(urlRef));
-    return image ? image->getFirstCGImageRefOfSize(IntSize(static_cast<int>(size.width), static_cast<int>(size.height))) : 0;
+    return image ? image->nativeImageOfSize(IntSize(static_cast<int>(size.width), static_cast<int>(size.height))).get() : nullptr;
 }
 
 CFArrayRef WKIconDatabaseTryCopyCGImageArrayForURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef urlRef)
 {
     Image* image = toImpl(iconDatabaseRef)->imageForPageURL(toWTFString(urlRef));
-    return image ? image->getCGImageArray().leakRef() : 0;
+    if (!image)
+        return nullptr;
+
+    auto nativeImages = image->framesNativeImages();
+    if (!nativeImages.size())
+        return nullptr;
+    
+    CFMutableArrayRef array = CFArrayCreateMutable(nullptr, nativeImages.size(), &kCFTypeArrayCallBacks);
+    for (auto nativeImage : nativeImages)
+        CFArrayAppendValue(array, nativeImage.get());
+    
+    return static_cast<CFArrayRef>(CFRetain(array));
 }
 
index 08397ee..8b70fe8 100644 (file)
@@ -31,7 +31,7 @@
 #include "WebIconDatabaseClient.h"
 #include <WebCore/IconDatabaseClient.h>
 #include <WebCore/IntSize.h>
-#include <WebCore/NativeImagePtr.h>
+#include <WebCore/NativeImage.h>
 
 namespace API {
 class Data;
index 3c1d3d9..0251088 100644 (file)
@@ -4131,7 +4131,7 @@ static NSString *previewIdentifierForElementAction(_WKElementAction *action)
 {
     if (!_positionInformation.linkIndicator.contentImage)
         return nullptr;
-    return [[[UIImage alloc] initWithCGImage:_positionInformation.linkIndicator.contentImage->getCGImageRef()] autorelease];
+    return [[[UIImage alloc] initWithCGImage:_positionInformation.linkIndicator.contentImage->nativeImage().get()] autorelease];
 }
 
 - (NSArray *)_presentationRectsForPreviewItemController:(UIPreviewItemController *)controller
index 526602e..f5be254 100644 (file)
@@ -1730,7 +1730,7 @@ void PluginView::windowedPluginVisibilityDidChange(bool isVisible, uint64_t wind
 #if PLATFORM(COCOA)
 static bool isAlmostSolidColor(BitmapImage* bitmap)
 {
-    CGImageRef image = bitmap->getCGImageRef();
+    CGImageRef image = bitmap->nativeImage().get();
     ASSERT(CGImageGetBitsPerComponent(image) == 8);
 
     CGBitmapInfo imageInfo = CGImageGetBitmapInfo(image);