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

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/base/switches.h"
16 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
17 #include "cc/output/copy_output_request.h" 18 #include "cc/output/copy_output_request.h"
18 #include "cc/output/copy_output_result.h" 19 #include "cc/output/copy_output_result.h"
19 #include "cc/resources/texture_mailbox.h" 20 #include "cc/resources/texture_mailbox.h"
20 #include "cc/trees/layer_tree_settings.h" 21 #include "cc/trees/layer_tree_settings.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h" 22 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 23 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
23 #include "content/browser/frame_host/frame_tree.h" 24 #include "content/browser/frame_host/frame_tree.h"
24 #include "content/browser/frame_host/frame_tree_node.h" 25 #include "content/browser/frame_host/frame_tree_node.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 26 #include "content/browser/frame_host/render_frame_host_impl.h"
(...skipping 28 matching lines...) Expand all
54 #include "ui/aura/env.h" 55 #include "ui/aura/env.h"
55 #include "ui/aura/window.h" 56 #include "ui/aura/window.h"
56 #include "ui/aura/window_event_dispatcher.h" 57 #include "ui/aura/window_event_dispatcher.h"
57 #include "ui/aura/window_observer.h" 58 #include "ui/aura/window_observer.h"
58 #include "ui/aura/window_tracker.h" 59 #include "ui/aura/window_tracker.h"
59 #include "ui/aura/window_tree_host.h" 60 #include "ui/aura/window_tree_host.h"
60 #include "ui/base/clipboard/scoped_clipboard_writer.h" 61 #include "ui/base/clipboard/scoped_clipboard_writer.h"
61 #include "ui/base/hit_test.h" 62 #include "ui/base/hit_test.h"
62 #include "ui/base/ime/input_method.h" 63 #include "ui/base/ime/input_method.h"
63 #include "ui/base/ui_base_types.h" 64 #include "ui/base/ui_base_types.h"
64 #include "ui/compositor/compositor_vsync_manager.h"
65 #include "ui/compositor/dip_util.h" 65 #include "ui/compositor/dip_util.h"
66 #include "ui/events/event.h" 66 #include "ui/events/event.h"
67 #include "ui/events/event_utils.h" 67 #include "ui/events/event_utils.h"
68 #include "ui/events/gestures/gesture_recognizer.h" 68 #include "ui/events/gestures/gesture_recognizer.h"
69 #include "ui/gfx/canvas.h" 69 #include "ui/gfx/canvas.h"
70 #include "ui/gfx/display.h" 70 #include "ui/gfx/display.h"
71 #include "ui/gfx/rect_conversions.h" 71 #include "ui/gfx/rect_conversions.h"
72 #include "ui/gfx/screen.h" 72 #include "ui/gfx/screen.h"
73 #include "ui/gfx/size_conversions.h" 73 #include "ui/gfx/size_conversions.h"
74 #include "ui/gfx/skia_util.h" 74 #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), 445 last_swapped_software_frame_scale_factor_(1.f),
446 paint_canvas_(NULL), 446 paint_canvas_(NULL),
447 synthetic_move_sent_(false), 447 synthetic_move_sent_(false),
448 cursor_visibility_state_in_renderer_(UNKNOWN), 448 cursor_visibility_state_in_renderer_(UNKNOWN),
449 #if defined(OS_WIN) 449 #if defined(OS_WIN)
450 legacy_render_widget_host_HWND_(NULL), 450 legacy_render_widget_host_HWND_(NULL),
451 legacy_window_destroyed_(false), 451 legacy_window_destroyed_(false),
452 #endif 452 #endif
453 has_snapped_to_boundary_(false), 453 has_snapped_to_boundary_(false),
454 touch_editing_client_(NULL), 454 touch_editing_client_(NULL),
455 needs_begin_frame_(false),
455 weak_ptr_factory_(this) { 456 weak_ptr_factory_(this) {
456 host_->SetView(this); 457 host_->SetView(this);
457 window_observer_.reset(new WindowObserver(this)); 458 window_observer_.reset(new WindowObserver(this));
458 aura::client::SetTooltipText(window_, &tooltip_); 459 aura::client::SetTooltipText(window_, &tooltip_);
459 aura::client::SetActivationDelegate(window_, this); 460 aura::client::SetActivationDelegate(window_, this);
460 aura::client::SetActivationChangeObserver(window_, this); 461 aura::client::SetActivationChangeObserver(window_, this);
461 aura::client::SetFocusChangeObserver(window_, this); 462 aura::client::SetFocusChangeObserver(window_, this);
462 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 463 window_->set_layer_owner_delegate(delegated_frame_host_.get());
463 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 464 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
464 465
465 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> 466 bool overscroll_enabled = CommandLine::ForCurrentProcess()->
466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 467 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
467 SetOverscrollControllerEnabled(overscroll_enabled); 468 SetOverscrollControllerEnabled(overscroll_enabled);
468 } 469 }
469 470
470 //////////////////////////////////////////////////////////////////////////////// 471 ////////////////////////////////////////////////////////////////////////////////
471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: 472 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
472 473
474 bool RenderWidgetHostViewAura::OnMessageReceived(const IPC::Message& msg) {
475 bool handled = true;
476 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, msg)
477 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrame, OnSetNeedsBeginFrame)
478 IPC_MESSAGE_UNHANDLED(handled = false)
479 IPC_END_MESSAGE_MAP()
480 return handled;
481 }
482
473 void RenderWidgetHostViewAura::InitAsChild( 483 void RenderWidgetHostViewAura::InitAsChild(
474 gfx::NativeView parent_view) { 484 gfx::NativeView parent_view) {
475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 485 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
476 window_->Init(aura::WINDOW_LAYER_TEXTURED); 486 window_->Init(aura::WINDOW_LAYER_TEXTURED);
477 window_->SetName("RenderWidgetHostViewAura"); 487 window_->SetName("RenderWidgetHostViewAura");
478 } 488 }
479 489
480 void RenderWidgetHostViewAura::InitAsPopup( 490 void RenderWidgetHostViewAura::InitAsPopup(
481 RenderWidgetHostView* parent_host_view, 491 RenderWidgetHostView* parent_host_view,
482 const gfx::Rect& bounds_in_screen) { 492 const gfx::Rect& bounds_in_screen) {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, 863 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status,
854 int error_code) { 864 int error_code) {
855 UpdateCursorIfOverSelf(); 865 UpdateCursorIfOverSelf();
856 Destroy(); 866 Destroy();
857 } 867 }
858 868
859 void RenderWidgetHostViewAura::Destroy() { 869 void RenderWidgetHostViewAura::Destroy() {
860 // Beware, this function is not called on all destruction paths. It will 870 // Beware, this function is not called on all destruction paths. It will
861 // implicitly end up calling ~RenderWidgetHostViewAura though, so all 871 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
862 // destruction/cleanup code should happen there, not here. 872 // destruction/cleanup code should happen there, not here.
873
874 // Remove observation from BeginFrameManager in here because we can't access
875 // to compositor in destructor.
876 if (needs_begin_frame_ && GetCompositor()) {
877 GetCompositor()->begin_frame_manager()->RemoveObserver(this);
878 needs_begin_frame_ = false;
879 }
880
863 in_shutdown_ = true; 881 in_shutdown_ = true;
864 delete window_; 882 delete window_;
865 } 883 }
866 884
867 void RenderWidgetHostViewAura::SetTooltipText( 885 void RenderWidgetHostViewAura::SetTooltipText(
868 const base::string16& tooltip_text) { 886 const base::string16& tooltip_text) {
869 tooltip_ = tooltip_text; 887 tooltip_ = tooltip_text;
870 aura::Window* root_window = window_->GetRootWindow(); 888 aura::Window* root_window = window_->GetRootWindow();
871 aura::client::TooltipClient* tooltip_client = 889 aura::client::TooltipClient* tooltip_client =
872 aura::client::GetTooltipClient(root_window); 890 aura::client::GetTooltipClient(root_window);
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 2130
2113 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, 2131 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host,
2114 const gfx::Point& new_origin) { 2132 const gfx::Point& new_origin) {
2115 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", 2133 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2116 "new_origin", new_origin.ToString()); 2134 "new_origin", new_origin.ToString());
2117 2135
2118 UpdateScreenInfo(window_); 2136 UpdateScreenInfo(window_);
2119 } 2137 }
2120 2138
2121 //////////////////////////////////////////////////////////////////////////////// 2139 ////////////////////////////////////////////////////////////////////////////////
2140 // ui::BeginFrameManager::Observer implementation:
2141 void RenderWidgetHostViewAura::OnSendBeginFrame(
2142 const cc::BeginFrameArgs& args) {
2143 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame");
2144 if (!host_)
2145 return;
2146
2147 cc::BeginFrameArgs adjusted_args(args);
2148
2149 delegated_frame_host_->UpdateVSyncParameters(adjusted_args);
2150
2151 // TODO(brianderson): Use adaptive draw-time estimation.
2152 base::TimeDelta estimated_browser_composite_time =
2153 base::TimeDelta::FromMicroseconds(
2154 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60));
2155
2156 adjusted_args.deadline -= estimated_browser_composite_time;
2157
2158 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), adjusted_args));
2159
2160 last_begin_frame_args_ = args;
2161 }
2162
2163 ////////////////////////////////////////////////////////////////////////////////
2122 // RenderWidgetHostViewAura, private: 2164 // RenderWidgetHostViewAura, private:
2123 2165
2124 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { 2166 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2167 // When we are using unified BeginFrame(--enable-begin-frame-scheduling),
2168 // |needs_begin_frame_| always be false in here. We can't remove
2169 // observation from BeginFrameManager via compositor in this function
2170 // because |window_| is already removed from window tree host.
2171 DCHECK(!needs_begin_frame_);
2172
2125 if (touch_editing_client_) 2173 if (touch_editing_client_)
2126 touch_editing_client_->OnViewDestroyed(); 2174 touch_editing_client_->OnViewDestroyed();
2127 2175
2128 delegated_frame_host_.reset(); 2176 delegated_frame_host_.reset();
2129 window_observer_.reset(); 2177 window_observer_.reset();
2130 if (window_->GetHost()) 2178 if (window_->GetHost())
2131 window_->GetHost()->RemoveObserver(this); 2179 window_->GetHost()->RemoveObserver(this);
2132 UnlockMouse(); 2180 UnlockMouse();
2133 if (popup_parent_host_view_) { 2181 if (popup_parent_host_view_) {
2134 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || 2182 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL ||
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 2420
2373 #if defined(OS_WIN) 2421 #if defined(OS_WIN)
2374 // The parent may have changed here. Ensure that the legacy window is 2422 // The parent may have changed here. Ensure that the legacy window is
2375 // reparented accordingly. 2423 // reparented accordingly.
2376 if (legacy_render_widget_host_HWND_) 2424 if (legacy_render_widget_host_HWND_)
2377 legacy_render_widget_host_HWND_->UpdateParent( 2425 legacy_render_widget_host_HWND_->UpdateParent(
2378 reinterpret_cast<HWND>(GetNativeViewId())); 2426 reinterpret_cast<HWND>(GetNativeViewId()));
2379 #endif 2427 #endif
2380 2428
2381 delegated_frame_host_->AddedToWindow(); 2429 delegated_frame_host_->AddedToWindow();
2430
2431 // When this RWHV is added to new root window after tab dragging, this RWHV
2432 // should be added to the BeginFrameManager of new compositor.
2433 if (needs_begin_frame_) {
2434 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
2435 cc::switches::kEnableBeginFrameScheduling));
2436 GetCompositor()->begin_frame_manager()->AddObserver(this,
2437 last_begin_frame_args_);
2438 }
2382 } 2439 }
2383 2440
2384 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 2441 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2385 aura::client::CursorClient* cursor_client = 2442 aura::client::CursorClient* cursor_client =
2386 aura::client::GetCursorClient(window_->GetRootWindow()); 2443 aura::client::GetCursorClient(window_->GetRootWindow());
2387 if (cursor_client) 2444 if (cursor_client)
2388 cursor_client->RemoveObserver(this); 2445 cursor_client->RemoveObserver(this);
2389 2446
2390 DetachFromInputMethod(); 2447 DetachFromInputMethod();
2391 2448
2392 window_->GetHost()->RemoveObserver(this); 2449 window_->GetHost()->RemoveObserver(this);
2393 delegated_frame_host_->RemovingFromWindow(); 2450 delegated_frame_host_->RemovingFromWindow();
2394 2451
2395 #if defined(OS_WIN) 2452 #if defined(OS_WIN)
2396 // Update the legacy window's parent temporarily to the desktop window. It 2453 // Update the legacy window's parent temporarily to the desktop window. It
2397 // will eventually get reparented to the right root. 2454 // will eventually get reparented to the right root.
2398 if (legacy_render_widget_host_HWND_) 2455 if (legacy_render_widget_host_HWND_)
2399 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); 2456 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow());
2400 #endif 2457 #endif
2458
2459 // When this RWHV is activated during the tab dragging, this RWHV should be
2460 // removed from BeginFrameManager of current compositor which will be removed.
2461 if (needs_begin_frame_) {
2462 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
2463 cc::switches::kEnableBeginFrameScheduling));
2464 GetCompositor()->begin_frame_manager()->RemoveObserver(this);
2465 }
2401 } 2466 }
2402 2467
2403 void RenderWidgetHostViewAura::DetachFromInputMethod() { 2468 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2404 ui::InputMethod* input_method = GetInputMethod(); 2469 ui::InputMethod* input_method = GetInputMethod();
2405 if (input_method && input_method->GetTextInputClient() == this) 2470 if (input_method && input_method->GetTextInputClient() == this)
2406 input_method->SetFocusedTextInputClient(NULL); 2471 input_method->SetFocusedTextInputClient(NULL);
2407 } 2472 }
2408 2473
2409 void RenderWidgetHostViewAura::ForwardKeyboardEvent( 2474 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2410 const NativeWebKeyboardEvent& event) { 2475 const NativeWebKeyboardEvent& event) {
(...skipping 21 matching lines...) Expand all
2432 } 2497 }
2433 #endif 2498 #endif
2434 2499
2435 host_->ForwardKeyboardEvent(event); 2500 host_->ForwardKeyboardEvent(event);
2436 } 2501 }
2437 2502
2438 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { 2503 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() {
2439 return kN32_SkColorType; 2504 return kN32_SkColorType;
2440 } 2505 }
2441 2506
2507 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) {
2508 if (needs_begin_frame_ == enabled)
2509 return;
2510
2511 TRACE_EVENT1("cc", "RenderWidgetHostViewAura::OnSetNeedsBeginFrame",
2512 "enabled", enabled);
2513 if(enabled) {
2514 GetCompositor()->begin_frame_manager()->AddObserver(this,
2515 last_begin_frame_args_);
2516 } else {
2517 GetCompositor()->begin_frame_manager()->RemoveObserver(this);
2518 }
2519
2520 needs_begin_frame_ = enabled;
2521 }
2522
2442 //////////////////////////////////////////////////////////////////////////////// 2523 ////////////////////////////////////////////////////////////////////////////////
2443 // DelegatedFrameHost, public: 2524 // DelegatedFrameHost, public:
2444 2525
2445 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { 2526 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const {
2446 aura::WindowTreeHost* host = window_->GetHost(); 2527 aura::WindowTreeHost* host = window_->GetHost();
2447 return host ? host->compositor() : NULL; 2528 return host ? host->compositor() : NULL;
2448 } 2529 }
2449 2530
2450 ui::Layer* RenderWidgetHostViewAura::GetLayer() { 2531 ui::Layer* RenderWidgetHostViewAura::GetLayer() {
2451 return window_->layer(); 2532 return window_->layer();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 2574
2494 //////////////////////////////////////////////////////////////////////////////// 2575 ////////////////////////////////////////////////////////////////////////////////
2495 // RenderWidgetHostViewBase, public: 2576 // RenderWidgetHostViewBase, public:
2496 2577
2497 // static 2578 // static
2498 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2579 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2499 GetScreenInfoForWindow(results, NULL); 2580 GetScreenInfoForWindow(results, NULL);
2500 } 2581 }
2501 2582
2502 } // namespace content 2583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698