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 | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 15 | GrResource::GrResource(GrGpu* gpu) { |
| 16 | fGpu = gpu; |
| 17 | fNext = NULL; |
| 18 | fPrevious = NULL; |
| 19 | fGpu->insertResource(this); |
| 20 | } |
| 21 | |
bsalomon@google.com | 76b7fcc | 2012-04-27 17:24:09 +0000 | [diff] [blame] | 22 | GrResource::~GrResource() { |
| 23 | // subclass should have released this. |
| 24 | GrAssert(!this->isValid()); |
| 25 | } |
| 26 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 27 | void GrResource::release() { |
| 28 | if (NULL != fGpu) { |
| 29 | this->onRelease(); |
| 30 | fGpu->removeResource(this); |
| 31 | fGpu = NULL; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void GrResource::abandon() { |
| 36 | if (NULL != fGpu) { |
| 37 | this->onAbandon(); |
| 38 | fGpu->removeResource(this); |
| 39 | fGpu = NULL; |
| 40 | } |
| 41 | } |
bsalomon@google.com | f7b5c1e | 2011-11-15 19:42:07 +0000 | [diff] [blame] | 42 | |
| 43 | const GrContext* GrResource::getContext() const { |
| 44 | if (NULL != fGpu) { |
| 45 | return fGpu->getContext(); |
| 46 | } else { |
| 47 | return NULL; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | GrContext* GrResource::getContext() { |
| 52 | if (NULL != fGpu) { |
| 53 | return fGpu->getContext(); |
| 54 | } else { |
| 55 | return NULL; |
| 56 | } |
| 57 | } |
| 58 | |