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 "GrRecordReplaceDraw.h" |
| 11 |
10 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkGrPixelRef.h" |
11 #include "SkRecordDraw.h" | 14 #include "SkRecordDraw.h" |
12 #include "GrRecordReplaceDraw.h" | |
13 #include "SkGrPixelRef.h" | |
14 #include "SkSurface.h" | 15 #include "SkSurface.h" |
15 | 16 |
16 // Create the layer information for the hoisted layer and secure the | 17 // Create the layer information for the hoisted layer and secure the |
17 // required texture/render target resources. | 18 // required texture/render target resources. |
18 static void prepare_for_hoisting(GrLayerCache* layerCache, | 19 static void prepare_for_hoisting(GrLayerCache* layerCache, |
19 const SkPicture* topLevelPicture, | 20 const SkPicture* topLevelPicture, |
20 const GrAccelData::SaveLayerInfo& info, | 21 const GrAccelData::SaveLayerInfo& info, |
| 22 const SkIRect& layerRect, |
21 SkTDArray<GrHoistedLayer>* atlased, | 23 SkTDArray<GrHoistedLayer>* atlased, |
22 SkTDArray<GrHoistedLayer>* nonAtlased, | 24 SkTDArray<GrHoistedLayer>* nonAtlased, |
23 SkTDArray<GrHoistedLayer>* recycled) { | 25 SkTDArray<GrHoistedLayer>* recycled) { |
24 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; | 26 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; |
25 | 27 |
26 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), | 28 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), |
27 info.fSaveLayerOpID, | 29 info.fSaveLayerOpID, |
28 info.fRestoreOpID, | 30 info.fRestoreOpID, |
| 31 layerRect, |
29 info.fOriginXform, | 32 info.fOriginXform, |
30 info.fPaint); | 33 info.fPaint); |
31 | 34 |
32 GrTextureDesc desc; | 35 GrTextureDesc desc; |
33 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 36 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
34 desc.fWidth = info.fSize.fWidth; | 37 desc.fWidth = layerRect.width(); |
35 desc.fHeight = info.fSize.fHeight; | 38 desc.fHeight = layerRect.height(); |
36 desc.fConfig = kSkia8888_GrPixelConfig; | 39 desc.fConfig = kSkia8888_GrPixelConfig; |
37 // TODO: need to deal with sample count | 40 // TODO: need to deal with sample count |
38 | 41 |
39 bool needsRendering = layerCache->lock(layer, desc, info.fHasNestedLayers ||
info.fIsNested); | 42 |
| 43 bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested || |
| 44 (layer->paint() && layer->paint()->getImageFilter())
; |
| 45 |
| 46 bool needsRendering = layerCache->lock(layer, desc, disallowAtlasing); |
40 if (NULL == layer->texture()) { | 47 if (NULL == layer->texture()) { |
41 // GPU resources could not be secured for the hoisting of this layer | 48 // GPU resources could not be secured for the hoisting of this layer |
42 return; | 49 return; |
43 } | 50 } |
44 | 51 |
45 GrHoistedLayer* hl; | 52 GrHoistedLayer* hl; |
46 | 53 |
47 if (needsRendering) { | 54 if (needsRendering) { |
48 if (layer->isAtlased()) { | 55 if (layer->isAtlased()) { |
49 hl = atlased->append(); | 56 hl = atlased->append(); |
50 } else { | 57 } else { |
51 hl = nonAtlased->append(); | 58 hl = nonAtlased->append(); |
52 } | 59 } |
53 } else { | 60 } else { |
54 hl = recycled->append(); | 61 hl = recycled->append(); |
55 } | 62 } |
56 | 63 |
57 layerCache->addUse(layer); | 64 layerCache->addUse(layer); |
58 hl->fLayer = layer; | 65 hl->fLayer = layer; |
59 hl->fPicture = pict; | 66 hl->fPicture = pict; |
60 hl->fOffset = info.fOffset; | 67 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop); |
61 hl->fCTM = info.fOriginXform; | 68 hl->fCTM = info.fOriginXform; |
62 } | 69 } |
63 | 70 |
64 // Return true if any layers are suitable for hoisting | 71 // Return true if any layers are suitable for hoisting |
65 bool GrLayerHoister::FindLayersToHoist(GrContext* context, | 72 bool GrLayerHoister::FindLayersToHoist(GrContext* context, |
66 const SkPicture* topLevelPicture, | 73 const SkPicture* topLevelPicture, |
67 const SkRect& query, | 74 const SkRect& query, |
68 SkTDArray<GrHoistedLayer>* atlased, | 75 SkTDArray<GrHoistedLayer>* atlased, |
69 SkTDArray<GrHoistedLayer>* nonAtlased, | 76 SkTDArray<GrHoistedLayer>* nonAtlased, |
70 SkTDArray<GrHoistedLayer>* recycled) { | 77 SkTDArray<GrHoistedLayer>* recycled) { |
71 | |
72 GrLayerCache* layerCache = context->getLayerCache(); | 78 GrLayerCache* layerCache = context->getLayerCache(); |
73 | 79 |
74 layerCache->processDeletedPictures(); | 80 layerCache->processDeletedPictures(); |
75 | 81 |
76 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 82 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
77 | 83 |
78 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 84 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
79 if (!topLevelData) { | 85 if (!topLevelData) { |
80 return false; | 86 return false; |
81 } | 87 } |
(...skipping 13 matching lines...) Expand all Loading... |
95 // Parent layers are hoisted but are never atlased (so that we never swap | 101 // Parent layers are hoisted but are never atlased (so that we never swap |
96 // away from the atlas rendertarget when generating the hoisted layers). | 102 // away from the atlas rendertarget when generating the hoisted layers). |
97 | 103 |
98 atlased->setReserve(atlased->count() + topLevelGPUData->numSaveLayers()); | 104 atlased->setReserve(atlased->count() + topLevelGPUData->numSaveLayers()); |
99 | 105 |
100 // Find and prepare for hoisting all the layers that intersect the query rec
t | 106 // Find and prepare for hoisting all the layers that intersect the query rec
t |
101 for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) { | 107 for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) { |
102 | 108 |
103 const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(
i); | 109 const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(
i); |
104 | 110 |
105 SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX), | 111 SkRect layerRect = SkRect::Make(info.fBounds); |
106 SkIntToScalar(info.fOffset.fY), | 112 if (!layerRect.intersect(query)) { |
107 SkIntToScalar(info.fSize.fWidth), | |
108 SkIntToScalar(info.fSize.fHeight)); | |
109 | |
110 if (!SkRect::Intersects(query, layerRect)) { | |
111 continue; | 113 continue; |
112 } | 114 } |
113 | 115 |
| 116 |
| 117 SkIRect ir; |
| 118 layerRect.roundOut(&ir); |
| 119 |
114 // TODO: ignore perspective projected layers here! | 120 // TODO: ignore perspective projected layers here! |
115 // TODO: once this code is more stable unsuitable layers can | 121 // TODO: once this code is more stable unsuitable layers can |
116 // just be omitted during the optimization stage | 122 // just be omitted during the optimization stage |
117 if (info.fIsNested) { | 123 if (info.fIsNested) { |
118 continue; | 124 continue; |
119 } | 125 } |
120 | 126 |
121 prepare_for_hoisting(layerCache, topLevelPicture, info, atlased, nonAtla
sed, recycled); | 127 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, non
Atlased, recycled); |
122 anyHoisted = true; | 128 anyHoisted = true; |
123 } | 129 } |
124 | 130 |
125 return anyHoisted; | 131 return anyHoisted; |
126 } | 132 } |
127 | 133 |
128 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 134 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
129 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 135 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
130 result->setInfo(info); | 136 result->setInfo(info); |
131 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 137 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 #if DISABLE_CACHING | 291 #if DISABLE_CACHING |
286 // This code completely clears out the atlas. It is required when | 292 // This code completely clears out the atlas. It is required when |
287 // caching is disabled so the atlas doesn't fill up and force more | 293 // caching is disabled so the atlas doesn't fill up and force more |
288 // free floating layers | 294 // free floating layers |
289 layerCache->purgeAll(); | 295 layerCache->purgeAll(); |
290 #endif | 296 #endif |
291 | 297 |
292 SkDEBUGCODE(layerCache->validate();) | 298 SkDEBUGCODE(layerCache->validate();) |
293 } | 299 } |
294 | 300 |
OLD | NEW |