blob: 43a86f2d51bace98a209eac9294e64f291191c5e [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
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000010#include "GrGpuObject.h"
bsalomon@google.com8fe72472011-03-30 21:26:44 +000011#include "GrGpu.h"
12
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000013GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) {
bsalomon@google.com838f6e12013-01-23 21:37:01 +000014 fGpu = gpu;
bsalomon@google.com838f6e12013-01-23 21:37:01 +000015 fDeferredRefCount = 0;
bsalomon@google.com72830222013-01-23 20:25:22 +000016 if (isWrapped) {
robertphillips@google.com9ef04262013-10-29 14:06:15 +000017 fFlags = kWrapped_FlagBit;
bsalomon@google.com72830222013-01-23 20:25:22 +000018 } else {
19 fFlags = 0;
20 }
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000021 fGpu->insertObject(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000022}
23
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000024GrGpuObject::~GrGpuObject() {
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000025 // subclass should have released this.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000026 SkASSERT(0 == fDeferredRefCount);
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000027 SkASSERT(this->wasDestroyed());
bsalomon@google.com76b7fcc2012-04-27 17:24:09 +000028}
29
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000030void GrGpuObject::release() {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000031 if (NULL != fGpu) {
32 this->onRelease();
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000033 fGpu->removeObject(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000034 fGpu = NULL;
35 }
36}
37
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000038void GrGpuObject::abandon() {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000039 if (NULL != fGpu) {
40 this->onAbandon();
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000041 fGpu->removeObject(this);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000042 fGpu = NULL;
43 }
44}
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000045
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000046const GrContext* GrGpuObject::getContext() const {
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000047 if (NULL != fGpu) {
48 return fGpu->getContext();
49 } else {
50 return NULL;
51 }
52}
53
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000054GrContext* GrGpuObject::getContext() {
bsalomon@google.comf7b5c1e2011-11-15 19:42:07 +000055 if (NULL != fGpu) {
56 return fGpu->getContext();
57 } else {
58 return NULL;
59 }
60}