OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/buffer_manager.h" | 5 #include "gpu/command_buffer/service/buffer_manager.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace gpu { | 8 namespace gpu { |
9 namespace gles2 { | 9 namespace gles2 { |
10 | 10 |
11 class BufferManagerTest : public testing::Test { | 11 class BufferManagerTest : public testing::Test { |
12 public: | 12 public: |
13 BufferManagerTest() { | 13 BufferManagerTest() { |
14 } | 14 } |
15 | 15 |
16 protected: | 16 protected: |
17 virtual void SetUp() { | 17 virtual void SetUp() { |
18 } | 18 } |
19 | 19 |
20 virtual void TearDown() { | 20 virtual void TearDown() { |
21 } | 21 } |
22 | 22 |
23 BufferManager manager_; | 23 BufferManager manager_; |
24 }; | 24 }; |
25 | 25 |
26 TEST_F(BufferManagerTest, Basic) { | 26 TEST_F(BufferManagerTest, Basic) { |
27 const GLuint kBuffer1Id = 1; | 27 const GLuint kClientBuffer1Id = 1; |
| 28 const GLuint kServiceBuffer1Id = 11; |
28 const GLsizeiptr kBuffer1Size = 123; | 29 const GLsizeiptr kBuffer1Size = 123; |
29 const GLuint kBuffer2Id = 2; | 30 const GLuint kClientBuffer2Id = 2; |
30 // Check we can create buffer. | 31 // Check we can create buffer. |
31 manager_.CreateBufferInfo(kBuffer1Id); | 32 manager_.CreateBufferInfo(kClientBuffer1Id, kServiceBuffer1Id); |
32 // Check buffer got created. | 33 // Check buffer got created. |
33 BufferManager::BufferInfo* info1 = manager_.GetBufferInfo(kBuffer1Id); | 34 BufferManager::BufferInfo* info1 = manager_.GetBufferInfo(kClientBuffer1Id); |
34 ASSERT_TRUE(info1 != NULL); | 35 ASSERT_TRUE(info1 != NULL); |
35 EXPECT_EQ(0u, info1->target()); | 36 EXPECT_EQ(0u, info1->target()); |
36 EXPECT_EQ(0, info1->size()); | 37 EXPECT_EQ(0, info1->size()); |
37 EXPECT_FALSE(info1->IsDeleted()); | 38 EXPECT_FALSE(info1->IsDeleted()); |
38 EXPECT_EQ(kBuffer1Id, info1->buffer_id()); | 39 EXPECT_EQ(kServiceBuffer1Id, info1->service_id()); |
39 info1->set_target(GL_ELEMENT_ARRAY_BUFFER); | 40 info1->set_target(GL_ELEMENT_ARRAY_BUFFER); |
40 EXPECT_EQ(static_cast<GLenum>(GL_ELEMENT_ARRAY_BUFFER), info1->target()); | 41 EXPECT_EQ(static_cast<GLenum>(GL_ELEMENT_ARRAY_BUFFER), info1->target()); |
41 // Check we and set its size. | 42 // Check we and set its size. |
42 info1->SetSize(kBuffer1Size); | 43 info1->SetSize(kBuffer1Size); |
43 EXPECT_EQ(kBuffer1Size, info1->size()); | 44 EXPECT_EQ(kBuffer1Size, info1->size()); |
44 // Check we get nothing for a non-existent buffer. | 45 // Check we get nothing for a non-existent buffer. |
45 EXPECT_TRUE(manager_.GetBufferInfo(kBuffer2Id) == NULL); | 46 EXPECT_TRUE(manager_.GetBufferInfo(kClientBuffer2Id) == NULL); |
46 // Check trying to a remove non-existent buffers does not crash. | 47 // Check trying to a remove non-existent buffers does not crash. |
47 manager_.RemoveBufferInfo(kBuffer2Id); | 48 manager_.RemoveBufferInfo(kClientBuffer2Id); |
48 // Check we can't get the buffer after we remove it. | 49 // Check we can't get the buffer after we remove it. |
49 manager_.RemoveBufferInfo(kBuffer1Id); | 50 manager_.RemoveBufferInfo(kClientBuffer1Id); |
50 EXPECT_TRUE(manager_.GetBufferInfo(kBuffer1Id) == NULL); | 51 EXPECT_TRUE(manager_.GetBufferInfo(kClientBuffer1Id) == NULL); |
51 } | 52 } |
52 | 53 |
53 TEST_F(BufferManagerTest, SetRange) { | 54 TEST_F(BufferManagerTest, SetRange) { |
54 const GLuint kBufferId = 1; | 55 const GLuint kClientBufferId = 1; |
| 56 const GLuint kServiceBufferId = 11; |
55 const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; | 57 const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; |
56 manager_.CreateBufferInfo(kBufferId); | 58 manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); |
57 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); | 59 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); |
58 ASSERT_TRUE(info != NULL); | 60 ASSERT_TRUE(info != NULL); |
59 info->set_target(GL_ELEMENT_ARRAY_BUFFER); | 61 info->set_target(GL_ELEMENT_ARRAY_BUFFER); |
60 info->SetSize(sizeof(data)); | 62 info->SetSize(sizeof(data)); |
61 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); | 63 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); |
62 EXPECT_TRUE(info->SetRange(sizeof(data), 0, data)); | 64 EXPECT_TRUE(info->SetRange(sizeof(data), 0, data)); |
63 EXPECT_FALSE(info->SetRange(sizeof(data), 1, data)); | 65 EXPECT_FALSE(info->SetRange(sizeof(data), 1, data)); |
64 EXPECT_FALSE(info->SetRange(0, sizeof(data) + 1, data)); | 66 EXPECT_FALSE(info->SetRange(0, sizeof(data) + 1, data)); |
65 } | 67 } |
66 | 68 |
67 TEST_F(BufferManagerTest, GetMaxValueForRangeUint8) { | 69 TEST_F(BufferManagerTest, GetMaxValueForRangeUint8) { |
68 const GLuint kBufferId = 1; | 70 const GLuint kClientBufferId = 1; |
| 71 const GLuint kServiceBufferId = 11; |
69 const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; | 72 const uint8 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; |
70 const uint8 new_data[] = {100, 120, 110}; | 73 const uint8 new_data[] = {100, 120, 110}; |
71 manager_.CreateBufferInfo(kBufferId); | 74 manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); |
72 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); | 75 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); |
73 ASSERT_TRUE(info != NULL); | 76 ASSERT_TRUE(info != NULL); |
74 info->set_target(GL_ELEMENT_ARRAY_BUFFER); | 77 info->set_target(GL_ELEMENT_ARRAY_BUFFER); |
75 info->SetSize(sizeof(data)); | 78 info->SetSize(sizeof(data)); |
76 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); | 79 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); |
77 GLuint max_value; | 80 GLuint max_value; |
78 // Check entire range succeeds. | 81 // Check entire range succeeds. |
79 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_BYTE, &max_value)); | 82 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_BYTE, &max_value)); |
80 EXPECT_EQ(10u, max_value); | 83 EXPECT_EQ(10u, max_value); |
81 // Check sub range succeeds. | 84 // Check sub range succeeds. |
82 EXPECT_TRUE(info->GetMaxValueForRange(4, 3, GL_UNSIGNED_BYTE, &max_value)); | 85 EXPECT_TRUE(info->GetMaxValueForRange(4, 3, GL_UNSIGNED_BYTE, &max_value)); |
83 EXPECT_EQ(6u, max_value); | 86 EXPECT_EQ(6u, max_value); |
84 // Check changing sub range succeeds. | 87 // Check changing sub range succeeds. |
85 EXPECT_TRUE(info->SetRange(4, sizeof(new_data), new_data)); | 88 EXPECT_TRUE(info->SetRange(4, sizeof(new_data), new_data)); |
86 EXPECT_TRUE(info->GetMaxValueForRange(4, 3, GL_UNSIGNED_BYTE, &max_value)); | 89 EXPECT_TRUE(info->GetMaxValueForRange(4, 3, GL_UNSIGNED_BYTE, &max_value)); |
87 EXPECT_EQ(120u, max_value); | 90 EXPECT_EQ(120u, max_value); |
88 max_value = 0; | 91 max_value = 0; |
89 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_BYTE, &max_value)); | 92 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_BYTE, &max_value)); |
90 EXPECT_EQ(120u, max_value); | 93 EXPECT_EQ(120u, max_value); |
91 // Check out of range fails. | 94 // Check out of range fails. |
92 EXPECT_FALSE(info->GetMaxValueForRange(0, 11, GL_UNSIGNED_BYTE, &max_value)); | 95 EXPECT_FALSE(info->GetMaxValueForRange(0, 11, GL_UNSIGNED_BYTE, &max_value)); |
93 EXPECT_FALSE(info->GetMaxValueForRange(10, 1, GL_UNSIGNED_BYTE, &max_value)); | 96 EXPECT_FALSE(info->GetMaxValueForRange(10, 1, GL_UNSIGNED_BYTE, &max_value)); |
94 } | 97 } |
95 | 98 |
96 TEST_F(BufferManagerTest, GetMaxValueForRangeUint16) { | 99 TEST_F(BufferManagerTest, GetMaxValueForRangeUint16) { |
97 const GLuint kBufferId = 1; | 100 const GLuint kClientBufferId = 1; |
| 101 const GLuint kServiceBufferId = 11; |
98 const uint16 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; | 102 const uint16 data[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; |
99 const uint16 new_data[] = {100, 120, 110}; | 103 const uint16 new_data[] = {100, 120, 110}; |
100 manager_.CreateBufferInfo(kBufferId); | 104 manager_.CreateBufferInfo(kClientBufferId, kServiceBufferId); |
101 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kBufferId); | 105 BufferManager::BufferInfo* info = manager_.GetBufferInfo(kClientBufferId); |
102 ASSERT_TRUE(info != NULL); | 106 ASSERT_TRUE(info != NULL); |
103 info->set_target(GL_ELEMENT_ARRAY_BUFFER); | 107 info->set_target(GL_ELEMENT_ARRAY_BUFFER); |
104 info->SetSize(sizeof(data)); | 108 info->SetSize(sizeof(data)); |
105 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); | 109 EXPECT_TRUE(info->SetRange(0, sizeof(data), data)); |
106 GLuint max_value; | 110 GLuint max_value; |
107 // Check entire range succeeds. | 111 // Check entire range succeeds. |
108 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_SHORT, &max_value)); | 112 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_SHORT, &max_value)); |
109 EXPECT_EQ(10u, max_value); | 113 EXPECT_EQ(10u, max_value); |
110 // Check odd offset fails for GL_UNSIGNED_SHORT. | 114 // Check odd offset fails for GL_UNSIGNED_SHORT. |
111 EXPECT_FALSE(info->GetMaxValueForRange(1, 10, GL_UNSIGNED_SHORT, &max_value)); | 115 EXPECT_FALSE(info->GetMaxValueForRange(1, 10, GL_UNSIGNED_SHORT, &max_value)); |
112 // Check sub range succeeds. | 116 // Check sub range succeeds. |
113 EXPECT_TRUE(info->GetMaxValueForRange(8, 3, GL_UNSIGNED_SHORT, &max_value)); | 117 EXPECT_TRUE(info->GetMaxValueForRange(8, 3, GL_UNSIGNED_SHORT, &max_value)); |
114 EXPECT_EQ(6u, max_value); | 118 EXPECT_EQ(6u, max_value); |
115 // Check changing sub range succeeds. | 119 // Check changing sub range succeeds. |
116 EXPECT_TRUE(info->SetRange(8, sizeof(new_data), new_data)); | 120 EXPECT_TRUE(info->SetRange(8, sizeof(new_data), new_data)); |
117 EXPECT_TRUE(info->GetMaxValueForRange(8, 3, GL_UNSIGNED_SHORT, &max_value)); | 121 EXPECT_TRUE(info->GetMaxValueForRange(8, 3, GL_UNSIGNED_SHORT, &max_value)); |
118 EXPECT_EQ(120u, max_value); | 122 EXPECT_EQ(120u, max_value); |
119 max_value = 0; | 123 max_value = 0; |
120 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_SHORT, &max_value)); | 124 EXPECT_TRUE(info->GetMaxValueForRange(0, 10, GL_UNSIGNED_SHORT, &max_value)); |
121 EXPECT_EQ(120u, max_value); | 125 EXPECT_EQ(120u, max_value); |
122 // Check out of range fails. | 126 // Check out of range fails. |
123 EXPECT_FALSE(info->GetMaxValueForRange(0, 11, GL_UNSIGNED_SHORT, &max_value)); | 127 EXPECT_FALSE(info->GetMaxValueForRange(0, 11, GL_UNSIGNED_SHORT, &max_value)); |
124 EXPECT_FALSE(info->GetMaxValueForRange(20, 1, GL_UNSIGNED_SHORT, &max_value)); | 128 EXPECT_FALSE(info->GetMaxValueForRange(20, 1, GL_UNSIGNED_SHORT, &max_value)); |
125 } | 129 } |
126 | 130 |
127 } // namespace gles2 | 131 } // namespace gles2 |
128 } // namespace gpu | 132 } // namespace gpu |
129 | 133 |
130 | 134 |
OLD | NEW |