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