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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/SkiaTextureHolder.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/SkiaTextureHolder.h"
6
7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "platform/CrossThreadFunctional.h"
9 #include "platform/graphics/MailboxTextureHolder.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 releaseImage(sk_sp<SkImage>&& image,
20 std::unique_ptr<gpu::SyncToken>&& syncToken) {
21 if (SharedGpuContext::isValid() && syncToken->HasData())
22 SharedGpuContext::gl()->WaitSyncTokenCHROMIUM(syncToken->GetData());
23 image.reset();
24 }
25
26 } // namespace
27
28 SkiaTextureHolder::SkiaTextureHolder(sk_sp<SkImage> image)
29 : m_image(std::move(image)),
30 m_sharedContextId(SharedGpuContext::contextId()) {}
31
32 SkiaTextureHolder::SkiaTextureHolder(
33 std::unique_ptr<TextureHolder> textureHolder) {
34 DCHECK(textureHolder->isMailboxTextureHolder());
35 const gpu::Mailbox mailbox = textureHolder->mailbox();
36 const gpu::SyncToken syncToken = textureHolder->syncToken();
37 const IntSize mailboxSize = textureHolder->size();
38
39 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl();
40 GrContext* sharedGrContext = SharedGpuContext::gr();
41 DCHECK(sharedGL &&
42 sharedGrContext); // context isValid already checked in callers
43
44 sharedGL->WaitSyncTokenCHROMIUM(syncToken.GetConstData());
45 GLuint sharedContextTextureId =
46 sharedGL->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
47 GrGLTextureInfo textureInfo;
48 textureInfo.fTarget = GL_TEXTURE_2D;
49 textureInfo.fID = sharedContextTextureId;
50 GrBackendTextureDesc backendTexture;
51 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin;
52 backendTexture.fWidth = mailboxSize.width();
53 backendTexture.fHeight = mailboxSize.height();
54 backendTexture.fConfig = kSkia8888_GrPixelConfig;
55 backendTexture.fTextureHandle =
56 skia::GrGLTextureInfoToGrBackendObject(textureInfo);
57
58 sk_sp<SkImage> newImage =
59 SkImage::MakeFromAdoptedTexture(sharedGrContext, backendTexture);
60 releaseImageThreadSafe();
61 m_image = newImage;
62 m_sharedContextId = SharedGpuContext::contextId();
63 }
64
65 SkiaTextureHolder::~SkiaTextureHolder() {
66 releaseImageThreadSafe();
67 }
68
69 unsigned SkiaTextureHolder::sharedContextId() {
70 return m_sharedContextId;
71 }
72
73 void SkiaTextureHolder::releaseImageThreadSafe() {
74 // If m_image belongs to a GrContext that is on another thread, it
75 // must be released on that thread.
76 if (textureThreadTaskRunner() && m_image && wasTransferred() &&
77 SharedGpuContext::isValid()) {
78 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl();
79 std::unique_ptr<gpu::SyncToken> releaseSyncToken(new gpu::SyncToken);
80 const GLuint64 fenceSync = sharedGL->InsertFenceSyncCHROMIUM();
81 sharedGL->Flush();
82 sharedGL->GenSyncTokenCHROMIUM(fenceSync, releaseSyncToken->GetData());
83 textureThreadTaskRunner()->postTask(
84 BLINK_FROM_HERE,
85 crossThreadBind(&releaseImage, passed(std::move(m_image)),
86 passed(std::move(releaseSyncToken))));
87 }
88 m_image = nullptr;
89 setWasTransferred(false);
90 setTextureThreadTaskRunner(nullptr);
91 }
92
93 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698