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