| OLD | NEW |
| 1 // Copyright 2013 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/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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 static const GLuint kRenderbufferId = 2; | 22 static const GLuint kRenderbufferId = 2; |
| 23 | 23 |
| 24 static unsigned s_context_id = 1; | 24 static unsigned s_context_id = 1; |
| 25 | 25 |
| 26 const GLuint TestWebGraphicsContext3D::kExternalTextureId = 1337; | 26 const GLuint TestWebGraphicsContext3D::kExternalTextureId = 1337; |
| 27 | 27 |
| 28 static base::LazyInstance<base::Lock>::Leaky | 28 static base::LazyInstance<base::Lock>::Leaky |
| 29 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; | 29 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; |
| 30 | 30 |
| 31 TestWebGraphicsContext3D::Namespace* | 31 TestWebGraphicsContext3D::Namespace* |
| 32 TestWebGraphicsContext3D::shared_namespace_ = NULL; | 32 TestWebGraphicsContext3D::shared_namespace_ = nullptr; |
| 33 | 33 |
| 34 TestWebGraphicsContext3D::Namespace::Namespace() | 34 TestWebGraphicsContext3D::Namespace::Namespace() |
| 35 : next_buffer_id(1), | 35 : next_buffer_id(1), |
| 36 next_image_id(1), | 36 next_image_id(1), |
| 37 next_texture_id(1) { | 37 next_texture_id(1) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 TestWebGraphicsContext3D::Namespace::~Namespace() { | 40 TestWebGraphicsContext3D::Namespace::~Namespace() { |
| 41 g_shared_namespace_lock.Get().AssertAcquired(); | 41 g_shared_namespace_lock.Get().AssertAcquired(); |
| 42 if (shared_namespace_ == this) | 42 if (shared_namespace_ == this) |
| 43 shared_namespace_ = NULL; | 43 shared_namespace_ = nullptr; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { | 47 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { |
| 48 return make_scoped_ptr(new TestWebGraphicsContext3D()); | 48 return make_scoped_ptr(new TestWebGraphicsContext3D()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TestWebGraphicsContext3D::TestWebGraphicsContext3D() | 51 TestWebGraphicsContext3D::TestWebGraphicsContext3D() |
| 52 : context_id_(s_context_id++), | 52 : context_id_(s_context_id++), |
| 53 times_bind_texture_succeeds_(-1), | 53 times_bind_texture_succeeds_(-1), |
| 54 times_end_query_succeeds_(-1), | 54 times_end_query_succeeds_(-1), |
| 55 context_lost_(false), | 55 context_lost_(false), |
| 56 times_map_image_chromium_succeeds_(-1), | 56 times_map_image_chromium_succeeds_(-1), |
| 57 times_map_buffer_chromium_succeeds_(-1), | 57 times_map_buffer_chromium_succeeds_(-1), |
| 58 current_used_transfer_buffer_usage_bytes_(0), | 58 current_used_transfer_buffer_usage_bytes_(0), |
| 59 max_used_transfer_buffer_usage_bytes_(0), | 59 max_used_transfer_buffer_usage_bytes_(0), |
| 60 next_program_id_(1000), | 60 next_program_id_(1000), |
| 61 next_shader_id_(2000), | 61 next_shader_id_(2000), |
| 62 max_texture_size_(2048), | 62 max_texture_size_(2048), |
| 63 reshape_called_(false), | 63 reshape_called_(false), |
| 64 width_(0), | 64 width_(0), |
| 65 height_(0), | 65 height_(0), |
| 66 scale_factor_(-1.f), | 66 scale_factor_(-1.f), |
| 67 test_support_(NULL), | 67 test_support_(nullptr), |
| 68 last_update_type_(NoUpdate), | 68 last_update_type_(NoUpdate), |
| 69 next_insert_sync_point_(1), | 69 next_insert_sync_point_(1), |
| 70 last_waited_sync_point_(0), | 70 last_waited_sync_point_(0), |
| 71 bound_buffer_(0), | 71 bound_buffer_(0), |
| 72 weak_ptr_factory_(this) { | 72 weak_ptr_factory_(this) { |
| 73 CreateNamespace(); | 73 CreateNamespace(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { | 76 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { |
| 77 base::AutoLock lock(g_shared_namespace_lock.Get()); | 77 base::AutoLock lock(g_shared_namespace_lock.Get()); |
| 78 namespace_ = NULL; | 78 namespace_ = nullptr; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void TestWebGraphicsContext3D::CreateNamespace() { | 81 void TestWebGraphicsContext3D::CreateNamespace() { |
| 82 base::AutoLock lock(g_shared_namespace_lock.Get()); | 82 base::AutoLock lock(g_shared_namespace_lock.Get()); |
| 83 if (shared_namespace_) { | 83 if (shared_namespace_) { |
| 84 namespace_ = shared_namespace_; | 84 namespace_ = shared_namespace_; |
| 85 } else { | 85 } else { |
| 86 namespace_ = new Namespace; | 86 namespace_ = new Namespace; |
| 87 shared_namespace_ = namespace_.get(); | 87 shared_namespace_ = namespace_.get(); |
| 88 } | 88 } |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 Buffer* buffer = buffers.get(bound_buffer_); | 503 Buffer* buffer = buffers.get(bound_buffer_); |
| 504 if (context_lost_) { | 504 if (context_lost_) { |
| 505 buffer->pixels = nullptr; | 505 buffer->pixels = nullptr; |
| 506 return; | 506 return; |
| 507 } | 507 } |
| 508 | 508 |
| 509 size_t old_size = buffer->size; | 509 size_t old_size = buffer->size; |
| 510 | 510 |
| 511 buffer->pixels.reset(new uint8[size]); | 511 buffer->pixels.reset(new uint8[size]); |
| 512 buffer->size = size; | 512 buffer->size = size; |
| 513 if (data != NULL) | 513 if (data != nullptr) |
| 514 memcpy(buffer->pixels.get(), data, size); | 514 memcpy(buffer->pixels.get(), data, size); |
| 515 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) | 515 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) |
| 516 current_used_transfer_buffer_usage_bytes_ += buffer->size - old_size; | 516 current_used_transfer_buffer_usage_bytes_ += buffer->size - old_size; |
| 517 max_used_transfer_buffer_usage_bytes_ = | 517 max_used_transfer_buffer_usage_bytes_ = |
| 518 std::max(max_used_transfer_buffer_usage_bytes_, | 518 std::max(max_used_transfer_buffer_usage_bytes_, |
| 519 current_used_transfer_buffer_usage_bytes_); | 519 current_used_transfer_buffer_usage_bytes_); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(GLenum target, | 522 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(GLenum target, |
| 523 GLenum access) { | 523 GLenum access) { |
| 524 base::AutoLock lock(namespace_->lock); | 524 base::AutoLock lock(namespace_->lock); |
| 525 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | 525 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; |
| 526 DCHECK_GT(buffers.count(bound_buffer_), 0u); | 526 DCHECK_GT(buffers.count(bound_buffer_), 0u); |
| 527 DCHECK_EQ(target, buffers.get(bound_buffer_)->target); | 527 DCHECK_EQ(target, buffers.get(bound_buffer_)->target); |
| 528 if (times_map_buffer_chromium_succeeds_ >= 0) { | 528 if (times_map_buffer_chromium_succeeds_ >= 0) { |
| 529 if (!times_map_buffer_chromium_succeeds_) { | 529 if (!times_map_buffer_chromium_succeeds_) { |
| 530 return NULL; | 530 return nullptr; |
| 531 } | 531 } |
| 532 --times_map_buffer_chromium_succeeds_; | 532 --times_map_buffer_chromium_succeeds_; |
| 533 } | 533 } |
| 534 | 534 |
| 535 return buffers.get(bound_buffer_)->pixels.get(); | 535 return buffers.get(bound_buffer_)->pixels.get(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 GLboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( | 538 GLboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( |
| 539 GLenum target) { | 539 GLenum target) { |
| 540 base::AutoLock lock(namespace_->lock); | 540 base::AutoLock lock(namespace_->lock); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); | 572 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); |
| 573 *params = 0; | 573 *params = 0; |
| 574 } | 574 } |
| 575 | 575 |
| 576 void* TestWebGraphicsContext3D::mapImageCHROMIUM(GLuint image_id) { | 576 void* TestWebGraphicsContext3D::mapImageCHROMIUM(GLuint image_id) { |
| 577 base::AutoLock lock(namespace_->lock); | 577 base::AutoLock lock(namespace_->lock); |
| 578 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; | 578 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; |
| 579 DCHECK_GT(images.count(image_id), 0u); | 579 DCHECK_GT(images.count(image_id), 0u); |
| 580 if (times_map_image_chromium_succeeds_ >= 0) { | 580 if (times_map_image_chromium_succeeds_ >= 0) { |
| 581 if (!times_map_image_chromium_succeeds_) { | 581 if (!times_map_image_chromium_succeeds_) { |
| 582 return NULL; | 582 return nullptr; |
| 583 } | 583 } |
| 584 --times_map_image_chromium_succeeds_; | 584 --times_map_image_chromium_succeeds_; |
| 585 } | 585 } |
| 586 return images.get(image_id)->pixels.get(); | 586 return images.get(image_id)->pixels.get(); |
| 587 } | 587 } |
| 588 | 588 |
| 589 void TestWebGraphicsContext3D::unmapImageCHROMIUM( | 589 void TestWebGraphicsContext3D::unmapImageCHROMIUM( |
| 590 GLuint image_id) { | 590 GLuint image_id) { |
| 591 base::AutoLock lock(namespace_->lock); | 591 base::AutoLock lock(namespace_->lock); |
| 592 DCHECK_GT(namespace_->images.count(image_id), 0u); | 592 DCHECK_GT(namespace_->images.count(image_id), 0u); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 740 |
| 741 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} | 741 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} |
| 742 | 742 |
| 743 TestWebGraphicsContext3D::Buffer::~Buffer() {} | 743 TestWebGraphicsContext3D::Buffer::~Buffer() {} |
| 744 | 744 |
| 745 TestWebGraphicsContext3D::Image::Image() {} | 745 TestWebGraphicsContext3D::Image::Image() {} |
| 746 | 746 |
| 747 TestWebGraphicsContext3D::Image::~Image() {} | 747 TestWebGraphicsContext3D::Image::~Image() {} |
| 748 | 748 |
| 749 } // namespace cc | 749 } // namespace cc |
| OLD | NEW |