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