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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 558 |
559 RenderWidgetHost* | 559 RenderWidgetHost* |
560 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 560 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
561 return host_; | 561 return host_; |
562 } | 562 } |
563 | 563 |
564 void RenderWidgetHostViewAndroid::WasResized() { | 564 void RenderWidgetHostViewAndroid::WasResized() { |
565 host_->WasResized(); | 565 host_->WasResized(); |
566 } | 566 } |
567 | 567 |
568 void RenderWidgetHostViewAndroid::OnFullscreenStateChanged( | |
569 bool entered_fullscreen) { | |
570 web_contents_is_fullscreen_ = entered_fullscreen; | |
571 UpdateFullscreenState(false); | |
572 } | |
573 | |
568 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 574 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
569 // Ignore the given size as only the Java code has the power to | 575 // Ignore the given size as only the Java code has the power to |
570 // resize the view on Android. | 576 // resize the view on Android. |
571 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); | 577 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); |
572 } | 578 } |
573 | 579 |
574 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 580 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
575 default_bounds_ = rect; | 581 default_bounds_ = rect; |
576 } | 582 } |
577 | 583 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 bad_message::RWH_BAD_FRAME_SINK_REQUEST); | 1183 bad_message::RWH_BAD_FRAME_SINK_REQUEST); |
1178 return; | 1184 return; |
1179 } | 1185 } |
1180 delegated_frame_host_->CompositorFrameSinkChanged(); | 1186 delegated_frame_host_->CompositorFrameSinkChanged(); |
1181 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; | 1187 renderer_compositor_frame_sink_ = renderer_compositor_frame_sink; |
1182 // Accumulated resources belong to the old RendererCompositorFrameSink and | 1188 // Accumulated resources belong to the old RendererCompositorFrameSink and |
1183 // should not be returned. | 1189 // should not be returned. |
1184 surface_returned_resources_.clear(); | 1190 surface_returned_resources_.clear(); |
1185 } | 1191 } |
1186 | 1192 |
1193 void RenderWidgetHostViewAndroid::UpdateFullscreenState( | |
1194 bool physical_backing_resized) { | |
1195 bool mismatched_fullscreen_states = | |
1196 web_contents_is_fullscreen_ != current_frame_is_fullscreen_; | |
1197 bool mismatched_sizes = | |
1198 view_.GetPhysicalBackingSize() != current_surface_size_; | |
1199 | |
1200 if (physical_backing_resized) | |
1201 fullscreen_transition_awaiting_resize_ = false; | |
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 DCHECK(!physical_backing_resized); | |
1210 fullscreen_state_ = FullscreenState::kEnteringFullscreen; | |
1211 fullscreen_transition_awaiting_resize_ = true; | |
1212 } | |
1213 break; | |
1214 // From kFullscreen, we transition to kExitingFullscreen on a fullscreen | |
1215 // state change, or to kFullscreenRotation if we get a new size. | |
1216 case FullscreenState::kFullscreen: | |
1217 if (mismatched_fullscreen_states) { | |
1218 DCHECK(!web_contents_is_fullscreen_); | |
1219 DCHECK(!physical_backing_resized); | |
1220 fullscreen_state_ = FullscreenState::kExitingFullscreen; | |
1221 fullscreen_transition_awaiting_resize_ = true; | |
1222 } | |
1223 if (mismatched_sizes) | |
1224 fullscreen_state_ = FullscreenState::kFullscreenRotation; | |
1225 break; | |
1226 // From any transition state, once we receive a "good" frame we transition | |
1227 // to the proper "good" state. | |
1228 case FullscreenState::kExitingFullscreen: | |
Khushal
2017/06/15 18:42:55
nit: Would it be better if we handled the 3 transi
steimel
2017/06/15 21:46:38
Discussed offline. Holding off on updating the tra
| |
1229 case FullscreenState::kEnteringFullscreen: | |
1230 case FullscreenState::kFullscreenRotation: | |
1231 if (!mismatched_fullscreen_states && !mismatched_sizes && | |
1232 !fullscreen_transition_awaiting_resize_) { | |
1233 fullscreen_state_ = web_contents_is_fullscreen_ | |
1234 ? FullscreenState::kFullscreen | |
1235 : FullscreenState::kNotFullscreen; | |
1236 } | |
1237 break; | |
1238 } | |
1239 | |
1240 if (fullscreen_state_ == FullscreenState::kEnteringFullscreen || | |
1241 fullscreen_state_ == FullscreenState::kExitingFullscreen || | |
1242 fullscreen_state_ == FullscreenState::kFullscreenRotation) { | |
1243 EvictDelegatedFrame(); | |
1244 UpdateBackgroundColor(SK_ColorBLACK); | |
1245 } | |
1246 } | |
1247 | |
1187 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 1248 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
1188 const cc::LocalSurfaceId& local_surface_id, | 1249 const cc::LocalSurfaceId& local_surface_id, |
1189 cc::CompositorFrame frame) { | 1250 cc::CompositorFrame frame) { |
1190 if (!delegated_frame_host_) { | 1251 if (!delegated_frame_host_) { |
1191 DCHECK(!using_browser_compositor_); | 1252 DCHECK(!using_browser_compositor_); |
1192 return; | 1253 return; |
1193 } | 1254 } |
1194 | 1255 |
1195 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1256 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1196 DCHECK(!frame.render_pass_list.empty()); | 1257 DCHECK(!frame.render_pass_list.empty()); |
1197 | 1258 |
1198 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 1259 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
1199 current_surface_size_ = root_pass->output_rect.size(); | 1260 current_surface_size_ = root_pass->output_rect.size(); |
1261 current_frame_is_fullscreen_ = frame.metadata.is_fullscreen; | |
1200 bool is_transparent = root_pass->has_transparent_background; | 1262 bool is_transparent = root_pass->has_transparent_background; |
1201 | 1263 |
1202 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 1264 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
1203 | 1265 |
1204 bool has_content = !current_surface_size_.IsEmpty(); | 1266 bool has_content = !current_surface_size_.IsEmpty(); |
1205 | 1267 |
1206 base::Closure ack_callback = | 1268 base::Closure ack_callback = |
1207 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 1269 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
1208 weak_ptr_factory_.GetWeakPtr(), true /* is_swap_ack */); | 1270 weak_ptr_factory_.GetWeakPtr(), true /* is_swap_ack */); |
1209 | 1271 |
(...skipping 11 matching lines...) Expand all Loading... | |
1221 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1283 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
1222 AcknowledgeBeginFrame(ack); | 1284 AcknowledgeBeginFrame(ack); |
1223 } | 1285 } |
1224 | 1286 |
1225 if (host_->is_hidden()) | 1287 if (host_->is_hidden()) |
1226 RunAckCallbacks(); | 1288 RunAckCallbacks(); |
1227 | 1289 |
1228 // As the metadata update may trigger view invalidation, always call it after | 1290 // As the metadata update may trigger view invalidation, always call it after |
1229 // any potential compositor scheduling. | 1291 // any potential compositor scheduling. |
1230 OnFrameMetadataUpdated(std::move(metadata), is_transparent); | 1292 OnFrameMetadataUpdated(std::move(metadata), is_transparent); |
1293 | |
1294 UpdateFullscreenState(false); | |
1231 } | 1295 } |
1232 | 1296 |
1233 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | 1297 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { |
1234 DCHECK(!delegated_frame_host_ || | 1298 DCHECK(!delegated_frame_host_ || |
1235 delegated_frame_host_->HasDelegatedContent() == | 1299 delegated_frame_host_->HasDelegatedContent() == |
1236 frame_evictor_->HasFrame()); | 1300 frame_evictor_->HasFrame()); |
1237 | 1301 |
1238 if (!delegated_frame_host_) | 1302 if (!delegated_frame_host_) |
1239 return; | 1303 return; |
1240 | 1304 |
1241 if (!delegated_frame_host_->HasDelegatedContent()) | 1305 if (!delegated_frame_host_->HasDelegatedContent()) |
1242 return; | 1306 return; |
1243 | 1307 |
1244 frame_evictor_->DiscardedFrame(); | 1308 frame_evictor_->DiscardedFrame(); |
1245 delegated_frame_host_->DestroyDelegatedContent(); | 1309 delegated_frame_host_->DestroyDelegatedContent(); |
1310 current_surface_size_.SetSize(0, 0); | |
1246 } | 1311 } |
1247 | 1312 |
1248 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame( | 1313 void RenderWidgetHostViewAndroid::OnDidNotProduceFrame( |
1249 const cc::BeginFrameAck& ack) { | 1314 const cc::BeginFrameAck& ack) { |
1250 if (!delegated_frame_host_) { | 1315 if (!delegated_frame_host_) { |
1251 // We are not using the browser compositor and there's no DisplayScheduler | 1316 // 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. | 1317 // that needs to be notified about the BeginFrameAck, so we can drop it. |
1253 DCHECK(!using_browser_compositor_); | 1318 DCHECK(!using_browser_compositor_); |
1254 return; | 1319 return; |
1255 } | 1320 } |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1923 | 1988 |
1924 void RenderWidgetHostViewAndroid::SetTextHandlesTemporarilyHidden(bool hidden) { | 1989 void RenderWidgetHostViewAndroid::SetTextHandlesTemporarilyHidden(bool hidden) { |
1925 if (touch_selection_controller_) | 1990 if (touch_selection_controller_) |
1926 touch_selection_controller_->SetTemporarilyHidden(hidden); | 1991 touch_selection_controller_->SetTemporarilyHidden(hidden); |
1927 } | 1992 } |
1928 | 1993 |
1929 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { | 1994 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { |
1930 return cached_background_color_; | 1995 return cached_background_color_; |
1931 } | 1996 } |
1932 | 1997 |
1998 bool RenderWidgetHostViewAndroid::CanShowThumbnailPlaceholder() const { | |
1999 return !(fullscreen_state_ == FullscreenState::kEnteringFullscreen || | |
2000 fullscreen_state_ == FullscreenState::kExitingFullscreen || | |
2001 fullscreen_state_ == FullscreenState::kFullscreenRotation); | |
2002 } | |
2003 | |
1933 void RenderWidgetHostViewAndroid::SetIsInVR(bool is_in_vr) { | 2004 void RenderWidgetHostViewAndroid::SetIsInVR(bool is_in_vr) { |
1934 is_in_vr_ = is_in_vr; | 2005 is_in_vr_ = is_in_vr; |
1935 } | 2006 } |
1936 | 2007 |
1937 bool RenderWidgetHostViewAndroid::IsInVR() const { | 2008 bool RenderWidgetHostViewAndroid::IsInVR() const { |
1938 return is_in_vr_; | 2009 return is_in_vr_; |
1939 } | 2010 } |
1940 | 2011 |
1941 void RenderWidgetHostViewAndroid::DidOverscroll( | 2012 void RenderWidgetHostViewAndroid::DidOverscroll( |
1942 const ui::DidOverscrollParams& params) { | 2013 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. | 2123 // unintended shift+click interpretation of all accessibility clicks. |
2053 // See crbug.com/443247. | 2124 // See crbug.com/443247. |
2054 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap && | 2125 if (web_gesture.GetType() == blink::WebInputEvent::kGestureTap && |
2055 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) { | 2126 web_gesture.GetModifiers() == blink::WebInputEvent::kShiftKey) { |
2056 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers); | 2127 web_gesture.SetModifiers(blink::WebInputEvent::kNoModifiers); |
2057 } | 2128 } |
2058 SendGestureEvent(web_gesture); | 2129 SendGestureEvent(web_gesture); |
2059 } | 2130 } |
2060 | 2131 |
2061 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() { | 2132 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() { |
2133 // If we're entering a fullscreen transition, show black until the transition | |
2134 // is completed. | |
2135 UpdateFullscreenState(true); | |
2062 WasResized(); | 2136 WasResized(); |
2063 } | 2137 } |
2064 | 2138 |
2065 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { | 2139 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { |
2066 SetContentViewCore(NULL); | 2140 SetContentViewCore(NULL); |
2067 overscroll_controller_.reset(); | 2141 overscroll_controller_.reset(); |
2068 } | 2142 } |
2069 | 2143 |
2070 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { | 2144 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { |
2071 TRACE_EVENT1("browser", | 2145 TRACE_EVENT1("browser", |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2280 | 2354 |
2281 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2355 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
2282 if (!compositor) | 2356 if (!compositor) |
2283 return; | 2357 return; |
2284 | 2358 |
2285 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2359 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
2286 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2360 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
2287 } | 2361 } |
2288 | 2362 |
2289 } // namespace content | 2363 } // namespace content |
OLD | NEW |