OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkCanvas.h" |
| 9 #include "SkMultiPictureDraw.h" |
| 10 #include "SkPicture.h" |
| 11 |
| 12 SkMultiPictureDraw::SkMultiPictureDraw(int reserve) { |
| 13 if (reserve > 0) { |
| 14 fDrawData.setReserve(reserve); |
| 15 } |
| 16 } |
| 17 |
| 18 void SkMultiPictureDraw::reset() { |
| 19 for (int i = 0; i < fDrawData.count(); ++i) { |
| 20 fDrawData[i].picture->unref(); |
| 21 fDrawData[i].canvas->unref(); |
| 22 SkDELETE(fDrawData[i].paint); |
| 23 } |
| 24 |
| 25 fDrawData.rewind(); |
| 26 } |
| 27 |
| 28 void SkMultiPictureDraw::add(SkCanvas* canvas, |
| 29 const SkPicture* picture, |
| 30 const SkMatrix* matrix, |
| 31 const SkPaint* paint) { |
| 32 if (NULL == canvas || NULL == picture) { |
| 33 SkDEBUGFAIL("parameters to SkMultiPictureDraw::add should be non-NULL"); |
| 34 return; |
| 35 } |
| 36 |
| 37 DrawData* data = fDrawData.append(); |
| 38 |
| 39 data->picture = SkRef(picture); |
| 40 data->canvas = SkRef(canvas); |
| 41 if (NULL != matrix) { |
| 42 data->matrix = *matrix; |
| 43 } else { |
| 44 data->matrix.setIdentity(); |
| 45 } |
| 46 if (NULL != paint) { |
| 47 data->paint = SkNEW_ARGS(SkPaint, (*paint)); |
| 48 } else { |
| 49 data->paint = NULL; |
| 50 } |
| 51 } |
| 52 |
| 53 void SkMultiPictureDraw::draw() { |
| 54 for (int i = 0; i < fDrawData.count(); ++i) { |
| 55 fDrawData[i].canvas->drawPicture(fDrawData[i].picture, |
| 56 &fDrawData[i].matrix, |
| 57 fDrawData[i].paint); |
| 58 } |
| 59 |
| 60 this->reset(); |
| 61 } |
| 62 |
OLD | NEW |