Issue #2657 - Remove -moz-samplesize resize-decoding for low-vram mobiles

Resolves #2657
This commit is contained in:
Moonchild
2024-11-20 14:10:10 +01:00
committed by roytam1
parent 75d698133f
commit ef5f052d97
18 changed files with 13 additions and 193 deletions
-1
View File
@@ -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
-8
View File
@@ -179,14 +179,6 @@ public:
*/
Maybe<gfx::IntSize> 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().)
+2 -6
View File
@@ -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<IDecodingTask>
DecoderFactory::CreateMetadataDecoder(DecoderType aType,
NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer,
int aSampleSize)
NotNull<SourceBuffer*> 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;
+2 -8
View File
@@ -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<IDecodingTask>
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<IDecodingTask>
CreateMetadataDecoder(DecoderType aType,
NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer,
int aSampleSize);
NotNull<SourceBuffer*> aSourceBuffer);
/**
* Creates and initializes a decoder for an ICO resource, which may be either
-19
View File
@@ -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<nsIChannel> chan(do_QueryInterface(aRequest));
nsCOMPtr<nsIPrincipal> 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);
+2 -4
View File
@@ -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<IDecodingTask> task =
DecoderFactory::CreateMetadataDecoder(mDecoderType, WrapNotNull(this),
mSourceBuffer, mRequestedSampleSize);
mSourceBuffer);
// Make sure DecoderFactory was able to create a decoder successfully.
if (!task) {
-8
View File
@@ -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<layers::ImageContainer> mImageContainer;
+5 -12
View File
@@ -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.
-7
View File
@@ -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
@@ -1,41 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<body>
<img id="test">
</body>
<script>
var image = new Image;
image.onload = function() {
// Create a canvas.
var canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
// Draw the image into the canvas.
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
// Convert the image into a blob URI and use it as #test's src.
canvas.toBlob(function(blob) {
var uri = window.URL.createObjectURL(blob);
uri += '#-moz-samplesize=8';
var testImage = document.getElementById('test');
testImage.onload = testImage.onerror = function() {
// Take the snapshot.
document.documentElement.removeAttribute('class');
};
testImage.src = uri;
}, 'image/jpeg', 0.99);
}
// Start loading the image.
image.src = 'image.png';
</script>
</html>
@@ -1,40 +0,0 @@
<!DOCTYPE html>
<html class="reftest-wait">
<body>
<img id="test">
</body>
<script>
var image = new Image;
image.onload = function() {
// Create a canvas.
var canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
// Draw the image into the canvas.
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
// Convert the image into a blob URI and use it as #test's src.
canvas.toBlob(function(blob) {
var uri = window.URL.createObjectURL(blob);
var testImage = document.getElementById('test');
testImage.onload = testImage.onerror = function() {
// Take the snapshot.
document.documentElement.removeAttribute('class');
};
testImage.src = uri;
}, 'image/jpeg', 0.99);
}
// Start loading the image.
image.src = 'image.png';
</script>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 840 B

-7
View File
@@ -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
-2
View File
@@ -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
-3
View File
@@ -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
-3
View File
@@ -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
+2 -18
View File
@@ -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));
}
}
}
-6
View File
@@ -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<double> mStart;
Maybe<double> mEnd;
Maybe<nsIntRect> mClip;
ClipUnit mClipUnit;
Maybe<int> mSampleSize;
};
} // namespace net