| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/services/view_manager/root_node_manager.h" | 5 #include "mojo/services/view_manager/root_node_manager.h" |
| 6 #include "mojo/services/view_manager/window_tree_host_impl.h" | 6 #include "mojo/services/view_manager/window_tree_host_impl.h" |
| 7 #include "mojo/public/c/gles2/gles2.h" | 7 #include "mojo/public/c/gles2/gles2.h" |
| 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 10 #include "mojo/services/view_manager/context_factory_impl.h" | 10 #include "mojo/services/view_manager/context_factory_impl.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void RootLayoutManager::SetChildBounds(aura::Window* child, | 60 void RootLayoutManager::SetChildBounds(aura::Window* child, |
| 61 const gfx::Rect& requested_bounds) { | 61 const gfx::Rect& requested_bounds) { |
| 62 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 62 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 63 } | 63 } |
| 64 | 64 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// |
| 66 // WindowTreeHostImpl, public: | 66 // WindowTreeHostImpl, public: |
| 67 | 67 |
| 68 WindowTreeHostImpl::WindowTreeHostImpl( | 68 WindowTreeHostImpl::WindowTreeHostImpl( |
| 69 NativeViewportPtr viewport, | 69 NativeViewportPtr viewport, |
| 70 GpuPtr gpu_service, |
| 70 const gfx::Rect& bounds, | 71 const gfx::Rect& bounds, |
| 71 const Callback<void()>& compositor_created_callback, | 72 const Callback<void()>& compositor_created_callback, |
| 72 const Callback<void()>& native_viewport_closed_callback, | 73 const Callback<void()>& native_viewport_closed_callback, |
| 73 const Callback<void(EventPtr)>& event_received_callback) | 74 const Callback<void(EventPtr)>& event_received_callback) |
| 74 : native_viewport_(viewport.Pass()), | 75 : native_viewport_(viewport.Pass()), |
| 76 gpu_service_(gpu_service.Pass()), |
| 77 widget_(gfx::kNullAcceleratedWidget), |
| 75 compositor_created_callback_(compositor_created_callback), | 78 compositor_created_callback_(compositor_created_callback), |
| 76 native_viewport_closed_callback_(native_viewport_closed_callback), | 79 native_viewport_closed_callback_(native_viewport_closed_callback), |
| 77 event_received_callback_(event_received_callback), | 80 event_received_callback_(event_received_callback), |
| 78 bounds_(bounds) { | 81 bounds_(bounds) { |
| 79 native_viewport_.set_client(this); | 82 native_viewport_.set_client(this); |
| 80 native_viewport_->Create(Rect::From(bounds)); | 83 native_viewport_->Create(Rect::From(bounds)); |
| 81 | 84 native_viewport_->Show(); |
| 82 MessagePipe pipe; | |
| 83 native_viewport_->CreateGLES2Context( | |
| 84 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); | |
| 85 | |
| 86 // The ContextFactory must exist before any Compositors are created. | |
| 87 if (context_factory_) { | |
| 88 delete context_factory_; | |
| 89 context_factory_ = NULL; | |
| 90 } | |
| 91 context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); | |
| 92 aura::Env::GetInstance()->set_context_factory(context_factory_); | |
| 93 | 85 |
| 94 window()->SetLayoutManager(new RootLayoutManager()); | 86 window()->SetLayoutManager(new RootLayoutManager()); |
| 95 } | 87 } |
| 96 | 88 |
| 97 WindowTreeHostImpl::~WindowTreeHostImpl() { | 89 WindowTreeHostImpl::~WindowTreeHostImpl() { |
| 98 DestroyCompositor(); | 90 DestroyCompositor(); |
| 99 DestroyDispatcher(); | 91 DestroyDispatcher(); |
| 100 } | 92 } |
| 101 | 93 |
| 102 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 103 // WindowTreeHostImpl, aura::WindowTreeHost implementation: | 95 // WindowTreeHostImpl, aura::WindowTreeHost implementation: |
| 104 | 96 |
| 105 ui::EventSource* WindowTreeHostImpl::GetEventSource() { | 97 ui::EventSource* WindowTreeHostImpl::GetEventSource() { |
| 106 return this; | 98 return this; |
| 107 } | 99 } |
| 108 | 100 |
| 109 gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() { | 101 gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() { |
| 110 NOTIMPLEMENTED() << "GetAcceleratedWidget"; | 102 return widget_; |
| 111 return gfx::kNullAcceleratedWidget; | |
| 112 } | 103 } |
| 113 | 104 |
| 114 void WindowTreeHostImpl::Show() { | 105 void WindowTreeHostImpl::Show() { |
| 115 window()->Show(); | 106 window()->Show(); |
| 116 native_viewport_->Show(); | |
| 117 } | 107 } |
| 118 | 108 |
| 119 void WindowTreeHostImpl::Hide() { | 109 void WindowTreeHostImpl::Hide() { |
| 120 native_viewport_->Hide(); | 110 native_viewport_->Hide(); |
| 121 window()->Hide(); | 111 window()->Hide(); |
| 122 } | 112 } |
| 123 | 113 |
| 124 gfx::Rect WindowTreeHostImpl::GetBounds() const { | 114 gfx::Rect WindowTreeHostImpl::GetBounds() const { |
| 125 return bounds_; | 115 return bounds_; |
| 126 } | 116 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
| 162 // WindowTreeHostImpl, ui::EventSource implementation: | 152 // WindowTreeHostImpl, ui::EventSource implementation: |
| 163 | 153 |
| 164 ui::EventProcessor* WindowTreeHostImpl::GetEventProcessor() { | 154 ui::EventProcessor* WindowTreeHostImpl::GetEventProcessor() { |
| 165 return dispatcher(); | 155 return dispatcher(); |
| 166 } | 156 } |
| 167 | 157 |
| 168 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
| 169 // WindowTreeHostImpl, NativeViewportClient implementation: | 159 // WindowTreeHostImpl, NativeViewportClient implementation: |
| 170 | 160 |
| 171 void WindowTreeHostImpl::OnCreated() { | 161 void WindowTreeHostImpl::OnCreated(uint64_t native_viewport_id) { |
| 172 CreateCompositor(GetAcceleratedWidget()); | 162 LOG(ERROR) << "OnCreated " << native_viewport_id; |
| 163 CommandBufferPtr cb; |
| 164 gpu_service_->CreateOnscreenGLES2Context( |
| 165 native_viewport_id, Size::From(bounds_.size()), Get(&cb)); |
| 166 widget_ = bit_cast<gfx::AcceleratedWidget>( |
| 167 static_cast<uintptr_t>(native_viewport_id)); |
| 168 |
| 169 // The ContextFactory must exist before any Compositors are created. |
| 170 if (context_factory_) { |
| 171 delete context_factory_; |
| 172 context_factory_ = NULL; |
| 173 } |
| 174 context_factory_ = new ContextFactoryImpl(cb.PassMessagePipe()); |
| 175 aura::Env::GetInstance()->set_context_factory(context_factory_); |
| 176 |
| 177 CreateCompositor(gfx::kNullAcceleratedWidget); |
| 173 compositor_created_callback_.Run(); | 178 compositor_created_callback_.Run(); |
| 174 } | 179 } |
| 175 | 180 |
| 176 void WindowTreeHostImpl::OnBoundsChanged(RectPtr bounds) { | 181 void WindowTreeHostImpl::OnBoundsChanged(RectPtr bounds) { |
| 177 bounds_ = bounds.To<gfx::Rect>(); | 182 bounds_ = bounds.To<gfx::Rect>(); |
| 178 OnHostResized(bounds_.size()); | 183 if (context_factory_) |
| 184 OnHostResized(bounds_.size()); |
| 179 } | 185 } |
| 180 | 186 |
| 181 void WindowTreeHostImpl::OnDestroyed(const mojo::Callback<void()>& callback) { | 187 void WindowTreeHostImpl::OnDestroyed() { |
| 182 DestroyCompositor(); | 188 DestroyCompositor(); |
| 183 native_viewport_closed_callback_.Run(); | 189 native_viewport_closed_callback_.Run(); |
| 184 // TODO(beng): quit the message loop once we are on our own thread. | 190 // TODO(beng): quit the message loop once we are on our own thread. |
| 185 callback.Run(); | |
| 186 } | 191 } |
| 187 | 192 |
| 188 void WindowTreeHostImpl::OnEvent(EventPtr event, | 193 void WindowTreeHostImpl::OnEvent(EventPtr event, |
| 189 const mojo::Callback<void()>& callback) { | 194 const mojo::Callback<void()>& callback) { |
| 190 event_received_callback_.Run(event.Pass()); | 195 event_received_callback_.Run(event.Pass()); |
| 191 callback.Run(); | 196 callback.Run(); |
| 192 }; | 197 }; |
| 193 | 198 |
| 194 } // namespace service | 199 } // namespace service |
| 195 } // namespace mojo | 200 } // namespace mojo |
| OLD | NEW |