blob: 9e828f90fe241b4c0d4d81c3c63a2ca972b0fc80 [file] [log] [blame]
Robert Phillips96601082018-05-29 16:13:26 -04001/*
2 * Copyright 2018 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tools/DDLTileHelper.h"
Robert Phillips96601082018-05-29 16:13:26 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkDeferredDisplayListRecorder.h"
12#include "include/core/SkPicture.h"
13#include "include/core/SkSurface.h"
14#include "include/core/SkSurfaceCharacterization.h"
Robert Phillipsd5f3c982020-07-07 13:18:47 -040015#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/core/SkDeferredDisplayListPriv.h"
17#include "src/core/SkTaskGroup.h"
Robert Phillips7b0ed552020-02-20 12:45:19 -050018#include "src/gpu/GrContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/image/SkImage_Gpu.h"
20#include "tools/DDLPromiseImageHelper.h"
Robert Phillips96601082018-05-29 16:13:26 -040021
Robert Phillips19f466d2020-02-26 10:27:07 -050022void DDLTileHelper::TileData::init(int id,
Robert Phillipsd5f3c982020-07-07 13:18:47 -040023 GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -050024 const SkSurfaceCharacterization& dstSurfaceCharacterization,
25 const SkIRect& clip) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -050026 fID = id;
Robert Phillipsa865a3a2020-02-14 10:49:39 -050027 fClip = clip;
28
Robert Phillips19f466d2020-02-26 10:27:07 -050029 fCharacterization = dstSurfaceCharacterization.createResized(clip.width(), clip.height());
Robert Phillipsa865a3a2020-02-14 10:49:39 -050030 SkASSERT(fCharacterization.isValid());
Robert Phillips11c67672020-04-23 15:10:03 -040031
Robert Phillipsd5f3c982020-07-07 13:18:47 -040032 GrBackendFormat backendFormat = direct->defaultBackendFormat(fCharacterization.colorType(),
33 GrRenderable::kYes);
34 SkDEBUGCODE(const GrCaps* caps = direct->priv().caps());
Robert Phillips11c67672020-04-23 15:10:03 -040035 SkASSERT(caps->isFormatTexturable(backendFormat));
36
Robert Phillipsd5f3c982020-07-07 13:18:47 -040037 fCallbackContext.reset(new PromiseImageCallbackContext(direct, backendFormat));
Robert Phillips96601082018-05-29 16:13:26 -040038}
39
Robert Phillipsa865a3a2020-02-14 10:49:39 -050040DDLTileHelper::TileData::~TileData() {}
41
Robert Phillips96601082018-05-29 16:13:26 -040042void DDLTileHelper::TileData::createTileSpecificSKP(SkData* compressedPictureData,
43 const DDLPromiseImageHelper& helper) {
Robert Phillips7a3197b2018-09-26 21:18:23 +000044 SkASSERT(!fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040045
Robert Phillips7a3197b2018-09-26 21:18:23 +000046 // This is bending the DDLRecorder contract! The promise images in the SKP should be
47 // created by the same recorder used to create the matching DDL.
48 SkDeferredDisplayListRecorder recorder(fCharacterization);
Robert Phillips96601082018-05-29 16:13:26 -040049
Robert Phillips7a3197b2018-09-26 21:18:23 +000050 fReconstitutedPicture = helper.reinflateSKP(&recorder, compressedPictureData, &fPromiseImages);
Robert Phillipse8e2bb12018-09-27 14:26:47 -040051
Adlai Holler7580ad42020-06-24 13:45:25 -040052 auto ddl = recorder.detach();
Robert Phillipsdc369702020-08-13 13:34:27 -040053 if (ddl && ddl->priv().numRenderTasks()) {
Robert Phillipse8e2bb12018-09-27 14:26:47 -040054 // TODO: remove this once skbug.com/8424 is fixed. If the DDL resulting from the
Greg Danielf41b2bd2019-08-22 16:19:24 -040055 // reinflation of the SKPs contains opsTasks that means some image subset operation
Robert Phillipse8e2bb12018-09-27 14:26:47 -040056 // created a draw.
57 fReconstitutedPicture.reset();
58 }
Robert Phillips96601082018-05-29 16:13:26 -040059}
60
61void DDLTileHelper::TileData::createDDL() {
Robert Phillips24a8e9e2020-03-06 20:26:28 +000062 SkASSERT(!fDisplayList && fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040063
Robert Phillips7a3197b2018-09-26 21:18:23 +000064 SkDeferredDisplayListRecorder recorder(fCharacterization);
65
66 // DDL TODO: the DDLRecorder's GrContext isn't initialized until getCanvas is called.
67 // Maybe set it up in the ctor?
Robert Phillips24a8e9e2020-03-06 20:26:28 +000068 SkCanvas* recordingCanvas = recorder.getCanvas();
Robert Phillips7a3197b2018-09-26 21:18:23 +000069
70 // Because we cheated in createTileSpecificSKP and used the wrong DDLRecorder, the GrContext's
71 // stored in fReconstitutedPicture's promise images are incorrect. Patch them with the correct
72 // one now.
73 for (int i = 0; i < fPromiseImages.count(); ++i) {
Robert Phillipsb27b38b2020-07-10 16:23:47 -040074 // CONTEXT TODO: this can be converted to a recording context once images no longer
75 // hold GrContexts
Robert Phillips24a8e9e2020-03-06 20:26:28 +000076 GrContext* newContext = recordingCanvas->getGrContext();
Robert Phillips7a3197b2018-09-26 21:18:23 +000077
78 if (fPromiseImages[i]->isTextureBacked()) {
Jim Van Verth21bd60d2018-10-12 15:00:20 -040079 SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get();
Robert Phillips7a3197b2018-09-26 21:18:23 +000080 gpuImage->resetContext(sk_ref_sp(newContext));
81 }
82 }
Robert Phillips96601082018-05-29 16:13:26 -040083
Robert Phillips24a8e9e2020-03-06 20:26:28 +000084 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
85 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040086
87 // Note: in this use case we only render a picture to the deferred canvas
88 // but, more generally, clients will use arbitrary draw calls.
Robert Phillips24a8e9e2020-03-06 20:26:28 +000089 recordingCanvas->drawPicture(fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040090
Robert Phillips7a3197b2018-09-26 21:18:23 +000091 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040092}
93
Robert Phillips11c67672020-04-23 15:10:03 -040094void DDLTileHelper::createComposeDDL() {
95 SkASSERT(!fComposeDDL);
96
97 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
98
99 SkCanvas* recordingCanvas = recorder.getCanvas();
100
101 for (int i = 0; i < this->numTiles(); ++i) {
102 TileData* tile = &fTiles[i];
103
104 sk_sp<SkImage> promiseImage = tile->makePromiseImage(&recorder);
105
106 SkIRect clipRect = tile->clipRect();
107
108 SkASSERT(clipRect.width() == promiseImage->width() &&
109 clipRect.height() == promiseImage->height());
110
111 recordingCanvas->drawImage(promiseImage, clipRect.fLeft, clipRect.fTop);
112 }
113
114 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -0400115 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -0400116}
117
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400118void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500119 SkASSERT(fDisplayList);
120
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400121 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500122 for (; !iter.done(); iter.next()) {
123 iter.compile();
124 }
125}
126
Robert Phillips8472a3d2020-04-16 16:27:45 -0400127sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrContext* context) {
Robert Phillips11c67672020-04-23 15:10:03 -0400128 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
129
130 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
131 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400132 return nullptr;
133 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400134
Robert Phillips11c67672020-04-23 15:10:03 -0400135 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
136 // Both the tile's destination surface and the promise image used to draw the tile will be
137 // backed by the same backendTexture - unbeknownst to Ganesh.
Robert Phillips8472a3d2020-04-16 16:27:45 -0400138 return SkSurface::MakeFromBackendTexture(context,
Robert Phillips11c67672020-04-23 15:10:03 -0400139 promiseImageTexture->backendTexture(),
Robert Phillips8472a3d2020-04-16 16:27:45 -0400140 fCharacterization.origin(),
141 fCharacterization.sampleCount(),
142 fCharacterization.colorType(),
143 fCharacterization.refColorSpace(),
144 &fCharacterization.surfaceProps());
145}
146
147void DDLTileHelper::TileData::drawSKPDirectly(GrContext* context) {
148 SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture);
149
150 fTileSurface = this->makeWrappedTileDest(context);
151 if (fTileSurface) {
152 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000153
154 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
155 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
156
157 tileCanvas->drawPicture(fReconstitutedPicture);
158
Robert Phillips8472a3d2020-04-16 16:27:45 -0400159 // We can't snap an image here bc, since we're using wrapped backend textures for the
160 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000161 }
162}
163
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400164void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400165 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400166
Robert Phillips11c67672020-04-23 15:10:03 -0400167 // The tile's surface needs to be held until after the DDL is flushed bc the DDL doesn't take
168 // a ref on its destination proxy.
169 // TODO: make the DDL (or probably the drawing manager) take a ref on the destination proxy
170 // (maybe in GrDrawingManager::addDDLTarget).
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400171 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400172 if (fTileSurface) {
Adlai Holler7580ad42020-06-24 13:45:25 -0400173 fTileSurface->draw(fDisplayList);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500174
Robert Phillips8472a3d2020-04-16 16:27:45 -0400175 // We can't snap an image here bc, since we're using wrapped backend textures for the
176 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500177 }
Robert Phillips96601082018-05-29 16:13:26 -0400178}
179
Robert Phillips96601082018-05-29 16:13:26 -0400180void DDLTileHelper::TileData::reset() {
181 // TODO: when DDLs are re-renderable we don't need to do this
182 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400183
Robert Phillips8472a3d2020-04-16 16:27:45 -0400184 fTileSurface = nullptr;
185}
186
Robert Phillips11c67672020-04-23 15:10:03 -0400187sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImage(SkDeferredDisplayListRecorder* recorder) {
188 SkASSERT(fCallbackContext);
189
190 // The promise image gets a ref on the promise callback context
191 sk_sp<SkImage> promiseImage = recorder->makePromiseTexture(
192 fCallbackContext->backendFormat(),
193 fClip.width(),
194 fClip.height(),
Brian Salomon7e67dca2020-07-21 09:27:25 -0400195 GrMipmapped::kNo,
Robert Phillips11c67672020-04-23 15:10:03 -0400196 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
197 fCharacterization.colorType(),
198 kPremul_SkAlphaType,
199 fCharacterization.refColorSpace(),
200 PromiseImageCallbackContext::PromiseImageFulfillProc,
201 PromiseImageCallbackContext::PromiseImageReleaseProc,
202 PromiseImageCallbackContext::PromiseImageDoneProc,
203 (void*)this->refCallbackContext().release(),
204 SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
205 fCallbackContext->wasAddedToImage();
206
207 return promiseImage;
208}
209
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400210void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400211 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400212
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400213 GrBackendTexture beTex = direct->createBackendTexture(tile->fCharacterization);
Robert Phillips11c67672020-04-23 15:10:03 -0400214 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400215}
216
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400217void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400218 SkASSERT(tile->fCallbackContext);
219
Robert Phillips8472a3d2020-04-16 16:27:45 -0400220 // TODO: it seems that, on the Linux bots, backend texture creation is failing
221 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400222 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
223 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400224
225 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400226
227 SkASSERT(tile->fCallbackContext->unique());
228 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400229}
230
231///////////////////////////////////////////////////////////////////////////////////////////////////
232
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400233DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500234 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500235 const SkIRect& viewport,
236 int numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400237 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400238 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400239 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400240 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400241
242 int xTileSize = viewport.width()/fNumDivisions;
243 int yTileSize = viewport.height()/fNumDivisions;
244
245 // Create the destination tiles
246 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
247 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
248
249 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
250 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
251
252 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
253
254 SkASSERT(viewport.contains(clip));
255
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400256 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip);
Robert Phillips96601082018-05-29 16:13:26 -0400257 }
258 }
259}
260
261void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
262 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500263 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400264 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
265 }
266}
267
268void DDLTileHelper::createDDLsInParallel() {
269#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500270 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400271 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400272 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400273#else
274 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000275 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400276 fTiles[i].createDDL();
277 }
Robert Phillips11c67672020-04-23 15:10:03 -0400278 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400279#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500280}
Robert Phillips96601082018-05-29 16:13:26 -0400281
Robert Phillips7b0ed552020-02-20 12:45:19 -0500282// On the gpu thread:
283// precompile any programs
284// replay the DDL into a surface to make the tile image
285// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400286static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500287
288 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400289 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500290
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400291 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400292
Robert Phillips5dbcca52020-05-29 10:41:33 -0400293 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500294}
295
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500296// We expect to have more than one recording thread but just one gpu thread
297void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
298 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400299 GrDirectContext* direct) {
300 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500301
302 for (int i = 0; i < this->numTiles(); ++i) {
303 TileData* tile = &fTiles[i];
304
305 // On a recording thread:
306 // generate the tile's DDL
307 // schedule gpu-thread processing of the DDL
308 // Note: a finer grained approach would be add a scheduling task which would evaluate
309 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400310 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500311 tile->createDDL();
312
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400313 gpuTaskGroup->add([direct, tile]() {
314 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500315 });
316 });
317 }
Robert Phillips11c67672020-04-23 15:10:03 -0400318
319 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400320}
321
Robert Phillips5dbcca52020-05-29 10:41:33 -0400322// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400323void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500324 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400325 fTiles[i].precompile(direct);
326 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400327 }
Robert Phillips96601082018-05-29 16:13:26 -0400328}
329
Robert Phillips5dbcca52020-05-29 10:41:33 -0400330// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400331void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000332 for (int i = 0; i < this->numTiles(); ++i) {
333 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400334 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000335 }
336}
337
Robert Phillips5dbcca52020-05-29 10:41:33 -0400338// Only called from skpbench
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000339void DDLTileHelper::drawAllTilesDirectly(GrContext* context) {
340 for (int i = 0; i < this->numTiles(); ++i) {
341 fTiles[i].drawSKPDirectly(context);
342 }
343}
344
Robert Phillips11c67672020-04-23 15:10:03 -0400345void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500346 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400347 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400348 }
349}
350
351void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500352 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400353 fTiles[i].reset();
354 }
Robert Phillips11c67672020-04-23 15:10:03 -0400355 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400356}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400357
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400358void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400359
360 if (taskGroup) {
361 for (int i = 0; i < this->numTiles(); ++i) {
362 TileData* tile = &fTiles[i];
363
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400364 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400365 }
366 } else {
367 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400368 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400369 }
370 }
371}
372
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400373void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400374 if (taskGroup) {
375 for (int i = 0; i < this->numTiles(); ++i) {
376 TileData* tile = &fTiles[i];
377
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400378 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400379 }
380 } else {
381 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400382 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400383 }
384 }
385}