OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 StaticBitmapImage_h | 5 #ifndef StaticBitmapImage_h |
6 #define StaticBitmapImage_h | 6 #define StaticBitmapImage_h |
7 | 7 |
8 #include "gpu/command_buffer/common/mailbox.h" | 8 #include "gpu/command_buffer/common/mailbox.h" |
9 #include "gpu/command_buffer/common/sync_token.h" | 9 #include "gpu/command_buffer/common/sync_token.h" |
10 #include "platform/graphics/Image.h" | 10 #include "platform/graphics/Image.h" |
11 #include "third_party/khronos/GLES2/gl2.h" | 11 #include "third_party/khronos/GLES2/gl2.h" |
12 #include "third_party/skia/include/core/SkRefCnt.h" | 12 #include "third_party/skia/include/core/SkRefCnt.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class WebGraphicsContext3DProvider; | 16 class WebGraphicsContext3DProvider; |
17 | 17 |
18 class PLATFORM_EXPORT StaticBitmapImage : public Image { | 18 class PLATFORM_EXPORT StaticBitmapImage : public Image { |
19 public: | 19 public: |
20 ~StaticBitmapImage() override; | 20 static PassRefPtr<StaticBitmapImage> create(sk_sp<SkImage>); |
21 | 21 |
22 bool currentFrameIsComplete() override { return true; } | 22 // Methods overrided by all sub-classes |
23 | 23 virtual ~StaticBitmapImage() {} |
24 static PassRefPtr<StaticBitmapImage> create(sk_sp<SkImage>); | 24 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) = 0; |
25 void destroyDecodedData() override {} | 25 sk_sp<SkImage> imageForCurrentFrame() = 0; |
26 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override; | 26 bool isTextureBacked() = 0; |
27 IntSize size() const override; | |
28 void draw(SkCanvas*, | 27 void draw(SkCanvas*, |
29 const SkPaint&, | 28 const SkPaint&, |
30 const FloatRect& dstRect, | 29 const FloatRect& dstRect, |
31 const FloatRect& srcRect, | 30 const FloatRect& srcRect, |
32 RespectImageOrientationEnum, | 31 RespectImageOrientationEnum, |
33 ImageClampingMode) override; | 32 ImageClampingMode) = 0; |
34 | 33 |
35 sk_sp<SkImage> imageForCurrentFrame() override; | 34 // Methods have common implementation for all sub-classes |
| 35 bool currentFrameIsComplete() override { return true; } |
| 36 void destroyDecodedData() {} |
36 | 37 |
37 bool originClean() const { return m_isOriginClean; } | 38 // Methods that have a default implementation, and overrided by only one |
38 void setOriginClean(bool flag) { m_isOriginClean = flag; } | 39 // sub-class |
39 bool isPremultiplied() const { return m_isPremultiplied; } | 40 virtual bool hasMailbox() { return false; } |
40 void setPremultiplied(bool flag) { m_isPremultiplied = flag; } | 41 virtual void transfer() {} |
41 bool isTextureBacked() override; | 42 |
| 43 // Methods overrided by AcceleratedStaticBitmapImage only |
42 virtual void copyToTexture(WebGraphicsContext3DProvider*, | 44 virtual void copyToTexture(WebGraphicsContext3DProvider*, |
43 GLuint, | 45 GLuint, |
44 GLenum, | 46 GLenum, |
45 GLenum, | 47 GLenum, |
46 bool) { | 48 bool) { |
47 NOTREACHED(); | 49 NOTREACHED(); |
48 } | 50 } |
49 virtual bool hasMailbox() { return false; } | 51 virtual void ensureMailbox() { NOTREACHED(); } |
50 virtual void transfer() {} | 52 virtual gpu::Mailbox mailbox() { |
| 53 NOTREACHED(); |
| 54 return gpu::Mailbox(); |
| 55 } |
| 56 virtual gpu::SyncToken syncToken() { |
| 57 NOTREACHED(); |
| 58 return gpu::SyncToken(); |
| 59 } |
| 60 virtual void updateSyncToken(gpu::SyncToken) { NOTREACHED(); } |
51 | 61 |
52 virtual gpu::Mailbox getMailbox() { return gpu::Mailbox(); } | 62 // Methods have exactly the same implementation for all sub-classes |
53 virtual gpu::SyncToken getSyncToken() { return gpu::SyncToken(); } | 63 bool originClean() const { return m_isOriginClean; } |
54 virtual void ensureMailbox() {} | 64 void setOriginClean(bool flag) { m_isOriginClean = flag; } |
| 65 bool isPremultiplied() const { return m_isPremultiplied; } |
| 66 void setPremultiplied(bool flag) { m_isPremultiplied = flag; } |
55 | 67 |
56 protected: | 68 protected: |
57 StaticBitmapImage(sk_sp<SkImage>); | 69 // Helper for sub-classes |
58 StaticBitmapImage(); // empty constructor for derived class. | 70 void drawHelper(SkCanvas*, |
59 sk_sp<SkImage> m_image; | 71 const SkPaint&, |
| 72 const FloatRect&, |
| 73 const FloatRect&, |
| 74 ImageClampingMode, |
| 75 sk_sp<SkImage>); |
60 | 76 |
61 private: | 77 // These two properties are here because the SkImage API doesn't expose the |
| 78 // info. They applied to both UnacceleratedStaticBitmapImage and |
| 79 // AcceleratedStaticBitmapImage. To change these two properties, the call |
| 80 // site would have to call the API setOriginClean() and setPremultiplied(). |
62 bool m_isOriginClean = true; | 81 bool m_isOriginClean = true; |
63 // The premultiply info is stored here because the SkImage API | |
64 // doesn't expose this info. | |
65 bool m_isPremultiplied = true; | 82 bool m_isPremultiplied = true; |
66 }; | 83 }; |
67 | 84 |
68 } // namespace blink | 85 } // namespace blink |
69 | 86 |
70 #endif | 87 #endif |
OLD | NEW |