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 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 #include "SkTArray.h" | 12 #include "SkTArray.h" |
13 | 13 |
14 class GrProgramResource; | 14 class GrGpuResourceRef; |
15 | 15 |
16 /** | 16 /** |
17 * Base class for GrEffect (and future GrGeometryProcessor). GrDrawState uses th
is to manage | 17 * Base class for GrEffect (and future GrGeometryProcessor). GrDrawState uses th
is to manage |
18 * transitioning a GrEffect from being owned by a client to being scheduled for
execution. It | 18 * transitioning a GrEffect from being owned by a client to being scheduled for
execution. It |
19 * converts resources owned by the effect from being ref'ed to having pending re
ads/writes. | 19 * converts resources owned by the effect from being ref'ed to having pending re
ads/writes. |
20 * | 20 * |
21 * All GrGpuResource objects owned by a GrProgramElement or derived classes (eit
her directly or | 21 * All GrGpuResource objects owned by a GrProgramElement or derived classes (eit
her directly or |
22 * indirectly) must be wrapped in a GrProgramResource and registered with the Gr
ProgramElement using | 22 * indirectly) must be wrapped in a GrGpuResourceRef and registered with the GrP
rogramElement using |
23 * addGrProgramResource(). This allows the regular refs to be converted to pendi
ng IO events | 23 * addGpuResource(). This allows the regular refs to be converted to pending IO
events |
24 * when the program element is scheduled for deferred execution. | 24 * when the program element is scheduled for deferred execution. |
25 */ | 25 */ |
26 class GrProgramElement : public SkNoncopyable { | 26 class GrProgramElement : public SkNoncopyable { |
27 public: | 27 public: |
28 SK_DECLARE_INST_COUNT_ROOT(GrProgramElement) | 28 SK_DECLARE_INST_COUNT_ROOT(GrProgramElement) |
29 | 29 |
30 virtual ~GrProgramElement() { | 30 virtual ~GrProgramElement() { |
31 // fRefCnt can be one when an effect is created statically using GR_CREA
TE_STATIC_EFFECT | 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); | 32 SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions); |
33 // Set to invalid values. | 33 // Set to invalid values. |
(...skipping 26 matching lines...) Expand all Loading... |
60 SkASSERT(fPendingExecutions >= 0); | 60 SkASSERT(fPendingExecutions >= 0); |
61 SkASSERT(fRefCnt + fPendingExecutions > 0); | 61 SkASSERT(fRefCnt + fPendingExecutions > 0); |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 protected: | 65 protected: |
66 GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniq
ueID()) {} | 66 GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniq
ueID()) {} |
67 | 67 |
68 /** 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 |
69 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 |
70 GrProgramResource is registered its setResource must not be called. | 70 GrGpuResourceRef is registered its setResource must not be called. |
71 */ | 71 */ |
72 void addProgramResource(const GrProgramResource* res) { | 72 void addGpuResource(const GrGpuResourceRef* res) { |
73 fProgramResources.push_back(res); | 73 fGpuResources.push_back(res); |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 static uint32_t CreateUniqueID(); | 77 static uint32_t CreateUniqueID(); |
78 | 78 |
79 void convertRefToPendingExecution() const; | 79 void convertRefToPendingExecution() const; |
80 | 80 |
81 void completedExecution() const; | 81 void completedExecution() const; |
82 | 82 |
83 mutable int32_t fRefCnt; | 83 mutable int32_t fRefCnt; |
84 // Count of deferred executions not yet issued to the 3D API. | 84 // Count of deferred executions not yet issued to the 3D API. |
85 mutable int32_t fPendingExecutions; | 85 mutable int32_t fPendingExecutions; |
86 uint32_t fUniqueID; | 86 uint32_t fUniqueID; |
87 | 87 |
88 SkSTArray<4, const GrProgramResource*, true> fProgramResources; | 88 SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources; |
89 | 89 |
90 // Only this class can access convertRefToPendingExecution() and completedEx
ecution(). | 90 // Only this class can access convertRefToPendingExecution() and completedEx
ecution(). |
91 template <typename T> friend class GrProgramElementRef; | 91 template <typename T> friend class GrProgramElementRef; |
92 | 92 |
93 typedef SkNoncopyable INHERITED; | 93 typedef SkNoncopyable INHERITED; |
94 }; | 94 }; |
95 | 95 |
96 #endif | 96 #endif |
OLD | NEW |