michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "GrResource.h" michael@0: #include "GrGpu.h" michael@0: michael@0: GrResource::GrResource(GrGpu* gpu, bool isWrapped) { michael@0: fGpu = gpu; michael@0: fCacheEntry = NULL; michael@0: fDeferredRefCount = 0; michael@0: if (isWrapped) { michael@0: fFlags = kWrapped_FlagBit; michael@0: } else { michael@0: fFlags = 0; michael@0: } michael@0: fGpu->insertResource(this); michael@0: } michael@0: michael@0: GrResource::~GrResource() { michael@0: // subclass should have released this. michael@0: SkASSERT(0 == fDeferredRefCount); michael@0: SkASSERT(!this->isValid()); michael@0: } michael@0: michael@0: void GrResource::release() { michael@0: if (NULL != fGpu) { michael@0: this->onRelease(); michael@0: fGpu->removeResource(this); michael@0: fGpu = NULL; michael@0: } michael@0: } michael@0: michael@0: void GrResource::abandon() { michael@0: if (NULL != fGpu) { michael@0: this->onAbandon(); michael@0: fGpu->removeResource(this); michael@0: fGpu = NULL; michael@0: } michael@0: } michael@0: michael@0: const GrContext* GrResource::getContext() const { michael@0: if (NULL != fGpu) { michael@0: return fGpu->getContext(); michael@0: } else { michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: GrContext* GrResource::getContext() { michael@0: if (NULL != fGpu) { michael@0: return fGpu->getContext(); michael@0: } else { michael@0: return NULL; michael@0: } michael@0: }