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 23 matching lines...) Expand all Loading... | |
34 #include "core/platform/graphics/ImageBuffer.h" | 34 #include "core/platform/graphics/ImageBuffer.h" |
35 | 35 |
36 #include "core/html/ImageData.h" | 36 #include "core/html/ImageData.h" |
37 #include "core/platform/MIMETypeRegistry.h" | 37 #include "core/platform/MIMETypeRegistry.h" |
38 #include "core/platform/PlatformMemoryInstrumentation.h" | 38 #include "core/platform/PlatformMemoryInstrumentation.h" |
39 #include "core/platform/graphics/BitmapImage.h" | 39 #include "core/platform/graphics/BitmapImage.h" |
40 #include "core/platform/graphics/Extensions3D.h" | 40 #include "core/platform/graphics/Extensions3D.h" |
41 #include "core/platform/graphics/GraphicsContext.h" | 41 #include "core/platform/graphics/GraphicsContext.h" |
42 #include "core/platform/graphics/GraphicsContext3D.h" | 42 #include "core/platform/graphics/GraphicsContext3D.h" |
43 #include "core/platform/graphics/IntRect.h" | 43 #include "core/platform/graphics/IntRect.h" |
44 #include "core/platform/graphics/SkiaImage.h" | |
44 #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h" | 45 #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h" |
45 #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h" | 46 #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h" |
46 #include "core/platform/graphics/skia/MemoryInstrumentationSkia.h" | 47 #include "core/platform/graphics/skia/MemoryInstrumentationSkia.h" |
47 #include "core/platform/graphics/skia/NativeImageSkia.h" | 48 #include "core/platform/graphics/skia/NativeImageSkia.h" |
48 #include "core/platform/graphics/skia/SkiaUtils.h" | 49 #include "core/platform/graphics/skia/SkiaUtils.h" |
49 #include "core/platform/image-encoders/skia/JPEGImageEncoder.h" | 50 #include "core/platform/image-encoders/skia/JPEGImageEncoder.h" |
50 #include "core/platform/image-encoders/skia/PNGImageEncoder.h" | 51 #include "core/platform/image-encoders/skia/PNGImageEncoder.h" |
51 #include "core/platform/image-encoders/skia/WEBPImageEncoder.h" | 52 #include "core/platform/image-encoders/skia/WEBPImageEncoder.h" |
52 #include "public/platform/Platform.h" | 53 #include "public/platform/Platform.h" |
53 #include "skia/ext/platform_canvas.h" | 54 #include "skia/ext/platform_canvas.h" |
54 #include "third_party/skia/include/core/SkColorPriv.h" | 55 #include "third_party/skia/include/core/SkColorPriv.h" |
55 #include "third_party/skia/include/core/SkSurface.h" | 56 #include "third_party/skia/include/core/SkSurface.h" |
56 #include "third_party/skia/include/gpu/GrContext.h" | 57 #include "third_party/skia/include/gpu/GrContext.h" |
57 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 58 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
58 #include "wtf/MathExtras.h" | 59 #include "wtf/MathExtras.h" |
59 #include "wtf/text/Base64.h" | 60 #include "wtf/text/Base64.h" |
60 #include "wtf/text/WTFString.h" | 61 #include "wtf/text/WTFString.h" |
61 | 62 |
62 using namespace std; | 63 using namespace std; |
63 | 64 |
64 namespace WebCore { | 65 namespace WebCore { |
65 | 66 |
66 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay erBridge>* outLayerBridge, OpacityMode opacityMode) | 67 SkCanvas* ImageBuffer::createAcceleratedCanvas(const IntSize& size, OwnPtr<Canva s2DLayerBridge>* outLayerBridge, OpacityMode opacityMode) |
67 { | 68 { |
68 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 69 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
69 if (!context3D) | 70 if (!context3D) |
70 return 0; | 71 return 0; |
71 GrContext* gr = context3D->grContext(); | 72 GrContext* gr = context3D->grContext(); |
72 if (!gr) | 73 if (!gr) |
73 return 0; | 74 return 0; |
74 gr->resetContext(); | 75 gr->resetContext(); |
75 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | 76 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; |
76 SkImage::Info info; | 77 SkImage::Info info; |
77 info.fWidth = size.width(); | 78 info.fWidth = size.width(); |
78 info.fHeight = size.height(); | 79 info.fHeight = size.height(); |
79 info.fColorType = SkImage::kPMColor_ColorType; | 80 info.fColorType = SkImage::kPMColor_ColorType; |
80 info.fAlphaType = SkImage::kPremul_AlphaType; | 81 info.fAlphaType = SkImage::kPremul_AlphaType; |
81 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context3D->grCont ext(), info)); | 82 m_surface = SkSurface::NewRenderTarget(context3D->grContext(), info); |
Justin Novosad
2013/07/22 15:35:41
You will need adoptPtr here, once m_surface is an
| |
82 if (!surface.get()) | 83 if (!m_surface.get()) |
83 return 0; | 84 return 0; |
84 SkDeferredCanvas* canvas = new SkDeferredCanvas(surface.get()); | 85 SkDeferredCanvas* canvas = new SkDeferredCanvas(m_surface.get()); |
85 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), canvas, b ridgeOpacityMode); | 86 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), canvas, b ridgeOpacityMode); |
86 // If canvas buffer allocation failed, debug build will have asserted | 87 // If canvas buffer allocation failed, debug build will have asserted |
87 // For release builds, we must verify whether the device has a render target | 88 // For release builds, we must verify whether the device has a render target |
88 return canvas; | 89 return canvas; |
Justin Novosad
2013/07/22 15:35:41
Now that createAcceleratedCanvas is a member of Im
| |
89 } | 90 } |
90 | 91 |
91 static SkCanvas* createNonPlatformCanvas(const IntSize& size) | 92 SkCanvas* ImageBuffer::createNonPlatformCanvas(const IntSize& size) |
92 { | 93 { |
93 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height())); | 94 SkImage::Info info; |
94 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 95 info.fWidth = size.width(); |
95 return pixelRef ? new SkCanvas(device) : 0; | 96 info.fHeight = size.height(); |
97 info.fColorType = SkImage::kPMColor_ColorType; | |
98 info.fAlphaType = SkImage::kPremul_AlphaType; | |
99 m_surface = SkSurface::NewRaster(info); | |
100 if (!m_surface.get()) | |
101 return 0; | |
102 SkCanvas* canvas = m_surface->getCanvas(); | |
103 return canvas; | |
96 } | 104 } |
97 | 105 |
98 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha) | 106 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha) |
99 { | 107 { |
100 bool success = false; | 108 bool success = false; |
101 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co ntext, hasAlpha, success)); | 109 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co ntext, hasAlpha, success)); |
102 if (!success) | 110 if (!success) |
103 return nullptr; | 111 return nullptr; |
104 return buf.release(); | 112 return buf.release(); |
105 } | 113 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 | 196 |
189 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) | 197 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) |
190 { | 198 { |
191 SkBitmap tmp; | 199 SkBitmap tmp; |
192 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) | 200 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) |
193 bitmap.copyTo(&tmp, bitmap.config()); | 201 bitmap.copyTo(&tmp, bitmap.config()); |
194 | 202 |
195 return tmp; | 203 return tmp; |
196 } | 204 } |
197 | 205 |
206 PassRefPtr<Image> ImageBuffer::imageSnapshot() const | |
207 { | |
208 if (!m_surface.get()) | |
Justin Novosad
2013/07/22 15:35:41
Inside this 'if' you add ASSERT(!m_canvas) With th
| |
209 return 0; | |
210 return SkiaImage::create(m_surface->newImageSnapshot()); | |
211 } | |
212 | |
198 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBeh avior) const | 213 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBeh avior) const |
199 { | 214 { |
200 const SkBitmap& bitmap = *context()->bitmap(); | 215 const SkBitmap& bitmap = *context()->bitmap(); |
201 // FIXME: Start honoring ScaleBehavior to scale 2x buffers down to 1x. | 216 // 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)); | 217 return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBacki ngStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); |
203 } | 218 } |
204 | 219 |
205 BackingStoreCopy ImageBuffer::fastCopyImageMode() | 220 BackingStoreCopy ImageBuffer::fastCopyImageMode() |
206 { | 221 { |
207 return DontCopyBackingStore; | 222 return DontCopyBackingStore; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 | 504 |
490 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 505 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
491 { | 506 { |
492 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 507 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
493 info.addMember(m_canvas, "canvas"); | 508 info.addMember(m_canvas, "canvas"); |
494 info.addMember(m_context, "context"); | 509 info.addMember(m_context, "context"); |
495 info.addMember(m_layerBridge, "layerBridge"); | 510 info.addMember(m_layerBridge, "layerBridge"); |
496 } | 511 } |
497 | 512 |
498 } // namespace WebCore | 513 } // namespace WebCore |
OLD | NEW |