blob: 701bb9e8b748eecedd98a84fecb6d5dd40e55707 [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,
Robert Phillips0c088492020-11-10 08:30:50 -050025 const SkIRect& clip,
26 const SkIRect& paddingOutsets) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -050027 fID = id;
Robert Phillipsa865a3a2020-02-14 10:49:39 -050028 fClip = clip;
Robert Phillips0c088492020-11-10 08:30:50 -050029 fPaddingOutsets = paddingOutsets;
Robert Phillipsa865a3a2020-02-14 10:49:39 -050030
Robert Phillipsbc688322020-12-14 11:38:59 -050031 fPlaybackChar = dstSurfaceCharacterization.createResized(this->paddedRectSize().width(),
32 this->paddedRectSize().height());
33 SkASSERT(fPlaybackChar.isValid());
Robert Phillips11c67672020-04-23 15:10:03 -040034
Robert Phillipsbc688322020-12-14 11:38:59 -050035 GrBackendFormat backendFormat = direct->defaultBackendFormat(fPlaybackChar.colorType(),
Robert Phillipsd5f3c982020-07-07 13:18:47 -040036 GrRenderable::kYes);
37 SkDEBUGCODE(const GrCaps* caps = direct->priv().caps());
Robert Phillips11c67672020-04-23 15:10:03 -040038 SkASSERT(caps->isFormatTexturable(backendFormat));
39
Robert Phillipsd5f3c982020-07-07 13:18:47 -040040 fCallbackContext.reset(new PromiseImageCallbackContext(direct, backendFormat));
Robert Phillips96601082018-05-29 16:13:26 -040041}
42
Robert Phillipsa865a3a2020-02-14 10:49:39 -050043DDLTileHelper::TileData::~TileData() {}
44
Robert Phillips96601082018-05-29 16:13:26 -040045void DDLTileHelper::TileData::createTileSpecificSKP(SkData* compressedPictureData,
46 const DDLPromiseImageHelper& helper) {
Robert Phillips7a3197b2018-09-26 21:18:23 +000047 SkASSERT(!fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040048
Robert Phillipsbc688322020-12-14 11:38:59 -050049 auto recordingChar = fPlaybackChar.createResized(fClip.width(), fClip.height());
50 SkASSERT(recordingChar.isValid());
51
Robert Phillips7a3197b2018-09-26 21:18:23 +000052 // This is bending the DDLRecorder contract! The promise images in the SKP should be
53 // created by the same recorder used to create the matching DDL.
Robert Phillipsbc688322020-12-14 11:38:59 -050054 SkDeferredDisplayListRecorder recorder(recordingChar);
Robert Phillips96601082018-05-29 16:13:26 -040055
Robert Phillips7a3197b2018-09-26 21:18:23 +000056 fReconstitutedPicture = helper.reinflateSKP(&recorder, compressedPictureData, &fPromiseImages);
Robert Phillipse8e2bb12018-09-27 14:26:47 -040057
Adlai Holler7580ad42020-06-24 13:45:25 -040058 auto ddl = recorder.detach();
Robert Phillipsdc369702020-08-13 13:34:27 -040059 if (ddl && ddl->priv().numRenderTasks()) {
Robert Phillipse8e2bb12018-09-27 14:26:47 -040060 // TODO: remove this once skbug.com/8424 is fixed. If the DDL resulting from the
Greg Danielf41b2bd2019-08-22 16:19:24 -040061 // reinflation of the SKPs contains opsTasks that means some image subset operation
Robert Phillipse8e2bb12018-09-27 14:26:47 -040062 // created a draw.
63 fReconstitutedPicture.reset();
64 }
Robert Phillips96601082018-05-29 16:13:26 -040065}
66
67void DDLTileHelper::TileData::createDDL() {
Robert Phillips24a8e9e2020-03-06 20:26:28 +000068 SkASSERT(!fDisplayList && fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040069
Robert Phillipsbc688322020-12-14 11:38:59 -050070 auto recordingChar = fPlaybackChar.createResized(fClip.width(), fClip.height());
71 SkASSERT(recordingChar.isValid());
72
73 SkDeferredDisplayListRecorder recorder(recordingChar);
Robert Phillips7a3197b2018-09-26 21:18:23 +000074
75 // DDL TODO: the DDLRecorder's GrContext isn't initialized until getCanvas is called.
76 // Maybe set it up in the ctor?
Robert Phillips24a8e9e2020-03-06 20:26:28 +000077 SkCanvas* recordingCanvas = recorder.getCanvas();
Robert Phillips7a3197b2018-09-26 21:18:23 +000078
79 // Because we cheated in createTileSpecificSKP and used the wrong DDLRecorder, the GrContext's
80 // stored in fReconstitutedPicture's promise images are incorrect. Patch them with the correct
81 // one now.
82 for (int i = 0; i < fPromiseImages.count(); ++i) {
Robert Phillips7a3197b2018-09-26 21:18:23 +000083 if (fPromiseImages[i]->isTextureBacked()) {
Adlai Holler302e8fb2020-09-14 11:58:06 -040084 auto rContext = recordingCanvas->recordingContext();
Jim Van Verth21bd60d2018-10-12 15:00:20 -040085 SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get();
Adlai Holler302e8fb2020-09-14 11:58:06 -040086 gpuImage->resetContext(sk_ref_sp(rContext));
Robert Phillips7a3197b2018-09-26 21:18:23 +000087 }
88 }
Robert Phillips96601082018-05-29 16:13:26 -040089
Robert Phillips0c088492020-11-10 08:30:50 -050090 // We always record the DDL in the (0,0) .. (clipWidth, clipHeight) coordinates
Robert Phillips24a8e9e2020-03-06 20:26:28 +000091 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
92 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040093
94 // Note: in this use case we only render a picture to the deferred canvas
95 // but, more generally, clients will use arbitrary draw calls.
Robert Phillips24a8e9e2020-03-06 20:26:28 +000096 recordingCanvas->drawPicture(fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040097
Robert Phillips7a3197b2018-09-26 21:18:23 +000098 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040099}
100
Robert Phillips11c67672020-04-23 15:10:03 -0400101void DDLTileHelper::createComposeDDL() {
102 SkASSERT(!fComposeDDL);
103
104 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
105
106 SkCanvas* recordingCanvas = recorder.getCanvas();
107
108 for (int i = 0; i < this->numTiles(); ++i) {
109 TileData* tile = &fTiles[i];
110
Robert Phillips0c088492020-11-10 08:30:50 -0500111 sk_sp<SkImage> promiseImage = tile->makePromiseImageForDst(&recorder);
Robert Phillips11c67672020-04-23 15:10:03 -0400112
Robert Phillips0c088492020-11-10 08:30:50 -0500113 SkRect dstRect = SkRect::Make(tile->clipRect());
114 SkIRect srcRect = tile->clipRect();
115 srcRect.offsetTo(tile->padOffset().x(), tile->padOffset().y());
Robert Phillips11c67672020-04-23 15:10:03 -0400116
Robert Phillips0c088492020-11-10 08:30:50 -0500117 SkASSERT(promiseImage->bounds().contains(srcRect));
Robert Phillips11c67672020-04-23 15:10:03 -0400118
Robert Phillips0c088492020-11-10 08:30:50 -0500119 recordingCanvas->drawImageRect(promiseImage.get(), srcRect, dstRect, nullptr);
Robert Phillips11c67672020-04-23 15:10:03 -0400120 }
121
122 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -0400123 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -0400124}
125
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400126void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500127 SkASSERT(fDisplayList);
128
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400129 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500130 for (; !iter.done(); iter.next()) {
131 iter.compile();
132 }
133}
134
Adlai Hollerb2705682020-10-20 10:11:53 -0400135sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrRecordingContext* context) {
Robert Phillips11c67672020-04-23 15:10:03 -0400136 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
137
138 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
139 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400140 return nullptr;
141 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400142
Robert Phillips11c67672020-04-23 15:10:03 -0400143 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
144 // Both the tile's destination surface and the promise image used to draw the tile will be
145 // backed by the same backendTexture - unbeknownst to Ganesh.
Robert Phillips8472a3d2020-04-16 16:27:45 -0400146 return SkSurface::MakeFromBackendTexture(context,
Robert Phillips11c67672020-04-23 15:10:03 -0400147 promiseImageTexture->backendTexture(),
Robert Phillipsbc688322020-12-14 11:38:59 -0500148 fPlaybackChar.origin(),
149 fPlaybackChar.sampleCount(),
150 fPlaybackChar.colorType(),
151 fPlaybackChar.refColorSpace(),
152 &fPlaybackChar.surfaceProps());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400153}
154
Adlai Hollerb2705682020-10-20 10:11:53 -0400155void DDLTileHelper::TileData::drawSKPDirectly(GrRecordingContext* context) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400156 SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture);
157
158 fTileSurface = this->makeWrappedTileDest(context);
159 if (fTileSurface) {
160 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000161
Robert Phillips0c088492020-11-10 08:30:50 -0500162 SkASSERT(this->padOffset().isZero() && this->paddedRectSize() == fClip.size());
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000163 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
164 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
165
166 tileCanvas->drawPicture(fReconstitutedPicture);
167
Robert Phillips8472a3d2020-04-16 16:27:45 -0400168 // We can't snap an image here bc, since we're using wrapped backend textures for the
169 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000170 }
171}
172
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400173void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400174 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400175
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400176 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400177 if (fTileSurface) {
Robert Phillips0c088492020-11-10 08:30:50 -0500178 fTileSurface->draw(fDisplayList, this->padOffset().x(), this->padOffset().y());
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500179
Robert Phillips8472a3d2020-04-16 16:27:45 -0400180 // We can't snap an image here bc, since we're using wrapped backend textures for the
181 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500182 }
Robert Phillips96601082018-05-29 16:13:26 -0400183}
184
Robert Phillips96601082018-05-29 16:13:26 -0400185void DDLTileHelper::TileData::reset() {
186 // TODO: when DDLs are re-renderable we don't need to do this
187 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400188
Robert Phillips8472a3d2020-04-16 16:27:45 -0400189 fTileSurface = nullptr;
190}
191
Robert Phillips0c088492020-11-10 08:30:50 -0500192sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImageForDst(
193 SkDeferredDisplayListRecorder* recorder) {
Robert Phillips11c67672020-04-23 15:10:03 -0400194 SkASSERT(fCallbackContext);
195
196 // The promise image gets a ref on the promise callback context
Brian Salomonf1432742020-11-09 15:40:27 -0500197 sk_sp<SkImage> promiseImage =
198 recorder->makePromiseTexture(fCallbackContext->backendFormat(),
Robert Phillips0c088492020-11-10 08:30:50 -0500199 this->paddedRectSize().width(),
200 this->paddedRectSize().height(),
Brian Salomonf1432742020-11-09 15:40:27 -0500201 GrMipmapped::kNo,
202 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
Robert Phillipsbc688322020-12-14 11:38:59 -0500203 fPlaybackChar.colorType(),
Brian Salomonf1432742020-11-09 15:40:27 -0500204 kPremul_SkAlphaType,
Robert Phillipsbc688322020-12-14 11:38:59 -0500205 fPlaybackChar.refColorSpace(),
Brian Salomonf1432742020-11-09 15:40:27 -0500206 PromiseImageCallbackContext::PromiseImageFulfillProc,
207 PromiseImageCallbackContext::PromiseImageReleaseProc,
208 (void*)this->refCallbackContext().release());
Robert Phillips11c67672020-04-23 15:10:03 -0400209 fCallbackContext->wasAddedToImage();
210
211 return promiseImage;
212}
213
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400214void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400215 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Robert Phillipsbc688322020-12-14 11:38:59 -0500216
217 const SkSurfaceCharacterization& c = tile->fPlaybackChar;
Greg Daniel398ecf12020-08-26 16:33:54 -0400218 GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
219 GrMipMapped(c.isMipMapped()),
220 GrRenderable::kYes);
Robert Phillips11c67672020-04-23 15:10:03 -0400221 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400222}
223
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400224void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400225 SkASSERT(tile->fCallbackContext);
226
Robert Phillips8472a3d2020-04-16 16:27:45 -0400227 // TODO: it seems that, on the Linux bots, backend texture creation is failing
228 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400229 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
230 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400231
232 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400233
234 SkASSERT(tile->fCallbackContext->unique());
235 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400236}
237
238///////////////////////////////////////////////////////////////////////////////////////////////////
239
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400240DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500241 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500242 const SkIRect& viewport,
Robert Phillips0c088492020-11-10 08:30:50 -0500243 int numDivisions,
244 bool addRandomPaddingToDst)
Robert Phillips11c67672020-04-23 15:10:03 -0400245 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400246 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400247 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400248 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400249
250 int xTileSize = viewport.width()/fNumDivisions;
251 int yTileSize = viewport.height()/fNumDivisions;
252
Robert Phillips0c088492020-11-10 08:30:50 -0500253 SkRandom rand;
254
Robert Phillips96601082018-05-29 16:13:26 -0400255 // Create the destination tiles
256 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
257 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
258
259 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
260 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
261
262 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
263
264 SkASSERT(viewport.contains(clip));
265
Robert Phillips0c088492020-11-10 08:30:50 -0500266 static const uint32_t kMaxPad = 64;
267 int32_t lPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
268 int32_t tPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
269 int32_t rPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
270 int32_t bPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
271
272 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip,
273 {lPad, tPad, rPad, bPad});
Robert Phillips96601082018-05-29 16:13:26 -0400274 }
275 }
276}
277
278void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
279 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500280 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400281 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
282 }
283}
284
285void DDLTileHelper::createDDLsInParallel() {
286#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500287 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400288 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400289 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400290#else
291 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000292 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400293 fTiles[i].createDDL();
294 }
Robert Phillips11c67672020-04-23 15:10:03 -0400295 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400296#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500297}
Robert Phillips96601082018-05-29 16:13:26 -0400298
Robert Phillips7b0ed552020-02-20 12:45:19 -0500299// On the gpu thread:
300// precompile any programs
301// replay the DDL into a surface to make the tile image
302// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400303static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500304
305 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400306 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500307
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400308 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400309
Robert Phillips5dbcca52020-05-29 10:41:33 -0400310 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500311}
312
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500313// We expect to have more than one recording thread but just one gpu thread
314void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
315 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400316 GrDirectContext* direct) {
317 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500318
319 for (int i = 0; i < this->numTiles(); ++i) {
320 TileData* tile = &fTiles[i];
321
322 // On a recording thread:
323 // generate the tile's DDL
324 // schedule gpu-thread processing of the DDL
325 // Note: a finer grained approach would be add a scheduling task which would evaluate
326 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400327 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500328 tile->createDDL();
329
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400330 gpuTaskGroup->add([direct, tile]() {
331 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500332 });
333 });
334 }
Robert Phillips11c67672020-04-23 15:10:03 -0400335
336 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400337}
338
Robert Phillips5dbcca52020-05-29 10:41:33 -0400339// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400340void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500341 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400342 fTiles[i].precompile(direct);
343 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400344 }
Robert Phillips96601082018-05-29 16:13:26 -0400345}
346
Robert Phillips5dbcca52020-05-29 10:41:33 -0400347// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400348void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000349 for (int i = 0; i < this->numTiles(); ++i) {
350 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400351 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000352 }
353}
354
Robert Phillips5dbcca52020-05-29 10:41:33 -0400355// Only called from skpbench
Adlai Hollerb2705682020-10-20 10:11:53 -0400356void DDLTileHelper::drawAllTilesDirectly(GrDirectContext* context) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000357 for (int i = 0; i < this->numTiles(); ++i) {
358 fTiles[i].drawSKPDirectly(context);
359 }
360}
361
Robert Phillips11c67672020-04-23 15:10:03 -0400362void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500363 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400364 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400365 }
366}
367
368void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500369 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400370 fTiles[i].reset();
371 }
Robert Phillips11c67672020-04-23 15:10:03 -0400372 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400373}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400374
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400375void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400376
377 if (taskGroup) {
378 for (int i = 0; i < this->numTiles(); ++i) {
379 TileData* tile = &fTiles[i];
380
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400381 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400382 }
383 } else {
384 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400385 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400386 }
387 }
388}
389
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400390void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400391 if (taskGroup) {
392 for (int i = 0; i < this->numTiles(); ++i) {
393 TileData* tile = &fTiles[i];
394
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400395 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400396 }
397 } else {
398 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400399 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400400 }
401 }
402}