Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2564403002: [android] Make RWHVAndroid a BeginFrameObserver. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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.
boliu 2016/12/12 21:41:48 I think previous comment is fine. RWHVA could alr
Eric Seckler 2016/12/13 10:03:56 Ok, reverted. We probably don't want to get rid of
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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1375
1378 view_.GetLayer()->SetHideLayerAndSubtree(false); 1376 view_.GetLayer()->SetHideLayerAndSubtree(false);
1379 1377
1380 frame_evictor_->SetVisible(true); 1378 frame_evictor_->SetVisible(true);
1381 1379
1382 if (overscroll_controller_) 1380 if (overscroll_controller_)
1383 overscroll_controller_->Enable(); 1381 overscroll_controller_->Enable();
1384 1382
1385 host_->WasShown(ui::LatencyInfo()); 1383 host_->WasShown(ui::LatencyInfo());
1386 1384
1387 if (content_view_core_) { 1385 if (content_view_core_ && view_.GetWindowAndroid()) {
1388 StartObservingRootWindow(); 1386 StartObservingRootWindow();
1389 RequestVSyncUpdate(BEGIN_FRAME); 1387 AddBeginFrameRequest(BEGIN_FRAME);
1390 } 1388 }
1391 } 1389 }
1392 1390
1393 void RenderWidgetHostViewAndroid::HideInternal() { 1391 void RenderWidgetHostViewAndroid::HideInternal() {
1394 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) 1392 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_)
1395 << "Hide called when the widget should be shown."; 1393 << "Hide called when the widget should be shown.";
1396 1394
1397 // Only preserve the frontbuffer if the activity was stopped while the 1395 // Only preserve the frontbuffer if the activity was stopped while the
1398 // window is still visible. This avoids visual artificts when transitioning 1396 // window is still visible. This avoids visual artificts when transitioning
1399 // between activities. 1397 // between activities.
(...skipping 22 matching lines...) Expand all
1422 if (overscroll_controller_) 1420 if (overscroll_controller_)
1423 overscroll_controller_->Disable(); 1421 overscroll_controller_->Disable();
1424 1422
1425 RunAckCallbacks(); 1423 RunAckCallbacks();
1426 1424
1427 // Inform the renderer that we are being hidden so it can reduce its resource 1425 // Inform the renderer that we are being hidden so it can reduce its resource
1428 // utilization. 1426 // utilization.
1429 host_->WasHidden(); 1427 host_->WasHidden();
1430 } 1428 }
1431 1429
1432 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { 1430 void RenderWidgetHostViewAndroid::SetBeginFrameSource(
1433 bool should_request_vsync = !outstanding_vsync_requests_ && requests; 1431 cc::BeginFrameSource* begin_frame_source) {
1434 outstanding_vsync_requests_ |= requests; 1432 if (begin_frame_source_ == begin_frame_source)
1433 return;
1435 1434
1436 // Note that if we're not currently observing the root window, outstanding 1435 if (begin_frame_source_ && outstanding_begin_frame_requests_)
1437 // vsync requests will be pushed if/when we resume observing in 1436 begin_frame_source_->RemoveObserver(this);
1438 // |StartObservingRootWindow()|. 1437 begin_frame_source_ = begin_frame_source;
1439 if (observing_root_window_ && should_request_vsync) { 1438 if (begin_frame_source_ && outstanding_begin_frame_requests_)
1439 begin_frame_source_->AddObserver(this);
1440 }
1441
1442 void RenderWidgetHostViewAndroid::AddBeginFrameRequest(
1443 BeginFrameRequestType request) {
1444 DCHECK(this);
boliu 2016/12/12 21:41:48 hmm?
Eric Seckler 2016/12/13 10:03:56 thanks, was debugging here.. removed :)
1445 uint32_t requests = outstanding_begin_frame_requests_ | request;
1446
1447 // Note that if we don't currently have a BeginFrameSource, outstanding begin
1448 // frame requests will be pushed if/when we get one during
1449 // |StartObservingRootWindow()| or when the DelegatedFrameHostAndroid sets it.
1450 cc::BeginFrameSource* source = begin_frame_source_;
1451 if (source && requests && !outstanding_begin_frame_requests_) {
1440 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid(); 1452 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid();
1441 DCHECK(windowAndroid); 1453 DCHECK(windowAndroid);
boliu 2016/12/12 21:41:48 So windowAndroid pointer can change throughout the
Eric Seckler 2016/12/13 10:03:56 In android-chrome, there's a direct relationship b
boliu 2016/12/13 18:07:47 And it looks like RegisterFrameSinkHierarchy->Regi
Eric Seckler 2016/12/14 15:36:57 Ok, got rid of it.
1442 // TODO(boliu): This check should be redundant with 1454 // TODO(boliu): This check should be redundant with |source| check above.
1443 // |observing_root_window_| check above. However we are receiving trickle 1455 // 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 1456 // destruction, which leaves a dangling |source| pointer. See also related
1445 // investigate more when time allows what corner case is missed. 1457 // crash reports in crbug.com/639868 (from before RWHVA became a
1458 // BeginFrameObserver).
1446 if (windowAndroid) 1459 if (windowAndroid)
1447 windowAndroid->RequestVSyncUpdate(); 1460 source->AddObserver(this);
1448 } 1461 }
1462 outstanding_begin_frame_requests_ = requests;
1463 }
1464
1465 void RenderWidgetHostViewAndroid::ClearBeginFrameRequest(
1466 BeginFrameRequestType request) {
1467 uint32_t requests = outstanding_begin_frame_requests_ & ~request;
1468
1469 cc::BeginFrameSource* source = begin_frame_source_;
1470 if (source && !requests && outstanding_begin_frame_requests_)
1471 source->RemoveObserver(this);
1472 outstanding_begin_frame_requests_ = requests;
1449 } 1473 }
1450 1474
1451 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { 1475 void RenderWidgetHostViewAndroid::StartObservingRootWindow() {
1452 DCHECK(content_view_core_); 1476 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()); 1477 DCHECK(view_.GetWindowAndroid());
1456 DCHECK(is_showing_); 1478 DCHECK(is_showing_);
1457 if (observing_root_window_) 1479 if (observing_root_window_)
1458 return; 1480 return;
1459 1481
1460 observing_root_window_ = true; 1482 observing_root_window_ = true;
1461 if (host_) 1483 if (host_)
1462 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); 1484 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false));
1463 view_.GetWindowAndroid()->AddObserver(this); 1485 view_.GetWindowAndroid()->AddObserver(this);
1464 1486 // When using browser compositor, DelegatedFrameHostAndroid provides the BFS.
1465 // Clear existing vsync requests to allow a request to the new window. 1487 if (!using_browser_compositor_)
1466 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; 1488 SetBeginFrameSource(view_.GetWindowAndroid()->GetBeginFrameSource());
1467 outstanding_vsync_requests_ = 0;
1468 RequestVSyncUpdate(outstanding_vsync_requests);
1469 1489
1470 ui::WindowAndroidCompositor* compositor = 1490 ui::WindowAndroidCompositor* compositor =
1471 view_.GetWindowAndroid()->GetCompositor(); 1491 view_.GetWindowAndroid()->GetCompositor();
1472 if (compositor) { 1492 if (compositor) {
1473 delegated_frame_host_->RegisterFrameSinkHierarchy( 1493 delegated_frame_host_->RegisterFrameSinkHierarchy(
1474 compositor->GetFrameSinkId()); 1494 compositor->GetFrameSinkId());
1475 } 1495 }
1476 } 1496 }
1477 1497
1478 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { 1498 void RenderWidgetHostViewAndroid::StopObservingRootWindow() {
1479 if (!(view_.GetWindowAndroid())) { 1499 if (!(view_.GetWindowAndroid())) {
1480 DCHECK(!observing_root_window_); 1500 DCHECK(!observing_root_window_);
1481 return; 1501 return;
1482 } 1502 }
1483 1503
1484 if (!observing_root_window_) 1504 if (!observing_root_window_)
1485 return; 1505 return;
1486 1506
1487 // Reset window state variables to their defaults. 1507 // Reset window state variables to their defaults.
1488 is_window_activity_started_ = true; 1508 is_window_activity_started_ = true;
1489 is_window_visible_ = true; 1509 is_window_visible_ = true;
1490 observing_root_window_ = false; 1510 observing_root_window_ = false;
1491 if (host_) 1511 if (host_)
1492 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); 1512 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true));
1493 view_.GetWindowAndroid()->RemoveObserver(this); 1513 view_.GetWindowAndroid()->RemoveObserver(this);
1514 if (!using_browser_compositor_)
1515 SetBeginFrameSource(nullptr);
1494 // If the DFH has already been destroyed, it will have cleaned itself up. 1516 // If the DFH has already been destroyed, it will have cleaned itself up.
1495 // This happens in some WebView cases. 1517 // This happens in some WebView cases.
1496 if (delegated_frame_host_) 1518 if (delegated_frame_host_)
1497 delegated_frame_host_->UnregisterFrameSinkHierarchy(); 1519 delegated_frame_host_->UnregisterFrameSinkHierarchy();
1520 DCHECK_EQ(nullptr, begin_frame_source_);
boliu 2016/12/12 21:41:48 nit: DCHECK(!begin_frame_source_)?
Eric Seckler 2016/12/13 10:03:55 Done.
1498 } 1521 }
1499 1522
1500 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, 1523 void RenderWidgetHostViewAndroid::SendBeginFrame(cc::BeginFrameArgs args) {
1501 base::TimeDelta vsync_period) {
1502 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", 1524 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame",
1503 "frame_time_us", frame_time.ToInternalValue()); 1525 "frame_time_us", args.frame_time.ToInternalValue());
1504 1526
1505 // Synchronous compositor does not use deadline-based scheduling. 1527 // Synchronous compositor does not use deadline-based scheduling.
1506 // TODO(brianderson): Replace this hardcoded deadline after Android 1528 // TODO(brianderson): Replace this hardcoded deadline after Android
1507 // switches to Surfaces and the Browser's commit isn't in the critcal path. 1529 // switches to Surfaces and the Browser's commit isn't in the critical path.
1508 base::TimeTicks deadline = 1530 args.deadline = sync_compositor_ ? base::TimeTicks()
1509 sync_compositor_ ? base::TimeTicks() : frame_time + (vsync_period * 0.6); 1531 : args.frame_time + (args.interval * 0.6);
1510 host_->Send(new ViewMsg_BeginFrame( 1532 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_) 1533 if (sync_compositor_)
1515 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); 1534 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid());
1516 } 1535 }
1517 1536
1518 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { 1537 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) {
1519 bool needs_animate = false; 1538 bool needs_animate = false;
1520 if (overscroll_controller_ && is_showing_overscroll_glow_) { 1539 if (overscroll_controller_ && is_showing_overscroll_glow_) {
1521 needs_animate |= overscroll_controller_->Animate( 1540 needs_animate |= overscroll_controller_->Animate(
1522 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); 1541 frame_time, content_view_core_->GetViewAndroid()->GetLayer());
1523 } 1542 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 if (shim && gpu_data && 1636 if (shim && gpu_data &&
1618 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) 1637 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING))
1619 shim->Send(new GpuMsg_WakeUpGpu); 1638 shim->Send(new GpuMsg_WakeUpGpu);
1620 } 1639 }
1621 1640
1622 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 1641 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1623 } 1642 }
1624 1643
1625 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { 1644 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() {
1626 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); 1645 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput");
1627 RequestVSyncUpdate(FLUSH_INPUT); 1646 AddBeginFrameRequest(FLUSH_INPUT);
1628 } 1647 }
1629 1648
1630 BrowserAccessibilityManager* 1649 BrowserAccessibilityManager*
1631 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( 1650 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager(
1632 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { 1651 BrowserAccessibilityDelegate* delegate, bool for_root_frame) {
1633 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj; 1652 base::android::ScopedJavaLocalRef<jobject> content_view_core_obj;
1634 if (for_root_frame && host_ && content_view_core_) 1653 if (for_root_frame && host_ && content_view_core_)
1635 content_view_core_obj = content_view_core_->GetJavaObject(); 1654 content_view_core_obj = content_view_core_->GetJavaObject();
1636 return new BrowserAccessibilityManagerAndroid( 1655 return new BrowserAccessibilityManagerAndroid(
1637 content_view_core_obj, 1656 content_view_core_obj,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 if (content_view_core_) 1819 if (content_view_core_)
1801 obj = content_view_core_->GetJavaObject(); 1820 obj = content_view_core_->GetJavaObject();
1802 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); 1821 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj);
1803 } 1822 }
1804 1823
1805 if (!content_view_core_) { 1824 if (!content_view_core_) {
1806 sync_compositor_.reset(); 1825 sync_compositor_.reset();
1807 return; 1826 return;
1808 } 1827 }
1809 1828
1810 if (is_showing_) 1829 if (is_showing_ && view_.GetWindowAndroid())
1811 StartObservingRootWindow(); 1830 StartObservingRootWindow();
1812 1831
1813 if (resize) 1832 if (resize)
1814 WasResized(); 1833 WasResized();
1815 1834
1816 if (!selection_controller_) 1835 if (!selection_controller_)
1817 selection_controller_ = CreateSelectionController(this, content_view_core_); 1836 selection_controller_ = CreateSelectionController(this, content_view_core_);
1818 1837
1819 if (!overscroll_controller_ && 1838 if (!overscroll_controller_ &&
1820 view_.GetWindowAndroid()->GetCompositor()) { 1839 view_.GetWindowAndroid()->GetCompositor()) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { 1900 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() {
1882 StopObservingRootWindow(); 1901 StopObservingRootWindow();
1883 OnDetachCompositor(); 1902 OnDetachCompositor();
1884 } 1903 }
1885 1904
1886 void RenderWidgetHostViewAndroid::OnAttachCompositor() { 1905 void RenderWidgetHostViewAndroid::OnAttachCompositor() {
1887 DCHECK(content_view_core_); 1906 DCHECK(content_view_core_);
1888 if (!overscroll_controller_) 1907 if (!overscroll_controller_)
1889 overscroll_controller_ = CreateOverscrollController( 1908 overscroll_controller_ = CreateOverscrollController(
1890 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); 1909 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView()));
1891 ui::WindowAndroidCompositor* compositor = 1910 if (observing_root_window_) {
boliu 2016/12/12 21:41:48 this should not be needed, this still comes from t
Eric Seckler 2016/12/13 10:03:56 I think this was a preexisting bug. What you say a
boliu 2016/12/13 18:07:47 Keep it. Your analysis looks correct to me
1892 view_.GetWindowAndroid()->GetCompositor(); 1911 ui::WindowAndroidCompositor* compositor =
1893 delegated_frame_host_->RegisterFrameSinkHierarchy( 1912 view_.GetWindowAndroid()->GetCompositor();
1894 compositor->GetFrameSinkId()); 1913 delegated_frame_host_->RegisterFrameSinkHierarchy(
1914 compositor->GetFrameSinkId());
1915 }
1895 } 1916 }
1896 1917
1897 void RenderWidgetHostViewAndroid::OnDetachCompositor() { 1918 void RenderWidgetHostViewAndroid::OnDetachCompositor() {
1898 DCHECK(content_view_core_); 1919 DCHECK(content_view_core_);
1899 DCHECK(using_browser_compositor_); 1920 DCHECK(using_browser_compositor_);
1900 RunAckCallbacks(); 1921 RunAckCallbacks();
1901 overscroll_controller_.reset(); 1922 overscroll_controller_.reset();
1902 delegated_frame_host_->UnregisterFrameSinkHierarchy(); 1923 delegated_frame_host_->UnregisterFrameSinkHierarchy();
1903 } 1924 }
1904 1925
1905 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, 1926 void RenderWidgetHostViewAndroid::OnBeginFrame(const cc::BeginFrameArgs& args) {
1906 base::TimeDelta vsync_period) { 1927 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnBeginFrame");
1907 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync");
1908 if (!host_) 1928 if (!host_)
1909 return; 1929 return;
1910 1930
1911 if (outstanding_vsync_requests_ & FLUSH_INPUT) { 1931 // In sync mode, we disregard missed frame args to ensure that
1912 outstanding_vsync_requests_ &= ~FLUSH_INPUT; 1932 // SynchronousCompositorBrowserFilter::SyncStateAfterVSync will be called
1933 // during WindowAndroid::WindowBeginFrameSource::OnVSync() observer iteration.
1934 if (sync_compositor_ && args.type == cc::BeginFrameArgs::MISSED)
1935 return;
1936
1937 if (outstanding_begin_frame_requests_ & FLUSH_INPUT) {
1938 ClearBeginFrameRequest(FLUSH_INPUT);
1913 host_->FlushInput(); 1939 host_->FlushInput();
1914 } 1940 }
1915 1941
1916 if (outstanding_vsync_requests_ & BEGIN_FRAME || 1942 if ((outstanding_begin_frame_requests_ & BEGIN_FRAME) ||
1917 outstanding_vsync_requests_ & PERSISTENT_BEGIN_FRAME) { 1943 (outstanding_begin_frame_requests_ & PERSISTENT_BEGIN_FRAME)) {
1918 outstanding_vsync_requests_ &= ~BEGIN_FRAME; 1944 ClearBeginFrameRequest(BEGIN_FRAME);
1919 SendBeginFrame(frame_time, vsync_period); 1945 SendBeginFrame(args);
1920 } 1946 }
1921 1947
1922 // This allows for SendBeginFrame and FlushInput to modify 1948 last_begin_frame_args_ = args;
1923 // outstanding_vsync_requests. 1949 }
1924 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; 1950
1925 outstanding_vsync_requests_ = 0; 1951 const cc::BeginFrameArgs& RenderWidgetHostViewAndroid::LastUsedBeginFrameArgs()
1926 RequestVSyncUpdate(outstanding_vsync_requests); 1952 const {
1953 return last_begin_frame_args_;
1954 }
1955
1956 void RenderWidgetHostViewAndroid::OnBeginFrameSourcePausedChanged(bool paused) {
1957 // The BeginFrameSources we listen to don't use this. For WebView, we signal
1958 // the "paused" state to the RenderWidget when our window attaches/detaches,
1959 // see |StartObservingRootWindow()| and |StopObservingRootWindow()|.
1960 DCHECK(!paused);
1927 } 1961 }
1928 1962
1929 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { 1963 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) {
1930 if (Animate(begin_frame_time)) 1964 if (Animate(begin_frame_time))
1931 SetNeedsAnimate(); 1965 SetNeedsAnimate();
1932 } 1966 }
1933 1967
1934 void RenderWidgetHostViewAndroid::OnActivityStopped() { 1968 void RenderWidgetHostViewAndroid::OnActivityStopped() {
1935 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped"); 1969 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStopped");
1936 DCHECK(observing_root_window_); 1970 DCHECK(observing_root_window_);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 case ui::MotionEvent::ACTION_UP: 2029 case ui::MotionEvent::ACTION_UP:
1996 case ui::MotionEvent::ACTION_POINTER_UP: 2030 case ui::MotionEvent::ACTION_POINTER_UP:
1997 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 2031 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1998 delta.InMicroseconds(), 1, 1000000, 50); 2032 delta.InMicroseconds(), 1, 1000000, 50);
1999 default: 2033 default:
2000 return; 2034 return;
2001 } 2035 }
2002 } 2036 }
2003 2037
2004 } // namespace content 2038 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698