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