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 | 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, | 9 // framework build, which gets its defines from SkTypes rather than a makefile, |
10 // has the definition before checking it. | 10 // has the definition before checking it. |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkCanvasPriv.h" | 12 #include "SkCanvasPriv.h" |
13 #include "SkMultiPictureDraw.h" | 13 #include "SkMultiPictureDraw.h" |
14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
15 #include "SkTaskGroup.h" | 15 #include "SkTaskGroup.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "GrContext.h" | 18 #include "GrContext.h" |
| 19 #include "GrDrawContext.h" |
19 #include "GrLayerHoister.h" | 20 #include "GrLayerHoister.h" |
20 #include "GrRecordReplaceDraw.h" | 21 #include "GrRecordReplaceDraw.h" |
21 #include "GrRenderTarget.h" | 22 #include "GrRenderTarget.h" |
22 #endif | 23 #endif |
23 | 24 |
24 void SkMultiPictureDraw::DrawData::draw() { | 25 void SkMultiPictureDraw::DrawData::draw() { |
25 fCanvas->drawPicture(fPicture, &fMatrix, fPaint); | 26 fCanvas->drawPicture(fPicture, &fMatrix, fPaint); |
26 } | 27 } |
27 | 28 |
28 void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* pictu
re, | 29 void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* pictu
re, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 126 |
126 if (!data.fPaint) { | 127 if (!data.fPaint) { |
127 SkRect clipBounds; | 128 SkRect clipBounds; |
128 if (!data.fCanvas->getClipBounds(&clipBounds)) { | 129 if (!data.fCanvas->getClipBounds(&clipBounds)) { |
129 continue; | 130 continue; |
130 } | 131 } |
131 | 132 |
132 SkMatrix initialMatrix = data.fCanvas->getTotalMatrix(); | 133 SkMatrix initialMatrix = data.fCanvas->getTotalMatrix(); |
133 initialMatrix.preConcat(data.fMatrix); | 134 initialMatrix.preConcat(data.fMatrix); |
134 | 135 |
135 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe
nderTarget(); | 136 GrDrawContext* dc = data.fCanvas->internal_private_accessTopLayerDra
wContext(); |
136 SkASSERT(rt); | 137 SkASSERT(dc); |
137 | 138 |
138 // TODO: sorting the cacheable layers from smallest to largest | 139 // TODO: sorting the cacheable layers from smallest to largest |
139 // would improve the packing and reduce the number of swaps | 140 // would improve the packing and reduce the number of swaps |
140 // TODO: another optimization would be to make a first pass to | 141 // TODO: another optimization would be to make a first pass to |
141 // lock any required layer that is already in the atlas | 142 // lock any required layer that is already in the atlas |
142 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, initialMat
rix, | 143 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, initialMat
rix, |
143 clipBounds, | 144 clipBounds, |
144 &atlasedNeedRendering, &atlasedRec
ycled, | 145 &atlasedNeedRendering, &atlasedRec
ycled, |
145 rt->numColorSamples()); | 146 dc->numColorSamples()); |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); | 150 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); |
150 | 151 |
151 SkTDArray<GrHoistedLayer> needRendering, recycled; | 152 SkTDArray<GrHoistedLayer> needRendering, recycled; |
152 #endif | 153 #endif |
153 | 154 |
154 for (int i = 0; i < count; ++i) { | 155 for (int i = 0; i < count; ++i) { |
155 const DrawData& data = fGPUDrawData[i]; | 156 const DrawData& data = fGPUDrawData[i]; |
156 SkCanvas* canvas = data.fCanvas; | 157 SkCanvas* canvas = data.fCanvas; |
157 const SkPicture* picture = data.fPicture; | 158 const SkPicture* picture = data.fPicture; |
158 | 159 |
159 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU | 160 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU |
160 if (!data.fPaint) { | 161 if (!data.fPaint) { |
161 | 162 |
162 SkRect clipBounds; | 163 SkRect clipBounds; |
163 if (!canvas->getClipBounds(&clipBounds)) { | 164 if (!canvas->getClipBounds(&clipBounds)) { |
164 continue; | 165 continue; |
165 } | 166 } |
166 | 167 |
167 SkAutoCanvasMatrixPaint acmp(canvas, &data.fMatrix, data.fPaint, pic
ture->cullRect()); | 168 SkAutoCanvasMatrixPaint acmp(canvas, &data.fMatrix, data.fPaint, pic
ture->cullRect()); |
168 | 169 |
169 const SkMatrix initialMatrix = canvas->getTotalMatrix(); | 170 const SkMatrix initialMatrix = canvas->getTotalMatrix(); |
170 | 171 |
171 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe
nderTarget(); | 172 GrDrawContext* dc = data.fCanvas->internal_private_accessTopLayerDra
wContext(); |
172 SkASSERT(rt); | 173 SkASSERT(dc); |
173 | 174 |
174 // Find the layers required by this canvas. It will return atlased | 175 // Find the layers required by this canvas. It will return atlased |
175 // layers in the 'recycled' list since they have already been drawn. | 176 // layers in the 'recycled' list since they have already been drawn. |
176 GrLayerHoister::FindLayersToHoist(context, picture, initialMatrix, | 177 GrLayerHoister::FindLayersToHoist(context, picture, initialMatrix, |
177 clipBounds, &needRendering, &recyc
led, | 178 clipBounds, &needRendering, &recyc
led, |
178 rt->numColorSamples()); | 179 dc->numColorSamples()); |
179 | 180 |
180 GrLayerHoister::DrawLayers(context, needRendering); | 181 GrLayerHoister::DrawLayers(context, needRendering); |
181 | 182 |
182 // Render the entire picture using new layers | 183 // Render the entire picture using new layers |
183 GrRecordReplaceDraw(picture, canvas, context->getLayerCache(), | 184 GrRecordReplaceDraw(picture, canvas, context->getLayerCache(), |
184 initialMatrix, nullptr); | 185 initialMatrix, nullptr); |
185 | 186 |
186 GrLayerHoister::UnlockLayers(context, needRendering); | 187 GrLayerHoister::UnlockLayers(context, needRendering); |
187 GrLayerHoister::UnlockLayers(context, recycled); | 188 GrLayerHoister::UnlockLayers(context, recycled); |
188 | 189 |
189 needRendering.rewind(); | 190 needRendering.rewind(); |
190 recycled.rewind(); | 191 recycled.rewind(); |
191 } else | 192 } else |
192 #endif | 193 #endif |
193 { | 194 { |
194 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); | 195 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); |
195 } | 196 } |
196 if (flush) { | 197 if (flush) { |
197 canvas->flush(); | 198 canvas->flush(); |
198 } | 199 } |
199 } | 200 } |
200 | 201 |
201 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU | 202 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU |
202 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); | 203 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); |
203 GrLayerHoister::UnlockLayers(context, atlasedRecycled); | 204 GrLayerHoister::UnlockLayers(context, atlasedRecycled); |
204 GrLayerHoister::End(context); | 205 GrLayerHoister::End(context); |
205 #endif | 206 #endif |
206 } | 207 } |
OLD | NEW |