Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: ui/gl/gl_image_shared_memory_unittest.cc

Issue 1484473003: gl, ozone: enable GLImageBindTest unittests Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reveman's comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gl/gl_image_ref_counted_memory_unittest.cc ('k') | ui/gl/gl_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gl/gl_image_shared_memory.h" 11 #include "ui/gl/gl_image_shared_memory.h"
12 #include "ui/gl/gl_utils.h"
12 #include "ui/gl/test/gl_image_test_template.h" 13 #include "ui/gl/test/gl_image_test_template.h"
13 14
14 namespace gl { 15 namespace gl {
15 namespace { 16 namespace {
16 17
17 template <gfx::BufferFormat format>
18 class GLImageSharedMemoryTestDelegate { 18 class GLImageSharedMemoryTestDelegate {
19 public: 19 public:
20 scoped_refptr<gl::GLImage> CreateSolidColorImage( 20 scoped_refptr<gl::GLImage> CreateSolidColorImage(
21 const gfx::Size& size, 21 const gfx::Size& size,
22 gfx::BufferFormat format,
22 const uint8_t color[4]) const { 23 const uint8_t color[4]) const {
23 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); 24 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u);
24 base::SharedMemory shared_memory; 25 base::SharedMemory shared_memory;
25 bool rv = shared_memory.CreateAndMapAnonymous( 26 bool rv = shared_memory.CreateAndMapAnonymous(
26 gfx::BufferSizeForBufferFormat(size, format)); 27 gfx::BufferSizeForBufferFormat(size, format));
27 DCHECK(rv); 28 DCHECK(rv);
28 GLImageTestSupport::SetBufferDataToColor( 29 GLImageTestSupport::SetBufferDataToColor(
29 size.width(), size.height(), 30 size.width(), size.height(),
30 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0, 31 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0,
31 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory())); 32 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory()));
32 scoped_refptr<gl::GLImageSharedMemory> image(new gl::GLImageSharedMemory( 33 scoped_refptr<gl::GLImageSharedMemory> image(
33 size, gl::GLImageMemory::GetInternalFormatForTesting(format))); 34 new gl::GLImageSharedMemory(size, gl::GetTextureFormatFrom(format)));
34 rv = image->Initialize( 35 rv = image->Initialize(
35 base::SharedMemory::DuplicateHandle(shared_memory.handle()), 36 base::SharedMemory::DuplicateHandle(shared_memory.handle()),
36 gfx::GenericSharedMemoryId(0), format, 0, 37 gfx::GenericSharedMemoryId(0), format, 0,
37 gfx::RowSizeForBufferFormat(size.width(), format, 0)); 38 gfx::RowSizeForBufferFormat(size.width(), format, 0));
38 EXPECT_TRUE(rv); 39 EXPECT_TRUE(rv);
39 return image; 40 return image;
40 } 41 }
42
43 static bool IsSupported(gfx::BufferFormat format) {
44 switch (format) {
45 case gfx::BufferFormat::RGBX_8888:
46 case gfx::BufferFormat::RGBA_8888:
47 case gfx::BufferFormat::BGRX_8888:
48 case gfx::BufferFormat::BGRA_8888:
49 return true;
50 default:
51 return false;
52 }
53 return false;
54 }
41 }; 55 };
42 56
43 using GLImageTestTypes = testing::Types<
44 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>,
45 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>,
46 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>,
47 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>;
48
49 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, 57 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
50 GLImageTest, 58 GLImageTest,
51 GLImageTestTypes); 59 GLImageSharedMemoryTestDelegate);
52 60
53 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, 61 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
54 GLImageCopyTest, 62 GLImageCopyTest,
55 GLImageTestTypes); 63 GLImageSharedMemoryTestDelegate);
56 64
57 class GLImageSharedMemoryPoolTestDelegate { 65 class GLImageSharedMemoryPoolTestDelegate {
58 public: 66 public:
59 scoped_refptr<gl::GLImage> CreateSolidColorImage( 67 scoped_refptr<gl::GLImage> CreateSolidColorImage(
60 const gfx::Size& size, 68 const gfx::Size& size,
69 gfx::BufferFormat format,
61 const uint8_t color[4]) const { 70 const uint8_t color[4]) const {
62 // Create a shared memory segment that holds an image with a stride that is 71 // Create a shared memory segment that holds an image with a stride that is
63 // twice the row size and 2 pages larger than image. 72 // twice the row size and 2 pages larger than image.
64 size_t stride = gfx::RowSizeForBufferFormat( 73 size_t stride = gfx::RowSizeForBufferFormat(size.width(), format, 0) * 2;
65 size.width(), gfx::BufferFormat::RGBA_8888, 0) *
66 2;
67 size_t pool_size = 74 size_t pool_size =
68 stride * size.height() + base::SysInfo::VMAllocationGranularity() * 3; 75 stride * size.height() + base::SysInfo::VMAllocationGranularity() * 3;
69 base::SharedMemory shared_memory; 76 base::SharedMemory shared_memory;
70 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); 77 bool rv = shared_memory.CreateAndMapAnonymous(pool_size);
71 DCHECK(rv); 78 DCHECK(rv);
72 // Initialize memory to a value that is easy to recognize if test fails. 79 // Initialize memory to a value that is easy to recognize if test fails.
73 memset(shared_memory.memory(), 0x55, pool_size); 80 memset(shared_memory.memory(), 0x55, pool_size);
74 // Place buffer at a non-zero non-page-aligned offset in shared memory. 81 // Place buffer at a non-zero non-page-aligned offset in shared memory.
75 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; 82 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2;
76 GLImageTestSupport::SetBufferDataToColor( 83 GLImageTestSupport::SetBufferDataToColor(
77 size.width(), size.height(), static_cast<int>(stride), 0, 84 size.width(), size.height(), static_cast<int>(stride), 0, format, color,
78 gfx::BufferFormat::RGBA_8888, color,
79 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); 85 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset);
80 scoped_refptr<gl::GLImageSharedMemory> image( 86 scoped_refptr<gl::GLImageSharedMemory> image(
81 new gl::GLImageSharedMemory(size, GL_RGBA)); 87 new gl::GLImageSharedMemory(size, gl::GetTextureFormatFrom(format)));
82 rv = image->Initialize( 88 rv = image->Initialize(
83 base::SharedMemory::DuplicateHandle(shared_memory.handle()), 89 base::SharedMemory::DuplicateHandle(shared_memory.handle()),
84 gfx::GenericSharedMemoryId(0), gfx::BufferFormat::RGBA_8888, 90 gfx::GenericSharedMemoryId(0), format, buffer_offset, stride);
85 buffer_offset, stride);
86 EXPECT_TRUE(rv); 91 EXPECT_TRUE(rv);
87 return image; 92 return image;
88 } 93 }
94
95 static bool IsSupported(gfx::BufferFormat format) {
96 switch (format) {
97 case gfx::BufferFormat::RGBA_8888:
98 return true;
99 default:
100 return false;
101 }
102 return false;
103 }
89 }; 104 };
90 105
91 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, 106 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool,
92 GLImageCopyTest, 107 GLImageCopyTest,
93 GLImageSharedMemoryPoolTestDelegate); 108 GLImageSharedMemoryPoolTestDelegate);
94 109
95 } // namespace 110 } // namespace
96 } // namespace gl 111 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/gl_image_ref_counted_memory_unittest.cc ('k') | ui/gl/gl_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698