blob: cc44cec3679e735e9710dc4f5f9e2a8ac78365e0 [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]04c5900d2014-08-18 13:38:3621#include "cc/output/begin_frame_args.h"
[email protected]7f0d825f2013-03-18 07:24:3022#include "cc/output/context_provider.h"
jbaumanfdc3baa2014-10-10 00:22:0923#include "cc/surfaces/surface_id_allocator.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host.h"
[email protected]83afcbcc2012-07-27 03:06:2725#include "third_party/skia/include/core/SkBitmap.h"
[email protected]116302fc2012-05-05 21:45:4126#include "ui/compositor/compositor_observer.h"
27#include "ui/compositor/compositor_switches.h"
[email protected]2bd1fcf02014-02-12 22:35:5328#include "ui/compositor/compositor_vsync_manager.h"
[email protected]cd9a61c72012-05-08 19:16:5929#include "ui/compositor/dip_util.h"
[email protected]116302fc2012-05-05 21:45:4130#include "ui/compositor/layer.h"
[email protected]9034a282014-06-05 03:11:4731#include "ui/compositor/layer_animator_collection.h"
[email protected]de2cf8c2013-10-25 19:46:4632#include "ui/gfx/frame_time.h"
[email protected]c9e2cbbb2012-05-12 21:17:2733#include "ui/gl/gl_context.h"
[email protected]cc2ae012012-09-21 19:35:2534#include "ui/gl/gl_switches.h"
[email protected]ab6627372012-01-29 21:22:1335
36namespace {
37
38const double kDefaultRefreshRate = 60.0;
[email protected]7ddeaab2013-04-06 00:47:0539const double kTestRefreshRate = 200.0;
[email protected]ab6627372012-01-29 21:22:1340
[email protected]6b16679e2012-10-27 00:44:2841const int kCompositorLockTimeoutMs = 67;
42
[email protected]83afcbcc2012-07-27 03:06:2743} // namespace
[email protected]c797cd42011-03-15 02:18:3644
45namespace ui {
46
[email protected]6b16679e2012-10-27 00:44:2847CompositorLock::CompositorLock(Compositor* compositor)
48 : compositor_(compositor) {
[email protected]bd30a23e2014-07-25 21:54:1549 compositor_->task_runner_->PostDelayedTask(
[email protected]6b16679e2012-10-27 00:44:2850 FROM_HERE,
51 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
52 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
53}
54
55CompositorLock::~CompositorLock() {
56 CancelLock();
57}
58
59void CompositorLock::CancelLock() {
60 if (!compositor_)
61 return;
62 compositor_->UnlockCompositor();
63 compositor_ = NULL;
64}
65
[email protected]4183bf092014-05-17 17:33:5666Compositor::Compositor(gfx::AcceleratedWidget widget,
[email protected]bd30a23e2014-07-25 21:54:1567 ui::ContextFactory* context_factory,
68 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
[email protected]4183bf092014-05-17 17:33:5669 : context_factory_(context_factory),
70 root_layer_(NULL),
71 widget_(widget),
jbaumanfdc3baa2014-10-10 00:22:0972 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
[email protected]4183bf092014-05-17 17:33:5673 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
[email protected]bd30a23e2014-07-25 21:54:1574 task_runner_(task_runner),
[email protected]4183bf092014-05-17 17:33:5675 vsync_manager_(new CompositorVSyncManager()),
76 device_scale_factor_(0.0f),
weiliangc1f27b282014-10-09 17:10:3377 last_started_frame_(0),
78 last_ended_frame_(0),
[email protected]4183bf092014-05-17 17:33:5679 disable_schedule_composite_(false),
80 compositor_lock_(NULL),
weiliangc1f27b282014-10-09 17:10:3381 defer_draw_scheduling_(false),
82 waiting_on_compositing_end_(false),
83 draw_on_compositing_end_(false),
84 swap_state_(SWAP_NONE),
85 layer_animator_collection_(this),
jbauman1a7a5122014-10-28 00:22:5286 weak_ptr_factory_(this) {
[email protected]7aba6662013-03-12 10:17:3487 root_web_layer_ = cc::Layer::Create();
[email protected]ec05af52012-11-21 23:07:0088
[email protected]ab6627372012-01-29 21:22:1389 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]4d5e6762013-03-19 18:46:5790
[email protected]ec05af52012-11-21 23:07:0091 cc::LayerTreeSettings settings;
[email protected]8e0176d2013-03-21 03:14:5292 settings.refresh_rate =
[email protected]4183bf092014-05-17 17:33:5693 context_factory_->DoesCreateTestContexts()
[email protected]d56d3bb2013-08-12 20:58:0194 ? kTestRefreshRate
95 : kDefaultRefreshRate;
[email protected]0c7a5612014-03-12 21:58:2296 settings.main_frame_before_activation_enabled = false;
[email protected]541f86ff2014-03-31 22:09:5097 settings.throttle_frame_production =
98 !command_line->HasSwitch(switches::kDisableGpuVsync);
[email protected]977cff12014-06-06 17:43:2399#if !defined(OS_MACOSX)
[email protected]50e157272013-04-13 05:07:19100 settings.partial_swap_enabled =
101 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap);
[email protected]977cff12014-06-06 17:43:23102#endif
[email protected]c6d0ba72014-02-19 20:47:28103#if defined(OS_CHROMEOS)
104 settings.per_tile_painting_enabled = true;
105#endif
sunnyps340939792014-10-16 21:59:58106#if defined(OS_WIN)
107 settings.disable_hi_res_timer_tasks_on_battery = true;
108#endif
[email protected]4d5e6762013-03-19 18:46:57109
110 // These flags should be mirrored by renderer versions in content/renderer/.
[email protected]8e0176d2013-03-21 03:14:52111 settings.initial_debug_state.show_debug_borders =
[email protected]4d5e6762013-03-19 18:46:57112 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
[email protected]8e0176d2013-03-21 03:14:52113 settings.initial_debug_state.show_fps_counter =
[email protected]4d5e6762013-03-19 18:46:57114 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
[email protected]bf9ed2c2013-12-10 22:18:39115 settings.initial_debug_state.show_layer_animation_bounds_rects =
116 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds);
[email protected]8e0176d2013-03-21 03:14:52117 settings.initial_debug_state.show_paint_rects =
[email protected]4d5e6762013-03-19 18:46:57118 command_line->HasSwitch(switches::kUIShowPaintRects);
[email protected]8e0176d2013-03-21 03:14:52119 settings.initial_debug_state.show_property_changed_rects =
[email protected]4d5e6762013-03-19 18:46:57120 command_line->HasSwitch(cc::switches::kUIShowPropertyChangedRects);
[email protected]8e0176d2013-03-21 03:14:52121 settings.initial_debug_state.show_surface_damage_rects =
[email protected]4d5e6762013-03-19 18:46:57122 command_line->HasSwitch(cc::switches::kUIShowSurfaceDamageRects);
[email protected]8e0176d2013-03-21 03:14:52123 settings.initial_debug_state.show_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57124 command_line->HasSwitch(cc::switches::kUIShowScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52125 settings.initial_debug_state.show_replica_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57126 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52127 settings.initial_debug_state.show_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57128 command_line->HasSwitch(cc::switches::kUIShowOccludingRects);
[email protected]8e0176d2013-03-21 03:14:52129 settings.initial_debug_state.show_non_occluding_rects =
[email protected]4d5e6762013-03-19 18:46:57130 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects);
[email protected]302fe422012-06-11 14:49:11131
[email protected]fe3beef2014-02-06 09:20:53132 settings.initial_debug_state.SetRecordRenderingStats(
133 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
134
[email protected]dafdf5052014-03-13 17:02:57135 settings.impl_side_painting = IsUIImplSidePaintingEnabled();
[email protected]2cccfef2014-05-01 06:05:16136 settings.use_zero_copy = IsUIZeroCopyEnabled();
weiliangc1f27b282014-10-09 17:10:33137 settings.single_thread_proxy_scheduler = false;
[email protected]dafdf5052014-03-13 17:02:57138
[email protected]2f2fd9e2013-12-05 03:36:30139 base::TimeTicks before_create = base::TimeTicks::Now();
dcheng0efb94f2014-08-25 21:49:41140 if (compositor_thread_loop_.get()) {
[email protected]943528e2013-11-07 05:01:32141 host_ = cc::LayerTreeHost::CreateThreaded(
[email protected]142b19f2014-03-14 21:50:36142 this,
[email protected]4183bf092014-05-17 17:33:56143 context_factory_->GetSharedBitmapManager(),
reveman22dd9292014-10-13 20:52:05144 context_factory_->GetGpuMemoryBufferManager(),
[email protected]142b19f2014-03-14 21:50:36145 settings,
[email protected]bd30a23e2014-07-25 21:54:15146 task_runner_,
[email protected]7898d192014-05-10 19:00:51147 compositor_thread_loop_);
[email protected]943528e2013-11-07 05:01:32148 } else {
[email protected]142b19f2014-03-14 21:50:36149 host_ = cc::LayerTreeHost::CreateSingleThreaded(
[email protected]27e6a212014-07-18 15:51:27150 this,
151 this,
152 context_factory_->GetSharedBitmapManager(),
reveman22dd9292014-10-13 20:52:05153 context_factory_->GetGpuMemoryBufferManager(),
[email protected]27e6a212014-07-18 15:51:27154 settings,
[email protected]bd30a23e2014-07-25 21:54:15155 task_runner_);
[email protected]943528e2013-11-07 05:01:32156 }
[email protected]2f2fd9e2013-12-05 03:36:30157 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
158 base::TimeTicks::Now() - before_create);
[email protected]804c8982013-03-13 16:32:21159 host_->SetRootLayer(root_web_layer_);
jbaumandbccae1ab2014-11-06 23:26:44160 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace());
[email protected]14bd5542013-05-08 21:51:30161 host_->SetLayerTreeHostClientReady();
[email protected]82a01ac2011-09-08 16:00:18162}
163
164Compositor::~Compositor() {
[email protected]89af4002013-09-06 07:47:07165 TRACE_EVENT0("shutdown", "Compositor::destructor");
166
[email protected]6b16679e2012-10-27 00:44:28167 CancelCompositorLock();
168 DCHECK(!compositor_lock_);
169
[email protected]7ab3f272011-11-16 00:51:56170 if (root_layer_)
171 root_layer_->SetCompositor(NULL);
[email protected]2700daddd2012-07-13 19:35:37172
173 // Stop all outstanding draws before telling the ContextFactory to tear
174 // down any contexts that the |host_| may rely upon.
175 host_.reset();
176
[email protected]4183bf092014-05-17 17:33:56177 context_factory_->RemoveCompositor(this);
[email protected]82a01ac2011-09-08 16:00:18178}
179
jbauman1a7a5122014-10-28 00:22:52180void Compositor::SetOutputSurface(
181 scoped_ptr<cc::OutputSurface> output_surface) {
182 host_->SetOutputSurface(output_surface.Pass());
183}
184
[email protected]332749032011-10-22 00:32:46185void Compositor::ScheduleDraw() {
weiliangc1f27b282014-10-09 17:10:33186 if (compositor_thread_loop_.get()) {
187 host_->SetNeedsCommit();
188 } else if (!defer_draw_scheduling_) {
189 defer_draw_scheduling_ = true;
190 task_runner_->PostTask(
191 FROM_HERE,
jbauman1a7a5122014-10-28 00:22:52192 base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr()));
weiliangc1f27b282014-10-09 17:10:33193 }
[email protected]332749032011-10-22 00:32:46194}
195
[email protected]993d6b322011-09-27 19:14:38196void Compositor::SetRootLayer(Layer* root_layer) {
[email protected]12233c362011-11-21 16:09:25197 if (root_layer_ == root_layer)
198 return;
[email protected]7ab3f272011-11-16 00:51:56199 if (root_layer_)
200 root_layer_->SetCompositor(NULL);
[email protected]993d6b322011-09-27 19:14:38201 root_layer_ = root_layer;
[email protected]7ab3f272011-11-16 00:51:56202 if (root_layer_ && !root_layer_->GetCompositor())
[email protected]993d6b322011-09-27 19:14:38203 root_layer_->SetCompositor(this);
[email protected]7aba6662013-03-12 10:17:34204 root_web_layer_->RemoveAllChildren();
[email protected]66efabe2012-08-18 03:06:06205 if (root_layer_)
[email protected]7aba6662013-03-12 10:17:34206 root_web_layer_->AddChild(root_layer_->cc_layer());
[email protected]993d6b322011-09-27 19:14:38207}
208
[email protected]ebd52522012-10-04 15:49:40209void Compositor::SetHostHasTransparentBackground(
210 bool host_has_transparent_background) {
[email protected]804c8982013-03-13 16:32:21211 host_->set_has_transparent_background(host_has_transparent_background);
[email protected]ebd52522012-10-04 15:49:40212}
213
weiliangc1f27b282014-10-09 17:10:33214void Compositor::Draw() {
215 DCHECK(!compositor_thread_loop_.get());
216
217 defer_draw_scheduling_ = false;
218 if (waiting_on_compositing_end_) {
219 draw_on_compositing_end_ = true;
220 return;
221 }
222 if (!root_layer_)
223 return;
224
225 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
226
227 DCHECK_NE(swap_state_, SWAP_POSTED);
228 swap_state_ = SWAP_NONE;
229
230 waiting_on_compositing_end_ = true;
231 last_started_frame_++;
232 if (!IsLocked()) {
233 // TODO(nduca): Temporary while compositor calls
234 // compositeImmediately() directly.
235 cc::BeginFrameArgs args =
236 cc::BeginFrameArgs::Create(gfx::FrameTime::Now(),
237 base::TimeTicks(),
238 cc::BeginFrameArgs::DefaultInterval());
239 BeginMainFrame(args);
240 host_->Composite(args.frame_time);
241 }
242 if (swap_state_ == SWAP_NONE)
243 NotifyEnd();
244}
245
[email protected]878705be2013-04-15 22:44:02246void Compositor::ScheduleFullRedraw() {
[email protected]804c8982013-03-13 16:32:21247 host_->SetNeedsRedraw();
[email protected]7df588fbd2012-02-10 14:15:56248}
249
[email protected]878705be2013-04-15 22:44:02250void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
251 host_->SetNeedsRedrawRect(damage_rect);
252}
253
[email protected]b5e2a732014-05-13 21:27:50254void Compositor::FinishAllRendering() {
255 host_->FinishAllRendering();
256}
257
[email protected]66239a22013-06-05 03:38:26258void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
[email protected]d359203a2013-11-29 06:16:55259 scoped_ptr<cc::SwapPromise> swap_promise(
260 new cc::LatencyInfoSwapPromise(latency_info));
261 host_->QueueSwapPromise(swap_promise.Pass());
[email protected]66239a22013-06-05 03:38:26262}
263
[email protected]cd9a61c72012-05-08 19:16:59264void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
[email protected]cff176a2012-06-29 21:11:00265 DCHECK_GT(scale, 0);
[email protected]351b8ce2012-11-27 23:37:16266 if (!size_in_pixel.IsEmpty()) {
267 size_ = size_in_pixel;
[email protected]18ce59702013-04-09 04:58:40268 host_->SetViewportSize(size_in_pixel);
[email protected]7aba6662013-03-12 10:17:34269 root_web_layer_->SetBounds(size_in_pixel);
[email protected]351b8ce2012-11-27 23:37:16270 }
[email protected]2e2216e42012-05-17 15:17:00271 if (device_scale_factor_ != scale) {
[email protected]cd9a61c72012-05-08 19:16:59272 device_scale_factor_ = scale;
[email protected]caa21662014-05-14 10:02:32273 host_->SetDeviceScaleFactor(scale);
[email protected]cd9a61c72012-05-08 19:16:59274 if (root_layer_)
275 root_layer_->OnDeviceScaleFactorChanged(scale);
276 }
[email protected]ed8de92d2011-09-14 04:16:48277}
278
[email protected]87601922013-04-02 03:56:42279void Compositor::SetBackgroundColor(SkColor color) {
280 host_->set_background_color(color);
281 ScheduleDraw();
282}
283
ccameron18bbc2a2014-08-28 22:36:16284void Compositor::SetVisible(bool visible) {
285 host_->SetVisible(visible);
286}
287
[email protected]2bd1fcf02014-02-12 22:35:53288scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const {
289 return vsync_manager_;
290}
291
[email protected]ed8de92d2011-09-14 04:16:48292void Compositor::AddObserver(CompositorObserver* observer) {
[email protected]80be33882014-08-13 09:34:19293#if defined(OS_MACOSX)
294 // Debugging instrumentation for crbug.com/401630.
295 // TODO(ccameron): remove this.
296 CHECK(observer);
[email protected]6b4504f2014-08-09 10:29:47297 if (!observer_list_.HasObserver(observer))
298 observer->observing_count_ += 1;
299#endif
300
[email protected]ed8de92d2011-09-14 04:16:48301 observer_list_.AddObserver(observer);
302}
303
304void Compositor::RemoveObserver(CompositorObserver* observer) {
[email protected]80be33882014-08-13 09:34:19305#if defined(OS_MACOSX)
306 // Debugging instrumentation for crbug.com/401630.
307 // TODO(ccameron): remove this.
[email protected]6b4504f2014-08-09 10:29:47308 if (observer_list_.HasObserver(observer))
309 observer->observing_count_ -= 1;
310#endif
311
[email protected]ed8de92d2011-09-14 04:16:48312 observer_list_.RemoveObserver(observer);
313}
314
[email protected]3ce2feb2011-09-19 18:44:23315bool Compositor::HasObserver(CompositorObserver* observer) {
316 return observer_list_.HasObserver(observer);
317}
318
[email protected]5ffe6d142014-08-01 16:04:38319void Compositor::AddAnimationObserver(CompositorAnimationObserver* observer) {
320 animation_observer_list_.AddObserver(observer);
321 host_->SetNeedsAnimate();
322}
323
324void Compositor::RemoveAnimationObserver(
325 CompositorAnimationObserver* observer) {
326 animation_observer_list_.RemoveObserver(observer);
327}
328
329bool Compositor::HasAnimationObserver(CompositorAnimationObserver* observer) {
330 return animation_observer_list_.HasObserver(observer);
331}
332
[email protected]04c5900d2014-08-18 13:38:36333void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
[email protected]5ffe6d142014-08-01 16:04:38334 FOR_EACH_OBSERVER(CompositorAnimationObserver,
335 animation_observer_list_,
[email protected]04c5900d2014-08-18 13:38:36336 OnAnimationStep(args.frame_time));
[email protected]5ffe6d142014-08-01 16:04:38337 if (animation_observer_list_.might_have_observers())
[email protected]9034a282014-06-05 03:11:47338 host_->SetNeedsAnimate();
339}
340
[email protected]408b5e22013-03-19 09:48:09341void Compositor::Layout() {
[email protected]d4ae80572012-06-06 23:02:06342 // We're sending damage that will be addressed during this composite
343 // cycle, so we don't need to schedule another composite to address it.
344 disable_schedule_composite_ = true;
[email protected]f78649ea2012-02-23 18:39:04345 if (root_layer_)
[email protected]cedc3952012-03-06 06:15:55346 root_layer_->SendDamagedRects();
[email protected]d4ae80572012-06-06 23:02:06347 disable_schedule_composite_ = false;
[email protected]ab6627372012-01-29 21:22:13348}
349
enne2097cab2014-09-25 20:16:31350void Compositor::RequestNewOutputSurface(bool fallback) {
jbauman1a7a5122014-10-28 00:22:52351 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr(),
352 fallback);
[email protected]ab6627372012-01-29 21:22:13353}
354
[email protected]408b5e22013-03-19 09:48:09355void Compositor::DidCommit() {
[email protected]6b16679e2012-10-27 00:44:28356 DCHECK(!IsLocked());
[email protected]2700daddd2012-07-13 19:35:37357 FOR_EACH_OBSERVER(CompositorObserver,
358 observer_list_,
359 OnCompositingDidCommit(this));
360}
361
[email protected]408b5e22013-03-19 09:48:09362void Compositor::DidCommitAndDrawFrame() {
[email protected]de2cf8c2013-10-25 19:46:46363 base::TimeTicks start_time = gfx::FrameTime::Now();
[email protected]a8f677c2012-03-23 01:36:06364 FOR_EACH_OBSERVER(CompositorObserver,
365 observer_list_,
[email protected]3b6085512013-02-21 01:26:20366 OnCompositingStarted(this, start_time));
[email protected]ba7aeb82012-02-24 23:36:13367}
368
weiliangc1f27b282014-10-09 17:10:33369void Compositor::DidCompleteSwapBuffers() {
370 if (compositor_thread_loop_.get()) {
371 NotifyEnd();
372 } else {
373 DCHECK_EQ(swap_state_, SWAP_POSTED);
374 NotifyEnd();
375 swap_state_ = SWAP_COMPLETED;
376 }
377}
378
379void Compositor::ScheduleComposite() {
380 if (!disable_schedule_composite_)
381 ScheduleDraw();
382}
383
384void Compositor::ScheduleAnimation() {
385 ScheduleComposite();
386}
387
388void Compositor::DidPostSwapBuffers() {
389 DCHECK(!compositor_thread_loop_.get());
390 DCHECK_EQ(swap_state_, SWAP_NONE);
391 swap_state_ = SWAP_POSTED;
392}
393
[email protected]4d7e46a2013-11-08 05:33:40394void Compositor::DidAbortSwapBuffers() {
weiliangc1f27b282014-10-09 17:10:33395 if (!compositor_thread_loop_.get()) {
396 if (swap_state_ == SWAP_POSTED) {
397 NotifyEnd();
398 swap_state_ = SWAP_COMPLETED;
399 }
400 }
401
[email protected]4d7e46a2013-11-08 05:33:40402 FOR_EACH_OBSERVER(CompositorObserver,
403 observer_list_,
404 OnCompositingAborted(this));
405}
406
[email protected]2e77cdbb2013-04-29 13:59:14407const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
408 return host_->debug_state();
[email protected]918f8db42013-04-27 01:53:40409}
410
[email protected]2e77cdbb2013-04-29 13:59:14411void Compositor::SetLayerTreeDebugState(
412 const cc::LayerTreeDebugState& debug_state) {
[email protected]918f8db42013-04-27 01:53:40413 host_->SetDebugState(debug_state);
414}
415
[email protected]6b16679e2012-10-27 00:44:28416scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
417 if (!compositor_lock_) {
418 compositor_lock_ = new CompositorLock(this);
weiliangc1f27b282014-10-09 17:10:33419 if (compositor_thread_loop_.get())
420 host_->SetDeferCommits(true);
[email protected]6b16679e2012-10-27 00:44:28421 FOR_EACH_OBSERVER(CompositorObserver,
422 observer_list_,
423 OnCompositingLockStateChanged(this));
424 }
425 return compositor_lock_;
426}
427
428void Compositor::UnlockCompositor() {
429 DCHECK(compositor_lock_);
430 compositor_lock_ = NULL;
weiliangc1f27b282014-10-09 17:10:33431 if (compositor_thread_loop_.get())
432 host_->SetDeferCommits(false);
[email protected]6b16679e2012-10-27 00:44:28433 FOR_EACH_OBSERVER(CompositorObserver,
434 observer_list_,
435 OnCompositingLockStateChanged(this));
436}
437
438void Compositor::CancelCompositorLock() {
439 if (compositor_lock_)
440 compositor_lock_->CancelLock();
441}
442
weiliangc1f27b282014-10-09 17:10:33443void Compositor::NotifyEnd() {
444 last_ended_frame_++;
445 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
446 waiting_on_compositing_end_ = false;
447 if (draw_on_compositing_end_) {
448 draw_on_compositing_end_ = false;
449
450 // Call ScheduleDraw() instead of Draw() in order to allow other
451 // CompositorObservers to be notified before starting another
452 // draw cycle.
453 ScheduleDraw();
454 }
455 FOR_EACH_OBSERVER(
456 CompositorObserver, observer_list_, OnCompositingEnded(this));
457}
458
[email protected]c797cd42011-03-15 02:18:36459} // namespace ui