OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 8 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; | 45 std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; |
46 int buffer_count_; | 46 int buffer_count_; |
47 | 47 |
48 private: | 48 private: |
49 scoped_ptr<GpuMemoryBufferFactory> factory_; | 49 scoped_ptr<GpuMemoryBufferFactory> factory_; |
50 }; | 50 }; |
51 | 51 |
52 TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { | 52 TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { |
53 const int kBufferId = 1; | 53 const int kBufferId = 1; |
54 | 54 |
55 gfx::Size buffer_size(1, 1); | 55 gfx::Size buffer_size(8, 8); |
56 | 56 |
57 for (auto configuration : supported_configurations_) { | 57 for (auto configuration : supported_configurations_) { |
58 scoped_ptr<GpuMemoryBufferImpl> buffer( | 58 scoped_ptr<GpuMemoryBufferImpl> buffer( |
59 GpuMemoryBufferImpl::CreateFromHandle( | 59 GpuMemoryBufferImpl::CreateFromHandle( |
60 CreateGpuMemoryBuffer(kBufferId, | 60 CreateGpuMemoryBuffer(kBufferId, |
61 buffer_size, | 61 buffer_size, |
62 configuration.format, | 62 configuration.format, |
63 configuration.usage), | 63 configuration.usage), |
64 buffer_size, | 64 buffer_size, |
65 configuration.format, | 65 configuration.format, |
66 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, | 66 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
67 base::Unretained(this), | 67 base::Unretained(this), |
68 kBufferId))); | 68 kBufferId))); |
69 EXPECT_EQ(1, buffer_count_); | 69 EXPECT_EQ(1, buffer_count_); |
70 ASSERT_TRUE(buffer); | 70 ASSERT_TRUE(buffer); |
71 EXPECT_EQ(buffer->GetFormat(), configuration.format); | 71 EXPECT_EQ(buffer->GetFormat(), configuration.format); |
72 | 72 |
73 // Check if destruction callback is executed when deleting the buffer. | 73 // Check if destruction callback is executed when deleting the buffer. |
74 buffer.reset(); | 74 buffer.reset(); |
75 EXPECT_EQ(0, buffer_count_); | 75 EXPECT_EQ(0, buffer_count_); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 TEST_P(GpuMemoryBufferImplTest, Map) { | 79 TEST_P(GpuMemoryBufferImplTest, Map) { |
80 const int kBufferId = 1; | 80 const int kBufferId = 1; |
81 | 81 |
82 gfx::Size buffer_size(1, 1); | 82 gfx::Size buffer_size(8, 8); |
83 | 83 |
84 for (auto configuration : supported_configurations_) { | 84 for (auto configuration : supported_configurations_) { |
85 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) | 85 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) |
86 continue; | 86 continue; |
87 | 87 |
88 size_t width_in_bytes = 0; | 88 size_t num_planes = |
89 EXPECT_TRUE(GpuMemoryBufferImpl::StrideInBytes( | 89 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
90 buffer_size.width(), configuration.format, &width_in_bytes)); | 90 configuration.format); |
91 EXPECT_GT(width_in_bytes, 0u); | 91 |
92 scoped_ptr<char[]> data(new char[width_in_bytes]); | 92 // Alocate buffers for each plane. |
93 memset(data.get(), 0x2a, width_in_bytes); | 93 std::vector<scoped_ptr<char[]>> data; |
94 std::vector<size_t> width_in_bytes; | |
95 for (size_t i = 0; i < num_planes; ++i) { | |
96 size_t width = 0u; | |
97 EXPECT_TRUE(GpuMemoryBufferImpl::StrideInBytes( | |
98 buffer_size.width(), configuration.format, i, &width)); | |
99 EXPECT_GT(width, 0u); | |
100 data.push_back(scoped_ptr<char[]>(new char[width])); | |
101 memset(data[i].get(), i, width); | |
102 width_in_bytes.push_back(width); | |
103 } | |
reveman
2015/04/07 19:03:25
line 88-103: this doesn't need to be done here. I
emircan
2015/04/07 20:08:12
Done.
| |
94 | 104 |
95 scoped_ptr<GpuMemoryBufferImpl> buffer( | 105 scoped_ptr<GpuMemoryBufferImpl> buffer( |
96 GpuMemoryBufferImpl::CreateFromHandle( | 106 GpuMemoryBufferImpl::CreateFromHandle( |
97 CreateGpuMemoryBuffer(kBufferId, | 107 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
98 buffer_size, | |
99 configuration.format, | |
100 configuration.usage), | 108 configuration.usage), |
101 buffer_size, | 109 buffer_size, configuration.format, |
102 configuration.format, | |
103 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, | 110 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
104 base::Unretained(this), | 111 base::Unretained(this), kBufferId))); |
105 kBufferId))); | |
106 ASSERT_TRUE(buffer); | 112 ASSERT_TRUE(buffer); |
107 EXPECT_FALSE(buffer->IsMapped()); | 113 EXPECT_FALSE(buffer->IsMapped()); |
108 | 114 |
109 void* memory; | 115 // Map buffer into user space. |
110 bool rv = buffer->Map(&memory); | 116 void* mapped_buffers[num_planes]; |
117 bool rv = buffer->Map(mapped_buffers); | |
111 ASSERT_TRUE(rv); | 118 ASSERT_TRUE(rv); |
112 EXPECT_TRUE(buffer->IsMapped()); | 119 EXPECT_TRUE(buffer->IsMapped()); |
113 uint32 stride; | 120 |
114 buffer->GetStride(&stride); | 121 // Get strides. |
115 EXPECT_GE(stride, width_in_bytes); | 122 uint32 strides[num_planes]; |
116 memcpy(memory, data.get(), width_in_bytes); | 123 buffer->GetStride(strides); |
117 EXPECT_EQ(memcmp(memory, data.get(), width_in_bytes), 0); | 124 |
125 // Copy and compare mapped buffers. | |
126 for (size_t i = 0; i < num_planes; ++i) { | |
127 EXPECT_GE(strides[i], width_in_bytes[i]); | |
128 memcpy(mapped_buffers[i], data[i].get(), width_in_bytes[i]); | |
129 EXPECT_EQ(memcmp(mapped_buffers[i], data[i].get(), width_in_bytes[i]), 0); | |
130 } | |
131 | |
118 buffer->Unmap(); | 132 buffer->Unmap(); |
119 EXPECT_FALSE(buffer->IsMapped()); | 133 EXPECT_FALSE(buffer->IsMapped()); |
120 } | 134 } |
121 } | 135 } |
122 | 136 |
123 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { | 137 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { |
124 std::vector<gfx::GpuMemoryBufferType> supported_types; | 138 std::vector<gfx::GpuMemoryBufferType> supported_types; |
125 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 139 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
126 return supported_types; | 140 return supported_types; |
127 } | 141 } |
128 | 142 |
129 INSTANTIATE_TEST_CASE_P( | 143 INSTANTIATE_TEST_CASE_P( |
130 GpuMemoryBufferImplTests, | 144 GpuMemoryBufferImplTests, |
131 GpuMemoryBufferImplTest, | 145 GpuMemoryBufferImplTest, |
132 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); | 146 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); |
133 | 147 |
134 } // namespace | 148 } // namespace |
135 } // namespace content | 149 } // namespace content |
OLD | NEW |