Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 Compositor::Compositor(CompositorDelegate* delegate, | 403 Compositor::Compositor(CompositorDelegate* delegate, |
| 404 gfx::AcceleratedWidget widget) | 404 gfx::AcceleratedWidget widget) |
| 405 : delegate_(delegate), | 405 : delegate_(delegate), |
| 406 root_layer_(NULL), | 406 root_layer_(NULL), |
| 407 widget_(widget), | 407 widget_(widget), |
| 408 posted_swaps_(new PostedSwapQueue()), | 408 posted_swaps_(new PostedSwapQueue()), |
| 409 device_scale_factor_(0.0f), | 409 device_scale_factor_(0.0f), |
| 410 last_started_frame_(0), | 410 last_started_frame_(0), |
| 411 last_ended_frame_(0), | 411 last_ended_frame_(0), |
| 412 disable_schedule_composite_(false), | 412 disable_schedule_composite_(false), |
| 413 is_resizing_ (false), | |
| 413 compositor_lock_(NULL) { | 414 compositor_lock_(NULL) { |
| 414 root_web_layer_ = cc::Layer::Create(); | 415 root_web_layer_ = cc::Layer::Create(); |
| 415 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); | 416 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
| 416 | 417 |
| 417 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 418 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 418 cc::LayerTreeSettings settings; | 419 cc::LayerTreeSettings settings; |
| 419 settings.initialDebugState.show_fps_counter = | 420 settings.initialDebugState.show_fps_counter = |
| 420 command_line->HasSwitch(switches::kUIShowFPSCounter); | 421 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 421 settings.initialDebugState.show_platform_layer_tree = | 422 settings.initialDebugState.show_platform_layer_tree = |
| 422 command_line->HasSwitch(switches::kUIShowLayerTree); | 423 command_line->HasSwitch(switches::kUIShowLayerTree); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 root_web_layer_->RemoveAllChildren(); | 490 root_web_layer_->RemoveAllChildren(); |
| 490 if (root_layer_) | 491 if (root_layer_) |
| 491 root_web_layer_->AddChild(root_layer_->cc_layer()); | 492 root_web_layer_->AddChild(root_layer_->cc_layer()); |
| 492 } | 493 } |
| 493 | 494 |
| 494 void Compositor::SetHostHasTransparentBackground( | 495 void Compositor::SetHostHasTransparentBackground( |
| 495 bool host_has_transparent_background) { | 496 bool host_has_transparent_background) { |
| 496 host_->set_has_transparent_background(host_has_transparent_background); | 497 host_->set_has_transparent_background(host_has_transparent_background); |
| 497 } | 498 } |
| 498 | 499 |
| 500 #if defined (OS_WIN) | |
| 501 #ifndef NDEBUG | |
| 502 const int kResizePaintLatency = 12 * 16; | |
| 503 #else | |
| 504 const int kResizePaintLatency = 4 * 16; | |
| 505 #endif | |
| 506 #endif // OS_WIN. | |
| 507 | |
| 499 void Compositor::Draw(bool force_clear) { | 508 void Compositor::Draw(bool force_clear) { |
| 500 DCHECK(!g_compositor_thread); | 509 DCHECK(!g_compositor_thread); |
| 501 | 510 |
| 502 if (!root_layer_) | 511 if (!root_layer_) |
| 503 return; | 512 return; |
| 504 | 513 |
| 505 last_started_frame_++; | 514 last_started_frame_++; |
| 506 PendingSwap pending_swap(DRAW_SWAP, posted_swaps_.get()); | 515 PendingSwap pending_swap(DRAW_SWAP, posted_swaps_.get()); |
| 507 if (!IsLocked()) { | 516 if (!IsLocked()) { |
| 508 // TODO(nduca): Temporary while compositor calls | 517 // TODO(nduca): Temporary while compositor calls |
| 509 // compositeImmediately() directly. | 518 // compositeImmediately() directly. |
| 510 layout(); | 519 layout(); |
| 511 host_->Composite(base::TimeTicks::Now()); | 520 host_->Composite(base::TimeTicks::Now()); |
| 521 | |
| 522 #if defined(OS_WIN) | |
| 523 // While we resize, we are usually a few frames behind. By blocking | |
| 524 // the UI thread here we minize the area that is mis-painted, specially | |
| 525 // in the non-client area. See RenderWidgetHostViewAura::SetBounds for | |
| 526 // more details. | |
| 527 if (is_resizing_ && (last_ended_frame_ > 1)) { | |
|
cpu_(ooo_6.6-7.5)
2013/04/04 02:09:07
when chrome starts we hit here with frames 0 and 1
| |
| 528 is_resizing_ = false; | |
| 529 base::PlatformThread::Sleep( | |
| 530 base::TimeDelta::FromMilliseconds(kResizePaintLatency)); | |
|
jonathan.backer
2013/04/04 17:25:09
My experience has been that there are a lot of eve
| |
| 531 } | |
| 532 #endif | |
| 533 | |
| 512 } | 534 } |
| 513 if (!pending_swap.posted()) | 535 if (!pending_swap.posted()) |
| 514 NotifyEnd(); | 536 NotifyEnd(); |
| 515 } | 537 } |
| 516 | 538 |
| 517 void Compositor::ScheduleFullDraw() { | 539 void Compositor::ScheduleFullDraw() { |
| 518 host_->SetNeedsRedraw(); | 540 host_->SetNeedsRedraw(); |
| 519 } | 541 } |
| 520 | 542 |
| 521 bool Compositor::ReadPixels(SkBitmap* bitmap, | 543 bool Compositor::ReadPixels(SkBitmap* bitmap, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 532 PendingSwap pending_swap(READPIXELS_SWAP, posted_swaps_.get()); | 554 PendingSwap pending_swap(READPIXELS_SWAP, posted_swaps_.get()); |
| 533 return host_->CompositeAndReadback(pixels, bounds_in_pixel); | 555 return host_->CompositeAndReadback(pixels, bounds_in_pixel); |
| 534 } | 556 } |
| 535 | 557 |
| 536 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { | 558 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { |
| 537 DCHECK_GT(scale, 0); | 559 DCHECK_GT(scale, 0); |
| 538 if (!size_in_pixel.IsEmpty()) { | 560 if (!size_in_pixel.IsEmpty()) { |
| 539 size_ = size_in_pixel; | 561 size_ = size_in_pixel; |
| 540 host_->SetViewportSize(size_in_pixel, size_in_pixel); | 562 host_->SetViewportSize(size_in_pixel, size_in_pixel); |
| 541 root_web_layer_->SetBounds(size_in_pixel); | 563 root_web_layer_->SetBounds(size_in_pixel); |
| 564 | |
| 565 is_resizing_ = true; | |
| 542 } | 566 } |
| 543 if (device_scale_factor_ != scale) { | 567 if (device_scale_factor_ != scale) { |
| 544 device_scale_factor_ = scale; | 568 device_scale_factor_ = scale; |
| 545 if (root_layer_) | 569 if (root_layer_) |
| 546 root_layer_->OnDeviceScaleFactorChanged(scale); | 570 root_layer_->OnDeviceScaleFactorChanged(scale); |
| 547 } | 571 } |
| 548 } | 572 } |
| 549 | 573 |
| 550 void Compositor::AddObserver(CompositorObserver* observer) { | 574 void Compositor::AddObserver(CompositorObserver* observer) { |
| 551 observer_list_.AddObserver(observer); | 575 observer_list_.AddObserver(observer); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 COMPOSITOR_EXPORT void DisableTestCompositor() { | 743 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 720 ResetImplicitFactory(); | 744 ResetImplicitFactory(); |
| 721 g_test_compositor_enabled = false; | 745 g_test_compositor_enabled = false; |
| 722 } | 746 } |
| 723 | 747 |
| 724 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 748 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 725 return g_test_compositor_enabled; | 749 return g_test_compositor_enabled; |
| 726 } | 750 } |
| 727 | 751 |
| 728 } // namespace ui | 752 } // namespace ui |
| OLD | NEW |