| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gpu/command_buffer/service/valuebuffer_manager.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "gpu/command_buffer/common/gles2_cmd_format.h" | |
| 12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
| 13 #include "gpu/command_buffer/common/value_state.h" | |
| 14 #include "gpu/command_buffer/service/common_decoder.h" | |
| 15 #include "gpu/command_buffer/service/feature_info.h" | |
| 16 #include "gpu/command_buffer/service/gpu_service_test.h" | |
| 17 #include "gpu/command_buffer/service/mocks.h" | |
| 18 #include "gpu/command_buffer/service/test_helper.h" | |
| 19 #include "testing/gmock/include/gmock/gmock.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 #include "ui/gl/gl_bindings.h" | |
| 22 #include "ui/gl/gl_mock.h" | |
| 23 | |
| 24 namespace gpu { | |
| 25 namespace gles2 { | |
| 26 | |
| 27 class MockSubscriptionRefSetObserver : public SubscriptionRefSet::Observer { | |
| 28 public: | |
| 29 MOCK_METHOD1(OnAddSubscription, void(unsigned int target)); | |
| 30 MOCK_METHOD1(OnRemoveSubscription, void(unsigned int target)); | |
| 31 }; | |
| 32 | |
| 33 class ValuebufferManagerTest : public GpuServiceTest { | |
| 34 public: | |
| 35 ValuebufferManagerTest() {} | |
| 36 ~ValuebufferManagerTest() override {} | |
| 37 | |
| 38 void SetUp() override { | |
| 39 GpuServiceTest::SetUp(); | |
| 40 subscription_ref_set_ = new SubscriptionRefSet(); | |
| 41 pending_state_map_ = new ValueStateMap(); | |
| 42 subscription_ref_set_->AddObserver(&mock_observer_); | |
| 43 manager_.reset(new ValuebufferManager(subscription_ref_set_.get(), | |
| 44 pending_state_map_.get())); | |
| 45 } | |
| 46 | |
| 47 void TearDown() override { | |
| 48 manager_->Destroy(); | |
| 49 subscription_ref_set_->RemoveObserver(&mock_observer_); | |
| 50 GpuServiceTest::TearDown(); | |
| 51 } | |
| 52 | |
| 53 protected: | |
| 54 MockSubscriptionRefSetObserver mock_observer_; | |
| 55 | |
| 56 scoped_refptr<SubscriptionRefSet> subscription_ref_set_; | |
| 57 scoped_refptr<ValueStateMap> pending_state_map_; | |
| 58 std::unique_ptr<ValuebufferManager> manager_; | |
| 59 }; | |
| 60 | |
| 61 TEST_F(ValuebufferManagerTest, Basic) { | |
| 62 const GLuint kClient1Id = 1; | |
| 63 const GLuint kClient2Id = 2; | |
| 64 // Check we can create a Valuebuffer | |
| 65 manager_->CreateValuebuffer(kClient1Id); | |
| 66 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); | |
| 67 ASSERT_TRUE(valuebuffer0 != NULL); | |
| 68 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | |
| 69 // Check we get nothing for a non-existent Valuebuffer. | |
| 70 // Check trying to a remove non-existent Valuebuffer does not crash | |
| 71 manager_->RemoveValuebuffer(kClient2Id); | |
| 72 // Check we can't get the renderbuffer after we remove it. | |
| 73 manager_->RemoveValuebuffer(kClient1Id); | |
| 74 EXPECT_TRUE(manager_->GetValuebuffer(kClient1Id) == NULL); | |
| 75 } | |
| 76 | |
| 77 TEST_F(ValuebufferManagerTest, Destroy) { | |
| 78 const GLuint kClient1Id = 1; | |
| 79 // Check we can create Valuebuffer. | |
| 80 manager_->CreateValuebuffer(kClient1Id); | |
| 81 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); | |
| 82 ASSERT_TRUE(valuebuffer0 != NULL); | |
| 83 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | |
| 84 manager_->Destroy(); | |
| 85 // Check the resources were released. | |
| 86 Valuebuffer* valuebuffer1 = manager_->GetValuebuffer(kClient1Id); | |
| 87 ASSERT_TRUE(valuebuffer1 == NULL); | |
| 88 } | |
| 89 | |
| 90 TEST_F(ValuebufferManagerTest, ValueBuffer) { | |
| 91 const GLuint kClient1Id = 1; | |
| 92 // Check we can create a Valuebuffer | |
| 93 manager_->CreateValuebuffer(kClient1Id); | |
| 94 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); | |
| 95 ASSERT_TRUE(valuebuffer0 != NULL); | |
| 96 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | |
| 97 EXPECT_FALSE(valuebuffer0->IsValid()); | |
| 98 } | |
| 99 | |
| 100 TEST_F(ValuebufferManagerTest, UpdateState) { | |
| 101 const GLuint kClient1Id = 1; | |
| 102 ValueState valuestate1; | |
| 103 valuestate1.int_value[0] = 111; | |
| 104 ValueState valuestate2; | |
| 105 valuestate2.int_value[0] = 222; | |
| 106 manager_->CreateValuebuffer(kClient1Id); | |
| 107 Valuebuffer* valuebuffer0 = manager_->GetValuebuffer(kClient1Id); | |
| 108 ASSERT_TRUE(valuebuffer0 != NULL); | |
| 109 EXPECT_EQ(kClient1Id, valuebuffer0->client_id()); | |
| 110 valuebuffer0->AddSubscription(GL_MOUSE_POSITION_CHROMIUM); | |
| 111 ASSERT_TRUE(valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM) == NULL); | |
| 112 pending_state_map_->UpdateState(GL_MOUSE_POSITION_CHROMIUM, valuestate1); | |
| 113 manager_->UpdateValuebufferState(valuebuffer0); | |
| 114 const ValueState* new_state1 = | |
| 115 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); | |
| 116 ASSERT_TRUE(new_state1 != NULL); | |
| 117 ASSERT_TRUE(new_state1->int_value[0] == 111); | |
| 118 // Ensure state changes | |
| 119 pending_state_map_->UpdateState(GL_MOUSE_POSITION_CHROMIUM, valuestate2); | |
| 120 manager_->UpdateValuebufferState(valuebuffer0); | |
| 121 const ValueState* new_state2 = | |
| 122 valuebuffer0->GetState(GL_MOUSE_POSITION_CHROMIUM); | |
| 123 ASSERT_TRUE(new_state2 != NULL); | |
| 124 ASSERT_TRUE(new_state2->int_value[0] == 222); | |
| 125 } | |
| 126 | |
| 127 TEST_F(ValuebufferManagerTest, NotifySubscriptionRefs) { | |
| 128 const GLuint kClientId1 = 1; | |
| 129 const GLuint kClientId2 = 2; | |
| 130 manager_->CreateValuebuffer(kClientId1); | |
| 131 Valuebuffer* valuebuffer1 = manager_->GetValuebuffer(kClientId1); | |
| 132 ASSERT_TRUE(valuebuffer1 != NULL); | |
| 133 manager_->CreateValuebuffer(kClientId2); | |
| 134 Valuebuffer* valuebuffer2 = manager_->GetValuebuffer(kClientId2); | |
| 135 ASSERT_TRUE(valuebuffer2 != NULL); | |
| 136 EXPECT_CALL(mock_observer_, OnAddSubscription(GL_MOUSE_POSITION_CHROMIUM)) | |
| 137 .Times(1); | |
| 138 valuebuffer1->AddSubscription(GL_MOUSE_POSITION_CHROMIUM); | |
| 139 EXPECT_CALL(mock_observer_, OnAddSubscription(GL_MOUSE_POSITION_CHROMIUM)) | |
| 140 .Times(0); | |
| 141 valuebuffer2->AddSubscription(GL_MOUSE_POSITION_CHROMIUM); | |
| 142 EXPECT_CALL(mock_observer_, OnRemoveSubscription(GL_MOUSE_POSITION_CHROMIUM)) | |
| 143 .Times(0); | |
| 144 valuebuffer1->RemoveSubscription(GL_MOUSE_POSITION_CHROMIUM); | |
| 145 // Ensure the manager still thinks a buffer has a reference to the | |
| 146 // subscription target. | |
| 147 EXPECT_CALL(mock_observer_, OnRemoveSubscription(GL_MOUSE_POSITION_CHROMIUM)) | |
| 148 .Times(1); | |
| 149 valuebuffer2->RemoveSubscription(GL_MOUSE_POSITION_CHROMIUM); | |
| 150 } | |
| 151 | |
| 152 } // namespace gles2 | |
| 153 } // namespace gpu | |
| OLD | NEW |