OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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/test_web_graphics_context_3d.h" | 5 #include "cc/test/test_web_graphics_context_3d.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/bind.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" |
11 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/khronos/GLES2/gl2ext.h" | 15 #include "third_party/khronos/GLES2/gl2ext.h" |
14 | 16 |
15 using WebKit::WGC3Dboolean; | 17 using WebKit::WGC3Dboolean; |
16 using WebKit::WGC3Dchar; | 18 using WebKit::WGC3Dchar; |
17 using WebKit::WGC3Denum; | 19 using WebKit::WGC3Denum; |
18 using WebKit::WGC3Dint; | 20 using WebKit::WGC3Dint; |
19 using WebKit::WGC3Dsizei; | 21 using WebKit::WGC3Dsizei; |
20 using WebKit::WGC3Dsizeiptr; | 22 using WebKit::WGC3Dsizeiptr; |
21 using WebKit::WGC3Duint; | 23 using WebKit::WGC3Duint; |
22 using WebKit::WebGLId; | 24 using WebKit::WebGLId; |
23 using WebKit::WebGraphicsContext3D; | 25 using WebKit::WebGraphicsContext3D; |
24 | 26 |
25 namespace cc { | 27 namespace cc { |
26 | 28 |
27 static const WebGLId kBufferId = 1; | 29 static const WebGLId kFramebufferId = 1; |
28 static const WebGLId kFramebufferId = 2; | 30 static const WebGLId kProgramId = 2; |
29 static const WebGLId kProgramId = 3; | 31 static const WebGLId kRenderbufferId = 3; |
30 static const WebGLId kRenderbufferId = 4; | 32 static const WebGLId kShaderId = 4; |
31 static const WebGLId kShaderId = 5; | |
32 | 33 |
33 static unsigned s_context_id = 1; | 34 static unsigned s_context_id = 1; |
34 | 35 |
35 const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; | 36 const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; |
36 | 37 |
37 TestWebGraphicsContext3D::TestWebGraphicsContext3D() | 38 TestWebGraphicsContext3D::TestWebGraphicsContext3D() |
38 : FakeWebGraphicsContext3D(), | 39 : FakeWebGraphicsContext3D(), |
39 context_id_(s_context_id++), | 40 context_id_(s_context_id++), |
| 41 next_buffer_id_(1), |
40 next_texture_id_(1), | 42 next_texture_id_(1), |
41 have_extension_io_surface_(false), | 43 have_extension_io_surface_(false), |
42 have_extension_egl_image_(false), | 44 have_extension_egl_image_(false), |
43 times_make_current_succeeds_(-1), | 45 times_make_current_succeeds_(-1), |
44 times_bind_texture_succeeds_(-1), | 46 times_bind_texture_succeeds_(-1), |
45 times_end_query_succeeds_(-1), | 47 times_end_query_succeeds_(-1), |
46 context_lost_(false), | 48 context_lost_(false), |
47 context_lost_callback_(NULL), | 49 context_lost_callback_(NULL), |
48 max_texture_size_(1024), | 50 max_texture_size_(1024), |
49 width_(0), | 51 width_(0), |
50 height_(0) { | 52 height_(0), |
| 53 bound_buffer_(0) { |
51 } | 54 } |
52 | 55 |
53 TestWebGraphicsContext3D::TestWebGraphicsContext3D( | 56 TestWebGraphicsContext3D::TestWebGraphicsContext3D( |
54 const WebGraphicsContext3D::Attributes& attributes) | 57 const WebGraphicsContext3D::Attributes& attributes) |
55 : FakeWebGraphicsContext3D(), | 58 : FakeWebGraphicsContext3D(), |
56 context_id_(s_context_id++), | 59 context_id_(s_context_id++), |
| 60 next_buffer_id_(1), |
57 next_texture_id_(1), | 61 next_texture_id_(1), |
58 attributes_(attributes), | 62 attributes_(attributes), |
59 have_extension_io_surface_(false), | 63 have_extension_io_surface_(false), |
60 have_extension_egl_image_(false), | 64 have_extension_egl_image_(false), |
61 times_make_current_succeeds_(-1), | 65 times_make_current_succeeds_(-1), |
62 times_bind_texture_succeeds_(-1), | 66 times_bind_texture_succeeds_(-1), |
63 times_end_query_succeeds_(-1), | 67 times_end_query_succeeds_(-1), |
64 context_lost_(false), | 68 context_lost_(false), |
65 context_lost_callback_(NULL), | 69 context_lost_callback_(NULL), |
66 max_texture_size_(1024), | 70 max_texture_size_(1024), |
67 width_(0), | 71 width_(0), |
68 height_(0) { | 72 height_(0), |
| 73 bound_buffer_(0) { |
69 } | 74 } |
70 | 75 |
71 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { | 76 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { |
| 77 for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) { |
| 78 if (sync_point_callbacks_[i] != NULL) |
| 79 delete sync_point_callbacks_[i]; |
| 80 } |
72 } | 81 } |
73 | 82 |
74 bool TestWebGraphicsContext3D::makeContextCurrent() { | 83 bool TestWebGraphicsContext3D::makeContextCurrent() { |
75 if (times_make_current_succeeds_ >= 0) { | 84 if (times_make_current_succeeds_ >= 0) { |
76 if (!times_make_current_succeeds_) { | 85 if (!times_make_current_succeeds_) { |
77 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 86 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
78 GL_INNOCENT_CONTEXT_RESET_ARB); | 87 GL_INNOCENT_CONTEXT_RESET_ARB); |
79 } | 88 } |
80 --times_make_current_succeeds_; | 89 --times_make_current_succeeds_; |
81 } | 90 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 WebGLId shader) { | 178 WebGLId shader) { |
170 return false; | 179 return false; |
171 } | 180 } |
172 | 181 |
173 WGC3Dboolean TestWebGraphicsContext3D::isTexture( | 182 WGC3Dboolean TestWebGraphicsContext3D::isTexture( |
174 WebGLId texture) { | 183 WebGLId texture) { |
175 return false; | 184 return false; |
176 } | 185 } |
177 | 186 |
178 WebGLId TestWebGraphicsContext3D::createBuffer() { | 187 WebGLId TestWebGraphicsContext3D::createBuffer() { |
179 return kBufferId | context_id_ << 16; | 188 return NextBufferId(); |
180 } | 189 } |
181 | 190 |
182 void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) { | 191 void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) { |
183 EXPECT_EQ(kBufferId | context_id_ << 16, id); | 192 unsigned context_id = id >> 17; |
| 193 unsigned buffer_id = id & 0x1ffff; |
| 194 DCHECK(buffer_id && buffer_id < next_buffer_id_); |
| 195 DCHECK_EQ(context_id, context_id_); |
184 } | 196 } |
185 | 197 |
186 WebGLId TestWebGraphicsContext3D::createFramebuffer() { | 198 WebGLId TestWebGraphicsContext3D::createFramebuffer() { |
187 return kFramebufferId | context_id_ << 16; | 199 return kFramebufferId | context_id_ << 16; |
188 } | 200 } |
189 | 201 |
190 void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) { | 202 void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) { |
191 EXPECT_EQ(kFramebufferId | context_id_ << 16, id); | 203 EXPECT_EQ(kFramebufferId | context_id_ << 16, id); |
192 } | 204 } |
193 | 205 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 EXPECT_EQ(kProgramId | context_id_ << 16, program); | 244 EXPECT_EQ(kProgramId | context_id_ << 16, program); |
233 EXPECT_EQ(kShaderId | context_id_ << 16, shader); | 245 EXPECT_EQ(kShaderId | context_id_ << 16, shader); |
234 } | 246 } |
235 | 247 |
236 void TestWebGraphicsContext3D::useProgram(WebGLId program) { | 248 void TestWebGraphicsContext3D::useProgram(WebGLId program) { |
237 if (!program) | 249 if (!program) |
238 return; | 250 return; |
239 EXPECT_EQ(kProgramId | context_id_ << 16, program); | 251 EXPECT_EQ(kProgramId | context_id_ << 16, program); |
240 } | 252 } |
241 | 253 |
242 void TestWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) { | |
243 if (!buffer) | |
244 return; | |
245 EXPECT_EQ(kBufferId | context_id_ << 16, buffer); | |
246 } | |
247 | |
248 void TestWebGraphicsContext3D::bindFramebuffer( | 254 void TestWebGraphicsContext3D::bindFramebuffer( |
249 WGC3Denum target, WebGLId framebuffer) { | 255 WGC3Denum target, WebGLId framebuffer) { |
250 if (!framebuffer) | 256 if (!framebuffer) |
251 return; | 257 return; |
252 EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); | 258 EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); |
253 } | 259 } |
254 | 260 |
255 void TestWebGraphicsContext3D::bindRenderbuffer( | 261 void TestWebGraphicsContext3D::bindRenderbuffer( |
256 WGC3Denum target, WebGLId renderbuffer) { | 262 WGC3Denum target, WebGLId renderbuffer) { |
257 if (!renderbuffer) | 263 if (!renderbuffer) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 return; | 333 return; |
328 context_lost_ = true; | 334 context_lost_ = true; |
329 if (context_lost_callback_) | 335 if (context_lost_callback_) |
330 context_lost_callback_->onContextLost(); | 336 context_lost_callback_->onContextLost(); |
331 | 337 |
332 for (size_t i = 0; i < shared_contexts_.size(); ++i) | 338 for (size_t i = 0; i < shared_contexts_.size(); ++i) |
333 shared_contexts_[i]->loseContextCHROMIUM(current, other); | 339 shared_contexts_[i]->loseContextCHROMIUM(current, other); |
334 shared_contexts_.clear(); | 340 shared_contexts_.clear(); |
335 } | 341 } |
336 | 342 |
| 343 void TestWebGraphicsContext3D::signalSyncPoint( |
| 344 unsigned sync_point, |
| 345 WebGraphicsSyncPointCallback* callback) { |
| 346 sync_point_callbacks_.push_back(callback); |
| 347 } |
| 348 |
| 349 void TestWebGraphicsContext3D::prepareTexture() { |
| 350 CallAllSyncPointCallbacks(); |
| 351 } |
| 352 |
| 353 void TestWebGraphicsContext3D::finish() { |
| 354 CallAllSyncPointCallbacks(); |
| 355 } |
| 356 |
| 357 void TestWebGraphicsContext3D::flush() { |
| 358 CallAllSyncPointCallbacks(); |
| 359 } |
| 360 |
| 361 static void CallAndDestroy( |
| 362 WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback* callback) { |
| 363 if (!callback) |
| 364 return; |
| 365 callback->onSyncPointReached(); |
| 366 delete callback; |
| 367 } |
| 368 |
| 369 void TestWebGraphicsContext3D::CallAllSyncPointCallbacks() { |
| 370 for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) { |
| 371 base::MessageLoop::current()->PostTask( |
| 372 FROM_HERE, |
| 373 base::Bind(&CallAndDestroy, |
| 374 sync_point_callbacks_[i])); |
| 375 } |
| 376 sync_point_callbacks_.clear(); |
| 377 } |
| 378 |
| 379 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, |
| 380 WebKit::WebGLId buffer) { |
| 381 bound_buffer_ = buffer; |
| 382 if (!bound_buffer_) |
| 383 return; |
| 384 unsigned context_id = buffer >> 17; |
| 385 unsigned buffer_id = buffer & 0x1ffff; |
| 386 DCHECK(buffer_id && buffer_id < next_buffer_id_); |
| 387 DCHECK_EQ(context_id, context_id_); |
| 388 |
| 389 if (buffers_.count(bound_buffer_) == 0) |
| 390 buffers_.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); |
| 391 |
| 392 buffers_.get(bound_buffer_)->target = target; |
| 393 } |
| 394 |
| 395 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, |
| 396 WebKit::WGC3Dsizeiptr size, |
| 397 const void* data, |
| 398 WebKit::WGC3Denum usage) { |
| 399 DCHECK_GT(buffers_.count(bound_buffer_), 0u); |
| 400 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); |
| 401 buffers_.get(bound_buffer_)->pixels.reset(new uint8[size]); |
| 402 if (data != NULL) |
| 403 memcpy(buffers_.get(bound_buffer_)->pixels.get(), data, size); |
| 404 } |
| 405 |
| 406 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target, |
| 407 WebKit::WGC3Denum access) { |
| 408 DCHECK_GT(buffers_.count(bound_buffer_), 0u); |
| 409 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); |
| 410 return buffers_.get(bound_buffer_)->pixels.get(); |
| 411 } |
| 412 |
| 413 WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( |
| 414 WebKit::WGC3Denum target) { |
| 415 DCHECK_GT(buffers_.count(bound_buffer_), 0u); |
| 416 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); |
| 417 buffers_.get(bound_buffer_)->pixels.reset(); |
| 418 return true; |
| 419 } |
| 420 |
337 WebGLId TestWebGraphicsContext3D::NextTextureId() { | 421 WebGLId TestWebGraphicsContext3D::NextTextureId() { |
338 WebGLId texture_id = next_texture_id_++; | 422 WebGLId texture_id = next_texture_id_++; |
339 DCHECK(texture_id < (1 << 16)); | 423 DCHECK(texture_id < (1 << 16)); |
340 texture_id |= context_id_ << 16; | 424 texture_id |= context_id_ << 16; |
341 return texture_id; | 425 return texture_id; |
342 } | 426 } |
343 | 427 |
| 428 WebGLId TestWebGraphicsContext3D::NextBufferId() { |
| 429 WebGLId buffer_id = next_buffer_id_++; |
| 430 DCHECK(buffer_id < (1 << 17)); |
| 431 buffer_id |= context_id_ << 17; |
| 432 return buffer_id; |
| 433 } |
| 434 |
| 435 TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {} |
| 436 |
| 437 TestWebGraphicsContext3D::Buffer::~Buffer() {} |
| 438 |
344 } // namespace cc | 439 } // namespace cc |
OLD | NEW |