From ef5f052d9739bf6b0931f1c618c2be920ea23a7a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 20 Nov 2024 14:10:10 +0100 Subject: [PATCH] Issue #2657 - Remove -moz-samplesize resize-decoding for low-vram mobiles Resolves #2657 --- gfx/thebes/gfxPrefs.h | 1 - image/Decoder.h | 8 ---- image/DecoderFactory.cpp | 8 +--- image/DecoderFactory.h | 10 +---- image/ImageFactory.cpp | 19 -------- image/RasterImage.cpp | 6 +-- image/RasterImage.h | 8 ---- image/decoders/nsJPEGDecoder.cpp | 17 +++----- image/decoders/nsJPEGDecoder.h | 7 --- .../blob/blob-uri-with-ref-param-notref.html | 41 ------------------ .../reftest/blob/blob-uri-with-ref-param.html | 40 ----------------- image/test/reftest/blob/image.png | Bin 840 -> 0 bytes image/test/reftest/blob/reftest.list | 7 --- image/test/reftest/jpeg/reftest.list | 2 - image/test/reftest/reftest.list | 3 -- modules/libpref/init/all.js | 3 -- netwerk/base/nsMediaFragmentURIParser.cpp | 20 +-------- netwerk/base/nsMediaFragmentURIParser.h | 6 --- 18 files changed, 13 insertions(+), 193 deletions(-) delete mode 100644 image/test/reftest/blob/blob-uri-with-ref-param-notref.html delete mode 100644 image/test/reftest/blob/blob-uri-with-ref-param.html delete mode 100644 image/test/reftest/blob/image.png delete mode 100644 image/test/reftest/blob/reftest.list diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index 382cc0ee20..e24e7eb037 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -446,7 +446,6 @@ private: DECL_GFX_PREF(Once, "image.mem.surfacecache.max_size_kb", ImageMemSurfaceCacheMaxSizeKB, uint32_t, 100 * 1024); DECL_GFX_PREF(Once, "image.mem.surfacecache.min_expiration_ms", ImageMemSurfaceCacheMinExpirationMS, uint32_t, 60*1000); DECL_GFX_PREF(Once, "image.mem.surfacecache.size_factor", ImageMemSurfaceCacheSizeFactor, uint32_t, 64); - DECL_GFX_PREF(Live, "image.mozsamplesize.enabled", ImageMozSampleSizeEnabled, bool, false); DECL_GFX_PREF(Once, "image.multithreaded_decoding.limit", ImageMTDecodingLimit, int32_t, -1); DECL_GFX_PREF(Live, "image.webp.enabled", ImageWebPEnabled, bool, true); #ifdef MOZ_JXL diff --git a/image/Decoder.h b/image/Decoder.h index 87dfb00508..a306cfce37 100644 --- a/image/Decoder.h +++ b/image/Decoder.h @@ -179,14 +179,6 @@ public: */ Maybe ExplicitOutputSize() const; - /** - * Set the requested sample size for this decoder. Used to implement the - * -moz-sample-size media fragment. - * - * XXX(seth): Support for -moz-sample-size will be removed in bug 1120056. - */ - virtual void SetSampleSize(int aSampleSize) { } - /** * Set an iterator to the SourceBuffer which will feed data to this decoder. * This must always be called before calling Init(). (And only before Init().) diff --git a/image/DecoderFactory.cpp b/image/DecoderFactory.cpp index 916971ba6d..d68f6bd976 100644 --- a/image/DecoderFactory.cpp +++ b/image/DecoderFactory.cpp @@ -144,8 +144,7 @@ DecoderFactory::CreateDecoder(DecoderType aType, const IntSize& aIntrinsicSize, const IntSize& aOutputSize, DecoderFlags aDecoderFlags, - SurfaceFlags aSurfaceFlags, - int aSampleSize) + SurfaceFlags aSurfaceFlags) { if (aType == DecoderType::UNKNOWN) { return nullptr; @@ -163,7 +162,6 @@ DecoderFactory::CreateDecoder(DecoderType aType, decoder->SetOutputSize(aOutputSize); decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::FIRST_FRAME_ONLY); decoder->SetSurfaceFlags(aSurfaceFlags); - decoder->SetSampleSize(aSampleSize); if (NS_FAILED(decoder->Init())) { return nullptr; @@ -275,8 +273,7 @@ DecoderFactory::CloneAnimationDecoder(Decoder* aDecoder) /* static */ already_AddRefed DecoderFactory::CreateMetadataDecoder(DecoderType aType, NotNull aImage, - NotNull aSourceBuffer, - int aSampleSize) + NotNull aSourceBuffer) { if (aType == DecoderType::UNKNOWN) { return nullptr; @@ -289,7 +286,6 @@ DecoderFactory::CreateMetadataDecoder(DecoderType aType, // Initialize the decoder. decoder->SetMetadataDecode(true); decoder->SetIterator(aSourceBuffer->Iterator()); - decoder->SetSampleSize(aSampleSize); if (NS_FAILED(decoder->Init())) { return nullptr; diff --git a/image/DecoderFactory.h b/image/DecoderFactory.h index 4267b1f809..900f69f5c4 100644 --- a/image/DecoderFactory.h +++ b/image/DecoderFactory.h @@ -66,8 +66,6 @@ public: * @param aDecoderFlags Flags specifying the behavior of this decoder. * @param aSurfaceFlags Flags specifying the type of output this decoder * should produce. - * @param aSampleSize The sample size requested using #-moz-samplesize (or 0 - * if none). */ static already_AddRefed CreateDecoder(DecoderType aType, @@ -76,8 +74,7 @@ public: const gfx::IntSize& aIntrinsicSize, const gfx::IntSize& aOutputSize, DecoderFlags aDecoderFlags, - SurfaceFlags aSurfaceFlags, - int aSampleSize); + SurfaceFlags aSurfaceFlags); /** * Creates and initializes a decoder for animated images of type @aType. @@ -124,14 +121,11 @@ public: * notifications as decoding progresses. * @param aSourceBuffer The SourceBuffer which the decoder will read its data * from. - * @param aSampleSize The sample size requested using #-moz-samplesize (or 0 - * if none). */ static already_AddRefed CreateMetadataDecoder(DecoderType aType, NotNull aImage, - NotNull aSourceBuffer, - int aSampleSize); + NotNull aSourceBuffer); /** * Creates and initializes a decoder for an ICO resource, which may be either diff --git a/image/ImageFactory.cpp b/image/ImageFactory.cpp index 343f7b582b..ccdfe5b96a 100644 --- a/image/ImageFactory.cpp +++ b/image/ImageFactory.cpp @@ -230,25 +230,6 @@ ImageFactory::CreateRasterImage(nsIRequest* aRequest, aProgressTracker->SetImage(newImage); newImage->SetProgressTracker(aProgressTracker); - nsAutoCString ref; - aURI->GetRef(ref); - net::nsMediaFragmentURIParser parser(ref); - if (parser.HasSampleSize()) { - /* Get our principal */ - nsCOMPtr chan(do_QueryInterface(aRequest)); - nsCOMPtr principal; - if (chan) { - nsContentUtils::GetSecurityManager() - ->GetChannelResultPrincipal(chan, getter_AddRefs(principal)); - } - - if ((principal && - principal->GetAppStatus() == nsIPrincipal::APP_STATUS_CERTIFIED) || - gfxPrefs::ImageMozSampleSizeEnabled()) { - newImage->SetRequestedSampleSize(parser.GetSampleSize()); - } - } - rv = newImage->Init(aMimeType.get(), aImageFlags); if (NS_FAILED(rv)) { return BadImage("RasterImage::Init failed", newImage); diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index bb591920ef..31a6d7a991 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -72,7 +72,6 @@ RasterImage::RasterImage(ImageURL* aURI /* = nullptr */) : mSize(0,0), mLockCount(0), mDecodeCount(0), - mRequestedSampleSize(0), mImageProducerID(ImageContainer::AllocateProducerID()), mLastFrameID(0), mLastImageContainerDrawResult(DrawResult::NOT_READY), @@ -1200,8 +1199,7 @@ RasterImage::Decode(const IntSize& aSize, } else { task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this), mSourceBuffer, mSize, aSize, - decoderFlags, surfaceFlags, - mRequestedSampleSize); + decoderFlags, surfaceFlags); } // Make sure DecoderFactory was able to create a decoder successfully. @@ -1228,7 +1226,7 @@ RasterImage::DecodeMetadata(uint32_t aFlags) // Create a decoder. RefPtr task = DecoderFactory::CreateMetadataDecoder(mDecoderType, WrapNotNull(this), - mSourceBuffer, mRequestedSampleSize); + mSourceBuffer); // Make sure DecoderFactory was able to create a decoder successfully. if (!task) { diff --git a/image/RasterImage.h b/image/RasterImage.h index 42af0a4887..e1a7cb1506 100644 --- a/image/RasterImage.h +++ b/image/RasterImage.h @@ -261,11 +261,6 @@ public: */ nsresult SetSourceSizeHint(uint32_t aSizeHint); - /* Provide a hint for the requested dimension of the resulting image. */ - void SetRequestedSampleSize(int requestedSampleSize) { - mRequestedSampleSize = requestedSampleSize; - } - nsCString GetURIString() { nsCString spec; if (GetURI()) { @@ -407,9 +402,6 @@ private: // data // This is currently only used for statistics int32_t mDecodeCount; - // A hint for image decoder that directly scale the image to smaller buffer - int mRequestedSampleSize; - // A weak pointer to our ImageContainer, which stays alive only as long as // the layer system needs it. WeakPtr mImageContainer; diff --git a/image/decoders/nsJPEGDecoder.cpp b/image/decoders/nsJPEGDecoder.cpp index 1ac25fc6e2..c9df02551b 100644 --- a/image/decoders/nsJPEGDecoder.cpp +++ b/image/decoders/nsJPEGDecoder.cpp @@ -76,7 +76,6 @@ nsJPEGDecoder::nsJPEGDecoder(RasterImage* aImage, SIZE_MAX), Transition::TerminateSuccess()) , mDecodeStyle(aDecodeStyle) - , mSampleSize(0) { mState = JPEG_HEADER; mReading = true; @@ -239,17 +238,8 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength) return Transition::ContinueUnbuffered(State::JPEG_DATA); // I/O suspension } - // If we have a sample size specified for -moz-sample-size, use it. - if (mSampleSize > 0) { - mInfo.scale_num = 1; - mInfo.scale_denom = mSampleSize; - } - - // Used to set up image size so arrays can be allocated - jpeg_calc_output_dimensions(&mInfo); - // Post our size to the superclass - PostSize(mInfo.output_width, mInfo.output_height, + PostSize(mInfo.image_width, mInfo.image_height, ReadOrientationFromEXIF()); if (HasError()) { // Setting the size led to an error. @@ -384,6 +374,9 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength) mInfo.buffered_image = mDecodeStyle == PROGRESSIVE && jpeg_has_multiple_scans(&mInfo); + /* Used to set up image size so arrays can be allocated */ + jpeg_calc_output_dimensions(&mInfo); + MOZ_ASSERT(!mImageData, "Already have a buffer allocated?"); nsresult rv = AllocateFrame(OutputSize(), FullOutputFrame(), SurfaceFormat::B8G8R8X8); @@ -409,7 +402,7 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength) MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug, (" JPEGDecoderAccounting: nsJPEGDecoder::" "Write -- created image frame with %ux%u pixels", - mInfo.output_width, mInfo.output_height)); + mInfo.image_width, mInfo.image_height)); mState = JPEG_START_DECOMPRESS; MOZ_FALLTHROUGH; // to start decompressing. diff --git a/image/decoders/nsJPEGDecoder.h b/image/decoders/nsJPEGDecoder.h index 25177cef91..14a4ed5646 100644 --- a/image/decoders/nsJPEGDecoder.h +++ b/image/decoders/nsJPEGDecoder.h @@ -54,11 +54,6 @@ public: DecoderType GetType() const override { return DecoderType::JPEG; } - virtual void SetSampleSize(int aSampleSize) override - { - mSampleSize = aSampleSize; - } - void NotifyDone(); protected: @@ -115,8 +110,6 @@ public: const Decoder::DecodeStyle mDecodeStyle; uint32_t mCMSMode; - - int mSampleSize; }; } // namespace image diff --git a/image/test/reftest/blob/blob-uri-with-ref-param-notref.html b/image/test/reftest/blob/blob-uri-with-ref-param-notref.html deleted file mode 100644 index 3b62a3c139..0000000000 --- a/image/test/reftest/blob/blob-uri-with-ref-param-notref.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - diff --git a/image/test/reftest/blob/blob-uri-with-ref-param.html b/image/test/reftest/blob/blob-uri-with-ref-param.html deleted file mode 100644 index 8f2e4e7cfd..0000000000 --- a/image/test/reftest/blob/blob-uri-with-ref-param.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - diff --git a/image/test/reftest/blob/image.png b/image/test/reftest/blob/image.png deleted file mode 100644 index d7d87adce09ac7655ab4de9ebbb4bc7791bdd739..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 840 zcmeAS@N?(olHy`uVBq!ia0vp^DImO~;A0Q19Vr=PJ{0vA-r9s4i zOo#>$0}L2Je49=y5uoDJo-U3d6}R5r%@sPNz~dTN@%w&ptYfaiL*wc9qfUNQ4NI5F z()5qqJuj;^C3er%T@0t!ZJv2oXN|^!r3H^Sx*7YbNVl0@&X{(KVa-+_<&#buza>gJ zFFU=|$y{vWn%tR-l$YrQ2}YNyyjEDYphI)+l;qD|>Q6NsC6`ul2L`QNS2QJj)n1LI z)3S7YZ!V4E5()Zd)H-EvglO2A27gg)=aWvS;w*AsoupI_@smjhnzyoxF`qWu<{_5LAr_&&cGsW# z8YQOIQSJY#lRReL{!pbK-PpDF&e5P==6_!6r!6vhcWJt3>0PUs$5-Pzp6xlq z8q_!Y(&D{U=I`w?AFTNw{`+3?+S;GZOT3=E)UbBfc_Di>Px@BassfLTS!-lZ^jZGP zT6k+E`)Xgc-A_*JD=fG!$0nJy{TK6h_IJ5$OaIuKdqOyF_uJx1F z?!IYQl$UyQO5hQ;F!>ey;YU9;M-^7w46$5r^;$tdZEnKMHyj&$$^<&pl=)&V$7)P^ z!dewN{bGQ@T*h0IJ=VWEAdu(1WL0gVwvNC-sXwODlO@(9uxdwmZ)BPNGbTxB|Dj1$ zd+Q|LdWvYiIX|KP>C4u)i~>KK>|FFWRyR+||QeKD$hugTe~DWM4f2qs?x diff --git a/image/test/reftest/blob/reftest.list b/image/test/reftest/blob/reftest.list deleted file mode 100644 index e795ba9d38..0000000000 --- a/image/test/reftest/blob/reftest.list +++ /dev/null @@ -1,7 +0,0 @@ -# Blob URI tests - -# Test that blob URIs don't get merged if they have different ref params. -# (We run the test twice to check both cached and non-cached cases.) -default-preferences pref(image.mozsamplesize.enabled,true) -!= blob-uri-with-ref-param.html blob-uri-with-ref-param-notref.html -!= blob-uri-with-ref-param.html blob-uri-with-ref-param-notref.html diff --git a/image/test/reftest/jpeg/reftest.list b/image/test/reftest/jpeg/reftest.list index 0eafb77e72..f48d3641aa 100644 --- a/image/test/reftest/jpeg/reftest.list +++ b/image/test/reftest/jpeg/reftest.list @@ -52,5 +52,3 @@ random-if(Android) == jpg-srgb-icc.jpg jpg-srgb-icc.png # "Here is the beginning of a boundary," and --$(boundary)-- means "All done # sending you parts.") HTTP == webcam-simulacrum.mjpg blue.jpg -pref(image.mozsamplesize.enabled,true) fuzzy(21,256) == jpg-size-32x32.jpg#-moz-samplesize=2 jpg-size-16x16.png -pref(image.mozsamplesize.enabled,true) fuzzy(92,16) == jpg-size-32x32.jpg#-moz-samplesize=8 jpg-size-4x4.png diff --git a/image/test/reftest/reftest.list b/image/test/reftest/reftest.list index 8547e50369..4658e42871 100644 --- a/image/test/reftest/reftest.list +++ b/image/test/reftest/reftest.list @@ -46,8 +46,5 @@ include color-management/reftest.list # Downscaling tests include downscaling/reftest.list -# Blob URI tests -include blob/reftest.list - # Lossless encoders skip-if(Android) include encoders-lossless/reftest.list diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 064a6be7ed..9bbb026997 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5038,9 +5038,6 @@ pref("layout.accessiblecaret.hide_carets_for_mouse_input", true); // Wakelock is disabled by default. pref("dom.wakelock.enabled", false); -// disable mozsample size for now -pref("image.mozsamplesize.enabled", false); - pref("beacon.enabled", true); // Camera prefs diff --git a/netwerk/base/nsMediaFragmentURIParser.cpp b/netwerk/base/nsMediaFragmentURIParser.cpp index b90d42fbb3..42dcd63bcf 100644 --- a/netwerk/base/nsMediaFragmentURIParser.cpp +++ b/netwerk/base/nsMediaFragmentURIParser.cpp @@ -334,19 +334,6 @@ bool nsMediaFragmentURIParser::ParseXYWH(nsDependentSubstring aString) return false; } -bool nsMediaFragmentURIParser::ParseMozSampleSize(nsDependentSubstring aString) -{ - int32_t sampleSize; - - // Read and validate coordinates. - if (ParseInteger(aString, sampleSize) && sampleSize > 0) { - mSampleSize.emplace(sampleSize); - return true; - } - - return false; -} - void nsMediaFragmentURIParser::Parse(nsACString& aRef) { // Create an array of possibly-invalid media fragments. @@ -367,9 +354,9 @@ void nsMediaFragmentURIParser::Parse(nsACString& aRef) } // Parse the media fragment values. - bool gotTemporal = false, gotSpatial = false, gotSampleSize = false; + bool gotTemporal = false, gotSpatial = false; for (int i = fragments.Length() - 1 ; i >= 0 ; --i) { - if (gotTemporal && gotSpatial && gotSampleSize) { + if (gotTemporal && gotSpatial) { // We've got one of each possible type. No need to look at the rest. break; } else if (!gotTemporal && fragments[i].first.EqualsLiteral("t")) { @@ -378,9 +365,6 @@ void nsMediaFragmentURIParser::Parse(nsACString& aRef) } else if (!gotSpatial && fragments[i].first.EqualsLiteral("xywh")) { nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i].second); gotSpatial = ParseXYWH(nsDependentSubstring(value, 0)); - } else if (!gotSampleSize && fragments[i].first.EqualsLiteral("-moz-samplesize")) { - nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i].second); - gotSampleSize = ParseMozSampleSize(nsDependentSubstring(value, 0)); } } } diff --git a/netwerk/base/nsMediaFragmentURIParser.h b/netwerk/base/nsMediaFragmentURIParser.h index fdd9f60803..a5e678b635 100644 --- a/netwerk/base/nsMediaFragmentURIParser.h +++ b/netwerk/base/nsMediaFragmentURIParser.h @@ -63,10 +63,6 @@ public: // returns the unit used. ClipUnit GetClipUnit() const { return mClipUnit; } - bool HasSampleSize() const { return mSampleSize.isSome(); } - - int GetSampleSize() const { return *mSampleSize; } - private: // Parse the URI ref provided, looking for media fragments. This is // the top-level parser the invokes the others below. @@ -88,14 +84,12 @@ private: bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute); bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond); bool ParseXYWH(nsDependentSubstring aString); - bool ParseMozSampleSize(nsDependentSubstring aString); // Media fragment information. Maybe mStart; Maybe mEnd; Maybe mClip; ClipUnit mClipUnit; - Maybe mSampleSize; }; } // namespace net