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 GrGpuResourceRef_DEFINED | 8 #ifndef GrGpuResourceRef_DEFINED |
9 #define GrGpuResourceRef_DEFINED | 9 #define GrGpuResourceRef_DEFINED |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO | 46 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO |
47 is called. */ | 47 is called. */ |
48 void reset(); | 48 void reset(); |
49 | 49 |
50 protected: | 50 protected: |
51 GrGpuResourceRef(); | 51 GrGpuResourceRef(); |
52 | 52 |
53 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 53 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
54 pending on the resource when markPendingIO is called. */ | 54 pending on the resource when markPendingIO is called. */ |
55 GrGpuResourceRef(GrGpuResource*, GrIORef::IOType); | 55 GrGpuResourceRef(GrGpuResource*, GrIOType); |
56 | 56 |
57 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 57 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
58 pending on the resource when markPendingIO is called. */ | 58 pending on the resource when markPendingIO is called. */ |
59 void setResource(GrGpuResource*, GrIORef::IOType); | 59 void setResource(GrGpuResource*, GrIOType); |
60 | 60 |
61 private: | 61 private: |
62 /** Called by owning GrProgramElement when the program element is first sche
duled for | 62 /** Called by owning GrProgramElement when the program element is first sche
duled for |
63 execution. It can only be called once. */ | 63 execution. It can only be called once. */ |
64 void markPendingIO() const; | 64 void markPendingIO() const; |
65 | 65 |
66 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. | 66 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. |
67 This lets the cache know that the drawing code will no longer schedule a
dditional reads or | 67 This lets the cache know that the drawing code will no longer schedule a
dditional reads or |
68 writes to the resource using the program element or draw state. It can o
nly be called once. | 68 writes to the resource using the program element or draw state. It can o
nly be called once. |
69 */ | 69 */ |
70 void removeRef() const; | 70 void removeRef() const; |
71 | 71 |
72 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object | 72 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object |
73 still has refs, so it is not about to destroy this GrGpuResourceRef, but
its previously | 73 still has refs, so it is not about to destroy this GrGpuResourceRef, but
its previously |
74 pending executions have been complete. Can only be called if removeRef()
was not previously | 74 pending executions have been complete. Can only be called if removeRef()
was not previously |
75 called. */ | 75 called. */ |
76 void pendingIOComplete() const; | 76 void pendingIOComplete() const; |
77 | 77 |
78 friend class GrDrawState; | 78 friend class GrDrawState; |
79 friend class GrOptDrawState; | 79 friend class GrOptDrawState; |
80 friend class GrProgramElement; | 80 friend class GrProgramElement; |
81 | 81 |
82 GrGpuResource* fResource; | 82 GrGpuResource* fResource; |
83 mutable bool fOwnRef; | 83 mutable bool fOwnRef; |
84 mutable bool fPendingIO; | 84 mutable bool fPendingIO; |
85 GrIORef::IOType fIOType; | 85 GrIOType fIOType; |
86 | 86 |
87 typedef SkNoncopyable INHERITED; | 87 typedef SkNoncopyable INHERITED; |
88 }; | 88 }; |
89 | 89 |
90 /** | 90 /** |
91 * Templated version of GrGpuResourceRef to enforce type safety. | 91 * Templated version of GrGpuResourceRef to enforce type safety. |
92 */ | 92 */ |
93 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { | 93 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { |
94 public: | 94 public: |
95 GrTGpuResourceRef() {} | 95 GrTGpuResourceRef() {} |
96 | 96 |
97 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 97 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
98 pending on the resource when markPendingIO is called. */ | 98 pending on the resource when markPendingIO is called. */ |
99 GrTGpuResourceRef(T* resource, GrIORef::IOType ioType) : INHERITED(resource,
ioType) {} | 99 GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType
) {} |
100 | 100 |
101 T* get() const { return static_cast<T*>(this->getResource()); } | 101 T* get() const { return static_cast<T*>(this->getResource()); } |
102 | 102 |
103 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 103 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
104 pending on the resource when markPendingIO is called. */ | 104 pending on the resource when markPendingIO is called. */ |
105 void set(T* resource, GrIORef::IOType ioType) { this->setResource(resource,
ioType); } | 105 void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType)
; } |
106 | 106 |
107 private: | 107 private: |
108 typedef GrGpuResourceRef INHERITED; | 108 typedef GrGpuResourceRef INHERITED; |
109 }; | 109 }; |
110 | 110 |
111 /** | 111 /** |
112 * This is similar to GrTGpuResourceRef but can only be in the pending IO state.
It never owns a | 112 * This is similar to GrTGpuResourceRef but can only be in the pending IO state.
It never owns a |
113 * ref. | 113 * ref. |
114 */ | 114 */ |
115 template <typename T, GrIORef::IOType IO_TYPE> class GrPendingIOResource : SkNon
copyable { | 115 template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyabl
e { |
116 public: | 116 public: |
117 GrPendingIOResource(T* resource) : fResource(resource) { | 117 GrPendingIOResource(T* resource) : fResource(resource) { |
118 if (NULL != fResource) { | 118 if (NULL != fResource) { |
119 switch (IO_TYPE) { | 119 switch (IO_TYPE) { |
120 case GrIORef::kRead_IOType: | 120 case kRead_GrIOType: |
121 fResource->addPendingRead(); | 121 fResource->addPendingRead(); |
122 break; | 122 break; |
123 case GrIORef::kWrite_IOType: | 123 case kWrite_GrIOType: |
124 fResource->addPendingWrite(); | 124 fResource->addPendingWrite(); |
125 break; | 125 break; |
126 case GrIORef::kRW_IOType: | 126 case kRW_GrIOType: |
127 fResource->addPendingRead(); | 127 fResource->addPendingRead(); |
128 fResource->addPendingWrite(); | 128 fResource->addPendingWrite(); |
129 break; | 129 break; |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 ~GrPendingIOResource() { | 134 ~GrPendingIOResource() { |
135 if (NULL != fResource) { | 135 if (NULL != fResource) { |
136 switch (IO_TYPE) { | 136 switch (IO_TYPE) { |
137 case GrIORef::kRead_IOType: | 137 case kRead_GrIOType: |
138 fResource->completedRead(); | 138 fResource->completedRead(); |
139 break; | 139 break; |
140 case GrIORef::kWrite_IOType: | 140 case kWrite_GrIOType: |
141 fResource->completedWrite(); | 141 fResource->completedWrite(); |
142 break; | 142 break; |
143 case GrIORef::kRW_IOType: | 143 case kRW_GrIOType: |
144 fResource->completedRead(); | 144 fResource->completedRead(); |
145 fResource->completedWrite(); | 145 fResource->completedWrite(); |
146 break; | 146 break; |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 T* get() const { return fResource; } | 151 T* get() const { return fResource; } |
152 | 152 |
153 private: | 153 private: |
154 T* fResource; | 154 T* fResource; |
155 }; | 155 }; |
156 #endif | 156 #endif |
OLD | NEW |