Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / GrGpuResource.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 "GrGpuResource.h"
11 #include "GrGpu.h"
12
13 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
14     : fRefCnt(1)
15     , fCacheEntry(NULL)
16     , fUniqueID(CreateUniqueID()) {
17     fGpu              = gpu;
18     if (isWrapped) {
19         fFlags = kWrapped_FlagBit;
20     } else {
21         fFlags = 0;
22     }
23     fGpu->insertObject(this);
24 }
25
26 GrGpuResource::~GrGpuResource() {
27     SkASSERT(0 == fRefCnt);
28     // subclass should have released this.
29     SkASSERT(this->wasDestroyed());
30 }
31
32 void GrGpuResource::release() {
33     if (NULL != fGpu) {
34         this->onRelease();
35         fGpu->removeObject(this);
36         fGpu = NULL;
37     }
38 }
39
40 void GrGpuResource::abandon() {
41     if (NULL != fGpu) {
42         this->onAbandon();
43         fGpu->removeObject(this);
44         fGpu = NULL;
45     }
46 }
47
48 const GrContext* GrGpuResource::getContext() const {
49     if (NULL != fGpu) {
50         return fGpu->getContext();
51     } else {
52         return NULL;
53     }
54 }
55
56 GrContext* GrGpuResource::getContext() {
57     if (NULL != fGpu) {
58         return fGpu->getContext();
59     } else {
60         return NULL;
61     }
62 }
63
64 uint32_t GrGpuResource::CreateUniqueID() {
65     static int32_t gUniqueID = SK_InvalidUniqueID;
66     uint32_t id;
67     do {
68         id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
69     } while (id == SK_InvalidUniqueID);
70     return id;
71 }