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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2810813004: Hide fullscreen rotation jank (Closed)
Patch Set: Refactor jank logic. Make RWHVA a WebContentsObserver to observe fullscreen state Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 555
556 RenderWidgetHost* 556 RenderWidgetHost*
557 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { 557 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const {
558 return host_; 558 return host_;
559 } 559 }
560 560
561 void RenderWidgetHostViewAndroid::WasResized() { 561 void RenderWidgetHostViewAndroid::WasResized() {
562 host_->WasResized(); 562 host_->WasResized();
563 } 563 }
564 564
565 void RenderWidgetHostViewAndroid::DidToggleFullscreenModeForTab(
566 bool entered_fullscreen,
567 bool will_cause_resize) {
568 if (!fullscreen_transitioning_) {
569 fullscreen_transitioning_ = true;
Khushal 2017/06/07 05:36:01 The reason why I suggested the enum was so its eas
liberato (no reviews please) 2017/06/13 22:06:42 +1. it took me several reads to notice that |fulls
steimel 2017/06/13 23:15:44 Done.
570 // TODO(steimel): Do we always want to await a resize? Danger of getting
571 // stuck with a black screen if we await one that's not going to occur.
572 // However, even when |will_cause_resize| == false, I still see a resize
573 // occurring, which means that even if there are cases in which we don't
574 // want to await a resize, we won't be able to tell from that parameter.
575 awaiting_resize_ = true;
576 }
577 HideFullscreenTransitionJank();
578 }
579
565 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 580 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
566 // Ignore the given size as only the Java code has the power to 581 // Ignore the given size as only the Java code has the power to
567 // resize the view on Android. 582 // resize the view on Android.
568 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); 583 default_bounds_ = gfx::Rect(default_bounds_.origin(), size);
569 } 584 }
570 585
571 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 586 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
572 default_bounds_ = rect; 587 default_bounds_ = rect;
573 } 588 }
574 589
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 bad_message::RWH_BAD_FRAME_SINK_REQUEST); 1189 bad_message::RWH_BAD_FRAME_SINK_REQUEST);
1175 return; 1190 return;
1176 } 1191 }
1177 delegated_frame_host_->CompositorFrameSinkChanged(); 1192 delegated_frame_host_->CompositorFrameSinkChanged();
1178 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; 1193 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink;
1179 // Accumulated resources belong to the old RendererCompositorFrameSink and 1194 // Accumulated resources belong to the old RendererCompositorFrameSink and
1180 // should not be returned. 1195 // should not be returned.
1181 surface_returned_resources_.clear(); 1196 surface_returned_resources_.clear();
1182 } 1197 }
1183 1198
1199 bool RenderWidgetHostViewAndroid::HasFullscreenTransitionJank(
1200 const cc::CompositorFrame& frame) const {
1201 // We only check for fullscreen jank during a fullscreen transition.
1202 if (fullscreen_transitioning_) {
liberato (no reviews please) 2017/06/13 22:06:42 if (!fullscreen_transitioning_) return false; o
steimel 2017/06/13 23:15:44 This has been completely refactored now :)
1203 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
1204 bool mismatched_layer_sizes = view_.GetPhysicalBackingSize() != frame_size;
1205
1206 bool mismatched_fullscreen_states =
1207 content_view_core_ &&
1208 (content_view_core_->GetWebContents()->IsFullscreen() !=
1209 frame.metadata.is_fullscreen);
1210
1211 return mismatched_fullscreen_states || mismatched_layer_sizes ||
1212 awaiting_resize_;
Khushal 2017/06/07 05:36:01 When do we hit this case? Where layer sizes and fu
steimel 2017/06/13 23:15:44 Discussed offline
1213 }
1214
1215 return false;
1216 }
1217
1218 void RenderWidgetHostViewAndroid::HideFullscreenTransitionJank() {
1219 EvictDelegatedFrame();
1220 UpdateBackgroundColor(SK_ColorBLACK);
1221 }
1222
1223 void RenderWidgetHostViewAndroid::EndFullscreenTransition() {
1224 fullscreen_transitioning_ = false;
1225 awaiting_resize_ = false;
1226 }
1227
1184 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( 1228 void RenderWidgetHostViewAndroid::SubmitCompositorFrame(
1185 const cc::LocalSurfaceId& local_surface_id, 1229 const cc::LocalSurfaceId& local_surface_id,
1186 cc::CompositorFrame frame) { 1230 cc::CompositorFrame frame) {
1187 if (!delegated_frame_host_) { 1231 if (!delegated_frame_host_) {
1188 DCHECK(!using_browser_compositor_); 1232 DCHECK(!using_browser_compositor_);
1189 return; 1233 return;
1190 } 1234 }
1191 1235
1236 bool has_jank = HasFullscreenTransitionJank(frame);
1237
1192 last_scroll_offset_ = frame.metadata.root_scroll_offset; 1238 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1193 DCHECK(!frame.render_pass_list.empty()); 1239 DCHECK(!frame.render_pass_list.empty());
1194 1240
1195 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 1241 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
1196 current_surface_size_ = root_pass->output_rect.size(); 1242 current_surface_size_ = root_pass->output_rect.size();
1197 bool is_transparent = root_pass->has_transparent_background; 1243 bool is_transparent = root_pass->has_transparent_background;
1198 1244
1199 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 1245 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1200 1246
1201 bool has_content = !current_surface_size_.IsEmpty(); 1247 bool has_content = !current_surface_size_.IsEmpty();
(...skipping 16 matching lines...) Expand all
1218 frame_evictor_->SwappedFrame(!host_->is_hidden()); 1264 frame_evictor_->SwappedFrame(!host_->is_hidden());
1219 AcknowledgeBeginFrame(ack); 1265 AcknowledgeBeginFrame(ack);
1220 } 1266 }
1221 1267
1222 if (host_->is_hidden()) 1268 if (host_->is_hidden())
1223 RunAckCallbacks(); 1269 RunAckCallbacks();
1224 1270
1225 // As the metadata update may trigger view invalidation, always call it after 1271 // As the metadata update may trigger view invalidation, always call it after
1226 // any potential compositor scheduling. 1272 // any potential compositor scheduling.
1227 OnFrameMetadataUpdated(std::move(metadata), is_transparent); 1273 OnFrameMetadataUpdated(std::move(metadata), is_transparent);
1274
1275 if (has_jank) {
1276 HideFullscreenTransitionJank();
1277 } else if (fullscreen_transitioning_) {
1278 EndFullscreenTransition();
1279 }
1228 } 1280 }
1229 1281
1230 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { 1282 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
1231 DCHECK(!delegated_frame_host_ || 1283 DCHECK(!delegated_frame_host_ ||
1232 delegated_frame_host_->HasDelegatedContent() == 1284 delegated_frame_host_->HasDelegatedContent() ==
1233 frame_evictor_->HasFrame()); 1285 frame_evictor_->HasFrame());
1234 1286
1235 if (!delegated_frame_host_) 1287 if (!delegated_frame_host_)
1236 return; 1288 return;
1237 1289
1238 if (!delegated_frame_host_->HasDelegatedContent()) 1290 if (!delegated_frame_host_->HasDelegatedContent())
1239 return; 1291 return;
1240 1292
1241 frame_evictor_->DiscardedFrame(); 1293 frame_evictor_->DiscardedFrame();
1242 delegated_frame_host_->DestroyDelegatedContent(); 1294 delegated_frame_host_->DestroyDelegatedContent();
1295 current_surface_size_.SetSize(0, 0);
1243 } 1296 }
1244 1297
1245 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame( 1298 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame(
1246 const cc::BeginFrameAck& ack) { 1299 const cc::BeginFrameAck& ack) {
1247 if (!delegated_frame_host_) { 1300 if (!delegated_frame_host_) {
1248 // We are not using the browser compositor and there's no DisplayScheduler 1301 // We are not using the browser compositor and there's no DisplayScheduler
1249 // that needs to be notified about the BeginFrameAck, so we can drop it. 1302 // that needs to be notified about the BeginFrameAck, so we can drop it.
1250 DCHECK(!using_browser_compositor_); 1303 DCHECK(!using_browser_compositor_);
1251 return; 1304 return;
1252 } 1305 }
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 || content_view_core->GetViewportSizeDip().height() != 0; 1984 || content_view_core->GetViewportSizeDip().height() != 0;
1932 if (content_view_core_ || is_size_initialized) 1985 if (content_view_core_ || is_size_initialized)
1933 resize = true; 1986 resize = true;
1934 if (content_view_core_) { 1987 if (content_view_core_) {
1935 content_view_core_->RemoveObserver(this); 1988 content_view_core_->RemoveObserver(this);
1936 view_.RemoveFromParent(); 1989 view_.RemoveFromParent();
1937 view_.GetLayer()->RemoveFromParent(); 1990 view_.GetLayer()->RemoveFromParent();
1938 } 1991 }
1939 if (content_view_core) { 1992 if (content_view_core) {
1940 content_view_core->AddObserver(this); 1993 content_view_core->AddObserver(this);
1994 content::WebContentsObserver::Observe(
1995 content_view_core->GetWebContents());
1941 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid(); 1996 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid();
1942 parent_view->AddChild(&view_); 1997 parent_view->AddChild(&view_);
1943 parent_view->GetLayer()->AddChild(view_.GetLayer()); 1998 parent_view->GetLayer()->AddChild(view_.GetLayer());
1999 } else {
2000 content::WebContentsObserver::Observe(NULL);
1944 } 2001 }
1945 content_view_core_ = content_view_core; 2002 content_view_core_ = content_view_core;
1946 } 2003 }
1947 2004
1948 BrowserAccessibilityManager* manager = NULL; 2005 BrowserAccessibilityManager* manager = NULL;
1949 if (host_) 2006 if (host_)
1950 manager = host_->GetRootBrowserAccessibilityManager(); 2007 manager = host_->GetRootBrowserAccessibilityManager();
1951 if (manager) { 2008 if (manager) {
1952 base::android::ScopedJavaLocalRef<jobject> obj; 2009 base::android::ScopedJavaLocalRef<jobject> obj;
1953 if (content_view_core_) 2010 if (content_view_core_)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 // unintended shift+click interpretation of all accessibility clicks. 2071 // unintended shift+click interpretation of all accessibility clicks.
2015 // See crbug.com/443247. 2072 // See crbug.com/443247.
2016 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap && 2073 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap &&
2017 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) { 2074 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) {
2018 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers); 2075 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers);
2019 } 2076 }
2020 SendGestureEvent(web_gesture); 2077 SendGestureEvent(web_gesture);
2021 } 2078 }
2022 2079
2023 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() { 2080 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() {
2081 // If we're entering a fullscreen transition, show black until the transition
2082 // is completed.
2083 if (content_view_core_) {
2084 bool is_fullscreen = content_view_core_->GetWebContents()->IsFullscreen();
Khushal 2017/06/07 05:36:01 Shouldn't be able to include WebContents here but
steimel 2017/06/13 23:15:44 Refactored to store what we get when WebContents t
2085 if (is_fullscreen || fullscreen_transitioning_) {
2086 fullscreen_transitioning_ = true;
2087 awaiting_resize_ = false;
2088 HideFullscreenTransitionJank();
2089 }
2090 }
2024 WasResized(); 2091 WasResized();
2025 } 2092 }
2026 2093
2027 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { 2094 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() {
2028 SetContentViewCore(NULL); 2095 SetContentViewCore(NULL);
2029 overscroll_controller_.reset(); 2096 overscroll_controller_.reset();
2030 } 2097 }
2031 2098
2032 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { 2099 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) {
2033 TRACE_EVENT1("browser", 2100 TRACE_EVENT1("browser",
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 2305
2239 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2306 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2240 if (!compositor) 2307 if (!compositor)
2241 return; 2308 return;
2242 2309
2243 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2310 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2244 overscroll_refresh_handler, compositor, view_.GetDipScale()); 2311 overscroll_refresh_handler, compositor, view_.GetDipScale());
2245 } 2312 }
2246 2313
2247 } // namespace content 2314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698