3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #include "GrGpuResource.h"
13 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
16 , fUniqueID(CreateUniqueID()) {
19 fFlags = kWrapped_FlagBit;
23 fGpu->insertObject(this);
26 GrGpuResource::~GrGpuResource() {
27 SkASSERT(0 == fRefCnt);
28 // subclass should have released this.
29 SkASSERT(this->wasDestroyed());
32 void GrGpuResource::release() {
35 fGpu->removeObject(this);
40 void GrGpuResource::abandon() {
43 fGpu->removeObject(this);
48 const GrContext* GrGpuResource::getContext() const {
50 return fGpu->getContext();
56 GrContext* GrGpuResource::getContext() {
58 return fGpu->getContext();
64 uint32_t GrGpuResource::CreateUniqueID() {
65 static int32_t gUniqueID = SK_InvalidUniqueID;
68 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
69 } while (id == SK_InvalidUniqueID);