| 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 = nullptr; | 11 fResource = nullptr; |
| 12 fOwnRef = false; | 12 fOwnRef = false; |
| 13 fPendingIO = false; | 13 fPendingIO = false; |
| 14 fDst = NULL; |
| 14 } | 15 } |
| 15 | 16 |
| 16 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, GrIOType ioType) { | 17 GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, GrIOType ioType, GrG
puResource* dst) { |
| 17 fResource = nullptr; | 18 fResource = nullptr; |
| 18 fOwnRef = false; | 19 fOwnRef = false; |
| 19 fPendingIO = false; | 20 fPendingIO = false; |
| 20 this->setResource(resource, ioType); | 21 fDst = NULL; |
| 22 this->setResource(resource, ioType, dst); |
| 21 } | 23 } |
| 22 | 24 |
| 23 GrGpuResourceRef::~GrGpuResourceRef() { | 25 GrGpuResourceRef::~GrGpuResourceRef() { |
| 24 if (fOwnRef) { | 26 if (fOwnRef) { |
| 25 SkASSERT(fResource); | 27 SkASSERT(fResource); |
| 26 fResource->unref(); | 28 fResource->unref(); |
| 27 } | 29 } |
| 28 if (fPendingIO) { | 30 if (fPendingIO) { |
| 29 switch (fIOType) { | 31 switch (fIOType) { |
| 30 case kRead_GrIOType: | 32 case kRead_GrIOType: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 } | 44 } |
| 43 | 45 |
| 44 void GrGpuResourceRef::reset() { | 46 void GrGpuResourceRef::reset() { |
| 45 SkASSERT(!fPendingIO); | 47 SkASSERT(!fPendingIO); |
| 46 SkASSERT(SkToBool(fResource) == fOwnRef); | 48 SkASSERT(SkToBool(fResource) == fOwnRef); |
| 47 if (fOwnRef) { | 49 if (fOwnRef) { |
| 48 fResource->unref(); | 50 fResource->unref(); |
| 49 fOwnRef = false; | 51 fOwnRef = false; |
| 50 fResource = nullptr; | 52 fResource = nullptr; |
| 51 } | 53 } |
| 54 fDst = NULL; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void GrGpuResourceRef::setResource(GrGpuResource* resource, GrIOType ioType) { | 57 void GrGpuResourceRef::setResource(GrGpuResource* resource, GrIOType ioType, GrG
puResource* dst) { |
| 55 SkASSERT(!fPendingIO); | 58 SkASSERT(!fPendingIO); |
| 56 SkASSERT(SkToBool(fResource) == fOwnRef); | 59 SkASSERT(SkToBool(fResource) == fOwnRef); |
| 57 SkSafeUnref(fResource); | 60 SkSafeUnref(fResource); |
| 58 if (nullptr == resource) { | 61 if (nullptr == resource) { |
| 62 SkASSERT(nullptr == dst); |
| 59 fResource = nullptr; | 63 fResource = nullptr; |
| 60 fOwnRef = false; | 64 fOwnRef = false; |
| 65 fDst = NULL; |
| 61 } else { | 66 } else { |
| 62 fResource = resource; | 67 fResource = resource; |
| 63 fOwnRef = true; | 68 fOwnRef = true; |
| 64 fIOType = ioType; | 69 fIOType = ioType; |
| 70 if (fIOType == kRead_GrIOType || fIOType == kRW_GrIOType) { |
| 71 SkASSERT(dst); |
| 72 fDst = dst; |
| 73 } else { |
| 74 fDst = NULL; |
| 75 } |
| 65 } | 76 } |
| 66 } | 77 } |
| 67 | 78 |
| 68 void GrGpuResourceRef::markPendingIO() const { | 79 void GrGpuResourceRef::markPendingIO() const { |
| 69 // This should only be called when the owning GrProgramElement gets its firs
t | 80 // This should only be called when the owning GrProgramElement gets its firs
t |
| 70 // pendingExecution ref. | 81 // pendingExecution ref. |
| 71 SkASSERT(!fPendingIO); | 82 SkASSERT(!fPendingIO); |
| 72 SkASSERT(fResource); | 83 SkASSERT(fResource); |
| 73 fPendingIO = true; | 84 fPendingIO = true; |
| 74 switch (fIOType) { | 85 switch (fIOType) { |
| 75 case kRead_GrIOType: | 86 case kRead_GrIOType: |
| 76 fResource->addPendingRead(); | 87 SkASSERT(fDst); |
| 88 fResource->addPendingRead(fDst); |
| 77 break; | 89 break; |
| 78 case kWrite_GrIOType: | 90 case kWrite_GrIOType: |
| 79 fResource->addPendingWrite(); | 91 fResource->addPendingWrite(); |
| 80 break; | 92 break; |
| 81 case kRW_GrIOType: | 93 case kRW_GrIOType: |
| 82 fResource->addPendingRead(); | 94 SkASSERT(fDst); |
| 95 fResource->addPendingRead(fDst); |
| 83 fResource->addPendingWrite(); | 96 fResource->addPendingWrite(); |
| 84 break; | 97 break; |
| 85 } | 98 } |
| 86 } | 99 } |
| 87 | 100 |
| 88 void GrGpuResourceRef::pendingIOComplete() const { | 101 void GrGpuResourceRef::pendingIOComplete() const { |
| 89 // This should only be called when the owner's pending executions have ocurr
ed but it is still | 102 // This should only be called when the owner's pending executions have ocurr
ed but it is still |
| 90 // reffed. | 103 // reffed. |
| 91 SkASSERT(fOwnRef); | 104 SkASSERT(fOwnRef); |
| 92 SkASSERT(fPendingIO); | 105 SkASSERT(fPendingIO); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 | 121 |
| 109 void GrGpuResourceRef::removeRef() const { | 122 void GrGpuResourceRef::removeRef() const { |
| 110 // This should only be called once, when the owners last ref goes away and | 123 // This should only be called once, when the owners last ref goes away and |
| 111 // there is a pending execution. | 124 // there is a pending execution. |
| 112 SkASSERT(fOwnRef); | 125 SkASSERT(fOwnRef); |
| 113 SkASSERT(fPendingIO); | 126 SkASSERT(fPendingIO); |
| 114 SkASSERT(fResource); | 127 SkASSERT(fResource); |
| 115 fResource->unref(); | 128 fResource->unref(); |
| 116 fOwnRef = false; | 129 fOwnRef = false; |
| 117 } | 130 } |
| OLD | NEW |