Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "cc/layers/layer.h" | 26 #include "cc/layers/layer.h" |
| 27 #include "cc/layers/surface_layer.h" | 27 #include "cc/layers/surface_layer.h" |
| 28 #include "cc/output/compositor_frame.h" | 28 #include "cc/output/compositor_frame.h" |
| 29 #include "cc/output/copy_output_request.h" | 29 #include "cc/output/copy_output_request.h" |
| 30 #include "cc/output/copy_output_result.h" | 30 #include "cc/output/copy_output_result.h" |
| 31 #include "cc/output/latency_info_swap_promise.h" | 31 #include "cc/output/latency_info_swap_promise.h" |
| 32 #include "cc/quads/solid_color_draw_quad.h" | |
| 32 #include "cc/resources/single_release_callback.h" | 33 #include "cc/resources/single_release_callback.h" |
| 33 #include "cc/surfaces/surface.h" | 34 #include "cc/surfaces/surface.h" |
| 34 #include "cc/surfaces/surface_hittest.h" | 35 #include "cc/surfaces/surface_hittest.h" |
| 35 #include "cc/surfaces/surface_manager.h" | 36 #include "cc/surfaces/surface_manager.h" |
| 36 #include "cc/trees/layer_tree_host.h" | 37 #include "cc/trees/layer_tree_host.h" |
| 37 #include "components/viz/display_compositor/gl_helper.h" | 38 #include "components/viz/display_compositor/gl_helper.h" |
| 38 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 39 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 39 #include "content/browser/android/composited_touch_handle_drawable.h" | 40 #include "content/browser/android/composited_touch_handle_drawable.h" |
| 40 #include "content/browser/android/content_view_core_impl.h" | 41 #include "content/browser/android/content_view_core_impl.h" |
| 41 #include "content/browser/android/ime_adapter_android.h" | 42 #include "content/browser/android/ime_adapter_android.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 RenderWidgetHostView* reference_host_view) { | 553 RenderWidgetHostView* reference_host_view) { |
| 553 NOTIMPLEMENTED(); | 554 NOTIMPLEMENTED(); |
| 554 } | 555 } |
| 555 | 556 |
| 556 RenderWidgetHost* | 557 RenderWidgetHost* |
| 557 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 558 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
| 558 return host_; | 559 return host_; |
| 559 } | 560 } |
| 560 | 561 |
| 561 void RenderWidgetHostViewAndroid::WasResized() { | 562 void RenderWidgetHostViewAndroid::WasResized() { |
| 563 // If we're entering a fullscreen transition, show black until the transition | |
| 564 // is completed. | |
| 565 if (content_view_core_ && | |
| 566 view_.GetPhysicalBackingSize() != prev_physical_backing_size_) { | |
| 567 bool is_fullscreen = content_view_core_->GetWebContents()->IsFullscreen(); | |
| 568 if (is_fullscreen || was_fullscreen_) { | |
| 569 fullscreen_transitioning_ = true; | |
| 570 | |
| 571 // Immediately queue a black frame to hide jank while we wait to receive a | |
| 572 // "good" frame via SubmitCompositorFrame. | |
| 573 cc::CompositorFrame frame; | |
| 574 frame.render_pass_list.push_back(CreateBlackRenderPass()); | |
| 575 frame.metadata.root_background_color = SK_ColorBLACK; | |
| 576 delegated_frame_host_->ForceFrame(std::move(frame)); | |
| 577 UpdateBackgroundColor(SK_ColorBLACK); | |
| 578 } | |
| 579 was_fullscreen_ = is_fullscreen; | |
| 580 prev_physical_backing_size_ = view_.GetPhysicalBackingSize(); | |
|
Khushal
2017/05/24 05:14:22
I'm a bit confused about saving the previous fulls
steimel
2017/05/24 19:32:58
Hmm I may be able to simplify some of the logic, b
| |
| 581 } | |
| 562 host_->WasResized(); | 582 host_->WasResized(); |
| 563 } | 583 } |
| 564 | 584 |
| 565 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 585 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
| 566 // Ignore the given size as only the Java code has the power to | 586 // Ignore the given size as only the Java code has the power to |
| 567 // resize the view on Android. | 587 // resize the view on Android. |
| 568 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); | 588 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); |
| 569 } | 589 } |
| 570 | 590 |
| 571 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 591 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 bad_message::RWH_BAD_FRAME_SINK_REQUEST); | 1194 bad_message::RWH_BAD_FRAME_SINK_REQUEST); |
| 1175 return; | 1195 return; |
| 1176 } | 1196 } |
| 1177 delegated_frame_host_->CompositorFrameSinkChanged(); | 1197 delegated_frame_host_->CompositorFrameSinkChanged(); |
| 1178 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; | 1198 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; |
| 1179 // Accumulated resources belong to the old RendererCompositorFrameSink and | 1199 // Accumulated resources belong to the old RendererCompositorFrameSink and |
| 1180 // should not be returned. | 1200 // should not be returned. |
| 1181 surface_returned_resources_.clear(); | 1201 surface_returned_resources_.clear(); |
| 1182 } | 1202 } |
| 1183 | 1203 |
| 1204 std::unique_ptr<cc::RenderPass> | |
| 1205 RenderWidgetHostViewAndroid::CreateBlackRenderPass() { | |
| 1206 gfx::Rect rect(current_surface_size_); | |
| 1207 std::unique_ptr<cc::RenderPass> rp = cc::RenderPass::Create(); | |
| 1208 rp->SetNew(1, rect, gfx::Rect(), gfx::Transform()); | |
| 1209 rp->has_transparent_background = false; | |
| 1210 cc::SharedQuadState* sqs = rp->CreateAndAppendSharedQuadState(); | |
| 1211 sqs->SetAll(gfx::Transform(), rect, rect, rect, false, 1.0, | |
| 1212 SkBlendMode::kColor, 1); | |
| 1213 cc::SolidColorDrawQuad* quad = | |
| 1214 rp->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | |
| 1215 quad->SetNew(sqs, rect, rect, SK_ColorBLACK, false); | |
| 1216 return rp; | |
| 1217 } | |
| 1218 | |
| 1219 bool RenderWidgetHostViewAndroid::CheckForFullscreenTransitionJank( | |
| 1220 const cc::CompositorFrameMetadata& metadata) { | |
| 1221 // Sometimes we'll receive a new frame before WasResized initializes a | |
| 1222 // fullscreen transition. In that case, we'll block everything until | |
| 1223 // WasResized is called. | |
| 1224 if (content_view_core_ && | |
| 1225 content_view_core_->GetWebContents()->IsFullscreen() != was_fullscreen_) { | |
| 1226 return true; | |
| 1227 } | |
| 1228 | |
| 1229 // We only check for fullscreen jank during a fullscreen transition. | |
| 1230 if (fullscreen_transitioning_) { | |
| 1231 bool top_controls_transitioning = metadata.top_controls_shown_ratio > 0 && | |
| 1232 metadata.top_controls_shown_ratio < 1; | |
| 1233 bool bottom_controls_transitioning = | |
| 1234 metadata.bottom_controls_shown_ratio > 0 && | |
| 1235 metadata.bottom_controls_shown_ratio < 1; | |
| 1236 bool mismatched_fullscreen_states = | |
| 1237 content_view_core_ && | |
| 1238 (content_view_core_->GetWebContents()->IsFullscreen() != | |
| 1239 metadata.is_fullscreen); | |
| 1240 bool mismatched_layer_sizes = | |
| 1241 view_.GetPhysicalBackingSize() != metadata.device_viewport_size; | |
|
Khushal
2017/05/24 05:14:23
Shouldn't we be comparing this with the |current_s
steimel
2017/05/24 19:32:58
Well, view_.GetPhysicalBackingSize is the "correct
Khushal
2017/05/25 03:33:40
Yup, my bad for not stating that clearly. But you
steimel
2017/06/06 03:07:53
Done.
| |
| 1242 | |
| 1243 gfx::Size modified_scrollable_viewport_size = | |
| 1244 gfx::ToFlooredSize(gfx::ScaleSize(metadata.scrollable_viewport_size, | |
| 1245 metadata.page_scale_factor)); | |
| 1246 bool controls_will_transition = | |
|
Khushal
2017/05/24 05:14:23
Could you describe what the behaviour is for top c
steimel
2017/05/24 19:32:58
So this particular check is something that's used
| |
| 1247 content_view_core_ && (content_view_core_->GetViewSize().width() == | |
| 1248 modified_scrollable_viewport_size.width() && | |
| 1249 content_view_core_->GetViewSize().height() != | |
| 1250 modified_scrollable_viewport_size.height()); | |
| 1251 | |
| 1252 if (top_controls_transitioning || bottom_controls_transitioning || | |
| 1253 mismatched_fullscreen_states || mismatched_layer_sizes || | |
| 1254 controls_will_transition) { | |
| 1255 return true; | |
| 1256 } else { | |
| 1257 // Done with current fullscreen transition. | |
| 1258 fullscreen_transitioning_ = false; | |
| 1259 } | |
| 1260 } | |
| 1261 | |
| 1262 return false; | |
| 1263 } | |
| 1264 | |
| 1184 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 1265 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
| 1185 const cc::LocalSurfaceId& local_surface_id, | 1266 const cc::LocalSurfaceId& local_surface_id, |
| 1186 cc::CompositorFrame frame) { | 1267 cc::CompositorFrame frame) { |
| 1187 if (!delegated_frame_host_) { | 1268 if (!delegated_frame_host_) { |
| 1188 DCHECK(!using_browser_compositor_); | 1269 DCHECK(!using_browser_compositor_); |
| 1189 return; | 1270 return; |
| 1190 } | 1271 } |
| 1191 | 1272 |
| 1273 if (CheckForFullscreenTransitionJank(frame.metadata)) { | |
| 1274 // Block this frame since it will look janky. | |
| 1275 frame.render_pass_list.clear(); | |
| 1276 frame.render_pass_list.push_back(CreateBlackRenderPass()); | |
| 1277 frame.metadata.root_background_color = SK_ColorBLACK; | |
| 1278 UpdateBackgroundColor(SK_ColorBLACK); | |
| 1279 } | |
| 1280 | |
| 1192 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1281 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 1193 DCHECK(!frame.render_pass_list.empty()); | 1282 DCHECK(!frame.render_pass_list.empty()); |
| 1194 | 1283 |
| 1195 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 1284 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
| 1196 current_surface_size_ = root_pass->output_rect.size(); | 1285 current_surface_size_ = root_pass->output_rect.size(); |
| 1197 bool is_transparent = root_pass->has_transparent_background; | 1286 bool is_transparent = root_pass->has_transparent_background; |
| 1198 | 1287 |
| 1199 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 1288 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
| 1200 | 1289 |
| 1201 bool has_content = !current_surface_size_.IsEmpty(); | 1290 bool has_content = !current_surface_size_.IsEmpty(); |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2238 | 2327 |
| 2239 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2328 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
| 2240 if (!compositor) | 2329 if (!compositor) |
| 2241 return; | 2330 return; |
| 2242 | 2331 |
| 2243 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2332 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
| 2244 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2333 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
| 2245 } | 2334 } |
| 2246 | 2335 |
| 2247 } // namespace content | 2336 } // namespace content |
| OLD | NEW |