2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrPictureUtils_DEFINED
9 #define GrPictureUtils_DEFINED
11 #include "SkPicture.h"
14 // This class encapsulates the GPU-backend-specific acceleration data
15 // for a single SkPicture
16 class GrAccelData : public SkPicture::AccelData {
18 // Information about a given saveLayer in an SkPicture
21 SaveLayerInfo() : fPicture(NULL), fPaint(NULL) {}
22 ~SaveLayerInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); }
24 // True if the SaveLayerInfo is valid. False if 'fOffset' is
25 // invalid (due to a non-invertible CTM).
26 // TODO: remove fValid
28 // The picture owning the layer. If the owning picture is the top-most
29 // one (i.e., the picture for which this GrAccelData was created) then
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;
33 // The size of the saveLayer
35 // The matrix state in which this layer's draws must occur. It does not
36 // include the translation needed to map the layer's top-left point to the origin.
37 SkMatrix fOriginXform;
38 // The offset that needs to be passed to drawBitmap to correctly
39 // position the pre-rendered layer. It is in device space.
41 // The paint to use on restore. Can be NULL since it is optional.
42 const SkPaint* fPaint;
43 // The ID of this saveLayer in the picture. 0 is an invalid ID.
44 size_t fSaveLayerOpID;
45 // The ID of the matching restore in the picture. 0 is an invalid ID.
47 // True if this saveLayer has at least one other saveLayer nested within it.
49 bool fHasNestedLayers;
50 // True if this saveLayer is nested within another. False otherwise.
54 GrAccelData(Key key) : INHERITED(key) { }
56 virtual ~GrAccelData() { }
58 SaveLayerInfo& addSaveLayerInfo() { return fSaveLayerInfo.push_back(); }
60 int numSaveLayers() const { return fSaveLayerInfo.count(); }
62 const SaveLayerInfo& saveLayerInfo(int index) const {
63 SkASSERT(index < fSaveLayerInfo.count());
65 return fSaveLayerInfo[index];
68 // We may, in the future, need to pass in the GPUDevice in order to
69 // incorporate the clip and matrix state into the key
70 static SkPicture::AccelData::Key ComputeAccelDataKey();
73 SkTArray<SaveLayerInfo, true> fSaveLayerInfo;
75 typedef SkPicture::AccelData INHERITED;
78 const GrAccelData* GPUOptimize(const SkPicture* pict);
80 #endif // GrPictureUtils_DEFINED