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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 gfx::BufferSizeForBufferFormat(size, format)); | 23 gfx::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)), |
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 gfx::GenericSharedMemoryId(0), format, 0, | 33 gfx::GenericSharedMemoryId(0), format, 0); |
34 gfx::RowSizeForBufferFormat(size.width(), format, 0)); | |
35 EXPECT_TRUE(rv); | 34 EXPECT_TRUE(rv); |
36 return image; | 35 return image; |
37 } | 36 } |
38 }; | 37 }; |
39 | 38 |
40 using GLImageTestTypes = testing::Types< | 39 using GLImageTestTypes = testing::Types< |
41 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>, | 40 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>, |
42 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>, | 41 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>, |
43 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>, | 42 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>, |
44 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>; | 43 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>; |
45 | 44 |
46 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, | 45 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, |
47 GLImageTest, | 46 GLImageTest, |
48 GLImageTestTypes); | 47 GLImageTestTypes); |
49 | 48 |
50 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, | 49 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, |
51 GLImageCopyTest, | 50 GLImageCopyTest, |
52 GLImageTestTypes); | 51 GLImageTestTypes); |
53 | 52 |
54 class GLImageSharedMemoryPoolTestDelegate { | 53 class GLImageSharedMemoryPoolTestDelegate { |
55 public: | 54 public: |
56 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 55 scoped_refptr<gl::GLImage> CreateSolidColorImage( |
57 const gfx::Size& size, | 56 const gfx::Size& size, |
58 const uint8_t color[4]) const { | 57 const uint8_t color[4]) const { |
59 // Create a shared memory segment that holds an image with a stride that is | 58 // Create a shared memory segment that is 2 pages larger than image. |
60 // twice the row size and 2 pages larger than image. | |
61 size_t stride = gfx::RowSizeForBufferFormat( | |
62 size.width(), gfx::BufferFormat::RGBA_8888, 0) * | |
63 2; | |
64 size_t pool_size = | 59 size_t pool_size = |
65 stride * size.height() + base::SysInfo::VMAllocationGranularity() * 3; | 60 gfx::BufferSizeForBufferFormat(size, gfx::BufferFormat::RGBA_8888) + |
| 61 base::SysInfo::VMAllocationGranularity() * 3; |
66 base::SharedMemory shared_memory; | 62 base::SharedMemory shared_memory; |
67 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); | 63 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); |
68 DCHECK(rv); | 64 DCHECK(rv); |
69 // Initialize memory to a value that is easy to recognize if test fails. | 65 // Initialize memory to a value that is easy to recognize if test fails. |
70 memset(shared_memory.memory(), 0x55, pool_size); | 66 memset(shared_memory.memory(), 0x55, pool_size); |
71 // Place buffer at a non-zero non-page-aligned offset in shared memory. | 67 // Place buffer at a non-zero non-page-aligned offset in shared memory. |
72 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; | 68 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; |
73 GLImageTestSupport::SetBufferDataToColor( | 69 GLImageTestSupport::SetBufferDataToColor( |
74 size.width(), size.height(), static_cast<int>(stride), | 70 size.width(), size.height(), |
| 71 static_cast<int>(RowSizeForBufferFormat( |
| 72 size.width(), gfx::BufferFormat::RGBA_8888, 0)), |
75 gfx::BufferFormat::RGBA_8888, color, | 73 gfx::BufferFormat::RGBA_8888, color, |
76 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); | 74 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); |
77 scoped_refptr<gl::GLImageSharedMemory> image( | 75 scoped_refptr<gl::GLImageSharedMemory> image( |
78 new gl::GLImageSharedMemory(size, GL_RGBA)); | 76 new gl::GLImageSharedMemory(size, GL_RGBA)); |
79 rv = image->Initialize( | 77 rv = image->Initialize( |
80 base::SharedMemory::DuplicateHandle(shared_memory.handle()), | 78 base::SharedMemory::DuplicateHandle(shared_memory.handle()), |
81 gfx::GenericSharedMemoryId(0), gfx::BufferFormat::RGBA_8888, | 79 gfx::GenericSharedMemoryId(0), gfx::BufferFormat::RGBA_8888, |
82 buffer_offset, stride); | 80 buffer_offset); |
83 EXPECT_TRUE(rv); | 81 EXPECT_TRUE(rv); |
84 return image; | 82 return image; |
85 } | 83 } |
86 }; | 84 }; |
87 | 85 |
88 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, | 86 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, |
89 GLImageCopyTest, | 87 GLImageCopyTest, |
90 GLImageSharedMemoryPoolTestDelegate); | 88 GLImageSharedMemoryPoolTestDelegate); |
91 | 89 |
92 } // namespace | 90 } // namespace |
93 } // namespace gl | 91 } // namespace gl |
OLD | NEW |