Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2016 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 GrOpList_DEFINED
      9 #define GrOpList_DEFINED
     10 
     11 #include "GrGpuResourceRef.h"
     12 #include "SkRefCnt.h"
     13 #include "SkTDArray.h"
     14 
     15 //#define ENABLE_MDB 1
     16 
     17 class GrAuditTrail;
     18 class GrCaps;
     19 class GrOpFlushState;
     20 class GrRenderTargetOpList;
     21 class GrResourceProvider;
     22 class GrSurfaceProxy;
     23 class GrTextureProxy;
     24 class GrTextureOpList;
     25 
     26 struct SkIPoint;
     27 struct SkIRect;
     28 
     29 class GrOpList : public SkRefCnt {
     30 public:
     31     GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*);
     32     ~GrOpList() override;
     33 
     34     // These three methods are invoked at flush time
     35     bool instantiate(GrResourceProvider* resourceProvider);
     36     virtual void prepareOps(GrOpFlushState* flushState) = 0;
     37     virtual bool executeOps(GrOpFlushState* flushState) = 0;
     38 
     39     virtual bool copySurface(const GrCaps& caps,
     40                              GrSurfaceProxy* dst,
     41                              GrSurfaceProxy* src,
     42                              const SkIRect& srcRect,
     43                              const SkIPoint& dstPoint) = 0;
     44 
     45     virtual void makeClosed(const GrCaps&) {
     46         if (!this->isClosed()) {
     47             this->setFlag(kClosed_Flag);
     48             fTarget.removeRef();
     49         }
     50     }
     51 
     52     virtual void reset();
     53 
     54     // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
     55     // these could go away
     56     virtual void abandonGpuResources() = 0;
     57     virtual void freeGpuResources() = 0;
     58 
     59     bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
     60 
     61     /*
     62      * Notify this GrOpList that it relies on the contents of 'dependedOn'
     63      */
     64     void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
     65 
     66     /*
     67      * Does this opList depend on 'dependedOn'?
     68      */
     69     bool dependsOn(GrOpList* dependedOn) const {
     70         return fDependencies.find(dependedOn) >= 0;
     71     }
     72 
     73     /*
     74      * Safely cast this GrOpList to a GrTextureOpList (if possible).
     75      */
     76     virtual GrTextureOpList* asTextureOpList() { return nullptr; }
     77 
     78     /*
     79      * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
     80      */
     81     virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
     82 
     83     int32_t uniqueID() const { return fUniqueID; }
     84 
     85     /*
     86      * Dump out the GrOpList dependency DAG
     87      */
     88     SkDEBUGCODE(virtual void dump() const;)
     89 
     90     SkDEBUGCODE(virtual int numOps() const = 0;)
     91     SkDEBUGCODE(virtual int numClips() const { return 0; })
     92 
     93 protected:
     94     GrSurfaceProxyRef fTarget;
     95     GrAuditTrail*     fAuditTrail;
     96 
     97 private:
     98     friend class GrDrawingManager; // for resetFlag & TopoSortTraits
     99 
    100     static uint32_t CreateUniqueID();
    101 
    102     enum Flags {
    103         kClosed_Flag    = 0x01,   //!< This GrOpList can't accept any more ops
    104 
    105         kWasOutput_Flag = 0x02,   //!< Flag for topological sorting
    106         kTempMark_Flag  = 0x04,   //!< Flag for topological sorting
    107     };
    108 
    109     void setFlag(uint32_t flag) {
    110         fFlags |= flag;
    111     }
    112 
    113     void resetFlag(uint32_t flag) {
    114         fFlags &= ~flag;
    115     }
    116 
    117     bool isSetFlag(uint32_t flag) const {
    118         return SkToBool(fFlags & flag);
    119     }
    120 
    121     struct TopoSortTraits {
    122         static void Output(GrOpList* dt, int /* index */) {
    123             dt->setFlag(GrOpList::kWasOutput_Flag);
    124         }
    125         static bool WasOutput(const GrOpList* dt) {
    126             return dt->isSetFlag(GrOpList::kWasOutput_Flag);
    127         }
    128         static void SetTempMark(GrOpList* dt) {
    129             dt->setFlag(GrOpList::kTempMark_Flag);
    130         }
    131         static void ResetTempMark(GrOpList* dt) {
    132             dt->resetFlag(GrOpList::kTempMark_Flag);
    133         }
    134         static bool IsTempMarked(const GrOpList* dt) {
    135             return dt->isSetFlag(GrOpList::kTempMark_Flag);
    136         }
    137         static int NumDependencies(const GrOpList* dt) {
    138             return dt->fDependencies.count();
    139         }
    140         static GrOpList* Dependency(GrOpList* dt, int index) {
    141             return dt->fDependencies[index];
    142         }
    143     };
    144 
    145     void addDependency(GrOpList* dependedOn);
    146 
    147     uint32_t              fUniqueID;
    148     uint32_t              fFlags;
    149 
    150     // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
    151     SkTDArray<GrOpList*>  fDependencies;
    152 
    153     typedef SkRefCnt INHERITED;
    154 };
    155 
    156 #endif
    157