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