blob: 55b294ac6985a14c00c5e59b3e6ebddd2d7f65d8 [file] [log] [blame]
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +00001/*
2 * Copyright 2014 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 GrPictureUtils_DEFINED
9#define GrPictureUtils_DEFINED
10
11#include "SkPicture.h"
12#include "SkTDArray.h"
13
14// This class encapsulates the GPU-backend-specific acceleration data
15// for a single SkPicture
robertphillips6617d502014-08-18 09:39:34 -070016class GrAccelData : public SkPicture::AccelData {
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000017public:
18 // Information about a given saveLayer in an SkPicture
19 struct SaveLayerInfo {
commit-bot@chromium.org0205aba2014-05-06 12:02:22 +000020 // True if the SaveLayerInfo is valid. False if either 'fOffset' is
21 // invalid (due to a non-invertible CTM) or 'fPaint' is NULL (due
22 // to a non-copyable paint).
23 bool fValid;
robertphillipsd6283302014-08-27 11:53:28 -070024 // ID of the picture containing the layer. This can be the ID of
25 // a sub-picture embedded within the picture owning the GrAccelData
26 uint32_t fPictureID;
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000027 // The size of the saveLayer
28 SkISize fSize;
robertphillips4815fe52014-09-16 10:32:43 -070029 // The matrix state in which this layer's draws must occur. It does not
30 // include the translation needed to map the layer's top-left point to the origin.
robertphillipsd6283302014-08-27 11:53:28 -070031 SkMatrix fOriginXform;
commit-bot@chromium.org0205aba2014-05-06 12:02:22 +000032 // The offset that needs to be passed to drawBitmap to correctly
commit-bot@chromium.orgf97d65d2014-05-08 23:24:05 +000033 // position the pre-rendered layer. It is in device space.
34 SkIPoint fOffset;
commit-bot@chromium.org0205aba2014-05-06 12:02:22 +000035 // The paint to use on restore. NULL if the paint was not copyable (and
36 // thus that this layer should not be pulled forward).
37 const SkPaint* fPaint;
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000038 // The ID of this saveLayer in the picture. 0 is an invalid ID.
39 size_t fSaveLayerOpID;
40 // The ID of the matching restore in the picture. 0 is an invalid ID.
41 size_t fRestoreOpID;
42 // True if this saveLayer has at least one other saveLayer nested within it.
43 // False otherwise.
44 bool fHasNestedLayers;
commit-bot@chromium.org0205aba2014-05-06 12:02:22 +000045 // True if this saveLayer is nested within another. False otherwise.
46 bool fIsNested;
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000047 };
48
robertphillips6617d502014-08-18 09:39:34 -070049 GrAccelData(Key key) : INHERITED(key) { }
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000050
robertphillips6617d502014-08-18 09:39:34 -070051 virtual ~GrAccelData() {
commit-bot@chromium.org8fd93822014-05-06 13:43:22 +000052 for (int i = 0; i < fSaveLayerInfo.count(); ++i) {
53 SkDELETE(fSaveLayerInfo[i].fPaint);
54 }
55 }
56
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000057 void addSaveLayerInfo(const SaveLayerInfo& info) {
58 SkASSERT(info.fSaveLayerOpID < info.fRestoreOpID);
59 *fSaveLayerInfo.push() = info;
60 }
61
62 int numSaveLayers() const { return fSaveLayerInfo.count(); }
63
64 const SaveLayerInfo& saveLayerInfo(int index) const {
65 SkASSERT(index < fSaveLayerInfo.count());
66
67 return fSaveLayerInfo[index];
68 }
69
commit-bot@chromium.org0205aba2014-05-06 12:02:22 +000070 // We may, in the future, need to pass in the GPUDevice in order to
71 // incorporate the clip and matrix state into the key
72 static SkPicture::AccelData::Key ComputeAccelDataKey();
73
robertphillips@google.combeb1af22014-05-07 21:31:09 +000074private:
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000075 SkTDArray<SaveLayerInfo> fSaveLayerInfo;
76
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000077 typedef SkPicture::AccelData INHERITED;
78};
79
robertphillipsd6283302014-08-27 11:53:28 -070080const GrAccelData* GPUOptimize(const SkPicture* pict);
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +000081
82#endif // GrPictureUtils_DEFINED