| 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" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 SkRegion::Iterator clip_iterator(clip); | 164 SkRegion::Iterator clip_iterator(clip); |
| 165 for (; !clip_iterator.done(); clip_iterator.next()) { | 165 for (; !clip_iterator.done(); clip_iterator.next()) { |
| 166 // this assumes the SkIRect is stored in l,t,r,b ordering which | 166 // this assumes the SkIRect is stored in l,t,r,b ordering which |
| 167 // matches the ordering of our ClipRect struct | 167 // matches the ordering of our ClipRect struct |
| 168 clipWriter.writeIRect(clip_iterator.rect()); | 168 clipWriter.writeIRect(clip_iterator.rect()); |
| 169 state->clipRectCount++; | 169 state->clipRectCount++; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // allocate memory for the clip then and copy them to the struct | 173 // allocate memory for the clip then and copy them to the struct |
| 174 state->clipRects = (ClipRect*) sk_malloc_throw(clipWriter.size()); | 174 state->clipRects = (ClipRect*) sk_malloc_throw(clipWriter.bytesWritten()); |
| 175 clipWriter.flatten(state->clipRects); | 175 clipWriter.flatten(state->clipRects); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 | 179 |
| 180 SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { | 180 SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { |
| 181 SkASSERT(canvas); | 181 SkASSERT(canvas); |
| 182 | 182 |
| 183 // 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). |
| 184 ClipValidator validator; | 184 ClipValidator validator; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return NULL; | 232 return NULL; |
| 233 } | 233 } |
| 234 layerState->raster.rowBytes = bitmap.rowBytes(); | 234 layerState->raster.rowBytes = bitmap.rowBytes(); |
| 235 layerState->raster.pixels = bitmap.getPixels(); | 235 layerState->raster.pixels = bitmap.getPixels(); |
| 236 | 236 |
| 237 setup_MC_state(&layerState->mcState, layer.matrix(), layer.clip()); | 237 setup_MC_state(&layerState->mcState, layer.matrix(), layer.clip()); |
| 238 layerCount++; | 238 layerCount++; |
| 239 } | 239 } |
| 240 | 240 |
| 241 // 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 |
| 242 SkASSERT(layerWriter.size() == layerCount * sizeof(SkCanvasLayerState)); | 242 SkASSERT(layerWriter.bytesWritten() == layerCount * sizeof(SkCanvasLayerStat
e)); |
| 243 canvasState->layerCount = layerCount; | 243 canvasState->layerCount = layerCount; |
| 244 canvasState->layers = (SkCanvasLayerState*) sk_malloc_throw(layerWriter.size
()); | 244 canvasState->layers = (SkCanvasLayerState*) sk_malloc_throw(layerWriter.byte
sWritten()); |
| 245 layerWriter.flatten(canvasState->layers); | 245 layerWriter.flatten(canvasState->layers); |
| 246 | 246 |
| 247 // for now, just ignore any client supplied DrawFilter. | 247 // for now, just ignore any client supplied DrawFilter. |
| 248 if (canvas->getDrawFilter()) { | 248 if (canvas->getDrawFilter()) { |
| 249 // SkDEBUGF(("CaptureCanvasState will ignore the canvases draw filter.\n"
)); | 249 // SkDEBUGF(("CaptureCanvasState will ignore the canvases draw filter.\n"
)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 return canvasState.detach(); | 252 return canvasState.detach(); |
| 253 } | 253 } |
| 254 | 254 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 334 } |
| 335 | 335 |
| 336 return canvas.detach(); | 336 return canvas.detach(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 340 | 340 |
| 341 void SkCanvasStateUtils::ReleaseCanvasState(SkCanvasState* state) { | 341 void SkCanvasStateUtils::ReleaseCanvasState(SkCanvasState* state) { |
| 342 SkDELETE(state); | 342 SkDELETE(state); |
| 343 } | 343 } |
| OLD | NEW |