blob: 2ff7df61cba1829926903635131ff6596fba2c39 [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.com8fe72472011-03-30 21:26:44 +000015GrResource::GrResource(GrGpu* gpu) {
16 fGpu = gpu;
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000017 fCacheEntry = NULL;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000018 fGpu->insertResource(this);
19}
20
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000021GrResource::~GrResource() {
22 // subclass should have released this.
23 GrAssert(!this->isValid());
24}
25
bsalomon@google.com8fe72472011-03-30 21:26:44 +000026void GrResource::release() {
27 if (NULL != fGpu) {
28 this->onRelease();
29 fGpu->removeResource(this);
30 fGpu = NULL;
31 }
32}
33
34void GrResource::abandon() {
35 if (NULL != fGpu) {
36 this->onAbandon();
37 fGpu->removeResource(this);
38 fGpu = NULL;
39 }
40}
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000041
42const GrContext* GrResource::getContext() const {
43 if (NULL != fGpu) {
44 return fGpu->getContext();
45 } else {
46 return NULL;
47 }
48}
49
50GrContext* GrResource::getContext() {
51 if (NULL != fGpu) {
52 return fGpu->getContext();
53 } else {
54 return NULL;
55 }
56}
57