blob: afb502601aa476812330d19d7c50f94dfdce366d [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
avi87b8b582015-12-24 21:35:257#include <stddef.h>
8
[email protected]cff176a2012-06-29 21:11:009#include <algorithm>
[email protected]337bd042012-11-05 23:43:4310#include <deque>
dcheng79c14492015-12-18 05:07:2611#include <utility>
[email protected]cff176a2012-06-29 21:11:0012
[email protected]6b16679e2012-10-27 00:44:2813#include "base/bind.h"
[email protected]ab6627372012-01-29 21:22:1314#include "base/command_line.h"
[email protected]4e2d03e22013-07-18 04:19:5415#include "base/message_loop/message_loop.h"
[email protected]2f2fd9e2013-12-05 03:36:3016#include "base/metrics/histogram.h"
[email protected]f3652ff92013-06-11 13:54:3117#include "base/strings/string_util.h"
[email protected]49c4cf852013-09-27 19:28:2418#include "base/sys_info.h"
ssid334fb87a2015-01-27 20:12:0719#include "base/trace_event/trace_event.h"
avi87b8b582015-12-24 21:35:2520#include "build/build_config.h"
loyso841229002015-12-21 10:03:2421#include "cc/animation/animation_host.h"
22#include "cc/animation/animation_id_provider.h"
23#include "cc/animation/animation_timeline.h"
[email protected]4d5e6762013-03-19 18:46:5724#include "cc/base/switches.h"
[email protected]3052b10f2013-03-18 07:41:2125#include "cc/input/input_handler.h"
[email protected]cc3cfaa2013-03-18 09:05:5226#include "cc/layers/layer.h"
[email protected]04c5900d2014-08-18 13:38:3627#include "cc/output/begin_frame_args.h"
[email protected]7f0d825f2013-03-18 07:24:3028#include "cc/output/context_provider.h"
jamesrf313a212015-03-16 21:27:3729#include "cc/output/latency_info_swap_promise.h"
simonhonga7e3ac42014-11-11 20:50:2230#include "cc/scheduler/begin_frame_source.h"
jbaumanfdc3baa2014-10-10 00:22:0931#include "cc/surfaces/surface_id_allocator.h"
[email protected]556fd292013-03-18 08:03:0432#include "cc/trees/layer_tree_host.h"
[email protected]83afcbcc2012-07-27 03:06:2733#include "third_party/skia/include/core/SkBitmap.h"
[email protected]116302fc2012-05-05 21:45:4134#include "ui/compositor/compositor_observer.h"
35#include "ui/compositor/compositor_switches.h"
dbeame627c522015-05-05 03:25:5236#include "ui/compositor/compositor_vsync_manager.h"
[email protected]cd9a61c72012-05-08 19:16:5937#include "ui/compositor/dip_util.h"
[email protected]116302fc2012-05-05 21:45:4138#include "ui/compositor/layer.h"
[email protected]9034a282014-06-05 03:11:4739#include "ui/compositor/layer_animator_collection.h"
[email protected]c9e2cbbb2012-05-12 21:17:2740#include "ui/gl/gl_context.h"
[email protected]cc2ae012012-09-21 19:35:2541#include "ui/gl/gl_switches.h"
[email protected]ab6627372012-01-29 21:22:1342
43namespace {
44
45const double kDefaultRefreshRate = 60.0;
[email protected]7ddeaab2013-04-06 00:47:0546const double kTestRefreshRate = 200.0;
[email protected]ab6627372012-01-29 21:22:1347
[email protected]83afcbcc2012-07-27 03:06:2748} // namespace
[email protected]c797cd42011-03-15 02:18:3649
50namespace ui {
51
[email protected]6b16679e2012-10-27 00:44:2852CompositorLock::CompositorLock(Compositor* compositor)
53 : compositor_(compositor) {
ccameron00e438cd2015-03-12 06:18:1454 if (compositor_->locks_will_time_out_) {
55 compositor_->task_runner_->PostDelayedTask(
56 FROM_HERE,
57 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()),
58 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
59 }
[email protected]6b16679e2012-10-27 00:44:2860}
61
62CompositorLock::~CompositorLock() {
63 CancelLock();
64}
65
66void CompositorLock::CancelLock() {
67 if (!compositor_)
68 return;
69 compositor_->UnlockCompositor();
70 compositor_ = NULL;
71}
72
sieversb2a31d3372015-08-25 19:27:1373Compositor::Compositor(ui::ContextFactory* context_factory,
[email protected]bd30a23e2014-07-25 21:54:1574 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
[email protected]4183bf092014-05-17 17:33:5675 : context_factory_(context_factory),
76 root_layer_(NULL),
sieversb2a31d3372015-08-25 19:27:1377 widget_(gfx::kNullAcceleratedWidget),
sieversca8baca2015-10-05 23:38:0278 widget_valid_(false),
79 output_surface_requested_(false),
jbaumanfdc3baa2014-10-10 00:22:0980 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
[email protected]bd30a23e2014-07-25 21:54:1581 task_runner_(task_runner),
dbeame627c522015-05-05 03:25:5282 vsync_manager_(new CompositorVSyncManager()),
[email protected]4183bf092014-05-17 17:33:5683 device_scale_factor_(0.0f),
isherman4f0404e12014-12-06 01:01:3384 last_started_frame_(0),
85 last_ended_frame_(0),
ccameron00e438cd2015-03-12 06:18:1486 locks_will_time_out_(true),
[email protected]4183bf092014-05-17 17:33:5687 compositor_lock_(NULL),
weiliangc1f27b282014-10-09 17:10:3388 layer_animator_collection_(this),
jbauman1a7a5122014-10-28 00:22:5289 weak_ptr_factory_(this) {
loysoa6edaaff2015-05-25 03:26:4490 root_web_layer_ = cc::Layer::Create(Layer::UILayerSettings());
[email protected]ec05af52012-11-21 23:07:0091
avi6b10fd02014-12-23 05:51:2392 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
[email protected]4d5e6762013-03-19 18:46:5793
[email protected]ec05af52012-11-21 23:07:0094 cc::LayerTreeSettings settings;
loysoa6edaaff2015-05-25 03:26:4495
danakj0006e95b2015-08-08 00:36:5496 // This will ensure PictureLayers always can have LCD text, to match the
97 // previous behaviour with ContentLayers, where LCD-not-allowed notifications
98 // were ignored.
danakj3f76ace2014-11-18 16:56:0099 settings.layers_always_allowed_lcd_text = true;
danakj0006e95b2015-08-08 00:36:54100 // Use occlusion to allow more overlapping windows to take less memory.
101 settings.use_occlusion_for_tile_prioritization = true;
jbaumanc5be44c2014-11-20 22:17:12102 settings.renderer_settings.refresh_rate =
103 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate
104 : kDefaultRefreshRate;
[email protected]0c7a5612014-03-12 21:58:22105 settings.main_frame_before_activation_enabled = false;
jincheol.jo5899bd552015-07-15 02:06:46106 if (command_line->HasSwitch(switches::kDisableGpuVsync)) {
107 std::string display_vsync_string =
108 command_line->GetSwitchValueASCII(switches::kDisableGpuVsync);
109 if (display_vsync_string == "gpu") {
110 settings.renderer_settings.disable_display_vsync = true;
111 } else if (display_vsync_string == "beginframe") {
112 settings.wait_for_beginframe_interval = false;
113 } else {
114 settings.renderer_settings.disable_display_vsync = true;
115 settings.wait_for_beginframe_interval = false;
116 }
117 }
jbaumanc5be44c2014-11-20 22:17:12118 settings.renderer_settings.partial_swap_enabled =
danakjee38c1c2015-10-15 19:22:50119 !command_line->HasSwitch(switches::kUIDisablePartialSwap);
sunnyps340939792014-10-16 21:59:58120#if defined(OS_WIN)
jbauman616238a2014-12-03 03:17:53121 settings.renderer_settings.finish_rendering_on_resize = true;
ccameron07e6ae22015-11-20 04:46:29122#elif defined(OS_MACOSX)
ccameronbe2457f2016-01-12 01:15:40123 settings.renderer_settings.release_overlay_resources_on_swap_complete = true;
sunnyps340939792014-10-16 21:59:58124#endif
[email protected]4d5e6762013-03-19 18:46:57125
126 // These flags should be mirrored by renderer versions in content/renderer/.
[email protected]8e0176d2013-03-21 03:14:52127 settings.initial_debug_state.show_debug_borders =
[email protected]4d5e6762013-03-19 18:46:57128 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
[email protected]bf9ed2c2013-12-10 22:18:39129 settings.initial_debug_state.show_layer_animation_bounds_rects =
130 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds);
[email protected]8e0176d2013-03-21 03:14:52131 settings.initial_debug_state.show_paint_rects =
[email protected]4d5e6762013-03-19 18:46:57132 command_line->HasSwitch(switches::kUIShowPaintRects);
[email protected]8e0176d2013-03-21 03:14:52133 settings.initial_debug_state.show_property_changed_rects =
[email protected]4d5e6762013-03-19 18:46:57134 command_line->HasSwitch(cc::switches::kUIShowPropertyChangedRects);
[email protected]8e0176d2013-03-21 03:14:52135 settings.initial_debug_state.show_surface_damage_rects =
[email protected]4d5e6762013-03-19 18:46:57136 command_line->HasSwitch(cc::switches::kUIShowSurfaceDamageRects);
[email protected]8e0176d2013-03-21 03:14:52137 settings.initial_debug_state.show_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57138 command_line->HasSwitch(cc::switches::kUIShowScreenSpaceRects);
[email protected]8e0176d2013-03-21 03:14:52139 settings.initial_debug_state.show_replica_screen_space_rects =
[email protected]4d5e6762013-03-19 18:46:57140 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects);
[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
ajumab6adea92015-12-06 17:19:15145 if (command_line->HasSwitch(cc::switches::kDisableCompositorPropertyTrees))
146 settings.use_property_trees = false;
[email protected]2cccfef2014-05-01 06:05:16147 settings.use_zero_copy = IsUIZeroCopyEnabled();
danakjadd76822015-05-27 02:09:43148
rbyers77d1de52015-12-18 15:56:22149 settings.renderer_settings.use_rgba_4444_textures =
150 command_line->HasSwitch(switches::kUIEnableRGBA4444Textures);
revemancfd85ee2015-08-20 21:14:01151
ericrk1d17f752015-10-20 03:03:07152 // UI compositor always uses partial raster if not using zero-copy. Zero copy
153 // doesn't currently support partial raster.
154 settings.use_partial_raster = !settings.use_zero_copy;
155
revemaneb0fda22015-10-26 20:27:47156 // Use CPU_READ_WRITE_PERSISTENT memory buffers to support partial tile
157 // raster if needed.
158 gfx::BufferUsage usage =
159 settings.use_partial_raster
160 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT
161 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE;
danakjadd76822015-05-27 02:09:43162
jie.a.chen0ffadce32015-08-07 12:59:23163 for (size_t format = 0;
164 format < static_cast<size_t>(gfx::BufferFormat::LAST) + 1; format++) {
165 DCHECK_GT(settings.use_image_texture_targets.size(), format);
166 settings.use_image_texture_targets[format] =
167 context_factory_->GetImageTextureTarget(
168 static_cast<gfx::BufferFormat>(format), usage);
169 }
danakjadd76822015-05-27 02:09:43170
vmpstrdfd22862015-09-25 17:42:41171 // Note: Only enable image decode tasks if we have more than one worker
172 // thread.
173 settings.image_decode_tasks_enabled = false;
[email protected]dafdf5052014-03-13 17:02:57174
loyso4cc0ad4e2015-12-21 23:34:03175 settings.use_compositor_animation_timelines = !command_line->HasSwitch(
176 switches::kUIDisableCompositorAnimationTimelines);
loyso85a000ae2015-06-02 01:31:27177
sohan.jyotidb8e72682015-11-04 17:46:32178#if !defined(OS_ANDROID)
179 // TODO(sohanjg): Revisit this memory usage in tile manager.
180 cc::ManagedMemoryPolicy policy(
181 512 * 1024 * 1024, gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
182 settings.memory_policy_.num_resources_limit);
183 settings.memory_policy_ = policy;
184#endif
185
[email protected]2f2fd9e2013-12-05 03:36:30186 base::TimeTicks before_create = base::TimeTicks::Now();
sadrul6780f3da2015-05-11 17:01:52187
188 cc::LayerTreeHost::InitParams params;
189 params.client = this;
190 params.shared_bitmap_manager = context_factory_->GetSharedBitmapManager();
191 params.gpu_memory_buffer_manager =
192 context_factory_->GetGpuMemoryBufferManager();
193 params.task_graph_runner = context_factory_->GetTaskGraphRunner();
194 params.settings = &settings;
195 params.main_task_runner = task_runner_;
196 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
[email protected]2f2fd9e2013-12-05 03:36:30197 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
198 base::TimeTicks::Now() - before_create);
loyso841229002015-12-21 10:03:24199
200 if (settings.use_compositor_animation_timelines) {
201 animation_timeline_ = cc::AnimationTimeline::Create(
202 cc::AnimationIdProvider::NextTimelineId());
203 host_->animation_host()->AddAnimationTimeline(animation_timeline_.get());
204 }
[email protected]804c8982013-03-13 16:32:21205 host_->SetRootLayer(root_web_layer_);
jbaumandbccae1ab2014-11-06 23:26:44206 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace());
sievers71c62dd52015-10-07 01:44:39207 host_->SetVisible(true);
[email protected]82a01ac2011-09-08 16:00:18208}
209
210Compositor::~Compositor() {
[email protected]89af4002013-09-06 07:47:07211 TRACE_EVENT0("shutdown", "Compositor::destructor");
212
[email protected]6b16679e2012-10-27 00:44:28213 CancelCompositorLock();
214 DCHECK(!compositor_lock_);
215
ccameron92bcf312015-01-23 21:04:09216 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
217 OnCompositingShuttingDown(this));
218
lof84adf2ce862015-06-02 22:23:32219 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_,
220 OnCompositingShuttingDown(this));
221
[email protected]7ab3f272011-11-16 00:51:56222 if (root_layer_)
loysoac008462015-05-27 01:05:50223 root_layer_->ResetCompositor();
[email protected]2700daddd2012-07-13 19:35:37224
loyso841229002015-12-21 10:03:24225 if (animation_timeline_)
226 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get());
227
[email protected]2700daddd2012-07-13 19:35:37228 // Stop all outstanding draws before telling the ContextFactory to tear
229 // down any contexts that the |host_| may rely upon.
230 host_.reset();
231
[email protected]4183bf092014-05-17 17:33:56232 context_factory_->RemoveCompositor(this);
[email protected]82a01ac2011-09-08 16:00:18233}
234
jbauman1a7a5122014-10-28 00:22:52235void Compositor::SetOutputSurface(
236 scoped_ptr<cc::OutputSurface> output_surface) {
sieversca8baca2015-10-05 23:38:02237 output_surface_requested_ = false;
dcheng79c14492015-12-18 05:07:26238 host_->SetOutputSurface(std::move(output_surface));
jbauman1a7a5122014-10-28 00:22:52239}
240
[email protected]332749032011-10-22 00:32:46241void Compositor::ScheduleDraw() {
weiliangc5efa0a12015-01-29 19:56:46242 host_->SetNeedsCommit();
[email protected]332749032011-10-22 00:32:46243}
244
[email protected]993d6b322011-09-27 19:14:38245void Compositor::SetRootLayer(Layer* root_layer) {
[email protected]12233c362011-11-21 16:09:25246 if (root_layer_ == root_layer)
247 return;
[email protected]7ab3f272011-11-16 00:51:56248 if (root_layer_)
loysoac008462015-05-27 01:05:50249 root_layer_->ResetCompositor();
[email protected]993d6b322011-09-27 19:14:38250 root_layer_ = root_layer;
[email protected]7aba6662013-03-12 10:17:34251 root_web_layer_->RemoveAllChildren();
[email protected]66efabe2012-08-18 03:06:06252 if (root_layer_)
loysoac008462015-05-27 01:05:50253 root_layer_->SetCompositor(this, root_web_layer_);
[email protected]993d6b322011-09-27 19:14:38254}
255
loyso841229002015-12-21 10:03:24256cc::AnimationTimeline* Compositor::GetAnimationTimeline() const {
257 return animation_timeline_.get();
258}
259
[email protected]ebd52522012-10-04 15:49:40260void Compositor::SetHostHasTransparentBackground(
261 bool host_has_transparent_background) {
[email protected]804c8982013-03-13 16:32:21262 host_->set_has_transparent_background(host_has_transparent_background);
[email protected]ebd52522012-10-04 15:49:40263}
264
[email protected]878705be2013-04-15 22:44:02265void Compositor::ScheduleFullRedraw() {
weiliangc5efa0a12015-01-29 19:56:46266 // TODO(enne): Some callers (mac) call this function expecting that it
267 // will also commit. This should probably just redraw the screen
268 // from damage and not commit. ScheduleDraw/ScheduleRedraw need
269 // better names.
[email protected]804c8982013-03-13 16:32:21270 host_->SetNeedsRedraw();
weiliangc5efa0a12015-01-29 19:56:46271 host_->SetNeedsCommit();
[email protected]7df588fbd2012-02-10 14:15:56272}
273
[email protected]878705be2013-04-15 22:44:02274void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
weiliangc5efa0a12015-01-29 19:56:46275 // TODO(enne): Make this not commit. See ScheduleFullRedraw.
[email protected]878705be2013-04-15 22:44:02276 host_->SetNeedsRedrawRect(damage_rect);
weiliangc5efa0a12015-01-29 19:56:46277 host_->SetNeedsCommit();
[email protected]878705be2013-04-15 22:44:02278}
279
chirantan40e4cd82015-02-19 01:08:19280void Compositor::FinishAllRendering() {
281 host_->FinishAllRendering();
282}
283
jbauman616238a2014-12-03 03:17:53284void Compositor::DisableSwapUntilResize() {
[email protected]b5e2a732014-05-13 21:27:50285 host_->FinishAllRendering();
jbauman616238a2014-12-03 03:17:53286 context_factory_->ResizeDisplay(this, gfx::Size());
[email protected]b5e2a732014-05-13 21:27:50287}
288
[email protected]66239a22013-06-05 03:38:26289void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
[email protected]d359203a2013-11-29 06:16:55290 scoped_ptr<cc::SwapPromise> swap_promise(
291 new cc::LatencyInfoSwapPromise(latency_info));
dcheng79c14492015-12-18 05:07:26292 host_->QueueSwapPromise(std::move(swap_promise));
[email protected]66239a22013-06-05 03:38:26293}
294
[email protected]cd9a61c72012-05-08 19:16:59295void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
[email protected]cff176a2012-06-29 21:11:00296 DCHECK_GT(scale, 0);
[email protected]351b8ce2012-11-27 23:37:16297 if (!size_in_pixel.IsEmpty()) {
298 size_ = size_in_pixel;
[email protected]18ce59702013-04-09 04:58:40299 host_->SetViewportSize(size_in_pixel);
[email protected]7aba6662013-03-12 10:17:34300 root_web_layer_->SetBounds(size_in_pixel);
jbauman616238a2014-12-03 03:17:53301 context_factory_->ResizeDisplay(this, size_in_pixel);
[email protected]351b8ce2012-11-27 23:37:16302 }
[email protected]2e2216e42012-05-17 15:17:00303 if (device_scale_factor_ != scale) {
[email protected]cd9a61c72012-05-08 19:16:59304 device_scale_factor_ = scale;
[email protected]caa21662014-05-14 10:02:32305 host_->SetDeviceScaleFactor(scale);
[email protected]cd9a61c72012-05-08 19:16:59306 if (root_layer_)
307 root_layer_->OnDeviceScaleFactorChanged(scale);
308 }
[email protected]ed8de92d2011-09-14 04:16:48309}
310
[email protected]87601922013-04-02 03:56:42311void Compositor::SetBackgroundColor(SkColor color) {
312 host_->set_background_color(color);
313 ScheduleDraw();
314}
315
ccameron18bbc2a2014-08-28 22:36:16316void Compositor::SetVisible(bool visible) {
317 host_->SetVisible(visible);
318}
319
chirantan40e4cd82015-02-19 01:08:19320bool Compositor::IsVisible() {
321 return host_->visible();
322}
323
simonhong047d61b2015-05-22 02:37:58324void Compositor::SetAuthoritativeVSyncInterval(
325 const base::TimeDelta& interval) {
326 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
327 cc::switches::kEnableBeginFrameScheduling)) {
328 host_->SetAuthoritativeVSyncInterval(interval);
329 return;
330 }
331
332 vsync_manager_->SetAuthoritativeVSyncInterval(interval);
333}
334
sieversca8baca2015-10-05 23:38:02335void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
sieversb2a31d3372015-08-25 19:27:13336 // This function should only get called once.
sieversca8baca2015-10-05 23:38:02337 DCHECK(!widget_valid_);
sieversb2a31d3372015-08-25 19:27:13338 widget_ = widget;
sieversca8baca2015-10-05 23:38:02339 widget_valid_ = true;
340 if (output_surface_requested_)
341 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr());
342}
343
sievers13e78282015-10-06 01:54:40344gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() {
345 DCHECK(!IsVisible());
346 if (!host_->output_surface_lost())
347 host_->ReleaseOutputSurface();
348 context_factory_->RemoveCompositor(this);
349 widget_valid_ = false;
350 gfx::AcceleratedWidget widget = widget_;
351 widget_ = gfx::kNullAcceleratedWidget;
352 return widget;
353}
354
sieversca8baca2015-10-05 23:38:02355gfx::AcceleratedWidget Compositor::widget() const {
356 DCHECK(widget_valid_);
357 return widget_;
sieversb2a31d3372015-08-25 19:27:13358}
359
dbeame627c522015-05-05 03:25:52360scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const {
361 return vsync_manager_;
[email protected]2bd1fcf02014-02-12 22:35:53362}
363
[email protected]ed8de92d2011-09-14 04:16:48364void Compositor::AddObserver(CompositorObserver* observer) {
365 observer_list_.AddObserver(observer);
366}
367
368void Compositor::RemoveObserver(CompositorObserver* observer) {
369 observer_list_.RemoveObserver(observer);
370}
371
mgiuca64ccf2362014-11-10 06:44:23372bool Compositor::HasObserver(const CompositorObserver* observer) const {
[email protected]3ce2feb2011-09-19 18:44:23373 return observer_list_.HasObserver(observer);
374}
375
[email protected]5ffe6d142014-08-01 16:04:38376void Compositor::AddAnimationObserver(CompositorAnimationObserver* observer) {
377 animation_observer_list_.AddObserver(observer);
378 host_->SetNeedsAnimate();
379}
380
381void Compositor::RemoveAnimationObserver(
382 CompositorAnimationObserver* observer) {
383 animation_observer_list_.RemoveObserver(observer);
384}
385
mgiuca64ccf2362014-11-10 06:44:23386bool Compositor::HasAnimationObserver(
387 const CompositorAnimationObserver* observer) const {
[email protected]5ffe6d142014-08-01 16:04:38388 return animation_observer_list_.HasObserver(observer);
389}
390
simonhong8af4c832015-03-21 07:40:51391void Compositor::AddBeginFrameObserver(CompositorBeginFrameObserver* observer) {
jdduke7620c3c82015-10-22 21:46:47392 if (!begin_frame_observer_list_.might_have_observers())
simonhong8af4c832015-03-21 07:40:51393 host_->SetChildrenNeedBeginFrames(true);
394
jdduke7620c3c82015-10-22 21:46:47395 begin_frame_observer_list_.AddObserver(observer);
396
simonhong8af4c832015-03-21 07:40:51397 if (missed_begin_frame_args_.IsValid())
398 observer->OnSendBeginFrame(missed_begin_frame_args_);
simonhong8af4c832015-03-21 07:40:51399}
400
401void Compositor::RemoveBeginFrameObserver(
402 CompositorBeginFrameObserver* observer) {
jdduke7620c3c82015-10-22 21:46:47403 begin_frame_observer_list_.RemoveObserver(observer);
simonhong8af4c832015-03-21 07:40:51404
jdduke7620c3c82015-10-22 21:46:47405 // As this call may take place while iterating over observers, unsubscription
406 // from |host_| is performed after iteration in |SendBeginFramesToChildren()|.
simonhong8af4c832015-03-21 07:40:51407}
408
[email protected]04c5900d2014-08-18 13:38:36409void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
[email protected]5ffe6d142014-08-01 16:04:38410 FOR_EACH_OBSERVER(CompositorAnimationObserver,
411 animation_observer_list_,
[email protected]04c5900d2014-08-18 13:38:36412 OnAnimationStep(args.frame_time));
[email protected]5ffe6d142014-08-01 16:04:38413 if (animation_observer_list_.might_have_observers())
[email protected]9034a282014-06-05 03:11:47414 host_->SetNeedsAnimate();
415}
416
rmcilroy0a19362a2015-02-18 12:34:25417void Compositor::BeginMainFrameNotExpectedSoon() {
418}
419
danakj0b5eae6c2015-04-24 22:35:11420static void SendDamagedRectsRecursive(ui::Layer* layer) {
421 layer->SendDamagedRects();
422 for (auto* child : layer->children())
423 SendDamagedRectsRecursive(child);
424}
425
wkorman7265db012015-11-03 04:08:25426void Compositor::UpdateLayerTreeHost() {
danakj0b5eae6c2015-04-24 22:35:11427 if (!root_layer())
428 return;
429 SendDamagedRectsRecursive(root_layer());
[email protected]ab6627372012-01-29 21:22:13430}
431
enne7f8fdde2014-12-10 21:32:09432void Compositor::RequestNewOutputSurface() {
sieversca8baca2015-10-05 23:38:02433 DCHECK(!output_surface_requested_);
434 output_surface_requested_ = true;
435 if (widget_valid_)
436 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr());
[email protected]ab6627372012-01-29 21:22:13437}
438
enne7f8fdde2014-12-10 21:32:09439void Compositor::DidInitializeOutputSurface() {
enne7f8fdde2014-12-10 21:32:09440}
441
442void Compositor::DidFailToInitializeOutputSurface() {
danakj13d97082015-02-25 23:04:47443 // The OutputSurface should already be bound/initialized before being given to
444 // the Compositor.
445 NOTREACHED();
enne7f8fdde2014-12-10 21:32:09446}
447
[email protected]408b5e22013-03-19 09:48:09448void Compositor::DidCommit() {
[email protected]6b16679e2012-10-27 00:44:28449 DCHECK(!IsLocked());
[email protected]2700daddd2012-07-13 19:35:37450 FOR_EACH_OBSERVER(CompositorObserver,
451 observer_list_,
452 OnCompositingDidCommit(this));
453}
454
[email protected]408b5e22013-03-19 09:48:09455void Compositor::DidCommitAndDrawFrame() {
weiliangc1f27b282014-10-09 17:10:33456}
457
isherman4f0404e12014-12-06 01:01:33458void Compositor::DidCompleteSwapBuffers() {
weiliangc5efa0a12015-01-29 19:56:46459 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
460 OnCompositingEnded(this));
isherman4f0404e12014-12-06 01:01:33461}
462
463void Compositor::DidPostSwapBuffers() {
abhishek.ka7215854d2015-05-26 06:13:17464 base::TimeTicks start_time = base::TimeTicks::Now();
weiliangc5efa0a12015-01-29 19:56:46465 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
466 OnCompositingStarted(this, start_time));
isherman4f0404e12014-12-06 01:01:33467}
468
[email protected]4d7e46a2013-11-08 05:33:40469void Compositor::DidAbortSwapBuffers() {
[email protected]4d7e46a2013-11-08 05:33:40470 FOR_EACH_OBSERVER(CompositorObserver,
471 observer_list_,
472 OnCompositingAborted(this));
473}
474
simonhong8af4c832015-03-21 07:40:51475void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) {
jdduke7620c3c82015-10-22 21:46:47476 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, begin_frame_observer_list_,
477 OnSendBeginFrame(args));
478
479 // Unsubscription is performed here, after iteration, to handle the case where
480 // the last BeginFrame observer is removed while iterating over the observers.
481 if (!begin_frame_observer_list_.might_have_observers()) {
482 host_->SetChildrenNeedBeginFrames(false);
483 // Unsubscription should reset |missed_begin_frame_args_|, avoiding stale
484 // BeginFrame dispatch when the next BeginFrame observer is added.
485 missed_begin_frame_args_ = cc::BeginFrameArgs();
486 return;
487 }
simonhong8af4c832015-03-21 07:40:51488
489 missed_begin_frame_args_ = args;
490 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED;
491}
492
[email protected]2e77cdbb2013-04-29 13:59:14493const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
494 return host_->debug_state();
[email protected]918f8db42013-04-27 01:53:40495}
496
[email protected]2e77cdbb2013-04-29 13:59:14497void Compositor::SetLayerTreeDebugState(
498 const cc::LayerTreeDebugState& debug_state) {
[email protected]918f8db42013-04-27 01:53:40499 host_->SetDebugState(debug_state);
500}
501
jbaumanc5be44c2014-11-20 22:17:12502const cc::RendererSettings& Compositor::GetRendererSettings() const {
503 return host_->settings().renderer_settings;
504}
505
[email protected]6b16679e2012-10-27 00:44:28506scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
507 if (!compositor_lock_) {
508 compositor_lock_ = new CompositorLock(this);
weiliangc5efa0a12015-01-29 19:56:46509 host_->SetDeferCommits(true);
[email protected]6b16679e2012-10-27 00:44:28510 FOR_EACH_OBSERVER(CompositorObserver,
511 observer_list_,
512 OnCompositingLockStateChanged(this));
513 }
514 return compositor_lock_;
515}
516
517void Compositor::UnlockCompositor() {
518 DCHECK(compositor_lock_);
519 compositor_lock_ = NULL;
weiliangc5efa0a12015-01-29 19:56:46520 host_->SetDeferCommits(false);
[email protected]6b16679e2012-10-27 00:44:28521 FOR_EACH_OBSERVER(CompositorObserver,
522 observer_list_,
523 OnCompositingLockStateChanged(this));
524}
525
526void Compositor::CancelCompositorLock() {
527 if (compositor_lock_)
528 compositor_lock_->CancelLock();
529}
530
[email protected]c797cd42011-03-15 02:18:36531} // namespace ui