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

Unified Diff: Source/platform/graphics/RecordingImageBufferSurface.cpp

Issue 429643002: Add non-blocking frame rate limiting logic to display list 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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: Source/platform/graphics/RecordingImageBufferSurface.cpp
diff --git a/Source/platform/graphics/RecordingImageBufferSurface.cpp b/Source/platform/graphics/RecordingImageBufferSurface.cpp
index abd7003fa38821b46f8c9c7bdc24eb30e8d309ea..5fb87dbaf39fee6f5ffeca84d415bc22bbfacf72 100644
--- a/Source/platform/graphics/RecordingImageBufferSurface.cpp
+++ b/Source/platform/graphics/RecordingImageBufferSurface.cpp
@@ -8,6 +8,7 @@
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/ImageBuffer.h"
+#include "public/platform/Platform.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "wtf/PassOwnPtr.h"
@@ -20,13 +21,17 @@ RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Op
, m_graphicsContext(0)
, m_initialSaveCount(0)
, m_frameWasCleared(true)
- , m_surfaceUsedSincePreviousFrameWasPresented(false)
+ , m_recordedSinceLastFrameWasFinalized(false)
{
initializeCurrentFrame();
}
RecordingImageBufferSurface::~RecordingImageBufferSurface()
-{ }
+{
+ if (m_recordedSinceLastFrameWasFinalized) {
+ blink::Platform::current()->currentThread()->removeTaskObserver(this);
+ }
+}
void RecordingImageBufferSurface::initializeCurrentFrame()
{
@@ -90,8 +95,7 @@ SkCanvas* RecordingImageBufferSurface::canvas() const
PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture()
{
- if (handleOpaqueFrame()) {
- m_surfaceUsedSincePreviousFrameWasPresented = false;
+ if (finalizeFrame()) {
return m_previousFrame;
}
@@ -100,9 +104,30 @@ PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture()
return nullptr;
}
-void RecordingImageBufferSurface::willUse()
+void RecordingImageBufferSurface::didDraw()
+{
+ if (!m_recordedSinceLastFrameWasFinalized && m_currentFrame) {
+ m_recordedSinceLastFrameWasFinalized = true;
+ blink::Platform::current()->currentThread()->addTaskObserver(this);
+ }
+}
+
+void RecordingImageBufferSurface::willProcessTask()
+{
+}
+
+void RecordingImageBufferSurface::didProcessTask()
{
- m_surfaceUsedSincePreviousFrameWasPresented = true;
+ ASSERT(m_recordedSinceLastFrameWasFinalized);
+ // This is to insert a frame barrier at the end of each script execution
+ // task that touches the canvas. finalizeFrame() will discard the previous
+ // frame and replace it with the current frame even if it has not been
+ // consumed, thus allowing the renderer to skip ahead to the most recently
+ // recorded frame.
+ if (!finalizeFrame()) {
+ ASSERT(!m_rasterCanvas);
+ fallBackToRasterCanvas();
+ }
}
void RecordingImageBufferSurface::didClearCanvas()
@@ -110,14 +135,23 @@ void RecordingImageBufferSurface::didClearCanvas()
m_frameWasCleared = true;
}
-bool RecordingImageBufferSurface::handleOpaqueFrame()
+bool RecordingImageBufferSurface::finalizeFrame()
{
- if (!m_currentFrame)
+ if (!m_currentFrame) {
+ ASSERT(!m_recordedSinceLastFrameWasFinalized);
return false;
+ }
+
+ bool canvasIsAnimated = m_recordedSinceLastFrameWasFinalized;
+ if (m_recordedSinceLastFrameWasFinalized) {
+ blink::Platform::current()->currentThread()->removeTaskObserver(this);
+ m_recordedSinceLastFrameWasFinalized = false;
+ }
+
IntRect canvasRect(IntPoint(0, 0), size());
if (!m_frameWasCleared && !m_graphicsContext->opaqueRegion().asRect().contains(canvasRect)) {
// No clear happened. If absolutely nothing was drawn, then we can just continue to use the previous frame.
- return !m_surfaceUsedSincePreviousFrameWasPresented;
+ return !canvasIsAnimated;
Stephen White 2014/07/29 18:38:55 Is this more like "canvas has changed"? I.e., some
}
SkCanvas* oldCanvas = m_currentFrame->getRecordingCanvas(); // Could be raster or picture

Powered by Google App Engine
This is Rietveld 408576698