2016-10-25 18:20:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrOpList_DEFINED
|
|
|
|
#define GrOpList_DEFINED
|
|
|
|
|
2017-08-29 11:24:09 +00:00
|
|
|
#include "GrColor.h"
|
2017-05-11 20:29:14 +00:00
|
|
|
#include "GrGpuResourceRef.h"
|
2016-10-25 18:20:06 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
|
2017-09-14 14:56:45 +00:00
|
|
|
|
|
|
|
// Turn on/off the explicit distribution of GPU resources at flush time
|
|
|
|
//#define MDB_ALLOC_RESOURCES 1
|
|
|
|
|
|
|
|
// Turn on/off the sorting of opLists at flush time
|
|
|
|
//#define ENABLE_MDB_SORT 1
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2016-10-26 16:02:18 +00:00
|
|
|
class GrAuditTrail;
|
2017-04-26 15:53:10 +00:00
|
|
|
class GrCaps;
|
2016-12-07 22:06:19 +00:00
|
|
|
class GrOpFlushState;
|
2017-09-11 17:38:55 +00:00
|
|
|
class GrPrepareCallback;
|
2016-11-23 14:37:01 +00:00
|
|
|
class GrRenderTargetOpList;
|
2017-09-14 16:45:25 +00:00
|
|
|
class GrResourceAllocator;
|
2017-05-17 13:36:38 +00:00
|
|
|
class GrResourceProvider;
|
2016-10-28 17:25:24 +00:00
|
|
|
class GrSurfaceProxy;
|
2017-06-01 16:55:44 +00:00
|
|
|
class GrTextureProxy;
|
2016-11-23 14:37:01 +00:00
|
|
|
class GrTextureOpList;
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2017-06-28 14:33:41 +00:00
|
|
|
struct SkIPoint;
|
|
|
|
struct SkIRect;
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
class GrOpList : public SkRefCnt {
|
|
|
|
public:
|
2017-05-30 17:47:32 +00:00
|
|
|
GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*);
|
2016-10-25 18:20:06 +00:00
|
|
|
~GrOpList() override;
|
|
|
|
|
2017-05-17 13:36:38 +00:00
|
|
|
// These three methods are invoked at flush time
|
|
|
|
bool instantiate(GrResourceProvider* resourceProvider);
|
2017-08-22 19:01:32 +00:00
|
|
|
void prepare(GrOpFlushState* flushState);
|
|
|
|
bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2017-06-28 14:33:41 +00:00
|
|
|
virtual bool copySurface(const GrCaps& caps,
|
|
|
|
GrSurfaceProxy* dst,
|
|
|
|
GrSurfaceProxy* src,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
const SkIPoint& dstPoint) = 0;
|
|
|
|
|
2017-04-26 15:53:10 +00:00
|
|
|
virtual void makeClosed(const GrCaps&) {
|
2017-06-14 19:16:59 +00:00
|
|
|
if (!this->isClosed()) {
|
|
|
|
this->setFlag(kClosed_Flag);
|
|
|
|
fTarget.removeRef();
|
|
|
|
}
|
2016-10-25 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 20:29:14 +00:00
|
|
|
virtual void reset();
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2017-09-11 17:38:55 +00:00
|
|
|
void addPrepareCallback(std::unique_ptr<GrPrepareCallback> callback);
|
2017-08-22 19:01:32 +00:00
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
// TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
|
|
|
|
// these could go away
|
|
|
|
virtual void abandonGpuResources() = 0;
|
|
|
|
virtual void freeGpuResources() = 0;
|
|
|
|
|
|
|
|
bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify this GrOpList that it relies on the contents of 'dependedOn'
|
|
|
|
*/
|
2017-04-26 15:53:10 +00:00
|
|
|
void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
|
2016-10-25 18:20:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Does this opList depend on 'dependedOn'?
|
|
|
|
*/
|
|
|
|
bool dependsOn(GrOpList* dependedOn) const {
|
2017-09-14 22:14:14 +00:00
|
|
|
return fDependencies.find(dependedOn) >= 0;
|
2016-10-25 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:37:01 +00:00
|
|
|
/*
|
|
|
|
* Safely cast this GrOpList to a GrTextureOpList (if possible).
|
|
|
|
*/
|
|
|
|
virtual GrTextureOpList* asTextureOpList() { return nullptr; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Safely case this GrOpList to a GrRenderTargetOpList (if possible).
|
|
|
|
*/
|
|
|
|
virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
|
|
|
|
|
2017-03-08 16:50:55 +00:00
|
|
|
int32_t uniqueID() const { return fUniqueID; }
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
/*
|
|
|
|
* Dump out the GrOpList dependency DAG
|
|
|
|
*/
|
|
|
|
SkDEBUGCODE(virtual void dump() const;)
|
|
|
|
|
2017-05-08 19:35:11 +00:00
|
|
|
SkDEBUGCODE(virtual int numOps() const = 0;)
|
|
|
|
SkDEBUGCODE(virtual int numClips() const { return 0; })
|
|
|
|
|
2017-08-30 11:41:07 +00:00
|
|
|
// TODO: it would be nice for this to be hidden
|
2017-08-29 11:24:09 +00:00
|
|
|
void setStencilLoadOp(GrLoadOp loadOp) { fStencilLoadOp = loadOp; }
|
|
|
|
|
2017-04-13 16:23:54 +00:00
|
|
|
protected:
|
2017-09-13 19:25:47 +00:00
|
|
|
SkDEBUGCODE(bool isInstantiated() const;)
|
|
|
|
|
2017-05-30 17:47:32 +00:00
|
|
|
GrSurfaceProxyRef fTarget;
|
|
|
|
GrAuditTrail* fAuditTrail;
|
2017-04-13 16:23:54 +00:00
|
|
|
|
2017-08-29 11:24:09 +00:00
|
|
|
GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
|
|
|
|
GrColor fLoadClearColor = 0x0;
|
|
|
|
GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
private:
|
2017-09-14 16:45:25 +00:00
|
|
|
friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
|
|
|
|
|
|
|
|
// Feed proxy usage intervals to the GrResourceAllocator class
|
|
|
|
virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2017-03-08 16:50:55 +00:00
|
|
|
static uint32_t CreateUniqueID();
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
enum Flags {
|
2016-12-07 20:05:04 +00:00
|
|
|
kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
|
2016-10-25 18:20:06 +00:00
|
|
|
|
|
|
|
kWasOutput_Flag = 0x02, //!< Flag for topological sorting
|
|
|
|
kTempMark_Flag = 0x04, //!< Flag for topological sorting
|
|
|
|
};
|
|
|
|
|
|
|
|
void setFlag(uint32_t flag) {
|
|
|
|
fFlags |= flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetFlag(uint32_t flag) {
|
|
|
|
fFlags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSetFlag(uint32_t flag) const {
|
|
|
|
return SkToBool(fFlags & flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TopoSortTraits {
|
|
|
|
static void Output(GrOpList* dt, int /* index */) {
|
|
|
|
dt->setFlag(GrOpList::kWasOutput_Flag);
|
|
|
|
}
|
|
|
|
static bool WasOutput(const GrOpList* dt) {
|
|
|
|
return dt->isSetFlag(GrOpList::kWasOutput_Flag);
|
|
|
|
}
|
|
|
|
static void SetTempMark(GrOpList* dt) {
|
|
|
|
dt->setFlag(GrOpList::kTempMark_Flag);
|
|
|
|
}
|
|
|
|
static void ResetTempMark(GrOpList* dt) {
|
|
|
|
dt->resetFlag(GrOpList::kTempMark_Flag);
|
|
|
|
}
|
|
|
|
static bool IsTempMarked(const GrOpList* dt) {
|
|
|
|
return dt->isSetFlag(GrOpList::kTempMark_Flag);
|
|
|
|
}
|
|
|
|
static int NumDependencies(const GrOpList* dt) {
|
|
|
|
return dt->fDependencies.count();
|
|
|
|
}
|
|
|
|
static GrOpList* Dependency(GrOpList* dt, int index) {
|
|
|
|
return dt->fDependencies[index];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-22 19:01:32 +00:00
|
|
|
virtual void onPrepare(GrOpFlushState* flushState) = 0;
|
|
|
|
virtual bool onExecute(GrOpFlushState* flushState) = 0;
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
void addDependency(GrOpList* dependedOn);
|
|
|
|
|
2017-09-14 22:14:14 +00:00
|
|
|
uint32_t fUniqueID;
|
|
|
|
uint32_t fFlags;
|
2016-10-25 18:20:06 +00:00
|
|
|
|
|
|
|
// 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
|
2017-09-14 22:14:14 +00:00
|
|
|
SkTDArray<GrOpList*> fDependencies;
|
2016-10-25 18:20:06 +00:00
|
|
|
|
2017-08-22 19:01:32 +00:00
|
|
|
// These are used rarely, most clients never produce any
|
|
|
|
SkTArray<std::unique_ptr<GrPrepareCallback>> fPrepareCallbacks;
|
|
|
|
|
2016-10-25 18:20:06 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|