Bug 1062411 - Make FrameMetrics::mContentDescription an nsCString so there is no limit to its length. r=BenWa

This commit is contained in:
Botond Ballo 2014-09-03 12:54:26 -04:00
parent 07fd6499d9
commit 559196f20a
2 changed files with 17 additions and 15 deletions

View File

@ -60,10 +60,6 @@ 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>;
@ -101,7 +97,6 @@ public:
, mViewport(0, 0, 0, 0)
, mBackgroundColor(0, 0, 0, 0)
{
mContentDescription[0] = '\0';
}
// Default copy ctor and operator= are fine
@ -128,8 +123,7 @@ public:
mScrollOffset == aOther.mScrollOffset &&
mHasScrollgrab == aOther.mHasScrollgrab &&
mUpdateScrollOffset == aOther.mUpdateScrollOffset &&
mBackgroundColor == aOther.mBackgroundColor &&
!strcmp(mContentDescription, aOther.mContentDescription);
mBackgroundColor == aOther.mBackgroundColor;
}
bool operator!=(const FrameMetrics& aOther) const
{
@ -247,6 +241,16 @@ public:
mScrollGeneration = aOther.mScrollGeneration;
}
// Make a copy of this FrameMetrics object which does not have any pointers
// to heap-allocated memory (i.e. is Plain Old Data, or 'POD'), and is
// therefore safe to be placed into shared memory.
FrameMetrics MakePODObject() const
{
FrameMetrics copy = *this;
copy.mContentDescription.Truncate();
return copy;
}
// ---------------------------------------------------------------------------
// The following metrics are all in widget space/device pixels.
//
@ -484,16 +488,14 @@ public:
mBackgroundColor = aBackgroundColor;
}
nsCString GetContentDescription() const
const nsCString& GetContentDescription() const
{
return nsCString(mContentDescription);
return mContentDescription;
}
void SetContentDescription(const nsCString& aContentDescription)
{
strncpy(mContentDescription, aContentDescription.get(),
sizeof(mContentDescription));
mContentDescription[sizeof(mContentDescription) - 1] = 0;
mContentDescription = aContentDescription;
}
private:
@ -569,9 +571,9 @@ private:
gfxRGBA mBackgroundColor;
// A description of the content element corresponding to this frame.
// This is empty unless this is a scrollable ContainerLayer and the
// This is empty unless this is a scrollable layer and the
// apz.printtree pref is turned on.
char mContentDescription[20];
nsCString mContentDescription;
};
/**

View File

@ -2868,7 +2868,7 @@ void AsyncPanZoomController::UpdateSharedCompositorFrameMetrics()
if (frame && mSharedLock && gfxPrefs::UseProgressiveTilePainting()) {
mSharedLock->Lock();
*frame = mFrameMetrics;
*frame = mFrameMetrics.MakePODObject();
mSharedLock->Unlock();
}
}