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

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

Issue 423773002: Unified BeginFrame scheduling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
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_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "cc/layers/layer.h" 16 #include "cc/layers/layer.h"
17 #include "cc/output/copy_output_request.h" 17 #include "cc/output/copy_output_request.h"
18 #include "cc/output/copy_output_result.h" 18 #include "cc/output/copy_output_result.h"
19 #include "cc/resources/texture_mailbox.h" 19 #include "cc/resources/texture_mailbox.h"
20 #include "cc/trees/layer_tree_settings.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h" 20 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 21 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
23 #include "content/browser/frame_host/frame_tree.h" 22 #include "content/browser/frame_host/frame_tree.h"
24 #include "content/browser/frame_host/frame_tree_node.h" 23 #include "content/browser/frame_host/frame_tree_node.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 24 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/browser/gpu/compositor_util.h" 25 #include "content/browser/gpu/compositor_util.h"
27 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" 26 #include "content/browser/renderer_host/compositor_resize_lock_aura.h"
28 #include "content/browser/renderer_host/dip_util.h" 27 #include "content/browser/renderer_host/dip_util.h"
29 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" 28 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
30 #include "content/browser/renderer_host/overscroll_controller.h" 29 #include "content/browser/renderer_host/overscroll_controller.h"
(...skipping 23 matching lines...) Expand all
54 #include "ui/aura/env.h" 53 #include "ui/aura/env.h"
55 #include "ui/aura/window.h" 54 #include "ui/aura/window.h"
56 #include "ui/aura/window_event_dispatcher.h" 55 #include "ui/aura/window_event_dispatcher.h"
57 #include "ui/aura/window_observer.h" 56 #include "ui/aura/window_observer.h"
58 #include "ui/aura/window_tracker.h" 57 #include "ui/aura/window_tracker.h"
59 #include "ui/aura/window_tree_host.h" 58 #include "ui/aura/window_tree_host.h"
60 #include "ui/base/clipboard/scoped_clipboard_writer.h" 59 #include "ui/base/clipboard/scoped_clipboard_writer.h"
61 #include "ui/base/hit_test.h" 60 #include "ui/base/hit_test.h"
62 #include "ui/base/ime/input_method.h" 61 #include "ui/base/ime/input_method.h"
63 #include "ui/base/ui_base_types.h" 62 #include "ui/base/ui_base_types.h"
64 #include "ui/compositor/compositor_vsync_manager.h"
65 #include "ui/compositor/dip_util.h" 63 #include "ui/compositor/dip_util.h"
66 #include "ui/events/event.h" 64 #include "ui/events/event.h"
67 #include "ui/events/event_utils.h" 65 #include "ui/events/event_utils.h"
68 #include "ui/events/gestures/gesture_recognizer.h" 66 #include "ui/events/gestures/gesture_recognizer.h"
69 #include "ui/gfx/canvas.h" 67 #include "ui/gfx/canvas.h"
70 #include "ui/gfx/display.h" 68 #include "ui/gfx/display.h"
71 #include "ui/gfx/rect_conversions.h" 69 #include "ui/gfx/rect_conversions.h"
72 #include "ui/gfx/screen.h" 70 #include "ui/gfx/screen.h"
73 #include "ui/gfx/size_conversions.h" 71 #include "ui/gfx/size_conversions.h"
74 #include "ui/gfx/skia_util.h" 72 #include "ui/gfx/skia_util.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 last_swapped_software_frame_scale_factor_(1.f), 443 last_swapped_software_frame_scale_factor_(1.f),
446 paint_canvas_(NULL), 444 paint_canvas_(NULL),
447 synthetic_move_sent_(false), 445 synthetic_move_sent_(false),
448 cursor_visibility_state_in_renderer_(UNKNOWN), 446 cursor_visibility_state_in_renderer_(UNKNOWN),
449 #if defined(OS_WIN) 447 #if defined(OS_WIN)
450 legacy_render_widget_host_HWND_(NULL), 448 legacy_render_widget_host_HWND_(NULL),
451 legacy_window_destroyed_(false), 449 legacy_window_destroyed_(false),
452 #endif 450 #endif
453 has_snapped_to_boundary_(false), 451 has_snapped_to_boundary_(false),
454 touch_editing_client_(NULL), 452 touch_editing_client_(NULL),
453 needs_begin_frame_(false),
454 begin_frame_scheduling_is_enabled_(false),
455 weak_ptr_factory_(this) { 455 weak_ptr_factory_(this) {
456 host_->SetView(this); 456 host_->SetView(this);
457 window_observer_.reset(new WindowObserver(this)); 457 window_observer_.reset(new WindowObserver(this));
458 aura::client::SetTooltipText(window_, &tooltip_); 458 aura::client::SetTooltipText(window_, &tooltip_);
459 aura::client::SetActivationDelegate(window_, this); 459 aura::client::SetActivationDelegate(window_, this);
460 aura::client::SetActivationChangeObserver(window_, this); 460 aura::client::SetActivationChangeObserver(window_, this);
461 aura::client::SetFocusChangeObserver(window_, this); 461 aura::client::SetFocusChangeObserver(window_, this);
462 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 462 window_->set_layer_owner_delegate(delegated_frame_host_.get());
463 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 463 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
464 464
465 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> 465 bool overscroll_enabled = CommandLine::ForCurrentProcess()->
466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
467 SetOverscrollControllerEnabled(overscroll_enabled); 467 SetOverscrollControllerEnabled(overscroll_enabled);
468
469 #if !defined(OS_CHROMEOS)
470 begin_frame_scheduling_is_enabled_ = true;
brianderson 2014/09/04 18:45:46 Can we assume this is true for all Aura platforms?
471 #endif
468 } 472 }
469 473
470 //////////////////////////////////////////////////////////////////////////////// 474 ////////////////////////////////////////////////////////////////////////////////
471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: 475 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
472 476
477 bool RenderWidgetHostViewAura::OnMessageReceived(const IPC::Message& msg) {
478 bool handled = true;
479 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, msg)
480 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrame, OnSetNeedsBeginFrame)
481 IPC_MESSAGE_UNHANDLED(handled = false)
482 IPC_END_MESSAGE_MAP()
483 return handled;
484 }
485
473 void RenderWidgetHostViewAura::InitAsChild( 486 void RenderWidgetHostViewAura::InitAsChild(
474 gfx::NativeView parent_view) { 487 gfx::NativeView parent_view) {
475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 488 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
476 window_->Init(aura::WINDOW_LAYER_TEXTURED); 489 window_->Init(aura::WINDOW_LAYER_TEXTURED);
477 window_->SetName("RenderWidgetHostViewAura"); 490 window_->SetName("RenderWidgetHostViewAura");
478 } 491 }
479 492
480 void RenderWidgetHostViewAura::InitAsPopup( 493 void RenderWidgetHostViewAura::InitAsPopup(
481 RenderWidgetHostView* parent_host_view, 494 RenderWidgetHostView* parent_host_view,
482 const gfx::Rect& bounds_in_screen) { 495 const gfx::Rect& bounds_in_screen) {
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 865
853 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, 866 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status,
854 int error_code) { 867 int error_code) {
855 UpdateCursorIfOverSelf(); 868 UpdateCursorIfOverSelf();
856 Destroy(); 869 Destroy();
857 } 870 }
858 871
859 void RenderWidgetHostViewAura::Destroy() { 872 void RenderWidgetHostViewAura::Destroy() {
860 // Beware, this function is not called on all destruction paths. It will 873 // Beware, this function is not called on all destruction paths. It will
861 // implicitly end up calling ~RenderWidgetHostViewAura though, so all 874 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
862 // destruction/cleanup code should happen there, not here. 875 // destruction/cleanup code should happen there, not here.
piman 2014/09/04 20:56:38 Beware of this comment!
876
877 // Remove observation from Compositor in here because we can't access
878 // to compositor in destructor.
879 if (needs_begin_frame_ && GetCompositor()) {
880 GetCompositor()->RemoveBeginFrameObserver(this);
881 needs_begin_frame_ = false;
882 }
883
863 in_shutdown_ = true; 884 in_shutdown_ = true;
864 delete window_; 885 delete window_;
865 } 886 }
866 887
867 void RenderWidgetHostViewAura::SetTooltipText( 888 void RenderWidgetHostViewAura::SetTooltipText(
868 const base::string16& tooltip_text) { 889 const base::string16& tooltip_text) {
869 tooltip_ = tooltip_text; 890 tooltip_ = tooltip_text;
870 aura::Window* root_window = window_->GetRootWindow(); 891 aura::Window* root_window = window_->GetRootWindow();
871 aura::client::TooltipClient* tooltip_client = 892 aura::client::TooltipClient* tooltip_client =
872 aura::client::GetTooltipClient(root_window); 893 aura::client::GetTooltipClient(root_window);
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 2133
2113 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, 2134 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host,
2114 const gfx::Point& new_origin) { 2135 const gfx::Point& new_origin) {
2115 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", 2136 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2116 "new_origin", new_origin.ToString()); 2137 "new_origin", new_origin.ToString());
2117 2138
2118 UpdateScreenInfo(window_); 2139 UpdateScreenInfo(window_);
2119 } 2140 }
2120 2141
2121 //////////////////////////////////////////////////////////////////////////////// 2142 ////////////////////////////////////////////////////////////////////////////////
2143 // ui::CompositorBeginFrameObserver implementation:
2144 void RenderWidgetHostViewAura::OnSendBeginFrame(
2145 const cc::BeginFrameArgs& args) {
2146 DCHECK(begin_frame_scheduling_is_enabled_);
2147 DCHECK(host_);
2148 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame");
2149
2150 delegated_frame_host_->UpdateVSyncParameters(args);
2151
2152 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args));
2153
2154 last_begin_frame_args_ = args;
2155 }
2156
2157 ////////////////////////////////////////////////////////////////////////////////
2122 // RenderWidgetHostViewAura, private: 2158 // RenderWidgetHostViewAura, private:
2123 2159
2124 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { 2160 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2161 // When we are using unified BeginFrame(--enable-begin-frame-scheduling),
2162 // |needs_begin_frame_| always be false in here. We can't remove
2163 // observation from Compositor in this function because |window_| is already
2164 // removed from window tree host.
2165 DCHECK(!needs_begin_frame_);
2166
2125 if (touch_editing_client_) 2167 if (touch_editing_client_)
2126 touch_editing_client_->OnViewDestroyed(); 2168 touch_editing_client_->OnViewDestroyed();
2127 2169
2128 delegated_frame_host_.reset(); 2170 delegated_frame_host_.reset();
2129 window_observer_.reset(); 2171 window_observer_.reset();
2130 if (window_->GetHost()) 2172 if (window_->GetHost())
2131 window_->GetHost()->RemoveObserver(this); 2173 window_->GetHost()->RemoveObserver(this);
2132 UnlockMouse(); 2174 UnlockMouse();
2133 if (popup_parent_host_view_) { 2175 if (popup_parent_host_view_) {
2134 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || 2176 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL ||
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 2414
2373 #if defined(OS_WIN) 2415 #if defined(OS_WIN)
2374 // The parent may have changed here. Ensure that the legacy window is 2416 // The parent may have changed here. Ensure that the legacy window is
2375 // reparented accordingly. 2417 // reparented accordingly.
2376 if (legacy_render_widget_host_HWND_) 2418 if (legacy_render_widget_host_HWND_)
2377 legacy_render_widget_host_HWND_->UpdateParent( 2419 legacy_render_widget_host_HWND_->UpdateParent(
2378 reinterpret_cast<HWND>(GetNativeViewId())); 2420 reinterpret_cast<HWND>(GetNativeViewId()));
2379 #endif 2421 #endif
2380 2422
2381 delegated_frame_host_->AddedToWindow(); 2423 delegated_frame_host_->AddedToWindow();
2424
2425 // When this RWHV is added to new root window, this RWHV should be added to
2426 // the new compositor.
2427 if (needs_begin_frame_) {
2428 DCHECK(begin_frame_scheduling_is_enabled_);
2429 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_);
2430 }
piman 2014/09/04 20:56:38 A lot of this logic is common between mac and aura
2382 } 2431 }
2383 2432
2384 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 2433 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2385 aura::client::CursorClient* cursor_client = 2434 aura::client::CursorClient* cursor_client =
2386 aura::client::GetCursorClient(window_->GetRootWindow()); 2435 aura::client::GetCursorClient(window_->GetRootWindow());
2387 if (cursor_client) 2436 if (cursor_client)
2388 cursor_client->RemoveObserver(this); 2437 cursor_client->RemoveObserver(this);
2389 2438
2390 DetachFromInputMethod(); 2439 DetachFromInputMethod();
2391 2440
2392 window_->GetHost()->RemoveObserver(this); 2441 window_->GetHost()->RemoveObserver(this);
2393 delegated_frame_host_->RemovingFromWindow(); 2442 delegated_frame_host_->RemovingFromWindow();
2394 2443
2395 #if defined(OS_WIN) 2444 #if defined(OS_WIN)
2396 // Update the legacy window's parent temporarily to the desktop window. It 2445 // Update the legacy window's parent temporarily to the desktop window. It
2397 // will eventually get reparented to the right root. 2446 // will eventually get reparented to the right root.
2398 if (legacy_render_widget_host_HWND_) 2447 if (legacy_render_widget_host_HWND_)
2399 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); 2448 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow());
2400 #endif 2449 #endif
2450
2451 // When this RWHV is removed from current root window, this RWHV should be
2452 // removed from the current compositor which will be removed.
2453 if (needs_begin_frame_) {
2454 DCHECK(begin_frame_scheduling_is_enabled_);
2455 GetCompositor()->RemoveBeginFrameObserver(this);
2456 }
2401 } 2457 }
2402 2458
2403 void RenderWidgetHostViewAura::DetachFromInputMethod() { 2459 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2404 ui::InputMethod* input_method = GetInputMethod(); 2460 ui::InputMethod* input_method = GetInputMethod();
2405 if (input_method && input_method->GetTextInputClient() == this) 2461 if (input_method && input_method->GetTextInputClient() == this)
2406 input_method->SetFocusedTextInputClient(NULL); 2462 input_method->SetFocusedTextInputClient(NULL);
2407 } 2463 }
2408 2464
2409 void RenderWidgetHostViewAura::ForwardKeyboardEvent( 2465 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2410 const NativeWebKeyboardEvent& event) { 2466 const NativeWebKeyboardEvent& event) {
(...skipping 21 matching lines...) Expand all
2432 } 2488 }
2433 #endif 2489 #endif
2434 2490
2435 host_->ForwardKeyboardEvent(event); 2491 host_->ForwardKeyboardEvent(event);
2436 } 2492 }
2437 2493
2438 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { 2494 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() {
2439 return kN32_SkColorType; 2495 return kN32_SkColorType;
2440 } 2496 }
2441 2497
2498 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) {
2499 DCHECK(begin_frame_scheduling_is_enabled_);
2500 DCHECK(GetCompositor());
2501
2502 if (needs_begin_frame_ == enabled)
2503 return;
2504
2505 TRACE_EVENT1("cc", "RenderWidgetHostViewAura::OnSetNeedsBeginFrame",
2506 "enabled", enabled);
2507 if (enabled)
2508 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_);
2509 else
2510 GetCompositor()->RemoveBeginFrameObserver(this);
2511
2512 needs_begin_frame_ = enabled;
2513 }
2514
2442 //////////////////////////////////////////////////////////////////////////////// 2515 ////////////////////////////////////////////////////////////////////////////////
2443 // DelegatedFrameHost, public: 2516 // DelegatedFrameHost, public:
2444 2517
2445 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { 2518 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const {
2446 aura::WindowTreeHost* host = window_->GetHost(); 2519 aura::WindowTreeHost* host = window_->GetHost();
2447 return host ? host->compositor() : NULL; 2520 return host ? host->compositor() : NULL;
2448 } 2521 }
2449 2522
2450 ui::Layer* RenderWidgetHostViewAura::GetLayer() { 2523 ui::Layer* RenderWidgetHostViewAura::GetLayer() {
2451 return window_->layer(); 2524 return window_->layer();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 2566
2494 //////////////////////////////////////////////////////////////////////////////// 2567 ////////////////////////////////////////////////////////////////////////////////
2495 // RenderWidgetHostViewBase, public: 2568 // RenderWidgetHostViewBase, public:
2496 2569
2497 // static 2570 // static
2498 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2571 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2499 GetScreenInfoForWindow(results, NULL); 2572 GetScreenInfoForWindow(results, NULL);
2500 } 2573 }
2501 2574
2502 } // namespace content 2575 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698