commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 16 | class GPUAccelData : public SkPicture::AccelData { |
| 17 | public: |
| 18 | // Information about a given saveLayer in an SkPicture |
| 19 | struct SaveLayerInfo { |
commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 20 | // 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; |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 24 | // The size of the saveLayer |
| 25 | SkISize fSize; |
commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 26 | // The CTM in which this layer's draws must occur. It already incorporates |
| 27 | // the translation needed to map the layer's top-left point to the origin. |
| 28 | SkMatrix fCTM; |
| 29 | // The offset that needs to be passed to drawBitmap to correctly |
commit-bot@chromium.org | f97d65d | 2014-05-08 23:24:05 +0000 | [diff] [blame] | 30 | // position the pre-rendered layer. It is in device space. |
| 31 | SkIPoint fOffset; |
commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 32 | // The paint to use on restore. NULL if the paint was not copyable (and |
| 33 | // thus that this layer should not be pulled forward). |
| 34 | const SkPaint* fPaint; |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 35 | // The ID of this saveLayer in the picture. 0 is an invalid ID. |
| 36 | size_t fSaveLayerOpID; |
| 37 | // The ID of the matching restore in the picture. 0 is an invalid ID. |
| 38 | size_t fRestoreOpID; |
| 39 | // True if this saveLayer has at least one other saveLayer nested within it. |
| 40 | // False otherwise. |
| 41 | bool fHasNestedLayers; |
commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 42 | // True if this saveLayer is nested within another. False otherwise. |
| 43 | bool fIsNested; |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | GPUAccelData(Key key) : INHERITED(key) { } |
| 47 | |
commit-bot@chromium.org | 8fd9382 | 2014-05-06 13:43:22 +0000 | [diff] [blame] | 48 | virtual ~GPUAccelData() { |
| 49 | for (int i = 0; i < fSaveLayerInfo.count(); ++i) { |
| 50 | SkDELETE(fSaveLayerInfo[i].fPaint); |
| 51 | } |
| 52 | } |
| 53 | |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 54 | void addSaveLayerInfo(const SaveLayerInfo& info) { |
| 55 | SkASSERT(info.fSaveLayerOpID < info.fRestoreOpID); |
| 56 | *fSaveLayerInfo.push() = info; |
| 57 | } |
| 58 | |
| 59 | int numSaveLayers() const { return fSaveLayerInfo.count(); } |
| 60 | |
| 61 | const SaveLayerInfo& saveLayerInfo(int index) const { |
| 62 | SkASSERT(index < fSaveLayerInfo.count()); |
| 63 | |
| 64 | return fSaveLayerInfo[index]; |
| 65 | } |
| 66 | |
commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 67 | // We may, in the future, need to pass in the GPUDevice in order to |
| 68 | // incorporate the clip and matrix state into the key |
| 69 | static SkPicture::AccelData::Key ComputeAccelDataKey(); |
| 70 | |
robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 71 | private: |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 72 | SkTDArray<SaveLayerInfo> fSaveLayerInfo; |
| 73 | |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 74 | typedef SkPicture::AccelData INHERITED; |
| 75 | }; |
| 76 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 77 | void GatherGPUInfo(const SkPicture* pict, GPUAccelData* accelData); |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 78 | |
| 79 | #endif // GrPictureUtils_DEFINED |