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