OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef GrProgramElement_DEFINED | |
9 #define GrProgramElement_DEFINED | |
10 | |
11 #include "SkRefCnt.h" | |
12 #include "SkTArray.h" | |
13 | |
14 class GrProgramResource; | |
15 | |
16 /** | |
17 * Base class for GrEffect. GrDrawState uses this to manage transitioning a GrEf fect from being | |
18 * owned by a client to being scheduled for execution. It converts resources own ed by the | |
19 * effect from being ref'ed to having pending reads/writes. | |
20 * | |
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"
| |
21 * All GrGpuResource objects owned by a GrProgramResource or derived classes (ei ther 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"
| |
22 * indirectly) must be owned via GrProgramResource and registered with the GrPro gramElement using | |
23 * addGrProgramResource(). This allows the regular refs to be converted to pendi ng IO events | |
24 * when the program element is scheduled for deferred execution. | |
25 */ | |
26 class GrProgramElement : public SkNoncopyable { | |
27 public: | |
28 SK_DECLARE_INST_COUNT_ROOT(GrProgramElement) | |
29 | |
30 virtual ~GrProgramElement() { | |
31 // fRefCnt can be one when an effect is created statically using GR_CREA TE_STATIC_EFFECT | |
32 SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions); | |
33 // Set to invalid values. | |
34 SkDEBUGCODE(fRefCnt = fPendingExecutions = -10;) | |
35 } | |
36 | |
37 void ref() const { | |
38 // Once the ref cnt reaches zero it should never be ref'ed again. | |
39 SkASSERT(fRefCnt > 0); | |
40 this->validate(); | |
41 ++fRefCnt; | |
42 } | |
43 | |
44 void unref() const { | |
45 this->validate(); | |
46 --fRefCnt; | |
robertphillips
2014/09/04 17:39:12
Extra space here ?
bsalomon
2014/09/04 18:09:42
Done.
| |
47 if (0 == fRefCnt && 0 == fPendingExecutions) { | |
48 SkDELETE(this); | |
49 } | |
50 } | |
51 | |
52 void validate() const { | |
53 #ifdef SK_DEBUG | |
54 SkASSERT(fRefCnt >= 0); | |
55 SkASSERT(fPendingExecutions >= 0); | |
56 SkASSERT(fRefCnt + fPendingExecutions > 0); | |
57 #endif | |
58 } | |
59 | |
60 protected: | |
61 GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {} | |
62 | |
63 /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce | |
64 is and will remain owned by the subclass and this function will retain a raw ptr. Once a | |
65 GrProgramResource is registered its setResource must not be called. | |
66 */ | |
67 void addGrProgramResource(const GrProgramResource* rr) { | |
68 fGrProgramResources.push_back(rr); | |
69 } | |
70 | |
71 private: | |
robertphillips
2014/09/04 17:39:12
convertRefToPendeingExecution - extra 'e' ?
bsalomon
2014/09/04 18:09:42
Done.
| |
72 void convertRefToPendeingExecution() const; | |
73 | |
74 void completedExecution() const { | |
75 this->validate(); | |
76 --fPendingExecutions; | |
77 if (0 == fRefCnt && 0 == fPendingExecutions) { | |
78 SkDELETE(this); | |
79 } | |
80 } | |
81 | |
82 mutable int32_t fRefCnt; | |
robertphillips
2014/09/04 17:39:12
// comment ?
bsalomon
2014/09/04 18:09:42
Done.
| |
83 mutable int32_t fPendingExecutions; | |
84 | |
85 SkSTArray<4, const GrProgramResource*, true> fGrProgramResources; | |
86 | |
87 // Only this class can access convertRefToPendingExecution() and completedEx ecution(). | |
88 template <typename T> friend class GrProgramElementRef; | |
89 | |
90 typedef SkNoncopyable INHERITED; | |
91 }; | |
92 | |
93 #endif | |
OLD | NEW |