OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGpuResource_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
9 #define GrGpuResource_DEFINED | 9 #define GrGpuResource_DEFINED |
10 | 10 |
11 #include "GrResourceKey.h" | 11 #include "GrResourceKey.h" |
12 #include "GrTypesPriv.h" | 12 #include "GrTypesPriv.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkInstCnt.h" | 14 #include "SkInstCnt.h" |
15 #include "SkTInternalLList.h" | 15 #include "SkTInternalLList.h" |
16 | 16 |
17 class GrContext; | 17 class GrContext; |
18 class GrGpu; | 18 class GrGpu; |
19 class GrResourceCache2; | 19 class GrResourceCache2; |
20 | 20 |
21 /** | 21 /** |
22 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base | 22 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base |
23 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of | 23 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of |
24 * GrGpuResource. | 24 * GrGpuResource. |
25 * | 25 * |
26 * Gpu resources can have three types of refs: | 26 * Gpu resources can have three types of refs: |
27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls | 27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls |
28 * that read and write the resource via GrDrawTarget and by any object that
must own a | 28 * that read and write the resource via GrDrawTarget and by any object that
must own a |
29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. | 29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. |
30 * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext ha
s scheduled a read | 30 * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext ha
s scheduled a read |
31 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. | 31 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. |
32 * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext
has scheduled a | 32 * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext
has scheduled a |
33 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. | 33 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. |
34 * | 34 * |
35 * The latter two ref types are private and intended only for Gr core code. | 35 * The latter two ref types are private and intended only for Gr core code. |
36 * | 36 * |
37 * When an item is purgable DERIVED:notifyIsPurgable() will be called (static po
ly morphism using | 37 * When an item is purgable DERIVED:notifyIsPurgable() will be called (static po
ly morphism using |
38 * CRTP). GrIORef and GrGpuResource are separate classes for organizational reas
ons and to be | 38 * CRTP). GrIORef and GrGpuResource are separate classes for organizational reas
ons and to be |
39 * able to give access via friendship to only the functions related to pending I
O operations. | 39 * able to give access via friendship to only the functions related to pending I
O operations. |
40 */ | 40 */ |
41 template <typename DERIVED> class GrIORef : public SkNoncopyable { | 41 template <typename DERIVED> class GrIORef : public SkNoncopyable { |
42 public: | 42 public: |
43 SK_DECLARE_INST_COUNT_ROOT(GrIORef) | 43 SK_DECLARE_INST_COUNT(GrIORef) |
44 | 44 |
45 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with | 45 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with |
46 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of | 46 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of |
47 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are | 47 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are |
48 // not intended to cross thread boundaries. | 48 // not intended to cross thread boundaries. |
49 void ref() const { | 49 void ref() const { |
50 this->validate(); | 50 this->validate(); |
51 ++fRefCnt; | 51 ++fRefCnt; |
52 } | 52 } |
53 | 53 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 uint32_t fFlags; | 286 uint32_t fFlags; |
287 const uint32_t fUniqueID; | 287 const uint32_t fUniqueID; |
288 | 288 |
289 SkAutoTUnref<const SkData> fData; | 289 SkAutoTUnref<const SkData> fData; |
290 | 290 |
291 typedef GrIORef<GrGpuResource> INHERITED; | 291 typedef GrIORef<GrGpuResource> INHERITED; |
292 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. | 292 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. |
293 }; | 293 }; |
294 | 294 |
295 #endif | 295 #endif |
OLD | NEW |