* Copyright 2019 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrRenderTask_DEFINED
#define GrRenderTask_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTDArray.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/GrTextureResolveManager.h"
class GrOpFlushState;
class GrOpList;
class GrRenderTargetOpList;
class GrResourceAllocator;
class GrTextureOpList;
class GrRenderTask : public SkRefCnt {
public:
GrRenderTask(sk_sp<GrSurfaceProxy> target);
~GrRenderTask() override;
void prepare(GrOpFlushState* flushState);
bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
virtual void makeClosed(const GrCaps&) {
if (!this->isClosed()) {
this->setFlag(kClosed_Flag);
}
}
virtual void endFlush() {}
bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
* Notify this GrRenderTask that it relies on the contents of 'dependedOn'
*/
void addDependency(GrSurfaceProxy* dependedOn, GrMipMapped, GrTextureResolveManager,
const GrCaps& caps);
* Does this renderTask depend on 'dependedOn'?
*/
bool dependsOn(const GrRenderTask* dependedOn) const;
uint32_t uniqueID() const { return fUniqueID; }
* Safely cast this GrRenderTask to a GrTextureOpList (if possible).
*/
virtual GrTextureOpList* asTextureOpList() { return nullptr; }
* Safely cast this GrRenderTask to a GrRenderTargetOpList (if possible).
*/
virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
* Dump out the GrRenderTask dependency DAG
*/
SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
SkDEBUGCODE(virtual int numClips() const { return 0; })
protected:
bool isInstantiated() const;
SkDEBUGCODE(bool deferredProxiesAreInstantiated() const;)
sk_sp<GrSurfaceProxy> fTarget;
SkTArray<GrTextureProxy*, true> fDeferredProxies;
private:
friend class GrDrawingManager;
virtual void handleInternalAllocationFailure() = 0;
virtual bool onIsUsed(GrSurfaceProxy*) const = 0;
bool isUsed(GrSurfaceProxy* proxy) const {
if (proxy == fTarget.get()) {
return true;
}
return this->onIsUsed(proxy);
}
void addDependency(GrRenderTask* dependedOn);
void addDependent(GrRenderTask* dependent);
SkDEBUGCODE(bool isDependedent(const GrRenderTask* dependent) const;)
SkDEBUGCODE(void validate() const;)
void closeThoseWhoDependOnMe(const GrCaps&);
virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
static uint32_t CreateUniqueID();
enum Flags {
kClosed_Flag = 0x01,
kWasOutput_Flag = 0x02,
kTempMark_Flag = 0x04,
};
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(GrRenderTask* renderTask, int ) {
renderTask->setFlag(kWasOutput_Flag);
}
static bool WasOutput(const GrRenderTask* renderTask) {
return renderTask->isSetFlag(kWasOutput_Flag);
}
static void SetTempMark(GrRenderTask* renderTask) {
renderTask->setFlag(kTempMark_Flag);
}
static void ResetTempMark(GrRenderTask* renderTask) {
renderTask->resetFlag(kTempMark_Flag);
}
static bool IsTempMarked(const GrRenderTask* renderTask) {
return renderTask->isSetFlag(kTempMark_Flag);
}
static int NumDependencies(const GrRenderTask* renderTask) {
return renderTask->fDependencies.count();
}
static GrRenderTask* Dependency(GrRenderTask* renderTask, int index) {
return renderTask->fDependencies[index];
}
};
virtual void onPrepare(GrOpFlushState* flushState) = 0;
virtual bool onExecute(GrOpFlushState* flushState) = 0;
const uint32_t fUniqueID;
uint32_t fFlags;
SkSTArray<1, GrRenderTask*, true> fDependencies;
SkSTArray<1, GrRenderTask*, true> fDependents;
};
#endif