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/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 { |
| 22 namespace { |
20 | 23 |
21 class ChildThreadImplBrowserTest : public ContentBrowserTest { | 24 class ChildThreadImplBrowserTest : public ContentBrowserTest { |
22 public: | 25 public: |
23 ChildThreadImplBrowserTest() | 26 ChildThreadImplBrowserTest() |
24 : child_discardable_shared_memory_manager_(nullptr) {} | 27 : child_gpu_memory_buffer_manager_(nullptr), |
| 28 child_discardable_shared_memory_manager_(nullptr) {} |
25 | 29 |
26 // Overridden from BrowserTestBase: | 30 // Overridden from BrowserTestBase: |
27 void SetUpCommandLine(base::CommandLine* command_line) override { | 31 void SetUpCommandLine(base::CommandLine* command_line) override { |
28 command_line->AppendSwitch(switches::kSingleProcess); | 32 command_line->AppendSwitch(switches::kSingleProcess); |
29 } | 33 } |
30 void SetUpOnMainThread() override { | 34 void SetUpOnMainThread() override { |
31 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 35 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
32 PostTaskToInProcessRendererAndWait( | 36 PostTaskToInProcessRendererAndWait( |
33 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this)); | 37 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this)); |
34 } | 38 } |
35 | 39 |
| 40 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager() { |
| 41 return child_gpu_memory_buffer_manager_; |
| 42 } |
| 43 |
36 ChildDiscardableSharedMemoryManager* | 44 ChildDiscardableSharedMemoryManager* |
37 child_discardable_shared_memory_manager() { | 45 child_discardable_shared_memory_manager() { |
38 return child_discardable_shared_memory_manager_; | 46 return child_discardable_shared_memory_manager_; |
39 } | 47 } |
40 | 48 |
41 private: | 49 private: |
42 void SetUpOnChildThread() { | 50 void SetUpOnChildThread() { |
| 51 child_gpu_memory_buffer_manager_ = |
| 52 ChildThreadImpl::current()->gpu_memory_buffer_manager(); |
43 child_discardable_shared_memory_manager_ = | 53 child_discardable_shared_memory_manager_ = |
44 ChildThreadImpl::current()->discardable_shared_memory_manager(); | 54 ChildThreadImpl::current()->discardable_shared_memory_manager(); |
45 } | 55 } |
46 | 56 |
| 57 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager_; |
47 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_; | 58 ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_; |
48 }; | 59 }; |
49 | 60 |
50 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, | 61 IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, |
51 DISABLED_LockDiscardableMemory) { | 62 DISABLED_LockDiscardableMemory) { |
52 const size_t kSize = 1024 * 1024; // 1MiB. | 63 const size_t kSize = 1024 * 1024; // 1MiB. |
53 | 64 |
54 scoped_ptr<base::DiscardableMemory> memory = | 65 scoped_ptr<base::DiscardableMemory> memory = |
55 child_discardable_shared_memory_manager() | 66 child_discardable_shared_memory_manager() |
56 ->AllocateLockedDiscardableMemory(kSize); | 67 ->AllocateLockedDiscardableMemory(kSize); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 base::TimeTicks end = | 117 base::TimeTicks end = |
107 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); | 118 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); |
108 while (base::TimeTicks::Now() < end) { | 119 while (base::TimeTicks::Now() < end) { |
109 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated()) | 120 if (!HostDiscardableSharedMemoryManager::current()->GetBytesAllocated()) |
110 break; | 121 break; |
111 } | 122 } |
112 | 123 |
113 EXPECT_LT(base::TimeTicks::Now(), end); | 124 EXPECT_LT(base::TimeTicks::Now(), end); |
114 } | 125 } |
115 | 126 |
116 } // content | 127 enum NativeBufferFlag { kDisableNativeBuffers, kEnableNativeBuffers }; |
| 128 |
| 129 class ChildThreadImplGpuMemoryBufferBrowserTest |
| 130 : public ChildThreadImplBrowserTest, |
| 131 public testing::WithParamInterface< |
| 132 ::testing::tuple<NativeBufferFlag, gfx::GpuMemoryBuffer::Format>> { |
| 133 public: |
| 134 // Overridden from BrowserTestBase: |
| 135 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 136 ChildThreadImplBrowserTest::SetUpCommandLine(command_line); |
| 137 NativeBufferFlag native_buffer_flag = ::testing::get<0>(GetParam()); |
| 138 switch (native_buffer_flag) { |
| 139 case kEnableNativeBuffers: |
| 140 command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers); |
| 141 break; |
| 142 case kDisableNativeBuffers: |
| 143 break; |
| 144 } |
| 145 } |
| 146 }; |
| 147 |
| 148 IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest, |
| 149 DISABLED_Map) { |
| 150 gfx::GpuMemoryBuffer::Format format = ::testing::get<1>(GetParam()); |
| 151 gfx::Size buffer_size(4, 4); |
| 152 |
| 153 scoped_ptr<gfx::GpuMemoryBuffer> buffer = |
| 154 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| 155 buffer_size, format, gfx::GpuMemoryBuffer::MAP); |
| 156 ASSERT_TRUE(buffer); |
| 157 EXPECT_EQ(format, buffer->GetFormat()); |
| 158 |
| 159 size_t num_planes = |
| 160 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format); |
| 161 |
| 162 // Map buffer planes. |
| 163 scoped_ptr<void* []> planes(new void* [num_planes]); |
| 164 bool rv = buffer->Map(planes.get()); |
| 165 ASSERT_TRUE(rv); |
| 166 EXPECT_TRUE(buffer->IsMapped()); |
| 167 |
| 168 // Get strides. |
| 169 scoped_ptr<int[]> strides(new int[num_planes]); |
| 170 buffer->GetStride(strides.get()); |
| 171 |
| 172 // Write to buffer and check result. |
| 173 for (size_t plane = 0; plane < num_planes; ++plane) { |
| 174 size_t row_size_in_bytes = 0; |
| 175 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(buffer_size.width(), format, |
| 176 plane, &row_size_in_bytes)); |
| 177 |
| 178 scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
| 179 memset(data.get(), 0x2a + plane, row_size_in_bytes); |
| 180 size_t height = buffer_size.height() / |
| 181 GpuMemoryBufferImpl::SubsamplingFactor(format, plane); |
| 182 for (size_t y = 0; y < height; ++y) { |
| 183 // Copy |data| to row |y| of |plane| and verify result. |
| 184 memcpy(static_cast<char*>(planes[plane]) + y * strides[plane], data.get(), |
| 185 row_size_in_bytes); |
| 186 EXPECT_EQ(memcmp(static_cast<char*>(planes[plane]) + y * strides[plane], |
| 187 data.get(), row_size_in_bytes), |
| 188 0); |
| 189 } |
| 190 } |
| 191 |
| 192 buffer->Unmap(); |
| 193 EXPECT_FALSE(buffer->IsMapped()); |
| 194 } |
| 195 |
| 196 INSTANTIATE_TEST_CASE_P( |
| 197 ChildThreadImplGpuMemoryBufferBrowserTests, |
| 198 ChildThreadImplGpuMemoryBufferBrowserTest, |
| 199 ::testing::Combine(::testing::Values(kDisableNativeBuffers, |
| 200 kEnableNativeBuffers), |
| 201 // These formats are guaranteed to work on all platforms. |
| 202 ::testing::Values(gfx::GpuMemoryBuffer::R_8, |
| 203 gfx::GpuMemoryBuffer::RGBA_4444, |
| 204 gfx::GpuMemoryBuffer::RGBA_8888, |
| 205 gfx::GpuMemoryBuffer::BGRA_8888, |
| 206 gfx::GpuMemoryBuffer::YUV_420))); |
| 207 |
| 208 } // namespace |
| 209 } // namespace content |
OLD | NEW |