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

Side by Side Diff: src/gpu/GrGpuResourceRef.cpp

Issue 579403003: Move IOType to GrGpuRef and rename that to GrIORef. Template GrPendingIORef on IOType. (Closed) Base URL: https://skia.googlesource.com/skia.git@ref
Patch Set: rebase again 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
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | src/gpu/GrInOrderDrawBuffer.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 #include "GrGpuResourceRef.h" 8 #include "GrGpuResourceRef.h"
9 #include "GrGpuResource.h"
10 9
11 GrGpuResourceRef::GrGpuResourceRef() { 10 GrGpuResourceRef::GrGpuResourceRef() {
12 fResource = NULL; 11 fResource = NULL;
13 fOwnRef = false; 12 fOwnRef = false;
14 fPendingIO = false; 13 fPendingIO = false;
15 fIOType = kNone_IOType;
16 } 14 }
17 15
18 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, IOType ioType) { 16 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, GrIORef::IOType ioTy pe) {
19 fResource = NULL; 17 fResource = NULL;
20 fOwnRef = false; 18 fOwnRef = false;
21 fPendingIO = false; 19 fPendingIO = false;
22 this->setResource(resource, ioType); 20 this->setResource(resource, ioType);
23 } 21 }
24 22
25 GrGpuResourceRef::~GrGpuResourceRef() { 23 GrGpuResourceRef::~GrGpuResourceRef() {
26 if (fOwnRef) { 24 if (fOwnRef) {
27 SkASSERT(fResource); 25 SkASSERT(fResource);
28 fResource->unref(); 26 fResource->unref();
29 } 27 }
30 if (fPendingIO) { 28 if (fPendingIO) {
31 switch (fIOType) { 29 switch (fIOType) {
32 case kNone_IOType: 30 case GrIORef::kRead_IOType:
33 SkFAIL("Shouldn't get here if fIOType is kNone.");
34 break;
35 case kRead_IOType:
36 fResource->completedRead(); 31 fResource->completedRead();
37 break; 32 break;
38 case kWrite_IOType: 33 case GrIORef::kWrite_IOType:
39 fResource->completedWrite(); 34 fResource->completedWrite();
40 break; 35 break;
41 case kRW_IOType: 36 case GrIORef::kRW_IOType:
42 fResource->completedRead(); 37 fResource->completedRead();
43 fResource->completedWrite(); 38 fResource->completedWrite();
44 break; 39 break;
45 } 40 }
46 } 41 }
47 } 42 }
48 43
49 void GrGpuResourceRef::reset() { 44 void GrGpuResourceRef::reset() {
50 SkASSERT(!fPendingIO); 45 SkASSERT(!fPendingIO);
51 SkASSERT(SkToBool(fResource) == fOwnRef); 46 SkASSERT(SkToBool(fResource) == fOwnRef);
52 if (fOwnRef) { 47 if (fOwnRef) {
53 fResource->unref(); 48 fResource->unref();
54 fOwnRef = false; 49 fOwnRef = false;
55 fResource = NULL; 50 fResource = NULL;
56 fIOType = kNone_IOType;
57 } 51 }
58 } 52 }
59 53
60 void GrGpuResourceRef::setResource(GrGpuResource* resource, IOType ioType) { 54 void GrGpuResourceRef::setResource(GrGpuResource* resource, GrIORef::IOType ioTy pe) {
61 SkASSERT(!fPendingIO); 55 SkASSERT(!fPendingIO);
62 SkASSERT(SkToBool(fResource) == fOwnRef); 56 SkASSERT(SkToBool(fResource) == fOwnRef);
63 SkSafeUnref(fResource); 57 SkSafeUnref(fResource);
64 if (NULL == resource) { 58 if (NULL == resource) {
65 fResource = NULL; 59 fResource = NULL;
66 fOwnRef = false; 60 fOwnRef = false;
67 fIOType = kNone_IOType;
68 } else { 61 } else {
69 SkASSERT(kNone_IOType != ioType);
70 fResource = resource; 62 fResource = resource;
71 fOwnRef = true; 63 fOwnRef = true;
72 fIOType = ioType; 64 fIOType = ioType;
73 } 65 }
74 } 66 }
75 67
76 void GrGpuResourceRef::markPendingIO() const { 68 void GrGpuResourceRef::markPendingIO() const {
77 // 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
78 // pendingExecution ref. 70 // pendingExecution ref.
79 SkASSERT(!fPendingIO); 71 SkASSERT(!fPendingIO);
80 SkASSERT(fResource); 72 SkASSERT(fResource);
81 fPendingIO = true; 73 fPendingIO = true;
82 switch (fIOType) { 74 switch (fIOType) {
83 case kNone_IOType: 75 case GrIORef::kRead_IOType:
84 SkFAIL("GrGpuResourceRef with neither reads nor writes?");
85 break;
86 case kRead_IOType:
87 fResource->addPendingRead(); 76 fResource->addPendingRead();
88 break; 77 break;
89 case kWrite_IOType: 78 case GrIORef::kWrite_IOType:
90 fResource->addPendingWrite(); 79 fResource->addPendingWrite();
91 break; 80 break;
92 case kRW_IOType: 81 case GrIORef::kRW_IOType:
93 fResource->addPendingRead(); 82 fResource->addPendingRead();
94 fResource->addPendingWrite(); 83 fResource->addPendingWrite();
95 break; 84 break;
96 } 85 }
97 } 86 }
98 87
99 void GrGpuResourceRef::pendingIOComplete() const { 88 void GrGpuResourceRef::pendingIOComplete() const {
100 // 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
101 // reffed. 90 // reffed.
102 SkASSERT(fOwnRef); 91 SkASSERT(fOwnRef);
103 SkASSERT(fPendingIO); 92 SkASSERT(fPendingIO);
104 switch (fIOType) { 93 switch (fIOType) {
105 case kNone_IOType: 94 case GrIORef::kRead_IOType:
106 SkFAIL("GrGpuResourceRef with neither reads nor writes?");
107 break;
108 case kRead_IOType:
109 fResource->completedRead(); 95 fResource->completedRead();
110 break; 96 break;
111 case kWrite_IOType: 97 case GrIORef::kWrite_IOType:
112 fResource->completedWrite(); 98 fResource->completedWrite();
113 break; 99 break;
114 case kRW_IOType: 100 case GrIORef::kRW_IOType:
115 fResource->completedRead(); 101 fResource->completedRead();
116 fResource->completedWrite(); 102 fResource->completedWrite();
117 break; 103 break;
118 104
119 } 105 }
120 fPendingIO = false; 106 fPendingIO = false;
121 } 107 }
122 108
123 void GrGpuResourceRef::removeRef() const { 109 void GrGpuResourceRef::removeRef() const {
124 // 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
125 // there is a pending execution. 111 // there is a pending execution.
126 SkASSERT(fOwnRef); 112 SkASSERT(fOwnRef);
127 SkASSERT(fPendingIO); 113 SkASSERT(fPendingIO);
128 SkASSERT(kNone_IOType != fIOType);
129 SkASSERT(fResource); 114 SkASSERT(fResource);
130 fResource->unref(); 115 fResource->unref();
131 fOwnRef = false; 116 fOwnRef = false;
132 } 117 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | src/gpu/GrInOrderDrawBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698