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 24 matching lines...) Expand all Loading... |
35 #include "ui/gfx/display.h" | 35 #include "ui/gfx/display.h" |
36 #include "ui/gfx/point3.h" | 36 #include "ui/gfx/point3.h" |
37 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
38 | 38 |
39 using std::vector; | 39 using std::vector; |
40 | 40 |
41 namespace aura { | 41 namespace aura { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 const int kCompositorLockTimeoutMs = 67; | |
46 | |
47 // Returns true if |target| has a non-client (frame) component at |location|, | 45 // Returns true if |target| has a non-client (frame) component at |location|, |
48 // in window coordinates. | 46 // in window coordinates. |
49 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 47 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
50 if (!target->delegate()) | 48 if (!target->delegate()) |
51 return false; | 49 return false; |
52 int hit_test_code = target->delegate()->GetNonClientComponent(location); | 50 int hit_test_code = target->delegate()->GetNonClientComponent(location); |
53 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; | 51 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; |
54 } | 52 } |
55 | 53 |
56 typedef std::vector<EventFilter*> EventFilters; | 54 typedef std::vector<EventFilter*> EventFilters; |
(...skipping 18 matching lines...) Expand all Loading... |
75 static_cast<Window*>(consumer) : NULL; | 73 static_cast<Window*>(consumer) : NULL; |
76 } | 74 } |
77 | 75 |
78 void SetLastMouseLocation(const Window* root_window, | 76 void SetLastMouseLocation(const Window* root_window, |
79 const gfx::Point& location) { | 77 const gfx::Point& location) { |
80 Env::GetInstance()->SetLastMouseLocation(*root_window, location); | 78 Env::GetInstance()->SetLastMouseLocation(*root_window, location); |
81 } | 79 } |
82 | 80 |
83 } // namespace | 81 } // namespace |
84 | 82 |
85 CompositorLock::CompositorLock(RootWindow* root_window) | |
86 : root_window_(root_window) { | |
87 MessageLoop::current()->PostDelayedTask( | |
88 FROM_HERE, | |
89 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), | |
90 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); | |
91 } | |
92 | |
93 CompositorLock::~CompositorLock() { | |
94 CancelLock(); | |
95 } | |
96 | |
97 void CompositorLock::CancelLock() { | |
98 if (!root_window_) | |
99 return; | |
100 root_window_->UnlockCompositor(); | |
101 root_window_ = NULL; | |
102 } | |
103 | |
104 bool RootWindow::hide_host_cursor_ = false; | 83 bool RootWindow::hide_host_cursor_ = false; |
105 | 84 |
106 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
107 // RootWindow, public: | 86 // RootWindow, public: |
108 | 87 |
109 RootWindow::RootWindow(const gfx::Rect& initial_bounds) | 88 RootWindow::RootWindow(const gfx::Rect& initial_bounds) |
110 : Window(NULL), | 89 : Window(NULL), |
111 ALLOW_THIS_IN_INITIALIZER_LIST( | 90 ALLOW_THIS_IN_INITIALIZER_LIST( |
112 host_(RootWindowHost::Create(this, initial_bounds))), | 91 host_(RootWindowHost::Create(this, initial_bounds))), |
113 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 92 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
114 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 93 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
115 mouse_button_flags_(0), | 94 mouse_button_flags_(0), |
116 touch_ids_down_(0), | 95 touch_ids_down_(0), |
117 last_cursor_(ui::kCursorNull), | 96 last_cursor_(ui::kCursorNull), |
118 mouse_pressed_handler_(NULL), | 97 mouse_pressed_handler_(NULL), |
119 mouse_moved_handler_(NULL), | 98 mouse_moved_handler_(NULL), |
120 ALLOW_THIS_IN_INITIALIZER_LIST( | 99 ALLOW_THIS_IN_INITIALIZER_LIST( |
121 gesture_recognizer_(ui::GestureRecognizer::Create(this))), | 100 gesture_recognizer_(ui::GestureRecognizer::Create(this))), |
122 synthesize_mouse_move_(false), | 101 synthesize_mouse_move_(false), |
123 waiting_on_compositing_end_(false), | 102 waiting_on_compositing_end_(false), |
124 draw_on_compositing_end_(false), | 103 draw_on_compositing_end_(false), |
125 defer_draw_scheduling_(false), | 104 defer_draw_scheduling_(false), |
126 mouse_move_hold_count_(0), | 105 mouse_move_hold_count_(0), |
127 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)), | 106 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)) { |
128 compositor_lock_(NULL), | |
129 draw_on_compositor_unlock_(false) { | |
130 SetName("RootWindow"); | 107 SetName("RootWindow"); |
131 | 108 |
132 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget())); | 109 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget())); |
133 DCHECK(compositor_.get()); | 110 DCHECK(compositor_.get()); |
134 compositor_->AddObserver(this); | 111 compositor_->AddObserver(this); |
135 } | 112 } |
136 | 113 |
137 RootWindow::~RootWindow() { | 114 RootWindow::~RootWindow() { |
138 if (compositor_lock_) { | |
139 // No need to schedule a draw, we're going away. | |
140 draw_on_compositor_unlock_ = false; | |
141 compositor_lock_->CancelLock(); | |
142 DCHECK(!compositor_lock_); | |
143 } | |
144 compositor_->RemoveObserver(this); | 115 compositor_->RemoveObserver(this); |
145 // Make sure to destroy the compositor before terminating so that state is | 116 // Make sure to destroy the compositor before terminating so that state is |
146 // cleared and we don't hit asserts. | 117 // cleared and we don't hit asserts. |
147 compositor_.reset(); | 118 compositor_.reset(); |
148 | 119 |
149 // Tear down in reverse. Frees any references held by the host. | 120 // Tear down in reverse. Frees any references held by the host. |
150 host_.reset(NULL); | 121 host_.reset(NULL); |
151 | 122 |
152 // An observer may have been added by an animation on the RootWindow. | 123 // An observer may have been added by an animation on the RootWindow. |
153 layer()->GetAnimator()->RemoveObserver(this); | 124 layer()->GetAnimator()->RemoveObserver(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // being used in fullscreen mode, so root_window bounds = window bounds. | 214 // being used in fullscreen mode, so root_window bounds = window bounds. |
244 return host_->ConfineCursorToRootWindow(); | 215 return host_->ConfineCursorToRootWindow(); |
245 } | 216 } |
246 | 217 |
247 void RootWindow::Draw() { | 218 void RootWindow::Draw() { |
248 defer_draw_scheduling_ = false; | 219 defer_draw_scheduling_ = false; |
249 if (waiting_on_compositing_end_) { | 220 if (waiting_on_compositing_end_) { |
250 draw_on_compositing_end_ = true; | 221 draw_on_compositing_end_ = true; |
251 return; | 222 return; |
252 } | 223 } |
253 if (compositor_lock_) { | |
254 draw_on_compositor_unlock_ = true; | |
255 return; | |
256 } | |
257 waiting_on_compositing_end_ = true; | 224 waiting_on_compositing_end_ = true; |
258 | 225 |
259 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::Draw", | 226 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::Draw", |
260 compositor_->last_started_frame() + 1); | 227 compositor_->last_started_frame() + 1); |
261 | 228 |
262 compositor_->Draw(false); | 229 compositor_->Draw(false); |
263 } | 230 } |
264 | 231 |
265 void RootWindow::ScheduleFullDraw() { | 232 void RootWindow::ScheduleFullDraw() { |
266 compositor_->ScheduleFullDraw(); | 233 compositor_->ScheduleFullDraw(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // dispatching another one may not be safe/expected. | 349 // dispatching another one may not be safe/expected. |
383 // Instead we post a task, that we may cancel if HoldMouseMoves is called | 350 // Instead we post a task, that we may cancel if HoldMouseMoves is called |
384 // again before it executes. | 351 // again before it executes. |
385 MessageLoop::current()->PostTask( | 352 MessageLoop::current()->PostTask( |
386 FROM_HERE, | 353 FROM_HERE, |
387 base::Bind(&RootWindow::DispatchHeldMouseMove, | 354 base::Bind(&RootWindow::DispatchHeldMouseMove, |
388 held_mouse_event_factory_.GetWeakPtr())); | 355 held_mouse_event_factory_.GetWeakPtr())); |
389 } | 356 } |
390 } | 357 } |
391 | 358 |
392 scoped_refptr<CompositorLock> RootWindow::GetCompositorLock() { | |
393 if (!compositor_lock_) | |
394 compositor_lock_ = new CompositorLock(this); | |
395 return compositor_lock_; | |
396 } | |
397 | |
398 void RootWindow::SetFocusWhenShown(bool focused) { | 359 void RootWindow::SetFocusWhenShown(bool focused) { |
399 host_->SetFocusWhenShown(focused); | 360 host_->SetFocusWhenShown(focused); |
400 } | 361 } |
401 | 362 |
402 bool RootWindow::GrabSnapshot(const gfx::Rect& snapshot_bounds, | 363 bool RootWindow::GrabSnapshot(const gfx::Rect& snapshot_bounds, |
403 std::vector<unsigned char>* png_representation) { | 364 std::vector<unsigned char>* png_representation) { |
404 DCHECK(bounds().Contains(snapshot_bounds)); | 365 DCHECK(bounds().Contains(snapshot_bounds)); |
405 gfx::Rect snapshot_pixels = ui::ConvertRectToPixel(layer(), snapshot_bounds); | 366 gfx::Rect snapshot_pixels = ui::ConvertRectToPixel(layer(), snapshot_bounds); |
406 return host_->GrabSnapshot(snapshot_pixels, png_representation); | 367 return host_->GrabSnapshot(snapshot_pixels, png_representation); |
407 } | 368 } |
(...skipping 23 matching lines...) Expand all Loading... |
431 // If the layer is not animating, then we need to update the host size | 392 // If the layer is not animating, then we need to update the host size |
432 // immediately. | 393 // immediately. |
433 if (!layer()->GetAnimator()->is_animating()) | 394 if (!layer()->GetAnimator()->is_animating()) |
434 OnHostResized(host_->GetBounds().size()); | 395 OnHostResized(host_->GetBounds().size()); |
435 } | 396 } |
436 | 397 |
437 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
438 // RootWindow, ui::CompositorDelegate implementation: | 399 // RootWindow, ui::CompositorDelegate implementation: |
439 | 400 |
440 void RootWindow::ScheduleDraw() { | 401 void RootWindow::ScheduleDraw() { |
441 if (compositor_lock_) { | 402 if (!defer_draw_scheduling_) { |
442 draw_on_compositor_unlock_ = true; | |
443 } else if (!defer_draw_scheduling_) { | |
444 defer_draw_scheduling_ = true; | 403 defer_draw_scheduling_ = true; |
445 MessageLoop::current()->PostTask( | 404 MessageLoop::current()->PostTask( |
446 FROM_HERE, | 405 FROM_HERE, |
447 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); | 406 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); |
448 } | 407 } |
449 } | 408 } |
450 | 409 |
451 //////////////////////////////////////////////////////////////////////////////// | 410 //////////////////////////////////////////////////////////////////////////////// |
452 // RootWindow, ui::CompositorObserver implementation: | 411 // RootWindow, ui::CompositorObserver implementation: |
453 | 412 |
454 void RootWindow::OnCompositingDidCommit(ui::Compositor*) { | |
455 } | |
456 | |
457 void RootWindow::OnCompositingWillStart(ui::Compositor*) { | |
458 } | |
459 | |
460 void RootWindow::OnCompositingStarted(ui::Compositor*) { | 413 void RootWindow::OnCompositingStarted(ui::Compositor*) { |
461 } | 414 } |
462 | 415 |
463 void RootWindow::OnCompositingEnded(ui::Compositor*) { | 416 void RootWindow::OnCompositingEnded(ui::Compositor*) { |
464 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::Draw", | 417 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::Draw", |
465 compositor_->last_ended_frame()); | 418 compositor_->last_ended_frame()); |
466 waiting_on_compositing_end_ = false; | 419 waiting_on_compositing_end_ = false; |
467 if (draw_on_compositing_end_) { | 420 if (draw_on_compositing_end_) { |
468 draw_on_compositing_end_ = false; | 421 draw_on_compositing_end_ = false; |
469 | 422 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's | 979 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's |
1027 // currently broken. See/ crbug.com/107931. | 980 // currently broken. See/ crbug.com/107931. |
1028 MouseEvent event(ui::ET_MOUSE_MOVED, | 981 MouseEvent event(ui::ET_MOUSE_MOVED, |
1029 orig_mouse_location, | 982 orig_mouse_location, |
1030 orig_mouse_location, | 983 orig_mouse_location, |
1031 ui::EF_IS_SYNTHESIZED); | 984 ui::EF_IS_SYNTHESIZED); |
1032 OnHostMouseEvent(&event); | 985 OnHostMouseEvent(&event); |
1033 #endif | 986 #endif |
1034 } | 987 } |
1035 | 988 |
1036 void RootWindow::UnlockCompositor() { | |
1037 DCHECK(compositor_lock_); | |
1038 compositor_lock_ = NULL; | |
1039 if (draw_on_compositor_unlock_) { | |
1040 draw_on_compositor_unlock_ = false; | |
1041 ScheduleDraw(); | |
1042 } | |
1043 } | |
1044 | |
1045 } // namespace aura | 989 } // namespace aura |
OLD | NEW |