Chromium Code Reviews| 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/mus/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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 void DrawViewTree(cc::RenderPass* pass, | 50 void DrawViewTree(cc::RenderPass* pass, |
| 51 const ServerView* view, | 51 const ServerView* view, |
| 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 |
| 60 const float combined_opacity = opacity * view->opacity(); | 60 if (!view->parent() || view->surface_id().is_null()) { |
| 61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); | 61 std::vector<const ServerView*> children(view->GetChildren()); |
| 62 it != children.rend(); ++it) { | 62 const float combined_opacity = opacity * view->opacity(); |
| 63 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), | 63 for (auto it = children.rbegin(); it != children.rend(); ++it) { |
| 64 combined_opacity); | 64 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), |
|
rjkroege
2015/09/16 21:31:37
can you remind me why there are multiple view tree
Fady Samuel
2015/09/17 18:31:42
We don't really. This is recursively visiting the
| |
| 65 combined_opacity); | |
| 66 } | |
| 65 } | 67 } |
| 66 | 68 |
| 67 gfx::Transform quad_to_target_transform; | 69 gfx::Transform quad_to_target_transform; |
| 68 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 70 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
| 69 const gfx::Rect bounds_at_origin(view->bounds().size()); | 71 const gfx::Rect bounds_at_origin(view->bounds().size()); |
| 70 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 72 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 71 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 73 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
| 72 // to be populated from CompositorFrame structs. | 74 // to be populated from CompositorFrame structs. |
| 73 sqs->SetAll( | 75 sqs->SetAll( |
| 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | 76 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 if (ime) | 192 if (ime) |
| 191 ime->UpdateTextInputState(state); | 193 ime->UpdateTextInputState(state); |
| 192 } | 194 } |
| 193 | 195 |
| 194 void DefaultDisplayManager::SetImeVisibility(bool visible) { | 196 void DefaultDisplayManager::SetImeVisibility(bool visible) { |
| 195 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 197 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 196 if (ime) | 198 if (ime) |
| 197 ime->SetImeVisibility(visible); | 199 ime->SetImeVisibility(visible); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void DefaultDisplayManager::Draw() { | 202 void DefaultDisplayManager::Draw() { |
|
rjkroege
2015/09/16 21:31:37
this is the top-level draw to the display function
Fady Samuel
2015/09/17 18:31:42
To be fair, I didn't write this method :P I did ad
| |
| 201 if (!delegate_->GetRootView()->visible()) | 203 if (!delegate_->GetRootView()->visible()) |
| 202 return; | 204 return; |
| 203 | 205 |
| 204 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 206 scoped_ptr<cc::CompositorFrame> frame(GenerateCompositorFrame()); |
|
rjkroege
2015/09/16 21:31:37
you assemble the top-level OutputSurface Composito
Fady Samuel
2015/09/17 18:31:42
Done.
| |
| 205 render_pass->damage_rect = dirty_rect_; | |
| 206 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | |
| 207 | |
| 208 DrawViewTree(render_pass.get(), delegate_->GetRootView(), gfx::Vector2d(), | |
| 209 1.0f); | |
| 210 | |
| 211 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); | |
| 212 frame_data->device_scale_factor = 1.f; | |
| 213 frame_data->render_pass_list.push_back(render_pass.Pass()); | |
| 214 | |
| 215 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
| 216 frame->delegated_frame_data = frame_data.Pass(); | |
| 217 frame_pending_ = true; | 207 frame_pending_ = true; |
| 218 if (top_level_display_client_) { | 208 if (top_level_display_client_) { |
| 219 top_level_display_client_->SubmitCompositorFrame( | 209 top_level_display_client_->SubmitCompositorFrame( |
| 220 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, | 210 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, |
| 221 weak_factory_.GetWeakPtr())); | 211 weak_factory_.GetWeakPtr())); |
| 222 } | 212 } |
| 223 dirty_rect_ = gfx::Rect(); | 213 dirty_rect_ = gfx::Rect(); |
| 224 } | 214 } |
| 225 | 215 |
| 226 void DefaultDisplayManager::DidDraw() { | 216 void DefaultDisplayManager::DidDraw() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 248 mojo::ViewportMetrics old_metrics; | 238 mojo::ViewportMetrics old_metrics; |
| 249 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); | 239 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); |
| 250 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; | 240 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; |
| 251 | 241 |
| 252 metrics_.size_in_pixels = mojo::Size::From(size); | 242 metrics_.size_in_pixels = mojo::Size::From(size); |
| 253 metrics_.device_pixel_ratio = device_pixel_ratio; | 243 metrics_.device_pixel_ratio = device_pixel_ratio; |
| 254 | 244 |
| 255 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 245 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 256 } | 246 } |
| 257 | 247 |
| 248 scoped_ptr<cc::CompositorFrame> | |
| 249 DefaultDisplayManager::GenerateCompositorFrame() { | |
| 250 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | |
| 251 render_pass->damage_rect = dirty_rect_; | |
| 252 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | |
| 253 | |
| 254 DrawViewTree(render_pass.get(), | |
| 255 delegate_->GetRootView(), | |
| 256 gfx::Vector2d(), 1.0f); | |
| 257 | |
| 258 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); | |
| 259 frame_data->device_scale_factor = 1.f; | |
| 260 frame_data->render_pass_list.push_back(render_pass.Pass()); | |
| 261 | |
| 262 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
| 263 frame->delegated_frame_data = frame_data.Pass(); | |
| 264 return frame.Pass(); | |
| 265 } | |
| 266 | |
| 267 const cc::CompositorFrame* | |
| 268 DefaultDisplayManager::GetLastCompositorFrame() const { | |
| 269 if (!top_level_display_client_) | |
| 270 return nullptr; | |
| 271 | |
| 272 return top_level_display_client_->GetLastCompositorFrame(); | |
| 273 } | |
| 274 | |
| 258 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { | 275 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 259 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 276 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
| 260 } | 277 } |
| 261 | 278 |
| 262 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 279 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
| 263 dirty_rect_.Union(damaged_region); | 280 dirty_rect_.Union(damaged_region); |
| 264 WantToDraw(); | 281 WantToDraw(); |
| 265 } | 282 } |
| 266 | 283 |
| 267 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 284 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
| 268 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 285 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
| 269 if (event->IsMouseWheelEvent()) { | 286 if (event->IsMouseWheelEvent()) { |
| 270 // Mojo's event type has a different meaning for wheel events. Convert | 287 // Mojo's event type has a different meaning for wheel events. Convert |
| 271 // between the two. | 288 // between the two. |
| 272 ui::MouseWheelEvent* wheel_event = static_cast<ui::MouseWheelEvent*>(event); | 289 ui::MouseWheelEvent* wheel_event = static_cast<ui::MouseWheelEvent*>(event); |
| 273 DCHECK(mojo_event->pointer_data); | 290 DCHECK(mojo_event->pointer_data); |
| 274 mojo_event->pointer_data->horizontal_wheel = | 291 mojo_event->pointer_data->horizontal_wheel = |
| 275 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); | 292 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); |
| 276 mojo_event->pointer_data->horizontal_wheel = | 293 mojo_event->pointer_data->horizontal_wheel = |
| 277 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); | 294 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); |
| 278 } | 295 } |
| 279 delegate_->OnEvent(mojo_event.Pass()); | 296 ViewId id; |
| 297 if (event->IsLocatedEvent() && !!top_level_display_client_) { | |
| 298 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); | |
| 299 gfx::Point transformed_point; | |
| 300 cc::SurfaceId target_surface = | |
| 301 surfaces_state_->hit_tester()->GetTargetSurfaceAtPoint( | |
| 302 top_level_display_client_->surface_id(), | |
| 303 located_event->location(), | |
| 304 &transformed_point); | |
| 305 id = ViewIdFromTransportId( | |
| 306 cc::SurfaceIdAllocator::NamespaceForId(target_surface)); | |
| 307 mojo_event->pointer_data->x = transformed_point.x(); | |
|
rjkroege
2015/09/16 21:31:37
you don't translate the screen coords? they are in
Fady Samuel
2015/09/17 18:31:42
I'm not translating the screen coordinates. I'm ac
| |
| 308 mojo_event->pointer_data->y = transformed_point.y(); | |
| 309 } | |
| 310 delegate_->OnEvent(id, mojo_event.Pass()); | |
| 280 | 311 |
| 281 switch (event->type()) { | 312 switch (event->type()) { |
| 282 case ui::ET_MOUSE_PRESSED: | 313 case ui::ET_MOUSE_PRESSED: |
| 283 case ui::ET_TOUCH_PRESSED: | 314 case ui::ET_TOUCH_PRESSED: |
| 284 platform_window_->SetCapture(); | 315 platform_window_->SetCapture(); |
| 285 break; | 316 break; |
| 286 case ui::ET_MOUSE_RELEASED: | 317 case ui::ET_MOUSE_RELEASED: |
| 287 case ui::ET_TOUCH_RELEASED: | 318 case ui::ET_TOUCH_RELEASED: |
| 288 platform_window_->ReleaseCapture(); | 319 platform_window_->ReleaseCapture(); |
| 289 break; | 320 break; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 312 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); | 343 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); |
| 313 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 344 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 314 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 345 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 315 | 346 |
| 316 char_event.SetExtendedKeyEventData( | 347 char_event.SetExtendedKeyEventData( |
| 317 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( | 348 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( |
| 318 key_press_event->GetLocatedWindowsKeyboardCode(), | 349 key_press_event->GetLocatedWindowsKeyboardCode(), |
| 319 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); | 350 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); |
| 320 char_event.set_platform_keycode(key_press_event->platform_keycode()); | 351 char_event.set_platform_keycode(key_press_event->platform_keycode()); |
| 321 | 352 |
| 322 delegate_->OnEvent(mojo::Event::From(char_event)); | 353 delegate_->OnEvent(id, mojo::Event::From(char_event)); |
| 323 } | 354 } |
| 324 #endif | 355 #endif |
| 325 } | 356 } |
| 326 | 357 |
| 327 void DefaultDisplayManager::OnCloseRequest() { | 358 void DefaultDisplayManager::OnCloseRequest() { |
| 328 platform_window_->Close(); | 359 platform_window_->Close(); |
| 329 } | 360 } |
| 330 | 361 |
| 331 void DefaultDisplayManager::OnClosed() { | 362 void DefaultDisplayManager::OnClosed() { |
| 332 delegate_->OnDisplayClosed(); | 363 delegate_->OnDisplayClosed(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 343 if (widget != gfx::kNullAcceleratedWidget) { | 374 if (widget != gfx::kNullAcceleratedWidget) { |
| 344 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( | 375 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( |
| 345 widget, gpu_state_, surfaces_state_)); | 376 widget, gpu_state_, surfaces_state_)); |
| 346 } | 377 } |
| 347 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 378 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
| 348 } | 379 } |
| 349 | 380 |
| 350 void DefaultDisplayManager::OnActivationChanged(bool active) {} | 381 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
| 351 | 382 |
| 352 } // namespace view_manager | 383 } // namespace view_manager |
| OLD | NEW |