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 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. | |
|
rjkroege
2015/09/17 19:03:56
this code is all on the critical redraw path?
On
Fady Samuel
2015/09/17 20:00:21
GenerateCompositorFrame is the top level call. Do
| |
| 50 void DrawViewTree(cc::RenderPass* pass, | 53 void DrawViewTree(cc::RenderPass* pass, |
| 51 const ServerView* view, | 54 const ServerView* view, |
| 52 const gfx::Vector2d& parent_to_root_origin_offset, | 55 const gfx::Vector2d& parent_to_root_origin_offset, |
| 53 float opacity) { | 56 float opacity) { |
| 54 if (!view->visible()) | 57 if (!view->visible()) |
| 55 return; | 58 return; |
| 56 | 59 |
| 57 const gfx::Rect absolute_bounds = | 60 const gfx::Rect absolute_bounds = |
| 58 view->bounds() + parent_to_root_origin_offset; | 61 view->bounds() + parent_to_root_origin_offset; |
| 59 std::vector<const ServerView*> children(view->GetChildren()); | 62 |
| 60 const float combined_opacity = opacity * view->opacity(); | 63 if (!view->parent() || view->surface_id().is_null()) { |
| 61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); | 64 std::vector<const ServerView*> children(view->GetChildren()); |
| 62 it != children.rend(); ++it) { | 65 const float combined_opacity = opacity * view->opacity(); |
|
rjkroege
2015/09/17 19:08:05
do we have pre-multiplied alpha? if we do (pre-mul
Fady Samuel
2015/09/17 20:00:21
Done.
| |
| 63 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), | 66 for (auto it = children.rbegin(); it != children.rend(); ++it) { |
| 64 combined_opacity); | 67 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), |
| 68 combined_opacity); | |
| 69 } | |
| 65 } | 70 } |
| 66 | 71 |
| 67 gfx::Transform quad_to_target_transform; | 72 gfx::Transform quad_to_target_transform; |
| 68 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 73 quad_to_target_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
| 69 const gfx::Rect bounds_at_origin(view->bounds().size()); | 74 const gfx::Rect bounds_at_origin(view->bounds().size()); |
| 70 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 75 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 71 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 76 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
| 72 // to be populated from CompositorFrame structs. | 77 // to be populated from CompositorFrame structs. |
| 73 sqs->SetAll( | 78 sqs->SetAll( |
| 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | 79 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 void DefaultDisplayManager::SetImeVisibility(bool visible) { | 190 void DefaultDisplayManager::SetImeVisibility(bool visible) { |
| 186 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 191 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 187 if (ime) | 192 if (ime) |
| 188 ime->SetImeVisibility(visible); | 193 ime->SetImeVisibility(visible); |
| 189 } | 194 } |
| 190 | 195 |
| 191 void DefaultDisplayManager::Draw() { | 196 void DefaultDisplayManager::Draw() { |
| 192 if (!delegate_->GetRootView()->visible()) | 197 if (!delegate_->GetRootView()->visible()) |
| 193 return; | 198 return; |
| 194 | 199 |
| 195 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 200 // TODO(fsamuel): We should add a trace for generating a top level frame. |
| 196 render_pass->damage_rect = dirty_rect_; | 201 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; | 202 frame_pending_ = true; |
| 209 if (top_level_display_client_) { | 203 if (top_level_display_client_) { |
| 210 top_level_display_client_->SubmitCompositorFrame( | 204 top_level_display_client_->SubmitCompositorFrame( |
| 211 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, | 205 frame.Pass(), base::Bind(&DefaultDisplayManager::DidDraw, |
| 212 weak_factory_.GetWeakPtr())); | 206 weak_factory_.GetWeakPtr())); |
| 213 } | 207 } |
| 214 dirty_rect_ = gfx::Rect(); | 208 dirty_rect_ = gfx::Rect(); |
| 215 } | 209 } |
| 216 | 210 |
| 217 void DefaultDisplayManager::DidDraw() { | 211 void DefaultDisplayManager::DidDraw() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 239 mojo::ViewportMetrics old_metrics; | 233 mojo::ViewportMetrics old_metrics; |
| 240 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); | 234 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); |
| 241 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; | 235 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; |
| 242 | 236 |
| 243 metrics_.size_in_pixels = mojo::Size::From(size); | 237 metrics_.size_in_pixels = mojo::Size::From(size); |
| 244 metrics_.device_pixel_ratio = device_pixel_ratio; | 238 metrics_.device_pixel_ratio = device_pixel_ratio; |
| 245 | 239 |
| 246 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 240 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 247 } | 241 } |
| 248 | 242 |
| 243 scoped_ptr<cc::CompositorFrame> | |
| 244 DefaultDisplayManager::GenerateCompositorFrame() { | |
| 245 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | |
| 246 render_pass->damage_rect = dirty_rect_; | |
| 247 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | |
| 248 | |
| 249 DrawViewTree(render_pass.get(), | |
| 250 delegate_->GetRootView(), | |
| 251 gfx::Vector2d(), 1.0f); | |
| 252 | |
| 253 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); | |
| 254 frame_data->device_scale_factor = 1.f; | |
|
rjkroege
2015/09/17 19:08:05
? won't this break native apps that have their CF
Fady Samuel
2015/09/17 20:00:21
Done.
| |
| 255 frame_data->render_pass_list.push_back(render_pass.Pass()); | |
| 256 | |
| 257 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | |
| 258 frame->delegated_frame_data = frame_data.Pass(); | |
| 259 return frame.Pass(); | |
| 260 } | |
| 261 | |
| 262 const cc::CompositorFrame* | |
| 263 DefaultDisplayManager::GetLastCompositorFrame() const { | |
| 264 if (!top_level_display_client_) | |
| 265 return nullptr; | |
| 266 | |
| 267 return top_level_display_client_->GetLastCompositorFrame(); | |
| 268 } | |
| 269 | |
| 249 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { | 270 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 250 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 271 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
| 251 } | 272 } |
| 252 | 273 |
| 253 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 274 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
| 254 dirty_rect_.Union(damaged_region); | 275 dirty_rect_.Union(damaged_region); |
| 255 WantToDraw(); | 276 WantToDraw(); |
| 256 } | 277 } |
| 257 | 278 |
| 258 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 279 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
| 259 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 280 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
| 260 delegate_->OnEvent(mojo_event.Pass()); | 281 ViewId id; |
| 282 if (event->IsLocatedEvent() && !!top_level_display_client_) { | |
| 283 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); | |
| 284 gfx::Point transformed_point; | |
| 285 cc::SurfaceId target_surface = | |
| 286 surfaces_state_->hit_tester()->GetTargetSurfaceAtPoint( | |
| 287 top_level_display_client_->surface_id(), | |
| 288 located_event->location(), | |
| 289 &transformed_point); | |
| 290 id = ViewIdFromTransportId( | |
| 291 cc::SurfaceIdAllocator::NamespaceForId(target_surface)); | |
| 292 mojo_event->pointer_data->location->x = transformed_point.x(); | |
| 293 mojo_event->pointer_data->location->y = transformed_point.y(); | |
| 294 } | |
| 295 delegate_->OnEvent(id, mojo_event.Pass()); | |
| 261 | 296 |
| 262 switch (event->type()) { | 297 switch (event->type()) { |
| 263 case ui::ET_MOUSE_PRESSED: | 298 case ui::ET_MOUSE_PRESSED: |
| 264 case ui::ET_TOUCH_PRESSED: | 299 case ui::ET_TOUCH_PRESSED: |
| 265 platform_window_->SetCapture(); | 300 platform_window_->SetCapture(); |
| 266 break; | 301 break; |
| 267 case ui::ET_MOUSE_RELEASED: | 302 case ui::ET_MOUSE_RELEASED: |
| 268 case ui::ET_TOUCH_RELEASED: | 303 case ui::ET_TOUCH_RELEASED: |
| 269 platform_window_->ReleaseCapture(); | 304 platform_window_->ReleaseCapture(); |
| 270 break; | 305 break; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 292 | 327 |
| 293 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); | 328 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); |
| 294 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 329 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 295 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 330 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 296 | 331 |
| 297 char_event.SetExtendedKeyEventData( | 332 char_event.SetExtendedKeyEventData( |
| 298 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( | 333 make_scoped_ptr(new mojo::MojoExtendedKeyEventData( |
| 299 key_press_event->GetLocatedWindowsKeyboardCode(), | 334 key_press_event->GetLocatedWindowsKeyboardCode(), |
| 300 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); | 335 key_press_event->GetText(), key_press_event->GetUnmodifiedText()))); |
| 301 | 336 |
| 302 delegate_->OnEvent(mojo::Event::From(char_event)); | 337 delegate_->OnEvent(id, mojo::Event::From(char_event)); |
| 303 } | 338 } |
| 304 #endif | 339 #endif |
| 305 } | 340 } |
| 306 | 341 |
| 307 void DefaultDisplayManager::OnCloseRequest() { | 342 void DefaultDisplayManager::OnCloseRequest() { |
| 308 platform_window_->Close(); | 343 platform_window_->Close(); |
| 309 } | 344 } |
| 310 | 345 |
| 311 void DefaultDisplayManager::OnClosed() { | 346 void DefaultDisplayManager::OnClosed() { |
| 312 delegate_->OnDisplayClosed(); | 347 delegate_->OnDisplayClosed(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 323 if (widget != gfx::kNullAcceleratedWidget) { | 358 if (widget != gfx::kNullAcceleratedWidget) { |
| 324 top_level_display_client_.reset( | 359 top_level_display_client_.reset( |
| 325 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); | 360 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); |
| 326 } | 361 } |
| 327 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 362 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
| 328 } | 363 } |
| 329 | 364 |
| 330 void DefaultDisplayManager::OnActivationChanged(bool active) {} | 365 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
| 331 | 366 |
| 332 } // namespace mus | 367 } // namespace mus |
| OLD | NEW |