 Chromium Code Reviews
 Chromium Code Reviews Issue 1120873002:
  Re-land: content: Single process support for native GpuMemoryBuffers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@dm-browsertests-refactor
    
  
    Issue 1120873002:
  Re-land: content: Single process support for native GpuMemoryBuffers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@dm-browsertests-refactor| Index: content/child/child_thread_impl_browsertest.cc | 
| diff --git a/content/child/child_thread_impl_browsertest.cc b/content/child/child_thread_impl_browsertest.cc | 
| index 4a37196d77d9dbe9812911763e9f6e7c9765af61..64fa9abd7a25d81932d5dbde6232bd364ca967d0 100644 | 
| --- a/content/child/child_thread_impl_browsertest.cc | 
| +++ b/content/child/child_thread_impl_browsertest.cc | 
| @@ -8,7 +8,9 @@ | 
| #include "base/memory/scoped_vector.h" | 
| #include "base/time/time.h" | 
| #include "content/child/child_discardable_shared_memory_manager.h" | 
| +#include "content/child/child_gpu_memory_buffer_manager.h" | 
| #include "content/child/child_thread_impl.h" | 
| +#include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 
| #include "content/common/host_discardable_shared_memory_manager.h" | 
| #include "content/public/common/content_switches.h" | 
| #include "content/public/test/content_browser_test.h" | 
| @@ -21,7 +23,8 @@ namespace content { | 
| class ChildThreadImplBrowserTest : public ContentBrowserTest { | 
| public: | 
| ChildThreadImplBrowserTest() | 
| - : child_discardable_shared_memory_manager_(nullptr) {} | 
| + : child_gpu_memory_buffer_manager_(nullptr), | 
| + child_discardable_shared_memory_manager_(nullptr) {} | 
| // Overridden from BrowserTestBase: | 
| void SetUpCommandLine(base::CommandLine* command_line) override { | 
| @@ -33,6 +36,10 @@ class ChildThreadImplBrowserTest : public ContentBrowserTest { | 
| base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this)); | 
| } | 
| + ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager() { | 
| + return child_gpu_memory_buffer_manager_; | 
| + } | 
| + | 
| ChildDiscardableSharedMemoryManager* | 
| child_discardable_shared_memory_manager() { | 
| return child_discardable_shared_memory_manager_; | 
| @@ -40,10 +47,13 @@ class ChildThreadImplBrowserTest : public ContentBrowserTest { | 
| private: | 
| void SetUpOnChildThread() { | 
| + child_gpu_memory_buffer_manager_ = | 
| + ChildThreadImpl::current()->gpu_memory_buffer_manager(); | 
| child_discardable_shared_memory_manager_ = | 
| ChildThreadImpl::current()->discardable_shared_memory_manager(); | 
| } | 
| + ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager_; | 
| ChildDiscardableSharedMemoryManager* child_discardable_shared_memory_manager_; | 
| }; | 
| @@ -113,4 +123,82 @@ IN_PROC_BROWSER_TEST_F(ChildThreadImplBrowserTest, | 
| EXPECT_LT(base::TimeTicks::Now(), end); | 
| } | 
| -} // content | 
| +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
 | 
| + | 
| +class ChildThreadImplGpuMemoryBufferBrowserTest | 
| + : public ChildThreadImplBrowserTest, | 
| + public testing::WithParamInterface< | 
| + ::testing::tuple<NativeBufferFlag, gfx::GpuMemoryBuffer::Format>> { | 
| + public: | 
| + // Overridden from BrowserTestBase: | 
| + void SetUpCommandLine(base::CommandLine* command_line) override { | 
| + ChildThreadImplBrowserTest::SetUpCommandLine(command_line); | 
| + 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.
 | 
| + case kEnableNativeBuffers: | 
| + command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers); | 
| + break; | 
| + case kDisableNativeBuffers: | 
| + break; | 
| + } | 
| + } | 
| +}; | 
| + | 
| +IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest, Map) { | 
| + gfx::GpuMemoryBuffer::Format format = ::testing::get<1>(GetParam()); | 
| + gfx::Size buffer_size(2, 2); | 
| + | 
| + scoped_ptr<gfx::GpuMemoryBuffer> buffer = | 
| + child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 
| + buffer_size, format, gfx::GpuMemoryBuffer::MAP); | 
| + ASSERT_TRUE(buffer); | 
| + EXPECT_EQ(format, buffer->GetFormat()); | 
| + | 
| + size_t num_planes = | 
| + GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format); | 
| + | 
| + // Map buffer planes. | 
| + scoped_ptr<void* []> planes(new void* [num_planes]); | 
| + bool rv = buffer->Map(planes.get()); | 
| + 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
 | 
| + EXPECT_TRUE(buffer->IsMapped()); | 
| + | 
| + // Get strides. | 
| + scoped_ptr<int[]> strides(new int[num_planes]); | 
| + buffer->GetStride(strides.get()); | 
| + | 
| + // Write to buffer and check result. | 
| + for (size_t plane = 0; plane < num_planes; ++plane) { | 
| + size_t row_size_in_bytes = 0; | 
| + EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(buffer_size.width(), format, | 
| + plane, &row_size_in_bytes)); | 
| + | 
| + scoped_ptr<char[]> data(new char[row_size_in_bytes]); | 
| + memset(data.get(), 0x2a + plane, row_size_in_bytes); | 
| + size_t height = buffer_size.height() / | 
| + GpuMemoryBufferImpl::SubsamplingFactor(format, plane); | 
| + for (size_t y = 0; y < height; ++y) { | 
| + // Copy |data| to row |y| of |plane| and verify result. | 
| + memcpy(static_cast<char*>(planes[plane]) + y * strides[plane], data.get(), | 
| + row_size_in_bytes); | 
| + EXPECT_EQ(memcmp(static_cast<char*>(planes[plane]) + y * strides[plane], | 
| + data.get(), row_size_in_bytes), | 
| + 0); | 
| + } | 
| + } | 
| + | 
| + buffer->Unmap(); | 
| + EXPECT_FALSE(buffer->IsMapped()); | 
| +} | 
| + | 
| +INSTANTIATE_TEST_CASE_P( | 
| + ChildThreadImplGpuMemoryBufferBrowserTests, | 
| + ChildThreadImplGpuMemoryBufferBrowserTest, | 
| + ::testing::Combine(::testing::Values(kDisableNativeBuffers, | 
| + kEnableNativeBuffers), | 
| + // These formats are guaranteed to work on all platforms. | 
| + ::testing::Values(gfx::GpuMemoryBuffer::R_8, | 
| + gfx::GpuMemoryBuffer::RGBA_8888, | 
| + gfx::GpuMemoryBuffer::BGRA_8888, | 
| + gfx::GpuMemoryBuffer::YUV_420))); | 
| + | 
| +} // namespace content |