Title: [230334] trunk/Source/WebCore
Revision
230334
Author
an...@apple.com
Date
2018-04-06 09:29:52 -0700 (Fri, 06 Apr 2018)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (230333 => 230334)


--- trunk/Source/WebCore/ChangeLog	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/ChangeLog	2018-04-06 16:29:52 UTC (rev 230334)
@@ -1,3 +1,31 @@
+2018-04-06  Antti Koivisto  <an...@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  <bfulg...@apple.com>
 
         Unreviewed test fix after r230323

Modified: trunk/Source/WebCore/loader/ImageLoader.cpp (230333 => 230334)


--- trunk/Source/WebCore/loader/ImageLoader.cpp	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/loader/ImageLoader.cpp	2018-04-06 16:29:52 UTC (rev 230334)
@@ -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 @@
     }
 
     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();
     });

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2018-04-06 16:29:52 UTC (rev 230334)
@@ -99,7 +99,7 @@
 
     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 @@
     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 @@
     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.

Modified: trunk/Source/WebCore/platform/graphics/Image.h (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/Image.h	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2018-04-06 16:29:52 UTC (rev 230334)
@@ -137,9 +137,6 @@
     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 @@
     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.
 

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2018-04-06 16:29:52 UTC (rev 230334)
@@ -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)

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/ImageSource.h	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h	2018-04-06 16:29:52 UTC (rev 230334)
@@ -35,8 +35,8 @@
 
 namespace WebCore {
 
+class BitmapImage;
 class GraphicsContext;
-class Image;
 class ImageDecoder;
 class URL;
 
@@ -43,11 +43,9 @@
 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 @@
     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 @@
 
     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 };

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2018-04-06 16:29:52 UTC (rev 230334)
@@ -48,14 +48,14 @@
     // 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,

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2018-04-06 16:29:52 UTC (rev 230334)
@@ -325,12 +325,12 @@
         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();

Modified: trunk/Source/WebCore/platform/graphics/mac/ImageMac.mm (230333 => 230334)


--- trunk/Source/WebCore/platform/graphics/mac/ImageMac.mm	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/platform/graphics/mac/ImageMac.mm	2018-04-06 16:29:52 UTC (rev 230334)
@@ -105,9 +105,7 @@
         return nullptr;
 
     m_tiffRep = data;
-    return m_tiffRep.get();
-
-    
+    return m_tiffRep.get();    
 }
 
 #if USE(APPKIT)

Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (230333 => 230334)


--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2018-04-06 16:26:04 UTC (rev 230333)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2018-04-06 16:29:52 UTC (rev 230334)
@@ -27,6 +27,7 @@
 
 #include "RenderLayerBacking.h"
 
+#include "BitmapImage.h"
 #include "CSSAnimationController.h"
 #include "CanvasRenderingContext.h"
 #include "CSSPropertyNames.h"
@@ -2189,10 +2190,10 @@
             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))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to