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

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: minor 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
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
robertphillips 2014/09/18 19:30:51 reosource - typo.
bsalomon 2014/09/18 19:43:54 Done.
17 * converting refs to pending io operations. Like SkAutoTUnref, its constructor and setter adopt 19 * converting refs to pending IO operations. It allows a reosource ownership to be 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. */
robertphillips 2014/09/18 19:30:51 Was reverting the INHERITED stuff intentional ?
bsalomon 2014/09/18 19:43:55 oops.. no
87 GrTGpuResourceRef(T* resource, IOType ioType) : INHERITED(resource, ioType) {} 107 GrTGpuResourceRef(T* resource, IOType ioType) : GrGpuResourceRef(resource, i oType) {}
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); }
114 };
115
116 /**
117 * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a
118 * ref.
119 */
120 template <typename T> class GrPendingIOResource : SkNoncopyable {
121 public:
122 typedef GrGpuResourceRef::IOType IOType;
123 GrPendingIOResource(T* resource, IOType ioType) : fResource(resource), fIOTy pe(ioType) {
124 if (NULL != fResource) {
125 switch (fIOType) {
126 case GrGpuResourceRef::kNone_IOType:
127 SkFAIL("GrPendingIOResource with neither reads nor writes?") ;
128 break;
129 case GrGpuResourceRef::kRead_IOType:
130 fResource->addPendingRead();
131 break;
132 case GrGpuResourceRef::kWrite_IOType:
133 fResource->addPendingWrite();
134 break;
135 case GrGpuResourceRef::kRW_IOType:
136 fResource->addPendingRead();
137 fResource->addPendingWrite();
138 break;
139 }
140 }
141 }
142
143 ~GrPendingIOResource() {
144 if (NULL != fResource) {
145 switch (fIOType) {
146 case GrGpuResourceRef::kNone_IOType:
147 SkFAIL("GrPendingIOResource with neither reads nor writes?") ;
148 break;
149 case GrGpuResourceRef::kRead_IOType:
150 fResource->completedRead();
151 break;
152 case GrGpuResourceRef::kWrite_IOType:
153 fResource->completedWrite();
154 break;
155 case GrGpuResourceRef::kRW_IOType:
156 fResource->completedRead();
157 fResource->completedWrite();
158 break;
159 }
160 }
161 }
162
robertphillips 2014/09/18 19:30:51 Should this really be const ?
bsalomon 2014/09/18 19:43:54 I think so. It is on other similar classes. const
163 T* get() const { return fResource; }
94 164
95 private: 165 private:
96 typedef GrGpuResourceRef INHERITED; 166 IOType fIOType;
167 T* fResource;
97 }; 168 };
98
99
100 #endif 169 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698