Chromium Code Reviews| Index: include/gpu/GrProgramElement.h |
| diff --git a/include/gpu/GrProgramElement.h b/include/gpu/GrProgramElement.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2778ca69e9361333853e6e87f087f8a573b05910 |
| --- /dev/null |
| +++ b/include/gpu/GrProgramElement.h |
| @@ -0,0 +1,93 @@ |
| +/* |
| + * 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 GrProgramElement_DEFINED |
| +#define GrProgramElement_DEFINED |
| + |
| +#include "SkRefCnt.h" |
| +#include "SkTArray.h" |
| + |
| +class GrProgramResource; |
| + |
| +/** |
| + * Base class for GrEffect. GrDrawState uses this to manage transitioning a GrEffect from being |
| + * owned by a client to being scheduled for execution. It converts resources owned by the |
| + * effect from being ref'ed to having pending reads/writes. |
| + * |
|
robertphillips
2014/09/04 17:39:12
All GrGpuResource objects owned by a GrProgramReso
bsalomon
2014/09/04 18:09:42
changed to ".. owned by a GrProgramElement"
|
| + * All GrGpuResource objects owned by a GrProgramResource or derived classes (either directly or |
|
robertphillips
2014/09/04 17:39:12
owned via GrProgramResource ?
bsalomon
2014/09/04 18:09:42
changed to "... wrapped in a GrProgramResource"
|
| + * indirectly) must be owned via GrProgramResource and registered with the GrProgramElement using |
| + * addGrProgramResource(). This allows the regular refs to be converted to pending IO events |
| + * when the program element is scheduled for deferred execution. |
| + */ |
| +class GrProgramElement : public SkNoncopyable { |
| +public: |
| + SK_DECLARE_INST_COUNT_ROOT(GrProgramElement) |
| + |
| + virtual ~GrProgramElement() { |
| + // fRefCnt can be one when an effect is created statically using GR_CREATE_STATIC_EFFECT |
| + SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions); |
| + // Set to invalid values. |
| + SkDEBUGCODE(fRefCnt = fPendingExecutions = -10;) |
| + } |
| + |
| + void ref() const { |
| + // Once the ref cnt reaches zero it should never be ref'ed again. |
| + SkASSERT(fRefCnt > 0); |
| + this->validate(); |
| + ++fRefCnt; |
| + } |
| + |
| + void unref() const { |
| + this->validate(); |
| + --fRefCnt; |
|
robertphillips
2014/09/04 17:39:12
Extra space here ?
bsalomon
2014/09/04 18:09:42
Done.
|
| + if (0 == fRefCnt && 0 == fPendingExecutions) { |
| + SkDELETE(this); |
| + } |
| + } |
| + |
| + void validate() const { |
| +#ifdef SK_DEBUG |
| + SkASSERT(fRefCnt >= 0); |
| + SkASSERT(fPendingExecutions >= 0); |
| + SkASSERT(fRefCnt + fPendingExecutions > 0); |
| +#endif |
| + } |
| + |
| +protected: |
| + GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {} |
| + |
| + /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce |
| + is and will remain owned by the subclass and this function will retain a raw ptr. Once a |
| + GrProgramResource is registered its setResource must not be called. |
| + */ |
| + void addGrProgramResource(const GrProgramResource* rr) { |
| + fGrProgramResources.push_back(rr); |
| + } |
| + |
| +private: |
|
robertphillips
2014/09/04 17:39:12
convertRefToPendeingExecution - extra 'e' ?
bsalomon
2014/09/04 18:09:42
Done.
|
| + void convertRefToPendeingExecution() const; |
| + |
| + void completedExecution() const { |
| + this->validate(); |
| + --fPendingExecutions; |
| + if (0 == fRefCnt && 0 == fPendingExecutions) { |
| + SkDELETE(this); |
| + } |
| + } |
| + |
| + mutable int32_t fRefCnt; |
|
robertphillips
2014/09/04 17:39:12
// comment ?
bsalomon
2014/09/04 18:09:42
Done.
|
| + mutable int32_t fPendingExecutions; |
| + |
| + SkSTArray<4, const GrProgramResource*, true> fGrProgramResources; |
| + |
| + // Only this class can access convertRefToPendingExecution() and completedExecution(). |
| + template <typename T> friend class GrProgramElementRef; |
| + |
| + typedef SkNoncopyable INHERITED; |
| +}; |
| + |
| +#endif |