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 "services/view_manager/display_manager.h" | 5 #include "services/view_manager/display_manager.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "mojo/converters/geometry/geometry_type_converters.h" | 8 #include "mojo/converters/geometry/geometry_type_converters.h" |
9 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 9 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
12 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" | 12 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
13 #include "mojo/services/surfaces/public/cpp/surfaces_utils.h" | 13 #include "mojo/services/surfaces/public/cpp/surfaces_utils.h" |
14 #include "mojo/services/surfaces/public/interfaces/quads.mojom.h" | 14 #include "mojo/services/surfaces/public/interfaces/quads.mojom.h" |
15 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 15 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
16 #include "services/view_manager/connection_manager.h" | 16 #include "services/view_manager/connection_manager.h" |
17 #include "services/view_manager/server_view.h" | 17 #include "services/view_manager/server_view.h" |
18 #include "services/view_manager/view_coordinate_conversions.h" | 18 #include "services/view_manager/view_coordinate_conversions.h" |
19 | 19 |
20 using mojo::Rect; | |
21 using mojo::Size; | |
22 | |
23 namespace view_manager { | 20 namespace view_manager { |
24 namespace { | 21 namespace { |
25 | 22 |
26 void DrawViewTree(mojo::Pass* pass, | 23 void DrawViewTree(mojo::Pass* pass, |
27 const ServerView* view, | 24 const ServerView* view, |
28 const gfx::Vector2d& parent_to_root_origin_offset, | 25 const gfx::Vector2d& parent_to_root_origin_offset, |
29 float opacity) { | 26 float opacity) { |
30 if (!view->visible()) | 27 if (!view->visible()) |
31 return; | 28 return; |
32 | 29 |
(...skipping 12 matching lines...) Expand all Loading... |
45 | 42 |
46 auto surface_quad_state = mojo::SurfaceQuadState::New(); | 43 auto surface_quad_state = mojo::SurfaceQuadState::New(); |
47 surface_quad_state->surface = mojo::SurfaceId::From(node_id); | 44 surface_quad_state->surface = mojo::SurfaceId::From(node_id); |
48 | 45 |
49 gfx::Transform node_transform; | 46 gfx::Transform node_transform; |
50 node_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); | 47 node_transform.Translate(absolute_bounds.x(), absolute_bounds.y()); |
51 | 48 |
52 const gfx::Rect bounds_at_origin(view->bounds().size()); | 49 const gfx::Rect bounds_at_origin(view->bounds().size()); |
53 auto surface_quad = mojo::Quad::New(); | 50 auto surface_quad = mojo::Quad::New(); |
54 surface_quad->material = mojo::Material::MATERIAL_SURFACE_CONTENT; | 51 surface_quad->material = mojo::Material::MATERIAL_SURFACE_CONTENT; |
55 surface_quad->rect = Rect::From(bounds_at_origin); | 52 surface_quad->rect = mojo::Rect::From(bounds_at_origin); |
56 surface_quad->opaque_rect = Rect::From(bounds_at_origin); | 53 surface_quad->opaque_rect = mojo::Rect::From(bounds_at_origin); |
57 surface_quad->visible_rect = Rect::From(bounds_at_origin); | 54 surface_quad->visible_rect = mojo::Rect::From(bounds_at_origin); |
58 surface_quad->needs_blending = true; | 55 surface_quad->needs_blending = true; |
59 surface_quad->shared_quad_state_index = | 56 surface_quad->shared_quad_state_index = |
60 base::saturated_cast<int32_t>(pass->shared_quad_states.size()); | 57 base::saturated_cast<int32_t>(pass->shared_quad_states.size()); |
61 surface_quad->surface_quad_state = surface_quad_state.Pass(); | 58 surface_quad->surface_quad_state = surface_quad_state.Pass(); |
62 | 59 |
63 auto sqs = CreateDefaultSQS(*Size::From(view->bounds().size())); | 60 auto sqs = CreateDefaultSQS(*mojo::Size::From(view->bounds().size())); |
64 sqs->blend_mode = mojo::SK_XFERMODE_kSrcOver_Mode; | 61 sqs->blend_mode = mojo::SK_XFERMODE_kSrcOver_Mode; |
65 sqs->opacity = combined_opacity; | 62 sqs->opacity = combined_opacity; |
66 sqs->content_to_target_transform = mojo::Transform::From(node_transform); | 63 sqs->content_to_target_transform = mojo::Transform::From(node_transform); |
67 | 64 |
68 pass->quads.push_back(surface_quad.Pass()); | 65 pass->quads.push_back(surface_quad.Pass()); |
69 pass->shared_quad_states.push_back(sqs.Pass()); | 66 pass->shared_quad_states.push_back(sqs.Pass()); |
70 } | 67 } |
71 | 68 |
72 } // namespace | 69 } // namespace |
73 | 70 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return; | 120 return; |
124 const gfx::Rect root_relative_rect = | 121 const gfx::Rect root_relative_rect = |
125 ConvertRectBetweenViews(view, connection_manager_->root(), bounds); | 122 ConvertRectBetweenViews(view, connection_manager_->root(), bounds); |
126 if (root_relative_rect.IsEmpty()) | 123 if (root_relative_rect.IsEmpty()) |
127 return; | 124 return; |
128 dirty_rect_.Union(root_relative_rect); | 125 dirty_rect_.Union(root_relative_rect); |
129 WantToDraw(); | 126 WantToDraw(); |
130 } | 127 } |
131 | 128 |
132 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { | 129 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { |
133 native_viewport_->SetSize(Size::From(size)); | 130 native_viewport_->SetSize(mojo::Size::From(size)); |
134 } | 131 } |
135 | 132 |
136 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { | 133 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { |
137 return metrics_; | 134 return metrics_; |
138 } | 135 } |
139 | 136 |
140 void DefaultDisplayManager::Draw() { | 137 void DefaultDisplayManager::Draw() { |
141 Rect rect; | 138 mojo::Rect rect; |
142 rect.width = metrics_.size->width; | 139 rect.width = metrics_.size->width; |
143 rect.height = metrics_.size->height; | 140 rect.height = metrics_.size->height; |
144 auto pass = CreateDefaultPass(1, rect); | 141 auto pass = CreateDefaultPass(1, rect); |
145 pass->damage_rect = Rect::From(dirty_rect_); | 142 pass->damage_rect = mojo::Rect::From(dirty_rect_); |
146 | 143 |
147 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); | 144 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); |
148 | 145 |
149 auto frame = mojo::Frame::New(); | 146 auto frame = mojo::Frame::New(); |
150 frame->passes.push_back(pass.Pass()); | 147 frame->passes.push_back(pass.Pass()); |
151 frame->resources.resize(0u); | 148 frame->resources.resize(0u); |
152 frame_pending_ = true; | 149 frame_pending_ = true; |
153 display_->SubmitFrame( | 150 display_->SubmitFrame( |
154 frame.Pass(), | 151 frame.Pass(), |
155 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); | 152 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this))); |
(...skipping 19 matching lines...) Expand all Loading... |
175 metrics_.size = metrics->size.Clone(); | 172 metrics_.size = metrics->size.Clone(); |
176 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; | 173 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; |
177 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); | 174 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); |
178 connection_manager_->root()->SetBounds(bounds); | 175 connection_manager_->root()->SetBounds(bounds); |
179 connection_manager_->ProcessViewportMetricsChanged(metrics_, *metrics); | 176 connection_manager_->ProcessViewportMetricsChanged(metrics_, *metrics); |
180 native_viewport_->RequestMetrics(base::Bind( | 177 native_viewport_->RequestMetrics(base::Bind( |
181 &DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); | 178 &DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); |
182 } | 179 } |
183 | 180 |
184 } // namespace view_manager | 181 } // namespace view_manager |
OLD | NEW |