render_widget_compositor.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/renderer/gpu/render_widget_compositor.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <limits>
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_number_conversions.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/synchronization/lock.h"
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/sys_info.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/values.h"
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "cc/base/latency_info_swap_promise.h"
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "cc/base/latency_info_swap_promise_monitor.h"
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "cc/base/swap_promise.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/switches.h"
2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "cc/blink/web_layer_impl.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/debug/layer_tree_debug_state.h"
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "cc/debug/micro_benchmark.h"
24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "cc/input/layer_selection_bound.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/layer.h"
2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "cc/output/begin_frame_args.h"
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "cc/output/copy_output_request.h"
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "cc/output/copy_output_result.h"
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "cc/resources/single_release_callback.h"
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/trees/layer_tree_host.h"
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/child/child_shared_bitmap_manager.h"
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/common/content_switches_internal.h"
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/gpu/client/context_provider_command_buffer.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/content_switches.h"
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/renderer/input/input_handler_manager.h"
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/renderer/render_thread_impl.h"
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gpu/command_buffer/client/gles2_interface.h"
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "third_party/WebKit/public/platform/WebSelectionBound.h"
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebSize.h"
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "third_party/WebKit/public/web/WebKit.h"
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebWidget.h"
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/gfx/frame_time.h"
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gl/gl_switches.h"
4523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/native_theme/native_theme_switches.h"
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(OS_ANDROID)
48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/renderer/android/synchronous_compositor_factory.h"
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/gfx/android/device_display_info.h"
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace base {
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class Value;
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Layer;
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using blink::WebBeginFrameArgs;
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebFloatPoint;
6203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using blink::WebRect;
63116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing blink::WebSelectionBound;
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebSize;
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content {
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool GetSwitchValueAsInt(
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const CommandLine& command_line,
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const std::string& switch_string,
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int min_value,
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int max_value,
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int* result) {
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string string_value = command_line.GetSwitchValueASCII(switch_string);
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int int_value;
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (base::StringToInt(string_value, &int_value) &&
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int_value >= min_value && int_value <= max_value) {
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    *result = int_value;
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LOG(WARNING) << "Failed to parse switch " << switch_string  << ": " <<
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        string_value;
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
88116680a4aac90f2aa7413d9095a592090648e557Ben Murdochcc::LayerSelectionBound ConvertWebSelectionBound(
8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    const WebSelectionBound& web_bound) {
9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  DCHECK(web_bound.layerId);
91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
9203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  cc::LayerSelectionBound cc_bound;
9303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  switch (web_bound.type) {
94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    case blink::WebSelectionBound::Caret:
9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      cc_bound.type = cc::SELECTION_BOUND_CENTER;
96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      break;
97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    case blink::WebSelectionBound::SelectionLeft:
9803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      cc_bound.type = cc::SELECTION_BOUND_LEFT;
99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      break;
100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    case blink::WebSelectionBound::SelectionRight:
10103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      cc_bound.type = cc::SELECTION_BOUND_RIGHT;
102116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      break;
103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
10403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  cc_bound.layer_id = web_bound.layerId;
10503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  cc_bound.edge_top = gfx::Point(web_bound.edgeTopInLayer);
10603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  cc_bound.edge_bottom = gfx::Point(web_bound.edgeBottomInLayer);
10703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return cc_bound;
108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
110116680a4aac90f2aa7413d9095a592090648e557Ben Murdochgfx::Size CalculateDefaultTileSize() {
111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int default_tile_size = 256;
112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(OS_ANDROID)
113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // TODO(epenner): unify this for all platforms if it
114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // makes sense (http://crbug.com/159524)
115116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  gfx::DeviceDisplayInfo info;
117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool real_size_supported = true;
118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int display_width = info.GetPhysicalDisplayWidth();
119116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int display_height = info.GetPhysicalDisplayHeight();
120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (display_width == 0 || display_height == 0) {
121116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    real_size_supported = false;
122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    display_width = info.GetDisplayWidth();
123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    display_height = info.GetDisplayHeight();
124116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int portrait_width = std::min(display_width, display_height);
127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  int landscape_width = std::max(display_width, display_height);
128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (real_size_supported) {
130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // Maximum HD dimensions should be 768x1280
131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // Maximum FHD dimensions should be 1200x1920
132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (portrait_width > 768 || landscape_width > 1280)
133116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size = 384;
134116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (portrait_width > 1200 || landscape_width > 1920)
135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size = 512;
136116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // Adjust for some resolutions that barely straddle an extra
138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // tile when in portrait mode. This helps worst case scroll/raster
139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // by not needing a full extra tile for each row.
140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (default_tile_size == 256 && portrait_width == 768)
141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size += 32;
142116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (default_tile_size == 384 && portrait_width == 1200)
143116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size += 32;
144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  } else {
145116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // We don't know the exact resolution due to screen controls etc.
146116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // So this just estimates the values above using tile counts.
147116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int numTiles = (display_width * display_height) / (256 * 256);
148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (numTiles > 16)
149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size = 384;
150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    if (numTiles >= 40)
151116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      default_tile_size = 512;
152116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
153116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
154116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return gfx::Size(default_tile_size, default_tile_size);
155116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
156116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
161ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    RenderWidget* widget,
162ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    bool threaded) {
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<RenderWidgetCompositor> compositor(
164ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      new RenderWidgetCompositor(widget, threaded));
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine* cmd = CommandLine::ForCurrentProcess();
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::LayerTreeSettings settings;
169b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
170b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // For web contents, layer transforms should scale up the contents of layers
171b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // to keep content always crisp when possible.
172b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  settings.layer_transforms_should_scale_layer_contents = true;
173b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
17490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  settings.throttle_frame_production =
17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      !cmd->HasSwitch(switches::kDisableGpuVsync);
1765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  settings.begin_frame_scheduling_enabled =
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cmd->HasSwitch(switches::kEnableBeginFrameScheduling);
178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  settings.main_frame_before_activation_enabled =
179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      cmd->HasSwitch(cc::switches::kEnableMainFrameBeforeActivation) &&
180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      !cmd->HasSwitch(cc::switches::kDisableMainFrameBeforeActivation);
181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  settings.main_frame_before_draw_enabled =
182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      !cmd->HasSwitch(cc::switches::kDisableMainFrameBeforeDraw);
183116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.report_overscroll_only_for_scrollable_axes = true;
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.accelerated_animation_enabled =
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      !cmd->HasSwitch(cc::switches::kDisableThreadedAnimation);
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
187116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.default_tile_size = CalculateDefaultTileSize();
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(switches::kDefaultTileWidth)) {
189116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int tile_width = 0;
190116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    GetSwitchValueAsInt(*cmd,
191116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        switches::kDefaultTileWidth,
192116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        1,
193116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        std::numeric_limits<int>::max(),
194116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        &tile_width);
195116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    settings.default_tile_size.set_width(tile_width);
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(switches::kDefaultTileHeight)) {
198116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int tile_height = 0;
199116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    GetSwitchValueAsInt(*cmd,
200116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        switches::kDefaultTileHeight,
201116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        1,
202116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        std::numeric_limits<int>::max(),
203116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        &tile_height);
204116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    settings.default_tile_size.set_height(tile_height);
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int max_untiled_layer_width = settings.max_untiled_layer_size.width();
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(switches::kMaxUntiledLayerWidth)) {
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerWidth, 1,
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        std::numeric_limits<int>::max(),
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        &max_untiled_layer_width);
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int max_untiled_layer_height = settings.max_untiled_layer_size.height();
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(switches::kMaxUntiledLayerHeight)) {
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerHeight, 1,
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        std::numeric_limits<int>::max(),
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        &max_untiled_layer_height);
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.max_untiled_layer_size = gfx::Size(max_untiled_layer_width,
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                           max_untiled_layer_height);
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RenderThreadImpl* render_thread = RenderThreadImpl::current();
2245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // render_thread may be NULL in tests.
2255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (render_thread) {
2265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    settings.impl_side_painting =
2275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        render_thread->is_impl_side_painting_enabled();
228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.gpu_rasterization_forced =
229010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        render_thread->is_gpu_rasterization_forced();
230010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.gpu_rasterization_enabled =
231010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        render_thread->is_gpu_rasterization_enabled();
2325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    settings.can_use_lcd_text = render_thread->is_lcd_text_enabled();
233010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.use_distance_field_text =
234010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        render_thread->is_distance_field_text_enabled();
2355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    settings.use_zero_copy = render_thread->is_zero_copy_enabled();
2365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    settings.use_one_copy = render_thread->is_one_copy_enabled();
2375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (cmd->HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths)) {
240010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.recording_mode = cc::LayerTreeSettings::RecordWithSkRecord;
241010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
242010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.calculate_top_controls_position =
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kEnableTopControlsPositionCalculation);
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kTopControlsHeight)) {
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string controls_height_str =
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        cmd->GetSwitchValueASCII(cc::switches::kTopControlsHeight);
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    double controls_height;
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (base::StringToDouble(controls_height_str, &controls_height) &&
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        controls_height > 0)
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      settings.top_controls_height = controls_height;
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (settings.calculate_top_controls_position &&
2555e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)      settings.top_controls_height <= 0) {
2565e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)    DCHECK(false)
2575e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)        << "Top controls repositioning enabled without valid height set.";
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    settings.calculate_top_controls_position = false;
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kTopControlsShowThreshold)) {
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::string top_threshold_str =
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          cmd->GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold);
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      double show_threshold;
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (base::StringToDouble(top_threshold_str, &show_threshold) &&
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          show_threshold >= 0.f && show_threshold <= 1.f)
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        settings.top_controls_show_threshold = show_threshold;
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kTopControlsHideThreshold)) {
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::string top_threshold_str =
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          cmd->GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold);
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      double hide_threshold;
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          hide_threshold >= 0.f && hide_threshold <= 1.f)
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        settings.top_controls_hide_threshold = hide_threshold;
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  settings.use_pinch_virtual_viewport =
28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport);
281ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  settings.allow_antialiasing &=
282ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      !cmd->HasSwitch(cc::switches::kDisableCompositedAntialiasing);
28303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  settings.single_thread_proxy_scheduler =
28403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      !cmd->HasSwitch(switches::kDisableSingleThreadProxyScheduler);
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These flags should be mirrored by UI versions in ui/compositor/.
2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_debug_borders =
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowCompositedLayerBorders);
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_fps_counter =
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowFPSCounter);
291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  settings.initial_debug_state.show_layer_animation_bounds_rects =
292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowLayerAnimationBounds);
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_paint_rects =
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(switches::kShowPaintRects);
2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_property_changed_rects =
2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowPropertyChangedRects);
2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_surface_damage_rects =
2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowSurfaceDamageRects);
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_screen_space_rects =
3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowScreenSpaceRects);
3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_replica_screen_space_rects =
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowReplicaScreenSpaceRects);
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_occluding_rects =
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowOccludingRects);
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.show_non_occluding_rects =
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kShowNonOccludingRects);
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.initial_debug_state.SetRecordRenderingStats(
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      cmd->HasSwitch(cc::switches::kEnableGpuBenchmarking));
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const int kMinSlowDownScaleFactor = 0;
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const int kMaxSlowDownScaleFactor = INT_MAX;
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    GetSwitchValueAsInt(
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        *cmd,
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        cc::switches::kSlowDownRasterScaleFactor,
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        kMinSlowDownScaleFactor,
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        kMaxSlowDownScaleFactor,
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        &settings.initial_debug_state.slow_down_raster_scale_factor);
3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
322c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kMaxTilesForInterestArea)) {
323c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    int max_tiles_for_interest_area;
324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (GetSwitchValueAsInt(*cmd,
325c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            cc::switches::kMaxTilesForInterestArea,
326c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            1, std::numeric_limits<int>::max(),
327c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            &max_tiles_for_interest_area))
328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      settings.max_tiles_for_interest_area = max_tiles_for_interest_area;
329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
330c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
331c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (cmd->HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage)) {
332c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    int max_unused_resource_memory_percentage;
333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (GetSwitchValueAsInt(
334c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            *cmd,
335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            cc::switches::kMaxUnusedResourceMemoryUsagePercentage,
336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            0, 100,
337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            &max_unused_resource_memory_percentage)) {
338c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      settings.max_unused_resource_memory_percentage =
339c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          max_unused_resource_memory_percentage;
340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
342c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  settings.strict_layer_property_change_checking =
344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      cmd->HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking);
345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_ANDROID)
347116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SynchronousCompositorFactory* synchronous_compositor_factory =
348116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      SynchronousCompositorFactory::GetInstance();
349116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
350116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.using_synchronous_renderer_compositor =
351116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      synchronous_compositor_factory;
352116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.record_full_layer =
353116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      synchronous_compositor_factory &&
354116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      synchronous_compositor_factory->RecordFullLayer();
355116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.report_overscroll_only_for_scrollable_axes =
356116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      !synchronous_compositor_factory;
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  settings.max_partial_texture_updates = 0;
358116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (synchronous_compositor_factory) {
359010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    // Android WebView uses system scrollbars, so make ours invisible.
360010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.scrollbar_animator = cc::LayerTreeSettings::NoAnimator;
361010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT;
362010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  } else {
363010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
364010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.scrollbar_fade_delay_ms = 300;
365010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.scrollbar_fade_duration_ms = 300;
366010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
367010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
368c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  settings.highp_threshold_min = 2048;
369a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Android WebView handles root layer flings itself.
370a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  settings.ignore_root_layer_flings =
371116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      synchronous_compositor_factory;
372116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Memory policy on Android WebView does not depend on whether device is
373116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // low end, so always use default policy.
374116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool is_low_end_device =
375116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::SysInfo::IsLowEndDevice() && !synchronous_compositor_factory;
376d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // RGBA_4444 textures are only enabled for low end devices
377d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // and are disabled for Android WebView as it doesn't support the format.
378116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  settings.use_rgba_4444_textures = is_low_end_device;
379116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (is_low_end_device) {
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // On low-end we want to be very carefull about killing other
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // apps. So initially we use 50% more memory to avoid flickering
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // or raster-on-demand.
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    settings.max_memory_for_prepaint_percentage = 67;
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // On other devices we have increased memory excessively to avoid
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // raster-on-demand already, so now we reserve 50% _only_ to avoid
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // raster-on-demand, and use 50% of the memory otherwise.
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    settings.max_memory_for_prepaint_percentage = 50;
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
390effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Webview does not own the surface so should not clear it.
391effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  settings.should_clear_root_render_pass =
392116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      !synchronous_compositor_factory;
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(danakj): Only do this on low end devices.
3951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  settings.create_low_res_tiling = true;
3961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
397c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch#elif !defined(OS_MACOSX)
39823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  if (ui::IsOverlayScrollbarEnabled()) {
39958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    settings.scrollbar_animator = cc::LayerTreeSettings::Thinning;
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport)) {
4025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // use_pinch_zoom_scrollbars is only true on desktop when non-overlay
4035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // scrollbars are in use.
4045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    settings.use_pinch_zoom_scrollbars = true;
4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
406c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
407c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  }
408010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  settings.scrollbar_fade_delay_ms = 500;
409010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  settings.scrollbar_fade_duration_ms = 300;
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (cmd->HasSwitch(switches::kEnableLowResTiling))
4131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    settings.create_low_res_tiling = true;
4141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (cmd->HasSwitch(switches::kDisableLowResTiling))
4151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    settings.create_low_res_tiling = false;
4161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  compositor->Initialize(settings);
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return compositor.Pass();
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochRenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget,
423ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                               bool threaded)
424ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    : threaded_(threaded),
4251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      widget_(widget),
4261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      send_v8_idle_notification_after_commit_(true) {
4271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CommandLine* cmd = CommandLine::ForCurrentProcess();
4281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (cmd->HasSwitch(switches::kEnableV8IdleNotificationAfterCommit))
4301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    send_v8_idle_notification_after_commit_ = true;
4311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (cmd->HasSwitch(switches::kDisableV8IdleNotificationAfterCommit))
4321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    send_v8_idle_notification_after_commit_ = false;
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)RenderWidgetCompositor::~RenderWidgetCompositor() {}
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
43790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const base::WeakPtr<cc::InputHandler>&
43890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)RenderWidgetCompositor::GetInputHandler() {
43990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return layer_tree_host_->GetInputHandler();
44090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
44190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool RenderWidgetCompositor::BeginMainFrameRequested() const {
4431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return layer_tree_host_->BeginMainFrameRequested();
4441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
4451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
446c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void RenderWidgetCompositor::SetNeedsDisplayOnAllLayers() {
447c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  layer_tree_host_->SetNeedsDisplayOnAllLayers();
448c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
449c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
45090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void RenderWidgetCompositor::SetRasterizeOnlyVisibleContent() {
45190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  cc::LayerTreeDebugState current = layer_tree_host_->debug_state();
45290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  current.rasterize_only_visible_content = true;
45390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  layer_tree_host_->SetDebugState(current);
45490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
45590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
45690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void RenderWidgetCompositor::UpdateTopControlsState(
45790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    cc::TopControlsState constraints,
45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    cc::TopControlsState current,
45990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    bool animate) {
46090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  layer_tree_host_->UpdateTopControlsState(constraints,
46190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                           current,
462c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                           animate);
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderWidgetCompositor::SetTopControlsLayoutHeight(float height) {
4661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  layer_tree_host_->SetTopControlsLayoutHeight(height);
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
469c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void RenderWidgetCompositor::SetNeedsRedrawRect(gfx::Rect damage_rect) {
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  layer_tree_host_->SetNeedsRedrawRect(damage_rect);
471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
472c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void RenderWidgetCompositor::SetNeedsForcedRedraw() {
4744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  layer_tree_host_->SetNextCommitForcesRedraw();
475f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  setNeedsAnimate();
4764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
4774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
478a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)scoped_ptr<cc::SwapPromiseMonitor>
479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)RenderWidgetCompositor::CreateLatencyInfoSwapPromiseMonitor(
480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ui::LatencyInfo* latency) {
481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return scoped_ptr<cc::SwapPromiseMonitor>(
482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      new cc::LatencyInfoSwapPromiseMonitor(
483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          latency, layer_tree_host_.get(), NULL));
484b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
485b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
486cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void RenderWidgetCompositor::QueueSwapPromise(
487cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    scoped_ptr<cc::SwapPromise> swap_promise) {
488cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  layer_tree_host_->QueueSwapPromise(swap_promise.Pass());
489cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
490cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
491a3f7b4e666c476898878fa745f637129375cd889Ben Murdochint RenderWidgetCompositor::GetLayerTreeId() const {
492a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  return layer_tree_host_->id();
493a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch}
494a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)int RenderWidgetCompositor::GetSourceFrameNumber() const {
4965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return layer_tree_host_->source_frame_number();
4975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
4985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
4995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void RenderWidgetCompositor::SetNeedsCommit() {
5005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  layer_tree_host_->SetNeedsCommit();
5015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
5025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
503a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void RenderWidgetCompositor::NotifyInputThrottledUntilCommit() {
504a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  layer_tree_host_->NotifyInputThrottledUntilCommit();
505a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
506a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
5073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const cc::Layer* RenderWidgetCompositor::GetRootLayer() const {
5083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return layer_tree_host_->root_layer();
5093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
5103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
511cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)int RenderWidgetCompositor::ScheduleMicroBenchmark(
5124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const std::string& name,
5138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    scoped_ptr<base::Value> value,
5144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const base::Callback<void(scoped_ptr<base::Value>)>& callback) {
5158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback);
5164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
5174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
518cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool RenderWidgetCompositor::SendMessageToMicroBenchmark(
519cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    int id,
520cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    scoped_ptr<base::Value> value) {
521cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass());
522cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
523cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
5255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy;
5261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_refptr<base::SingleThreadTaskRunner>
5271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      main_thread_compositor_task_runner(base::MessageLoopProxy::current());
5285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RenderThreadImpl* render_thread = RenderThreadImpl::current();
5295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  cc::SharedBitmapManager* shared_bitmap_manager = NULL;
5305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // render_thread may be NULL in tests.
5315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (render_thread) {
5325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    compositor_message_loop_proxy =
5335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        render_thread->compositor_message_loop_proxy();
5345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    shared_bitmap_manager = render_thread->shared_bitmap_manager();
5351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    main_thread_compositor_task_runner =
5361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        render_thread->main_thread_compositor_task_runner();
5375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
538f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (compositor_message_loop_proxy.get()) {
5391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    layer_tree_host_ =
5401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        cc::LayerTreeHost::CreateThreaded(this,
5411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                          shared_bitmap_manager,
5421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                          settings,
5431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                          main_thread_compositor_task_runner,
5441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                          compositor_message_loop_proxy);
545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else {
546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
5475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        this,
5485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        this,
5495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        shared_bitmap_manager,
5505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        settings,
5511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        main_thread_compositor_task_runner);
552f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(layer_tree_host_);
5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setSurfaceReady() {
55703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // In tests without a RenderThreadImpl, don't set ready as this kicks
55803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // off creating output surfaces that the test can't create.
55903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (RenderThreadImpl::current())
56003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    layer_tree_host_->SetLayerTreeHostClientReady();
5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
563f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::setRootLayer(const blink::WebLayer& layer) {
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetRootLayer(
56503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      static_cast<const cc_blink::WebLayerImpl*>(&layer)->layer());
5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::clearRootLayer() {
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setViewportSize(
573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const WebSize&,
5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebSize& device_viewport_size) {
575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  layer_tree_host_->SetViewportSize(device_viewport_size);
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
578cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void RenderWidgetCompositor::setViewportSize(
579cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    const WebSize& device_viewport_size) {
580cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  layer_tree_host_->SetViewportSize(device_viewport_size);
581cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
582cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebSize RenderWidgetCompositor::layoutViewportSize() const {
584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return layer_tree_host_->device_viewport_size();
5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebSize RenderWidgetCompositor::deviceViewportSize() const {
5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return layer_tree_host_->device_viewport_size();
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebFloatPoint RenderWidgetCompositor::adjustEventPointForPinchZoom(
5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebFloatPoint& point) const {
5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return point;
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setDeviceScaleFactor(float device_scale) {
5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDeviceScaleFactor(device_scale);
5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float RenderWidgetCompositor::deviceScaleFactor() const {
6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return layer_tree_host_->device_scale_factor();
6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
604f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::setBackgroundColor(blink::WebColor color) {
6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->set_background_color(color);
6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setHasTransparentBackground(bool transparent) {
6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->set_has_transparent_background(transparent);
6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
61258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void RenderWidgetCompositor::setOverhangBitmap(const SkBitmap& bitmap) {
61358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  layer_tree_host_->SetOverhangBitmap(bitmap);
61458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
61558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setVisible(bool visible) {
6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetVisible(visible);
6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setPageScaleFactorAndLimits(
6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float page_scale_factor, float minimum, float maximum) {
6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetPageScaleFactorAndLimits(
6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      page_scale_factor, minimum, maximum);
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::startPageScaleAnimation(
627f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebPoint& destination,
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool use_anchor,
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float new_page_scale,
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    double duration_sec) {
6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta duration = base::TimeDelta::FromMicroseconds(
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      duration_sec * base::Time::kMicrosecondsPerSecond);
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->StartPageScaleAnimation(
6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      gfx::Vector2d(destination.x, destination.y),
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      use_anchor,
6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      new_page_scale,
6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      duration);
6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid RenderWidgetCompositor::heuristicsForGpuRasterizationUpdated(
6415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    bool matches_heuristics) {
64246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  layer_tree_host_->SetHasGpuRasterizationTrigger(matches_heuristics);
6435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
6445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setNeedsAnimate() {
6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetNeedsAnimate();
6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool RenderWidgetCompositor::commitRequested() const {
6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return layer_tree_host_->CommitRequested();
6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::didStopFlinging() {
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->DidStopFlinging();
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
657f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::registerForAnimations(blink::WebLayer* layer) {
65803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  cc::Layer* cc_layer = static_cast<cc_blink::WebLayerImpl*>(layer)->layer();
6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc_layer->layer_animation_controller()->SetAnimationRegistrar(
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      layer_tree_host_->animation_registrar());
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
663d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void RenderWidgetCompositor::registerViewportLayers(
664f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebLayer* pageScaleLayer,
665f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebLayer* innerViewportScrollLayer,
666f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebLayer* outerViewportScrollLayer) {
667d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  layer_tree_host_->RegisterViewportLayers(
66803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(),
66903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer)
67003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)          ->layer(),
671d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // The outer viewport layer will only exist when using pinch virtual
672d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // viewports.
67303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      outerViewportScrollLayer ? static_cast<const cc_blink::WebLayerImpl*>(
67403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                     outerViewportScrollLayer)->layer()
67503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                               : NULL);
676d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
677d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
678d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void RenderWidgetCompositor::clearViewportLayers() {
679d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
680d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                           scoped_refptr<cc::Layer>(),
681d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                           scoped_refptr<cc::Layer>());
682d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
683d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
684116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderWidgetCompositor::registerSelection(
685116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const blink::WebSelectionBound& start,
686116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const blink::WebSelectionBound& end) {
687116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  layer_tree_host_->RegisterSelection(ConvertWebSelectionBound(start),
688116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                      ConvertWebSelectionBound(end));
689116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
690116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
691116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderWidgetCompositor::clearSelection() {
692116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  cc::LayerSelectionBound empty_selection;
693116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  layer_tree_host_->RegisterSelection(empty_selection, empty_selection);
694116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
695116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
696010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void CompositeAndReadbackAsyncCallback(
697010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    blink::WebCompositeAndReadbackAsyncCallback* callback,
698010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    scoped_ptr<cc::CopyOutputResult> result) {
699010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (result->HasBitmap()) {
700010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap();
701010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    callback->didCompositeAndReadback(*result_bitmap);
702010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  } else {
703010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    callback->didCompositeAndReadback(SkBitmap());
704010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
705010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
706010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
707010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void RenderWidgetCompositor::compositeAndReadbackAsync(
708010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    blink::WebCompositeAndReadbackAsyncCallback* callback) {
709010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  DCHECK(layer_tree_host_->root_layer());
710010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  scoped_ptr<cc::CopyOutputRequest> request =
711010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      cc::CopyOutputRequest::CreateBitmapRequest(
712010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          base::Bind(&CompositeAndReadbackAsyncCallback, callback));
713010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  layer_tree_host_->root_layer()->RequestCopyOfOutput(request.Pass());
71403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
71503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (!threaded_ &&
71603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      !layer_tree_host_->settings().single_thread_proxy_scheduler) {
717010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    layer_tree_host_->Composite(gfx::FrameTime::Now());
718010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
719010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
720010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::finishAllRendering() {
7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->FinishAllRendering();
7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setDeferCommits(bool defer_commits) {
7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDeferCommits(defer_commits);
7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setShowFPSCounter(bool show) {
7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  debug_state.show_fps_counter = show;
7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDebugState(debug_state);
7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setShowPaintRects(bool show) {
7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  debug_state.show_paint_rects = show;
7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDebugState(debug_state);
7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setShowDebugBorders(bool show) {
7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  debug_state.show_debug_borders = show;
7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDebugState(debug_state);
7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::setContinuousPaintingEnabled(bool enabled) {
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  debug_state.continuous_painting = enabled;
7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  layer_tree_host_->SetDebugState(debug_state);
7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid RenderWidgetCompositor::setShowScrollBottleneckRects(bool show) {
7547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
7557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  debug_state.show_touch_event_handler_rects = show;
7567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  debug_state.show_wheel_event_handler_rects = show;
7577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  debug_state.show_non_fast_scrollable_rects = show;
7587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  layer_tree_host_->SetDebugState(debug_state);
7597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
7607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
7611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderWidgetCompositor::setTopControlsContentOffset(float offset) {
7621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  layer_tree_host_->SetTopControlsContentOffset(offset);
7631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
7641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
765f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::WillBeginMainFrame(int frame_id) {
766f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  widget_->InstrumentWillBeginFrame(frame_id);
7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->willBeginCompositorFrame();
7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void RenderWidgetCompositor::DidBeginMainFrame() {
7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->InstrumentDidBeginFrame();
7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
77403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void RenderWidgetCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
7751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  begin_main_frame_time_ = args.frame_time;
7761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  begin_main_frame_interval_ = args.interval;
7771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF();
7781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  double deadline_sec = (args.deadline - base::TimeTicks()).InSecondsF();
7791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  double interval_sec = args.interval.InSecondsF();
7801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  WebBeginFrameArgs web_begin_frame_args =
7811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      WebBeginFrameArgs(frame_time_sec, deadline_sec, interval_sec);
78203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  widget_->webwidget()->beginFrame(web_begin_frame_args);
7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::Layout() {
7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->webwidget()->layout();
7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderWidgetCompositor::ApplyViewportDeltas(
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const gfx::Vector2d& scroll_delta,
7911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    float page_scale,
7921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    float top_controls_delta) {
7931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  widget_->webwidget()->applyViewportDeltas(
7941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      scroll_delta,
7951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      page_scale,
7961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      top_controls_delta);
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderWidgetCompositor::RequestNewOutputSurface(bool fallback) {
8001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  layer_tree_host_->SetOutputSurface(widget_->CreateOutputSurface(fallback));
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid RenderWidgetCompositor::DidInitializeOutputSurface() {
8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::WillCommit() {
8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->InstrumentWillComposite();
8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::DidCommit() {
8111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (send_v8_idle_notification_after_commit_) {
8121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    base::TimeDelta idle_time = begin_main_frame_time_ +
8131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                begin_main_frame_interval_ -
8141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                gfx::FrameTime::Now();
8151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (idle_time > base::TimeDelta()) {
8161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      // Convert to 32-bit microseconds first to avoid costly 64-bit division.
8171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      int32 idle_time_in_us = idle_time.InMicroseconds();
8181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      int32 idle_time_in_ms = idle_time_in_us / 1000;
8191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      if (idle_time_in_ms)
8201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        blink::mainThreadIsolate()->IdleNotification(idle_time_in_ms);
8211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    }
8221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
8231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->DidCommitCompositorFrame();
8252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->didBecomeReadyForAdditionalInput();
8261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  widget_->webwidget()->didCommitFrameToCompositor();
8272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::DidCommitAndDrawFrame() {
8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->didCommitAndDrawCompositorFrame();
8312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RenderWidgetCompositor::DidCompleteSwapBuffers() {
8342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget_->didCompleteSwapBuffers();
835f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!threaded_)
836f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    widget_->OnSwapBuffersComplete();
837f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
838f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
839f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::ScheduleAnimation() {
840f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  widget_->scheduleAnimation();
841f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
842f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
843f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::DidPostSwapBuffers() {
844f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  widget_->OnSwapBuffersPosted();
845f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
846f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
847f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::DidAbortSwapBuffers() {
848f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  widget_->OnSwapBuffersAborted();
849f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
850f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderWidgetCompositor::RateLimitSharedMainThreadContext() {
852f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  cc::ContextProvider* provider =
853f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
8545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  provider->ContextGL()->RateLimitOffscreenContextCHROMIUM();
8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace content
858