Title: [191352] trunk/Source/WebCore
Revision
191352
Author
[email protected]
Date
2015-10-20 13:38:03 -0700 (Tue, 20 Oct 2015)

Log Message

Add basic TextStream output for Images
https://bugs.webkit.org/show_bug.cgi?id=150350

Reviewed by Darin Adler.

Add a TextStream output operator for Image, and virtual dump() member functions
that the various image types override to dump their own data.

Add isFoo() functions for each image type (surprising that these didn't already
exist) so we can print the image type.

Make isAnimated() const, and isBitmapImage() private.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::dump):
* platform/graphics/BitmapImage.h:
* platform/graphics/CrossfadeGeneratedImage.cpp:
(WebCore::CrossfadeGeneratedImage::dump):
* platform/graphics/CrossfadeGeneratedImage.h:
* platform/graphics/GeneratedImage.cpp:
* platform/graphics/GeneratedImage.h:
* platform/graphics/GradientImage.cpp:
(WebCore::GradientImage::dump):
* platform/graphics/GradientImage.h:
* platform/graphics/Image.cpp:
(WebCore::Image::dump):
(WebCore::operator<<):
* platform/graphics/Image.h:
(WebCore::Image::isGeneratedImage):
(WebCore::Image::isCrossfadeGeneratedImage):
(WebCore::Image::isNamedImageGeneratedImage):
(WebCore::Image::isGradientImage):
(WebCore::Image::isSVGImage):
(WebCore::Image::isAnimated):
* platform/graphics/NamedImageGeneratedImage.cpp:
(WebCore::NamedImageGeneratedImage::dump):
* platform/graphics/NamedImageGeneratedImage.h:
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::dump):
* platform/graphics/cg/PDFDocumentImage.h:
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::dump):
* svg/graphics/SVGImage.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (191351 => 191352)


--- trunk/Source/WebCore/ChangeLog	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/ChangeLog	2015-10-20 20:38:03 UTC (rev 191352)
@@ -1,3 +1,49 @@
+2015-10-20  Simon Fraser  <[email protected]>
+
+        Add basic TextStream output for Images
+        https://bugs.webkit.org/show_bug.cgi?id=150350
+
+        Reviewed by Darin Adler.
+
+        Add a TextStream output operator for Image, and virtual dump() member functions
+        that the various image types override to dump their own data.
+        
+        Add isFoo() functions for each image type (surprising that these didn't already
+        exist) so we can print the image type.
+        
+        Make isAnimated() const, and isBitmapImage() private.
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::dump):
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/CrossfadeGeneratedImage.cpp:
+        (WebCore::CrossfadeGeneratedImage::dump):
+        * platform/graphics/CrossfadeGeneratedImage.h:
+        * platform/graphics/GeneratedImage.cpp:
+        * platform/graphics/GeneratedImage.h:
+        * platform/graphics/GradientImage.cpp:
+        (WebCore::GradientImage::dump):
+        * platform/graphics/GradientImage.h:
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::dump):
+        (WebCore::operator<<):
+        * platform/graphics/Image.h:
+        (WebCore::Image::isGeneratedImage):
+        (WebCore::Image::isCrossfadeGeneratedImage):
+        (WebCore::Image::isNamedImageGeneratedImage):
+        (WebCore::Image::isGradientImage):
+        (WebCore::Image::isSVGImage):
+        (WebCore::Image::isAnimated):
+        * platform/graphics/NamedImageGeneratedImage.cpp:
+        (WebCore::NamedImageGeneratedImage::dump):
+        * platform/graphics/NamedImageGeneratedImage.h:
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::dump):
+        * platform/graphics/cg/PDFDocumentImage.h:
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::dump):
+        * svg/graphics/SVGImage.h:
+
 2015-10-20  Chris Dumez  <[email protected]>
 
         Use tighter typing for collections / node lists' item() / namedItem() methods

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -33,6 +33,7 @@
 #include "ImageObserver.h"
 #include "IntRect.h"
 #include "MIMETypeRegistry.h"
+#include "TextStream.h"
 #include "Timer.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/Vector.h>
@@ -709,4 +710,25 @@
     return shouldAnimate() && frameCount() > 1;
 }
 
+void BitmapImage::dump(TextStream& ts) const
+{
+    Image::dump(ts);
+
+    ts.dumpProperty("type", m_source.filenameExtension());
+
+    if (isAnimated()) {
+        ts.dumpProperty("frame-count", m_frameCount);
+        ts.dumpProperty("repetitions", m_repetitionCount);
+        ts.dumpProperty("current-frame", m_currentFrame);
+    }
+    
+    if (allowSubsampling())
+        ts.dumpProperty("allow-subsampling", allowSubsampling());
+    if (m_isSolidColor)
+        ts.dumpProperty("solid-color", m_isSolidColor);
+    
+    if (m_imageOrientation != OriginTopLeft)
+        ts.dumpProperty("orientation", m_imageOrientation);
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -121,8 +121,6 @@
 #endif
     virtual ~BitmapImage();
     
-    virtual bool isBitmapImage() const override { return true; }
-
     virtual bool hasSingleSecurityOrigin() const override;
 
     // FloatSize due to override.
@@ -179,7 +177,7 @@
 
     virtual bool currentFrameKnownToBeOpaque() override;
 
-    virtual bool isAnimated() override { return m_frameCount > 1; }
+    virtual bool isAnimated() const override { return m_frameCount > 1; }
     
     bool canAnimate();
 
@@ -187,6 +185,8 @@
     void setAllowSubsampling(bool allowSubsampling) { m_allowSubsampling = allowSubsampling; }
     
 private:
+    virtual bool isBitmapImage() const override { return true; }
+
     void updateSize(ImageOrientationDescription = ImageOrientationDescription()) const;
     void determineMinimumSubsamplingLevel() const;
 
@@ -291,6 +291,8 @@
     void clearTimer();
     void startTimer(double delay);
 
+    virtual void dump(TextStream&) const override;
+
     ImageSource m_source;
     mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image).
     mutable IntSize m_sizeRespectingOrientation;

Modified: trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -29,6 +29,7 @@
 #include "FloatRect.h"
 #include "GraphicsContext.h"
 #include "ImageBuffer.h"
+#include "TextStream.h"
 
 namespace WebCore {
 
@@ -109,4 +110,12 @@
     imageBuffer->drawPattern(context, srcRect, patternTransform, phase, spacing, styleColorSpace, compositeOp, dstRect, blendMode);
 }
 
+void CrossfadeGeneratedImage::dump(TextStream& ts) const
+{
+    GeneratedImage::dump(ts);
+    ts.dumpProperty("from-image", m_fromImage.get());
+    ts.dumpProperty("to-image", m_toImage.get());
+    ts.dumpProperty("percentage", m_percentage);
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -55,6 +55,9 @@
     CrossfadeGeneratedImage(Image& fromImage, Image& toImage, float percentage, const FloatSize& crossfadeSize, const FloatSize&);
 
 private:
+    virtual bool isCrossfadeGeneratedImage() const override { return true; }
+    virtual void dump(TextStream&) const override;
+    
     void drawCrossfade(GraphicsContext&);
 
     Ref<Image> m_fromImage;

Modified: trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -33,7 +33,6 @@
 
 #include "FloatSize.h"
 
-
 namespace WebCore {
 
 void GeneratedImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)

Modified: trunk/Source/WebCore/platform/graphics/GeneratedImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/GeneratedImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/GeneratedImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -59,6 +59,8 @@
     GeneratedImage() { }
 
 private:
+    virtual bool isGeneratedImage() const override { return true; }
+
     FloatSize m_size;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/GradientImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/GradientImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/GradientImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -30,6 +30,7 @@
 #include "GraphicsContext.h"
 #include "ImageBuffer.h"
 #include "Length.h"
+#include "TextStream.h"
 
 namespace WebCore {
 
@@ -94,4 +95,10 @@
     m_cachedImageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, spacing, styleColorSpace, compositeOp, destRect, blendMode);
 }
 
+void GradientImage::dump(TextStream& ts) const
+{
+    GeneratedImage::dump(ts);
+    // FIXME: dump the gradient.
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/GradientImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/GradientImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/GradientImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -53,6 +53,9 @@
     GradientImage(PassRefPtr<Gradient>, const FloatSize&);
 
 private:
+    virtual bool isGradientImage() const override { return true; }
+    virtual void dump(TextStream&) const override;
+    
     RefPtr<Gradient> m_gradient;
     std::unique_ptr<ImageBuffer> m_cachedImageBuffer;
     FloatSize m_cachedAdjustedSize;

Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/Image.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -34,6 +34,7 @@
 #include "Length.h"
 #include "MIMETypeRegistry.h"
 #include "SharedBuffer.h"
+#include "TextStream.h"
 #include <math.h>
 #include <wtf/MainThread.h>
 #include <wtf/StdLibExtras.h>
@@ -270,4 +271,36 @@
     intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
 }
 
+void Image::dump(TextStream& ts) const
+{
+    if (isAnimated())
+        ts.dumpProperty("animated", isAnimated());
+
+    if (isNull())
+        ts.dumpProperty("is-null-image", true);
+
+    ts.dumpProperty("size", size());
 }
+
+TextStream& operator<<(TextStream& ts, const Image& image)
+{
+    TextStream::GroupScope scope(ts);
+    
+    if (image.isBitmapImage())
+        ts << "bitmap image";
+    else if (image.isCrossfadeGeneratedImage())
+        ts << "crossfade image";
+    else if (image.isNamedImageGeneratedImage())
+        ts << "named image";
+    else if (image.isGradientImage())
+        ts << "gradient image";
+    else if (image.isSVGImage())
+        ts << "svg image";
+    else if (image.isPDFDocumentImage())
+        ts << "pdf image";
+
+    image.dump(ts);
+    return ts;
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/Image.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/Image.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -80,13 +80,17 @@
     WEBCORE_EXPORT static PassRefPtr<Image> loadPlatformResource(const char* name);
     WEBCORE_EXPORT static bool supportsType(const String&);
 
+    virtual bool isBitmapImage() const { return false; }
+    virtual bool isGeneratedImage() const { return false; }
+    virtual bool isCrossfadeGeneratedImage() const { return false; }
+    virtual bool isNamedImageGeneratedImage() const { return false; }
+    virtual bool isGradientImage() const { return false; }
     virtual bool isSVGImage() const { return false; }
-    virtual bool isBitmapImage() const { return false; }
     virtual bool isPDFDocumentImage() const { return false; }
+
     virtual bool currentFrameKnownToBeOpaque() = 0;
+    virtual bool isAnimated() const { return false; }
 
-    virtual bool isAnimated() { return false; }
-
     // Derived classes should override this if they can assure that 
     // the image contains only resources from its own security origin.
     virtual bool hasSingleSecurityOrigin() const { return false; }
@@ -177,6 +181,8 @@
     virtual bool notSolidColor() { return true; }
 #endif
 
+    virtual void dump(TextStream&) const;
+
 protected:
     Image(ImageObserver* = nullptr);
 
@@ -200,6 +206,8 @@
     ImageObserver* m_imageObserver;
 };
 
+TextStream& operator<<(TextStream&, const Image&);
+
 } // namespace WebCore
 
 #define SPECIALIZE_TYPE_TRAITS_IMAGE(ToClassName) \

Modified: trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -29,6 +29,7 @@
 #include "FloatRect.h"
 #include "GraphicsContext.h"
 #include "ImageBuffer.h"
+#include "TextStream.h"
 #include "Theme.h"
 
 namespace WebCore {
@@ -85,4 +86,10 @@
 #endif
 }
 
+void NamedImageGeneratedImage::dump(TextStream& ts) const
+{
+    GeneratedImage::dump(ts);
+    ts.dumpProperty("name", m_name);
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -47,6 +47,9 @@
     NamedImageGeneratedImage(String name, const FloatSize&);
 
 private:
+    virtual bool isNamedImageGeneratedImage() const override { return true; }
+    virtual void dump(TextStream&) const override;
+
     String m_name;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -40,6 +40,7 @@
 #include "IntRect.h"
 #include "Length.h"
 #include "SharedBuffer.h"
+#include "TextStream.h"
 #include <CoreGraphics/CGContext.h>
 #include <CoreGraphics/CGPDFDocument.h>
 #include <wtf/MathExtras.h>
@@ -264,6 +265,15 @@
 
 #endif // !USE(PDFKIT_FOR_PDFDOCUMENTIMAGE)
 
+void PDFDocumentImage::dump(TextStream& ts) const
+{
+    Image::dump(ts);
+    ts.dumpProperty("page-count", pageCount());
+    ts.dumpProperty("crop-box", m_cropBox);
+    if (m_rotationDegrees)
+        ts.dumpProperty("rotation", m_rotationDegrees);
 }
 
+}
+
 #endif // USE(CG)

Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h (191351 => 191352)


--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -74,6 +74,8 @@
     // FIXME: Implement this to be less conservative.
     virtual bool currentFrameKnownToBeOpaque() override { return false; }
 
+    virtual void dump(TextStream&) const override;
+
     void createPDFDocument();
     void computeBoundsForCurrentPage();
     unsigned pageCount() const;

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (191351 => 191352)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2015-10-20 20:38:03 UTC (rev 191352)
@@ -45,6 +45,7 @@
 #include "SVGImageClients.h"
 #include "SVGSVGElement.h"
 #include "Settings.h"
+#include "TextStream.h"
 
 namespace WebCore {
 
@@ -400,4 +401,11 @@
     return page->chrome().client().isSVGImageChromeClient();
 }
 
+void SVGImage::dump(TextStream& ts) const
+{
+    Image::dump(ts);
+    ts.dumpProperty("url", m_url.string());
 }
+
+
+}

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.h (191351 => 191352)


--- trunk/Source/WebCore/svg/graphics/SVGImage.h	2015-10-20 18:48:26 UTC (rev 191351)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.h	2015-10-20 20:38:03 UTC (rev 191352)
@@ -90,6 +90,8 @@
     // FIXME: Implement this to be less conservative.
     virtual bool currentFrameKnownToBeOpaque() override { return false; }
 
+    virtual void dump(TextStream&) const override;
+
     SVGImage(ImageObserver&, const URL&);
     virtual void draw(GraphicsContext&, const FloatRect& fromRect, const FloatRect& toRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, ImageOrientationDescription) override;
     void drawForContainer(GraphicsContext&, const FloatSize, float, const FloatRect&, const FloatRect&, ColorSpace, CompositeOperator, BlendMode);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to