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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/MailboxTextureHolder.cpp

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: No long keep WeakPtr<DrawingBuffer> 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/graphics/MailboxTextureHolder.h"
6
7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "platform/CrossThreadFunctional.h"
9 #include "platform/graphics/SkiaTextureHolder.h"
10 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h"
11 #include "platform/graphics/gpu/SharedGpuContext.h"
12 #include "public/platform/Platform.h"
13 #include "skia/ext/texture_handle.h"
14 #include "third_party/skia/include/gpu/GrContext.h"
15
16 namespace blink {
17
18 MailboxTextureHolder::MailboxTextureHolder(
19 const gpu::Mailbox& mailbox,
20 const gpu::SyncToken& syncToken,
21 unsigned textureIdToDeleteAfterMailboxConsumed,
22 WeakPtr<WebGraphicsContext3DProviderWrapper> contextProvider,
23 IntSize mailboxSize)
24 : m_mailbox(mailbox),
25 m_syncToken(syncToken),
26 m_textureId(textureIdToDeleteAfterMailboxConsumed),
27 m_contextProvider(contextProvider),
28 m_size(mailboxSize),
29 m_isConvertedFromSkiaTexture(false) {}
30
31 MailboxTextureHolder::MailboxTextureHolder(
32 std::unique_ptr<TextureHolder> textureHolder) {
33 DCHECK(textureHolder->isSkiaTextureHolder());
34 sk_sp<SkImage> image = textureHolder->skImage();
35 DCHECK(image);
36
37 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl();
38 GrContext* sharedGrContext = SharedGpuContext::gr();
39 if (!sharedGrContext) {
40 // Can happen if the context is lost. The SkImage won't be any good now
41 // anyway.
42 return;
43 }
44 GLuint imageTextureId =
45 skia::GrBackendObjectToGrGLTextureInfo(image->getTextureHandle(true))
46 ->fID;
47 sharedGL->BindTexture(GL_TEXTURE_2D, imageTextureId);
48
49 sharedGL->GenMailboxCHROMIUM(m_mailbox.name);
50 sharedGL->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name);
51 const GLuint64 fenceSync = sharedGL->InsertFenceSyncCHROMIUM();
52 sharedGL->Flush();
53 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData());
54
55 sharedGL->BindTexture(GL_TEXTURE_2D, 0);
56 // We changed bound textures in this function, so reset the GrContext.
57 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState);
58 m_size = IntSize(image->width(), image->height());
59 m_textureId = imageTextureId;
60 m_isConvertedFromSkiaTexture = true;
61 }
62
63 MailboxTextureHolder::~MailboxTextureHolder() {
64 // Avoid leaking mailboxes in cases where the texture gets recycled by skia.
65 if (SharedGpuContext::isValid()) {
66 SharedGpuContext::gl()->ProduceTextureDirectCHROMIUM(0, GL_TEXTURE_2D,
67 m_mailbox.name);
68 }
69 releaseTextureThreadSafe();
70 }
71
72 static void releaseTexture(
Justin Novosad 2016/11/08 19:38:54 should use unnamed namespace instead of 'static'.
xidachen 2016/11/08 20:30:57 Done.
73 bool isConvertedFromSkiaTexture,
74 unsigned textureId,
75 WeakPtr<WebGraphicsContext3DProviderWrapper> contextProvider,
76 std::unique_ptr<gpu::SyncToken> syncToken) {
Justin Novosad 2016/11/08 19:02:18 Why not just pass sync token by value? It is a POD
77 if (!isConvertedFromSkiaTexture && textureId && contextProvider) {
78 contextProvider->contextProvider()->contextGL()->WaitSyncTokenCHROMIUM(
79 syncToken->GetData());
xidachen 2016/11/08 18:46:07 junov@: it is crashing at syncToken->GetData(). I
80 contextProvider->contextProvider()->contextGL()->DeleteTextures(1,
81 &textureId);
82 }
83 }
84
85 void MailboxTextureHolder::releaseTextureThreadSafe() {
86 // If this member is still null, it means we are still at the thread where
87 // the m_texture was created.
88 std::unique_ptr<gpu::SyncToken> passedSyncToken(
89 new gpu::SyncToken(m_syncToken));
90 if (!m_textureThreadDoNotCall) {
91 releaseTexture(m_isConvertedFromSkiaTexture, m_textureId, m_contextProvider,
92 std::move(passedSyncToken));
xidachen 2016/11/08 19:07:10 Also, I found that if I replace this releaseTextur
93 } else if (m_textureThreadDoNotCall && m_textureThreadTaskRunner) {
94 m_textureThreadTaskRunner->postTask(
95 BLINK_FROM_HERE,
96 crossThreadBind(&releaseTexture, m_isConvertedFromSkiaTexture,
97 m_textureId, passed(std::move(m_contextProvider)),
98 passed(std::move(passedSyncToken))));
xidachen 2016/11/08 19:07:10 we have to do a crossThreadBind to call the releas
99 }
100 m_textureId = 0u; // invalidate the texture.
101 }
102
103 unsigned MailboxTextureHolder::sharedContextId() {
104 return SharedGpuContext::kNoSharedContext;
105 }
106
107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698