| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #include "content/public/common/content_switches.h" | 69 #include "content/public/common/content_switches.h" |
| 70 #include "gpu/command_buffer/client/gles2_implementation.h" | 70 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 71 #include "gpu/command_buffer/client/gles2_interface.h" | 71 #include "gpu/command_buffer/client/gles2_interface.h" |
| 72 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 72 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
| 73 #include "ipc/ipc_message_macros.h" | 73 #include "ipc/ipc_message_macros.h" |
| 74 #include "ipc/ipc_message_start.h" | 74 #include "ipc/ipc_message_start.h" |
| 75 #include "skia/ext/image_operations.h" | 75 #include "skia/ext/image_operations.h" |
| 76 #include "third_party/khronos/GLES2/gl2.h" | 76 #include "third_party/khronos/GLES2/gl2.h" |
| 77 #include "third_party/khronos/GLES2/gl2ext.h" | 77 #include "third_party/khronos/GLES2/gl2ext.h" |
| 78 #include "third_party/skia/include/core/SkCanvas.h" | 78 #include "third_party/skia/include/core/SkCanvas.h" |
| 79 #include "ui/android/delegated_frame_host_android.h" | |
| 80 #include "ui/android/window_android.h" | 79 #include "ui/android/window_android.h" |
| 81 #include "ui/android/window_android_compositor.h" | 80 #include "ui/android/window_android_compositor.h" |
| 82 #include "ui/base/layout.h" | 81 #include "ui/base/layout.h" |
| 83 #include "ui/display/display.h" | 82 #include "ui/display/display.h" |
| 84 #include "ui/display/screen.h" | 83 #include "ui/display/screen.h" |
| 85 #include "ui/events/base_event_utils.h" | 84 #include "ui/events/base_event_utils.h" |
| 86 #include "ui/events/blink/blink_event_util.h" | 85 #include "ui/events/blink/blink_event_util.h" |
| 87 #include "ui/events/blink/did_overscroll_params.h" | 86 #include "ui/events/blink/did_overscroll_params.h" |
| 88 #include "ui/events/blink/web_input_event_traits.h" | 87 #include "ui/events/blink/web_input_event_traits.h" |
| 89 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 88 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) | 430 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) |
| 432 ->OnLostResources(); | 431 ->OnLostResources(); |
| 433 } | 432 } |
| 434 } | 433 } |
| 435 } | 434 } |
| 436 | 435 |
| 437 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 436 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 438 RenderWidgetHostImpl* widget_host, | 437 RenderWidgetHostImpl* widget_host, |
| 439 ContentViewCoreImpl* content_view_core) | 438 ContentViewCoreImpl* content_view_core) |
| 440 : host_(widget_host), | 439 : host_(widget_host), |
| 441 outstanding_vsync_requests_(0), | 440 begin_frame_source_(nullptr), |
| 441 outstanding_begin_frame_requests_(0), |
| 442 is_showing_(!widget_host->is_hidden()), | 442 is_showing_(!widget_host->is_hidden()), |
| 443 is_window_visible_(true), | 443 is_window_visible_(true), |
| 444 is_window_activity_started_(true), | 444 is_window_activity_started_(true), |
| 445 is_showing_overscroll_glow_(true), | 445 is_showing_overscroll_glow_(true), |
| 446 content_view_core_(nullptr), | 446 content_view_core_(nullptr), |
| 447 ime_adapter_android_(this), | 447 ime_adapter_android_(this), |
| 448 cached_background_color_(SK_ColorWHITE), | 448 cached_background_color_(SK_ColorWHITE), |
| 449 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), | 449 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), |
| 450 gesture_provider_(ui::GetGestureProviderConfig( | 450 gesture_provider_(ui::GetGestureProviderConfig( |
| 451 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 451 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 452 this), | 452 this), |
| 453 stylus_text_selector_(this), | 453 stylus_text_selector_(this), |
| 454 using_browser_compositor_(CompositorImpl::IsInitialized()), | 454 using_browser_compositor_(CompositorImpl::IsInitialized()), |
| 455 synchronous_compositor_client_(nullptr), | 455 synchronous_compositor_client_(nullptr), |
| 456 frame_evictor_(new DelegatedFrameEvictor(this)), | 456 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 457 locks_on_frame_count_(0), | 457 locks_on_frame_count_(0), |
| 458 observing_root_window_(false), | 458 observing_root_window_(false), |
| 459 weak_ptr_factory_(this) { | 459 weak_ptr_factory_(this) { |
| 460 // Set the layer which will hold the content layer for this view. The content | 460 // Set the layer which will hold the content layer for this view. The content |
| 461 // layer is managed by the DelegatedFrameHost. | 461 // layer is managed by the DelegatedFrameHost. |
| 462 view_.SetLayer(cc::Layer::Create()); | 462 view_.SetLayer(cc::Layer::Create()); |
| 463 if (using_browser_compositor_) { | 463 if (using_browser_compositor_) { |
| 464 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( | 464 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
| 465 &view_, cached_background_color_, | 465 &view_, cached_background_color_, this)); |
| 466 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, | |
| 467 weak_ptr_factory_.GetWeakPtr()))); | |
| 468 } | 466 } |
| 469 | 467 |
| 470 host_->SetView(this); | 468 host_->SetView(this); |
| 471 SetContentViewCore(content_view_core); | 469 SetContentViewCore(content_view_core); |
| 472 | 470 |
| 473 if (GetTextInputManager()) | 471 if (GetTextInputManager()) |
| 474 GetTextInputManager()->AddObserver(this); | 472 GetTextInputManager()->AddObserver(this); |
| 475 } | 473 } |
| 476 | 474 |
| 477 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 475 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 delegated_frame_host_->UpdateBackgroundColor(color); | 793 delegated_frame_host_->UpdateBackgroundColor(color); |
| 796 | 794 |
| 797 if (content_view_core_) | 795 if (content_view_core_) |
| 798 content_view_core_->OnBackgroundColorChanged(color); | 796 content_view_core_->OnBackgroundColorChanged(color); |
| 799 } | 797 } |
| 800 | 798 |
| 801 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { | 799 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 802 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", | 800 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", |
| 803 "needs_begin_frames", needs_begin_frames); | 801 "needs_begin_frames", needs_begin_frames); |
| 804 if (needs_begin_frames) | 802 if (needs_begin_frames) |
| 805 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); | 803 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 806 else | 804 else |
| 807 outstanding_vsync_requests_ &= ~PERSISTENT_BEGIN_FRAME; | 805 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 808 } | 806 } |
| 809 | 807 |
| 810 void RenderWidgetHostViewAndroid::OnStartContentIntent( | 808 void RenderWidgetHostViewAndroid::OnStartContentIntent( |
| 811 const GURL& content_url, bool is_main_frame) { | 809 const GURL& content_url, bool is_main_frame) { |
| 812 if (content_view_core_) | 810 if (content_view_core_) |
| 813 content_view_core_->StartContentIntent(content_url, is_main_frame); | 811 content_view_core_->StartContentIntent(content_url, is_main_frame); |
| 814 } | 812 } |
| 815 | 813 |
| 816 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( | 814 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( |
| 817 const base::string16& text, | 815 const base::string16& text, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 847 if (!result.succeeded) | 845 if (!result.succeeded) |
| 848 return false; | 846 return false; |
| 849 | 847 |
| 850 blink::WebTouchEvent web_event = ui::CreateWebTouchEventFromMotionEvent( | 848 blink::WebTouchEvent web_event = ui::CreateWebTouchEventFromMotionEvent( |
| 851 event, result.moved_beyond_slop_region); | 849 event, result.moved_beyond_slop_region); |
| 852 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); | 850 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); |
| 853 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 851 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 854 host_->ForwardTouchEventWithLatencyInfo(web_event, latency_info); | 852 host_->ForwardTouchEventWithLatencyInfo(web_event, latency_info); |
| 855 | 853 |
| 856 // Send a proactive BeginFrame for this vsync to reduce scroll latency for | 854 // Send a proactive BeginFrame for this vsync to reduce scroll latency for |
| 857 // scroll-inducing touch events. Note that Android's Choreographer ensures | 855 // scroll-inducing touch events. Note that even if we weren't observing the |
| 858 // that BeginFrame requests made during ACTION_MOVE dispatch will be honored | 856 // BeginFrameSource prior to this, we will receive a (missed) BeginFrame for |
| 859 // in the same vsync phase. | 857 // the current vsync phase. |
| 860 if (observing_root_window_ && result.moved_beyond_slop_region) | 858 if (observing_root_window_ && result.moved_beyond_slop_region) |
| 861 RequestVSyncUpdate(BEGIN_FRAME); | 859 AddBeginFrameRequest(BEGIN_FRAME); |
| 862 | 860 |
| 863 return true; | 861 return true; |
| 864 } | 862 } |
| 865 | 863 |
| 866 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent( | 864 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent( |
| 867 const ui::MotionEvent& event) { | 865 const ui::MotionEvent& event) { |
| 868 return selection_controller_ && | 866 return selection_controller_ && |
| 869 selection_controller_->WillHandleTouchEvent(event); | 867 selection_controller_->WillHandleTouchEvent(event); |
| 870 } | 868 } |
| 871 | 869 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 if (!delegated_frame_host_->HasDelegatedContent()) | 1146 if (!delegated_frame_host_->HasDelegatedContent()) |
| 1149 return; | 1147 return; |
| 1150 | 1148 |
| 1151 frame_evictor_->DiscardedFrame(); | 1149 frame_evictor_->DiscardedFrame(); |
| 1152 delegated_frame_host_->DestroyDelegatedContent(); | 1150 delegated_frame_host_->DestroyDelegatedContent(); |
| 1153 } | 1151 } |
| 1154 | 1152 |
| 1155 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 1153 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| 1156 uint32_t compositor_frame_sink_id, | 1154 uint32_t compositor_frame_sink_id, |
| 1157 cc::CompositorFrame frame) { | 1155 cc::CompositorFrame frame) { |
| 1156 uint64_t begin_frame_source_id = frame.metadata.begin_frame_source_id; |
| 1157 uint64_t begin_frame_number = frame.metadata.begin_frame_number; |
| 1158 uint64_t latest_confirmed_frame = frame.metadata.latest_confirmed_frame; |
| 1159 |
| 1158 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame)); | 1160 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame)); |
| 1161 |
| 1162 // DelegatedFrameHostAndroid always submits a frame. |
| 1163 bool has_damage = true; |
| 1164 cc::BeginFrameAck ack(begin_frame_source_id, begin_frame_number, |
| 1165 latest_confirmed_frame, 0, has_damage); |
| 1166 if (begin_frame_source_) |
| 1167 begin_frame_source_->DidFinishFrame(this, ack); |
| 1168 } |
| 1169 |
| 1170 void RenderWidgetHostViewAndroid::OnBeginFrameDidNotDraw( |
| 1171 const cc::BeginFrameAck& ack) { |
| 1172 if (begin_frame_source_) |
| 1173 begin_frame_source_->DidFinishFrame(this, ack); |
| 1159 } | 1174 } |
| 1160 | 1175 |
| 1161 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 1176 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
| 1162 DestroyDelegatedContent(); | 1177 DestroyDelegatedContent(); |
| 1163 } | 1178 } |
| 1164 | 1179 |
| 1165 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id, | 1180 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id, |
| 1166 cc::CompositorFrame frame) { | 1181 cc::CompositorFrame frame) { |
| 1167 DCHECK(locks_on_frame_count_); | 1182 DCHECK(locks_on_frame_count_); |
| 1168 | 1183 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 | 1392 |
| 1378 view_.GetLayer()->SetHideLayerAndSubtree(false); | 1393 view_.GetLayer()->SetHideLayerAndSubtree(false); |
| 1379 | 1394 |
| 1380 frame_evictor_->SetVisible(true); | 1395 frame_evictor_->SetVisible(true); |
| 1381 | 1396 |
| 1382 if (overscroll_controller_) | 1397 if (overscroll_controller_) |
| 1383 overscroll_controller_->Enable(); | 1398 overscroll_controller_->Enable(); |
| 1384 | 1399 |
| 1385 host_->WasShown(ui::LatencyInfo()); | 1400 host_->WasShown(ui::LatencyInfo()); |
| 1386 | 1401 |
| 1387 if (content_view_core_) { | 1402 if (content_view_core_ && view_.GetWindowAndroid()) { |
| 1388 StartObservingRootWindow(); | 1403 StartObservingRootWindow(); |
| 1389 RequestVSyncUpdate(BEGIN_FRAME); | 1404 AddBeginFrameRequest(BEGIN_FRAME); |
| 1390 } | 1405 } |
| 1391 } | 1406 } |
| 1392 | 1407 |
| 1393 void RenderWidgetHostViewAndroid::HideInternal() { | 1408 void RenderWidgetHostViewAndroid::HideInternal() { |
| 1394 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) | 1409 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) |
| 1395 << "Hide called when the widget should be shown."; | 1410 << "Hide called when the widget should be shown."; |
| 1396 | 1411 |
| 1397 // Only preserve the frontbuffer if the activity was stopped while the | 1412 // Only preserve the frontbuffer if the activity was stopped while the |
| 1398 // window is still visible. This avoids visual artificts when transitioning | 1413 // window is still visible. This avoids visual artificts when transitioning |
| 1399 // between activities. | 1414 // between activities. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1422 if (overscroll_controller_) | 1437 if (overscroll_controller_) |
| 1423 overscroll_controller_->Disable(); | 1438 overscroll_controller_->Disable(); |
| 1424 | 1439 |
| 1425 RunAckCallbacks(); | 1440 RunAckCallbacks(); |
| 1426 | 1441 |
| 1427 // Inform the renderer that we are being hidden so it can reduce its resource | 1442 // Inform the renderer that we are being hidden so it can reduce its resource |
| 1428 // utilization. | 1443 // utilization. |
| 1429 host_->WasHidden(); | 1444 host_->WasHidden(); |
| 1430 } | 1445 } |
| 1431 | 1446 |
| 1432 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { | 1447 void RenderWidgetHostViewAndroid::SetBeginFrameSource( |
| 1433 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1448 cc::BeginFrameSource* begin_frame_source) { |
| 1434 outstanding_vsync_requests_ |= requests; | 1449 if (begin_frame_source_ == begin_frame_source) |
| 1450 return; |
| 1435 | 1451 |
| 1436 // Note that if we're not currently observing the root window, outstanding | 1452 if (begin_frame_source_ && outstanding_begin_frame_requests_) |
| 1437 // vsync requests will be pushed if/when we resume observing in | 1453 begin_frame_source_->RemoveObserver(this); |
| 1438 // |StartObservingRootWindow()|. | 1454 begin_frame_source_ = begin_frame_source; |
| 1439 if (observing_root_window_ && should_request_vsync) { | 1455 if (begin_frame_source_ && outstanding_begin_frame_requests_) |
| 1456 begin_frame_source_->AddObserver(this); |
| 1457 } |
| 1458 |
| 1459 void RenderWidgetHostViewAndroid::AddBeginFrameRequest( |
| 1460 BeginFrameRequestType request) { |
| 1461 DCHECK(this); |
| 1462 uint32_t requests = outstanding_begin_frame_requests_ | request; |
| 1463 |
| 1464 // Note that if we don't currently have a BeginFrameSource, outstanding begin |
| 1465 // frame requests will be pushed if/when we get one during |
| 1466 // |StartObservingRootWindow()| or when the DelegatedFrameHostAndroid sets it. |
| 1467 cc::BeginFrameSource* source = begin_frame_source_; |
| 1468 if (source && requests && !outstanding_begin_frame_requests_) { |
| 1440 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid(); | 1469 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid(); |
| 1441 DCHECK(windowAndroid); | 1470 DCHECK(windowAndroid); |
| 1442 // TODO(boliu): This check should be redundant with | 1471 // TODO(boliu): This check should be redundant with |source| check above. |
| 1443 // |observing_root_window_| check above. However we are receiving trickle | 1472 // However, there seem to be cases where we are not notified of window |
| 1444 // of crash reports (crbug.com/639868) with no root cause. Should | 1473 // destruction, which invalidates the BeginFrameSource. See also related |
| 1445 // investigate more when time allows what corner case is missed. | 1474 // crash reports in crbug.com/639868. |
| 1446 if (windowAndroid) | 1475 if (windowAndroid) |
| 1447 windowAndroid->RequestVSyncUpdate(); | 1476 source->AddObserver(this); |
| 1448 } | 1477 } |
| 1478 outstanding_begin_frame_requests_ = requests; |
| 1479 } |
| 1480 |
| 1481 void RenderWidgetHostViewAndroid::ClearBeginFrameRequest( |
| 1482 BeginFrameRequestType request) { |
| 1483 uint32_t requests = outstanding_begin_frame_requests_ & ~request; |
| 1484 |
| 1485 cc::BeginFrameSource* source = begin_frame_source_; |
| 1486 if (source && !requests && outstanding_begin_frame_requests_) |
| 1487 source->RemoveObserver(this); |
| 1488 outstanding_begin_frame_requests_ = requests; |
| 1449 } | 1489 } |
| 1450 | 1490 |
| 1451 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { | 1491 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { |
| 1452 DCHECK(content_view_core_); | 1492 DCHECK(content_view_core_); |
| 1453 // TODO(yusufo): This will need to have a better fallback for cases where | |
| 1454 // setContentViewCore is called with a valid ContentViewCore without a window. | |
| 1455 DCHECK(view_.GetWindowAndroid()); | 1493 DCHECK(view_.GetWindowAndroid()); |
| 1456 DCHECK(is_showing_); | 1494 DCHECK(is_showing_); |
| 1457 if (observing_root_window_) | 1495 if (observing_root_window_) |
| 1458 return; | 1496 return; |
| 1459 | 1497 |
| 1460 observing_root_window_ = true; | 1498 observing_root_window_ = true; |
| 1461 if (host_) | 1499 if (host_) |
| 1462 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); | 1500 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); |
| 1463 view_.GetWindowAndroid()->AddObserver(this); | 1501 view_.GetWindowAndroid()->AddObserver(this); |
| 1464 | 1502 // When using browser compositor, DelegatedFrameHostAndroid provides the BFS. |
| 1465 // Clear existing vsync requests to allow a request to the new window. | 1503 if (!using_browser_compositor_) |
| 1466 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; | 1504 SetBeginFrameSource(view_.GetWindowAndroid()->GetBeginFrameSource()); |
| 1467 outstanding_vsync_requests_ = 0; | |
| 1468 RequestVSyncUpdate(outstanding_vsync_requests); | |
| 1469 | 1505 |
| 1470 ui::WindowAndroidCompositor* compositor = | 1506 ui::WindowAndroidCompositor* compositor = |
| 1471 view_.GetWindowAndroid()->GetCompositor(); | 1507 view_.GetWindowAndroid()->GetCompositor(); |
| 1472 if (compositor) { | 1508 if (compositor) { |
| 1473 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1509 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1474 compositor->GetFrameSinkId()); | 1510 compositor->GetFrameSinkId()); |
| 1475 } | 1511 } |
| 1476 } | 1512 } |
| 1477 | 1513 |
| 1478 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { | 1514 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { |
| 1479 if (!(view_.GetWindowAndroid())) { | 1515 if (!(view_.GetWindowAndroid())) { |
| 1480 DCHECK(!observing_root_window_); | 1516 DCHECK(!observing_root_window_); |
| 1481 return; | 1517 return; |
| 1482 } | 1518 } |
| 1483 | 1519 |
| 1484 if (!observing_root_window_) | 1520 if (!observing_root_window_) |
| 1485 return; | 1521 return; |
| 1486 | 1522 |
| 1487 // Reset window state variables to their defaults. | 1523 // Reset window state variables to their defaults. |
| 1488 is_window_activity_started_ = true; | 1524 is_window_activity_started_ = true; |
| 1489 is_window_visible_ = true; | 1525 is_window_visible_ = true; |
| 1490 observing_root_window_ = false; | 1526 observing_root_window_ = false; |
| 1491 if (host_) | 1527 if (host_) |
| 1492 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); | 1528 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); |
| 1493 view_.GetWindowAndroid()->RemoveObserver(this); | 1529 view_.GetWindowAndroid()->RemoveObserver(this); |
| 1530 if (!using_browser_compositor_) |
| 1531 SetBeginFrameSource(nullptr); |
| 1494 // If the DFH has already been destroyed, it will have cleaned itself up. | 1532 // If the DFH has already been destroyed, it will have cleaned itself up. |
| 1495 // This happens in some WebView cases. | 1533 // This happens in some WebView cases. |
| 1496 if (delegated_frame_host_) | 1534 if (delegated_frame_host_) |
| 1497 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1535 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| 1536 DCHECK_EQ(nullptr, begin_frame_source_); |
| 1498 } | 1537 } |
| 1499 | 1538 |
| 1500 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, | 1539 void RenderWidgetHostViewAndroid::SendBeginFrame(cc::BeginFrameArgs args) { |
| 1501 base::TimeDelta vsync_period) { | 1540 TRACE_EVENT2("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", |
| 1502 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", | 1541 "frame_number", args.sequence_number, |
| 1503 "frame_time_us", frame_time.ToInternalValue()); | 1542 "frame_time_us", args.frame_time.ToInternalValue()); |
| 1504 | 1543 |
| 1505 // Synchronous compositor does not use deadline-based scheduling. | 1544 // Synchronous compositor does not use deadline-based scheduling. |
| 1506 // TODO(brianderson): Replace this hardcoded deadline after Android | 1545 // TODO(brianderson): Replace this hardcoded deadline after Android |
| 1507 // switches to Surfaces and the Browser's commit isn't in the critcal path. | 1546 // switches to Surfaces and the Browser's commit isn't in the critical path. |
| 1508 base::TimeTicks deadline = | 1547 args.deadline = sync_compositor_ ? base::TimeTicks() |
| 1509 sync_compositor_ ? base::TimeTicks() : frame_time + (vsync_period * 0.6); | 1548 : args.frame_time + (args.interval * 0.6); |
| 1510 host_->Send(new ViewMsg_BeginFrame( | 1549 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); |
| 1511 host_->GetRoutingID(), | |
| 1512 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, | |
| 1513 vsync_period, cc::BeginFrameArgs::NORMAL))); | |
| 1514 if (sync_compositor_) | 1550 if (sync_compositor_) |
| 1515 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); | 1551 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); |
| 1516 } | 1552 } |
| 1517 | 1553 |
| 1518 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1554 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
| 1519 bool needs_animate = false; | 1555 bool needs_animate = false; |
| 1520 if (overscroll_controller_ && is_showing_overscroll_glow_) { | 1556 if (overscroll_controller_ && is_showing_overscroll_glow_) { |
| 1521 needs_animate |= overscroll_controller_->Animate( | 1557 needs_animate |= overscroll_controller_->Animate( |
| 1522 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); | 1558 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); |
| 1523 } | 1559 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 if (shim && gpu_data && | 1653 if (shim && gpu_data && |
| 1618 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) | 1654 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) |
| 1619 shim->Send(new GpuMsg_WakeUpGpu); | 1655 shim->Send(new GpuMsg_WakeUpGpu); |
| 1620 } | 1656 } |
| 1621 | 1657 |
| 1622 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1658 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 1623 } | 1659 } |
| 1624 | 1660 |
| 1625 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { | 1661 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { |
| 1626 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); | 1662 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); |
| 1627 RequestVSyncUpdate(FLUSH_INPUT); | 1663 AddBeginFrameRequest(FLUSH_INPUT); |
| 1628 } | 1664 } |
| 1629 | 1665 |
| 1630 BrowserAccessibilityManager* | 1666 BrowserAccessibilityManager* |
| 1631 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( | 1667 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( |
| 1632 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 1668 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 1633 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj; | 1669 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj; |
| 1634 if (for_root_frame && host_ && content_view_core_) | 1670 if (for_root_frame && host_ && content_view_core_) |
| 1635 content_view_core_obj = content_view_core_->GetJavaObject(); | 1671 content_view_core_obj = content_view_core_->GetJavaObject(); |
| 1636 return new BrowserAccessibilityManagerAndroid( | 1672 return new BrowserAccessibilityManagerAndroid( |
| 1637 content_view_core_obj, | 1673 content_view_core_obj, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 if (content_view_core_) | 1836 if (content_view_core_) |
| 1801 obj = content_view_core_->GetJavaObject(); | 1837 obj = content_view_core_->GetJavaObject(); |
| 1802 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1838 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
| 1803 } | 1839 } |
| 1804 | 1840 |
| 1805 if (!content_view_core_) { | 1841 if (!content_view_core_) { |
| 1806 sync_compositor_.reset(); | 1842 sync_compositor_.reset(); |
| 1807 return; | 1843 return; |
| 1808 } | 1844 } |
| 1809 | 1845 |
| 1810 if (is_showing_) | 1846 if (is_showing_ && view_.GetWindowAndroid()) |
| 1811 StartObservingRootWindow(); | 1847 StartObservingRootWindow(); |
| 1812 | 1848 |
| 1813 if (resize) | 1849 if (resize) |
| 1814 WasResized(); | 1850 WasResized(); |
| 1815 | 1851 |
| 1816 if (!selection_controller_) | 1852 if (!selection_controller_) |
| 1817 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1853 selection_controller_ = CreateSelectionController(this, content_view_core_); |
| 1818 | 1854 |
| 1819 if (!overscroll_controller_ && | 1855 if (!overscroll_controller_ && |
| 1820 view_.GetWindowAndroid()->GetCompositor()) { | 1856 view_.GetWindowAndroid()->GetCompositor()) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1917 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1882 StopObservingRootWindow(); | 1918 StopObservingRootWindow(); |
| 1883 OnDetachCompositor(); | 1919 OnDetachCompositor(); |
| 1884 } | 1920 } |
| 1885 | 1921 |
| 1886 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1922 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1887 DCHECK(content_view_core_); | 1923 DCHECK(content_view_core_); |
| 1888 if (!overscroll_controller_) | 1924 if (!overscroll_controller_) |
| 1889 overscroll_controller_ = CreateOverscrollController( | 1925 overscroll_controller_ = CreateOverscrollController( |
| 1890 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | 1926 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); |
| 1891 ui::WindowAndroidCompositor* compositor = | 1927 if (observing_root_window_) { |
| 1892 view_.GetWindowAndroid()->GetCompositor(); | 1928 ui::WindowAndroidCompositor* compositor = |
| 1893 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1929 view_.GetWindowAndroid()->GetCompositor(); |
| 1894 compositor->GetFrameSinkId()); | 1930 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1931 compositor->GetFrameSinkId()); |
| 1932 } |
| 1895 } | 1933 } |
| 1896 | 1934 |
| 1897 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1935 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1898 DCHECK(content_view_core_); | 1936 DCHECK(content_view_core_); |
| 1899 DCHECK(using_browser_compositor_); | 1937 DCHECK(using_browser_compositor_); |
| 1900 RunAckCallbacks(); | 1938 RunAckCallbacks(); |
| 1901 overscroll_controller_.reset(); | 1939 overscroll_controller_.reset(); |
| 1902 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1940 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| 1903 } | 1941 } |
| 1904 | 1942 |
| 1905 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1943 void RenderWidgetHostViewAndroid::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 1906 base::TimeDelta vsync_period) { | 1944 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnBeginFrame"); |
| 1907 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); | |
| 1908 if (!host_) | 1945 if (!host_) |
| 1909 return; | 1946 return; |
| 1910 | 1947 |
| 1911 if (outstanding_vsync_requests_ & FLUSH_INPUT) { | 1948 // In sync mode, we disregard missed frame args to ensure that |
| 1912 outstanding_vsync_requests_ &= ~FLUSH_INPUT; | 1949 // SynchronousCompositorBrowserFilter::SyncStateAfterVSync will be called |
| 1950 // during an OnVSync() observer iteration. |
| 1951 if (sync_compositor_ && args.type == cc::BeginFrameArgs::MISSED) |
| 1952 return; |
| 1953 |
| 1954 if (outstanding_begin_frame_requests_ & FLUSH_INPUT) { |
| 1955 ClearBeginFrameRequest(FLUSH_INPUT); |
| 1913 host_->FlushInput(); | 1956 host_->FlushInput(); |
| 1914 } | 1957 } |
| 1915 | 1958 |
| 1916 if (outstanding_vsync_requests_ & BEGIN_FRAME || | 1959 if ((outstanding_begin_frame_requests_ & BEGIN_FRAME) || |
| 1917 outstanding_vsync_requests_ & PERSISTENT_BEGIN_FRAME) { | 1960 (outstanding_begin_frame_requests_ & PERSISTENT_BEGIN_FRAME)) { |
| 1918 outstanding_vsync_requests_ &= ~BEGIN_FRAME; | 1961 ClearBeginFrameRequest(BEGIN_FRAME); |
| 1919 SendBeginFrame(frame_time, vsync_period); | 1962 SendBeginFrame(args); |
| 1920 } | 1963 } |
| 1921 | 1964 |
| 1922 // This allows for SendBeginFrame and FlushInput to modify | 1965 last_begin_frame_args_ = args; |
| 1923 // outstanding_vsync_requests. | 1966 } |
| 1924 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; | 1967 |
| 1925 outstanding_vsync_requests_ = 0; | 1968 const cc::BeginFrameArgs& RenderWidgetHostViewAndroid::LastUsedBeginFrameArgs() |
| 1926 RequestVSyncUpdate(outstanding_vsync_requests); | 1969 const { |
| 1970 return last_begin_frame_args_; |
| 1971 } |
| 1972 |
| 1973 void RenderWidgetHostViewAndroid::OnBeginFrameSourcePausedChanged(bool paused) { |
| 1974 // The BeginFrameSources we listen to don't use this. For WebView, we signal |
| 1975 // the "paused" state to the RenderWidget when our window attaches/detaches, |
| 1976 // see |StartObservingRootWindow()| and |StopObservingRootWindow()|. |
| 1977 DCHECK(!paused); |
| 1927 } | 1978 } |
| 1928 | 1979 |
| 1929 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1980 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
| 1930 if (Animate(begin_frame_time)) | 1981 if (Animate(begin_frame_time)) |
| 1931 SetNeedsAnimate(); | 1982 SetNeedsAnimate(); |
| 1932 } | 1983 } |
| 1933 | 1984 |
| 1934 void RenderWidgetHostViewAndroid::OnActivityStopped() { | 1985 void RenderWidgetHostViewAndroid::OnActivityStopped() { |
| 1935 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped"); | 1986 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped"); |
| 1936 DCHECK(observing_root_window_); | 1987 DCHECK(observing_root_window_); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 case ui::MotionEvent::ACTION_UP: | 2046 case ui::MotionEvent::ACTION_UP: |
| 1996 case ui::MotionEvent::ACTION_POINTER_UP: | 2047 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1997 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 2048 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1998 delta.InMicroseconds(), 1, 1000000, 50); | 2049 delta.InMicroseconds(), 1, 1000000, 50); |
| 1999 default: | 2050 default: |
| 2000 return; | 2051 return; |
| 2001 } | 2052 } |
| 2002 } | 2053 } |
| 2003 | 2054 |
| 2004 } // namespace content | 2055 } // namespace content |
| OLD | NEW |