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

Side by Side 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: Release 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 unified diff | Download patch
« no previous file with comments | « Source/platform/graphics/RecordingImageBufferSurface.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 142
150 m_previousFrame = adoptRef(m_currentFrame->endRecording()); 143 m_previousFrame = adoptRef(m_currentFrame->endRecording());
151 initializeCurrentFrame(); 144 initializeCurrentFrame();
152 145
153 SkCanvas* newCanvas = m_currentFrame->getRecordingCanvas(); 146 setCurrentState(m_currentFrame->getRecordingCanvas(), &stateStack);
154 newCanvas->concat(ctm);
155 newCanvas->clipRect(clip);
156 147
157 m_frameWasCleared = false; 148 m_frameWasCleared = false;
158 return true; 149 return true;
159 } 150 }
160 151
152 bool RecordingImageBufferSurface::saveState(SkCanvas* srcCanvas, StateStack* sta teStack)
153 {
154 StateRec state;
155
156 // we will remove all the saved state stack in endRecording anyway, so it ma kes no difference
157 while (srcCanvas->getSaveCount() > m_initialSaveCount) {
158 state.m_ctm = srcCanvas->getTotalMatrix();
159 // FIXME: don't mess up the state in case we will have to fallback, crbu g.com/408392
160 if (!srcCanvas->getClipDeviceBounds(&state.m_clip))
161 return false;
162 stateStack->push(state);
163 srcCanvas->restore();
164 }
165
166 state.m_ctm = srcCanvas->getTotalMatrix();
167 // FIXME: don't mess up the state in case we will have to fallback, crbug.co m/408392
168 if (!srcCanvas->getClipDeviceBounds(&state.m_clip))
169 return false;
170 stateStack->push(state);
171
172 return true;
173 }
174
175 void RecordingImageBufferSurface::setCurrentState(SkCanvas* dstCanvas, StateStac k* stateStack)
176 {
177 while (stateStack->size() > 1) {
178 dstCanvas->resetMatrix();
179 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip));
180 dstCanvas->setMatrix(stateStack->peek().m_ctm);
181 dstCanvas->save();
182 stateStack->pop();
183 }
184
185 dstCanvas->resetMatrix();
186 dstCanvas->clipRect(SkRect::MakeFromIRect(stateStack->peek().m_clip));
187 dstCanvas->setMatrix(stateStack->peek().m_ctm);
188 }
189
161 } // namespace blink 190 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/RecordingImageBufferSurface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698