Chromium Code Reviews| Index: Source/platform/graphics/RecordingImageBufferSurface.cpp |
| diff --git a/Source/platform/graphics/RecordingImageBufferSurface.cpp b/Source/platform/graphics/RecordingImageBufferSurface.cpp |
| index 252d436f8c42e33feb8aa66c68e1426396e14e15..67531a66e2f4203f1f6932805652cae8348f2dea 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)) |
| 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: |
| + // - 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); |
| + 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->concat(stateStack->last().m_ctm); |
|
Justin Novosad
2014/08/28 14:53:00
I think this should be setMatrix rather than conca
Sergey
2014/09/03 01:50:51
Done.
|
| + dstCanvas->clipRect(stateStack->last().m_clip); |
| + dstCanvas->save(); |
| + stateStack->removeLast(); |
| + } |
| + |
| + dstCanvas->concat(stateStack->last().m_ctm); |
|
Justin Novosad
2014/08/28 14:53:00
here too.
Sergey
2014/09/03 01:50:51
Done.
|
| + dstCanvas->clipRect(stateStack->last().m_clip); |
| +} |
| + |
| } // namespace blink |