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

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: Source code adjustements + [WIP] layout test problems 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
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
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))
zino 2014/09/03 10:50:17 How does it work in the following cases? - displa
Sergey 2014/09/04 10:26:50 First, right now there is no "fallback mode -> dis
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);
zino 2014/09/03 10:50:17 ditto
Sergey 2014/09/04 10:26:50 It is not required at this point, as we are not go
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);
zino 2014/09/03 10:50:17 I think you should use getClipDeviceBounds() inste
Justin Novosad 2014/09/03 15:24:39 This is a good point. Using getDeviceClipBounds sa
Sergey 2014/09/11 12:58:52 Probably not required here at all.
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->setMatrix(stateStack->last().m_ctm);
182 dstCanvas->clipRect(stateStack->last().m_clip);
183 dstCanvas->save();
184 stateStack->removeLast();
185 }
186
187 dstCanvas->setMatrix(stateStack->last().m_ctm);
188 dstCanvas->clipRect(stateStack->last().m_clip);
189 }
190
161 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698