OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/view_manager/display_manager.h" | 5 #include "components/view_manager/display_manager.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "components/view_manager/display_manager_factory.h" | 8 #include "components/view_manager/display_manager_factory.h" |
9 #include "components/view_manager/gles2/gpu_state.h" | 9 #include "components/view_manager/gles2/gpu_state.h" |
10 #include "components/view_manager/native_viewport/onscreen_context_provider.h" | |
11 #include "components/view_manager/public/interfaces/gpu.mojom.h" | 10 #include "components/view_manager/public/interfaces/gpu.mojom.h" |
12 #include "components/view_manager/public/interfaces/quads.mojom.h" | 11 #include "components/view_manager/public/interfaces/quads.mojom.h" |
13 #include "components/view_manager/public/interfaces/surfaces.mojom.h" | 12 #include "components/view_manager/public/interfaces/surfaces.mojom.h" |
14 #include "components/view_manager/server_view.h" | 13 #include "components/view_manager/server_view.h" |
| 14 #include "components/view_manager/surfaces/surfaces_state.h" |
15 #include "components/view_manager/view_coordinate_conversions.h" | 15 #include "components/view_manager/view_coordinate_conversions.h" |
16 #include "mojo/application/public/cpp/application_connection.h" | 16 #include "mojo/application/public/cpp/application_connection.h" |
17 #include "mojo/application/public/cpp/application_impl.h" | 17 #include "mojo/application/public/cpp/application_impl.h" |
18 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
19 #include "mojo/converters/input_events/input_events_type_converters.h" | 19 #include "mojo/converters/input_events/input_events_type_converters.h" |
20 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" | 20 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" |
21 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 21 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
22 #include "mojo/converters/surfaces/surfaces_utils.h" | 22 #include "mojo/converters/surfaces/surfaces_utils.h" |
23 #include "mojo/converters/transform/transform_type_converters.h" | 23 #include "mojo/converters/transform/transform_type_converters.h" |
24 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 // static | 101 // static |
102 DisplayManagerFactory* DisplayManager::factory_ = nullptr; | 102 DisplayManagerFactory* DisplayManager::factory_ = nullptr; |
103 | 103 |
104 // static | 104 // static |
105 DisplayManager* DisplayManager::Create( | 105 DisplayManager* DisplayManager::Create( |
106 bool is_headless, | 106 bool is_headless, |
107 mojo::ApplicationImpl* app_impl, | 107 mojo::ApplicationImpl* app_impl, |
108 const scoped_refptr<gles2::GpuState>& gpu_state) { | 108 const scoped_refptr<gles2::GpuState>& gpu_state, |
109 if (factory_) | 109 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) { |
110 return factory_->CreateDisplayManager(is_headless, app_impl, gpu_state); | 110 if (factory_) { |
111 return new DefaultDisplayManager(is_headless, app_impl, gpu_state); | 111 return factory_->CreateDisplayManager(is_headless, app_impl, gpu_state, |
| 112 surfaces_state); |
| 113 } |
| 114 return new DefaultDisplayManager(is_headless, app_impl, gpu_state, |
| 115 surfaces_state); |
112 } | 116 } |
113 | 117 |
114 DefaultDisplayManager::DefaultDisplayManager( | 118 DefaultDisplayManager::DefaultDisplayManager( |
115 bool is_headless, | 119 bool is_headless, |
116 mojo::ApplicationImpl* app_impl, | 120 mojo::ApplicationImpl* app_impl, |
117 const scoped_refptr<gles2::GpuState>& gpu_state) | 121 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 122 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) |
118 : is_headless_(is_headless), | 123 : is_headless_(is_headless), |
119 app_impl_(app_impl), | 124 app_impl_(app_impl), |
120 gpu_state_(gpu_state), | 125 gpu_state_(gpu_state), |
| 126 surfaces_state_(surfaces_state), |
121 delegate_(nullptr), | 127 delegate_(nullptr), |
122 draw_timer_(false, false), | 128 draw_timer_(false, false), |
123 frame_pending_(false), | 129 frame_pending_(false) { |
124 context_provider_( | |
125 new native_viewport::OnscreenContextProvider(gpu_state)), | |
126 weak_factory_(this) { | |
127 metrics_.size_in_pixels = mojo::Size::New(); | 130 metrics_.size_in_pixels = mojo::Size::New(); |
128 metrics_.size_in_pixels->width = 800; | 131 metrics_.size_in_pixels->width = 800; |
129 metrics_.size_in_pixels->height = 600; | 132 metrics_.size_in_pixels->height = 600; |
130 } | 133 } |
131 | 134 |
132 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) { | 135 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) { |
133 delegate_ = delegate; | 136 delegate_ = delegate; |
134 | 137 |
135 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); | 138 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); |
136 if (is_headless_) { | 139 if (is_headless_) { |
137 platform_window_.reset(new ui::StubWindow(this)); | 140 platform_window_.reset(new ui::StubWindow(this)); |
138 } else { | 141 } else { |
139 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
140 platform_window_.reset(new ui::WinWindow(this, bounds)); | 143 platform_window_.reset(new ui::WinWindow(this, bounds)); |
141 #elif defined(USE_X11) | 144 #elif defined(USE_X11) |
142 platform_window_.reset(new ui::X11Window(this)); | 145 platform_window_.reset(new ui::X11Window(this)); |
143 #elif defined(OS_ANDROID) | 146 #elif defined(OS_ANDROID) |
144 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 147 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
145 #else | 148 #else |
146 NOTREACHED() << "Unsupported platform"; | 149 NOTREACHED() << "Unsupported platform"; |
147 #endif | 150 #endif |
148 } | 151 } |
149 platform_window_->SetBounds(bounds); | 152 platform_window_->SetBounds(bounds); |
150 platform_window_->Show(); | 153 platform_window_->Show(); |
151 | |
152 mojo::ContextProviderPtr context_provider; | |
153 context_provider_->Bind(GetProxy(&context_provider).Pass()); | |
154 mojo::DisplayFactoryPtr display_factory; | |
155 mojo::URLRequestPtr request(mojo::URLRequest::New()); | |
156 request->url = mojo::String::From("mojo:surfaces_service"); | |
157 app_impl_->ConnectToService(request.Pass(), &display_factory); | |
158 // TODO(fsamuel): We should indicate to the delegate that this object failed | |
159 // to initialize. | |
160 if (!display_factory) | |
161 return; | |
162 display_factory->Create(context_provider.Pass(), | |
163 nullptr, // returner - we never submit resources. | |
164 GetProxy(&display_)); | |
165 } | 154 } |
166 | 155 |
167 DefaultDisplayManager::~DefaultDisplayManager() { | 156 DefaultDisplayManager::~DefaultDisplayManager() { |
168 // Destroy before |platform_window_| because this will destroy | |
169 // CommandBufferDriver objects that contain child windows. Otherwise if this | |
170 // class destroys its window first, X errors will occur. | |
171 context_provider_.reset(); | |
172 | |
173 // Destroy the PlatformWindow early on as it may call us back during | 157 // Destroy the PlatformWindow early on as it may call us back during |
174 // destruction and we want to be in a known state. | 158 // destruction and we want to be in a known state. |
175 platform_window_.reset(); | 159 platform_window_.reset(); |
176 } | 160 } |
177 | 161 |
178 void DefaultDisplayManager::SchedulePaint(const ServerView* view, | 162 void DefaultDisplayManager::SchedulePaint(const ServerView* view, |
179 const gfx::Rect& bounds) { | 163 const gfx::Rect& bounds) { |
180 DCHECK(view); | 164 DCHECK(view); |
181 if (!view->IsDrawn()) | 165 if (!view->IsDrawn()) |
182 return; | 166 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); | 199 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); |
216 auto pass = mojo::CreateDefaultPass(1, rect); | 200 auto pass = mojo::CreateDefaultPass(1, rect); |
217 pass->damage_rect = Rect::From(dirty_rect_); | 201 pass->damage_rect = Rect::From(dirty_rect_); |
218 | 202 |
219 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); | 203 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); |
220 | 204 |
221 auto frame = mojo::Frame::New(); | 205 auto frame = mojo::Frame::New(); |
222 frame->passes.push_back(pass.Pass()); | 206 frame->passes.push_back(pass.Pass()); |
223 frame->resources.resize(0u); | 207 frame->resources.resize(0u); |
224 frame_pending_ = true; | 208 frame_pending_ = true; |
225 if (display_) { | 209 if (top_level_display_client_) { |
226 display_->SubmitFrame(frame.Pass(), | 210 top_level_display_client_->SubmitFrame( |
227 base::Bind(&DefaultDisplayManager::DidDraw, | 211 frame.Pass(), |
228 weak_factory_.GetWeakPtr())); | 212 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); |
229 } | 213 } |
230 dirty_rect_ = gfx::Rect(); | 214 dirty_rect_ = gfx::Rect(); |
231 } | 215 } |
232 | 216 |
233 void DefaultDisplayManager::DidDraw() { | 217 void DefaultDisplayManager::DidDraw() { |
234 frame_pending_ = false; | 218 frame_pending_ = false; |
235 if (!dirty_rect_.IsEmpty()) | 219 if (!dirty_rect_.IsEmpty()) |
236 WantToDraw(); | 220 WantToDraw(); |
237 } | 221 } |
238 | 222 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 void DefaultDisplayManager::OnWindowStateChanged( | 324 void DefaultDisplayManager::OnWindowStateChanged( |
341 ui::PlatformWindowState new_state) { | 325 ui::PlatformWindowState new_state) { |
342 } | 326 } |
343 | 327 |
344 void DefaultDisplayManager::OnLostCapture() { | 328 void DefaultDisplayManager::OnLostCapture() { |
345 } | 329 } |
346 | 330 |
347 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( | 331 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( |
348 gfx::AcceleratedWidget widget, | 332 gfx::AcceleratedWidget widget, |
349 float device_pixel_ratio) { | 333 float device_pixel_ratio) { |
350 context_provider_->SetAcceleratedWidget(widget); | 334 if (widget != gfx::kNullAcceleratedWidget) { |
| 335 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( |
| 336 widget, gpu_state_, surfaces_state_)); |
| 337 } |
351 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 338 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
352 } | 339 } |
353 | 340 |
354 void DefaultDisplayManager::OnActivationChanged(bool active) { | 341 void DefaultDisplayManager::OnActivationChanged(bool active) { |
355 } | 342 } |
356 | 343 |
357 } // namespace view_manager | 344 } // namespace view_manager |
OLD | NEW |