Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef Image_h | 27 #ifndef Image_h |
| 28 #define Image_h | 28 #define Image_h |
| 29 | 29 |
| 30 #include "platform/PlatformExport.h" | 30 #include "platform/PlatformExport.h" |
| 31 #include "platform/SharedBuffer.h" | |
| 31 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
| 32 #include "platform/graphics/Color.h" | 33 #include "platform/graphics/Color.h" |
| 33 #include "platform/graphics/GraphicsTypes.h" | 34 #include "platform/graphics/GraphicsTypes.h" |
| 34 #include "platform/graphics/ImageAnimationPolicy.h" | 35 #include "platform/graphics/ImageAnimationPolicy.h" |
| 35 #include "platform/graphics/ImageObserver.h" | 36 #include "platform/graphics/ImageObserver.h" |
| 36 #include "platform/graphics/ImageOrientation.h" | 37 #include "platform/graphics/ImageOrientation.h" |
| 37 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
| 38 #include "wtf/Noncopyable.h" | 39 #include "wtf/Noncopyable.h" |
| 39 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
| 40 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
| 41 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 42 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
| 43 | 44 |
| 44 class SkBitmap; | 45 class SkBitmap; |
| 45 class SkCanvas; | 46 class SkCanvas; |
| 46 class SkImage; | 47 class SkImage; |
| 47 class SkMatrix; | 48 class SkMatrix; |
| 48 class SkPaint; | 49 class SkPaint; |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 52 class FloatPoint; | 53 class FloatPoint; |
| 53 class FloatRect; | 54 class FloatRect; |
| 54 class FloatSize; | 55 class FloatSize; |
| 55 class GraphicsContext; | 56 class GraphicsContext; |
| 56 class Length; | 57 class Length; |
| 57 class SharedBuffer; | |
| 58 class Image; | 58 class Image; |
| 59 | 59 |
| 60 class PLATFORM_EXPORT Image : public RefCounted<Image> { | 60 class PLATFORM_EXPORT Image : public RefCounted<Image> { |
| 61 friend class GeneratedImage; | 61 friend class GeneratedImage; |
| 62 friend class CrossfadeGeneratedImage; | 62 friend class CrossfadeGeneratedImage; |
| 63 friend class GradientGeneratedImage; | 63 friend class GradientGeneratedImage; |
| 64 friend class GraphicsContext; | 64 friend class GraphicsContext; |
| 65 WTF_MAKE_NONCOPYABLE(Image); | 65 WTF_MAKE_NONCOPYABLE(Image); |
| 66 | 66 |
| 67 public: | 67 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 int height() const { return size().height(); } | 101 int height() const { return size().height(); } |
| 102 virtual bool getHotSpot(IntPoint&) const { return false; } | 102 virtual bool getHotSpot(IntPoint&) const { return false; } |
| 103 | 103 |
| 104 bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived); | 104 bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived); |
| 105 virtual bool dataChanged(bool /*allDataReceived*/) { return false; } | 105 virtual bool dataChanged(bool /*allDataReceived*/) { return false; } |
| 106 | 106 |
| 107 virtual String filenameExtension() const { return String(); } // null string if unknown | 107 virtual String filenameExtension() const { return String(); } // null string if unknown |
| 108 | 108 |
| 109 virtual void destroyDecodedData() = 0; | 109 virtual void destroyDecodedData() = 0; |
| 110 | 110 |
| 111 SharedBuffer* data() { return m_encodedImageData.get(); } | 111 virtual PassRefPtr<SharedBuffer> data() { return m_encodedImageData; } |
| 112 | 112 |
| 113 // Animation begins whenever someone draws the image, so startAnimation() is not normally called. | 113 // Animation begins whenever someone draws the image, so startAnimation() is not normally called. |
| 114 // It will automatically pause once all observers no longer want to render t he image anywhere. | 114 // It will automatically pause once all observers no longer want to render t he image anywhere. |
| 115 enum CatchUpAnimation { DoNotCatchUp, CatchUp }; | 115 enum CatchUpAnimation { DoNotCatchUp, CatchUp }; |
| 116 virtual void startAnimation(CatchUpAnimation = CatchUp) { } | 116 virtual void startAnimation(CatchUpAnimation = CatchUp) { } |
| 117 virtual void resetAnimation() {} | 117 virtual void resetAnimation() {} |
| 118 | 118 |
| 119 // True if this image can potentially animate. | 119 // True if this image can potentially animate. |
| 120 virtual bool maybeAnimated() { return false; } | 120 virtual bool maybeAnimated() { return false; } |
| 121 | 121 |
| 122 // Set animationPolicy | 122 // Set animationPolicy |
| 123 virtual void setAnimationPolicy(ImageAnimationPolicy) { } | 123 virtual void setAnimationPolicy(ImageAnimationPolicy) { } |
| 124 virtual ImageAnimationPolicy animationPolicy() { return ImageAnimationPolicy Allowed; } | 124 virtual ImageAnimationPolicy animationPolicy() { return ImageAnimationPolicy Allowed; } |
| 125 virtual void advanceTime(double deltaTimeInSeconds) { } | 125 virtual void advanceTime(double deltaTimeInSeconds) { } |
| 126 | 126 |
| 127 // Advances an animated image. For BitmapImage (e.g., animated gifs) this | 127 // Advances an animated image. For BitmapImage (e.g., animated gifs) this |
| 128 // will advance to the next frame. For SVGImage, this will trigger an | 128 // will advance to the next frame. For SVGImage, this will trigger an |
| 129 // animation update for CSS and advance the SMIL timeline by one frame. | 129 // animation update for CSS and advance the SMIL timeline by one frame. |
| 130 virtual void advanceAnimationForTesting() { } | 130 virtual void advanceAnimationForTesting() { } |
| 131 | 131 |
| 132 // Typically the ImageResource that owns us. | 132 // Typically the ImageResource that owns us. |
| 133 ImageObserver* getImageObserver() const { return m_imageObserverDisabled ? n ullptr : m_imageObserver; } | 133 ImageObserver* getImageObserver() const { return m_imageObserverDisabled ? n ullptr : m_imageObserver; } |
| 134 void clearImageObserver() { m_imageObserver = nullptr; } | |
| 135 // Do not call setImageObserverDisabled() other than from ImageObserverDisab ler to avoid interleaved accesses to |m_imageObserverDisabled|. | 134 // Do not call setImageObserverDisabled() other than from ImageObserverDisab ler to avoid interleaved accesses to |m_imageObserverDisabled|. |
| 136 void setImageObserverDisabled(bool disabled) { m_imageObserverDisabled = dis abled; } | 135 void setImageObserverDisabled(bool disabled) { m_imageObserverDisabled = dis abled; } |
| 137 | 136 |
| 138 enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile }; | 137 enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile }; |
| 139 | 138 |
| 140 virtual PassRefPtr<SkImage> imageForCurrentFrame() = 0; | 139 virtual PassRefPtr<SkImage> imageForCurrentFrame() = 0; |
| 141 virtual PassRefPtr<Image> imageForDefaultFrame(); | 140 virtual PassRefPtr<Image> imageForDefaultFrame(); |
| 142 | 141 |
| 143 virtual void drawPattern(GraphicsContext&, const FloatRect&, | 142 virtual void drawPattern(GraphicsContext&, const FloatRect&, |
| 144 const FloatSize&, const FloatPoint& phase, SkXfermode::Mode, | 143 const FloatSize&, const FloatPoint& phase, SkXfermode::Mode, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 164 static FloatRect computeSubsetForTile(const FloatRect& tile, const FloatRect & dest, | 163 static FloatRect computeSubsetForTile(const FloatRect& tile, const FloatRect & dest, |
| 165 const FloatSize& imageSize); | 164 const FloatSize& imageSize); |
| 166 | 165 |
| 167 protected: | 166 protected: |
| 168 Image(ImageObserver* = 0); | 167 Image(ImageObserver* = 0); |
| 169 | 168 |
| 170 void drawTiled(GraphicsContext&, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, | 169 void drawTiled(GraphicsContext&, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, |
| 171 SkXfermode::Mode, const FloatSize& repeatSpacing); | 170 SkXfermode::Mode, const FloatSize& repeatSpacing); |
| 172 void drawTiled(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, const FloatSize& tileScaleFactor, TileRule hRule, TileRule vRule, SkXfe rmode::Mode); | 171 void drawTiled(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, const FloatSize& tileScaleFactor, TileRule hRule, TileRule vRule, SkXfe rmode::Mode); |
| 173 | 172 |
| 173 // Releases m_encodedImageData when the subclass can have encoded image data | |
| 174 // in another way. | |
| 175 void resetCachedData() { m_encodedImageData.release(); } | |
|
scroggo_chromium
2016/06/28 15:33:44
This method has an awkward name. It's a method on
hajimehoshi
2016/07/04 10:46:25
Agreed. Removed this and overrided setData instead
| |
| 176 | |
| 174 private: | 177 private: |
| 175 RefPtr<SharedBuffer> m_encodedImageData; | 178 RefPtr<SharedBuffer> m_encodedImageData; |
| 176 // TODO(Oilpan): consider having Image on the Oilpan heap and | 179 // TODO(Oilpan): consider having Image on the Oilpan heap and |
| 177 // turn this into a Member<>. | 180 // turn this into a Member<>. |
| 178 // | 181 // |
| 179 // The observer (an ImageResource) is an untraced member, with the ImageReso urce | 182 // The observer (an ImageResource) is an untraced member, with the ImageReso urce |
| 180 // being responsible of clearing itself out. | 183 // being responsible of clearing itself out. |
| 181 UntracedMember<ImageObserver> m_imageObserver; | 184 UntracedMember<ImageObserver> m_imageObserver; |
| 182 bool m_imageObserverDisabled; | 185 bool m_imageObserverDisabled; |
| 183 }; | 186 }; |
| 184 | 187 |
| 185 #define DEFINE_IMAGE_TYPE_CASTS(typeName) \ | 188 #define DEFINE_IMAGE_TYPE_CASTS(typeName) \ |
| 186 DEFINE_TYPE_CASTS(typeName, Image, image, image->is##typeName(), image.is##t ypeName()) | 189 DEFINE_TYPE_CASTS(typeName, Image, image, image->is##typeName(), image.is##t ypeName()) |
| 187 | 190 |
| 188 } // namespace blink | 191 } // namespace blink |
| 189 | 192 |
| 190 #endif | 193 #endif |
| OLD | NEW |