Changeset 191352 in webkit


Ignore:
Timestamp:
Oct 20, 2015, 1:38:03 PM (10 years ago)
Author:
Simon Fraser
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:
Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r191351 r191352  
     12015-10-20  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add basic TextStream output for Images
     4        https://bugs.webkit.org/show_bug.cgi?id=150350
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a TextStream output operator for Image, and virtual dump() member functions
     9        that the various image types override to dump their own data.
     10       
     11        Add isFoo() functions for each image type (surprising that these didn't already
     12        exist) so we can print the image type.
     13       
     14        Make isAnimated() const, and isBitmapImage() private.
     15
     16        * platform/graphics/BitmapImage.cpp:
     17        (WebCore::BitmapImage::dump):
     18        * platform/graphics/BitmapImage.h:
     19        * platform/graphics/CrossfadeGeneratedImage.cpp:
     20        (WebCore::CrossfadeGeneratedImage::dump):
     21        * platform/graphics/CrossfadeGeneratedImage.h:
     22        * platform/graphics/GeneratedImage.cpp:
     23        * platform/graphics/GeneratedImage.h:
     24        * platform/graphics/GradientImage.cpp:
     25        (WebCore::GradientImage::dump):
     26        * platform/graphics/GradientImage.h:
     27        * platform/graphics/Image.cpp:
     28        (WebCore::Image::dump):
     29        (WebCore::operator<<):
     30        * platform/graphics/Image.h:
     31        (WebCore::Image::isGeneratedImage):
     32        (WebCore::Image::isCrossfadeGeneratedImage):
     33        (WebCore::Image::isNamedImageGeneratedImage):
     34        (WebCore::Image::isGradientImage):
     35        (WebCore::Image::isSVGImage):
     36        (WebCore::Image::isAnimated):
     37        * platform/graphics/NamedImageGeneratedImage.cpp:
     38        (WebCore::NamedImageGeneratedImage::dump):
     39        * platform/graphics/NamedImageGeneratedImage.h:
     40        * platform/graphics/cg/PDFDocumentImage.cpp:
     41        (WebCore::PDFDocumentImage::dump):
     42        * platform/graphics/cg/PDFDocumentImage.h:
     43        * svg/graphics/SVGImage.cpp:
     44        (WebCore::SVGImage::dump):
     45        * svg/graphics/SVGImage.h:
     46
    1472015-10-20  Chris Dumez  <cdumez@apple.com>
    248
  • TabularUnified trunk/Source/WebCore/platform/graphics/BitmapImage.cpp

    r190910 r191352  
    3434#include "IntRect.h"
    3535#include "MIMETypeRegistry.h"
     36#include "TextStream.h"
    3637#include "Timer.h"
    3738#include <wtf/CurrentTime.h>
     
    710711}
    711712
    712 }
     713void BitmapImage::dump(TextStream& ts) const
     714{
     715    Image::dump(ts);
     716
     717    ts.dumpProperty("type", m_source.filenameExtension());
     718
     719    if (isAnimated()) {
     720        ts.dumpProperty("frame-count", m_frameCount);
     721        ts.dumpProperty("repetitions", m_repetitionCount);
     722        ts.dumpProperty("current-frame", m_currentFrame);
     723    }
     724   
     725    if (allowSubsampling())
     726        ts.dumpProperty("allow-subsampling", allowSubsampling());
     727    if (m_isSolidColor)
     728        ts.dumpProperty("solid-color", m_isSolidColor);
     729   
     730    if (m_imageOrientation != OriginTopLeft)
     731        ts.dumpProperty("orientation", m_imageOrientation);
     732}
     733
     734}
  • TabularUnified trunk/Source/WebCore/platform/graphics/BitmapImage.h

    r190910 r191352  
    122122    virtual ~BitmapImage();
    123123   
    124     virtual bool isBitmapImage() const override { return true; }
    125 
    126124    virtual bool hasSingleSecurityOrigin() const override;
    127125
     
    180178    virtual bool currentFrameKnownToBeOpaque() override;
    181179
    182     virtual bool isAnimated() override { return m_frameCount > 1; }
     180    virtual bool isAnimated() const override { return m_frameCount > 1; }
    183181   
    184182    bool canAnimate();
     
    188186   
    189187private:
     188    virtual bool isBitmapImage() const override { return true; }
     189
    190190    void updateSize(ImageOrientationDescription = ImageOrientationDescription()) const;
    191191    void determineMinimumSubsamplingLevel() const;
     
    292292    void startTimer(double delay);
    293293
     294    virtual void dump(TextStream&) const override;
     295
    294296    ImageSource m_source;
    295297    mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image).
  • TabularUnified trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp

    r191049 r191352  
    3030#include "GraphicsContext.h"
    3131#include "ImageBuffer.h"
     32#include "TextStream.h"
    3233
    3334namespace WebCore {
     
    110111}
    111112
     113void CrossfadeGeneratedImage::dump(TextStream& ts) const
     114{
     115    GeneratedImage::dump(ts);
     116    ts.dumpProperty("from-image", m_fromImage.get());
     117    ts.dumpProperty("to-image", m_toImage.get());
     118    ts.dumpProperty("percentage", m_percentage);
    112119}
     120
     121}
  • TabularUnified trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.h

    r191049 r191352  
    5656
    5757private:
     58    virtual bool isCrossfadeGeneratedImage() const override { return true; }
     59    virtual void dump(TextStream&) const override;
     60   
    5861    void drawCrossfade(GraphicsContext&);
    5962
  • TabularUnified trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp

    r148921 r191352  
    3434#include "FloatSize.h"
    3535
    36 
    3736namespace WebCore {
    3837
  • TabularUnified trunk/Source/WebCore/platform/graphics/GeneratedImage.h

    r190910 r191352  
    6060
    6161private:
     62    virtual bool isGeneratedImage() const override { return true; }
     63
    6264    FloatSize m_size;
    6365};
  • TabularUnified trunk/Source/WebCore/platform/graphics/GradientImage.cpp

    r191049 r191352  
    3131#include "ImageBuffer.h"
    3232#include "Length.h"
     33#include "TextStream.h"
    3334
    3435namespace WebCore {
     
    9596}
    9697
     98void GradientImage::dump(TextStream& ts) const
     99{
     100    GeneratedImage::dump(ts);
     101    // FIXME: dump the gradient.
    97102}
     103
     104}
  • TabularUnified trunk/Source/WebCore/platform/graphics/GradientImage.h

    r190910 r191352  
    5454
    5555private:
     56    virtual bool isGradientImage() const override { return true; }
     57    virtual void dump(TextStream&) const override;
     58   
    5659    RefPtr<Gradient> m_gradient;
    5760    std::unique_ptr<ImageBuffer> m_cachedImageBuffer;
  • TabularUnified trunk/Source/WebCore/platform/graphics/Image.cpp

    r190910 r191352  
    3535#include "MIMETypeRegistry.h"
    3636#include "SharedBuffer.h"
     37#include "TextStream.h"
    3738#include <math.h>
    3839#include <wtf/MainThread.h>
     
    271272}
    272273
    273 }
     274void Image::dump(TextStream& ts) const
     275{
     276    if (isAnimated())
     277        ts.dumpProperty("animated", isAnimated());
     278
     279    if (isNull())
     280        ts.dumpProperty("is-null-image", true);
     281
     282    ts.dumpProperty("size", size());
     283}
     284
     285TextStream& operator<<(TextStream& ts, const Image& image)
     286{
     287    TextStream::GroupScope scope(ts);
     288   
     289    if (image.isBitmapImage())
     290        ts << "bitmap image";
     291    else if (image.isCrossfadeGeneratedImage())
     292        ts << "crossfade image";
     293    else if (image.isNamedImageGeneratedImage())
     294        ts << "named image";
     295    else if (image.isGradientImage())
     296        ts << "gradient image";
     297    else if (image.isSVGImage())
     298        ts << "svg image";
     299    else if (image.isPDFDocumentImage())
     300        ts << "pdf image";
     301
     302    image.dump(ts);
     303    return ts;
     304}
     305
     306}
  • TabularUnified trunk/Source/WebCore/platform/graphics/Image.h

    r191326 r191352  
    8181    WEBCORE_EXPORT static bool supportsType(const String&);
    8282
     83    virtual bool isBitmapImage() const { return false; }
     84    virtual bool isGeneratedImage() const { return false; }
     85    virtual bool isCrossfadeGeneratedImage() const { return false; }
     86    virtual bool isNamedImageGeneratedImage() const { return false; }
     87    virtual bool isGradientImage() const { return false; }
    8388    virtual bool isSVGImage() const { return false; }
    84     virtual bool isBitmapImage() const { return false; }
    8589    virtual bool isPDFDocumentImage() const { return false; }
     90
    8691    virtual bool currentFrameKnownToBeOpaque() = 0;
    87 
    88     virtual bool isAnimated() { return false; }
     92    virtual bool isAnimated() const { return false; }
    8993
    9094    // Derived classes should override this if they can assure that
     
    178182#endif
    179183
     184    virtual void dump(TextStream&) const;
     185
    180186protected:
    181187    Image(ImageObserver* = nullptr);
     
    201207};
    202208
     209TextStream& operator<<(TextStream&, const Image&);
     210
    203211} // namespace WebCore
    204212
  • TabularUnified trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp

    r190911 r191352  
    3030#include "GraphicsContext.h"
    3131#include "ImageBuffer.h"
     32#include "TextStream.h"
    3233#include "Theme.h"
    3334
     
    8687}
    8788
     89void NamedImageGeneratedImage::dump(TextStream& ts) const
     90{
     91    GeneratedImage::dump(ts);
     92    ts.dumpProperty("name", m_name);
    8893}
     94
     95}
  • TabularUnified trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.h

    r190910 r191352  
    4848
    4949private:
     50    virtual bool isNamedImageGeneratedImage() const override { return true; }
     51    virtual void dump(TextStream&) const override;
     52
    5053    String m_name;
    5154};
  • TabularUnified trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp

    r191049 r191352  
    4141#include "Length.h"
    4242#include "SharedBuffer.h"
     43#include "TextStream.h"
    4344#include <CoreGraphics/CGContext.h>
    4445#include <CoreGraphics/CGPDFDocument.h>
     
    265266#endif // !USE(PDFKIT_FOR_PDFDOCUMENTIMAGE)
    266267
     268void PDFDocumentImage::dump(TextStream& ts) const
     269{
     270    Image::dump(ts);
     271    ts.dumpProperty("page-count", pageCount());
     272    ts.dumpProperty("crop-box", m_cropBox);
     273    if (m_rotationDegrees)
     274        ts.dumpProperty("rotation", m_rotationDegrees);
     275}
     276
    267277}
    268278
  • TabularUnified trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h

    r189144 r191352  
    7575    virtual bool currentFrameKnownToBeOpaque() override { return false; }
    7676
     77    virtual void dump(TextStream&) const override;
     78
    7779    void createPDFDocument();
    7880    void computeBoundsForCurrentPage();
  • TabularUnified trunk/Source/WebCore/svg/graphics/SVGImage.cpp

    r190910 r191352  
    4646#include "SVGSVGElement.h"
    4747#include "Settings.h"
     48#include "TextStream.h"
    4849
    4950namespace WebCore {
     
    401402}
    402403
    403 }
     404void SVGImage::dump(TextStream& ts) const
     405{
     406    Image::dump(ts);
     407    ts.dumpProperty("url", m_url.string());
     408}
     409
     410
     411}
  • TabularUnified trunk/Source/WebCore/svg/graphics/SVGImage.h

    r190910 r191352  
    9191    virtual bool currentFrameKnownToBeOpaque() override { return false; }
    9292
     93    virtual void dump(TextStream&) const override;
     94
    9395    SVGImage(ImageObserver&, const URL&);
    9496    virtual void draw(GraphicsContext&, const FloatRect& fromRect, const FloatRect& toRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, ImageOrientationDescription) override;
Note: See TracChangeset for help on using the changeset viewer.