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 "gpu/command_buffer/common/mailbox.h" | 9 #include "gpu/command_buffer/common/mailbox.h" |
9 #include "gpu/command_buffer/common/sync_token.h" | 10 #include "gpu/command_buffer/common/sync_token.h" |
10 #include "platform/geometry/IntSize.h" | 11 #include "platform/geometry/IntSize.h" |
11 #include "platform/graphics/StaticBitmapImage.h" | 12 #include "platform/graphics/StaticBitmapImage.h" |
12 #include "third_party/skia/include/core/SkRefCnt.h" | 13 #include "third_party/skia/include/core/SkRefCnt.h" |
13 | 14 |
14 #include <memory> | 15 #include <memory> |
15 | 16 |
16 class GrContext; | 17 class GrContext; |
17 | 18 |
18 namespace cc { | 19 namespace cc { |
19 class SingleReleaseCallback; | 20 class SingleReleaseCallback; |
20 } | 21 } |
21 | 22 |
22 namespace blink { | 23 namespace blink { |
| 24 class WebThread; |
23 | 25 |
24 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final : public StaticBitmapIm
age { | 26 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final : public StaticBitmapIm
age { |
25 public: | 27 public: |
26 // SkImage with a texture backing that is assumed to be from the shared main
thread context. | 28 // SkImage with a texture backing that is assumed to be from the shared cont
ext of the current thread. |
27 static PassRefPtr<AcceleratedStaticBitmapImage> create(sk_sp<SkImage>); | 29 static PassRefPtr<AcceleratedStaticBitmapImage> createFromSharedContextImage
(sk_sp<SkImage>); |
28 // Can specify the GrContext that created the texture backing the for the gi
ven SkImage. Ideally all callers would use this option. | 30 // Can specify the GrContext that created the texture backing the for the gi
ven SkImage. Ideally all callers would use this option. |
29 // The |mailbox| is a name for the texture backing the SkImage, allowing oth
er contexts to use the same backing. | 31 // The |mailbox| is a name for the texture backing the SkImage, allowing oth
er contexts to use the same backing. |
30 static PassRefPtr<AcceleratedStaticBitmapImage> create(sk_sp<SkImage>, sk_sp
<GrContext>, const gpu::Mailbox&, const gpu::SyncToken&); | 32 static PassRefPtr<AcceleratedStaticBitmapImage> createFromWebGLContextImage(
sk_sp<SkImage>, const gpu::Mailbox&, const gpu::SyncToken&); |
31 | 33 |
32 ~AcceleratedStaticBitmapImage() override; | 34 ~AcceleratedStaticBitmapImage() override; |
33 | 35 |
34 // StaticBitmapImage overrides. | 36 // StaticBitmapImage overrides. |
35 sk_sp<SkImage> imageForCurrentFrame() override; | 37 sk_sp<SkImage> imageForCurrentFrame() override; |
36 void copyToTexture(WebGraphicsContext3DProvider*, GLuint destTextureId, GLen
um destInternalFormat, GLenum destType, bool flipY) override; | 38 void copyToTexture(WebGraphicsContext3DProvider*, GLuint destTextureId, GLen
um destInternalFormat, GLenum destType, bool flipY) override; |
37 | 39 |
| 40 // Image overrides. |
| 41 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
| 42 |
| 43 // To be called on sender thread before performing a transfer |
| 44 void transfer() final; |
| 45 |
38 private: | 46 private: |
39 AcceleratedStaticBitmapImage(sk_sp<SkImage>); | 47 AcceleratedStaticBitmapImage(sk_sp<SkImage>); |
40 AcceleratedStaticBitmapImage(sk_sp<SkImage>, sk_sp<GrContext>, const gpu::Ma
ilbox&, const gpu::SyncToken&); | 48 AcceleratedStaticBitmapImage(sk_sp<SkImage>, const gpu::Mailbox&, const gpu:
:SyncToken&); |
41 | |
42 bool switchStorageToMailbox(WebGraphicsContext3DProvider*); | |
43 GLuint switchStorageToSkImageForWebGL(WebGraphicsContext3DProvider*); | |
44 GLuint switchStorageToSkImage(WebGraphicsContext3DProvider*); | |
45 | 49 |
46 void ensureMailbox(); | 50 void ensureMailbox(); |
| 51 void createImageFromMailboxIfNeeded(); |
| 52 void checkThread(); |
| 53 void waitSyncTokenIfNeeded(); |
| 54 bool isValid(); |
| 55 void releaseImageThreadSafe(); |
| 56 bool imageBelongsToSharedContext(); |
47 | 57 |
48 // True when the |m_image| has a texture id backing it from the shared main
thread context. | 58 // Id of the shared context where m_image was created |
49 bool m_imageIsForSharedMainThreadContext; | 59 unsigned m_sharedContextId; |
50 | |
51 // Keeps the context alive that the SkImage is associated with. Not used if
the SkImage is coming from the shared main | |
52 // thread context as we assume that context is kept alive elsewhere since it
is globally shared in the process. | |
53 sk_sp<GrContext> m_grContext; | |
54 // True when the below mailbox and sync token are valid for getting at the t
exture backing the object's SkImage. | 60 // True when the below mailbox and sync token are valid for getting at the t
exture backing the object's SkImage. |
55 bool m_hasMailbox = false; | 61 bool m_hasMailbox = false; |
56 // A mailbox referring to the texture id backing the SkImage. The mailbox is
valid as long as the SkImage is held alive. | 62 // A mailbox referring to the texture id backing the SkImage. The mailbox is
valid as long as the SkImage is held alive. |
57 gpu::Mailbox m_mailbox; | 63 gpu::Mailbox m_mailbox; |
58 // This token must be waited for before using the mailbox. | 64 // This token must be waited for before using the mailbox. |
59 gpu::SyncToken m_syncToken; | 65 gpu::SyncToken m_syncToken; |
| 66 // Thread that m_image belongs to. Set to null when m_image belong to the sa
me thread |
| 67 // as this AcceleratedStaticBitmapImage. Should only be non-null after a tr
ansfer. |
| 68 WebThread* m_imageThread = nullptr; |
| 69 |
| 70 base::ThreadChecker m_threadChecker; |
| 71 bool m_detachThreadAtNextCheck = false; |
60 }; | 72 }; |
61 | 73 |
62 } // namespace blink | 74 } // namespace blink |
63 | 75 |
64 #endif | 76 #endif |
OLD | NEW |