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

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

Issue 2014223002: Follow-up fixes to changing namespace gfx to gl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 6 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_image_surface_texture.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/test/gl_image_test_template.h" 12 #include "ui/gl/test/gl_image_test_template.h"
13 13
14 namespace gl { 14 namespace gl {
15 namespace { 15 namespace {
16 16
17 template <gfx::BufferFormat format> 17 template <gfx::BufferFormat format>
18 class GLImageSharedMemoryTestDelegate { 18 class GLImageSharedMemoryTestDelegate {
19 public: 19 public:
20 scoped_refptr<gl::GLImage> CreateSolidColorImage( 20 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size,
21 const gfx::Size& size, 21 const uint8_t color[4]) const {
22 const uint8_t color[4]) const {
23 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); 22 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u);
24 base::SharedMemory shared_memory; 23 base::SharedMemory shared_memory;
25 bool rv = shared_memory.CreateAndMapAnonymous( 24 bool rv = shared_memory.CreateAndMapAnonymous(
26 gfx::BufferSizeForBufferFormat(size, format)); 25 gfx::BufferSizeForBufferFormat(size, format));
27 DCHECK(rv); 26 DCHECK(rv);
28 GLImageTestSupport::SetBufferDataToColor( 27 GLImageTestSupport::SetBufferDataToColor(
29 size.width(), size.height(), 28 size.width(), size.height(),
30 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0, 29 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0,
31 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory())); 30 format, color, reinterpret_cast<uint8_t*>(shared_memory.memory()));
32 scoped_refptr<gl::GLImageSharedMemory> image(new gl::GLImageSharedMemory( 31 scoped_refptr<GLImageSharedMemory> image(new GLImageSharedMemory(
33 size, gl::GLImageMemory::GetInternalFormatForTesting(format))); 32 size, GLImageMemory::GetInternalFormatForTesting(format)));
34 rv = image->Initialize( 33 rv = image->Initialize(
35 base::SharedMemory::DuplicateHandle(shared_memory.handle()), 34 base::SharedMemory::DuplicateHandle(shared_memory.handle()),
36 gfx::GenericSharedMemoryId(0), format, 0, 35 gfx::GenericSharedMemoryId(0), format, 0,
37 gfx::RowSizeForBufferFormat(size.width(), format, 0)); 36 gfx::RowSizeForBufferFormat(size.width(), format, 0));
38 EXPECT_TRUE(rv); 37 EXPECT_TRUE(rv);
39 return image; 38 return image;
40 } 39 }
41 40
42 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } 41 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; }
43 }; 42 };
44 43
45 using GLImageTestTypes = testing::Types< 44 using GLImageTestTypes = testing::Types<
46 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGR_565>, 45 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGR_565>,
47 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>, 46 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>,
48 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>, 47 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>,
49 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>, 48 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>,
50 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>; 49 GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>;
51 50
52 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, 51 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
53 GLImageTest, 52 GLImageTest,
54 GLImageTestTypes); 53 GLImageTestTypes);
55 54
56 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory, 55 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
57 GLImageCopyTest, 56 GLImageCopyTest,
58 GLImageTestTypes); 57 GLImageTestTypes);
59 58
60 class GLImageSharedMemoryPoolTestDelegate { 59 class GLImageSharedMemoryPoolTestDelegate {
61 public: 60 public:
62 scoped_refptr<gl::GLImage> CreateSolidColorImage( 61 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size,
63 const gfx::Size& size, 62 const uint8_t color[4]) const {
64 const uint8_t color[4]) const {
65 // Create a shared memory segment that holds an image with a stride that is 63 // Create a shared memory segment that holds an image with a stride that is
66 // twice the row size and 2 pages larger than image. 64 // twice the row size and 2 pages larger than image.
67 size_t stride = gfx::RowSizeForBufferFormat( 65 size_t stride = gfx::RowSizeForBufferFormat(
68 size.width(), gfx::BufferFormat::RGBA_8888, 0) * 66 size.width(), gfx::BufferFormat::RGBA_8888, 0) *
69 2; 67 2;
70 size_t pool_size = 68 size_t pool_size =
71 stride * size.height() + base::SysInfo::VMAllocationGranularity() * 3; 69 stride * size.height() + base::SysInfo::VMAllocationGranularity() * 3;
72 base::SharedMemory shared_memory; 70 base::SharedMemory shared_memory;
73 bool rv = shared_memory.CreateAndMapAnonymous(pool_size); 71 bool rv = shared_memory.CreateAndMapAnonymous(pool_size);
74 DCHECK(rv); 72 DCHECK(rv);
75 // Initialize memory to a value that is easy to recognize if test fails. 73 // Initialize memory to a value that is easy to recognize if test fails.
76 memset(shared_memory.memory(), 0x55, pool_size); 74 memset(shared_memory.memory(), 0x55, pool_size);
77 // Place buffer at a non-zero non-page-aligned offset in shared memory. 75 // Place buffer at a non-zero non-page-aligned offset in shared memory.
78 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2; 76 size_t buffer_offset = 3 * base::SysInfo::VMAllocationGranularity() / 2;
79 GLImageTestSupport::SetBufferDataToColor( 77 GLImageTestSupport::SetBufferDataToColor(
80 size.width(), size.height(), static_cast<int>(stride), 0, 78 size.width(), size.height(), static_cast<int>(stride), 0,
81 gfx::BufferFormat::RGBA_8888, color, 79 gfx::BufferFormat::RGBA_8888, color,
82 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset); 80 reinterpret_cast<uint8_t*>(shared_memory.memory()) + buffer_offset);
83 scoped_refptr<gl::GLImageSharedMemory> image( 81 scoped_refptr<GLImageSharedMemory> image(
84 new gl::GLImageSharedMemory(size, GL_RGBA)); 82 new GLImageSharedMemory(size, GL_RGBA));
85 rv = image->Initialize( 83 rv = image->Initialize(
86 base::SharedMemory::DuplicateHandle(shared_memory.handle()), 84 base::SharedMemory::DuplicateHandle(shared_memory.handle()),
87 gfx::GenericSharedMemoryId(0), gfx::BufferFormat::RGBA_8888, 85 gfx::GenericSharedMemoryId(0), gfx::BufferFormat::RGBA_8888,
88 buffer_offset, stride); 86 buffer_offset, stride);
89 EXPECT_TRUE(rv); 87 EXPECT_TRUE(rv);
90 return image; 88 return image;
91 } 89 }
92 90
93 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; } 91 unsigned GetTextureTarget() const { return GL_TEXTURE_2D; }
94 }; 92 };
95 93
96 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool, 94 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemoryPool,
97 GLImageCopyTest, 95 GLImageCopyTest,
98 GLImageSharedMemoryPoolTestDelegate); 96 GLImageSharedMemoryPoolTestDelegate);
99 97
100 } // namespace 98 } // namespace
101 } // namespace gl 99 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/gl_image_ref_counted_memory_unittest.cc ('k') | ui/gl/gl_image_surface_texture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698