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