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