| 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 29 matching lines...) Expand all Loading... |
| 40 #elif defined(OS_ANDROID) | 40 #elif defined(OS_ANDROID) |
| 41 #include "ui/platform_window/android/platform_window_android.h" | 41 #include "ui/platform_window/android/platform_window_android.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 using mojo::Rect; | 44 using mojo::Rect; |
| 45 using mojo::Size; | 45 using mojo::Size; |
| 46 | 46 |
| 47 namespace mus { | 47 namespace mus { |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // DrawViewTree recursively visits ServerViews, creating a SurfaceDrawQuad for |
| 51 // each that lacks one. For Views that already have CompositorFrames, we can |
| 52 // skip this step and let cc::SurfaceAggregator do the heavy lifting. |
| 53 // |skip_view| indicates whether or not we should generate a SurfaceDrawQuad |
| 54 // for the provided |view|. |
| 50 void DrawViewTree(cc::RenderPass* pass, | 55 void DrawViewTree(cc::RenderPass* pass, |
| 51 const ServerView* view, | 56 const ServerView* view, |
| 52 const gfx::Vector2d& parent_to_root_origin_offset, | 57 const gfx::Vector2d& parent_to_root_origin_offset, |
| 53 float opacity) { | 58 float opacity, |
| 59 bool skip_view) { |
| 54 if (!view->visible()) | 60 if (!view->visible()) |
| 55 return; | 61 return; |
| 56 | 62 |
| 57 const gfx::Rect absolute_bounds = | 63 const gfx::Rect absolute_bounds = |
| 58 view->bounds() + parent_to_root_origin_offset; | 64 view->bounds() + parent_to_root_origin_offset; |
| 65 |
| 59 std::vector<const ServerView*> children(view->GetChildren()); | 66 std::vector<const ServerView*> children(view->GetChildren()); |
| 67 // TODO(rjkroege, fsamuel): Make sure we're handling alpha correctly. |
| 60 const float combined_opacity = opacity * view->opacity(); | 68 const float combined_opacity = opacity * view->opacity(); |
| 61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); | 69 for (auto it = children.rbegin(); it != children.rend(); ++it) { |
| 62 it != children.rend(); ++it) { | |
| 63 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), | 70 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), |
| 64 combined_opacity); | 71 combined_opacity, |
| 72 view->parent() && |
| 73 !view->surface_id().is_null() /* skip_view */); |
| 65 } | 74 } |
| 66 | 75 |
| 76 if (skip_view || view->surface_id().is_null()) |
| 77 return; |
| 78 |
| 67 gfx::Transform quad_to_target_transform; | 79 gfx::Transform quad_to_target_transform; |
| 68 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 80 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
| 69 const gfx::Rect bounds_at_origin(view->bounds().size()); | 81 gfx::Rect bounds_at_origin(view->bounds().size()); |
| 82 |
| 70 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 83 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 71 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 84 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
| 72 // to be populated from CompositorFrame structs. | 85 // to be populated from CompositorFrame structs. |
| 73 sqs->SetAll( | 86 sqs->SetAll( |
| 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | 87 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
| 75 bounds_at_origin /* visible_layer_bounds */, | 88 bounds_at_origin /* visible_layer_bounds */, |
| 76 bounds_at_origin /* clip_rect */, false /* is_clipped */, view->opacity(), | 89 bounds_at_origin /* clip_rect */, false /* is_clipped */, view->opacity(), |
| 77 SkXfermode::kSrc_Mode, 0 /* sorting-context_id */); | 90 SkXfermode::kSrc_Mode, 0 /* sorting-context_id */); |
| 78 | 91 |
| 79 auto surface_quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 92 auto surface_quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void DefaultDisplayManager::SetImeVisibility(bool visible) { | 198 void DefaultDisplayManager::SetImeVisibility(bool visible) { |
| 186 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 199 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 187 if (ime) | 200 if (ime) |
| 188 ime->SetImeVisibility(visible); | 201 ime->SetImeVisibility(visible); |
| 189 } | 202 } |
| 190 | 203 |
| 191 void DefaultDisplayManager::Draw() { | 204 void DefaultDisplayManager::Draw() { |
| 192 if (!delegate_->GetRootView()->visible()) | 205 if (!delegate_->GetRootView()->visible()) |
| 193 return; | 206 return; |
| 194 | 207 |
| 195 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 208 // TODO(fsamuel): We should add a trace for generating a top level frame. |
| 196 render_pass->damage_rect = dirty_rect_; | 209 scoped_ptr<cc::CompositorFrame> frame(GenerateCompositorFrame()); |
| 197 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | |
| 198 | |
| 199 DrawViewTree(render_pass.get(), delegate_->GetRootView(), gfx::Vector2d(), | |
| 200 1.0f); | |
| 201 | |
| 202 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); | |
| 203 frame_data->device_scale_factor = 1.f; | |
| 204 frame_data->render_pass_list.push_back(render_pass.Pass()); | |
| 205 | |
| 206 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
| 207 frame->delegated_frame_data = frame_data.Pass(); | |
| 208 frame_pending_ = true; | 210 frame_pending_ = true; |
| 209 if (top_level_display_client_) { | 211 if (top_level_display_client_) { |
| 210 top_level_display_client_->SubmitCompositorFrame( | 212 top_level_display_client_->SubmitCompositorFrame( |
| 211 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, | 213 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, |
| 212 weak_factory_.GetWeakPtr())); | 214 weak_factory_.GetWeakPtr())); |
| 213 } | 215 } |
| 214 dirty_rect_ = gfx::Rect(); | 216 dirty_rect_ = gfx::Rect(); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void DefaultDisplayManager::DidDraw() { | 219 void DefaultDisplayManager::DidDraw() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 239 mojo::ViewportMetrics old_metrics; | 241 mojo::ViewportMetrics old_metrics; |
| 240 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); | 242 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); |
| 241 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; | 243 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; |
| 242 | 244 |
| 243 metrics_.size_in_pixels = mojo::Size::From(size); | 245 metrics_.size_in_pixels = mojo::Size::From(size); |
| 244 metrics_.device_pixel_ratio = device_pixel_ratio; | 246 metrics_.device_pixel_ratio = device_pixel_ratio; |
| 245 | 247 |
| 246 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 248 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 247 } | 249 } |
| 248 | 250 |
| 251 scoped_ptr<cc::CompositorFrame> |
| 252 DefaultDisplayManager::GenerateCompositorFrame() { |
| 253 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 254 render_pass->damage_rect = dirty_rect_; |
| 255 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); |
| 256 |
| 257 DrawViewTree(render_pass.get(), |
| 258 delegate_->GetRootView(), |
| 259 gfx::Vector2d(), 1.0f, |
| 260 false /* skip_view */); |
| 261 |
| 262 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); |
| 263 frame_data->device_scale_factor = metrics_.device_pixel_ratio; |
| 264 frame_data->render_pass_list.push_back(render_pass.Pass()); |
| 265 |
| 266 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 267 frame->delegated_frame_data = frame_data.Pass(); |
| 268 return frame.Pass(); |
| 269 } |
| 270 |
| 271 const cc::CompositorFrame* |
| 272 DefaultDisplayManager::GetLastCompositorFrame() const { |
| 273 if (!top_level_display_client_) |
| 274 return nullptr; |
| 275 |
| 276 return top_level_display_client_->GetLastCompositorFrame(); |
| 277 } |
| 278 |
| 249 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { | 279 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 250 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 280 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
| 251 } | 281 } |
| 252 | 282 |
| 253 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 283 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
| 254 dirty_rect_.Union(damaged_region); | 284 dirty_rect_.Union(damaged_region); |
| 255 WantToDraw(); | 285 WantToDraw(); |
| 256 } | 286 } |
| 257 | 287 |
| 258 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 288 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
| 259 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 289 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
| 260 delegate_->OnEvent(mojo_event.Pass()); | 290 ViewId id; |
| 291 if (event->IsLocatedEvent() && !!top_level_display_client_) { |
| 292 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); |
| 293 gfx::Point transformed_point; |
| 294 cc::SurfaceId target_surface = |
| 295 surfaces_state_->hit_tester()->GetTargetSurfaceAtPoint( |
| 296 top_level_display_client_->surface_id(), |
| 297 located_event->location(), |
| 298 &transformed_point); |
| 299 id = ViewIdFromTransportId( |
| 300 cc::SurfaceIdAllocator::NamespaceForId(target_surface)); |
| 301 mojo_event->pointer_data->location->x = transformed_point.x(); |
| 302 mojo_event->pointer_data->location->y = transformed_point.y(); |
| 303 } |
| 304 delegate_->OnEvent(id, mojo_event.Pass()); |
| 261 | 305 |
| 262 switch (event->type()) { | 306 switch (event->type()) { |
| 263 case ui::ET_MOUSE_PRESSED: | 307 case ui::ET_MOUSE_PRESSED: |
| 264 case ui::ET_TOUCH_PRESSED: | 308 case ui::ET_TOUCH_PRESSED: |
| 265 platform_window_->SetCapture(); | 309 platform_window_->SetCapture(); |
| 266 break; | 310 break; |
| 267 case ui::ET_MOUSE_RELEASED: | 311 case ui::ET_MOUSE_RELEASED: |
| 268 case ui::ET_TOUCH_RELEASED: | 312 case ui::ET_TOUCH_RELEASED: |
| 269 platform_window_->ReleaseCapture(); | 313 platform_window_->ReleaseCapture(); |
| 270 break; | 314 break; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 292 | 336 |
| 293 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); | 337 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); |
| 294 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 338 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 295 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 339 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 296 | 340 |
| 297 char_event.SetExtendedKeyEventData( | 341 char_event.SetExtendedKeyEventData( |
| 298 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( | 342 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( |
| 299 key_press_event->GetLocatedWindowsKeyboardCode(), | 343 key_press_event->GetLocatedWindowsKeyboardCode(), |
| 300 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); | 344 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); |
| 301 | 345 |
| 302 delegate_->OnEvent(mojo::Event::From(char_event)); | 346 delegate_->OnEvent(id, mojo::Event::From(char_event)); |
| 303 } | 347 } |
| 304 #endif | 348 #endif |
| 305 } | 349 } |
| 306 | 350 |
| 307 void DefaultDisplayManager::OnCloseRequest() { | 351 void DefaultDisplayManager::OnCloseRequest() { |
| 308 platform_window_->Close(); | 352 platform_window_->Close(); |
| 309 } | 353 } |
| 310 | 354 |
| 311 void DefaultDisplayManager::OnClosed() { | 355 void DefaultDisplayManager::OnClosed() { |
| 312 delegate_->OnDisplayClosed(); | 356 delegate_->OnDisplayClosed(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 323 if (widget != gfx::kNullAcceleratedWidget) { | 367 if (widget != gfx::kNullAcceleratedWidget) { |
| 324 top_level_display_client_.reset( | 368 top_level_display_client_.reset( |
| 325 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); | 369 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); |
| 326 } | 370 } |
| 327 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 371 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
| 328 } | 372 } |
| 329 | 373 |
| 330 void DefaultDisplayManager::OnActivationChanged(bool active) {} | 374 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
| 331 | 375 |
| 332 } // namespace mus | 376 } // namespace mus |
| OLD | NEW |