Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/graphics/gpu/SharedGpuContext.h" | |
| 9 #include "public/platform/Platform.h" | |
| 10 #include "skia/ext/texture_handle.h" | |
| 11 #include "third_party/skia/include/gpu/GrContext.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 MailboxTextureHolder::MailboxTextureHolder(const gpu::Mailbox& mailbox, | |
| 16 const gpu::SyncToken& syncToken, | |
| 17 unsigned textureId, | |
| 18 gpu::gles2::GLES2Interface* gl, | |
| 19 IntSize mailboxSize) | |
| 20 : m_mailbox(mailbox), | |
| 21 m_syncToken(syncToken), | |
| 22 m_textureId(textureId), | |
|
Justin Novosad
2016/10/31 16:38:32
Rename this to textureIdToDeleteAfterMailboxConsum
| |
| 23 m_gl(gl), | |
| 24 m_size(mailboxSize) {} | |
| 25 | |
| 26 MailboxTextureHolder::MailboxTextureHolder(sk_sp<SkImage> image) { | |
| 27 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl(); | |
| 28 GrContext* sharedGrContext = SharedGpuContext::gr(); | |
| 29 if (!sharedGrContext) { | |
| 30 // Can happen if the context is lost. The SkImage won't be any good now | |
| 31 // anyway. | |
| 32 return; | |
| 33 } | |
| 34 GLuint imageTextureId = | |
| 35 skia::GrBackendObjectToGrGLTextureInfo(image->getTextureHandle(true)) | |
| 36 ->fID; | |
| 37 sharedGL->BindTexture(GL_TEXTURE_2D, imageTextureId); | |
| 38 | |
| 39 sharedGL->GenMailboxCHROMIUM(m_mailbox.name); | |
| 40 sharedGL->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name); | |
| 41 const GLuint64 fenceSync = sharedGL->InsertFenceSyncCHROMIUM(); | |
| 42 sharedGL->Flush(); | |
| 43 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData()); | |
| 44 | |
| 45 sharedGL->BindTexture(GL_TEXTURE_2D, 0); | |
| 46 // We changed bound textures in this function, so reset the GrContext. | |
| 47 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState); | |
| 48 m_size = IntSize(image->width(), image->height()); | |
| 49 } | |
| 50 | |
| 51 MailboxTextureHolder::~MailboxTextureHolder() { | |
| 52 m_gl->WaitSyncTokenCHROMIUM(m_syncToken.GetData()); | |
| 53 m_gl->DeleteTextures(1, &m_textureId); | |
| 54 } | |
| 55 | |
| 56 WebThread* MailboxTextureHolder::getImageThread() { | |
| 57 return Platform::current()->currentThread(); | |
| 58 } | |
| 59 | |
| 60 unsigned MailboxTextureHolder::sharedContextId() { | |
| 61 return SharedGpuContext::kNoSharedContext; | |
| 62 } | |
| 63 | |
| 64 } // namespace blink | |
| OLD | NEW |