skia2/tools/DDLTileHelper.h
Robert Phillips a865a3aedb Improve DDLTileHelper
TileData now gets a pointer to the final surface
   This allows the tile to, once rendered, compose itself into
   the final surface

DDLTileHelper now stores the TileData in a dumb array
   SkTArray is overkill and, since TileData*s are being doled
   out to threads, we never want reallocation

Added DDLTileHelper::kickOffThreadedWork
   The old code only performed DDL creation in parallel. This
   entry point also replays the DDLs and composes them into the
   final surface in parallel

Change-Id: I66e02ef7f8291b4d402e22bee0ad3546e930609e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270796
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-02-14 18:48:50 +00:00

95 lines
3.0 KiB
C++

/*
* 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
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurfaceCharacterization.h"
class DDLPromiseImageHelper;
class SkCanvas;
class SkData;
class SkDeferredDisplayList;
class SkPicture;
class SkSurface;
class SkSurfaceCharacterization;
class DDLTileHelper {
public:
// The TileData class encapsulates the information and behavior of a single tile when
// rendering with DDLs.
class TileData {
public:
TileData() {}
~TileData();
void init(int id, sk_sp<SkSurface> dstSurface, const SkIRect& clip);
// Convert the compressedPictureData into an SkPicture replacing each image-index
// with a promise image.
void createTileSpecificSKP(SkData* compressedPictureData,
const DDLPromiseImageHelper& helper);
// Create the DDL for this tile (i.e., fill in 'fDisplayList').
void createDDL();
// Replay the recorded DDL into the tile surface - creating 'fImage'.
void draw(GrContext*);
// Draw the result of replaying the DDL (i.e., 'fImage') into the
// final destination surface ('fDstSurface').
void compose();
void reset();
int id() const { return fID; }
private:
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
std::unique_ptr<SkDeferredDisplayList> fDisplayList;
};
DDLTileHelper(sk_sp<SkSurface> dstSurface,
const SkIRect& viewport,
int numDivisions);
~DDLTileHelper() {
delete[] fTiles;
}
void createSKPPerTile(SkData* compressedPictureData, const DDLPromiseImageHelper& helper);
void kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
SkTaskGroup* gpuTaskGroup,
GrContext* gpuThreadContext);
void createDDLsInParallel();
void drawAllTilesAndFlush(GrContext*, bool flush);
void composeAllTiles();
void resetAllTiles();
int numTiles() const { return fNumDivisions * fNumDivisions; }
private:
int fNumDivisions; // number of tiles along a side
TileData* fTiles; // 'fNumDivisions' x 'fNumDivisions'
};
#endif