Chromium Code Reviews| 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 "ui/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 typedef std::vector<EventFilter*> EventFilters; | 46 typedef std::vector<EventFilter*> EventFilters; |
| 47 | 47 |
| 48 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 48 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
| 49 while (target) { | 49 while (target) { |
| 50 if (target->event_filter()) | 50 if (target->event_filter()) |
| 51 filters->push_back(target->event_filter()); | 51 filters->push_back(target->event_filter()); |
| 52 target = target->parent(); | 52 target = target->parent(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 const int kCompositorLockTimeoutMs = 67; | |
| 57 | |
| 56 } // namespace | 58 } // namespace |
| 57 | 59 |
| 60 CompositorLock::CompositorLock(RootWindow* root_window) | |
| 61 : root_window_(root_window) { | |
| 62 MessageLoop::current()->PostDelayedTask( | |
| 63 FROM_HERE, | |
| 64 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), | |
| 65 kCompositorLockTimeoutMs); | |
| 66 } | |
| 67 | |
| 68 CompositorLock::~CompositorLock() { | |
| 69 CancelLock(); | |
| 70 } | |
| 71 | |
| 72 void CompositorLock::CancelLock() { | |
| 73 if (!root_window_) | |
| 74 return; | |
| 75 root_window_->UnlockCompositor(); | |
|
jonathan.backer
2012/03/23 15:48:00
I think that you want to "root_window_ = NULL" her
piman
2012/03/23 17:41:09
Thanks for paying attention! You're absolutely rig
| |
| 76 } | |
| 77 | |
| 58 bool RootWindow::hide_host_cursor_ = false; | 78 bool RootWindow::hide_host_cursor_ = false; |
| 59 | 79 |
| 60 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 61 // RootWindow, public: | 81 // RootWindow, public: |
| 62 | 82 |
| 63 RootWindow::RootWindow(const gfx::Rect& initial_bounds) | 83 RootWindow::RootWindow(const gfx::Rect& initial_bounds) |
| 64 : Window(NULL), | 84 : Window(NULL), |
| 65 host_(aura::RootWindowHost::Create(initial_bounds)), | 85 host_(aura::RootWindowHost::Create(initial_bounds)), |
| 66 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 86 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 67 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 87 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
| 68 mouse_button_flags_(0), | 88 mouse_button_flags_(0), |
| 69 last_cursor_(kCursorNull), | 89 last_cursor_(kCursorNull), |
| 70 cursor_shown_(true), | 90 cursor_shown_(true), |
| 71 capture_window_(NULL), | 91 capture_window_(NULL), |
| 72 mouse_pressed_handler_(NULL), | 92 mouse_pressed_handler_(NULL), |
| 73 mouse_moved_handler_(NULL), | 93 mouse_moved_handler_(NULL), |
| 74 focused_window_(NULL), | 94 focused_window_(NULL), |
| 75 ALLOW_THIS_IN_INITIALIZER_LIST( | 95 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 76 gesture_recognizer_(GestureRecognizer::Create())), | 96 gesture_recognizer_(GestureRecognizer::Create())), |
| 77 synthesize_mouse_move_(false), | 97 synthesize_mouse_move_(false), |
| 78 waiting_on_compositing_end_(false), | 98 waiting_on_compositing_end_(false), |
| 79 draw_on_compositing_end_(false), | 99 draw_on_compositing_end_(false), |
| 80 defer_draw_scheduling_(false), | 100 defer_draw_scheduling_(false), |
| 81 mouse_move_hold_count_(0), | 101 mouse_move_hold_count_(0), |
| 82 should_hold_mouse_moves_(false) { | 102 should_hold_mouse_moves_(false), |
| 103 compositor_lock_(NULL), | |
| 104 scheduled_while_locked_(false) { | |
| 83 SetName("RootWindow"); | 105 SetName("RootWindow"); |
| 84 last_mouse_location_ = host_->QueryMouseLocation(); | 106 last_mouse_location_ = host_->QueryMouseLocation(); |
| 85 | 107 |
| 86 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( | 108 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 switches::kAuraDisableHoldMouseMoves); | 109 switches::kAuraDisableHoldMouseMoves); |
| 88 | 110 |
| 89 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), | 111 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), |
| 90 host_->GetBounds().size())); | 112 host_->GetBounds().size())); |
| 91 DCHECK(compositor_.get()); | 113 DCHECK(compositor_.get()); |
| 92 compositor_->AddObserver(this); | 114 compositor_->AddObserver(this); |
| 93 Init(); | 115 Init(); |
| 94 } | 116 } |
| 95 | 117 |
| 96 RootWindow::~RootWindow() { | 118 RootWindow::~RootWindow() { |
| 119 if (compositor_lock_) { | |
| 120 // No need to schedule a draw, we're going away. | |
| 121 scheduled_while_locked_ = false; | |
| 122 compositor_lock_->CancelLock(); | |
| 123 DCHECK(!compositor_lock_); | |
| 124 } | |
| 97 compositor_->RemoveObserver(this); | 125 compositor_->RemoveObserver(this); |
| 98 // Make sure to destroy the compositor before terminating so that state is | 126 // Make sure to destroy the compositor before terminating so that state is |
| 99 // cleared and we don't hit asserts. | 127 // cleared and we don't hit asserts. |
| 100 compositor_.reset(); | 128 compositor_.reset(); |
| 101 | 129 |
| 102 // Tear down in reverse. Frees any references held by the host. | 130 // Tear down in reverse. Frees any references held by the host. |
| 103 host_.reset(NULL); | 131 host_.reset(NULL); |
| 104 | 132 |
| 105 // An observer may have been added by an animation on the RootWindow. | 133 // An observer may have been added by an animation on the RootWindow. |
| 106 layer()->GetAnimator()->RemoveObserver(this); | 134 layer()->GetAnimator()->RemoveObserver(this); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // being used in fullscreen mode, so root_window bounds = window bounds. | 183 // being used in fullscreen mode, so root_window bounds = window bounds. |
| 156 return host_->ConfineCursorToRootWindow(); | 184 return host_->ConfineCursorToRootWindow(); |
| 157 } | 185 } |
| 158 | 186 |
| 159 void RootWindow::Draw() { | 187 void RootWindow::Draw() { |
| 160 if (waiting_on_compositing_end_) { | 188 if (waiting_on_compositing_end_) { |
| 161 draw_on_compositing_end_ = true; | 189 draw_on_compositing_end_ = true; |
| 162 defer_draw_scheduling_ = false; | 190 defer_draw_scheduling_ = false; |
| 163 return; | 191 return; |
| 164 } | 192 } |
| 193 if (compositor_lock_) { | |
| 194 scheduled_while_locked_ = true; | |
|
jonathan.backer
2012/03/23 15:48:00
nit: is it conceivable that the draw task had been
piman
2012/03/23 17:41:09
Yes (imagine a caller doing ScheduleDraw() then Ge
| |
| 195 defer_draw_scheduling_ = false; | |
| 196 return; | |
| 197 } | |
| 165 waiting_on_compositing_end_ = true; | 198 waiting_on_compositing_end_ = true; |
| 166 | 199 |
| 167 compositor_->Draw(false); | 200 compositor_->Draw(false); |
| 168 defer_draw_scheduling_ = false; | 201 defer_draw_scheduling_ = false; |
| 169 } | 202 } |
| 170 | 203 |
| 171 void RootWindow::ScheduleFullDraw() { | 204 void RootWindow::ScheduleFullDraw() { |
| 172 compositor_->ScheduleFullDraw(); | 205 compositor_->ScheduleFullDraw(); |
| 173 } | 206 } |
| 174 | 207 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 | 420 |
| 388 void RootWindow::ReleaseMouseMoves() { | 421 void RootWindow::ReleaseMouseMoves() { |
| 389 if (should_hold_mouse_moves_) { | 422 if (should_hold_mouse_moves_) { |
| 390 --mouse_move_hold_count_; | 423 --mouse_move_hold_count_; |
| 391 DCHECK_GE(mouse_move_hold_count_, 0); | 424 DCHECK_GE(mouse_move_hold_count_, 0); |
| 392 if (!mouse_move_hold_count_) | 425 if (!mouse_move_hold_count_) |
| 393 DispatchHeldMouseMove(); | 426 DispatchHeldMouseMove(); |
| 394 } | 427 } |
| 395 } | 428 } |
| 396 | 429 |
| 430 scoped_refptr<CompositorLock> RootWindow::GetCompositorLock() { | |
| 431 if (!compositor_lock_) | |
| 432 compositor_lock_ = new CompositorLock(this); | |
| 433 return compositor_lock_; | |
| 434 } | |
| 435 | |
| 397 //////////////////////////////////////////////////////////////////////////////// | 436 //////////////////////////////////////////////////////////////////////////////// |
| 398 // RootWindow, Window overrides: | 437 // RootWindow, Window overrides: |
| 399 | 438 |
| 400 RootWindow* RootWindow::GetRootWindow() { | 439 RootWindow* RootWindow::GetRootWindow() { |
| 401 return this; | 440 return this; |
| 402 } | 441 } |
| 403 | 442 |
| 404 const RootWindow* RootWindow::GetRootWindow() const { | 443 const RootWindow* RootWindow::GetRootWindow() const { |
| 405 return this; | 444 return this; |
| 406 } | 445 } |
| 407 | 446 |
| 408 void RootWindow::SetTransform(const ui::Transform& transform) { | 447 void RootWindow::SetTransform(const ui::Transform& transform) { |
| 409 Window::SetTransform(transform); | 448 Window::SetTransform(transform); |
| 410 | 449 |
| 411 // If the layer is not animating, then we need to update the host size | 450 // If the layer is not animating, then we need to update the host size |
| 412 // immediately. | 451 // immediately. |
| 413 if (!layer()->GetAnimator()->is_animating()) | 452 if (!layer()->GetAnimator()->is_animating()) |
| 414 OnHostResized(host_->GetBounds().size()); | 453 OnHostResized(host_->GetBounds().size()); |
| 415 } | 454 } |
| 416 | 455 |
| 417 //////////////////////////////////////////////////////////////////////////////// | 456 //////////////////////////////////////////////////////////////////////////////// |
| 418 // RootWindow, ui::CompositorDelegate implementation: | 457 // RootWindow, ui::CompositorDelegate implementation: |
| 419 | 458 |
| 420 void RootWindow::ScheduleDraw() { | 459 void RootWindow::ScheduleDraw() { |
| 421 if (!defer_draw_scheduling_) { | 460 if (compositor_lock_) { |
| 461 scheduled_while_locked_ = true; | |
| 462 } else if (!defer_draw_scheduling_) { | |
| 422 defer_draw_scheduling_ = true; | 463 defer_draw_scheduling_ = true; |
| 423 MessageLoop::current()->PostTask( | 464 MessageLoop::current()->PostTask( |
| 424 FROM_HERE, | 465 FROM_HERE, |
| 425 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); | 466 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); |
| 426 } | 467 } |
| 427 } | 468 } |
| 428 | 469 |
| 429 //////////////////////////////////////////////////////////////////////////////// | 470 //////////////////////////////////////////////////////////////////////////////// |
| 430 // RootWindow, ui::CompositorObserver implementation: | 471 // RootWindow, ui::CompositorObserver implementation: |
| 431 | 472 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's | 849 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's |
| 809 // is currently broken. See/ crbug.com/107931. | 850 // is currently broken. See/ crbug.com/107931. |
| 810 MouseEvent event(ui::ET_MOUSE_MOVED, | 851 MouseEvent event(ui::ET_MOUSE_MOVED, |
| 811 orig_mouse_location, | 852 orig_mouse_location, |
| 812 orig_mouse_location, | 853 orig_mouse_location, |
| 813 ui::EF_IS_SYNTHESIZED); | 854 ui::EF_IS_SYNTHESIZED); |
| 814 DispatchMouseEvent(&event); | 855 DispatchMouseEvent(&event); |
| 815 #endif | 856 #endif |
| 816 } | 857 } |
| 817 | 858 |
| 859 void RootWindow::UnlockCompositor() { | |
| 860 DCHECK(compositor_lock_); | |
| 861 compositor_lock_ = NULL; | |
| 862 if (scheduled_while_locked_) { | |
| 863 scheduled_while_locked_ = false; | |
| 864 ScheduleDraw(); | |
| 865 } | |
| 866 } | |
| 867 | |
| 818 } // namespace aura | 868 } // namespace aura |
| OLD | NEW |