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/mus/display_manager.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/delegated_frame_data.h" | 9 #include "cc/output/delegated_frame_data.h" |
10 #include "cc/quads/render_pass.h" | 10 #include "cc/quads/render_pass.h" |
11 #include "cc/quads/shared_quad_state.h" | 11 #include "cc/quads/shared_quad_state.h" |
12 #include "cc/quads/surface_draw_quad.h" | 12 #include "cc/quads/surface_draw_quad.h" |
13 #include "components/view_manager/display_manager_factory.h" | 13 #include "components/mus/display_manager_factory.h" |
14 #include "components/view_manager/gles2/gpu_state.h" | 14 #include "components/mus/gles2/gpu_state.h" |
15 #include "components/view_manager/public/interfaces/gpu.mojom.h" | 15 #include "components/mus/public/interfaces/gpu.mojom.h" |
16 #include "components/view_manager/public/interfaces/quads.mojom.h" | 16 #include "components/mus/public/interfaces/quads.mojom.h" |
17 #include "components/view_manager/server_view.h" | 17 #include "components/mus/server_view.h" |
18 #include "components/view_manager/surfaces/surfaces_state.h" | 18 #include "components/mus/surfaces/surfaces_state.h" |
19 #include "components/view_manager/view_coordinate_conversions.h" | 19 #include "components/mus/view_coordinate_conversions.h" |
20 #include "mojo/application/public/cpp/application_connection.h" | 20 #include "mojo/application/public/cpp/application_connection.h" |
21 #include "mojo/application/public/cpp/application_impl.h" | 21 #include "mojo/application/public/cpp/application_impl.h" |
22 #include "mojo/converters/geometry/geometry_type_converters.h" | 22 #include "mojo/converters/geometry/geometry_type_converters.h" |
23 #include "mojo/converters/input_events/input_events_type_converters.h" | 23 #include "mojo/converters/input_events/input_events_type_converters.h" |
24 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" | 24 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" |
25 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 25 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
26 #include "mojo/converters/surfaces/surfaces_utils.h" | 26 #include "mojo/converters/surfaces/surfaces_utils.h" |
27 #include "mojo/converters/transform/transform_type_converters.h" | 27 #include "mojo/converters/transform/transform_type_converters.h" |
28 #include "third_party/skia/include/core/SkXfermode.h" | 28 #include "third_party/skia/include/core/SkXfermode.h" |
29 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
(...skipping 22 matching lines...) Expand all Loading... |
52 const gfx::Vector2d& parent_to_root_origin_offset, | 52 const gfx::Vector2d& parent_to_root_origin_offset, |
53 float opacity) { | 53 float opacity) { |
54 if (!view->visible()) | 54 if (!view->visible()) |
55 return; | 55 return; |
56 | 56 |
57 const gfx::Rect absolute_bounds = | 57 const gfx::Rect absolute_bounds = |
58 view->bounds() + parent_to_root_origin_offset; | 58 view->bounds() + parent_to_root_origin_offset; |
59 std::vector<const ServerView*> children(view->GetChildren()); | 59 std::vector<const ServerView*> children(view->GetChildren()); |
60 const float combined_opacity = opacity * view->opacity(); | 60 const float combined_opacity = opacity * view->opacity(); |
61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); | 61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); |
62 it != children.rend(); | 62 it != children.rend(); ++it) { |
63 ++it) { | |
64 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), | 63 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), |
65 combined_opacity); | 64 combined_opacity); |
66 } | 65 } |
67 | 66 |
68 gfx::Transform quad_to_target_transform; | 67 gfx::Transform quad_to_target_transform; |
69 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 68 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
70 const gfx::Rect bounds_at_origin(view->bounds().size()); | 69 const gfx::Rect bounds_at_origin(view->bounds().size()); |
71 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 70 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
72 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 71 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
73 // to be populated from CompositorFrame structs. | 72 // to be populated from CompositorFrame structs. |
74 sqs->SetAll(quad_to_target_transform, | 73 sqs->SetAll( |
75 bounds_at_origin.size() /* layer_bounds */, | 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
76 bounds_at_origin /* visible_layer_bounds */, | 75 bounds_at_origin /* visible_layer_bounds */, |
77 bounds_at_origin /* clip_rect */, | 76 bounds_at_origin /* clip_rect */, false /* is_clipped */, view->opacity(), |
78 false /* is_clipped */, | 77 SkXfermode::kSrc_Mode, 0 /* sorting-context_id */); |
79 view->opacity(), | |
80 SkXfermode::kSrc_Mode, | |
81 0 /* sorting-context_id */); | |
82 | 78 |
83 auto surface_quad = | 79 auto surface_quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
84 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 80 surface_quad->SetNew(sqs, bounds_at_origin /* rect */, |
85 surface_quad->SetNew(sqs, | 81 bounds_at_origin /* visible_rect */, view->surface_id()); |
86 bounds_at_origin /* rect */, | |
87 bounds_at_origin /* visible_rect */, | |
88 view->surface_id()); | |
89 } | 82 } |
90 | 83 |
91 float ConvertUIWheelValueToMojoValue(int offset) { | 84 float ConvertUIWheelValueToMojoValue(int offset) { |
92 // Mojo's event type takes a value between -1 and 1. Normalize by allowing | 85 // Mojo's event type takes a value between -1 and 1. Normalize by allowing |
93 // up to 20 of ui's offset. This is a bit arbitrary. | 86 // up to 20 of ui's offset. This is a bit arbitrary. |
94 return std::max( | 87 return std::max( |
95 -1.0f, std::min(1.0f, static_cast<float>(offset) / | 88 -1.0f, std::min(1.0f, static_cast<float>(offset) / |
96 (20 * static_cast<float>( | 89 (20 * static_cast<float>( |
97 ui::MouseWheelEvent::kWheelDelta)))); | 90 ui::MouseWheelEvent::kWheelDelta)))); |
98 } | 91 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 198 } |
206 | 199 |
207 void DefaultDisplayManager::Draw() { | 200 void DefaultDisplayManager::Draw() { |
208 if (!delegate_->GetRootView()->visible()) | 201 if (!delegate_->GetRootView()->visible()) |
209 return; | 202 return; |
210 | 203 |
211 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 204 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
212 render_pass->damage_rect = dirty_rect_; | 205 render_pass->damage_rect = dirty_rect_; |
213 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | 206 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); |
214 | 207 |
215 DrawViewTree(render_pass.get(), | 208 DrawViewTree(render_pass.get(), delegate_->GetRootView(), gfx::Vector2d(), |
216 delegate_->GetRootView(), | 209 1.0f); |
217 gfx::Vector2d(), 1.0f); | |
218 | 210 |
219 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); | 211 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); |
220 frame_data->device_scale_factor = 1.f; | 212 frame_data->device_scale_factor = 1.f; |
221 frame_data->render_pass_list.push_back(render_pass.Pass()); | 213 frame_data->render_pass_list.push_back(render_pass.Pass()); |
222 | 214 |
223 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 215 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
224 frame->delegated_frame_data = frame_data.Pass(); | 216 frame->delegated_frame_data = frame_data.Pass(); |
225 frame_pending_ = true; | 217 frame_pending_ = true; |
226 if (top_level_display_client_) { | 218 if (top_level_display_client_) { |
227 top_level_display_client_->SubmitCompositorFrame( | 219 top_level_display_client_->SubmitCompositorFrame( |
228 frame.Pass(), | 220 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, |
229 base::Bind(&DefaultDisplayManager::DidDraw, | 221 weak_factory_.GetWeakPtr())); |
230 weak_factory_.GetWeakPtr())); | |
231 } | 222 } |
232 dirty_rect_ = gfx::Rect(); | 223 dirty_rect_ = gfx::Rect(); |
233 } | 224 } |
234 | 225 |
235 void DefaultDisplayManager::DidDraw() { | 226 void DefaultDisplayManager::DidDraw() { |
236 frame_pending_ = false; | 227 frame_pending_ = false; |
237 if (!dirty_rect_.IsEmpty()) | 228 if (!dirty_rect_.IsEmpty()) |
238 WantToDraw(); | 229 WantToDraw(); |
239 } | 230 } |
240 | 231 |
(...skipping 30 matching lines...) Expand all Loading... |
271 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 262 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
272 dirty_rect_.Union(damaged_region); | 263 dirty_rect_.Union(damaged_region); |
273 WantToDraw(); | 264 WantToDraw(); |
274 } | 265 } |
275 | 266 |
276 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 267 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
277 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 268 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
278 if (event->IsMouseWheelEvent()) { | 269 if (event->IsMouseWheelEvent()) { |
279 // Mojo's event type has a different meaning for wheel events. Convert | 270 // Mojo's event type has a different meaning for wheel events. Convert |
280 // between the two. | 271 // between the two. |
281 ui::MouseWheelEvent* wheel_event = | 272 ui::MouseWheelEvent* wheel_event = static_cast<ui::MouseWheelEvent*>(event); |
282 static_cast<ui::MouseWheelEvent*>(event); | |
283 DCHECK(mojo_event->pointer_data); | 273 DCHECK(mojo_event->pointer_data); |
284 mojo_event->pointer_data->horizontal_wheel = | 274 mojo_event->pointer_data->horizontal_wheel = |
285 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); | 275 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); |
286 mojo_event->pointer_data->horizontal_wheel = | 276 mojo_event->pointer_data->horizontal_wheel = |
287 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); | 277 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); |
288 } | 278 } |
289 delegate_->OnEvent(mojo_event.Pass()); | 279 delegate_->OnEvent(mojo_event.Pass()); |
290 | 280 |
291 switch (event->type()) { | 281 switch (event->type()) { |
292 case ui::ET_MOUSE_PRESSED: | 282 case ui::ET_MOUSE_PRESSED: |
(...skipping 26 matching lines...) Expand all Loading... |
319 key_press_event->key_code(), | 309 key_press_event->key_code(), |
320 key_press_event->flags()); | 310 key_press_event->flags()); |
321 | 311 |
322 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); | 312 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); |
323 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 313 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
324 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 314 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
325 | 315 |
326 char_event.SetExtendedKeyEventData( | 316 char_event.SetExtendedKeyEventData( |
327 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( | 317 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( |
328 key_press_event->GetLocatedWindowsKeyboardCode(), | 318 key_press_event->GetLocatedWindowsKeyboardCode(), |
329 key_press_event->GetText(), | 319 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); |
330 key_press_event->GetUnmodifiedText()))); | |
331 char_event.set_platform_keycode(key_press_event->platform_keycode()); | 320 char_event.set_platform_keycode(key_press_event->platform_keycode()); |
332 | 321 |
333 delegate_->OnEvent(mojo::Event::From(char_event)); | 322 delegate_->OnEvent(mojo::Event::From(char_event)); |
334 } | 323 } |
335 #endif | 324 #endif |
336 } | 325 } |
337 | 326 |
338 void DefaultDisplayManager::OnCloseRequest() { | 327 void DefaultDisplayManager::OnCloseRequest() { |
339 platform_window_->Close(); | 328 platform_window_->Close(); |
340 } | 329 } |
341 | 330 |
342 void DefaultDisplayManager::OnClosed() { | 331 void DefaultDisplayManager::OnClosed() { |
343 delegate_->OnDisplayClosed(); | 332 delegate_->OnDisplayClosed(); |
344 } | 333 } |
345 | 334 |
346 void DefaultDisplayManager::OnWindowStateChanged( | 335 void DefaultDisplayManager::OnWindowStateChanged( |
347 ui::PlatformWindowState new_state) { | 336 ui::PlatformWindowState new_state) {} |
348 } | |
349 | 337 |
350 void DefaultDisplayManager::OnLostCapture() { | 338 void DefaultDisplayManager::OnLostCapture() {} |
351 } | |
352 | 339 |
353 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( | 340 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( |
354 gfx::AcceleratedWidget widget, | 341 gfx::AcceleratedWidget widget, |
355 float device_pixel_ratio) { | 342 float device_pixel_ratio) { |
356 if (widget != gfx::kNullAcceleratedWidget) { | 343 if (widget != gfx::kNullAcceleratedWidget) { |
357 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( | 344 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( |
358 widget, gpu_state_, surfaces_state_)); | 345 widget, gpu_state_, surfaces_state_)); |
359 } | 346 } |
360 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 347 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
361 } | 348 } |
362 | 349 |
363 void DefaultDisplayManager::OnActivationChanged(bool active) { | 350 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
364 } | |
365 | 351 |
366 } // namespace view_manager | 352 } // namespace view_manager |
OLD | NEW |