OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "aura/desktop.h" | 5 #include "aura/desktop.h" |
6 | 6 |
7 #include "aura/desktop_host.h" | 7 #include "aura/desktop_host.h" |
8 #include "aura/root_window.h" | 8 #include "aura/root_window.h" |
9 #include "aura/window.h" | 9 #include "aura/window.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "ui/gfx/compositor/compositor.h" | 12 #include "ui/gfx/compositor/compositor.h" |
13 | 13 |
14 namespace aura { | 14 namespace aura { |
15 | 15 |
16 // static | 16 // static |
17 Desktop* Desktop::instance_ = NULL; | 17 Desktop* Desktop::instance_ = NULL; |
18 | 18 |
19 Desktop::Desktop() | 19 Desktop::Desktop() |
20 : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))) { | 20 : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))), |
21 compositor_ = ui::Compositor::Create(host_->GetAcceleratedWidget(), | 21 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)), |
22 main_loop_(new MessageLoop(MessageLoop::TYPE_UI)) { | |
23 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | |
22 host_->GetSize()); | 24 host_->GetSize()); |
23 host_->SetDesktop(this); | 25 host_->SetDesktop(this); |
24 DCHECK(compositor_.get()); | 26 DCHECK(compositor_.get()); |
25 window_.reset(new internal::RootWindow); | 27 window_.reset(new internal::RootWindow); |
26 } | 28 } |
27 | 29 |
28 Desktop::~Desktop() { | 30 Desktop::~Desktop() { |
29 } | 31 } |
30 | 32 |
31 void Desktop::Show() { | 33 void Desktop::Show() { |
32 host_->Show(); | 34 host_->Show(); |
33 } | 35 } |
34 | 36 |
35 void Desktop::SetSize(const gfx::Size& size) { | 37 void Desktop::SetSize(const gfx::Size& size) { |
36 host_->SetSize(size); | 38 host_->SetSize(size); |
37 } | 39 } |
38 | 40 |
39 void Desktop::Run() { | 41 void Desktop::Run() { |
40 Show(); | 42 Show(); |
41 MessageLoop main_message_loop(MessageLoop::TYPE_UI); | |
sky
2011/09/06 20:10:07
I actually just had problems with this too and was
sadrul
2011/09/06 21:50:11
I have made the change so callers create and own t
| |
42 MessageLoopForUI::current()->Run(host_); | 43 MessageLoopForUI::current()->Run(host_); |
43 } | 44 } |
44 | 45 |
45 void Desktop::Draw() { | 46 void Desktop::Draw() { |
46 compositor_->NotifyStart(); | 47 compositor_->NotifyStart(); |
47 window_->DrawTree(); | 48 window_->DrawTree(); |
48 compositor_->NotifyEnd(); | 49 compositor_->NotifyEnd(); |
49 } | 50 } |
50 | 51 |
51 bool Desktop::OnMouseEvent(const MouseEvent& event) { | 52 bool Desktop::OnMouseEvent(const MouseEvent& event) { |
52 return window_->HandleMouseEvent(event); | 53 return window_->HandleMouseEvent(event); |
53 } | 54 } |
54 | 55 |
55 bool Desktop::OnKeyEvent(const KeyEvent& event) { | 56 bool Desktop::OnKeyEvent(const KeyEvent& event) { |
56 return window_->HandleKeyEvent(event); | 57 return window_->HandleKeyEvent(event); |
57 } | 58 } |
58 | 59 |
60 void Desktop::ScheduleCompositorPaint() { | |
61 if (schedule_paint_.empty()) { | |
62 MessageLoop::current()->PostTask(FROM_HERE, | |
63 schedule_paint_.NewRunnableMethod(&Desktop::Draw)); | |
64 } | |
65 } | |
66 | |
59 // static | 67 // static |
60 Desktop* Desktop::GetInstance() { | 68 Desktop* Desktop::GetInstance() { |
61 if (!instance_) { | 69 if (!instance_) { |
62 instance_ = new Desktop; | 70 instance_ = new Desktop; |
63 instance_->window_->Init(); | 71 instance_->window_->Init(); |
64 } | 72 } |
65 return instance_; | 73 return instance_; |
66 } | 74 } |
67 | 75 |
68 } // namespace aura | 76 } // namespace aura |
OLD | NEW |