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

Side by Side Diff: cc/test/test_gles2_interface.h

Issue 93283002: Add GLES2Interface version of TWGC3D Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/test/test_gles2_interface.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_TEST_TEST_GLES2_INTERFACE_H_
6 #define CC_TEST_TEST_GLES2_INTERFACE_H_
7
8 #include <vector>
9
10 #include "base/compiler_specific.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/stl_util.h"
17 #include "base/synchronization/lock.h"
18 #include "cc/output/context_provider.h"
19 #include "cc/test/ordered_texture_map.h"
20 #include "cc/test/test_texture.h"
21 #include "gpu/command_buffer/client/gles2_interface_stub.h"
22 #include "third_party/khronos/GLES2/gl2.h"
23
24 namespace cc {
25 class TestContextSupport;
26
27 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
28 public:
29 static scoped_ptr<TestGLES2Interface> Create();
30
31 virtual ~TestGLES2Interface();
32
33 virtual bool makeContextCurrent();
34
35 virtual void reshapeWithScaleFactor(
36 int width, int height, float scale_factor);
37
38 virtual bool isContextLost();
39
40 GLuint CreateExternalTexture();
41
42 virtual void AttachShader(GLuint program, GLuint shader) OVERRIDE;
43 virtual void BindFramebuffer(
44 GLenum target, GLuint framebuffer) OVERRIDE;
45 virtual void BindRenderbuffer(
46 GLenum target, GLuint renderbuffer) OVERRIDE;
47 virtual void BindTexture(
48 GLenum target,
49 GLuint texture_id) OVERRIDE;
50
51 virtual GLenum CheckFramebufferStatus(GLenum target) OVERRIDE;
52
53 virtual const GLubyte* GetString(GLenum name) OVERRIDE;
54 virtual GLint GetUniformLocation(
55 GLuint program,
56 const GLchar* name) OVERRIDE;
57 virtual void GetVertexAttribPointerv(
58 GLuint index,
59 GLenum pname,
60 void** pointer) OVERRIDE;
61
62 virtual void UseProgram(GLuint program) OVERRIDE;
63
64 virtual void GenBuffers(GLsizei count, GLuint* ids) OVERRIDE;
65 virtual void GenFramebuffers(GLsizei count, GLuint* ids) OVERRIDE;
66 virtual void GenRenderbuffers(GLsizei count, GLuint* ids) OVERRIDE;
67 virtual void GenTextures(GLsizei count, GLuint* ids) OVERRIDE;
68
69 virtual void DeleteBuffers(GLsizei count, const GLuint* ids) OVERRIDE;
70 virtual void DeleteFramebuffers(
71 GLsizei count, const GLuint* ids) OVERRIDE;
72 virtual void DeleteRenderbuffers(
73 GLsizei count, const GLuint* ids) OVERRIDE;
74 virtual void DeleteTextures(GLsizei count, const GLuint* ids) OVERRIDE;
75
76 virtual GLuint CreateProgram() OVERRIDE;
77 virtual GLuint CreateShader(GLenum) OVERRIDE;
78
79 virtual void DeleteProgram(GLuint id) OVERRIDE;
80 virtual void DeleteShader(GLuint id) OVERRIDE;
81
82 virtual void EndQueryEXT(GLenum target) OVERRIDE;
83 virtual void GetQueryObjectuivEXT(
84 GLuint query,
85 GLenum pname,
86 GLuint* params) OVERRIDE;
87
88 virtual void GetIntegerv(
89 GLenum pname,
90 GLint* value) OVERRIDE;
91
92 virtual void GenMailboxCHROMIUM(GLbyte* mailbox) OVERRIDE;
93
94 virtual void LoseContextCHROMIUM(GLenum current,
95 GLenum other) OVERRIDE;
96
97 virtual void Finish() OVERRIDE;
98 virtual void Flush() OVERRIDE;
99
100 virtual void BindBuffer(GLenum target, GLuint buffer) OVERRIDE;
101 virtual void BufferData(GLenum target,
102 GLsizeiptr size,
103 const void* data,
104 GLenum usage) OVERRIDE;
105 virtual void* MapBufferCHROMIUM(GLenum target,
106 GLenum access) OVERRIDE;
107 virtual GLboolean UnmapBufferCHROMIUM(GLenum target) OVERRIDE;
108
109 virtual GLuint CreateImageCHROMIUM(
110 GLsizei width,
111 GLsizei height,
112 GLenum internalformat) OVERRIDE;
113 virtual void DestroyImageCHROMIUM(GLuint image_id) OVERRIDE;
114 virtual void GetImageParameterivCHROMIUM(
115 GLuint image_id,
116 GLenum pname,
117 GLint* params) OVERRIDE;
118 virtual void* MapImageCHROMIUM(
119 GLuint image_id,
120 GLenum access) OVERRIDE;
121 virtual void UnmapImageCHROMIUM(GLuint image_id) OVERRIDE;
122
123 const ContextProvider::Capabilities& test_capabilities() const {
124 return test_capabilities_;
125 }
126
127 // When set, MakeCurrent() will fail after this many times.
128 void set_times_make_current_succeeds(int times) {
129 times_make_current_succeeds_ = times;
130 }
131 void set_times_bind_texture_succeeds(int times) {
132 times_bind_texture_succeeds_ = times;
133 }
134 void set_times_end_query_succeeds(int times) {
135 times_end_query_succeeds_ = times;
136 }
137 void set_times_gen_mailbox_succeeds(int times) {
138 times_gen_mailbox_succeeds_ = times;
139 }
140
141 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after
142 // this many times.
143 void set_times_map_image_chromium_succeeds(int times) {
144 times_map_image_chromium_succeeds_ = times;
145 }
146 void set_times_map_buffer_chromium_succeeds(int times) {
147 times_map_buffer_chromium_succeeds_ = times;
148 }
149
150 size_t NumTextures() const;
151 GLuint TextureAt(int i) const;
152
153 size_t NumUsedTextures() const { return used_textures_.size(); }
154 bool UsedTexture(int texture) const {
155 return ContainsKey(used_textures_, texture);
156 }
157 void ResetUsedTextures() { used_textures_.clear(); }
158
159 void set_support_swapbuffers_complete_callback(bool support) {
160 test_capabilities_.swapbuffers_complete_callback = support;
161 }
162 void set_have_extension_io_surface(bool have) {
163 test_capabilities_.iosurface = have;
164 test_capabilities_.texture_rectangle = have;
165 }
166 void set_have_extension_egl_image(bool have) {
167 test_capabilities_.egl_image_external = have;
168 }
169 void set_have_post_sub_buffer(bool have) {
170 test_capabilities_.post_sub_buffer = have;
171 }
172 void set_have_discard_framebuffer(bool have) {
173 test_capabilities_.discard_framebuffer = have;
174 }
175 void set_support_compressed_texture_etc1(bool support) {
176 test_capabilities_.texture_format_etc1 = support;
177 }
178
179 // When this context is lost, all contexts in its share group are also lost.
180 void add_share_group_context(gpu::gles2::GLES2Interface* context3d) {
181 shared_contexts_.push_back(context3d);
182 }
183
184 void set_max_texture_size(int size) { max_texture_size_ = size; }
185
186 static const GLuint kExternalTextureId;
187 virtual GLuint NextTextureId();
188 virtual void RetireTextureId(GLuint id);
189
190 virtual GLuint NextBufferId();
191 virtual void RetireBufferId(GLuint id);
192
193 virtual GLuint NextImageId();
194 virtual void RetireImageId(GLuint id);
195
196 size_t GetTransferBufferMemoryUsedBytes() const;
197 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
198
199 void set_test_support(TestContextSupport* test_support) {
200 test_support_ = test_support;
201 }
202
203 protected:
204 struct TextureTargets {
205 TextureTargets();
206 ~TextureTargets();
207
208 void BindTexture(GLenum target, GLuint id);
209 void UnbindTexture(GLuint id);
210
211 GLuint BoundTexture(GLenum target);
212
213 private:
214 typedef base::hash_map<GLenum, GLuint> TargetTextureMap;
215 TargetTextureMap bound_textures_;
216 };
217
218 struct Buffer {
219 Buffer();
220 ~Buffer();
221
222 GLenum target;
223 scoped_ptr<uint8[]> pixels;
224 size_t size;
225
226 private:
227 DISALLOW_COPY_AND_ASSIGN(Buffer);
228 };
229
230 struct Image {
231 Image();
232 ~Image();
233
234 scoped_ptr<uint8[]> pixels;
235
236 private:
237 DISALLOW_COPY_AND_ASSIGN(Image);
238 };
239
240 struct Namespace : public base::RefCountedThreadSafe<Namespace> {
241 Namespace();
242
243 // Protects all fields.
244 base::Lock lock;
245 uint8 next_buffer_id;
246 uint8 next_image_id;
247 uint8 next_texture_id;
248 base::ScopedPtrHashMap<uint8, Buffer> buffers;
249 base::ScopedPtrHashMap<uint8, Image> images;
250 OrderedTextureMap textures;
251
252 private:
253 friend class base::RefCountedThreadSafe<Namespace>;
254 ~Namespace();
255 DISALLOW_COPY_AND_ASSIGN(Namespace);
256 };
257
258 TestGLES2Interface();
259
260 void CallAllSyncPointCallbacks();
261 void SwapBuffersComplete();
262 void CreateNamespace();
263 GLuint BoundTextureId(GLenum target);
264
265 uint8 context_id_;
266 ContextProvider::Capabilities test_capabilities_;
267 int times_make_current_succeeds_;
268 int times_bind_texture_succeeds_;
269 int times_end_query_succeeds_;
270 int times_gen_mailbox_succeeds_;
271 bool context_lost_;
272 int times_map_image_chromium_succeeds_;
273 int times_map_buffer_chromium_succeeds_;
274 base::hash_set<GLuint> used_textures_;
275 GLuint next_program_id_;
276 base::hash_set<GLuint> program_set_;
277 GLuint next_shader_id_;
278 base::hash_set<GLuint> shader_set_;
279 std::vector<gpu::gles2::GLES2Interface*> shared_contexts_;
280 int max_texture_size_;
281 int width_;
282 int height_;
283 TestContextSupport* test_support_;
284
285 uint8 bound_buffer_;
286 TextureTargets texture_targets_;
287
288 scoped_refptr<Namespace> namespace_;
289 static Namespace* shared_namespace_;
290
291 base::WeakPtrFactory<TestGLES2Interface> weak_ptr_factory_;
292 };
293
294 } // namespace cc
295
296 #endif // CC_TEST_TEST_GLES2_INTERFACE_H_
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/test/test_gles2_interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698