Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / test / test_web_graphics_context_3d.h
blobc7a92a5fc06bd970caa2b5e37b0c66a59cfa8940
1 // Copyright 2011 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.
5 #ifndef CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_
6 #define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/hash_tables.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/stl_util.h"
14 #include "cc/debug/fake_web_graphics_context_3d.h"
15 #include "third_party/khronos/GLES2/gl2.h"
17 namespace cc {
19 class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
20 public:
21 static scoped_ptr<TestWebGraphicsContext3D> Create() {
22 return make_scoped_ptr(new TestWebGraphicsContext3D());
24 static scoped_ptr<TestWebGraphicsContext3D> Create(
25 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
26 return make_scoped_ptr(new TestWebGraphicsContext3D(attributes));
28 virtual ~TestWebGraphicsContext3D();
30 virtual bool makeContextCurrent();
32 virtual int width();
33 virtual int height();
35 virtual void reshape(int width, int height);
37 virtual bool isContextLost();
38 virtual WebKit::WGC3Denum getGraphicsResetStatusARB();
40 virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
41 virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer);
42 virtual void bindFramebuffer(
43 WebKit::WGC3Denum target, WebKit::WebGLId framebuffer);
44 virtual void bindRenderbuffer(
45 WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer);
46 virtual void bindTexture(
47 WebKit::WGC3Denum target,
48 WebKit::WebGLId texture_id);
50 virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target);
52 virtual Attributes getContextAttributes();
54 virtual WebKit::WebString getString(WebKit::WGC3Denum name);
55 virtual WebKit::WGC3Dint getUniformLocation(
56 WebKit::WebGLId program,
57 const WebKit::WGC3Dchar* name);
58 virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset(
59 WebKit::WGC3Duint index,
60 WebKit::WGC3Denum pname);
62 virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer);
63 virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap);
64 virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer);
65 virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program);
66 virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer);
67 virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader);
68 virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture);
70 virtual void useProgram(WebKit::WebGLId program);
72 virtual WebKit::WebGLId createBuffer();
73 virtual WebKit::WebGLId createFramebuffer();
74 virtual WebKit::WebGLId createProgram();
75 virtual WebKit::WebGLId createRenderbuffer();
76 virtual WebKit::WebGLId createShader(WebKit::WGC3Denum);
77 virtual WebKit::WebGLId createTexture();
79 virtual void deleteBuffer(WebKit::WebGLId id);
80 virtual void deleteFramebuffer(WebKit::WebGLId id);
81 virtual void deleteProgram(WebKit::WebGLId id);
82 virtual void deleteRenderbuffer(WebKit::WebGLId id);
83 virtual void deleteShader(WebKit::WebGLId id);
84 virtual void deleteTexture(WebKit::WebGLId texture_id);
86 virtual void endQueryEXT(WebKit::WGC3Denum target);
87 virtual void getQueryObjectuivEXT(
88 WebKit::WebGLId query,
89 WebKit::WGC3Denum pname,
90 WebKit::WGC3Duint* params);
92 virtual void getIntegerv(
93 WebKit::WGC3Denum pname,
94 WebKit::WGC3Dint* value);
96 virtual void genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox);
97 virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target,
98 const WebKit::WGC3Dbyte* mailbox) { }
99 virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target,
100 const WebKit::WGC3Dbyte* mailbox) { }
102 virtual void setContextLostCallback(
103 WebGraphicsContextLostCallback* callback);
105 virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
106 WebKit::WGC3Denum other);
108 // When set, MakeCurrent() will fail after this many times.
109 void set_times_make_current_succeeds(int times) {
110 times_make_current_succeeds_ = times;
112 void set_times_bind_texture_succeeds(int times) {
113 times_bind_texture_succeeds_ = times;
115 void set_times_end_query_succeeds(int times) {
116 times_end_query_succeeds_ = times;
119 size_t NumTextures() const { return textures_.size(); }
120 WebKit::WebGLId TextureAt(int i) const { return textures_[i]; }
122 size_t NumUsedTextures() const { return used_textures_.size(); }
123 bool UsedTexture(int texture) const {
124 return ContainsKey(used_textures_, texture);
126 void ResetUsedTextures() { used_textures_.clear(); }
128 void set_have_extension_io_surface(bool have) {
129 have_extension_io_surface_ = have;
131 void set_have_extension_egl_image(bool have) {
132 have_extension_egl_image_ = have;
135 // When this context is lost, all contexts in its share group are also lost.
136 void add_share_group_context(WebKit::WebGraphicsContext3D* context3d) {
137 shared_contexts_.push_back(context3d);
140 void set_max_texture_size(int size) { max_texture_size_ = size; }
142 static const WebKit::WebGLId kExternalTextureId;
143 virtual WebKit::WebGLId NextTextureId();
145 protected:
146 TestWebGraphicsContext3D();
147 TestWebGraphicsContext3D(
148 const WebKit::WebGraphicsContext3D::Attributes& attributes);
150 unsigned context_id_;
151 unsigned next_texture_id_;
152 Attributes attributes_;
153 bool have_extension_io_surface_;
154 bool have_extension_egl_image_;
155 int times_make_current_succeeds_;
156 int times_bind_texture_succeeds_;
157 int times_end_query_succeeds_;
158 bool context_lost_;
159 WebGraphicsContextLostCallback* context_lost_callback_;
160 std::vector<WebKit::WebGLId> textures_;
161 base::hash_set<WebKit::WebGLId> used_textures_;
162 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
163 int max_texture_size_;
164 int width_;
165 int height_;
168 } // namespace cc
170 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_