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" | 10 #include "GrRecordReplaceDraw.h" |
11 | 11 |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
14 #include "SkRecordDraw.h" | 14 #include "SkRecordDraw.h" |
15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
16 | 16 |
17 // Create the layer information for the hoisted layer and secure the | 17 // Create the layer information for the hoisted layer and secure the |
18 // required texture/render target resources. | 18 // required texture/render target resources. |
19 static void prepare_for_hoisting(GrLayerCache* layerCache, | 19 static void prepare_for_hoisting(GrLayerCache* layerCache, |
20 const SkPicture* topLevelPicture, | 20 const SkPicture* topLevelPicture, |
21 const GrAccelData::SaveLayerInfo& info, | 21 const GrAccelData::SaveLayerInfo& info, |
22 const SkIRect& layerRect, | 22 const SkIRect& layerRect, |
23 SkTDArray<GrHoistedLayer>* needRendering, | 23 SkTDArray<GrHoistedLayer>* needRendering, |
24 SkTDArray<GrHoistedLayer>* recycled, | 24 SkTDArray<GrHoistedLayer>* recycled, |
25 bool attemptToAtlas) { | 25 bool attemptToAtlas, |
| 26 int numSamples) { |
26 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; | 27 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; |
27 | 28 |
28 SkMatrix combined = SkMatrix::Concat(info.fPreMat, info.fLocalMat); | 29 SkMatrix combined = SkMatrix::Concat(info.fPreMat, info.fLocalMat); |
29 | 30 |
30 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), | 31 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), |
31 info.fSaveLayerOpID, | 32 info.fSaveLayerOpID, |
32 info.fRestoreOpID, | 33 info.fRestoreOpID, |
33 layerRect, | 34 layerRect, |
34 combined, | 35 combined, |
35 info.fPaint); | 36 info.fPaint); |
36 GrSurfaceDesc desc; | 37 GrSurfaceDesc desc; |
37 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 38 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
38 desc.fWidth = layerRect.width(); | 39 desc.fWidth = layerRect.width(); |
39 desc.fHeight = layerRect.height(); | 40 desc.fHeight = layerRect.height(); |
40 desc.fConfig = kSkia8888_GrPixelConfig; | 41 desc.fConfig = kSkia8888_GrPixelConfig; |
41 // TODO: need to deal with sample count | 42 desc.fSampleCnt = numSamples; |
42 | 43 |
43 bool locked, needsRendering; | 44 bool locked, needsRendering; |
44 if (attemptToAtlas) { | 45 if (attemptToAtlas) { |
45 locked = layerCache->tryToAtlas(layer, desc, &needsRendering); | 46 locked = layerCache->tryToAtlas(layer, desc, &needsRendering); |
46 } else { | 47 } else { |
47 locked = layerCache->lock(layer, desc, &needsRendering); | 48 locked = layerCache->lock(layer, desc, &needsRendering); |
48 } | 49 } |
49 if (!locked) { | 50 if (!locked) { |
50 // GPU resources could not be secured for the hoisting of this layer | 51 // GPU resources could not be secured for the hoisting of this layer |
51 return; | 52 return; |
(...skipping 22 matching lines...) Expand all Loading... |
74 hl->fPreMat = info.fPreMat; | 75 hl->fPreMat = info.fPreMat; |
75 } | 76 } |
76 | 77 |
77 // Atlased layers must be small enough to fit in the atlas, not have a | 78 // Atlased layers must be small enough to fit in the atlas, not have a |
78 // paint with an image filter and be neither nested nor nesting. | 79 // paint with an image filter and be neither nested nor nesting. |
79 // TODO: allow leaf nested layers to appear in the atlas. | 80 // TODO: allow leaf nested layers to appear in the atlas. |
80 void GrLayerHoister::FindLayersToAtlas(GrContext* context, | 81 void GrLayerHoister::FindLayersToAtlas(GrContext* context, |
81 const SkPicture* topLevelPicture, | 82 const SkPicture* topLevelPicture, |
82 const SkRect& query, | 83 const SkRect& query, |
83 SkTDArray<GrHoistedLayer>* atlased, | 84 SkTDArray<GrHoistedLayer>* atlased, |
84 SkTDArray<GrHoistedLayer>* recycled) { | 85 SkTDArray<GrHoistedLayer>* recycled, |
| 86 int numSamples) { |
| 87 if (0 != numSamples) { |
| 88 // MSAA layers are currently never atlased |
| 89 return; |
| 90 } |
| 91 |
85 GrLayerCache* layerCache = context->getLayerCache(); | 92 GrLayerCache* layerCache = context->getLayerCache(); |
86 | 93 |
87 layerCache->processDeletedPictures(); | 94 layerCache->processDeletedPictures(); |
88 | 95 |
89 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 96 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
90 | 97 |
91 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 98 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
92 if (!topLevelData) { | 99 if (!topLevelData) { |
93 return; | 100 return; |
94 } | 101 } |
(...skipping 21 matching lines...) Expand all Loading... |
116 continue; | 123 continue; |
117 } | 124 } |
118 | 125 |
119 SkIRect ir; | 126 SkIRect ir; |
120 layerRect.roundOut(&ir); | 127 layerRect.roundOut(&ir); |
121 | 128 |
122 if (!GrLayerCache::PlausiblyAtlasable(ir.width(), ir.height())) { | 129 if (!GrLayerCache::PlausiblyAtlasable(ir.width(), ir.height())) { |
123 continue; | 130 continue; |
124 } | 131 } |
125 | 132 |
126 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, rec
ycled, true); | 133 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, rec
ycled, true, 0); |
127 } | 134 } |
128 | 135 |
129 } | 136 } |
130 | 137 |
131 void GrLayerHoister::FindLayersToHoist(GrContext* context, | 138 void GrLayerHoister::FindLayersToHoist(GrContext* context, |
132 const SkPicture* topLevelPicture, | 139 const SkPicture* topLevelPicture, |
133 const SkRect& query, | 140 const SkRect& query, |
134 SkTDArray<GrHoistedLayer>* needRendering, | 141 SkTDArray<GrHoistedLayer>* needRendering, |
135 SkTDArray<GrHoistedLayer>* recycled) { | 142 SkTDArray<GrHoistedLayer>* recycled, |
| 143 int numSamples) { |
136 GrLayerCache* layerCache = context->getLayerCache(); | 144 GrLayerCache* layerCache = context->getLayerCache(); |
137 | 145 |
138 layerCache->processDeletedPictures(); | 146 layerCache->processDeletedPictures(); |
139 | 147 |
140 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 148 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
141 | 149 |
142 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 150 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
143 if (!topLevelData) { | 151 if (!topLevelData) { |
144 return; | 152 return; |
145 } | 153 } |
(...skipping 13 matching lines...) Expand all Loading... |
159 | 167 |
160 SkRect layerRect = info.fBounds; | 168 SkRect layerRect = info.fBounds; |
161 if (!layerRect.intersect(query)) { | 169 if (!layerRect.intersect(query)) { |
162 continue; | 170 continue; |
163 } | 171 } |
164 | 172 |
165 SkIRect ir; | 173 SkIRect ir; |
166 layerRect.roundOut(&ir); | 174 layerRect.roundOut(&ir); |
167 | 175 |
168 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, | 176 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, |
169 needRendering, recycled, false); | 177 needRendering, recycled, false, numSamples); |
170 } | 178 } |
171 } | 179 } |
172 | 180 |
173 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 181 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
174 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 182 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
175 result->setInfo(info); | 183 result->setInfo(info); |
176 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 184 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
177 } | 185 } |
178 | 186 |
179 void GrLayerHoister::ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>
& layers, | 187 void GrLayerHoister::ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>
& layers, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 void GrLayerHoister::PurgeCache(GrContext* context) { | 328 void GrLayerHoister::PurgeCache(GrContext* context) { |
321 #if !GR_CACHE_HOISTED_LAYERS | 329 #if !GR_CACHE_HOISTED_LAYERS |
322 GrLayerCache* layerCache = context->getLayerCache(); | 330 GrLayerCache* layerCache = context->getLayerCache(); |
323 | 331 |
324 // This code completely clears out the atlas. It is required when | 332 // This code completely clears out the atlas. It is required when |
325 // caching is disabled so the atlas doesn't fill up and force more | 333 // caching is disabled so the atlas doesn't fill up and force more |
326 // free floating layers | 334 // free floating layers |
327 layerCache->purgeAll(); | 335 layerCache->purgeAll(); |
328 #endif | 336 #endif |
329 } | 337 } |
OLD | NEW |