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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 weak_factory_(this) { | 84 weak_factory_(this) { |
85 metrics_.size = mojo::Size::New(); | 85 metrics_.size = mojo::Size::New(); |
86 metrics_.size->width = 800; | 86 metrics_.size->width = 800; |
87 metrics_.size->height = 600; | 87 metrics_.size->height = 600; |
88 } | 88 } |
89 | 89 |
90 void DefaultDisplayManager::Init(ConnectionManager* connection_manager) { | 90 void DefaultDisplayManager::Init(ConnectionManager* connection_manager) { |
91 connection_manager_ = connection_manager; | 91 connection_manager_ = connection_manager; |
92 app_connection_->ConnectToService("mojo:native_viewport_service", | 92 app_connection_->ConnectToService("mojo:native_viewport_service", |
93 &native_viewport_); | 93 &native_viewport_); |
94 native_viewport_.set_client(this); | 94 native_viewport_.set_error_handler(this); |
95 native_viewport_->Create( | 95 native_viewport_->Create( |
96 metrics_.size->Clone(), | 96 metrics_.size->Clone(), |
97 base::Bind(&DefaultDisplayManager::OnCreatedNativeViewport, | 97 base::Bind(&DefaultDisplayManager::OnCreatedNativeViewport, |
98 weak_factory_.GetWeakPtr())); | 98 weak_factory_.GetWeakPtr())); |
99 native_viewport_->Show(); | 99 native_viewport_->Show(); |
100 | 100 |
101 app_connection_->ConnectToService("mojo:surfaces_service", &surface_); | 101 app_connection_->ConnectToService("mojo:surfaces_service", &surface_); |
102 surface_.set_client(this); | 102 surface_.set_client(this); |
103 | 103 |
104 mojo::NativeViewportEventDispatcherPtr event_dispatcher; | 104 mojo::NativeViewportEventDispatcherPtr event_dispatcher; |
(...skipping 22 matching lines...) Expand all Loading... |
127 | 127 |
128 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { | 128 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { |
129 native_viewport_->SetSize(Size::From(size)); | 129 native_viewport_->SetSize(Size::From(size)); |
130 } | 130 } |
131 | 131 |
132 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { | 132 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { |
133 return metrics_; | 133 return metrics_; |
134 } | 134 } |
135 | 135 |
136 void DefaultDisplayManager::OnCreatedNativeViewport( | 136 void DefaultDisplayManager::OnCreatedNativeViewport( |
137 uint64_t native_viewport_id) { | 137 uint64_t native_viewport_id, |
| 138 mojo::ViewportMetricsPtr metrics) { |
| 139 OnMetricsChanged(metrics.Pass()); |
138 } | 140 } |
139 | 141 |
140 void DefaultDisplayManager::Draw() { | 142 void DefaultDisplayManager::Draw() { |
141 if (!surface_allocated_) { | 143 if (!surface_allocated_) { |
142 surface_->CreateSurface(kLocalSurfaceID); | 144 surface_->CreateSurface(kLocalSurfaceID); |
143 surface_allocated_ = true; | 145 surface_allocated_ = true; |
144 } | 146 } |
145 | 147 |
146 Rect rect; | 148 Rect rect; |
147 rect.width = metrics_.size->width; | 149 rect.width = metrics_.size->width; |
(...skipping 11 matching lines...) Expand all Loading... |
159 | 161 |
160 if (id_namespace_ == 0u) | 162 if (id_namespace_ == 0u) |
161 return; | 163 return; |
162 | 164 |
163 auto qualified_id = mojo::SurfaceId::New(); | 165 auto qualified_id = mojo::SurfaceId::New(); |
164 qualified_id->id_namespace = id_namespace_; | 166 qualified_id->id_namespace = id_namespace_; |
165 qualified_id->local = kLocalSurfaceID; | 167 qualified_id->local = kLocalSurfaceID; |
166 native_viewport_->SubmittedFrame(qualified_id.Pass()); | 168 native_viewport_->SubmittedFrame(qualified_id.Pass()); |
167 } | 169 } |
168 | 170 |
169 void DefaultDisplayManager::OnDestroyed() { | |
170 // This is called when the native_viewport is torn down before | |
171 // ~DefaultDisplayManager may be called. | |
172 native_viewport_closed_callback_.Run(); | |
173 } | |
174 | |
175 void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { | 171 void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { |
176 metrics_.size = metrics->size.Pass(); | 172 metrics_.size = metrics->size.Clone(); |
177 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; | 173 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; |
178 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); | 174 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); |
179 connection_manager_->root()->SetBounds(bounds); | 175 connection_manager_->root()->SetBounds(bounds); |
180 if (!surface_allocated_) | 176 if (!surface_allocated_) |
181 return; | 177 return; |
182 surface_->DestroySurface(kLocalSurfaceID); | 178 surface_->DestroySurface(kLocalSurfaceID); |
183 surface_allocated_ = false; | 179 surface_allocated_ = false; |
184 SchedulePaint(connection_manager_->root(), bounds); | 180 SchedulePaint(connection_manager_->root(), bounds); |
| 181 native_viewport_->RequestMetrics(base::Bind( |
| 182 &DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); |
185 } | 183 } |
186 | 184 |
187 void DefaultDisplayManager::SetIdNamespace(uint32_t id_namespace) { | 185 void DefaultDisplayManager::SetIdNamespace(uint32_t id_namespace) { |
188 id_namespace_ = id_namespace; | 186 id_namespace_ = id_namespace; |
189 if (surface_allocated_) { | 187 if (surface_allocated_) { |
190 auto qualified_id = mojo::SurfaceId::New(); | 188 auto qualified_id = mojo::SurfaceId::New(); |
191 qualified_id->id_namespace = id_namespace_; | 189 qualified_id->id_namespace = id_namespace_; |
192 qualified_id->local = kLocalSurfaceID; | 190 qualified_id->local = kLocalSurfaceID; |
193 native_viewport_->SubmittedFrame(qualified_id.Pass()); | 191 native_viewport_->SubmittedFrame(qualified_id.Pass()); |
194 } | 192 } |
195 } | 193 } |
196 | 194 |
197 void DefaultDisplayManager::ReturnResources( | 195 void DefaultDisplayManager::ReturnResources( |
198 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 196 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
199 DCHECK_EQ(0u, resources.size()); | 197 DCHECK_EQ(0u, resources.size()); |
200 } | 198 } |
201 | 199 |
| 200 void DefaultDisplayManager::OnConnectionError() { |
| 201 // This is called when the native_viewport is torn down before |
| 202 // ~DefaultDisplayManager may be called. |
| 203 native_viewport_closed_callback_.Run(); |
| 204 } |
| 205 |
202 } // namespace view_manager | 206 } // namespace view_manager |
OLD | NEW |