OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/test/fake_web_graphics_context_3d.h" | 5 #include "cc/fake_web_graphics_context_3d.h" |
6 | 6 |
7 #include <algorithm> | 7 #include "third_party/khronos/GLES2/gl2.h" |
8 #include <string> | |
9 | |
10 #include "base/logging.h" | |
11 #include "gpu/GLES2/gl2extchromium.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "third_party/khronos/GLES2/gl2ext.h" | |
14 | 8 |
15 using WebKit::WGC3Dboolean; | 9 using WebKit::WGC3Dboolean; |
16 using WebKit::WGC3Denum; | 10 using WebKit::WGC3Denum; |
17 using WebKit::WebGLId; | 11 using WebKit::WebGLId; |
18 using WebKit::WebGraphicsContext3D; | 12 using WebKit::WebGraphicsContext3D; |
19 | 13 |
20 namespace cc { | 14 namespace cc { |
21 | 15 |
22 static const WebGLId kBufferId = 1; | |
23 static const WebGLId kFramebufferId = 2; | |
24 static const WebGLId kProgramId = 3; | |
25 static const WebGLId kRenderbufferId = 4; | |
26 static const WebGLId kShaderId = 5; | |
27 | |
28 static unsigned s_context_id = 1; | |
29 | |
30 const WebGLId FakeWebGraphicsContext3D::kExternalTextureId = 1337; | |
31 | |
32 FakeWebGraphicsContext3D::FakeWebGraphicsContext3D() | 16 FakeWebGraphicsContext3D::FakeWebGraphicsContext3D() |
33 : context_id_(s_context_id++), | 17 : WebKit::WebGraphicsContext3D() { |
34 next_texture_id_(1), | |
35 have_extension_io_surface_(false), | |
36 have_extension_egl_image_(false), | |
37 times_make_current_succeeds_(-1), | |
38 times_bind_texture_succeeds_(-1), | |
39 times_end_query_succeeds_(-1), | |
40 context_lost_(false), | |
41 context_lost_callback_(NULL), | |
42 width_(0), | |
43 height_(0) { | |
44 } | |
45 | |
46 FakeWebGraphicsContext3D::FakeWebGraphicsContext3D( | |
47 const WebGraphicsContext3D::Attributes& attributes) | |
48 : context_id_(s_context_id++), | |
49 next_texture_id_(1), | |
50 attributes_(attributes), | |
51 have_extension_io_surface_(false), | |
52 have_extension_egl_image_(false), | |
53 times_make_current_succeeds_(-1), | |
54 times_bind_texture_succeeds_(-1), | |
55 times_end_query_succeeds_(-1), | |
56 context_lost_(false), | |
57 context_lost_callback_(NULL), | |
58 width_(0), | |
59 height_(0) { | |
60 } | 18 } |
61 | 19 |
62 FakeWebGraphicsContext3D::~FakeWebGraphicsContext3D() { | 20 FakeWebGraphicsContext3D::~FakeWebGraphicsContext3D() { |
63 } | 21 } |
64 | 22 |
65 bool FakeWebGraphicsContext3D::makeContextCurrent() { | 23 bool FakeWebGraphicsContext3D::makeContextCurrent() { |
66 if (times_make_current_succeeds_ >= 0) { | 24 return true; |
67 if (!times_make_current_succeeds_) { | |
68 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
69 GL_INNOCENT_CONTEXT_RESET_ARB); | |
70 } | |
71 --times_make_current_succeeds_; | |
72 } | |
73 return !context_lost_; | |
74 } | 25 } |
75 | 26 |
76 int FakeWebGraphicsContext3D::width() { | 27 int FakeWebGraphicsContext3D::width() { |
77 return width_; | 28 return 1; |
78 } | 29 } |
79 | 30 |
80 int FakeWebGraphicsContext3D::height() { | 31 int FakeWebGraphicsContext3D::height() { |
81 return height_; | 32 return 1; |
82 } | 33 } |
83 | 34 |
84 void FakeWebGraphicsContext3D::reshape(int width, int height) { | 35 void FakeWebGraphicsContext3D::reshape(int width, int height) { |
85 width_ = width; | |
86 height_ = height; | |
87 } | 36 } |
88 | 37 |
89 bool FakeWebGraphicsContext3D::isGLES2Compliant() { | 38 bool FakeWebGraphicsContext3D::isGLES2Compliant() { |
90 return false; | 39 return false; |
91 } | 40 } |
92 | 41 |
93 bool FakeWebGraphicsContext3D::readBackFramebuffer( | 42 bool FakeWebGraphicsContext3D::readBackFramebuffer( |
94 unsigned char* pixels, | 43 unsigned char* pixels, |
95 size_t bufferSize, | 44 size_t bufferSize, |
96 WebGLId framebuffer, | 45 WebGLId framebuffer, |
97 int width, | 46 int width, |
98 int height) { | 47 int height) { |
99 return false; | 48 return false; |
100 } | 49 } |
101 | 50 |
102 WebGLId FakeWebGraphicsContext3D::getPlatformTextureId() { | 51 WebGLId FakeWebGraphicsContext3D::getPlatformTextureId() { |
103 return 0; | 52 return 0; |
104 } | 53 } |
105 | 54 |
106 bool FakeWebGraphicsContext3D::isContextLost() { | 55 bool FakeWebGraphicsContext3D::isContextLost() { |
107 return context_lost_; | 56 return false; |
108 } | 57 } |
109 | 58 |
110 WGC3Denum FakeWebGraphicsContext3D::getGraphicsResetStatusARB() { | 59 WGC3Denum FakeWebGraphicsContext3D::getGraphicsResetStatusARB() { |
111 return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; | 60 return GL_NO_ERROR; |
112 } | 61 } |
113 | 62 |
114 void* FakeWebGraphicsContext3D::mapBufferSubDataCHROMIUM( | 63 void* FakeWebGraphicsContext3D::mapBufferSubDataCHROMIUM( |
115 WGC3Denum target, | 64 WGC3Denum target, |
116 WebKit::WGC3Dintptr offset, | 65 WebKit::WGC3Dintptr offset, |
117 WebKit::WGC3Dsizeiptr size, | 66 WebKit::WGC3Dsizeiptr size, |
118 WGC3Denum access) { | 67 WGC3Denum access) { |
119 return 0; | 68 return 0; |
120 } | 69 } |
121 | 70 |
122 void* FakeWebGraphicsContext3D::mapTexSubImage2DCHROMIUM( | 71 void* FakeWebGraphicsContext3D::mapTexSubImage2DCHROMIUM( |
123 WGC3Denum target, | 72 WGC3Denum target, |
124 WebKit::WGC3Dint level, | 73 WebKit::WGC3Dint level, |
125 WebKit::WGC3Dint xoffset, | 74 WebKit::WGC3Dint xoffset, |
126 WebKit::WGC3Dint yoffset, | 75 WebKit::WGC3Dint yoffset, |
127 WebKit::WGC3Dsizei width, | 76 WebKit::WGC3Dsizei width, |
128 WebKit::WGC3Dsizei height, | 77 WebKit::WGC3Dsizei height, |
129 WGC3Denum format, | 78 WGC3Denum format, |
130 WGC3Denum type, | 79 WGC3Denum type, |
131 WGC3Denum access) { | 80 WGC3Denum access) { |
132 return 0; | 81 return 0; |
133 } | 82 } |
134 | 83 |
135 WebKit::WebString FakeWebGraphicsContext3D::getRequestableExtensionsCHROMIUM() { | 84 WebKit::WebString FakeWebGraphicsContext3D::getRequestableExtensionsCHROMIUM() { |
136 return WebKit::WebString(); | 85 return WebKit::WebString(); |
137 } | 86 } |
138 | 87 |
139 WGC3Denum FakeWebGraphicsContext3D::checkFramebufferStatus( | 88 WGC3Denum FakeWebGraphicsContext3D::checkFramebufferStatus( |
140 WGC3Denum target) { | 89 WGC3Denum target) { |
141 if (context_lost_) | |
142 return GL_FRAMEBUFFER_UNDEFINED_OES; | |
143 return GL_FRAMEBUFFER_COMPLETE; | 90 return GL_FRAMEBUFFER_COMPLETE; |
144 } | 91 } |
145 | 92 |
146 bool FakeWebGraphicsContext3D::getActiveAttrib( | 93 bool FakeWebGraphicsContext3D::getActiveAttrib( |
147 WebGLId program, | 94 WebGLId program, |
148 WebKit::WGC3Duint index, | 95 WebKit::WGC3Duint index, |
149 ActiveInfo&) { | 96 ActiveInfo&) { |
150 return false; | 97 return false; |
151 } | 98 } |
152 | 99 |
153 bool FakeWebGraphicsContext3D::getActiveUniform( | 100 bool FakeWebGraphicsContext3D::getActiveUniform( |
154 WebGLId program, | 101 WebGLId program, |
155 WebKit::WGC3Duint index, | 102 WebKit::WGC3Duint index, |
156 ActiveInfo&) { | 103 ActiveInfo&) { |
157 return false; | 104 return false; |
158 } | 105 } |
159 | 106 |
160 WebKit::WGC3Dint FakeWebGraphicsContext3D::getAttribLocation( | 107 WebKit::WGC3Dint FakeWebGraphicsContext3D::getAttribLocation( |
161 WebGLId program, | 108 WebGLId program, |
162 const WebKit::WGC3Dchar* name) { | 109 const WebKit::WGC3Dchar* name) { |
163 return 0; | 110 return 0; |
164 } | 111 } |
165 | 112 |
166 WebGraphicsContext3D::Attributes | 113 WebGraphicsContext3D::Attributes |
167 FakeWebGraphicsContext3D::getContextAttributes() { | 114 FakeWebGraphicsContext3D::getContextAttributes() { |
168 return attributes_; | 115 return WebGraphicsContext3D::Attributes(); |
169 } | 116 } |
170 | 117 |
171 WGC3Denum FakeWebGraphicsContext3D::getError() { | 118 WGC3Denum FakeWebGraphicsContext3D::getError() { |
172 return 0; | 119 return 0; |
173 } | 120 } |
174 | 121 |
175 void FakeWebGraphicsContext3D::getIntegerv( | 122 void FakeWebGraphicsContext3D::getIntegerv( |
176 WGC3Denum pname, | 123 WGC3Denum pname, |
177 WebKit::WGC3Dint* value) { | 124 WebKit::WGC3Dint* value) { |
178 if (pname == GL_MAX_TEXTURE_SIZE) | 125 if (pname == GL_MAX_TEXTURE_SIZE) |
(...skipping 25 matching lines...) Expand all Loading... |
204 WebGLId shader) { | 151 WebGLId shader) { |
205 return WebKit::WebString(); | 152 return WebKit::WebString(); |
206 } | 153 } |
207 | 154 |
208 WebKit::WebString FakeWebGraphicsContext3D::getShaderSource( | 155 WebKit::WebString FakeWebGraphicsContext3D::getShaderSource( |
209 WebGLId shader) { | 156 WebGLId shader) { |
210 return WebKit::WebString(); | 157 return WebKit::WebString(); |
211 } | 158 } |
212 | 159 |
213 WebKit::WebString FakeWebGraphicsContext3D::getString(WGC3Denum name) { | 160 WebKit::WebString FakeWebGraphicsContext3D::getString(WGC3Denum name) { |
214 std::string string; | 161 return WebKit::WebString(); |
215 | |
216 if (name == GL_EXTENSIONS) { | |
217 if (have_extension_io_surface_) | |
218 string += "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle "; | |
219 if (have_extension_egl_image_) | |
220 string += "GL_OES_EGL_image_external"; | |
221 } | |
222 | |
223 return WebKit::WebString::fromUTF8(string.c_str()); | |
224 } | 162 } |
225 | 163 |
226 WebKit::WGC3Dint FakeWebGraphicsContext3D::getUniformLocation( | 164 WebKit::WGC3Dint FakeWebGraphicsContext3D::getUniformLocation( |
227 WebGLId program, | 165 WebGLId program, |
228 const WebKit::WGC3Dchar* name) { | 166 const WebKit::WGC3Dchar* name) { |
229 return 0; | 167 return 0; |
230 } | 168 } |
231 | 169 |
232 WebKit::WGC3Dsizeiptr FakeWebGraphicsContext3D::getVertexAttribOffset( | 170 WebKit::WGC3Dsizeiptr FakeWebGraphicsContext3D::getVertexAttribOffset( |
233 WebKit::WGC3Duint index, | 171 WebKit::WGC3Duint index, |
(...skipping 30 matching lines...) Expand all Loading... |
264 WebGLId shader) { | 202 WebGLId shader) { |
265 return false; | 203 return false; |
266 } | 204 } |
267 | 205 |
268 WGC3Dboolean FakeWebGraphicsContext3D::isTexture( | 206 WGC3Dboolean FakeWebGraphicsContext3D::isTexture( |
269 WebGLId texture) { | 207 WebGLId texture) { |
270 return false; | 208 return false; |
271 } | 209 } |
272 | 210 |
273 WebGLId FakeWebGraphicsContext3D::createBuffer() { | 211 WebGLId FakeWebGraphicsContext3D::createBuffer() { |
274 return kBufferId | context_id_ << 16; | 212 return 1; |
275 } | 213 } |
276 | 214 |
277 void FakeWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) { | 215 void FakeWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) { |
278 EXPECT_EQ(kBufferId | context_id_ << 16, id); | |
279 } | 216 } |
280 | 217 |
281 WebGLId FakeWebGraphicsContext3D::createFramebuffer() { | 218 WebGLId FakeWebGraphicsContext3D::createFramebuffer() { |
282 return kFramebufferId | context_id_ << 16; | 219 return 1; |
283 } | 220 } |
284 | 221 |
285 void FakeWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) { | 222 void FakeWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) { |
286 EXPECT_EQ(kFramebufferId | context_id_ << 16, id); | |
287 } | 223 } |
288 | 224 |
289 WebGLId FakeWebGraphicsContext3D::createProgram() { | 225 WebGLId FakeWebGraphicsContext3D::createProgram() { |
290 return kProgramId | context_id_ << 16; | 226 return 1; |
291 } | 227 } |
292 | 228 |
293 void FakeWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) { | 229 void FakeWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) { |
294 EXPECT_EQ(kProgramId | context_id_ << 16, id); | |
295 } | 230 } |
296 | 231 |
297 WebGLId FakeWebGraphicsContext3D::createRenderbuffer() { | 232 WebGLId FakeWebGraphicsContext3D::createRenderbuffer() { |
298 return kRenderbufferId | context_id_ << 16; | 233 return 1; |
299 } | 234 } |
300 | 235 |
301 void FakeWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) { | 236 void FakeWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) { |
302 EXPECT_EQ(kRenderbufferId | context_id_ << 16, id); | |
303 } | 237 } |
304 | 238 |
305 WebGLId FakeWebGraphicsContext3D::createShader(WGC3Denum) { | 239 WebGLId FakeWebGraphicsContext3D::createShader(WGC3Denum) { |
306 return kShaderId | context_id_ << 16; | 240 return 1; |
307 } | 241 } |
308 | 242 |
309 void FakeWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) { | 243 void FakeWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) { |
310 EXPECT_EQ(kShaderId | context_id_ << 16, id); | |
311 } | 244 } |
312 | 245 |
313 WebGLId FakeWebGraphicsContext3D::createTexture() { | 246 WebGLId FakeWebGraphicsContext3D::createTexture() { |
314 WebGLId texture_id = NextTextureId(); | 247 return 1; |
315 DCHECK_NE(texture_id, kExternalTextureId); | |
316 textures_.push_back(texture_id); | |
317 return texture_id; | |
318 } | 248 } |
319 | 249 |
320 void FakeWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { | 250 void FakeWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { |
321 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != | |
322 textures_.end()); | |
323 textures_.erase(std::find(textures_.begin(), textures_.end(), texture_id)); | |
324 } | 251 } |
325 | 252 |
326 void FakeWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { | 253 void FakeWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { |
327 EXPECT_EQ(kProgramId | context_id_ << 16, program); | |
328 EXPECT_EQ(kShaderId | context_id_ << 16, shader); | |
329 } | 254 } |
330 | 255 |
331 void FakeWebGraphicsContext3D::useProgram(WebGLId program) { | 256 void FakeWebGraphicsContext3D::useProgram(WebGLId program) { |
332 if (!program) | |
333 return; | |
334 EXPECT_EQ(kProgramId | context_id_ << 16, program); | |
335 } | 257 } |
336 | 258 |
337 void FakeWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) { | 259 void FakeWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) { |
338 if (!buffer) | |
339 return; | |
340 EXPECT_EQ(kBufferId | context_id_ << 16, buffer); | |
341 } | 260 } |
342 | 261 |
343 void FakeWebGraphicsContext3D::bindFramebuffer( | 262 void FakeWebGraphicsContext3D::bindFramebuffer( |
344 WGC3Denum target, WebGLId framebuffer) { | 263 WGC3Denum target, WebGLId framebuffer) { |
345 if (!framebuffer) | |
346 return; | |
347 EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); | |
348 } | 264 } |
349 | 265 |
350 void FakeWebGraphicsContext3D::bindRenderbuffer( | 266 void FakeWebGraphicsContext3D::bindRenderbuffer( |
351 WGC3Denum target, WebGLId renderbuffer) { | 267 WGC3Denum target, WebGLId renderbuffer) { |
352 if (!renderbuffer) | |
353 return; | |
354 EXPECT_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); | |
355 } | 268 } |
356 | 269 |
357 void FakeWebGraphicsContext3D::bindTexture( | 270 void FakeWebGraphicsContext3D::bindTexture( |
358 WGC3Denum target, WebGLId texture_id) { | 271 WGC3Denum target, WebGLId texture_id) { |
359 if (times_bind_texture_succeeds_ >= 0) { | |
360 if (!times_bind_texture_succeeds_) { | |
361 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
362 GL_INNOCENT_CONTEXT_RESET_ARB); | |
363 } | |
364 --times_bind_texture_succeeds_; | |
365 } | |
366 | |
367 if (!texture_id) | |
368 return; | |
369 if (texture_id == kExternalTextureId) | |
370 return; | |
371 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != | |
372 textures_.end()); | |
373 used_textures_.insert(texture_id); | |
374 } | 272 } |
375 | 273 |
376 WebGLId FakeWebGraphicsContext3D::createQueryEXT() { | 274 WebGLId FakeWebGraphicsContext3D::createQueryEXT() { |
377 return 1; | 275 return 1; |
378 } | 276 } |
379 | 277 |
380 WGC3Dboolean FakeWebGraphicsContext3D::isQueryEXT(WebGLId query) { | 278 WGC3Dboolean FakeWebGraphicsContext3D::isQueryEXT(WebGLId query) { |
381 return true; | 279 return true; |
382 } | 280 } |
383 | 281 |
384 void FakeWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) { | 282 void FakeWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) { |
385 if (times_end_query_succeeds_ >= 0) { | |
386 if (!times_end_query_succeeds_) { | |
387 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
388 GL_INNOCENT_CONTEXT_RESET_ARB); | |
389 } | |
390 --times_end_query_succeeds_; | |
391 } | |
392 } | 283 } |
393 | 284 |
394 void FakeWebGraphicsContext3D::getQueryObjectuivEXT( | 285 void FakeWebGraphicsContext3D::getQueryObjectuivEXT( |
395 WebKit::WebGLId query, | 286 WebKit::WebGLId query, |
396 WebKit::WGC3Denum pname, | 287 WebKit::WGC3Denum pname, |
397 WebKit::WGC3Duint* params) { | 288 WebKit::WGC3Duint* params) { |
398 // If the context is lost, behave as if result is available. | |
399 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) | |
400 *params = 1; | |
401 } | 289 } |
402 | 290 |
403 void FakeWebGraphicsContext3D::setContextLostCallback( | 291 void FakeWebGraphicsContext3D::setContextLostCallback( |
404 WebGraphicsContextLostCallback* callback) { | 292 WebGraphicsContextLostCallback* callback) { |
405 context_lost_callback_ = callback; | |
406 } | 293 } |
407 | 294 |
408 void FakeWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, | 295 void FakeWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, |
409 WGC3Denum other) { | 296 WGC3Denum other) { |
410 if (context_lost_) | |
411 return; | |
412 context_lost_ = true; | |
413 if (context_lost_callback_) | |
414 context_lost_callback_->onContextLost(); | |
415 } | |
416 | |
417 WebKit::WebGLId FakeWebGraphicsContext3D::NextTextureId() { | |
418 WebGLId texture_id = next_texture_id_++; | |
419 DCHECK(texture_id < (1 << 16)); | |
420 texture_id |= context_id_ << 16; | |
421 return texture_id; | |
422 } | 297 } |
423 | 298 |
424 } // namespace cc | 299 } // namespace cc |
OLD | NEW |