blob: e20a30ffd39cdb7ce90c704101faf4d0269ffd95 [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
bsalomon@google.com72830222013-01-23 20:25:22 +000013GrResource::GrResource(GrGpu* gpu, bool isWrapped) {
bsalomon@google.com838f6e12013-01-23 21:37:01 +000014 fGpu = gpu;
15 fCacheEntry = NULL;
16 fDeferredRefCount = 0;
bsalomon@google.com72830222013-01-23 20:25:22 +000017 if (isWrapped) {
robertphillips@google.com9ef04262013-10-29 14:06:15 +000018 fFlags = kWrapped_FlagBit;
bsalomon@google.com72830222013-01-23 20:25:22 +000019 } else {
20 fFlags = 0;
21 }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000022 fGpu->insertResource(this);
23}
24
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000025GrResource::~GrResource() {
26 // subclass should have released this.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000027 SkASSERT(0 == fDeferredRefCount);
28 SkASSERT(!this->isValid());
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000029}
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}