Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / GrGpuObject.cpp
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
13 GrGpuObject::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
24 GrGpuObject::~GrGpuObject() {
25     // subclass should have released this.
26     SkASSERT(0 == fDeferredRefCount);
27     SkASSERT(this->wasDestroyed());
28 }
29
30 void GrGpuObject::release() {
31     if (NULL != fGpu) {
32         this->onRelease();
33         fGpu->removeObject(this);
34         fGpu = NULL;
35     }
36 }
37
38 void GrGpuObject::abandon() {
39     if (NULL != fGpu) {
40         this->onAbandon();
41         fGpu->removeObject(this);
42         fGpu = NULL;
43     }
44 }
45
46 const GrContext* GrGpuObject::getContext() const {
47     if (NULL != fGpu) {
48         return fGpu->getContext();
49     } else {
50         return NULL;
51     }
52 }
53
54 GrContext* GrGpuObject::getContext() {
55     if (NULL != fGpu) {
56         return fGpu->getContext();
57     } else {
58         return NULL;
59     }
60 }