2018-05-29 20:13:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/DDLTileHelper.h"
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkDeferredDisplayListRecorder.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2020-07-07 17:18:47 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkDeferredDisplayListPriv.h"
|
|
|
|
#include "src/core/SkTaskGroup.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Gpu.h"
|
|
|
|
#include "tools/DDLPromiseImageHelper.h"
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-02-26 15:27:07 +00:00
|
|
|
void DDLTileHelper::TileData::init(int id,
|
2020-07-07 17:18:47 +00:00
|
|
|
GrDirectContext* direct,
|
2020-02-26 15:27:07 +00:00
|
|
|
const SkSurfaceCharacterization& dstSurfaceCharacterization,
|
2020-11-10 13:30:50 +00:00
|
|
|
const SkIRect& clip,
|
|
|
|
const SkIRect& paddingOutsets) {
|
2020-02-14 15:49:39 +00:00
|
|
|
fID = id;
|
|
|
|
fClip = clip;
|
2020-11-10 13:30:50 +00:00
|
|
|
fPaddingOutsets = paddingOutsets;
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2020-12-14 16:38:59 +00:00
|
|
|
fPlaybackChar = dstSurfaceCharacterization.createResized(this->paddedRectSize().width(),
|
|
|
|
this->paddedRectSize().height());
|
|
|
|
SkASSERT(fPlaybackChar.isValid());
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
SkDEBUGCODE(const GrCaps* caps = direct->priv().caps());
|
2021-08-13 20:20:18 +00:00
|
|
|
SkASSERT(caps->isFormatTexturable(fPlaybackChar.backendFormat(),
|
|
|
|
fPlaybackChar.backendFormat().textureType()));
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2021-08-13 20:20:18 +00:00
|
|
|
fCallbackContext.reset(new PromiseImageCallbackContext(direct, fPlaybackChar.backendFormat()));
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 22:24:22 +00:00
|
|
|
DDLTileHelper::TileData::TileData() {}
|
2020-02-14 15:49:39 +00:00
|
|
|
DDLTileHelper::TileData::~TileData() {}
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
void DDLTileHelper::TileData::createDDL(const SkPicture* picture) {
|
|
|
|
SkASSERT(!fDisplayList && picture);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-12-14 16:38:59 +00:00
|
|
|
auto recordingChar = fPlaybackChar.createResized(fClip.width(), fClip.height());
|
|
|
|
SkASSERT(recordingChar.isValid());
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(recordingChar);
|
2018-09-26 21:18:23 +00:00
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
// DDL TODO: the DDLRecorder's rContext isn't initialized until getCanvas is called.
|
2018-09-26 21:18:23 +00:00
|
|
|
// Maybe set it up in the ctor?
|
2020-03-06 20:26:28 +00:00
|
|
|
SkCanvas* recordingCanvas = recorder.getCanvas();
|
2018-09-26 21:18:23 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
// We always record the DDL in the (0,0) .. (clipWidth, clipHeight) coordinates
|
2020-03-06 20:26:28 +00:00
|
|
|
recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
|
|
|
|
recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
// Note: in this use case we only render a picture to the deferred canvas
|
|
|
|
// but, more generally, clients will use arbitrary draw calls.
|
2021-03-03 23:12:56 +00:00
|
|
|
recordingCanvas->drawPicture(picture);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2018-09-26 21:18:23 +00:00
|
|
|
fDisplayList = recorder.detach();
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
void DDLTileHelper::createComposeDDL() {
|
|
|
|
SkASSERT(!fComposeDDL);
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(fDstCharacterization);
|
|
|
|
|
|
|
|
SkCanvas* recordingCanvas = recorder.getCanvas();
|
|
|
|
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
|
|
|
TileData* tile = &fTiles[i];
|
2021-01-11 17:29:20 +00:00
|
|
|
if (!tile->initialized()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<SkImage> promiseImage = tile->makePromiseImageForDst(
|
|
|
|
recordingCanvas->recordingContext()->threadSafeProxy());
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
SkRect dstRect = SkRect::Make(tile->clipRect());
|
|
|
|
SkIRect srcRect = tile->clipRect();
|
|
|
|
srcRect.offsetTo(tile->padOffset().x(), tile->padOffset().y());
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
SkASSERT(promiseImage->bounds().contains(srcRect));
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2021-01-22 03:25:21 +00:00
|
|
|
recordingCanvas->drawImageRect(promiseImage.get(), SkRect::Make(srcRect), dstRect,
|
|
|
|
SkSamplingOptions(), nullptr,
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
2020-04-23 19:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fComposeDDL = recorder.detach();
|
2020-06-16 15:11:33 +00:00
|
|
|
SkASSERT(fComposeDDL);
|
2020-04-23 19:10:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
|
2021-01-11 17:29:20 +00:00
|
|
|
if (!this->initialized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-05 17:52:45 +00:00
|
|
|
SkASSERT(fDisplayList);
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
|
2020-03-05 17:52:45 +00:00
|
|
|
for (; !iter.done(); iter.next()) {
|
|
|
|
iter.compile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrRecordingContext* rContext) {
|
2020-04-23 19:10:03 +00:00
|
|
|
SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
|
|
|
|
|
|
|
|
auto promiseImageTexture = fCallbackContext->promiseImageTexture();
|
|
|
|
if (!promiseImageTexture->backendTexture().isValid()) {
|
2020-04-16 20:27:45 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
// Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
|
|
|
|
// Both the tile's destination surface and the promise image used to draw the tile will be
|
|
|
|
// backed by the same backendTexture - unbeknownst to Ganesh.
|
2021-03-03 23:12:56 +00:00
|
|
|
return SkSurface::MakeFromBackendTexture(rContext,
|
2020-04-23 19:10:03 +00:00
|
|
|
promiseImageTexture->backendTexture(),
|
2020-12-14 16:38:59 +00:00
|
|
|
fPlaybackChar.origin(),
|
|
|
|
fPlaybackChar.sampleCount(),
|
|
|
|
fPlaybackChar.colorType(),
|
|
|
|
fPlaybackChar.refColorSpace(),
|
|
|
|
&fPlaybackChar.surfaceProps());
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
void DDLTileHelper::TileData::drawSKPDirectly(GrDirectContext* dContext,
|
|
|
|
const SkPicture* picture) {
|
|
|
|
SkASSERT(!fDisplayList && !fTileSurface && picture);
|
2020-03-06 20:26:28 +00:00
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
fTileSurface = this->makeWrappedTileDest(dContext);
|
2020-04-16 20:27:45 +00:00
|
|
|
if (fTileSurface) {
|
|
|
|
SkCanvas* tileCanvas = fTileSurface->getCanvas();
|
2020-03-06 20:26:28 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
SkASSERT(this->padOffset().isZero() && this->paddedRectSize() == fClip.size());
|
2020-03-06 20:26:28 +00:00
|
|
|
tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
|
|
|
|
tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
tileCanvas->drawPicture(picture);
|
2020-03-06 20:26:28 +00:00
|
|
|
|
2020-04-16 20:27:45 +00:00
|
|
|
// We can't snap an image here bc, since we're using wrapped backend textures for the
|
|
|
|
// surfaces, that would incur a copy.
|
2020-03-06 20:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
|
2020-04-16 20:27:45 +00:00
|
|
|
SkASSERT(fDisplayList && !fTileSurface);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
fTileSurface = this->makeWrappedTileDest(direct);
|
2020-04-16 20:27:45 +00:00
|
|
|
if (fTileSurface) {
|
2020-11-10 13:30:50 +00:00
|
|
|
fTileSurface->draw(fDisplayList, this->padOffset().x(), this->padOffset().y());
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-04-16 20:27:45 +00:00
|
|
|
// We can't snap an image here bc, since we're using wrapped backend textures for the
|
|
|
|
// surfaces, that would incur a copy.
|
2020-02-14 15:49:39 +00:00
|
|
|
}
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DDLTileHelper::TileData::reset() {
|
|
|
|
// TODO: when DDLs are re-renderable we don't need to do this
|
|
|
|
fDisplayList = nullptr;
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-04-16 20:27:45 +00:00
|
|
|
fTileSurface = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImageForDst(
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<GrContextThreadSafeProxy> threadSafeProxy) {
|
2020-04-23 19:10:03 +00:00
|
|
|
SkASSERT(fCallbackContext);
|
|
|
|
|
|
|
|
// The promise image gets a ref on the promise callback context
|
2020-11-09 20:40:27 +00:00
|
|
|
sk_sp<SkImage> promiseImage =
|
2021-03-03 23:12:56 +00:00
|
|
|
SkImage::MakePromiseTexture(std::move(threadSafeProxy),
|
|
|
|
fCallbackContext->backendFormat(),
|
|
|
|
this->paddedRectSize(),
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
|
|
|
|
fPlaybackChar.colorType(),
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
fPlaybackChar.refColorSpace(),
|
|
|
|
PromiseImageCallbackContext::PromiseImageFulfillProc,
|
|
|
|
PromiseImageCallbackContext::PromiseImageReleaseProc,
|
|
|
|
(void*)this->refCallbackContext().release());
|
2020-04-23 19:10:03 +00:00
|
|
|
fCallbackContext->wasAddedToImage();
|
|
|
|
|
|
|
|
return promiseImage;
|
|
|
|
}
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
|
2020-04-23 19:10:03 +00:00
|
|
|
SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
|
2020-12-14 16:38:59 +00:00
|
|
|
|
|
|
|
const SkSurfaceCharacterization& c = tile->fPlaybackChar;
|
2020-08-26 20:33:54 +00:00
|
|
|
GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
|
2022-04-15 13:19:38 +00:00
|
|
|
GrMipmapped(c.isMipMapped()),
|
2020-08-26 20:33:54 +00:00
|
|
|
GrRenderable::kYes);
|
2020-04-23 19:10:03 +00:00
|
|
|
tile->fCallbackContext->setBackendTexture(beTex);
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
|
2021-01-11 17:29:20 +00:00
|
|
|
if (!tile->initialized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
SkASSERT(tile->fCallbackContext);
|
|
|
|
|
2020-04-16 20:27:45 +00:00
|
|
|
// TODO: it seems that, on the Linux bots, backend texture creation is failing
|
|
|
|
// a lot (skbug.com/10142)
|
2020-04-23 19:10:03 +00:00
|
|
|
SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
|
|
|
|
tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
|
2020-04-16 20:27:45 +00:00
|
|
|
|
|
|
|
tile->fTileSurface = nullptr;
|
2020-04-23 19:10:03 +00:00
|
|
|
|
|
|
|
SkASSERT(tile->fCallbackContext->unique());
|
|
|
|
tile->fCallbackContext.reset();
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
|
2020-02-26 15:27:07 +00:00
|
|
|
const SkSurfaceCharacterization& dstChar,
|
2020-02-14 15:49:39 +00:00
|
|
|
const SkIRect& viewport,
|
2021-02-26 15:41:06 +00:00
|
|
|
int numXDivisions, int numYDivisions,
|
2020-11-10 13:30:50 +00:00
|
|
|
bool addRandomPaddingToDst)
|
2021-02-26 15:41:06 +00:00
|
|
|
: fNumXDivisions(numXDivisions)
|
|
|
|
, fNumYDivisions(numYDivisions)
|
|
|
|
, fTiles(numXDivisions * numYDivisions)
|
2020-04-23 19:10:03 +00:00
|
|
|
, fDstCharacterization(dstChar) {
|
2021-02-26 15:41:06 +00:00
|
|
|
SkASSERT(fNumXDivisions > 0 && fNumYDivisions > 0);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2021-02-26 15:41:06 +00:00
|
|
|
int xTileSize = viewport.width()/fNumXDivisions;
|
|
|
|
int yTileSize = viewport.height()/fNumYDivisions;
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
SkRandom rand;
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
// Create the destination tiles
|
2021-02-26 15:41:06 +00:00
|
|
|
for (int y = 0, yOff = 0; y < fNumYDivisions; ++y, yOff += yTileSize) {
|
|
|
|
int ySize = (y < fNumYDivisions-1) ? yTileSize : viewport.height()-yOff;
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2021-02-26 15:41:06 +00:00
|
|
|
for (int x = 0, xOff = 0; x < fNumXDivisions; ++x, xOff += xTileSize) {
|
|
|
|
int xSize = (x < fNumXDivisions-1) ? xTileSize : viewport.width()-xOff;
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
|
|
|
|
|
|
|
|
SkASSERT(viewport.contains(clip));
|
|
|
|
|
2020-11-10 13:30:50 +00:00
|
|
|
static const uint32_t kMaxPad = 64;
|
|
|
|
int32_t lPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
|
|
|
|
int32_t tPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
|
|
|
|
int32_t rPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
|
|
|
|
int32_t bPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
|
|
|
|
|
2021-02-26 15:41:06 +00:00
|
|
|
fTiles[y*fNumXDivisions+x].init(y*fNumXDivisions+x, direct, dstChar, clip,
|
2020-11-10 13:30:50 +00:00
|
|
|
{lPad, tPad, rPad, bPad});
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 17:29:40 +00:00
|
|
|
void DDLTileHelper::createDDLsInParallel(SkPicture* picture) {
|
2018-05-29 20:13:26 +00:00
|
|
|
#if 1
|
2021-03-03 23:12:56 +00:00
|
|
|
SkTaskGroup().batch(this->numTiles(), [&](int i) {
|
2021-03-29 17:29:40 +00:00
|
|
|
fTiles[i].createDDL(picture);
|
2021-03-03 23:12:56 +00:00
|
|
|
});
|
2020-04-23 19:10:03 +00:00
|
|
|
SkTaskGroup().add([this]{ this->createComposeDDL(); });
|
2018-06-13 13:01:36 +00:00
|
|
|
SkTaskGroup().wait();
|
2018-05-29 20:13:26 +00:00
|
|
|
#else
|
|
|
|
// Use this code path to debug w/o threads
|
2020-03-06 20:26:28 +00:00
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2021-03-29 17:29:40 +00:00
|
|
|
fTiles[i].createDDL(picture);
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
2020-04-23 19:10:03 +00:00
|
|
|
this->createComposeDDL();
|
2018-05-29 20:13:26 +00:00
|
|
|
#endif
|
2020-02-14 15:49:39 +00:00
|
|
|
}
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-02-20 17:45:19 +00:00
|
|
|
// On the gpu thread:
|
|
|
|
// precompile any programs
|
|
|
|
// replay the DDL into a surface to make the tile image
|
|
|
|
// compose the tile image into the main canvas
|
2020-07-07 17:18:47 +00:00
|
|
|
static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
|
2020-02-20 17:45:19 +00:00
|
|
|
|
|
|
|
// TODO: schedule program compilation as their own tasks
|
2020-07-07 17:18:47 +00:00
|
|
|
tile->precompile(direct);
|
2020-02-20 17:45:19 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
tile->draw(direct);
|
2020-05-29 14:41:33 +00:00
|
|
|
|
|
|
|
tile->dropDDL();
|
2020-02-20 17:45:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
// We expect to have more than one recording thread but just one gpu thread
|
|
|
|
void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
|
|
|
|
SkTaskGroup* gpuTaskGroup,
|
2021-03-29 17:29:40 +00:00
|
|
|
GrDirectContext* dContext,
|
|
|
|
SkPicture* picture) {
|
2021-02-22 22:24:22 +00:00
|
|
|
SkASSERT(recordingTaskGroup && gpuTaskGroup && dContext);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
|
|
|
TileData* tile = &fTiles[i];
|
2021-01-11 17:29:20 +00:00
|
|
|
if (!tile->initialized()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-14 15:49:39 +00:00
|
|
|
|
|
|
|
// On a recording thread:
|
|
|
|
// generate the tile's DDL
|
|
|
|
// schedule gpu-thread processing of the DDL
|
|
|
|
// Note: a finer grained approach would be add a scheduling task which would evaluate
|
|
|
|
// which DDLs were ready to be rendered based on their prerequisites
|
2021-03-29 17:29:40 +00:00
|
|
|
recordingTaskGroup->add([tile, gpuTaskGroup, dContext, picture]() {
|
|
|
|
tile->createDDL(picture);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2021-02-22 22:24:22 +00:00
|
|
|
gpuTaskGroup->add([dContext, tile]() {
|
|
|
|
do_gpu_stuff(dContext, tile);
|
2020-02-14 15:49:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-04-23 19:10:03 +00:00
|
|
|
|
|
|
|
recordingTaskGroup->add([this] { this->createComposeDDL(); });
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:41:33 +00:00
|
|
|
// Only called from skpbench
|
2021-03-29 17:29:40 +00:00
|
|
|
void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* dContext, SkPicture* picture) {
|
2020-03-06 20:26:28 +00:00
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2021-03-29 17:29:40 +00:00
|
|
|
fTiles[i].createDDL(picture);
|
|
|
|
fTiles[i].draw(dContext);
|
2020-03-06 20:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:41:33 +00:00
|
|
|
// Only called from skpbench
|
2021-03-29 17:29:40 +00:00
|
|
|
void DDLTileHelper::drawAllTilesDirectly(GrDirectContext* dContext, SkPicture* picture) {
|
2020-03-06 20:26:28 +00:00
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2021-03-29 17:29:40 +00:00
|
|
|
fTiles[i].drawSKPDirectly(dContext, picture);
|
2020-03-06 20:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
void DDLTileHelper::dropCallbackContexts() {
|
2020-02-14 15:49:39 +00:00
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2020-04-23 19:10:03 +00:00
|
|
|
fTiles[i].dropCallbackContext();
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DDLTileHelper::resetAllTiles() {
|
2020-02-14 15:49:39 +00:00
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2018-05-29 20:13:26 +00:00
|
|
|
fTiles[i].reset();
|
|
|
|
}
|
2020-04-23 19:10:03 +00:00
|
|
|
fComposeDDL.reset();
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
|
2020-04-16 20:27:45 +00:00
|
|
|
|
|
|
|
if (taskGroup) {
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
|
|
|
TileData* tile = &fTiles[i];
|
2021-01-11 17:29:20 +00:00
|
|
|
if (!tile->initialized()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2020-07-07 17:18:47 +00:00
|
|
|
TileData::CreateBackendTexture(direct, &fTiles[i]);
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
|
2020-04-16 20:27:45 +00:00
|
|
|
if (taskGroup) {
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
|
|
|
TileData* tile = &fTiles[i];
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < this->numTiles(); ++i) {
|
2020-07-07 17:18:47 +00:00
|
|
|
TileData::DeleteBackendTexture(direct, &fTiles[i]);
|
2020-04-16 20:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|