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 "GrProgramElement.h" | 8 #include "GrProgramElement.h" |
9 #include "GrGpuResourceRef.h" | 9 #include "GrGpuResourceRef.h" |
10 | 10 |
11 uint32_t GrProgramElement::CreateUniqueID() { | 11 uint32_t GrProgramElement::CreateUniqueID() { |
12 static int32_t gUniqueID = SK_InvalidUniqueID; | 12 static int32_t gUniqueID = SK_InvalidUniqueID; |
13 uint32_t id; | 13 uint32_t id; |
14 do { | 14 do { |
15 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 15 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
16 } while (id == SK_InvalidUniqueID); | 16 } while (id == SK_InvalidUniqueID); |
17 return id; | 17 return id; |
18 } | 18 } |
19 | 19 |
20 void GrProgramElement::convertRefToPendingExecution() const { | 20 void GrProgramElement::addPendingIOs() const { |
21 // This function makes it so that all the GrGpuResourceRefs own a single ref
to their | 21 for (int i = 0; i < fGpuResources.count(); ++i) { |
22 // underlying GrGpuResource if there are any refs to the GrProgramElement an
d a single | 22 fGpuResources[i]->markPendingIO(); |
23 // pending read/write if there are any pending executions of the GrProgramEl
ement. The | |
24 // GrGpuResourceRef will give up its single ref and/or pending read/write in
its destructor. | |
25 SkASSERT(fRefCnt > 0); | |
26 if (0 == fPendingExecutions) { | |
27 for (int i = 0; i < fGpuResources.count(); ++i) { | |
28 fGpuResources[i]->markPendingIO(); | |
29 } | |
30 } | |
31 ++fPendingExecutions; | |
32 this->unref(); | |
33 if (0 == fRefCnt) { | |
34 this->removeRefs(); | |
35 } | |
36 } | |
37 | |
38 void GrProgramElement::completedExecution() const { | |
39 this->validate(); | |
40 --fPendingExecutions; | |
41 if (0 == fPendingExecutions) { | |
42 if (0 == fRefCnt) { | |
43 SkDELETE(this); | |
44 } else { | |
45 // Now our pending executions have ocurred and we still have refs. C
onvert | |
46 // ownership of our resources back to regular refs. | |
47 for (int i = 0; i < fGpuResources.count(); ++i) { | |
48 fGpuResources[i]->pendingIOComplete(); | |
49 } | |
50 | |
51 } | |
52 } | 23 } |
53 } | 24 } |
54 | 25 |
55 void GrProgramElement::removeRefs() const { | 26 void GrProgramElement::removeRefs() const { |
56 for (int i = 0; i < fGpuResources.count(); ++i) { | 27 for (int i = 0; i < fGpuResources.count(); ++i) { |
57 fGpuResources[i]->removeRef(); | 28 fGpuResources[i]->removeRef(); |
58 } | 29 } |
59 } | 30 } |
| 31 |
| 32 void GrProgramElement::pendingIOComplete() const { |
| 33 for (int i = 0; i < fGpuResources.count(); ++i) { |
| 34 fGpuResources[i]->pendingIOComplete(); |
| 35 } |
| 36 } |
| 37 |
OLD | NEW |