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, |
| 112 app_impl, |
| 113 gpu_state, |
| 114 surfaces_state); |
| 115 } |
| 116 return new DefaultDisplayManager(is_headless, |
| 117 app_impl, |
| 118 gpu_state, |
| 119 surfaces_state); |
112 } | 120 } |
113 | 121 |
114 DefaultDisplayManager::DefaultDisplayManager( | 122 DefaultDisplayManager::DefaultDisplayManager( |
115 bool is_headless, | 123 bool is_headless, |
116 mojo::ApplicationImpl* app_impl, | 124 mojo::ApplicationImpl* app_impl, |
117 const scoped_refptr<gles2::GpuState>& gpu_state) | 125 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 126 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) |
118 : is_headless_(is_headless), | 127 : is_headless_(is_headless), |
119 app_impl_(app_impl), | 128 app_impl_(app_impl), |
120 gpu_state_(gpu_state), | 129 gpu_state_(gpu_state), |
| 130 surfaces_state_(surfaces_state), |
121 delegate_(nullptr), | 131 delegate_(nullptr), |
122 draw_timer_(false, false), | 132 draw_timer_(false, false), |
123 frame_pending_(false), | 133 frame_pending_(false), |
124 context_provider_( | |
125 new native_viewport::OnscreenContextProvider(gpu_state)), | |
126 weak_factory_(this) { | 134 weak_factory_(this) { |
127 metrics_.size_in_pixels = mojo::Size::New(); | 135 metrics_.size_in_pixels = mojo::Size::New(); |
128 metrics_.size_in_pixels->width = 800; | 136 metrics_.size_in_pixels->width = 800; |
129 metrics_.size_in_pixels->height = 600; | 137 metrics_.size_in_pixels->height = 600; |
130 } | 138 } |
131 | 139 |
132 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) { | 140 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) { |
133 delegate_ = delegate; | 141 delegate_ = delegate; |
134 | 142 |
135 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); | 143 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); |
136 if (is_headless_) { | 144 if (is_headless_) { |
137 platform_window_.reset(new ui::StubWindow(this)); | 145 platform_window_.reset(new ui::StubWindow(this)); |
138 } else { | 146 } else { |
139 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
140 platform_window_.reset(new ui::WinWindow(this, bounds)); | 148 platform_window_.reset(new ui::WinWindow(this, bounds)); |
141 #elif defined(USE_X11) | 149 #elif defined(USE_X11) |
142 platform_window_.reset(new ui::X11Window(this)); | 150 platform_window_.reset(new ui::X11Window(this)); |
143 #elif defined(OS_ANDROID) | 151 #elif defined(OS_ANDROID) |
144 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 152 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
145 #else | 153 #else |
146 NOTREACHED() << "Unsupported platform"; | 154 NOTREACHED() << "Unsupported platform"; |
147 #endif | 155 #endif |
148 } | 156 } |
149 platform_window_->SetBounds(bounds); | 157 platform_window_->SetBounds(bounds); |
150 platform_window_->Show(); | 158 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 } | 159 } |
166 | 160 |
167 DefaultDisplayManager::~DefaultDisplayManager() { | 161 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 | 162 // Destroy the PlatformWindow early on as it may call us back during |
174 // destruction and we want to be in a known state. | 163 // destruction and we want to be in a known state. |
175 platform_window_.reset(); | 164 platform_window_.reset(); |
176 } | 165 } |
177 | 166 |
178 void DefaultDisplayManager::SchedulePaint(const ServerView* view, | 167 void DefaultDisplayManager::SchedulePaint(const ServerView* view, |
179 const gfx::Rect& bounds) { | 168 const gfx::Rect& bounds) { |
180 DCHECK(view); | 169 DCHECK(view); |
181 if (!view->IsDrawn()) | 170 if (!view->IsDrawn()) |
182 return; | 171 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>()); | 204 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); |
216 auto pass = mojo::CreateDefaultPass(1, rect); | 205 auto pass = mojo::CreateDefaultPass(1, rect); |
217 pass->damage_rect = Rect::From(dirty_rect_); | 206 pass->damage_rect = Rect::From(dirty_rect_); |
218 | 207 |
219 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); | 208 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); |
220 | 209 |
221 auto frame = mojo::Frame::New(); | 210 auto frame = mojo::Frame::New(); |
222 frame->passes.push_back(pass.Pass()); | 211 frame->passes.push_back(pass.Pass()); |
223 frame->resources.resize(0u); | 212 frame->resources.resize(0u); |
224 frame_pending_ = true; | 213 frame_pending_ = true; |
225 if (display_) { | 214 if (top_level_display_client_) { |
226 display_->SubmitFrame(frame.Pass(), | 215 top_level_display_client_->SubmitFrame( |
227 base::Bind(&DefaultDisplayManager::DidDraw, | 216 frame.Pass(), |
228 weak_factory_.GetWeakPtr())); | 217 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); |
229 } | 218 } |
230 dirty_rect_ = gfx::Rect(); | 219 dirty_rect_ = gfx::Rect(); |
231 } | 220 } |
232 | 221 |
233 void DefaultDisplayManager::DidDraw() { | 222 void DefaultDisplayManager::DidDraw() { |
234 frame_pending_ = false; | 223 frame_pending_ = false; |
235 if (!dirty_rect_.IsEmpty()) | 224 if (!dirty_rect_.IsEmpty()) |
236 WantToDraw(); | 225 WantToDraw(); |
237 } | 226 } |
238 | 227 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 void DefaultDisplayManager::OnWindowStateChanged( | 329 void DefaultDisplayManager::OnWindowStateChanged( |
341 ui::PlatformWindowState new_state) { | 330 ui::PlatformWindowState new_state) { |
342 } | 331 } |
343 | 332 |
344 void DefaultDisplayManager::OnLostCapture() { | 333 void DefaultDisplayManager::OnLostCapture() { |
345 } | 334 } |
346 | 335 |
347 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( | 336 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( |
348 gfx::AcceleratedWidget widget, | 337 gfx::AcceleratedWidget widget, |
349 float device_pixel_ratio) { | 338 float device_pixel_ratio) { |
350 context_provider_->SetAcceleratedWidget(widget); | 339 top_level_display_client_.reset( |
| 340 new surfaces::TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); |
351 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 341 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
352 } | 342 } |
353 | 343 |
354 void DefaultDisplayManager::OnActivationChanged(bool active) { | 344 void DefaultDisplayManager::OnActivationChanged(bool active) { |
355 } | 345 } |
356 | 346 |
357 } // namespace view_manager | 347 } // namespace view_manager |
OLD | NEW |