Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(975)

Side by Side Diff: include/gpu/GrGpuResourceRef.h

Issue 581123002: Make GrIODB keep pending IO refs on all resources it records into its cmd stream. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix param init order warning Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | src/gpu/GrAllocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "SkRefCnt.h" 11 #include "SkRefCnt.h"
12 12
13 class GrGpuResource; 13 class GrGpuResource;
14 14
15 /** 15 /**
16 * This class is intended only for internal use in core Gr code.
17 *
16 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages 18 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages
17 * converting refs to pending io operations. Like SkAutoTUnref, its constructor and setter adopt 19 * converting refs to pending IO operations. It allows a resource ownership to b e in three
18 * a ref from their caller. This class is intended only for internal use in core Gr code. 20 * states:
21 * 1. Owns a single ref
22 * 2. Owns a single ref and a pending IO operation (read, write, or rea d-write)
23 * 3. Owns a single pending IO operation.
24 *
25 * It is legal to destroy the GrGpuResourceRef in any of these states. It starts in state
26 * 1. Calling markPendingIO() converts it from state 1 to state 2. Calling remov eRef() goes from
27 * state 2 to state 3. Calling pendingIOComplete() moves from state 2 to state 1 . There is no
28 * valid way of going from state 3 back to 2 or 1.
29 *
30 * Like SkAutoTUnref, its constructor and setter adopt a ref from their caller.
31 *
32 * TODO: Once GrDODrawState no longer exists and therefore GrDrawState and GrOpt DrawState no
33 * longer share an instance of this class, attempt to make the resource owned by GrGpuResourceRef
34 * only settable via the constructor.
19 */ 35 */
20 class GrGpuResourceRef : SkNoncopyable { 36 class GrGpuResourceRef : SkNoncopyable {
21 public: 37 public:
22 SK_DECLARE_INST_COUNT_ROOT(GrGpuResourceRef); 38 SK_DECLARE_INST_COUNT_ROOT(GrGpuResourceRef);
23 39
24 enum IOType { 40 enum IOType {
25 kRead_IOType, 41 kRead_IOType,
26 kWrite_IOType, 42 kWrite_IOType,
27 kRW_IOType, 43 kRW_IOType,
28 44
(...skipping 17 matching lines...) Expand all
46 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 62 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
47 pending on the resource when markPendingIO is called. */ 63 pending on the resource when markPendingIO is called. */
48 GrGpuResourceRef(GrGpuResource*, IOType); 64 GrGpuResourceRef(GrGpuResource*, IOType);
49 65
50 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 66 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
51 pending on the resource when markPendingIO is called. */ 67 pending on the resource when markPendingIO is called. */
52 void setResource(GrGpuResource*, IOType); 68 void setResource(GrGpuResource*, IOType);
53 69
54 private: 70 private:
55 /** Called by owning GrProgramElement when the program element is first sche duled for 71 /** Called by owning GrProgramElement when the program element is first sche duled for
56 execution. */ 72 execution. It can only be called once. */
57 void markPendingIO() const; 73 void markPendingIO() const;
58 74
59 /** Called when the program element/draw state is no longer owned by GrDrawT arget-client code. 75 /** Called when the program element/draw state is no longer owned by GrDrawT arget-client code.
60 This lets the cache know that the drawing code will no longer schedule a dditional reads or 76 This lets the cache know that the drawing code will no longer schedule a dditional reads or
61 writes to the resource using the program element or draw state. */ 77 writes to the resource using the program element or draw state. It can o nly be called once.
78 */
62 void removeRef() const; 79 void removeRef() const;
63 80
64 /** Called to indicate that the previous pending IO is complete. Useful when the owning object 81 /** Called to indicate that the previous pending IO is complete. Useful when the owning object
65 still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously 82 still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously
66 pending executions have been complete. 83 pending executions have been complete. Can only be called if removeRef() was not previously
67 */ 84 called. */
68 void pendingIOComplete() const; 85 void pendingIOComplete() const;
69 86
70 friend class GrRODrawState; 87 friend class GrRODrawState;
71 friend class GrProgramElement; 88 friend class GrProgramElement;
72 89
73 GrGpuResource* fResource; 90 GrGpuResource* fResource;
74 mutable bool fOwnRef; 91 mutable bool fOwnRef;
75 mutable bool fPendingIO; 92 mutable bool fPendingIO;
76 IOType fIOType; 93 IOType fIOType;
77 94
78 typedef SkNoncopyable INHERITED; 95 typedef SkNoncopyable INHERITED;
79 }; 96 };
80 97
98 /**
99 * Templated version of GrGpuResourceRef to enforce type safety.
100 */
81 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { 101 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef {
82 public: 102 public:
83 GrTGpuResourceRef() {} 103 GrTGpuResourceRef() {}
84 104
85 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 105 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
86 pending on the resource when markPendingIO is called. */ 106 pending on the resource when markPendingIO is called. */
87 GrTGpuResourceRef(T* resource, IOType ioType) : INHERITED(resource, ioType) {} 107 GrTGpuResourceRef(T* resource, IOType ioType) : INHERITED(resource, ioType) {}
88 108
89 T* get() const { return static_cast<T*>(this->getResource()); } 109 T* get() const { return static_cast<T*>(this->getResource()); }
90 110
91 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 111 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
92 pending on the resource when markPendingIO is called. */ 112 pending on the resource when markPendingIO is called. */
93 void set(T* resource, IOType ioType) { this->setResource(resource, ioType); } 113 void set(T* resource, IOType ioType) { this->setResource(resource, ioType); }
94 114
95 private: 115 private:
96 typedef GrGpuResourceRef INHERITED; 116 typedef GrGpuResourceRef INHERITED;
97 }; 117 };
98 118
119 /**
120 * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a
121 * ref.
122 */
123 template <typename T> class GrPendingIOResource : SkNoncopyable {
124 public:
125 typedef GrGpuResourceRef::IOType IOType;
126 GrPendingIOResource(T* resource, IOType ioType) : fResource(resource), fIOTy pe(ioType) {
127 if (NULL != fResource) {
128 switch (fIOType) {
129 case GrGpuResourceRef::kNone_IOType:
130 SkFAIL("GrPendingIOResource with neither reads nor writes?") ;
131 break;
132 case GrGpuResourceRef::kRead_IOType:
133 fResource->addPendingRead();
134 break;
135 case GrGpuResourceRef::kWrite_IOType:
136 fResource->addPendingWrite();
137 break;
138 case GrGpuResourceRef::kRW_IOType:
139 fResource->addPendingRead();
140 fResource->addPendingWrite();
141 break;
142 }
143 }
144 }
99 145
146 ~GrPendingIOResource() {
147 if (NULL != fResource) {
148 switch (fIOType) {
149 case GrGpuResourceRef::kNone_IOType:
150 SkFAIL("GrPendingIOResource with neither reads nor writes?") ;
151 break;
152 case GrGpuResourceRef::kRead_IOType:
153 fResource->completedRead();
154 break;
155 case GrGpuResourceRef::kWrite_IOType:
156 fResource->completedWrite();
157 break;
158 case GrGpuResourceRef::kRW_IOType:
159 fResource->completedRead();
160 fResource->completedWrite();
161 break;
162 }
163 }
164 }
165
166 T* get() const { return fResource; }
167
168 private:
169 T* fResource;
170 IOType fIOType;
171 };
100 #endif 172 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | src/gpu/GrAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698