OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #if SK_SUPPORT_GPU |
| 9 #include "GrLayerHoister.h" |
| 10 #include "GrRecordReplaceDraw.h" |
| 11 #endif |
| 12 |
8 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
9 #include "SkMultiPictureDraw.h" | 14 #include "SkMultiPictureDraw.h" |
10 #include "SkPicture.h" | 15 #include "SkPicture.h" |
11 | 16 |
12 SkMultiPictureDraw::SkMultiPictureDraw(int reserve) { | 17 SkMultiPictureDraw::SkMultiPictureDraw(int reserve) { |
13 if (reserve > 0) { | 18 if (reserve > 0) { |
14 fDrawData.setReserve(reserve); | 19 fDrawData.setReserve(reserve); |
15 } | 20 } |
16 } | 21 } |
17 | 22 |
(...skipping 25 matching lines...) Expand all Loading... |
43 } else { | 48 } else { |
44 data->matrix.setIdentity(); | 49 data->matrix.setIdentity(); |
45 } | 50 } |
46 if (paint) { | 51 if (paint) { |
47 data->paint = SkNEW_ARGS(SkPaint, (*paint)); | 52 data->paint = SkNEW_ARGS(SkPaint, (*paint)); |
48 } else { | 53 } else { |
49 data->paint = NULL; | 54 data->paint = NULL; |
50 } | 55 } |
51 } | 56 } |
52 | 57 |
| 58 #undef SK_IGNORE_GPU_LAYER_HOISTING |
| 59 #define SK_IGNORE_GPU_LAYER_HOISTING 1 |
| 60 |
53 void SkMultiPictureDraw::draw() { | 61 void SkMultiPictureDraw::draw() { |
| 62 |
| 63 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| 64 GrContext* context = NULL; |
| 65 |
| 66 SkTDArray<GrHoistedLayer> atlased, nonAtlased, recycled; |
| 67 |
54 for (int i = 0; i < fDrawData.count(); ++i) { | 68 for (int i = 0; i < fDrawData.count(); ++i) { |
55 fDrawData[i].canvas->drawPicture(fDrawData[i].picture, | 69 if (fDrawData[i].canvas->getGrContext() && |
56 &fDrawData[i].matrix, | 70 !fDrawData[i].paint && fDrawData[i].matrix.isIdentity()) { |
57 fDrawData[i].paint); | 71 SkASSERT(NULL == context || context == fDrawData[i].canvas->getGrCon
text()); |
| 72 context = fDrawData[i].canvas->getGrContext(); |
| 73 |
| 74 // TODO: this path always tries to optimize pictures. Should we |
| 75 // switch to this API approach (vs. SkCanvas::EXPERIMENTAL_optimize)
? |
| 76 fDrawData[i].canvas->EXPERIMENTAL_optimize(fDrawData[i].picture); |
| 77 |
| 78 SkRect clipBounds; |
| 79 if (!fDrawData[i].canvas->getClipBounds(&clipBounds)) { |
| 80 continue; |
| 81 } |
| 82 |
| 83 GrLayerHoister::FindLayersToHoist(context, fDrawData[i].picture, |
| 84 clipBounds, &atlased, &nonAtlased,
&recycled); |
| 85 } |
58 } | 86 } |
59 | 87 |
| 88 GrReplacements replacements; |
| 89 |
| 90 if (NULL != context) { |
| 91 GrLayerHoister::DrawLayers(atlased, nonAtlased, recycled, &replacements)
; |
| 92 } |
| 93 #endif |
| 94 |
| 95 for (int i = 0; i < fDrawData.count(); ++i) { |
| 96 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| 97 if (fDrawData[i].canvas->getGrContext() && |
| 98 !fDrawData[i].paint && fDrawData[i].matrix.isIdentity()) { |
| 99 // Render the entire picture using new layers |
| 100 const SkMatrix initialMatrix = fDrawData[i].canvas->getTotalMatrix()
; |
| 101 |
| 102 GrRecordReplaceDraw(fDrawData[i].picture, fDrawData[i].canvas, |
| 103 &replacements, initialMatrix, NULL); |
| 104 } else |
| 105 #endif |
| 106 { |
| 107 fDrawData[i].canvas->drawPicture(fDrawData[i].picture, |
| 108 &fDrawData[i].matrix, |
| 109 fDrawData[i].paint); |
| 110 } |
| 111 } |
| 112 |
| 113 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| 114 if (NULL != context) { |
| 115 GrLayerHoister::UnlockLayers(context, atlased, nonAtlased, recycled); |
| 116 } |
| 117 #endif |
| 118 |
60 this->reset(); | 119 this->reset(); |
61 } | 120 } |
62 | 121 |
OLD | NEW |