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

Side by Side Diff: content/renderer/render_thread_impl_browsertest.cc

Issue 2386913002: content: Remove gpu memory buffer manager from ChildThreadImpl. (Closed)
Patch Set: restore test 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/discardable_memory.h" 14 #include "base/memory/discardable_memory.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "cc/output/buffer_to_texture_target_map.h" 19 #include "cc/output/buffer_to_texture_target_map.h"
20 #include "content/app/mojo/mojo_init.h" 20 #include "content/app/mojo/mojo_init.h"
21 #include "content/child/child_gpu_memory_buffer_manager.h"
21 #include "content/common/in_process_child_thread_params.h" 22 #include "content/common/in_process_child_thread_params.h"
22 #include "content/common/mojo/mojo_child_connection.h" 23 #include "content/common/mojo/mojo_child_connection.h"
23 #include "content/common/resource_messages.h" 24 #include "content/common/resource_messages.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/content_browser_client.h" 26 #include "content/public/browser/content_browser_client.h"
26 #include "content/public/common/content_client.h" 27 #include "content/public/common/content_client.h"
27 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
28 #include "content/public/common/mojo_shell_connection.h" 29 #include "content/public/common/mojo_shell_connection.h"
29 #include "content/public/common/service_names.h" 30 #include "content/public/common/service_names.h"
30 #include "content/public/renderer/content_renderer_client.h" 31 #include "content/public/renderer/content_renderer_client.h"
32 #include "content/public/test/content_browser_test.h"
33 #include "content/public/test/content_browser_test_utils.h"
31 #include "content/public/test/test_browser_thread_bundle.h" 34 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "content/public/test/test_content_client_initializer.h" 35 #include "content/public/test/test_content_client_initializer.h"
33 #include "content/public/test/test_mojo_shell_context.h" 36 #include "content/public/test/test_mojo_shell_context.h"
34 #include "content/renderer/render_process_impl.h" 37 #include "content/renderer/render_process_impl.h"
35 #include "content/test/mock_render_process.h" 38 #include "content/test/mock_render_process.h"
36 #include "gpu/GLES2/gl2extchromium.h" 39 #include "gpu/GLES2/gl2extchromium.h"
37 #include "ipc/ipc.mojom.h" 40 #include "ipc/ipc.mojom.h"
38 #include "ipc/ipc_channel_mojo.h" 41 #include "ipc/ipc_channel_mojo.h"
39 #include "mojo/edk/embedder/embedder.h" 42 #include "mojo/edk/embedder/embedder.h"
40 #include "mojo/edk/test/scoped_ipc_support.h" 43 #include "mojo/edk/test/scoped_ipc_support.h"
41 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
42 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" 45 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h"
46 #include "ui/gfx/buffer_format_util.h"
43 47
44 // IPC messages for testing ---------------------------------------------------- 48 // IPC messages for testing ----------------------------------------------------
45 49
46 // TODO(mdempsky): Fix properly by moving into a separate 50 // TODO(mdempsky): Fix properly by moving into a separate
47 // browsertest_message_generator.cc file. 51 // browsertest_message_generator.cc file.
48 #undef IPC_IPC_MESSAGE_MACROS_H_ 52 #undef IPC_IPC_MESSAGE_MACROS_H_
49 #undef IPC_MESSAGE_EXTRA 53 #undef IPC_MESSAGE_EXTRA
50 #define IPC_MESSAGE_IMPL 54 #define IPC_MESSAGE_IMPL
51 #include "ipc/ipc_message_macros.h" 55 #include "ipc/ipc_message_macros.h"
52 #include "ipc/ipc_message_templates_impl.h" 56 #include "ipc/ipc_message_templates_impl.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // NOTE other than not being a resource message, the actual message is 269 // NOTE other than not being a resource message, the actual message is
266 // unimportant. 270 // unimportant.
267 271
268 sender()->Send(new TestMsg_QuitRunLoop()); 272 sender()->Send(new TestMsg_QuitRunLoop());
269 273
270 base::RunLoop().Run(); 274 base::RunLoop().Run();
271 275
272 EXPECT_EQ(0, test_task_counter_->NumTasksPosted()); 276 EXPECT_EQ(0, test_task_counter_->NumTasksPosted());
273 } 277 }
274 278
279 enum NativeBufferFlag { kDisableNativeBuffers, kEnableNativeBuffers };
280
281 class ChildThreadImplGpuMemoryBufferBrowserTest
reveman 2016/10/03 15:37:40 nit: RenderThreadImplGpuMemoryBufferBrowserTest
sadrul 2016/10/03 21:24:20 Done.
282 : public ContentBrowserTest,
283 public testing::WithParamInterface<
284 ::testing::tuple<NativeBufferFlag, gfx::BufferFormat>> {
285 public:
286 ChildThreadImplGpuMemoryBufferBrowserTest() {}
287 ~ChildThreadImplGpuMemoryBufferBrowserTest() override {}
288
289 gpu::GpuMemoryBufferManager* memory_buffer_manager() {
290 return memory_buffer_manager_;
291 }
292
293 private:
294 void SetUpOnChildThread() {
reveman 2016/10/03 15:37:41 nit: SetUpOnRenderThread
sadrul 2016/10/03 21:24:20 Done.
295 memory_buffer_manager_ =
296 RenderThreadImpl::current()->GetGpuMemoryBufferManager();
297 }
298
299 // Overridden from BrowserTestBase:
300 void SetUpCommandLine(base::CommandLine* command_line) override {
301 command_line->AppendSwitch(switches::kSingleProcess);
302 NativeBufferFlag native_buffer_flag = ::testing::get<0>(GetParam());
303 switch (native_buffer_flag) {
304 case kEnableNativeBuffers:
305 command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers);
306 break;
307 case kDisableNativeBuffers:
308 command_line->AppendSwitch(switches::kDisableNativeGpuMemoryBuffers);
309 break;
310 }
311 }
312
313 void SetUpOnMainThread() override {
314 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
315 PostTaskToInProcessRendererAndWait(base::Bind(
316 &ChildThreadImplGpuMemoryBufferBrowserTest::SetUpOnChildThread,
317 base::Unretained(this)));
318 }
319
320 gpu::GpuMemoryBufferManager* memory_buffer_manager_ = nullptr;
321
322 DISALLOW_COPY_AND_ASSIGN(ChildThreadImplGpuMemoryBufferBrowserTest);
323 };
324
325 IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferBrowserTest,
326 DISABLED_Map) {
327 gfx::BufferFormat format = ::testing::get<1>(GetParam());
328 gfx::Size buffer_size(4, 4);
329
330 std::unique_ptr<gfx::GpuMemoryBuffer> buffer =
331 memory_buffer_manager()->AllocateGpuMemoryBuffer(
332 buffer_size, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
333 gpu::kNullSurfaceHandle);
334 ASSERT_TRUE(buffer);
335 EXPECT_EQ(format, buffer->GetFormat());
336
337 // Map buffer planes.
338 ASSERT_TRUE(buffer->Map());
339
340 // Write to buffer and check result.
341 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
342 for (size_t plane = 0; plane < num_planes; ++plane) {
343 ASSERT_TRUE(buffer->memory(plane));
344 ASSERT_TRUE(buffer->stride(plane));
345 size_t row_size_in_bytes =
346 gfx::RowSizeForBufferFormat(buffer_size.width(), format, plane);
347 EXPECT_GT(row_size_in_bytes, 0u);
348
349 std::unique_ptr<char[]> data(new char[row_size_in_bytes]);
350 memset(data.get(), 0x2a + plane, row_size_in_bytes);
351 size_t height = buffer_size.height() /
352 gfx::SubsamplingFactorForBufferFormat(format, plane);
353 for (size_t y = 0; y < height; ++y) {
354 // Copy |data| to row |y| of |plane| and verify result.
355 memcpy(
356 static_cast<char*>(buffer->memory(plane)) + y * buffer->stride(plane),
357 data.get(), row_size_in_bytes);
358 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
359 y * buffer->stride(plane),
360 data.get(), row_size_in_bytes));
361 }
362 }
363
364 buffer->Unmap();
365 }
366
367 INSTANTIATE_TEST_CASE_P(
368 ChildThreadImplGpuMemoryBufferBrowserTests,
369 ChildThreadImplGpuMemoryBufferBrowserTest,
370 ::testing::Combine(::testing::Values(kDisableNativeBuffers,
371 kEnableNativeBuffers),
372 // These formats are guaranteed to work on all platforms.
373 ::testing::Values(gfx::BufferFormat::R_8,
374 gfx::BufferFormat::BGR_565,
375 gfx::BufferFormat::RGBA_4444,
376 gfx::BufferFormat::RGBA_8888,
377 gfx::BufferFormat::BGRA_8888,
378 gfx::BufferFormat::YVU_420)));
379
275 } // namespace 380 } // namespace
276 } // namespace content 381 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698