From a36e0f76fb99966a4da557563cb310f020cd196a Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Fri, 25 Sep 2020 08:57:23 +0000 Subject: [PATCH] Bug 1667176 - Collapse ScrollableLayerGuid stringification functions. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D91334 --- gfx/layers/LayersLogging.cpp | 9 --------- gfx/layers/LayersLogging.h | 3 --- gfx/layers/ScrollableLayerGuid.cpp | 9 +++++++++ gfx/layers/ScrollableLayerGuid.h | 15 ++++----------- gfx/layers/apz/src/APZCTreeManager.cpp | 11 +++++++---- gfx/layers/apz/src/HitTestingTreeNode.cpp | 3 ++- gfx/layers/apz/src/InputQueue.cpp | 5 +++-- gfx/layers/apz/util/APZEventState.cpp | 5 +++-- 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/gfx/layers/LayersLogging.cpp b/gfx/layers/LayersLogging.cpp index 09c2c8a92a220..864e577d3b1a5 100644 --- a/gfx/layers/LayersLogging.cpp +++ b/gfx/layers/LayersLogging.cpp @@ -259,15 +259,6 @@ void AppendToString(std::stringstream& aStream, const FrameMetrics& m, aStream << sfx; } -void AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s, - const char* pfx, const char* sfx) { - aStream << pfx - << nsPrintfCString("{ l=0x%" PRIx64 ", p=%u, v=%" PRIu64 " }", - uint64_t(s.mLayersId), s.mPresShellId, s.mScrollId) - .get() - << sfx; -} - void AppendToString(std::stringstream& aStream, const ZoomConstraints& z, const char* pfx, const char* sfx) { aStream << pfx diff --git a/gfx/layers/LayersLogging.h b/gfx/layers/LayersLogging.h index b977a0360e857..519f3bd069271 100644 --- a/gfx/layers/LayersLogging.h +++ b/gfx/layers/LayersLogging.h @@ -181,9 +181,6 @@ void AppendToString(std::stringstream& aStream, const FrameMetrics& m, const char* pfx = "", const char* sfx = "", bool detailed = false); -void AppendToString(std::stringstream& aStream, const ScrollableLayerGuid& s, - const char* pfx = "", const char* sfx = ""); - void AppendToString(std::stringstream& aStream, const ZoomConstraints& z, const char* pfx = "", const char* sfx = ""); diff --git a/gfx/layers/ScrollableLayerGuid.cpp b/gfx/layers/ScrollableLayerGuid.cpp index bda2648316057..158d91e611196 100644 --- a/gfx/layers/ScrollableLayerGuid.cpp +++ b/gfx/layers/ScrollableLayerGuid.cpp @@ -6,7 +6,9 @@ #include "ScrollableLayerGuid.h" +#include #include "mozilla/HashFunctions.h" // for HashGeneric +#include "nsPrintfCString.h" // for nsPrintfCString namespace mozilla { namespace layers { @@ -43,6 +45,13 @@ bool ScrollableLayerGuid::operator<(const ScrollableLayerGuid& other) const { return false; } +std::ostream& operator<<(std::ostream& aOut, const ScrollableLayerGuid& aGuid) { + return aOut << nsPrintfCString("{ l=0x%" PRIx64 ", p=%u, v=%" PRIu64 " }", + uint64_t(aGuid.mLayersId), aGuid.mPresShellId, + aGuid.mScrollId) + .get(); +} + std::size_t ScrollableLayerGuid::HashFn::operator()( const ScrollableLayerGuid& aGuid) const { return HashGeneric(uint64_t(aGuid.mLayersId), aGuid.mPresShellId, diff --git a/gfx/layers/ScrollableLayerGuid.h b/gfx/layers/ScrollableLayerGuid.h index c8bc70eee004c..63e51c3f6f808 100644 --- a/gfx/layers/ScrollableLayerGuid.h +++ b/gfx/layers/ScrollableLayerGuid.h @@ -7,11 +7,10 @@ #ifndef GFX_SCROLLABLELAYERGUID_H #define GFX_SCROLLABLELAYERGUID_H +#include // for ostream #include // for uint8_t, uint32_t, uint64_t -#include "mozilla/gfx/Logging.h" // for Log #include "mozilla/layers/LayersTypes.h" // for LayersId #include "nsHashKeys.h" // for nsUint64HashKey -#include "nsPrintfCString.h" // for nsPrintfCString namespace mozilla { namespace layers { @@ -49,6 +48,9 @@ struct ScrollableLayerGuid { bool operator!=(const ScrollableLayerGuid& other) const; bool operator<(const ScrollableLayerGuid& other) const; + friend std::ostream& operator<<(std::ostream& aOut, + const ScrollableLayerGuid& aGuid); + // Helper structs to use as hash/equality functions in std::unordered_map. // e.g. std::unordered_map -gfx::Log& operator<<(gfx::Log& log, - const ScrollableLayerGuid& aGuid) { - return log << nsPrintfCString("(0x%" PRIx64 ", %u, %" PRIu64 ")", - uint64_t(aGuid.mLayersId), aGuid.mPresShellId, - aGuid.mScrollId) - .get(); -} - } // namespace layers } // namespace mozilla diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 25d31d3482dbb..e35bbaa7b70ab 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -40,6 +40,7 @@ #include "mozilla/StaticPrefs_accessibility.h" #include "mozilla/StaticPrefs_apz.h" #include "mozilla/StaticPrefs_layout.h" +#include "mozilla/ToString.h" #include "mozilla/TouchEvents.h" #include "mozilla/EventStateManager.h" // for WheelPrefs #include "mozilla/webrender/WebRenderAPI.h" @@ -1004,7 +1005,9 @@ template void APZCTreeManager::PrintAPZCInfo(const ScrollNode& aLayer, const AsyncPanZoomController* apzc) { const FrameMetrics& metrics = aLayer.Metrics(); - mApzcTreeLog << "APZC " << apzc->GetGuid() + std::stringstream guidStr; + guidStr << apzc->GetGuid(); + mApzcTreeLog << "APZC " << guidStr.str() << "\tcb=" << metrics.GetCompositionBounds() << "\tsr=" << metrics.GetScrollableRect() << (metrics.IsScrollInfoLayer() ? "\tscrollinfo" : "") @@ -2431,10 +2434,10 @@ void APZCTreeManager::UpdateZoomConstraints( if (aConstraints) { APZCTM_LOG("Recording constraints %s for guid %s\n", Stringify(aConstraints.value()).c_str(), - Stringify(aGuid).c_str()); + ToString(aGuid).c_str()); mZoomConstraints[aGuid] = aConstraints.ref(); } else { - APZCTM_LOG("Removing constraints for guid %s\n", Stringify(aGuid).c_str()); + APZCTM_LOG("Removing constraints for guid %s\n", ToString(aGuid).c_str()); mZoomConstraints.erase(aGuid); } if (node && aConstraints) { @@ -2804,7 +2807,7 @@ APZCTreeManager::HitTestResult APZCTreeManager::GetAPZCAtPointWR( for (const wr::WrHitResult& result : results) { ScrollableLayerGuid guid{result.mLayersId, 0, result.mScrollId}; APZCTM_LOG("Examining result with guid %s hit info 0x%x... ", - Stringify(guid).c_str(), result.mHitInfo.serialize()); + ToString(guid).c_str(), result.mHitInfo.serialize()); if (result.mHitInfo == CompositorHitTestInvisibleToHit) { APZCTM_LOG("skipping due to invisibility.\n"); continue; diff --git a/gfx/layers/apz/src/HitTestingTreeNode.cpp b/gfx/layers/apz/src/HitTestingTreeNode.cpp index f50cc360c5f49..2f564a49b0914 100644 --- a/gfx/layers/apz/src/HitTestingTreeNode.cpp +++ b/gfx/layers/apz/src/HitTestingTreeNode.cpp @@ -10,6 +10,7 @@ #include "mozilla/gfx/Point.h" // for Point4D #include "mozilla/layers/APZUtils.h" // for AsyncTransform, CompleteAsyncTransform #include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics +#include "mozilla/ToString.h" // for ToString #include "nsPrintfCString.h" // for nsPrintfCString #include "UnitTransforms.h" // for ViewAs @@ -432,7 +433,7 @@ void HitTestingTreeNode::Dump(const char* aPrefix) const { ("%sHitTestingTreeNode (%p) APZC (%p) g=(%s) %s%s%sr=(%s) t=(%s) " "c=(%s)%s%s\n", aPrefix, this, mApzc.get(), - mApzc ? Stringify(mApzc->GetGuid()).c_str() + mApzc ? ToString(mApzc->GetGuid()).c_str() : nsPrintfCString("l=0x%" PRIx64, uint64_t(mLayersId)).get(), (mOverride & EventRegionsOverride::ForceDispatchToContent) ? "fdtc " : "", diff --git a/gfx/layers/apz/src/InputQueue.cpp b/gfx/layers/apz/src/InputQueue.cpp index 98b5e07099dfe..9e11a83696632 100644 --- a/gfx/layers/apz/src/InputQueue.cpp +++ b/gfx/layers/apz/src/InputQueue.cpp @@ -11,6 +11,7 @@ #include "InputBlockState.h" #include "LayersLogging.h" #include "mozilla/layers/APZThreadUtils.h" +#include "mozilla/ToString.h" #include "OverscrollHandoffState.h" #include "QueuedInput.h" #include "mozilla/StaticPrefs_apz.h" @@ -787,7 +788,7 @@ void InputQueue::SetConfirmedTargetApzc( APZThreadUtils::AssertOnControllerThread(); INPQ_LOG("got a target apzc; block=%" PRIu64 " guid=%s\n", aInputBlockId, - aTargetApzc ? Stringify(aTargetApzc->GetGuid()).c_str() : ""); + aTargetApzc ? ToString(aTargetApzc->GetGuid()).c_str() : ""); bool success = false; InputData* firstInput = nullptr; InputBlockState* inputBlock = FindBlockForId(aInputBlockId, &firstInput); @@ -818,7 +819,7 @@ void InputQueue::ConfirmDragBlock( INPQ_LOG("got a target apzc; block=%" PRIu64 " guid=%s dragtarget=%" PRIu64 "\n", aInputBlockId, - aTargetApzc ? Stringify(aTargetApzc->GetGuid()).c_str() : "", + aTargetApzc ? ToString(aTargetApzc->GetGuid()).c_str() : "", aDragMetrics.mViewId); bool success = false; InputData* firstInput = nullptr; diff --git a/gfx/layers/apz/util/APZEventState.cpp b/gfx/layers/apz/util/APZEventState.cpp index 277db263b7cd4..59987b2d766ce 100644 --- a/gfx/layers/apz/util/APZEventState.cpp +++ b/gfx/layers/apz/util/APZEventState.cpp @@ -19,6 +19,7 @@ #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_ui.h" +#include "mozilla/ToString.h" #include "mozilla/TouchEvents.h" #include "mozilla/ViewportUtils.h" #include "mozilla/dom/BrowserChild.h" @@ -355,7 +356,7 @@ void APZEventState::ProcessTouchEvent( sentContentResponse = true; } else { APZES_LOG("Event not prevented; pending response for %" PRIu64 " %s\n", - aInputBlockId, Stringify(aGuid).c_str()); + aInputBlockId, ToString(aGuid).c_str()); mPendingTouchPreventedResponse = true; mPendingTouchPreventedGuid = aGuid; mPendingTouchPreventedBlockId = aInputBlockId; @@ -524,7 +525,7 @@ void APZEventState::ProcessAPZStateChange(ViewID aViewId, bool APZEventState::SendPendingTouchPreventedResponse(bool aPreventDefault) { if (mPendingTouchPreventedResponse) { APZES_LOG("Sending response %d for pending guid: %s\n", aPreventDefault, - Stringify(mPendingTouchPreventedGuid).c_str()); + ToString(mPendingTouchPreventedGuid).c_str()); mContentReceivedInputBlockCallback(mPendingTouchPreventedBlockId, aPreventDefault); mPendingTouchPreventedResponse = false;