OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrProgramElement_DEFINED | 8 #ifndef GrProgramElement_DEFINED |
9 #define GrProgramElement_DEFINED | 9 #define GrProgramElement_DEFINED |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 void unref() const { | 44 void unref() const { |
45 this->validate(); | 45 this->validate(); |
46 --fRefCnt; | 46 --fRefCnt; |
47 if (0 == fRefCnt && 0 == fPendingExecutions) { | 47 if (0 == fRefCnt && 0 == fPendingExecutions) { |
48 SkDELETE(this); | 48 SkDELETE(this); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
| 52 /** |
| 53 * Gets an id that is unique for this GrProgramElement object. This will nev
er return 0. |
| 54 */ |
| 55 uint32_t getUniqueID() const { return fUniqueID; } |
| 56 |
52 void validate() const { | 57 void validate() const { |
53 #ifdef SK_DEBUG | 58 #ifdef SK_DEBUG |
54 SkASSERT(fRefCnt >= 0); | 59 SkASSERT(fRefCnt >= 0); |
55 SkASSERT(fPendingExecutions >= 0); | 60 SkASSERT(fPendingExecutions >= 0); |
56 SkASSERT(fRefCnt + fPendingExecutions > 0); | 61 SkASSERT(fRefCnt + fPendingExecutions > 0); |
57 #endif | 62 #endif |
58 } | 63 } |
59 | 64 |
60 protected: | 65 protected: |
61 GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {} | 66 GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniq
ueID()) {} |
62 | 67 |
63 /** Subclasses registers their resources using this function. It is assumed
the GrProgramResouce | 68 /** 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 | 69 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. | 70 GrProgramResource is registered its setResource must not be called. |
66 */ | 71 */ |
67 void addProgramResource(const GrProgramResource* res) { | 72 void addProgramResource(const GrProgramResource* res) { |
68 fProgramResources.push_back(res); | 73 fProgramResources.push_back(res); |
69 } | 74 } |
70 | 75 |
71 private: | 76 private: |
| 77 static uint32_t CreateUniqueID(); |
| 78 |
72 void convertRefToPendingExecution() const; | 79 void convertRefToPendingExecution() const; |
73 | 80 |
74 void completedExecution() const; | 81 void completedExecution() const; |
75 | 82 |
76 mutable int32_t fRefCnt; | 83 mutable int32_t fRefCnt; |
77 // Count of deferred executions not yet issued to the 3D API. | 84 // Count of deferred executions not yet issued to the 3D API. |
78 mutable int32_t fPendingExecutions; | 85 mutable int32_t fPendingExecutions; |
| 86 uint32_t fUniqueID; |
79 | 87 |
80 SkSTArray<4, const GrProgramResource*, true> fProgramResources; | 88 SkSTArray<4, const GrProgramResource*, true> fProgramResources; |
81 | 89 |
82 // Only this class can access convertRefToPendingExecution() and completedEx
ecution(). | 90 // Only this class can access convertRefToPendingExecution() and completedEx
ecution(). |
83 template <typename T> friend class GrProgramElementRef; | 91 template <typename T> friend class GrProgramElementRef; |
84 | 92 |
85 typedef SkNoncopyable INHERITED; | 93 typedef SkNoncopyable INHERITED; |
86 }; | 94 }; |
87 | 95 |
88 #endif | 96 #endif |
OLD | NEW |