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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 #include "content/common/gpu_stream_constants.h" | 64 #include "content/common/gpu_stream_constants.h" |
65 #include "content/common/input_messages.h" | 65 #include "content/common/input_messages.h" |
66 #include "content/common/site_isolation_policy.h" | 66 #include "content/common/site_isolation_policy.h" |
67 #include "content/common/view_messages.h" | 67 #include "content/common/view_messages.h" |
68 #include "content/public/browser/android/compositor.h" | 68 #include "content/public/browser/android/compositor.h" |
69 #include "content/public/browser/android/synchronous_compositor_client.h" | 69 #include "content/public/browser/android/synchronous_compositor_client.h" |
70 #include "content/public/browser/browser_thread.h" | 70 #include "content/public/browser/browser_thread.h" |
71 #include "content/public/browser/devtools_agent_host.h" | 71 #include "content/public/browser/devtools_agent_host.h" |
72 #include "content/public/browser/render_view_host.h" | 72 #include "content/public/browser/render_view_host.h" |
73 #include "content/public/browser/render_widget_host_iterator.h" | 73 #include "content/public/browser/render_widget_host_iterator.h" |
74 #include "content/public/common/content_features.h" | |
74 #include "content/public/common/content_switches.h" | 75 #include "content/public/common/content_switches.h" |
75 #include "gpu/command_buffer/client/gles2_implementation.h" | 76 #include "gpu/command_buffer/client/gles2_implementation.h" |
76 #include "gpu/command_buffer/client/gles2_interface.h" | 77 #include "gpu/command_buffer/client/gles2_interface.h" |
77 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 78 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
78 #include "ipc/ipc_message_macros.h" | 79 #include "ipc/ipc_message_macros.h" |
79 #include "ipc/ipc_message_start.h" | 80 #include "ipc/ipc_message_start.h" |
80 #include "skia/ext/image_operations.h" | 81 #include "skia/ext/image_operations.h" |
81 #include "third_party/khronos/GLES2/gl2.h" | 82 #include "third_party/khronos/GLES2/gl2.h" |
82 #include "third_party/khronos/GLES2/gl2ext.h" | 83 #include "third_party/khronos/GLES2/gl2ext.h" |
83 #include "third_party/skia/include/core/SkCanvas.h" | 84 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 559 |
559 RenderWidgetHost* | 560 RenderWidgetHost* |
560 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 561 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
561 return host_; | 562 return host_; |
562 } | 563 } |
563 | 564 |
564 void RenderWidgetHostViewAndroid::WasResized() { | 565 void RenderWidgetHostViewAndroid::WasResized() { |
565 host_->WasResized(); | 566 host_->WasResized(); |
566 } | 567 } |
567 | 568 |
569 void RenderWidgetHostViewAndroid::OnFullscreenStateChanged( | |
570 bool entered_fullscreen) { | |
571 web_contents_is_fullscreen_ = entered_fullscreen; | |
572 UpdateFullscreenState(); | |
573 } | |
574 | |
568 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 575 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
569 // Ignore the given size as only the Java code has the power to | 576 // Ignore the given size as only the Java code has the power to |
570 // resize the view on Android. | 577 // resize the view on Android. |
571 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); | 578 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); |
572 } | 579 } |
573 | 580 |
574 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 581 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
575 default_bounds_ = rect; | 582 default_bounds_ = rect; |
576 } | 583 } |
577 | 584 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 bad_message::RWH_BAD_FRAME_SINK_REQUEST); | 1184 bad_message::RWH_BAD_FRAME_SINK_REQUEST); |
1178 return; | 1185 return; |
1179 } | 1186 } |
1180 delegated_frame_host_->CompositorFrameSinkChanged(); | 1187 delegated_frame_host_->CompositorFrameSinkChanged(); |
1181 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; | 1188 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; |
1182 // Accumulated resources belong to the old RendererCompositorFrameSink and | 1189 // Accumulated resources belong to the old RendererCompositorFrameSink and |
1183 // should not be returned. | 1190 // should not be returned. |
1184 surface_returned_resources_.clear(); | 1191 surface_returned_resources_.clear(); |
1185 } | 1192 } |
1186 | 1193 |
1194 void RenderWidgetHostViewAndroid::UpdateFullscreenState() { | |
1195 if (!base::FeatureList::IsEnabled(features::kHideFullscreenTransitionJank)) | |
1196 return; | |
1197 | |
1198 bool mismatched_fullscreen_states = | |
1199 web_contents_is_fullscreen_ != current_frame_is_fullscreen_; | |
1200 bool mismatched_sizes = | |
1201 view_.GetPhysicalBackingSize() != current_surface_size_; | |
1202 | |
1203 switch (fullscreen_state_) { | |
1204 // From kNotFullscreen, we transition to kEnteringFullscreen whenever the | |
1205 // fullscreen state changes. | |
1206 case FullscreenState::kNotFullscreen: | |
1207 if (mismatched_fullscreen_states) { | |
1208 DCHECK(web_contents_is_fullscreen_); | |
1209 fullscreen_state_ = FullscreenState::kEnteringFullscreen; | |
1210 fullscreen_transition_awaiting_resize_ = true; | |
boliu
2017/06/20 20:54:44
this seems way too brittle. how do you know enter/
aelias_OOO_until_Jul13
2017/06/20 21:15:14
Agreed, I gave a lot of feedback/suggestions about
Khushal
2017/06/20 21:26:35
You're right, this is a brittle assumption. We nee
Khushal
2017/06/20 21:44:03
How do you feel about an API via ViewAndroidDelega
boliu
2017/06/20 22:07:51
You can get the display size directly through the
Khushal
2017/06/20 23:25:05
WebView was what I was most unsure about. Is a res
boliu
2017/06/20 23:53:51
Nope. (It's more likely the app doesn't implement
Khushal
2017/06/21 00:08:25
Oh right. WebView doesn't get any frames at all he
boliu
2017/06/21 00:32:36
I'd prefer neither. But resize is probably safer o
| |
1211 } | |
1212 break; | |
1213 // From kFullscreen, we transition to kExitingFullscreen on a fullscreen | |
1214 // state change, or to kFullscreenRotation if we get a new size. | |
1215 case FullscreenState::kFullscreen: | |
1216 if (mismatched_fullscreen_states) { | |
1217 DCHECK(!web_contents_is_fullscreen_); | |
1218 fullscreen_state_ = FullscreenState::kExitingFullscreen; | |
1219 fullscreen_transition_awaiting_resize_ = true; | |
1220 } else if (mismatched_sizes) { | |
1221 fullscreen_state_ = FullscreenState::kFullscreenRotation; | |
1222 } | |
1223 break; | |
1224 // From any transition state, once we receive a "good" frame we transition | |
1225 // to the proper "good" state. | |
1226 case FullscreenState::kExitingFullscreen: | |
1227 case FullscreenState::kEnteringFullscreen: | |
1228 case FullscreenState::kFullscreenRotation: | |
1229 if (!mismatched_fullscreen_states && !mismatched_sizes && | |
boliu
2017/06/20 20:54:44
also, how do you know entering/existing fullscreen
aelias_OOO_until_Jul13
2017/06/20 21:15:14
I'm comfortable assuming that fullscreen and rotat
Khushal
2017/06/20 21:26:35
Yup, need a more explicit way to handle the resize
steimel
2017/06/20 21:28:35
A lot of good points here, though regarding the sq
boliu
2017/06/20 21:33:49
Sure square phone is not realistic. But I'm not su
Khushal
2017/06/20 21:44:03
The place where that bit is being set doesn't requ
boliu
2017/06/20 22:07:51
Err... that makes me think background color is wro
Khushal
2017/06/20 23:25:05
Hmmm, may be it should be asking for a commit...
| |
1230 !fullscreen_transition_awaiting_resize_) { | |
1231 fullscreen_state_ = web_contents_is_fullscreen_ | |
1232 ? FullscreenState::kFullscreen | |
1233 : FullscreenState::kNotFullscreen; | |
1234 } | |
1235 break; | |
1236 } | |
1237 | |
1238 if (fullscreen_state_ == FullscreenState::kEnteringFullscreen || | |
1239 fullscreen_state_ == FullscreenState::kExitingFullscreen || | |
1240 fullscreen_state_ == FullscreenState::kFullscreenRotation) { | |
1241 EvictDelegatedFrame(); | |
boliu
2017/06/20 20:54:44
need a comment why this is desirable
steimel
2017/06/22 01:32:11
Done.
| |
1242 UpdateBackgroundColor(SK_ColorBLACK); | |
1243 } | |
1244 } | |
1245 | |
1187 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 1246 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
1188 const cc::LocalSurfaceId& local_surface_id, | 1247 const cc::LocalSurfaceId& local_surface_id, |
1189 cc::CompositorFrame frame) { | 1248 cc::CompositorFrame frame) { |
1190 if (!delegated_frame_host_) { | 1249 if (!delegated_frame_host_) { |
1191 DCHECK(!using_browser_compositor_); | 1250 DCHECK(!using_browser_compositor_); |
1192 return; | 1251 return; |
1193 } | 1252 } |
1194 | 1253 |
1195 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1254 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1196 DCHECK(!frame.render_pass_list.empty()); | 1255 DCHECK(!frame.render_pass_list.empty()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1236 frame_evictor_->HasFrame()); | 1295 frame_evictor_->HasFrame()); |
1237 | 1296 |
1238 if (!delegated_frame_host_) | 1297 if (!delegated_frame_host_) |
1239 return; | 1298 return; |
1240 | 1299 |
1241 if (!delegated_frame_host_->HasDelegatedContent()) | 1300 if (!delegated_frame_host_->HasDelegatedContent()) |
1242 return; | 1301 return; |
1243 | 1302 |
1244 frame_evictor_->DiscardedFrame(); | 1303 frame_evictor_->DiscardedFrame(); |
1245 delegated_frame_host_->DestroyDelegatedContent(); | 1304 delegated_frame_host_->DestroyDelegatedContent(); |
1305 current_surface_size_.SetSize(0, 0); | |
1246 } | 1306 } |
1247 | 1307 |
1248 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame( | 1308 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame( |
1249 const cc::BeginFrameAck& ack) { | 1309 const cc::BeginFrameAck& ack) { |
1250 if (!delegated_frame_host_) { | 1310 if (!delegated_frame_host_) { |
1251 // We are not using the browser compositor and there's no DisplayScheduler | 1311 // We are not using the browser compositor and there's no DisplayScheduler |
1252 // that needs to be notified about the BeginFrameAck, so we can drop it. | 1312 // that needs to be notified about the BeginFrameAck, so we can drop it. |
1253 DCHECK(!using_browser_compositor_); | 1313 DCHECK(!using_browser_compositor_); |
1254 return; | 1314 return; |
1255 } | 1315 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 | 1508 |
1449 // Set parameters for adaptive handle orientation. | 1509 // Set parameters for adaptive handle orientation. |
1450 gfx::SizeF viewport_size(frame_metadata.scrollable_viewport_size); | 1510 gfx::SizeF viewport_size(frame_metadata.scrollable_viewport_size); |
1451 viewport_size.Scale(frame_metadata.page_scale_factor); | 1511 viewport_size.Scale(frame_metadata.page_scale_factor); |
1452 gfx::RectF viewport_rect(0.0f, frame_metadata.top_controls_height * | 1512 gfx::RectF viewport_rect(0.0f, frame_metadata.top_controls_height * |
1453 frame_metadata.top_controls_shown_ratio, | 1513 frame_metadata.top_controls_shown_ratio, |
1454 viewport_size.width(), viewport_size.height()); | 1514 viewport_size.width(), viewport_size.height()); |
1455 touch_selection_controller_->OnViewportChanged(viewport_rect); | 1515 touch_selection_controller_->OnViewportChanged(viewport_rect); |
1456 } | 1516 } |
1457 | 1517 |
1518 current_frame_is_fullscreen_ = frame_metadata.is_fullscreen; | |
1458 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT | 1519 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT |
1459 : frame_metadata.root_background_color); | 1520 : frame_metadata.root_background_color); |
1460 | 1521 |
1461 view_.set_content_offset(gfx::Vector2dF(0.0f, | 1522 view_.set_content_offset(gfx::Vector2dF(0.0f, |
1462 frame_metadata.top_controls_height * | 1523 frame_metadata.top_controls_height * |
1463 frame_metadata.top_controls_shown_ratio)); | 1524 frame_metadata.top_controls_shown_ratio)); |
1464 | 1525 |
1465 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_); | 1526 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_); |
1466 if (top_changed) { | 1527 if (top_changed) { |
1467 float translate = top_shown_pix - top_controls_pix; | 1528 float translate = top_shown_pix - top_controls_pix; |
(...skipping 13 matching lines...) Expand all Loading... | |
1481 | 1542 |
1482 // All offsets and sizes are in CSS pixels. | 1543 // All offsets and sizes are in CSS pixels. |
1483 content_view_core_->UpdateFrameInfo( | 1544 content_view_core_->UpdateFrameInfo( |
1484 frame_metadata.root_scroll_offset, frame_metadata.page_scale_factor, | 1545 frame_metadata.root_scroll_offset, frame_metadata.page_scale_factor, |
1485 gfx::Vector2dF(frame_metadata.min_page_scale_factor, | 1546 gfx::Vector2dF(frame_metadata.min_page_scale_factor, |
1486 frame_metadata.max_page_scale_factor), | 1547 frame_metadata.max_page_scale_factor), |
1487 frame_metadata.root_layer_size, frame_metadata.scrollable_viewport_size, | 1548 frame_metadata.root_layer_size, frame_metadata.scrollable_viewport_size, |
1488 frame_metadata.top_controls_height * | 1549 frame_metadata.top_controls_height * |
1489 frame_metadata.top_controls_shown_ratio, | 1550 frame_metadata.top_controls_shown_ratio, |
1490 top_shown_pix, top_changed, is_mobile_optimized); | 1551 top_shown_pix, top_changed, is_mobile_optimized); |
1552 | |
1553 UpdateFullscreenState(); | |
1491 } | 1554 } |
1492 | 1555 |
1493 void RenderWidgetHostViewAndroid::ShowInternal() { | 1556 void RenderWidgetHostViewAndroid::ShowInternal() { |
1494 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; | 1557 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; |
1495 if (!show) | 1558 if (!show) |
1496 return; | 1559 return; |
1497 | 1560 |
1498 if (!host_ || !host_->is_hidden()) | 1561 if (!host_ || !host_->is_hidden()) |
1499 return; | 1562 return; |
1500 | 1563 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1923 | 1986 |
1924 void RenderWidgetHostViewAndroid::SetTextHandlesTemporarilyHidden(bool hidden) { | 1987 void RenderWidgetHostViewAndroid::SetTextHandlesTemporarilyHidden(bool hidden) { |
1925 if (touch_selection_controller_) | 1988 if (touch_selection_controller_) |
1926 touch_selection_controller_->SetTemporarilyHidden(hidden); | 1989 touch_selection_controller_->SetTemporarilyHidden(hidden); |
1927 } | 1990 } |
1928 | 1991 |
1929 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { | 1992 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { |
1930 return cached_background_color_; | 1993 return cached_background_color_; |
1931 } | 1994 } |
1932 | 1995 |
1996 bool RenderWidgetHostViewAndroid::CanShowThumbnailPlaceholder() const { | |
1997 return !(fullscreen_state_ == FullscreenState::kEnteringFullscreen || | |
1998 fullscreen_state_ == FullscreenState::kExitingFullscreen || | |
1999 fullscreen_state_ == FullscreenState::kFullscreenRotation); | |
2000 } | |
2001 | |
1933 void RenderWidgetHostViewAndroid::SetIsInVR(bool is_in_vr) { | 2002 void RenderWidgetHostViewAndroid::SetIsInVR(bool is_in_vr) { |
1934 is_in_vr_ = is_in_vr; | 2003 is_in_vr_ = is_in_vr; |
1935 } | 2004 } |
1936 | 2005 |
1937 bool RenderWidgetHostViewAndroid::IsInVR() const { | 2006 bool RenderWidgetHostViewAndroid::IsInVR() const { |
1938 return is_in_vr_; | 2007 return is_in_vr_; |
1939 } | 2008 } |
1940 | 2009 |
1941 void RenderWidgetHostViewAndroid::DidOverscroll( | 2010 void RenderWidgetHostViewAndroid::DidOverscroll( |
1942 const ui::DidOverscrollParams& params) { | 2011 const ui::DidOverscrollParams& params) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2052 // unintended shift+click interpretation of all accessibility clicks. | 2121 // unintended shift+click interpretation of all accessibility clicks. |
2053 // See crbug.com/443247. | 2122 // See crbug.com/443247. |
2054 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap && | 2123 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap && |
2055 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) { | 2124 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) { |
2056 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers); | 2125 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers); |
2057 } | 2126 } |
2058 SendGestureEvent(web_gesture); | 2127 SendGestureEvent(web_gesture); |
2059 } | 2128 } |
2060 | 2129 |
2061 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() { | 2130 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() { |
2131 fullscreen_transition_awaiting_resize_ = false; | |
2132 UpdateFullscreenState(); | |
2062 WasResized(); | 2133 WasResized(); |
2063 } | 2134 } |
2064 | 2135 |
2065 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { | 2136 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { |
2066 SetContentViewCore(NULL); | 2137 SetContentViewCore(NULL); |
2067 overscroll_controller_.reset(); | 2138 overscroll_controller_.reset(); |
2068 } | 2139 } |
2069 | 2140 |
2070 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { | 2141 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { |
2071 TRACE_EVENT1("browser", | 2142 TRACE_EVENT1("browser", |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2280 | 2351 |
2281 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2352 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
2282 if (!compositor) | 2353 if (!compositor) |
2283 return; | 2354 return; |
2284 | 2355 |
2285 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2356 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
2286 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2357 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
2287 } | 2358 } |
2288 | 2359 |
2289 } // namespace content | 2360 } // namespace content |
OLD | NEW |