2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "GrGpuResourceRef.h"
10 GrGpuResourceRef::GrGpuResourceRef() {
16 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, GrIORef::IOType ioType) {
20 this->setResource(resource, ioType);
23 GrGpuResourceRef::~GrGpuResourceRef() {
30 case GrIORef::kRead_IOType:
31 fResource->completedRead();
33 case GrIORef::kWrite_IOType:
34 fResource->completedWrite();
36 case GrIORef::kRW_IOType:
37 fResource->completedRead();
38 fResource->completedWrite();
44 void GrGpuResourceRef::reset() {
45 SkASSERT(!fPendingIO);
46 SkASSERT(SkToBool(fResource) == fOwnRef);
54 void GrGpuResourceRef::setResource(GrGpuResource* resource, GrIORef::IOType ioType) {
55 SkASSERT(!fPendingIO);
56 SkASSERT(SkToBool(fResource) == fOwnRef);
57 SkSafeUnref(fResource);
58 if (NULL == resource) {
68 void GrGpuResourceRef::markPendingIO() const {
69 // This should only be called when the owning GrProgramElement gets its first
70 // pendingExecution ref.
71 SkASSERT(!fPendingIO);
75 case GrIORef::kRead_IOType:
76 fResource->addPendingRead();
78 case GrIORef::kWrite_IOType:
79 fResource->addPendingWrite();
81 case GrIORef::kRW_IOType:
82 fResource->addPendingRead();
83 fResource->addPendingWrite();
88 void GrGpuResourceRef::pendingIOComplete() const {
89 // This should only be called when the owner's pending executions have ocurred but it is still
94 case GrIORef::kRead_IOType:
95 fResource->completedRead();
97 case GrIORef::kWrite_IOType:
98 fResource->completedWrite();
100 case GrIORef::kRW_IOType:
101 fResource->completedRead();
102 fResource->completedWrite();
109 void GrGpuResourceRef::removeRef() const {
110 // This should only be called once, when the owners last ref goes away and
111 // there is a pending execution.
113 SkASSERT(fPendingIO);