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

Side by Side Diff: content/child/child_thread_impl_browsertest.cc

Issue 2386913002: content: Remove gpu memory buffer manager from ChildThreadImpl. (Closed)
Patch Set: . Created 4 years, 2 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
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 "content/child/child_thread_impl.h" 5 #include "content/child/child_thread_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" 23 #include "gpu/ipc/client/gpu_memory_buffer_impl.h"
24 #include "ui/gfx/buffer_format_util.h" 24 #include "ui/gfx/buffer_format_util.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 namespace content { 27 namespace content {
28 namespace { 28 namespace {
29 29
30 class ChildThreadImplBrowserTest : public ContentBrowserTest { 30 class ChildThreadImplBrowserTest : public ContentBrowserTest {
31 public: 31 public:
32 ChildThreadImplBrowserTest() 32 ChildThreadImplBrowserTest()
33 : child_gpu_memory_buffer_manager_(nullptr), 33 : child_discardable_shared_memory_manager_(nullptr) {}
34 child_discardable_shared_memory_manager_(nullptr) {}
35 34
36 // Overridden from BrowserTestBase: 35 // Overridden from BrowserTestBase:
37 void SetUpCommandLine(base::CommandLine* command_line) override { 36 void SetUpCommandLine(base::CommandLine* command_line) override {
38 command_line->AppendSwitch(switches::kSingleProcess); 37 command_line->AppendSwitch(switches::kSingleProcess);
39 } 38 }
40 void SetUpOnMainThread() override { 39 void SetUpOnMainThread() override {
41 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 40 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
42 PostTaskToInProcessRendererAndWait( 41 PostTaskToInProcessRendererAndWait(
43 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, 42 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread,
44 base::Unretained(this))); 43 base::Unretained(this)));
45 } 44 }
46 45
47 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager() {
48 return child_gpu_memory_buffer_manager_;
49 }
50
51 ChildDiscardableSharedMemoryManager* 46 ChildDiscardableSharedMemoryManager*
52 child_discardable_shared_memory_manager() { 47 child_discardable_shared_memory_manager() {
53 return child_discardable_shared_memory_manager_; 48 return child_discardable_shared_memory_manager_;
54 } 49 }
55 50
56 private: 51 private:
57 void SetUpOnChildThread() { 52 void SetUpOnChildThread() {
58 child_gpu_memory_buffer_manager_ =
59 ChildThreadImpl::current()->gpu_memory_buffer_manager();
60 child_discardable_shared_memory_manager_ = 53 child_discardable_shared_memory_manager_ =
61 ChildThreadImpl::current()->discardable_shared_memory_manager(); 54 ChildThreadImpl::current()->discardable_shared_memory_manager();
62 } 55 }
63 56
64 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager_;
65 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_; 57 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_;
66 }; 58 };
67 59
68 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, LockDiscardableMemory) { 60 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, LockDiscardableMemory) {
69 const size_t kSize = 1024 * 1024; // 1MiB. 61 const size_t kSize = 1024 * 1024; // 1MiB.
70 62
71 std::unique_ptr<base::DiscardableMemory> memory = 63 std::unique_ptr<base::DiscardableMemory> memory =
72 child_discardable_shared_memory_manager() 64 child_discardable_shared_memory_manager()
73 ->AllocateLockedDiscardableMemory(kSize); 65 ->AllocateLockedDiscardableMemory(kSize);
74 66
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 base::TimeTicks end = 115 base::TimeTicks end =
124 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); 116 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5);
125 while (base::TimeTicks::Now() < end) { 117 while (base::TimeTicks::Now() < end) {
126 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated()) 118 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated())
127 break; 119 break;
128 } 120 }
129 121
130 EXPECT_LT(base::TimeTicks::Now(), end); 122 EXPECT_LT(base::TimeTicks::Now(), end);
131 } 123 }
132 124
133 enum NativeBufferFlag { kDisableNativeBuffers, kEnableNativeBuffers };
134
135 class ChildThreadImplGpuMemoryBufferBrowserTest
136 : public ChildThreadImplBrowserTest,
137 public testing::WithParamInterface<
138 ::testing::tuple<NativeBufferFlag, gfx::BufferFormat>> {
139 public:
140 // Overridden from BrowserTestBase:
141 void SetUpCommandLine(base::CommandLine* command_line) override {
142 ChildThreadImplBrowserTest::SetUpCommandLine(command_line);
143 NativeBufferFlag native_buffer_flag = ::testing::get<0>(GetParam());
144 switch (native_buffer_flag) {
145 case kEnableNativeBuffers:
146 command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers);
147 break;
148 case kDisableNativeBuffers:
149 command_line->AppendSwitch(switches::kDisableNativeGpuMemoryBuffers);
150 break;
151 }
152 }
153 };
154
155 IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest,
156 DISABLED_Map) {
157 gfx::BufferFormat format = ::testing::get<1>(GetParam());
158 gfx::Size buffer_size(4, 4);
159
160 std::unique_ptr<gfx::GpuMemoryBuffer> buffer =
161 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer(
162 buffer_size, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
163 gpu::kNullSurfaceHandle);
164 ASSERT_TRUE(buffer);
165 EXPECT_EQ(format, buffer->GetFormat());
166
167 // Map buffer planes.
168 ASSERT_TRUE(buffer->Map());
169
170 // Write to buffer and check result.
171 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
172 for (size_t plane = 0; plane < num_planes; ++plane) {
173 ASSERT_TRUE(buffer->memory(plane));
174 ASSERT_TRUE(buffer->stride(plane));
175 size_t row_size_in_bytes =
176 gfx::RowSizeForBufferFormat(buffer_size.width(), format, plane);
177 EXPECT_GT(row_size_in_bytes, 0u);
178
179 std::unique_ptr<char[]> data(new char[row_size_in_bytes]);
180 memset(data.get(), 0x2a + plane, row_size_in_bytes);
181 size_t height = buffer_size.height() /
182 gfx::SubsamplingFactorForBufferFormat(format, plane);
183 for (size_t y = 0; y < height; ++y) {
184 // Copy |data| to row |y| of |plane| and verify result.
185 memcpy(
186 static_cast<char*>(buffer->memory(plane)) + y * buffer->stride(plane),
187 data.get(), row_size_in_bytes);
188 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
189 y * buffer->stride(plane),
190 data.get(), row_size_in_bytes));
191 }
192 }
193
194 buffer->Unmap();
195 }
196
197 INSTANTIATE_TEST_CASE_P(
198 ChildThreadImplGpuMemoryBufferBrowserTests,
199 ChildThreadImplGpuMemoryBufferBrowserTest,
200 ::testing::Combine(::testing::Values(kDisableNativeBuffers,
201 kEnableNativeBuffers),
202 // These formats are guaranteed to work on all platforms.
203 ::testing::Values(gfx::BufferFormat::R_8,
204 gfx::BufferFormat::BGR_565,
205 gfx::BufferFormat::RGBA_4444,
206 gfx::BufferFormat::RGBA_8888,
207 gfx::BufferFormat::BGRA_8888,
208 gfx::BufferFormat::YVU_420)));
209
210 } // namespace 125 } // namespace
211 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698