Skip to content

Commit

Permalink
Bug 1015278 - Replace the std::string with a char[20] in FrameMetrics…
Browse files Browse the repository at this point in the history
… to make it cross-process shmem friendly. r=botond
  • Loading branch information
staktrace committed May 24, 2014
1 parent ac5d74b commit 870ae6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ struct ParamTraits<mozilla::layers::FrameMetrics>
WriteParam(aMsg, aParam.mHasScrollgrab);
WriteParam(aMsg, aParam.mUpdateScrollOffset);
WriteParam(aMsg, aParam.mScrollGeneration);
WriteParam(aMsg, aParam.mContentDescription);
aMsg->WriteBytes(aParam.mContentDescription,
sizeof(aParam.mContentDescription));
WriteParam(aMsg, aParam.mTransformScale);
}

Expand All @@ -789,7 +790,9 @@ struct ParamTraits<mozilla::layers::FrameMetrics>
ReadParam(aMsg, aIter, &aResult->mHasScrollgrab) &&
ReadParam(aMsg, aIter, &aResult->mUpdateScrollOffset) &&
ReadParam(aMsg, aIter, &aResult->mScrollGeneration) &&
ReadParam(aMsg, aIter, &aResult->mContentDescription) &&
aMsg->ReadBytes(aIter,
reinterpret_cast<const char**>(&aResult->mContentDescription),
sizeof(aResult->mContentDescription)) &&
ReadParam(aMsg, aIter, &aResult->mTransformScale));
}
};
Expand Down
15 changes: 11 additions & 4 deletions gfx/layers/FrameMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ namespace layers {
* time of a layer-tree transaction. These metrics are especially
* useful for shadow layers, because the metrics values are updated
* atomically with new pixels.
*
* Note that the FrameMetrics struct is sometimes stored in shared
* memory and shared across processes, so it should be a "Plain Old
* Data (POD)" type with no members that use dynamic memory.
*/
struct FrameMetrics {
friend struct IPC::ParamTraits<mozilla::layers::FrameMetrics>;
Expand Down Expand Up @@ -84,6 +88,7 @@ struct FrameMetrics {
, mZoom(1)
, mUpdateScrollOffset(false)
, mScrollGeneration(0)
, mContentDescription()
, mRootCompositionSize(0, 0)
, mDisplayPortMargins(0, 0, 0, 0)
, mUseDisplayPortMargins(false)
Expand Down Expand Up @@ -380,14 +385,16 @@ struct FrameMetrics {
return mScrollGeneration;
}

const std::string& GetContentDescription() const
std::string GetContentDescription() const
{
return mContentDescription;
return std::string(mContentDescription);
}

void SetContentDescription(const std::string& aContentDescription)
{
mContentDescription = 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
Expand Down Expand Up @@ -478,7 +485,7 @@ struct FrameMetrics {

// A description of the content element corresponding to this frame.
// This is empty unless the apz.printtree pref is turned on.
std::string mContentDescription;
char mContentDescription[20];

// The size of the root scrollable's composition bounds, but in local CSS pixels.
CSSSize mRootCompositionSize;
Expand Down

0 comments on commit 870ae6f

Please sign in to comment.