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 "base/android/sys_utils.h" | 9 #include "base/android/sys_utils.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 scoped_ptr<cc::CompositorFrame> output_frame) | 138 scoped_ptr<cc::CompositorFrame> output_frame) |
139 : output_surface_id(output_id), frame(output_frame.Pass()) {} | 139 : output_surface_id(output_id), frame(output_frame.Pass()) {} |
140 | 140 |
141 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 141 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
142 | 142 |
143 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 143 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
144 RenderWidgetHostImpl* widget_host, | 144 RenderWidgetHostImpl* widget_host, |
145 ContentViewCoreImpl* content_view_core) | 145 ContentViewCoreImpl* content_view_core) |
146 : host_(widget_host), | 146 : host_(widget_host), |
147 needs_begin_frame_(false), | 147 needs_begin_frame_(false), |
148 requested_vsync_for_touch_event_(false), | |
148 is_showing_(!widget_host->is_hidden()), | 149 is_showing_(!widget_host->is_hidden()), |
149 content_view_core_(NULL), | 150 content_view_core_(NULL), |
150 ime_adapter_android_(this), | 151 ime_adapter_android_(this), |
151 cached_background_color_(SK_ColorWHITE), | 152 cached_background_color_(SK_ColorWHITE), |
152 last_output_surface_id_(kUndefinedOutputSurfaceId), | 153 last_output_surface_id_(kUndefinedOutputSurfaceId), |
153 weak_ptr_factory_(this), | 154 weak_ptr_factory_(this), |
154 overscroll_effect_enabled_(!CommandLine::ForCurrentProcess()->HasSwitch( | 155 overscroll_effect_enabled_(!CommandLine::ForCurrentProcess()->HasSwitch( |
155 switches::kDisableOverscrollEdgeEffect)), | 156 switches::kDisableOverscrollEdgeEffect)), |
156 overscroll_effect_(OverscrollGlow::Create(overscroll_effect_enabled_)), | 157 overscroll_effect_(OverscrollGlow::Create(overscroll_effect_enabled_)), |
157 flush_input_requested_(false), | 158 flush_input_requested_(false), |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor( | 479 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor( |
479 SkColor color) { | 480 SkColor color) { |
480 if (cached_background_color_ == color) | 481 if (cached_background_color_ == color) |
481 return; | 482 return; |
482 | 483 |
483 cached_background_color_ = color; | 484 cached_background_color_ = color; |
484 if (content_view_core_) | 485 if (content_view_core_) |
485 content_view_core_->OnBackgroundColorChanged(color); | 486 content_view_core_->OnBackgroundColorChanged(color); |
486 } | 487 } |
487 | 488 |
488 void RenderWidgetHostViewAndroid::SendBeginFrame( | |
489 const cc::BeginFrameArgs& args) { | |
490 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); | |
491 if (!host_) | |
492 return; | |
493 | |
494 if (flush_input_requested_) { | |
495 flush_input_requested_ = false; | |
496 host_->FlushInput(); | |
497 content_view_core_->RemoveBeginFrameSubscriber(); | |
498 } | |
499 | |
500 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); | |
501 } | |
502 | |
503 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame( | 489 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame( |
504 bool enabled) { | 490 bool enabled) { |
505 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame", | 491 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame", |
506 "enabled", enabled); | 492 "enabled", enabled); |
no sievers
2014/04/15 21:19:26
Hmm, can this have an early out if enabled == need
jdduke (slow)
2014/04/15 22:08:43
Yeah, I think an early out should work as long as
no sievers
2014/04/25 22:23:33
Done.
| |
507 // ContentViewCoreImpl handles multiple subscribers to the BeginFrame, so | 493 if (content_view_core_ && enabled) |
508 // we have to make sure calls to ContentViewCoreImpl's | 494 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
509 // {Add,Remove}BeginFrameSubscriber are balanced, even if | 495 |
510 // RenderWidgetHostViewAndroid's may not be. | 496 needs_begin_frame_ = enabled; |
511 if (content_view_core_ && needs_begin_frame_ != enabled) { | |
512 if (enabled) | |
513 content_view_core_->AddBeginFrameSubscriber(); | |
514 else | |
515 content_view_core_->RemoveBeginFrameSubscriber(); | |
516 needs_begin_frame_ = enabled; | |
517 } | |
518 } | 497 } |
519 | 498 |
520 void RenderWidgetHostViewAndroid::OnStartContentIntent( | 499 void RenderWidgetHostViewAndroid::OnStartContentIntent( |
521 const GURL& content_url) { | 500 const GURL& content_url) { |
522 if (content_view_core_) | 501 if (content_view_core_) |
523 content_view_core_->StartContentIntent(content_url); | 502 content_view_core_->StartContentIntent(content_url); |
524 } | 503 } |
525 | 504 |
526 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( | 505 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( |
527 const base::string16& result) { | 506 const base::string16& result) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 void RenderWidgetHostViewAndroid::RemoveLayers() { | 956 void RenderWidgetHostViewAndroid::RemoveLayers() { |
978 if (!content_view_core_) | 957 if (!content_view_core_) |
979 return; | 958 return; |
980 if (!layer_.get()) | 959 if (!layer_.get()) |
981 return; | 960 return; |
982 | 961 |
983 content_view_core_->RemoveLayer(layer_); | 962 content_view_core_->RemoveLayer(layer_); |
984 overscroll_effect_->Disable(); | 963 overscroll_effect_->Disable(); |
985 } | 964 } |
986 | 965 |
966 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | |
967 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
968 } | |
969 | |
987 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 970 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
988 return overscroll_effect_->Animate(frame_time); | 971 return overscroll_effect_->Animate(frame_time); |
989 } | 972 } |
990 | 973 |
991 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 974 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
992 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 975 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
993 int gpu_host_id) { | 976 int gpu_host_id) { |
994 NOTREACHED(); | 977 NOTREACHED(); |
995 } | 978 } |
996 | 979 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 if (compositor) | 1066 if (compositor) |
1084 return compositor->HandleInputEvent(input_event); | 1067 return compositor->HandleInputEvent(input_event); |
1085 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1068 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1086 } | 1069 } |
1087 | 1070 |
1088 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { | 1071 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { |
1089 if (flush_input_requested_ || !content_view_core_) | 1072 if (flush_input_requested_ || !content_view_core_) |
1090 return; | 1073 return; |
1091 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); | 1074 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); |
1092 flush_input_requested_ = true; | 1075 flush_input_requested_ = true; |
1093 content_view_core_->AddBeginFrameSubscriber(); | |
1094 } | 1076 } |
1095 | 1077 |
1096 void RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManagerIfNeeded() { | 1078 void RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManagerIfNeeded() { |
1097 if (!host_ || host_->accessibility_mode() != AccessibilityModeComplete) | 1079 if (!host_ || host_->accessibility_mode() != AccessibilityModeComplete) |
1098 return; | 1080 return; |
1099 | 1081 |
1100 if (!GetBrowserAccessibilityManager()) { | 1082 if (!GetBrowserAccessibilityManager()) { |
1101 base::android::ScopedJavaLocalRef<jobject> obj; | 1083 base::android::ScopedJavaLocalRef<jobject> obj; |
1102 if (content_view_core_) | 1084 if (content_view_core_) |
1103 obj = content_view_core_->GetJavaObject(); | 1085 obj = content_view_core_->GetJavaObject(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 void RenderWidgetHostViewAndroid::SendKeyEvent( | 1156 void RenderWidgetHostViewAndroid::SendKeyEvent( |
1175 const NativeWebKeyboardEvent& event) { | 1157 const NativeWebKeyboardEvent& event) { |
1176 if (host_) | 1158 if (host_) |
1177 host_->ForwardKeyboardEvent(event); | 1159 host_->ForwardKeyboardEvent(event); |
1178 } | 1160 } |
1179 | 1161 |
1180 void RenderWidgetHostViewAndroid::SendTouchEvent( | 1162 void RenderWidgetHostViewAndroid::SendTouchEvent( |
1181 const blink::WebTouchEvent& event) { | 1163 const blink::WebTouchEvent& event) { |
1182 if (host_) | 1164 if (host_) |
1183 host_->ForwardTouchEventWithLatencyInfo(event, CreateLatencyInfo(event)); | 1165 host_->ForwardTouchEventWithLatencyInfo(event, CreateLatencyInfo(event)); |
1166 | |
1167 // Send a proactive BeginFrame on the next vsync to reduce latency. | |
1168 // This is good enough as long as the first touch event has Begin semantics | |
1169 // and the actual scroll happens on the next vsync. | |
1170 if (content_view_core_) { | |
1171 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
1172 requested_vsync_for_touch_event_ = true; | |
1173 } | |
1184 } | 1174 } |
1185 | 1175 |
1186 void RenderWidgetHostViewAndroid::SendMouseEvent( | 1176 void RenderWidgetHostViewAndroid::SendMouseEvent( |
1187 const blink::WebMouseEvent& event) { | 1177 const blink::WebMouseEvent& event) { |
1188 if (host_) | 1178 if (host_) |
1189 host_->ForwardMouseEvent(event); | 1179 host_->ForwardMouseEvent(event); |
1190 } | 1180 } |
1191 | 1181 |
1192 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( | 1182 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( |
1193 const blink::WebMouseWheelEvent& event) { | 1183 const blink::WebMouseWheelEvent& event) { |
(...skipping 25 matching lines...) Expand all Loading... | |
1219 gfx::Vector2dF current_fling_velocity) { | 1209 gfx::Vector2dF current_fling_velocity) { |
1220 if (!content_view_core_ || !layer_ || !is_showing_) | 1210 if (!content_view_core_ || !layer_ || !is_showing_) |
1221 return; | 1211 return; |
1222 | 1212 |
1223 const float device_scale_factor = content_view_core_->GetDpiScale(); | 1213 const float device_scale_factor = content_view_core_->GetDpiScale(); |
1224 if (overscroll_effect_->OnOverscrolled( | 1214 if (overscroll_effect_->OnOverscrolled( |
1225 content_view_core_->GetLayer(), | 1215 content_view_core_->GetLayer(), |
1226 base::TimeTicks::Now(), | 1216 base::TimeTicks::Now(), |
1227 gfx::ScaleVector2d(accumulated_overscroll, device_scale_factor), | 1217 gfx::ScaleVector2d(accumulated_overscroll, device_scale_factor), |
1228 gfx::ScaleVector2d(current_fling_velocity, device_scale_factor))) { | 1218 gfx::ScaleVector2d(current_fling_velocity, device_scale_factor))) { |
1229 content_view_core_->SetNeedsAnimate(); | 1219 SetNeedsAnimate(); |
1230 } | 1220 } |
1231 } | 1221 } |
1232 | 1222 |
1233 void RenderWidgetHostViewAndroid::DidStopFlinging() { | 1223 void RenderWidgetHostViewAndroid::DidStopFlinging() { |
1234 if (content_view_core_) | 1224 if (content_view_core_) |
1235 content_view_core_->DidStopFlinging(); | 1225 content_view_core_->DidStopFlinging(); |
1236 } | 1226 } |
1237 | 1227 |
1238 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1228 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1239 ContentViewCoreImpl* content_view_core) { | 1229 ContentViewCoreImpl* content_view_core) { |
(...skipping 17 matching lines...) Expand all Loading... | |
1257 if (content_view_core_) | 1247 if (content_view_core_) |
1258 obj = content_view_core_->GetJavaObject(); | 1248 obj = content_view_core_->GetJavaObject(); |
1259 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> | 1249 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> |
1260 SetContentViewCore(obj); | 1250 SetContentViewCore(obj); |
1261 } | 1251 } |
1262 | 1252 |
1263 AttachLayers(); | 1253 AttachLayers(); |
1264 if (content_view_core_ && !root_window_destroyed_ && | 1254 if (content_view_core_ && !root_window_destroyed_ && |
1265 !using_synchronous_compositor_) { | 1255 !using_synchronous_compositor_) { |
1266 content_view_core_->GetWindowAndroid()->AddObserver(this); | 1256 content_view_core_->GetWindowAndroid()->AddObserver(this); |
1257 if (needs_begin_frame_) | |
1258 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
jdduke (slow)
2014/04/15 22:08:43
Probably worth making |content_view_core_->GetWind
| |
1267 } | 1259 } |
1268 } | 1260 } |
1269 | 1261 |
1270 void RenderWidgetHostViewAndroid::RunAckCallbacks() { | 1262 void RenderWidgetHostViewAndroid::RunAckCallbacks() { |
1271 while (!ack_callbacks_.empty()) { | 1263 while (!ack_callbacks_.empty()) { |
1272 ack_callbacks_.front().Run(); | 1264 ack_callbacks_.front().Run(); |
1273 ack_callbacks_.pop(); | 1265 ack_callbacks_.pop(); |
1274 } | 1266 } |
1275 } | 1267 } |
1276 | 1268 |
1277 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1269 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
1278 RunAckCallbacks(); | 1270 RunAckCallbacks(); |
1279 } | 1271 } |
1280 | 1272 |
1281 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1273 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
1282 DCHECK(content_view_core_); | 1274 DCHECK(content_view_core_); |
1283 DCHECK(!using_synchronous_compositor_); | 1275 DCHECK(!using_synchronous_compositor_); |
1284 RunAckCallbacks(); | 1276 RunAckCallbacks(); |
1285 } | 1277 } |
1286 | 1278 |
1287 void RenderWidgetHostViewAndroid::OnWillDestroyWindow() { | 1279 void RenderWidgetHostViewAndroid::OnWillDestroyWindow() { |
1288 root_window_destroyed_ = true; | 1280 root_window_destroyed_ = true; |
1289 } | 1281 } |
1290 | 1282 |
1283 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | |
1284 base::TimeDelta vsync_period) { | |
1285 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); | |
1286 if (!host_) | |
1287 return; | |
1288 | |
1289 if (flush_input_requested_) { | |
1290 flush_input_requested_ = false; | |
1291 host_->FlushInput(); | |
1292 } | |
1293 | |
1294 if (needs_begin_frame_ || requested_vsync_for_touch_event_) { | |
1295 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); | |
1296 base::TimeTicks display_time = frame_time + vsync_period; | |
1297 | |
1298 // TODO(brianderson): Use adaptive draw-time estimation. | |
1299 base::TimeDelta estimated_browser_composite_time = | |
1300 base::TimeDelta::FromMilliseconds(1000.0 / (3 * 60)); | |
1301 | |
1302 base::TimeTicks deadline = display_time - estimated_browser_composite_time; | |
1303 | |
1304 host_->Send(new ViewMsg_BeginFrame( | |
1305 host_->GetRoutingID(), | |
1306 cc::BeginFrameArgs::Create(frame_time, deadline, vsync_period))); | |
1307 requested_vsync_for_touch_event_ = false; | |
jdduke (slow)
2014/04/15 22:08:43
Nit: Maybe move |requested_vsync_for_touch_event_
no sievers
2014/04/25 22:23:33
Hm, I left it as is because it otherwise hides the
| |
1308 } | |
1309 | |
1310 // TODO(sievers): This should use the LayerTreeHostClient callback | |
1311 bool needs_animate = Animate(frame_time); | |
1312 if (needs_begin_frame_ || needs_animate) | |
1313 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
1314 } | |
1315 | |
1291 void RenderWidgetHostViewAndroid::OnLostResources() { | 1316 void RenderWidgetHostViewAndroid::OnLostResources() { |
1292 ReleaseLocksOnSurface(); | 1317 ReleaseLocksOnSurface(); |
1293 if (layer_.get()) | 1318 if (layer_.get()) |
1294 DestroyDelegatedContent(); | 1319 DestroyDelegatedContent(); |
1295 DCHECK(ack_callbacks_.empty()); | 1320 DCHECK(ack_callbacks_.empty()); |
1296 } | 1321 } |
1297 | 1322 |
1298 // static | 1323 // static |
1299 void | 1324 void |
1300 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( | 1325 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 // RenderWidgetHostView, public: | 1431 // RenderWidgetHostView, public: |
1407 | 1432 |
1408 // static | 1433 // static |
1409 RenderWidgetHostView* | 1434 RenderWidgetHostView* |
1410 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1435 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1411 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1436 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1412 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1437 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1413 } | 1438 } |
1414 | 1439 |
1415 } // namespace content | 1440 } // namespace content |
OLD | NEW |