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