diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 20995170abfa..71b35c2de5af 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -667,6 +667,10 @@ nsCSSRendering::PaintBorder(nsPresContext* aPresContext, } nsStyleBorder newStyleBorder(*styleBorder); + // We could do something fancy to avoid the TrackImage/UntrackImage + // work, but it doesn't seem worth it. (We need to call TrackImage + // since we're not going through nsRuleNode::ComputeBorderData.) + newStyleBorder.TrackImage(aPresContext); NS_FOR_CSS_SIDES(side) { nscolor color = aStyleContext->GetVisitedDependentColor( @@ -678,6 +682,11 @@ nsCSSRendering::PaintBorder(nsPresContext* aPresContext, aDirtyRect, aBorderArea, newStyleBorder, aStyleContext, aFlags, aSkipSides); + // We could do something fancy to avoid the TrackImage/UntrackImage + // work, but it doesn't seem worth it. (We need to call UntrackImage + // since we're not going through nsStyleBorder::Destroy.) + newStyleBorder.UntrackImage(aPresContext); + return result; } @@ -5023,13 +5032,8 @@ ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage, return false; } - imgRequestProxy* req = aImage->GetImageData(); - if (!req) { - return false; - } - uint32_t status = 0; - if (NS_FAILED(req->GetImageStatus(&status))) { + if (NS_FAILED(aImage->GetImageData()->GetImageStatus(&status))) { return false; } @@ -5037,7 +5041,7 @@ ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage, // The image is "complete" since it's a corrupt image. If we created an // imgIContainer at all, return true. nsCOMPtr image; - req->GetImage(getter_AddRefs(image)); + aImage->GetImageData()->GetImage(getter_AddRefs(image)); return bool(image); } @@ -5074,9 +5078,8 @@ nsImageRenderer::PrepareImage() } switch (mType) { - case eStyleImageType_Image: { - MOZ_ASSERT(mImage->GetImageData(), - "must have image data, since we checked IsEmpty above"); + case eStyleImageType_Image: + { nsCOMPtr srcImage; DebugOnly rv = mImage->GetImageData()->GetImage(getter_AddRefs(srcImage)); diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 318e592eb180..e04f3352828a 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -2864,9 +2864,7 @@ nsDisplayBackgroundImage::ShouldCreateOwnLayer(nsDisplayListBuilder* aBuilder, if (image->GetType() == eStyleImageType_Image) { imgIRequest* imgreq = image->GetImageData(); nsCOMPtr image; - if (imgreq && - NS_SUCCEEDED(imgreq->GetImage(getter_AddRefs(image))) && - image) { + if (NS_SUCCEEDED(imgreq->GetImage(getter_AddRefs(image))) && image) { bool animated = false; if (NS_SUCCEEDED(image->GetAnimated(&animated)) && animated) { return WHENEVER_POSSIBLE; diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index e86a0e65333d..1cf36c3e89cd 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -792,9 +792,8 @@ AddAndRemoveImageAssociations(nsFrame* aFrame, continue; } - if (imgRequestProxy* req = oldImage.GetImageData()) { - imageLoader->DisassociateRequestFromFrame(req, aFrame); - } + imageLoader->DisassociateRequestFromFrame(oldImage.GetImageData(), + aFrame); } } } @@ -809,9 +808,7 @@ AddAndRemoveImageAssociations(nsFrame* aFrame, continue; } - if (imgRequestProxy* req = newImage.GetImageData()) { - imageLoader->AssociateRequestToFrame(req, aFrame); - } + imageLoader->AssociateRequestToFrame(newImage.GetImageData(), aFrame); } } } @@ -4303,11 +4300,7 @@ nsIFrame::AssociateImage(const nsStyleImage& aImage, nsPresContext* aPresContext return; } - imgRequestProxy* req = aImage.GetImageData(); - if (!req) { - return; - } - + imgIRequest *req = aImage.GetImageData(); mozilla::css::ImageLoader* loader = aPresContext->Document()->StyleImageLoader(); diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index e4c3ffee1310..34c86375d506 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -734,45 +734,6 @@ Gecko_SetGradientImageValue(nsStyleImage* aImage, nsStyleGradient* aGradient) aImage->SetGradientData(aGradient); } -static already_AddRefed -CreateStyleImageRequest(nsStyleImageRequest::Mode aModeFlags, - const uint8_t* aURLString, uint32_t aURLStringLength, - ThreadSafeURIHolder* aBaseURI, - ThreadSafeURIHolder* aReferrer, - ThreadSafePrincipalHolder* aPrincipal) -{ - MOZ_ASSERT(aURLString); - MOZ_ASSERT(aBaseURI); - MOZ_ASSERT(aReferrer); - MOZ_ASSERT(aPrincipal); - - nsString url; - nsDependentCSubstring urlString(reinterpret_cast(aURLString), - aURLStringLength); - AppendUTF8toUTF16(urlString, url); - RefPtr urlBuffer = nsCSSValue::BufferFromString(url); - - RefPtr req = - new nsStyleImageRequest(aModeFlags, urlBuffer, do_AddRef(aBaseURI), - do_AddRef(aReferrer), do_AddRef(aPrincipal)); - return req.forget(); -} - -void -Gecko_SetUrlImageValue(nsStyleImage* aImage, - const uint8_t* aURLString, uint32_t aURLStringLength, - ThreadSafeURIHolder* aBaseURI, - ThreadSafeURIHolder* aReferrer, - ThreadSafePrincipalHolder* aPrincipal) -{ - RefPtr req = - CreateStyleImageRequest(nsStyleImageRequest::Mode::Track | - nsStyleImageRequest::Mode::Lock, - aURLString, aURLStringLength, - aBaseURI, aReferrer, aPrincipal); - aImage->SetImageRequest(req.forget()); -} - void Gecko_CopyImageValueFrom(nsStyleImage* aImage, const nsStyleImage* aOther) { @@ -814,32 +775,6 @@ Gecko_CreateGradient(uint8_t aShape, return result; } -void -Gecko_SetListStyleImageNone(nsStyleList* aList) -{ - aList->mListStyleImage = nullptr; -} - -void -Gecko_SetListStyleImage(nsStyleList* aList, - const uint8_t* aURLString, uint32_t aURLStringLength, - ThreadSafeURIHolder* aBaseURI, - ThreadSafeURIHolder* aReferrer, - ThreadSafePrincipalHolder* aPrincipal) -{ - aList->mListStyleImage = - CreateStyleImageRequest(nsStyleImageRequest::Mode::Track | - nsStyleImageRequest::Mode::Lock, - aURLString, aURLStringLength, - aBaseURI, aReferrer, aPrincipal); -} - -void -Gecko_CopyListStyleImageFrom(nsStyleList* aList, const nsStyleList* aSource) -{ - aList->mListStyleImage = aSource->mListStyleImage; -} - void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity, size_t aElemSize) { diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index 78b8a554dede..71079b72a15e 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -156,10 +156,6 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator) extern "C" { -// Object refcounting. -NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal) -NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI) - // DOM Traversal. uint32_t Gecko_ChildrenCount(RawGeckoNodeBorrowed node); bool Gecko_NodeIsElement(RawGeckoNodeBorrowed node); @@ -250,15 +246,9 @@ void Gecko_SetListStyleType(nsStyleList* style_struct, uint32_t type); void Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src); // background-image style. -// TODO: support element() and -moz-image() +// TODO: support url() values (and maybe element() too?). void Gecko_SetNullImageValue(nsStyleImage* image); void Gecko_SetGradientImageValue(nsStyleImage* image, nsStyleGradient* gradient); -void Gecko_SetUrlImageValue(nsStyleImage* image, - const uint8_t* url_bytes, - uint32_t url_length, - ThreadSafeURIHolder* base_uri, - ThreadSafeURIHolder* referrer, - ThreadSafePrincipalHolder* principal); void Gecko_CopyImageValueFrom(nsStyleImage* image, const nsStyleImage* other); nsStyleGradient* Gecko_CreateGradient(uint8_t shape, @@ -267,14 +257,9 @@ nsStyleGradient* Gecko_CreateGradient(uint8_t shape, bool legacy_syntax, uint32_t stops); -// list-style-image style. -void Gecko_SetListStyleImageNone(nsStyleList* style_struct); -void Gecko_SetListStyleImage(nsStyleList* style_struct, - const uint8_t* string_bytes, uint32_t string_length, - ThreadSafeURIHolder* base_uri, - ThreadSafeURIHolder* referrer, - ThreadSafePrincipalHolder* principal); -void Gecko_CopyListStyleImageFrom(nsStyleList* dest, const nsStyleList* src); +// Object refcounting. +NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal) +NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI) // Display style. void Gecko_SetMozBinding(nsStyleDisplay* style_struct, diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 9f6553179724..c52ca102afe4 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -25,7 +25,6 @@ #include "nsStyleUtil.h" #include "nsDeviceContext.h" #include "nsStyleSet.h" -#include "nsContentUtils.h" using namespace mozilla; @@ -366,17 +365,6 @@ imgRequestProxy* nsCSSValue::GetImageValue(nsIDocument* aDocument) const return mValue.mImage->mRequests.GetWeak(aDocument); } -already_AddRefed -nsCSSValue::GetPossiblyStaticImageValue(nsIDocument* aDocument, - nsPresContext* aPresContext) const -{ - imgRequestProxy* req = GetImageValue(aDocument); - if (aPresContext->IsDynamic()) { - return do_AddRef(req); - } - return nsContentUtils::GetStaticRequest(req); -} - nscoord nsCSSValue::GetFixedLength(nsPresContext* aPresContext) const { MOZ_ASSERT(mUnit == eCSSUnit_PhysicalMillimeter, @@ -2878,25 +2866,8 @@ css::ImageValue::ImageValue(nsIURI* aURI, nsStringBuffer* aString, do_AddRef(new PtrHolder(aBaseURI, false)), do_AddRef(new PtrHolder(aReferrer)), do_AddRef(new PtrHolder(aOriginPrincipal))) -{ - Initialize(aDocument); -} - -css::ImageValue::ImageValue( - nsStringBuffer* aString, - already_AddRefed> aBaseURI, - already_AddRefed> aReferrer, - already_AddRefed> aOriginPrincipal) - : URLValueData(aString, Move(aBaseURI), Move(aReferrer), - Move(aOriginPrincipal)) -{ -} - -void -css::ImageValue::Initialize(nsIDocument* aDocument) { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(!mInitialized); // NB: If aDocument is not the original document, we may not be able to load // images from aDocument. Instead we do the image load from the original doc @@ -2906,16 +2877,12 @@ css::ImageValue::Initialize(nsIDocument* aDocument) loadingDoc = aDocument; } - loadingDoc->StyleImageLoader()->LoadImage(GetURI(), mOriginPrincipal, - mReferrer, this); + loadingDoc->StyleImageLoader()->LoadImage(aURI, aOriginPrincipal, aReferrer, + this); if (loadingDoc != aDocument) { aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this); } - -#ifdef DEBUG - mInitialized = true; -#endif } css::ImageValue::~ImageValue() diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index 0e7f18c7f87a..be3efbb36934 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -208,18 +208,9 @@ struct ImageValue final : public URLValueData nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal, nsIDocument* aDocument); - // This constructor is safe to call from any thread, but Initialize - // must be called later for the object to be useful. - ImageValue(nsStringBuffer* aString, - already_AddRefed> aBaseURI, - already_AddRefed> aReferrer, - already_AddRefed> aOriginPrincipal); - ImageValue(const ImageValue&) = delete; ImageValue& operator=(const ImageValue&) = delete; - void Initialize(nsIDocument* aDocument); - // XXXheycam We should have our own SizeOfIncludingThis method. protected: @@ -229,11 +220,6 @@ public: // Inherit Equals from URLValueData nsRefPtrHashtable, imgRequestProxy> mRequests; - -private: -#ifdef DEBUG - bool mInitialized = false; -#endif }; struct GridNamedArea { @@ -869,11 +855,6 @@ public: // all over. imgRequestProxy* GetImageValue(nsIDocument* aDocument) const; - // Like GetImageValue, but additionally will pass the imgRequestProxy - // through nsContentUtils::GetStaticRequest if aPresContent is static. - already_AddRefed GetPossiblyStaticImageValue( - nsIDocument* aDocument, nsPresContext* aPresContext) const; - nscoord GetFixedLength(nsPresContext* aPresContext) const; nscoord GetPixelLength() const; diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 504e562c7c59..4244658d580b 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -2082,15 +2082,7 @@ nsComputedDOMStyle::SetValueToStyleImage(const nsStyleImage& aStyleImage, switch (aStyleImage.GetType()) { case eStyleImageType_Image: { - imgIRequest* req = aStyleImage.GetImageData(); - if (!req) { - // XXXheycam If we had some problem resolving the imgRequestProxy, - // maybe we should just use the URL stored in the nsStyleImage's - // mImageValue? (Similarly in DoGetListStyleImage.) - aValue->SetIdent(eCSSKeyword_none); - break; - } - + imgIRequest *req = aStyleImage.GetImageData(); nsCOMPtr uri; req->GetURI(getter_AddRefs(uri)); @@ -3503,16 +3495,13 @@ nsComputedDOMStyle::DoGetListStyleImage() const nsStyleList* list = StyleList(); - // XXXheycam As in SetValueToStyleImage, we might want to use the - // URL stored in the nsStyleImageRequest's mImageValue if we - // failed to resolve the imgRequestProxy. - - imgRequestProxy* image = list->GetListStyleImage(); - if (!image) { + if (!list->GetListStyleImage()) { val->SetIdent(eCSSKeyword_none); } else { nsCOMPtr uri; - image->GetURI(getter_AddRefs(uri)); + if (list->GetListStyleImage()) { + list->GetListStyleImage()->GetURI(getter_AddRefs(uri)); + } val->SetURI(uri); } diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index b1e03b94a36b..5b133cadfcbb 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -128,30 +128,13 @@ SetImageRequest(function aCallback, nsPresContext* aPresContext, const nsCSSValue& aValue) { - RefPtr req = - aValue.GetPossiblyStaticImageValue(aPresContext->Document(), - aPresContext); - aCallback(req); -} - -static void -SetStyleImageRequest(function aCallback, - nsPresContext* aPresContext, - const nsCSSValue& aValue, - nsStyleImageRequest::Mode aModeFlags = - nsStyleImageRequest::Mode::Track | - nsStyleImageRequest::Mode::Lock) -{ - SetImageRequest([&](imgRequestProxy* aProxy) { - RefPtr request; - if (aProxy) { - css::ImageValue* imageValue = aValue.GetImageStructValue(); - ImageTracker* imageTracker = aPresContext->Document()->ImageTracker(); - request = - new nsStyleImageRequest(aModeFlags, aProxy, imageValue, imageTracker); - } - aCallback(request); - }, aPresContext, aValue); + imgRequestProxy* req = GetImageRequest(aPresContext, aValue); + if (aPresContext->IsDynamic()) { + aCallback(req); + } else { + RefPtr staticReq = nsContentUtils::GetStaticRequest(req); + aCallback(staticReq); + } } template @@ -1284,8 +1267,8 @@ static void SetStyleImageToImageRect(nsStyleContext* aStyleContext, // if (arr->Item(1).GetUnit() == eCSSUnit_Image) { - SetStyleImageRequest([&](nsStyleImageRequest* req) { - aResult.SetImageRequest(do_AddRef(req)); + SetImageRequest([&](imgRequestProxy* req) { + aResult.SetImageData(req); }, aStyleContext->PresContext(), arr->Item(1)); } else { NS_WARNING("nsCSSValue::Image::Image() failed?"); @@ -1320,8 +1303,8 @@ static void SetStyleImage(nsStyleContext* aStyleContext, switch (aValue.GetUnit()) { case eCSSUnit_Image: - SetStyleImageRequest([&](nsStyleImageRequest* req) { - aResult.SetImageRequest(do_AddRef(req)); + SetImageRequest([&](imgRequestProxy* req) { + aResult.SetImageData(req); }, aStyleContext->PresContext(), aValue); break; case eCSSUnit_Function: @@ -7345,6 +7328,9 @@ nsRuleNode::ComputeBackgroundData(void* aStartStruct, FillAllBackgroundLists(bg->mImage, maxItemCount); } + // Now that the dust has settled, register the images with the document + bg->mImage.TrackImages(aContext->PresContext()); + COMPUTE_END_RESET(Background, bg) } @@ -7731,6 +7717,8 @@ nsRuleNode::ComputeBorderData(void* aStartStruct, parentBorder->mBorderImageRepeatV, NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH); + border->TrackImage(aContext->PresContext()); + COMPUTE_END_RESET(Border, border) } @@ -7963,18 +7951,18 @@ nsRuleNode::ComputeListData(void* aStartStruct, // list-style-image: url, none, inherit const nsCSSValue* imageValue = aRuleData->ValueForListStyleImage(); if (eCSSUnit_Image == imageValue->GetUnit()) { - SetStyleImageRequest([&](nsStyleImageRequest* req) { - list->mListStyleImage = req; + SetImageRequest([&](imgRequestProxy* req) { + list->SetListStyleImage(req); }, mPresContext, *imageValue); } else if (eCSSUnit_None == imageValue->GetUnit() || eCSSUnit_Initial == imageValue->GetUnit()) { - list->mListStyleImage = nullptr; + list->SetListStyleImage(nullptr); } else if (eCSSUnit_Inherit == imageValue->GetUnit() || eCSSUnit_Unset == imageValue->GetUnit()) { conditions.SetUncacheable(); - list->mListStyleImage = parentList->mListStyleImage; + list->SetListStyleImage(parentList->GetListStyleImage()); } // list-style-position: enum, inherit, initial @@ -8997,8 +8985,7 @@ nsRuleNode::ComputeContentData(void* aStartStruct, for (uint32_t i = 0; i < content->ContentCount(); ++i) { if ((content->ContentAt(i).mType == eStyleContentType_Image) && content->ContentAt(i).mContent.mImage) { - content->ContentAt(i).TrackImage( - aContext->PresContext()->Document()->ImageTracker()); + content->ContentAt(i).TrackImage(aContext->PresContext()); } } @@ -10067,6 +10054,8 @@ nsRuleNode::ComputeSVGResetData(void* aStartStruct, } #endif + svgReset->mMask.TrackImages(aContext->PresContext()); + COMPUTE_END_RESET(SVGReset, svgReset) } diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index e82dd3ec4bfb..56563597cba5 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -468,24 +468,8 @@ const void* nsStyleContext::StyleData(nsStyleStructID aSID) mCachedInheritedData.mStyleStructs[aSID] = const_cast(newData); } } else { - newData = StyleStructFromServoComputedValues(aSID); - - // perform any remaining main thread work on the struct - switch (aSID) { -#define STYLE_STRUCT(name_, checkdata_cb_) \ - case eStyleStruct_##name_: { \ - auto data = static_cast(newData); \ - const_cast(data)->FinishStyle(PresContext()); \ - break; \ - } -#include "nsStyleStructList.h" -#undef STYLE_STRUCT - default: - MOZ_ASSERT_UNREACHABLE("unexpected nsStyleStructID value"); - break; - } - // The Servo-backed StyleContextSource owns the struct. + newData = StyleStructFromServoComputedValues(aSID); AddStyleBit(nsCachedStyleData::GetBitForSID(aSID)); // XXXbholley: Unconditionally caching reset structs here defeats the memory diff --git a/layout/style/nsStyleContext.h b/layout/style/nsStyleContext.h index cb76b81f1265..6d641ac175fd 100644 --- a/layout/style/nsStyleContext.h +++ b/layout/style/nsStyleContext.h @@ -673,8 +673,6 @@ private: newData = \ Servo_GetStyle##name_(mSource.AsServoComputedValues()); \ } \ - /* perform any remaining main thread work on the struct */ \ - const_cast(newData)->FinishStyle(PresContext());\ /* the Servo-backed StyleContextSource owns the struct */ \ AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \ } \ @@ -703,8 +701,6 @@ private: } else { \ newData = \ Servo_GetStyle##name_(mSource.AsServoComputedValues()); \ - /* perform any remaining main thread work on the struct */ \ - const_cast(newData)->FinishStyle(PresContext());\ /* The Servo-backed StyleContextSource owns the struct. \ * \ * XXXbholley: Unconditionally caching reset structs here \ diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 8d387b0a58d3..70a8bb6f2cd3 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -93,21 +93,6 @@ EqualImages(imgIRequest *aImage1, imgIRequest* aImage2) return EqualURIs(uri1, uri2); } -static bool -DefinitelyEqualImages(nsStyleImageRequest* aRequest1, - nsStyleImageRequest* aRequest2) -{ - if (aRequest1 == aRequest2) { - return true; - } - - if (!aRequest1 || !aRequest2) { - return false; - } - - return aRequest1->DefinitelyEquals(*aRequest2); -} - // A nullsafe wrapper for strcmp. We depend on null-safety. static int safe_strcmp(const char16_t* a, const char16_t* b) @@ -451,15 +436,6 @@ nsStyleBorder::~nsStyleBorder() } } -void -nsStyleBorder::FinishStyle(nsPresContext* aPresContext) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aPresContext->StyleSet()->IsServo()); - - mBorderImageSource.ResolveImage(aPresContext); -} - nsMargin nsStyleBorder::GetImageOutset() const { @@ -488,8 +464,8 @@ nsStyleBorder::GetImageOutset() const } void -nsStyleBorder::Destroy(nsPresContext* aContext) -{ +nsStyleBorder::Destroy(nsPresContext* aContext) { + UntrackImage(aContext); this->~nsStyleBorder(); aContext->PresShell()-> FreeByObjectID(eArenaObjectID_nsStyleBorder, this); @@ -666,25 +642,14 @@ nsStyleList::~nsStyleList() nsStyleList::nsStyleList(const nsStyleList& aSource) : mListStylePosition(aSource.mListStylePosition) - , mListStyleImage(aSource.mListStyleImage) , mCounterStyle(aSource.mCounterStyle) , mQuotes(aSource.mQuotes) , mImageRegion(aSource.mImageRegion) { + SetListStyleImage(aSource.GetListStyleImage()); MOZ_COUNT_CTOR(nsStyleList); } -void -nsStyleList::FinishStyle(nsPresContext* aPresContext) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aPresContext->StyleSet()->IsServo()); - - if (mListStyleImage && !mListStyleImage->IsResolved()) { - mListStyleImage->Resolve(aPresContext); - } -} - void nsStyleList::SetQuotesInherit(const nsStyleList* aOther) { @@ -749,7 +714,7 @@ nsStyleList::CalcDifference(const nsStyleList& aNewData) const if (mListStylePosition != aNewData.mListStylePosition) { return nsChangeHint_ReconstructFrame; } - if (DefinitelyEqualImages(mListStyleImage, aNewData.mListStyleImage) && + if (EqualImages(mListStyleImage, aNewData.mListStyleImage) && mCounterStyle == aNewData.mCounterStyle) { if (mImageRegion.IsEqualInterior(aNewData.mImageRegion)) { return nsChangeHint(0); @@ -1204,20 +1169,13 @@ nsStyleSVGReset::nsStyleSVGReset(const nsStyleSVGReset& aSource) void nsStyleSVGReset::Destroy(nsPresContext* aContext) { + mMask.UntrackImages(aContext); + this->~nsStyleSVGReset(); aContext->PresShell()-> FreeByObjectID(mozilla::eArenaObjectID_nsStyleSVGReset, this); } -void -nsStyleSVGReset::FinishStyle(nsPresContext* aPresContext) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aPresContext->StyleSet()->IsServo()); - - mMask.ResolveImages(aPresContext); -} - nsChangeHint nsStyleSVGReset::CalcDifference(const nsStyleSVGReset& aNewData) const { @@ -1911,174 +1869,6 @@ nsStyleGradient::HasCalc() mRadiusX.IsCalcUnit() || mRadiusY.IsCalcUnit(); } - -// -------------------- -// nsStyleImageRequest - -/** - * Runnable to release the nsStyleImageRequest's mRequestProxy, - * mImageValue and mImageValue on the main thread, and to perform - * any necessary unlocking and untracking of the image. - */ -class StyleImageRequestCleanupTask : public mozilla::Runnable -{ -public: - typedef nsStyleImageRequest::Mode Mode; - - StyleImageRequestCleanupTask(Mode aModeFlags, - already_AddRefed aRequestProxy, - already_AddRefed aImageValue, - already_AddRefed aImageTracker) - : mModeFlags(aModeFlags) - , mRequestProxy(aRequestProxy) - , mImageValue(aImageValue) - , mImageTracker(aImageTracker) - { - } - - NS_IMETHOD Run() final - { - MOZ_ASSERT(NS_IsMainThread()); - - if (!mRequestProxy) { - return NS_OK; - } - - MOZ_ASSERT(mImageTracker); - - if (mModeFlags & Mode::Lock) { - mRequestProxy->UnlockImage(); - } - - if (mModeFlags & Mode::Discard) { - mRequestProxy->RequestDiscard(); - } - - if (mModeFlags & Mode::Track) { - mImageTracker->Remove(mRequestProxy); - } - - return NS_OK; - } - -protected: - virtual ~StyleImageRequestCleanupTask() { MOZ_ASSERT(NS_IsMainThread()); } - -private: - Mode mModeFlags; - // Since we always dispatch this runnable to the main thread, these will be - // released on the main thread when the runnable itself is released. - RefPtr mRequestProxy; - RefPtr mImageValue; - RefPtr mImageTracker; -}; - -nsStyleImageRequest::nsStyleImageRequest(Mode aModeFlags, - imgRequestProxy* aRequestProxy, - css::ImageValue* aImageValue, - ImageTracker* aImageTracker) - : mRequestProxy(aRequestProxy) - , mImageValue(aImageValue) - , mImageTracker(aImageTracker) - , mModeFlags(aModeFlags) - , mResolved(true) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aRequestProxy); - MOZ_ASSERT(aImageValue); - MOZ_ASSERT(aImageTracker); - - MaybeTrackAndLock(); -} - -nsStyleImageRequest::nsStyleImageRequest( - Mode aModeFlags, - nsStringBuffer* aURLBuffer, - already_AddRefed> aBaseURI, - already_AddRefed> aReferrer, - already_AddRefed> aPrincipal) - : mModeFlags(aModeFlags) - , mResolved(false) -{ - mImageValue = new css::ImageValue(aURLBuffer, Move(aBaseURI), - Move(aReferrer), Move(aPrincipal)); -} - -nsStyleImageRequest::~nsStyleImageRequest() -{ - // We may or may not be being destroyed on the main thread. To clean - // up, we must untrack and unlock the image (depending on mModeFlags), - // and release mRequestProxy and mImageValue, all on the main thread. - { - RefPtr task = - new StyleImageRequestCleanupTask(mModeFlags, - mRequestProxy.forget(), - mImageValue.forget(), - mImageTracker.forget()); - if (NS_IsMainThread()) { - task->Run(); - } else { - NS_DispatchToMainThread(task.forget()); - } - } - - MOZ_ASSERT(!mRequestProxy); - MOZ_ASSERT(!mImageValue); - MOZ_ASSERT(!mImageTracker); -} - -bool -nsStyleImageRequest::Resolve(nsPresContext* aPresContext) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(!IsResolved(), "already resolved"); - - mResolved = true; - - // For now, just have unique nsCSSValue/ImageValue objects. We should - // really store the ImageValue on the Servo specified value, so that we can - // share imgRequestProxys that come from the same rule in the same - // document. - mImageValue->Initialize(aPresContext->Document()); - - nsCSSValue value; - value.SetImageValue(mImageValue); - mRequestProxy = value.GetPossiblyStaticImageValue(aPresContext->Document(), - aPresContext); - - if (!mRequestProxy) { - // The URL resolution or image load failed. - return false; - } - - mImageTracker = aPresContext->Document()->ImageTracker(); - MaybeTrackAndLock(); - return true; -} - -void -nsStyleImageRequest::MaybeTrackAndLock() -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(IsResolved()); - MOZ_ASSERT(mRequestProxy); - MOZ_ASSERT(mImageTracker); - - if (mModeFlags & Mode::Track) { - mImageTracker->Add(mRequestProxy); - } - - if (mModeFlags & Mode::Lock) { - mRequestProxy->LockImage(); - } -} - -bool -nsStyleImageRequest::DefinitelyEquals(const nsStyleImageRequest& aOther) const -{ - return DefinitelyEqualURIs(mImageValue, aOther.mImageValue); -} - // -------------------- // CachedBorderImageData // @@ -2123,6 +1913,9 @@ CachedBorderImageData::GetSubImage(uint8_t aIndex) nsStyleImage::nsStyleImage() : mType(eStyleImageType_Null) , mCropRect(nullptr) +#ifdef DEBUG + , mImageTracked(false) +#endif { MOZ_COUNT_CTOR(nsStyleImage); } @@ -2138,6 +1931,9 @@ nsStyleImage::~nsStyleImage() nsStyleImage::nsStyleImage(const nsStyleImage& aOther) : mType(eStyleImageType_Null) , mCropRect(nullptr) +#ifdef DEBUG + , mImageTracked(false) +#endif { // We need our own copy constructor because we don't want // to copy the reference count @@ -2161,7 +1957,7 @@ nsStyleImage::DoCopy(const nsStyleImage& aOther) SetNull(); if (aOther.mType == eStyleImageType_Image) { - SetImageRequest(do_AddRef(aOther.mImage)); + SetImageData(aOther.mImage); } else if (aOther.mType == eStyleImageType_Gradient) { SetGradientData(aOther.mGradient); } else if (aOther.mType == eStyleImageType_Element) { @@ -2178,6 +1974,9 @@ nsStyleImage::DoCopy(const nsStyleImage& aOther) void nsStyleImage::SetNull() { + MOZ_ASSERT(!mImageTracked, + "Calling SetNull() with image tracked!"); + if (mType == eStyleImageType_Gradient) { mGradient->Release(); } else if (mType == eStyleImageType_Image) { @@ -2191,16 +1990,19 @@ nsStyleImage::SetNull() } void -nsStyleImage::SetImageRequest(already_AddRefed aImage) +nsStyleImage::SetImageData(imgRequestProxy* aImage) { - RefPtr image = aImage; + MOZ_ASSERT(!mImageTracked, + "Setting a new image without untracking the old one!"); + + NS_IF_ADDREF(aImage); if (mType != eStyleImageType_Null) { SetNull(); } - if (image) { - mImage = image.forget().take(); + if (aImage) { + mImage = aImage; mType = eStyleImageType_Image; } if (mCachedBIData) { @@ -2208,6 +2010,46 @@ nsStyleImage::SetImageRequest(already_AddRefed aImage) } } +void +nsStyleImage::TrackImage(nsPresContext* aContext) +{ + // Sanity + MOZ_ASSERT(!mImageTracked, "Already tracking image!"); + MOZ_ASSERT(mType == eStyleImageType_Image, + "Can't track image when there isn't one!"); + + // Register the image with the document + nsIDocument* doc = aContext->Document(); + if (doc) { + doc->ImageTracker()->Add(mImage); + } + + // Mark state +#ifdef DEBUG + mImageTracked = true; +#endif +} + +void +nsStyleImage::UntrackImage(nsPresContext* aContext) +{ + // Sanity + MOZ_ASSERT(mImageTracked, "Image not tracked!"); + MOZ_ASSERT(mType == eStyleImageType_Image, + "Can't untrack image when there isn't one!"); + + // Unregister the image with the document + nsIDocument* doc = aContext->Document(); + if (doc) { + doc->ImageTracker()->Remove(mImage); + } + + // Mark state +#ifdef DEBUG + mImageTracked = false; +#endif +} + void nsStyleImage::SetGradientData(nsStyleGradient* aGradient) { @@ -2272,13 +2114,8 @@ nsStyleImage::ComputeActualCropRect(nsIntRect& aActualCropRect, return false; } - imgRequestProxy* req = GetImageData(); - if (!req) { - return false; - } - nsCOMPtr imageContainer; - req->GetImage(getter_AddRefs(imageContainer)); + mImage->GetImage(getter_AddRefs(imageContainer)); if (!imageContainer) { return false; } @@ -2310,11 +2147,7 @@ nsresult nsStyleImage::StartDecoding() const { if (mType == eStyleImageType_Image) { - imgRequestProxy* req = GetImageData(); - if (!req) { - return NS_ERROR_FAILURE; - } - return req->StartDecoding(); + return mImage->StartDecoding(); } return NS_OK; } @@ -2335,10 +2168,9 @@ nsStyleImage::IsOpaque() const } MOZ_ASSERT(mType == eStyleImageType_Image, "unexpected image type"); - MOZ_ASSERT(GetImageData(), "should've returned earlier above"); nsCOMPtr imageContainer; - GetImageData()->GetImage(getter_AddRefs(imageContainer)); + mImage->GetImage(getter_AddRefs(imageContainer)); MOZ_ASSERT(imageContainer, "IsComplete() said image container is ready"); // Check if the crop region of the image is opaque. @@ -2367,13 +2199,10 @@ nsStyleImage::IsComplete() const case eStyleImageType_Gradient: case eStyleImageType_Element: return true; - case eStyleImageType_Image: { - imgRequestProxy* req = GetImageData(); - if (!req) { - return false; - } + case eStyleImageType_Image: + { uint32_t status = imgIRequest::STATUS_ERROR; - return NS_SUCCEEDED(req->GetImageStatus(&status)) && + return NS_SUCCEEDED(mImage->GetImageStatus(&status)) && (status & imgIRequest::STATUS_SIZE_AVAILABLE) && (status & imgIRequest::STATUS_FRAME_COMPLETE); } @@ -2392,13 +2221,10 @@ nsStyleImage::IsLoaded() const case eStyleImageType_Gradient: case eStyleImageType_Element: return true; - case eStyleImageType_Image: { - imgRequestProxy* req = GetImageData(); - if (!req) { - return false; - } + case eStyleImageType_Image: + { uint32_t status = imgIRequest::STATUS_ERROR; - return NS_SUCCEEDED(req->GetImageStatus(&status)) && + return NS_SUCCEEDED(mImage->GetImageStatus(&status)) && !(status & imgIRequest::STATUS_ERROR) && (status & imgIRequest::STATUS_LOAD_COMPLETE); } @@ -2427,7 +2253,7 @@ nsStyleImage::operator==(const nsStyleImage& aOther) const } if (mType == eStyleImageType_Image) { - return DefinitelyEqualImages(mImage, aOther.mImage); + return EqualImages(mImage, aOther.mImage); } if (mType == eStyleImageType_Gradient) { @@ -2708,9 +2534,7 @@ nsStyleImageLayers::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImag if (type == eStyleImageType_Image) { nsCOMPtr imgContainer; - if (imgRequestProxy* req = aImage.GetImageData()) { - req->GetImage(getter_AddRefs(imgContainer)); - } + aImage.GetImageData()->GetImage(getter_AddRefs(imgContainer)); if (imgContainer) { CSSIntSize imageSize; nsSize imageRatio; @@ -2944,20 +2768,14 @@ nsStyleBackground::~nsStyleBackground() void nsStyleBackground::Destroy(nsPresContext* aContext) { + // Untrack all the images stored in our layers + mImage.UntrackImages(aContext); + this->~nsStyleBackground(); aContext->PresShell()-> FreeByObjectID(eArenaObjectID_nsStyleBackground, this); } -void -nsStyleBackground::FinishStyle(nsPresContext* aPresContext) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aPresContext->StyleSet()->IsServo()); - - mImage.ResolveImages(aPresContext); -} - nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aNewData) const { @@ -3609,7 +3427,7 @@ nsStyleContentData::operator==(const nsStyleContentData& aOther) const } void -nsStyleContentData::TrackImage(ImageTracker* aImageTracker) +nsStyleContentData::TrackImage(nsPresContext* aContext) { // Sanity MOZ_ASSERT(!mImageTracked, "Already tracking image!"); @@ -3618,7 +3436,11 @@ nsStyleContentData::TrackImage(ImageTracker* aImageTracker) MOZ_ASSERT(mContent.mImage, "Can't track image when there isn't one!"); - aImageTracker->Add(mContent.mImage); + // Register the image with the document + nsIDocument* doc = aContext->Document(); + if (doc) { + doc->ImageTracker()->Add(mContent.mImage); + } // Mark state #ifdef DEBUG @@ -3627,7 +3449,7 @@ nsStyleContentData::TrackImage(ImageTracker* aImageTracker) } void -nsStyleContentData::UntrackImage(ImageTracker* aImageTracker) +nsStyleContentData::UntrackImage(nsPresContext* aContext) { // Sanity MOZ_ASSERT(mImageTracked, "Image not tracked!"); @@ -3636,7 +3458,11 @@ nsStyleContentData::UntrackImage(ImageTracker* aImageTracker) MOZ_ASSERT(mContent.mImage, "Can't untrack image when there isn't one!"); - aImageTracker->Remove(mContent.mImage); + // Unregister the image with the document + nsIDocument* doc = aContext->Document(); + if (doc) { + doc->ImageTracker()->Remove(mContent.mImage); + } // Mark state #ifdef DEBUG @@ -3666,7 +3492,7 @@ nsStyleContent::Destroy(nsPresContext* aContext) // Unregister any images we might have with the document. for (auto& content : mContents) { if (content.mType == eStyleContentType_Image && content.mContent.mImage) { - content.UntrackImage(aContext->Document()->ImageTracker()); + content.UntrackImage(aContext); } } diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 34be357dc814..41ad9794cf22 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -46,11 +46,6 @@ class nsStyleContext; class nsTextFrame; class imgIContainer; struct nsStyleVisibility; -namespace mozilla { -namespace dom { -class ImageTracker; -} // namespace dom -} // namespace mozilla typedef nsINode RawGeckoNode; typedef mozilla::dom::Element RawGeckoElement; @@ -166,7 +161,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont ~nsStyleFont() { MOZ_COUNT_DTOR(nsStyleFont); } - void FinishStyle(nsPresContext* aPresContext) {} nsChangeHint CalcDifference(const nsStyleFont& aNewData) const; static nsChangeHint MaxDifference() { @@ -288,97 +282,6 @@ private: nsStyleGradient& operator=(const nsStyleGradient& aOther) = delete; }; -/** - * A wrapper for an imgRequestProxy that supports off-main-thread creation - * and equality comparison. - * - * An nsStyleImageRequest can be created in two ways: - * - * 1. Using the constructor that takes an imgRequestProxy. This must - * be called from the main thread. The nsStyleImageRequest is - * immediately considered "resolved", and the get() method that - * returns the imgRequestProxy can be called. - * - * 2. Using the constructor that takes the URL, base URI, referrer - * and principal that can be used to inititiate an image load and - * produce an imgRequestProxy later. This can be called from - * any thread. The nsStyleImageRequest is not considered "resolved" - * at this point, and the Resolve() method must be called later - * to initiate the image load and make calls to get() valid. - * - * Calls to TrackImage(), UntrackImage(), LockImage(), UnlockImage() and - * RequestDiscard() are made to the imgRequestProxy and ImageTracker as - * appropriate, according to the mode flags passed in to the constructor. - * - * The main thread constructor takes a pointer to the css::ImageValue that - * is the specified url() value, while the off-main-thread constructor - * creates a new css::ImageValue to represent the url() information passed - * to the constructor. This ImageValue is held on to for the comparisons done - * in DefinitelyEquals(), so that we don't need to call into the non-OMT-safe - * Equals() on the nsIURI objects returned from imgRequestProxy::GetURI(). - */ -class nsStyleImageRequest -{ -public: - // Flags describing whether the imgRequestProxy must be tracked in the - // ImageTracker, whether LockImage/UnlockImage calls will be made - // when obtaining and releasing the imgRequestProxy, and whether - // RequestDiscard will be called on release. - enum class Mode : uint8_t { - Track = 0x1, // used by all except nsCursorImage - Lock = 0x2, // used by all except nsStyleContentData - Discard = 0x4, // used only by nsCursorImage - }; - - // Must be called from the main thread. - nsStyleImageRequest(Mode aModeFlags, - imgRequestProxy* aRequestProxy, - mozilla::css::ImageValue* aImageValue, - mozilla::dom::ImageTracker* aImageTracker); - - // Can be called from any thread, but Resolve() must be called later - // on the main thread before get() can be used. - nsStyleImageRequest( - Mode aModeFlags, - nsStringBuffer* aURLBuffer, - already_AddRefed> aBaseURI, - already_AddRefed> aReferrer, - already_AddRefed> aPrincipal); - - bool Resolve(nsPresContext* aPresContext); - bool IsResolved() const { return mResolved; } - - imgRequestProxy* get() { - MOZ_ASSERT(IsResolved(), "Resolve() must be called first"); - MOZ_ASSERT(NS_IsMainThread()); - return mRequestProxy.get(); - } - const imgRequestProxy* get() const { - return const_cast(this)->get(); - } - - // Returns whether the ImageValue objects in the two nsStyleImageRequests - // return true from URLValueData::DefinitelyEqualURIs. - bool DefinitelyEquals(const nsStyleImageRequest& aOther) const; - - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsStyleImageRequest); - -private: - ~nsStyleImageRequest(); - nsStyleImageRequest& operator=(const nsStyleImageRequest& aOther) = delete; - - void MaybeTrackAndLock(); - - RefPtr mRequestProxy; - RefPtr mImageValue; - RefPtr mImageTracker; - - Mode mModeFlags; - bool mResolved; -}; - -MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(nsStyleImageRequest::Mode) - enum nsStyleImageType { eStyleImageType_Null, eStyleImageType_Image, @@ -422,29 +325,23 @@ struct nsStyleImage nsStyleImage& operator=(const nsStyleImage& aOther); void SetNull(); - void SetImageRequest(already_AddRefed aImage); + void SetImageData(imgRequestProxy* aImage); + void TrackImage(nsPresContext* aContext); + void UntrackImage(nsPresContext* aContext); void SetGradientData(nsStyleGradient* aGradient); void SetElementId(const char16_t* aElementId); void SetCropRect(mozilla::UniquePtr aCropRect); - void ResolveImage(nsPresContext* aContext) { - MOZ_ASSERT(mType != eStyleImageType_Image || mImage); - if (mType == eStyleImageType_Image && !mImage->IsResolved()) { - mImage->Resolve(aContext); - } - } - nsStyleImageType GetType() const { return mType; } - nsStyleImageRequest* GetImageRequest() const { + imgRequestProxy* GetImageData() const { MOZ_ASSERT(mType == eStyleImageType_Image, "Data is not an image!"); MOZ_ASSERT(mImage); + MOZ_ASSERT(mImageTracked, + "Should be tracking any image we're going to use!"); return mImage; } - imgRequestProxy* GetImageData() const { - return GetImageRequest()->get(); - } nsStyleGradient* GetGradientData() const { NS_ASSERTION(mType == eStyleImageType_Gradient, "Data is not a gradient!"); return mGradient; @@ -537,13 +434,16 @@ private: nsStyleImageType mType; union { - nsStyleImageRequest* mImage; + imgRequestProxy* mImage; nsStyleGradient* mGradient; char16_t* mElementId; }; // This is _currently_ used only in conjunction with eStyleImageType_Image. mozilla::UniquePtr mCropRect; +#ifdef DEBUG + bool mImageTracked; +#endif }; struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor @@ -553,7 +453,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor ~nsStyleColor() { MOZ_COUNT_DTOR(nsStyleColor); } - void FinishStyle(nsPresContext* aPresContext) {} nscolor CalcComplexColor(const mozilla::StyleComplexColor& aColor) const { return mozilla::LinearBlendColors(aColor.mColor, mColor, @@ -820,9 +719,16 @@ struct nsStyleImageLayers { // Initialize mRepeat and mOrigin by specified layer type void Initialize(LayerType aType); - void ResolveImage(nsPresContext* aContext) { + // Register/unregister images with the document. We do this only + // after the dust has settled in ComputeBackgroundData. + void TrackImages(nsPresContext* aContext) { if (mImage.GetType() == eStyleImageType_Image) { - mImage.ResolveImage(aContext); + mImage.TrackImage(aContext); + } + } + void UntrackImages(nsPresContext* aContext) { + if (mImage.GetType() == eStyleImageType_Image) { + mImage.UntrackImage(aContext); } } @@ -872,11 +778,15 @@ struct nsStyleImageLayers { const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; } - void ResolveImages(nsPresContext* aContext) { + void TrackImages(nsPresContext* aContext) { for (uint32_t i = 0; i < mImageCount; ++i) { - mLayers[i].ResolveImage(aContext); + mLayers[i].TrackImages(aContext); } } + void UntrackImages(nsPresContext* aContext) { + for (uint32_t i = 0; i < mImageCount; ++i) + mLayers[i].UntrackImages(aContext); + } nsChangeHint CalcDifference(const nsStyleImageLayers& aNewLayers, nsStyleImageLayers::LayerType aType) const; @@ -899,11 +809,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBackground { nsStyleBackground(const nsStyleBackground& aOther); ~nsStyleBackground(); - // Resolves and tracks the images in mImage. Only called with a Servo-backed - // style system, where those images must be resolved later than the OMT - // nsStyleBackground constructor call. - void FinishStyle(nsPresContext* aPresContext); - void* operator new(size_t sz, nsStyleBackground* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { return aContext->PresShell()-> @@ -955,7 +860,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin ~nsStyleMargin() { MOZ_COUNT_DTOR(nsStyleMargin); } - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleMargin* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -1003,7 +907,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePadding ~nsStylePadding() { MOZ_COUNT_DTOR(nsStylePadding); } - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStylePadding* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -1212,11 +1115,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder nsStyleBorder(const nsStyleBorder& aBorder); ~nsStyleBorder(); - // Resolves and tracks mBorderImageSource. Only called with a Servo-backed - // style system, where those images must be resolved later than the OMT - // nsStyleBorder constructor call. - void FinishStyle(nsPresContext* aPresContext); - void* operator new(size_t sz, nsStyleBorder* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { return aContext->PresShell()-> @@ -1319,10 +1217,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder return mBorderImageSource.IsLoaded(); } - void ResolveImage(nsPresContext* aContext) + void TrackImage(nsPresContext* aContext) { if (mBorderImageSource.GetType() == eStyleImageType_Image) { - mBorderImageSource.ResolveImage(aContext); + mBorderImageSource.TrackImage(aContext); + } + } + void UntrackImage(nsPresContext* aContext) + { + if (mBorderImageSource.GetType() == eStyleImageType_Image) { + mBorderImageSource.UntrackImage(aContext); } } @@ -1439,7 +1343,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline ~nsStyleOutline() { MOZ_COUNT_DTOR(nsStyleOutline); } - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleOutline* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -1514,8 +1417,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList nsStyleList(const nsStyleList& aStyleList); ~nsStyleList(); - void FinishStyle(nsPresContext* aPresContext); - void* operator new(size_t sz, nsStyleList* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { return aContext->PresShell()-> @@ -1545,9 +1446,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList sNoneQuotes = nullptr; } - imgRequestProxy* GetListStyleImage() const + imgRequestProxy* GetListStyleImage() const { return mListStyleImage; } + void SetListStyleImage(imgRequestProxy* aReq) { - return mListStyleImage ? mListStyleImage->get() : nullptr; + if (mListStyleImage) { + mListStyleImage->UnlockImage(); + } + mListStyleImage = aReq; + if (mListStyleImage) { + mListStyleImage->LockImage(); + } } void GetListStyleType(nsSubstring& aType) const { mCounterStyle->GetStyleName(aType); } @@ -1575,10 +1483,10 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList void SetQuotesNone(); void SetQuotes(nsStyleQuoteValues::QuotePairArray&& aValues); - uint8_t mListStylePosition; // [inherited] - RefPtr mListStyleImage; // [inherited] + uint8_t mListStylePosition; // [inherited] private: RefPtr mCounterStyle; // [inherited] + RefPtr mListStyleImage; // [inherited] RefPtr mQuotes; // [inherited] nsStyleList& operator=(const nsStyleList& aOther) = delete; public: @@ -1737,7 +1645,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition explicit nsStylePosition(StyleStructContext aContext); nsStylePosition(const nsStylePosition& aOther); ~nsStylePosition(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStylePosition* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -1974,7 +1881,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset explicit nsStyleTextReset(StyleStructContext aContext); nsStyleTextReset(const nsStyleTextReset& aOther); ~nsStyleTextReset(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleTextReset* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -2023,7 +1929,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText explicit nsStyleText(StyleStructContext aContext); nsStyleText(const nsStyleText& aOther); ~nsStyleText(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleText* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -2242,7 +2147,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility ~nsStyleVisibility() { MOZ_COUNT_DTOR(nsStyleVisibility); } - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleVisibility* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -2750,7 +2654,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay ~nsStyleDisplay() { MOZ_COUNT_DTOR(nsStyleDisplay); } - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleDisplay* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3062,7 +2965,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTable explicit nsStyleTable(StyleStructContext aContext); nsStyleTable(const nsStyleTable& aOther); ~nsStyleTable(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleTable* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3094,7 +2996,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTableBorder explicit nsStyleTableBorder(StyleStructContext aContext); nsStyleTableBorder(const nsStyleTableBorder& aOther); ~nsStyleTableBorder(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleTableBorder* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3172,8 +3073,8 @@ struct nsStyleContentData return !(*this == aOther); } - void TrackImage(mozilla::dom::ImageTracker* aImageTracker); - void UntrackImage(mozilla::dom::ImageTracker* aImageTracker); + void TrackImage(nsPresContext* aContext); + void UntrackImage(nsPresContext* aContext); void SetImage(imgRequestProxy* aRequest) { @@ -3203,7 +3104,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent explicit nsStyleContent(StyleStructContext aContext); nsStyleContent(const nsStyleContent& aContent); ~nsStyleContent(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleContent* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3286,7 +3186,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset explicit nsStyleUIReset(StyleStructContext aContext); nsStyleUIReset(const nsStyleUIReset& aOther); ~nsStyleUIReset(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleUIReset* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3359,7 +3258,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUserInterface explicit nsStyleUserInterface(StyleStructContext aContext); nsStyleUserInterface(const nsStyleUserInterface& aOther); ~nsStyleUserInterface(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleUserInterface* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3403,7 +3301,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL explicit nsStyleXUL(StyleStructContext aContext); nsStyleXUL(const nsStyleXUL& aSource); ~nsStyleXUL(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleXUL* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3443,7 +3340,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn explicit nsStyleColumn(StyleStructContext aContext); nsStyleColumn(const nsStyleColumn& aSource); ~nsStyleColumn(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleColumn* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3568,7 +3464,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG explicit nsStyleSVG(StyleStructContext aContext); nsStyleSVG(const nsStyleSVG& aSource); ~nsStyleSVG(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleSVG* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3702,7 +3597,6 @@ struct nsStyleFilter nsStyleFilter(); nsStyleFilter(const nsStyleFilter& aSource); ~nsStyleFilter(); - void FinishStyle(nsPresContext* aPresContext) {} nsStyleFilter& operator=(const nsStyleFilter& aOther); @@ -3760,11 +3654,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset nsStyleSVGReset(const nsStyleSVGReset& aSource); ~nsStyleSVGReset(); - // Resolves and tracks the images in mMask. Only called with a Servo-backed - // style system, where those images must be resolved later than the OMT - // nsStyleSVGReset constructor call. - void FinishStyle(nsPresContext* aPresContext); - void* operator new(size_t sz, nsStyleSVGReset* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { return aContext->PresShell()-> @@ -3816,7 +3705,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVariables explicit nsStyleVariables(StyleStructContext aContext); nsStyleVariables(const nsStyleVariables& aSource); ~nsStyleVariables(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleVariables* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) { @@ -3847,7 +3735,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects explicit nsStyleEffects(StyleStructContext aContext); nsStyleEffects(const nsStyleEffects& aSource); ~nsStyleEffects(); - void FinishStyle(nsPresContext* aPresContext) {} void* operator new(size_t sz, nsStyleEffects* aSelf) { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) {