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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 scoped_ptr<void*[]> mapped_buffers(new void*[num_planes]); | 103 scoped_ptr<void*[]> mapped_buffers(new void*[num_planes]); |
104 bool rv = buffer->Map(mapped_buffers.get()); | 104 bool rv = buffer->Map(mapped_buffers.get()); |
105 ASSERT_TRUE(rv); | 105 ASSERT_TRUE(rv); |
106 EXPECT_TRUE(buffer->IsMapped()); | 106 EXPECT_TRUE(buffer->IsMapped()); |
107 | 107 |
108 // Get strides. | 108 // Get strides. |
109 scoped_ptr<int[]> strides(new int[num_planes]); | 109 scoped_ptr<int[]> strides(new int[num_planes]); |
110 buffer->GetStride(strides.get()); | 110 buffer->GetStride(strides.get()); |
111 | 111 |
112 // Copy and compare mapped buffers. | 112 // Copy and compare mapped buffers. |
113 for (size_t i = 0; i < num_planes; ++i) { | 113 for (size_t plane = 0; plane < num_planes; ++plane) { |
114 size_t width_in_bytes = 0u; | 114 size_t row_size_in_bytes = 0; |
115 EXPECT_TRUE(GpuMemoryBufferImpl::StrideInBytes( | 115 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes( |
116 buffer_size.width(), configuration.format, i, &width_in_bytes)); | 116 buffer_size.width(), configuration.format, plane, |
117 EXPECT_GT(width_in_bytes, 0u); | 117 &row_size_in_bytes)); |
118 EXPECT_GT(row_size_in_bytes, 0u); | |
118 | 119 |
119 scoped_ptr<char[]> data(new char[width_in_bytes]); | 120 scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
120 memset(data.get(), 0x2a + i, width_in_bytes); | 121 memset(data.get(), 0x2a + plane, row_size_in_bytes); |
121 memcpy(mapped_buffers[i], data.get(), width_in_bytes); | 122 |
122 EXPECT_EQ(memcmp(mapped_buffers[i], data.get(), width_in_bytes), 0); | 123 size_t height = |
124 buffer_size.height() / | |
125 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane); | |
126 for (size_t y = 0; y < height; ++y) { | |
127 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane], | |
128 data.get(), row_size_in_bytes); | |
129 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + | |
Daniele Castagna
2015/04/27 19:07:47
Not sure what you're testing here, just that copyi
reveman
2015/04/27 19:30:30
We're testing the storage and the memory mapping,
Daniele Castagna
2015/04/27 19:43:56
Just looking at the code, and seeing
memcpy(target
reveman
2015/04/27 20:28:08
It could crash and it could fail if there's someth
| |
130 y * strides[plane], | |
131 data.get(), row_size_in_bytes), | |
132 0); | |
133 } | |
123 } | 134 } |
124 | 135 |
125 buffer->Unmap(); | 136 buffer->Unmap(); |
126 EXPECT_FALSE(buffer->IsMapped()); | 137 EXPECT_FALSE(buffer->IsMapped()); |
127 } | 138 } |
128 } | 139 } |
129 | 140 |
130 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { | 141 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { |
131 std::vector<gfx::GpuMemoryBufferType> supported_types; | 142 std::vector<gfx::GpuMemoryBufferType> supported_types; |
132 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 143 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
133 return supported_types; | 144 return supported_types; |
134 } | 145 } |
135 | 146 |
136 INSTANTIATE_TEST_CASE_P( | 147 INSTANTIATE_TEST_CASE_P( |
137 GpuMemoryBufferImplTests, | 148 GpuMemoryBufferImplTests, |
138 GpuMemoryBufferImplTest, | 149 GpuMemoryBufferImplTest, |
139 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); | 150 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); |
140 | 151 |
141 } // namespace | 152 } // namespace |
142 } // namespace content | 153 } // namespace content |
OLD | NEW |