| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file defines tests that implementations of GpuMemoryBufferFactory should | 5 // This file defines tests that implementations of GpuMemoryBufferFactory should |
| 6 // pass in order to be conformant. | 6 // pass in order to be conformant. |
| 7 | 7 |
| 8 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ | 8 #ifndef GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ |
| 9 #define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ | 9 #define GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ |
| 10 | 10 |
| 11 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 11 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| 12 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 12 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/buffer_format_util.h" | 14 #include "ui/gfx/buffer_format_util.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace gpu { |
| 17 | 17 |
| 18 template <typename GpuMemoryBufferFactoryType> | 18 template <typename GpuMemoryBufferFactoryType> |
| 19 class GpuMemoryBufferFactoryTest : public testing::Test { | 19 class GpuMemoryBufferFactoryTest : public testing::Test { |
| 20 protected: | 20 protected: |
| 21 GpuMemoryBufferFactoryType factory_; | 21 GpuMemoryBufferFactoryType factory_; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 TYPED_TEST_CASE_P(GpuMemoryBufferFactoryTest); | 24 TYPED_TEST_CASE_P(GpuMemoryBufferFactoryTest); |
| 25 | 25 |
| 26 TYPED_TEST_P(GpuMemoryBufferFactoryTest, CreateGpuMemoryBuffer) { | 26 TYPED_TEST_P(GpuMemoryBufferFactoryTest, CreateGpuMemoryBuffer) { |
| 27 const gfx::GpuMemoryBufferId kBufferId(1); | 27 const gfx::GpuMemoryBufferId kBufferId(1); |
| 28 const int kClientId = 1; | 28 const int kClientId = 1; |
| 29 | 29 |
| 30 gfx::Size buffer_size(2, 2); | 30 gfx::Size buffer_size(2, 2); |
| 31 | 31 |
| 32 for (auto format : gfx::GetBufferFormatsForTesting()) { | 32 for (auto format : gfx::GetBufferFormatsForTesting()) { |
| 33 gfx::BufferUsage usages[] = { | 33 gfx::BufferUsage usages[] = { |
| 34 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, | 34 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, |
| 35 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 35 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 36 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; | 36 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; |
| 37 for (auto usage : usages) { | 37 for (auto usage : usages) { |
| 38 if (!gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | 38 if (!IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 39 continue; | 39 continue; |
| 40 | 40 |
| 41 gfx::GpuMemoryBufferHandle handle = | 41 gfx::GpuMemoryBufferHandle handle = |
| 42 TestFixture::factory_.CreateGpuMemoryBuffer(kBufferId, buffer_size, | 42 TestFixture::factory_.CreateGpuMemoryBuffer(kBufferId, buffer_size, |
| 43 format, usage, kClientId, | 43 format, usage, kClientId, |
| 44 gfx::kNullPluginWindow); | 44 gfx::kNullPluginWindow); |
| 45 EXPECT_NE(handle.type, gfx::EMPTY_BUFFER); | 45 EXPECT_NE(handle.type, gfx::EMPTY_BUFFER); |
| 46 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId, kClientId); | 46 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId, kClientId); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 // The GpuMemoryBufferFactoryTest test case verifies behavior that is expected | 51 // The GpuMemoryBufferFactoryTest test case verifies behavior that is expected |
| 52 // from a GpuMemoryBuffer factory in order to be conformant. | 52 // from a GpuMemoryBuffer factory in order to be conformant. |
| 53 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferFactoryTest, CreateGpuMemoryBuffer); | 53 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferFactoryTest, CreateGpuMemoryBuffer); |
| 54 | 54 |
| 55 template <typename GpuMemoryBufferFactoryType> | 55 template <typename GpuMemoryBufferFactoryType> |
| 56 class GpuMemoryBufferFactoryImportTest | 56 class GpuMemoryBufferFactoryImportTest |
| 57 : public GpuMemoryBufferFactoryTest<GpuMemoryBufferFactoryType> {}; | 57 : public GpuMemoryBufferFactoryTest<GpuMemoryBufferFactoryType> {}; |
| 58 | 58 |
| 59 TYPED_TEST_CASE_P(GpuMemoryBufferFactoryImportTest); | 59 TYPED_TEST_CASE_P(GpuMemoryBufferFactoryImportTest); |
| 60 | 60 |
| 61 TYPED_TEST_P(GpuMemoryBufferFactoryImportTest, | 61 TYPED_TEST_P(GpuMemoryBufferFactoryImportTest, |
| 62 CreateGpuMemoryBufferFromHandle) { | 62 CreateGpuMemoryBufferFromHandle) { |
| 63 const int kClientId = 1; | 63 const int kClientId = 1; |
| 64 | 64 |
| 65 gfx::Size buffer_size(2, 2); | 65 gfx::Size buffer_size(2, 2); |
| 66 | 66 |
| 67 for (auto format : gfx::GetBufferFormatsForTesting()) { | 67 for (auto format : gfx::GetBufferFormatsForTesting()) { |
| 68 if (!gpu::IsNativeGpuMemoryBufferConfigurationSupported( | 68 if (!IsNativeGpuMemoryBufferConfigurationSupported( |
| 69 format, gfx::BufferUsage::GPU_READ)) { | 69 format, gfx::BufferUsage::GPU_READ)) { |
| 70 continue; | 70 continue; |
| 71 } | 71 } |
| 72 | 72 |
| 73 const gfx::GpuMemoryBufferId kBufferId1(1); | 73 const gfx::GpuMemoryBufferId kBufferId1(1); |
| 74 gfx::GpuMemoryBufferHandle handle1 = | 74 gfx::GpuMemoryBufferHandle handle1 = |
| 75 TestFixture::factory_.CreateGpuMemoryBuffer( | 75 TestFixture::factory_.CreateGpuMemoryBuffer( |
| 76 kBufferId1, buffer_size, format, gfx::BufferUsage::GPU_READ, | 76 kBufferId1, buffer_size, format, gfx::BufferUsage::GPU_READ, |
| 77 kClientId, gfx::kNullPluginWindow); | 77 kClientId, gfx::kNullPluginWindow); |
| 78 EXPECT_NE(handle1.type, gfx::EMPTY_BUFFER); | 78 EXPECT_NE(handle1.type, gfx::EMPTY_BUFFER); |
| 79 | 79 |
| 80 // Create new buffer from |handle1|. | 80 // Create new buffer from |handle1|. |
| 81 const gfx::GpuMemoryBufferId kBufferId2(2); | 81 const gfx::GpuMemoryBufferId kBufferId2(2); |
| 82 gfx::GpuMemoryBufferHandle handle2 = | 82 gfx::GpuMemoryBufferHandle handle2 = |
| 83 TestFixture::factory_.CreateGpuMemoryBufferFromHandle( | 83 TestFixture::factory_.CreateGpuMemoryBufferFromHandle( |
| 84 handle1, kBufferId2, buffer_size, format, kClientId); | 84 handle1, kBufferId2, buffer_size, format, kClientId); |
| 85 EXPECT_NE(handle2.type, gfx::EMPTY_BUFFER); | 85 EXPECT_NE(handle2.type, gfx::EMPTY_BUFFER); |
| 86 | 86 |
| 87 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId1, kClientId); | 87 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId1, kClientId); |
| 88 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId2, kClientId); | 88 TestFixture::factory_.DestroyGpuMemoryBuffer(kBufferId2, kClientId); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 // The GpuMemoryBufferFactoryImportTest test case verifies that the | 92 // The GpuMemoryBufferFactoryImportTest test case verifies that the |
| 93 // GpuMemoryBufferFactory implementation handles import of buffers correctly. | 93 // GpuMemoryBufferFactory implementation handles import of buffers correctly. |
| 94 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferFactoryImportTest, | 94 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferFactoryImportTest, |
| 95 CreateGpuMemoryBufferFromHandle); | 95 CreateGpuMemoryBufferFromHandle); |
| 96 | 96 |
| 97 } // namespace content | 97 } // namespace gpu |
| 98 | 98 |
| 99 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ | 99 #endif // GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_TEST_TEMPLATE_H_ |
| OLD | NEW |