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 #include "GrLayerCache.h" | 8 #include "GrLayerCache.h" |
9 #include "GrLayerHoister.h" | 9 #include "GrLayerHoister.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkRecordDraw.h" | 11 #include "SkRecordDraw.h" |
12 #include "GrRecordReplaceDraw.h" | 12 #include "GrRecordReplaceDraw.h" |
13 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
14 #include "SkSurface.h" | 14 #include "SkSurface.h" |
15 | 15 |
16 // Return true if any layers are suitable for hoisting | 16 // Return true if any layers are suitable for hoisting |
17 bool GrLayerHoister::FindLayersToHoist(const SkPicture* topLevelPicture, | 17 bool GrLayerHoister::FindLayersToHoist(const SkPicture* topLevelPicture, |
18 const SkRect& query, | 18 const SkRect& query, |
19 SkTDArray<HoistedLayer>* atlased, | 19 SkTDArray<HoistedLayer>* atlased, |
20 SkTDArray<HoistedLayer>* nonAtlased, | 20 SkTDArray<HoistedLayer>* nonAtlased, |
| 21 SkTDArray<HoistedLayer>* recycled, |
21 GrLayerCache* layerCache) { | 22 GrLayerCache* layerCache) { |
22 bool anyHoisted = false; | 23 bool anyHoisted = false; |
23 | 24 |
24 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 25 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
25 | 26 |
26 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 27 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
27 if (NULL == topLevelData) { | 28 if (NULL == topLevelData) { |
28 return false; | 29 return false; |
29 } | 30 } |
30 | 31 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 desc.fHeight = info.fSize.fHeight; | 95 desc.fHeight = info.fSize.fHeight; |
95 desc.fConfig = kSkia8888_GrPixelConfig; | 96 desc.fConfig = kSkia8888_GrPixelConfig; |
96 // TODO: need to deal with sample count | 97 // TODO: need to deal with sample count |
97 | 98 |
98 bool needsRendering = layerCache->lock(layer, desc, | 99 bool needsRendering = layerCache->lock(layer, desc, |
99 info.fHasNestedLayers || info
.fIsNested); | 100 info.fHasNestedLayers || info
.fIsNested); |
100 if (NULL == layer->texture()) { | 101 if (NULL == layer->texture()) { |
101 continue; | 102 continue; |
102 } | 103 } |
103 | 104 |
| 105 HoistedLayer* hl; |
| 106 |
104 if (needsRendering) { | 107 if (needsRendering) { |
105 HoistedLayer* hl; | |
106 | |
107 if (layer->isAtlased()) { | 108 if (layer->isAtlased()) { |
108 hl = atlased->append(); | 109 hl = atlased->append(); |
109 } else { | 110 } else { |
110 hl = nonAtlased->append(); | 111 hl = nonAtlased->append(); |
111 } | 112 } |
112 | 113 } else { |
113 hl->fLayer = layer; | 114 hl = recycled->append(); |
114 hl->fPicture = pict; | |
115 hl->fOffset = info.fOffset; | |
116 hl->fCTM = info.fOriginXform; | |
117 } | 115 } |
| 116 |
| 117 hl->fLayer = layer; |
| 118 hl->fPicture = pict; |
| 119 hl->fOffset = info.fOffset; |
| 120 hl->fCTM = info.fOriginXform; |
118 } | 121 } |
119 } | 122 } |
120 | 123 |
121 return anyHoisted; | 124 return anyHoisted; |
122 } | 125 } |
123 | 126 |
124 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 127 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
125 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 128 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
126 result->setInfo(info); | 129 result->setInfo(info); |
127 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 130 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
(...skipping 25 matching lines...) Expand all Loading... |
153 | 156 |
154 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].fLayer->rect().fLeft, | 157 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].fLayer->rect().fLeft, |
155 layers[i].fLayer->rect().fTop, | 158 layers[i].fLayer->rect().fTop, |
156 layers[i].fLayer->rect().width()
, | 159 layers[i].fLayer->rect().width()
, |
157 layers[i].fLayer->rect().height(
)); | 160 layers[i].fLayer->rect().height(
)); |
158 } | 161 } |
159 } | 162 } |
160 | 163 |
161 void GrLayerHoister::DrawLayers(const SkTDArray<HoistedLayer>& atlased, | 164 void GrLayerHoister::DrawLayers(const SkTDArray<HoistedLayer>& atlased, |
162 const SkTDArray<HoistedLayer>& nonAtlased, | 165 const SkTDArray<HoistedLayer>& nonAtlased, |
| 166 const SkTDArray<HoistedLayer>& recycled, |
163 GrReplacements* replacements) { | 167 GrReplacements* replacements) { |
164 // Render the atlased layers that require it | 168 // Render the atlased layers that require it |
165 if (atlased.count() > 0) { | 169 if (atlased.count() > 0) { |
166 // All the atlased layers are rendered into the same GrTexture | 170 // All the atlased layers are rendered into the same GrTexture |
167 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( | 171 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
168 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); | 172 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); |
169 | 173 |
170 SkCanvas* atlasCanvas = surface->getCanvas(); | 174 SkCanvas* atlasCanvas = surface->getCanvas(); |
171 | 175 |
172 SkPaint paint; | 176 SkPaint paint; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 layerCanvas->concat(nonAtlased[i].fCTM); | 250 layerCanvas->concat(nonAtlased[i].fCTM); |
247 | 251 |
248 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, bound, | 252 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, bound, |
249 layer->start()+1, layer->stop(), initialCTM); | 253 layer->start()+1, layer->stop(), initialCTM); |
250 | 254 |
251 layerCanvas->flush(); | 255 layerCanvas->flush(); |
252 } | 256 } |
253 | 257 |
254 convert_layers_to_replacements(atlased, replacements); | 258 convert_layers_to_replacements(atlased, replacements); |
255 convert_layers_to_replacements(nonAtlased, replacements); | 259 convert_layers_to_replacements(nonAtlased, replacements); |
| 260 convert_layers_to_replacements(recycled, replacements); |
256 } | 261 } |
257 | 262 |
258 static void unlock_layer_in_cache(GrLayerCache* layerCache, | 263 static void unlock_layer_in_cache(GrLayerCache* layerCache, |
259 const SkPicture* picture, | 264 const SkPicture* picture, |
260 GrCachedLayer* layer) { | 265 GrCachedLayer* layer) { |
261 layerCache->unlock(layer); | 266 layerCache->unlock(layer); |
262 | 267 |
263 #if DISABLE_CACHING | 268 #if DISABLE_CACHING |
264 // This code completely clears out the atlas. It is required when | 269 // This code completely clears out the atlas. It is required when |
265 // caching is disabled so the atlas doesn't fill up and force more | 270 // caching is disabled so the atlas doesn't fill up and force more |
266 // free floating layers | 271 // free floating layers |
267 layerCache->purge(picture->uniqueID()); | 272 layerCache->purge(picture->uniqueID()); |
268 #endif | 273 #endif |
269 } | 274 } |
270 | 275 |
271 void GrLayerHoister::UnlockLayers(GrLayerCache* layerCache, | 276 void GrLayerHoister::UnlockLayers(GrLayerCache* layerCache, |
272 const SkTDArray<HoistedLayer>& atlased, | 277 const SkTDArray<HoistedLayer>& atlased, |
273 const SkTDArray<HoistedLayer>& nonAtlased) { | 278 const SkTDArray<HoistedLayer>& nonAtlased, |
| 279 const SkTDArray<HoistedLayer>& recycled) { |
274 | 280 |
275 for (int i = 0; i < atlased.count(); ++i) { | 281 for (int i = 0; i < atlased.count(); ++i) { |
276 unlock_layer_in_cache(layerCache, atlased[i].fPicture, atlased[i].fLayer
); | 282 unlock_layer_in_cache(layerCache, atlased[i].fPicture, atlased[i].fLayer
); |
277 } | 283 } |
278 | 284 |
279 for (int i = 0; i < nonAtlased.count(); ++i) { | 285 for (int i = 0; i < nonAtlased.count(); ++i) { |
280 unlock_layer_in_cache(layerCache, nonAtlased[i].fPicture, nonAtlased[i].
fLayer); | 286 unlock_layer_in_cache(layerCache, nonAtlased[i].fPicture, nonAtlased[i].
fLayer); |
281 } | 287 } |
282 | 288 |
| 289 for (int i = 0; i < recycled.count(); ++i) { |
| 290 unlock_layer_in_cache(layerCache, recycled[i].fPicture, recycled[i].fLay
er); |
| 291 } |
| 292 |
283 #if DISABLE_CACHING | 293 #if DISABLE_CACHING |
284 // This code completely clears out the atlas. It is required when | 294 // This code completely clears out the atlas. It is required when |
285 // caching is disabled so the atlas doesn't fill up and force more | 295 // caching is disabled so the atlas doesn't fill up and force more |
286 // free floating layers | 296 // free floating layers |
287 layerCache->purgeAll(); | 297 layerCache->purgeAll(); |
288 #endif | 298 #endif |
289 } | 299 } |
290 | 300 |
OLD | NEW |