Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "platform/graphics/RecordingImageBufferSurface.h" | 7 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 8 | 8 |
| 9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/ImageBuffer.h" | 10 #include "platform/graphics/ImageBuffer.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 111 |
| 112 void RecordingImageBufferSurface::didClearCanvas() | 112 void RecordingImageBufferSurface::didClearCanvas() |
| 113 { | 113 { |
| 114 m_frameWasCleared = true; | 114 m_frameWasCleared = true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool RecordingImageBufferSurface::finalizeFrameInternal() | 117 bool RecordingImageBufferSurface::finalizeFrameInternal() |
| 118 { | 118 { |
| 119 if (!m_imageBuffer->isDirty()) { | 119 if (!m_imageBuffer->isDirty()) { |
| 120 if (m_currentFrame && !m_previousFrame) { | 120 if (m_currentFrame && !m_previousFrame) { |
| 121 // Create an initial blank frame | |
| 122 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 121 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
| 123 initializeCurrentFrame(); | 122 initializeCurrentFrame(); |
| 124 } | 123 } |
| 125 return m_currentFrame; | 124 return m_currentFrame; |
| 126 } | 125 } |
| 127 | 126 |
| 128 if (!m_currentFrame) { | 127 if (!m_currentFrame) { |
| 129 return false; | 128 return false; |
| 130 } | 129 } |
| 131 | 130 |
| 132 IntRect canvasRect(IntPoint(0, 0), size()); | 131 IntRect canvasRect(IntPoint(0, 0), size()); |
| 133 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) { | 132 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) { |
| 134 return false; | 133 return false; |
| 135 } | 134 } |
| 136 | 135 |
| 137 SkCanvas* oldCanvas = m_currentFrame->getRecordingCanvas(); // Could be rast er or picture | 136 StateStack stateStack; |
| 138 | 137 |
| 139 // FIXME(crbug.com/392614): handle transferring complex state from the curre nt picture to the new one. | 138 if (!saveState(m_currentFrame->getRecordingCanvas(), &stateStack)) |
| 140 if (oldCanvas->getSaveCount() > m_initialSaveCount) | |
| 141 return false; | 139 return false; |
| 142 | 140 |
| 143 if (!oldCanvas->isClipRect()) | |
| 144 return false; | |
| 145 | |
| 146 SkMatrix ctm = oldCanvas->getTotalMatrix(); | |
| 147 SkRect clip; | |
| 148 oldCanvas->getClipBounds(&clip); | |
| 149 | |
| 150 m_previousFrame = adoptRef(m_currentFrame->endRecording()); | 141 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
| 151 initializeCurrentFrame(); | 142 initializeCurrentFrame(); |
| 152 | 143 |
| 153 SkCanvas* newCanvas = m_currentFrame->getRecordingCanvas(); | 144 setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack); |
| 154 newCanvas->concat(ctm); | |
| 155 newCanvas->clipRect(clip); | |
| 156 | 145 |
| 157 m_frameWasCleared = false; | 146 m_frameWasCleared = false; |
| 158 return true; | 147 return true; |
| 159 } | 148 } |
| 160 | 149 |
| 150 bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* sta teStack) | |
| 151 { | |
| 152 // FIXME(crbug.com/392614): handle transferring complex state from the curre nt picture to the new one: | |
| 153 // - non-rectangular clip | |
| 154 // - non-invertible clip | |
| 155 if (!srcCanvas->isClipRect()) | |
| 156 return false; | |
| 157 | |
| 158 StateRec state; | |
| 159 | |
| 160 // we will remove all the saved state stack in endRecording anyway, so it ma kes no difference | |
| 161 while (srcCanvas->getSaveCount() > m_initialSaveCount) { | |
| 162 state.m_ctm = srcCanvas->getTotalMatrix(); | |
| 163 srcCanvas->getClipBounds(&state.m_clip); | |
| 164 stateStack->append(state); | |
| 165 srcCanvas->restore(); | |
| 166 // FIXME(crbug.com/408392): don't mess up the state in case we will have to fallback | |
| 167 if (!srcCanvas->isClipRect()) | |
| 168 return false; | |
| 169 } | |
| 170 | |
| 171 state.m_ctm = srcCanvas->getTotalMatrix(); | |
| 172 srcCanvas->getClipBounds(&state.m_clip); | |
| 173 stateStack->append(state); | |
| 174 | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 void RecordingImageBufferSurface::setCurrentState(SkCanvas* dstCanvas, StateStac k* stateStack) | |
| 179 { | |
| 180 while (stateStack->size() > 1) { | |
| 181 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.
| |
| 182 dstCanvas->clipRect(stateStack->last().m_clip); | |
| 183 dstCanvas->save(); | |
| 184 stateStack->removeLast(); | |
| 185 } | |
| 186 | |
| 187 dstCanvas->concat(stateStack->last().m_ctm); | |
|
Justin Novosad
2014/08/28 14:53:00
here too.
Sergey
2014/09/03 01:50:51
Done.
| |
| 188 dstCanvas->clipRect(stateStack->last().m_clip); | |
| 189 } | |
| 190 | |
| 161 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |