diff --git a/gfx/layers/FrameMetrics.h b/gfx/layers/FrameMetrics.h index ea4e72f0bf3d..2763c5bfcf3e 100644 --- a/gfx/layers/FrameMetrics.h +++ b/gfx/layers/FrameMetrics.h @@ -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; @@ -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; }; /** diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index d397afa4fc47..817894b7713e 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -2868,7 +2868,7 @@ void AsyncPanZoomController::UpdateSharedCompositorFrameMetrics() if (frame && mSharedLock && gfxPrefs::UseProgressiveTilePainting()) { mSharedLock->Lock(); - *frame = mFrameMetrics; + *frame = mFrameMetrics.MakePODObject(); mSharedLock->Unlock(); } }