1 2/* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10#include "GrResource.h" 11#include "GrGpu.h" 12 13SK_DEFINE_INST_COUNT(GrResource) 14 15GrResource::GrResource(GrGpu* gpu, bool isWrapped) { 16 fGpu = gpu; 17 fCacheEntry = NULL; 18 fDeferredRefCount = 0; 19 if (isWrapped) { 20 fFlags = kWrapped_Flag; 21 } else { 22 fFlags = 0; 23 } 24 fGpu->insertResource(this); 25} 26 27GrResource::~GrResource() { 28 // subclass should have released this. 29 GrAssert(0 == fDeferredRefCount); 30 GrAssert(!this->isValid()); 31} 32 33void GrResource::release() { 34 if (NULL != fGpu) { 35 this->onRelease(); 36 fGpu->removeResource(this); 37 fGpu = NULL; 38 } 39} 40 41void GrResource::abandon() { 42 if (NULL != fGpu) { 43 this->onAbandon(); 44 fGpu->removeResource(this); 45 fGpu = NULL; 46 } 47} 48 49const GrContext* GrResource::getContext() const { 50 if (NULL != fGpu) { 51 return fGpu->getContext(); 52 } else { 53 return NULL; 54 } 55} 56 57GrContext* GrResource::getContext() { 58 if (NULL != fGpu) { 59 return fGpu->getContext(); 60 } else { 61 return NULL; 62 } 63} 64