Home | History | Annotate | Download | only in gpu
      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 "SkTArray.h"
     13 
     14 // This class encapsulates the GPU-backend-specific acceleration data
     15 // for a single SkPicture
     16 class GrAccelData : public SkPicture::AccelData {
     17 public:
     18     // Information about a given saveLayer in an SkPicture
     19     class SaveLayerInfo {
     20     public:
     21         SaveLayerInfo() : fPicture(NULL), fPaint(NULL) {}
     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
     27         bool 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
     34         SkISize fSize;
     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.
     40         SkIPoint fOffset;
     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.
     46         size_t  fRestoreOpID;
     47         // True if this saveLayer has at least one other saveLayer nested within it.
     48         // False otherwise.
     49         bool    fHasNestedLayers;
     50         // True if this saveLayer is nested within another. False otherwise.
     51         bool    fIsNested;
     52     };
     53 
     54     GrAccelData(Key key) : INHERITED(key) { }
     55 
     56     virtual ~GrAccelData() { }
     57 
     58     SaveLayerInfo& addSaveLayerInfo() { return fSaveLayerInfo.push_back(); }
     59 
     60     int numSaveLayers() const { return fSaveLayerInfo.count(); }
     61 
     62     const SaveLayerInfo& saveLayerInfo(int index) const {
     63         SkASSERT(index < fSaveLayerInfo.count());
     64 
     65         return fSaveLayerInfo[index];
     66     }
     67 
     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();
     71 
     72 private:
     73     SkTArray<SaveLayerInfo, true> fSaveLayerInfo;
     74 
     75     typedef SkPicture::AccelData INHERITED;
     76 };
     77 
     78 const GrAccelData* GPUOptimize(const SkPicture* pict);
     79 
     80 #endif // GrPictureUtils_DEFINED
     81