Index: third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h |
diff --git a/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h |
index a45db448f88088283da39340d67a7ef67803c5fc..6615266340b36759ed191d8a9882f843a768741f 100644 |
--- a/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h |
+++ b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h |
@@ -5,6 +5,7 @@ |
#ifndef AcceleratedStaticBitmapImage_h |
#define AcceleratedStaticBitmapImage_h |
+#include "base/threading/thread_checker.h" |
#include "gpu/command_buffer/common/mailbox.h" |
#include "gpu/command_buffer/common/sync_token.h" |
#include "platform/geometry/IntSize.h" |
@@ -19,14 +20,15 @@ class SingleReleaseCallback; |
} |
namespace blink { |
+class WebThread; |
class PLATFORM_EXPORT AcceleratedStaticBitmapImage final : public StaticBitmapImage { |
public: |
- // SkImage with a texture backing that is assumed to be from the shared main thread context. |
+ // SkImage with a texture backing that is assumed to be from the shared context of the current thread. |
static PassRefPtr<AcceleratedStaticBitmapImage> create(PassRefPtr<SkImage>); |
// Can specify the GrContext that created the texture backing the for the given SkImage. Ideally all callers would use this option. |
// The |mailbox| is a name for the texture backing the SkImage, allowing other contexts to use the same backing. |
- static PassRefPtr<AcceleratedStaticBitmapImage> create(PassRefPtr<SkImage>, sk_sp<GrContext>, const gpu::Mailbox&, const gpu::SyncToken&); |
+ static PassRefPtr<AcceleratedStaticBitmapImage> create(PassRefPtr<SkImage>, GrContext*, const gpu::Mailbox&, const gpu::SyncToken&); |
~AcceleratedStaticBitmapImage() override; |
@@ -34,28 +36,39 @@ public: |
PassRefPtr<SkImage> imageForCurrentFrame() override; |
void copyToTexture(WebGraphicsContext3DProvider*, GLuint destTextureId, GLenum destInternalFormat, GLenum destType, bool flipY) override; |
-private: |
- AcceleratedStaticBitmapImage(PassRefPtr<SkImage>); |
- AcceleratedStaticBitmapImage(PassRefPtr<SkImage>, sk_sp<GrContext>, const gpu::Mailbox&, const gpu::SyncToken&); |
+ // Image overrides. |
+ void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
- bool switchStorageToMailbox(WebGraphicsContext3DProvider*); |
- GLuint switchStorageToSkImageForWebGL(WebGraphicsContext3DProvider*); |
- GLuint switchStorageToSkImage(WebGraphicsContext3DProvider*); |
- void ensureMailbox(); |
+ // To be called on sender thread before performing a transfer |
+ void transfer() final; |
- // True when the |m_image| has a texture id backing it from the shared main thread context. |
- bool m_imageIsForSharedMainThreadContext; |
+private: |
+ AcceleratedStaticBitmapImage(PassRefPtr<SkImage>); |
+ AcceleratedStaticBitmapImage(PassRefPtr<SkImage>, GrContext*, const gpu::Mailbox&, const gpu::SyncToken&); |
- // Keeps the context alive that the SkImage is associated with. Not used if the SkImage is coming from the shared main |
- // thread context as we assume that context is kept alive elsewhere since it is globally shared in the process. |
- sk_sp<GrContext> m_grContext; |
+ void ensureMailbox(); |
+ void createImageFromMailboxIfNeeded(); |
+ void checkThread(); |
+ void waitSyncTokenIfNeeded(); |
+ bool isValid(); |
+ void releaseImageThreadSafe(); |
+ bool imageBelongsToSharedContext(); |
+ |
+ // Id of the shared context where m_image was created |
+ unsigned m_sharedContextId; |
// True when the below mailbox and sync token are valid for getting at the texture backing the object's SkImage. |
bool m_hasMailbox = false; |
// A mailbox referring to the texture id backing the SkImage. The mailbox is valid as long as the SkImage is held alive. |
gpu::Mailbox m_mailbox; |
// This token must be waited for before using the mailbox. |
gpu::SyncToken m_syncToken; |
+ // Thread that m_image belongs to. Set to null when m_image belong to the same thread |
+ // as this AcceleratedStaticBitmapImage. Should only be non-null after a transfer. |
+ WebThread* m_imageThread = nullptr; |
+ |
+ base::ThreadChecker m_threadChecker; |
+ bool m_detachThreadAtNextCheck = false; |
}; |
} // namespace blink |