Chromium Code Reviews| Index: Source/core/html/HTMLCanvasElement.cpp |
| diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp |
| index 90b660c4213213862e7b1f0f2ae23e311cf9de09..1bf3459b2655240fa12bddf02f432141a28a5c3c 100644 |
| --- a/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/Source/core/html/HTMLCanvasElement.cpp |
| @@ -43,10 +43,13 @@ |
| #include "core/html/canvas/WebGLRenderingContext.h" |
| #include "core/frame/Frame.h" |
| #include "core/page/Settings.h" |
| +#include "core/platform/graphics/Canvas2DImageBufferSurface.h" |
| #include "core/platform/graphics/GraphicsContextStateSaver.h" |
| #include "core/platform/graphics/ImageBuffer.h" |
| +#include "core/platform/graphics/gpu/NonDrawableAcceleratedImageBufferSurface.h" |
| #include "core/rendering/RenderHTMLCanvas.h" |
| #include "platform/MIMETypeRegistry.h" |
| +#include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| #include "public/platform/Platform.h" |
| namespace WebCore { |
| @@ -432,6 +435,30 @@ bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const |
| return true; |
| } |
| +PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount) |
| +{ |
| + OwnPtr<ImageBufferSurface> surface; |
| + OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; |
| + *msaaSampleCount = 0; |
| + if (is3D()) { |
| + // Note: No MSAA for 3D canvases because the image buffer is only used for capturing contents. |
| + // The actual rendering happens in DrawingBuffer. |
| + surface = adoptPtr(new NonDrawableAcceleratedImageBufferSurface(size(), opacityMode, m_deviceScaleFactor)); |
| + } else { |
| + if (shouldAccelerate(deviceSize)) { |
| + if (document().settings()) |
| + *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleCount(); |
| + surface = adoptPtr(new Canvas2DImageBufferSurface(size(), opacityMode, m_deviceScaleFactor, *msaaSampleCount)); |
| + } |
| + |
| + if (!surface || !surface->isValid()) { |
| + surface = adoptPtr(new UnacceleratedImageBufferSurface(size(), opacityMode, m_deviceScaleFactor)); |
|
Stephen White
2013/12/04 21:18:40
I'd prefer a Create() method on the surface subcla
|
| + } |
| + } |
| + |
| + return surface.release(); |
| +} |
| + |
| void HTMLCanvasElement::createImageBuffer() |
| { |
| ASSERT(!m_imageBuffer); |
| @@ -449,15 +476,15 @@ void HTMLCanvasElement::createImageBuffer() |
| if (!deviceSize.width() || !deviceSize.height()) |
| return; |
| - RenderingMode renderingMode = is3D() ? TextureBacked : (shouldAccelerate(deviceSize) ? Accelerated : UnacceleratedNonPlatformBuffer); |
| - int msaaSampleCount = 0; |
| - if (document().settings()) |
| - msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleCount(); |
| - OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; |
| - m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, renderingMode, opacityMode, msaaSampleCount); |
| - if (!m_imageBuffer) |
| + int msaaSampleCount; |
| + OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(deviceSize, &msaaSampleCount); |
| + if (!surface || !surface->isValid()) |
| return; |
| + |
| m_didFailToCreateImageBuffer = false; |
| + |
| + m_imageBuffer = adoptPtr(new ImageBuffer(surface.release())); |
| + |
| setExternallyAllocatedMemory(4 * width() * height()); |
| m_imageBuffer->context()->setShouldClampToSourceRect(false); |
| m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQuality); |