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

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

Issue 22900018: cc: Set the mapped memory reclaim limit for the renderer compositor on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the unittest Created 7 years, 3 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 (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
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
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) {
681 context_provider = ContextProviderCommandBuffer::Create( 682 context_provider = ContextProviderCommandBuffer::Create(
682 CreateGraphicsContext3D(attributes)); 683 CreateGraphicsContext3D(attributes));
683 } 684 }
684 685
686 uint32 output_surface_id = next_output_surface_id_++;
685 if (!context_provider.get()) { 687 if (!context_provider.get()) {
686 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) 688 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing))
687 return scoped_ptr<cc::OutputSurface>(); 689 return scoped_ptr<cc::OutputSurface>();
688 690
689 scoped_ptr<cc::SoftwareOutputDevice> software_device( 691 scoped_ptr<cc::SoftwareOutputDevice> software_device(
690 new CompositorSoftwareOutputDevice()); 692 new CompositorSoftwareOutputDevice());
691 693
692 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( 694 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
693 routing_id(), 695 routing_id(),
694 output_surface_id, 696 output_surface_id,
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 if (CommandLine::ForCurrentProcess()->HasSwitch( 2518 if (CommandLine::ForCurrentProcess()->HasSwitch(
2517 switches::kDisableGpuCompositing)) 2519 switches::kDisableGpuCompositing))
2518 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); 2520 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
2519 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( 2521 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2520 new WebGraphicsContext3DCommandBufferImpl( 2522 new WebGraphicsContext3DCommandBufferImpl(
2521 surface_id(), 2523 surface_id(),
2522 GetURLForGraphicsContext3D(), 2524 GetURLForGraphicsContext3D(),
2523 RenderThreadImpl::current(), 2525 RenderThreadImpl::current(),
2524 weak_ptr_factory_.GetWeakPtr())); 2526 weak_ptr_factory_.GetWeakPtr()));
2525 2527
2526 if (!context->InitializeWithDefaultBufferSizes( 2528 #if defined(OS_ANDROID)
2529 // If we raster too fast we become upload bound, and pending
2530 // uploads consume memory. For maximum upload throughput, we would
2531 // want to allow for upload_throughput * pipeline_time of pending
2532 // uploads, after which we are just wasting memory. Since we don't
2533 // know our upload throughput yet, this just caps our memory usage.
2534 size_t divider = 1;
2535 if (base::android::SysUtils::IsLowEndDevice())
2536 divider = 3;
2537
2538 // For reference Nexus10 can upload 1MB in about 2.5ms.
2539 const size_t kMaxBytesUploadedPerMs = (2 * 1024 * 1024) / (5 * divider);
2540 // Deadline to draw a frame to achieve 60 frames per second.
2541 const size_t kMillisecondsPerFrame = 16;
2542 // Assuming a two frame deep pipeline between the CPU and the GPU.
2543 const size_t kMaxTransferBufferUsageBytes =
2544 2 * kMillisecondsPerFrame * kMaxBytesUploadedPerMs;
2545 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2546 // to avoid unnecessarily stalling the compositor thread.
2547 const size_t kMappedMemoryReclaimLimit = kMaxTransferBufferUsageBytes;
2548 #else
2549 const size_t kMappedMemoryReclaimLimit =
2550 WebGraphicsContext3DCommandBufferImpl::kNoLimit;
2551 #endif
2552 if (!context->Initialize(
2527 attributes, 2553 attributes,
2528 false /* bind generates resources */, 2554 false /* bind generates resources */,
2529 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) ) 2555 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE,
2556 kDefaultCommandBufferSize,
2557 kDefaultStartTransferBufferSize,
2558 kDefaultMinTransferBufferSize,
2559 kDefaultMaxTransferBufferSize,
2560 kMappedMemoryReclaimLimit))
2530 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); 2561 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
2531 return context.Pass(); 2562 return context.Pass();
2532 } 2563 }
2533 2564
2534 } // namespace content 2565 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698