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

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

Issue 695813003: Add class GrGLTextureRenderTarget for GL texture/rendertarget objects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: forgot to save file Created 6 years, 1 month 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
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 GrGpuResourceRef_DEFINED 8 #ifndef GrGpuResourceRef_DEFINED
9 #define GrGpuResourceRef_DEFINED 9 #define GrGpuResourceRef_DEFINED
10 10
11 #include "GrGpuResource.h" 11 #include "GrGpuResource.h"
12 #include "GrRenderTarget.h"
13 #include "GrTexture.h"
12 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
13 15
14 /** 16 /**
15 * This class is intended only for internal use in core Gr code. 17 * This class is intended only for internal use in core Gr code.
16 * 18 *
17 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages 19 * Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages
18 * converting refs to pending IO operations. It allows a resource ownership to b e in three 20 * converting refs to pending IO operations. It allows a resource ownership to b e in three
19 * states: 21 * states:
20 * 1. Owns a single ref 22 * 1. Owns a single ref
21 * 2. Owns a single ref and a pending IO operation (read, write, or rea d-write) 23 * 2. Owns a single ref and a pending IO operation (read, write, or rea d-write)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 91
90 /** 92 /**
91 * Templated version of GrGpuResourceRef to enforce type safety. 93 * Templated version of GrGpuResourceRef to enforce type safety.
92 */ 94 */
93 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { 95 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef {
94 public: 96 public:
95 GrTGpuResourceRef() {} 97 GrTGpuResourceRef() {}
96 98
97 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 99 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
98 pending on the resource when markPendingIO is called. */ 100 pending on the resource when markPendingIO is called. */
99 GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType ) {} 101 GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType ) { }
100 102
101 T* get() const { return static_cast<T*>(this->getResource()); } 103 T* get() const { return static_cast<T*>(this->getResource()); }
102 104
103 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as 105 /** Adopts a ref from the caller. ioType expresses what type of IO operation s will be marked as
104 pending on the resource when markPendingIO is called. */ 106 pending on the resource when markPendingIO is called. */
105 void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType) ; } 107 void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType) ; }
106 108
107 private: 109 private:
108 typedef GrGpuResourceRef INHERITED; 110 typedef GrGpuResourceRef INHERITED;
109 }; 111 };
110 112
113 // Specializations for GrTexture and GrRenderTarget because they use virtual inh eritance.
114 template<> class GrTGpuResourceRef<GrTexture> : public GrGpuResourceRef {
115 public:
116 GrTGpuResourceRef() {}
117
118 GrTGpuResourceRef(GrTexture* texture, GrIOType ioType) : INHERITED(texture, ioType) { }
119
120 GrTexture* get() const {
121 GrSurface* surface = static_cast<GrSurface*>(this->getResource());
122 if (surface) {
123 return surface->asTexture();
124 } else {
125 return NULL;
126 }
127 }
128
129 void set(GrTexture* texture, GrIOType ioType) { this->setResource(texture, i oType); }
130
131 private:
132 typedef GrGpuResourceRef INHERITED;
133 };
134
135 template<> class GrTGpuResourceRef<GrRenderTarget> : public GrGpuResourceRef {
136 public:
137 GrTGpuResourceRef() {}
138
139 GrTGpuResourceRef(GrRenderTarget* rt, GrIOType ioType) : INHERITED(rt, ioTyp e) { }
140
141 GrRenderTarget* get() const {
142 GrSurface* surface = static_cast<GrSurface*>(this->getResource());
143 if (surface) {
144 return surface->asRenderTarget();
145 } else {
146 return NULL;
147 }
148 }
149
150 void set(GrRenderTarget* rt, GrIOType ioType) { this->setResource(rt, ioType ); }
151
152 private:
153 typedef GrGpuResourceRef INHERITED;
154 };
155
111 /** 156 /**
112 * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a 157 * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a
113 * ref. 158 * ref.
114 */ 159 */
115 template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyabl e { 160 template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyabl e {
116 public: 161 public:
117 GrPendingIOResource(T* resource) : fResource(resource) { 162 GrPendingIOResource(T* resource) : fResource(resource) {
118 if (NULL != fResource) { 163 if (NULL != fResource) {
119 switch (IO_TYPE) { 164 switch (IO_TYPE) {
120 case kRead_GrIOType: 165 case kRead_GrIOType:
(...skipping 26 matching lines...) Expand all
147 } 192 }
148 } 193 }
149 } 194 }
150 195
151 T* get() const { return fResource; } 196 T* get() const { return fResource; }
152 197
153 private: 198 private:
154 T* fResource; 199 T* fResource;
155 }; 200 };
156 #endif 201 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698