Tighten ImageSource to have BitmapImage pointer instead of Image
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 16:29:52 +0000 (16:29 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 16:29:52 +0000 (16:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184356

Reviewed by Said Abou-Hallawa.

ImageSource is an implementation detail of BitmapImage, not a generic type.

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::decode):
* platform/graphics/BitmapImage.h:
* platform/graphics/Image.h:
(WebCore::Image::decode): Deleted.
(WebCore::Image::imageFrameAvailableAtIndex): Deleted.

Also make some BitmapImage specific functions non-virtual and remove them from Image.

* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::ImageSource):
* platform/graphics/ImageSource.h:
(WebCore::ImageSource::create):

Make constructors private.

* platform/graphics/cg/GraphicsContext3DCG.cpp:
(WebCore::GraphicsContext3D::ImageExtractor::extractImage):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/platform/graphics/BitmapImage.h
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/ImageSource.cpp
Source/WebCore/platform/graphics/ImageSource.h
Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp
Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
Source/WebCore/platform/graphics/mac/ImageMac.mm
Source/WebCore/rendering/RenderLayerBacking.cpp

index 41d2c2a..d3718a1 100644 (file)
@@ -1,3 +1,31 @@
+2018-04-06  Antti Koivisto  <antti@apple.com>
+
+        Tighten ImageSource to have BitmapImage pointer instead of Image
+        https://bugs.webkit.org/show_bug.cgi?id=184356
+
+        Reviewed by Said Abou-Hallawa.
+
+        ImageSource is an implementation detail of BitmapImage, not a generic type.
+
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::decode):
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Image.h:
+        (WebCore::Image::decode): Deleted.
+        (WebCore::Image::imageFrameAvailableAtIndex): Deleted.
+
+        Also make some BitmapImage specific functions non-virtual and remove them from Image.
+
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::ImageSource):
+        * platform/graphics/ImageSource.h:
+        (WebCore::ImageSource::create):
+
+        Make constructors private.
+
+        * platform/graphics/cg/GraphicsContext3DCG.cpp:
+        (WebCore::GraphicsContext3D::ImageExtractor::extractImage):
+
 2018-04-06  Brent Fulgham  <bfulgham@apple.com>
 
         Unreviewed test fix after r230323
index f7cc2e7..eef3967 100644 (file)
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "ImageLoader.h"
 
+#include "BitmapImage.h"
 #include "CachedImage.h"
 #include "CachedResourceLoader.h"
 #include "CachedResourceRequest.h"
@@ -418,12 +419,13 @@ void ImageLoader::decode()
     }
 
     Image* image = m_image->image();
-    if (!image->isBitmapImage()) {
+    if (!is<BitmapImage>(image)) {
         decodeError("Invalid image type.");
         return;
     }
-    
-    image->decode([promises = WTFMove(m_decodingPromises)]() mutable {
+
+    auto& bitmapImage = downcast<BitmapImage>(*image);
+    bitmapImage.decode([promises = WTFMove(m_decodingPromises)]() mutable {
         for (auto& promise : promises)
             promise->resolve();
     });
index a377a0b..199079e 100644 (file)
@@ -99,7 +99,7 @@ public:
 
     size_t currentFrame() const { return m_currentFrame; }
     bool currentFrameKnownToBeOpaque() const override { return !frameHasAlphaAtIndex(currentFrame()); }
-    ImageOrientation orientationForCurrentFrame() const override { return frameOrientationAtIndex(currentFrame()); }
+    ImageOrientation orientationForCurrentFrame() const { return frameOrientationAtIndex(currentFrame()); }
     bool canAnimate() const;
 
     bool shouldUseAsyncDecodingForAnimatedImagesForTesting() const { return m_frameDecodingDurationForTesting > 0_s; }
@@ -135,9 +135,12 @@ public:
     NativeImagePtr nativeImageForCurrentFrame(const GraphicsContext* = nullptr) override;
 #if USE(CG)
     NativeImagePtr nativeImageOfSize(const IntSize&, const GraphicsContext* = nullptr) override;
-    Vector<NativeImagePtr> framesNativeImages() override;
+    Vector<NativeImagePtr> framesNativeImages();
 #endif
 
+    void imageFrameAvailableAtIndex(size_t);
+    void decode(Function<void()>&&);
+
 protected:
     WEBCORE_EXPORT BitmapImage(NativeImagePtr&&, ImageObserver* = nullptr);
     WEBCORE_EXPORT BitmapImage(ImageObserver* = nullptr);
@@ -197,9 +200,7 @@ private:
     bool canDestroyDecodedData();
     void setCurrentFrameDecodingStatusIfNecessary(DecodingStatus);
     bool isBitmapImage() const override { return true; }
-    void decode(WTF::Function<void()>&&) override;
     void callDecodingCallbacks();
-    void imageFrameAvailableAtIndex(size_t) override;
     void dump(WTF::TextStream&) const override;
 
     // Animated images over a certain size are considered large enough that we'll only hang on to one frame at a time.
index 8b693c2..0975f59 100644 (file)
@@ -137,9 +137,6 @@ public:
     virtual bool isAnimating() const { return false; }
     bool animationPending() const { return m_animationStartTimer.isActive(); }
 
-    virtual void decode(WTF::Function<void()>&&) { }
-    virtual void imageFrameAvailableAtIndex(size_t) { }
-
     // Typically the CachedImage that owns us.
     ImageObserver* imageObserver() const { return m_imageObserver; }
     void setImageObserver(ImageObserver* observer) { m_imageObserver = observer; }
@@ -152,8 +149,6 @@ public:
     virtual NativeImagePtr nativeImage(const GraphicsContext* = nullptr) { return nullptr; }
     virtual NativeImagePtr nativeImageOfSize(const IntSize&, const GraphicsContext* = nullptr) { return nullptr; }
     virtual NativeImagePtr nativeImageForCurrentFrame(const GraphicsContext* = nullptr) { return nullptr; }
-    virtual ImageOrientation orientationForCurrentFrame() const { return ImageOrientation(); }
-    virtual Vector<NativeImagePtr> framesNativeImages() { return { }; }
 
     // Accessors for native image formats.
 
index 12adcdc..e73e79d 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "ImageSource.h"
 
-#include "Image.h"
+#include "BitmapImage.h"
 #include "ImageDecoder.h"
 #include "ImageObserver.h"
 #include "Logging.h"
@@ -38,7 +38,7 @@
 
 namespace WebCore {
 
-ImageSource::ImageSource(Image* image, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
+ImageSource::ImageSource(BitmapImage* image, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
     : m_image(image)
     , m_alphaOption(alphaOption)
     , m_gammaAndColorProfileOption(gammaAndColorProfileOption)
index 0e5139d..fd466b1 100644 (file)
 
 namespace WebCore {
 
+class BitmapImage;
 class GraphicsContext;
-class Image;
 class ImageDecoder;
 class URL;
 
 class ImageSource : public ThreadSafeRefCounted<ImageSource> {
     friend class BitmapImage;
 public:
-    ImageSource(Image*, AlphaOption = AlphaOption::Premultiplied, GammaAndColorProfileOption = GammaAndColorProfileOption::Applied);
-    ImageSource(NativeImagePtr&&);
     ~ImageSource();
 
-    static Ref<ImageSource> create(Image* image, AlphaOption alphaOption = AlphaOption::Premultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileOption::Applied)
+    static Ref<ImageSource> create(BitmapImage* image, AlphaOption alphaOption = AlphaOption::Premultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileOption::Applied)
     {
         return adoptRef(*new ImageSource(image, alphaOption, gammaAndColorProfileOption));
     }
@@ -123,6 +121,9 @@ public:
     NativeImagePtr frameImageAtIndexCacheIfNeeded(size_t, SubsamplingLevel = SubsamplingLevel::Default);
 
 private:
+    ImageSource(BitmapImage*, AlphaOption = AlphaOption::Premultiplied, GammaAndColorProfileOption = GammaAndColorProfileOption::Applied);
+    ImageSource(NativeImagePtr&&);
+
     template<typename T, T (ImageDecoder::*functor)() const>
     T metadata(const T& defaultValue, std::optional<T>* cachedValue = nullptr);
 
@@ -155,7 +156,7 @@ private:
 
     void dump(TextStream&);
 
-    Image* m_image { nullptr };
+    BitmapImage* m_image { nullptr };
     RefPtr<ImageDecoder> m_decoder;
     AlphaOption m_alphaOption { AlphaOption::Premultiplied };
     GammaAndColorProfileOption m_gammaAndColorProfileOption { GammaAndColorProfileOption::Applied };
index ca8e4f8..360640f 100644 (file)
@@ -48,14 +48,14 @@ bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool
     // We need this to stay in scope because the native image is just a shallow copy of the data.
     AlphaOption alphaOption = premultiplyAlpha ? AlphaOption::Premultiplied : AlphaOption::NotPremultiplied;
     GammaAndColorProfileOption gammaAndColorProfileOption = ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied;
-    ImageSource source(nullptr, alphaOption, gammaAndColorProfileOption);
+    auto source = ImageSource::create(nullptr, alphaOption, gammaAndColorProfileOption);
     m_alphaOp = AlphaDoNothing;
 
     if (m_image->data()) {
-        source.setData(m_image->data(), true);
-        if (!source.frameCount())
+        source->setData(m_image->data(), true);
+        if (!source->frameCount())
             return false;
-        m_imageSurface = source.createFrameImageAtIndex(0);
+        m_imageSurface = source->createFrameImageAtIndex(0);
     } else {
         m_imageSurface = m_image->nativeImageForCurrentFrame();
         // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAlpha had been applied and the alpha value is 0xFF for each pixel,
index 9daff78..ddb744e 100644 (file)
@@ -325,12 +325,12 @@ bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool
         return false;
     bool hasAlpha = !m_image->currentFrameKnownToBeOpaque();
     if ((ignoreGammaAndColorProfile || (hasAlpha && !premultiplyAlpha)) && m_image->data()) {
-        ImageSource source(nullptr, AlphaOption::NotPremultiplied, ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied);
-        source.setData(m_image->data(), true);
-        if (!source.frameCount())
+        auto source = ImageSource::create(nullptr, AlphaOption::NotPremultiplied, ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied);
+        source->setData(m_image->data(), true);
+        if (!source->frameCount())
             return false;
 
-        m_decodedImage = source.createFrameImageAtIndex(0);
+        m_decodedImage = source->createFrameImageAtIndex(0);
         m_cgImage = m_decodedImage;
     } else
         m_cgImage = m_image->nativeImageForCurrentFrame();
index e1cfe3f..9f67575 100644 (file)
@@ -105,9 +105,7 @@ CFDataRef BitmapImage::tiffRepresentation()
         return nullptr;
 
     m_tiffRep = data;
-    return m_tiffRep.get();
-
-    
+    return m_tiffRep.get();    
 }
 
 #if USE(APPKIT)
index 5e29692..7b2620a 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "RenderLayerBacking.h"
 
+#include "BitmapImage.h"
 #include "CSSAnimationController.h"
 #include "CanvasRenderingContext.h"
 #include "CSSPropertyNames.h"
@@ -2189,10 +2190,10 @@ bool RenderLayerBacking::isDirectlyCompositedImage() const
             return false;
 
         auto* image = cachedImage->imageForRenderer(&imageRenderer);
-        if (!image->isBitmapImage())
+        if (!is<BitmapImage>(image))
             return false;
 
-        if (image->orientationForCurrentFrame() != DefaultImageOrientation)
+        if (downcast<BitmapImage>(*image).orientationForCurrentFrame() != DefaultImageOrientation)
             return false;
 
 #if (PLATFORM(GTK) || PLATFORM(WPE))