epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 10 | #include "GrGpuObject.h" |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 11 | #include "GrGpu.h" |
| 12 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 13 | GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) { |
bsalomon@google.com | 838f6e1 | 2013-01-23 21:37:01 +0000 | [diff] [blame] | 14 | fGpu = gpu; |
bsalomon@google.com | 838f6e1 | 2013-01-23 21:37:01 +0000 | [diff] [blame] | 15 | fDeferredRefCount = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 16 | if (isWrapped) { |
robertphillips@google.com | 9ef0426 | 2013-10-29 14:06:15 +0000 | [diff] [blame] | 17 | fFlags = kWrapped_FlagBit; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 18 | } else { |
| 19 | fFlags = 0; |
| 20 | } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 21 | fGpu->insertObject(this); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 22 | } |
| 23 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 24 | GrGpuObject::~GrGpuObject() { |
bsalomon@google.com | 76b7fcc | 2012-04-27 17:24:09 +0000 | [diff] [blame] | 25 | // subclass should have released this. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 26 | SkASSERT(0 == fDeferredRefCount); |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 27 | SkASSERT(this->wasDestroyed()); |
bsalomon@google.com | 76b7fcc | 2012-04-27 17:24:09 +0000 | [diff] [blame] | 28 | } |
| 29 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 30 | void GrGpuObject::release() { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 31 | if (NULL != fGpu) { |
| 32 | this->onRelease(); |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 33 | fGpu->removeObject(this); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 34 | fGpu = NULL; |
| 35 | } |
| 36 | } |
| 37 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 38 | void GrGpuObject::abandon() { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 39 | if (NULL != fGpu) { |
| 40 | this->onAbandon(); |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 41 | fGpu->removeObject(this); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 42 | fGpu = NULL; |
| 43 | } |
| 44 | } |
bsalomon@google.com | f7b5c1e | 2011-11-15 19:42:07 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 46 | const GrContext* GrGpuObject::getContext() const { |
bsalomon@google.com | f7b5c1e | 2011-11-15 19:42:07 +0000 | [diff] [blame] | 47 | if (NULL != fGpu) { |
| 48 | return fGpu->getContext(); |
| 49 | } else { |
| 50 | return NULL; |
| 51 | } |
| 52 | } |
| 53 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 54 | GrContext* GrGpuObject::getContext() { |
bsalomon@google.com | f7b5c1e | 2011-11-15 19:42:07 +0000 | [diff] [blame] | 55 | if (NULL != fGpu) { |
| 56 | return fGpu->getContext(); |
| 57 | } else { |
| 58 | return NULL; |
| 59 | } |
| 60 | } |