| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 31 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| 32 | 32 |
| 33 #include "platform/graphics/gpu/SharedGpuContext.h" | 33 #include "platform/graphics/gpu/SharedGpuContext.h" |
| 34 #include "platform/graphics/skia/SkiaUtils.h" | 34 #include "platform/graphics/skia/SkiaUtils.h" |
| 35 #include "skia/ext/texture_handle.h" | 35 #include "skia/ext/texture_handle.h" |
| 36 #include "skia/ext/cdl_canvas.h" |
| 36 #include "third_party/skia/include/gpu/GrContext.h" | 37 #include "third_party/skia/include/gpu/GrContext.h" |
| 37 #include "wtf/PtrUtil.h" | 38 #include "wtf/PtrUtil.h" |
| 38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 AcceleratedImageBufferSurface::AcceleratedImageBufferSurface( | 43 AcceleratedImageBufferSurface::AcceleratedImageBufferSurface( |
| 43 const IntSize& size, | 44 const IntSize& size, |
| 44 OpacityMode opacityMode, | 45 OpacityMode opacityMode, |
| 45 sk_sp<SkColorSpace> colorSpace, | 46 sk_sp<SkColorSpace> colorSpace, |
| 46 SkColorType colorType) | 47 SkColorType colorType) |
| 47 : ImageBufferSurface(size, opacityMode, colorSpace, colorType) { | 48 : ImageBufferSurface(size, opacityMode, colorSpace, colorType) { |
| 48 if (!SharedGpuContext::isValid()) | 49 if (!SharedGpuContext::isValid()) |
| 49 return; | 50 return; |
| 50 GrContext* grContext = SharedGpuContext::gr(); | 51 GrContext* grContext = SharedGpuContext::gr(); |
| 51 m_contextId = SharedGpuContext::contextId(); | 52 m_contextId = SharedGpuContext::contextId(); |
| 52 CHECK(grContext); | 53 CHECK(grContext); |
| 53 | 54 |
| 54 SkAlphaType alphaType = | 55 SkAlphaType alphaType = |
| 55 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 56 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 56 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, | 57 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, |
| 57 alphaType, colorSpace); | 58 alphaType, colorSpace); |
| 58 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); | 59 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); |
| 59 m_surface = SkSurface::MakeRenderTarget( | 60 m_surface = SkSurface::MakeRenderTarget( |
| 60 grContext, SkBudgeted::kYes, info, 0 /* sampleCount */, | 61 grContext, SkBudgeted::kYes, info, 0 /* sampleCount */, |
| 61 Opaque == opacityMode ? nullptr : &disableLCDProps); | 62 Opaque == opacityMode ? nullptr : &disableLCDProps); |
| 62 if (!m_surface) | 63 if (!m_surface) |
| 63 return; | 64 return; |
| 65 m_canvas.reset(new CdlPassThroughCanvas(m_surface->getCanvas())); |
| 64 clear(); | 66 clear(); |
| 65 | 67 |
| 66 // Always save an initial frame, to support resetting the top level matrix | 68 // Always save an initial frame, to support resetting the top level matrix |
| 67 // and clip. | 69 // and clip. |
| 68 m_surface->getCanvas()->save(); | 70 canvas()->save(); |
| 69 } | 71 } |
| 70 | 72 |
| 71 bool AcceleratedImageBufferSurface::isValid() const { | 73 bool AcceleratedImageBufferSurface::isValid() const { |
| 72 return m_surface && SharedGpuContext::isValid() && | 74 return m_canvas && SharedGpuContext::isValid() && |
| 73 m_contextId == SharedGpuContext::contextId(); | 75 m_contextId == SharedGpuContext::contextId(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 sk_sp<SkImage> AcceleratedImageBufferSurface::newImageSnapshot(AccelerationHint, | 78 sk_sp<SkImage> AcceleratedImageBufferSurface::newImageSnapshot(AccelerationHint, |
| 77 SnapshotReason) { | 79 SnapshotReason) { |
| 78 return m_surface->makeImageSnapshot(); | 80 return m_surface->makeImageSnapshot(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 GLuint AcceleratedImageBufferSurface::getBackingTextureHandleForOverwrite() { | 83 GLuint AcceleratedImageBufferSurface::getBackingTextureHandleForOverwrite() { |
| 82 if (!m_surface) | 84 if (!m_surface) |
| 83 return 0; | 85 return 0; |
| 84 return skia::GrBackendObjectToGrGLTextureInfo( | 86 return skia::GrBackendObjectToGrGLTextureInfo( |
| 85 m_surface->getTextureHandle( | 87 m_surface->getTextureHandle( |
| 86 SkSurface::kDiscardWrite_TextureHandleAccess)) | 88 SkSurface::kDiscardWrite_TextureHandleAccess)) |
| 87 ->fID; | 89 ->fID; |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace blink | 92 } // namespace blink |
| OLD | NEW |