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 "cc/surfaces/surface_id_allocator.h" | 8 #include "cc/surfaces/surface_id_allocator.h" |
9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 10 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.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 "services/view_manager/connection_manager.h" | 15 #include "services/view_manager/connection_manager.h" |
16 #include "services/view_manager/server_view.h" | 16 #include "services/view_manager/server_view.h" |
17 #include "services/view_manager/view_coordinate_conversions.h" | 17 #include "services/view_manager/view_coordinate_conversions.h" |
18 | 18 |
19 using mojo::Rect; | 19 using mojo::Rect; |
20 using mojo::Size; | 20 using mojo::Size; |
21 | 21 |
22 namespace view_manager { | 22 namespace view_manager { |
23 namespace { | 23 namespace { |
24 | 24 |
| 25 static uint32_t kLocalSurfaceID = 1u; |
| 26 |
25 void DrawViewTree(mojo::Pass* pass, | 27 void DrawViewTree(mojo::Pass* pass, |
26 const ServerView* view, | 28 const ServerView* view, |
27 const gfx::Vector2d& parent_to_root_origin_offset, | 29 const gfx::Vector2d& parent_to_root_origin_offset, |
28 float opacity) { | 30 float opacity) { |
29 if (!view->visible()) | 31 if (!view->visible()) |
30 return; | 32 return; |
31 | 33 |
32 const gfx::Rect absolute_bounds = | 34 const gfx::Rect absolute_bounds = |
33 view->bounds() + parent_to_root_origin_offset; | 35 view->bounds() + parent_to_root_origin_offset; |
34 std::vector<const ServerView*> children(view->GetChildren()); | 36 std::vector<const ServerView*> children(view->GetChildren()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 71 } |
70 | 72 |
71 } // namespace | 73 } // namespace |
72 | 74 |
73 DefaultDisplayManager::DefaultDisplayManager( | 75 DefaultDisplayManager::DefaultDisplayManager( |
74 mojo::ApplicationConnection* app_connection, | 76 mojo::ApplicationConnection* app_connection, |
75 const mojo::Callback<void()>& native_viewport_closed_callback) | 77 const mojo::Callback<void()>& native_viewport_closed_callback) |
76 : app_connection_(app_connection), | 78 : app_connection_(app_connection), |
77 connection_manager_(nullptr), | 79 connection_manager_(nullptr), |
78 draw_timer_(false, false), | 80 draw_timer_(false, false), |
| 81 id_namespace_(0u), |
| 82 surface_allocated_(false), |
79 native_viewport_closed_callback_(native_viewport_closed_callback), | 83 native_viewport_closed_callback_(native_viewport_closed_callback), |
80 weak_factory_(this) { | 84 weak_factory_(this) { |
81 metrics_.size = mojo::Size::New(); | 85 metrics_.size = mojo::Size::New(); |
82 metrics_.size->width = 800; | 86 metrics_.size->width = 800; |
83 metrics_.size->height = 600; | 87 metrics_.size->height = 600; |
84 } | 88 } |
85 | 89 |
86 void DefaultDisplayManager::Init(ConnectionManager* connection_manager) { | 90 void DefaultDisplayManager::Init(ConnectionManager* connection_manager) { |
87 connection_manager_ = connection_manager; | 91 connection_manager_ = connection_manager; |
88 app_connection_->ConnectToService("mojo:native_viewport_service", | 92 app_connection_->ConnectToService("mojo:native_viewport_service", |
89 &native_viewport_); | 93 &native_viewport_); |
90 native_viewport_.set_client(this); | 94 native_viewport_.set_client(this); |
91 native_viewport_->Create( | 95 native_viewport_->Create( |
92 metrics_.size->Clone(), | 96 metrics_.size->Clone(), |
93 base::Bind(&DefaultDisplayManager::OnCreatedNativeViewport, | 97 base::Bind(&DefaultDisplayManager::OnCreatedNativeViewport, |
94 weak_factory_.GetWeakPtr())); | 98 weak_factory_.GetWeakPtr())); |
95 native_viewport_->Show(); | 99 native_viewport_->Show(); |
96 app_connection_->ConnectToService("mojo:surfaces_service", | 100 |
97 &surfaces_service_); | 101 app_connection_->ConnectToService("mojo:surfaces_service", &surface_); |
98 surfaces_service_->CreateSurfaceConnection( | 102 surface_.set_client(this); |
99 base::Bind(&DefaultDisplayManager::OnSurfaceConnectionCreated, | |
100 weak_factory_.GetWeakPtr())); | |
101 | 103 |
102 mojo::NativeViewportEventDispatcherPtr event_dispatcher; | 104 mojo::NativeViewportEventDispatcherPtr event_dispatcher; |
103 app_connection_->ConnectToService(&event_dispatcher); | 105 app_connection_->ConnectToService(&event_dispatcher); |
104 native_viewport_->SetEventDispatcher(event_dispatcher.Pass()); | 106 native_viewport_->SetEventDispatcher(event_dispatcher.Pass()); |
105 } | 107 } |
106 | 108 |
107 DefaultDisplayManager::~DefaultDisplayManager() { | 109 DefaultDisplayManager::~DefaultDisplayManager() { |
108 } | 110 } |
109 | 111 |
110 void DefaultDisplayManager::SchedulePaint(const ServerView* view, | 112 void DefaultDisplayManager::SchedulePaint(const ServerView* view, |
(...skipping 17 matching lines...) Expand all Loading... |
128 } | 130 } |
129 | 131 |
130 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { | 132 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { |
131 return metrics_; | 133 return metrics_; |
132 } | 134 } |
133 | 135 |
134 void DefaultDisplayManager::OnCreatedNativeViewport( | 136 void DefaultDisplayManager::OnCreatedNativeViewport( |
135 uint64_t native_viewport_id) { | 137 uint64_t native_viewport_id) { |
136 } | 138 } |
137 | 139 |
138 void DefaultDisplayManager::OnSurfaceConnectionCreated(mojo::SurfacePtr surface, | |
139 uint32_t id_namespace) { | |
140 surface_ = surface.Pass(); | |
141 surface_.set_client(this); | |
142 surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | |
143 Draw(); | |
144 } | |
145 | |
146 void DefaultDisplayManager::Draw() { | 140 void DefaultDisplayManager::Draw() { |
147 if (!surface_) | 141 if (!surface_allocated_) { |
148 return; | 142 surface_->CreateSurface(kLocalSurfaceID); |
149 if (surface_id_.is_null()) { | 143 surface_allocated_ = true; |
150 surface_id_ = surface_id_allocator_->GenerateId(); | |
151 surface_->CreateSurface(mojo::SurfaceId::From(surface_id_)); | |
152 } | 144 } |
153 | 145 |
154 Rect rect; | 146 Rect rect; |
155 rect.width = metrics_.size->width; | 147 rect.width = metrics_.size->width; |
156 rect.height = metrics_.size->height; | 148 rect.height = metrics_.size->height; |
157 auto pass = CreateDefaultPass(1, rect); | 149 auto pass = CreateDefaultPass(1, rect); |
158 pass->damage_rect = Rect::From(dirty_rect_); | 150 pass->damage_rect = Rect::From(dirty_rect_); |
159 | 151 |
160 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); | 152 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); |
161 | 153 |
162 auto frame = mojo::Frame::New(); | 154 auto frame = mojo::Frame::New(); |
163 frame->passes.push_back(pass.Pass()); | 155 frame->passes.push_back(pass.Pass()); |
164 frame->resources.resize(0u); | 156 frame->resources.resize(0u); |
165 surface_->SubmitFrame(mojo::SurfaceId::From(surface_id_), frame.Pass(), | 157 surface_->SubmitFrame(kLocalSurfaceID, frame.Pass(), mojo::Closure()); |
166 mojo::Closure()); | 158 dirty_rect_ = gfx::Rect(); |
167 | 159 |
168 native_viewport_->SubmittedFrame(mojo::SurfaceId::From(surface_id_)); | 160 if (id_namespace_ == 0u) |
| 161 return; |
169 | 162 |
170 dirty_rect_ = gfx::Rect(); | 163 auto qualified_id = mojo::SurfaceId::New(); |
| 164 qualified_id->id_namespace = id_namespace_; |
| 165 qualified_id->local = kLocalSurfaceID; |
| 166 native_viewport_->SubmittedFrame(qualified_id.Pass()); |
171 } | 167 } |
172 | 168 |
173 void DefaultDisplayManager::OnDestroyed() { | 169 void DefaultDisplayManager::OnDestroyed() { |
174 // This is called when the native_viewport is torn down before | 170 // This is called when the native_viewport is torn down before |
175 // ~DefaultDisplayManager may be called. | 171 // ~DefaultDisplayManager may be called. |
176 native_viewport_closed_callback_.Run(); | 172 native_viewport_closed_callback_.Run(); |
177 } | 173 } |
178 | 174 |
179 void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { | 175 void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { |
180 metrics_.size = metrics->size.Pass(); | 176 metrics_.size = metrics->size.Pass(); |
181 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; | 177 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; |
182 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); | 178 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); |
183 connection_manager_->root()->SetBounds(bounds); | 179 connection_manager_->root()->SetBounds(bounds); |
184 if (surface_id_.is_null()) | 180 if (!surface_allocated_) |
185 return; | 181 return; |
186 surface_->DestroySurface(mojo::SurfaceId::From(surface_id_)); | 182 surface_->DestroySurface(kLocalSurfaceID); |
187 surface_id_ = cc::SurfaceId(); | 183 surface_allocated_ = false; |
188 SchedulePaint(connection_manager_->root(), bounds); | 184 SchedulePaint(connection_manager_->root(), bounds); |
189 } | 185 } |
190 | 186 |
191 void DefaultDisplayManager::SetIdNamespace(uint32_t id_namespace) { | 187 void DefaultDisplayManager::SetIdNamespace(uint32_t id_namespace) { |
| 188 id_namespace_ = id_namespace; |
| 189 if (surface_allocated_) { |
| 190 auto qualified_id = mojo::SurfaceId::New(); |
| 191 qualified_id->id_namespace = id_namespace_; |
| 192 qualified_id->local = kLocalSurfaceID; |
| 193 native_viewport_->SubmittedFrame(qualified_id.Pass()); |
| 194 } |
192 } | 195 } |
193 | 196 |
194 void DefaultDisplayManager::ReturnResources( | 197 void DefaultDisplayManager::ReturnResources( |
195 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 198 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
196 DCHECK_EQ(0u, resources.size()); | 199 DCHECK_EQ(0u, resources.size()); |
197 } | 200 } |
198 | 201 |
199 } // namespace view_manager | 202 } // namespace view_manager |
OLD | NEW |