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 AcceleratedStaticBitmapImage_h | 5 #ifndef AcceleratedStaticBitmapImage_h |
6 #define AcceleratedStaticBitmapImage_h | 6 #define AcceleratedStaticBitmapImage_h |
7 | 7 |
8 #include "base/threading/thread_checker.h" | 8 #include "base/threading/thread_checker.h" |
9 #include "platform/geometry/IntSize.h" | |
10 #include "platform/graphics/StaticBitmapImage.h" | 9 #include "platform/graphics/StaticBitmapImage.h" |
11 #include "third_party/skia/include/core/SkRefCnt.h" | 10 #include "platform/graphics/TextureHolder.h" |
| 11 #include "wtf/WeakPtr.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 class GrContext; | 15 class GrContext; |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 class SingleReleaseCallback; | 18 class SingleReleaseCallback; |
19 } | 19 } |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 class WebThread; | 22 class DrawingBuffer; |
| 23 class TextureHolder; |
23 | 24 |
24 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final | 25 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final |
25 : public StaticBitmapImage { | 26 : public StaticBitmapImage { |
26 public: | 27 public: |
| 28 ~AcceleratedStaticBitmapImage() override; |
27 // SkImage with a texture backing that is assumed to be from the shared | 29 // SkImage with a texture backing that is assumed to be from the shared |
28 // context of the current thread. | 30 // context of the current thread. |
29 static PassRefPtr<AcceleratedStaticBitmapImage> createFromSharedContextImage( | 31 static PassRefPtr<AcceleratedStaticBitmapImage> createFromSharedContextImage( |
30 sk_sp<SkImage>); | 32 sk_sp<SkImage>); |
31 // Can specify the GrContext that created the texture backing the for the | 33 // Can specify the GrContext that created the texture backing. Ideally all |
32 // given SkImage. Ideally all callers would use this option. The |mailbox| is | 34 // callers would use this option. The |mailbox| is a name for the texture |
33 // a name for the texture backing the SkImage, allowing other contexts to use | 35 // backing, allowing other contexts to use the same backing. |
34 // the same backing. | |
35 static PassRefPtr<AcceleratedStaticBitmapImage> createFromWebGLContextImage( | 36 static PassRefPtr<AcceleratedStaticBitmapImage> createFromWebGLContextImage( |
36 sk_sp<SkImage>, | |
37 const gpu::Mailbox&, | 37 const gpu::Mailbox&, |
38 const gpu::SyncToken&); | 38 const gpu::SyncToken&, |
| 39 unsigned textureId, |
| 40 WeakPtr<DrawingBuffer>, |
| 41 IntSize mailboxSize); |
39 | 42 |
40 ~AcceleratedStaticBitmapImage() override; | 43 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override; |
| 44 IntSize size() const override; |
| 45 sk_sp<SkImage> imageForCurrentFrame() override; |
| 46 bool isTextureBacked() final { return true; } |
41 | 47 |
42 // StaticBitmapImage overrides. | |
43 sk_sp<SkImage> imageForCurrentFrame() override; | |
44 void copyToTexture(WebGraphicsContext3DProvider*, | |
45 GLuint destTextureId, | |
46 GLenum destInternalFormat, | |
47 GLenum destType, | |
48 bool flipY) override; | |
49 | |
50 // Image overrides. | |
51 void draw(SkCanvas*, | 48 void draw(SkCanvas*, |
52 const SkPaint&, | 49 const SkPaint&, |
53 const FloatRect& dstRect, | 50 const FloatRect& dstRect, |
54 const FloatRect& srcRect, | 51 const FloatRect& srcRect, |
55 RespectImageOrientationEnum, | 52 RespectImageOrientationEnum, |
56 ImageClampingMode) override; | 53 ImageClampingMode) override; |
57 | 54 |
| 55 void copyToTexture(WebGraphicsContext3DProvider*, |
| 56 GLuint destTextureId, |
| 57 GLenum destInternalFormat, |
| 58 GLenum destType, |
| 59 bool flipY) override; |
| 60 |
| 61 bool hasMailbox() final { return m_textureHolder->isMailboxTextureHolder(); } |
58 // To be called on sender thread before performing a transfer | 62 // To be called on sender thread before performing a transfer |
59 void transfer() final; | 63 void transfer() final; |
60 | 64 |
61 void ensureMailbox() final; | 65 void ensureMailbox() final; |
62 gpu::Mailbox getMailbox() final { return m_mailbox; } | 66 gpu::Mailbox mailbox() final { return m_textureHolder->mailbox(); } |
63 gpu::SyncToken getSyncToken() final { return m_syncToken; } | 67 gpu::SyncToken syncToken() final { return m_textureHolder->syncToken(); } |
| 68 void updateSyncToken(gpu::SyncToken) final; |
64 | 69 |
65 private: | 70 private: |
66 AcceleratedStaticBitmapImage(sk_sp<SkImage>); | 71 AcceleratedStaticBitmapImage(sk_sp<SkImage>); |
67 AcceleratedStaticBitmapImage(sk_sp<SkImage>, | 72 AcceleratedStaticBitmapImage(const gpu::Mailbox&, |
68 const gpu::Mailbox&, | 73 const gpu::SyncToken&, |
69 const gpu::SyncToken&); | 74 unsigned textureId, |
| 75 WeakPtr<DrawingBuffer>, |
| 76 IntSize mailboxSize); |
70 | 77 |
71 void createImageFromMailboxIfNeeded(); | 78 void createImageFromMailboxIfNeeded(); |
72 void checkThread(); | 79 void checkThread(); |
73 void waitSyncTokenIfNeeded(); | 80 void waitSyncTokenIfNeeded(); |
74 bool isValid(); | 81 bool isValid(); |
75 void releaseImageThreadSafe(); | |
76 bool imageBelongsToSharedContext(); | |
77 | 82 |
78 // Id of the shared context where m_image was created | 83 std::unique_ptr<TextureHolder> m_textureHolder; |
79 unsigned m_sharedContextId; | |
80 // True when the below mailbox and sync token are valid for getting at the | |
81 // texture backing the object's SkImage. | |
82 bool m_hasMailbox = false; | |
83 // A mailbox referring to the texture id backing the SkImage. The mailbox is | |
84 // valid as long as the SkImage is held alive. | |
85 gpu::Mailbox m_mailbox; | |
86 // This token must be waited for before using the mailbox. | |
87 gpu::SyncToken m_syncToken; | |
88 // Thread that |m_image| belongs to. Set to null when |m_image| belongs to the | |
89 // same thread as this AcceleratedStaticBitmapImage. Should only be non-null | |
90 // after a transfer. | |
91 WebThread* m_imageThread = nullptr; | |
92 | 84 |
93 base::ThreadChecker m_threadChecker; | 85 base::ThreadChecker m_threadChecker; |
94 bool m_detachThreadAtNextCheck = false; | 86 bool m_detachThreadAtNextCheck = false; |
95 }; | 87 }; |
96 | 88 |
97 } // namespace blink | 89 } // namespace blink |
98 | 90 |
99 #endif | 91 #endif |
OLD | NEW |