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 GrProgramResource_DEFINED | 8 #ifndef GrGpuResourceRef_DEFINED |
9 #define GrProgramResource_DEFINED | 9 #define GrGpuResourceRef_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 | 12 |
13 class GrGpuResource; | 13 class GrGpuResource; |
14 | 14 |
15 /** | 15 /** |
16 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState.
It manages | 16 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState.
It manages |
17 * converting refs to pending io operations. Like SkAutoTUnref, its constructor
and setter adopt | 17 * converting refs to pending io operations. Like SkAutoTUnref, its constructor
and setter adopt |
18 * a ref from their caller. This class is intended only for internal use in core
Gr code. | 18 * a ref from their caller. This class is intended only for internal use in core
Gr code. |
19 */ | 19 */ |
20 class GrProgramResource : SkNoncopyable { | 20 class GrGpuResourceRef : SkNoncopyable { |
21 public: | 21 public: |
22 SK_DECLARE_INST_COUNT_ROOT(GrProgramResource); | 22 SK_DECLARE_INST_COUNT_ROOT(GrGpuResourceRef); |
23 | 23 |
24 enum IOType { | 24 enum IOType { |
25 kRead_IOType, | 25 kRead_IOType, |
26 kWrite_IOType, | 26 kWrite_IOType, |
27 kRW_IOType, | 27 kRW_IOType, |
28 | 28 |
29 kNone_IOType, // For internal use only, don't specify to constructor or
setResource(). | 29 kNone_IOType, // For internal use only, don't specify to constructor or
setResource(). |
30 }; | 30 }; |
31 | 31 |
32 ~GrProgramResource(); | 32 ~GrGpuResourceRef(); |
33 | 33 |
34 GrGpuResource* getResource() const { return fResource; } | 34 GrGpuResource* getResource() const { return fResource; } |
35 | 35 |
36 /** Does this object own a pending read or write on the resource it is wrapp
ing. */ | 36 /** Does this object own a pending read or write on the resource it is wrapp
ing. */ |
37 bool ownsPendingIO() const { return fPendingIO; } | 37 bool ownsPendingIO() const { return fPendingIO; } |
38 | 38 |
39 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO | 39 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO |
40 is called. */ | 40 is called. */ |
41 void reset(); | 41 void reset(); |
42 | 42 |
43 protected: | 43 protected: |
44 GrProgramResource(); | 44 GrGpuResourceRef(); |
45 | 45 |
46 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 46 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
47 pending on the resource when markPendingIO is called. */ | 47 pending on the resource when markPendingIO is called. */ |
48 GrProgramResource(GrGpuResource*, IOType); | 48 GrGpuResourceRef(GrGpuResource*, IOType); |
49 | 49 |
50 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 50 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
51 pending on the resource when markPendingIO is called. */ | 51 pending on the resource when markPendingIO is called. */ |
52 void setResource(GrGpuResource*, IOType); | 52 void setResource(GrGpuResource*, IOType); |
53 | 53 |
54 private: | 54 private: |
55 /** Called by owning GrProgramElement when the program element is first sche
duled for | 55 /** Called by owning GrProgramElement when the program element is first sche
duled for |
56 execution. */ | 56 execution. */ |
57 void markPendingIO() const; | 57 void markPendingIO() const; |
58 | 58 |
59 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. | 59 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. |
60 This lets the cache know that the drawing code will no longer schedule a
dditional reads or | 60 This lets the cache know that the drawing code will no longer schedule a
dditional reads or |
61 writes to the resource using the program element or draw state. */ | 61 writes to the resource using the program element or draw state. */ |
62 void removeRef() const; | 62 void removeRef() const; |
63 | 63 |
64 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object | 64 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object |
65 still has refs, so it is not about to destroy this GrProgramResource, bu
t its previously | 65 still has refs, so it is not about to destroy this GrGpuResourceRef, but
its previously |
66 pending executions have been complete. | 66 pending executions have been complete. |
67 */ | 67 */ |
68 void pendingIOComplete() const; | 68 void pendingIOComplete() const; |
69 | 69 |
70 friend class GrRODrawState; | 70 friend class GrRODrawState; |
71 friend class GrProgramElement; | 71 friend class GrProgramElement; |
72 | 72 |
73 GrGpuResource* fResource; | 73 GrGpuResource* fResource; |
74 mutable bool fOwnRef; | 74 mutable bool fOwnRef; |
75 mutable bool fPendingIO; | 75 mutable bool fPendingIO; |
76 IOType fIOType; | 76 IOType fIOType; |
77 | 77 |
78 typedef SkNoncopyable INHERITED; | 78 typedef SkNoncopyable INHERITED; |
79 }; | 79 }; |
80 | 80 |
81 template <typename T> class GrProgramTResource : public GrProgramResource { | 81 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { |
82 public: | 82 public: |
83 GrProgramTResource() {} | 83 GrTGpuResourceRef() {} |
84 | 84 |
85 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 85 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
86 pending on the resource when markPendingIO is called. */ | 86 pending on the resource when markPendingIO is called. */ |
87 GrProgramTResource(T* resource, IOType ioType) : GrProgramResource(resource,
ioType) {} | 87 GrTGpuResourceRef(T* resource, IOType ioType) : INHERITED(resource, ioType)
{} |
88 | 88 |
89 T* get() const { return static_cast<T*>(this->getResource()); } | 89 T* get() const { return static_cast<T*>(this->getResource()); } |
90 | 90 |
91 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 91 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
92 pending on the resource when markPendingIO is called. */ | 92 pending on the resource when markPendingIO is called. */ |
93 void set(T* resource, IOType ioType) { this->setResource(resource, ioType);
} | 93 void set(T* resource, IOType ioType) { this->setResource(resource, ioType);
} |
| 94 |
| 95 private: |
| 96 typedef GrGpuResourceRef INHERITED; |
94 }; | 97 }; |
95 | 98 |
96 | 99 |
97 #endif | 100 #endif |
OLD | NEW |