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

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

Issue 501353002: Transfer canvas state to the next frame with noticable restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Release Created 6 years, 3 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
« no previous file with comments | « Source/platform/graphics/RecordingImageBufferSurface.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/RecordingImageBufferSurface.cpp
diff --git a/Source/platform/graphics/RecordingImageBufferSurface.cpp b/Source/platform/graphics/RecordingImageBufferSurface.cpp
index 252d436f8c42e33feb8aa66c68e1426396e14e15..33d603fa9e014d69fadee44d8165ff9ad275319e 100644
--- a/Source/platform/graphics/RecordingImageBufferSurface.cpp
+++ b/Source/platform/graphics/RecordingImageBufferSurface.cpp
@@ -134,28 +134,57 @@ bool RecordingImageBufferSurface::finalizeFrameInternal()
return false;
}
- SkCanvas* oldCanvas = m_currentFrame->getRecordingCanvas(); // Could be raster or picture
+ StateStack stateStack;
- // FIXME(crbug.com/392614): handle transferring complex state from the current picture to the new one.
- if (oldCanvas->getSaveCount() > m_initialSaveCount)
+ if (!saveState(m_currentFrame->getRecordingCanvas(), &stateStack)) {
return false;
-
- if (!oldCanvas->isClipRect())
- return false;
-
- SkMatrix ctm = oldCanvas->getTotalMatrix();
- SkRect clip;
- oldCanvas->getClipBounds(&clip);
+ }
m_previousFrame = adoptRef(m_currentFrame->endRecording());
initializeCurrentFrame();
- SkCanvas* newCanvas = m_currentFrame->getRecordingCanvas();
- newCanvas->concat(ctm);
- newCanvas->clipRect(clip);
+ setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack);
m_frameWasCleared = false;
return true;
}
+bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* stateStack)
+{
+ StateRec state;
+
+ // we will remove all the saved state stack in endRecording anyway, so it makes no difference
+ while (srcCanvas->getSaveCount() > m_initialSaveCount) {
+ state.m_ctm = srcCanvas->getTotalMatrix();
+ // FIXME: don't mess up the state in case we will have to fallback, crbug.com/408392
+ if (!srcCanvas->getClipDeviceBounds(&state.m_clip))
+ return false;
+ stateStack->push(state);
+ srcCanvas->restore();
+ }
+
+ state.m_ctm = srcCanvas->getTotalMatrix();
+ // FIXME: don't mess up the state in case we will have to fallback, crbug.com/408392
+ if (!srcCanvas->getClipDeviceBounds(&state.m_clip))
+ return false;
+ stateStack->push(state);
+
+ return true;
+}
+
+void RecordingImageBufferSurface::setCurrentState(SkCanvas* dstCanvas, StateStack* stateStack)
+{
+ while (stateStack->size() > 1) {
+ dstCanvas->resetMatrix();
+ dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip));
+ dstCanvas->setMatrix(stateStack->peek().m_ctm);
+ dstCanvas->save();
+ stateStack->pop();
+ }
+
+ dstCanvas->resetMatrix();
+ dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip));
+ dstCanvas->setMatrix(stateStack->peek().m_ctm);
+}
+
} // namespace blink
« no previous file with comments | « Source/platform/graphics/RecordingImageBufferSurface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698