| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 params.main_task_runner = task_runner_; | 201 params.main_task_runner = task_runner_; |
| 202 params.mutator_host = animation_host_.get(); | 202 params.mutator_host = animation_host_.get(); |
| 203 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 203 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 204 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 204 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 205 base::TimeTicks::Now() - before_create); | 205 base::TimeTicks::Now() - before_create); |
| 206 | 206 |
| 207 animation_timeline_ = | 207 animation_timeline_ = |
| 208 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId()); | 208 cc::AnimationTimeline::Create(cc::AnimationIdProvider::NextTimelineId()); |
| 209 animation_host_->AddAnimationTimeline(animation_timeline_.get()); | 209 animation_host_->AddAnimationTimeline(animation_timeline_.get()); |
| 210 | 210 |
| 211 host_->GetLayerTree()->SetRootLayer(root_web_layer_); | 211 host_->SetRootLayer(root_web_layer_); |
| 212 host_->SetFrameSinkId(frame_sink_id_); | 212 host_->SetFrameSinkId(frame_sink_id_); |
| 213 host_->SetVisible(true); | 213 host_->SetVisible(true); |
| 214 | 214 |
| 215 if (command_line->HasSwitch(switches::kUISlowAnimations)) { | 215 if (command_line->HasSwitch(switches::kUISlowAnimations)) { |
| 216 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>( | 216 slow_animations_ = base::MakeUnique<ScopedAnimationDurationScaleMode>( |
| 217 ScopedAnimationDurationScaleMode::SLOW_DURATION); | 217 ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 Compositor::~Compositor() { | 221 Compositor::~Compositor() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 if (root_layer_) | 296 if (root_layer_) |
| 297 root_layer_->SetCompositor(this, root_web_layer_); | 297 root_layer_->SetCompositor(this, root_web_layer_); |
| 298 } | 298 } |
| 299 | 299 |
| 300 cc::AnimationTimeline* Compositor::GetAnimationTimeline() const { | 300 cc::AnimationTimeline* Compositor::GetAnimationTimeline() const { |
| 301 return animation_timeline_.get(); | 301 return animation_timeline_.get(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void Compositor::SetHostHasTransparentBackground( | 304 void Compositor::SetHostHasTransparentBackground( |
| 305 bool host_has_transparent_background) { | 305 bool host_has_transparent_background) { |
| 306 host_->GetLayerTree()->set_has_transparent_background( | 306 host_->set_has_transparent_background(host_has_transparent_background); |
| 307 host_has_transparent_background); | |
| 308 } | 307 } |
| 309 | 308 |
| 310 void Compositor::ScheduleFullRedraw() { | 309 void Compositor::ScheduleFullRedraw() { |
| 311 // TODO(enne): Some callers (mac) call this function expecting that it | 310 // TODO(enne): Some callers (mac) call this function expecting that it |
| 312 // will also commit. This should probably just redraw the screen | 311 // will also commit. This should probably just redraw the screen |
| 313 // from damage and not commit. ScheduleDraw/ScheduleRedraw need | 312 // from damage and not commit. ScheduleDraw/ScheduleRedraw need |
| 314 // better names. | 313 // better names. |
| 315 host_->SetNeedsRedrawRect( | 314 host_->SetNeedsRedrawRect(gfx::Rect(host_->device_viewport_size())); |
| 316 gfx::Rect(host_->GetLayerTree()->device_viewport_size())); | |
| 317 host_->SetNeedsCommit(); | 315 host_->SetNeedsCommit(); |
| 318 } | 316 } |
| 319 | 317 |
| 320 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { | 318 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { |
| 321 // TODO(enne): Make this not commit. See ScheduleFullRedraw. | 319 // TODO(enne): Make this not commit. See ScheduleFullRedraw. |
| 322 host_->SetNeedsRedrawRect(damage_rect); | 320 host_->SetNeedsRedrawRect(damage_rect); |
| 323 host_->SetNeedsCommit(); | 321 host_->SetNeedsCommit(); |
| 324 } | 322 } |
| 325 | 323 |
| 326 void Compositor::DisableSwapUntilResize() { | 324 void Compositor::DisableSwapUntilResize() { |
| 327 context_factory_private_->ResizeDisplay(this, gfx::Size()); | 325 context_factory_private_->ResizeDisplay(this, gfx::Size()); |
| 328 } | 326 } |
| 329 | 327 |
| 330 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) { | 328 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) { |
| 331 std::unique_ptr<cc::SwapPromise> swap_promise( | 329 std::unique_ptr<cc::SwapPromise> swap_promise( |
| 332 new cc::LatencyInfoSwapPromise(latency_info)); | 330 new cc::LatencyInfoSwapPromise(latency_info)); |
| 333 host_->QueueSwapPromise(std::move(swap_promise)); | 331 host_->QueueSwapPromise(std::move(swap_promise)); |
| 334 } | 332 } |
| 335 | 333 |
| 336 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { | 334 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { |
| 337 DCHECK_GT(scale, 0); | 335 DCHECK_GT(scale, 0); |
| 338 if (!size_in_pixel.IsEmpty()) { | 336 if (!size_in_pixel.IsEmpty()) { |
| 339 size_ = size_in_pixel; | 337 size_ = size_in_pixel; |
| 340 host_->GetLayerTree()->SetViewportSize(size_in_pixel); | 338 host_->SetViewportSize(size_in_pixel); |
| 341 root_web_layer_->SetBounds(size_in_pixel); | 339 root_web_layer_->SetBounds(size_in_pixel); |
| 342 // TODO(fsamuel): Get rid of ContextFactoryPrivate. | 340 // TODO(fsamuel): Get rid of ContextFactoryPrivate. |
| 343 if (context_factory_private_) | 341 if (context_factory_private_) |
| 344 context_factory_private_->ResizeDisplay(this, size_in_pixel); | 342 context_factory_private_->ResizeDisplay(this, size_in_pixel); |
| 345 } | 343 } |
| 346 if (device_scale_factor_ != scale) { | 344 if (device_scale_factor_ != scale) { |
| 347 device_scale_factor_ = scale; | 345 device_scale_factor_ = scale; |
| 348 host_->GetLayerTree()->SetDeviceScaleFactor(scale); | 346 host_->SetDeviceScaleFactor(scale); |
| 349 if (root_layer_) | 347 if (root_layer_) |
| 350 root_layer_->OnDeviceScaleFactorChanged(scale); | 348 root_layer_->OnDeviceScaleFactorChanged(scale); |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 | 351 |
| 354 void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space) { | 352 void Compositor::SetDisplayColorSpace(const gfx::ColorSpace& color_space) { |
| 355 host_->GetLayerTree()->SetDeviceColorSpace(color_space); | 353 host_->SetDeviceColorSpace(color_space); |
| 356 color_space_ = color_space; | 354 color_space_ = color_space; |
| 357 // Color space is reset when the output surface is lost, so this must also be | 355 // Color space is reset when the output surface is lost, so this must also be |
| 358 // updated then. | 356 // updated then. |
| 359 // TODO(fsamuel): Get rid of this. | 357 // TODO(fsamuel): Get rid of this. |
| 360 if (context_factory_private_) | 358 if (context_factory_private_) |
| 361 context_factory_private_->SetDisplayColorSpace(this, color_space_); | 359 context_factory_private_->SetDisplayColorSpace(this, color_space_); |
| 362 } | 360 } |
| 363 | 361 |
| 364 void Compositor::SetBackgroundColor(SkColor color) { | 362 void Compositor::SetBackgroundColor(SkColor color) { |
| 365 host_->GetLayerTree()->set_background_color(color); | 363 host_->set_background_color(color); |
| 366 ScheduleDraw(); | 364 ScheduleDraw(); |
| 367 } | 365 } |
| 368 | 366 |
| 369 void Compositor::SetVisible(bool visible) { | 367 void Compositor::SetVisible(bool visible) { |
| 370 host_->SetVisible(visible); | 368 host_->SetVisible(visible); |
| 371 // Visibility is reset when the output surface is lost, so this must also be | 369 // Visibility is reset when the output surface is lost, so this must also be |
| 372 // updated then. | 370 // updated then. |
| 373 // TODO(fsamuel): Eliminate this call. | 371 // TODO(fsamuel): Eliminate this call. |
| 374 if (context_factory_private_) | 372 if (context_factory_private_) |
| 375 context_factory_private_->SetDisplayVisible(this, visible); | 373 context_factory_private_->SetDisplayVisible(this, visible); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 for (auto& observer : observer_list_) | 557 for (auto& observer : observer_list_) |
| 560 observer.OnCompositingLockStateChanged(this); | 558 observer.OnCompositingLockStateChanged(this); |
| 561 } | 559 } |
| 562 | 560 |
| 563 void Compositor::CancelCompositorLock() { | 561 void Compositor::CancelCompositorLock() { |
| 564 if (compositor_lock_) | 562 if (compositor_lock_) |
| 565 compositor_lock_->CancelLock(); | 563 compositor_lock_->CancelLock(); |
| 566 } | 564 } |
| 567 | 565 |
| 568 } // namespace ui | 566 } // namespace ui |
| OLD | NEW |