blob: d426b5cd1563676bee5b5f9956742c0903cd4747 [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());
Greg Daniel398ecf12020-08-26 16:33:54 -0400212 const SkSurfaceCharacterization& c = tile->fCharacterization;
213 GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
214 GrMipMapped(c.isMipMapped()),
215 GrRenderable::kYes);
Robert Phillips11c67672020-04-23 15:10:03 -0400216 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400217}
218
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400219void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400220 SkASSERT(tile->fCallbackContext);
221
Robert Phillips8472a3d2020-04-16 16:27:45 -0400222 // TODO: it seems that, on the Linux bots, backend texture creation is failing
223 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400224 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
225 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400226
227 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400228
229 SkASSERT(tile->fCallbackContext->unique());
230 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400231}
232
233///////////////////////////////////////////////////////////////////////////////////////////////////
234
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400235DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500236 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500237 const SkIRect& viewport,
238 int numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400239 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400240 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400241 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400242 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400243
244 int xTileSize = viewport.width()/fNumDivisions;
245 int yTileSize = viewport.height()/fNumDivisions;
246
247 // Create the destination tiles
248 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
249 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
250
251 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
252 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
253
254 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
255
256 SkASSERT(viewport.contains(clip));
257
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400258 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip);
Robert Phillips96601082018-05-29 16:13:26 -0400259 }
260 }
261}
262
263void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
264 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500265 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400266 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
267 }
268}
269
270void DDLTileHelper::createDDLsInParallel() {
271#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500272 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400273 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400274 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400275#else
276 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000277 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400278 fTiles[i].createDDL();
279 }
Robert Phillips11c67672020-04-23 15:10:03 -0400280 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400281#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500282}
Robert Phillips96601082018-05-29 16:13:26 -0400283
Robert Phillips7b0ed552020-02-20 12:45:19 -0500284// On the gpu thread:
285// precompile any programs
286// replay the DDL into a surface to make the tile image
287// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400288static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500289
290 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400291 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500292
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400293 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400294
Robert Phillips5dbcca52020-05-29 10:41:33 -0400295 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500296}
297
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500298// We expect to have more than one recording thread but just one gpu thread
299void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
300 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400301 GrDirectContext* direct) {
302 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500303
304 for (int i = 0; i < this->numTiles(); ++i) {
305 TileData* tile = &fTiles[i];
306
307 // On a recording thread:
308 // generate the tile's DDL
309 // schedule gpu-thread processing of the DDL
310 // Note: a finer grained approach would be add a scheduling task which would evaluate
311 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400312 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500313 tile->createDDL();
314
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400315 gpuTaskGroup->add([direct, tile]() {
316 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500317 });
318 });
319 }
Robert Phillips11c67672020-04-23 15:10:03 -0400320
321 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400322}
323
Robert Phillips5dbcca52020-05-29 10:41:33 -0400324// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400325void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500326 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400327 fTiles[i].precompile(direct);
328 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400329 }
Robert Phillips96601082018-05-29 16:13:26 -0400330}
331
Robert Phillips5dbcca52020-05-29 10:41:33 -0400332// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400333void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000334 for (int i = 0; i < this->numTiles(); ++i) {
335 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400336 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000337 }
338}
339
Robert Phillips5dbcca52020-05-29 10:41:33 -0400340// Only called from skpbench
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000341void DDLTileHelper::drawAllTilesDirectly(GrContext* context) {
342 for (int i = 0; i < this->numTiles(); ++i) {
343 fTiles[i].drawSKPDirectly(context);
344 }
345}
346
Robert Phillips11c67672020-04-23 15:10:03 -0400347void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500348 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400349 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400350 }
351}
352
353void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500354 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400355 fTiles[i].reset();
356 }
Robert Phillips11c67672020-04-23 15:10:03 -0400357 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400358}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400359
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400360void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400361
362 if (taskGroup) {
363 for (int i = 0; i < this->numTiles(); ++i) {
364 TileData* tile = &fTiles[i];
365
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400366 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400367 }
368 } else {
369 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400370 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400371 }
372 }
373}
374
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400375void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400376 if (taskGroup) {
377 for (int i = 0; i < this->numTiles(); ++i) {
378 TileData* tile = &fTiles[i];
379
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400380 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400381 }
382 } else {
383 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400384 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400385 }
386 }
387}