| 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 "cc/output/compositor_frame.h" |
| 9 #include "cc/output/delegated_frame_data.h" |
| 10 #include "cc/quads/render_pass.h" |
| 11 #include "cc/quads/shared_quad_state.h" |
| 12 #include "cc/quads/surface_draw_quad.h" |
| 8 #include "components/view_manager/display_manager_factory.h" | 13 #include "components/view_manager/display_manager_factory.h" |
| 9 #include "components/view_manager/gles2/gpu_state.h" | 14 #include "components/view_manager/gles2/gpu_state.h" |
| 10 #include "components/view_manager/public/interfaces/gpu.mojom.h" | 15 #include "components/view_manager/public/interfaces/gpu.mojom.h" |
| 11 #include "components/view_manager/public/interfaces/quads.mojom.h" | 16 #include "components/view_manager/public/interfaces/quads.mojom.h" |
| 12 #include "components/view_manager/public/interfaces/surfaces.mojom.h" | 17 #include "components/view_manager/public/interfaces/surfaces.mojom.h" |
| 13 #include "components/view_manager/server_view.h" | 18 #include "components/view_manager/server_view.h" |
| 14 #include "components/view_manager/surfaces/surfaces_state.h" | 19 #include "components/view_manager/surfaces/surfaces_state.h" |
| 15 #include "components/view_manager/view_coordinate_conversions.h" | 20 #include "components/view_manager/view_coordinate_conversions.h" |
| 16 #include "mojo/application/public/cpp/application_connection.h" | 21 #include "mojo/application/public/cpp/application_connection.h" |
| 17 #include "mojo/application/public/cpp/application_impl.h" | 22 #include "mojo/application/public/cpp/application_impl.h" |
| 18 #include "mojo/converters/geometry/geometry_type_converters.h" | 23 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 19 #include "mojo/converters/input_events/input_events_type_converters.h" | 24 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 20 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" | 25 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" |
| 21 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 26 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 22 #include "mojo/converters/surfaces/surfaces_utils.h" | 27 #include "mojo/converters/surfaces/surfaces_utils.h" |
| 23 #include "mojo/converters/transform/transform_type_converters.h" | 28 #include "mojo/converters/transform/transform_type_converters.h" |
| 29 #include "third_party/skia/include/core/SkXfermode.h" |
| 24 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
| 25 #include "ui/events/event_utils.h" | 31 #include "ui/events/event_utils.h" |
| 26 #include "ui/platform_window/platform_ime_controller.h" | 32 #include "ui/platform_window/platform_ime_controller.h" |
| 27 #include "ui/platform_window/platform_window.h" | 33 #include "ui/platform_window/platform_window.h" |
| 28 #include "ui/platform_window/stub/stub_window.h" | 34 #include "ui/platform_window/stub/stub_window.h" |
| 29 | 35 |
| 30 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 31 #include "ui/platform_window/win/win_window.h" | 37 #include "ui/platform_window/win/win_window.h" |
| 32 #elif defined(USE_X11) | 38 #elif defined(USE_X11) |
| 33 #include "ui/platform_window/x11/x11_window.h" | 39 #include "ui/platform_window/x11/x11_window.h" |
| 34 #elif defined(OS_ANDROID) | 40 #elif defined(OS_ANDROID) |
| 35 #include "ui/platform_window/android/platform_window_android.h" | 41 #include "ui/platform_window/android/platform_window_android.h" |
| 36 #endif | 42 #endif |
| 37 | 43 |
| 38 using mojo::Rect; | 44 using mojo::Rect; |
| 39 using mojo::Size; | 45 using mojo::Size; |
| 40 | 46 |
| 41 namespace view_manager { | 47 namespace view_manager { |
| 42 namespace { | 48 namespace { |
| 43 | 49 |
| 44 void DrawViewTree(mojo::Pass* pass, | 50 void DrawViewTree(cc::RenderPass* pass, |
| 45 const ServerView* view, | 51 const ServerView* view, |
| 46 const gfx::Vector2d& parent_to_root_origin_offset, | 52 const gfx::Vector2d& parent_to_root_origin_offset, |
| 47 float opacity) { | 53 float opacity) { |
| 48 if (!view->visible()) | 54 if (!view->visible()) |
| 49 return; | 55 return; |
| 50 | 56 |
| 51 const gfx::Rect absolute_bounds = | 57 const gfx::Rect absolute_bounds = |
| 52 view->bounds() + parent_to_root_origin_offset; | 58 view->bounds() + parent_to_root_origin_offset; |
| 53 std::vector<const ServerView*> children(view->GetChildren()); | 59 std::vector<const ServerView*> children(view->GetChildren()); |
| 54 const float combined_opacity = opacity * view->opacity(); | 60 const float combined_opacity = opacity * view->opacity(); |
| 55 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); | 61 for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin(); |
| 56 it != children.rend(); | 62 it != children.rend(); |
| 57 ++it) { | 63 ++it) { |
| 58 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), | 64 DrawViewTree(pass, *it, absolute_bounds.OffsetFromOrigin(), |
| 59 combined_opacity); | 65 combined_opacity); |
| 60 } | 66 } |
| 61 | 67 |
| 62 cc::SurfaceId node_id = view->surface_id(); | |
| 63 | |
| 64 auto surface_quad_state = mojo::SurfaceQuadState::New(); | |
| 65 surface_quad_state->surface = mojo::SurfaceId::From(node_id); | |
| 66 | |
| 67 gfx::Transform node_transform; | 68 gfx::Transform node_transform; |
| 68 node_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 69 node_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
| 70 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 71 sqs->SetAll(node_transform /* quad_to_target_transform */, |
| 72 view->bounds().size() /* layer_bounds */, |
| 73 gfx::Rect(view->bounds().size()) /* visible_layer_rect */, |
| 74 gfx::Rect(view->bounds().size()) /* clip_rect */, |
| 75 false /* is_clipped */, |
| 76 view->opacity() /* opacity */, |
| 77 SkXfermode::kSrc_Mode, |
| 78 0 /* sorting-context_id */); |
| 69 | 79 |
| 70 const gfx::Rect bounds_at_origin(view->bounds().size()); | 80 const gfx::Rect bounds_at_origin(view->bounds().size()); |
| 71 auto surface_quad = mojo::Quad::New(); | 81 auto surface_quad = |
| 72 surface_quad->material = mojo::Material::MATERIAL_SURFACE_CONTENT; | 82 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 73 surface_quad->rect = Rect::From(bounds_at_origin); | 83 surface_quad->SetNew(sqs, |
| 74 surface_quad->opaque_rect = Rect::From(bounds_at_origin); | 84 bounds_at_origin /* rect */, |
| 75 surface_quad->visible_rect = Rect::From(bounds_at_origin); | 85 bounds_at_origin /* visible_rect */, |
| 76 surface_quad->needs_blending = true; | 86 view->surface_id()); |
| 77 surface_quad->shared_quad_state_index = | |
| 78 base::saturated_cast<int32_t>(pass->shared_quad_states.size()); | |
| 79 surface_quad->surface_quad_state = surface_quad_state.Pass(); | |
| 80 | |
| 81 auto sqs = mojo::CreateDefaultSQS(view->bounds().size()); | |
| 82 sqs->blend_mode = mojo::SK_XFERMODE_kSrcOver_Mode; | |
| 83 sqs->opacity = combined_opacity; | |
| 84 sqs->quad_to_target_transform = mojo::Transform::From(node_transform); | |
| 85 | |
| 86 pass->quads.push_back(surface_quad.Pass()); | |
| 87 pass->shared_quad_states.push_back(sqs.Pass()); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 float ConvertUIWheelValueToMojoValue(int offset) { | 89 float ConvertUIWheelValueToMojoValue(int offset) { |
| 91 // Mojo's event type takes a value between -1 and 1. Normalize by allowing | 90 // Mojo's event type takes a value between -1 and 1. Normalize by allowing |
| 92 // up to 20 of ui's offset. This is a bit arbitrary. | 91 // up to 20 of ui's offset. This is a bit arbitrary. |
| 93 return std::max( | 92 return std::max( |
| 94 -1.0f, std::min(1.0f, static_cast<float>(offset) / | 93 -1.0f, std::min(1.0f, static_cast<float>(offset) / |
| 95 (20 * static_cast<float>( | 94 (20 * static_cast<float>( |
| 96 ui::MouseWheelEvent::kWheelDelta)))); | 95 ui::MouseWheelEvent::kWheelDelta)))); |
| 97 } | 96 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 193 |
| 195 void DefaultDisplayManager::SetImeVisibility(bool visible) { | 194 void DefaultDisplayManager::SetImeVisibility(bool visible) { |
| 196 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 195 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 197 if (ime) | 196 if (ime) |
| 198 ime->SetImeVisibility(visible); | 197 ime->SetImeVisibility(visible); |
| 199 } | 198 } |
| 200 | 199 |
| 201 void DefaultDisplayManager::Draw() { | 200 void DefaultDisplayManager::Draw() { |
| 202 if (!delegate_->GetRootView()->visible()) | 201 if (!delegate_->GetRootView()->visible()) |
| 203 return; | 202 return; |
| 204 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); | |
| 205 auto pass = mojo::CreateDefaultPass(1, rect); | |
| 206 pass->damage_rect = Rect::From(dirty_rect_); | |
| 207 | 203 |
| 208 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); | 204 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 205 render_pass->damage_rect = dirty_rect_; |
| 206 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); |
| 209 | 207 |
| 210 auto frame = mojo::Frame::New(); | 208 DrawViewTree(render_pass.get(), |
| 211 frame->passes.push_back(pass.Pass()); | 209 delegate_->GetRootView(), |
| 212 frame->resources.resize(0u); | 210 gfx::Vector2d(), 1.0f); |
| 211 |
| 212 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); |
| 213 frame_data->device_scale_factor = 1.f; |
| 214 frame_data->render_pass_list.push_back(render_pass.Pass()); |
| 215 |
| 216 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 217 frame->delegated_frame_data = frame_data.Pass(); |
| 213 frame_pending_ = true; | 218 frame_pending_ = true; |
| 214 if (top_level_display_client_) { | 219 if (top_level_display_client_) { |
| 215 top_level_display_client_->SubmitFrame( | 220 top_level_display_client_->SubmitFrame( |
| 216 frame.Pass(), | 221 frame.Pass(), |
| 217 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); | 222 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); |
| 218 } | 223 } |
| 219 dirty_rect_ = gfx::Rect(); | 224 dirty_rect_ = gfx::Rect(); |
| 220 } | 225 } |
| 221 | 226 |
| 222 void DefaultDisplayManager::DidDraw() { | 227 void DefaultDisplayManager::DidDraw() { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 float device_pixel_ratio) { | 343 float device_pixel_ratio) { |
| 339 top_level_display_client_.reset( | 344 top_level_display_client_.reset( |
| 340 new surfaces::TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); | 345 new surfaces::TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); |
| 341 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 346 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
| 342 } | 347 } |
| 343 | 348 |
| 344 void DefaultDisplayManager::OnActivationChanged(bool active) { | 349 void DefaultDisplayManager::OnActivationChanged(bool active) { |
| 345 } | 350 } |
| 346 | 351 |
| 347 } // namespace view_manager | 352 } // namespace view_manager |
| OLD | NEW |