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 #include "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 #include "base/sys_info.h" | 6 #include "base/sys_info.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gl/gl_image_shared_memory.h" | 8 #include "ui/gl/gl_image_shared_memory.h" |
9 #include "ui/gl/test/gl_image_test_template.h" | 9 #include "ui/gl/test/gl_image_test_template.h" |
10 | 10 |
11 namespace gfx { | 11 namespace gfx { |
12 namespace { | 12 namespace { |
13 | 13 |
14 template <BufferFormat format> | 14 template <BufferFormat format> |
15 class GLImageSharedMemoryTestDelegate { | 15 class GLImageSharedMemoryTestDelegate { |
16 public: | 16 public: |
17 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 17 scoped_refptr<gl::GLImage> CreateSolidColorImage( |
18 const Size& size, | 18 const Size& size, |
19 const uint8_t color[4]) const { | 19 const uint8_t color[4]) const { |
20 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); | 20 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); |
21 base::SharedMemory shared_memory; | 21 base::SharedMemory shared_memory; |
22 bool rv = shared_memory.CreateAndMapAnonymous( | 22 bool rv = shared_memory.CreateAndMapAnonymous( |
23 BufferSizeForBufferFormat(size, format)); | 23 BufferSizeForBufferFormat(size, format)); |
24 DCHECK(rv); | 24 DCHECK(rv); |
25 GLImageTestSupport::SetBufferDataToColor( | 25 GLImageTestSupport::SetBufferDataToColor( |
26 size.width(), size.height(), | 26 size.width(), size.height(), |
27 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), | 27 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0, |
28 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory())); | 28 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory())); |
29 scoped_refptr<gl::GLImageSharedMemory> image(new gl::GLImageSharedMemory( | 29 scoped_refptr<gl::GLImageSharedMemory> image(new gl::GLImageSharedMemory( |
30 size, gl::GLImageMemory::GetInternalFormatForTesting(format))); | 30 size, gl::GLImageMemory::GetInternalFormatForTesting(format))); |
31 rv = image->Initialize( | 31 rv = image->Initialize( |
32 base::SharedMemory::DuplicateHandle(shared_memory.handle()), | 32 base::SharedMemory::DuplicateHandle(shared_memory.handle()), |
33 GenericSharedMemoryId(0), format, 0); | 33 GenericSharedMemoryId(0), format, 0); |
34 EXPECT_TRUE(rv); | 34 EXPECT_TRUE(rv); |
35 return image; | 35 return image; |
36 } | 36 } |
37 }; | 37 }; |
(...skipping 24 matching lines...) Expand all Loading... |
62 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); | 62 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); |
63 DCHECK(rv); | 63 DCHECK(rv); |
64 // Initialize memory to a value that is easy to recognize if test fails. | 64 // Initialize memory to a value that is easy to recognize if test fails. |
65 memset(shared_memory.memory(), 0x55, pool_size); | 65 memset(shared_memory.memory(), 0x55, pool_size); |
66 // Place buffer at a non-zero non-page-aligned offset in shared memory. | 66 // Place buffer at a non-zero non-page-aligned offset in shared memory. |
67 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; | 67 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; |
68 GLImageTestSupport::SetBufferDataToColor( | 68 GLImageTestSupport::SetBufferDataToColor( |
69 size.width(), size.height(), | 69 size.width(), size.height(), |
70 static_cast<int>( | 70 static_cast<int>( |
71 RowSizeForBufferFormat(size.width(), BufferFormat::RGBA_8888, 0)), | 71 RowSizeForBufferFormat(size.width(), BufferFormat::RGBA_8888, 0)), |
72 BufferFormat::RGBA_8888, color, | 72 0, BufferFormat::RGBA_8888, color, |
73 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); | 73 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); |
74 scoped_refptr<gl::GLImageSharedMemory> image( | 74 scoped_refptr<gl::GLImageSharedMemory> image( |
75 new gl::GLImageSharedMemory(size, GL_RGBA)); | 75 new gl::GLImageSharedMemory(size, GL_RGBA)); |
76 rv = image->Initialize( | 76 rv = image->Initialize( |
77 base::SharedMemory::DuplicateHandle(shared_memory.handle()), | 77 base::SharedMemory::DuplicateHandle(shared_memory.handle()), |
78 GenericSharedMemoryId(0), BufferFormat::RGBA_8888, buffer_offset); | 78 GenericSharedMemoryId(0), BufferFormat::RGBA_8888, buffer_offset); |
79 EXPECT_TRUE(rv); | 79 EXPECT_TRUE(rv); |
80 return image; | 80 return image; |
81 } | 81 } |
82 }; | 82 }; |
83 | 83 |
84 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, | 84 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, |
85 GLImageCopyTest, | 85 GLImageCopyTest, |
86 GLImageSharedMemoryPoolTestDelegate); | 86 GLImageSharedMemoryPoolTestDelegate); |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 } // namespace gfx | 89 } // namespace gfx |
OLD | NEW |