Bug 1404243 Part 3 - Remove refcount for StyleBasicShape, and use UniquePtr to hold it. r=heycam

After StyleBasicShape is set to StyleShapeSource, it's life cycle never go
beyond StyleShapeSource, so I make StyleBasicShape hold by a UniquePtr in
StyleShapeSource.

Also, replace all raw pointers to StyleBasicShape by UniquePtr in all APIs.

MozReview-Commit-ID: 1MfIFjP8TsQ

--HG--
extra : rebase_source : bdbbd47de57e0bc610e37913752ab8413f62588a
This commit is contained in:
Ting-Yu Lin 2017-09-25 18:50:24 +08:00
Родитель d8c9dae62b
Коммит d944131798
14 изменённых файлов: 57 добавлений и 63 удалений

Просмотреть файл

@ -38,7 +38,7 @@ ShapeUtils::ComputeShapeRadius(const StyleShapeRadius aType,
}
nsPoint
ShapeUtils::ComputeCircleOrEllipseCenter(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputeCircleOrEllipseCenter(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox)
{
MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Circle ||
@ -54,7 +54,7 @@ ShapeUtils::ComputeCircleOrEllipseCenter(const StyleBasicShape* aBasicShape,
}
nscoord
ShapeUtils::ComputeCircleRadius(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputeCircleRadius(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter,
const nsRect& aRefBox)
{
@ -86,7 +86,7 @@ ShapeUtils::ComputeCircleRadius(const StyleBasicShape* aBasicShape,
}
nsSize
ShapeUtils::ComputeEllipseRadii(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputeEllipseRadii(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter,
const nsRect& aRefBox)
{
@ -117,7 +117,7 @@ ShapeUtils::ComputeEllipseRadii(const StyleBasicShape* aBasicShape,
}
/* static */ nsRect
ShapeUtils::ComputeInsetRect(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputeInsetRect(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox)
{
MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Inset,
@ -138,7 +138,7 @@ ShapeUtils::ComputeInsetRect(const StyleBasicShape* aBasicShape,
}
/* static */ bool
ShapeUtils::ComputeInsetRadii(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputeInsetRadii(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aInsetRect,
const nsRect& aRefBox,
nscoord aRadii[8])
@ -150,7 +150,7 @@ ShapeUtils::ComputeInsetRadii(const StyleBasicShape* aBasicShape,
}
/* static */ nsTArray<nsPoint>
ShapeUtils::ComputePolygonVertices(const StyleBasicShape* aBasicShape,
ShapeUtils::ComputePolygonVertices(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox)
{
MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Polygon,

Просмотреть файл

@ -36,7 +36,7 @@ struct ShapeUtils final
// @param aRefBox The reference box of the basic shape.
// @return The point of the center.
static nsPoint ComputeCircleOrEllipseCenter(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox);
// Compute the radius for a circle.
@ -44,7 +44,7 @@ struct ShapeUtils final
// @param aRefBox the reference box of the circle.
// @return The length of the radius in app units.
static nscoord ComputeCircleRadius(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter, const nsRect& aRefBox);
// Compute the radii for an ellipse.
@ -53,14 +53,14 @@ struct ShapeUtils final
// @return The radii of the ellipse in app units. The width and height
// represent the x-axis and y-axis radii of the ellipse.
static nsSize ComputeEllipseRadii(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter, const nsRect& aRefBox);
// Compute the rect for an inset.
// @param aRefBox the reference box of the inset.
// @return The inset rect in app units.
static nsRect ComputeInsetRect(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox);
// Compute the radii for an inset.
@ -69,7 +69,7 @@ struct ShapeUtils final
// @param aRadii the returned radii in app units.
// @return true if any of the radii is nonzero; false otherwise.
static bool ComputeInsetRadii(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aInsetRect,
const nsRect& aRefBox,
nscoord aRadii[8]);
@ -79,7 +79,7 @@ struct ShapeUtils final
// @return The vertices in app units; the coordinate space is the same
// as aRefBox.
static nsTArray<nsPoint> ComputePolygonVertices(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox);
};

Просмотреть файл

@ -774,7 +774,7 @@ nsFloatManager::FloatInfo::FloatInfo(nsIFrame* aFrame,
mShapeInfo = ShapeInfo::CreateShapeBox(mFrame, shapeBoxRect, aWM,
aContainerSize);
} else if (shapeOutside.GetType() == StyleShapeSourceType::Shape) {
StyleBasicShape* const basicShape = shapeOutside.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = shapeOutside.GetBasicShape();
switch (basicShape->GetShapeType()) {
case StyleBasicShapeType::Polygon:
@ -961,7 +961,7 @@ nsFloatManager::ShapeInfo::CreateShapeBox(
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
nsFloatManager::ShapeInfo::CreateInset(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const LogicalRect& aShapeBoxRect,
WritingMode aWM,
const nsSize& aContainerSize)
@ -993,7 +993,7 @@ nsFloatManager::ShapeInfo::CreateInset(
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
nsFloatManager::ShapeInfo::CreateCircleOrEllipse(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const LogicalRect& aShapeBoxRect,
WritingMode aWM,
const nsSize& aContainerSize)
@ -1029,7 +1029,7 @@ nsFloatManager::ShapeInfo::CreateCircleOrEllipse(
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
nsFloatManager::ShapeInfo::CreatePolygon(
const StyleBasicShape* aBasicShape,
const UniquePtr<StyleBasicShape>& aBasicShape,
const LogicalRect& aShapeBoxRect,
WritingMode aWM,
const nsSize& aContainerSize)

Просмотреть файл

@ -382,19 +382,19 @@ private:
const nsSize& aContainerSize);
static mozilla::UniquePtr<ShapeInfo> CreateInset(
const mozilla::StyleBasicShape* aBasicShape,
const mozilla::UniquePtr<mozilla::StyleBasicShape>& aBasicShape,
const mozilla::LogicalRect& aShapeBoxRect,
mozilla::WritingMode aWM,
const nsSize& aContainerSize);
static mozilla::UniquePtr<ShapeInfo> CreateCircleOrEllipse(
const mozilla::StyleBasicShape* aBasicShape,
const mozilla::UniquePtr<mozilla::StyleBasicShape>& aBasicShape,
const mozilla::LogicalRect& aShapeBoxRect,
mozilla::WritingMode aWM,
const nsSize& aContainerSize);
static mozilla::UniquePtr<ShapeInfo> CreatePolygon(
const mozilla::StyleBasicShape* aBasicShape,
const mozilla::UniquePtr<mozilla::StyleBasicShape>& aBasicShape,
const mozilla::LogicalRect& aShapeBoxRect,
mozilla::WritingMode aWM,
const nsSize& aContainerSize);

Просмотреть файл

@ -1993,11 +1993,12 @@ Gecko_StyleShapeSource_SetURLValue(mozilla::StyleShapeSource* aShape, ServoBundl
aShape->SetURL(url.get());
}
mozilla::StyleBasicShape*
Gecko_NewBasicShape(mozilla::StyleBasicShapeType aType)
void
Gecko_NewBasicShape(mozilla::StyleShapeSource* aShape,
mozilla::StyleBasicShapeType aType)
{
RefPtr<StyleBasicShape> ptr = new mozilla::StyleBasicShape(aType);
return ptr.forget().take();
aShape->SetBasicShape(MakeUnique<mozilla::StyleBasicShape>(aType),
StyleGeometryBox::NoBox);
}
void

Просмотреть файл

@ -504,7 +504,8 @@ void Gecko_SetStyleCoordCalcValue(nsStyleUnit* unit, nsStyleUnion* value, nsStyl
void Gecko_CopyShapeSourceFrom(mozilla::StyleShapeSource* dst, const mozilla::StyleShapeSource* src);
void Gecko_DestroyShapeSource(mozilla::StyleShapeSource* shape);
mozilla::StyleBasicShape* Gecko_NewBasicShape(mozilla::StyleBasicShapeType type);
void Gecko_NewBasicShape(mozilla::StyleShapeSource* shape,
mozilla::StyleBasicShapeType type);
void Gecko_StyleShapeSource_SetURLValue(mozilla::StyleShapeSource* shape, ServoBundledURI uri);
void Gecko_ResetFilters(nsStyleEffects* effects, size_t new_len);

Просмотреть файл

@ -287,7 +287,6 @@ whitelist-types = [
"SheetParsingMode",
"StaticRefPtr",
"StyleAnimation",
"StyleBasicShape",
"StyleBasicShapeType",
"StyleGeometryBox",
"StyleShapeSource",
@ -442,7 +441,6 @@ structs-types = [
"ServoElementSnapshotTable",
"ServoStyleSetSizes",
"SheetParsingMode",
"StyleBasicShape",
"StyleBasicShapeType",
"StyleShapeSource",
"StyleTransition",

Просмотреть файл

@ -4158,7 +4158,7 @@ StyleShapeSourceToCSSArray(const StyleShapeSource& aShapeSource,
MOZ_ASSERT(aResult->Count() == 2,
"Expected array to be presized for a function and the sizing-box");
const StyleBasicShape* shape = aShapeSource.GetBasicShape();
const UniquePtr<StyleBasicShape>& shape = aShapeSource.GetBasicShape();
nsCSSKeyword functionName = shape->GetShapeTypeName();
RefPtr<nsCSSValue::Array> functionArray;
switch (shape->GetShapeType()) {

Просмотреть файл

@ -6356,7 +6356,7 @@ nsComputedDOMStyle::BasicShapeRadiiToString(nsAString& aCssText,
already_AddRefed<CSSValue>
nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
const StyleBasicShape* aStyleBasicShape)
const UniquePtr<StyleBasicShape>& aStyleBasicShape)
{
MOZ_ASSERT(aStyleBasicShape, "Expect a valid basic shape pointer!");
@ -6437,7 +6437,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
template<typename ReferenceBox>
already_AddRefed<CSSValue>
nsComputedDOMStyle::CreatePrimitiveValueForShapeSource(
const StyleBasicShape* aStyleBasicShape,
const UniquePtr<StyleBasicShape>& aStyleBasicShape,
ReferenceBox aReferenceBox,
const KTableEntry aBoxKeywordTable[])
{

Просмотреть файл

@ -12,6 +12,7 @@
#include "mozilla/ArenaRefPtrInlines.h"
#include "mozilla/Attributes.h"
#include "mozilla/StyleComplexColor.h"
#include "mozilla/UniquePtr.h"
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsCSSProps.h"
@ -703,13 +704,13 @@ private:
template<typename ReferenceBox>
already_AddRefed<CSSValue>
CreatePrimitiveValueForShapeSource(
const mozilla::StyleBasicShape* aStyleBasicShape,
const mozilla::UniquePtr<mozilla::StyleBasicShape>& aStyleBasicShape,
ReferenceBox aReferenceBox,
const KTableEntry aBoxKeywordTable[]);
// Helper function for computing basic shape styles.
already_AddRefed<CSSValue> CreatePrimitiveValueForBasicShape(
const mozilla::StyleBasicShape* aStyleBasicShape);
const mozilla::UniquePtr<mozilla::StyleBasicShape>& aStyleBasicShape);
void BoxValuesToString(nsAString& aString,
const nsTArray<nsStyleCoord>& aBoxValues);
void BasicShapeRadiiToString(nsAString& aCssText,

Просмотреть файл

@ -9795,13 +9795,13 @@ nsRuleNode::ComputeSVGData(void* aStartStruct,
COMPUTE_END_INHERITED(SVG, svg)
}
static already_AddRefed<StyleBasicShape>
static UniquePtr<StyleBasicShape>
GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
GeckoStyleContext* aStyleContext,
nsPresContext* aPresContext,
RuleNodeCacheConditions& aConditions)
{
RefPtr<StyleBasicShape> basicShape;
UniquePtr<StyleBasicShape> basicShape;
nsCSSValue::Array* shapeFunction = aValue.GetArrayValue();
nsCSSKeyword functionName =
@ -9809,7 +9809,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
if (functionName == eCSSKeyword_polygon) {
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new StyleBasicShape(StyleBasicShapeType::Polygon);
basicShape = MakeUnique<StyleBasicShape>(StyleBasicShapeType::Polygon);
MOZ_ASSERT(shapeFunction->Count() > 1,
"polygon has wrong number of arguments");
size_t j = 1;
@ -9846,7 +9846,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
StyleBasicShapeType::Circle :
StyleBasicShapeType::Ellipse;
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new StyleBasicShape(type);
basicShape = MakeUnique<StyleBasicShape>(type);
const int32_t mask = SETCOORD_PERCENT | SETCOORD_LENGTH |
SETCOORD_STORE_CALC | SETCOORD_ENUMERATED;
size_t count = type == StyleBasicShapeType::Circle ? 2 : 3;
@ -9882,7 +9882,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
}
} else if (functionName == eCSSKeyword_inset) {
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new StyleBasicShape(StyleBasicShapeType::Inset);
basicShape = MakeUnique<StyleBasicShape>(StyleBasicShapeType::Inset);
MOZ_ASSERT(shapeFunction->Count() == 6,
"inset function has wrong number of arguments");
MOZ_ASSERT(shapeFunction->Item(1).GetUnit() != eCSSUnit_Null,
@ -9943,7 +9943,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
NS_NOTREACHED("unexpected basic shape function");
}
return basicShape.forget();
return basicShape;
}
static void
@ -9962,7 +9962,7 @@ SetStyleShapeSourceToCSSValue(
"Expect one or both of a shape function and a reference box");
StyleGeometryBox referenceBox = StyleGeometryBox::NoBox;
RefPtr<StyleBasicShape> basicShape;
UniquePtr<StyleBasicShape> basicShape;
for (size_t i = 0; i < array->Count(); ++i) {
const nsCSSValue& item = array->Item(i);
@ -9978,7 +9978,7 @@ SetStyleShapeSourceToCSSValue(
}
if (basicShape) {
aShapeSource->SetBasicShape(basicShape, referenceBox);
aShapeSource->SetBasicShape(Move(basicShape), referenceBox);
} else {
aShapeSource->SetReferenceBox(referenceBox);
}

Просмотреть файл

@ -1047,7 +1047,8 @@ StyleShapeSource::StyleShapeSource(const StyleShapeSource& aSource)
if (aSource.mType == StyleShapeSourceType::URL) {
SetURL(aSource.mURL);
} else if (aSource.mType == StyleShapeSourceType::Shape) {
SetBasicShape(aSource.mBasicShape, aSource.mReferenceBox);
SetBasicShape(MakeUnique<StyleBasicShape>(*aSource.mBasicShape),
aSource.mReferenceBox);
} else if (aSource.mType == StyleShapeSourceType::Box) {
SetReferenceBox(aSource.mReferenceBox);
}
@ -1063,7 +1064,8 @@ StyleShapeSource::operator=(const StyleShapeSource& aOther)
if (aOther.mType == StyleShapeSourceType::URL) {
SetURL(aOther.mURL);
} else if (aOther.mType == StyleShapeSourceType::Shape) {
SetBasicShape(aOther.mBasicShape, aOther.mReferenceBox);
SetBasicShape(MakeUnique<StyleBasicShape>(*aOther.mBasicShape),
aOther.mReferenceBox);
} else if (aOther.mType == StyleShapeSourceType::Box) {
SetReferenceBox(aOther.mReferenceBox);
} else {
@ -1105,13 +1107,12 @@ StyleShapeSource::SetURL(css::URLValue* aValue)
}
void
StyleShapeSource::SetBasicShape(StyleBasicShape* aBasicShape,
StyleShapeSource::SetBasicShape(UniquePtr<StyleBasicShape> aBasicShape,
StyleGeometryBox aReferenceBox)
{
NS_ASSERTION(aBasicShape, "expected pointer");
ReleaseRef();
mBasicShape = aBasicShape;
mBasicShape->AddRef();
mBasicShape = Move(aBasicShape);
mReferenceBox = aReferenceBox;
mType = StyleShapeSourceType::Shape;
}
@ -1127,15 +1128,11 @@ StyleShapeSource::SetReferenceBox(StyleGeometryBox aReferenceBox)
void
StyleShapeSource::ReleaseRef()
{
if (mType == StyleShapeSourceType::Shape) {
NS_ASSERTION(mBasicShape, "expected pointer");
mBasicShape->Release();
} else if (mType == StyleShapeSourceType::URL) {
if (mType == StyleShapeSourceType::URL) {
NS_ASSERTION(mURL, "expected pointer");
mURL->Release();
}
// Both mBasicShape and mURL are pointers in a union. Nulling one of them
// nulls both of them.
mURL = nullptr;
}

Просмотреть файл

@ -2421,11 +2421,7 @@ public:
return !(*this == aOther);
}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(StyleBasicShape);
private:
~StyleBasicShape() {}
StyleBasicShapeType mType;
StyleFillRule mFillRule;
@ -2439,7 +2435,7 @@ private:
nsStyleCorners mRadius;
};
struct StyleShapeSource
struct StyleShapeSource final
{
StyleShapeSource()
: mURL(nullptr)
@ -2474,13 +2470,13 @@ struct StyleShapeSource
bool SetURL(css::URLValue* aValue);
StyleBasicShape* GetBasicShape() const
const UniquePtr<StyleBasicShape>& GetBasicShape() const
{
MOZ_ASSERT(mType == StyleShapeSourceType::Shape, "Wrong shape source type!");
return mBasicShape;
}
void SetBasicShape(StyleBasicShape* aBasicShape,
void SetBasicShape(UniquePtr<StyleBasicShape> aBasicShape,
StyleGeometryBox aReferenceBox);
StyleGeometryBox GetReferenceBox() const
@ -2498,8 +2494,8 @@ private:
void* operator new(size_t) = delete;
mozilla::UniquePtr<StyleBasicShape> mBasicShape;
union {
StyleBasicShape* mBasicShape;
css::URLValue* mURL;
};
StyleShapeSourceType mType = StyleShapeSourceType::None;

Просмотреть файл

@ -87,7 +87,7 @@ nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget)
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
r = ToAppUnits(r.ToNearestPixels(appUnitsPerDevPixel), appUnitsPerDevPixel);
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = mClipPathStyle.GetBasicShape();
switch (basicShape->GetShapeType()) {
case StyleBasicShapeType::Circle:
return CreateClipPathCircle(aDrawTarget, r);
@ -110,7 +110,7 @@ already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget,
const nsRect& aRefBox)
{
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = mClipPathStyle.GetBasicShape();
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
@ -130,7 +130,7 @@ already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPathEllipse(DrawTarget* aDrawTarget,
const nsRect& aRefBox)
{
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = mClipPathStyle.GetBasicShape();
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
@ -150,7 +150,7 @@ already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPathPolygon(DrawTarget* aDrawTarget,
const nsRect& aRefBox)
{
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = mClipPathStyle.GetBasicShape();
FillRule fillRule = basicShape->GetFillRule() == StyleFillRule::Nonzero ?
FillRule::FILL_WINDING : FillRule::FILL_EVEN_ODD;
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder(fillRule);
@ -176,7 +176,7 @@ already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPathInset(DrawTarget* aDrawTarget,
const nsRect& aRefBox)
{
StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
const UniquePtr<StyleBasicShape>& basicShape = mClipPathStyle.GetBasicShape();
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();