| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; | 44 std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; |
| 45 int buffer_count_; | 45 int buffer_count_; |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 scoped_ptr<GpuMemoryBufferFactory> factory_; | 48 scoped_ptr<GpuMemoryBufferFactory> factory_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { | 51 TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { |
| 52 const int kBufferId = 1; | 52 const gfx::GpuMemoryBufferId kBufferId(1); |
| 53 | 53 |
| 54 gfx::Size buffer_size(8, 8); | 54 gfx::Size buffer_size(8, 8); |
| 55 | 55 |
| 56 for (auto configuration : supported_configurations_) { | 56 for (auto configuration : supported_configurations_) { |
| 57 scoped_ptr<GpuMemoryBufferImpl> buffer( | 57 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 58 GpuMemoryBufferImpl::CreateFromHandle( | 58 GpuMemoryBufferImpl::CreateFromHandle( |
| 59 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, | 59 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| 60 configuration.usage), | 60 configuration.usage), |
| 61 buffer_size, configuration.format, configuration.usage, | 61 buffer_size, configuration.format, configuration.usage, |
| 62 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, | 62 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
| 63 base::Unretained(this), kBufferId))); | 63 base::Unretained(this), kBufferId))); |
| 64 EXPECT_EQ(1, buffer_count_); | 64 EXPECT_EQ(1, buffer_count_); |
| 65 ASSERT_TRUE(buffer); | 65 ASSERT_TRUE(buffer); |
| 66 EXPECT_EQ(buffer->GetFormat(), configuration.format); | 66 EXPECT_EQ(buffer->GetFormat(), configuration.format); |
| 67 | 67 |
| 68 // Check if destruction callback is executed when deleting the buffer. | 68 // Check if destruction callback is executed when deleting the buffer. |
| 69 buffer.reset(); | 69 buffer.reset(); |
| 70 EXPECT_EQ(0, buffer_count_); | 70 EXPECT_EQ(0, buffer_count_); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST_P(GpuMemoryBufferImplTest, Map) { | 74 TEST_P(GpuMemoryBufferImplTest, Map) { |
| 75 const int kBufferId = 1; | 75 const gfx::GpuMemoryBufferId kBufferId(1); |
| 76 | 76 |
| 77 // Use a multiple of 4 for both dimensions to support compressed formats. | 77 // Use a multiple of 4 for both dimensions to support compressed formats. |
| 78 gfx::Size buffer_size(4, 4); | 78 gfx::Size buffer_size(4, 4); |
| 79 | 79 |
| 80 for (auto configuration : supported_configurations_) { | 80 for (auto configuration : supported_configurations_) { |
| 81 if (configuration.usage != gfx::BufferUsage::MAP) | 81 if (configuration.usage != gfx::BufferUsage::MAP) |
| 82 continue; | 82 continue; |
| 83 | 83 |
| 84 scoped_ptr<GpuMemoryBufferImpl> buffer( | 84 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 85 GpuMemoryBufferImpl::CreateFromHandle( | 85 GpuMemoryBufferImpl::CreateFromHandle( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 0); | 128 0); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 buffer->Unmap(); | 132 buffer->Unmap(); |
| 133 EXPECT_FALSE(buffer->IsMapped()); | 133 EXPECT_FALSE(buffer->IsMapped()); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 TEST_P(GpuMemoryBufferImplTest, PersistentMap) { | 137 TEST_P(GpuMemoryBufferImplTest, PersistentMap) { |
| 138 const int kBufferId = 1; | 138 const gfx::GpuMemoryBufferId kBufferId(1); |
| 139 | 139 |
| 140 // Use a multiple of 4 for both dimensions to support compressed formats. | 140 // Use a multiple of 4 for both dimensions to support compressed formats. |
| 141 gfx::Size buffer_size(4, 4); | 141 gfx::Size buffer_size(4, 4); |
| 142 | 142 |
| 143 for (auto configuration : supported_configurations_) { | 143 for (auto configuration : supported_configurations_) { |
| 144 if (configuration.usage != gfx::BufferUsage::PERSISTENT_MAP) | 144 if (configuration.usage != gfx::BufferUsage::PERSISTENT_MAP) |
| 145 continue; | 145 continue; |
| 146 | 146 |
| 147 scoped_ptr<GpuMemoryBufferImpl> buffer( | 147 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 148 GpuMemoryBufferImpl::CreateFromHandle( | 148 GpuMemoryBufferImpl::CreateFromHandle( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return supported_types; | 232 return supported_types; |
| 233 } | 233 } |
| 234 | 234 |
| 235 INSTANTIATE_TEST_CASE_P( | 235 INSTANTIATE_TEST_CASE_P( |
| 236 GpuMemoryBufferImplTests, | 236 GpuMemoryBufferImplTests, |
| 237 GpuMemoryBufferImplTest, | 237 GpuMemoryBufferImplTest, |
| 238 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); | 238 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); |
| 239 | 239 |
| 240 } // namespace | 240 } // namespace |
| 241 } // namespace content | 241 } // namespace content |
| OLD | NEW |