diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 14:45:44 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 14:45:44 +0000 |
commit | 98dbd68a3ab7e6128e6b6a47f309536506e65ea6 (patch) | |
tree | 3498627783f164125fd3068f7600310cbbfef480 | |
parent | 7b427bbdd308777d8551f2ff701f10a20db7498a (diff) | |
download | chromium_src-98dbd68a3ab7e6128e6b6a47f309536506e65ea6.zip chromium_src-98dbd68a3ab7e6128e6b6a47f309536506e65ea6.tar.gz chromium_src-98dbd68a3ab7e6128e6b6a47f309536506e65ea6.tar.bz2 |
Merge 261063 "ui: Replace PostedSwapQueue with a SwapState enum."
> ui: Replace PostedSwapQueue with a SwapState enum.
>
> The posted swap queue can only ever have a single swap in it, which
> is verified by DCHECKs, and it only has a single swap type in the
> enum, so this deque is pointless and it is causing mysterious crashes.
>
> Refactor the posted swap queue into a single SwapState enum to track
> if a swap was/is currently posted or not.
>
> R=piman@chromium.org
> BUG=348609
>
> Review URL: https://codereview.chromium.org/214013002
TBR=danakj@chromium.org
Review URL: https://codereview.chromium.org/226073002
git-svn-id: svn://svn.chromium.org/chrome/branches/1916/src@261754 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/compositor/compositor.cc | 109 | ||||
-rw-r--r-- | ui/compositor/compositor.h | 6 |
2 files changed, 15 insertions, 100 deletions
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index 76b4413..2021798 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; cc::SharedBitmapManager* g_shared_bitmap_manager; @@ -51,24 +47,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 { @@ -117,68 +95,10 @@ 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 { @@ -187,7 +107,6 @@ 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), @@ -197,6 +116,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget) defer_draw_scheduling_(false), waiting_on_compositing_end_(false), draw_on_compositing_end_(false), + swap_state_(SWAP_NONE), schedule_draw_factory_(this) { DCHECK(g_compositor_initialized) << "Compositor::Initialize must be called before creating a Compositor."; @@ -374,8 +294,10 @@ void Compositor::Draw() { if (!root_layer_) return; + DCHECK_NE(swap_state_, SWAP_POSTED); + swap_state_ = SWAP_NONE; + last_started_frame_++; - PendingSwap pending_swap(DRAW_SWAP, posted_swaps_.get()); if (!IsLocked()) { // TODO(nduca): Temporary while compositor calls // compositeImmediately() directly. @@ -394,7 +316,7 @@ void Compositor::Draw() { #endif } - if (!pending_swap.posted()) + if (swap_state_ == SWAP_NONE) NotifyEnd(); } @@ -480,11 +402,9 @@ 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(); + DCHECK_EQ(swap_state_, SWAP_POSTED); + NotifyEnd(); + swap_state_ = SWAP_COMPLETED; } } @@ -503,18 +423,15 @@ void Compositor::ScheduleAnimation() { void Compositor::DidPostSwapBuffers() { DCHECK(!g_compositor_thread); - posted_swaps_->PostSwap(); + DCHECK_EQ(swap_state_, SWAP_NONE); + swap_state_ = SWAP_POSTED; } 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(); + if (swap_state_ == SWAP_POSTED) { + NotifyEnd(); + swap_state_ = SWAP_COMPLETED; } } diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h index f91a294..7b4ce6a 100644 --- a/ui/compositor/compositor.h +++ b/ui/compositor/compositor.h @@ -50,7 +50,6 @@ namespace ui { class Compositor; class CompositorVSyncManager; class Layer; -class PostedSwapQueue; class Reflector; class Texture; struct LatencyInfo; @@ -311,9 +310,6 @@ class COMPOSITOR_EXPORT Compositor // The manager of vsync parameters for this compositor. scoped_refptr<CompositorVSyncManager> vsync_manager_; - // Used to verify that we have at most one draw swap in flight. - scoped_ptr<PostedSwapQueue> posted_swaps_; - // The device scale factor of the monitor that this compositor is compositing // layers on. float device_scale_factor_; @@ -333,6 +329,8 @@ class COMPOSITOR_EXPORT Compositor // Used to prevent Draw()s while a composite is in progress. bool waiting_on_compositing_end_; bool draw_on_compositing_end_; + enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; + SwapState swap_state_; base::WeakPtrFactory<Compositor> schedule_draw_factory_; |