Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: components/view_manager/display_manager.cc

Issue 1245683004: Mandoline: Merge Surfaces and Views apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove context_provider.mojom Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/display_manager_factory.h" 8 #include "components/view_manager/display_manager_factory.h"
9 #include "components/view_manager/gles2/gpu_state.h" 9 #include "components/view_manager/gles2/gpu_state.h"
10 #include "components/view_manager/native_viewport/onscreen_context_provider.h"
11 #include "components/view_manager/public/interfaces/gpu.mojom.h" 10 #include "components/view_manager/public/interfaces/gpu.mojom.h"
12 #include "components/view_manager/public/interfaces/quads.mojom.h" 11 #include "components/view_manager/public/interfaces/quads.mojom.h"
13 #include "components/view_manager/public/interfaces/surfaces.mojom.h" 12 #include "components/view_manager/public/interfaces/surfaces.mojom.h"
14 #include "components/view_manager/server_view.h" 13 #include "components/view_manager/server_view.h"
14 #include "components/view_manager/surfaces/surfaces_state.h"
15 #include "components/view_manager/view_coordinate_conversions.h" 15 #include "components/view_manager/view_coordinate_conversions.h"
16 #include "mojo/application/public/cpp/application_connection.h" 16 #include "mojo/application/public/cpp/application_connection.h"
17 #include "mojo/application/public/cpp/application_impl.h" 17 #include "mojo/application/public/cpp/application_impl.h"
18 #include "mojo/converters/geometry/geometry_type_converters.h" 18 #include "mojo/converters/geometry/geometry_type_converters.h"
19 #include "mojo/converters/input_events/input_events_type_converters.h" 19 #include "mojo/converters/input_events/input_events_type_converters.h"
20 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" 20 #include "mojo/converters/input_events/mojo_extended_key_event_data.h"
21 #include "mojo/converters/surfaces/surfaces_type_converters.h" 21 #include "mojo/converters/surfaces/surfaces_type_converters.h"
22 #include "mojo/converters/surfaces/surfaces_utils.h" 22 #include "mojo/converters/surfaces/surfaces_utils.h"
23 #include "mojo/converters/transform/transform_type_converters.h" 23 #include "mojo/converters/transform/transform_type_converters.h"
24 #include "ui/events/event.h" 24 #include "ui/events/event.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 } // namespace 98 } // namespace
99 99
100 // static 100 // static
101 DisplayManagerFactory* DisplayManager::factory_ = nullptr; 101 DisplayManagerFactory* DisplayManager::factory_ = nullptr;
102 102
103 // static 103 // static
104 DisplayManager* DisplayManager::Create( 104 DisplayManager* DisplayManager::Create(
105 bool is_headless, 105 bool is_headless,
106 mojo::ApplicationImpl* app_impl, 106 mojo::ApplicationImpl* app_impl,
107 const scoped_refptr<gles2::GpuState>& gpu_state) { 107 const scoped_refptr<gles2::GpuState>& gpu_state,
108 if (factory_) 108 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) {
109 return factory_->CreateDisplayManager(is_headless, app_impl, gpu_state); 109 if (factory_) {
110 return new DefaultDisplayManager(is_headless, app_impl, gpu_state); 110 return factory_->CreateDisplayManager(is_headless,
111 app_impl,
112 gpu_state,
113 surfaces_state);
114 }
115 return new DefaultDisplayManager(is_headless,
116 app_impl,
117 gpu_state,
118 surfaces_state);
111 } 119 }
112 120
113 DefaultDisplayManager::DefaultDisplayManager( 121 DefaultDisplayManager::DefaultDisplayManager(
114 bool is_headless, 122 bool is_headless,
115 mojo::ApplicationImpl* app_impl, 123 mojo::ApplicationImpl* app_impl,
116 const scoped_refptr<gles2::GpuState>& gpu_state) 124 const scoped_refptr<gles2::GpuState>& gpu_state,
125 const scoped_refptr<surfaces::SurfacesState>& surfaces_state)
117 : is_headless_(is_headless), 126 : is_headless_(is_headless),
118 app_impl_(app_impl), 127 app_impl_(app_impl),
119 gpu_state_(gpu_state), 128 gpu_state_(gpu_state),
129 surfaces_state_(surfaces_state),
120 delegate_(nullptr), 130 delegate_(nullptr),
121 draw_timer_(false, false), 131 draw_timer_(false, false),
122 frame_pending_(false), 132 frame_pending_(false),
123 context_provider_(
124 new native_viewport::OnscreenContextProvider(gpu_state)),
125 weak_factory_(this) { 133 weak_factory_(this) {
126 metrics_.size_in_pixels = mojo::Size::New(); 134 metrics_.size_in_pixels = mojo::Size::New();
127 metrics_.size_in_pixels->width = 800; 135 metrics_.size_in_pixels->width = 800;
128 metrics_.size_in_pixels->height = 600; 136 metrics_.size_in_pixels->height = 600;
129 } 137 }
130 138
131 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) { 139 void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) {
132 delegate_ = delegate; 140 delegate_ = delegate;
133 141
134 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); 142 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>());
135 if (is_headless_) { 143 if (is_headless_) {
136 platform_window_.reset(new ui::StubWindow(this)); 144 platform_window_.reset(new ui::StubWindow(this));
137 } else { 145 } else {
138 #if defined(OS_WIN) 146 #if defined(OS_WIN)
139 platform_window_.reset(new ui::WinWindow(this, bounds)); 147 platform_window_.reset(new ui::WinWindow(this, bounds));
140 #elif defined(USE_X11) 148 #elif defined(USE_X11)
141 platform_window_.reset(new ui::X11Window(this)); 149 platform_window_.reset(new ui::X11Window(this));
142 #elif defined(OS_ANDROID) 150 #elif defined(OS_ANDROID)
143 platform_window_.reset(new ui::PlatformWindowAndroid(this)); 151 platform_window_.reset(new ui::PlatformWindowAndroid(this));
144 #else 152 #else
145 NOTREACHED() << "Unsupported platform"; 153 NOTREACHED() << "Unsupported platform";
146 #endif 154 #endif
147 } 155 }
148 platform_window_->SetBounds(bounds); 156 platform_window_->SetBounds(bounds);
149 platform_window_->Show(); 157 platform_window_->Show();
150
151 mojo::ContextProviderPtr context_provider;
152 context_provider_->Bind(GetProxy(&context_provider).Pass());
153 mojo::DisplayFactoryPtr display_factory;
154 mojo::URLRequestPtr request(mojo::URLRequest::New());
155 request->url = mojo::String::From("mojo:surfaces_service");
156 app_impl_->ConnectToService(request.Pass(), &display_factory);
157 // TODO(fsamuel): We should indicate to the delegate that this object failed
158 // to initialize.
159 if (!display_factory)
160 return;
161 display_factory->Create(context_provider.Pass(),
162 nullptr, // returner - we never submit resources.
163 GetProxy(&display_));
164 } 158 }
165 159
166 DefaultDisplayManager::~DefaultDisplayManager() { 160 DefaultDisplayManager::~DefaultDisplayManager() {
167 // Destroy before |platform_window_| because this will destroy
168 // CommandBufferDriver objects that contain child windows. Otherwise if this
169 // class destroys its window first, X errors will occur.
170 context_provider_.reset();
171
172 // Destroy the PlatformWindow early on as it may call us back during 161 // Destroy the PlatformWindow early on as it may call us back during
173 // destruction and we want to be in a known state. 162 // destruction and we want to be in a known state.
174 platform_window_.reset(); 163 platform_window_.reset();
175 } 164 }
176 165
177 void DefaultDisplayManager::SchedulePaint(const ServerView* view, 166 void DefaultDisplayManager::SchedulePaint(const ServerView* view,
178 const gfx::Rect& bounds) { 167 const gfx::Rect& bounds) {
179 DCHECK(view); 168 DCHECK(view);
180 if (!view->IsDrawn()) 169 if (!view->IsDrawn())
181 return; 170 return;
(...skipping 19 matching lines...) Expand all
201 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); 190 gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>());
202 auto pass = mojo::CreateDefaultPass(1, rect); 191 auto pass = mojo::CreateDefaultPass(1, rect);
203 pass->damage_rect = Rect::From(dirty_rect_); 192 pass->damage_rect = Rect::From(dirty_rect_);
204 193
205 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f); 194 DrawViewTree(pass.get(), delegate_->GetRootView(), gfx::Vector2d(), 1.0f);
206 195
207 auto frame = mojo::Frame::New(); 196 auto frame = mojo::Frame::New();
208 frame->passes.push_back(pass.Pass()); 197 frame->passes.push_back(pass.Pass());
209 frame->resources.resize(0u); 198 frame->resources.resize(0u);
210 frame_pending_ = true; 199 frame_pending_ = true;
211 if (display_) { 200 if (top_level_display_client_) {
212 display_->SubmitFrame(frame.Pass(), 201 top_level_display_client_->SubmitFrame(
213 base::Bind(&DefaultDisplayManager::DidDraw, 202 frame.Pass(),
214 weak_factory_.GetWeakPtr())); 203 base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this)));
215 } 204 }
216 dirty_rect_ = gfx::Rect(); 205 dirty_rect_ = gfx::Rect();
217 } 206 }
218 207
219 void DefaultDisplayManager::DidDraw() { 208 void DefaultDisplayManager::DidDraw() {
220 frame_pending_ = false; 209 frame_pending_ = false;
221 if (!dirty_rect_.IsEmpty()) 210 if (!dirty_rect_.IsEmpty())
222 WantToDraw(); 211 WantToDraw();
223 } 212 }
224 213
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 void DefaultDisplayManager::OnWindowStateChanged( 315 void DefaultDisplayManager::OnWindowStateChanged(
327 ui::PlatformWindowState new_state) { 316 ui::PlatformWindowState new_state) {
328 } 317 }
329 318
330 void DefaultDisplayManager::OnLostCapture() { 319 void DefaultDisplayManager::OnLostCapture() {
331 } 320 }
332 321
333 void DefaultDisplayManager::OnAcceleratedWidgetAvailable( 322 void DefaultDisplayManager::OnAcceleratedWidgetAvailable(
334 gfx::AcceleratedWidget widget, 323 gfx::AcceleratedWidget widget,
335 float device_pixel_ratio) { 324 float device_pixel_ratio) {
336 context_provider_->SetAcceleratedWidget(widget); 325 top_level_display_client_.reset(
326 new surfaces::TopLevelDisplayClient(widget, gpu_state_, surfaces_state_));
337 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); 327 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio);
338 } 328 }
339 329
340 void DefaultDisplayManager::OnActivationChanged(bool active) { 330 void DefaultDisplayManager::OnActivationChanged(bool active) {
341 } 331 }
342 332
343 } // namespace view_manager 333 } // namespace view_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698