| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <cmath> |
| 8 #include <limits> | 10 #include <limits> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <utility> | 12 #include <utility> |
| 11 | 13 |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 16 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 42 #include "cc/proto/compositor_message.pb.h" | 44 #include "cc/proto/compositor_message.pb.h" |
| 43 #include "cc/resources/single_release_callback.h" | 45 #include "cc/resources/single_release_callback.h" |
| 44 #include "cc/scheduler/begin_frame_source.h" | 46 #include "cc/scheduler/begin_frame_source.h" |
| 45 #include "cc/trees/latency_info_swap_promise_monitor.h" | 47 #include "cc/trees/latency_info_swap_promise_monitor.h" |
| 46 #include "cc/trees/layer_tree_host_in_process.h" | 48 #include "cc/trees/layer_tree_host_in_process.h" |
| 47 #include "cc/trees/layer_tree_mutator.h" | 49 #include "cc/trees/layer_tree_mutator.h" |
| 48 #include "content/common/content_switches_internal.h" | 50 #include "content/common/content_switches_internal.h" |
| 49 #include "content/common/layer_tree_settings_factory.h" | 51 #include "content/common/layer_tree_settings_factory.h" |
| 50 #include "content/public/common/content_client.h" | 52 #include "content/public/common/content_client.h" |
| 51 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
| 54 #include "content/public/common/screen_info.h" |
| 52 #include "content/public/renderer/content_renderer_client.h" | 55 #include "content/public/renderer/content_renderer_client.h" |
| 53 #include "content/renderer/gpu/render_widget_compositor_delegate.h" | 56 #include "content/renderer/gpu/render_widget_compositor_delegate.h" |
| 54 #include "content/renderer/input/input_handler_manager.h" | 57 #include "content/renderer/input/input_handler_manager.h" |
| 55 #include "gpu/command_buffer/client/gles2_interface.h" | 58 #include "gpu/command_buffer/client/gles2_interface.h" |
| 56 #include "gpu/command_buffer/service/gpu_switches.h" | 59 #include "gpu/command_buffer/service/gpu_switches.h" |
| 57 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 60 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 58 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 61 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 59 #include "third_party/WebKit/public/platform/WebCompositorMutatorClient.h" | 62 #include "third_party/WebKit/public/platform/WebCompositorMutatorClient.h" |
| 60 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 63 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
| 61 #include "third_party/WebKit/public/platform/WebSize.h" | 64 #include "third_party/WebKit/public/platform/WebSize.h" |
| 62 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 65 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
| 63 #include "third_party/WebKit/public/web/WebKit.h" | 66 #include "third_party/WebKit/public/web/WebKit.h" |
| 64 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 67 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 65 #include "third_party/WebKit/public/web/WebSelection.h" | 68 #include "third_party/WebKit/public/web/WebSelection.h" |
| 66 #include "ui/gl/gl_switches.h" | 69 #include "ui/gl/gl_switches.h" |
| 67 #include "ui/native_theme/native_theme_switches.h" | 70 #include "ui/native_theme/native_theme_switches.h" |
| 68 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" | 71 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" |
| 69 | 72 |
| 70 #if defined(OS_ANDROID) | |
| 71 #include "base/android/build_info.h" | |
| 72 #include "ui/gfx/android/device_display_info.h" | |
| 73 #endif | |
| 74 | |
| 75 namespace base { | 73 namespace base { |
| 76 class Value; | 74 class Value; |
| 77 } | 75 } |
| 78 | 76 |
| 79 namespace cc { | 77 namespace cc { |
| 80 class Layer; | 78 class Layer; |
| 81 } | 79 } |
| 82 | 80 |
| 83 using blink::WebFloatPoint; | 81 using blink::WebFloatPoint; |
| 84 using blink::WebRect; | 82 using blink::WebRect; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 cc::LayerSelection ConvertWebSelection(const WebSelection& web_selection) { | 134 cc::LayerSelection ConvertWebSelection(const WebSelection& web_selection) { |
| 137 cc::LayerSelection cc_selection; | 135 cc::LayerSelection cc_selection; |
| 138 cc_selection.start = ConvertWebSelectionBound(web_selection, true); | 136 cc_selection.start = ConvertWebSelectionBound(web_selection, true); |
| 139 cc_selection.end = ConvertWebSelectionBound(web_selection, false); | 137 cc_selection.end = ConvertWebSelectionBound(web_selection, false); |
| 140 cc_selection.is_editable = web_selection.isEditable(); | 138 cc_selection.is_editable = web_selection.isEditable(); |
| 141 cc_selection.is_empty_text_form_control = | 139 cc_selection.is_empty_text_form_control = |
| 142 web_selection.isEmptyTextFormControl(); | 140 web_selection.isEmptyTextFormControl(); |
| 143 return cc_selection; | 141 return cc_selection; |
| 144 } | 142 } |
| 145 | 143 |
| 146 gfx::Size CalculateDefaultTileSize(float initial_device_scale_factor) { | 144 gfx::Size CalculateDefaultTileSize(float initial_device_scale_factor, |
| 145 const ScreenInfo& screen_info) { |
| 147 int default_tile_size = 256; | 146 int default_tile_size = 256; |
| 148 #if defined(OS_ANDROID) | 147 #if defined(OS_ANDROID) |
| 149 // TODO(epenner): unify this for all platforms if it | 148 const gfx::Size screen_size = gfx::ScaleToFlooredSize( |
| 150 // makes sense (http://crbug.com/159524) | 149 screen_info.rect.size(), screen_info.device_scale_factor); |
| 150 int display_width = screen_size.width(); |
| 151 int display_height = screen_size.height(); |
| 152 int numTiles = (display_width * display_height) / (256 * 256); |
| 153 if (numTiles > 16) |
| 154 default_tile_size = 384; |
| 155 if (numTiles >= 40) |
| 156 default_tile_size = 512; |
| 151 | 157 |
| 152 gfx::DeviceDisplayInfo info; | 158 // Adjust for some resolutions that barely straddle an extra |
| 153 bool real_size_supported = true; | 159 // tile when in portrait mode. This helps worst case scroll/raster |
| 154 int display_width = info.GetPhysicalDisplayWidth(); | 160 // by not needing a full extra tile for each row. |
| 155 int display_height = info.GetPhysicalDisplayHeight(); | 161 constexpr int tolerance = 10; // To avoid rounding errors. |
| 156 if (display_width == 0 || display_height == 0) { | |
| 157 real_size_supported = false; | |
| 158 display_width = info.GetDisplayWidth(); | |
| 159 display_height = info.GetDisplayHeight(); | |
| 160 } | |
| 161 | |
| 162 int portrait_width = std::min(display_width, display_height); | 162 int portrait_width = std::min(display_width, display_height); |
| 163 int landscape_width = std::max(display_width, display_height); | 163 if (default_tile_size == 256 && std::abs(portrait_width - 768) < tolerance) |
| 164 | 164 default_tile_size += 32; |
| 165 if (real_size_supported) { | 165 if (default_tile_size == 384 && std::abs(portrait_width - 1200) < tolerance) |
| 166 // Maximum HD dimensions should be 768x1280 | 166 default_tile_size += 32; |
| 167 // Maximum FHD dimensions should be 1200x1920 | |
| 168 if (portrait_width > 768 || landscape_width > 1280) | |
| 169 default_tile_size = 384; | |
| 170 if (portrait_width > 1200 || landscape_width > 1920) | |
| 171 default_tile_size = 512; | |
| 172 | |
| 173 // Adjust for some resolutions that barely straddle an extra | |
| 174 // tile when in portrait mode. This helps worst case scroll/raster | |
| 175 // by not needing a full extra tile for each row. | |
| 176 if (default_tile_size == 256 && portrait_width == 768) | |
| 177 default_tile_size += 32; | |
| 178 if (default_tile_size == 384 && portrait_width == 1200) | |
| 179 default_tile_size += 32; | |
| 180 } else { | |
| 181 // We don't know the exact resolution due to screen controls etc. | |
| 182 // So this just estimates the values above using tile counts. | |
| 183 int numTiles = (display_width * display_height) / (256 * 256); | |
| 184 if (numTiles > 16) | |
| 185 default_tile_size = 384; | |
| 186 if (numTiles >= 40) | |
| 187 default_tile_size = 512; | |
| 188 } | |
| 189 #elif defined(OS_CHROMEOS) || defined(OS_MACOSX) | 167 #elif defined(OS_CHROMEOS) || defined(OS_MACOSX) |
| 190 // Use 512 for high DPI (dsf=2.0f) devices. | 168 // Use 512 for high DPI (dsf=2.0f) devices. |
| 191 if (initial_device_scale_factor >= 2.0f) | 169 if (initial_device_scale_factor >= 2.0f) |
| 192 default_tile_size = 512; | 170 default_tile_size = 512; |
| 193 #endif | 171 #endif |
| 194 | 172 |
| 195 return gfx::Size(default_tile_size, default_tile_size); | 173 return gfx::Size(default_tile_size, default_tile_size); |
| 196 } | 174 } |
| 197 | 175 |
| 198 // Check cc::BrowserControlsState, and blink::WebBrowserControlsState | 176 // Check cc::BrowserControlsState, and blink::WebBrowserControlsState |
| 199 // are kept in sync. | 177 // are kept in sync. |
| 200 static_assert(int(blink::WebBrowserControlsBoth) == int(cc::BOTH), | 178 static_assert(int(blink::WebBrowserControlsBoth) == int(cc::BOTH), |
| 201 "mismatching enums: BOTH"); | 179 "mismatching enums: BOTH"); |
| 202 static_assert(int(blink::WebBrowserControlsHidden) == int(cc::HIDDEN), | 180 static_assert(int(blink::WebBrowserControlsHidden) == int(cc::HIDDEN), |
| 203 "mismatching enums: HIDDEN"); | 181 "mismatching enums: HIDDEN"); |
| 204 static_assert(int(blink::WebBrowserControlsShown) == int(cc::SHOWN), | 182 static_assert(int(blink::WebBrowserControlsShown) == int(cc::SHOWN), |
| 205 "mismatching enums: SHOWN"); | 183 "mismatching enums: SHOWN"); |
| 206 | 184 |
| 207 static cc::BrowserControlsState ConvertBrowserControlsState( | 185 static cc::BrowserControlsState ConvertBrowserControlsState( |
| 208 WebBrowserControlsState state) { | 186 WebBrowserControlsState state) { |
| 209 return static_cast<cc::BrowserControlsState>(state); | 187 return static_cast<cc::BrowserControlsState>(state); |
| 210 } | 188 } |
| 211 | 189 |
| 212 } // namespace | 190 } // namespace |
| 213 | 191 |
| 214 // static | 192 // static |
| 215 std::unique_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( | 193 std::unique_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( |
| 216 RenderWidgetCompositorDelegate* delegate, | 194 RenderWidgetCompositorDelegate* delegate, |
| 217 float device_scale_factor, | 195 float device_scale_factor, |
| 196 const ScreenInfo& screen_info, |
| 218 CompositorDependencies* compositor_deps) { | 197 CompositorDependencies* compositor_deps) { |
| 219 std::unique_ptr<RenderWidgetCompositor> compositor( | 198 std::unique_ptr<RenderWidgetCompositor> compositor( |
| 220 new RenderWidgetCompositor(delegate, compositor_deps)); | 199 new RenderWidgetCompositor(delegate, compositor_deps)); |
| 221 compositor->Initialize(device_scale_factor); | 200 compositor->Initialize(device_scale_factor, screen_info); |
| 222 return compositor; | 201 return compositor; |
| 223 } | 202 } |
| 224 | 203 |
| 225 RenderWidgetCompositor::RenderWidgetCompositor( | 204 RenderWidgetCompositor::RenderWidgetCompositor( |
| 226 RenderWidgetCompositorDelegate* delegate, | 205 RenderWidgetCompositorDelegate* delegate, |
| 227 CompositorDependencies* compositor_deps) | 206 CompositorDependencies* compositor_deps) |
| 228 : num_failed_recreate_attempts_(0), | 207 : num_failed_recreate_attempts_(0), |
| 229 delegate_(delegate), | 208 delegate_(delegate), |
| 230 compositor_deps_(compositor_deps), | 209 compositor_deps_(compositor_deps), |
| 231 threaded_(!!compositor_deps_->GetCompositorImplThreadTaskRunner()), | 210 threaded_(!!compositor_deps_->GetCompositorImplThreadTaskRunner()), |
| 232 never_visible_(false), | 211 never_visible_(false), |
| 233 layout_and_paint_async_callback_(nullptr), | 212 layout_and_paint_async_callback_(nullptr), |
| 234 remote_proto_channel_receiver_(nullptr), | 213 remote_proto_channel_receiver_(nullptr), |
| 235 weak_factory_(this) {} | 214 weak_factory_(this) {} |
| 236 | 215 |
| 237 void RenderWidgetCompositor::Initialize(float device_scale_factor) { | 216 void RenderWidgetCompositor::Initialize(float device_scale_factor, |
| 217 const ScreenInfo& screen_info) { |
| 238 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 218 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 239 cc::LayerTreeSettings settings = | 219 cc::LayerTreeSettings settings = GenerateLayerTreeSettings( |
| 240 GenerateLayerTreeSettings(*cmd, compositor_deps_, device_scale_factor); | 220 *cmd, compositor_deps_, device_scale_factor, screen_info); |
| 241 | 221 |
| 242 animation_host_ = cc::AnimationHost::CreateMainInstance(); | 222 animation_host_ = cc::AnimationHost::CreateMainInstance(); |
| 243 | 223 |
| 244 if (cmd->HasSwitch(switches::kUseRemoteCompositing)) { | 224 if (cmd->HasSwitch(switches::kUseRemoteCompositing)) { |
| 245 DCHECK(!threaded_); | 225 DCHECK(!threaded_); |
| 246 | 226 |
| 247 cc::LayerTreeHostRemote::InitParams params; | 227 cc::LayerTreeHostRemote::InitParams params; |
| 248 params.client = this; | 228 params.client = this; |
| 249 params.main_task_runner = | 229 params.main_task_runner = |
| 250 compositor_deps_->GetCompositorMainThreadTaskRunner(); | 230 compositor_deps_->GetCompositorMainThreadTaskRunner(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 277 | 257 |
| 278 DCHECK(layer_tree_host_); | 258 DCHECK(layer_tree_host_); |
| 279 } | 259 } |
| 280 | 260 |
| 281 RenderWidgetCompositor::~RenderWidgetCompositor() = default; | 261 RenderWidgetCompositor::~RenderWidgetCompositor() = default; |
| 282 | 262 |
| 283 // static | 263 // static |
| 284 cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( | 264 cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( |
| 285 const base::CommandLine& cmd, | 265 const base::CommandLine& cmd, |
| 286 CompositorDependencies* compositor_deps, | 266 CompositorDependencies* compositor_deps, |
| 287 float device_scale_factor) { | 267 float device_scale_factor, |
| 268 const ScreenInfo& screen_info) { |
| 288 cc::LayerTreeSettings settings; | 269 cc::LayerTreeSettings settings; |
| 289 | 270 |
| 290 // For web contents, layer transforms should scale up the contents of layers | 271 // For web contents, layer transforms should scale up the contents of layers |
| 291 // to keep content always crisp when possible. | 272 // to keep content always crisp when possible. |
| 292 settings.layer_transforms_should_scale_layer_contents = true; | 273 settings.layer_transforms_should_scale_layer_contents = true; |
| 293 | 274 |
| 294 settings.main_frame_before_activation_enabled = | 275 settings.main_frame_before_activation_enabled = |
| 295 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation); | 276 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation); |
| 296 | 277 |
| 297 // TODO(danakj): This should not be a setting O_O; it should change when the | 278 // TODO(danakj): This should not be a setting O_O; it should change when the |
| 298 // device scale factor on LayerTreeHost changes. | 279 // device scale factor on LayerTreeHost changes. |
| 299 settings.default_tile_size = CalculateDefaultTileSize(device_scale_factor); | 280 settings.default_tile_size = |
| 281 CalculateDefaultTileSize(device_scale_factor, screen_info); |
| 300 if (cmd.HasSwitch(switches::kDefaultTileWidth)) { | 282 if (cmd.HasSwitch(switches::kDefaultTileWidth)) { |
| 301 int tile_width = 0; | 283 int tile_width = 0; |
| 302 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1, | 284 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1, |
| 303 std::numeric_limits<int>::max(), &tile_width); | 285 std::numeric_limits<int>::max(), &tile_width); |
| 304 settings.default_tile_size.set_width(tile_width); | 286 settings.default_tile_size.set_width(tile_width); |
| 305 } | 287 } |
| 306 if (cmd.HasSwitch(switches::kDefaultTileHeight)) { | 288 if (cmd.HasSwitch(switches::kDefaultTileHeight)) { |
| 307 int tile_height = 0; | 289 int tile_height = 0; |
| 308 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1, | 290 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1, |
| 309 std::numeric_limits<int>::max(), &tile_height); | 291 std::numeric_limits<int>::max(), &tile_height); |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 float device_scale) { | 1116 float device_scale) { |
| 1135 layer_tree_host_->GetLayerTree()->SetPaintedDeviceScaleFactor(device_scale); | 1117 layer_tree_host_->GetLayerTree()->SetPaintedDeviceScaleFactor(device_scale); |
| 1136 } | 1118 } |
| 1137 | 1119 |
| 1138 void RenderWidgetCompositor::SetDeviceColorSpace( | 1120 void RenderWidgetCompositor::SetDeviceColorSpace( |
| 1139 const gfx::ColorSpace& color_space) { | 1121 const gfx::ColorSpace& color_space) { |
| 1140 layer_tree_host_->GetLayerTree()->SetDeviceColorSpace(color_space); | 1122 layer_tree_host_->GetLayerTree()->SetDeviceColorSpace(color_space); |
| 1141 } | 1123 } |
| 1142 | 1124 |
| 1143 } // namespace content | 1125 } // namespace content |
| OLD | NEW |