Loading gfx/layers/apz/util/APZCCallbackHelper.cpp +13 −27 Original line number Diff line number Diff line Loading @@ -649,7 +649,7 @@ static bool PrepareForSetTargetAPZCNotification( static void SendLayersDependentApzcTargetConfirmation( PresShell* aPresShell, uint64_t aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) { nsTArray<ScrollableLayerGuid>&& aTargets) { LayerManager* lm = aPresShell->GetLayerManager(); if (!lm) { return; Loading Loading @@ -679,11 +679,13 @@ static void SendLayersDependentApzcTargetConfirmation( DisplayportSetListener::DisplayportSetListener( nsIWidget* aWidget, PresShell* aPresShell, const uint64_t& aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) : mWidget(aWidget), mPresShell(aPresShell), nsTArray<ScrollableLayerGuid>&& aTargets) : OneShotPostRefreshObserver( aPresShell, [this](PresShell* aPresShell) { OnPostRefresh(this, aPresShell); }), mWidget(aWidget), mInputBlockId(aInputBlockId), mTargets(aTargets.Clone()) {} mTargets(std::move(aTargets)) {} DisplayportSetListener::~DisplayportSetListener() = default; Loading @@ -699,29 +701,13 @@ bool DisplayportSetListener::Register() { return false; } void DisplayportSetListener::DidRefresh() { if (!mPresShell) { MOZ_ASSERT_UNREACHABLE( "Post-refresh observer fired again after failed attempt at " "unregistering it"); return; } /* static */ void DisplayportSetListener::OnPostRefresh(DisplayportSetListener* aListener, PresShell* aPresShell) { APZCCH_LOG("Got refresh, sending target APZCs for input block %" PRIu64 "\n", mInputBlockId); SendLayersDependentApzcTargetConfirmation(mPresShell, mInputBlockId, std::move(mTargets)); if (!mPresShell->RemovePostRefreshObserver(this)) { MOZ_ASSERT_UNREACHABLE( "Unable to unregister post-refresh observer! Leaking it instead of " "leaving garbage registered"); // Graceful handling, just in case... mPresShell = nullptr; return; } delete this; aListener->mInputBlockId); SendLayersDependentApzcTargetConfirmation( aPresShell, aListener->mInputBlockId, std::move(aListener->mTargets)); } UniquePtr<DisplayportSetListener> Loading gfx/layers/apz/util/APZCCallbackHelper.h +5 −4 Original line number Diff line number Diff line Loading @@ -35,20 +35,21 @@ typedef std::function<void(uint64_t, const nsTArray<TouchBehaviorFlags>&)> SetAllowedTouchBehaviorCallback; /* Refer to documentation on SendSetTargetAPZCNotification for this class */ class DisplayportSetListener : public nsAPostRefreshObserver { class DisplayportSetListener : public OneShotPostRefreshObserver { public: DisplayportSetListener(nsIWidget* aWidget, PresShell* aPresShell, const uint64_t& aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets); nsTArray<ScrollableLayerGuid>&& aTargets); virtual ~DisplayportSetListener(); bool Register(); void DidRefresh() override; private: RefPtr<nsIWidget> mWidget; RefPtr<PresShell> mPresShell; uint64_t mInputBlockId; nsTArray<ScrollableLayerGuid> mTargets; static void OnPostRefresh(DisplayportSetListener* aListener, PresShell* aPresShell); }; /* This class contains some helper methods that facilitate implementing the Loading layout/base/moz.build +2 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ EXPORTS.mozilla.layout += [ ] UNIFIED_SOURCES += [ <<<<<<< dest: e0db5954e844 - jyavenard: Bug 1672553 - Don't use AudioTrimme... 'AccessibleCaret.cpp', 'AccessibleCaretEventHub.cpp', 'AccessibleCaretManager.cpp', Loading @@ -125,6 +126,7 @@ UNIFIED_SOURCES += [ 'nsPresArena.cpp', 'nsPresContext.cpp', 'nsQuoteList.cpp', 'nsRefreshObservers.cpp', 'nsStyleChangeList.cpp', 'nsStyleSheetService.cpp', 'PositionedEventTargeting.cpp', Loading layout/base/nsRefreshObservers.cpp 0 → 100644 +41 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsRefreshObservers.h" #include "PresShell.h" namespace mozilla { OneShotPostRefreshObserver::OneShotPostRefreshObserver(PresShell* aPresShell, Action&& aAction) : mPresShell(aPresShell), mAction(std::move(aAction)) {} OneShotPostRefreshObserver::~OneShotPostRefreshObserver() = default; void OneShotPostRefreshObserver::DidRefresh() { if (!mPresShell) { MOZ_ASSERT_UNREACHABLE( "Post-refresh observer fired again after failed attempt at " "unregistering it"); return; } mAction(mPresShell); if (!mPresShell->RemovePostRefreshObserver(this)) { MOZ_ASSERT_UNREACHABLE( "Unable to unregister post-refresh observer! Leaking it instead of " "leaving garbage registered"); // Graceful handling, just in case... mPresShell = nullptr; mAction = Action(); return; } delete this; } } // namespace mozilla No newline at end of file layout/base/nsRefreshObservers.h +25 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ namespace mozilla { class AnimationEventDispatcher; class PendingFullscreenEvent; class PresShell; class RefreshDriverTimer; namespace layout { class VsyncChild; Loading Loading @@ -64,4 +65,28 @@ class nsAPostRefreshObserver { virtual void DidRefresh() = 0; }; namespace mozilla { /** * A wrapper for nsAPostRefreshObserver that's one-shot (unregisters itself * after firing once) and can be used without writing a derived class by passing * in the action in the form of a lambda (or other function object). * * Note, while the observer unregisters itself, the registering still needs to * be done by the caller. */ class OneShotPostRefreshObserver : public nsAPostRefreshObserver { public: using Action = std::function<void(mozilla::PresShell*)>; OneShotPostRefreshObserver(mozilla::PresShell* aPresShell, Action&& aAction); virtual ~OneShotPostRefreshObserver(); void DidRefresh() override; protected: RefPtr<mozilla::PresShell> mPresShell; Action mAction; }; } // namespace mozilla #endif Loading
gfx/layers/apz/util/APZCCallbackHelper.cpp +13 −27 Original line number Diff line number Diff line Loading @@ -649,7 +649,7 @@ static bool PrepareForSetTargetAPZCNotification( static void SendLayersDependentApzcTargetConfirmation( PresShell* aPresShell, uint64_t aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) { nsTArray<ScrollableLayerGuid>&& aTargets) { LayerManager* lm = aPresShell->GetLayerManager(); if (!lm) { return; Loading Loading @@ -679,11 +679,13 @@ static void SendLayersDependentApzcTargetConfirmation( DisplayportSetListener::DisplayportSetListener( nsIWidget* aWidget, PresShell* aPresShell, const uint64_t& aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) : mWidget(aWidget), mPresShell(aPresShell), nsTArray<ScrollableLayerGuid>&& aTargets) : OneShotPostRefreshObserver( aPresShell, [this](PresShell* aPresShell) { OnPostRefresh(this, aPresShell); }), mWidget(aWidget), mInputBlockId(aInputBlockId), mTargets(aTargets.Clone()) {} mTargets(std::move(aTargets)) {} DisplayportSetListener::~DisplayportSetListener() = default; Loading @@ -699,29 +701,13 @@ bool DisplayportSetListener::Register() { return false; } void DisplayportSetListener::DidRefresh() { if (!mPresShell) { MOZ_ASSERT_UNREACHABLE( "Post-refresh observer fired again after failed attempt at " "unregistering it"); return; } /* static */ void DisplayportSetListener::OnPostRefresh(DisplayportSetListener* aListener, PresShell* aPresShell) { APZCCH_LOG("Got refresh, sending target APZCs for input block %" PRIu64 "\n", mInputBlockId); SendLayersDependentApzcTargetConfirmation(mPresShell, mInputBlockId, std::move(mTargets)); if (!mPresShell->RemovePostRefreshObserver(this)) { MOZ_ASSERT_UNREACHABLE( "Unable to unregister post-refresh observer! Leaking it instead of " "leaving garbage registered"); // Graceful handling, just in case... mPresShell = nullptr; return; } delete this; aListener->mInputBlockId); SendLayersDependentApzcTargetConfirmation( aPresShell, aListener->mInputBlockId, std::move(aListener->mTargets)); } UniquePtr<DisplayportSetListener> Loading
gfx/layers/apz/util/APZCCallbackHelper.h +5 −4 Original line number Diff line number Diff line Loading @@ -35,20 +35,21 @@ typedef std::function<void(uint64_t, const nsTArray<TouchBehaviorFlags>&)> SetAllowedTouchBehaviorCallback; /* Refer to documentation on SendSetTargetAPZCNotification for this class */ class DisplayportSetListener : public nsAPostRefreshObserver { class DisplayportSetListener : public OneShotPostRefreshObserver { public: DisplayportSetListener(nsIWidget* aWidget, PresShell* aPresShell, const uint64_t& aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets); nsTArray<ScrollableLayerGuid>&& aTargets); virtual ~DisplayportSetListener(); bool Register(); void DidRefresh() override; private: RefPtr<nsIWidget> mWidget; RefPtr<PresShell> mPresShell; uint64_t mInputBlockId; nsTArray<ScrollableLayerGuid> mTargets; static void OnPostRefresh(DisplayportSetListener* aListener, PresShell* aPresShell); }; /* This class contains some helper methods that facilitate implementing the Loading
layout/base/moz.build +2 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ EXPORTS.mozilla.layout += [ ] UNIFIED_SOURCES += [ <<<<<<< dest: e0db5954e844 - jyavenard: Bug 1672553 - Don't use AudioTrimme... 'AccessibleCaret.cpp', 'AccessibleCaretEventHub.cpp', 'AccessibleCaretManager.cpp', Loading @@ -125,6 +126,7 @@ UNIFIED_SOURCES += [ 'nsPresArena.cpp', 'nsPresContext.cpp', 'nsQuoteList.cpp', 'nsRefreshObservers.cpp', 'nsStyleChangeList.cpp', 'nsStyleSheetService.cpp', 'PositionedEventTargeting.cpp', Loading
layout/base/nsRefreshObservers.cpp 0 → 100644 +41 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsRefreshObservers.h" #include "PresShell.h" namespace mozilla { OneShotPostRefreshObserver::OneShotPostRefreshObserver(PresShell* aPresShell, Action&& aAction) : mPresShell(aPresShell), mAction(std::move(aAction)) {} OneShotPostRefreshObserver::~OneShotPostRefreshObserver() = default; void OneShotPostRefreshObserver::DidRefresh() { if (!mPresShell) { MOZ_ASSERT_UNREACHABLE( "Post-refresh observer fired again after failed attempt at " "unregistering it"); return; } mAction(mPresShell); if (!mPresShell->RemovePostRefreshObserver(this)) { MOZ_ASSERT_UNREACHABLE( "Unable to unregister post-refresh observer! Leaking it instead of " "leaving garbage registered"); // Graceful handling, just in case... mPresShell = nullptr; mAction = Action(); return; } delete this; } } // namespace mozilla No newline at end of file
layout/base/nsRefreshObservers.h +25 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ namespace mozilla { class AnimationEventDispatcher; class PendingFullscreenEvent; class PresShell; class RefreshDriverTimer; namespace layout { class VsyncChild; Loading Loading @@ -64,4 +65,28 @@ class nsAPostRefreshObserver { virtual void DidRefresh() = 0; }; namespace mozilla { /** * A wrapper for nsAPostRefreshObserver that's one-shot (unregisters itself * after firing once) and can be used without writing a derived class by passing * in the action in the form of a lambda (or other function object). * * Note, while the observer unregisters itself, the registering still needs to * be done by the caller. */ class OneShotPostRefreshObserver : public nsAPostRefreshObserver { public: using Action = std::function<void(mozilla::PresShell*)>; OneShotPostRefreshObserver(mozilla::PresShell* aPresShell, Action&& aAction); virtual ~OneShotPostRefreshObserver(); void DidRefresh() override; protected: RefPtr<mozilla::PresShell> mPresShell; Action mAction; }; } // namespace mozilla #endif