blob: c39aa2007f9294bd31365906e1b454c32b9fdc62 [file] [log] [blame]
robertphillips98d709b2014-09-02 10:20:50 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrLayerCache.h"
9#include "GrLayerHoister.h"
robertphillips1c4c5282014-09-18 12:03:15 -070010#include "GrRecordReplaceDraw.h"
robertphillips3aac6e02014-10-20 08:52:40 -070011
mtklein9db912c2015-05-19 11:11:26 -070012#include "SkBigPicture.h"
robertphillips3aac6e02014-10-20 08:52:40 -070013#include "SkCanvas.h"
robertphillips7b9e8a42014-12-11 08:20:31 -080014#include "SkGpuDevice.h"
robertphillips82365912014-11-12 09:32:34 -080015#include "SkLayerInfo.h"
robertphillips3aac6e02014-10-20 08:52:40 -070016#include "SkRecordDraw.h"
robertphillips98d709b2014-09-02 10:20:50 -070017#include "SkSurface.h"
robertphillips7b9e8a42014-12-11 08:20:31 -080018#include "SkSurface_Gpu.h"
robertphillips98d709b2014-09-02 10:20:50 -070019
robertphillipscbe80ca2014-10-09 15:36:06 -070020// Create the layer information for the hoisted layer and secure the
21// required texture/render target resources.
mtklein9db912c2015-05-19 11:11:26 -070022static void prepare_for_hoisting(GrLayerCache* layerCache,
robertphillips232f6b02014-10-09 16:43:42 -070023 const SkPicture* topLevelPicture,
robertphillips01d6e5f2014-12-01 09:09:27 -080024 const SkMatrix& initialMat,
robertphillips82365912014-11-12 09:32:34 -080025 const SkLayerInfo::BlockInfo& info,
robertphillips478dd722014-12-16 08:25:55 -080026 const SkIRect& srcIR,
27 const SkIRect& dstIR,
robertphillipsfd61ed02014-10-28 07:21:44 -070028 SkTDArray<GrHoistedLayer>* needRendering,
29 SkTDArray<GrHoistedLayer>* recycled,
robertphillipsa63f32e2014-11-10 08:10:42 -080030 bool attemptToAtlas,
31 int numSamples) {
robertphillipscbe80ca2014-10-09 15:36:06 -070032 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture;
33
robertphillips01d6e5f2014-12-01 09:09:27 -080034 GrCachedLayer* layer = layerCache->findLayerOrCreate(topLevelPicture->uniqueID(),
bsalomonfbaace02014-12-12 16:41:46 -080035 SkToInt(info.fSaveLayerOpID),
36 SkToInt(info.fRestoreOpID),
robertphillips478dd722014-12-16 08:25:55 -080037 srcIR,
38 dstIR,
robertphillips01d6e5f2014-12-01 09:09:27 -080039 initialMat,
40 info.fKey,
41 info.fKeySize,
robertphillipscbe80ca2014-10-09 15:36:06 -070042 info.fPaint);
bsalomonf2703d82014-10-28 14:33:06 -070043 GrSurfaceDesc desc;
44 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips478dd722014-12-16 08:25:55 -080045 desc.fWidth = srcIR.width();
46 desc.fHeight = srcIR.height();
robertphillipscbe80ca2014-10-09 15:36:06 -070047 desc.fConfig = kSkia8888_GrPixelConfig;
robertphillipsa63f32e2014-11-10 08:10:42 -080048 desc.fSampleCnt = numSamples;
robertphillipscbe80ca2014-10-09 15:36:06 -070049
robertphillipsfd61ed02014-10-28 07:21:44 -070050 bool locked, needsRendering;
51 if (attemptToAtlas) {
52 locked = layerCache->tryToAtlas(layer, desc, &needsRendering);
53 } else {
54 locked = layerCache->lock(layer, desc, &needsRendering);
55 }
56 if (!locked) {
robertphillipscbe80ca2014-10-09 15:36:06 -070057 // GPU resources could not be secured for the hoisting of this layer
58 return;
59 }
60
robertphillipsfd61ed02014-10-28 07:21:44 -070061 if (attemptToAtlas) {
62 SkASSERT(layer->isAtlased());
63 }
64
robertphillipscbe80ca2014-10-09 15:36:06 -070065 GrHoistedLayer* hl;
66
67 if (needsRendering) {
robertphillipsfd61ed02014-10-28 07:21:44 -070068 if (!attemptToAtlas) {
69 SkASSERT(!layer->isAtlased());
robertphillipscbe80ca2014-10-09 15:36:06 -070070 }
robertphillipsfd61ed02014-10-28 07:21:44 -070071 hl = needRendering->append();
robertphillipscbe80ca2014-10-09 15:36:06 -070072 } else {
73 hl = recycled->append();
74 }
mtklein9db912c2015-05-19 11:11:26 -070075
robertphillips7bb9ed72014-10-10 11:38:29 -070076 layerCache->addUse(layer);
robertphillipscbe80ca2014-10-09 15:36:06 -070077 hl->fLayer = layer;
78 hl->fPicture = pict;
robertphillips9e6835d2014-10-22 05:33:52 -070079 hl->fLocalMat = info.fLocalMat;
robertphillips01d6e5f2014-12-01 09:09:27 -080080 hl->fInitialMat = initialMat;
81 hl->fPreMat = initialMat;
robertphillips30d78412014-11-24 09:49:17 -080082 hl->fPreMat.preConcat(info.fPreMat);
robertphillipscbe80ca2014-10-09 15:36:06 -070083}
84
robertphillips57f192d2015-01-08 10:15:25 -080085// Compute the source rect and return false if it is empty.
robertphillips478dd722014-12-16 08:25:55 -080086static bool compute_source_rect(const SkLayerInfo::BlockInfo& info, const SkMatrix& initialMat,
87 const SkIRect& dstIR, SkIRect* srcIR) {
88 SkIRect clipBounds = dstIR;
89
90 SkMatrix totMat = initialMat;
91 totMat.preConcat(info.fPreMat);
92 totMat.preConcat(info.fLocalMat);
93
94 if (info.fPaint && info.fPaint->getImageFilter()) {
95 info.fPaint->getImageFilter()->filterBounds(clipBounds, totMat, &clipBounds);
96 }
97
98 if (!info.fSrcBounds.isEmpty()) {
99 SkRect r;
100
101 totMat.mapRect(&r, info.fSrcBounds);
102 r.roundOut(srcIR);
103
104 if (!srcIR->intersect(clipBounds)) {
105 return false;
106 }
107 } else {
108 *srcIR = clipBounds;
109 }
110
robertphillips478dd722014-12-16 08:25:55 -0800111 return true;
112}
113
robertphillipsfd61ed02014-10-28 07:21:44 -0700114// Atlased layers must be small enough to fit in the atlas, not have a
115// paint with an image filter and be neither nested nor nesting.
116// TODO: allow leaf nested layers to appear in the atlas.
117void GrLayerHoister::FindLayersToAtlas(GrContext* context,
robertphillipsd61ef012014-10-08 05:17:02 -0700118 const SkPicture* topLevelPicture,
robertphillips30d78412014-11-24 09:49:17 -0800119 const SkMatrix& initialMat,
robertphillips98d709b2014-09-02 10:20:50 -0700120 const SkRect& query,
robertphillipsd61ef012014-10-08 05:17:02 -0700121 SkTDArray<GrHoistedLayer>* atlased,
robertphillipsa63f32e2014-11-10 08:10:42 -0800122 SkTDArray<GrHoistedLayer>* recycled,
123 int numSamples) {
124 if (0 != numSamples) {
125 // MSAA layers are currently never atlased
126 return;
127 }
128
robertphillipsd61ef012014-10-08 05:17:02 -0700129 GrLayerCache* layerCache = context->getLayerCache();
robertphillipsd61ef012014-10-08 05:17:02 -0700130 layerCache->processDeletedPictures();
131
halcanary96fcdcc2015-08-27 07:41:13 -0700132 const SkBigPicture::AccelData* topLevelData = nullptr;
mtklein9db912c2015-05-19 11:11:26 -0700133 if (const SkBigPicture* bp = topLevelPicture->asSkBigPicture()) {
134 topLevelData = bp->accelData();
135 }
robertphillipscbe80ca2014-10-09 15:36:06 -0700136 if (!topLevelData) {
robertphillipsfd61ed02014-10-28 07:21:44 -0700137 return;
robertphillips30d2cc62014-09-24 08:52:18 -0700138 }
139
robertphillips82365912014-11-12 09:32:34 -0800140 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLevelData);
141 if (0 == topLevelGPUData->numBlocks()) {
robertphillipsfd61ed02014-10-28 07:21:44 -0700142 return;
robertphillips30d2cc62014-09-24 08:52:18 -0700143 }
144
robertphillips82365912014-11-12 09:32:34 -0800145 atlased->setReserve(atlased->count() + topLevelGPUData->numBlocks());
robertphillipscbe80ca2014-10-09 15:36:06 -0700146
robertphillips82365912014-11-12 09:32:34 -0800147 for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) {
148 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i);
robertphillips98d709b2014-09-02 10:20:50 -0700149
robertphillipsfd61ed02014-10-28 07:21:44 -0700150 // TODO: ignore perspective projected layers here?
151 bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested ||
152 (info.fPaint && info.fPaint->getImageFilter());
153
154 if (disallowAtlasing) {
155 continue;
156 }
157
robertphillips30d78412014-11-24 09:49:17 -0800158 SkRect layerRect;
159 initialMat.mapRect(&layerRect, info.fBounds);
robertphillips3aac6e02014-10-20 08:52:40 -0700160 if (!layerRect.intersect(query)) {
robertphillips2ed8a752014-09-03 13:46:02 -0700161 continue;
robertphillips98d709b2014-09-02 10:20:50 -0700162 }
robertphillips98d709b2014-09-02 10:20:50 -0700163
robertphillips478dd722014-12-16 08:25:55 -0800164 const SkIRect dstIR = layerRect.roundOut();
robertphillips3aac6e02014-10-20 08:52:40 -0700165
robertphillips478dd722014-12-16 08:25:55 -0800166 SkIRect srcIR;
167
robertphillips57f192d2015-01-08 10:15:25 -0800168 if (!compute_source_rect(info, initialMat, dstIR, &srcIR) ||
169 !GrLayerCache::PlausiblyAtlasable(srcIR.width(), srcIR.height())) {
robertphillips2ed8a752014-09-03 13:46:02 -0700170 continue;
robertphillips98d709b2014-09-02 10:20:50 -0700171 }
robertphillips2ed8a752014-09-03 13:46:02 -0700172
robertphillips30d78412014-11-24 09:49:17 -0800173 prepare_for_hoisting(layerCache, topLevelPicture, initialMat,
robertphillips478dd722014-12-16 08:25:55 -0800174 info, srcIR, dstIR, atlased, recycled, true, 0);
robertphillips98d709b2014-09-02 10:20:50 -0700175 }
176
robertphillipsfd61ed02014-10-28 07:21:44 -0700177}
178
179void GrLayerHoister::FindLayersToHoist(GrContext* context,
180 const SkPicture* topLevelPicture,
robertphillips30d78412014-11-24 09:49:17 -0800181 const SkMatrix& initialMat,
robertphillipsfd61ed02014-10-28 07:21:44 -0700182 const SkRect& query,
183 SkTDArray<GrHoistedLayer>* needRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -0800184 SkTDArray<GrHoistedLayer>* recycled,
185 int numSamples) {
robertphillipsfd61ed02014-10-28 07:21:44 -0700186 GrLayerCache* layerCache = context->getLayerCache();
187
188 layerCache->processDeletedPictures();
189
halcanary96fcdcc2015-08-27 07:41:13 -0700190 const SkBigPicture::AccelData* topLevelData = nullptr;
mtklein9db912c2015-05-19 11:11:26 -0700191 if (const SkBigPicture* bp = topLevelPicture->asSkBigPicture()) {
192 topLevelData = bp->accelData();
193 }
robertphillipsfd61ed02014-10-28 07:21:44 -0700194 if (!topLevelData) {
195 return;
196 }
197
robertphillips82365912014-11-12 09:32:34 -0800198 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLevelData);
199 if (0 == topLevelGPUData->numBlocks()) {
robertphillipsfd61ed02014-10-28 07:21:44 -0700200 return;
201 }
202
203 // Find and prepare for hoisting all the layers that intersect the query rect
robertphillips82365912014-11-12 09:32:34 -0800204 for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) {
205 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i);
robertphillipsfd61ed02014-10-28 07:21:44 -0700206 if (info.fIsNested) {
207 // Parent layers are currently hoisted while nested layers are not.
208 continue;
209 }
210
robertphillips30d78412014-11-24 09:49:17 -0800211 SkRect layerRect;
212 initialMat.mapRect(&layerRect, info.fBounds);
robertphillipsfd61ed02014-10-28 07:21:44 -0700213 if (!layerRect.intersect(query)) {
214 continue;
215 }
216
robertphillips478dd722014-12-16 08:25:55 -0800217 const SkIRect dstIR = layerRect.roundOut();
robertphillipsfd61ed02014-10-28 07:21:44 -0700218
robertphillips478dd722014-12-16 08:25:55 -0800219 SkIRect srcIR;
220 if (!compute_source_rect(info, initialMat, dstIR, &srcIR)) {
221 continue;
222 }
223
224 prepare_for_hoisting(layerCache, topLevelPicture, initialMat, info, srcIR, dstIR,
robertphillipsa63f32e2014-11-10 08:10:42 -0800225 needRendering, recycled, false, numSamples);
robertphillipsfd61ed02014-10-28 07:21:44 -0700226 }
robertphillips98d709b2014-09-02 10:20:50 -0700227}
228
robertphillipsfd61ed02014-10-28 07:21:44 -0700229void GrLayerHoister::DrawLayersToAtlas(GrContext* context,
230 const SkTDArray<GrHoistedLayer>& atlased) {
robertphillips98d709b2014-09-02 10:20:50 -0700231 if (atlased.count() > 0) {
232 // All the atlased layers are rendered into the same GrTexture
robertphillipsa86a2332014-12-16 14:25:08 -0800233 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
robertphillips98d709b2014-09-02 10:20:50 -0700234 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
robertphillipsa86a2332014-12-16 14:25:08 -0800235 atlased[0].fLayer->texture()->asRenderTarget(), &props));
robertphillips98d709b2014-09-02 10:20:50 -0700236
237 SkCanvas* atlasCanvas = surface->getCanvas();
238
robertphillips98d709b2014-09-02 10:20:50 -0700239 for (int i = 0; i < atlased.count(); ++i) {
robertphillips9e6835d2014-10-22 05:33:52 -0700240 const GrCachedLayer* layer = atlased[i].fLayer;
mtklein9db912c2015-05-19 11:11:26 -0700241 const SkBigPicture* pict = atlased[i].fPicture->asSkBigPicture();
242 if (!pict) {
243 // TODO: can we assume / assert this?
244 continue;
245 }
robertphillips478dd722014-12-16 08:25:55 -0800246 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcIR().fTop);
robertphillips9e6835d2014-10-22 05:33:52 -0700247 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();)
248
249 SkASSERT(!layerPaint || !layerPaint->getImageFilter());
robertphillips7b9e8a42014-12-11 08:20:31 -0800250 SkASSERT(!layer->filter());
robertphillips98d709b2014-09-02 10:20:50 -0700251
252 atlasCanvas->save();
253
254 // Add a rect clip to make sure the rendering doesn't
255 // extend beyond the boundaries of the atlased sub-rect
robertphillipse99d4992014-12-03 07:33:57 -0800256 const SkRect bound = SkRect::Make(layer->rect());
robertphillips98d709b2014-09-02 10:20:50 -0700257 atlasCanvas->clipRect(bound);
reed8eddfb52014-12-04 07:50:14 -0800258 atlasCanvas->clear(0);
robertphillips98d709b2014-09-02 10:20:50 -0700259
robertphillipsfd61ed02014-10-28 07:21:44 -0700260 // '-offset' maps the layer's top/left to the origin.
robertphillips98d709b2014-09-02 10:20:50 -0700261 // Since this layer is atlased, the top/left corner needs
262 // to be offset to the correct location in the backing texture.
robertphillips4815fe52014-09-16 10:32:43 -0700263 SkMatrix initialCTM;
robertphillipsfd61ed02014-10-28 07:21:44 -0700264 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset.fY));
265 initialCTM.preTranslate(bound.fLeft, bound.fTop);
266 initialCTM.preConcat(atlased[i].fPreMat);
robertphillips9e6835d2014-10-22 05:33:52 -0700267
robertphillipsfd61ed02014-10-28 07:21:44 -0700268 atlasCanvas->setMatrix(initialCTM);
robertphillips9e6835d2014-10-22 05:33:52 -0700269 atlasCanvas->concat(atlased[i].fLocalMat);
robertphillips98d709b2014-09-02 10:20:50 -0700270
mtklein9db912c2015-05-19 11:11:26 -0700271 pict->partialPlayback(atlasCanvas, layer->start() + 1, layer->stop(), initialCTM);
robertphillips98d709b2014-09-02 10:20:50 -0700272 atlasCanvas->restore();
273 }
274
275 atlasCanvas->flush();
276 }
robertphillipsfd61ed02014-10-28 07:21:44 -0700277}
robertphillips98d709b2014-09-02 10:20:50 -0700278
robertphillips478dd722014-12-16 08:25:55 -0800279void GrLayerHoister::FilterLayer(GrContext* context,
280 SkGpuDevice* device,
281 const GrHoistedLayer& info) {
282 GrCachedLayer* layer = info.fLayer;
283
robertphillips7b9e8a42014-12-11 08:20:31 -0800284 SkASSERT(layer->filter());
285
286 static const int kDefaultCacheSize = 32 * 1024 * 1024;
287
robertphillips478dd722014-12-16 08:25:55 -0800288 SkBitmap filteredBitmap;
289 SkIPoint offset = SkIPoint::Make(0, 0);
robertphillips7b9e8a42014-12-11 08:20:31 -0800290
robertphillips478dd722014-12-16 08:25:55 -0800291 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcIR().fTop);
robertphillips7b9e8a42014-12-11 08:20:31 -0800292
robertphillips478dd722014-12-16 08:25:55 -0800293 SkMatrix totMat = SkMatrix::I();
294 totMat.preConcat(info.fPreMat);
295 totMat.preConcat(info.fLocalMat);
296 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterOffset.fY));
robertphillips7b9e8a42014-12-11 08:20:31 -0800297
robertphillips478dd722014-12-16 08:25:55 -0800298 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
299 SkIRect clipBounds = layer->rect();
robertphillips7b9e8a42014-12-11 08:20:31 -0800300
robertphillips478dd722014-12-16 08:25:55 -0800301 // This cache is transient, and is freed (along with all its contained
302 // textures) when it goes out of scope.
303 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
reed4e23cda2016-01-11 10:56:59 -0800304 SkImageFilter::Context filterContext(totMat, clipBounds, cache);
robertphillips478dd722014-12-16 08:25:55 -0800305
reed88d064d2015-10-12 11:30:02 -0700306 SkImageFilter::DeviceProxy proxy(device);
robertphillips1de87df2016-01-14 06:03:29 -0800307 SkBitmap src;
308 GrWrapTextureInBitmap(layer->texture(), layer->texture()->width(), layer->texture()->height(),
309 false, &src);
robertphillips95145a92015-01-14 08:08:21 -0800310
robertphillips48e78462016-02-17 13:57:16 -0800311 if (!layer->filter()->filterImageDeprecated(&proxy, src, filterContext,
312 &filteredBitmap, &offset)) {
robertphillips95145a92015-01-14 08:08:21 -0800313 // Filtering failed. Press on with the unfiltered version.
robertphillips478dd722014-12-16 08:25:55 -0800314 return;
robertphillips7b9e8a42014-12-11 08:20:31 -0800315 }
robertphillips478dd722014-12-16 08:25:55 -0800316
317 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.height());
robertphillips60029a52015-11-09 13:51:06 -0800318 layer->setTexture(filteredBitmap.getTexture(), newRect, false);
robertphillips478dd722014-12-16 08:25:55 -0800319 layer->setOffset(offset);
robertphillips7b9e8a42014-12-11 08:20:31 -0800320}
321
robertphillipsfd61ed02014-10-28 07:21:44 -0700322void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers) {
323 for (int i = 0; i < layers.count(); ++i) {
324 GrCachedLayer* layer = layers[i].fLayer;
mtklein9db912c2015-05-19 11:11:26 -0700325 const SkBigPicture* pict = layers[i].fPicture->asSkBigPicture();
326 if (!pict) {
327 // TODO: can we assume / assert this?
328 continue;
329 }
robertphillips478dd722014-12-16 08:25:55 -0800330 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcIR().fTop);
robertphillips98d709b2014-09-02 10:20:50 -0700331
332 // Each non-atlased layer has its own GrTexture
robertphillipsa86a2332014-12-16 14:25:08 -0800333 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
robertphillips98d709b2014-09-02 10:20:50 -0700334 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
robertphillipsa86a2332014-12-16 14:25:08 -0800335 layer->texture()->asRenderTarget(), &props));
robertphillips98d709b2014-09-02 10:20:50 -0700336
337 SkCanvas* layerCanvas = surface->getCanvas();
338
robertphillips9e6835d2014-10-22 05:33:52 -0700339 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
340
robertphillips98d709b2014-09-02 10:20:50 -0700341 // Add a rect clip to make sure the rendering doesn't
robertphillipsfd61ed02014-10-28 07:21:44 -0700342 // extend beyond the boundaries of the layer
robertphillipse99d4992014-12-03 07:33:57 -0800343 const SkRect bound = SkRect::Make(layer->rect());
robertphillipsfd61ed02014-10-28 07:21:44 -0700344 layerCanvas->clipRect(bound);
robertphillips98d709b2014-09-02 10:20:50 -0700345 layerCanvas->clear(SK_ColorTRANSPARENT);
346
robertphillips4815fe52014-09-16 10:32:43 -0700347 SkMatrix initialCTM;
robertphillips9e6835d2014-10-22 05:33:52 -0700348 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset.fY));
robertphillipsfd61ed02014-10-28 07:21:44 -0700349 initialCTM.preConcat(layers[i].fPreMat);
robertphillips4815fe52014-09-16 10:32:43 -0700350
robertphillipsfd61ed02014-10-28 07:21:44 -0700351 layerCanvas->setMatrix(initialCTM);
352 layerCanvas->concat(layers[i].fLocalMat);
robertphillips98d709b2014-09-02 10:20:50 -0700353
mtklein9db912c2015-05-19 11:11:26 -0700354 pict->partialPlayback(layerCanvas, layer->start()+1, layer->stop(), initialCTM);
robertphillips98d709b2014-09-02 10:20:50 -0700355 layerCanvas->flush();
robertphillips7b9e8a42014-12-11 08:20:31 -0800356
357 if (layer->filter()) {
358 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(surface.get());
359
robertphillips478dd722014-12-16 08:25:55 -0800360 FilterLayer(context, gpuSurf->getDevice(), layers[i]);
robertphillips7b9e8a42014-12-11 08:20:31 -0800361 }
robertphillips98d709b2014-09-02 10:20:50 -0700362 }
363}
364
robertphillipsd61ef012014-10-08 05:17:02 -0700365void GrLayerHoister::UnlockLayers(GrContext* context,
robertphillipsfd61ed02014-10-28 07:21:44 -0700366 const SkTDArray<GrHoistedLayer>& layers) {
robertphillipsd61ef012014-10-08 05:17:02 -0700367 GrLayerCache* layerCache = context->getLayerCache();
robertphillips30d2cc62014-09-24 08:52:18 -0700368
robertphillipsfd61ed02014-10-28 07:21:44 -0700369 for (int i = 0; i < layers.count(); ++i) {
370 layerCache->removeUse(layers[i].fLayer);
robertphillipsb5a97152014-09-30 11:33:02 -0700371 }
372
robertphillips4ab5a902014-10-29 13:56:02 -0700373 SkDEBUGCODE(layerCache->validate();)
374}
375
robertphillips60029a52015-11-09 13:51:06 -0800376void GrLayerHoister::Begin(GrContext* context) {
robertphillipscf1d1982015-11-06 05:59:14 -0800377 GrLayerCache* layerCache = context->getLayerCache();
robertphillips42597bc2015-11-06 04:14:55 -0800378
robertphillips60029a52015-11-09 13:51:06 -0800379 layerCache->begin();
380}
381
382void GrLayerHoister::End(GrContext* context) {
383 GrLayerCache* layerCache = context->getLayerCache();
384
385#if !GR_CACHE_HOISTED_LAYERS
386
robertphillips30d2cc62014-09-24 08:52:18 -0700387 // This code completely clears out the atlas. It is required when
388 // caching is disabled so the atlas doesn't fill up and force more
389 // free floating layers
robertphillips98d709b2014-09-02 10:20:50 -0700390 layerCache->purgeAll();
391#endif
robertphillips60029a52015-11-09 13:51:06 -0800392
393 layerCache->end();
robertphillips98d709b2014-09-02 10:20:50 -0700394}