|
1 |
|
2 /* |
|
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. |
|
7 */ |
|
8 |
|
9 |
|
10 #include "GrResource.h" |
|
11 #include "GrGpu.h" |
|
12 |
|
13 GrResource::GrResource(GrGpu* gpu, bool isWrapped) { |
|
14 fGpu = gpu; |
|
15 fCacheEntry = NULL; |
|
16 fDeferredRefCount = 0; |
|
17 if (isWrapped) { |
|
18 fFlags = kWrapped_FlagBit; |
|
19 } else { |
|
20 fFlags = 0; |
|
21 } |
|
22 fGpu->insertResource(this); |
|
23 } |
|
24 |
|
25 GrResource::~GrResource() { |
|
26 // subclass should have released this. |
|
27 SkASSERT(0 == fDeferredRefCount); |
|
28 SkASSERT(!this->isValid()); |
|
29 } |
|
30 |
|
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 } |
|
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 } |