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