From 1d35f25a8b52d7bb5b237349e9f421a75081d879 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Thu, 31 Jul 2014 16:11:47 -0400 Subject: [PATCH] Bug 1023557 - Store the content description in ContainerLayer instead of FrameMetrics. r=kats,BenWa --- gfx/ipc/GfxMessageUtils.h | 57 +++++++++-------------- gfx/layers/FrameMetrics.h | 20 -------- gfx/layers/Layers.cpp | 2 +- gfx/layers/Layers.h | 16 +++++++ gfx/layers/apz/src/APZCTreeManager.cpp | 2 +- gfx/layers/ipc/LayerTransactionParent.cpp | 1 + gfx/layers/ipc/LayersMessages.ipdlh | 2 + layout/base/nsDisplayList.cpp | 2 +- 8 files changed, 44 insertions(+), 58 deletions(-) diff --git a/gfx/ipc/GfxMessageUtils.h b/gfx/ipc/GfxMessageUtils.h index 38edaeaaa29..8a5345d24fb 100644 --- a/gfx/ipc/GfxMessageUtils.h +++ b/gfx/ipc/GfxMessageUtils.h @@ -740,46 +740,33 @@ struct ParamTraits WriteParam(aMsg, aParam.mHasScrollgrab); WriteParam(aMsg, aParam.mUpdateScrollOffset); WriteParam(aMsg, aParam.mScrollGeneration); - aMsg->WriteBytes(aParam.mContentDescription, - sizeof(aParam.mContentDescription)); WriteParam(aMsg, aParam.mTransformScale); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { - const char* contentDescription; - if (!(ReadParam(aMsg, aIter, &aResult->mScrollableRect) && - ReadParam(aMsg, aIter, &aResult->mViewport) && - ReadParam(aMsg, aIter, &aResult->mScrollOffset) && - ReadParam(aMsg, aIter, &aResult->mDisplayPort) && - ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) && - ReadParam(aMsg, aIter, &aResult->mUseDisplayPortMargins) && - ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) && - ReadParam(aMsg, aIter, &aResult->mCompositionBounds) && - ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) && - ReadParam(aMsg, aIter, &aResult->mScrollId) && - ReadParam(aMsg, aIter, &aResult->mResolution) && - ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) && - ReadParam(aMsg, aIter, &aResult->mZoom) && - ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) && - ReadParam(aMsg, aIter, &aResult->mMayHaveTouchListeners) && - ReadParam(aMsg, aIter, &aResult->mMayHaveTouchCaret) && - ReadParam(aMsg, aIter, &aResult->mPresShellId) && - ReadParam(aMsg, aIter, &aResult->mIsRoot) && - ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) && - ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) && - ReadParam(aMsg, aIter, &aResult->mScrollGeneration) && - aMsg->ReadBytes(aIter, &contentDescription, - sizeof(aResult->mContentDescription)) && - ReadParam(aMsg, aIter, &aResult->mTransformScale))) { - return false; - } - // ReadBytes() doesn't actually copy the string, it only points - // a pointer to the string in its internal buffer. - strncpy(aResult->mContentDescription, contentDescription, - sizeof(aResult->mContentDescription)); - aResult->mContentDescription[sizeof(aResult->mContentDescription) - 1] = '\0'; - return true; + return (ReadParam(aMsg, aIter, &aResult->mScrollableRect) && + ReadParam(aMsg, aIter, &aResult->mViewport) && + ReadParam(aMsg, aIter, &aResult->mScrollOffset) && + ReadParam(aMsg, aIter, &aResult->mDisplayPort) && + ReadParam(aMsg, aIter, &aResult->mDisplayPortMargins) && + ReadParam(aMsg, aIter, &aResult->mUseDisplayPortMargins) && + ReadParam(aMsg, aIter, &aResult->mCriticalDisplayPort) && + ReadParam(aMsg, aIter, &aResult->mCompositionBounds) && + ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) && + ReadParam(aMsg, aIter, &aResult->mScrollId) && + ReadParam(aMsg, aIter, &aResult->mResolution) && + ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) && + ReadParam(aMsg, aIter, &aResult->mZoom) && + ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) && + ReadParam(aMsg, aIter, &aResult->mMayHaveTouchListeners) && + ReadParam(aMsg, aIter, &aResult->mMayHaveTouchCaret) && + ReadParam(aMsg, aIter, &aResult->mPresShellId) && + ReadParam(aMsg, aIter, &aResult->mIsRoot) && + ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) && + ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) && + ReadParam(aMsg, aIter, &aResult->mScrollGeneration) && + ReadParam(aMsg, aIter, &aResult->mTransformScale)); } }; diff --git a/gfx/layers/FrameMetrics.h b/gfx/layers/FrameMetrics.h index 353bedbd7f4..f71d21d841f 100644 --- a/gfx/layers/FrameMetrics.h +++ b/gfx/layers/FrameMetrics.h @@ -7,7 +7,6 @@ #define GFX_FRAMEMETRICS_H #include // for uint32_t, uint64_t -#include // for std::string #include "Units.h" // for CSSRect, CSSPixel, etc #include "mozilla/gfx/BasePoint.h" // for BasePoint #include "mozilla/gfx/Rect.h" // for RoundedIn @@ -92,7 +91,6 @@ public: , mZoom(1) , mUpdateScrollOffset(false) , mScrollGeneration(0) - , mContentDescription() , mRootCompositionSize(0, 0) , mDisplayPortMargins(0, 0, 0, 0) , mUseDisplayPortMargins(false) @@ -103,8 +101,6 @@ public: bool operator==(const FrameMetrics& aOther) const { - // mContentDescription is not compared on purpose as it's only used - // for debugging. return mCompositionBounds.IsEqualEdges(aOther.mCompositionBounds) && mRootCompositionSize == aOther.mRootCompositionSize && mDisplayPort.IsEqualEdges(aOther.mDisplayPort) && @@ -402,18 +398,6 @@ public: return mScrollGeneration; } - std::string GetContentDescription() const - { - return std::string(mContentDescription); - } - - void SetContentDescription(const std::string& aContentDescription) - { - strncpy(mContentDescription, aContentDescription.c_str(), sizeof(mContentDescription)); - // forcibly null-terminate in case aContentDescription is too long - mContentDescription[sizeof(mContentDescription) - 1] = '\0'; - } - ViewID GetScrollId() const { return mScrollId; @@ -503,10 +487,6 @@ private: // The scroll generation counter used to acknowledge the scroll offset update. uint32_t mScrollGeneration; - // A description of the content element corresponding to this frame. - // This is empty unless the apz.printtree pref is turned on. - char mContentDescription[20]; - // The size of the root scrollable's composition bounds, but in local CSS pixels. CSSSize mRootCompositionSize; diff --git a/gfx/layers/Layers.cpp b/gfx/layers/Layers.cpp index b2b84c4e302..edf22039c23 100644 --- a/gfx/layers/Layers.cpp +++ b/gfx/layers/Layers.cpp @@ -922,7 +922,7 @@ ContainerLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs) aAttrs = ContainerLayerAttributes(GetFrameMetrics(), mScrollHandoffParentId, mPreXScale, mPreYScale, mInheritedXScale, mInheritedYScale, - mBackgroundColor); + mBackgroundColor, mContentDescription); } bool diff --git a/gfx/layers/Layers.h b/gfx/layers/Layers.h index d32f3e19729..1d3ca95f97c 100644 --- a/gfx/layers/Layers.h +++ b/gfx/layers/Layers.h @@ -1770,6 +1770,17 @@ public: Mutated(); } + void SetContentDescription(const std::string& aContentDescription) + { + if (mContentDescription == aContentDescription) { + return; + } + + MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ContentDescription", this)); + mContentDescription = aContentDescription; + Mutated(); + } + virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs); void SortChildrenBy3DZOrder(nsTArray& aArray); @@ -1789,6 +1800,7 @@ public: float GetInheritedYScale() const { return mInheritedYScale; } gfxRGBA GetBackgroundColor() const { return mBackgroundColor; } + const std::string& GetContentDescription() const { return mContentDescription; } MOZ_LAYER_DECL_NAME("ContainerLayer", TYPE_CONTAINER) @@ -1881,6 +1893,10 @@ protected: // When multi-layer-apz (bug 967844) is implemented, this is likely to move // elsewhere (e.g. to Layer). gfxRGBA mBackgroundColor; + // A description of the content element corresponding to this frame. + // This is empty unless this ContainerLayer is scrollable and the + // apz.printtree pref is turned on. + std::string mContentDescription; bool mUseIntermediateSurface; bool mSupportsComponentAlphaChildren; bool mMayHaveReadbackChild; diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index f77fc5afdd8..77882f88f44 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -269,7 +269,7 @@ APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor, << "\tsr=" << container->GetFrameMetrics().mScrollableRect << (aLayer->GetVisibleRegion().IsEmpty() ? "\tscrollinfo" : "") << (apzc->HasScrollgrab() ? "\tscrollgrab" : "") - << "\t" << container->GetFrameMetrics().GetContentDescription(); + << "\t" << container->GetContentDescription(); // Bind the APZC instance into the tree of APZCs if (aNextSibling) { diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 4a66fced30d..5d074ab3f66 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -353,6 +353,7 @@ LayerTransactionParent::RecvUpdate(const InfallibleTArray& cset, containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); containerLayer->SetBackgroundColor(attrs.backgroundColor().value()); + containerLayer->SetContentDescription(attrs.contentDescription()); break; } case Specific::TColorLayerAttributes: { diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index 3433c3ec8a3..a5f1b751934 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -41,6 +41,7 @@ using mozilla::layers::FrameMetrics::ViewID from "FrameMetrics.h"; using struct mozilla::layers::FenceHandle from "mozilla/layers/FenceUtils.h"; using struct mozilla::layers::FenceHandleFromChild from "mozilla/layers/FenceUtils.h"; using mozilla::layers::TextureIdentifier from "mozilla/layers/CompositorTypes.h"; +using std::string from "string"; namespace mozilla { namespace layers { @@ -227,6 +228,7 @@ struct ContainerLayerAttributes { float inheritedXScale; float inheritedYScale; LayerColor backgroundColor; + string contentDescription; }; struct ColorLayerAttributes { LayerColor color; nsIntRect bounds; }; struct CanvasLayerAttributes { GraphicsFilterType filter; nsIntRect bounds; }; diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 46c6125346d..86f5ed159c9 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -814,7 +814,7 @@ static void RecordFrameMetrics(nsIFrame* aForFrame, if (nsIContent* content = frameForCompositionBoundsCalculation->GetContent()) { nsAutoString contentDescription; content->Describe(contentDescription); - metrics.SetContentDescription(NS_LossyConvertUTF16toASCII(contentDescription).get()); + aRoot->SetContentDescription(NS_LossyConvertUTF16toASCII(contentDescription).get()); } }