| 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 |
| 11 namespace content { | 11 namespace content { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const int kClientId = 1; | 14 const int kClientId = 1; |
| 15 | 15 |
| 16 class GpuMemoryBufferImplTest | 16 class GpuMemoryBufferImplTest |
| 17 : public testing::TestWithParam<gfx::GpuMemoryBufferType> { | 17 : public testing::TestWithParam<gfx::GpuMemoryBufferType> { |
| 18 public: | 18 public: |
| 19 GpuMemoryBufferImplTest() : buffer_count_(0), factory_(nullptr) {} | 19 GpuMemoryBufferImplTest() : buffer_count_(0), factory_(nullptr) {} |
| 20 | 20 |
| 21 // Overridden from testing::Test: | 21 // Overridden from testing::Test: |
| 22 void SetUp() override { | 22 void SetUp() override { |
| 23 factory_ = GpuMemoryBufferFactory::Create(GetParam()); | 23 factory_ = GpuMemoryBufferFactory::Create(GetParam()); |
| 24 factory_->GetSupportedGpuMemoryBufferConfigurations( | 24 factory_->GetSupportedGpuMemoryBufferConfigurations( |
| 25 &supported_configurations_); | 25 &supported_configurations_); |
| 26 } | 26 } |
| 27 void TearDown() override { factory_.reset(); } | 27 void TearDown() override { factory_.reset(); } |
| 28 | 28 |
| 29 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( | 29 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 30 gfx::GpuMemoryBufferId id, | 30 const gfx::Size& size, |
| 31 const gfx::Size& size, | 31 gfx::BufferFormat format, |
| 32 gfx::GpuMemoryBuffer::Format format, | 32 gfx::BufferUsage usage) { |
| 33 gfx::GpuMemoryBuffer::Usage usage) { | |
| 34 ++buffer_count_; | 33 ++buffer_count_; |
| 35 return factory_->CreateGpuMemoryBuffer(id, size, format, usage, kClientId, | 34 return factory_->CreateGpuMemoryBuffer(id, size, format, usage, kClientId, |
| 36 gfx::kNullPluginWindow); | 35 gfx::kNullPluginWindow); |
| 37 } | 36 } |
| 38 | 37 |
| 39 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, uint32 sync_point) { | 38 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, uint32 sync_point) { |
| 40 factory_->DestroyGpuMemoryBuffer(id, kClientId); | 39 factory_->DestroyGpuMemoryBuffer(id, kClientId); |
| 41 DCHECK_GT(buffer_count_, 0); | 40 DCHECK_GT(buffer_count_, 0); |
| 42 --buffer_count_; | 41 --buffer_count_; |
| 43 } | 42 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 | 73 |
| 75 TEST_P(GpuMemoryBufferImplTest, Map) { | 74 TEST_P(GpuMemoryBufferImplTest, Map) { |
| 76 const int kBufferId = 1; | 75 const int kBufferId = 1; |
| 77 | 76 |
| 78 // 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. |
| 79 gfx::Size buffer_size(4, 4); | 78 gfx::Size buffer_size(4, 4); |
| 80 | 79 |
| 81 for (auto configuration : supported_configurations_) { | 80 for (auto configuration : supported_configurations_) { |
| 82 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) | 81 if (configuration.usage != gfx::BufferUsage::MAP) |
| 83 continue; | 82 continue; |
| 84 | 83 |
| 85 scoped_ptr<GpuMemoryBufferImpl> buffer( | 84 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 86 GpuMemoryBufferImpl::CreateFromHandle( | 85 GpuMemoryBufferImpl::CreateFromHandle( |
| 87 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, | 86 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| 88 configuration.usage), | 87 configuration.usage), |
| 89 buffer_size, configuration.format, configuration.usage, | 88 buffer_size, configuration.format, configuration.usage, |
| 90 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, | 89 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
| 91 base::Unretained(this), kBufferId))); | 90 base::Unretained(this), kBufferId))); |
| 92 ASSERT_TRUE(buffer); | 91 ASSERT_TRUE(buffer); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 | 136 |
| 138 TEST_P(GpuMemoryBufferImplTest, PersistentMap) { | 137 TEST_P(GpuMemoryBufferImplTest, PersistentMap) { |
| 139 const int kBufferId = 1; | 138 const int kBufferId = 1; |
| 140 | 139 |
| 141 // 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. |
| 142 gfx::Size buffer_size(4, 4); | 141 gfx::Size buffer_size(4, 4); |
| 143 | 142 |
| 144 for (auto configuration : supported_configurations_) { | 143 for (auto configuration : supported_configurations_) { |
| 145 if (configuration.usage != gfx::GpuMemoryBuffer::PERSISTENT_MAP) | 144 if (configuration.usage != gfx::BufferUsage::PERSISTENT_MAP) |
| 146 continue; | 145 continue; |
| 147 | 146 |
| 148 scoped_ptr<GpuMemoryBufferImpl> buffer( | 147 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 149 GpuMemoryBufferImpl::CreateFromHandle( | 148 GpuMemoryBufferImpl::CreateFromHandle( |
| 150 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, | 149 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| 151 configuration.usage), | 150 configuration.usage), |
| 152 buffer_size, configuration.format, configuration.usage, | 151 buffer_size, configuration.format, configuration.usage, |
| 153 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, | 152 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
| 154 base::Unretained(this), kBufferId))); | 153 base::Unretained(this), kBufferId))); |
| 155 ASSERT_TRUE(buffer); | 154 ASSERT_TRUE(buffer); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return supported_types; | 232 return supported_types; |
| 234 } | 233 } |
| 235 | 234 |
| 236 INSTANTIATE_TEST_CASE_P( | 235 INSTANTIATE_TEST_CASE_P( |
| 237 GpuMemoryBufferImplTests, | 236 GpuMemoryBufferImplTests, |
| 238 GpuMemoryBufferImplTest, | 237 GpuMemoryBufferImplTest, |
| 239 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); | 238 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); |
| 240 | 239 |
| 241 } // namespace | 240 } // namespace |
| 242 } // namespace content | 241 } // namespace content |
| OLD | NEW |