| 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 // Need to include something before #if SK_SUPPORT_GPU so that the Android | |
| 9 // framework build, which gets its defines from SkTypes rather than a makefile, | |
| 10 // has the definition before checking it. | |
| 11 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 12 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
| 13 #include "SkMultiPictureDraw.h" | 10 #include "SkMultiPictureDraw.h" |
| 14 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 15 #include "SkTaskGroup.h" | 12 #include "SkTaskGroup.h" |
| 16 | 13 |
| 17 #if SK_SUPPORT_GPU | |
| 18 #include "GrContext.h" | |
| 19 #include "GrDrawContext.h" | |
| 20 #include "GrLayerHoister.h" | |
| 21 #include "GrRecordReplaceDraw.h" | |
| 22 #include "GrRenderTarget.h" | |
| 23 #endif | |
| 24 | |
| 25 void SkMultiPictureDraw::DrawData::draw() { | 14 void SkMultiPictureDraw::DrawData::draw() { |
| 26 fCanvas->drawPicture(fPicture, &fMatrix, fPaint); | 15 fCanvas->drawPicture(fPicture, &fMatrix, fPaint); |
| 27 } | 16 } |
| 28 | 17 |
| 29 void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* pictu
re, | 18 void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* pictu
re, |
| 30 const SkMatrix* matrix, const SkPaint* p
aint) { | 19 const SkMatrix* matrix, const SkPaint* p
aint) { |
| 31 fPicture = SkRef(picture); | 20 fPicture = SkRef(picture); |
| 32 fCanvas = SkRef(canvas); | 21 fCanvas = SkRef(canvas); |
| 33 if (matrix) { | 22 if (matrix) { |
| 34 fMatrix = *matrix; | 23 fMatrix = *matrix; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 #endif | 90 #endif |
| 102 | 91 |
| 103 // N.B. we could get going on any GPU work from this main thread while the C
PU work runs. | 92 // N.B. we could get going on any GPU work from this main thread while the C
PU work runs. |
| 104 // But in practice, we've either got GPU work or CPU work, not both. | 93 // But in practice, we've either got GPU work or CPU work, not both. |
| 105 | 94 |
| 106 const int count = fGPUDrawData.count(); | 95 const int count = fGPUDrawData.count(); |
| 107 if (0 == count) { | 96 if (0 == count) { |
| 108 return; | 97 return; |
| 109 } | 98 } |
| 110 | 99 |
| 111 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU | |
| 112 GrContext* context = fGPUDrawData[0].fCanvas->getGrContext(); | |
| 113 SkASSERT(context); | |
| 114 | |
| 115 // Start by collecting all the layers that are going to be atlased and rende
r | |
| 116 // them (if necessary). Hoisting the free floating layers is deferred until | |
| 117 // drawing the canvas that requires them. | |
| 118 SkTDArray<GrHoistedLayer> atlasedNeedRendering, atlasedRecycled; | |
| 119 | |
| 120 GrLayerHoister::Begin(context); | |
| 121 | |
| 122 for (int i = 0; i < count; ++i) { | |
| 123 const DrawData& data = fGPUDrawData[i]; | |
| 124 // we only expect 1 context for all the canvases | |
| 125 SkASSERT(data.fCanvas->getGrContext() == context); | |
| 126 | |
| 127 if (!data.fPaint && | |
| 128 (kRGBA_8888_SkColorType == data.fCanvas->imageInfo().colorType() || | |
| 129 kBGRA_8888_SkColorType == data.fCanvas->imageInfo().colorType())) { | |
| 130 SkRect clipBounds; | |
| 131 if (!data.fCanvas->getClipBounds(&clipBounds)) { | |
| 132 continue; | |
| 133 } | |
| 134 | |
| 135 SkMatrix initialMatrix = data.fCanvas->getTotalMatrix(); | |
| 136 initialMatrix.preConcat(data.fMatrix); | |
| 137 | |
| 138 GrDrawContext* dc = data.fCanvas->internal_private_accessTopLayerDra
wContext(); | |
| 139 SkASSERT(dc); | |
| 140 | |
| 141 // TODO: sorting the cacheable layers from smallest to largest | |
| 142 // would improve the packing and reduce the number of swaps | |
| 143 // TODO: another optimization would be to make a first pass to | |
| 144 // lock any required layer that is already in the atlas | |
| 145 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, initialMat
rix, | |
| 146 clipBounds, | |
| 147 &atlasedNeedRendering, &atlasedRec
ycled, | |
| 148 dc->numColorSamples()); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); | |
| 153 | |
| 154 SkTDArray<GrHoistedLayer> needRendering, recycled; | |
| 155 #endif | |
| 156 | |
| 157 for (int i = 0; i < count; ++i) { | 100 for (int i = 0; i < count; ++i) { |
| 158 const DrawData& data = fGPUDrawData[i]; | 101 const DrawData& data = fGPUDrawData[i]; |
| 159 SkCanvas* canvas = data.fCanvas; | 102 SkCanvas* canvas = data.fCanvas; |
| 160 const SkPicture* picture = data.fPicture; | 103 const SkPicture* picture = data.fPicture; |
| 161 | 104 |
| 162 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU | 105 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); |
| 163 if (!data.fPaint) { | |
| 164 | |
| 165 SkRect clipBounds; | |
| 166 if (!canvas->getClipBounds(&clipBounds)) { | |
| 167 continue; | |
| 168 } | |
| 169 | |
| 170 SkAutoCanvasMatrixPaint acmp(canvas, &data.fMatrix, data.fPaint, pic
ture->cullRect()); | |
| 171 | |
| 172 const SkMatrix initialMatrix = canvas->getTotalMatrix(); | |
| 173 | |
| 174 GrDrawContext* dc = data.fCanvas->internal_private_accessTopLayerDra
wContext(); | |
| 175 SkASSERT(dc); | |
| 176 | |
| 177 // Find the layers required by this canvas. It will return atlased | |
| 178 // layers in the 'recycled' list since they have already been drawn. | |
| 179 GrLayerHoister::FindLayersToHoist(context, picture, initialMatrix, | |
| 180 clipBounds, &needRendering, &recyc
led, | |
| 181 dc->numColorSamples()); | |
| 182 | |
| 183 GrLayerHoister::DrawLayers(context, needRendering); | |
| 184 | |
| 185 // Render the entire picture using new layers | |
| 186 GrRecordReplaceDraw(picture, canvas, context->getLayerCache(), | |
| 187 initialMatrix, nullptr); | |
| 188 | |
| 189 GrLayerHoister::UnlockLayers(context, needRendering); | |
| 190 GrLayerHoister::UnlockLayers(context, recycled); | |
| 191 | |
| 192 needRendering.rewind(); | |
| 193 recycled.rewind(); | |
| 194 } else | |
| 195 #endif | |
| 196 { | |
| 197 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); | |
| 198 } | |
| 199 if (flush) { | 106 if (flush) { |
| 200 canvas->flush(); | 107 canvas->flush(); |
| 201 } | 108 } |
| 202 } | 109 } |
| 203 | |
| 204 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU | |
| 205 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); | |
| 206 GrLayerHoister::UnlockLayers(context, atlasedRecycled); | |
| 207 GrLayerHoister::End(context); | |
| 208 #endif | |
| 209 } | 110 } |
| OLD | NEW |