blob: 7e2d4a8bb5032e4b0e00e524e92efe06ed668711 [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;
17 fNext = NULL;
18 fPrevious = NULL;
19 fGpu->insertResource(this);
20}
21
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000022GrResource::~GrResource() {
23 // subclass should have released this.
24 GrAssert(!this->isValid());
25}
26
bsalomon@google.com8fe72472011-03-30 21:26:44 +000027void GrResource::release() {
28 if (NULL != fGpu) {
29 this->onRelease();
30 fGpu->removeResource(this);
31 fGpu = NULL;
32 }
33}
34
35void GrResource::abandon() {
36 if (NULL != fGpu) {
37 this->onAbandon();
38 fGpu->removeResource(this);
39 fGpu = NULL;
40 }
41}
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000042
43const GrContext* GrResource::getContext() const {
44 if (NULL != fGpu) {
45 return fGpu->getContext();
46 } else {
47 return NULL;
48 }
49}
50
51GrContext* GrResource::getContext() {
52 if (NULL != fGpu) {
53 return fGpu->getContext();
54 } else {
55 return NULL;
56 }
57}
58