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 "GrGpuObject.h"
11#include "GrGpu.h"
12
13GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) {
14    fGpu              = gpu;
15    fDeferredRefCount = 0;
16    if (isWrapped) {
17        fFlags = kWrapped_FlagBit;
18    } else {
19        fFlags = 0;
20    }
21    fGpu->insertObject(this);
22}
23
24GrGpuObject::~GrGpuObject() {
25    // subclass should have released this.
26    SkASSERT(0 == fDeferredRefCount);
27    SkASSERT(this->wasDestroyed());
28}
29
30void GrGpuObject::release() {
31    if (NULL != fGpu) {
32        this->onRelease();
33        fGpu->removeObject(this);
34        fGpu = NULL;
35    }
36}
37
38void GrGpuObject::abandon() {
39    if (NULL != fGpu) {
40        this->onAbandon();
41        fGpu->removeObject(this);
42        fGpu = NULL;
43    }
44}
45
46const GrContext* GrGpuObject::getContext() const {
47    if (NULL != fGpu) {
48        return fGpu->getContext();
49    } else {
50        return NULL;
51    }
52}
53
54GrContext* GrGpuObject::getContext() {
55    if (NULL != fGpu) {
56        return fGpu->getContext();
57    } else {
58        return NULL;
59    }
60}
61