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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DDLTileHelper_DEFINED
|
|
|
|
#define DDLTileHelper_DEFINED
|
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
#include "include/core/SkDeferredDisplayList.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2021-03-03 23:12:56 +00:00
|
|
|
#include "src/core/SkSpan.h"
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
class DDLPromiseImageHelper;
|
2020-04-23 19:10:03 +00:00
|
|
|
class PromiseImageCallbackContext;
|
2018-05-29 20:13:26 +00:00
|
|
|
class SkCanvas;
|
|
|
|
class SkData;
|
2020-04-23 19:10:03 +00:00
|
|
|
class SkDeferredDisplayListRecorder;
|
2018-05-29 20:13:26 +00:00
|
|
|
class SkPicture;
|
|
|
|
class SkSurface;
|
|
|
|
class SkSurfaceCharacterization;
|
2020-07-13 17:17:09 +00:00
|
|
|
class SkTaskGroup;
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
class DDLTileHelper {
|
|
|
|
public:
|
2020-02-14 15:49:39 +00:00
|
|
|
// The TileData class encapsulates the information and behavior of a single tile when
|
|
|
|
// rendering with DDLs.
|
2018-05-29 20:13:26 +00:00
|
|
|
class TileData {
|
|
|
|
public:
|
2021-02-22 22:24:22 +00:00
|
|
|
TileData();
|
2020-02-14 15:49:39 +00:00
|
|
|
~TileData();
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2021-01-11 17:29:20 +00:00
|
|
|
bool initialized() const { return fID != -1; }
|
|
|
|
|
2020-02-26 15:27:07 +00:00
|
|
|
void init(int id,
|
2020-07-07 17:18:47 +00:00
|
|
|
GrDirectContext*,
|
2020-02-26 15:27:07 +00:00
|
|
|
const SkSurfaceCharacterization& dstChar,
|
2020-11-10 13:30:50 +00:00
|
|
|
const SkIRect& clip,
|
|
|
|
const SkIRect& paddingOutsets);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
|
|
|
// Create the DDL for this tile (i.e., fill in 'fDisplayList').
|
2021-03-03 23:12:56 +00:00
|
|
|
void createDDL(const SkPicture*);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-05-29 14:41:33 +00:00
|
|
|
void dropDDL() { fDisplayList.reset(); }
|
|
|
|
|
2020-03-05 17:52:45 +00:00
|
|
|
// Precompile all the programs required to draw this tile's DDL
|
2020-07-07 17:18:47 +00:00
|
|
|
void precompile(GrDirectContext*);
|
2020-03-05 17:52:45 +00:00
|
|
|
|
2020-03-06 20:26:28 +00:00
|
|
|
// Just draw the re-inflated per-tile SKP directly into this tile w/o going through a DDL
|
|
|
|
// first. This is used for determining the overhead of using DDLs (i.e., it replaces
|
|
|
|
// a 'createDDL' and 'draw' pair.
|
2021-03-03 23:12:56 +00:00
|
|
|
void drawSKPDirectly(GrDirectContext*, const SkPicture*);
|
2020-03-06 20:26:28 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
// Replay the recorded DDL into the tile surface - filling in 'fBackendTexture'.
|
2020-07-07 17:18:47 +00:00
|
|
|
void draw(GrDirectContext*);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
int id() const { return fID; }
|
2020-04-23 19:10:03 +00:00
|
|
|
SkIRect clipRect() const { return fClip; }
|
2020-11-10 13:30:50 +00:00
|
|
|
SkISize paddedRectSize() const {
|
|
|
|
return { fClip.width() + fPaddingOutsets.fLeft + fPaddingOutsets.fRight,
|
|
|
|
fClip.height() + fPaddingOutsets.fTop + fPaddingOutsets.fBottom };
|
|
|
|
}
|
|
|
|
SkIVector padOffset() const { return { fPaddingOutsets.fLeft, fPaddingOutsets.fTop }; }
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2020-02-20 17:45:19 +00:00
|
|
|
SkDeferredDisplayList* ddl() { return fDisplayList.get(); }
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<SkImage> makePromiseImageForDst(sk_sp<GrContextThreadSafeProxy>);
|
2020-04-23 19:10:03 +00:00
|
|
|
void dropCallbackContext() { fCallbackContext.reset(); }
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
static void CreateBackendTexture(GrDirectContext*, TileData*);
|
|
|
|
static void DeleteBackendTexture(GrDirectContext*, TileData*);
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
private:
|
2020-10-20 14:11:53 +00:00
|
|
|
sk_sp<SkSurface> makeWrappedTileDest(GrRecordingContext* context);
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
sk_sp<PromiseImageCallbackContext> refCallbackContext() { return fCallbackContext; }
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
int fID = -1;
|
|
|
|
SkIRect fClip; // in the device space of the final SkSurface
|
2020-11-10 13:30:50 +00:00
|
|
|
SkIRect fPaddingOutsets; // random padding for the output surface
|
2020-12-14 16:38:59 +00:00
|
|
|
SkSurfaceCharacterization fPlaybackChar; // characterization for the tile's dst surface
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
// The callback context holds (via its SkPromiseImageTexture) the backend texture
|
|
|
|
// that is both wrapped in 'fTileSurface' and backs this tile's promise image
|
|
|
|
// (i.e., the one returned by 'makePromiseImage').
|
|
|
|
sk_sp<PromiseImageCallbackContext> fCallbackContext;
|
|
|
|
// 'fTileSurface' wraps the backend texture in 'fCallbackContext' and must exist until
|
|
|
|
// after 'fDisplayList' has been flushed (bc it owns the proxy the DDL's destination
|
|
|
|
// trampoline points at).
|
|
|
|
// TODO: fix the ref-order so we don't need 'fTileSurface' here
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkSurface> fTileSurface;
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> fDisplayList;
|
2018-05-29 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
DDLTileHelper(GrDirectContext*,
|
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);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
void kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
|
|
|
|
SkTaskGroup* gpuTaskGroup,
|
2021-03-29 17:29:40 +00:00
|
|
|
GrDirectContext*,
|
|
|
|
SkPicture*);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2021-03-29 17:29:40 +00:00
|
|
|
void createDDLsInParallel(SkPicture*);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
// Create the DDL that will compose all the tile images into a final result.
|
|
|
|
void createComposeDDL();
|
2020-06-29 14:00:08 +00:00
|
|
|
const sk_sp<SkDeferredDisplayList>& composeDDL() const { return fComposeDDL; }
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-03-06 20:26:28 +00:00
|
|
|
// For each tile, create its DDL and then draw it - all on a single thread. This is to allow
|
|
|
|
// comparison w/ just drawing the SKP directly (i.e., drawAllTilesDirectly). The
|
|
|
|
// DDL creations and draws are interleaved to prevent starvation of the GPU.
|
|
|
|
// Note: this is somewhat of a misuse/pessimistic-use of DDLs since they are supposed to
|
|
|
|
// be created on a separate thread.
|
2021-03-29 17:29:40 +00:00
|
|
|
void interleaveDDLCreationAndDraw(GrDirectContext*, SkPicture*);
|
2020-03-06 20:26:28 +00:00
|
|
|
|
|
|
|
// This draws all the per-tile SKPs directly into all of the tiles w/o converting them to
|
|
|
|
// DDLs first - all on a single thread.
|
2021-03-29 17:29:40 +00:00
|
|
|
void drawAllTilesDirectly(GrDirectContext*, SkPicture*);
|
2020-03-06 20:26:28 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
void dropCallbackContexts();
|
2018-05-29 20:13:26 +00:00
|
|
|
void resetAllTiles();
|
|
|
|
|
2021-02-26 15:41:06 +00:00
|
|
|
int numTiles() const { return fNumXDivisions * fNumYDivisions; }
|
2020-02-14 15:49:39 +00:00
|
|
|
|
2020-07-07 17:18:47 +00:00
|
|
|
void createBackendTextures(SkTaskGroup*, GrDirectContext*);
|
|
|
|
void deleteBackendTextures(SkTaskGroup*, GrDirectContext*);
|
2020-04-16 20:27:45 +00:00
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
private:
|
2021-02-26 15:41:06 +00:00
|
|
|
int fNumXDivisions; // number of tiles horizontally
|
|
|
|
int fNumYDivisions; // number of tiles vertically
|
|
|
|
SkAutoTArray<TileData> fTiles; // 'fNumXDivisions' x 'fNumYDivisions'
|
2020-04-23 19:10:03 +00:00
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> fComposeDDL;
|
2020-04-23 19:10:03 +00:00
|
|
|
|
|
|
|
const SkSurfaceCharacterization fDstCharacterization;
|
2018-05-29 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|