| 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 "mojo/examples/aura_demo/root_window_host_mojo.h" | 5 #include "mojo/examples/aura_demo/root_window_host_mojo.h" |
| 6 | 6 |
| 7 #include "mojo/examples/aura_demo/demo_context_factory.h" | 7 #include "mojo/examples/aura_demo/demo_context_factory.h" |
| 8 #include "mojo/examples/compositor_app/gles2_client_impl.h" | 8 #include "mojo/examples/compositor_app/gles2_client_impl.h" |
| 9 #include "mojo/public/gles2/gles2.h" | 9 #include "mojo/public/gles2/gles2.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_tree_host_delegate.h" | 12 #include "ui/aura/window_tree_host_delegate.h" |
| 13 #include "ui/compositor/compositor.h" | 13 #include "ui/compositor/compositor.h" |
| 14 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace examples { | 18 namespace examples { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 ui::ContextFactory* WindowTreeHostMojo::context_factory_ = NULL; | 21 ui::ContextFactory* WindowTreeHostMojo::context_factory_ = NULL; |
| 22 | 22 |
| 23 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
| 24 // WindowTreeHostMojo, public: | 24 // WindowTreeHostMojo, public: |
| 25 | 25 |
| 26 WindowTreeHostMojo::WindowTreeHostMojo( | 26 WindowTreeHostMojo::WindowTreeHostMojo( |
| 27 ScopedMessagePipeHandle viewport_handle, | 27 ScopedMessagePipeHandle viewport_handle, |
| 28 const base::Callback<void()>& compositor_created_callback) | 28 const base::Callback<void()>& compositor_created_callback) |
| 29 : native_viewport_(viewport_handle.Pass(), this), | 29 : context_created_(false), |
| 30 native_viewport_(viewport_handle.Pass(), this), |
| 30 compositor_created_callback_(compositor_created_callback) { | 31 compositor_created_callback_(compositor_created_callback) { |
| 31 native_viewport_->Open(); | 32 native_viewport_->Open(); |
| 32 | 33 |
| 33 ScopedMessagePipeHandle gles2_handle; | 34 ScopedMessagePipeHandle gles2_handle; |
| 34 ScopedMessagePipeHandle gles2_client_handle; | 35 ScopedMessagePipeHandle gles2_client_handle; |
| 35 CreateMessagePipe(&gles2_handle, &gles2_client_handle); | 36 CreateMessagePipe(&gles2_handle, &gles2_client_handle); |
| 36 | 37 |
| 37 // The ContextFactory must exist before any Compositors are created. | 38 // The ContextFactory must exist before any Compositors are created. |
| 38 if (!context_factory_) { | 39 if (!context_factory_) { |
| 39 scoped_ptr<DemoContextFactory> cf(new DemoContextFactory(this)); | 40 scoped_ptr<DemoContextFactory> cf(new DemoContextFactory(this)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 void WindowTreeHostMojo::Hide() { | 72 void WindowTreeHostMojo::Hide() { |
| 72 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void WindowTreeHostMojo::ToggleFullScreen() { | 76 void WindowTreeHostMojo::ToggleFullScreen() { |
| 76 NOTIMPLEMENTED(); | 77 NOTIMPLEMENTED(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 gfx::Rect WindowTreeHostMojo::GetBounds() const { | 80 gfx::Rect WindowTreeHostMojo::GetBounds() const { |
| 80 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
| 81 return gfx::Rect(500, 500); | 82 return gfx::Rect(viewport_size_); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { | 85 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { |
| 85 NOTIMPLEMENTED(); | 86 NOTIMPLEMENTED(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 gfx::Insets WindowTreeHostMojo::GetInsets() const { | 89 gfx::Insets WindowTreeHostMojo::GetInsets() const { |
| 89 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
| 90 return gfx::Insets(); | 91 return gfx::Insets(); |
| 91 } | 92 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void WindowTreeHostMojo::PrepareForShutdown() { | 145 void WindowTreeHostMojo::PrepareForShutdown() { |
| 145 NOTIMPLEMENTED(); | 146 NOTIMPLEMENTED(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 //////////////////////////////////////////////////////////////////////////////// | 149 //////////////////////////////////////////////////////////////////////////////// |
| 149 // WindowTreeHostMojo, NativeViewportClient implementation: | 150 // WindowTreeHostMojo, NativeViewportClient implementation: |
| 150 | 151 |
| 151 void WindowTreeHostMojo::OnCreated() { | 152 void WindowTreeHostMojo::OnCreated(uint32_t width, uint32_t height) { |
| 153 viewport_size_ = gfx::Size(width, height); |
| 154 MaybeCreateCompositor(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 void WindowTreeHostMojo::OnDestroyed() { | 157 void WindowTreeHostMojo::OnDestroyed() { |
| 155 base::MessageLoop::current()->Quit(); | 158 base::MessageLoop::current()->Quit(); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void WindowTreeHostMojo::OnEvent(const Event& event) { | 161 void WindowTreeHostMojo::OnEvent(const Event& event) { |
| 159 if (!event.location().is_null()) | 162 if (!event.location().is_null()) |
| 160 native_viewport_->AckEvent(event); | 163 native_viewport_->AckEvent(event); |
| 161 | 164 |
| 162 // TODO(beng): fwd to rootwindow. | 165 // TODO(beng): fwd to rootwindow. |
| 163 }; | 166 }; |
| 164 | 167 |
| 165 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 166 // WindowTreeHostMojo, private: | 169 // WindowTreeHostMojo, private: |
| 167 | 170 |
| 168 void WindowTreeHostMojo::DidCreateContext(gfx::Size viewport_size) { | 171 void WindowTreeHostMojo::DidCreateContext() { |
| 172 context_created_ = true; |
| 173 MaybeCreateCompositor(); |
| 174 } |
| 175 |
| 176 void WindowTreeHostMojo::MaybeCreateCompositor() { |
| 177 if (viewport_size_.IsEmpty() || !context_created_) |
| 178 return; |
| 169 CreateCompositor(GetAcceleratedWidget()); | 179 CreateCompositor(GetAcceleratedWidget()); |
| 170 compositor_created_callback_.Run(); | 180 compositor_created_callback_.Run(); |
| 171 NotifyHostResized(viewport_size); | 181 NotifyHostResized(viewport_size_); |
| 172 } | 182 } |
| 173 | 183 |
| 174 } // namespace examples | 184 } // namespace examples |
| 175 } // namespace mojo | 185 } // namespace mojo |
| OLD | NEW |