OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef GrProgramResource_DEFINED | |
9 #define GrProgramResource_DEFINED | |
10 | |
11 #include "SkRefCnt.h" | |
12 | |
13 class GrGpuResource; | |
14 | |
15 /** | |
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 | |
18 * a ref from their caller. This class is intended only for internal use in core
Gr code. | |
19 */ | |
20 class GrProgramResource : SkNoncopyable { | |
21 public: | |
22 SK_DECLARE_INST_COUNT_ROOT(GrProgramResource); | |
23 | |
24 enum IOType { | |
25 kRead_IOType, | |
26 kWrite_IOType, | |
27 kRW_IOType, | |
28 | |
29 kNone_IOType, // For internal use only, don't specify to constructor or
setResource(). | |
30 }; | |
31 | |
32 ~GrProgramResource(); | |
33 | |
34 GrGpuResource* getResource() const { return fResource; } | |
35 | |
36 /** Does this object own a pending read or write on the resource it is wrapp
ing. */ | |
37 bool ownsPendingIO() const { return fPendingIO; } | |
38 | |
39 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO | |
40 is called. */ | |
41 void reset(); | |
42 | |
43 protected: | |
44 GrProgramResource(); | |
45 | |
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. */ | |
48 GrProgramResource(GrGpuResource*, IOType); | |
49 | |
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. */ | |
52 void setResource(GrGpuResource*, IOType); | |
53 | |
54 private: | |
55 /** Called by owning GrProgramElement when the program element is first sche
duled for | |
56 execution. */ | |
57 void markPendingIO() const; | |
58 | |
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 | |
61 writes to the resource using the program element or draw state. */ | |
62 void removeRef() const; | |
63 | |
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 | |
66 pending executions have been complete. | |
67 */ | |
68 void pendingIOComplete() const; | |
69 | |
70 friend class GrRODrawState; | |
71 friend class GrProgramElement; | |
72 | |
73 GrGpuResource* fResource; | |
74 mutable bool fOwnRef; | |
75 mutable bool fPendingIO; | |
76 IOType fIOType; | |
77 | |
78 typedef SkNoncopyable INHERITED; | |
79 }; | |
80 | |
81 template <typename T> class GrProgramTResource : public GrProgramResource { | |
82 public: | |
83 GrProgramTResource() {} | |
84 | |
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. */ | |
87 GrProgramTResource(T* resource, IOType ioType) : GrProgramResource(resource,
ioType) {} | |
88 | |
89 T* get() const { return static_cast<T*>(this->getResource()); } | |
90 | |
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. */ | |
93 void set(T* resource, IOType ioType) { this->setResource(resource, ioType);
} | |
94 }; | |
95 | |
96 | |
97 #endif | |
OLD | NEW |