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/debug/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 genMailboxCHROMIUM(WebKit::WGC3Dbyte
* mailbox
);
93 virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target
,
94 const WebKit::WGC3Dbyte
* mailbox
) { }
95 virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target
,
96 const WebKit::WGC3Dbyte
* mailbox
) { }
98 virtual void setContextLostCallback(
99 WebGraphicsContextLostCallback
* callback
);
101 virtual void loseContextCHROMIUM(WebKit::WGC3Denum current
,
102 WebKit::WGC3Denum other
);
104 // When set, MakeCurrent() will fail after this many times.
105 void set_times_make_current_succeeds(int times
) {
106 times_make_current_succeeds_
= times
;
108 void set_times_bind_texture_succeeds(int times
) {
109 times_bind_texture_succeeds_
= times
;
111 void set_times_end_query_succeeds(int times
) {
112 times_end_query_succeeds_
= times
;
115 size_t NumTextures() const { return textures_
.size(); }
116 WebKit::WebGLId
TextureAt(int i
) const { return textures_
[i
]; }
118 size_t NumUsedTextures() const { return used_textures_
.size(); }
119 bool UsedTexture(int texture
) const {
120 return ContainsKey(used_textures_
, texture
);
122 void ResetUsedTextures() { used_textures_
.clear(); }
124 void set_have_extension_io_surface(bool have
) {
125 have_extension_io_surface_
= have
;
127 void set_have_extension_egl_image(bool have
) {
128 have_extension_egl_image_
= have
;
131 // When this context is lost, all contexts in its share group are also lost.
132 void add_share_group_context(WebKit::WebGraphicsContext3D
* context3d
) {
133 shared_contexts_
.push_back(context3d
);
136 static const WebKit::WebGLId kExternalTextureId
;
137 virtual WebKit::WebGLId
NextTextureId();
140 TestWebGraphicsContext3D();
141 TestWebGraphicsContext3D(
142 const WebKit::WebGraphicsContext3D::Attributes
& attributes
);
144 unsigned context_id_
;
145 unsigned next_texture_id_
;
146 Attributes attributes_
;
147 bool have_extension_io_surface_
;
148 bool have_extension_egl_image_
;
149 int times_make_current_succeeds_
;
150 int times_bind_texture_succeeds_
;
151 int times_end_query_succeeds_
;
153 WebGraphicsContextLostCallback
* context_lost_callback_
;
154 std::vector
<WebKit::WebGLId
> textures_
;
155 base::hash_set
<WebKit::WebGLId
> used_textures_
;
156 std::vector
<WebKit::WebGraphicsContext3D
*> shared_contexts_
;
163 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_