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

Unified Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 2141793002: Improving canvas 2D performance by switching graphics rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor change Created 4 years, 5 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/platform/graphics/ImageBuffer.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
index 581ef40acf18ab343ba51e8eef7d3fcbd696f578..501bb05924e56f25e7bcb72807b5e07d610fe785 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
@@ -38,6 +38,7 @@
#include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/ImageBufferClient.h"
+#include "platform/graphics/RecordingImageBufferSurface.h"
#include "platform/graphics/StaticBitmapImage.h"
#include "platform/graphics/UnacceleratedImageBufferSurface.h"
#include "platform/graphics/gpu/DrawingBuffer.h"
@@ -80,7 +81,8 @@ std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod
}
ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface)
- : m_snapshotState(InitialSnapshotState)
+ : m_weakPtrFactory(this)
+ , m_snapshotState(InitialSnapshotState)
, m_surface(std::move(surface))
, m_client(0)
, m_gpuMemoryUsage(0)
@@ -400,6 +402,37 @@ void ImageBuffer::updateGPUMemoryUsage() const
}
}
+class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory {
+public:
+ virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& size, OpacityMode opacityMode)
+ {
+ return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode));
+ }
+
+ virtual ~UnacceleratedSurfaceFactory() { }
+};
+
+void ImageBuffer::disableAcceleration()
+{
+ if (!isAccelerated()) {
+ return;
+ }
+
+ // Get current frame.
+ SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonPaint).get();
+
+ // Create and configure a recording (unaccelerated) surface.
+ std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
+ std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageBufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacityMode()));
+ surface->canvas()->drawImage(image, 0, 0);
+ surface->setImageBuffer(this);
+
+ // Replace the current surface with the new surface.
+ m_surface = std::move(surface);
+
+ didDisableAcceleration();
+}
+
bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
{
if (mimeType == "image/jpeg") {
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ImageBuffer.h ('k') | third_party/WebKit/Source/web/WebRuntimeFeatures.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698