aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'include/gpu')
-rw-r--r--include/gpu/GrFragmentStage.h (renamed from include/gpu/GrProcessorStage.h)52
-rw-r--r--include/gpu/GrPaint.h2
-rw-r--r--include/gpu/GrProgramElement.h35
-rw-r--r--include/gpu/GrProgramElementRef.h93
-rw-r--r--include/gpu/SkGr.h2
5 files changed, 44 insertions, 140 deletions
diff --git a/include/gpu/GrProcessorStage.h b/include/gpu/GrFragmentStage.h
index 0f24a30a32..8089e9fab7 100644
--- a/include/gpu/GrProcessorStage.h
+++ b/include/gpu/GrFragmentStage.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2010 Google Inc.
*
@@ -6,23 +5,17 @@
* found in the LICENSE file.
*/
+#ifndef GrFragmentStage_DEFINED
+#define GrFragmentStage_DEFINED
-
-#ifndef GrProcessorStage_DEFINED
-#define GrProcessorStage_DEFINED
-
-#include "GrBackendProcessorFactory.h"
-#include "GrCoordTransform.h"
#include "GrFragmentProcessor.h"
-#include "GrProgramElementRef.h"
#include "SkMatrix.h"
-#include "SkShader.h"
-// TODO: Make two variations on this class: One for GrDrawState that only owns regular refs
-// and supports compatibility checks and changing local coords. The second is for GrOptDrawState,
-// is immutable, and only owns pending execution refs. This requries removing the common base
-// class from GrDrawState and GrOptDrawState called GrRODrawState and converting to GrOptDrawState
-// when draws are enqueued in the GrInOrderDrawBuffer.
+/**
+ * Wraps a GrFragmentProcessor. It also contains a coord change matrix. This matrix should be
+ * concat'ed with all the processor's coord transforms that apply to local coords, unless
+ * explicit local coords are provided with the draw.
+ */
class GrFragmentStage {
public:
explicit GrFragmentStage(const GrFragmentProcessor* proc)
@@ -35,9 +28,9 @@ public:
if (other.fCoordChangeMatrixSet) {
fCoordChangeMatrix = other.fCoordChangeMatrix;
}
- fProc.initAndRef(other.fProc);
+ fProc.reset(SkRef(other.fProc.get()));
}
-
+
static bool AreCompatible(const GrFragmentStage& a, const GrFragmentStage& b,
bool usingExplicitLocalCoords) {
SkASSERT(a.fProc.get());
@@ -129,33 +122,12 @@ public:
}
}
- bool isPerspectiveCoordTransform(int matrixIndex, bool useExplicitLocalCoords) const {
- const GrCoordTransform& coordTransform = this->getProcessor()->coordTransform(matrixIndex);
- SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType();
- SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask;
- if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
- type1 = useExplicitLocalCoords ?
- SkMatrix::kIdentity_Mask : this->getCoordChangeMatrix().getType();
- }
-
- int combinedTypes = type0 | type1;
- if (SkMatrix::kPerspective_Mask & combinedTypes) {
- return true;
- } else {
- return false;
- }
- }
-
- const char* name() const { return fProc->name(); }
-
const GrFragmentProcessor* getProcessor() const { return fProc.get(); }
- void convertToPendingExec() { fProc.convertToPendingExec(); }
-
protected:
- bool fCoordChangeMatrixSet;
- SkMatrix fCoordChangeMatrix;
- GrProgramElementRef<const GrFragmentProcessor> fProc;
+ bool fCoordChangeMatrixSet;
+ SkMatrix fCoordChangeMatrix;
+ SkAutoTUnref<const GrFragmentProcessor> fProc;
};
#endif
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index d44dd89e60..6a40a71ffc 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -11,7 +11,7 @@
#define GrPaint_DEFINED
#include "GrColor.h"
-#include "GrProcessorStage.h"
+#include "GrFragmentStage.h"
#include "SkXfermode.h"
diff --git a/include/gpu/GrProgramElement.h b/include/gpu/GrProgramElement.h
index 2cdd1cc563..e1adcc31f7 100644
--- a/include/gpu/GrProgramElement.h
+++ b/include/gpu/GrProgramElement.h
@@ -35,10 +35,11 @@ public:
}
void ref() const {
+ this->validate();
// Once the ref cnt reaches zero it should never be ref'ed again.
SkASSERT(fRefCnt > 0);
- this->validate();
++fRefCnt;
+ this->validate();
}
void unref() const {
@@ -47,10 +48,12 @@ public:
if (0 == fRefCnt) {
if (0 == fPendingExecutions) {
SkDELETE(this);
+ return;
} else {
this->removeRefs();
}
}
+ this->validate();
}
/**
@@ -80,11 +83,33 @@ protected:
private:
static uint32_t CreateUniqueID();
- void convertRefToPendingExecution() const;
+ void addPendingExecution() const {
+ this->validate();
+ SkASSERT(fRefCnt > 0);
+ if (0 == fPendingExecutions) {
+ this->addPendingIOs();
+ }
+ ++fPendingExecutions;
+ this->validate();
+ }
- void completedExecution() const;
+ void completedExecution() const {
+ this->validate();
+ --fPendingExecutions;
+ if (0 == fPendingExecutions) {
+ if (0 == fRefCnt) {
+ SkDELETE(this);
+ return;
+ } else {
+ this->pendingIOComplete();
+ }
+ }
+ this->validate();
+ }
void removeRefs() const;
+ void addPendingIOs() const;
+ void pendingIOComplete() const;
mutable int32_t fRefCnt;
// Count of deferred executions not yet issued to the 3D API.
@@ -93,8 +118,8 @@ private:
SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources;
- // Only this class can access convertRefToPendingExecution() and completedExecution().
- template <typename T> friend class GrProgramElementRef;
+ // Only this class can access addPendingExecution() and completedExecution().
+ template <typename T> friend class GrPendingProgramElement;
typedef SkNoncopyable INHERITED;
};
diff --git a/include/gpu/GrProgramElementRef.h b/include/gpu/GrProgramElementRef.h
deleted file mode 100644
index ecc802317b..0000000000
--- a/include/gpu/GrProgramElementRef.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrProgramElementRef_DEFINED
-#define GrProgramElementRef_DEFINED
-
-#include "SkRefCnt.h"
-#include "GrTypes.h"
-
-/**
- * Helper for owning a GrProgramElement subclass and being able to convert a ref to pending
- * execution. It is like an SkAutoTUnref for program elements whose execution can be deferred. Once
- * in the pending execution state it is illegal to change the object that is owned by the
- * GrProgramElementRef. Its destructor will either unref the GrProgramElement or signal that
- * the pending execution has completed, depending on whether convertToPendingExec() was called.
- */
-template <typename T> class GrProgramElementRef : SkNoncopyable {
-public:
- GrProgramElementRef() : fOwnPendingExec(false), fObj(NULL) {};
-
- // Adopts a ref from the caller.
- explicit GrProgramElementRef(T* obj) : fOwnPendingExec(false), fObj(obj) {}
-
- // Adopts a ref from the caller. Do not call after convertToPendingExec.
- void reset(T* obj) {
- SkASSERT(!fOwnPendingExec);
- SkSafeUnref(fObj);
- fObj = obj;
- }
-
- void convertToPendingExec() {
- SkASSERT(!fOwnPendingExec);
- fObj->convertRefToPendingExecution();
- fOwnPendingExec = true;
- }
-
- // In the short term we need to support copying a GrProcessorStage and making the copy own
- // the same type of ref as the source. This function exists to support this. TODO: Once
- // GrDrawState and GrOptDrawState no longer share a base class they won't have to share
- // GrProcessorStage and we can have GrOptDrawState always own pending executions rather than
- // refs on GrProgramElements. At that point we should be able to delete this function.
- // This function makes assumptions that are valid in the GrProcessorStage use case and should
- // not be used elsewhere.
- void initAndRef(const GrProgramElementRef& that) {
- SkASSERT(!fObj);
- SkASSERT(that.fObj);
- if (that.fOwnPendingExec) {
- SkASSERT(that.fObj->fPendingExecutions > 0);
- that.fObj->fPendingExecutions++;
- } else {
- that.fObj->ref();
- }
- this->fOwnPendingExec = that.fOwnPendingExec;
- this->fObj = that.fObj;
- }
-
- T* get() const { return fObj; }
- operator T*() { return fObj; }
-
- /** If T is const, the type returned from operator-> will also be const. */
- typedef typename SkTConstType<typename SkAutoTUnref<T>::template BlockRef<T>,
- SkTIsConst<T>::value>::type BlockRefType;
-
- /**
- * GrProgramElementRef assumes ownership of the ref and manages converting the ref to a
- * pending execution. As a result, it is an error for the user to ref or unref through
- * GrProgramElementRef. Therefore operator-> returns BlockRef<T>*.
- */
- BlockRefType *operator->() const {
- return static_cast<BlockRefType*>(fObj);
- }
-
- ~GrProgramElementRef() {
- if (fObj) {
- if (fOwnPendingExec) {
- fObj->completedExecution();
- } else {
- fObj->unref();
- }
- }
- }
-
-private:
- bool fOwnPendingExec;
- T* fObj;
-
- typedef SkNoncopyable INHERITED;
-};
-#endif
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 8025c956ef..0f6780002c 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -89,7 +89,7 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
bool constantColor, GrPaint* grPaint);
// This function is similar to skPaint2GrPaintNoShader but also converts
-// skPaint's shader to a GrTexture/GrProcessorStage if possible.
+// skPaint's shader to a GrFragmentProcessor if possible.
// constantColor has the same meaning as in skPaint2GrPaintNoShader.
void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
bool constantColor, GrPaint* grPaint);