blob: 9e50619c5e0bfc9366d34972c205b0a0ca86b35f [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"
Adlai Hollera0693042020-10-14 11:23:11 -040018#include "src/gpu/GrDirectContextPriv.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 Phillips7a3197b2018-09-26 21:18:23 +000074 if (fPromiseImages[i]->isTextureBacked()) {
Adlai Holler302e8fb2020-09-14 11:58:06 -040075 auto rContext = recordingCanvas->recordingContext();
Jim Van Verth21bd60d2018-10-12 15:00:20 -040076 SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get();
Adlai Holler302e8fb2020-09-14 11:58:06 -040077 gpuImage->resetContext(sk_ref_sp(rContext));
Robert Phillips7a3197b2018-09-26 21:18:23 +000078 }
79 }
Robert Phillips96601082018-05-29 16:13:26 -040080
Robert Phillips24a8e9e2020-03-06 20:26:28 +000081 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
82 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040083
84 // Note: in this use case we only render a picture to the deferred canvas
85 // but, more generally, clients will use arbitrary draw calls.
Robert Phillips24a8e9e2020-03-06 20:26:28 +000086 recordingCanvas->drawPicture(fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040087
Robert Phillips7a3197b2018-09-26 21:18:23 +000088 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040089}
90
Robert Phillips11c67672020-04-23 15:10:03 -040091void DDLTileHelper::createComposeDDL() {
92 SkASSERT(!fComposeDDL);
93
94 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
95
96 SkCanvas* recordingCanvas = recorder.getCanvas();
97
98 for (int i = 0; i < this->numTiles(); ++i) {
99 TileData* tile = &fTiles[i];
100
101 sk_sp<SkImage> promiseImage = tile->makePromiseImage(&recorder);
102
103 SkIRect clipRect = tile->clipRect();
104
105 SkASSERT(clipRect.width() == promiseImage->width() &&
106 clipRect.height() == promiseImage->height());
107
108 recordingCanvas->drawImage(promiseImage, clipRect.fLeft, clipRect.fTop);
109 }
110
111 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -0400112 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -0400113}
114
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400115void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500116 SkASSERT(fDisplayList);
117
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400118 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500119 for (; !iter.done(); iter.next()) {
120 iter.compile();
121 }
122}
123
Adlai Hollerb2705682020-10-20 10:11:53 -0400124sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrRecordingContext* context) {
Robert Phillips11c67672020-04-23 15:10:03 -0400125 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
126
127 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
128 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400129 return nullptr;
130 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400131
Robert Phillips11c67672020-04-23 15:10:03 -0400132 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
133 // Both the tile's destination surface and the promise image used to draw the tile will be
134 // backed by the same backendTexture - unbeknownst to Ganesh.
Robert Phillips8472a3d2020-04-16 16:27:45 -0400135 return SkSurface::MakeFromBackendTexture(context,
Robert Phillips11c67672020-04-23 15:10:03 -0400136 promiseImageTexture->backendTexture(),
Robert Phillips8472a3d2020-04-16 16:27:45 -0400137 fCharacterization.origin(),
138 fCharacterization.sampleCount(),
139 fCharacterization.colorType(),
140 fCharacterization.refColorSpace(),
141 &fCharacterization.surfaceProps());
142}
143
Adlai Hollerb2705682020-10-20 10:11:53 -0400144void DDLTileHelper::TileData::drawSKPDirectly(GrRecordingContext* context) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400145 SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture);
146
147 fTileSurface = this->makeWrappedTileDest(context);
148 if (fTileSurface) {
149 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000150
151 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
152 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
153
154 tileCanvas->drawPicture(fReconstitutedPicture);
155
Robert Phillips8472a3d2020-04-16 16:27:45 -0400156 // We can't snap an image here bc, since we're using wrapped backend textures for the
157 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000158 }
159}
160
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400161void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400162 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400163
Robert Phillips11c67672020-04-23 15:10:03 -0400164 // The tile's surface needs to be held until after the DDL is flushed bc the DDL doesn't take
165 // a ref on its destination proxy.
166 // TODO: make the DDL (or probably the drawing manager) take a ref on the destination proxy
167 // (maybe in GrDrawingManager::addDDLTarget).
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400168 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400169 if (fTileSurface) {
Adlai Holler7580ad42020-06-24 13:45:25 -0400170 fTileSurface->draw(fDisplayList);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500171
Robert Phillips8472a3d2020-04-16 16:27:45 -0400172 // We can't snap an image here bc, since we're using wrapped backend textures for the
173 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500174 }
Robert Phillips96601082018-05-29 16:13:26 -0400175}
176
Robert Phillips96601082018-05-29 16:13:26 -0400177void DDLTileHelper::TileData::reset() {
178 // TODO: when DDLs are re-renderable we don't need to do this
179 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400180
Robert Phillips8472a3d2020-04-16 16:27:45 -0400181 fTileSurface = nullptr;
182}
183
Robert Phillips11c67672020-04-23 15:10:03 -0400184sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImage(SkDeferredDisplayListRecorder* recorder) {
185 SkASSERT(fCallbackContext);
186
187 // The promise image gets a ref on the promise callback context
Brian Salomonf1432742020-11-09 15:40:27 -0500188 sk_sp<SkImage> promiseImage =
189 recorder->makePromiseTexture(fCallbackContext->backendFormat(),
190 fClip.width(),
191 fClip.height(),
192 GrMipmapped::kNo,
193 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
194 fCharacterization.colorType(),
195 kPremul_SkAlphaType,
196 fCharacterization.refColorSpace(),
197 PromiseImageCallbackContext::PromiseImageFulfillProc,
198 PromiseImageCallbackContext::PromiseImageReleaseProc,
199 (void*)this->refCallbackContext().release());
Robert Phillips11c67672020-04-23 15:10:03 -0400200 fCallbackContext->wasAddedToImage();
201
202 return promiseImage;
203}
204
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400205void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400206 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Greg Daniel398ecf12020-08-26 16:33:54 -0400207 const SkSurfaceCharacterization& c = tile->fCharacterization;
208 GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
209 GrMipMapped(c.isMipMapped()),
210 GrRenderable::kYes);
Robert Phillips11c67672020-04-23 15:10:03 -0400211 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400212}
213
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400214void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400215 SkASSERT(tile->fCallbackContext);
216
Robert Phillips8472a3d2020-04-16 16:27:45 -0400217 // TODO: it seems that, on the Linux bots, backend texture creation is failing
218 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400219 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
220 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400221
222 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400223
224 SkASSERT(tile->fCallbackContext->unique());
225 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400226}
227
228///////////////////////////////////////////////////////////////////////////////////////////////////
229
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400230DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500231 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500232 const SkIRect& viewport,
233 int numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400234 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400235 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400236 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400237 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400238
239 int xTileSize = viewport.width()/fNumDivisions;
240 int yTileSize = viewport.height()/fNumDivisions;
241
242 // Create the destination tiles
243 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
244 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
245
246 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
247 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
248
249 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
250
251 SkASSERT(viewport.contains(clip));
252
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400253 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip);
Robert Phillips96601082018-05-29 16:13:26 -0400254 }
255 }
256}
257
258void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
259 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500260 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400261 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
262 }
263}
264
265void DDLTileHelper::createDDLsInParallel() {
266#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500267 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400268 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400269 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400270#else
271 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000272 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400273 fTiles[i].createDDL();
274 }
Robert Phillips11c67672020-04-23 15:10:03 -0400275 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400276#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500277}
Robert Phillips96601082018-05-29 16:13:26 -0400278
Robert Phillips7b0ed552020-02-20 12:45:19 -0500279// On the gpu thread:
280// precompile any programs
281// replay the DDL into a surface to make the tile image
282// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400283static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500284
285 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400286 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500287
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400288 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400289
Robert Phillips5dbcca52020-05-29 10:41:33 -0400290 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500291}
292
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500293// We expect to have more than one recording thread but just one gpu thread
294void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
295 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400296 GrDirectContext* direct) {
297 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500298
299 for (int i = 0; i < this->numTiles(); ++i) {
300 TileData* tile = &fTiles[i];
301
302 // On a recording thread:
303 // generate the tile's DDL
304 // schedule gpu-thread processing of the DDL
305 // Note: a finer grained approach would be add a scheduling task which would evaluate
306 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400307 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500308 tile->createDDL();
309
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400310 gpuTaskGroup->add([direct, tile]() {
311 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500312 });
313 });
314 }
Robert Phillips11c67672020-04-23 15:10:03 -0400315
316 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400317}
318
Robert Phillips5dbcca52020-05-29 10:41:33 -0400319// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400320void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500321 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400322 fTiles[i].precompile(direct);
323 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400324 }
Robert Phillips96601082018-05-29 16:13:26 -0400325}
326
Robert Phillips5dbcca52020-05-29 10:41:33 -0400327// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400328void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000329 for (int i = 0; i < this->numTiles(); ++i) {
330 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400331 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000332 }
333}
334
Robert Phillips5dbcca52020-05-29 10:41:33 -0400335// Only called from skpbench
Adlai Hollerb2705682020-10-20 10:11:53 -0400336void DDLTileHelper::drawAllTilesDirectly(GrDirectContext* context) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000337 for (int i = 0; i < this->numTiles(); ++i) {
338 fTiles[i].drawSKPDirectly(context);
339 }
340}
341
Robert Phillips11c67672020-04-23 15:10:03 -0400342void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500343 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400344 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400345 }
346}
347
348void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500349 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400350 fTiles[i].reset();
351 }
Robert Phillips11c67672020-04-23 15:10:03 -0400352 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400353}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400354
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400355void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400356
357 if (taskGroup) {
358 for (int i = 0; i < this->numTiles(); ++i) {
359 TileData* tile = &fTiles[i];
360
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400361 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400362 }
363 } else {
364 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400365 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400366 }
367 }
368}
369
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400370void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400371 if (taskGroup) {
372 for (int i = 0; i < this->numTiles(); ++i) {
373 TileData* tile = &fTiles[i];
374
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400375 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400376 }
377 } else {
378 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400379 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400380 }
381 }
382}