| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PlaceholderImage_h | 5 #ifndef PlaceholderImage_h |
| 6 #define PlaceholderImage_h | 6 #define PlaceholderImage_h |
| 7 | 7 |
| 8 #include "platform/SharedBuffer.h" | 8 #include "platform/SharedBuffer.h" |
| 9 #include "platform/geometry/IntSize.h" | 9 #include "platform/geometry/IntSize.h" |
| 10 #include "platform/graphics/Image.h" | 10 #include "platform/graphics/Image.h" |
| 11 #include "platform/graphics/ImageOrientation.h" | 11 #include "platform/graphics/ImageOrientation.h" |
| 12 #include "platform/wtf/PassRefPtr.h" | 12 #include "platform/wtf/PassRefPtr.h" |
| 13 #include "third_party/skia/include/core/SkImage.h" | 13 #include "third_party/skia/include/core/SkImage.h" |
| 14 #include "third_party/skia/include/core/SkRefCnt.h" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class FloatPoint; |
| 18 class FloatRect; | 19 class FloatRect; |
| 20 class FloatSize; |
| 21 class GraphicsContext; |
| 19 class ImageObserver; | 22 class ImageObserver; |
| 20 | 23 |
| 21 // A generated placeholder image that shows a translucent gray rectangle. | 24 // A generated placeholder image that shows a translucent gray rectangle. |
| 22 class PLATFORM_EXPORT PlaceholderImage final : public Image { | 25 class PLATFORM_EXPORT PlaceholderImage final : public Image { |
| 23 public: | 26 public: |
| 24 static PassRefPtr<PlaceholderImage> Create(ImageObserver* observer, | 27 static PassRefPtr<PlaceholderImage> Create(ImageObserver* observer, |
| 25 const IntSize& size) { | 28 const IntSize& size) { |
| 26 return AdoptRef(new PlaceholderImage(observer, size)); | 29 return AdoptRef(new PlaceholderImage(observer, size)); |
| 27 } | 30 } |
| 28 | 31 |
| 29 ~PlaceholderImage() override; | 32 ~PlaceholderImage() override; |
| 30 | 33 |
| 31 IntSize Size() const override { return size_; } | 34 IntSize Size() const override { return size_; } |
| 32 | 35 |
| 33 sk_sp<SkImage> ImageForCurrentFrame() override; | 36 sk_sp<SkImage> ImageForCurrentFrame() override; |
| 34 | 37 |
| 35 void Draw(PaintCanvas*, | 38 void Draw(PaintCanvas*, |
| 36 const PaintFlags&, | 39 const PaintFlags&, |
| 37 const FloatRect& dest_rect, | 40 const FloatRect& dest_rect, |
| 38 const FloatRect& src_rect, | 41 const FloatRect& src_rect, |
| 39 RespectImageOrientationEnum, | 42 RespectImageOrientationEnum, |
| 40 ImageClampingMode) override; | 43 ImageClampingMode) override; |
| 41 | 44 |
| 42 void DestroyDecodedData() override; | 45 void DestroyDecodedData() override; |
| 43 | 46 |
| 44 private: | 47 private: |
| 45 PlaceholderImage(ImageObserver* observer, const IntSize& size) | 48 PlaceholderImage(ImageObserver*, const IntSize&); |
| 46 : Image(observer), size_(size) {} | |
| 47 | 49 |
| 48 bool CurrentFrameHasSingleSecurityOrigin() const override { return true; } | 50 bool CurrentFrameHasSingleSecurityOrigin() const override { return true; } |
| 49 | 51 |
| 50 bool CurrentFrameKnownToBeOpaque( | 52 bool CurrentFrameKnownToBeOpaque( |
| 51 MetadataMode = kUseCurrentMetadata) override { | 53 MetadataMode = kUseCurrentMetadata) override { |
| 52 // Placeholder images are translucent. | 54 // Placeholder images are translucent. |
| 53 return false; | 55 return false; |
| 54 } | 56 } |
| 55 | 57 |
| 56 IntSize size_; | 58 void DrawPattern(GraphicsContext&, |
| 59 const FloatRect& src_rect, |
| 60 const FloatSize& scale, |
| 61 const FloatPoint& phase, |
| 62 SkBlendMode, |
| 63 const FloatRect& dest_rect, |
| 64 const FloatSize& repeat_spacing = FloatSize()) override; |
| 65 |
| 66 const IntSize size_; |
| 67 |
| 57 // Lazily initialized. | 68 // Lazily initialized. |
| 58 sk_sp<SkImage> image_for_current_frame_; | 69 sk_sp<SkImage> image_for_current_frame_; |
| 59 }; | 70 }; |
| 60 | 71 |
| 61 } // namespace blink | 72 } // namespace blink |
| 62 | 73 |
| 63 #endif | 74 #endif |
| OLD | NEW |