Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1093)

Side by Side Diff: cc/test/test_web_graphics_context_3d.cc

Issue 18796008: Implement shareResources==true in TestWebGraphicsContext3D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix destruction race Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/test/test_web_graphics_context_3d.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h"
11 #include "base/lazy_instance.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "gpu/GLES2/gl2extchromium.h" 14 #include "gpu/GLES2/gl2extchromium.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2ext.h" 16 #include "third_party/khronos/GLES2/gl2ext.h"
16 17
17 using WebKit::WGC3Dboolean; 18 using WebKit::WGC3Dboolean;
18 using WebKit::WGC3Dchar; 19 using WebKit::WGC3Dchar;
19 using WebKit::WGC3Denum; 20 using WebKit::WGC3Denum;
20 using WebKit::WGC3Dint; 21 using WebKit::WGC3Dint;
21 using WebKit::WGC3Dsizei; 22 using WebKit::WGC3Dsizei;
22 using WebKit::WGC3Dsizeiptr; 23 using WebKit::WGC3Dsizeiptr;
23 using WebKit::WGC3Duint; 24 using WebKit::WGC3Duint;
24 using WebKit::WebGLId; 25 using WebKit::WebGLId;
25 using WebKit::WebGraphicsContext3D; 26 using WebKit::WebGraphicsContext3D;
26 27
27 namespace cc { 28 namespace cc {
28 29
29 static const WebGLId kFramebufferId = 1; 30 static const WebGLId kFramebufferId = 1;
30 static const WebGLId kProgramId = 2; 31 static const WebGLId kProgramId = 2;
31 static const WebGLId kRenderbufferId = 3; 32 static const WebGLId kRenderbufferId = 3;
32 static const WebGLId kShaderId = 4; 33 static const WebGLId kShaderId = 4;
33 34
34 static unsigned s_context_id = 1; 35 static unsigned s_context_id = 1;
35 36
36 const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; 37 const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337;
37 38
39 static base::LazyInstance<base::Lock>::Leaky
40 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER;
41
42 TestWebGraphicsContext3D::Namespace*
43 TestWebGraphicsContext3D::shared_namespace_ = NULL;
44
45 TestWebGraphicsContext3D::Namespace::Namespace()
46 : next_buffer_id(1),
47 next_image_id(1),
48 next_texture_id(1) {
49 }
50
51 TestWebGraphicsContext3D::Namespace::~Namespace() {
52 g_shared_namespace_lock.Get().AssertAcquired();
53 if (shared_namespace_ == this)
54 shared_namespace_ = NULL;
55 }
56
38 TestWebGraphicsContext3D::TestWebGraphicsContext3D() 57 TestWebGraphicsContext3D::TestWebGraphicsContext3D()
39 : FakeWebGraphicsContext3D(), 58 : FakeWebGraphicsContext3D(),
40 context_id_(s_context_id++), 59 context_id_(s_context_id++),
41 next_buffer_id_(1),
42 next_image_id_(1),
43 next_texture_id_(1),
44 support_swapbuffers_complete_callback_(true), 60 support_swapbuffers_complete_callback_(true),
45 have_extension_io_surface_(false), 61 have_extension_io_surface_(false),
46 have_extension_egl_image_(false), 62 have_extension_egl_image_(false),
47 times_make_current_succeeds_(-1), 63 times_make_current_succeeds_(-1),
48 times_bind_texture_succeeds_(-1), 64 times_bind_texture_succeeds_(-1),
49 times_end_query_succeeds_(-1), 65 times_end_query_succeeds_(-1),
50 context_lost_(false), 66 context_lost_(false),
51 times_map_image_chromium_succeeds_(-1), 67 times_map_image_chromium_succeeds_(-1),
52 times_map_buffer_chromium_succeeds_(-1), 68 times_map_buffer_chromium_succeeds_(-1),
53 context_lost_callback_(NULL), 69 context_lost_callback_(NULL),
54 swap_buffers_callback_(NULL), 70 swap_buffers_callback_(NULL),
55 memory_allocation_changed_callback_(NULL), 71 memory_allocation_changed_callback_(NULL),
56 max_texture_size_(1024), 72 max_texture_size_(1024),
57 width_(0), 73 width_(0),
58 height_(0), 74 height_(0),
59 bound_buffer_(0), 75 bound_buffer_(0),
60 weak_ptr_factory_(this) { 76 weak_ptr_factory_(this) {
77 CreateNamespace();
61 } 78 }
62 79
63 TestWebGraphicsContext3D::TestWebGraphicsContext3D( 80 TestWebGraphicsContext3D::TestWebGraphicsContext3D(
64 const WebGraphicsContext3D::Attributes& attributes) 81 const WebGraphicsContext3D::Attributes& attributes)
65 : FakeWebGraphicsContext3D(), 82 : FakeWebGraphicsContext3D(),
66 context_id_(s_context_id++), 83 context_id_(s_context_id++),
67 next_buffer_id_(1),
68 next_image_id_(1),
69 next_texture_id_(1),
70 attributes_(attributes), 84 attributes_(attributes),
71 support_swapbuffers_complete_callback_(true), 85 support_swapbuffers_complete_callback_(true),
72 have_extension_io_surface_(false), 86 have_extension_io_surface_(false),
73 have_extension_egl_image_(false), 87 have_extension_egl_image_(false),
74 times_make_current_succeeds_(-1), 88 times_make_current_succeeds_(-1),
75 times_bind_texture_succeeds_(-1), 89 times_bind_texture_succeeds_(-1),
76 times_end_query_succeeds_(-1), 90 times_end_query_succeeds_(-1),
77 context_lost_(false), 91 context_lost_(false),
78 times_map_image_chromium_succeeds_(-1), 92 times_map_image_chromium_succeeds_(-1),
79 times_map_buffer_chromium_succeeds_(-1), 93 times_map_buffer_chromium_succeeds_(-1),
80 context_lost_callback_(NULL), 94 context_lost_callback_(NULL),
81 swap_buffers_callback_(NULL), 95 swap_buffers_callback_(NULL),
82 memory_allocation_changed_callback_(NULL), 96 memory_allocation_changed_callback_(NULL),
83 max_texture_size_(1024), 97 max_texture_size_(1024),
84 width_(0), 98 width_(0),
85 height_(0), 99 height_(0),
86 bound_buffer_(0), 100 bound_buffer_(0),
87 weak_ptr_factory_(this) { 101 weak_ptr_factory_(this) {
102 CreateNamespace();
103 }
104
105 void TestWebGraphicsContext3D::CreateNamespace() {
106 if (attributes_.shareResources) {
107 base::AutoLock lock(g_shared_namespace_lock.Get());
108 if (shared_namespace_) {
109 namespace_ = shared_namespace_;
110 } else {
111 namespace_ = new Namespace;
112 shared_namespace_ = namespace_.get();
113 }
114 } else {
115 namespace_ = new Namespace;
116 }
88 } 117 }
89 118
90 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { 119 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
91 for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) { 120 for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
92 if (sync_point_callbacks_[i] != NULL) 121 if (sync_point_callbacks_[i] != NULL)
93 delete sync_point_callbacks_[i]; 122 delete sync_point_callbacks_[i];
94 } 123 }
124 base::AutoLock lock(g_shared_namespace_lock.Get());
125 namespace_ = NULL;
95 } 126 }
96 127
97 bool TestWebGraphicsContext3D::makeContextCurrent() { 128 bool TestWebGraphicsContext3D::makeContextCurrent() {
98 if (times_make_current_succeeds_ >= 0) { 129 if (times_make_current_succeeds_ >= 0) {
99 if (!times_make_current_succeeds_) { 130 if (!times_make_current_succeeds_) {
100 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 131 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
101 GL_INNOCENT_CONTEXT_RESET_ARB); 132 GL_INNOCENT_CONTEXT_RESET_ARB);
102 } 133 }
103 --times_make_current_succeeds_; 134 --times_make_current_succeeds_;
104 } 135 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 WGC3Dboolean TestWebGraphicsContext3D::isTexture( 231 WGC3Dboolean TestWebGraphicsContext3D::isTexture(
201 WebGLId texture) { 232 WebGLId texture) {
202 return false; 233 return false;
203 } 234 }
204 235
205 WebGLId TestWebGraphicsContext3D::createBuffer() { 236 WebGLId TestWebGraphicsContext3D::createBuffer() {
206 return NextBufferId(); 237 return NextBufferId();
207 } 238 }
208 239
209 void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) { 240 void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) {
241 base::AutoLock lock(namespace_->lock);
210 unsigned context_id = id >> 17; 242 unsigned context_id = id >> 17;
211 unsigned buffer_id = id & 0x1ffff; 243 unsigned buffer_id = id & 0x1ffff;
212 DCHECK(buffer_id && buffer_id < next_buffer_id_); 244 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
213 DCHECK_EQ(context_id, context_id_); 245 DCHECK_EQ(context_id, context_id_);
214 } 246 }
215 247
216 WebGLId TestWebGraphicsContext3D::createFramebuffer() { 248 WebGLId TestWebGraphicsContext3D::createFramebuffer() {
217 return kFramebufferId | context_id_ << 16; 249 return kFramebufferId | context_id_ << 16;
218 } 250 }
219 251
220 void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) { 252 void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) {
221 EXPECT_EQ(kFramebufferId | context_id_ << 16, id); 253 EXPECT_EQ(kFramebufferId | context_id_ << 16, id);
222 } 254 }
(...skipping 18 matching lines...) Expand all
241 return kShaderId | context_id_ << 16; 273 return kShaderId | context_id_ << 16;
242 } 274 }
243 275
244 void TestWebGraphicsContext3D::deleteShader(WebGLId id) { 276 void TestWebGraphicsContext3D::deleteShader(WebGLId id) {
245 EXPECT_EQ(kShaderId | context_id_ << 16, id); 277 EXPECT_EQ(kShaderId | context_id_ << 16, id);
246 } 278 }
247 279
248 WebGLId TestWebGraphicsContext3D::createTexture() { 280 WebGLId TestWebGraphicsContext3D::createTexture() {
249 WebGLId texture_id = NextTextureId(); 281 WebGLId texture_id = NextTextureId();
250 DCHECK_NE(texture_id, kExternalTextureId); 282 DCHECK_NE(texture_id, kExternalTextureId);
251 textures_.push_back(texture_id); 283 base::AutoLock lock(namespace_->lock);
284 namespace_->textures.push_back(texture_id);
252 return texture_id; 285 return texture_id;
253 } 286 }
254 287
255 void TestWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { 288 void TestWebGraphicsContext3D::deleteTexture(WebGLId texture_id) {
256 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != 289 base::AutoLock lock(namespace_->lock);
257 textures_.end()); 290 std::vector<WebKit::WebGLId>& textures = namespace_->textures;
258 textures_.erase(std::find(textures_.begin(), textures_.end(), texture_id)); 291 DCHECK(std::find(textures.begin(), textures.end(), texture_id) !=
292 textures.end());
293 textures.erase(std::find(textures.begin(), textures.end(), texture_id));
259 } 294 }
260 295
261 void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { 296 void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) {
262 EXPECT_EQ(kProgramId | context_id_ << 16, program); 297 EXPECT_EQ(kProgramId | context_id_ << 16, program);
263 EXPECT_EQ(kShaderId | context_id_ << 16, shader); 298 EXPECT_EQ(kShaderId | context_id_ << 16, shader);
264 } 299 }
265 300
266 void TestWebGraphicsContext3D::useProgram(WebGLId program) { 301 void TestWebGraphicsContext3D::useProgram(WebGLId program) {
267 if (!program) 302 if (!program)
268 return; 303 return;
(...skipping 21 matching lines...) Expand all
290 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 325 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
291 GL_INNOCENT_CONTEXT_RESET_ARB); 326 GL_INNOCENT_CONTEXT_RESET_ARB);
292 } 327 }
293 --times_bind_texture_succeeds_; 328 --times_bind_texture_succeeds_;
294 } 329 }
295 330
296 if (!texture_id) 331 if (!texture_id)
297 return; 332 return;
298 if (texture_id == kExternalTextureId) 333 if (texture_id == kExternalTextureId)
299 return; 334 return;
300 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != 335 base::AutoLock lock(namespace_->lock);
301 textures_.end()); 336 std::vector<WebKit::WebGLId>& textures = namespace_->textures;
337 DCHECK(std::find(textures.begin(), textures.end(), texture_id) !=
338 textures.end());
302 used_textures_.insert(texture_id); 339 used_textures_.insert(texture_id);
303 } 340 }
304 341
305 void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) { 342 void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) {
306 if (times_end_query_succeeds_ >= 0) { 343 if (times_end_query_succeeds_ >= 0) {
307 if (!times_end_query_succeeds_) { 344 if (!times_end_query_succeeds_) {
308 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 345 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
309 GL_INNOCENT_CONTEXT_RESET_ARB); 346 GL_INNOCENT_CONTEXT_RESET_ARB);
310 } 347 }
311 --times_end_query_succeeds_; 348 --times_end_query_succeeds_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 swap_buffers_callback_->onSwapBuffersComplete(); 452 swap_buffers_callback_->onSwapBuffersComplete();
416 } 453 }
417 454
418 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, 455 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target,
419 WebKit::WebGLId buffer) { 456 WebKit::WebGLId buffer) {
420 bound_buffer_ = buffer; 457 bound_buffer_ = buffer;
421 if (!bound_buffer_) 458 if (!bound_buffer_)
422 return; 459 return;
423 unsigned context_id = buffer >> 17; 460 unsigned context_id = buffer >> 17;
424 unsigned buffer_id = buffer & 0x1ffff; 461 unsigned buffer_id = buffer & 0x1ffff;
425 DCHECK(buffer_id && buffer_id < next_buffer_id_); 462 base::AutoLock lock(namespace_->lock);
463 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
426 DCHECK_EQ(context_id, context_id_); 464 DCHECK_EQ(context_id, context_id_);
427 465
428 if (buffers_.count(bound_buffer_) == 0) 466 ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
429 buffers_.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); 467 if (buffers.count(bound_buffer_) == 0)
468 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass());
430 469
431 buffers_.get(bound_buffer_)->target = target; 470 buffers.get(bound_buffer_)->target = target;
432 } 471 }
433 472
434 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, 473 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target,
435 WebKit::WGC3Dsizeiptr size, 474 WebKit::WGC3Dsizeiptr size,
436 const void* data, 475 const void* data,
437 WebKit::WGC3Denum usage) { 476 WebKit::WGC3Denum usage) {
438 DCHECK_GT(buffers_.count(bound_buffer_), 0u); 477 base::AutoLock lock(namespace_->lock);
439 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); 478 ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
479 DCHECK_GT(buffers.count(bound_buffer_), 0u);
480 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
440 if (context_lost_) { 481 if (context_lost_) {
441 buffers_.get(bound_buffer_)->pixels.reset(); 482 buffers.get(bound_buffer_)->pixels.reset();
442 return; 483 return;
443 } 484 }
444 buffers_.get(bound_buffer_)->pixels.reset(new uint8[size]); 485 buffers.get(bound_buffer_)->pixels.reset(new uint8[size]);
445 if (data != NULL) 486 if (data != NULL)
446 memcpy(buffers_.get(bound_buffer_)->pixels.get(), data, size); 487 memcpy(buffers.get(bound_buffer_)->pixels.get(), data, size);
447 } 488 }
448 489
449 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target, 490 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target,
450 WebKit::WGC3Denum access) { 491 WebKit::WGC3Denum access) {
451 DCHECK_GT(buffers_.count(bound_buffer_), 0u); 492 base::AutoLock lock(namespace_->lock);
452 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); 493 ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
494 DCHECK_GT(buffers.count(bound_buffer_), 0u);
495 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
453 if (times_map_buffer_chromium_succeeds_ >= 0) { 496 if (times_map_buffer_chromium_succeeds_ >= 0) {
454 if (!times_map_buffer_chromium_succeeds_) { 497 if (!times_map_buffer_chromium_succeeds_) {
455 return NULL; 498 return NULL;
456 } 499 }
457 --times_map_buffer_chromium_succeeds_; 500 --times_map_buffer_chromium_succeeds_;
458 } 501 }
459 return buffers_.get(bound_buffer_)->pixels.get(); 502 return buffers.get(bound_buffer_)->pixels.get();
460 } 503 }
461 504
462 WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( 505 WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM(
463 WebKit::WGC3Denum target) { 506 WebKit::WGC3Denum target) {
464 DCHECK_GT(buffers_.count(bound_buffer_), 0u); 507 base::AutoLock lock(namespace_->lock);
465 DCHECK_EQ(target, buffers_.get(bound_buffer_)->target); 508 ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
466 buffers_.get(bound_buffer_)->pixels.reset(); 509 DCHECK_GT(buffers.count(bound_buffer_), 0u);
510 DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
511 buffers.get(bound_buffer_)->pixels.reset();
467 return true; 512 return true;
468 } 513 }
469 514
470 void TestWebGraphicsContext3D::bindTexImage2DCHROMIUM( 515 void TestWebGraphicsContext3D::bindTexImage2DCHROMIUM(
471 WebKit::WGC3Denum target, 516 WebKit::WGC3Denum target,
472 WebKit::WGC3Dint image_id) { 517 WebKit::WGC3Dint image_id) {
473 DCHECK_GT(images_.count(image_id), 0u); 518 base::AutoLock lock(namespace_->lock);
519 DCHECK_GT(namespace_->images.count(image_id), 0u);
474 } 520 }
475 521
476 WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM( 522 WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM(
477 WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height, 523 WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height,
478 WebKit::WGC3Denum internalformat) { 524 WebKit::WGC3Denum internalformat) {
479 DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat)); 525 DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat));
480 WebKit::WGC3Duint image_id = NextImageId(); 526 WebKit::WGC3Duint image_id = NextImageId();
481 images_.set(image_id, make_scoped_ptr(new Image).Pass()); 527 base::AutoLock lock(namespace_->lock);
482 images_.get(image_id)->pixels.reset(new uint8[width * height * 4]); 528 ScopedPtrHashMap<unsigned, Image>& images = namespace_->images;
529 images.set(image_id, make_scoped_ptr(new Image).Pass());
530 images.get(image_id)->pixels.reset(new uint8[width * height * 4]);
483 return image_id; 531 return image_id;
484 } 532 }
485 533
486 void TestWebGraphicsContext3D::destroyImageCHROMIUM( 534 void TestWebGraphicsContext3D::destroyImageCHROMIUM(
487 WebKit::WGC3Duint id) { 535 WebKit::WGC3Duint id) {
536 base::AutoLock lock(namespace_->lock);
488 unsigned context_id = id >> 17; 537 unsigned context_id = id >> 17;
489 unsigned image_id = id & 0x1ffff; 538 unsigned image_id = id & 0x1ffff;
490 DCHECK(image_id && image_id < next_image_id_); 539 DCHECK(image_id && image_id < namespace_->next_image_id);
491 DCHECK_EQ(context_id, context_id_); 540 DCHECK_EQ(context_id, context_id_);
492 } 541 }
493 542
494 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( 543 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM(
495 WebKit::WGC3Duint image_id, 544 WebKit::WGC3Duint image_id,
496 WebKit::WGC3Denum pname, 545 WebKit::WGC3Denum pname,
497 WebKit::WGC3Dint* params) { 546 WebKit::WGC3Dint* params) {
498 DCHECK_GT(images_.count(image_id), 0u); 547 base::AutoLock lock(namespace_->lock);
548 DCHECK_GT(namespace_->images.count(image_id), 0u);
499 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); 549 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname));
500 *params = 0; 550 *params = 0;
501 } 551 }
502 552
503 void* TestWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id, 553 void* TestWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id,
504 WebKit::WGC3Denum access) { 554 WebKit::WGC3Denum access) {
505 DCHECK_GT(images_.count(image_id), 0u); 555 base::AutoLock lock(namespace_->lock);
556 ScopedPtrHashMap<unsigned, Image>& images = namespace_->images;
557 DCHECK_GT(images.count(image_id), 0u);
506 if (times_map_image_chromium_succeeds_ >= 0) { 558 if (times_map_image_chromium_succeeds_ >= 0) {
507 if (!times_map_image_chromium_succeeds_) { 559 if (!times_map_image_chromium_succeeds_) {
508 return NULL; 560 return NULL;
509 } 561 }
510 --times_map_image_chromium_succeeds_; 562 --times_map_image_chromium_succeeds_;
511 } 563 }
512 return images_.get(image_id)->pixels.get(); 564 return images.get(image_id)->pixels.get();
513 } 565 }
514 566
515 void TestWebGraphicsContext3D::unmapImageCHROMIUM( 567 void TestWebGraphicsContext3D::unmapImageCHROMIUM(
516 WebKit::WGC3Duint image_id) { 568 WebKit::WGC3Duint image_id) {
517 DCHECK_GT(images_.count(image_id), 0u); 569 base::AutoLock lock(namespace_->lock);
570 DCHECK_GT(namespace_->images.count(image_id), 0u);
571 }
572
573 size_t TestWebGraphicsContext3D::NumTextures() const {
574 base::AutoLock lock(namespace_->lock);
575 return namespace_->textures.size();
576 }
577
578 WebKit::WebGLId TestWebGraphicsContext3D::TextureAt(int i) const {
579 base::AutoLock lock(namespace_->lock);
580 return namespace_->textures[i];
518 } 581 }
519 582
520 WebGLId TestWebGraphicsContext3D::NextTextureId() { 583 WebGLId TestWebGraphicsContext3D::NextTextureId() {
521 WebGLId texture_id = next_texture_id_++; 584 base::AutoLock lock(namespace_->lock);
585 WebGLId texture_id = namespace_->next_texture_id++;
522 DCHECK(texture_id < (1 << 16)); 586 DCHECK(texture_id < (1 << 16));
523 texture_id |= context_id_ << 16; 587 texture_id |= context_id_ << 16;
524 return texture_id; 588 return texture_id;
525 } 589 }
526 590
527 WebGLId TestWebGraphicsContext3D::NextBufferId() { 591 WebGLId TestWebGraphicsContext3D::NextBufferId() {
528 WebGLId buffer_id = next_buffer_id_++; 592 base::AutoLock lock(namespace_->lock);
593 WebGLId buffer_id = namespace_->next_buffer_id++;
529 DCHECK(buffer_id < (1 << 17)); 594 DCHECK(buffer_id < (1 << 17));
530 buffer_id |= context_id_ << 17; 595 buffer_id |= context_id_ << 17;
531 return buffer_id; 596 return buffer_id;
532 } 597 }
533 598
534 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { 599 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() {
535 WebKit::WGC3Duint image_id = next_image_id_++; 600 base::AutoLock lock(namespace_->lock);
601 WGC3Duint image_id = namespace_->next_image_id++;
536 DCHECK(image_id < (1 << 17)); 602 DCHECK(image_id < (1 << 17));
537 image_id |= context_id_ << 17; 603 image_id |= context_id_ << 17;
538 return image_id; 604 return image_id;
539 } 605 }
540 606
541 void TestWebGraphicsContext3D::SetMemoryAllocation( 607 void TestWebGraphicsContext3D::SetMemoryAllocation(
542 WebKit::WebGraphicsMemoryAllocation allocation) { 608 WebKit::WebGraphicsMemoryAllocation allocation) {
543 if (!memory_allocation_changed_callback_) 609 if (!memory_allocation_changed_callback_)
544 return; 610 return;
545 memory_allocation_changed_callback_->onMemoryAllocationChanged(allocation); 611 memory_allocation_changed_callback_->onMemoryAllocationChanged(allocation);
546 } 612 }
547 613
548 TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {} 614 TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {}
549 615
550 TestWebGraphicsContext3D::Buffer::~Buffer() {} 616 TestWebGraphicsContext3D::Buffer::~Buffer() {}
551 617
552 TestWebGraphicsContext3D::Image::Image() {} 618 TestWebGraphicsContext3D::Image::Image() {}
553 619
554 TestWebGraphicsContext3D::Image::~Image() {} 620 TestWebGraphicsContext3D::Image::~Image() {}
555 621
556 } // namespace cc 622 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_web_graphics_context_3d.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698