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_
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/fake_web_graphics_context_3d.h"
15 #include "third_party/khronos/GLES2/gl2.h"
19 class TestWebGraphicsContext3D
: public FakeWebGraphicsContext3D
{
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();
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 setContextLostCallback(
93 WebGraphicsContextLostCallback
* callback
);
95 virtual void loseContextCHROMIUM(WebKit::WGC3Denum current
,
96 WebKit::WGC3Denum other
);
98 // When set, MakeCurrent() will fail after this many times.
99 void set_times_make_current_succeeds(int times
) {
100 times_make_current_succeeds_
= times
;
102 void set_times_bind_texture_succeeds(int times
) {
103 times_bind_texture_succeeds_
= times
;
105 void set_times_end_query_succeeds(int times
) {
106 times_end_query_succeeds_
= times
;
109 size_t NumTextures() const { return textures_
.size(); }
110 WebKit::WebGLId
TextureAt(int i
) const { return textures_
[i
]; }
112 size_t NumUsedTextures() const { return used_textures_
.size(); }
113 bool UsedTexture(int texture
) const {
114 return ContainsKey(used_textures_
, texture
);
116 void ResetUsedTextures() { used_textures_
.clear(); }
118 void set_have_extension_io_surface(bool have
) {
119 have_extension_io_surface_
= have
;
121 void set_have_extension_egl_image(bool have
) {
122 have_extension_egl_image_
= have
;
125 // When this context is lost, all contexts in its share group are also lost.
126 void add_share_group_context(WebKit::WebGraphicsContext3D
* context3d
) {
127 shared_contexts_
.push_back(context3d
);
130 static const WebKit::WebGLId kExternalTextureId
;
131 virtual WebKit::WebGLId
NextTextureId();
134 TestWebGraphicsContext3D();
135 TestWebGraphicsContext3D(
136 const WebKit::WebGraphicsContext3D::Attributes
& attributes
);
138 unsigned context_id_
;
139 unsigned next_texture_id_
;
140 Attributes attributes_
;
141 bool have_extension_io_surface_
;
142 bool have_extension_egl_image_
;
143 int times_make_current_succeeds_
;
144 int times_bind_texture_succeeds_
;
145 int times_end_query_succeeds_
;
147 WebGraphicsContextLostCallback
* context_lost_callback_
;
148 std::vector
<WebKit::WebGLId
> textures_
;
149 base::hash_set
<WebKit::WebGLId
> used_textures_
;
150 std::vector
<WebKit::WebGraphicsContext3D
*> shared_contexts_
;
157 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_