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

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: Source code adjustements + [WIP] layout test problems 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
Index: Source/platform/graphics/RecordingImageBufferSurface.cpp
diff --git a/Source/platform/graphics/RecordingImageBufferSurface.cpp b/Source/platform/graphics/RecordingImageBufferSurface.cpp
index 252d436f8c42e33feb8aa66c68e1426396e14e15..7325975e5a07564454fb515ae8201262860f0494 100644
--- a/Source/platform/graphics/RecordingImageBufferSurface.cpp
+++ b/Source/platform/graphics/RecordingImageBufferSurface.cpp
@@ -118,7 +118,6 @@ bool RecordingImageBufferSurface::finalizeFrameInternal()
{
if (!m_imageBuffer->isDirty()) {
if (m_currentFrame && !m_previousFrame) {
- // Create an initial blank frame
m_previousFrame = adoptRef(m_currentFrame->endRecording());
initializeCurrentFrame();
}
@@ -134,28 +133,59 @@ 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))
zino 2014/09/03 10:50:17 How does it work in the following cases? - displa
Sergey 2014/09/04 10:26:50 First, right now there is no "fallback mode -> dis
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);
zino 2014/09/03 10:50:17 ditto
Sergey 2014/09/04 10:26:50 It is not required at this point, as we are not go
m_frameWasCleared = false;
return true;
}
+bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* stateStack)
+{
+ // FIXME(crbug.com/392614): handle transferring complex state from the current picture to the new one:
+ // - non-rectangular clip
+ // - non-invertible clip
+ if (!srcCanvas->isClipRect())
+ return false;
+
+ 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();
+ srcCanvas->getClipBounds(&state.m_clip);
zino 2014/09/03 10:50:17 I think you should use getClipDeviceBounds() inste
Justin Novosad 2014/09/03 15:24:39 This is a good point. Using getDeviceClipBounds sa
Sergey 2014/09/11 12:58:52 Probably not required here at all.
+ stateStack->append(state);
+ srcCanvas->restore();
+ // FIXME(crbug.com/408392): don't mess up the state in case we will have to fallback
+ if (!srcCanvas->isClipRect())
+ return false;
+ }
+
+ state.m_ctm = srcCanvas->getTotalMatrix();
+ srcCanvas->getClipBounds(&state.m_clip);
+ stateStack->append(state);
+
+ return true;
+}
+
+void RecordingImageBufferSurface::setCurrentState(SkCanvas* dstCanvas, StateStack* stateStack)
+{
+ while (stateStack->size() > 1) {
+ dstCanvas->setMatrix(stateStack->last().m_ctm);
+ dstCanvas->clipRect(stateStack->last().m_clip);
+ dstCanvas->save();
+ stateStack->removeLast();
+ }
+
+ dstCanvas->setMatrix(stateStack->last().m_ctm);
+ dstCanvas->clipRect(stateStack->last().m_clip);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698