| 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 "gpu/command_buffer/client/gles2_interface.h" |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebGraphicsContext3DProvider.h" | 11 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 12 #include "skia/ext/texture_handle.h" | 12 #include "skia/ext/texture_handle.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.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/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkShader.h" | 16 #include "third_party/skia/include/core/SkShader.h" |
| 17 #include "wtf/PtrUtil.h" |
| 18 #include <memory> |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag
e) | 22 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag
e) |
| 21 { | 23 { |
| 22 if (!image) | 24 if (!image) |
| 23 return nullptr; | 25 return nullptr; |
| 24 return adoptRef(new StaticBitmapImage(image)); | 26 return adoptRef(new StaticBitmapImage(image)); |
| 25 } | 27 } |
| 26 | 28 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 69 } |
| 68 | 70 |
| 69 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() | 71 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() |
| 70 { | 72 { |
| 71 if (m_image) | 73 if (m_image) |
| 72 return m_image; | 74 return m_image; |
| 73 DCHECK(isMainThread()); | 75 DCHECK(isMainThread()); |
| 74 // In the place when we consume an ImageBitmap that is gpu texture backed, | 76 // In the place when we consume an ImageBitmap that is gpu texture backed, |
| 75 // create a new SkImage from that texture. | 77 // create a new SkImage from that texture. |
| 76 // TODO(xidachen): make this work on a worker thread. | 78 // TODO(xidachen): make this work on a worker thread. |
| 77 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 79 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique(Platform
::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| 78 if (!provider) | 80 if (!provider) |
| 79 return nullptr; | 81 return nullptr; |
| 80 GrContext* grContext = provider->grContext(); | 82 GrContext* grContext = provider->grContext(); |
| 81 if (!grContext) | 83 if (!grContext) |
| 82 return nullptr; | 84 return nullptr; |
| 83 gpu::gles2::GLES2Interface* gl = provider->contextGL(); | 85 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
| 84 if (!gl) | 86 if (!gl) |
| 85 return nullptr; | 87 return nullptr; |
| 86 gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken); | 88 gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken); |
| 87 GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mail
box.name); | 89 GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mail
box.name); |
| 88 GrGLTextureInfo textureInfo; | 90 GrGLTextureInfo textureInfo; |
| 89 textureInfo.fTarget = GL_TEXTURE_2D; | 91 textureInfo.fTarget = GL_TEXTURE_2D; |
| 90 textureInfo.fID = textureId; | 92 textureInfo.fID = textureId; |
| 91 GrBackendTextureDesc backendTexture; | 93 GrBackendTextureDesc backendTexture; |
| 92 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; | 94 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 93 backendTexture.fWidth = m_mailbox.textureSize.width; | 95 backendTexture.fWidth = m_mailbox.textureSize.width; |
| 94 backendTexture.fHeight = m_mailbox.textureSize.height; | 96 backendTexture.fHeight = m_mailbox.textureSize.height; |
| 95 backendTexture.fConfig = kSkia8888_GrPixelConfig; | 97 backendTexture.fConfig = kSkia8888_GrPixelConfig; |
| 96 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu
reInfo); | 98 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu
reInfo); |
| 97 sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendT
exture); | 99 sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendT
exture); |
| 98 m_image = fromSkSp(skImage); | 100 m_image = fromSkSp(skImage); |
| 99 return m_image; | 101 return m_image; |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace blink | 104 } // namespace blink |
| OLD | NEW |