blob: 7a1b2928a8890ac7d73b46511fa8191782788865 [file] [log] [blame]
[email protected]1920930592012-01-11 14:54:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c797cd42011-03-15 02:18:362// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]116302fc2012-05-05 21:45:415#include "ui/compositor/compositor.h"
[email protected]ed8de92d2011-09-14 04:16:486
[email protected]cff176a2012-06-29 21:11:007#include <algorithm>
[email protected]337bd042012-11-05 23:43:438#include <deque>
[email protected]cff176a2012-06-29 21:11:009
[email protected]6b16679e2012-10-27 00:44:2810#include "base/bind.h"
[email protected]ab6627372012-01-29 21:22:1311#include "base/command_line.h"
[email protected]89af4002013-09-06 07:47:0712#include "base/debug/trace_event.h"
[email protected]4e2d03e22013-07-18 04:19:5413#include "base/message_loop/message_loop.h"
[email protected]2f2fd9e2013-12-05 03:36:3014#include "base/metrics/histogram.h"
[email protected]f3652ff92013-06-11 13:54:3115#include "base/strings/string_util.h"
[email protected]49c4cf852013-09-27 19:28:2416#include "base/sys_info.h"
[email protected]d359203a2013-11-29 06:16:5517#include "cc/base/latency_info_swap_promise.h"
[email protected]4d5e6762013-03-19 18:46:5718#include "cc/base/switches.h"
[email protected]3052b10f2013-03-18 07:41:2119#include "cc/input/input_handler.h"
[email protected]cc3cfaa2013-03-18 09:05:5220#include "cc/layers/layer.h"
[email protected]7f0d825f2013-03-18 07:24:3021#include "cc/output/context_provider.h"
[email protected]556fd292013-03-18 08:03:0422#include "cc/trees/layer_tree_host.h"
[email protected]83afcbcc2012-07-27 03:06:2723#include "third_party/skia/include/core/SkBitmap.h"
[email protected]116302fc2012-05-05 21:45:4124#include "ui/compositor/compositor_observer.h"
25#include "ui/compositor/compositor_switches.h"
[email protected]2bd1fcf02014-02-12 22:35:5326#include "ui/compositor/compositor_vsync_manager.h"
[email protected]cd9a61c72012-05-08 19:16:5927#include "ui/compositor/dip_util.h"
[email protected]116302fc2012-05-05 21:45:4128#include "ui/compositor/layer.h"
[email protected]de2cf8c2013-10-25 19:46:4629#include "ui/gfx/frame_time.h"
[email protected]c9e2cbbb2012-05-12 21:17:2730#include "ui/gl/gl_context.h"
[email protected]cc2ae012012-09-21 19:35:2531#include "ui/gl/gl_switches.h"
[email protected]ab6627372012-01-29 21:22:1332
33namespace {
34
35const double kDefaultRefreshRate = 60.0;
[email protected]7ddeaab2013-04-06 00:47:0536const double kTestRefreshRate = 200.0;
[email protected]ab6627372012-01-29 21:22:1337
[email protected]894e8fc2012-02-24 13:29:5038ui::ContextFactory* g_context_factory = NULL;
39
[email protected]6b16679e2012-10-27 00:44:2840const int kCompositorLockTimeoutMs = 67;
41
[email protected]83afcbcc2012-07-27 03:06:2742} // namespace
[email protected]c797cd42011-03-15 02:18:3643
44namespace ui {
45
[email protected]894e8fc2012-02-24 13:29:5046// static
47ContextFactory* ContextFactory::GetInstance() {
[email protected]d56d3bb2013-08-12 20:58:0148 DCHECK(g_context_factory);
[email protected]894e8fc2012-02-24 13:29:5049 return g_context_factory;
[email protected]ca806632012-02-16 02:15:5950}
51
[email protected]58b4b6d2012-02-16 01:40:2452// static
[email protected]894e8fc2012-02-24 13:29:5053void ContextFactory::SetInstance(ContextFactory* instance) {
[email protected]dd7770d42014-02-21 17:56:5854 DCHECK_NE(!!g_context_factory, !!instance);
[email protected]894e8fc2012-02-24 13:29:5055 g_context_factory = instance;
[email protected]ca806632012-02-16 02:15:5956}
57
[email protected]6b16679e2012-10-27 00:44:2858CompositorLock::CompositorLock(Compositor* compositor)
59 : compositor_(compositor) {
[email protected]7060d6592013-04-29 19:01:4860 base::MessageLoop::current()->PostDelayedTask(
[email protected]6b16679e2012-10-27 00:44:2861 FROM_HERE,
62 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
63 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
64}
65
66CompositorLock::~CompositorLock() {
67 CancelLock();
68}
69
70void CompositorLock::CancelLock() {
71 if (!compositor_)
72 return;
73 compositor_->UnlockCompositor();
74 compositor_ = NULL;
75}
76
[email protected]337bd042012-11-05 23:43:4377} // namespace ui
78
79namespace {
80
[email protected]337bd042012-11-05 23:43:4381} // namespace
82
83namespace ui {
84
[email protected]60cff2732013-11-11 18:11:5085Compositor::Compositor(gfx::AcceleratedWidget widget)
[email protected]4183bf092014-05-17 17:33:5686 : context_factory_(g_context_factory),
87 root_layer_(NULL),
[email protected]ab6627372012-01-29 21:22:1388 widget_(widget),
[email protected]7898d192014-05-10 19:00:5189 compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()),
[email protected]2bd1fcf02014-02-12 22:35:5390 vsync_manager_(new CompositorVSyncManager()),
[email protected]d4ae80572012-06-06 23:02:0691 device_scale_factor_(0.0f),
92 last_started_frame_(0),
93 last_ended_frame_(0),
[email protected]6b16679e2012-10-27 00:44:2894 disable_schedule_composite_(false),
[email protected]c3fac4d2013-10-17 22:10:0595 compositor_lock_(NULL),
96 defer_draw_scheduling_(false),
97 waiting_on_compositing_end_(false),
98 draw_on_compositing_end_(false),
[email protected]6f41ac2a2014-04-02 04:13:3699 swap_state_(SWAP_NONE),
[email protected]e30ecf712013-11-01 23:21:09100 schedule_draw_factory_(this) {
[email protected]4183bf092014-05-17 17:33:56101 Init();
102}
103
104Compositor::Compositor(gfx::AcceleratedWidget widget,
105 ui::ContextFactory* context_factory)
106 : context_factory_(context_factory),
107 root_layer_(NULL),
108 widget_(widget),
109 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
110 vsync_manager_(new CompositorVSyncManager()),
111 device_scale_factor_(0.0f),
112 last_started_frame_(0),
113 last_ended_frame_(0),
114 disable_schedule_composite_(false),
115 compositor_lock_(NULL),
116 defer_draw_scheduling_(false),
117 waiting_on_compositing_end_(false),
118 draw_on_compositing_end_(false),
119 swap_state_(SWAP_NONE),
120 schedule_draw_factory_(this) {
121 Init();
122}
123
124// Yes, this is the wrong place. I'm leaving here to minimize diffs since this
125// function will be nuked soonish.
126void Compositor::Init() {
[email protected]7aba6662013-03-12 10:17:34127 root_web_layer_ = cc::Layer::Create();
128 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
[email protected]ec05af52012-11-21 23:07:00129
[email protected]ab6627372012-01-29 21:22:13130 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]4d5e6762013-03-19 18:46:57131
[email protected]ec05af52012-11-21 23:07:00132 cc::LayerTreeSettings settings;
[email protected]8e0176d2013-03-21 03:14:52133 settings.refresh_rate =
[email protected]4183bf092014-05-17 17:33:56134 context_factory_->DoesCreateTestContexts()
[email protected]d56d3bb2013-08-12 20:58:01135 ? kTestRefreshRate
136 : kDefaultRefreshRate;
[email protected]0c7a5612014-03-12 21:58:22137 settings.main_frame_before_draw_enabled = false;
138 settings.main_frame_before_activation_enabled = false;
[email protected]541f86ff2014-03-31 22:09:50139 settings.throttle_frame_production =
140 !command_line->HasSwitch(switches::kDisableGpuVsync);
[email protected]50e157272013-04-13 05:07:19141 settings.partial_swap_enabled =
142 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap);
[email protected]c6d0ba72014-02-19 20:47:28143#if defined(OS_CHROMEOS)
144 settings.per_tile_painting_enabled = true;
145#endif
[email protected]4d5e6762013-03-19 18:46:57146
147 // These flags should be mirrored by renderer versions in content/renderer/.
[email protected]8e0176d2013-03-21 03:14:52148 settings.initial_debug_state.show_debug_borders =
[email protected]4d5e6762013-03-19 18:46:57149 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
[email protected]8e0176d2013-03-21 03:14:52150 settings.initial_debug_state.show_fps_counter =
[email protected]4d5e6762013-03-19 18:46:57151 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
[email protected]bf9ed2c2013-12-10 22:18:39152 settings.initial_debug_state.show_layer_animation_bounds_rects =
153 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds);
[email protected]8e0176d2013-03-21 03:14:52154 settings.initial_debug_state.show_paint_rects =
[email protected]4d5e6762013-03-19 18:46:57155 command_line->HasSwitch(switches::kUIShowPaintRects);
[email protected]8e0176d2013-03-21 03:14:52156 settings.initial_debug_state.show_property_changed_rects =
[email protected]4d5e6762013-03-19 18:46:57157 command_line->HasSwitch(cc::switches::kUIShowPropertyChangedRects);
[email protected]8e0176d2013-03-21 03:14:52158 settings.initial_debug_state.show_surface_damage_rects =
[email protected]4d5e6762013-03-19 18:46:57159 command_line->HasSwitch(cc::switches::kUIShowSurfaceDamageRects);
[email protected]8e0176d2013-03-21 03:14:52160 settings.initial_debug_state.show_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57161 command_line->HasSwitch(cc::switches::kUIShowScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52162 settings.initial_debug_state.show_replica_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57163 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52164 settings.initial_debug_state.show_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57165 command_line->HasSwitch(cc::switches::kUIShowOccludingRects);
[email protected]8e0176d2013-03-21 03:14:52166 settings.initial_debug_state.show_non_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57167 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects);
[email protected]302fe422012-06-11 14:49:11168
[email protected]fe3beef2014-02-06 09:20:53169 settings.initial_debug_state.SetRecordRenderingStats(
170 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
171
[email protected]dafdf5052014-03-13 17:02:57172 settings.impl_side_painting = IsUIImplSidePaintingEnabled();
[email protected]2cccfef2014-05-01 06:05:16173 settings.use_zero_copy = IsUIZeroCopyEnabled();
[email protected]dafdf5052014-03-13 17:02:57174
[email protected]2f2fd9e2013-12-05 03:36:30175 base::TimeTicks before_create = base::TimeTicks::Now();
[email protected]7898d192014-05-10 19:00:51176 if (compositor_thread_loop_) {
[email protected]943528e2013-11-07 05:01:32177 host_ = cc::LayerTreeHost::CreateThreaded(
[email protected]142b19f2014-03-14 21:50:36178 this,
[email protected]4183bf092014-05-17 17:33:56179 context_factory_->GetSharedBitmapManager(),
[email protected]142b19f2014-03-14 21:50:36180 settings,
[email protected]7898d192014-05-10 19:00:51181 compositor_thread_loop_);
[email protected]943528e2013-11-07 05:01:32182 } else {
[email protected]142b19f2014-03-14 21:50:36183 host_ = cc::LayerTreeHost::CreateSingleThreaded(
[email protected]4183bf092014-05-17 17:33:56184 this, this, context_factory_->GetSharedBitmapManager(), settings);
[email protected]943528e2013-11-07 05:01:32185 }
[email protected]2f2fd9e2013-12-05 03:36:30186 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
187 base::TimeTicks::Now() - before_create);
[email protected]804c8982013-03-13 16:32:21188 host_->SetRootLayer(root_web_layer_);
[email protected]14bd5542013-05-08 21:51:30189 host_->SetLayerTreeHostClientReady();
[email protected]82a01ac2011-09-08 16:00:18190}
191
192Compositor::~Compositor() {
[email protected]89af4002013-09-06 07:47:07193 TRACE_EVENT0("shutdown", "Compositor::destructor");
194
[email protected]6b16679e2012-10-27 00:44:28195 CancelCompositorLock();
196 DCHECK(!compositor_lock_);
197
[email protected]7ab3f272011-11-16 00:51:56198 if (root_layer_)
199 root_layer_->SetCompositor(NULL);
[email protected]2700daddd2012-07-13 19:35:37200
201 // Stop all outstanding draws before telling the ContextFactory to tear
202 // down any contexts that the |host_| may rely upon.
203 host_.reset();
204
[email protected]4183bf092014-05-17 17:33:56205 context_factory_->RemoveCompositor(this);
[email protected]82a01ac2011-09-08 16:00:18206}
207
[email protected]332749032011-10-22 00:32:46208void Compositor::ScheduleDraw() {
[email protected]7898d192014-05-10 19:00:51209 if (compositor_thread_loop_) {
[email protected]aed37032014-05-16 21:30:10210 host_->SetNeedsCommit();
[email protected]c3fac4d2013-10-17 22:10:05211 } else if (!defer_draw_scheduling_) {
212 defer_draw_scheduling_ = true;
213 base::MessageLoop::current()->PostTask(
214 FROM_HERE,
215 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr()));
216 }
[email protected]332749032011-10-22 00:32:46217}
218
[email protected]993d6b322011-09-27 19:14:38219void Compositor::SetRootLayer(Layer* root_layer) {
[email protected]12233c362011-11-21 16:09:25220 if (root_layer_ == root_layer)
221 return;
[email protected]7ab3f272011-11-16 00:51:56222 if (root_layer_)
223 root_layer_->SetCompositor(NULL);
[email protected]993d6b322011-09-27 19:14:38224 root_layer_ = root_layer;
[email protected]7ab3f272011-11-16 00:51:56225 if (root_layer_ && !root_layer_->GetCompositor())
[email protected]993d6b322011-09-27 19:14:38226 root_layer_->SetCompositor(this);
[email protected]7aba6662013-03-12 10:17:34227 root_web_layer_->RemoveAllChildren();
[email protected]66efabe2012-08-18 03:06:06228 if (root_layer_)
[email protected]7aba6662013-03-12 10:17:34229 root_web_layer_->AddChild(root_layer_->cc_layer());
[email protected]993d6b322011-09-27 19:14:38230}
231
[email protected]ebd52522012-10-04 15:49:40232void Compositor::SetHostHasTransparentBackground(
233 bool host_has_transparent_background) {
[email protected]804c8982013-03-13 16:32:21234 host_->set_has_transparent_background(host_has_transparent_background);
[email protected]ebd52522012-10-04 15:49:40235}
236
[email protected]878705be2013-04-15 22:44:02237void Compositor::Draw() {
[email protected]7898d192014-05-10 19:00:51238 DCHECK(!compositor_thread_loop_);
[email protected]337bd042012-11-05 23:43:43239
[email protected]c3fac4d2013-10-17 22:10:05240 defer_draw_scheduling_ = false;
241 if (waiting_on_compositing_end_) {
242 draw_on_compositing_end_ = true;
243 return;
244 }
245 waiting_on_compositing_end_ = true;
246
247 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
248
[email protected]ed8de92d2011-09-14 04:16:48249 if (!root_layer_)
250 return;
251
[email protected]6f41ac2a2014-04-02 04:13:36252 DCHECK_NE(swap_state_, SWAP_POSTED);
253 swap_state_ = SWAP_NONE;
254
[email protected]d4ae80572012-06-06 23:02:06255 last_started_frame_++;
[email protected]337bd042012-11-05 23:43:43256 if (!IsLocked()) {
[email protected]6b16679e2012-10-27 00:44:28257 // TODO(nduca): Temporary while compositor calls
258 // compositeImmediately() directly.
[email protected]408b5e22013-03-19 09:48:09259 Layout();
[email protected]de2cf8c2013-10-25 19:46:46260 host_->Composite(gfx::FrameTime::Now());
[email protected]6b16679e2012-10-27 00:44:28261 }
[email protected]6f41ac2a2014-04-02 04:13:36262 if (swap_state_ == SWAP_NONE)
[email protected]1920930592012-01-11 14:54:48263 NotifyEnd();
[email protected]ab6627372012-01-29 21:22:13264}
265
[email protected]878705be2013-04-15 22:44:02266void Compositor::ScheduleFullRedraw() {
[email protected]804c8982013-03-13 16:32:21267 host_->SetNeedsRedraw();
[email protected]7df588fbd2012-02-10 14:15:56268}
269
[email protected]878705be2013-04-15 22:44:02270void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
271 host_->SetNeedsRedrawRect(damage_rect);
272}
273
[email protected]b5e2a732014-05-13 21:27:50274void Compositor::FinishAllRendering() {
275 host_->FinishAllRendering();
276}
277
[email protected]66239a22013-06-05 03:38:26278void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
[email protected]d359203a2013-11-29 06:16:55279 scoped_ptr<cc::SwapPromise> swap_promise(
280 new cc::LatencyInfoSwapPromise(latency_info));
281 host_->QueueSwapPromise(swap_promise.Pass());
[email protected]66239a22013-06-05 03:38:26282}
283
[email protected]cd9a61c72012-05-08 19:16:59284void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
[email protected]cff176a2012-06-29 21:11:00285 DCHECK_GT(scale, 0);
[email protected]351b8ce2012-11-27 23:37:16286 if (!size_in_pixel.IsEmpty()) {
287 size_ = size_in_pixel;
[email protected]18ce59702013-04-09 04:58:40288 host_->SetViewportSize(size_in_pixel);
[email protected]7aba6662013-03-12 10:17:34289 root_web_layer_->SetBounds(size_in_pixel);
[email protected]351b8ce2012-11-27 23:37:16290 }
[email protected]2e2216e42012-05-17 15:17:00291 if (device_scale_factor_ != scale) {
[email protected]cd9a61c72012-05-08 19:16:59292 device_scale_factor_ = scale;
[email protected]caa21662014-05-14 10:02:32293 host_->SetDeviceScaleFactor(scale);
[email protected]cd9a61c72012-05-08 19:16:59294 if (root_layer_)
295 root_layer_->OnDeviceScaleFactorChanged(scale);
296 }
[email protected]ed8de92d2011-09-14 04:16:48297}
298
[email protected]87601922013-04-02 03:56:42299void Compositor::SetBackgroundColor(SkColor color) {
300 host_->set_background_color(color);
301 ScheduleDraw();
302}
303
[email protected]2bd1fcf02014-02-12 22:35:53304scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const {
305 return vsync_manager_;
306}
307
[email protected]ed8de92d2011-09-14 04:16:48308void Compositor::AddObserver(CompositorObserver* observer) {
309 observer_list_.AddObserver(observer);
310}
311
312void Compositor::RemoveObserver(CompositorObserver* observer) {
313 observer_list_.RemoveObserver(observer);
314}
315
[email protected]3ce2feb2011-09-19 18:44:23316bool Compositor::HasObserver(CompositorObserver* observer) {
317 return observer_list_.HasObserver(observer);
318}
319
[email protected]408b5e22013-03-19 09:48:09320void Compositor::Layout() {
[email protected]d4ae80572012-06-06 23:02:06321 // We're sending damage that will be addressed during this composite
322 // cycle, so we don't need to schedule another composite to address it.
323 disable_schedule_composite_ = true;
[email protected]f78649ea2012-02-23 18:39:04324 if (root_layer_)
[email protected]cedc3952012-03-06 06:15:55325 root_layer_->SendDamagedRects();
[email protected]d4ae80572012-06-06 23:02:06326 disable_schedule_composite_ = false;
[email protected]ab6627372012-01-29 21:22:13327}
328
[email protected]ebc0e1df2013-08-01 02:46:22329scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
[email protected]4183bf092014-05-17 17:33:56330 return context_factory_->CreateOutputSurface(this, fallback);
[email protected]ab6627372012-01-29 21:22:13331}
332
[email protected]408b5e22013-03-19 09:48:09333void Compositor::DidCommit() {
[email protected]6b16679e2012-10-27 00:44:28334 DCHECK(!IsLocked());
[email protected]2700daddd2012-07-13 19:35:37335 FOR_EACH_OBSERVER(CompositorObserver,
336 observer_list_,
337 OnCompositingDidCommit(this));
338}
339
[email protected]408b5e22013-03-19 09:48:09340void Compositor::DidCommitAndDrawFrame() {
[email protected]de2cf8c2013-10-25 19:46:46341 base::TimeTicks start_time = gfx::FrameTime::Now();
[email protected]a8f677c2012-03-23 01:36:06342 FOR_EACH_OBSERVER(CompositorObserver,
343 observer_list_,
[email protected]3b6085512013-02-21 01:26:20344 OnCompositingStarted(this, start_time));
[email protected]ba7aeb82012-02-24 23:36:13345}
346
[email protected]408b5e22013-03-19 09:48:09347void Compositor::DidCompleteSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51348 if (compositor_thread_loop_) {
[email protected]4d7e46a2013-11-08 05:33:40349 NotifyEnd();
350 } else {
[email protected]6f41ac2a2014-04-02 04:13:36351 DCHECK_EQ(swap_state_, SWAP_POSTED);
352 NotifyEnd();
353 swap_state_ = SWAP_COMPLETED;
[email protected]4d7e46a2013-11-08 05:33:40354 }
[email protected]ab6627372012-01-29 21:22:13355}
356
[email protected]408b5e22013-03-19 09:48:09357void Compositor::ScheduleComposite() {
[email protected]d4ae80572012-06-06 23:02:06358 if (!disable_schedule_composite_)
359 ScheduleDraw();
[email protected]332749032011-10-22 00:32:46360}
361
[email protected]e3067e32013-11-22 07:51:45362void Compositor::ScheduleAnimation() {
363 ScheduleComposite();
364}
365
[email protected]4d7e46a2013-11-08 05:33:40366void Compositor::DidPostSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51367 DCHECK(!compositor_thread_loop_);
[email protected]6f41ac2a2014-04-02 04:13:36368 DCHECK_EQ(swap_state_, SWAP_NONE);
369 swap_state_ = SWAP_POSTED;
[email protected]4d7e46a2013-11-08 05:33:40370}
371
372void Compositor::DidAbortSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51373 if (!compositor_thread_loop_) {
[email protected]6f41ac2a2014-04-02 04:13:36374 if (swap_state_ == SWAP_POSTED) {
375 NotifyEnd();
376 swap_state_ = SWAP_COMPLETED;
[email protected]4d7e46a2013-11-08 05:33:40377 }
378 }
379
380 FOR_EACH_OBSERVER(CompositorObserver,
381 observer_list_,
382 OnCompositingAborted(this));
383}
384
[email protected]2e77cdbb2013-04-29 13:59:14385const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
386 return host_->debug_state();
[email protected]918f8db42013-04-27 01:53:40387}
388
[email protected]2e77cdbb2013-04-29 13:59:14389void Compositor::SetLayerTreeDebugState(
390 const cc::LayerTreeDebugState& debug_state) {
[email protected]918f8db42013-04-27 01:53:40391 host_->SetDebugState(debug_state);
392}
393
[email protected]6b16679e2012-10-27 00:44:28394scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
395 if (!compositor_lock_) {
396 compositor_lock_ = new CompositorLock(this);
[email protected]7898d192014-05-10 19:00:51397 if (compositor_thread_loop_)
[email protected]804c8982013-03-13 16:32:21398 host_->SetDeferCommits(true);
[email protected]6b16679e2012-10-27 00:44:28399 FOR_EACH_OBSERVER(CompositorObserver,
400 observer_list_,
401 OnCompositingLockStateChanged(this));
402 }
403 return compositor_lock_;
404}
405
406void Compositor::UnlockCompositor() {
407 DCHECK(compositor_lock_);
408 compositor_lock_ = NULL;
[email protected]7898d192014-05-10 19:00:51409 if (compositor_thread_loop_)
[email protected]804c8982013-03-13 16:32:21410 host_->SetDeferCommits(false);
[email protected]6b16679e2012-10-27 00:44:28411 FOR_EACH_OBSERVER(CompositorObserver,
412 observer_list_,
413 OnCompositingLockStateChanged(this));
414}
415
416void Compositor::CancelCompositorLock() {
417 if (compositor_lock_)
418 compositor_lock_->CancelLock();
419}
420
[email protected]a8f21152011-09-08 15:30:02421void Compositor::NotifyEnd() {
[email protected]d4ae80572012-06-06 23:02:06422 last_ended_frame_++;
[email protected]c3fac4d2013-10-17 22:10:05423 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
424 waiting_on_compositing_end_ = false;
425 if (draw_on_compositing_end_) {
426 draw_on_compositing_end_ = false;
427
428 // Call ScheduleDraw() instead of Draw() in order to allow other
429 // CompositorObservers to be notified before starting another
430 // draw cycle.
431 ScheduleDraw();
432 }
[email protected]a8f21152011-09-08 15:30:02433 FOR_EACH_OBSERVER(CompositorObserver,
434 observer_list_,
[email protected]3ce2feb2011-09-19 18:44:23435 OnCompositingEnded(this));
[email protected]a8f21152011-09-08 15:30:02436}
437
[email protected]c797cd42011-03-15 02:18:36438} // namespace ui