OLD | NEW |
---|---|
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 <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "cc/base/latency_info_swap_promise.h" | 17 #include "cc/base/latency_info_swap_promise.h" |
18 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
19 #include "cc/input/input_handler.h" | 19 #include "cc/input/input_handler.h" |
20 #include "cc/layers/layer.h" | 20 #include "cc/layers/layer.h" |
21 #include "cc/output/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
22 #include "cc/output/context_provider.h" | 22 #include "cc/output/context_provider.h" |
23 #include "cc/surfaces/surface_id_allocator.h" | |
23 #include "cc/trees/layer_tree_host.h" | 24 #include "cc/trees/layer_tree_host.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/compositor/compositor_observer.h" | 26 #include "ui/compositor/compositor_observer.h" |
26 #include "ui/compositor/compositor_switches.h" | 27 #include "ui/compositor/compositor_switches.h" |
27 #include "ui/compositor/compositor_vsync_manager.h" | 28 #include "ui/compositor/compositor_vsync_manager.h" |
28 #include "ui/compositor/dip_util.h" | 29 #include "ui/compositor/dip_util.h" |
29 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
30 #include "ui/compositor/layer_animator_collection.h" | 31 #include "ui/compositor/layer_animator_collection.h" |
31 #include "ui/gfx/frame_time.h" | 32 #include "ui/gfx/frame_time.h" |
32 #include "ui/gl/gl_context.h" | 33 #include "ui/gl/gl_context.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
61 compositor_->UnlockCompositor(); | 62 compositor_->UnlockCompositor(); |
62 compositor_ = NULL; | 63 compositor_ = NULL; |
63 } | 64 } |
64 | 65 |
65 } // namespace ui | 66 } // namespace ui |
66 | 67 |
67 namespace {} // namespace | 68 namespace {} // namespace |
68 | 69 |
69 namespace ui { | 70 namespace ui { |
70 | 71 |
72 class SatisfySwapPromise : public cc::SwapPromise { | |
73 public: | |
74 SatisfySwapPromise(uint32_t id) : id_(id) {} | |
jamesr
2014/09/24 04:51:01
explicit
| |
75 | |
76 private: | |
77 virtual void DidSwap(cc::CompositorFrameMetadata* metadata) OVERRIDE { | |
78 metadata->satisfies_sequences.push_back(id_); | |
79 } | |
80 | |
81 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { | |
82 // TODO: Send to the SurfaceManager immediately. | |
83 DCHECK(false); | |
84 } | |
85 virtual int64 TraceId() const OVERRIDE { return 0; } | |
86 uint32_t id_; | |
87 }; | |
88 | |
71 Compositor::Compositor(gfx::AcceleratedWidget widget, | 89 Compositor::Compositor(gfx::AcceleratedWidget widget, |
72 ui::ContextFactory* context_factory, | 90 ui::ContextFactory* context_factory, |
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 91 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
74 : context_factory_(context_factory), | 92 : context_factory_(context_factory), |
75 root_layer_(NULL), | 93 root_layer_(NULL), |
76 widget_(widget), | 94 widget_(widget), |
95 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), | |
96 surface_sequence_number_(0), | |
77 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), | 97 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
78 task_runner_(task_runner), | 98 task_runner_(task_runner), |
79 vsync_manager_(new CompositorVSyncManager()), | 99 vsync_manager_(new CompositorVSyncManager()), |
80 device_scale_factor_(0.0f), | 100 device_scale_factor_(0.0f), |
81 last_started_frame_(0), | 101 last_started_frame_(0), |
82 last_ended_frame_(0), | 102 last_ended_frame_(0), |
83 disable_schedule_composite_(false), | 103 disable_schedule_composite_(false), |
84 compositor_lock_(NULL), | 104 compositor_lock_(NULL), |
85 defer_draw_scheduling_(false), | 105 defer_draw_scheduling_(false), |
86 waiting_on_compositing_end_(false), | 106 waiting_on_compositing_end_(false), |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 419 |
400 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 420 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
401 return host_->debug_state(); | 421 return host_->debug_state(); |
402 } | 422 } |
403 | 423 |
404 void Compositor::SetLayerTreeDebugState( | 424 void Compositor::SetLayerTreeDebugState( |
405 const cc::LayerTreeDebugState& debug_state) { | 425 const cc::LayerTreeDebugState& debug_state) { |
406 host_->SetDebugState(debug_state); | 426 host_->SetDebugState(debug_state); |
407 } | 427 } |
408 | 428 |
429 cc::SurfaceSequence Compositor::CreateSurfaceSequence() { | |
430 cc::SurfaceSequence sequence; | |
431 sequence.id_namespace = surface_id_allocator_->id_namespace(); | |
432 sequence.sequence = ++surface_sequence_number_; | |
433 scoped_ptr<cc::SwapPromise> promise( | |
434 new SatisfySwapPromise(surface_sequence_number_)); | |
435 host_->QueueSwapPromise(promise.Pass()); | |
436 return sequence; | |
437 } | |
438 | |
409 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 439 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
410 if (!compositor_lock_) { | 440 if (!compositor_lock_) { |
411 compositor_lock_ = new CompositorLock(this); | 441 compositor_lock_ = new CompositorLock(this); |
412 if (compositor_thread_loop_.get()) | 442 if (compositor_thread_loop_.get()) |
413 host_->SetDeferCommits(true); | 443 host_->SetDeferCommits(true); |
414 FOR_EACH_OBSERVER(CompositorObserver, | 444 FOR_EACH_OBSERVER(CompositorObserver, |
415 observer_list_, | 445 observer_list_, |
416 OnCompositingLockStateChanged(this)); | 446 OnCompositingLockStateChanged(this)); |
417 } | 447 } |
418 return compositor_lock_; | 448 return compositor_lock_; |
(...skipping 24 matching lines...) Expand all Loading... | |
443 // Call ScheduleDraw() instead of Draw() in order to allow other | 473 // Call ScheduleDraw() instead of Draw() in order to allow other |
444 // CompositorObservers to be notified before starting another | 474 // CompositorObservers to be notified before starting another |
445 // draw cycle. | 475 // draw cycle. |
446 ScheduleDraw(); | 476 ScheduleDraw(); |
447 } | 477 } |
448 FOR_EACH_OBSERVER( | 478 FOR_EACH_OBSERVER( |
449 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 479 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
450 } | 480 } |
451 | 481 |
452 } // namespace ui | 482 } // namespace ui |
OLD | NEW |