Index: Source/platform/graphics/RecordingImageBufferSurface.cpp |
diff --git a/Source/platform/graphics/RecordingImageBufferSurface.cpp b/Source/platform/graphics/RecordingImageBufferSurface.cpp |
index 252d436f8c42e33feb8aa66c68e1426396e14e15..41721889f7951a1634bbf50ad97e42dbca020621 100644 |
--- a/Source/platform/graphics/RecordingImageBufferSurface.cpp |
+++ b/Source/platform/graphics/RecordingImageBufferSurface.cpp |
@@ -134,28 +134,62 @@ 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) |
+{ |
+ // FIXME(crbug.com/392614): handle transferring complex state from the current picture to the new one: |
zino
2014/09/13 16:00:28
I think you should avoid FIXME(attribution) in Bli
Sergey
2014/09/15 02:45:36
I think one line comment would be better... PTAL.
|
+ // - non-rectangular clip |
+ // - non-invertible clip |
Justin Novosad
2014/09/12 14:54:35
I think you mean "inverted clip"?
Sergey
2014/09/15 02:45:36
I meant situation, when we can't invert transform
|
+ 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(); |
+ // FIXME(crbug.com/408392): don't mess up the state in case we will have to fallback |
zino
2014/09/13 16:00:28
ditto
Sergey
2014/09/15 02:45:36
Done.
|
+ if (!srcCanvas->getClipDeviceBounds(&state.m_clip)) |
+ return false; |
+ stateStack->push(state); |
+ srcCanvas->restore(); |
+ } |
+ |
+ state.m_ctm = srcCanvas->getTotalMatrix(); |
+ // FIXME(crbug.com/408392): don't mess up the state in case we will have to fallback |
zino
2014/09/13 16:00:28
ditto
Sergey
2014/09/15 02:45:36
Done.
|
+ 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 |