| 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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "cc/test/test_context_support.h" | 14 #include "cc/test/test_context_support.h" |
| 15 #include "gpu/GLES2/gl2extchromium.h" | 15 #include "gpu/GLES2/gl2extchromium.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/khronos/GLES2/gl2ext.h" | 17 #include "third_party/khronos/GLES2/gl2ext.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 static const GLuint kFramebufferId = 1; | |
| 22 static const GLuint kRenderbufferId = 2; | |
| 23 | |
| 24 static unsigned s_context_id = 1; | 21 static unsigned s_context_id = 1; |
| 25 | 22 |
| 26 const GLuint TestWebGraphicsContext3D::kExternalTextureId = 1337; | 23 const GLuint TestWebGraphicsContext3D::kExternalTextureId = 1337; |
| 27 | 24 |
| 28 static base::LazyInstance<base::Lock>::Leaky | 25 static base::LazyInstance<base::Lock>::Leaky |
| 29 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; | 26 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; |
| 30 | 27 |
| 31 TestWebGraphicsContext3D::Namespace* | 28 TestWebGraphicsContext3D::Namespace* |
| 32 TestWebGraphicsContext3D::shared_namespace_ = NULL; | 29 TestWebGraphicsContext3D::shared_namespace_ = NULL; |
| 33 | 30 |
| 34 TestWebGraphicsContext3D::Namespace::Namespace() | 31 TestWebGraphicsContext3D::Namespace::Namespace() |
| 35 : next_buffer_id(1), | 32 : next_buffer_id(1), |
| 36 next_image_id(1), | 33 next_image_id(1), |
| 37 next_texture_id(1) { | 34 next_texture_id(1), |
| 35 next_renderbuffer_id(1) { |
| 38 } | 36 } |
| 39 | 37 |
| 40 TestWebGraphicsContext3D::Namespace::~Namespace() { | 38 TestWebGraphicsContext3D::Namespace::~Namespace() { |
| 41 g_shared_namespace_lock.Get().AssertAcquired(); | 39 g_shared_namespace_lock.Get().AssertAcquired(); |
| 42 if (shared_namespace_ == this) | 40 if (shared_namespace_ == this) |
| 43 shared_namespace_ = NULL; | 41 shared_namespace_ = NULL; |
| 44 } | 42 } |
| 45 | 43 |
| 46 // static | 44 // static |
| 47 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { | 45 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { |
| 48 return make_scoped_ptr(new TestWebGraphicsContext3D()); | 46 return make_scoped_ptr(new TestWebGraphicsContext3D()); |
| 49 } | 47 } |
| 50 | 48 |
| 51 TestWebGraphicsContext3D::TestWebGraphicsContext3D() | 49 TestWebGraphicsContext3D::TestWebGraphicsContext3D() |
| 52 : context_id_(s_context_id++), | 50 : context_id_(s_context_id++), |
| 53 times_bind_texture_succeeds_(-1), | 51 times_bind_texture_succeeds_(-1), |
| 54 times_end_query_succeeds_(-1), | 52 times_end_query_succeeds_(-1), |
| 55 context_lost_(false), | 53 context_lost_(false), |
| 56 times_map_buffer_chromium_succeeds_(-1), | 54 times_map_buffer_chromium_succeeds_(-1), |
| 57 current_used_transfer_buffer_usage_bytes_(0), | 55 current_used_transfer_buffer_usage_bytes_(0), |
| 58 max_used_transfer_buffer_usage_bytes_(0), | 56 max_used_transfer_buffer_usage_bytes_(0), |
| 59 next_program_id_(1000), | 57 next_program_id_(1000), |
| 60 next_shader_id_(2000), | 58 next_shader_id_(2000), |
| 59 next_framebuffer_id_(1), |
| 60 current_framebuffer_(0), |
| 61 max_texture_size_(2048), | 61 max_texture_size_(2048), |
| 62 reshape_called_(false), | 62 reshape_called_(false), |
| 63 width_(0), | 63 width_(0), |
| 64 height_(0), | 64 height_(0), |
| 65 scale_factor_(-1.f), | 65 scale_factor_(-1.f), |
| 66 test_support_(NULL), | 66 test_support_(NULL), |
| 67 last_update_type_(NoUpdate), | 67 last_update_type_(NoUpdate), |
| 68 next_insert_sync_point_(1), | 68 next_insert_sync_point_(1), |
| 69 last_waited_sync_point_(0), | 69 last_waited_sync_point_(0), |
| 70 unpack_alignment_(4), | 70 unpack_alignment_(4), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TestWebGraphicsContext3D::genBuffers(GLsizei count, GLuint* ids) { | 157 void TestWebGraphicsContext3D::genBuffers(GLsizei count, GLuint* ids) { |
| 158 for (int i = 0; i < count; ++i) | 158 for (int i = 0; i < count; ++i) |
| 159 ids[i] = NextBufferId(); | 159 ids[i] = NextBufferId(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void TestWebGraphicsContext3D::genFramebuffers( | 162 void TestWebGraphicsContext3D::genFramebuffers( |
| 163 GLsizei count, GLuint* ids) { | 163 GLsizei count, GLuint* ids) { |
| 164 for (int i = 0; i < count; ++i) | 164 for (int i = 0; i < count; ++i) |
| 165 ids[i] = kFramebufferId | context_id_ << 16; | 165 ids[i] = NextFramebufferId(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void TestWebGraphicsContext3D::genRenderbuffers( | 168 void TestWebGraphicsContext3D::genRenderbuffers( |
| 169 GLsizei count, GLuint* ids) { | 169 GLsizei count, GLuint* ids) { |
| 170 for (int i = 0; i < count; ++i) | 170 for (int i = 0; i < count; ++i) |
| 171 ids[i] = kRenderbufferId | context_id_ << 16; | 171 ids[i] = NextRenderbufferId(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void TestWebGraphicsContext3D::genTextures(GLsizei count, GLuint* ids) { | 174 void TestWebGraphicsContext3D::genTextures(GLsizei count, GLuint* ids) { |
| 175 for (int i = 0; i < count; ++i) { | 175 for (int i = 0; i < count; ++i) { |
| 176 ids[i] = NextTextureId(); | 176 ids[i] = NextTextureId(); |
| 177 DCHECK_NE(ids[i], kExternalTextureId); | 177 DCHECK_NE(ids[i], kExternalTextureId); |
| 178 } | 178 } |
| 179 base::AutoLock lock(namespace_->lock); | 179 base::AutoLock lock(namespace_->lock); |
| 180 for (int i = 0; i < count; ++i) | 180 for (int i = 0; i < count; ++i) |
| 181 namespace_->textures.Append(ids[i], new TestTexture()); | 181 namespace_->textures.Append(ids[i], new TestTexture()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void TestWebGraphicsContext3D::deleteBuffers(GLsizei count, GLuint* ids) { | 184 void TestWebGraphicsContext3D::deleteBuffers(GLsizei count, GLuint* ids) { |
| 185 for (int i = 0; i < count; ++i) | 185 for (int i = 0; i < count; ++i) |
| 186 RetireBufferId(ids[i]); | 186 RetireBufferId(ids[i]); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void TestWebGraphicsContext3D::deleteFramebuffers( | 189 void TestWebGraphicsContext3D::deleteFramebuffers( |
| 190 GLsizei count, GLuint* ids) { | 190 GLsizei count, GLuint* ids) { |
| 191 for (int i = 0; i < count; ++i) | 191 for (int i = 0; i < count; ++i) { |
| 192 DCHECK_EQ(kFramebufferId | context_id_ << 16, ids[i]); | 192 if (ids[i]) { |
| 193 RetireFramebufferId(ids[i]); |
| 194 if (ids[i] == current_framebuffer_) |
| 195 current_framebuffer_ = 0; |
| 196 } |
| 197 } |
| 193 } | 198 } |
| 194 | 199 |
| 195 void TestWebGraphicsContext3D::deleteRenderbuffers( | 200 void TestWebGraphicsContext3D::deleteRenderbuffers( |
| 196 GLsizei count, GLuint* ids) { | 201 GLsizei count, GLuint* ids) { |
| 197 for (int i = 0; i < count; ++i) | 202 for (int i = 0; i < count; ++i) |
| 198 DCHECK_EQ(kRenderbufferId | context_id_ << 16, ids[i]); | 203 RetireRenderbufferId(ids[i]); |
| 199 } | 204 } |
| 200 | 205 |
| 201 void TestWebGraphicsContext3D::deleteTextures(GLsizei count, GLuint* ids) { | 206 void TestWebGraphicsContext3D::deleteTextures(GLsizei count, GLuint* ids) { |
| 202 for (int i = 0; i < count; ++i) | 207 for (int i = 0; i < count; ++i) |
| 203 RetireTextureId(ids[i]); | 208 RetireTextureId(ids[i]); |
| 204 base::AutoLock lock(namespace_->lock); | 209 base::AutoLock lock(namespace_->lock); |
| 205 for (int i = 0; i < count; ++i) { | 210 for (int i = 0; i < count; ++i) { |
| 206 namespace_->textures.Remove(ids[i]); | 211 namespace_->textures.Remove(ids[i]); |
| 207 texture_targets_.UnbindTexture(ids[i]); | 212 texture_targets_.UnbindTexture(ids[i]); |
| 208 } | 213 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 292 |
| 288 void TestWebGraphicsContext3D::useProgram(GLuint program) { | 293 void TestWebGraphicsContext3D::useProgram(GLuint program) { |
| 289 if (!program) | 294 if (!program) |
| 290 return; | 295 return; |
| 291 if (!program_set_.count(program)) | 296 if (!program_set_.count(program)) |
| 292 ADD_FAILURE() << "useProgram called on unknown program " << program; | 297 ADD_FAILURE() << "useProgram called on unknown program " << program; |
| 293 } | 298 } |
| 294 | 299 |
| 295 void TestWebGraphicsContext3D::bindFramebuffer( | 300 void TestWebGraphicsContext3D::bindFramebuffer( |
| 296 GLenum target, GLuint framebuffer) { | 301 GLenum target, GLuint framebuffer) { |
| 297 if (!framebuffer) | 302 base::AutoLock lock_for_framebuffer_access(namespace_->lock); |
| 298 return; | 303 if (framebuffer != 0 && |
| 299 DCHECK_EQ(kFramebufferId | context_id_ << 16, framebuffer); | 304 framebuffer_set_.find(framebuffer) == framebuffer_set_.end()) { |
| 305 ADD_FAILURE() << "bindFramebuffer called with unknown framebuffer"; |
| 306 } else if (framebuffer != 0 && (framebuffer >> 16) != context_id_) { |
| 307 ADD_FAILURE() |
| 308 << "bindFramebuffer called with framebuffer from other context"; |
| 309 } else { |
| 310 current_framebuffer_ = framebuffer; |
| 311 } |
| 300 } | 312 } |
| 301 | 313 |
| 302 void TestWebGraphicsContext3D::bindRenderbuffer( | 314 void TestWebGraphicsContext3D::bindRenderbuffer( |
| 303 GLenum target, GLuint renderbuffer) { | 315 GLenum target, GLuint renderbuffer) { |
| 304 if (!renderbuffer) | 316 if (!renderbuffer) |
| 305 return; | 317 return; |
| 306 DCHECK_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); | 318 base::AutoLock lock_for_renderbuffer_access(namespace_->lock); |
| 319 if (renderbuffer != 0 && |
| 320 namespace_->renderbuffer_set.find(renderbuffer) == |
| 321 namespace_->renderbuffer_set.end()) { |
| 322 ADD_FAILURE() << "bindRenderbuffer called with unknown renderbuffer"; |
| 323 } else if ((renderbuffer >> 16) != context_id_) { |
| 324 ADD_FAILURE() |
| 325 << "bindRenderbuffer called with renderbuffer from other context"; |
| 326 } |
| 307 } | 327 } |
| 308 | 328 |
| 309 void TestWebGraphicsContext3D::bindTexture( | 329 void TestWebGraphicsContext3D::bindTexture( |
| 310 GLenum target, GLuint texture_id) { | 330 GLenum target, GLuint texture_id) { |
| 311 if (times_bind_texture_succeeds_ >= 0) { | 331 if (times_bind_texture_succeeds_ >= 0) { |
| 312 if (!times_bind_texture_succeeds_) { | 332 if (!times_bind_texture_succeeds_) { |
| 313 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 333 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 314 GL_INNOCENT_CONTEXT_RESET_ARB); | 334 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 315 } | 335 } |
| 316 --times_bind_texture_succeeds_; | 336 --times_bind_texture_succeeds_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 383 |
| 364 void TestWebGraphicsContext3D::getIntegerv( | 384 void TestWebGraphicsContext3D::getIntegerv( |
| 365 GLenum pname, | 385 GLenum pname, |
| 366 GLint* value) { | 386 GLint* value) { |
| 367 if (pname == GL_MAX_TEXTURE_SIZE) | 387 if (pname == GL_MAX_TEXTURE_SIZE) |
| 368 *value = max_texture_size_; | 388 *value = max_texture_size_; |
| 369 else if (pname == GL_ACTIVE_TEXTURE) | 389 else if (pname == GL_ACTIVE_TEXTURE) |
| 370 *value = GL_TEXTURE0; | 390 *value = GL_TEXTURE0; |
| 371 else if (pname == GL_UNPACK_ALIGNMENT) | 391 else if (pname == GL_UNPACK_ALIGNMENT) |
| 372 *value = unpack_alignment_; | 392 *value = unpack_alignment_; |
| 393 else if (pname == GL_FRAMEBUFFER_BINDING) |
| 394 *value = current_framebuffer_; |
| 373 } | 395 } |
| 374 | 396 |
| 375 void TestWebGraphicsContext3D::getProgramiv(GLuint program, | 397 void TestWebGraphicsContext3D::getProgramiv(GLuint program, |
| 376 GLenum pname, | 398 GLenum pname, |
| 377 GLint* value) { | 399 GLint* value) { |
| 378 if (pname == GL_LINK_STATUS) | 400 if (pname == GL_LINK_STATUS) |
| 379 *value = 1; | 401 *value = 1; |
| 380 } | 402 } |
| 381 | 403 |
| 382 void TestWebGraphicsContext3D::getShaderiv(GLuint shader, | 404 void TestWebGraphicsContext3D::getShaderiv(GLuint shader, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 689 |
| 668 void TestWebGraphicsContext3D::RetireImageId(GLuint id) { | 690 void TestWebGraphicsContext3D::RetireImageId(GLuint id) { |
| 669 base::AutoLock lock(namespace_->lock); | 691 base::AutoLock lock(namespace_->lock); |
| 670 unsigned context_id = id >> 16; | 692 unsigned context_id = id >> 16; |
| 671 unsigned image_id = id & 0xffff; | 693 unsigned image_id = id & 0xffff; |
| 672 DCHECK(image_id); | 694 DCHECK(image_id); |
| 673 DCHECK_LT(image_id, namespace_->next_image_id); | 695 DCHECK_LT(image_id, namespace_->next_image_id); |
| 674 DCHECK_EQ(context_id, context_id_); | 696 DCHECK_EQ(context_id, context_id_); |
| 675 } | 697 } |
| 676 | 698 |
| 699 GLuint TestWebGraphicsContext3D::NextFramebufferId() { |
| 700 base::AutoLock lock_for_framebuffer_access(namespace_->lock); |
| 701 GLuint id = next_framebuffer_id_++; |
| 702 DCHECK(id < (1 << 16)); |
| 703 id |= context_id_ << 16; |
| 704 framebuffer_set_.insert(id); |
| 705 return id; |
| 706 } |
| 707 |
| 708 void TestWebGraphicsContext3D::RetireFramebufferId(GLuint id) { |
| 709 base::AutoLock lock_for_framebuffer_access(namespace_->lock); |
| 710 DCHECK(framebuffer_set_.find(id) != framebuffer_set_.end()); |
| 711 framebuffer_set_.erase(id); |
| 712 } |
| 713 |
| 714 GLuint TestWebGraphicsContext3D::NextRenderbufferId() { |
| 715 base::AutoLock lock_for_renderbuffer_access(namespace_->lock); |
| 716 GLuint id = namespace_->next_renderbuffer_id++; |
| 717 DCHECK(id < (1 << 16)); |
| 718 id |= context_id_ << 16; |
| 719 namespace_->renderbuffer_set.insert(id); |
| 720 return id; |
| 721 } |
| 722 |
| 723 void TestWebGraphicsContext3D::RetireRenderbufferId(GLuint id) { |
| 724 base::AutoLock lock_for_renderbuffer_access(namespace_->lock); |
| 725 DCHECK(namespace_->renderbuffer_set.find(id) != |
| 726 namespace_->renderbuffer_set.end()); |
| 727 namespace_->renderbuffer_set.erase(id); |
| 728 } |
| 729 |
| 677 void TestWebGraphicsContext3D::SetMaxTransferBufferUsageBytes( | 730 void TestWebGraphicsContext3D::SetMaxTransferBufferUsageBytes( |
| 678 size_t max_transfer_buffer_usage_bytes) { | 731 size_t max_transfer_buffer_usage_bytes) { |
| 679 test_capabilities_.max_transfer_buffer_usage_bytes = | 732 test_capabilities_.max_transfer_buffer_usage_bytes = |
| 680 max_transfer_buffer_usage_bytes; | 733 max_transfer_buffer_usage_bytes; |
| 681 } | 734 } |
| 682 | 735 |
| 683 TestWebGraphicsContext3D::TextureTargets::TextureTargets() { | 736 TestWebGraphicsContext3D::TextureTargets::TextureTargets() { |
| 684 // Initialize default bindings. | 737 // Initialize default bindings. |
| 685 bound_textures_[GL_TEXTURE_2D] = 0; | 738 bound_textures_[GL_TEXTURE_2D] = 0; |
| 686 bound_textures_[GL_TEXTURE_EXTERNAL_OES] = 0; | 739 bound_textures_[GL_TEXTURE_EXTERNAL_OES] = 0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 791 |
| 739 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} | 792 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} |
| 740 | 793 |
| 741 TestWebGraphicsContext3D::Buffer::~Buffer() {} | 794 TestWebGraphicsContext3D::Buffer::~Buffer() {} |
| 742 | 795 |
| 743 TestWebGraphicsContext3D::Image::Image() {} | 796 TestWebGraphicsContext3D::Image::Image() {} |
| 744 | 797 |
| 745 TestWebGraphicsContext3D::Image::~Image() {} | 798 TestWebGraphicsContext3D::Image::~Image() {} |
| 746 | 799 |
| 747 } // namespace cc | 800 } // namespace cc |
| OLD | NEW |