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

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

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: Keep a unique_ptr<WebGraphicsContext3DProvider>, otherwise crashes 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/gpu/SharedGpuContext.h"
11 #include "public/platform/Platform.h"
12 #include "skia/ext/texture_handle.h"
13 #include "third_party/skia/include/gpu/GrContext.h"
14
15 namespace blink {
16
17 namespace {
18
19 void releaseTexture(
20 bool isConvertedFromSkiaTexture,
21 unsigned textureId,
22 WeakPtr<WebGraphicsContext3DProviderWrapper> contextProvider,
23 std::unique_ptr<gpu::SyncToken> syncToken) {
24 if (!isConvertedFromSkiaTexture && textureId && contextProvider) {
25 contextProvider->contextProvider()->contextGL()->WaitSyncTokenCHROMIUM(
26 syncToken->GetData());
27 contextProvider->contextProvider()->contextGL()->DeleteTextures(1,
28 &textureId);
29 }
30 }
31
32 } // namespace
33
34 MailboxTextureHolder::MailboxTextureHolder(
35 const gpu::Mailbox& mailbox,
36 const gpu::SyncToken& syncToken,
37 unsigned textureIdToDeleteAfterMailboxConsumed,
38 WeakPtr<WebGraphicsContext3DProviderWrapper> contextProvider,
39 IntSize mailboxSize)
40 : m_mailbox(mailbox),
41 m_syncToken(syncToken),
42 m_textureId(textureIdToDeleteAfterMailboxConsumed),
43 m_contextProvider(contextProvider),
44 m_size(mailboxSize),
45 m_isConvertedFromSkiaTexture(false) {}
46
47 MailboxTextureHolder::MailboxTextureHolder(
48 std::unique_ptr<TextureHolder> textureHolder) {
49 DCHECK(textureHolder->isSkiaTextureHolder());
50 sk_sp<SkImage> image = textureHolder->skImage();
51 DCHECK(image);
52
53 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl();
54 GrContext* sharedGrContext = SharedGpuContext::gr();
55 if (!sharedGrContext) {
56 // Can happen if the context is lost. The SkImage won't be any good now
57 // anyway.
58 return;
59 }
60 GLuint imageTextureId =
61 skia::GrBackendObjectToGrGLTextureInfo(image->getTextureHandle(true))
62 ->fID;
63 sharedGL->BindTexture(GL_TEXTURE_2D, imageTextureId);
64
65 sharedGL->GenMailboxCHROMIUM(m_mailbox.name);
66 sharedGL->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name);
67 const GLuint64 fenceSync = sharedGL->InsertFenceSyncCHROMIUM();
68 sharedGL->Flush();
69 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData());
70
71 sharedGL->BindTexture(GL_TEXTURE_2D, 0);
72 // We changed bound textures in this function, so reset the GrContext.
73 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState);
74 m_size = IntSize(image->width(), image->height());
75 m_textureId = imageTextureId;
76 m_isConvertedFromSkiaTexture = true;
77 }
78
79 MailboxTextureHolder::~MailboxTextureHolder() {
80 // Avoid leaking mailboxes in cases where the texture gets recycled by skia.
81 if (SharedGpuContext::isValid()) {
82 SharedGpuContext::gl()->ProduceTextureDirectCHROMIUM(0, GL_TEXTURE_2D,
83 m_mailbox.name);
84 }
85 releaseTextureThreadSafe();
86 }
87
88 void MailboxTextureHolder::releaseTextureThreadSafe() {
89 // If this member is still null, it means we are still at the thread where
90 // the m_texture was created.
91 std::unique_ptr<gpu::SyncToken> passedSyncToken(
92 new gpu::SyncToken(m_syncToken));
93 if (!wasTransferred()) {
94 releaseTexture(m_isConvertedFromSkiaTexture, m_textureId, m_contextProvider,
95 std::move(passedSyncToken));
96 } else if (wasTransferred() && textureThreadTaskRunner()) {
97 textureThreadTaskRunner()->postTask(
98 BLINK_FROM_HERE,
99 crossThreadBind(&releaseTexture, m_isConvertedFromSkiaTexture,
100 m_textureId, passed(std::move(m_contextProvider)),
101 passed(std::move(passedSyncToken))));
102 }
103 m_textureId = 0u; // invalidate the texture.
104 setWasTransferred(false);
105 setTextureThreadTaskRunner(nullptr);
106 }
107
108 unsigned MailboxTextureHolder::sharedContextId() {
109 return SharedGpuContext::kNoSharedContext;
110 }
111
112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698