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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 // We pass a technically-uninitialized canvas to the platform context here since | 64 // We pass a technically-uninitialized canvas to the platform context here since |
65 // the canvas initialization completes in ImageBuffer::ImageBuffer. But | 65 // the canvas initialization completes in ImageBuffer::ImageBuffer. But |
66 // PlatformContext doesn't actually need to use the object, and this makes all | 66 // PlatformContext doesn't actually need to use the object, and this makes all |
67 // the ownership easier to manage. | 67 // the ownership easier to manage. |
68 ImageBufferData::ImageBufferData(const IntSize& size) | 68 ImageBufferData::ImageBufferData(const IntSize& size) |
69 : m_platformContext(0) // Canvas is set in ImageBuffer constructor. | 69 : m_platformContext(0) // Canvas is set in ImageBuffer constructor. |
70 { | 70 { |
71 } | 71 } |
72 | 72 |
73 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d
ata) | 73 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d
ata, OpacityMode opacityMode) |
74 { | 74 { |
75 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 75 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
76 if (!context3D) | 76 if (!context3D) |
77 return 0; | 77 return 0; |
78 GrContext* gr = context3D->grContext(); | 78 GrContext* gr = context3D->grContext(); |
79 if (!gr) | 79 if (!gr) |
80 return 0; | 80 return 0; |
81 gr->resetContext(); | 81 gr->resetContext(); |
| 82 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; |
82 Canvas2DLayerBridge::ThreadMode threadMode = WebKit::Platform::current()->is
ThreadedCompositingEnabled() ? Canvas2DLayerBridge::Threaded : Canvas2DLayerBrid
ge::SingleThread; | 83 Canvas2DLayerBridge::ThreadMode threadMode = WebKit::Platform::current()->is
ThreadedCompositingEnabled() ? Canvas2DLayerBridge::Threaded : Canvas2DLayerBrid
ge::SingleThread; |
83 SkImage::Info info; | 84 SkImage::Info info; |
84 info.fWidth = size.width(); | 85 info.fWidth = size.width(); |
85 info.fHeight = size.height(); | 86 info.fHeight = size.height(); |
86 info.fColorType = SkImage::kPMColor_ColorType; | 87 info.fColorType = SkImage::kPMColor_ColorType; |
87 info.fAlphaType = SkImage::kPremul_AlphaType; | 88 info.fAlphaType = SkImage::kPremul_AlphaType; |
88 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context3D->grCont
ext(), info)); | 89 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context3D->grCont
ext(), info)); |
89 if (!surface.get()) | 90 if (!surface.get()) |
90 return 0; | 91 return 0; |
91 SkDeferredCanvas* canvas = new SkDeferredCanvas(surface.get()); | 92 SkDeferredCanvas* canvas = new SkDeferredCanvas(surface.get()); |
92 data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), canva
s, threadMode); | 93 data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), canva
s, bridgeOpacityMode, threadMode); |
93 // If canvas buffer allocation failed, debug build will have asserted | 94 // If canvas buffer allocation failed, debug build will have asserted |
94 // For release builds, we must verify whether the device has a render target | 95 // For release builds, we must verify whether the device has a render target |
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(); |
(...skipping 34 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); |
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 |