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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 // We pass a technically-uninitialized canvas to the platform context here since | 63 // We pass a technically-uninitialized canvas to the platform context here since |
64 // the canvas initialization completes in ImageBuffer::ImageBuffer. But | 64 // the canvas initialization completes in ImageBuffer::ImageBuffer. But |
65 // PlatformContext doesn't actually need to use the object, and this makes all | 65 // PlatformContext doesn't actually need to use the object, and this makes all |
66 // the ownership easier to manage. | 66 // the ownership easier to manage. |
67 ImageBufferData::ImageBufferData(const IntSize& size) | 67 ImageBufferData::ImageBufferData(const IntSize& size) |
68 : m_platformContext(0) // Canvas is set in ImageBuffer constructor. | 68 : m_platformContext(0) // Canvas is set in ImageBuffer constructor. |
69 { | 69 { |
70 } | 70 } |
71 | 71 |
72 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d ata) | 72 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d ata, OpacityMode opacityMode) |
73 { | 73 { |
74 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 74 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
75 if (!context3D) | 75 if (!context3D) |
76 return 0; | 76 return 0; |
77 GrContext* gr = context3D->grContext(); | 77 GrContext* gr = context3D->grContext(); |
78 if (!gr) | 78 if (!gr) |
79 return 0; | 79 return 0; |
80 gr->resetContext(); | 80 gr->resetContext(); |
81 GrTextureDesc desc; | 81 GrTextureDesc desc; |
82 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 82 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
83 desc.fSampleCnt = 0; | 83 desc.fSampleCnt = 0; |
84 desc.fWidth = size.width(); | 84 desc.fWidth = size.width(); |
85 desc.fHeight = size.height(); | 85 desc.fHeight = size.height(); |
86 desc.fConfig = kSkia8888_GrPixelConfig; | 86 desc.fConfig = kSkia8888_GrPixelConfig; |
87 SkAutoTUnref<GrTexture> texture(gr->createUncachedTexture(desc, 0, 0)); | 87 SkAutoTUnref<GrTexture> texture(gr->createUncachedTexture(desc, 0, 0)); |
88 if (!texture.get()) | 88 if (!texture.get()) |
89 return 0; | 89 return 0; |
90 SkCanvas* canvas; | 90 SkCanvas* canvas; |
91 SkAutoTUnref<SkDevice> device(new SkGpuDevice(gr, texture.get())); | 91 SkAutoTUnref<SkDevice> device(new SkGpuDevice(gr, texture.get())); |
92 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | |
92 Canvas2DLayerBridge::ThreadMode threadMode = WebKit::Platform::current()->is ThreadedCompositingEnabled() ? Canvas2DLayerBridge::Threaded : Canvas2DLayerBrid ge::SingleThread; | 93 Canvas2DLayerBridge::ThreadMode threadMode = WebKit::Platform::current()->is ThreadedCompositingEnabled() ? Canvas2DLayerBridge::Threaded : Canvas2DLayerBrid ge::SingleThread; |
93 data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), size, threadMode, texture.get()->getTextureHandle()); | 94 data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bridgeOpacityMode, threadMode, texture.get()->getTextureHandle()); |
94 canvas = data->m_layerBridge->skCanvas(device.get()); | 95 canvas = data->m_layerBridge->skCanvas(device.get()); |
95 data->m_platformContext.setAccelerated(true); | 96 data->m_platformContext.setAccelerated(true); |
96 return canvas; | 97 return canvas; |
97 } | 98 } |
98 | 99 |
99 static SkCanvas* createNonPlatformCanvas(const IntSize& size) | 100 static SkCanvas* createNonPlatformCanvas(const IntSize& size) |
100 { | 101 { |
101 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height())); | 102 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height())); |
102 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 103 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); |
103 return pixelRef ? new SkCanvas(device) : 0; | 104 return pixelRef ? new SkCanvas(device) : 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 138 |
138 m_data.m_canvas = adoptPtr(new SkCanvas(device)); | 139 m_data.m_canvas = adoptPtr(new SkCanvas(device)); |
139 m_data.m_platformContext.setCanvas(m_data.m_canvas.get()); | 140 m_data.m_platformContext.setCanvas(m_data.m_canvas.get()); |
140 m_context = adoptPtr(new GraphicsContext(&m_data.m_platformContext)); | 141 m_context = adoptPtr(new GraphicsContext(&m_data.m_platformContext)); |
141 m_context->setShouldSmoothFonts(false); | 142 m_context->setShouldSmoothFonts(false); |
142 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); | 143 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); |
143 | 144 |
144 success = true; | 145 success = true; |
145 } | 146 } |
146 | 147 |
147 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, ColorSpace, RenderingMode renderingMode, bool& success) | 148 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, ColorSpace, RenderingMode renderingMode, OpacityMode opacityMode, bool& success) |
148 : m_data(size) | 149 : m_data(size) |
149 , m_size(size) | 150 , m_size(size) |
150 , m_logicalSize(size) | 151 , m_logicalSize(size) |
151 , m_resolutionScale(resolutionScale) | 152 , m_resolutionScale(resolutionScale) |
152 { | 153 { |
153 OwnPtr<SkCanvas> canvas; | 154 OwnPtr<SkCanvas> canvas; |
154 | 155 |
155 if (renderingMode == Accelerated) | 156 if (renderingMode == Accelerated) |
156 canvas = adoptPtr(createAcceleratedCanvas(size, &m_data)); | 157 canvas = adoptPtr(createAcceleratedCanvas(size, &m_data, opacityMode)); |
157 else if (renderingMode == UnacceleratedNonPlatformBuffer) | 158 else if (renderingMode == UnacceleratedNonPlatformBuffer) |
158 canvas = adoptPtr(createNonPlatformCanvas(size)); | 159 canvas = adoptPtr(createNonPlatformCanvas(size)); |
159 | 160 |
160 if (!canvas) | 161 if (!canvas) |
161 canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height( ), false)); | 162 canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height( ), false)); |
162 | 163 |
163 if (!canvas) { | 164 if (!canvas) { |
164 success = false; | 165 success = false; |
165 return; | 166 return; |
166 } | 167 } |
167 | 168 |
168 m_data.m_canvas = canvas.release(); | 169 m_data.m_canvas = canvas.release(); |
169 m_data.m_platformContext.setCanvas(m_data.m_canvas.get()); | 170 m_data.m_platformContext.setCanvas(m_data.m_canvas.get()); |
170 m_context = adoptPtr(new GraphicsContext(&m_data.m_platformContext)); | 171 m_context = adoptPtr(new GraphicsContext(&m_data.m_platformContext)); |
171 m_context->setShouldSmoothFonts(false); | 172 m_context->setShouldSmoothFonts(opacityMode == Opaque); |
jamesr
2013/04/26 18:30:09
is this a sufficient check? what about transforms,
| |
172 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); | 173 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); |
173 | 174 |
174 // Make the background transparent. It would be nice if this wasn't | 175 // Clear the background transparent or opaque, as required. It would be nice if this wasn't |
175 // required, but the canvas is currently filled with the magic transparency | 176 // required, but the canvas is currently filled with the magic transparency |
176 // color. Can we have another way to manage this? | 177 // color. Can we have another way to manage this? |
177 m_data.m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); | 178 if (opacityMode == Opaque) |
179 m_data.m_canvas->drawARGB(255, 0, 0, 0, SkXfermode::kSrc_Mode); | |
180 else | |
181 m_data.m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); | |
178 | 182 |
179 success = true; | 183 success = true; |
180 } | 184 } |
181 | 185 |
182 ImageBuffer::~ImageBuffer() | 186 ImageBuffer::~ImageBuffer() |
183 { | 187 { |
184 } | 188 } |
185 | 189 |
186 GraphicsContext* ImageBuffer::context() const | 190 GraphicsContext* ImageBuffer::context() const |
187 { | 191 { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 442 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
439 return "data:,"; | 443 return "data:,"; |
440 | 444 |
441 Vector<char> base64Data; | 445 Vector<char> base64Data; |
442 base64Encode(encodedImage, base64Data); | 446 base64Encode(encodedImage, base64Data); |
443 | 447 |
444 return "data:" + mimeType + ";base64," + base64Data; | 448 return "data:" + mimeType + ";base64," + base64Data; |
445 } | 449 } |
446 | 450 |
447 } // namespace WebCore | 451 } // namespace WebCore |
OLD | NEW |