| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "gpu/command_buffer/service/valuebuffer_manager.h" | 5 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 11 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 11 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 12 #include "gpu/command_buffer/service/common_decoder.h" | 12 #include "gpu/command_buffer/service/common_decoder.h" |
| 13 #include "gpu/command_buffer/service/feature_info.h" | 13 #include "gpu/command_buffer/service/feature_info.h" |
| 14 #include "gpu/command_buffer/service/gpu_service_test.h" | 14 #include "gpu/command_buffer/service/gpu_service_test.h" |
| 15 #include "gpu/command_buffer/service/mocks.h" | 15 #include "gpu/command_buffer/service/mocks.h" |
| 16 #include "gpu/command_buffer/service/test_helper.h" | 16 #include "gpu/command_buffer/service/test_helper.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
| 19 #include "ui/gl/gl_mock.h" | 19 #include "ui/gl/gl_mock.h" |
| 20 | 20 |
| 21 namespace gpu { | 21 namespace gpu { |
| 22 namespace gles2 { | 22 namespace gles2 { |
| 23 | 23 |
| 24 class ValuebufferManagerTest : public GpuServiceTest { | 24 class ValuebufferManagerTest : public GpuServiceTest { |
| 25 public: | 25 public: |
| 26 ValuebufferManagerTest() : manager_() {} | 26 ValuebufferManagerTest() {} |
| 27 ~ValuebufferManagerTest() override { manager_.Destroy(); } | 27 ~ValuebufferManagerTest() override {} |
| 28 |
| 29 void SetUp() override { |
| 30 GpuServiceTest::SetUp(); |
| 31 manager_ = new ValuebufferManager(); |
| 32 } |
| 28 | 33 |
| 29 protected: | 34 protected: |
| 30 ValuebufferManager manager_; | 35 scoped_refptr<ValuebufferManager> manager_; |
| 31 }; | 36 }; |
| 32 | 37 |
| 33 TEST_F(ValuebufferManagerTest, Basic) { | 38 TEST_F(ValuebufferManagerTest, Basic) { |
| 34 const GLuint kClient1Id = 1; | 39 const GLuint kClient1Id = 1; |
| 35 const GLuint kClient2Id = 2; | 40 const GLuint kClient2Id = 2; |
| 36 // Check we can create a Valuebuffer | 41 // Check we can create a Valuebuffer |
| 37 manager_.CreateValuebuffer(kClient1Id); | 42 manager_->CreateValuebuffer(kClient1Id); |
| 38 Valuebuffer* valuebuffer0 = manager_.GetValuebuffer(kClient1Id); | 43 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); |
| 39 ASSERT_TRUE(valuebuffer0 != NULL); | 44 ASSERT_TRUE(valuebuffer0 != NULL); |
| 40 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | 45 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); |
| 41 // Check we get nothing for a non-existent Valuebuffer. | 46 // Check we get nothing for a non-existent Valuebuffer. |
| 42 // Check trying to a remove non-existent Valuebuffer does not crash | 47 // Check trying to a remove non-existent Valuebuffer does not crash |
| 43 manager_.RemoveValuebuffer(kClient2Id); | 48 manager_->RemoveValuebuffer(kClient2Id); |
| 44 // Check we can't get the renderbuffer after we remove it. | 49 // Check we can't get the renderbuffer after we remove it. |
| 45 manager_.RemoveValuebuffer(kClient1Id); | 50 manager_->RemoveValuebuffer(kClient1Id); |
| 46 EXPECT_TRUE(manager_.GetValuebuffer(kClient1Id) == NULL); | 51 EXPECT_TRUE(manager_->GetValuebuffer(kClient1Id) == NULL); |
| 47 } | |
| 48 | |
| 49 TEST_F(ValuebufferManagerTest, Destroy) { | |
| 50 const GLuint kClient1Id = 1; | |
| 51 // Check we can create Valuebuffer. | |
| 52 manager_.CreateValuebuffer(kClient1Id); | |
| 53 Valuebuffer* valuebuffer0 = manager_.GetValuebuffer(kClient1Id); | |
| 54 ASSERT_TRUE(valuebuffer0 != NULL); | |
| 55 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | |
| 56 manager_.Destroy(); | |
| 57 // Check the resources were released. | |
| 58 Valuebuffer* valuebuffer1 = manager_.GetValuebuffer(kClient1Id); | |
| 59 ASSERT_TRUE(valuebuffer1 == NULL); | |
| 60 } | 52 } |
| 61 | 53 |
| 62 TEST_F(ValuebufferManagerTest, ValueBuffer) { | 54 TEST_F(ValuebufferManagerTest, ValueBuffer) { |
| 63 const GLuint kClient1Id = 1; | 55 const GLuint kClient1Id = 1; |
| 64 // Check we can create a Valuebuffer | 56 // Check we can create a Valuebuffer |
| 65 manager_.CreateValuebuffer(kClient1Id); | 57 manager_->CreateValuebuffer(kClient1Id); |
| 66 Valuebuffer* valuebuffer0 = manager_.GetValuebuffer(kClient1Id); | 58 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); |
| 67 ASSERT_TRUE(valuebuffer0 != NULL); | 59 ASSERT_TRUE(valuebuffer0 != NULL); |
| 68 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | 60 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); |
| 69 EXPECT_FALSE(valuebuffer0->IsValid()); | 61 EXPECT_FALSE(valuebuffer0->IsValid()); |
| 70 } | 62 } |
| 71 | 63 |
| 72 TEST_F(ValuebufferManagerTest, UpdateState) { | 64 TEST_F(ValuebufferManagerTest, UpdateState) { |
| 73 const GLuint kClient1Id = 1; | 65 const GLuint kClient1Id = 1; |
| 74 ValueState valuestate1; | 66 ValueState valuestate1; |
| 75 valuestate1.int_value[0] = 111; | 67 valuestate1.int_value[0] = 111; |
| 76 ValueState valuestate2; | 68 ValueState valuestate2; |
| 77 valuestate2.int_value[0] = 222; | 69 valuestate2.int_value[0] = 222; |
| 78 manager_.CreateValuebuffer(kClient1Id); | 70 manager_->CreateValuebuffer(kClient1Id); |
| 79 Valuebuffer* valuebuffer0 = manager_.GetValuebuffer(kClient1Id); | 71 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); |
| 80 ASSERT_TRUE(valuebuffer0 != NULL); | 72 ASSERT_TRUE(valuebuffer0 != NULL); |
| 81 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | 73 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); |
| 82 valuebuffer0->AddSubscription(GL_MOUSE_POSITION_CHROMIUM); | 74 valuebuffer0->AddSubscription(GL_MOUSE_POSITION_CHROMIUM); |
| 83 ASSERT_TRUE(valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM) == NULL); | 75 ASSERT_TRUE(valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM) == NULL); |
| 84 manager_.UpdateValueState(GL_MOUSE_POSITION_CHROMIUM, valuestate1); | 76 manager_->UpdateValueState(GL_MOUSE_POSITION_CHROMIUM, valuestate1); |
| 85 manager_.UpdateValuebufferState(valuebuffer0); | 77 manager_->UpdateValuebufferState(valuebuffer0); |
| 86 const ValueState* new_state1 = | 78 const ValueState* new_state1 = |
| 87 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); | 79 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); |
| 88 ASSERT_TRUE(new_state1 != NULL); | 80 ASSERT_TRUE(new_state1 != NULL); |
| 89 ASSERT_TRUE(new_state1->int_value[0] == 111); | 81 ASSERT_TRUE(new_state1->int_value[0] == 111); |
| 90 // Ensure state changes | 82 // Ensure state changes |
| 91 manager_.UpdateValueState(GL_MOUSE_POSITION_CHROMIUM, valuestate2); | 83 manager_->UpdateValueState(GL_MOUSE_POSITION_CHROMIUM, valuestate2); |
| 92 manager_.UpdateValuebufferState(valuebuffer0); | 84 manager_->UpdateValuebufferState(valuebuffer0); |
| 93 const ValueState* new_state2 = | 85 const ValueState* new_state2 = |
| 94 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); | 86 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); |
| 95 ASSERT_TRUE(new_state2 != NULL); | 87 ASSERT_TRUE(new_state2 != NULL); |
| 96 ASSERT_TRUE(new_state2->int_value[0] == 222); | 88 ASSERT_TRUE(new_state2->int_value[0] == 222); |
| 97 } | 89 } |
| 98 | 90 |
| 99 } // namespace gles2 | 91 } // namespace gles2 |
| 100 } // namespace gpu | 92 } // namespace gpu |
| OLD | NEW |