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 "SkPictureRangePlayback.h" | 10 #include "SkPictureRangePlayback.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 | 13 |
14 // Return true if any layers are suitable for hoisting | 14 // Return true if any layers are suitable for hoisting |
15 bool GrLayerHoister::FindLayersToHoist(const GrAccelData *gpuData, | 15 bool GrLayerHoister::FindLayersToHoist(const GrAccelData *gpuData, |
16 const SkPicture::OperationList* ops, | |
17 const SkRect& query, | 16 const SkRect& query, |
18 bool pullForward[]) { | 17 bool pullForward[]) { |
19 bool anyHoisted = false; | 18 bool anyHoisted = false; |
20 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | |
21 pullForward[i] = false; | |
22 } | |
23 | 19 |
24 // Layer hoisting pre-renders the entire layer since it will be cached and p
otentially | 20 // Layer hoisting pre-renders the entire layer since it will be cached and p
otentially |
25 // reused with different clips (e.g., in different tiles). Because of this t
he | 21 // reused with different clips (e.g., in different tiles). Because of this t
he |
26 // clip will not be limiting the size of the pre-rendered layer. kSaveLayerM
axSize | 22 // clip will not be limiting the size of the pre-rendered layer. kSaveLayerM
axSize |
27 // is used to limit which clips are pre-rendered. | 23 // is used to limit which clips are pre-rendered. |
28 static const int kSaveLayerMaxSize = 256; | 24 static const int kSaveLayerMaxSize = 256; |
29 | 25 |
30 if (NULL != ops) { | 26 // Pre-render all the layers that intersect the query rect |
31 // In this case the picture has been generated with a BBH so we use | 27 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
32 // the BBH to limit the pre-rendering to just the layers needed to cover | 28 pullForward[i] = false; |
33 // the region being drawn | |
34 for (int i = 0; i < ops->numOps(); ++i) { | |
35 uint32_t offset = ops->offset(i); | |
36 | 29 |
37 // For now we're saving all the layers in the GrAccelData so they | 30 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
38 // can be nested. Additionally, the nested layers appear before | |
39 // their parent in the list. | |
40 for (int j = 0; j < gpuData->numSaveLayers(); ++j) { | |
41 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(
j); | |
42 | 31 |
43 if (pullForward[j]) { | 32 SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX), |
44 continue; // already pulling forward | 33 SkIntToScalar(info.fOffset.fY), |
45 } | 34 SkIntToScalar(info.fSize.fWidth), |
| 35 SkIntToScalar(info.fSize.fHeight)); |
46 | 36 |
47 if (offset < info.fSaveLayerOpID || offset > info.fRestoreOpID)
{ | 37 if (!SkRect::Intersects(query, layerRect)) { |
48 continue; // the op isn't in this range | 38 continue; |
49 } | 39 } |
50 | 40 |
51 // TODO: once this code is more stable unsuitable layers can | 41 // TODO: once this code is more stable unsuitable layers can |
52 // just be omitted during the optimization stage | 42 // just be omitted during the optimization stage |
53 if (!info.fValid || | 43 if (!info.fValid || |
54 kSaveLayerMaxSize < info.fSize.fWidth || | 44 kSaveLayerMaxSize < info.fSize.fWidth || |
55 kSaveLayerMaxSize < info.fSize.fHeight || | 45 kSaveLayerMaxSize < info.fSize.fHeight || |
56 info.fIsNested) { | 46 info.fIsNested) { |
57 continue; // this layer is unsuitable | 47 continue; |
58 } | 48 } |
59 | 49 |
60 pullForward[j] = true; | 50 pullForward[i] = true; |
61 anyHoisted = true; | 51 anyHoisted = true; |
62 } | |
63 } | |
64 } else { | |
65 // In this case there is no BBH associated with the picture. Pre-render | |
66 // all the layers that intersect the drawn region | |
67 for (int j = 0; j < gpuData->numSaveLayers(); ++j) { | |
68 const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(j); | |
69 | |
70 SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX), | |
71 SkIntToScalar(info.fOffset.fY), | |
72 SkIntToScalar(info.fSize.fWidth)
, | |
73 SkIntToScalar(info.fSize.fHeight
)); | |
74 | |
75 if (!SkRect::Intersects(query, layerRect)) { | |
76 continue; | |
77 } | |
78 | |
79 // TODO: once this code is more stable unsuitable layers can | |
80 // just be omitted during the optimization stage | |
81 if (!info.fValid || | |
82 kSaveLayerMaxSize < info.fSize.fWidth || | |
83 kSaveLayerMaxSize < info.fSize.fHeight || | |
84 info.fIsNested) { | |
85 continue; | |
86 } | |
87 | |
88 pullForward[j] = true; | |
89 anyHoisted = true; | |
90 } | |
91 } | 52 } |
92 | 53 |
93 return anyHoisted; | 54 return anyHoisted; |
94 } | 55 } |
95 | 56 |
96 void GrLayerHoister::DrawLayers(const SkPicture* picture, | 57 void GrLayerHoister::DrawLayers(const SkPicture* picture, |
97 const SkTDArray<GrCachedLayer*>& atlased, | 58 const SkTDArray<GrCachedLayer*>& atlased, |
98 const SkTDArray<GrCachedLayer*>& nonAtlased) { | 59 const SkTDArray<GrCachedLayer*>& nonAtlased) { |
99 // Render the atlased layers that require it | 60 // Render the atlased layers that require it |
100 if (atlased.count() > 0) { | 61 if (atlased.count() > 0) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 #if DISABLE_CACHING | 162 #if DISABLE_CACHING |
202 // This code completely clears out the atlas. It is required when | 163 // This code completely clears out the atlas. It is required when |
203 // caching is disabled so the atlas doesn't fill up and force more | 164 // caching is disabled so the atlas doesn't fill up and force more |
204 // free floating layers | 165 // free floating layers |
205 layerCache->purge(picture->uniqueID()); | 166 layerCache->purge(picture->uniqueID()); |
206 | 167 |
207 layerCache->purgeAll(); | 168 layerCache->purgeAll(); |
208 #endif | 169 #endif |
209 } | 170 } |
210 | 171 |
OLD | NEW |