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

Side by Side Diff: ui/compositor/compositor.cc

Issue 2563783002: ui + mus: Split ContextFactory into ContextFactory(Client) and ContextFactoryPrivate (Closed)
Patch Set: Updated Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 void CompositorLock::CancelLock() { 67 void CompositorLock::CancelLock() {
68 if (!compositor_) 68 if (!compositor_)
69 return; 69 return;
70 compositor_->UnlockCompositor(); 70 compositor_->UnlockCompositor();
71 compositor_ = NULL; 71 compositor_ = NULL;
72 } 72 }
73 73
74 Compositor::Compositor(ui::ContextFactory* context_factory, 74 Compositor::Compositor(ui::ContextFactory* context_factory,
75 ui::ContextFactoryPrivate* context_factory_private,
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 76 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
76 : context_factory_(context_factory), 77 : context_factory_(context_factory),
78 context_factory_private_(context_factory_private),
77 root_layer_(NULL), 79 root_layer_(NULL),
78 widget_(gfx::kNullAcceleratedWidget), 80 widget_(gfx::kNullAcceleratedWidget),
79 #if defined(USE_AURA) 81 #if defined(USE_AURA)
80 window_(nullptr), 82 window_(nullptr),
81 #endif 83 #endif
82 widget_valid_(false), 84 widget_valid_(false),
83 compositor_frame_sink_requested_(false), 85 compositor_frame_sink_requested_(false),
84 frame_sink_id_(context_factory->AllocateFrameSinkId()), 86 frame_sink_id_(context_factory_private
87 ? context_factory_private->AllocateFrameSinkId()
88 : cc::FrameSinkId()),
85 task_runner_(task_runner), 89 task_runner_(task_runner),
86 vsync_manager_(new CompositorVSyncManager()), 90 vsync_manager_(new CompositorVSyncManager()),
87 device_scale_factor_(0.0f), 91 device_scale_factor_(0.0f),
88 locks_will_time_out_(true), 92 locks_will_time_out_(true),
89 compositor_lock_(NULL), 93 compositor_lock_(NULL),
90 layer_animator_collection_(this), 94 layer_animator_collection_(this),
91 weak_ptr_factory_(this) { 95 weak_ptr_factory_(this) {
92 context_factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 96 if (context_factory_private) {
97 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId(
98 frame_sink_id_);
99 }
93 root_web_layer_ = cc::Layer::Create(); 100 root_web_layer_ = cc::Layer::Create();
94 101
95 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 102 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
96 103
97 cc::LayerTreeSettings settings; 104 cc::LayerTreeSettings settings;
98 105
99 // This will ensure PictureLayers always can have LCD text, to match the 106 // This will ensure PictureLayers always can have LCD text, to match the
100 // previous behaviour with ContentLayers, where LCD-not-allowed notifications 107 // previous behaviour with ContentLayers, where LCD-not-allowed notifications
101 // were ignored. 108 // were ignored.
102 settings.layers_always_allowed_lcd_text = true; 109 settings.layers_always_allowed_lcd_text = true;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 root_layer_->ResetCompositor(); 230 root_layer_->ResetCompositor();
224 231
225 if (animation_timeline_) 232 if (animation_timeline_)
226 animation_host_->RemoveAnimationTimeline(animation_timeline_.get()); 233 animation_host_->RemoveAnimationTimeline(animation_timeline_.get());
227 234
228 // Stop all outstanding draws before telling the ContextFactory to tear 235 // Stop all outstanding draws before telling the ContextFactory to tear
229 // down any contexts that the |host_| may rely upon. 236 // down any contexts that the |host_| may rely upon.
230 host_.reset(); 237 host_.reset();
231 238
232 context_factory_->RemoveCompositor(this); 239 context_factory_->RemoveCompositor(this);
233 auto* manager = context_factory_->GetSurfaceManager(); 240 if (context_factory_private_) {
234 for (auto& client : child_frame_sinks_) { 241 auto* manager = context_factory_private_->GetSurfaceManager();
235 DCHECK(client.is_valid()); 242 for (auto& client : child_frame_sinks_) {
236 manager->UnregisterFrameSinkHierarchy(frame_sink_id_, client); 243 DCHECK(client.is_valid());
244 manager->UnregisterFrameSinkHierarchy(frame_sink_id_, client);
245 }
246 manager->InvalidateFrameSinkId(frame_sink_id_);
237 } 247 }
238 manager->InvalidateFrameSinkId(frame_sink_id_);
239 } 248 }
240 249
241 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) { 250 void Compositor::AddFrameSink(const cc::FrameSinkId& frame_sink_id) {
242 context_factory_->GetSurfaceManager()->RegisterFrameSinkHierarchy( 251 if (!context_factory_private_)
sadrul 2016/12/09 00:11:03 Probably should be DCHECK()?
Fady Samuel 2016/12/13 19:13:59 I cannot unfortunately because Chrome still uses C
252 return;
253 context_factory_private_->GetSurfaceManager()->RegisterFrameSinkHierarchy(
243 frame_sink_id_, frame_sink_id); 254 frame_sink_id_, frame_sink_id);
244 child_frame_sinks_.insert(frame_sink_id); 255 child_frame_sinks_.insert(frame_sink_id);
245 } 256 }
246 257
247 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) { 258 void Compositor::RemoveFrameSink(const cc::FrameSinkId& frame_sink_id) {
259 if (!context_factory_private_)
260 return;
248 auto it = child_frame_sinks_.find(frame_sink_id); 261 auto it = child_frame_sinks_.find(frame_sink_id);
249 DCHECK(it != child_frame_sinks_.end()); 262 DCHECK(it != child_frame_sinks_.end());
250 DCHECK(it->is_valid()); 263 DCHECK(it->is_valid());
251 context_factory_->GetSurfaceManager()->UnregisterFrameSinkHierarchy( 264 context_factory_private_->GetSurfaceManager()->UnregisterFrameSinkHierarchy(
252 frame_sink_id_, *it); 265 frame_sink_id_, *it);
253 child_frame_sinks_.erase(it); 266 child_frame_sinks_.erase(it);
254 } 267 }
255 268
256 void Compositor::SetCompositorFrameSink( 269 void Compositor::SetCompositorFrameSink(
257 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) { 270 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink) {
258 compositor_frame_sink_requested_ = false; 271 compositor_frame_sink_requested_ = false;
259 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); 272 host_->SetCompositorFrameSink(std::move(compositor_frame_sink));
260 // Display properties are reset when the output surface is lost, so update it 273 // Display properties are reset when the output surface is lost, so update it
261 // to match the Compositor's. 274 // to match the Compositor's.
262 context_factory_->SetDisplayVisible(this, host_->IsVisible()); 275 if (context_factory_private_) {
263 context_factory_->SetDisplayColorSpace(this, color_space_); 276 context_factory_private_->SetDisplayVisible(this, host_->IsVisible());
277 context_factory_private_->SetDisplayColorSpace(this, color_space_);
278 }
264 } 279 }
265 280
266 void Compositor::ScheduleDraw() { 281 void Compositor::ScheduleDraw() {
267 host_->SetNeedsCommit(); 282 host_->SetNeedsCommit();
268 } 283 }
269 284
270 void Compositor::SetRootLayer(Layer* root_layer) { 285 void Compositor::SetRootLayer(Layer* root_layer) {
271 if (root_layer_ == root_layer) 286 if (root_layer_ == root_layer)
272 return; 287 return;
273 if (root_layer_) 288 if (root_layer_)
(...skipping 24 matching lines...) Expand all
298 host_->SetNeedsCommit(); 313 host_->SetNeedsCommit();
299 } 314 }
300 315
301 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { 316 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
302 // TODO(enne): Make this not commit. See ScheduleFullRedraw. 317 // TODO(enne): Make this not commit. See ScheduleFullRedraw.
303 host_->SetNeedsRedrawRect(damage_rect); 318 host_->SetNeedsRedrawRect(damage_rect);
304 host_->SetNeedsCommit(); 319 host_->SetNeedsCommit();
305 } 320 }
306 321
307 void Compositor::DisableSwapUntilResize() { 322 void Compositor::DisableSwapUntilResize() {
308 context_factory_->ResizeDisplay(this, gfx::Size()); 323 context_factory_private_->ResizeDisplay(this, gfx::Size());
309 } 324 }
310 325
311 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) { 326 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
312 std::unique_ptr<cc::SwapPromise> swap_promise( 327 std::unique_ptr<cc::SwapPromise> swap_promise(
313 new cc::LatencyInfoSwapPromise(latency_info)); 328 new cc::LatencyInfoSwapPromise(latency_info));
314 host_->QueueSwapPromise(std::move(swap_promise)); 329 host_->QueueSwapPromise(std::move(swap_promise));
315 } 330 }
316 331
317 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { 332 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
318 DCHECK_GT(scale, 0); 333 DCHECK_GT(scale, 0);
319 if (!size_in_pixel.IsEmpty()) { 334 if (!size_in_pixel.IsEmpty()) {
320 size_ = size_in_pixel; 335 size_ = size_in_pixel;
321 host_->GetLayerTree()->SetViewportSize(size_in_pixel); 336 host_->GetLayerTree()->SetViewportSize(size_in_pixel);
322 root_web_layer_->SetBounds(size_in_pixel); 337 root_web_layer_->SetBounds(size_in_pixel);
323 context_factory_->ResizeDisplay(this, size_in_pixel); 338 // TODO(fsamuel): Get rid of ContextFactoryPrivate.
339 if (context_factory_private_)
340 context_factory_private_->ResizeDisplay(this, size_in_pixel);
324 } 341 }
325 if (device_scale_factor_ != scale) { 342 if (device_scale_factor_ != scale) {
326 device_scale_factor_ = scale; 343 device_scale_factor_ = scale;
327 host_->GetLayerTree()->SetDeviceScaleFactor(scale); 344 host_->GetLayerTree()->SetDeviceScaleFactor(scale);
328 if (root_layer_) 345 if (root_layer_)
329 root_layer_->OnDeviceScaleFactorChanged(scale); 346 root_layer_->OnDeviceScaleFactorChanged(scale);
330 } 347 }
331 } 348 }
332 349
333 void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space) { 350 void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space) {
334 host_->GetLayerTree()->SetDeviceColorSpace(color_space); 351 host_->GetLayerTree()->SetDeviceColorSpace(color_space);
335 color_space_ = color_space; 352 color_space_ = color_space;
336 // Color space is reset when the output surface is lost, so this must also be 353 // Color space is reset when the output surface is lost, so this must also be
337 // updated then. 354 // updated then.
338 context_factory_->SetDisplayColorSpace(this, color_space_); 355 // TODO(fsamuel): Get rid of this.
356 if (context_factory_private_)
357 context_factory_private_->SetDisplayColorSpace(this, color_space_);
339 } 358 }
340 359
341 void Compositor::SetBackgroundColor(SkColor color) { 360 void Compositor::SetBackgroundColor(SkColor color) {
342 host_->GetLayerTree()->set_background_color(color); 361 host_->GetLayerTree()->set_background_color(color);
343 ScheduleDraw(); 362 ScheduleDraw();
344 } 363 }
345 364
346 void Compositor::SetVisible(bool visible) { 365 void Compositor::SetVisible(bool visible) {
347 host_->SetVisible(visible); 366 host_->SetVisible(visible);
348 // Visibility is reset when the output surface is lost, so this must also be 367 // Visibility is reset when the output surface is lost, so this must also be
349 // updated then. 368 // updated then.
350 context_factory_->SetDisplayVisible(this, visible); 369 // TODO(fsamuel): Eliminate this call.
370 if (context_factory_private_)
371 context_factory_private_->SetDisplayVisible(this, visible);
351 } 372 }
352 373
353 bool Compositor::IsVisible() { 374 bool Compositor::IsVisible() {
354 return host_->IsVisible(); 375 return host_->IsVisible();
355 } 376 }
356 377
357 bool Compositor::ScrollLayerTo(int layer_id, const gfx::ScrollOffset& offset) { 378 bool Compositor::ScrollLayerTo(int layer_id, const gfx::ScrollOffset& offset) {
358 return host_->GetInputHandler()->ScrollLayerTo(layer_id, offset); 379 return host_->GetInputHandler()->ScrollLayerTo(layer_id, offset);
359 } 380 }
360 381
361 bool Compositor::GetScrollOffsetForLayer(int layer_id, 382 bool Compositor::GetScrollOffsetForLayer(int layer_id,
362 gfx::ScrollOffset* offset) const { 383 gfx::ScrollOffset* offset) const {
363 return host_->GetInputHandler()->GetScrollOffsetForLayer(layer_id, offset); 384 return host_->GetInputHandler()->GetScrollOffsetForLayer(layer_id, offset);
364 } 385 }
365 386
366 void Compositor::SetAuthoritativeVSyncInterval( 387 void Compositor::SetAuthoritativeVSyncInterval(
367 const base::TimeDelta& interval) { 388 const base::TimeDelta& interval) {
368 context_factory_->SetAuthoritativeVSyncInterval(this, interval); 389 if (context_factory_private_)
390 context_factory_private_->SetAuthoritativeVSyncInterval(this, interval);
369 vsync_manager_->SetAuthoritativeVSyncInterval(interval); 391 vsync_manager_->SetAuthoritativeVSyncInterval(interval);
370 } 392 }
371 393
372 void Compositor::SetDisplayVSyncParameters(base::TimeTicks timebase, 394 void Compositor::SetDisplayVSyncParameters(base::TimeTicks timebase,
373 base::TimeDelta interval) { 395 base::TimeDelta interval) {
374 if (interval.is_zero()) { 396 if (interval.is_zero()) {
375 // TODO(brianderson): We should not be receiving 0 intervals. 397 // TODO(brianderson): We should not be receiving 0 intervals.
376 interval = cc::BeginFrameArgs::DefaultInterval(); 398 interval = cc::BeginFrameArgs::DefaultInterval();
377 } 399 }
378 400
379 context_factory_->SetDisplayVSyncParameters(this, timebase, interval); 401 if (context_factory_private_) {
402 context_factory_private_->SetDisplayVSyncParameters(this, timebase,
403 interval);
404 }
380 vsync_manager_->UpdateVSyncParameters(timebase, interval); 405 vsync_manager_->UpdateVSyncParameters(timebase, interval);
381 } 406 }
382 407
383 void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { 408 void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
384 // This function should only get called once. 409 // This function should only get called once.
385 DCHECK(!widget_valid_); 410 DCHECK(!widget_valid_);
386 widget_ = widget; 411 widget_ = widget;
387 widget_valid_ = true; 412 widget_valid_ = true;
388 if (compositor_frame_sink_requested_) 413 if (compositor_frame_sink_requested_)
389 context_factory_->CreateCompositorFrameSink(weak_ptr_factory_.GetWeakPtr()); 414 context_factory_->CreateCompositorFrameSink(weak_ptr_factory_.GetWeakPtr());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 observer.OnCompositingEnded(this); 517 observer.OnCompositingEnded(this);
493 } 518 }
494 519
495 void Compositor::DidSubmitCompositorFrame() { 520 void Compositor::DidSubmitCompositorFrame() {
496 base::TimeTicks start_time = base::TimeTicks::Now(); 521 base::TimeTicks start_time = base::TimeTicks::Now();
497 for (auto& observer : observer_list_) 522 for (auto& observer : observer_list_)
498 observer.OnCompositingStarted(this, start_time); 523 observer.OnCompositingStarted(this, start_time);
499 } 524 }
500 525
501 void Compositor::SetOutputIsSecure(bool output_is_secure) { 526 void Compositor::SetOutputIsSecure(bool output_is_secure) {
502 context_factory_->SetOutputIsSecure(this, output_is_secure); 527 if (context_factory_private_)
528 context_factory_private_->SetOutputIsSecure(this, output_is_secure);
503 } 529 }
504 530
505 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 531 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
506 return host_->GetDebugState(); 532 return host_->GetDebugState();
507 } 533 }
508 534
509 void Compositor::SetLayerTreeDebugState( 535 void Compositor::SetLayerTreeDebugState(
510 const cc::LayerTreeDebugState& debug_state) { 536 const cc::LayerTreeDebugState& debug_state) {
511 host_->SetDebugState(debug_state); 537 host_->SetDebugState(debug_state);
512 } 538 }
(...skipping 19 matching lines...) Expand all
532 for (auto& observer : observer_list_) 558 for (auto& observer : observer_list_)
533 observer.OnCompositingLockStateChanged(this); 559 observer.OnCompositingLockStateChanged(this);
534 } 560 }
535 561
536 void Compositor::CancelCompositorLock() { 562 void Compositor::CancelCompositorLock() {
537 if (compositor_lock_) 563 if (compositor_lock_)
538 compositor_lock_->CancelLock(); 564 compositor_lock_->CancelLock();
539 } 565 }
540 566
541 } // namespace ui 567 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698