OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvasStateUtils.h" | 8 #include "SkCanvasStateUtils.h" |
9 | 9 |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkCanvasStack.h" | 12 #include "SkCanvasStack.h" |
| 13 #include "SkErrorInternals.h" |
13 #include "SkWriter32.h" | 14 #include "SkWriter32.h" |
14 | 15 |
15 #define CANVAS_STATE_VERSION 1 | 16 #define CANVAS_STATE_VERSION 1 |
16 /* | 17 /* |
17 * WARNING: The structs below are part of a stable ABI and as such we explicitly | 18 * WARNING: The structs below are part of a stable ABI and as such we explicitly |
18 * use unambigious primitives (e.g. int32_t instead of an enum). | 19 * use unambigious primitives (e.g. int32_t instead of an enum). |
19 * | 20 * |
20 * ANY CHANGES TO THE STRUCTS BELOW THAT IMPACT THE ABI SHOULD RESULT IN AN | 21 * ANY CHANGES TO THE STRUCTS BELOW THAT IMPACT THE ABI SHOULD RESULT IN AN |
21 * UPDATE OF THE CANVAS_STATE_VERSION. SUCH CHANGES SHOULD ONLY BE MADE IF | 22 * UPDATE OF THE CANVAS_STATE_VERSION. SUCH CHANGES SHOULD ONLY BE MADE IF |
22 * ABSOLUTELY NECESSARY! | 23 * ABSOLUTELY NECESSARY! |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 177 |
177 | 178 |
178 | 179 |
179 SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { | 180 SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { |
180 SkASSERT(canvas); | 181 SkASSERT(canvas); |
181 | 182 |
182 // Check the clip can be decomposed into rectangles (i.e. no soft clips). | 183 // Check the clip can be decomposed into rectangles (i.e. no soft clips). |
183 ClipValidator validator; | 184 ClipValidator validator; |
184 canvas->replayClips(&validator); | 185 canvas->replayClips(&validator); |
185 if (validator.failed()) { | 186 if (validator.failed()) { |
186 SkDEBUGF(("CaptureCanvasState does not support canvases with antialiased
clips.\n")); | 187 SkErrorInternals::SetError(kInvalidOperation_SkError, |
| 188 "CaptureCanvasState does not support canvases with antialiased c
lips.\n"); |
187 return NULL; | 189 return NULL; |
188 } | 190 } |
189 | 191 |
190 SkAutoTDelete<SkCanvasState> canvasState(SkNEW_ARGS(SkCanvasState, (canvas))
); | 192 SkAutoTDelete<SkCanvasState> canvasState(SkNEW_ARGS(SkCanvasState, (canvas))
); |
191 | 193 |
192 // decompose the total matrix and clip | 194 // decompose the total matrix and clip |
193 setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(), canvas->getT
otalClip()); | 195 setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(), canvas->getT
otalClip()); |
194 | 196 |
195 /* | 197 /* |
196 * decompose the layers | 198 * decompose the layers |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 239 } |
238 | 240 |
239 // allocate memory for the layers and then and copy them to the struct | 241 // allocate memory for the layers and then and copy them to the struct |
240 SkASSERT(layerWriter.size() == layerCount * sizeof(SkCanvasLayerState)); | 242 SkASSERT(layerWriter.size() == layerCount * sizeof(SkCanvasLayerState)); |
241 canvasState->layerCount = layerCount; | 243 canvasState->layerCount = layerCount; |
242 canvasState->layers = (SkCanvasLayerState*) sk_malloc_throw(layerWriter.size
()); | 244 canvasState->layers = (SkCanvasLayerState*) sk_malloc_throw(layerWriter.size
()); |
243 layerWriter.flatten(canvasState->layers); | 245 layerWriter.flatten(canvasState->layers); |
244 | 246 |
245 // for now, just ignore any client supplied DrawFilter. | 247 // for now, just ignore any client supplied DrawFilter. |
246 if (canvas->getDrawFilter()) { | 248 if (canvas->getDrawFilter()) { |
247 SkDEBUGF(("CaptureCanvasState will ignore the canvases draw filter.\n"))
; | 249 // SkDEBUGF(("CaptureCanvasState will ignore the canvases draw filter.\n"
)); |
248 } | 250 } |
249 | 251 |
250 return canvasState.detach(); | 252 return canvasState.detach(); |
251 } | 253 } |
252 | 254 |
253 //////////////////////////////////////////////////////////////////////////////// | 255 //////////////////////////////////////////////////////////////////////////////// |
254 | 256 |
255 static void setup_canvas_from_MC_state(const SkMCState& state, SkCanvas* canvas)
{ | 257 static void setup_canvas_from_MC_state(const SkMCState& state, SkCanvas* canvas)
{ |
256 // reconstruct the matrix | 258 // reconstruct the matrix |
257 SkMatrix matrix; | 259 SkMatrix matrix; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 334 } |
333 | 335 |
334 return canvas.detach(); | 336 return canvas.detach(); |
335 } | 337 } |
336 | 338 |
337 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
338 | 340 |
339 void SkCanvasStateUtils::ReleaseCanvasState(SkCanvasState* state) { | 341 void SkCanvasStateUtils::ReleaseCanvasState(SkCanvasState* state) { |
340 SkDELETE(state); | 342 SkDELETE(state); |
341 } | 343 } |
OLD | NEW |