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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 127 |
| 128 if (!m_currentFrame) { | 128 if (!m_currentFrame) { |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 IntRect canvasRect(IntPoint(0, 0), size()); | 132 IntRect canvasRect(IntPoint(0, 0), size()); |
| 133 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) { | 133 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect)) { |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 SkCanvas* oldCanvas = m_currentFrame->getRecordingCanvas(); // Could be rast er or picture | 137 StateStack stateStack; |
| 138 | 138 |
| 139 // FIXME(crbug.com/392614): handle transferring complex state from the curre nt picture to the new one. | 139 if (!saveState(m_currentFrame->getRecordingCanvas(), &stateStack)) |
| 140 if (oldCanvas->getSaveCount() > m_initialSaveCount) | |
| 141 return false; | 140 return false; |
| 142 | 141 |
| 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()); | 142 m_previousFrame = adoptRef(m_currentFrame->endRecording()); |
| 151 initializeCurrentFrame(); | 143 initializeCurrentFrame(); |
| 152 | 144 |
| 153 SkCanvas* newCanvas = m_currentFrame->getRecordingCanvas(); | 145 setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack); |
| 154 newCanvas->concat(ctm); | |
| 155 newCanvas->clipRect(clip); | |
| 156 | 146 |
| 157 m_frameWasCleared = false; | 147 m_frameWasCleared = false; |
| 158 return true; | 148 return true; |
| 159 } | 149 } |
| 160 | 150 |
| 151 bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* sta teStack) | |
| 152 { | |
| 153 // FIXME(crbug.com/392614): handle transferring complex state from the curre nt 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.
| |
| 154 // - non-rectangular clip | |
| 155 // - 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
| |
| 156 if (!srcCanvas->isClipRect()) | |
| 157 return false; | |
| 158 | |
| 159 StateRec state; | |
| 160 | |
| 161 // we will remove all the saved state stack in endRecording anyway, so it ma kes no difference | |
| 162 while (srcCanvas->getSaveCount() > m_initialSaveCount) { | |
| 163 state.m_ctm = srcCanvas->getTotalMatrix(); | |
| 164 // 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.
| |
| 165 if (!srcCanvas->getClipDeviceBounds(&state.m_clip)) | |
| 166 return false; | |
| 167 stateStack->push(state); | |
| 168 srcCanvas->restore(); | |
| 169 } | |
| 170 | |
| 171 state.m_ctm = srcCanvas->getTotalMatrix(); | |
| 172 // 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.
| |
| 173 if (!srcCanvas->getClipDeviceBounds(&state.m_clip)) | |
| 174 return false; | |
| 175 stateStack->push(state); | |
| 176 | |
| 177 return true; | |
| 178 } | |
| 179 | |
| 180 void RecordingImageBufferSurface::setCurrentState(SkCanvas* dstCanvas, StateStac k* stateStack) | |
| 181 { | |
| 182 while (stateStack->size() > 1) { | |
| 183 dstCanvas->resetMatrix(); | |
| 184 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); | |
| 185 dstCanvas->setMatrix(stateStack->peek().m_ctm); | |
| 186 dstCanvas->save(); | |
| 187 stateStack->pop(); | |
| 188 } | |
| 189 | |
| 190 dstCanvas->resetMatrix(); | |
| 191 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip)); | |
| 192 dstCanvas->setMatrix(stateStack->peek().m_ctm); | |
| 193 } | |
| 194 | |
| 161 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |