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 #include "GrProgramResource.h" | 8 #include "GrGpuResourceRef.h" |
9 #include "GrGpuResource.h" | 9 #include "GrGpuResource.h" |
10 | 10 |
11 GrProgramResource::GrProgramResource() { | 11 GrGpuResourceRef::GrGpuResourceRef() { |
12 fResource = NULL; | 12 fResource = NULL; |
13 fOwnRef = false; | 13 fOwnRef = false; |
14 fPendingIO = false; | 14 fPendingIO = false; |
15 fIOType = kNone_IOType; | 15 fIOType = kNone_IOType; |
16 } | 16 } |
17 | 17 |
18 GrProgramResource::GrProgramResource(GrGpuResource* resource, IOType ioType) { | 18 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, IOType ioType) { |
19 fResource = NULL; | 19 fResource = NULL; |
20 fOwnRef = false; | 20 fOwnRef = false; |
21 fPendingIO = false; | 21 fPendingIO = false; |
22 this->setResource(resource, ioType); | 22 this->setResource(resource, ioType); |
23 } | 23 } |
24 | 24 |
25 GrProgramResource::~GrProgramResource() { | 25 GrGpuResourceRef::~GrGpuResourceRef() { |
26 if (fOwnRef) { | 26 if (fOwnRef) { |
27 SkASSERT(fResource); | 27 SkASSERT(fResource); |
28 fResource->unref(); | 28 fResource->unref(); |
29 } | 29 } |
30 if (fPendingIO) { | 30 if (fPendingIO) { |
31 switch (fIOType) { | 31 switch (fIOType) { |
32 case kNone_IOType: | 32 case kNone_IOType: |
33 SkFAIL("Shouldn't get here if fIOType is kNone."); | 33 SkFAIL("Shouldn't get here if fIOType is kNone."); |
34 break; | 34 break; |
35 case kRead_IOType: | 35 case kRead_IOType: |
36 fResource->completedRead(); | 36 fResource->completedRead(); |
37 break; | 37 break; |
38 case kWrite_IOType: | 38 case kWrite_IOType: |
39 fResource->completedWrite(); | 39 fResource->completedWrite(); |
40 break; | 40 break; |
41 case kRW_IOType: | 41 case kRW_IOType: |
42 fResource->completedRead(); | 42 fResource->completedRead(); |
43 fResource->completedWrite(); | 43 fResource->completedWrite(); |
44 break; | 44 break; |
45 } | 45 } |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void GrProgramResource::reset() { | 49 void GrGpuResourceRef::reset() { |
50 SkASSERT(!fPendingIO); | 50 SkASSERT(!fPendingIO); |
51 SkASSERT(SkToBool(fResource) == fOwnRef); | 51 SkASSERT(SkToBool(fResource) == fOwnRef); |
52 if (fOwnRef) { | 52 if (fOwnRef) { |
53 fResource->unref(); | 53 fResource->unref(); |
54 fOwnRef = false; | 54 fOwnRef = false; |
55 fResource = NULL; | 55 fResource = NULL; |
56 fIOType = kNone_IOType; | 56 fIOType = kNone_IOType; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void GrProgramResource::setResource(GrGpuResource* resource, IOType ioType) { | 60 void GrGpuResourceRef::setResource(GrGpuResource* resource, IOType ioType) { |
61 SkASSERT(!fPendingIO); | 61 SkASSERT(!fPendingIO); |
62 SkASSERT(SkToBool(fResource) == fOwnRef); | 62 SkASSERT(SkToBool(fResource) == fOwnRef); |
63 SkSafeUnref(fResource); | 63 SkSafeUnref(fResource); |
64 if (NULL == resource) { | 64 if (NULL == resource) { |
65 fResource = NULL; | 65 fResource = NULL; |
66 fOwnRef = false; | 66 fOwnRef = false; |
67 fIOType = kNone_IOType; | 67 fIOType = kNone_IOType; |
68 } else { | 68 } else { |
69 SkASSERT(kNone_IOType != ioType); | 69 SkASSERT(kNone_IOType != ioType); |
70 fResource = resource; | 70 fResource = resource; |
71 fOwnRef = true; | 71 fOwnRef = true; |
72 fIOType = ioType; | 72 fIOType = ioType; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void GrProgramResource::markPendingIO() const { | 76 void GrGpuResourceRef::markPendingIO() const { |
77 // This should only be called when the owning GrProgramElement gets its firs
t | 77 // This should only be called when the owning GrProgramElement gets its firs
t |
78 // pendingExecution ref. | 78 // pendingExecution ref. |
79 SkASSERT(!fPendingIO); | 79 SkASSERT(!fPendingIO); |
80 SkASSERT(fResource); | 80 SkASSERT(fResource); |
81 fPendingIO = true; | 81 fPendingIO = true; |
82 switch (fIOType) { | 82 switch (fIOType) { |
83 case kNone_IOType: | 83 case kNone_IOType: |
84 SkFAIL("GrProgramResource with neither reads nor writes?"); | 84 SkFAIL("GrGpuResourceRef with neither reads nor writes?"); |
85 break; | 85 break; |
86 case kRead_IOType: | 86 case kRead_IOType: |
87 fResource->addPendingRead(); | 87 fResource->addPendingRead(); |
88 break; | 88 break; |
89 case kWrite_IOType: | 89 case kWrite_IOType: |
90 fResource->addPendingWrite(); | 90 fResource->addPendingWrite(); |
91 break; | 91 break; |
92 case kRW_IOType: | 92 case kRW_IOType: |
93 fResource->addPendingRead(); | 93 fResource->addPendingRead(); |
94 fResource->addPendingWrite(); | 94 fResource->addPendingWrite(); |
95 break; | 95 break; |
96 | 96 |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void GrProgramResource::pendingIOComplete() const { | 100 void GrGpuResourceRef::pendingIOComplete() const { |
101 // This should only be called when the owner's pending executions have ocurr
ed but it is still | 101 // This should only be called when the owner's pending executions have ocurr
ed but it is still |
102 // reffed. | 102 // reffed. |
103 SkASSERT(fOwnRef); | 103 SkASSERT(fOwnRef); |
104 SkASSERT(fPendingIO); | 104 SkASSERT(fPendingIO); |
105 switch (fIOType) { | 105 switch (fIOType) { |
106 case kNone_IOType: | 106 case kNone_IOType: |
107 SkFAIL("GrProgramResource with neither reads nor writes?"); | 107 SkFAIL("GrGpuResourceRef with neither reads nor writes?"); |
108 break; | 108 break; |
109 case kRead_IOType: | 109 case kRead_IOType: |
110 fResource->completedRead(); | 110 fResource->completedRead(); |
111 break; | 111 break; |
112 case kWrite_IOType: | 112 case kWrite_IOType: |
113 fResource->completedWrite(); | 113 fResource->completedWrite(); |
114 break; | 114 break; |
115 case kRW_IOType: | 115 case kRW_IOType: |
116 fResource->completedRead(); | 116 fResource->completedRead(); |
117 fResource->completedWrite(); | 117 fResource->completedWrite(); |
118 break; | 118 break; |
119 | 119 |
120 } | 120 } |
121 fPendingIO = false; | 121 fPendingIO = false; |
122 } | 122 } |
123 | 123 |
124 void GrProgramResource::removeRef() const { | 124 void GrGpuResourceRef::removeRef() const { |
125 // This should only be called once, when the owners last ref goes away and | 125 // This should only be called once, when the owners last ref goes away and |
126 // there is a pending execution. | 126 // there is a pending execution. |
127 SkASSERT(fOwnRef); | 127 SkASSERT(fOwnRef); |
128 SkASSERT(fPendingIO); | 128 SkASSERT(fPendingIO); |
129 SkASSERT(kNone_IOType != fIOType); | 129 SkASSERT(kNone_IOType != fIOType); |
130 SkASSERT(fResource); | 130 SkASSERT(fResource); |
131 fResource->unref(); | 131 fResource->unref(); |
132 fOwnRef = false; | 132 fOwnRef = false; |
133 } | 133 } |
OLD | NEW |