Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: include/gpu/GrProgramResource.h

Issue 563963004: Make templated GrProgramTResource subclass of GrProgramResource (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/gpu/GrTextureAccess.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GrProgramResource_DEFINED
9 #define GrProgramResource_DEFINED 9 #define GrProgramResource_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 GrProgramResource : SkNoncopyable {
21 public: 21 public:
22 SK_DECLARE_INST_COUNT_ROOT(GrProgramResource);
23
22 enum IOType { 24 enum IOType {
23 kRead_IOType, 25 kRead_IOType,
24 kWrite_IOType, 26 kWrite_IOType,
25 kRW_IOType, 27 kRW_IOType,
26 28
27 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().
28 }; 30 };
29 31
30 SK_DECLARE_INST_COUNT_ROOT(GrProgramResource);
31 GrProgramResource();
32
33 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
34 pending on the resource when markPendingIO is called. */
35 explicit GrProgramResource(GrGpuResource*, IOType ioType);
36
37 ~GrProgramResource(); 32 ~GrProgramResource();
38 33
39 GrGpuResource* getResource() const { return fResource; } 34 GrGpuResource* getResource() const { return fResource; }
40 35
41 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
42 pending on the resource when markPendingIO is called. */
43 void setResource(GrGpuResource*, IOType ioType);
44
45 /** 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. */
46 bool ownsPendingIO() const { return fPendingIO; } 37 bool ownsPendingIO() const { return fPendingIO; }
47 38
48 /** 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
49 is called. */ 40 is called. */
50 void reset(); 41 void reset();
51 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
52 private: 54 private:
53 /** 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
54 execution. */ 56 execution. */
55 void markPendingIO() const; 57 void markPendingIO() const;
56 58
57 /** 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.
58 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
59 writes to the resource using the program element or draw state. */ 61 writes to the resource using the program element or draw state. */
60 void removeRef() const; 62 void removeRef() const;
61 63
62 /** 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
63 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 GrProgramResource, bu t its previously
64 pending executions have been complete. 66 pending executions have been complete.
65 */ 67 */
66 void pendingIOComplete() const; 68 void pendingIOComplete() const;
67 69
68 friend class GrRODrawState; 70 friend class GrRODrawState;
69 friend class GrProgramElement; 71 friend class GrProgramElement;
70 72
71 GrGpuResource* fResource; 73 GrGpuResource* fResource;
72 mutable bool fOwnRef; 74 mutable bool fOwnRef;
73 mutable bool fPendingIO; 75 mutable bool fPendingIO;
74 IOType fIOType; 76 IOType fIOType;
75 77
76 typedef SkNoncopyable INHERITED; 78 typedef SkNoncopyable INHERITED;
77 }; 79 };
78 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
79 #endif 97 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrTextureAccess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698