cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / debug / test_web_graphics_context_3d.h
blob3dfc7ed272fc22c8c7490fea1ff101cbfe2e84cc
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.
5 #ifndef CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_
6 #define CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_
8 #include <vector>
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/base/cc_export.h"
19 #include "cc/debug/fake_web_graphics_context_3d.h"
20 #include "cc/output/context_provider.h"
21 #include "third_party/khronos/GLES2/gl2.h"
23 namespace cc {
25 class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
26 public:
27 static scoped_ptr<TestWebGraphicsContext3D> Create();
29 virtual ~TestWebGraphicsContext3D();
31 virtual bool makeContextCurrent();
33 virtual int width();
34 virtual int height();
36 virtual void reshapeWithScaleFactor(
37 int width, int height, float scale_factor);
39 virtual bool isContextLost();
40 virtual WebKit::WGC3Denum getGraphicsResetStatusARB();
42 virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
43 virtual void bindFramebuffer(
44 WebKit::WGC3Denum target, WebKit::WebGLId framebuffer);
45 virtual void bindRenderbuffer(
46 WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer);
47 virtual void bindTexture(
48 WebKit::WGC3Denum target,
49 WebKit::WebGLId texture_id);
51 virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target);
53 virtual Attributes getContextAttributes();
55 virtual WebKit::WebString getString(WebKit::WGC3Denum name);
56 virtual WebKit::WGC3Dint getUniformLocation(
57 WebKit::WebGLId program,
58 const WebKit::WGC3Dchar* name);
59 virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset(
60 WebKit::WGC3Duint index,
61 WebKit::WGC3Denum pname);
63 virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer);
64 virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap);
65 virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer);
66 virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program);
67 virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer);
68 virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader);
69 virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture);
71 virtual void useProgram(WebKit::WebGLId program);
73 virtual WebKit::WebGLId createBuffer();
74 virtual WebKit::WebGLId createFramebuffer();
75 virtual WebKit::WebGLId createProgram();
76 virtual WebKit::WebGLId createRenderbuffer();
77 virtual WebKit::WebGLId createShader(WebKit::WGC3Denum);
78 virtual WebKit::WebGLId createTexture();
80 virtual void deleteBuffer(WebKit::WebGLId id);
81 virtual void deleteFramebuffer(WebKit::WebGLId id);
82 virtual void deleteProgram(WebKit::WebGLId id);
83 virtual void deleteRenderbuffer(WebKit::WebGLId id);
84 virtual void deleteShader(WebKit::WebGLId id);
85 virtual void deleteTexture(WebKit::WebGLId texture_id);
87 virtual void endQueryEXT(WebKit::WGC3Denum target);
88 virtual void getQueryObjectuivEXT(
89 WebKit::WebGLId query,
90 WebKit::WGC3Denum pname,
91 WebKit::WGC3Duint* params);
93 virtual void getIntegerv(
94 WebKit::WGC3Denum pname,
95 WebKit::WGC3Dint* value);
97 virtual void genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox);
98 virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target,
99 const WebKit::WGC3Dbyte* mailbox) { }
100 virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target,
101 const WebKit::WGC3Dbyte* mailbox) { }
103 virtual void setContextLostCallback(
104 WebGraphicsContextLostCallback* callback);
106 virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
107 WebKit::WGC3Denum other);
109 // Takes ownership of the |callback|.
110 virtual void signalSyncPoint(unsigned sync_point,
111 WebGraphicsSyncPointCallback* callback);
112 virtual void signalQuery(WebKit::WebGLId query,
113 WebGraphicsSyncPointCallback* callback);
115 virtual void setSwapBuffersCompleteCallbackCHROMIUM(
116 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback);
118 virtual void prepareTexture();
119 virtual void finish();
120 virtual void flush();
122 virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer);
123 virtual void bufferData(WebKit::WGC3Denum target,
124 WebKit::WGC3Dsizeiptr size,
125 const void* data,
126 WebKit::WGC3Denum usage);
127 virtual void* mapBufferCHROMIUM(WebKit::WGC3Denum target,
128 WebKit::WGC3Denum access);
129 virtual WebKit::WGC3Dboolean unmapBufferCHROMIUM(WebKit::WGC3Denum target);
131 virtual WebKit::WGC3Duint createImageCHROMIUM(
132 WebKit::WGC3Dsizei width,
133 WebKit::WGC3Dsizei height,
134 WebKit::WGC3Denum internalformat);
135 virtual void destroyImageCHROMIUM(WebKit::WGC3Duint image_id);
136 virtual void getImageParameterivCHROMIUM(
137 WebKit::WGC3Duint image_id,
138 WebKit::WGC3Denum pname,
139 WebKit::WGC3Dint* params);
140 virtual void* mapImageCHROMIUM(
141 WebKit::WGC3Duint image_id,
142 WebKit::WGC3Denum access);
143 virtual void unmapImageCHROMIUM(WebKit::WGC3Duint image_id);
145 const ContextProvider::Capabilities& test_capabilities() const {
146 return test_capabilities_;
149 // When set, MakeCurrent() will fail after this many times.
150 void set_times_make_current_succeeds(int times) {
151 times_make_current_succeeds_ = times;
153 void set_times_bind_texture_succeeds(int times) {
154 times_bind_texture_succeeds_ = times;
156 void set_times_end_query_succeeds(int times) {
157 times_end_query_succeeds_ = times;
159 void set_times_gen_mailbox_succeeds(int times) {
160 times_gen_mailbox_succeeds_ = times;
163 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after
164 // this many times.
165 void set_times_map_image_chromium_succeeds(int times) {
166 times_map_image_chromium_succeeds_ = times;
168 void set_times_map_buffer_chromium_succeeds(int times) {
169 times_map_buffer_chromium_succeeds_ = times;
172 size_t NumTextures() const;
173 WebKit::WebGLId TextureAt(int i) const;
175 size_t NumUsedTextures() const { return used_textures_.size(); }
176 bool UsedTexture(int texture) const {
177 return ContainsKey(used_textures_, texture);
179 void ResetUsedTextures() { used_textures_.clear(); }
181 void set_support_swapbuffers_complete_callback(bool support) {
182 test_capabilities_.swapbuffers_complete_callback = support;
184 void set_have_extension_io_surface(bool have) {
185 test_capabilities_.iosurface = have;
187 void set_have_extension_egl_image(bool have) {
188 test_capabilities_.egl_image_external = have;
190 void set_have_post_sub_buffer(bool have) {
191 test_capabilities_.post_sub_buffer = have;
194 // When this context is lost, all contexts in its share group are also lost.
195 void add_share_group_context(WebKit::WebGraphicsContext3D* context3d) {
196 shared_contexts_.push_back(context3d);
199 void set_max_texture_size(int size) { max_texture_size_ = size; }
201 static const WebKit::WebGLId kExternalTextureId;
202 virtual WebKit::WebGLId NextTextureId();
204 virtual WebKit::WebGLId NextBufferId();
206 virtual WebKit::WebGLId NextImageId();
208 protected:
209 struct Buffer {
210 Buffer();
211 ~Buffer();
213 WebKit::WGC3Denum target;
214 scoped_ptr<uint8[]> pixels;
216 private:
217 DISALLOW_COPY_AND_ASSIGN(Buffer);
220 struct Image {
221 Image();
222 ~Image();
224 scoped_ptr<uint8[]> pixels;
226 private:
227 DISALLOW_COPY_AND_ASSIGN(Image);
230 struct Namespace : public base::RefCountedThreadSafe<Namespace> {
231 Namespace();
233 // Protects all fields.
234 base::Lock lock;
235 unsigned next_buffer_id;
236 unsigned next_image_id;
237 unsigned next_texture_id;
238 std::vector<WebKit::WebGLId> textures;
239 base::ScopedPtrHashMap<unsigned, Buffer> buffers;
240 base::ScopedPtrHashMap<unsigned, Image> images;
242 private:
243 friend class base::RefCountedThreadSafe<Namespace>;
244 ~Namespace();
245 DISALLOW_COPY_AND_ASSIGN(Namespace);
248 TestWebGraphicsContext3D();
249 TestWebGraphicsContext3D(
250 const WebKit::WebGraphicsContext3D::Attributes& attributes);
252 void CallAllSyncPointCallbacks();
253 void SwapBuffersComplete();
254 void CreateNamespace();
256 unsigned context_id_;
257 Attributes attributes_;
258 ContextProvider::Capabilities test_capabilities_;
259 int times_make_current_succeeds_;
260 int times_bind_texture_succeeds_;
261 int times_end_query_succeeds_;
262 int times_gen_mailbox_succeeds_;
263 bool context_lost_;
264 int times_map_image_chromium_succeeds_;
265 int times_map_buffer_chromium_succeeds_;
266 WebGraphicsContextLostCallback* context_lost_callback_;
267 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_;
268 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_;
269 base::hash_set<WebKit::WebGLId> used_textures_;
270 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
271 int max_texture_size_;
272 int width_;
273 int height_;
275 unsigned bound_buffer_;
277 scoped_refptr<Namespace> namespace_;
278 static Namespace* shared_namespace_;
280 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_;
283 } // namespace cc
285 #endif // CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_