Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.h

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: deleteTexture in desctructor Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 11
13 #include <memory> 12 #include <memory>
14 13
15 class GrContext; 14 class GrContext;
16 15
17 namespace cc { 16 namespace cc {
18 class SingleReleaseCallback; 17 class SingleReleaseCallback;
19 } 18 }
20 19
20 namespace gpu {
21 namespace gles2 {
22 class GLES2Interface;
23 }
24 }
25
21 namespace blink { 26 namespace blink {
22 class WebThread; 27 class TextureHolder;
23 28
24 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final 29 class PLATFORM_EXPORT AcceleratedStaticBitmapImage final
25 : public StaticBitmapImage { 30 : public StaticBitmapImage {
26 public: 31 public:
27 // SkImage with a texture backing that is assumed to be from the shared 32 // SkImage with a texture backing that is assumed to be from the shared
28 // context of the current thread. 33 // context of the current thread.
29 static PassRefPtr<AcceleratedStaticBitmapImage> createFromSharedContextImage( 34 static PassRefPtr<AcceleratedStaticBitmapImage> createFromSharedContextImage(
30 sk_sp<SkImage>); 35 sk_sp<SkImage>);
31 // Can specify the GrContext that created the texture backing the for the 36 // Can specify the GrContext that created the texture backing. Ideally all
32 // given SkImage. Ideally all callers would use this option. The |mailbox| is 37 // 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 38 // backing, allowing other contexts to use the same backing.
34 // the same backing.
35 static PassRefPtr<AcceleratedStaticBitmapImage> createFromWebGLContextImage( 39 static PassRefPtr<AcceleratedStaticBitmapImage> createFromWebGLContextImage(
36 sk_sp<SkImage>,
37 const gpu::Mailbox&, 40 const gpu::Mailbox&,
38 const gpu::SyncToken&); 41 const gpu::SyncToken&,
42 unsigned textureId,
43 gpu::gles2::GLES2Interface*,
44 IntSize mailboxSize);
39 45
40 ~AcceleratedStaticBitmapImage() override; 46 ~AcceleratedStaticBitmapImage() override;
41 47
48 IntSize size() const override;
42 // StaticBitmapImage overrides. 49 // StaticBitmapImage overrides.
43 sk_sp<SkImage> imageForCurrentFrame() override; 50 sk_sp<SkImage> imageForCurrentFrame() override;
44 void copyToTexture(WebGraphicsContext3DProvider*, 51 void copyToTexture(WebGraphicsContext3DProvider*,
45 GLuint destTextureId, 52 GLuint destTextureId,
46 GLenum destInternalFormat, 53 GLenum destInternalFormat,
47 GLenum destType, 54 GLenum destType,
48 bool flipY) override; 55 bool flipY) override;
49 56
50 // Image overrides. 57 // Image overrides.
51 void draw(SkCanvas*, 58 void draw(SkCanvas*,
52 const SkPaint&, 59 const SkPaint&,
53 const FloatRect& dstRect, 60 const FloatRect& dstRect,
54 const FloatRect& srcRect, 61 const FloatRect& srcRect,
55 RespectImageOrientationEnum, 62 RespectImageOrientationEnum,
56 ImageClampingMode) override; 63 ImageClampingMode) override;
57 64
65 bool isTextureBacked() final { return true; }
66 bool hasMailbox() final { return !m_texture->isSkiaTextureHolder(); }
Justin Novosad 2016/10/28 21:58:41 This is fragile code: it assumes there are only tw
58 // To be called on sender thread before performing a transfer 67 // To be called on sender thread before performing a transfer
59 void transfer() final; 68 void transfer() final;
60 69
61 void ensureMailbox() final; 70 void ensureMailbox() final;
62 gpu::Mailbox getMailbox() final { return m_mailbox; } 71 gpu::Mailbox getMailbox() final { return m_texture->getMailbox(); }
63 gpu::SyncToken getSyncToken() final { return m_syncToken; } 72 gpu::SyncToken getSyncToken() final { return m_texture->getSyncToken(); }
73 void updateSyncToken(gpu::SyncToken) final;
64 74
65 private: 75 private:
66 AcceleratedStaticBitmapImage(sk_sp<SkImage>); 76 AcceleratedStaticBitmapImage(sk_sp<SkImage>);
67 AcceleratedStaticBitmapImage(sk_sp<SkImage>, 77 AcceleratedStaticBitmapImage(const gpu::Mailbox&,
68 const gpu::Mailbox&, 78 const gpu::SyncToken&,
69 const gpu::SyncToken&); 79 unsigned textureId,
80 gpu::gles2::GLES2Interface*,
81 IntSize mailboxSize);
70 82
71 void createImageFromMailboxIfNeeded(); 83 void createImageFromMailboxIfNeeded();
72 void checkThread(); 84 void checkThread();
73 void waitSyncTokenIfNeeded(); 85 void waitSyncTokenIfNeeded();
74 bool isValid(); 86 bool isValid();
75 void releaseImageThreadSafe();
76 bool imageBelongsToSharedContext();
77 87
78 // Id of the shared context where m_image was created 88 TextureHolder* m_texture;
Justin Novosad 2016/10/28 21:58:41 Should call the m_textureHolder for clarity
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 89
93 base::ThreadChecker m_threadChecker; 90 base::ThreadChecker m_threadChecker;
94 bool m_detachThreadAtNextCheck = false; 91 bool m_detachThreadAtNextCheck = false;
95 }; 92 };
96 93
97 } // namespace blink 94 } // namespace blink
98 95
99 #endif 96 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698