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

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

Issue 1315923004: Convert child FPs from refs to pending executions when parent converts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: working Created 5 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/GrFragmentProcessor.h ('k') | include/gpu/GrXferProcessor.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 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 GrGpuResourceRef; 14 class GrGpuResourceRef;
15 15
16 /** 16 /**
17 * Base class for GrProcessor. GrDrawState uses this to manage 17 * Base class for GrProcessor. GrDrawState uses this to manage
18 * transitioning a GrProcessor from being owned by a client to being scheduled f or execution. It 18 * transitioning a GrProcessor from being owned by a client to being scheduled f or 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 GrGpuResourceRef and registered with the GrP rogramElement using 22 * indirectly) must be wrapped in a GrGpuResourceRef and registered with the GrP rogramElement using
23 * addGpuResource(). This allows the regular refs to be converted to pending 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.
robertphillips 2015/08/27 19:39:06 // Expand on this comment ?
25 */ 25 */
26 class GrProgramElement : public SkNoncopyable { 26 class GrProgramElement : public SkNoncopyable {
27 public: 27 public:
28 virtual ~GrProgramElement() { 28 virtual ~GrProgramElement() {
29 // fRefCnt can be one when an effect is created statically using GR_CREA TE_STATIC_EFFECT 29 // fRefCnt can be one when an effect is created statically using GR_CREA TE_STATIC_EFFECT
30 SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions); 30 SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions);
31 // Set to invalid values. 31 // Set to invalid values.
32 SkDEBUGCODE(fRefCnt = fPendingExecutions = -10;) 32 SkDEBUGCODE(fRefCnt = fPendingExecutions = -10;)
33 } 33 }
34 34
35 void ref() const { 35 void ref() const {
36 this->validate(); 36 this->validate();
37 // Once the ref cnt reaches zero it should never be ref'ed again. 37 // Once the ref cnt reaches zero it should never be ref'ed again.
38 SkASSERT(fRefCnt > 0); 38 SkASSERT(fRefCnt > 0);
39 ++fRefCnt; 39 ++fRefCnt;
40 this->validate(); 40 this->validate();
41 } 41 }
42 42
43 void unref() const { 43 void unref() const {
44 this->validate(); 44 this->validate();
45 --fRefCnt; 45 --fRefCnt;
46 if (0 == fRefCnt) { 46 if (0 == fRefCnt) {
47 this->notifyRefCntIsZero();
47 if (0 == fPendingExecutions) { 48 if (0 == fPendingExecutions) {
48 delete this; 49 delete this;
49 return; 50 return;
50 } else { 51 } else {
51 this->removeRefs(); 52 this->removeRefs();
52 } 53 }
53 } 54 }
54 this->validate(); 55 this->validate();
55 } 56 }
56 57
(...skipping 14 matching lines...) Expand all
71 GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniq ueID()) {} 72 GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniq ueID()) {}
72 73
73 /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce 74 /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce
74 is and will remain owned by the subclass and this function will retain a raw ptr. Once a 75 is and will remain owned by the subclass and this function will retain a raw ptr. Once a
75 GrGpuResourceRef is registered its setResource must not be called. 76 GrGpuResourceRef is registered its setResource must not be called.
76 */ 77 */
77 void addGpuResource(const GrGpuResourceRef* res) { 78 void addGpuResource(const GrGpuResourceRef* res) {
78 fGpuResources.push_back(res); 79 fGpuResources.push_back(res);
79 } 80 }
80 81
81 private:
82 static uint32_t CreateUniqueID();
83
84 void addPendingExecution() const { 82 void addPendingExecution() const {
85 this->validate(); 83 this->validate();
86 SkASSERT(fRefCnt > 0); 84 SkASSERT(fRefCnt > 0);
87 if (0 == fPendingExecutions) { 85 if (0 == fPendingExecutions) {
88 this->addPendingIOs(); 86 this->addPendingIOs();
89 } 87 }
90 ++fPendingExecutions; 88 ++fPendingExecutions;
91 this->validate(); 89 this->validate();
92 } 90 }
93 91
94 void completedExecution() const { 92 void completedExecution() const {
95 this->validate(); 93 this->validate();
96 --fPendingExecutions; 94 --fPendingExecutions;
97 if (0 == fPendingExecutions) { 95 if (0 == fPendingExecutions) {
98 if (0 == fRefCnt) { 96 if (0 == fRefCnt) {
99 delete this; 97 delete this;
100 return; 98 return;
101 } else { 99 } else {
102 this->pendingIOComplete(); 100 this->pendingIOComplete();
103 } 101 }
104 } 102 }
105 this->validate(); 103 this->validate();
106 } 104 }
107 105
106 private:
107 /** This will be called when the ref cnt is zero. The object may or may not have pending
108 executions. */
109 virtual void notifyRefCntIsZero() const = 0;
110
111 static uint32_t CreateUniqueID();
112
108 void removeRefs() const; 113 void removeRefs() const;
109 void addPendingIOs() const; 114 void addPendingIOs() const;
110 void pendingIOComplete() const; 115 void pendingIOComplete() const;
111 116
112 mutable int32_t fRefCnt; 117 mutable int32_t fRefCnt;
113 // Count of deferred executions not yet issued to the 3D API. 118 // Count of deferred executions not yet issued to the 3D API.
114 mutable int32_t fPendingExecutions; 119 mutable int32_t fPendingExecutions;
115 uint32_t fUniqueID; 120 uint32_t fUniqueID;
116 121
117 SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources; 122 SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources;
118 123
119 // Only this class can access addPendingExecution() and completedExecution() . 124 // Only this class can access addPendingExecution() and completedExecution() .
120 template <typename T> friend class GrPendingProgramElement; 125 template <typename T> friend class GrPendingProgramElement;
121 126
122 typedef SkNoncopyable INHERITED; 127 typedef SkNoncopyable INHERITED;
123 }; 128 };
124 129
125 #endif 130 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrFragmentProcessor.h ('k') | include/gpu/GrXferProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698