OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "third_party/skia/include/gpu/GrContext.h" | 56 #include "third_party/skia/include/gpu/GrContext.h" |
57 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 57 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
58 #include "wtf/MathExtras.h" | 58 #include "wtf/MathExtras.h" |
59 #include "wtf/text/Base64.h" | 59 #include "wtf/text/Base64.h" |
60 #include "wtf/text/WTFString.h" | 60 #include "wtf/text/WTFString.h" |
61 | 61 |
62 using namespace std; | 62 using namespace std; |
63 | 63 |
64 namespace WebCore { | 64 namespace WebCore { |
65 | 65 |
66 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay
erBridge>* outLayerBridge, OpacityMode opacityMode) | 66 SkCanvas* ImageBuffer::createAcceleratedCanvas(const IntSize& size, OwnPtr<Canva
s2DLayerBridge>* outLayerBridge, OpacityMode opacityMode) |
67 { | 67 { |
68 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 68 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
69 if (!context3D) | 69 if (!context3D) |
70 return 0; | 70 return 0; |
71 GrContext* gr = context3D->grContext(); | 71 GrContext* gr = context3D->grContext(); |
72 if (!gr) | 72 if (!gr) |
73 return 0; | 73 return 0; |
74 gr->resetContext(); | 74 gr->resetContext(); |
75 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | 75 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; |
76 SkImage::Info info; | 76 SkImage::Info info; |
77 info.fWidth = size.width(); | 77 info.fWidth = size.width(); |
78 info.fHeight = size.height(); | 78 info.fHeight = size.height(); |
79 info.fColorType = SkImage::kPMColor_ColorType; | 79 info.fColorType = SkImage::kPMColor_ColorType; |
80 info.fAlphaType = SkImage::kPremul_AlphaType; | 80 info.fAlphaType = SkImage::kPremul_AlphaType; |
81 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context3D->grCont
ext(), info)); | 81 m_surface = adoptRef(SkSurface::NewRenderTarget(context3D->grContext(), info
)); |
82 if (!surface.get()) | 82 if (!m_surface.get()) |
83 return 0; | 83 return 0; |
84 SkDeferredCanvas* canvas = new SkDeferredCanvas(surface.get()); | 84 SkDeferredCanvas* canvas = new SkDeferredCanvas(m_surface.get()); |
85 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), canvas, b
ridgeOpacityMode); | 85 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), canvas, b
ridgeOpacityMode); |
86 // If canvas buffer allocation failed, debug build will have asserted | 86 // If canvas buffer allocation failed, debug build will have asserted |
87 // For release builds, we must verify whether the device has a render target | 87 // For release builds, we must verify whether the device has a render target |
88 return canvas; | 88 return canvas; |
89 } | 89 } |
90 | 90 |
91 static SkCanvas* createNonPlatformCanvas(const IntSize& size) | 91 SkCanvas* ImageBuffer::createNonPlatformCanvas(const IntSize& size) |
92 { | 92 { |
93 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size
.width(), size.height())); | 93 SkImage::Info info; |
94 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 94 info.fWidth = size.width(); |
95 return pixelRef ? new SkCanvas(device) : 0; | 95 info.fHeight = size.height(); |
| 96 info.fColorType = SkImage::kPMColor_ColorType; |
| 97 info.fAlphaType = SkImage::kPremul_AlphaType; |
| 98 m_surface = SkSurface::NewRaster(info); |
| 99 if (!m_surface.get()) |
| 100 return 0; |
| 101 SkCanvas* canvas = m_surface->getCanvas(); |
| 102 return canvas; |
96 } | 103 } |
97 | 104 |
98 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size,
float resolutionScale, const GraphicsContext* context, bool hasAlpha) | 105 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size,
float resolutionScale, const GraphicsContext* context, bool hasAlpha) |
99 { | 106 { |
100 bool success = false; | 107 bool success = false; |
101 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co
ntext, hasAlpha, success)); | 108 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co
ntext, hasAlpha, success)); |
102 if (!success) | 109 if (!success) |
103 return nullptr; | 110 return nullptr; |
104 return buf.release(); | 111 return buf.release(); |
105 } | 112 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 195 |
189 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) | 196 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) |
190 { | 197 { |
191 SkBitmap tmp; | 198 SkBitmap tmp; |
192 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) | 199 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) |
193 bitmap.copyTo(&tmp, bitmap.config()); | 200 bitmap.copyTo(&tmp, bitmap.config()); |
194 | 201 |
195 return tmp; | 202 return tmp; |
196 } | 203 } |
197 | 204 |
| 205 SkImage* ImageBuffer::imageSnapshot() const |
| 206 { |
| 207 if (!m_surface.get()) |
| 208 return 0; |
| 209 return m_surface->newImageSnapshot(); |
| 210 } |
| 211 |
198 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBeh
avior) const | 212 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBeh
avior) const |
199 { | 213 { |
200 const SkBitmap& bitmap = *context()->bitmap(); | 214 const SkBitmap& bitmap = *context()->bitmap(); |
201 // FIXME: Start honoring ScaleBehavior to scale 2x buffers down to 1x. | 215 // FIXME: Start honoring ScaleBehavior to scale 2x buffers down to 1x. |
202 return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBacki
ngStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); | 216 return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBacki
ngStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); |
203 } | 217 } |
204 | 218 |
205 BackingStoreCopy ImageBuffer::fastCopyImageMode() | 219 BackingStoreCopy ImageBuffer::fastCopyImageMode() |
206 { | 220 { |
207 return DontCopyBackingStore; | 221 return DontCopyBackingStore; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 503 |
490 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 504 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
491 { | 505 { |
492 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 506 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
493 info.addMember(m_canvas, "canvas"); | 507 info.addMember(m_canvas, "canvas"); |
494 info.addMember(m_context, "context"); | 508 info.addMember(m_context, "context"); |
495 info.addMember(m_layerBridge, "layerBridge"); | 509 info.addMember(m_layerBridge, "layerBridge"); |
496 } | 510 } |
497 | 511 |
498 } // namespace WebCore | 512 } // namespace WebCore |
OLD | NEW |