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/SkiaTextureHolder.h" | |
| 9 #include "platform/graphics/gpu/DrawingBuffer.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 MailboxTextureHolder::MailboxTextureHolder( | |
| 18 const gpu::Mailbox& mailbox, | |
| 19 const gpu::SyncToken& syncToken, | |
| 20 unsigned textureIdToDeleteAfterMailboxConsumed, | |
| 21 WeakPtr<DrawingBuffer> drawingBuffer, | |
| 22 IntSize mailboxSize) | |
| 23 : m_mailbox(mailbox), | |
| 24 m_syncToken(syncToken), | |
| 25 m_textureId(textureIdToDeleteAfterMailboxConsumed), | |
| 26 m_drawingBuffer(drawingBuffer), | |
| 27 m_size(mailboxSize), | |
| 28 m_isConvertedFromSkiaTexture(false) {} | |
| 29 | |
| 30 MailboxTextureHolder::MailboxTextureHolder( | |
| 31 std::unique_ptr<TextureHolder> textureHolder) { | |
| 32 DCHECK(textureHolder->isSkiaTextureHolder()); | |
| 33 sk_sp<SkImage> image = textureHolder->skImage(); | |
| 34 DCHECK(image); | |
| 35 | |
| 36 gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl(); | |
| 37 GrContext* sharedGrContext = SharedGpuContext::gr(); | |
| 38 if (!sharedGrContext) { | |
| 39 // Can happen if the context is lost. The SkImage won't be any good now | |
| 40 // anyway. | |
| 41 return; | |
| 42 } | |
| 43 GLuint imageTextureId = | |
| 44 skia::GrBackendObjectToGrGLTextureInfo(image->getTextureHandle(true)) | |
| 45 ->fID; | |
| 46 sharedGL->BindTexture(GL_TEXTURE_2D, imageTextureId); | |
| 47 | |
| 48 sharedGL->GenMailboxCHROMIUM(m_mailbox.name); | |
| 49 sharedGL->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name); | |
| 50 const GLuint64 fenceSync = sharedGL->InsertFenceSyncCHROMIUM(); | |
| 51 sharedGL->Flush(); | |
| 52 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData()); | |
| 53 | |
| 54 sharedGL->BindTexture(GL_TEXTURE_2D, 0); | |
| 55 // We changed bound textures in this function, so reset the GrContext. | |
| 56 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState); | |
| 57 m_size = IntSize(image->width(), image->height()); | |
| 58 m_textureId = imageTextureId; | |
| 59 m_isConvertedFromSkiaTexture = true; | |
| 60 } | |
| 61 | |
| 62 MailboxTextureHolder::~MailboxTextureHolder() { | |
| 63 // Avoid leaking mailboxes in cases where the texture gets recycled by skia. | |
| 64 if (SharedGpuContext::isValid()) { | |
| 65 SharedGpuContext::gl()->ProduceTextureDirectCHROMIUM(0, GL_TEXTURE_2D, | |
| 66 m_mailbox.name); | |
| 67 } | |
| 68 if (m_drawingBuffer && m_textureId && !m_isConvertedFromSkiaTexture) { | |
| 69 m_drawingBuffer->contextGL()->WaitSyncTokenCHROMIUM(m_syncToken.GetData()); | |
| 70 m_drawingBuffer->contextGL()->DeleteTextures(1, &m_textureId); | |
| 71 } else if (m_isConvertedFromSkiaTexture && m_textureId) { | |
| 72 /*gpu::gles2::GLES2Interface* sharedGL = SharedGpuContext::gl(); | |
| 73 sharedGL->WaitSyncTokenCHROMIUM(m_syncToken.GetData()); | |
| 74 sharedGL->DeleteTextures(1, &m_textureId);*/ | |
|
xidachen
2016/11/02 01:28:08
If I un-comment this three lines of code, a lot of
| |
| 75 } | |
| 76 } | |
| 77 | |
| 78 WebThread* MailboxTextureHolder::imageThread() { | |
| 79 return Platform::current()->currentThread(); | |
| 80 } | |
| 81 | |
| 82 unsigned MailboxTextureHolder::sharedContextId() { | |
| 83 return SharedGpuContext::kNoSharedContext; | |
| 84 } | |
| 85 | |
| 86 } // namespace blink | |
| OLD | NEW |