Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp b/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp |
| index 0d596995fbf8df72a8cd4bc9efdb6ec61d948881..ac88b3d3d8c066136131b2f7aa9719f45976c96e 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp |
| @@ -4,8 +4,12 @@ |
| #include "platform/graphics/StaticBitmapImage.h" |
| +#include "gpu/command_buffer/client/gles2_interface.h" |
| #include "platform/graphics/GraphicsContext.h" |
| #include "platform/graphics/ImageObserver.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebGraphicsContext3DProvider.h" |
| +#include "skia/ext/texture_handle.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkImage.h" |
| #include "third_party/skia/include/core/SkPaint.h" |
| @@ -20,11 +24,20 @@ PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag |
| return adoptRef(new StaticBitmapImage(image)); |
| } |
| +PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(WebExternalTextureMailbox& mailbox) |
| +{ |
| + return adoptRef(new StaticBitmapImage(mailbox)); |
| +} |
| + |
| StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image) |
| { |
| ASSERT(m_image); |
| } |
| +StaticBitmapImage::StaticBitmapImage(WebExternalTextureMailbox& mailbox) : m_mailbox(mailbox) |
| +{ |
| +} |
| + |
| StaticBitmapImage::~StaticBitmapImage() { } |
| IntSize StaticBitmapImage::size() const |
| @@ -55,6 +68,34 @@ void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const Float |
| PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() |
| { |
| + if (m_image) |
| + return m_image; |
| + DCHECK(isMainThread()); |
| + // In the place when we consume an ImageBitmap that is gpu texture backed, |
| + // create a new SkImage from that texture. |
| + // TODO(xidachen): make this work on a worker thread. |
| + OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| + if (!provider) |
| + return nullptr; |
| + GrContext* grContext = provider->grContext(); |
| + if (!grContext) |
| + return nullptr; |
| + gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
| + if (!gl) |
| + return nullptr; |
| + gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken); |
| + GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name); |
| + GrGLTextureInfo textureInfo; |
| + textureInfo.fTarget = GL_TEXTURE_2D; |
| + textureInfo.fID = textureId; |
| + GrBackendTextureDesc backendTexture; |
| + backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| + backendTexture.fWidth = m_mailbox.textureSize.width; |
| + backendTexture.fHeight = m_mailbox.textureSize.height; |
| + backendTexture.fConfig = kSkia8888_GrPixelConfig; |
| + backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textureInfo); |
| + sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendTexture); |
| + m_image = fromSkSp(skImage); |
|
xidachen
2016/05/19 20:43:51
Here we cache this SkImage, so the next time when
Ken Russell (switch to Gerrit)
2016/05/19 21:38:42
I don't think so. The same ImageBitmap might be co
|
| return m_image; |
| } |