| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/AcceleratedStaticBitmapImage.h" | 5 #include "platform/graphics/AcceleratedStaticBitmapImage.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_interface.h" | 7 #include "gpu/command_buffer/client/gles2_interface.h" |
| 8 #include "gpu/command_buffer/common/sync_token.h" | 8 #include "gpu/command_buffer/common/sync_token.h" |
| 9 #include "platform/graphics/StaticBitmapImage.h" | 9 #include "platform/graphics/StaticBitmapImage.h" |
| 10 #include "platform/graphics/skia/SkiaUtils.h" | 10 #include "platform/graphics/skia/SkiaUtils.h" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebGraphicsContext3DProvider.h" | 12 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 13 #include "skia/ext/texture_handle.h" | 13 #include "skia/ext/texture_handle.h" |
| 14 #include "third_party/skia/include/core/SkImage.h" | 14 #include "third_party/skia/include/core/SkImage.h" |
| 15 #include "third_party/skia/include/gpu/GrContext.h" | 15 #include "third_party/skia/include/gpu/GrContext.h" |
| 16 #include "wtf/PtrUtil.h" | 16 #include "wtf/PtrUtil.h" |
| 17 | 17 |
| 18 #include <memory> | 18 #include <memory> |
| 19 #include <utility> | 19 #include <utility> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(Pa
ssRefPtr<SkImage> image) | 23 PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(sk
_sp<SkImage> image) |
| 24 { | 24 { |
| 25 return adoptRef(new AcceleratedStaticBitmapImage(image)); | 25 return adoptRef(new AcceleratedStaticBitmapImage(std::move(image))); |
| 26 } | 26 } |
| 27 | 27 |
| 28 PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(Pa
ssRefPtr<SkImage> image, sk_sp<GrContext> grContext, const gpu::Mailbox& mailbox
, const gpu::SyncToken& syncToken) | 28 PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(sk
_sp<SkImage> image, sk_sp<GrContext> grContext, const gpu::Mailbox& mailbox, con
st gpu::SyncToken& syncToken) |
| 29 { | 29 { |
| 30 return adoptRef(new AcceleratedStaticBitmapImage(image, std::move(grContext)
, mailbox, syncToken)); | 30 return adoptRef(new AcceleratedStaticBitmapImage(std::move(image), std::move
(grContext), mailbox, syncToken)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(PassRefPtr<SkImage> i
mage) | 33 AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(sk_sp<SkImage> image) |
| 34 : StaticBitmapImage(std::move(image)) | 34 : StaticBitmapImage(std::move(image)) |
| 35 , m_imageIsForSharedMainThreadContext(true) | 35 , m_imageIsForSharedMainThreadContext(true) |
| 36 { | 36 { |
| 37 } | 37 } |
| 38 | 38 |
| 39 AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(PassRefPtr<SkImage> i
mage, sk_sp<GrContext> grContext, const gpu::Mailbox& mailbox, const gpu::SyncTo
ken& syncToken) | 39 AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(sk_sp<SkImage> image,
sk_sp<GrContext> grContext, const gpu::Mailbox& mailbox, const gpu::SyncToken&
syncToken) |
| 40 : StaticBitmapImage(std::move(image)) | 40 : StaticBitmapImage(std::move(image)) |
| 41 , m_imageIsForSharedMainThreadContext(false) // TODO(danakj): Could be true
though, caller would know. | 41 , m_imageIsForSharedMainThreadContext(false) // TODO(danakj): Could be true
though, caller would know. |
| 42 , m_grContext(std::move(grContext)) | 42 , m_grContext(std::move(grContext)) |
| 43 , m_hasMailbox(true) | 43 , m_hasMailbox(true) |
| 44 , m_mailbox(mailbox) | 44 , m_mailbox(mailbox) |
| 45 , m_syncToken(syncToken) | 45 , m_syncToken(syncToken) |
| 46 { | 46 { |
| 47 DCHECK(m_grContext); | 47 DCHECK(m_grContext); |
| 48 } | 48 } |
| 49 | 49 |
| 50 AcceleratedStaticBitmapImage::~AcceleratedStaticBitmapImage() = default; | 50 AcceleratedStaticBitmapImage::~AcceleratedStaticBitmapImage() = default; |
| 51 | 51 |
| 52 void AcceleratedStaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* d
estProvider, GLuint destTextureId, GLenum internalFormat, GLenum destType, bool
flipY) | 52 void AcceleratedStaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* d
estProvider, GLuint destTextureId, GLenum internalFormat, GLenum destType, bool
flipY) |
| 53 { | 53 { |
| 54 // |destProvider| may not be the same context as the one used for |m_image|
so we use a mailbox to | 54 // |destProvider| may not be the same context as the one used for |m_image|
so we use a mailbox to |
| 55 // generate a texture id for |destProvider| to access. | 55 // generate a texture id for |destProvider| to access. |
| 56 ensureMailbox(); | 56 ensureMailbox(); |
| 57 | 57 |
| 58 // Get a texture id that |destProvider| knows about and copy from it. | 58 // Get a texture id that |destProvider| knows about and copy from it. |
| 59 gpu::gles2::GLES2Interface* destGL = destProvider->contextGL(); | 59 gpu::gles2::GLES2Interface* destGL = destProvider->contextGL(); |
| 60 destGL->WaitSyncTokenCHROMIUM(m_syncToken.GetData()); | 60 destGL->WaitSyncTokenCHROMIUM(m_syncToken.GetData()); |
| 61 GLuint sourceTextureId = destGL->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_
2D, m_mailbox.name); | 61 GLuint sourceTextureId = destGL->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_
2D, m_mailbox.name); |
| 62 destGL->CopyTextureCHROMIUM(sourceTextureId, destTextureId, internalFormat,
destType, flipY, false, false); | 62 destGL->CopyTextureCHROMIUM(sourceTextureId, destTextureId, internalFormat,
destType, flipY, false, false); |
| 63 // This drops the |destGL| context's reference on our |m_mailbox|, but it's
still held alive by our SkImage. | 63 // This drops the |destGL| context's reference on our |m_mailbox|, but it's
still held alive by our SkImage. |
| 64 destGL->DeleteTextures(1, &sourceTextureId); | 64 destGL->DeleteTextures(1, &sourceTextureId); |
| 65 } | 65 } |
| 66 | 66 |
| 67 PassRefPtr<SkImage> AcceleratedStaticBitmapImage::imageForCurrentFrame() | 67 sk_sp<SkImage> AcceleratedStaticBitmapImage::imageForCurrentFrame() |
| 68 { | 68 { |
| 69 // This must return an SkImage that can be used with the shared main thread
context. If |m_image| satisfies that, we are done. | 69 // This must return an SkImage that can be used with the shared main thread
context. If |m_image| satisfies that, we are done. |
| 70 if (m_imageIsForSharedMainThreadContext) | 70 if (m_imageIsForSharedMainThreadContext) |
| 71 return m_image; | 71 return m_image; |
| 72 | 72 |
| 73 // TODO(xidachen): make this work on a worker thread. | 73 // TODO(xidachen): make this work on a worker thread. |
| 74 DCHECK(isMainThread()); | 74 DCHECK(isMainThread()); |
| 75 | 75 |
| 76 // If the SkImage came from any other context than the shared main thread on
e, we expect to be given a mailbox at construction. We | 76 // If the SkImage came from any other context than the shared main thread on
e, we expect to be given a mailbox at construction. We |
| 77 // use the mailbox to generate a texture id for the shared main thread conte
xt to use. | 77 // use the mailbox to generate a texture id for the shared main thread conte
xt to use. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 GrGLTextureInfo textureInfo; | 89 GrGLTextureInfo textureInfo; |
| 90 textureInfo.fTarget = GL_TEXTURE_2D; | 90 textureInfo.fTarget = GL_TEXTURE_2D; |
| 91 textureInfo.fID = sharedContextTextureId; | 91 textureInfo.fID = sharedContextTextureId; |
| 92 GrBackendTextureDesc backendTexture; | 92 GrBackendTextureDesc backendTexture; |
| 93 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; | 93 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 94 backendTexture.fWidth = size().width(); | 94 backendTexture.fWidth = size().width(); |
| 95 backendTexture.fHeight = size().height(); | 95 backendTexture.fHeight = size().height(); |
| 96 backendTexture.fConfig = kSkia8888_GrPixelConfig; | 96 backendTexture.fConfig = kSkia8888_GrPixelConfig; |
| 97 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu
reInfo); | 97 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu
reInfo); |
| 98 | 98 |
| 99 m_image = fromSkSp(SkImage::MakeFromAdoptedTexture(sharedGrContext, backendT
exture)); | 99 m_image = SkImage::MakeFromAdoptedTexture(sharedGrContext, backendTexture); |
| 100 m_imageIsForSharedMainThreadContext = true; | 100 m_imageIsForSharedMainThreadContext = true; |
| 101 // Can drop the ref on the GrContext since m_image is now backed by a textur
e from the shared main thread context. | 101 // Can drop the ref on the GrContext since m_image is now backed by a textur
e from the shared main thread context. |
| 102 m_grContext = nullptr; | 102 m_grContext = nullptr; |
| 103 return m_image; | 103 return m_image; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void AcceleratedStaticBitmapImage::ensureMailbox() | 106 void AcceleratedStaticBitmapImage::ensureMailbox() |
| 107 { | 107 { |
| 108 if (m_hasMailbox) | 108 if (m_hasMailbox) |
| 109 return; | 109 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData()); | 127 sharedGL->GenSyncTokenCHROMIUM(fenceSync, m_syncToken.GetData()); |
| 128 | 128 |
| 129 sharedGL->BindTexture(GL_TEXTURE_2D, 0); | 129 sharedGL->BindTexture(GL_TEXTURE_2D, 0); |
| 130 // We changed bound textures in this function, so reset the GrContext. | 130 // We changed bound textures in this function, so reset the GrContext. |
| 131 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState); | 131 sharedGrContext->resetContext(kTextureBinding_GrGLBackendState); |
| 132 | 132 |
| 133 m_hasMailbox = true; | 133 m_hasMailbox = true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |