blob: 8fb21e8879f125f12b138a242157d77ecfbab02d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com8fe72472011-03-30 21:26:44 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
bsalomon@google.com8fe72472011-03-30 21:26:44 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com8fe72472011-03-30 21:26:44 +000010#include "GrResource.h"
11#include "GrGpu.h"
12
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000013SK_DEFINE_INST_COUNT(GrResource)
robertphillips@google.com977b9c82012-06-05 19:35:09 +000014
bsalomon@google.com72830222013-01-23 20:25:22 +000015GrResource::GrResource(GrGpu* gpu, bool isWrapped) {
bsalomon@google.com838f6e12013-01-23 21:37:01 +000016 fGpu = gpu;
17 fCacheEntry = NULL;
18 fDeferredRefCount = 0;
bsalomon@google.com72830222013-01-23 20:25:22 +000019 if (isWrapped) {
20 fFlags = kWrapped_Flag;
21 } else {
22 fFlags = 0;
23 }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000024 fGpu->insertResource(this);
25}
26
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000027GrResource::~GrResource() {
28 // subclass should have released this.
bsalomon@google.com838f6e12013-01-23 21:37:01 +000029 GrAssert(0 == fDeferredRefCount);
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000030 GrAssert(!this->isValid());
31}
32
bsalomon@google.com8fe72472011-03-30 21:26:44 +000033void GrResource::release() {
34 if (NULL != fGpu) {
35 this->onRelease();
36 fGpu->removeResource(this);
37 fGpu = NULL;
38 }
39}
40
41void GrResource::abandon() {
42 if (NULL != fGpu) {
43 this->onAbandon();
44 fGpu->removeResource(this);
45 fGpu = NULL;
46 }
47}
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000048
49const GrContext* GrResource::getContext() const {
50 if (NULL != fGpu) {
51 return fGpu->getContext();
52 } else {
53 return NULL;
54 }
55}
56
57GrContext* GrResource::getContext() {
58 if (NULL != fGpu) {
59 return fGpu->getContext();
60 } else {
61 return NULL;
62 }
63}