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