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

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

Issue 537773004: Add GrProgramElement base class for GrEffect with deferred exec ref. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: one more extra 'e' in pending 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
« src/gpu/GrProgramElement.cpp ('K') | « src/gpu/GrProgramElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrProgramResource.h"
9 #include "GrGpuResource.h"
10
11 GrProgramResource::GrProgramResource() {
12 fResource = NULL;
13 fOwnRef = false;
14 fPendingIO = false;
15 fIOType = kNone_IOType;
16 }
17
18 GrProgramResource::GrProgramResource(GrGpuResource* resource, IOType ioType) {
19 fResource = NULL;
20 fOwnRef = false;
21 fPendingIO = false;
22 this->setResource(resource, ioType);
23 }
24
25 GrProgramResource::~GrProgramResource() {
26 if (fOwnRef) {
27 SkASSERT(NULL != fResource);
28 fResource->unref();
29 }
30 if (fPendingIO) {
31 switch (fIOType) {
32 case kNone_IOType:
33 SkFAIL("Shouldn't get here if fIOType is kNone.");
34 break;
35 case kRead_IOType:
36 fResource->completedRead();
37 break;
38 case kWrite_IOType:
39 fResource->completedWrite();
40 break;
41 case kRW_IOType:
42 fResource->completedRead();
43 fResource->completedWrite();
44 break;
45 }
46 }
47 }
48
49 void GrProgramResource::reset() {
50 SkASSERT(!fPendingIO);
51 SkASSERT((NULL != fResource) == fOwnRef);
52 if (fOwnRef) {
53 fResource->unref();
54 fOwnRef = false;
55 fResource = NULL;
56 }
57 }
58
59 void GrProgramResource::setResource(GrGpuResource* resource, IOType ioType) {
60 SkASSERT(!fPendingIO);
61 SkASSERT((NULL != fResource) == fOwnRef);
62 SkSafeUnref(fResource);
63 if (NULL == resource) {
64 fResource = NULL;
65 fOwnRef = false;
robertphillips 2014/09/04 19:48:57 fIOType = kNone_IOType; ?
bsalomon 2014/09/04 20:03:17 Done (here and in reset()).
66 } else {
67 SkASSERT(kNone_IOType != ioType);
68 fResource = resource;
69 fOwnRef = true;
70 fIOType = ioType;
71 }
72 }
73
74 void GrProgramResource::markPendingIO() const {
75 // This should only be called once, when the owning GrProgramElement gets it s first
76 // pendingExecution ref.
77 SkASSERT(!fPendingIO);
78 SkASSERT(NULL != fResource);
79 fPendingIO = true;
80 switch (fIOType) {
81 case kNone_IOType:
82 SkFAIL("GrProgramResource with neither reads nor writes?");
83 break;
84 case kRead_IOType:
85 fResource->addPendingRead();
86 break;
87 case kWrite_IOType:
88 fResource->addPendingWrite();
89 break;
90 case kRW_IOType:
91 fResource->addPendingRead();
92 fResource->addPendingWrite();
93 break;
94
95 }
96 }
97
98 void GrProgramResource::removeRef() const {
99 // This should only be called once, when the owners last ref goes away and
100 // there is a pending execution.
101 SkASSERT(fOwnRef);
102 SkASSERT(fPendingIO);
103 SkASSERT(kNone_IOType != fIOType);
104 SkASSERT(NULL != fResource);
105 fResource->unref();
106 fOwnRef = false;
107 }
OLDNEW
« src/gpu/GrProgramElement.cpp ('K') | « src/gpu/GrProgramElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698