Index: include/gpu/GrGpuResourceRef.h |
diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h |
index 93298f0656f4e5e03529c27e04e59233c0dba1bc..3742e2519519dfaafaf251ca38fe2a553a7e44fc 100644 |
--- a/include/gpu/GrGpuResourceRef.h |
+++ b/include/gpu/GrGpuResourceRef.h |
@@ -159,25 +159,38 @@ private: |
*/ |
template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyable { |
public: |
- GrPendingIOResource(T* resource) : fResource(resource) { |
- if (NULL != fResource) { |
+ GrPendingIOResource(T* resource = NULL) : fResource(NULL) { |
+ this->reset(resource); |
+ } |
+ |
+ void reset(T* resource) { |
+ if (resource) { |
switch (IO_TYPE) { |
case kRead_GrIOType: |
- fResource->addPendingRead(); |
+ resource->addPendingRead(); |
break; |
case kWrite_GrIOType: |
- fResource->addPendingWrite(); |
+ resource->addPendingWrite(); |
break; |
case kRW_GrIOType: |
- fResource->addPendingRead(); |
- fResource->addPendingWrite(); |
+ resource->addPendingRead(); |
+ resource->addPendingWrite(); |
break; |
} |
} |
+ this->release(); |
+ fResource = resource; |
} |
~GrPendingIOResource() { |
- if (NULL != fResource) { |
+ this->release(); |
+ } |
+ |
+ T* get() const { return fResource; } |
+ |
+private: |
+ void release() { |
+ if (fResource) { |
switch (IO_TYPE) { |
case kRead_GrIOType: |
fResource->completedRead(); |
@@ -193,9 +206,6 @@ public: |
} |
} |
- T* get() const { return fResource; } |
- |
-private: |
T* fResource; |
}; |
#endif |