Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Unified Diff: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp

Issue 2192493003: Enable GPU acceleration in 2D OffscreenCanvases on main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix dev tools failure Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698