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_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 Loading... | |
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 Loading... | |
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), | |
456 begin_frame_scheduling_is_enabled_(false), | |
455 weak_ptr_factory_(this) { | 457 weak_ptr_factory_(this) { |
456 host_->SetView(this); | 458 host_->SetView(this); |
457 window_observer_.reset(new WindowObserver(this)); | 459 window_observer_.reset(new WindowObserver(this)); |
458 aura::client::SetTooltipText(window_, &tooltip_); | 460 aura::client::SetTooltipText(window_, &tooltip_); |
459 aura::client::SetActivationDelegate(window_, this); | 461 aura::client::SetActivationDelegate(window_, this); |
460 aura::client::SetActivationChangeObserver(window_, this); | 462 aura::client::SetActivationChangeObserver(window_, this); |
461 aura::client::SetFocusChangeObserver(window_, this); | 463 aura::client::SetFocusChangeObserver(window_, this); |
462 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 464 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
463 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 465 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
464 | 466 |
465 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> | 467 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 468 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
467 SetOverscrollControllerEnabled(overscroll_enabled); | 469 SetOverscrollControllerEnabled(overscroll_enabled); |
470 | |
471 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
472 cc::switches::kEnableBeginFrameScheduling)) | |
473 begin_frame_scheduling_is_enabled_ = true; | |
468 } | 474 } |
469 | 475 |
470 //////////////////////////////////////////////////////////////////////////////// | 476 //////////////////////////////////////////////////////////////////////////////// |
471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 477 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
472 | 478 |
479 bool RenderWidgetHostViewAura::OnMessageReceived(const IPC::Message& msg) { | |
480 bool handled = true; | |
481 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, msg) | |
482 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrame, OnSetNeedsBeginFrame) | |
483 IPC_MESSAGE_UNHANDLED(handled = false) | |
484 IPC_END_MESSAGE_MAP() | |
485 return handled; | |
486 } | |
487 | |
473 void RenderWidgetHostViewAura::InitAsChild( | 488 void RenderWidgetHostViewAura::InitAsChild( |
474 gfx::NativeView parent_view) { | 489 gfx::NativeView parent_view) { |
475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 490 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
476 window_->Init(aura::WINDOW_LAYER_TEXTURED); | 491 window_->Init(aura::WINDOW_LAYER_TEXTURED); |
477 window_->SetName("RenderWidgetHostViewAura"); | 492 window_->SetName("RenderWidgetHostViewAura"); |
478 } | 493 } |
479 | 494 |
480 void RenderWidgetHostViewAura::InitAsPopup( | 495 void RenderWidgetHostViewAura::InitAsPopup( |
481 RenderWidgetHostView* parent_host_view, | 496 RenderWidgetHostView* parent_host_view, |
482 const gfx::Rect& bounds_in_screen) { | 497 const gfx::Rect& bounds_in_screen) { |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, | 868 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, |
854 int error_code) { | 869 int error_code) { |
855 UpdateCursorIfOverSelf(); | 870 UpdateCursorIfOverSelf(); |
856 Destroy(); | 871 Destroy(); |
857 } | 872 } |
858 | 873 |
859 void RenderWidgetHostViewAura::Destroy() { | 874 void RenderWidgetHostViewAura::Destroy() { |
860 // Beware, this function is not called on all destruction paths. It will | 875 // Beware, this function is not called on all destruction paths. It will |
861 // implicitly end up calling ~RenderWidgetHostViewAura though, so all | 876 // implicitly end up calling ~RenderWidgetHostViewAura though, so all |
862 // destruction/cleanup code should happen there, not here. | 877 // destruction/cleanup code should happen there, not here. |
878 | |
879 // Remove observation from BeginFrameManager in here because we can't access | |
880 // to compositor in destructor. | |
881 if (needs_begin_frame_ && GetCompositor()) { | |
882 GetCompositor()->begin_frame_manager()->RemoveObserver(this); | |
883 needs_begin_frame_ = false; | |
884 } | |
885 | |
863 in_shutdown_ = true; | 886 in_shutdown_ = true; |
864 delete window_; | 887 delete window_; |
865 } | 888 } |
866 | 889 |
867 void RenderWidgetHostViewAura::SetTooltipText( | 890 void RenderWidgetHostViewAura::SetTooltipText( |
868 const base::string16& tooltip_text) { | 891 const base::string16& tooltip_text) { |
869 tooltip_ = tooltip_text; | 892 tooltip_ = tooltip_text; |
870 aura::Window* root_window = window_->GetRootWindow(); | 893 aura::Window* root_window = window_->GetRootWindow(); |
871 aura::client::TooltipClient* tooltip_client = | 894 aura::client::TooltipClient* tooltip_client = |
872 aura::client::GetTooltipClient(root_window); | 895 aura::client::GetTooltipClient(root_window); |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2112 | 2135 |
2113 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, | 2136 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, |
2114 const gfx::Point& new_origin) { | 2137 const gfx::Point& new_origin) { |
2115 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", | 2138 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", |
2116 "new_origin", new_origin.ToString()); | 2139 "new_origin", new_origin.ToString()); |
2117 | 2140 |
2118 UpdateScreenInfo(window_); | 2141 UpdateScreenInfo(window_); |
2119 } | 2142 } |
2120 | 2143 |
2121 //////////////////////////////////////////////////////////////////////////////// | 2144 //////////////////////////////////////////////////////////////////////////////// |
2145 // ui::BeginFrameManager::Observer implementation: | |
2146 void RenderWidgetHostViewAura::OnSendBeginFrame( | |
2147 const cc::BeginFrameArgs& args) { | |
2148 DCHECK(begin_frame_scheduling_is_enabled_); | |
2149 DCHECK(host_); | |
2150 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame"); | |
2151 | |
2152 cc::BeginFrameArgs adjusted_args(args); | |
2153 | |
2154 delegated_frame_host_->UpdateVSyncParameters(adjusted_args); | |
2155 | |
2156 // TODO(brianderson): Use adaptive draw-time estimation. | |
2157 base::TimeDelta estimated_browser_composite_time = | |
brianderson
2014/08/28 02:48:07
We should be able to remove this adjustment here a
simonhong
2014/09/03 21:02:23
Yep, did it in the scheduler.
| |
2158 base::TimeDelta::FromMicroseconds( | |
2159 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | |
2160 | |
2161 adjusted_args.deadline -= estimated_browser_composite_time; | |
2162 | |
2163 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), adjusted_args)); | |
2164 | |
2165 last_begin_frame_args_ = args; | |
2166 } | |
2167 | |
2168 //////////////////////////////////////////////////////////////////////////////// | |
2122 // RenderWidgetHostViewAura, private: | 2169 // RenderWidgetHostViewAura, private: |
2123 | 2170 |
2124 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2171 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
2172 // When we are using unified BeginFrame(--enable-begin-frame-scheduling), | |
2173 // |needs_begin_frame_| always be false in here. We can't remove | |
2174 // observation from BeginFrameManager via compositor in this function | |
2175 // because |window_| is already removed from window tree host. | |
2176 DCHECK(!needs_begin_frame_); | |
2177 | |
2125 if (touch_editing_client_) | 2178 if (touch_editing_client_) |
2126 touch_editing_client_->OnViewDestroyed(); | 2179 touch_editing_client_->OnViewDestroyed(); |
2127 | 2180 |
2128 delegated_frame_host_.reset(); | 2181 delegated_frame_host_.reset(); |
2129 window_observer_.reset(); | 2182 window_observer_.reset(); |
2130 if (window_->GetHost()) | 2183 if (window_->GetHost()) |
2131 window_->GetHost()->RemoveObserver(this); | 2184 window_->GetHost()->RemoveObserver(this); |
2132 UnlockMouse(); | 2185 UnlockMouse(); |
2133 if (popup_parent_host_view_) { | 2186 if (popup_parent_host_view_) { |
2134 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 2187 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2372 | 2425 |
2373 #if defined(OS_WIN) | 2426 #if defined(OS_WIN) |
2374 // The parent may have changed here. Ensure that the legacy window is | 2427 // The parent may have changed here. Ensure that the legacy window is |
2375 // reparented accordingly. | 2428 // reparented accordingly. |
2376 if (legacy_render_widget_host_HWND_) | 2429 if (legacy_render_widget_host_HWND_) |
2377 legacy_render_widget_host_HWND_->UpdateParent( | 2430 legacy_render_widget_host_HWND_->UpdateParent( |
2378 reinterpret_cast<HWND>(GetNativeViewId())); | 2431 reinterpret_cast<HWND>(GetNativeViewId())); |
2379 #endif | 2432 #endif |
2380 | 2433 |
2381 delegated_frame_host_->AddedToWindow(); | 2434 delegated_frame_host_->AddedToWindow(); |
2435 | |
2436 // When this RWHV is added to new root window, this RWHV should be added to | |
2437 // the BeginFrameManager of new compositor. | |
2438 if (needs_begin_frame_) { | |
2439 DCHECK(begin_frame_scheduling_is_enabled_); | |
2440 GetCompositor()->begin_frame_manager()->AddObserver(this, | |
2441 last_begin_frame_args_); | |
2442 } | |
2382 } | 2443 } |
2383 | 2444 |
2384 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 2445 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
2385 aura::client::CursorClient* cursor_client = | 2446 aura::client::CursorClient* cursor_client = |
2386 aura::client::GetCursorClient(window_->GetRootWindow()); | 2447 aura::client::GetCursorClient(window_->GetRootWindow()); |
2387 if (cursor_client) | 2448 if (cursor_client) |
2388 cursor_client->RemoveObserver(this); | 2449 cursor_client->RemoveObserver(this); |
2389 | 2450 |
2390 DetachFromInputMethod(); | 2451 DetachFromInputMethod(); |
2391 | 2452 |
2392 window_->GetHost()->RemoveObserver(this); | 2453 window_->GetHost()->RemoveObserver(this); |
2393 delegated_frame_host_->RemovingFromWindow(); | 2454 delegated_frame_host_->RemovingFromWindow(); |
2394 | 2455 |
2395 #if defined(OS_WIN) | 2456 #if defined(OS_WIN) |
2396 // Update the legacy window's parent temporarily to the desktop window. It | 2457 // Update the legacy window's parent temporarily to the desktop window. It |
2397 // will eventually get reparented to the right root. | 2458 // will eventually get reparented to the right root. |
2398 if (legacy_render_widget_host_HWND_) | 2459 if (legacy_render_widget_host_HWND_) |
2399 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); | 2460 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); |
2400 #endif | 2461 #endif |
2462 | |
2463 // When this RWHV is removed from current root window, this RWHV should be | |
2464 // removed from BeginFrameManager of current compositor which will be removed. | |
2465 if (needs_begin_frame_) { | |
2466 DCHECK(begin_frame_scheduling_is_enabled_); | |
2467 GetCompositor()->begin_frame_manager()->RemoveObserver(this); | |
2468 } | |
2401 } | 2469 } |
2402 | 2470 |
2403 void RenderWidgetHostViewAura::DetachFromInputMethod() { | 2471 void RenderWidgetHostViewAura::DetachFromInputMethod() { |
2404 ui::InputMethod* input_method = GetInputMethod(); | 2472 ui::InputMethod* input_method = GetInputMethod(); |
2405 if (input_method && input_method->GetTextInputClient() == this) | 2473 if (input_method && input_method->GetTextInputClient() == this) |
2406 input_method->SetFocusedTextInputClient(NULL); | 2474 input_method->SetFocusedTextInputClient(NULL); |
2407 } | 2475 } |
2408 | 2476 |
2409 void RenderWidgetHostViewAura::ForwardKeyboardEvent( | 2477 void RenderWidgetHostViewAura::ForwardKeyboardEvent( |
2410 const NativeWebKeyboardEvent& event) { | 2478 const NativeWebKeyboardEvent& event) { |
(...skipping 21 matching lines...) Expand all Loading... | |
2432 } | 2500 } |
2433 #endif | 2501 #endif |
2434 | 2502 |
2435 host_->ForwardKeyboardEvent(event); | 2503 host_->ForwardKeyboardEvent(event); |
2436 } | 2504 } |
2437 | 2505 |
2438 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { | 2506 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { |
2439 return kN32_SkColorType; | 2507 return kN32_SkColorType; |
2440 } | 2508 } |
2441 | 2509 |
2510 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) { | |
2511 DCHECK(begin_frame_scheduling_is_enabled_); | |
2512 | |
2513 if (needs_begin_frame_ == enabled) | |
2514 return; | |
2515 | |
2516 TRACE_EVENT1("cc", "RenderWidgetHostViewAura::OnSetNeedsBeginFrame", | |
2517 "enabled", enabled); | |
2518 if(enabled) { | |
2519 GetCompositor()->begin_frame_manager()->AddObserver(this, | |
2520 last_begin_frame_args_); | |
2521 } else { | |
2522 GetCompositor()->begin_frame_manager()->RemoveObserver(this); | |
2523 } | |
2524 | |
2525 needs_begin_frame_ = enabled; | |
2526 } | |
2527 | |
2442 //////////////////////////////////////////////////////////////////////////////// | 2528 //////////////////////////////////////////////////////////////////////////////// |
2443 // DelegatedFrameHost, public: | 2529 // DelegatedFrameHost, public: |
2444 | 2530 |
2445 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { | 2531 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { |
2446 aura::WindowTreeHost* host = window_->GetHost(); | 2532 aura::WindowTreeHost* host = window_->GetHost(); |
2447 return host ? host->compositor() : NULL; | 2533 return host ? host->compositor() : NULL; |
2448 } | 2534 } |
2449 | 2535 |
2450 ui::Layer* RenderWidgetHostViewAura::GetLayer() { | 2536 ui::Layer* RenderWidgetHostViewAura::GetLayer() { |
2451 return window_->layer(); | 2537 return window_->layer(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2493 | 2579 |
2494 //////////////////////////////////////////////////////////////////////////////// | 2580 //////////////////////////////////////////////////////////////////////////////// |
2495 // RenderWidgetHostViewBase, public: | 2581 // RenderWidgetHostViewBase, public: |
2496 | 2582 |
2497 // static | 2583 // static |
2498 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2584 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2499 GetScreenInfoForWindow(results, NULL); | 2585 GetScreenInfoForWindow(results, NULL); |
2500 } | 2586 } |
2501 | 2587 |
2502 } // namespace content | 2588 } // namespace content |
OLD | NEW |