aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-04-10 10:54:25 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-10 15:38:47 +0000
commitd61c9d93b126dca0af17eff89be8536944dadf81 (patch)
tree975f3418b8f1f303a2530a2a4b67a97c82c86dcc /include
parentf9aa9e51691d83970039f42c623c1fd354552378 (diff)
Move ref counting out of GrProcessor and into subclasses.
This will allow different subclasses to use different models for lifetime management. GrXferProcessor moves to simple ref counting since they don't own GrGpuResources. This also constifies GrXferProcessor factories. Change-Id: I6bea0ea8de718874063224232f9da50887868b16 Reviewed-on: https://skia-review.googlesource.com/11792 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrFragmentProcessor.h6
-rw-r--r--include/gpu/GrProcessor.h22
-rw-r--r--include/gpu/GrProgramElement.h42
3 files changed, 37 insertions, 33 deletions
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
index acbc63ea77..00f2dbd9d8 100644
--- a/include/gpu/GrFragmentProcessor.h
+++ b/include/gpu/GrFragmentProcessor.h
@@ -23,7 +23,7 @@ class GrSwizzle;
GrCoordTransforms to receive a transformation of the local coordinates that map from local space
to the fragment being processed.
*/
-class GrFragmentProcessor : public GrResourceIOProcessor {
+class GrFragmentProcessor : public GrResourceIOProcessor, public GrProgramElement {
public:
/**
* In many instances (e.g. SkShader::asFragmentProcessor() implementations) it is desirable to
@@ -300,6 +300,10 @@ protected:
void setWillUseDistanceVectorField() { fFlags |= kUsesDistanceVectorField_Flag; }
private:
+ void addPendingIOs() const override { GrResourceIOProcessor::addPendingIOs(); }
+ void removeRefs() const override { GrResourceIOProcessor::removeRefs(); }
+ void pendingIOComplete() const override { GrResourceIOProcessor::pendingIOComplete(); }
+
void notifyRefCntIsZero() const final;
virtual GrColor4f constantOutputForConstantInput(GrColor4f /* inputColor */) const {
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
index 54691812e1..d10136846a 100644
--- a/include/gpu/GrProcessor.h
+++ b/include/gpu/GrProcessor.h
@@ -61,7 +61,7 @@ private:
Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
processor must reach 0 before the thread terminates and the pool is destroyed.
*/
-class GrProcessor : public GrProgramElement<GrProcessor> {
+class GrProcessor {
public:
virtual ~GrProcessor() = default;
@@ -123,6 +123,9 @@ protected:
}
private:
+ GrProcessor(const GrProcessor&) = delete;
+ GrProcessor& operator=(const GrProcessor&) = delete;
+
static uint32_t GenClassID() {
// fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The
// atomic inc returns the old value not the incremented value. So we add
@@ -135,11 +138,6 @@ private:
return id;
}
- friend class GrProgramElement<GrProcessor>;
- virtual void addPendingIOs() const {}
- virtual void removeRefs() const {}
- virtual void pendingIOComplete() const {}
-
enum {
kIllegalProcessorClassID = 0,
};
@@ -147,8 +145,6 @@ private:
uint32_t fClassID;
RequiredFeatures fRequiredFeatures;
-
- typedef GrProgramElement INHERITED;
};
GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures);
@@ -195,12 +191,12 @@ protected:
bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const;
-private:
- friend class GrProgramElement<GrProcessor>;
- void addPendingIOs() const override;
- void removeRefs() const override;
- void pendingIOComplete() const override;
+ // These methods can be used by derived classes that also derive from GrProgramElement.
+ void addPendingIOs() const;
+ void removeRefs() const;
+ void pendingIOComplete() const;
+private:
SkSTArray<4, const TextureSampler*, true> fTextureSamplers;
SkSTArray<1, const BufferAccess*, true> fBufferAccesses;
SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses;
diff --git a/include/gpu/GrProgramElement.h b/include/gpu/GrProgramElement.h
index 2538680302..425f57a59d 100644
--- a/include/gpu/GrProgramElement.h
+++ b/include/gpu/GrProgramElement.h
@@ -17,15 +17,10 @@ class GrGpuResourceRef;
* Note: We are converting GrProcessor from ref counting to a single owner model using move
* semantics. This class will be removed.
*
- * Base class for GrProcessor. This exists to manage transitioning a GrProcessor from being owned by
- * a client to being scheduled for execution. While a GrProcessor is ref'ed by drawing code its
- * GrGpu resources must also be ref'ed to prevent incorrectly recycling them through the cache.
- * However, once the GrProcessor is baked into a GrPipeline and the drawing code has stopped ref'ing
- * it, it's internal resources can be recycled in some cases.
- *
- * We track this using two types of refs on GrProgramElement. A regular ref is owned by any client
- * that may continue to issue draws that use the GrProgramElement. The GrPipeline owns "pending
- * executions" instead of refs. A pending execution is cleared by ~GrPipeline().
+ * This is used to track "refs" for two separate types GrProcessor ownership. A regular ref is owned
+ * by any client that may continue to issue draws that use the GrProgramElement. A recorded op or
+ * GrPipeline uses "pending executions" instead of refs. A pending execution is cleared after the
+ * draw is executed (or aborted).
*
* While a GrProgramElement is ref'ed any resources it owns are also ref'ed. However, once it gets
* into the state where it has pending executions AND no refs then it converts its ownership of
@@ -33,13 +28,18 @@ class GrGpuResourceRef;
* safe to recycle a resource even though we still have buffered GrOps that read or write to the
* the resource.
*
- * To make this work the subclass, GrProcessor, implements addPendingIOs and pendingIOComplete. The
- * former adds pending reads/writes as appropriate when the processor is recorded in a GrOpList. The
- * latter removes them after the op list executes the operation. These calls must propagate to any
- * children processors. Similarly, the subclass implements a removeRefs function in order to remove
- * refs from resources once the processor is only owned for pending execution.
+ * To make this work the subclass GrProcessor implements addPendingIOs, removeRefs, and
+ * pendingIOComplete. addPendingIOs adds pending reads/writes to GrGpuResources owned by the
+ * processor as appropriate when the processor is recorded in a GrOpList. removeRefs is called when
+ * the ref count reaches 0 and the GrProcessor is only owned by "pending executions".
+ * pendingIOComplete occurs if the resource is still owned by a ref but all recorded draws have been
+ * completed. Whenever pending executions and refs reach zero the processor is deleted.
+ *
+ * The GrProcessor may also implement notifyRefCntIsZero in order to change its ownership of child
+ * processors from ref to pending execution when the processor is first owned exclusively in pending
+ * execution mode.
*/
-template<typename DERIVED> class GrProgramElement : public SkNoncopyable {
+class GrProgramElement : public SkNoncopyable {
public:
virtual ~GrProgramElement() {
// fRefCnt can be one when an effect is created statically using GR_CREATE_STATIC_EFFECT
@@ -65,7 +65,7 @@ public:
delete this;
return;
} else {
- static_cast<const DERIVED*>(this)->removeRefs();
+ this->removeRefs();
}
}
this->validate();
@@ -85,7 +85,7 @@ protected:
void addPendingExecution() const {
this->validate();
if (0 == fPendingExecutions) {
- static_cast<const DERIVED*>(this)->addPendingIOs();
+ this->addPendingIOs();
}
++fPendingExecutions;
this->validate();
@@ -99,13 +99,17 @@ protected:
delete this;
return;
} else {
- static_cast<const DERIVED*>(this)->pendingIOComplete();
+ this->pendingIOComplete();
}
}
this->validate();
}
private:
+ virtual void addPendingIOs() const = 0;
+ virtual void removeRefs() const = 0;
+ virtual void pendingIOComplete() const = 0;
+
/** This will be called when the ref cnt is zero. The object may or may not have pending
executions. */
virtual void notifyRefCntIsZero() const = 0;
@@ -114,7 +118,7 @@ private:
// Count of deferred executions not yet issued to the 3D API.
mutable int32_t fPendingExecutions;
- // Only this class can access addPendingExecution() and completedExecution().
+ // Only these classes can access addPendingExecution() and completedExecution().
template <typename T> friend class GrPendingProgramElement;
friend class GrProcessorSet;