blob: 0553eb00e014cc04dd6a2526798778316c8cc0e4 [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();
Chris Dalton6b498102019-08-01 14:14:52 -060053 if (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 Phillips24a8e9e2020-03-06 20:26:28 +000074 GrContext* newContext = recordingCanvas->getGrContext();
Robert Phillips7a3197b2018-09-26 21:18:23 +000075
76 if (fPromiseImages[i]->isTextureBacked()) {
Jim Van Verth21bd60d2018-10-12 15:00:20 -040077 SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get();
Robert Phillips7a3197b2018-09-26 21:18:23 +000078 gpuImage->resetContext(sk_ref_sp(newContext));
79 }
80 }
Robert Phillips96601082018-05-29 16:13:26 -040081
Robert Phillips24a8e9e2020-03-06 20:26:28 +000082 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
83 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040084
85 // Note: in this use case we only render a picture to the deferred canvas
86 // but, more generally, clients will use arbitrary draw calls.
Robert Phillips24a8e9e2020-03-06 20:26:28 +000087 recordingCanvas->drawPicture(fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040088
Robert Phillips7a3197b2018-09-26 21:18:23 +000089 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040090}
91
Robert Phillips11c67672020-04-23 15:10:03 -040092void DDLTileHelper::createComposeDDL() {
93 SkASSERT(!fComposeDDL);
94
95 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
96
97 SkCanvas* recordingCanvas = recorder.getCanvas();
98
99 for (int i = 0; i < this->numTiles(); ++i) {
100 TileData* tile = &fTiles[i];
101
102 sk_sp<SkImage> promiseImage = tile->makePromiseImage(&recorder);
103
104 SkIRect clipRect = tile->clipRect();
105
106 SkASSERT(clipRect.width() == promiseImage->width() &&
107 clipRect.height() == promiseImage->height());
108
109 recordingCanvas->drawImage(promiseImage, clipRect.fLeft, clipRect.fTop);
110 }
111
112 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -0400113 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -0400114}
115
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400116void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500117 SkASSERT(fDisplayList);
118
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400119 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500120 for (; !iter.done(); iter.next()) {
121 iter.compile();
122 }
123}
124
Robert Phillips8472a3d2020-04-16 16:27:45 -0400125sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrContext* context) {
Robert Phillips11c67672020-04-23 15:10:03 -0400126 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
127
128 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
129 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400130 return nullptr;
131 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400132
Robert Phillips11c67672020-04-23 15:10:03 -0400133 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
134 // Both the tile's destination surface and the promise image used to draw the tile will be
135 // backed by the same backendTexture - unbeknownst to Ganesh.
Robert Phillips8472a3d2020-04-16 16:27:45 -0400136 return SkSurface::MakeFromBackendTexture(context,
Robert Phillips11c67672020-04-23 15:10:03 -0400137 promiseImageTexture->backendTexture(),
Robert Phillips8472a3d2020-04-16 16:27:45 -0400138 fCharacterization.origin(),
139 fCharacterization.sampleCount(),
140 fCharacterization.colorType(),
141 fCharacterization.refColorSpace(),
142 &fCharacterization.surfaceProps());
143}
144
145void DDLTileHelper::TileData::drawSKPDirectly(GrContext* context) {
146 SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture);
147
148 fTileSurface = this->makeWrappedTileDest(context);
149 if (fTileSurface) {
150 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000151
152 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
153 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
154
155 tileCanvas->drawPicture(fReconstitutedPicture);
156
Robert Phillips8472a3d2020-04-16 16:27:45 -0400157 // We can't snap an image here bc, since we're using wrapped backend textures for the
158 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000159 }
160}
161
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400162void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400163 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400164
Robert Phillips11c67672020-04-23 15:10:03 -0400165 // The tile's surface needs to be held until after the DDL is flushed bc the DDL doesn't take
166 // a ref on its destination proxy.
167 // TODO: make the DDL (or probably the drawing manager) take a ref on the destination proxy
168 // (maybe in GrDrawingManager::addDDLTarget).
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400169 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400170 if (fTileSurface) {
Adlai Holler7580ad42020-06-24 13:45:25 -0400171 fTileSurface->draw(fDisplayList);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500172
Robert Phillips8472a3d2020-04-16 16:27:45 -0400173 // We can't snap an image here bc, since we're using wrapped backend textures for the
174 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500175 }
Robert Phillips96601082018-05-29 16:13:26 -0400176}
177
Robert Phillips96601082018-05-29 16:13:26 -0400178void DDLTileHelper::TileData::reset() {
179 // TODO: when DDLs are re-renderable we don't need to do this
180 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400181
Robert Phillips8472a3d2020-04-16 16:27:45 -0400182 fTileSurface = nullptr;
183}
184
Robert Phillips11c67672020-04-23 15:10:03 -0400185sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImage(SkDeferredDisplayListRecorder* recorder) {
186 SkASSERT(fCallbackContext);
187
188 // The promise image gets a ref on the promise callback context
189 sk_sp<SkImage> promiseImage = recorder->makePromiseTexture(
190 fCallbackContext->backendFormat(),
191 fClip.width(),
192 fClip.height(),
193 GrMipMapped::kNo,
194 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
195 fCharacterization.colorType(),
196 kPremul_SkAlphaType,
197 fCharacterization.refColorSpace(),
198 PromiseImageCallbackContext::PromiseImageFulfillProc,
199 PromiseImageCallbackContext::PromiseImageReleaseProc,
200 PromiseImageCallbackContext::PromiseImageDoneProc,
201 (void*)this->refCallbackContext().release(),
202 SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
203 fCallbackContext->wasAddedToImage();
204
205 return promiseImage;
206}
207
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400208void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400209 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400210
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400211 GrBackendTexture beTex = direct->createBackendTexture(tile->fCharacterization);
Robert Phillips11c67672020-04-23 15:10:03 -0400212 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400213}
214
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400215void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400216 SkASSERT(tile->fCallbackContext);
217
Robert Phillips8472a3d2020-04-16 16:27:45 -0400218 // TODO: it seems that, on the Linux bots, backend texture creation is failing
219 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400220 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
221 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400222
223 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400224
225 SkASSERT(tile->fCallbackContext->unique());
226 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400227}
228
229///////////////////////////////////////////////////////////////////////////////////////////////////
230
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400231DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500232 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500233 const SkIRect& viewport,
234 int numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400235 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400236 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400237 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400238 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400239
240 int xTileSize = viewport.width()/fNumDivisions;
241 int yTileSize = viewport.height()/fNumDivisions;
242
243 // Create the destination tiles
244 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
245 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
246
247 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
248 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
249
250 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
251
252 SkASSERT(viewport.contains(clip));
253
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400254 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip);
Robert Phillips96601082018-05-29 16:13:26 -0400255 }
256 }
257}
258
259void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
260 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500261 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400262 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
263 }
264}
265
266void DDLTileHelper::createDDLsInParallel() {
267#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500268 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400269 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400270 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400271#else
272 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000273 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400274 fTiles[i].createDDL();
275 }
Robert Phillips11c67672020-04-23 15:10:03 -0400276 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400277#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500278}
Robert Phillips96601082018-05-29 16:13:26 -0400279
Robert Phillips7b0ed552020-02-20 12:45:19 -0500280// On the gpu thread:
281// precompile any programs
282// replay the DDL into a surface to make the tile image
283// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400284static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500285
286 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400287 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500288
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400289 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400290
Robert Phillips5dbcca52020-05-29 10:41:33 -0400291 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500292}
293
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500294// We expect to have more than one recording thread but just one gpu thread
295void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
296 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400297 GrDirectContext* direct) {
298 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500299
300 for (int i = 0; i < this->numTiles(); ++i) {
301 TileData* tile = &fTiles[i];
302
303 // On a recording thread:
304 // generate the tile's DDL
305 // schedule gpu-thread processing of the DDL
306 // Note: a finer grained approach would be add a scheduling task which would evaluate
307 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400308 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500309 tile->createDDL();
310
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400311 gpuTaskGroup->add([direct, tile]() {
312 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500313 });
314 });
315 }
Robert Phillips11c67672020-04-23 15:10:03 -0400316
317 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400318}
319
Robert Phillips5dbcca52020-05-29 10:41:33 -0400320// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400321void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500322 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400323 fTiles[i].precompile(direct);
324 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400325 }
Robert Phillips96601082018-05-29 16:13:26 -0400326}
327
Robert Phillips5dbcca52020-05-29 10:41:33 -0400328// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400329void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000330 for (int i = 0; i < this->numTiles(); ++i) {
331 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400332 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000333 }
334}
335
Robert Phillips5dbcca52020-05-29 10:41:33 -0400336// Only called from skpbench
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000337void DDLTileHelper::drawAllTilesDirectly(GrContext* context) {
338 for (int i = 0; i < this->numTiles(); ++i) {
339 fTiles[i].drawSKPDirectly(context);
340 }
341}
342
Robert Phillips11c67672020-04-23 15:10:03 -0400343void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500344 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400345 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400346 }
347}
348
349void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500350 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400351 fTiles[i].reset();
352 }
Robert Phillips11c67672020-04-23 15:10:03 -0400353 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400354}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400355
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400356void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400357
358 if (taskGroup) {
359 for (int i = 0; i < this->numTiles(); ++i) {
360 TileData* tile = &fTiles[i];
361
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400362 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400363 }
364 } else {
365 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400366 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400367 }
368 }
369}
370
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400371void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400372 if (taskGroup) {
373 for (int i = 0; i < this->numTiles(); ++i) {
374 TileData* tile = &fTiles[i];
375
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400376 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400377 }
378 } else {
379 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400380 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400381 }
382 }
383}