Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/StaticBitmapImage.h" | 5 #include "platform/graphics/StaticBitmapImage.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 7 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 8 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "public/platform/Platform.h" | |
| 11 #include "public/platform/WebGraphicsContext3DProvider.h" | |
| 12 #include "skia/ext/texture_handle.h" | |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkImage.h" | 14 #include "third_party/skia/include/core/SkImage.h" |
| 11 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 12 #include "third_party/skia/include/core/SkShader.h" | 16 #include "third_party/skia/include/core/SkShader.h" |
| 13 | 17 |
| 14 namespace blink { | 18 namespace blink { |
| 15 | 19 |
| 16 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag e) | 20 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag e) |
| 17 { | 21 { |
| 18 if (!image) | 22 if (!image) |
| 19 return nullptr; | 23 return nullptr; |
| 20 return adoptRef(new StaticBitmapImage(image)); | 24 return adoptRef(new StaticBitmapImage(image)); |
| 21 } | 25 } |
| 22 | 26 |
| 27 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(WebExternalTextureMailbo x& mailbox) | |
| 28 { | |
| 29 return adoptRef(new StaticBitmapImage(mailbox)); | |
| 30 } | |
| 31 | |
| 23 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image) | 32 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image) |
| 24 { | 33 { |
| 25 ASSERT(m_image); | 34 ASSERT(m_image); |
| 26 } | 35 } |
| 27 | 36 |
| 37 StaticBitmapImage::StaticBitmapImage(WebExternalTextureMailbox& mailbox) : m_mai lbox(mailbox) | |
| 38 { | |
| 39 } | |
| 40 | |
| 28 StaticBitmapImage::~StaticBitmapImage() { } | 41 StaticBitmapImage::~StaticBitmapImage() { } |
| 29 | 42 |
| 30 IntSize StaticBitmapImage::size() const | 43 IntSize StaticBitmapImage::size() const |
| 31 { | 44 { |
| 32 return IntSize(m_image->width(), m_image->height()); | 45 return IntSize(m_image->width(), m_image->height()); |
| 33 } | 46 } |
| 34 | 47 |
| 35 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) | 48 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) |
| 36 { | 49 { |
| 37 return m_image->isOpaque(); | 50 return m_image->isOpaque(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 48 | 61 |
| 49 canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint, | 62 canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint, |
| 50 WebCoreClampingModeToSkiaRectConstraint(clampMode)); | 63 WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
| 51 | 64 |
| 52 if (ImageObserver* observer = getImageObserver()) | 65 if (ImageObserver* observer = getImageObserver()) |
| 53 observer->didDraw(this); | 66 observer->didDraw(this); |
| 54 } | 67 } |
| 55 | 68 |
| 56 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() | 69 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() |
| 57 { | 70 { |
| 71 if (m_image) | |
| 72 return m_image; | |
| 73 DCHECK(isMainThread()); | |
| 74 // In the place when we consume an ImageBitmap that is gpu texture backed, | |
| 75 // create a new SkImage from that texture. | |
| 76 // TODO(xidachen): make this work on a worker thread. | |
| 77 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createSharedOffscreenGraphicsContext3DProvider()); | |
| 78 if (!provider) | |
| 79 return nullptr; | |
| 80 GrContext* grContext = provider->grContext(); | |
| 81 if (!grContext) | |
| 82 return nullptr; | |
| 83 gpu::gles2::GLES2Interface* gl = provider->contextGL(); | |
| 84 if (!gl) | |
| 85 return nullptr; | |
| 86 gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken); | |
| 87 GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mail box.name); | |
| 88 GrGLTextureInfo textureInfo; | |
| 89 textureInfo.fTarget = GL_TEXTURE_2D; | |
| 90 textureInfo.fID = textureId; | |
| 91 GrBackendTextureDesc backendTexture; | |
| 92 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 93 backendTexture.fWidth = m_mailbox.textureSize.width; | |
| 94 backendTexture.fHeight = m_mailbox.textureSize.height; | |
| 95 backendTexture.fConfig = kSkia8888_GrPixelConfig; | |
| 96 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu reInfo); | |
| 97 sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendT exture); | |
| 98 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
| |
| 58 return m_image; | 99 return m_image; |
| 59 } | 100 } |
| 60 | 101 |
| 61 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |