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 // The picture owning the layer. If the owning picture is the top-most
25 // one (i.e., the picture for which this GrAccelData was created) then
26 // this pointer is NULL. If it is a nested picture then the pointer
27 // is non-NULL and owns a ref on the picture.
28 const SkPicture* fPicture;
29 // The device space bounds of this layer.
31 // The pre-matrix begins as the identity and accumulates the transforms
32 // of the containing SkPictures (if any). This matrix state has to be
33 // part of the initial matrix during replay so that it will be
34 // preserved across setMatrix calls.
36 // The matrix state (in the leaf picture) in which this layer's draws
37 // must occur. It will/can be overridden by setMatrix calls in the
38 // layer itself. It does not include the translation needed to map the
39 // layer's top-left point to the origin (which must be part of the
42 // The paint to use on restore. Can be NULL since it is optional.
43 const SkPaint* fPaint;
44 // The ID of this saveLayer in the picture. 0 is an invalid ID.
45 size_t fSaveLayerOpID;
46 // The ID of the matching restore in the picture. 0 is an invalid ID.
48 // True if this saveLayer has at least one other saveLayer nested within it.
50 bool fHasNestedLayers;
51 // True if this saveLayer is nested within another. False otherwise.
55 GrAccelData(Key key) : INHERITED(key) { }
57 virtual ~GrAccelData() { }
59 SaveLayerInfo& addSaveLayerInfo() { return fSaveLayerInfo.push_back(); }
61 int numSaveLayers() const { return fSaveLayerInfo.count(); }
63 const SaveLayerInfo& saveLayerInfo(int index) const {
64 SkASSERT(index < fSaveLayerInfo.count());
66 return fSaveLayerInfo[index];
69 // We may, in the future, need to pass in the GPUDevice in order to
70 // incorporate the clip and matrix state into the key
71 static SkPicture::AccelData::Key ComputeAccelDataKey();
74 SkTArray<SaveLayerInfo, true> fSaveLayerInfo;
76 typedef SkPicture::AccelData INHERITED;
79 const GrAccelData* GPUOptimize(const SkPicture* pict);
81 #endif // GrPictureUtils_DEFINED