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 "components/view_manager/connection_manager.h" | 8 #include "components/view_manager/connection_manager.h" |
9 #include "components/view_manager/gles2/gpu_state.h" | |
9 #include "components/view_manager/public/interfaces/gpu.mojom.h" | 10 #include "components/view_manager/public/interfaces/gpu.mojom.h" |
10 #include "components/view_manager/public/interfaces/quads.mojom.h" | 11 #include "components/view_manager/public/interfaces/quads.mojom.h" |
11 #include "components/view_manager/public/interfaces/surfaces.mojom.h" | 12 #include "components/view_manager/public/interfaces/surfaces.mojom.h" |
12 #include "components/view_manager/server_view.h" | 13 #include "components/view_manager/server_view.h" |
13 #include "components/view_manager/view_coordinate_conversions.h" | 14 #include "components/view_manager/view_coordinate_conversions.h" |
14 #include "mojo/application/public/cpp/application_connection.h" | 15 #include "mojo/application/public/cpp/application_connection.h" |
15 #include "mojo/application/public/cpp/application_impl.h" | 16 #include "mojo/application/public/cpp/application_impl.h" |
16 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
17 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
18 #include "mojo/converters/surfaces/surfaces_utils.h" | 19 #include "mojo/converters/surfaces/surfaces_utils.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 sqs->opacity = combined_opacity; | 67 sqs->opacity = combined_opacity; |
67 sqs->content_to_target_transform = mojo::Transform::From(node_transform); | 68 sqs->content_to_target_transform = mojo::Transform::From(node_transform); |
68 | 69 |
69 pass->quads.push_back(surface_quad.Pass()); | 70 pass->quads.push_back(surface_quad.Pass()); |
70 pass->shared_quad_states.push_back(sqs.Pass()); | 71 pass->shared_quad_states.push_back(sqs.Pass()); |
71 } | 72 } |
72 | 73 |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 DefaultDisplayManager::DefaultDisplayManager( | 76 DefaultDisplayManager::DefaultDisplayManager( |
77 bool is_headless, | |
76 mojo::ApplicationImpl* app_impl, | 78 mojo::ApplicationImpl* app_impl, |
79 const scoped_refptr<gles2::GpuState>& gpu_state, | |
77 const mojo::Callback<void()>& native_viewport_closed_callback) | 80 const mojo::Callback<void()>& native_viewport_closed_callback) |
78 : app_impl_(app_impl), | 81 : is_headless_(is_headless), |
82 app_impl_(app_impl), | |
83 gpu_state_(gpu_state), | |
79 connection_manager_(nullptr), | 84 connection_manager_(nullptr), |
85 event_dispatcher_(nullptr), | |
80 draw_timer_(false, false), | 86 draw_timer_(false, false), |
81 frame_pending_(false), | 87 frame_pending_(false), |
82 native_viewport_closed_callback_(native_viewport_closed_callback), | 88 native_viewport_closed_callback_(native_viewport_closed_callback), |
83 weak_factory_(this) { | 89 weak_factory_(this) { |
84 metrics_.size = mojo::Size::New(); | 90 metrics_.size_in_pixels = mojo::Size::New(); |
85 metrics_.size->width = 800; | 91 metrics_.size_in_pixels->width = 800; |
86 metrics_.size->height = 600; | 92 metrics_.size_in_pixels->height = 600; |
87 } | 93 } |
88 | 94 |
89 void DefaultDisplayManager::Init( | 95 void DefaultDisplayManager::Init( |
90 ConnectionManager* connection_manager, | 96 ConnectionManager* connection_manager, |
91 mojo::NativeViewportEventDispatcherPtr event_dispatcher) { | 97 EventDispatcher* event_dispatcher) { |
92 connection_manager_ = connection_manager; | 98 connection_manager_ = connection_manager; |
93 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 99 event_dispatcher_ = event_dispatcher; |
94 // TODO(beng): should not need to connect to ourselves, should just | 100 |
95 // create the appropriate platform window directly. | 101 native_viewport_.reset( |
96 request->url = mojo::String::From("mojo:view_manager"); | 102 new NativeViewport(this, |
97 app_impl_->ConnectToService(request.Pass(), | 103 metrics_.size_in_pixels.To<gfx::Size>(), |
98 &native_viewport_); | 104 is_headless_, |
99 native_viewport_.set_error_handler(this); | 105 gpu_state_)); |
100 native_viewport_->Create(metrics_.size->Clone(), | |
101 base::Bind(&DefaultDisplayManager::OnMetricsChanged, | |
102 weak_factory_.GetWeakPtr())); | |
103 native_viewport_->Show(); | 106 native_viewport_->Show(); |
104 | 107 |
108 | |
sky
2015/06/05 23:25:50
nit: one newline is enough here.
Fady Samuel
2015/06/05 23:34:52
Done.
| |
105 mojo::ContextProviderPtr context_provider; | 109 mojo::ContextProviderPtr context_provider; |
106 native_viewport_->GetContextProvider(GetProxy(&context_provider)); | 110 native_viewport_->GetContextProvider(GetProxy(&context_provider)); |
107 mojo::DisplayFactoryPtr display_factory; | 111 mojo::DisplayFactoryPtr display_factory; |
108 mojo::URLRequestPtr request2(mojo::URLRequest::New()); | 112 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
109 request2->url = mojo::String::From("mojo:surfaces_service"); | 113 request->url = mojo::String::From("mojo:surfaces_service"); |
110 app_impl_->ConnectToService(request2.Pass(), &display_factory); | 114 app_impl_->ConnectToService(request.Pass(), &display_factory); |
111 display_factory->Create(context_provider.Pass(), | 115 display_factory->Create(context_provider.Pass(), |
112 nullptr, // returner - we never submit resources. | 116 nullptr, // returner - we never submit resources. |
113 GetProxy(&display_)); | 117 GetProxy(&display_)); |
114 | |
115 native_viewport_->SetEventDispatcher(event_dispatcher.Pass()); | |
116 } | 118 } |
117 | 119 |
118 DefaultDisplayManager::~DefaultDisplayManager() { | 120 DefaultDisplayManager::~DefaultDisplayManager() { |
119 } | 121 } |
120 | 122 |
121 void DefaultDisplayManager::SchedulePaint(const ServerView* view, | 123 void DefaultDisplayManager::SchedulePaint(const ServerView* view, |
122 const gfx::Rect& bounds) { | 124 const gfx::Rect& bounds) { |
123 if (!view->IsDrawn(connection_manager_->root())) | 125 if (!view->IsDrawn(connection_manager_->root())) |
124 return; | 126 return; |
125 const gfx::Rect root_relative_rect = | 127 const gfx::Rect root_relative_rect = |
126 ConvertRectBetweenViews(view, connection_manager_->root(), bounds); | 128 ConvertRectBetweenViews(view, connection_manager_->root(), bounds); |
127 if (root_relative_rect.IsEmpty()) | 129 if (root_relative_rect.IsEmpty()) |
128 return; | 130 return; |
129 dirty_rect_.Union(root_relative_rect); | 131 dirty_rect_.Union(root_relative_rect); |
130 WantToDraw(); | 132 WantToDraw(); |
131 } | 133 } |
132 | 134 |
133 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { | 135 void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { |
134 native_viewport_->SetSize(Size::From(size)); | 136 native_viewport_->SetSize(size); |
135 } | 137 } |
136 | 138 |
137 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { | 139 const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { |
138 return metrics_; | 140 return metrics_; |
139 } | 141 } |
140 | 142 |
141 void DefaultDisplayManager::Draw() { | 143 void DefaultDisplayManager::Draw() { |
142 gfx::Rect rect(metrics_.size->width, metrics_.size->height); | 144 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); |
143 auto pass = mojo::CreateDefaultPass(1, rect); | 145 auto pass = mojo::CreateDefaultPass(1, rect); |
144 pass->damage_rect = Rect::From(dirty_rect_); | 146 pass->damage_rect = Rect::From(dirty_rect_); |
145 | 147 |
146 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); | 148 DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d(), 1.0f); |
147 | 149 |
148 auto frame = mojo::Frame::New(); | 150 auto frame = mojo::Frame::New(); |
149 frame->passes.push_back(pass.Pass()); | 151 frame->passes.push_back(pass.Pass()); |
150 frame->resources.resize(0u); | 152 frame->resources.resize(0u); |
151 frame_pending_ = true; | 153 frame_pending_ = true; |
152 display_->SubmitFrame( | 154 display_->SubmitFrame( |
(...skipping 10 matching lines...) Expand all Loading... | |
163 | 165 |
164 void DefaultDisplayManager::WantToDraw() { | 166 void DefaultDisplayManager::WantToDraw() { |
165 if (draw_timer_.IsRunning() || frame_pending_) | 167 if (draw_timer_.IsRunning() || frame_pending_) |
166 return; | 168 return; |
167 | 169 |
168 draw_timer_.Start( | 170 draw_timer_.Start( |
169 FROM_HERE, base::TimeDelta(), | 171 FROM_HERE, base::TimeDelta(), |
170 base::Bind(&DefaultDisplayManager::Draw, base::Unretained(this))); | 172 base::Bind(&DefaultDisplayManager::Draw, base::Unretained(this))); |
171 } | 173 } |
172 | 174 |
173 void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { | 175 bool DefaultDisplayManager::OnEvent(mojo::EventPtr event) { |
174 metrics_.size = metrics->size.Clone(); | 176 if (!event_dispatcher_) |
sky
2015/06/05 23:25:50
Do we ever pass in null?
Fady Samuel
2015/06/05 23:34:52
No, removed the check.
| |
175 metrics_.device_pixel_ratio = metrics->device_pixel_ratio; | 177 return false; |
176 gfx::Rect bounds(metrics_.size.To<gfx::Size>()); | 178 |
177 connection_manager_->root()->SetBounds(bounds); | 179 event_dispatcher_->OnEvent(event.Pass()); |
178 connection_manager_->ProcessViewportMetricsChanged(metrics_, *metrics); | 180 return false; |
179 native_viewport_->RequestMetrics(base::Bind( | |
180 &DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); | |
181 } | 181 } |
182 | 182 |
183 void DefaultDisplayManager::OnConnectionError() { | 183 void DefaultDisplayManager::OnMetricsChanged(const gfx::Size& size, |
184 // This is called when the native_viewport is torn down before | 184 float device_scale_factor) { |
sky
2015/06/05 23:25:50
It seems like we may get here and the metrics have
Fady Samuel
2015/06/05 23:34:52
Done.
| |
185 // ~DefaultDisplayManager may be called. | 185 mojo::ViewportMetrics metrics; |
186 native_viewport_closed_callback_.Run(); | 186 metrics.size_in_pixels = mojo::Size::From(size); |
187 metrics.device_pixel_ratio = device_scale_factor; | |
188 | |
189 connection_manager_->root()->SetBounds(gfx::Rect(size)); | |
190 connection_manager_->ProcessViewportMetricsChanged(metrics_, metrics); | |
191 | |
192 metrics_.size_in_pixels = metrics.size_in_pixels.Clone(); | |
193 metrics_.device_pixel_ratio = metrics.device_pixel_ratio; | |
194 } | |
195 | |
196 void DefaultDisplayManager::OnViewDestroyed() { | |
197 if (!native_viewport_closed_callback_.is_null()) | |
198 native_viewport_closed_callback_.Run(); | |
187 } | 199 } |
188 | 200 |
189 } // namespace view_manager | 201 } // namespace view_manager |
OLD | NEW |