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 "SkLayerInfo.h" | 14 #include "SkLayerInfo.h" |
15 #include "SkRecordDraw.h" | 15 #include "SkRecordDraw.h" |
16 #include "SkSurface.h" | 16 #include "SkSurface.h" |
17 | 17 |
18 // Create the layer information for the hoisted layer and secure the | 18 // Create the layer information for the hoisted layer and secure the |
19 // required texture/render target resources. | 19 // required texture/render target resources. |
20 static void prepare_for_hoisting(GrLayerCache* layerCache, | 20 static void prepare_for_hoisting(GrLayerCache* layerCache, |
21 const SkPicture* topLevelPicture, | 21 const SkPicture* topLevelPicture, |
22 const SkMatrix& matrix, | 22 const SkMatrix& initialMat, |
23 const SkLayerInfo::BlockInfo& info, | 23 const SkLayerInfo::BlockInfo& info, |
24 const SkIRect& layerRect, | 24 const SkIRect& layerRect, |
25 SkTDArray<GrHoistedLayer>* needRendering, | 25 SkTDArray<GrHoistedLayer>* needRendering, |
26 SkTDArray<GrHoistedLayer>* recycled, | 26 SkTDArray<GrHoistedLayer>* recycled, |
27 bool attemptToAtlas, | 27 bool attemptToAtlas, |
28 int numSamples) { | 28 int numSamples) { |
29 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; | 29 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; |
30 | 30 |
31 SkMatrix combined = matrix; | 31 GrCachedLayer* layer = layerCache->findLayerOrCreate(topLevelPicture->unique
ID(), |
32 combined.preConcat(info.fPreMat); | |
33 combined.preConcat(info.fLocalMat); | |
34 | |
35 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), | |
36 info.fSaveLayerOpID, | 32 info.fSaveLayerOpID, |
37 info.fRestoreOpID, | 33 info.fRestoreOpID, |
38 layerRect, | 34 layerRect, |
39 combined, | 35 initialMat, |
| 36 info.fKey, |
| 37 info.fKeySize, |
40 info.fPaint); | 38 info.fPaint); |
41 GrSurfaceDesc desc; | 39 GrSurfaceDesc desc; |
42 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 40 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
43 desc.fWidth = layerRect.width(); | 41 desc.fWidth = layerRect.width(); |
44 desc.fHeight = layerRect.height(); | 42 desc.fHeight = layerRect.height(); |
45 desc.fConfig = kSkia8888_GrPixelConfig; | 43 desc.fConfig = kSkia8888_GrPixelConfig; |
46 desc.fSampleCnt = numSamples; | 44 desc.fSampleCnt = numSamples; |
47 | 45 |
48 bool locked, needsRendering; | 46 bool locked, needsRendering; |
49 if (attemptToAtlas) { | 47 if (attemptToAtlas) { |
(...skipping 19 matching lines...) Expand all Loading... |
69 hl = needRendering->append(); | 67 hl = needRendering->append(); |
70 } else { | 68 } else { |
71 hl = recycled->append(); | 69 hl = recycled->append(); |
72 } | 70 } |
73 | 71 |
74 layerCache->addUse(layer); | 72 layerCache->addUse(layer); |
75 hl->fLayer = layer; | 73 hl->fLayer = layer; |
76 hl->fPicture = pict; | 74 hl->fPicture = pict; |
77 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop); | 75 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop); |
78 hl->fLocalMat = info.fLocalMat; | 76 hl->fLocalMat = info.fLocalMat; |
79 hl->fPreMat = matrix; | 77 hl->fInitialMat = initialMat; |
| 78 hl->fPreMat = initialMat; |
80 hl->fPreMat.preConcat(info.fPreMat); | 79 hl->fPreMat.preConcat(info.fPreMat); |
81 } | 80 } |
82 | 81 |
83 // Atlased layers must be small enough to fit in the atlas, not have a | 82 // Atlased layers must be small enough to fit in the atlas, not have a |
84 // paint with an image filter and be neither nested nor nesting. | 83 // paint with an image filter and be neither nested nor nesting. |
85 // TODO: allow leaf nested layers to appear in the atlas. | 84 // TODO: allow leaf nested layers to appear in the atlas. |
86 void GrLayerHoister::FindLayersToAtlas(GrContext* context, | 85 void GrLayerHoister::FindLayersToAtlas(GrContext* context, |
87 const SkPicture* topLevelPicture, | 86 const SkPicture* topLevelPicture, |
88 const SkMatrix& initialMat, | 87 const SkMatrix& initialMat, |
89 const SkRect& query, | 88 const SkRect& query, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 needRendering, recycled, false, numSamples); | 184 needRendering, recycled, false, numSamples); |
186 } | 185 } |
187 } | 186 } |
188 | 187 |
189 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 188 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
190 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 189 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
191 result->setInfo(info); | 190 result->setInfo(info); |
192 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 191 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
193 } | 192 } |
194 | 193 |
195 void GrLayerHoister::ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>
& layers, | 194 void GrLayerHoister::ConvertLayersToReplacements(const SkPicture* topLevelPictur
e, |
| 195 const SkTDArray<GrHoistedLayer>
& layers, |
196 GrReplacements* replacements) { | 196 GrReplacements* replacements) { |
197 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? | 197 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? |
198 for (int i = 0; i < layers.count(); ++i) { | 198 for (int i = 0; i < layers.count(); ++i) { |
199 GrCachedLayer* layer = layers[i].fLayer; | 199 GrCachedLayer* layer = layers[i].fLayer; |
200 const SkPicture* picture = layers[i].fPicture; | |
201 | |
202 SkMatrix combined = SkMatrix::Concat(layers[i].fPreMat, layers[i].fLocal
Mat); | |
203 | 200 |
204 GrReplacements::ReplacementInfo* layerInfo = | 201 GrReplacements::ReplacementInfo* layerInfo = |
205 replacements->newReplacement(picture->uniqueID(), | 202 replacements->newReplacement(topLevelPicture->uniqueID(), |
206 layer->start(), | 203 layers[i].fInitialMat, |
207 combined); | 204 layer->key(), layer->keySize())
; |
208 layerInfo->fStop = layer->stop(); | 205 layerInfo->fStop = layer->stop(); |
209 layerInfo->fPos = layers[i].fOffset; | 206 layerInfo->fPos = layers[i].fOffset; |
210 | 207 |
211 SkBitmap bm; | 208 SkBitmap bm; |
212 wrap_texture(layers[i].fLayer->texture(), | 209 wrap_texture(layers[i].fLayer->texture(), |
213 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().w
idth() | 210 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().w
idth() |
214 : layers[i].fLayer->texture(
)->width(), | 211 : layers[i].fLayer->texture(
)->width(), |
215 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().h
eight() | 212 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().h
eight() |
216 : layers[i].fLayer->texture(
)->height(), | 213 : layers[i].fLayer->texture(
)->height(), |
217 &bm); | 214 &bm); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 void GrLayerHoister::PurgeCache(GrContext* context) { | 335 void GrLayerHoister::PurgeCache(GrContext* context) { |
339 #if !GR_CACHE_HOISTED_LAYERS | 336 #if !GR_CACHE_HOISTED_LAYERS |
340 GrLayerCache* layerCache = context->getLayerCache(); | 337 GrLayerCache* layerCache = context->getLayerCache(); |
341 | 338 |
342 // This code completely clears out the atlas. It is required when | 339 // This code completely clears out the atlas. It is required when |
343 // caching is disabled so the atlas doesn't fill up and force more | 340 // caching is disabled so the atlas doesn't fill up and force more |
344 // free floating layers | 341 // free floating layers |
345 layerCache->purgeAll(); | 342 layerCache->purgeAll(); |
346 #endif | 343 #endif |
347 } | 344 } |
OLD | NEW |