| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrPictureUtils_DEFINED | 8 #ifndef GrPictureUtils_DEFINED |
| 9 #define GrPictureUtils_DEFINED | 9 #define GrPictureUtils_DEFINED |
| 10 | 10 |
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkTDArray.h" | 12 #include "SkTArray.h" |
| 13 | 13 |
| 14 // This class encapsulates the GPU-backend-specific acceleration data | 14 // This class encapsulates the GPU-backend-specific acceleration data |
| 15 // for a single SkPicture | 15 // for a single SkPicture |
| 16 class GrAccelData : public SkPicture::AccelData { | 16 class GrAccelData : public SkPicture::AccelData { |
| 17 public: | 17 public: |
| 18 // Information about a given saveLayer in an SkPicture | 18 // Information about a given saveLayer in an SkPicture |
| 19 struct SaveLayerInfo { | 19 class SaveLayerInfo { |
| 20 // True if the SaveLayerInfo is valid. False if either 'fOffset' is | 20 public: |
| 21 // invalid (due to a non-invertible CTM) or 'fPaint' is NULL (due | 21 SaveLayerInfo() : fPicture(NULL), fPaint(NULL) {} |
| 22 // to a non-copyable paint). | 22 ~SaveLayerInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); } |
| 23 |
| 24 // True if the SaveLayerInfo is valid. False if 'fOffset' is |
| 25 // invalid (due to a non-invertible CTM). |
| 26 // TODO: remove fValid |
| 23 bool fValid; | 27 bool fValid; |
| 24 // ID of the picture containing the layer. This can be the ID of | 28 // The picture owning the layer. If the owning picture is the top-most |
| 25 // a sub-picture embedded within the picture owning the GrAccelData | 29 // one (i.e., the picture for which this GrAccelData was created) then |
| 26 uint32_t fPictureID; | 30 // this pointer is NULL. If it is a nested picture then the pointer |
| 31 // is non-NULL and owns a ref on the picture. |
| 32 const SkPicture* fPicture; |
| 27 // The size of the saveLayer | 33 // The size of the saveLayer |
| 28 SkISize fSize; | 34 SkISize fSize; |
| 29 // The matrix state in which this layer's draws must occur. It does not | 35 // 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 t
he origin. | 36 // include the translation needed to map the layer's top-left point to t
he origin. |
| 31 SkMatrix fOriginXform; | 37 SkMatrix fOriginXform; |
| 32 // The offset that needs to be passed to drawBitmap to correctly | 38 // The offset that needs to be passed to drawBitmap to correctly |
| 33 // position the pre-rendered layer. It is in device space. | 39 // position the pre-rendered layer. It is in device space. |
| 34 SkIPoint fOffset; | 40 SkIPoint fOffset; |
| 35 // The paint to use on restore. NULL if the paint was not copyable (and | 41 // The paint to use on restore. Can be NULL since it is optional. |
| 36 // thus that this layer should not be pulled forward). | |
| 37 const SkPaint* fPaint; | 42 const SkPaint* fPaint; |
| 38 // The ID of this saveLayer in the picture. 0 is an invalid ID. | 43 // The ID of this saveLayer in the picture. 0 is an invalid ID. |
| 39 size_t fSaveLayerOpID; | 44 size_t fSaveLayerOpID; |
| 40 // The ID of the matching restore in the picture. 0 is an invalid ID. | 45 // The ID of the matching restore in the picture. 0 is an invalid ID. |
| 41 size_t fRestoreOpID; | 46 size_t fRestoreOpID; |
| 42 // True if this saveLayer has at least one other saveLayer nested within
it. | 47 // True if this saveLayer has at least one other saveLayer nested within
it. |
| 43 // False otherwise. | 48 // False otherwise. |
| 44 bool fHasNestedLayers; | 49 bool fHasNestedLayers; |
| 45 // True if this saveLayer is nested within another. False otherwise. | 50 // True if this saveLayer is nested within another. False otherwise. |
| 46 bool fIsNested; | 51 bool fIsNested; |
| 47 }; | 52 }; |
| 48 | 53 |
| 49 GrAccelData(Key key) : INHERITED(key) { } | 54 GrAccelData(Key key) : INHERITED(key) { } |
| 50 | 55 |
| 51 virtual ~GrAccelData() { | 56 virtual ~GrAccelData() { } |
| 52 for (int i = 0; i < fSaveLayerInfo.count(); ++i) { | |
| 53 SkDELETE(fSaveLayerInfo[i].fPaint); | |
| 54 } | |
| 55 } | |
| 56 | 57 |
| 57 void addSaveLayerInfo(const SaveLayerInfo& info) { | 58 SaveLayerInfo& addSaveLayerInfo() { return fSaveLayerInfo.push_back(); } |
| 58 SkASSERT(info.fSaveLayerOpID < info.fRestoreOpID); | |
| 59 *fSaveLayerInfo.push() = info; | |
| 60 } | |
| 61 | 59 |
| 62 int numSaveLayers() const { return fSaveLayerInfo.count(); } | 60 int numSaveLayers() const { return fSaveLayerInfo.count(); } |
| 63 | 61 |
| 64 const SaveLayerInfo& saveLayerInfo(int index) const { | 62 const SaveLayerInfo& saveLayerInfo(int index) const { |
| 65 SkASSERT(index < fSaveLayerInfo.count()); | 63 SkASSERT(index < fSaveLayerInfo.count()); |
| 66 | 64 |
| 67 return fSaveLayerInfo[index]; | 65 return fSaveLayerInfo[index]; |
| 68 } | 66 } |
| 69 | 67 |
| 70 // We may, in the future, need to pass in the GPUDevice in order to | 68 // We may, in the future, need to pass in the GPUDevice in order to |
| 71 // incorporate the clip and matrix state into the key | 69 // incorporate the clip and matrix state into the key |
| 72 static SkPicture::AccelData::Key ComputeAccelDataKey(); | 70 static SkPicture::AccelData::Key ComputeAccelDataKey(); |
| 73 | 71 |
| 74 private: | 72 private: |
| 75 SkTDArray<SaveLayerInfo> fSaveLayerInfo; | 73 SkTArray<SaveLayerInfo, true> fSaveLayerInfo; |
| 76 | 74 |
| 77 typedef SkPicture::AccelData INHERITED; | 75 typedef SkPicture::AccelData INHERITED; |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 const GrAccelData* GPUOptimize(const SkPicture* pict); | 78 const GrAccelData* GPUOptimize(const SkPicture* pict); |
| 81 | 79 |
| 82 #endif // GrPictureUtils_DEFINED | 80 #endif // GrPictureUtils_DEFINED |
| OLD | NEW |