| Index: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| diff --git a/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp b/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| index fe38ed1904863ae96ab6bf8be0b35c5ec1d39e52..0d901e4241ba66a9bb46d2e3f47a6ab9b05fa2ca 100644
|
| --- a/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| +++ b/third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp
|
| @@ -11,6 +11,8 @@
|
| #include "core/workers/WorkerSettings.h"
|
| #include "platform/graphics/ImageBuffer.h"
|
| #include "platform/graphics/StaticBitmapImage.h"
|
| +#include "platform/graphics/UnacceleratedImageBufferSurface.h"
|
| +#include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
|
| #include "wtf/Assertions.h"
|
|
|
| #define UNIMPLEMENTED ASSERT_NOT_REACHED
|
| @@ -80,12 +82,29 @@ bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const
|
| return !!m_imageBuffer;
|
| }
|
|
|
| +static bool shouldAccelerate(IntSize surfaceSize)
|
| +{
|
| + if (!isMainThread())
|
| + return false; // Add support on Workers crbug.com/
|
| + return RuntimeEnabledFeatures::accelerated2dCanvasEnabled();
|
| +}
|
| +
|
| ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const
|
| {
|
| if (!m_imageBuffer) {
|
| - // TODO: crbug.com/593514 Add support for GPU rendering
|
| + IntSize surfaceSize(width(), height());
|
| + OpacityMode opacityMode = m_hasAlpha ? NonOpaque : Opaque;
|
| + std::unique_ptr<ImageBufferSurface> surface;
|
| + if (shouldAccelerate(surfaceSize)) {
|
| + surface.reset(new AcceleratedImageBufferSurface(surfaceSize, opacityMode));
|
| + }
|
| +
|
| + if (!surface || !surface->isValid()) {
|
| + surface.reset(new UnacceleratedImageBufferSurface(surfaceSize, opacityMode, InitializeImagePixels));
|
| + }
|
| +
|
| OffscreenCanvasRenderingContext2D* nonConstThis = const_cast<OffscreenCanvasRenderingContext2D*>(this);
|
| - nonConstThis->m_imageBuffer = ImageBuffer::create(IntSize(width(), height()), m_hasAlpha ? NonOpaque : Opaque, InitializeImagePixels);
|
| + nonConstThis->m_imageBuffer = ImageBuffer::create(std::move(surface));
|
|
|
| if (m_needsMatrixClipRestore) {
|
| restoreMatrixClipStack(m_imageBuffer->canvas());
|
| @@ -100,8 +119,8 @@ ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS
|
| {
|
| if (!imageBuffer())
|
| return nullptr;
|
| - // TODO: crbug.com/593514 Add support for GPU rendering
|
| - RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonTransferToImageBitmap);
|
| + RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleration, SnapshotReasonTransferToImageBitmap);
|
| + DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not yet supported in Workers
|
| RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release());
|
| image->setOriginClean(this->originClean());
|
| m_imageBuffer.reset(); // "Transfer" means no retained buffer
|
|
|