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

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

Issue 1120873002: Re-land: content: Single process support for native GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dm-browsertests-refactor
Patch Set: Make InProcessSurfaceTextureManager thread safe Created 5 years, 7 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/discardable_memory.h" 7 #include "base/memory/discardable_memory.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/child/child_discardable_shared_memory_manager.h" 10 #include "content/child/child_discardable_shared_memory_manager.h"
11 #include "content/child/child_gpu_memory_buffer_manager.h"
11 #include "content/child/child_thread_impl.h" 12 #include "content/child/child_thread_impl.h"
13 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
12 #include "content/common/host_discardable_shared_memory_manager.h" 14 #include "content/common/host_discardable_shared_memory_manager.h"
13 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
14 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 namespace content { 21 namespace content {
20 22
21 class ChildThreadImplBrowserTest : public ContentBrowserTest { 23 class ChildThreadImplBrowserTest : public ContentBrowserTest {
22 public: 24 public:
23 ChildThreadImplBrowserTest() 25 ChildThreadImplBrowserTest()
24 : child_discardable_shared_memory_manager_(nullptr) {} 26 : child_gpu_memory_buffer_manager_(nullptr),
27 child_discardable_shared_memory_manager_(nullptr) {}
25 28
26 // Overridden from BrowserTestBase: 29 // Overridden from BrowserTestBase:
27 void SetUpCommandLine(base::CommandLine* command_line) override { 30 void SetUpCommandLine(base::CommandLine* command_line) override {
28 command_line->AppendSwitch(switches::kSingleProcess); 31 command_line->AppendSwitch(switches::kSingleProcess);
29 } 32 }
30 void SetUpOnMainThread() override { 33 void SetUpOnMainThread() override {
31 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 34 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
32 PostTaskToInProcessRendererAndWait( 35 PostTaskToInProcessRendererAndWait(
33 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this)); 36 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this));
34 } 37 }
35 38
39 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager() {
40 return child_gpu_memory_buffer_manager_;
41 }
42
36 ChildDiscardableSharedMemoryManager* 43 ChildDiscardableSharedMemoryManager*
37 child_discardable_shared_memory_manager() { 44 child_discardable_shared_memory_manager() {
38 return child_discardable_shared_memory_manager_; 45 return child_discardable_shared_memory_manager_;
39 } 46 }
40 47
41 private: 48 private:
42 void SetUpOnChildThread() { 49 void SetUpOnChildThread() {
50 child_gpu_memory_buffer_manager_ =
51 ChildThreadImpl::current()->gpu_memory_buffer_manager();
43 child_discardable_shared_memory_manager_ = 52 child_discardable_shared_memory_manager_ =
44 ChildThreadImpl::current()->discardable_shared_memory_manager(); 53 ChildThreadImpl::current()->discardable_shared_memory_manager();
45 } 54 }
46 55
56 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager_;
47 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_; 57 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_;
48 }; 58 };
49 59
50 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, 60 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest,
51 DISABLED_LockDiscardableMemory) { 61 DISABLED_LockDiscardableMemory) {
52 const size_t kSize = 1024 * 1024; // 1MiB. 62 const size_t kSize = 1024 * 1024; // 1MiB.
53 63
54 scoped_ptr<base::DiscardableMemory> memory = 64 scoped_ptr<base::DiscardableMemory> memory =
55 child_discardable_shared_memory_manager() 65 child_discardable_shared_memory_manager()
56 ->AllocateLockedDiscardableMemory(kSize); 66 ->AllocateLockedDiscardableMemory(kSize);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::TimeTicks end = 116 base::TimeTicks end =
107 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); 117 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5);
108 while (base::TimeTicks::Now() < end) { 118 while (base::TimeTicks::Now() < end) {
109 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated()) 119 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated())
110 break; 120 break;
111 } 121 }
112 122
113 EXPECT_LT(base::TimeTicks::Now(), end); 123 EXPECT_LT(base::TimeTicks::Now(), end);
114 } 124 }
115 125
116 } // content 126 enum NativeBufferFlag { kDisableNativeBuffers, kEnableNativeBuffers };
Daniele Castagna 2015/05/06 18:39:41 Should this be in an unnamed namespace?
reveman 2015/05/06 20:37:47 Moved everything into anonymous namespace
127
128 class ChildThreadImplGpuMemoryBufferBrowserTest
129 : public ChildThreadImplBrowserTest,
130 public testing::WithParamInterface<
131 ::testing::tuple<NativeBufferFlag, gfx::GpuMemoryBuffer::Format>> {
132 public:
133 // Overridden from BrowserTestBase:
134 void SetUpCommandLine(base::CommandLine* command_line) override {
135 ChildThreadImplBrowserTest::SetUpCommandLine(command_line);
136 switch (::testing::get<0>(GetParam())) {
Daniele Castagna 2015/05/06 18:39:41 Maybe NativeBufferFlag native_buffer_flag = ::tes
reveman 2015/05/06 20:37:47 Done.
137 case kEnableNativeBuffers:
138 command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers);
139 break;
140 case kDisableNativeBuffers:
141 break;
142 }
143 }
144 };
145
146 IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest, Map) {
147 gfx::GpuMemoryBuffer::Format format = ::testing::get<1>(GetParam());
148 gfx::Size buffer_size(2, 2);
149
150 scoped_ptr<gfx::GpuMemoryBuffer> buffer =
151 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer(
152 buffer_size, format, gfx::GpuMemoryBuffer::MAP);
153 ASSERT_TRUE(buffer);
154 EXPECT_EQ(format, buffer->GetFormat());
155
156 size_t num_planes =
157 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format);
158
159 // Map buffer planes.
160 scoped_ptr<void* []> planes(new void* [num_planes]);
161 bool rv = buffer->Map(planes.get());
162 ASSERT_TRUE(rv);
Daniele Castagna 2015/05/06 18:39:41 Why ASSERT here? EXPECT is typically preferred.
reveman 2015/05/06 20:37:47 We're going to crash below if this failed. ASSERT
163 EXPECT_TRUE(buffer->IsMapped());
164
165 // Get strides.
166 scoped_ptr<int[]> strides(new int[num_planes]);
167 buffer->GetStride(strides.get());
168
169 // Write to buffer and check result.
170 for (size_t plane = 0; plane < num_planes; ++plane) {
171 size_t row_size_in_bytes = 0;
172 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(buffer_size.width(), format,
173 plane, &row_size_in_bytes));
174
175 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
176 memset(data.get(), 0x2a + plane, row_size_in_bytes);
177 size_t height = buffer_size.height() /
178 GpuMemoryBufferImpl::SubsamplingFactor(format, plane);
179 for (size_t y = 0; y < height; ++y) {
180 // Copy |data| to row |y| of |plane| and verify result.
181 memcpy(static_cast<char*>(planes[plane]) + y * strides[plane], data.get(),
182 row_size_in_bytes);
183 EXPECT_EQ(memcmp(static_cast<char*>(planes[plane]) + y * strides[plane],
184 data.get(), row_size_in_bytes),
185 0);
186 }
187 }
188
189 buffer->Unmap();
190 EXPECT_FALSE(buffer->IsMapped());
191 }
192
193 INSTANTIATE_TEST_CASE_P(
194 ChildThreadImplGpuMemoryBufferBrowserTests,
195 ChildThreadImplGpuMemoryBufferBrowserTest,
196 ::testing::Combine(::testing::Values(kDisableNativeBuffers,
197 kEnableNativeBuffers),
198 // These formats are guaranteed to work on all platforms.
199 ::testing::Values(gfx::GpuMemoryBuffer::R_8,
200 gfx::GpuMemoryBuffer::RGBA_8888,
201 gfx::GpuMemoryBuffer::BGRA_8888,
202 gfx::GpuMemoryBuffer::YUV_420)));
203
204 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698