blob: b5fb62a5d8b5abf7afbcae2c66119752a4c5360a [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]c3fac4d2013-10-17 22:10:0586 : root_layer_(NULL),
[email protected]ab6627372012-01-29 21:22:1387 widget_(widget),
[email protected]7898d192014-05-10 19:00:5188 compositor_thread_loop_(g_context_factory->GetCompositorMessageLoop()),
[email protected]2bd1fcf02014-02-12 22:35:5389 vsync_manager_(new CompositorVSyncManager()),
[email protected]d4ae80572012-06-06 23:02:0690 device_scale_factor_(0.0f),
91 last_started_frame_(0),
92 last_ended_frame_(0),
[email protected]6b16679e2012-10-27 00:44:2893 disable_schedule_composite_(false),
[email protected]c3fac4d2013-10-17 22:10:0594 compositor_lock_(NULL),
95 defer_draw_scheduling_(false),
96 waiting_on_compositing_end_(false),
97 draw_on_compositing_end_(false),
[email protected]6f41ac2a2014-04-02 04:13:3698 swap_state_(SWAP_NONE),
[email protected]e30ecf712013-11-01 23:21:0999 schedule_draw_factory_(this) {
[email protected]7aba6662013-03-12 10:17:34100 root_web_layer_ = cc::Layer::Create();
101 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
[email protected]ec05af52012-11-21 23:07:00102
[email protected]ab6627372012-01-29 21:22:13103 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]4d5e6762013-03-19 18:46:57104
[email protected]ec05af52012-11-21 23:07:00105 cc::LayerTreeSettings settings;
[email protected]8e0176d2013-03-21 03:14:52106 settings.refresh_rate =
[email protected]d56d3bb2013-08-12 20:58:01107 ContextFactory::GetInstance()->DoesCreateTestContexts()
108 ? kTestRefreshRate
109 : kDefaultRefreshRate;
[email protected]0c7a5612014-03-12 21:58:22110 settings.main_frame_before_draw_enabled = false;
111 settings.main_frame_before_activation_enabled = false;
[email protected]541f86ff2014-03-31 22:09:50112 settings.throttle_frame_production =
113 !command_line->HasSwitch(switches::kDisableGpuVsync);
[email protected]50e157272013-04-13 05:07:19114 settings.partial_swap_enabled =
115 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap);
[email protected]c6d0ba72014-02-19 20:47:28116#if defined(OS_CHROMEOS)
117 settings.per_tile_painting_enabled = true;
118#endif
[email protected]4d5e6762013-03-19 18:46:57119
120 // These flags should be mirrored by renderer versions in content/renderer/.
[email protected]8e0176d2013-03-21 03:14:52121 settings.initial_debug_state.show_debug_borders =
[email protected]4d5e6762013-03-19 18:46:57122 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
[email protected]8e0176d2013-03-21 03:14:52123 settings.initial_debug_state.show_fps_counter =
[email protected]4d5e6762013-03-19 18:46:57124 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
[email protected]bf9ed2c2013-12-10 22:18:39125 settings.initial_debug_state.show_layer_animation_bounds_rects =
126 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds);
[email protected]8e0176d2013-03-21 03:14:52127 settings.initial_debug_state.show_paint_rects =
[email protected]4d5e6762013-03-19 18:46:57128 command_line->HasSwitch(switches::kUIShowPaintRects);
[email protected]8e0176d2013-03-21 03:14:52129 settings.initial_debug_state.show_property_changed_rects =
[email protected]4d5e6762013-03-19 18:46:57130 command_line->HasSwitch(cc::switches::kUIShowPropertyChangedRects);
[email protected]8e0176d2013-03-21 03:14:52131 settings.initial_debug_state.show_surface_damage_rects =
[email protected]4d5e6762013-03-19 18:46:57132 command_line->HasSwitch(cc::switches::kUIShowSurfaceDamageRects);
[email protected]8e0176d2013-03-21 03:14:52133 settings.initial_debug_state.show_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57134 command_line->HasSwitch(cc::switches::kUIShowScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52135 settings.initial_debug_state.show_replica_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57136 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52137 settings.initial_debug_state.show_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57138 command_line->HasSwitch(cc::switches::kUIShowOccludingRects);
[email protected]8e0176d2013-03-21 03:14:52139 settings.initial_debug_state.show_non_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57140 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects);
[email protected]302fe422012-06-11 14:49:11141
[email protected]fe3beef2014-02-06 09:20:53142 settings.initial_debug_state.SetRecordRenderingStats(
143 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
144
[email protected]dafdf5052014-03-13 17:02:57145 settings.impl_side_painting = IsUIImplSidePaintingEnabled();
[email protected]2cccfef2014-05-01 06:05:16146 settings.use_zero_copy = IsUIZeroCopyEnabled();
[email protected]dafdf5052014-03-13 17:02:57147
[email protected]2f2fd9e2013-12-05 03:36:30148 base::TimeTicks before_create = base::TimeTicks::Now();
[email protected]7898d192014-05-10 19:00:51149 if (compositor_thread_loop_) {
[email protected]943528e2013-11-07 05:01:32150 host_ = cc::LayerTreeHost::CreateThreaded(
[email protected]142b19f2014-03-14 21:50:36151 this,
[email protected]8cd6c222014-05-09 02:21:58152 g_context_factory->GetSharedBitmapManager(),
[email protected]142b19f2014-03-14 21:50:36153 settings,
[email protected]7898d192014-05-10 19:00:51154 compositor_thread_loop_);
[email protected]943528e2013-11-07 05:01:32155 } else {
[email protected]142b19f2014-03-14 21:50:36156 host_ = cc::LayerTreeHost::CreateSingleThreaded(
[email protected]8cd6c222014-05-09 02:21:58157 this, this, g_context_factory->GetSharedBitmapManager(), settings);
[email protected]943528e2013-11-07 05:01:32158 }
[email protected]2f2fd9e2013-12-05 03:36:30159 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
160 base::TimeTicks::Now() - before_create);
[email protected]804c8982013-03-13 16:32:21161 host_->SetRootLayer(root_web_layer_);
[email protected]14bd5542013-05-08 21:51:30162 host_->SetLayerTreeHostClientReady();
[email protected]82a01ac2011-09-08 16:00:18163}
164
165Compositor::~Compositor() {
[email protected]89af4002013-09-06 07:47:07166 TRACE_EVENT0("shutdown", "Compositor::destructor");
167
[email protected]6b16679e2012-10-27 00:44:28168 CancelCompositorLock();
169 DCHECK(!compositor_lock_);
170
[email protected]7ab3f272011-11-16 00:51:56171 if (root_layer_)
172 root_layer_->SetCompositor(NULL);
[email protected]2700daddd2012-07-13 19:35:37173
174 // Stop all outstanding draws before telling the ContextFactory to tear
175 // down any contexts that the |host_| may rely upon.
176 host_.reset();
177
[email protected]40034cf2013-03-13 05:05:37178 ContextFactory::GetInstance()->RemoveCompositor(this);
[email protected]82a01ac2011-09-08 16:00:18179}
180
[email protected]332749032011-10-22 00:32:46181void Compositor::ScheduleDraw() {
[email protected]7898d192014-05-10 19:00:51182 if (compositor_thread_loop_) {
[email protected]de2cf8c2013-10-25 19:46:46183 host_->Composite(gfx::FrameTime::Now());
[email protected]c3fac4d2013-10-17 22:10:05184 } else if (!defer_draw_scheduling_) {
185 defer_draw_scheduling_ = true;
186 base::MessageLoop::current()->PostTask(
187 FROM_HERE,
188 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr()));
189 }
[email protected]332749032011-10-22 00:32:46190}
191
[email protected]993d6b322011-09-27 19:14:38192void Compositor::SetRootLayer(Layer* root_layer) {
[email protected]12233c362011-11-21 16:09:25193 if (root_layer_ == root_layer)
194 return;
[email protected]7ab3f272011-11-16 00:51:56195 if (root_layer_)
196 root_layer_->SetCompositor(NULL);
[email protected]993d6b322011-09-27 19:14:38197 root_layer_ = root_layer;
[email protected]7ab3f272011-11-16 00:51:56198 if (root_layer_ && !root_layer_->GetCompositor())
[email protected]993d6b322011-09-27 19:14:38199 root_layer_->SetCompositor(this);
[email protected]7aba6662013-03-12 10:17:34200 root_web_layer_->RemoveAllChildren();
[email protected]66efabe2012-08-18 03:06:06201 if (root_layer_)
[email protected]7aba6662013-03-12 10:17:34202 root_web_layer_->AddChild(root_layer_->cc_layer());
[email protected]993d6b322011-09-27 19:14:38203}
204
[email protected]ebd52522012-10-04 15:49:40205void Compositor::SetHostHasTransparentBackground(
206 bool host_has_transparent_background) {
[email protected]804c8982013-03-13 16:32:21207 host_->set_has_transparent_background(host_has_transparent_background);
[email protected]ebd52522012-10-04 15:49:40208}
209
[email protected]878705be2013-04-15 22:44:02210void Compositor::Draw() {
[email protected]7898d192014-05-10 19:00:51211 DCHECK(!compositor_thread_loop_);
[email protected]337bd042012-11-05 23:43:43212
[email protected]c3fac4d2013-10-17 22:10:05213 defer_draw_scheduling_ = false;
214 if (waiting_on_compositing_end_) {
215 draw_on_compositing_end_ = true;
216 return;
217 }
218 waiting_on_compositing_end_ = true;
219
220 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
221
[email protected]ed8de92d2011-09-14 04:16:48222 if (!root_layer_)
223 return;
224
[email protected]6f41ac2a2014-04-02 04:13:36225 DCHECK_NE(swap_state_, SWAP_POSTED);
226 swap_state_ = SWAP_NONE;
227
[email protected]d4ae80572012-06-06 23:02:06228 last_started_frame_++;
[email protected]337bd042012-11-05 23:43:43229 if (!IsLocked()) {
[email protected]6b16679e2012-10-27 00:44:28230 // TODO(nduca): Temporary while compositor calls
231 // compositeImmediately() directly.
[email protected]408b5e22013-03-19 09:48:09232 Layout();
[email protected]de2cf8c2013-10-25 19:46:46233 host_->Composite(gfx::FrameTime::Now());
[email protected]6b16679e2012-10-27 00:44:28234 }
[email protected]6f41ac2a2014-04-02 04:13:36235 if (swap_state_ == SWAP_NONE)
[email protected]1920930592012-01-11 14:54:48236 NotifyEnd();
[email protected]ab6627372012-01-29 21:22:13237}
238
[email protected]878705be2013-04-15 22:44:02239void Compositor::ScheduleFullRedraw() {
[email protected]804c8982013-03-13 16:32:21240 host_->SetNeedsRedraw();
[email protected]7df588fbd2012-02-10 14:15:56241}
242
[email protected]878705be2013-04-15 22:44:02243void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
244 host_->SetNeedsRedrawRect(damage_rect);
245}
246
[email protected]b5e2a732014-05-13 21:27:50247void Compositor::FinishAllRendering() {
248 host_->FinishAllRendering();
249}
250
[email protected]66239a22013-06-05 03:38:26251void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
[email protected]d359203a2013-11-29 06:16:55252 scoped_ptr<cc::SwapPromise> swap_promise(
253 new cc::LatencyInfoSwapPromise(latency_info));
254 host_->QueueSwapPromise(swap_promise.Pass());
[email protected]66239a22013-06-05 03:38:26255}
256
[email protected]cd9a61c72012-05-08 19:16:59257void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
[email protected]cff176a2012-06-29 21:11:00258 DCHECK_GT(scale, 0);
[email protected]351b8ce2012-11-27 23:37:16259 if (!size_in_pixel.IsEmpty()) {
260 size_ = size_in_pixel;
[email protected]18ce59702013-04-09 04:58:40261 host_->SetViewportSize(size_in_pixel);
[email protected]7aba6662013-03-12 10:17:34262 root_web_layer_->SetBounds(size_in_pixel);
[email protected]351b8ce2012-11-27 23:37:16263 }
[email protected]2e2216e42012-05-17 15:17:00264 if (device_scale_factor_ != scale) {
[email protected]cd9a61c72012-05-08 19:16:59265 device_scale_factor_ = scale;
266 if (root_layer_)
267 root_layer_->OnDeviceScaleFactorChanged(scale);
268 }
[email protected]ed8de92d2011-09-14 04:16:48269}
270
[email protected]87601922013-04-02 03:56:42271void Compositor::SetBackgroundColor(SkColor color) {
272 host_->set_background_color(color);
273 ScheduleDraw();
274}
275
[email protected]2bd1fcf02014-02-12 22:35:53276scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const {
277 return vsync_manager_;
278}
279
[email protected]ed8de92d2011-09-14 04:16:48280void Compositor::AddObserver(CompositorObserver* observer) {
281 observer_list_.AddObserver(observer);
282}
283
284void Compositor::RemoveObserver(CompositorObserver* observer) {
285 observer_list_.RemoveObserver(observer);
286}
287
[email protected]3ce2feb2011-09-19 18:44:23288bool Compositor::HasObserver(CompositorObserver* observer) {
289 return observer_list_.HasObserver(observer);
290}
291
[email protected]408b5e22013-03-19 09:48:09292void Compositor::Layout() {
[email protected]d4ae80572012-06-06 23:02:06293 // We're sending damage that will be addressed during this composite
294 // cycle, so we don't need to schedule another composite to address it.
295 disable_schedule_composite_ = true;
[email protected]f78649ea2012-02-23 18:39:04296 if (root_layer_)
[email protected]cedc3952012-03-06 06:15:55297 root_layer_->SendDamagedRects();
[email protected]d4ae80572012-06-06 23:02:06298 disable_schedule_composite_ = false;
[email protected]ab6627372012-01-29 21:22:13299}
300
[email protected]ebc0e1df2013-08-01 02:46:22301scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
[email protected]032b23bd2013-12-03 13:00:08302 return ContextFactory::GetInstance()->CreateOutputSurface(this, fallback);
[email protected]ab6627372012-01-29 21:22:13303}
304
[email protected]408b5e22013-03-19 09:48:09305void Compositor::DidCommit() {
[email protected]6b16679e2012-10-27 00:44:28306 DCHECK(!IsLocked());
[email protected]2700daddd2012-07-13 19:35:37307 FOR_EACH_OBSERVER(CompositorObserver,
308 observer_list_,
309 OnCompositingDidCommit(this));
310}
311
[email protected]408b5e22013-03-19 09:48:09312void Compositor::DidCommitAndDrawFrame() {
[email protected]de2cf8c2013-10-25 19:46:46313 base::TimeTicks start_time = gfx::FrameTime::Now();
[email protected]a8f677c2012-03-23 01:36:06314 FOR_EACH_OBSERVER(CompositorObserver,
315 observer_list_,
[email protected]3b6085512013-02-21 01:26:20316 OnCompositingStarted(this, start_time));
[email protected]ba7aeb82012-02-24 23:36:13317}
318
[email protected]408b5e22013-03-19 09:48:09319void Compositor::DidCompleteSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51320 if (compositor_thread_loop_) {
[email protected]4d7e46a2013-11-08 05:33:40321 NotifyEnd();
322 } else {
[email protected]6f41ac2a2014-04-02 04:13:36323 DCHECK_EQ(swap_state_, SWAP_POSTED);
324 NotifyEnd();
325 swap_state_ = SWAP_COMPLETED;
[email protected]4d7e46a2013-11-08 05:33:40326 }
[email protected]ab6627372012-01-29 21:22:13327}
328
[email protected]408b5e22013-03-19 09:48:09329void Compositor::ScheduleComposite() {
[email protected]d4ae80572012-06-06 23:02:06330 if (!disable_schedule_composite_)
331 ScheduleDraw();
[email protected]332749032011-10-22 00:32:46332}
333
[email protected]e3067e32013-11-22 07:51:45334void Compositor::ScheduleAnimation() {
335 ScheduleComposite();
336}
337
[email protected]4d7e46a2013-11-08 05:33:40338void Compositor::DidPostSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51339 DCHECK(!compositor_thread_loop_);
[email protected]6f41ac2a2014-04-02 04:13:36340 DCHECK_EQ(swap_state_, SWAP_NONE);
341 swap_state_ = SWAP_POSTED;
[email protected]4d7e46a2013-11-08 05:33:40342}
343
344void Compositor::DidAbortSwapBuffers() {
[email protected]7898d192014-05-10 19:00:51345 if (!compositor_thread_loop_) {
[email protected]6f41ac2a2014-04-02 04:13:36346 if (swap_state_ == SWAP_POSTED) {
347 NotifyEnd();
348 swap_state_ = SWAP_COMPLETED;
[email protected]4d7e46a2013-11-08 05:33:40349 }
350 }
351
352 FOR_EACH_OBSERVER(CompositorObserver,
353 observer_list_,
354 OnCompositingAborted(this));
355}
356
[email protected]2e77cdbb2013-04-29 13:59:14357const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
358 return host_->debug_state();
[email protected]918f8db42013-04-27 01:53:40359}
360
[email protected]2e77cdbb2013-04-29 13:59:14361void Compositor::SetLayerTreeDebugState(
362 const cc::LayerTreeDebugState& debug_state) {
[email protected]918f8db42013-04-27 01:53:40363 host_->SetDebugState(debug_state);
364}
365
[email protected]6b16679e2012-10-27 00:44:28366scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
367 if (!compositor_lock_) {
368 compositor_lock_ = new CompositorLock(this);
[email protected]7898d192014-05-10 19:00:51369 if (compositor_thread_loop_)
[email protected]804c8982013-03-13 16:32:21370 host_->SetDeferCommits(true);
[email protected]6b16679e2012-10-27 00:44:28371 FOR_EACH_OBSERVER(CompositorObserver,
372 observer_list_,
373 OnCompositingLockStateChanged(this));
374 }
375 return compositor_lock_;
376}
377
378void Compositor::UnlockCompositor() {
379 DCHECK(compositor_lock_);
380 compositor_lock_ = NULL;
[email protected]7898d192014-05-10 19:00:51381 if (compositor_thread_loop_)
[email protected]804c8982013-03-13 16:32:21382 host_->SetDeferCommits(false);
[email protected]6b16679e2012-10-27 00:44:28383 FOR_EACH_OBSERVER(CompositorObserver,
384 observer_list_,
385 OnCompositingLockStateChanged(this));
386}
387
388void Compositor::CancelCompositorLock() {
389 if (compositor_lock_)
390 compositor_lock_->CancelLock();
391}
392
[email protected]a8f21152011-09-08 15:30:02393void Compositor::NotifyEnd() {
[email protected]d4ae80572012-06-06 23:02:06394 last_ended_frame_++;
[email protected]c3fac4d2013-10-17 22:10:05395 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
396 waiting_on_compositing_end_ = false;
397 if (draw_on_compositing_end_) {
398 draw_on_compositing_end_ = false;
399
400 // Call ScheduleDraw() instead of Draw() in order to allow other
401 // CompositorObservers to be notified before starting another
402 // draw cycle.
403 ScheduleDraw();
404 }
[email protected]a8f21152011-09-08 15:30:02405 FOR_EACH_OBSERVER(CompositorObserver,
406 observer_list_,
[email protected]3ce2feb2011-09-19 18:44:23407 OnCompositingEnded(this));
[email protected]a8f21152011-09-08 15:30:02408}
409
[email protected]c797cd42011-03-15 02:18:36410} // namespace ui