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/display_compositor/gl_helper.h" | 38 #include "components/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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 RenderWidgetHostView* reference_host_view) { | 547 RenderWidgetHostView* reference_host_view) { |
547 NOTIMPLEMENTED(); | 548 NOTIMPLEMENTED(); |
548 } | 549 } |
549 | 550 |
550 RenderWidgetHost* | 551 RenderWidgetHost* |
551 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 552 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
552 return host_; | 553 return host_; |
553 } | 554 } |
554 | 555 |
555 void RenderWidgetHostViewAndroid::WasResized() { | 556 void RenderWidgetHostViewAndroid::WasResized() { |
| 557 // If we're entering a fullscreen transition, show black until the transition |
| 558 // is completed. |
| 559 if (content_view_core_ && content_view_core_->GetPhysicalBackingSize() != |
| 560 prev_physical_backing_size_) { |
| 561 bool is_fullscreen = content_view_core_->GetWebContents()->IsFullscreen(); |
| 562 if (is_fullscreen || was_fullscreen_) { |
| 563 fullscreen_transitioning_ = true; |
| 564 |
| 565 // Immediately queue a black frame to hide jank while we wait to receive a |
| 566 // "good" frame via SubmitCompositorFrame. |
| 567 cc::CompositorFrame frame; |
| 568 frame.render_pass_list.push_back(CreateBlackRenderPass()); |
| 569 frame.metadata.root_background_color = SK_ColorBLACK; |
| 570 delegated_frame_host_->ForceFrame(std::move(frame)); |
| 571 UpdateBackgroundColor(SK_ColorBLACK); |
| 572 } |
| 573 was_fullscreen_ = is_fullscreen; |
| 574 prev_physical_backing_size_ = content_view_core_->GetPhysicalBackingSize(); |
| 575 } |
556 host_->WasResized(); | 576 host_->WasResized(); |
557 } | 577 } |
558 | 578 |
559 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 579 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
560 // Ignore the given size as only the Java code has the power to | 580 // Ignore the given size as only the Java code has the power to |
561 // resize the view on Android. | 581 // resize the view on Android. |
562 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); | 582 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); |
563 } | 583 } |
564 | 584 |
565 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 585 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 | 1164 |
1145 void RenderWidgetHostViewAndroid::DidCreateNewRendererCompositorFrameSink( | 1165 void RenderWidgetHostViewAndroid::DidCreateNewRendererCompositorFrameSink( |
1146 cc::mojom::MojoCompositorFrameSinkClient* renderer_compositor_frame_sink) { | 1166 cc::mojom::MojoCompositorFrameSinkClient* renderer_compositor_frame_sink) { |
1147 delegated_frame_host_->CompositorFrameSinkChanged(); | 1167 delegated_frame_host_->CompositorFrameSinkChanged(); |
1148 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; | 1168 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; |
1149 // Accumulated resources belong to the old RendererCompositorFrameSink and | 1169 // Accumulated resources belong to the old RendererCompositorFrameSink and |
1150 // should not be returned. | 1170 // should not be returned. |
1151 surface_returned_resources_.clear(); | 1171 surface_returned_resources_.clear(); |
1152 } | 1172 } |
1153 | 1173 |
| 1174 std::unique_ptr<cc::RenderPass> |
| 1175 RenderWidgetHostViewAndroid::CreateBlackRenderPass() { |
| 1176 gfx::Rect rect(current_surface_size_); |
| 1177 std::unique_ptr<cc::RenderPass> rp = cc::RenderPass::Create(); |
| 1178 rp->SetNew(1, rect, gfx::Rect(), gfx::Transform()); |
| 1179 rp->has_transparent_background = false; |
| 1180 cc::SharedQuadState* sqs = rp->CreateAndAppendSharedQuadState(); |
| 1181 sqs->SetAll(gfx::Transform(), rect, rect, rect, false, 1.0, |
| 1182 SkBlendMode::kColor, 1); |
| 1183 cc::SolidColorDrawQuad* quad = |
| 1184 rp->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 1185 quad->SetNew(sqs, rect, rect, SK_ColorBLACK, false); |
| 1186 return rp; |
| 1187 } |
| 1188 |
| 1189 bool RenderWidgetHostViewAndroid::CheckForFullscreenTransitionJank( |
| 1190 const cc::CompositorFrameMetadata& metadata) { |
| 1191 // Sometimes we'll receive a new frame before WasResized initializes a |
| 1192 // fullscreen transition. In that case, we'll block everything until |
| 1193 // WasResized is called. |
| 1194 if (content_view_core_ && |
| 1195 content_view_core_->GetWebContents()->IsFullscreen() != was_fullscreen_) { |
| 1196 return true; |
| 1197 } |
| 1198 |
| 1199 // We only check for fullscreen jank during a fullscreen transition. |
| 1200 if (fullscreen_transitioning_) { |
| 1201 bool top_controls_transitioning = metadata.top_controls_shown_ratio > 0 && |
| 1202 metadata.top_controls_shown_ratio < 1; |
| 1203 bool bottom_controls_transitioning = |
| 1204 metadata.bottom_controls_shown_ratio > 0 && |
| 1205 metadata.bottom_controls_shown_ratio < 1; |
| 1206 bool mismatched_fullscreen_states = |
| 1207 content_view_core_ && |
| 1208 (content_view_core_->GetWebContents()->IsFullscreen() != |
| 1209 metadata.is_fullscreen); |
| 1210 bool mismatched_layer_sizes = |
| 1211 content_view_core_ && (content_view_core_->GetPhysicalBackingSize() != |
| 1212 metadata.device_viewport_size); |
| 1213 |
| 1214 gfx::Size modified_scrollable_viewport_size = |
| 1215 gfx::ToFlooredSize(gfx::ScaleSize(metadata.scrollable_viewport_size, |
| 1216 metadata.page_scale_factor)); |
| 1217 bool controls_will_transition = |
| 1218 content_view_core_ && (content_view_core_->GetViewSize().width() == |
| 1219 modified_scrollable_viewport_size.width() && |
| 1220 content_view_core_->GetViewSize().height() != |
| 1221 modified_scrollable_viewport_size.height()); |
| 1222 |
| 1223 if (top_controls_transitioning || bottom_controls_transitioning || |
| 1224 mismatched_fullscreen_states || mismatched_layer_sizes || |
| 1225 controls_will_transition) { |
| 1226 return true; |
| 1227 } else { |
| 1228 // Done with current fullscreen transition. |
| 1229 fullscreen_transitioning_ = false; |
| 1230 } |
| 1231 } |
| 1232 |
| 1233 return false; |
| 1234 } |
| 1235 |
1154 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 1236 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
1155 const cc::LocalSurfaceId& local_surface_id, | 1237 const cc::LocalSurfaceId& local_surface_id, |
1156 cc::CompositorFrame frame) { | 1238 cc::CompositorFrame frame) { |
| 1239 if (CheckForFullscreenTransitionJank(frame.metadata)) { |
| 1240 // Block this frame since it will look janky. |
| 1241 frame.render_pass_list.clear(); |
| 1242 frame.render_pass_list.push_back(CreateBlackRenderPass()); |
| 1243 frame.metadata.root_background_color = SK_ColorBLACK; |
| 1244 UpdateBackgroundColor(SK_ColorBLACK); |
| 1245 } |
| 1246 |
1157 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1247 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1158 DCHECK(delegated_frame_host_); | 1248 DCHECK(delegated_frame_host_); |
1159 DCHECK(!frame.render_pass_list.empty()); | 1249 DCHECK(!frame.render_pass_list.empty()); |
1160 | 1250 |
1161 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 1251 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
1162 current_surface_size_ = root_pass->output_rect.size(); | 1252 current_surface_size_ = root_pass->output_rect.size(); |
1163 bool is_transparent = root_pass->has_transparent_background; | 1253 bool is_transparent = root_pass->has_transparent_background; |
1164 | 1254 |
1165 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 1255 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
1166 | 1256 |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 | 2281 |
2192 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2282 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
2193 if (!compositor) | 2283 if (!compositor) |
2194 return; | 2284 return; |
2195 | 2285 |
2196 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2286 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
2197 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2287 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
2198 } | 2288 } |
2199 | 2289 |
2200 } // namespace content | 2290 } // namespace content |
OLD | NEW |