| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #include "content/public/common/content_switches.h" | 70 #include "content/public/common/content_switches.h" |
| 71 #include "gpu/command_buffer/client/gles2_implementation.h" | 71 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 72 #include "gpu/command_buffer/client/gles2_interface.h" | 72 #include "gpu/command_buffer/client/gles2_interface.h" |
| 73 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 73 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
| 74 #include "ipc/ipc_message_macros.h" | 74 #include "ipc/ipc_message_macros.h" |
| 75 #include "ipc/ipc_message_start.h" | 75 #include "ipc/ipc_message_start.h" |
| 76 #include "skia/ext/image_operations.h" | 76 #include "skia/ext/image_operations.h" |
| 77 #include "third_party/khronos/GLES2/gl2.h" | 77 #include "third_party/khronos/GLES2/gl2.h" |
| 78 #include "third_party/khronos/GLES2/gl2ext.h" | 78 #include "third_party/khronos/GLES2/gl2ext.h" |
| 79 #include "third_party/skia/include/core/SkCanvas.h" | 79 #include "third_party/skia/include/core/SkCanvas.h" |
| 80 #include "ui/android/delegated_frame_host_android.h" | |
| 81 #include "ui/android/window_android.h" | 80 #include "ui/android/window_android.h" |
| 82 #include "ui/android/window_android_compositor.h" | 81 #include "ui/android/window_android_compositor.h" |
| 83 #include "ui/base/layout.h" | 82 #include "ui/base/layout.h" |
| 84 #include "ui/display/display.h" | 83 #include "ui/display/display.h" |
| 85 #include "ui/display/screen.h" | 84 #include "ui/display/screen.h" |
| 86 #include "ui/events/base_event_utils.h" | 85 #include "ui/events/base_event_utils.h" |
| 87 #include "ui/events/blink/blink_event_util.h" | 86 #include "ui/events/blink/blink_event_util.h" |
| 88 #include "ui/events/blink/did_overscroll_params.h" | 87 #include "ui/events/blink/did_overscroll_params.h" |
| 89 #include "ui/events/blink/web_input_event_traits.h" | 88 #include "ui/events/blink/web_input_event_traits.h" |
| 90 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 89 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) | 424 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) |
| 426 ->OnLostResources(); | 425 ->OnLostResources(); |
| 427 } | 426 } |
| 428 } | 427 } |
| 429 } | 428 } |
| 430 | 429 |
| 431 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 430 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 432 RenderWidgetHostImpl* widget_host, | 431 RenderWidgetHostImpl* widget_host, |
| 433 ContentViewCoreImpl* content_view_core) | 432 ContentViewCoreImpl* content_view_core) |
| 434 : host_(widget_host), | 433 : host_(widget_host), |
| 435 outstanding_vsync_requests_(0), | 434 begin_frame_source_(nullptr), |
| 435 outstanding_begin_frame_requests_(0), |
| 436 is_showing_(!widget_host->is_hidden()), | 436 is_showing_(!widget_host->is_hidden()), |
| 437 is_window_visible_(true), | 437 is_window_visible_(true), |
| 438 is_window_activity_started_(true), | 438 is_window_activity_started_(true), |
| 439 is_showing_overscroll_glow_(true), | 439 is_showing_overscroll_glow_(true), |
| 440 content_view_core_(nullptr), | 440 content_view_core_(nullptr), |
| 441 ime_adapter_android_(this), | 441 ime_adapter_android_(this), |
| 442 cached_background_color_(SK_ColorWHITE), | 442 cached_background_color_(SK_ColorWHITE), |
| 443 view_(this), | 443 view_(this), |
| 444 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), | 444 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), |
| 445 gesture_provider_(ui::GetGestureProviderConfig( | 445 gesture_provider_(ui::GetGestureProviderConfig( |
| 446 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 446 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 447 this), | 447 this), |
| 448 stylus_text_selector_(this), | 448 stylus_text_selector_(this), |
| 449 using_browser_compositor_(CompositorImpl::IsInitialized()), | 449 using_browser_compositor_(CompositorImpl::IsInitialized()), |
| 450 synchronous_compositor_client_(nullptr), | 450 synchronous_compositor_client_(nullptr), |
| 451 frame_evictor_(new DelegatedFrameEvictor(this)), | 451 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 452 locks_on_frame_count_(0), | 452 locks_on_frame_count_(0), |
| 453 observing_root_window_(false), | 453 observing_root_window_(false), |
| 454 weak_ptr_factory_(this) { | 454 weak_ptr_factory_(this) { |
| 455 // Set the layer which will hold the content layer for this view. The content | 455 // Set the layer which will hold the content layer for this view. The content |
| 456 // layer is managed by the DelegatedFrameHost. | 456 // layer is managed by the DelegatedFrameHost. |
| 457 view_.SetLayer(cc::Layer::Create()); | 457 view_.SetLayer(cc::Layer::Create()); |
| 458 if (using_browser_compositor_) { | 458 if (using_browser_compositor_) { |
| 459 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( | 459 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
| 460 &view_, cached_background_color_, | 460 &view_, cached_background_color_, this)); |
| 461 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, | |
| 462 weak_ptr_factory_.GetWeakPtr()))); | |
| 463 } | 461 } |
| 464 | 462 |
| 465 host_->SetView(this); | 463 host_->SetView(this); |
| 466 SetContentViewCore(content_view_core); | 464 SetContentViewCore(content_view_core); |
| 467 | 465 |
| 468 CreateOverscrollControllerIfPossible(); | 466 CreateOverscrollControllerIfPossible(); |
| 469 | 467 |
| 470 if (GetTextInputManager()) | 468 if (GetTextInputManager()) |
| 471 GetTextInputManager()->AddObserver(this); | 469 GetTextInputManager()->AddObserver(this); |
| 472 } | 470 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 delegated_frame_host_->UpdateBackgroundColor(color); | 790 delegated_frame_host_->UpdateBackgroundColor(color); |
| 793 | 791 |
| 794 if (content_view_core_) | 792 if (content_view_core_) |
| 795 content_view_core_->OnBackgroundColorChanged(color); | 793 content_view_core_->OnBackgroundColorChanged(color); |
| 796 } | 794 } |
| 797 | 795 |
| 798 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { | 796 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 799 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", | 797 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", |
| 800 "needs_begin_frames", needs_begin_frames); | 798 "needs_begin_frames", needs_begin_frames); |
| 801 if (needs_begin_frames) | 799 if (needs_begin_frames) |
| 802 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); | 800 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 803 else | 801 else |
| 804 outstanding_vsync_requests_ &= ~PERSISTENT_BEGIN_FRAME; | 802 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 805 } | 803 } |
| 806 | 804 |
| 807 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged(int width, | 805 void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged(int width, |
| 808 int height) { | 806 int height) { |
| 809 WasResized(); | 807 WasResized(); |
| 810 } | 808 } |
| 811 | 809 |
| 812 void RenderWidgetHostViewAndroid::OnStartContentIntent( | 810 void RenderWidgetHostViewAndroid::OnStartContentIntent( |
| 813 const GURL& content_url, bool is_main_frame) { | 811 const GURL& content_url, bool is_main_frame) { |
| 814 if (content_view_core_) | 812 if (content_view_core_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 event, result.moved_beyond_slop_region); | 851 event, result.moved_beyond_slop_region); |
| 854 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); | 852 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); |
| 855 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 853 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 856 host_->ForwardTouchEventWithLatencyInfo(web_event, latency_info); | 854 host_->ForwardTouchEventWithLatencyInfo(web_event, latency_info); |
| 857 | 855 |
| 858 // Send a proactive BeginFrame for this vsync to reduce scroll latency for | 856 // Send a proactive BeginFrame for this vsync to reduce scroll latency for |
| 859 // scroll-inducing touch events. Note that Android's Choreographer ensures | 857 // scroll-inducing touch events. Note that Android's Choreographer ensures |
| 860 // that BeginFrame requests made during ACTION_MOVE dispatch will be honored | 858 // that BeginFrame requests made during ACTION_MOVE dispatch will be honored |
| 861 // in the same vsync phase. | 859 // in the same vsync phase. |
| 862 if (observing_root_window_ && result.moved_beyond_slop_region) | 860 if (observing_root_window_ && result.moved_beyond_slop_region) |
| 863 RequestVSyncUpdate(BEGIN_FRAME); | 861 AddBeginFrameRequest(BEGIN_FRAME); |
| 864 | 862 |
| 865 return true; | 863 return true; |
| 866 } | 864 } |
| 867 | 865 |
| 868 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent( | 866 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent( |
| 869 const ui::MotionEvent& event) { | 867 const ui::MotionEvent& event) { |
| 870 return selection_controller_ && | 868 return selection_controller_ && |
| 871 selection_controller_->WillHandleTouchEvent(event); | 869 selection_controller_->WillHandleTouchEvent(event); |
| 872 } | 870 } |
| 873 | 871 |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 | 1382 |
| 1385 view_.GetLayer()->SetHideLayerAndSubtree(false); | 1383 view_.GetLayer()->SetHideLayerAndSubtree(false); |
| 1386 | 1384 |
| 1387 frame_evictor_->SetVisible(true); | 1385 frame_evictor_->SetVisible(true); |
| 1388 | 1386 |
| 1389 if (overscroll_controller_) | 1387 if (overscroll_controller_) |
| 1390 overscroll_controller_->Enable(); | 1388 overscroll_controller_->Enable(); |
| 1391 | 1389 |
| 1392 host_->WasShown(ui::LatencyInfo()); | 1390 host_->WasShown(ui::LatencyInfo()); |
| 1393 | 1391 |
| 1394 if (content_view_core_) { | 1392 if (content_view_core_ && view_.GetWindowAndroid()) { |
| 1395 StartObservingRootWindow(); | 1393 StartObservingRootWindow(); |
| 1396 RequestVSyncUpdate(BEGIN_FRAME); | 1394 AddBeginFrameRequest(BEGIN_FRAME); |
| 1397 } | 1395 } |
| 1398 } | 1396 } |
| 1399 | 1397 |
| 1400 void RenderWidgetHostViewAndroid::HideInternal() { | 1398 void RenderWidgetHostViewAndroid::HideInternal() { |
| 1401 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) | 1399 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) |
| 1402 << "Hide called when the widget should be shown."; | 1400 << "Hide called when the widget should be shown."; |
| 1403 | 1401 |
| 1404 // Only preserve the frontbuffer if the activity was stopped while the | 1402 // Only preserve the frontbuffer if the activity was stopped while the |
| 1405 // window is still visible. This avoids visual artificts when transitioning | 1403 // window is still visible. This avoids visual artificts when transitioning |
| 1406 // between activities. | 1404 // between activities. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1429 if (overscroll_controller_) | 1427 if (overscroll_controller_) |
| 1430 overscroll_controller_->Disable(); | 1428 overscroll_controller_->Disable(); |
| 1431 | 1429 |
| 1432 RunAckCallbacks(); | 1430 RunAckCallbacks(); |
| 1433 | 1431 |
| 1434 // Inform the renderer that we are being hidden so it can reduce its resource | 1432 // Inform the renderer that we are being hidden so it can reduce its resource |
| 1435 // utilization. | 1433 // utilization. |
| 1436 host_->WasHidden(); | 1434 host_->WasHidden(); |
| 1437 } | 1435 } |
| 1438 | 1436 |
| 1439 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { | 1437 void RenderWidgetHostViewAndroid::SetBeginFrameSource( |
| 1440 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1438 cc::BeginFrameSource* begin_frame_source) { |
| 1441 outstanding_vsync_requests_ |= requests; | 1439 if (begin_frame_source_ == begin_frame_source) |
| 1440 return; |
| 1442 | 1441 |
| 1443 // Note that if we're not currently observing the root window, outstanding | 1442 if (begin_frame_source_ && outstanding_begin_frame_requests_) |
| 1444 // vsync requests will be pushed if/when we resume observing in | 1443 begin_frame_source_->RemoveObserver(this); |
| 1445 // |StartObservingRootWindow()|. | 1444 begin_frame_source_ = begin_frame_source; |
| 1446 if (observing_root_window_ && should_request_vsync) { | 1445 if (begin_frame_source_ && outstanding_begin_frame_requests_) |
| 1447 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid(); | 1446 begin_frame_source_->AddObserver(this); |
| 1448 DCHECK(windowAndroid); | 1447 } |
| 1449 // TODO(boliu): This check should be redundant with | 1448 |
| 1450 // |observing_root_window_| check above. However we are receiving trickle | 1449 void RenderWidgetHostViewAndroid::AddBeginFrameRequest( |
| 1451 // of crash reports (crbug.com/639868) with no root cause. Should | 1450 BeginFrameRequestType request) { |
| 1452 // investigate more when time allows what corner case is missed. | 1451 uint32_t prior_requests = outstanding_begin_frame_requests_; |
| 1453 if (windowAndroid) | 1452 outstanding_begin_frame_requests_ = prior_requests | request; |
| 1454 windowAndroid->RequestVSyncUpdate(); | 1453 |
| 1455 } | 1454 // Note that if we don't currently have a BeginFrameSource, outstanding begin |
| 1455 // frame requests will be pushed if/when we get one during |
| 1456 // |StartObservingRootWindow()| or when the DelegatedFrameHostAndroid sets it. |
| 1457 cc::BeginFrameSource* source = begin_frame_source_; |
| 1458 if (source && outstanding_begin_frame_requests_ && !prior_requests) |
| 1459 source->AddObserver(this); |
| 1460 } |
| 1461 |
| 1462 void RenderWidgetHostViewAndroid::ClearBeginFrameRequest( |
| 1463 BeginFrameRequestType request) { |
| 1464 uint32_t prior_requests = outstanding_begin_frame_requests_; |
| 1465 outstanding_begin_frame_requests_ = prior_requests & ~request; |
| 1466 |
| 1467 cc::BeginFrameSource* source = begin_frame_source_; |
| 1468 if (source && !outstanding_begin_frame_requests_ && prior_requests) |
| 1469 source->RemoveObserver(this); |
| 1456 } | 1470 } |
| 1457 | 1471 |
| 1458 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { | 1472 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { |
| 1459 DCHECK(content_view_core_); | 1473 DCHECK(content_view_core_); |
| 1460 // TODO(yusufo): This will need to have a better fallback for cases where | |
| 1461 // setContentViewCore is called with a valid ContentViewCore without a window. | |
| 1462 DCHECK(view_.GetWindowAndroid()); | 1474 DCHECK(view_.GetWindowAndroid()); |
| 1463 DCHECK(is_showing_); | 1475 DCHECK(is_showing_); |
| 1464 if (observing_root_window_) | 1476 if (observing_root_window_) |
| 1465 return; | 1477 return; |
| 1466 | 1478 |
| 1467 observing_root_window_ = true; | 1479 observing_root_window_ = true; |
| 1468 if (host_) | 1480 if (host_) |
| 1469 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); | 1481 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); |
| 1470 view_.GetWindowAndroid()->AddObserver(this); | 1482 view_.GetWindowAndroid()->AddObserver(this); |
| 1471 | 1483 // When using browser compositor, DelegatedFrameHostAndroid provides the BFS. |
| 1472 // Clear existing vsync requests to allow a request to the new window. | 1484 if (!using_browser_compositor_) |
| 1473 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; | 1485 SetBeginFrameSource(view_.GetWindowAndroid()->GetBeginFrameSource()); |
| 1474 outstanding_vsync_requests_ = 0; | |
| 1475 RequestVSyncUpdate(outstanding_vsync_requests); | |
| 1476 | 1486 |
| 1477 ui::WindowAndroidCompositor* compositor = | 1487 ui::WindowAndroidCompositor* compositor = |
| 1478 view_.GetWindowAndroid()->GetCompositor(); | 1488 view_.GetWindowAndroid()->GetCompositor(); |
| 1479 if (compositor) { | 1489 if (compositor) { |
| 1480 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1490 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1481 compositor->GetFrameSinkId()); | 1491 compositor->GetFrameSinkId()); |
| 1482 } | 1492 } |
| 1483 } | 1493 } |
| 1484 | 1494 |
| 1485 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { | 1495 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { |
| 1486 if (!(view_.GetWindowAndroid())) { | 1496 if (!(view_.GetWindowAndroid())) { |
| 1487 DCHECK(!observing_root_window_); | 1497 DCHECK(!observing_root_window_); |
| 1488 return; | 1498 return; |
| 1489 } | 1499 } |
| 1490 | 1500 |
| 1491 if (!observing_root_window_) | 1501 if (!observing_root_window_) |
| 1492 return; | 1502 return; |
| 1493 | 1503 |
| 1494 // Reset window state variables to their defaults. | 1504 // Reset window state variables to their defaults. |
| 1495 is_window_activity_started_ = true; | 1505 is_window_activity_started_ = true; |
| 1496 is_window_visible_ = true; | 1506 is_window_visible_ = true; |
| 1497 observing_root_window_ = false; | 1507 observing_root_window_ = false; |
| 1498 if (host_) | 1508 if (host_) |
| 1499 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); | 1509 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); |
| 1500 view_.GetWindowAndroid()->RemoveObserver(this); | 1510 view_.GetWindowAndroid()->RemoveObserver(this); |
| 1511 if (!using_browser_compositor_) |
| 1512 SetBeginFrameSource(nullptr); |
| 1501 // If the DFH has already been destroyed, it will have cleaned itself up. | 1513 // If the DFH has already been destroyed, it will have cleaned itself up. |
| 1502 // This happens in some WebView cases. | 1514 // This happens in some WebView cases. |
| 1503 if (delegated_frame_host_) | 1515 if (delegated_frame_host_) |
| 1504 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1516 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| 1517 DCHECK(!begin_frame_source_); |
| 1505 } | 1518 } |
| 1506 | 1519 |
| 1507 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, | 1520 void RenderWidgetHostViewAndroid::SendBeginFrame(cc::BeginFrameArgs args) { |
| 1508 base::TimeDelta vsync_period) { | |
| 1509 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", | 1521 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", |
| 1510 "frame_time_us", frame_time.ToInternalValue()); | 1522 "frame_time_us", args.frame_time.ToInternalValue()); |
| 1511 | 1523 |
| 1512 // Synchronous compositor does not use deadline-based scheduling. | 1524 // Synchronous compositor does not use deadline-based scheduling. |
| 1513 // TODO(brianderson): Replace this hardcoded deadline after Android | 1525 // TODO(brianderson): Replace this hardcoded deadline after Android |
| 1514 // switches to Surfaces and the Browser's commit isn't in the critcal path. | 1526 // switches to Surfaces and the Browser's commit isn't in the critical path. |
| 1515 base::TimeTicks deadline = | 1527 args.deadline = sync_compositor_ ? base::TimeTicks() |
| 1516 sync_compositor_ ? base::TimeTicks() : frame_time + (vsync_period * 0.6); | 1528 : args.frame_time + (args.interval * 0.6); |
| 1517 host_->Send(new ViewMsg_BeginFrame( | 1529 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); |
| 1518 host_->GetRoutingID(), | |
| 1519 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, | |
| 1520 vsync_period, cc::BeginFrameArgs::NORMAL))); | |
| 1521 if (sync_compositor_) | 1530 if (sync_compositor_) |
| 1522 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); | 1531 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); |
| 1523 } | 1532 } |
| 1524 | 1533 |
| 1525 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1534 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
| 1526 bool needs_animate = false; | 1535 bool needs_animate = false; |
| 1527 if (overscroll_controller_ && is_showing_overscroll_glow_) { | 1536 if (overscroll_controller_ && is_showing_overscroll_glow_) { |
| 1528 needs_animate |= overscroll_controller_->Animate( | 1537 needs_animate |= overscroll_controller_->Animate( |
| 1529 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); | 1538 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); |
| 1530 } | 1539 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 if (shim && gpu_data && | 1633 if (shim && gpu_data && |
| 1625 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) | 1634 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) |
| 1626 shim->Send(new GpuMsg_WakeUpGpu); | 1635 shim->Send(new GpuMsg_WakeUpGpu); |
| 1627 } | 1636 } |
| 1628 | 1637 |
| 1629 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1638 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 1630 } | 1639 } |
| 1631 | 1640 |
| 1632 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { | 1641 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { |
| 1633 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); | 1642 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); |
| 1634 RequestVSyncUpdate(FLUSH_INPUT); | 1643 AddBeginFrameRequest(FLUSH_INPUT); |
| 1635 } | 1644 } |
| 1636 | 1645 |
| 1637 BrowserAccessibilityManager* | 1646 BrowserAccessibilityManager* |
| 1638 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( | 1647 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( |
| 1639 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 1648 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 1640 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj; | 1649 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj; |
| 1641 if (for_root_frame && host_ && content_view_core_) | 1650 if (for_root_frame && host_ && content_view_core_) |
| 1642 content_view_core_obj = content_view_core_->GetJavaObject(); | 1651 content_view_core_obj = content_view_core_->GetJavaObject(); |
| 1643 return new BrowserAccessibilityManagerAndroid( | 1652 return new BrowserAccessibilityManagerAndroid( |
| 1644 content_view_core_obj, | 1653 content_view_core_obj, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 if (content_view_core_) | 1815 if (content_view_core_) |
| 1807 obj = content_view_core_->GetJavaObject(); | 1816 obj = content_view_core_->GetJavaObject(); |
| 1808 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1817 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
| 1809 } | 1818 } |
| 1810 | 1819 |
| 1811 if (!content_view_core_) { | 1820 if (!content_view_core_) { |
| 1812 sync_compositor_.reset(); | 1821 sync_compositor_.reset(); |
| 1813 return; | 1822 return; |
| 1814 } | 1823 } |
| 1815 | 1824 |
| 1816 if (is_showing_) | 1825 if (is_showing_ && view_.GetWindowAndroid()) |
| 1817 StartObservingRootWindow(); | 1826 StartObservingRootWindow(); |
| 1818 | 1827 |
| 1819 if (resize) | 1828 if (resize) |
| 1820 WasResized(); | 1829 WasResized(); |
| 1821 | 1830 |
| 1822 if (!selection_controller_) | 1831 if (!selection_controller_) |
| 1823 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1832 selection_controller_ = CreateSelectionController(this, content_view_core_); |
| 1824 | 1833 |
| 1825 if (content_view_core_) | 1834 if (content_view_core_) |
| 1826 CreateOverscrollControllerIfPossible(); | 1835 CreateOverscrollControllerIfPossible(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 } | 1891 } |
| 1883 | 1892 |
| 1884 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1893 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1885 StopObservingRootWindow(); | 1894 StopObservingRootWindow(); |
| 1886 OnDetachCompositor(); | 1895 OnDetachCompositor(); |
| 1887 } | 1896 } |
| 1888 | 1897 |
| 1889 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1898 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1890 DCHECK(content_view_core_); | 1899 DCHECK(content_view_core_); |
| 1891 CreateOverscrollControllerIfPossible(); | 1900 CreateOverscrollControllerIfPossible(); |
| 1892 ui::WindowAndroidCompositor* compositor = | 1901 if (observing_root_window_) { |
| 1893 view_.GetWindowAndroid()->GetCompositor(); | 1902 ui::WindowAndroidCompositor* compositor = |
| 1894 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1903 view_.GetWindowAndroid()->GetCompositor(); |
| 1895 compositor->GetFrameSinkId()); | 1904 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1905 compositor->GetFrameSinkId()); |
| 1906 } |
| 1896 } | 1907 } |
| 1897 | 1908 |
| 1898 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1909 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1899 DCHECK(content_view_core_); | 1910 DCHECK(content_view_core_); |
| 1900 DCHECK(using_browser_compositor_); | 1911 DCHECK(using_browser_compositor_); |
| 1901 RunAckCallbacks(); | 1912 RunAckCallbacks(); |
| 1902 overscroll_controller_.reset(); | 1913 overscroll_controller_.reset(); |
| 1903 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1914 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| 1904 } | 1915 } |
| 1905 | 1916 |
| 1906 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1917 void RenderWidgetHostViewAndroid::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 1907 base::TimeDelta vsync_period) { | 1918 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnBeginFrame"); |
| 1908 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); | |
| 1909 if (!host_) | 1919 if (!host_) |
| 1910 return; | 1920 return; |
| 1911 | 1921 |
| 1912 if (outstanding_vsync_requests_ & FLUSH_INPUT) { | 1922 // In sync mode, we disregard missed frame args to ensure that |
| 1913 outstanding_vsync_requests_ &= ~FLUSH_INPUT; | 1923 // SynchronousCompositorBrowserFilter::SyncStateAfterVSync will be called |
| 1924 // during WindowAndroid::WindowBeginFrameSource::OnVSync() observer iteration. |
| 1925 if (sync_compositor_ && args.type == cc::BeginFrameArgs::MISSED) |
| 1926 return; |
| 1927 |
| 1928 // Update |last_begin_frame_args_| before handling |
| 1929 // |outstanding_begin_frame_requests_| to prevent the BeginFrameSource from |
| 1930 // sending the same MISSED args in infinite recursion. This may otherwise |
| 1931 // happen if |host_->FlushInput()| causes a synchronous OnSetNeedsFlushInput() |
| 1932 // which can lead to |begin_frame_source_->AddObserver()| and OnBeginFrame(). |
| 1933 // By setting |last_begin_frame_args_|, we indicate to the source not to send |
| 1934 // the same args during |AddObserver()| again. |
| 1935 last_begin_frame_args_ = args; |
| 1936 |
| 1937 if (outstanding_begin_frame_requests_ & FLUSH_INPUT) { |
| 1938 ClearBeginFrameRequest(FLUSH_INPUT); |
| 1914 host_->FlushInput(); | 1939 host_->FlushInput(); |
| 1915 } | 1940 } |
| 1916 | 1941 |
| 1917 if (outstanding_vsync_requests_ & BEGIN_FRAME || | 1942 if ((outstanding_begin_frame_requests_ & BEGIN_FRAME) || |
| 1918 outstanding_vsync_requests_ & PERSISTENT_BEGIN_FRAME) { | 1943 (outstanding_begin_frame_requests_ & PERSISTENT_BEGIN_FRAME)) { |
| 1919 outstanding_vsync_requests_ &= ~BEGIN_FRAME; | 1944 ClearBeginFrameRequest(BEGIN_FRAME); |
| 1920 SendBeginFrame(frame_time, vsync_period); | 1945 SendBeginFrame(args); |
| 1921 } | 1946 } |
| 1947 } |
| 1922 | 1948 |
| 1923 // This allows for SendBeginFrame and FlushInput to modify | 1949 const cc::BeginFrameArgs& RenderWidgetHostViewAndroid::LastUsedBeginFrameArgs() |
| 1924 // outstanding_vsync_requests. | 1950 const { |
| 1925 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; | 1951 return last_begin_frame_args_; |
| 1926 outstanding_vsync_requests_ = 0; | 1952 } |
| 1927 RequestVSyncUpdate(outstanding_vsync_requests); | 1953 |
| 1954 void RenderWidgetHostViewAndroid::OnBeginFrameSourcePausedChanged(bool paused) { |
| 1955 // The BeginFrameSources we listen to don't use this. For WebView, we signal |
| 1956 // the "paused" state to the RenderWidget when our window attaches/detaches, |
| 1957 // see |StartObservingRootWindow()| and |StopObservingRootWindow()|. |
| 1958 DCHECK(!paused); |
| 1928 } | 1959 } |
| 1929 | 1960 |
| 1930 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1961 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
| 1931 if (Animate(begin_frame_time)) | 1962 if (Animate(begin_frame_time)) |
| 1932 SetNeedsAnimate(); | 1963 SetNeedsAnimate(); |
| 1933 } | 1964 } |
| 1934 | 1965 |
| 1935 void RenderWidgetHostViewAndroid::OnActivityStopped() { | 1966 void RenderWidgetHostViewAndroid::OnActivityStopped() { |
| 1936 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped"); | 1967 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped"); |
| 1937 DCHECK(observing_root_window_); | 1968 DCHECK(observing_root_window_); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 if (!compositor) | 2070 if (!compositor) |
| 2040 return; | 2071 return; |
| 2041 | 2072 |
| 2042 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2073 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
| 2043 overscroll_refresh_handler, compositor, | 2074 overscroll_refresh_handler, compositor, |
| 2044 ui::GetScaleFactorForNativeView(GetNativeView())); | 2075 ui::GetScaleFactorForNativeView(GetNativeView())); |
| 2045 is_showing_overscroll_glow_ = true; | 2076 is_showing_overscroll_glow_ = true; |
| 2046 } | 2077 } |
| 2047 | 2078 |
| 2048 } // namespace content | 2079 } // namespace content |
| OLD | NEW |