| Index: ui/compositor/compositor.cc
|
| diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
|
| index 37a147adcbbef42648a2cf89b4b315929e8bdee6..b2b31ba6a8c501fc1ba843f4a04d7434104d1c60 100644
|
| --- a/ui/compositor/compositor.cc
|
| +++ b/ui/compositor/compositor.cc
|
| @@ -39,10 +39,6 @@ namespace {
|
| const double kDefaultRefreshRate = 60.0;
|
| const double kTestRefreshRate = 200.0;
|
|
|
| -enum SwapType {
|
| - DRAW_SWAP,
|
| -};
|
| -
|
| bool g_compositor_initialized = false;
|
| base::Thread* g_compositor_thread = NULL;
|
|
|
| @@ -50,24 +46,6 @@ ui::ContextFactory* g_context_factory = NULL;
|
|
|
| const int kCompositorLockTimeoutMs = 67;
|
|
|
| -class PendingSwap {
|
| - public:
|
| - PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps);
|
| - ~PendingSwap();
|
| -
|
| - SwapType type() const { return type_; }
|
| - bool posted() const { return posted_; }
|
| -
|
| - private:
|
| - friend class ui::PostedSwapQueue;
|
| -
|
| - SwapType type_;
|
| - bool posted_;
|
| - ui::PostedSwapQueue* posted_swaps_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PendingSwap);
|
| -};
|
| -
|
| } // namespace
|
|
|
| namespace ui {
|
| @@ -115,92 +93,25 @@ void CompositorLock::CancelLock() {
|
| compositor_ = NULL;
|
| }
|
|
|
| -class PostedSwapQueue {
|
| - public:
|
| - PostedSwapQueue() : pending_swap_(NULL) {
|
| - }
|
| -
|
| - ~PostedSwapQueue() {
|
| - DCHECK(!pending_swap_);
|
| - }
|
| -
|
| - SwapType NextPostedSwap() const {
|
| - return queue_.front();
|
| - }
|
| -
|
| - bool AreSwapsPosted() const {
|
| - return !queue_.empty();
|
| - }
|
| -
|
| - int NumSwapsPosted(SwapType type) const {
|
| - int count = 0;
|
| - for (std::deque<SwapType>::const_iterator it = queue_.begin();
|
| - it != queue_.end(); ++it) {
|
| - if (*it == type)
|
| - count++;
|
| - }
|
| - return count;
|
| - }
|
| -
|
| - void PostSwap() {
|
| - DCHECK(pending_swap_);
|
| - queue_.push_back(pending_swap_->type());
|
| - pending_swap_->posted_ = true;
|
| - }
|
| -
|
| - void EndSwap() {
|
| - queue_.pop_front();
|
| - }
|
| -
|
| - private:
|
| - friend class ::PendingSwap;
|
| -
|
| - PendingSwap* pending_swap_;
|
| - std::deque<SwapType> queue_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PostedSwapQueue);
|
| -};
|
| -
|
| } // namespace ui
|
|
|
| -namespace {
|
| -
|
| -PendingSwap::PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps)
|
| - : type_(type), posted_(false), posted_swaps_(posted_swaps) {
|
| - // Only one pending swap in flight.
|
| - DCHECK_EQ(static_cast<PendingSwap*>(NULL), posted_swaps_->pending_swap_);
|
| - posted_swaps_->pending_swap_ = this;
|
| -}
|
| -
|
| -PendingSwap::~PendingSwap() {
|
| - DCHECK_EQ(this, posted_swaps_->pending_swap_);
|
| - posted_swaps_->pending_swap_ = NULL;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| namespace ui {
|
|
|
| Compositor::Compositor(gfx::AcceleratedWidget widget)
|
| : root_layer_(NULL),
|
| widget_(widget),
|
| vsync_manager_(new CompositorVSyncManager()),
|
| - posted_swaps_(new PostedSwapQueue()),
|
| device_scale_factor_(0.0f),
|
| last_started_frame_(0),
|
| last_ended_frame_(0),
|
| - next_draw_is_resize_(false),
|
| disable_schedule_composite_(false),
|
| compositor_lock_(NULL),
|
| - defer_draw_scheduling_(false),
|
| - waiting_on_compositing_end_(false),
|
| - draw_on_compositing_end_(false),
|
| schedule_draw_factory_(this) {
|
| DCHECK(g_compositor_initialized)
|
| << "Compositor::Initialize must be called before creating a Compositor.";
|
|
|
| root_web_layer_ = cc::Layer::Create();
|
| - root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
|
| + root_web_layer_->SetAnchorPoint(gfx::PointF());
|
|
|
| CommandLine* command_line = CommandLine::ForCurrentProcess();
|
|
|
| @@ -319,16 +230,7 @@ void Compositor::Terminate() {
|
| g_compositor_initialized = false;
|
| }
|
|
|
| -void Compositor::ScheduleDraw() {
|
| - if (g_compositor_thread) {
|
| - host_->Composite(gfx::FrameTime::Now());
|
| - } else if (!defer_draw_scheduling_) {
|
| - defer_draw_scheduling_ = true;
|
| - base::MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr()));
|
| - }
|
| -}
|
| +void Compositor::ScheduleDraw() { host_->SetNeedsCommit(); }
|
|
|
| void Compositor::SetRootLayer(Layer* root_layer) {
|
| if (root_layer_ == root_layer)
|
| @@ -348,45 +250,6 @@ void Compositor::SetHostHasTransparentBackground(
|
| host_->set_has_transparent_background(host_has_transparent_background);
|
| }
|
|
|
| -void Compositor::Draw() {
|
| - DCHECK(!g_compositor_thread);
|
| -
|
| - defer_draw_scheduling_ = false;
|
| - if (waiting_on_compositing_end_) {
|
| - draw_on_compositing_end_ = true;
|
| - return;
|
| - }
|
| - waiting_on_compositing_end_ = true;
|
| -
|
| - TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
|
| -
|
| - if (!root_layer_)
|
| - return;
|
| -
|
| - last_started_frame_++;
|
| - PendingSwap pending_swap(DRAW_SWAP, posted_swaps_.get());
|
| - if (!IsLocked()) {
|
| - // TODO(nduca): Temporary while compositor calls
|
| - // compositeImmediately() directly.
|
| - Layout();
|
| - host_->Composite(gfx::FrameTime::Now());
|
| -
|
| -#if defined(OS_WIN)
|
| - // While we resize, we are usually a few frames behind. By blocking
|
| - // the UI thread here we minize the area that is mis-painted, specially
|
| - // in the non-client area. See RenderWidgetHostViewAura::SetBounds for
|
| - // more details and bug 177115.
|
| - if (next_draw_is_resize_ && (last_ended_frame_ > 1)) {
|
| - next_draw_is_resize_ = false;
|
| - host_->FinishAllRendering();
|
| - }
|
| -#endif
|
| -
|
| - }
|
| - if (!pending_swap.posted())
|
| - NotifyEnd();
|
| -}
|
| -
|
| void Compositor::ScheduleFullRedraw() {
|
| host_->SetNeedsRedraw();
|
| }
|
| @@ -407,8 +270,6 @@ void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
|
| size_ = size_in_pixel;
|
| host_->SetViewportSize(size_in_pixel);
|
| root_web_layer_->SetBounds(size_in_pixel);
|
| -
|
| - next_draw_is_resize_ = true;
|
| }
|
| if (device_scale_factor_ != scale) {
|
| device_scale_factor_ = scale;
|
| @@ -466,15 +327,10 @@ void Compositor::DidCommitAndDrawFrame() {
|
| }
|
|
|
| void Compositor::DidCompleteSwapBuffers() {
|
| - if (g_compositor_thread) {
|
| - NotifyEnd();
|
| - } else {
|
| - DCHECK(posted_swaps_->AreSwapsPosted());
|
| - DCHECK_GE(1, posted_swaps_->NumSwapsPosted(DRAW_SWAP));
|
| - if (posted_swaps_->NextPostedSwap() == DRAW_SWAP)
|
| - NotifyEnd();
|
| - posted_swaps_->EndSwap();
|
| - }
|
| + last_ended_frame_++;
|
| + TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
|
| + FOR_EACH_OBSERVER(
|
| + CompositorObserver, observer_list_, OnCompositingEnded(this));
|
| }
|
|
|
| scoped_refptr<cc::ContextProvider> Compositor::OffscreenContextProvider() {
|
| @@ -491,22 +347,9 @@ void Compositor::ScheduleAnimation() {
|
| }
|
|
|
| void Compositor::DidPostSwapBuffers() {
|
| - DCHECK(!g_compositor_thread);
|
| - posted_swaps_->PostSwap();
|
| }
|
|
|
| void Compositor::DidAbortSwapBuffers() {
|
| - if (!g_compositor_thread) {
|
| - DCHECK_GE(1, posted_swaps_->NumSwapsPosted(DRAW_SWAP));
|
| -
|
| - // We've just lost the context, so unwind all posted_swaps.
|
| - while (posted_swaps_->AreSwapsPosted()) {
|
| - if (posted_swaps_->NextPostedSwap() == DRAW_SWAP)
|
| - NotifyEnd();
|
| - posted_swaps_->EndSwap();
|
| - }
|
| - }
|
| -
|
| FOR_EACH_OBSERVER(CompositorObserver,
|
| observer_list_,
|
| OnCompositingAborted(this));
|
| @@ -524,8 +367,7 @@ void Compositor::SetLayerTreeDebugState(
|
| scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
|
| if (!compositor_lock_) {
|
| compositor_lock_ = new CompositorLock(this);
|
| - if (g_compositor_thread)
|
| - host_->SetDeferCommits(true);
|
| + host_->SetDeferCommits(true);
|
| FOR_EACH_OBSERVER(CompositorObserver,
|
| observer_list_,
|
| OnCompositingLockStateChanged(this));
|
| @@ -536,8 +378,7 @@ scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
|
| void Compositor::UnlockCompositor() {
|
| DCHECK(compositor_lock_);
|
| compositor_lock_ = NULL;
|
| - if (g_compositor_thread)
|
| - host_->SetDeferCommits(false);
|
| + host_->SetDeferCommits(false);
|
| FOR_EACH_OBSERVER(CompositorObserver,
|
| observer_list_,
|
| OnCompositingLockStateChanged(this));
|
| @@ -548,21 +389,4 @@ void Compositor::CancelCompositorLock() {
|
| compositor_lock_->CancelLock();
|
| }
|
|
|
| -void Compositor::NotifyEnd() {
|
| - last_ended_frame_++;
|
| - TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
|
| - waiting_on_compositing_end_ = false;
|
| - if (draw_on_compositing_end_) {
|
| - draw_on_compositing_end_ = false;
|
| -
|
| - // Call ScheduleDraw() instead of Draw() in order to allow other
|
| - // CompositorObservers to be notified before starting another
|
| - // draw cycle.
|
| - ScheduleDraw();
|
| - }
|
| - FOR_EACH_OBSERVER(CompositorObserver,
|
| - observer_list_,
|
| - OnCompositingEnded(this));
|
| -}
|
| -
|
| } // namespace ui
|
|
|