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 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 10 | #include "GrResource.h" |
| 11 | #include "GrGpu.h" |
| 12 | |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 13 | SK_DEFINE_INST_COUNT(GrResource) |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 15 | GrResource::GrResource(GrGpu* gpu, bool isWrapped) { |
bsalomon@google.com | 838f6e1 | 2013-01-23 21:37:01 +0000 | [diff] [blame] | 16 | fGpu = gpu; |
| 17 | fCacheEntry = NULL; |
| 18 | fDeferredRefCount = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 19 | if (isWrapped) { |
| 20 | fFlags = kWrapped_Flag; |
| 21 | } else { |
| 22 | fFlags = 0; |
| 23 | } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 24 | fGpu->insertResource(this); |
| 25 | } |
| 26 | |
bsalomon@google.com | 76b7fcc | 2012-04-27 17:24:09 +0000 | [diff] [blame] | 27 | GrResource::~GrResource() { |
| 28 | // subclass should have released this. |
bsalomon@google.com | 838f6e1 | 2013-01-23 21:37:01 +0000 | [diff] [blame] | 29 | GrAssert(0 == fDeferredRefCount); |
bsalomon@google.com | 76b7fcc | 2012-04-27 17:24:09 +0000 | [diff] [blame] | 30 | GrAssert(!this->isValid()); |
| 31 | } |
| 32 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 33 | void GrResource::release() { |
| 34 | if (NULL != fGpu) { |
| 35 | this->onRelease(); |
| 36 | fGpu->removeResource(this); |
| 37 | fGpu = NULL; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void GrResource::abandon() { |
| 42 | if (NULL != fGpu) { |
| 43 | this->onAbandon(); |
| 44 | fGpu->removeResource(this); |
| 45 | fGpu = NULL; |
| 46 | } |
| 47 | } |
bsalomon@google.com | f7b5c1e | 2011-11-15 19:42:07 +0000 | [diff] [blame] | 48 | |
| 49 | const GrContext* GrResource::getContext() const { |
| 50 | if (NULL != fGpu) { |
| 51 | return fGpu->getContext(); |
| 52 | } else { |
| 53 | return NULL; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | GrContext* GrResource::getContext() { |
| 58 | if (NULL != fGpu) { |
| 59 | return fGpu->getContext(); |
| 60 | } else { |
| 61 | return NULL; |
| 62 | } |
| 63 | } |