Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 #include "ui/base/ui_base_switches.h" | 55 #include "ui/base/ui_base_switches.h" |
| 56 #include "ui/gfx/point.h" | 56 #include "ui/gfx/point.h" |
| 57 #include "ui/gfx/rect_conversions.h" | 57 #include "ui/gfx/rect_conversions.h" |
| 58 #include "ui/gfx/size_conversions.h" | 58 #include "ui/gfx/size_conversions.h" |
| 59 #include "ui/gfx/skia_util.h" | 59 #include "ui/gfx/skia_util.h" |
| 60 #include "ui/gl/gl_switches.h" | 60 #include "ui/gl/gl_switches.h" |
| 61 #include "ui/surface/transport_dib.h" | 61 #include "ui/surface/transport_dib.h" |
| 62 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" | 62 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" |
| 63 | 63 |
| 64 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
| 65 #include "base/android/sys_utils.h" | |
| 65 #include "content/renderer/android/synchronous_compositor_factory.h" | 66 #include "content/renderer/android/synchronous_compositor_factory.h" |
| 66 #endif | 67 #endif |
| 67 | 68 |
| 68 #if defined(OS_POSIX) | 69 #if defined(OS_POSIX) |
| 69 #include "ipc/ipc_channel_posix.h" | 70 #include "ipc/ipc_channel_posix.h" |
| 70 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 71 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 71 #include "third_party/skia/include/core/SkPixelRef.h" | 72 #include "third_party/skia/include/core/SkPixelRef.h" |
| 72 #endif // defined(OS_POSIX) | 73 #endif // defined(OS_POSIX) |
| 73 | 74 |
| 74 #include "third_party/WebKit/public/web/WebWidget.h" | 75 #include "third_party/WebKit/public/web/WebWidget.h" |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 | 641 |
| 641 GURL RenderWidget::GetURLForGraphicsContext3D() { | 642 GURL RenderWidget::GetURLForGraphicsContext3D() { |
| 642 return GURL(); | 643 return GURL(); |
| 643 } | 644 } |
| 644 | 645 |
| 645 bool RenderWidget::ForceCompositingModeEnabled() { | 646 bool RenderWidget::ForceCompositingModeEnabled() { |
| 646 return false; | 647 return false; |
| 647 } | 648 } |
| 648 | 649 |
| 649 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 650 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
| 650 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 651 | 651 |
| 652 #if defined(OS_ANDROID) | 652 #if defined(OS_ANDROID) |
| 653 if (SynchronousCompositorFactory* factory = | 653 if (SynchronousCompositorFactory* factory = |
| 654 SynchronousCompositorFactory::GetInstance()) { | 654 SynchronousCompositorFactory::GetInstance()) { |
| 655 return factory->CreateOutputSurface(routing_id()); | 655 return factory->CreateOutputSurface(routing_id()); |
| 656 } | 656 } |
| 657 #endif | 657 #endif |
| 658 | 658 |
| 659 uint32 output_surface_id = next_output_surface_id_++; | |
| 660 | |
| 661 // Explicitly disable antialiasing for the compositor. As of the time of | 659 // Explicitly disable antialiasing for the compositor. As of the time of |
| 662 // this writing, the only platform that supported antialiasing for the | 660 // this writing, the only platform that supported antialiasing for the |
| 663 // compositor was Mac OS X, because the on-screen OpenGL context creation | 661 // compositor was Mac OS X, because the on-screen OpenGL context creation |
| 664 // code paths on Windows and Linux didn't yet have multisampling support. | 662 // code paths on Windows and Linux didn't yet have multisampling support. |
| 665 // Mac OS X essentially always behaves as though it's rendering offscreen. | 663 // Mac OS X essentially always behaves as though it's rendering offscreen. |
| 666 // Multisampling has a heavy cost especially on devices with relatively low | 664 // Multisampling has a heavy cost especially on devices with relatively low |
| 667 // fill rate like most notebooks, and the Mac implementation would need to | 665 // fill rate like most notebooks, and the Mac implementation would need to |
| 668 // be optimized to resolve directly into the IOSurface shared between the | 666 // be optimized to resolve directly into the IOSurface shared between the |
| 669 // GPU and browser processes. For these reasons and to avoid platform | 667 // GPU and browser processes. For these reasons and to avoid platform |
| 670 // disparities we explicitly disable antialiasing. | 668 // disparities we explicitly disable antialiasing. |
| 671 WebKit::WebGraphicsContext3D::Attributes attributes; | 669 WebKit::WebGraphicsContext3D::Attributes attributes; |
| 672 attributes.antialias = false; | 670 attributes.antialias = false; |
| 673 attributes.shareResources = true; | 671 attributes.shareResources = true; |
| 674 attributes.noAutomaticFlushes = true; | 672 attributes.noAutomaticFlushes = true; |
| 675 attributes.depth = false; | 673 attributes.depth = false; |
| 676 attributes.stencil = false; | 674 attributes.stencil = false; |
| 675 | |
| 676 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 677 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) | 677 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) |
| 678 attributes.stencil = true; | 678 attributes.stencil = true; |
| 679 | |
| 679 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 680 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 680 if (!fallback) { | 681 if (!fallback) { |
| 682 // If we raster too fast we become upload bound, and pending | |
|
danakj
2013/08/29 20:10:28
Any reason to do this here instead of inside Creat
kaanb
2013/08/30 01:11:35
Done.
| |
| 683 // uploads consume memory. For maximum upload throughput, we would | |
| 684 // want to allow for upload_throughput * pipeline_time of pending | |
| 685 // uploads, after which we are just wasting memory. Since we don't | |
| 686 // know our upload throughput yet, this just caps our memory usage. | |
| 687 #if defined(OS_ANDROID) | |
| 688 size_t divider = 1; | |
| 689 if (base::android::SysUtils::IsLowEndDevice()) | |
| 690 divider = 3; | |
| 691 | |
| 692 // For reference Nexus10 can upload 1MB in about 2.5ms. | |
| 693 const size_t kMaxBytesUploadedPerMs = (2 * 1024 * 1024) / (5 * divider); | |
| 694 #else | |
| 695 // For reference Chromebook Pixel can upload 1MB in about 0.5ms. | |
|
piman
2013/08/29 21:58:19
This affects more than the Pixel. It affects the c
kaanb
2013/08/30 01:11:35
Please note that this constant also eventually mak
| |
| 696 const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; | |
| 697 #endif | |
| 698 | |
| 699 // Assuming a two frame deep pipeline. | |
|
piman
2013/08/29 21:58:19
Between what and what?
kaanb
2013/08/30 01:11:35
Done.
| |
| 700 const size_t kMsPerFrame = 16; | |
|
piman
2013/08/29 21:58:19
What is this number?
kaanb
2013/08/30 01:11:35
Done.
| |
| 701 const size_t max_transfer_buffer_usage_bytes = | |
|
danakj
2013/08/29 20:10:28
nit: no const, or kMaxTransferBufferUsageBytes.
kaanb
2013/08/30 01:11:35
Done.
| |
| 702 2 * kMsPerFrame * kMaxBytesUploadedPerMs; | |
| 703 | |
| 681 context_provider = ContextProviderCommandBuffer::Create( | 704 context_provider = ContextProviderCommandBuffer::Create( |
| 682 CreateGraphicsContext3D(attributes)); | 705 CreateGraphicsContext3D(attributes, max_transfer_buffer_usage_bytes)); |
| 683 } | 706 } |
| 684 | 707 |
| 708 uint32 output_surface_id = next_output_surface_id_++; | |
| 685 if (!context_provider.get()) { | 709 if (!context_provider.get()) { |
| 686 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) | 710 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) |
| 687 return scoped_ptr<cc::OutputSurface>(); | 711 return scoped_ptr<cc::OutputSurface>(); |
| 688 | 712 |
| 689 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 713 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| 690 new CompositorSoftwareOutputDevice()); | 714 new CompositorSoftwareOutputDevice()); |
| 691 | 715 |
| 692 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 716 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
| 693 routing_id(), | 717 routing_id(), |
| 694 output_surface_id, | 718 output_surface_id, |
| (...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2503 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { | 2527 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { |
| 2504 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); | 2528 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 2505 } | 2529 } |
| 2506 | 2530 |
| 2507 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { | 2531 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 2508 return true; | 2532 return true; |
| 2509 } | 2533 } |
| 2510 | 2534 |
| 2511 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 2535 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 2512 RenderWidget::CreateGraphicsContext3D( | 2536 RenderWidget::CreateGraphicsContext3D( |
| 2513 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | 2537 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 2538 size_t max_bytes_pending_upload) { | |
| 2514 if (!webwidget_) | 2539 if (!webwidget_) |
| 2515 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2540 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
| 2516 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2541 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2517 switches::kDisableGpuCompositing)) | 2542 switches::kDisableGpuCompositing)) |
| 2518 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2543 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
| 2519 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 2544 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 2520 new WebGraphicsContext3DCommandBufferImpl( | 2545 new WebGraphicsContext3DCommandBufferImpl( |
| 2521 surface_id(), | 2546 surface_id(), |
| 2522 GetURLForGraphicsContext3D(), | 2547 GetURLForGraphicsContext3D(), |
| 2523 RenderThreadImpl::current(), | 2548 RenderThreadImpl::current(), |
| 2524 weak_ptr_factory_.GetWeakPtr())); | 2549 weak_ptr_factory_.GetWeakPtr())); |
| 2525 | 2550 |
| 2526 if (!context->InitializeWithDefaultBufferSizes( | 2551 // We keep the MappedMemoryReclaimLimit the same as the upload limit |
| 2552 // to avoid unnecessarily stalling the compositor thread. | |
| 2553 const size_t kMappedMemoryReclaimLimit = max_bytes_pending_upload; | |
| 2554 | |
| 2555 if (!context->Initialize( | |
| 2527 attributes, | 2556 attributes, |
| 2528 false /* bind generates resources */, | 2557 false /* bind generates resources */, |
| 2529 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) ) | 2558 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, |
| 2559 kDefaultCommandBufferSize, | |
| 2560 kDefaultStartTransferBufferSize, | |
| 2561 kDefaultMinTransferBufferSize, | |
| 2562 kDefaultMaxTransferBufferSize, | |
| 2563 kMappedMemoryReclaimLimit)) | |
| 2530 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2564 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
| 2531 return context.Pass(); | 2565 return context.Pass(); |
| 2532 } | 2566 } |
| 2533 | 2567 |
| 2534 } // namespace content | 2568 } // namespace content |
| OLD | NEW |