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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
class DDLPromiseImageHelper;
|
|
|
|
class SkCanvas;
|
|
|
|
class SkData;
|
|
|
|
class SkDeferredDisplayList;
|
|
|
|
class SkPicture;
|
|
|
|
class SkSurface;
|
|
|
|
class SkSurfaceCharacterization;
|
|
|
|
|
|
|
|
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:
|
2020-02-14 15:49:39 +00:00
|
|
|
TileData() {}
|
|
|
|
~TileData();
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-02-26 15:27:07 +00:00
|
|
|
void init(int id,
|
|
|
|
sk_sp<SkSurface> dstSurface,
|
|
|
|
const SkSurfaceCharacterization& dstChar,
|
|
|
|
const SkIRect& clip);
|
2020-02-14 15:49:39 +00:00
|
|
|
|
|
|
|
// Convert the compressedPictureData into an SkPicture replacing each image-index
|
|
|
|
// with a promise image.
|
2018-05-29 20:13:26 +00:00
|
|
|
void createTileSpecificSKP(SkData* compressedPictureData,
|
|
|
|
const DDLPromiseImageHelper& helper);
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
// Create the DDL for this tile (i.e., fill in 'fDisplayList').
|
2018-05-29 20:13:26 +00:00
|
|
|
void createDDL();
|
|
|
|
|
2020-03-05 17:52:45 +00:00
|
|
|
// Precompile all the programs required to draw this tile's DDL
|
|
|
|
void precompile(GrContext*);
|
|
|
|
|
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.
|
|
|
|
void drawSKPDirectly(GrContext*);
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
// Replay the recorded DDL into the tile surface - creating 'fImage'.
|
|
|
|
void draw(GrContext*);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
// Draw the result of replaying the DDL (i.e., 'fImage') into the
|
|
|
|
// final destination surface ('fDstSurface').
|
|
|
|
void compose();
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
int id() const { return fID; }
|
|
|
|
|
2020-02-20 17:45:19 +00:00
|
|
|
SkDeferredDisplayList* ddl() { return fDisplayList.get(); }
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
private:
|
2020-02-14 15:49:39 +00:00
|
|
|
int fID = -1;
|
|
|
|
sk_sp<SkSurface> fDstSurface; // the ultimate target for composition
|
|
|
|
SkSurfaceCharacterization fCharacterization; // characterization for the tile's surface
|
|
|
|
SkIRect fClip; // in the device space of the 'fDstSurface'
|
|
|
|
|
|
|
|
sk_sp<SkImage> fImage; // the result of replaying the DDL
|
|
|
|
sk_sp<SkPicture> fReconstitutedPicture;
|
|
|
|
SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the
|
|
|
|
// reconstituted picture
|
2018-05-29 20:13:26 +00:00
|
|
|
std::unique_ptr<SkDeferredDisplayList> fDisplayList;
|
|
|
|
};
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
DDLTileHelper(sk_sp<SkSurface> dstSurface,
|
2020-02-26 15:27:07 +00:00
|
|
|
const SkSurfaceCharacterization& dstChar,
|
2020-02-14 15:49:39 +00:00
|
|
|
const SkIRect& viewport,
|
|
|
|
int numDivisions);
|
|
|
|
~DDLTileHelper() {
|
|
|
|
delete[] fTiles;
|
|
|
|
}
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
void createSKPPerTile(SkData* compressedPictureData, const DDLPromiseImageHelper& helper);
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
void kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
|
|
|
|
SkTaskGroup* gpuTaskGroup,
|
|
|
|
GrContext* gpuThreadContext);
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
void createDDLsInParallel();
|
|
|
|
|
2020-03-05 17:52:45 +00:00
|
|
|
void precompileAndDrawAllTiles(GrContext*);
|
2018-05-29 20:13:26 +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.
|
|
|
|
void interleaveDDLCreationAndDraw(GrContext*);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
void drawAllTilesDirectly(GrContext*);
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
void composeAllTiles();
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
void resetAllTiles();
|
|
|
|
|
2020-02-14 15:49:39 +00:00
|
|
|
int numTiles() const { return fNumDivisions * fNumDivisions; }
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
private:
|
|
|
|
int fNumDivisions; // number of tiles along a side
|
2020-02-14 15:49:39 +00:00
|
|
|
TileData* fTiles; // 'fNumDivisions' x 'fNumDivisions'
|
2018-05-29 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|