OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/window_tree_host.h" | 5 #include "ui/aura/window_tree_host.h" |
6 | 6 |
7 #include "ui/aura/client/cursor_client.h" | 7 #include "ui/aura/client/cursor_client.h" |
8 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
9 #include "ui/aura/root_window_transformer.h" | 9 #include "ui/aura/root_window_transformer.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/aura/window_event_dispatcher.h" | 11 #include "ui/aura/window_event_dispatcher.h" |
| 12 #include "ui/aura/window_targeter.h" |
12 #include "ui/aura/window_tree_host_delegate.h" | 13 #include "ui/aura/window_tree_host_delegate.h" |
| 14 #include "ui/base/view_prop.h" |
13 #include "ui/compositor/dip_util.h" | 15 #include "ui/compositor/dip_util.h" |
14 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
15 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
16 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
17 #include "ui/gfx/point.h" | 19 #include "ui/gfx/point.h" |
18 #include "ui/gfx/point3_f.h" | 20 #include "ui/gfx/point3_f.h" |
19 #include "ui/gfx/point_conversions.h" | 21 #include "ui/gfx/point_conversions.h" |
20 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
21 #include "ui/gfx/size_conversions.h" | 23 #include "ui/gfx/size_conversions.h" |
22 | 24 |
23 namespace aura { | 25 namespace aura { |
24 | 26 |
| 27 const char kWindowTreeHostForAcceleratedWidget[] = |
| 28 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; |
| 29 |
25 float GetDeviceScaleFactorFromDisplay(Window* window) { | 30 float GetDeviceScaleFactorFromDisplay(Window* window) { |
26 gfx::Display display = gfx::Screen::GetScreenFor(window)-> | 31 gfx::Display display = gfx::Screen::GetScreenFor(window)-> |
27 GetDisplayNearestWindow(window); | 32 GetDisplayNearestWindow(window); |
28 DCHECK(display.is_valid()); | 33 DCHECK(display.is_valid()); |
29 return display.device_scale_factor(); | 34 return display.device_scale_factor(); |
30 } | 35 } |
31 | 36 |
32 class SimpleRootWindowTransformer : public RootWindowTransformer { | 37 class SimpleRootWindowTransformer : public RootWindowTransformer { |
33 public: | 38 public: |
34 SimpleRootWindowTransformer(const Window* root_window, | 39 SimpleRootWindowTransformer(const Window* root_window, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); | 75 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); |
71 }; | 76 }; |
72 | 77 |
73 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
74 // WindowTreeHost, public: | 79 // WindowTreeHost, public: |
75 | 80 |
76 WindowTreeHost::~WindowTreeHost() { | 81 WindowTreeHost::~WindowTreeHost() { |
77 DCHECK(!compositor_) << "compositor must be destroyed before root window"; | 82 DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
78 } | 83 } |
79 | 84 |
| 85 // static |
| 86 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( |
| 87 gfx::AcceleratedWidget widget) { |
| 88 return reinterpret_cast<WindowTreeHost*>( |
| 89 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); |
| 90 } |
| 91 |
80 void WindowTreeHost::InitHost() { | 92 void WindowTreeHost::InitHost() { |
81 InitCompositor(); | 93 InitCompositor(); |
82 UpdateRootWindowSize(GetBounds().size()); | 94 UpdateRootWindowSize(GetBounds().size()); |
83 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsDispatcher()); | 95 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsDispatcher()); |
84 window()->Show(); | 96 window()->Show(); |
85 } | 97 } |
86 | 98 |
87 void WindowTreeHost::InitCompositor() { | 99 void WindowTreeHost::InitCompositor() { |
88 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 100 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
89 GetBounds().size()); | 101 GetBounds().size()); |
90 compositor_->SetRootLayer(window()->layer()); | 102 compositor_->SetRootLayer(window()->layer()); |
91 transformer_.reset( | 103 transformer_.reset( |
92 new SimpleRootWindowTransformer(window(), gfx::Transform())); | 104 new SimpleRootWindowTransformer(window(), gfx::Transform())); |
93 } | 105 } |
94 | 106 |
95 aura::Window* WindowTreeHost::window() { | |
96 return const_cast<Window*>(const_cast<const WindowTreeHost*>(this)->window()); | |
97 } | |
98 | |
99 const aura::Window* WindowTreeHost::window() const { | |
100 return delegate_->AsDispatcher()->window(); | |
101 } | |
102 | |
103 void WindowTreeHost::SetRootWindowTransformer( | 107 void WindowTreeHost::SetRootWindowTransformer( |
104 scoped_ptr<RootWindowTransformer> transformer) { | 108 scoped_ptr<RootWindowTransformer> transformer) { |
105 transformer_ = transformer.Pass(); | 109 transformer_ = transformer.Pass(); |
106 SetInsets(transformer_->GetHostInsets()); | 110 SetInsets(transformer_->GetHostInsets()); |
107 window()->SetTransform(transformer_->GetTransform()); | 111 window()->SetTransform(transformer_->GetTransform()); |
108 // If the layer is not animating, then we need to update the root window | 112 // If the layer is not animating, then we need to update the root window |
109 // size immediately. | 113 // size immediately. |
110 if (!window()->layer()->GetAnimator()->is_animating()) | 114 if (!window()->layer()->GetAnimator()->is_animating()) |
111 UpdateRootWindowSize(GetBounds().size()); | 115 UpdateRootWindowSize(GetBounds().size()); |
112 } | 116 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 198 |
195 WindowEventDispatcher* WindowTreeHost::GetDispatcher() { | 199 WindowEventDispatcher* WindowTreeHost::GetDispatcher() { |
196 return delegate_->AsDispatcher(); | 200 return delegate_->AsDispatcher(); |
197 } | 201 } |
198 | 202 |
199 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
200 // WindowTreeHost, protected: | 204 // WindowTreeHost, protected: |
201 | 205 |
202 WindowTreeHost::WindowTreeHost() | 206 WindowTreeHost::WindowTreeHost() |
203 : delegate_(NULL), | 207 : delegate_(NULL), |
| 208 window_(new Window(NULL)), |
204 last_cursor_(ui::kCursorNull) { | 209 last_cursor_(ui::kCursorNull) { |
205 } | 210 } |
206 | 211 |
207 void WindowTreeHost::DestroyCompositor() { | 212 void WindowTreeHost::DestroyCompositor() { |
208 DCHECK(GetAcceleratedWidget()); | 213 DCHECK(GetAcceleratedWidget()); |
209 compositor_.reset(); | 214 compositor_.reset(); |
210 } | 215 } |
211 | 216 |
212 void WindowTreeHost::DestroyDispatcher() { | 217 void WindowTreeHost::DestroyDispatcher() { |
| 218 // An observer may have been added by an animation on the |
| 219 // WindowEventDispatcher. |
| 220 window()->layer()->GetAnimator()->RemoveObserver(dispatcher()); |
| 221 |
| 222 delete window_; |
| 223 window_ = NULL; |
213 dispatcher_.reset(); | 224 dispatcher_.reset(); |
| 225 |
| 226 // TODO(beng): this comment is no longer quite valid since this function |
| 227 // isn't called from WED, and WED isn't a subclass of Window. So it seems |
| 228 // like we could just rely on ~Window now. |
| 229 // Destroy child windows while we're still valid. This is also done by |
| 230 // ~Window, but by that time any calls to virtual methods overriden here (such |
| 231 // as GetRootWindow()) result in Window's implementation. By destroying here |
| 232 // we ensure GetRootWindow() still returns this. |
| 233 //window()->RemoveOrDestroyChildren(); |
214 } | 234 } |
215 | 235 |
216 void WindowTreeHost::CreateCompositor( | 236 void WindowTreeHost::CreateCompositor( |
217 gfx::AcceleratedWidget accelerated_widget) { | 237 gfx::AcceleratedWidget accelerated_widget) { |
218 compositor_.reset(new ui::Compositor(GetAcceleratedWidget())); | 238 compositor_.reset(new ui::Compositor(GetAcceleratedWidget())); |
219 DCHECK(compositor_.get()); | 239 DCHECK(compositor_.get()); |
220 // TODO(beng): I think this setup should probably all move to a "accelerated | 240 // TODO(beng): I think this setup should probably all move to a "accelerated |
221 // widget available" function. | 241 // widget available" function. |
222 if (!dispatcher()) | 242 if (!dispatcher()) { |
| 243 window()->Init(WINDOW_LAYER_NOT_DRAWN); |
| 244 window()->set_host(this); |
| 245 window()->SetName("RootWindow"); |
| 246 window()->SetEventTargeter( |
| 247 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); |
| 248 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), |
| 249 kWindowTreeHostForAcceleratedWidget, |
| 250 this)); |
223 dispatcher_.reset(new WindowEventDispatcher(this)); | 251 dispatcher_.reset(new WindowEventDispatcher(this)); |
| 252 } |
224 delegate_ = dispatcher(); | 253 delegate_ = dispatcher(); |
225 } | 254 } |
226 | 255 |
227 void WindowTreeHost::NotifyHostResized(const gfx::Size& new_size) { | 256 void WindowTreeHost::NotifyHostResized(const gfx::Size& new_size) { |
228 // The compositor should have the same size as the native root window host. | 257 // The compositor should have the same size as the native root window host. |
229 // Get the latest scale from display because it might have been changed. | 258 // Get the latest scale from display because it might have been changed. |
230 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 259 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
231 new_size); | 260 new_size); |
232 | 261 |
233 gfx::Size layer_size = GetBounds().size(); | 262 gfx::Size layer_size = GetBounds().size(); |
(...skipping 20 matching lines...) Expand all Loading... |
254 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 283 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
255 // This is only hit for tests and ash, right now these aren't an issue so | 284 // This is only hit for tests and ash, right now these aren't an issue so |
256 // adding the CHECK. | 285 // adding the CHECK. |
257 // TODO(sky): decide if we want a factory. | 286 // TODO(sky): decide if we want a factory. |
258 CHECK(false); | 287 CHECK(false); |
259 return NULL; | 288 return NULL; |
260 } | 289 } |
261 #endif | 290 #endif |
262 | 291 |
263 } // namespace aura | 292 } // namespace aura |
OLD | NEW |