blob: f7f45c0854fb83bda1d6a51657c04570a35c64db [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
8#ifndef DDLTileHelper_DEFINED
9#define DDLTileHelper_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
12#include "include/core/SkRefCnt.h"
13#include "include/core/SkSurfaceCharacterization.h"
Robert Phillips96601082018-05-29 16:13:26 -040014
Robert Phillips96601082018-05-29 16:13:26 -040015class DDLPromiseImageHelper;
16class SkCanvas;
17class SkData;
18class SkDeferredDisplayList;
19class SkPicture;
20class SkSurface;
21class SkSurfaceCharacterization;
22
23class DDLTileHelper {
24public:
25 // TileData class encapsulates the information and behavior for a single tile/thread in
26 // a DDL rendering.
27 class TileData {
28 public:
29 TileData(sk_sp<SkSurface>, const SkIRect& clip);
30
31 // This method can be invoked in parallel
32 // In each thread we will reconvert the compressedPictureData into an SkPicture
33 // replacing each image-index with a promise image.
34 void createTileSpecificSKP(SkData* compressedPictureData,
35 const DDLPromiseImageHelper& helper);
36
37 // This method can be invoked in parallel
38 // Create the per-tile DDL from the per-tile SKP
39 void createDDL();
40
41 // This method operates serially and replays the recorded DDL into the tile surface.
42 void draw();
43
44 // This method also operates serially and composes the results of replaying the DDL into
45 // the final destination surface.
46 void compose(SkCanvas* dst);
47
48 void reset();
49
50 private:
Robert Phillips7a3197b2018-09-26 21:18:23 +000051 sk_sp<SkSurface> fSurface;
52 SkSurfaceCharacterization fCharacterization;
53 SkIRect fClip; // in the device space of the dest canvas
54 sk_sp<SkPicture> fReconstitutedPicture;
55 SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the
56 // reconstituted picture
Robert Phillips96601082018-05-29 16:13:26 -040057 std::unique_ptr<SkDeferredDisplayList> fDisplayList;
58 };
59
60 DDLTileHelper(SkCanvas* canvas, const SkIRect& viewport, int numDivisions);
61
62 void createSKPPerTile(SkData* compressedPictureData, const DDLPromiseImageHelper& helper);
63
64 void createDDLsInParallel();
65
66 void drawAllTilesAndFlush(GrContext*, bool flush);
67
68 void composeAllTiles(SkCanvas* dstCanvas);
69
70 void resetAllTiles();
71
72private:
73 int fNumDivisions; // number of tiles along a side
74 SkTArray<TileData> fTiles;
75};
76
77#endif