import changes from `dev' branch of rmottola/Arctic-Fox:

- Bug 1188569: Drop unneeded MOZ_WARN_UNUSED_RESULT from from LookupBestMatch in SurfaceCache.cpp. r=seth (5e74e0028c)
- Bug 1192356 (Part 1) - Take advantage of mozilla::Tie() in SurfaceCache.cpp. r=dholbert (e4908c725d)
- Bug 1192356 (Part 2) - Take advantage of mozilla::Tie() in RasterImage.cpp. r=tn (1204189b73)
- Bug 1185800 - Add DecoderFlags and SurfaceFlags enum classes and use them instead of imgIContainer flags in all decoder-related code. r=tn (3abdab11f6)
- Bug 1196066 (Part 3) - Rewrite nsICODecoder to use StreamingLexer. r=tn (e2ba590c9d)
- Bug 1196066 (Part 4) - Enable the ICOMultiChunk test, which now passes. r=tn (9e02611959)
- Bug 1124084 - Flip on downscale-during-decode everywhere. r=tn (bd9deff966)
- Bug 1160801 - Treat invalid GIF disposal methods as DisposalMethod::NOT_SPECIFIED. r=jrmuizel (e26feaf8fb)
- Bug 1201796 (Part 1) - Treat ICOs with wrong widths and heights as corrupt. r=tn (322ba20808)
- Bug 1201796 (Part 2) - Add GetFrameAtSize() to support downscale-during-decode for GetFrame() use cases. r=tn (92f5d3a0a7)
- Bug 1194906 - Replace 'NS_ENSURE_TRUE(BadImage(..))' warnings with more useful messages. r=tn (cc3b368673)
- Bug 1201796 (Part 3) - Enable downscale-during-decode for imgITools::EncodeScaledImage(). r=tn (e2cdb5b520)
- Bug 1194472 - Correctly fetch compositor backend in WebGLContext. r=jgilbert (0092052dfc)
- Bug 1161913 - Part 1 - Add invalidation state for CaptureStream to Canvas and Contexts. r=mt (0377d6bbe7)
- Bug 1168075 - Fix CanvasCaptureMediaStream build fail for bluetooth2. r=pehrsons (53c67c0056)
- Bug 1176363 - Part 1: Make a raw copy of each Canvas::CaptureStream frame. r=mattwoodrow (a5df5793d6)
- Bug 1194575 - Rename RecoverFromLossOfFrames() to RecoverFromInvalidFrames() to better reflect its role. r=tn (baa6455e79)
- Bug 1146663 (Part 1) - Remove HQ scaling, which is now dead code. r=tn (efaddadea0)
- Bug 1146663 (Part 2) - Remove the concept of lifetimes from the SurfaceCache. r=dholbert (ab9862d7ee)
- Bug 1146663 (Part 3) - Make it impossible to deoptimize imgFrames. r=tn (19e2f1b370)
- Bug 1201763 - Add downscale-during-decode support for the ICON decoder. r=tn (33a2b95e5c)
- Bug 1194058 (Part 1) - Add Deinterlacer to allow Downscaler to work with interlaced images. r=tn (f7c57b7a8e)
- Bug 1194058 (Part 2) - Add downscale-during-decode support for the GIF decoder. r=tn (85622f9d55)
- Bug 1201796 (Part 4) - Add downscale-during-decode support for the ICO decoder. r=tn (d09d18b0d9)
- Bug 1146663 (Part 4) - Make all RasterImages support downscale-during-decode. r=tn (264642a895)
- Bug 1146663 (Part 5) - Require that all image decoders support downscale-during-decode. r=tn (79ad99885d)
- Bug 1206836 - When downscaling ICOs, downscale the AND mask as well. r=tn a=KWierso (08ec3d092b)
- missing bit of Bug 1138293 - Use malloc/free/realloc/calloc (eb8e5e1b9c)
- missing bit of Bug 1146663 (Part 3) - Make it impossible to deoptimize imgFrames. (233befe48f)
- Bug 1208935 - Move Deinterlacer to a standalone file. r=seth (b50322abc286)
This commit is contained in:
2022-05-18 11:52:08 +08:00
parent 00b0a024a4
commit f1d1e16669
78 changed files with 1660 additions and 1424 deletions
+33 -47
View File
@@ -19,6 +19,7 @@
#include "mozilla/Pair.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Tuple.h"
#include "nsIMemoryReporter.h"
#include "gfx2DGlue.h"
#include "gfxPattern.h" // Workaround for flaw in bug 921753 part 2.
@@ -133,17 +134,14 @@ public:
CachedSurface(imgFrame* aSurface,
const Cost aCost,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
const Lifetime aLifetime)
const SurfaceKey& aSurfaceKey)
: mSurface(aSurface)
, mCost(aCost)
, mImageKey(aImageKey)
, mSurfaceKey(aSurfaceKey)
, mLifetime(aLifetime)
{
MOZ_ASSERT(!IsPlaceholder() ||
(mCost == sPlaceholderCost && mLifetime == Lifetime::Transient),
"Placeholder should have trivial cost and transient lifetime");
MOZ_ASSERT(!IsPlaceholder() || mCost == sPlaceholderCost,
"Placeholder should have trivial cost");
MOZ_ASSERT(mImageKey, "Must have a valid image key");
}
@@ -163,7 +161,7 @@ public:
return; // Can't lock a placeholder.
}
if (aLocked && mLifetime == Lifetime::Persistent) {
if (aLocked) {
// This may fail, and that's OK. We make no guarantees about whether
// locking is successful if you call SurfaceCache::LockImage() after
// SurfaceCache::Insert().
@@ -180,7 +178,6 @@ public:
SurfaceKey GetSurfaceKey() const { return mSurfaceKey; }
CostEntry GetCostEntry() { return image::CostEntry(this, mCost); }
nsExpirationState* GetExpirationState() { return &mExpirationState; }
Lifetime GetLifetime() const { return mLifetime; }
bool IsDecoded() const
{
@@ -228,7 +225,6 @@ private:
const Cost mCost;
const ImageKey mImageKey;
const SurfaceKey mSurfaceKey;
const Lifetime mLifetime;
};
/**
@@ -257,9 +253,8 @@ public:
void Insert(const SurfaceKey& aKey, CachedSurface* aSurface)
{
MOZ_ASSERT(aSurface, "Should have a surface");
MOZ_ASSERT(!mLocked || aSurface->GetLifetime() != Lifetime::Persistent ||
aSurface->IsLocked(),
"Inserting an unlocked persistent surface for a locked image");
MOZ_ASSERT(!mLocked || aSurface->IsPlaceholder() || aSurface->IsLocked(),
"Inserting an unlocked surface for a locked image");
mSurfaces.Put(aKey, aSurface);
}
@@ -279,10 +274,9 @@ public:
return surface.forget();
}
MOZ_WARN_UNUSED_RESULT // See bug 1185044.
Pair<already_AddRefed<CachedSurface>, MatchType>
LookupBestMatch(const SurfaceKey& aSurfaceKey,
const Maybe<uint32_t>& aAlternateFlags)
const Maybe<SurfaceFlags>& aAlternateFlags)
{
// Try for an exact match first.
nsRefPtr<CachedSurface> exactMatch;
@@ -334,13 +328,13 @@ private:
struct MatchContext
{
MatchContext(const SurfaceKey& aIdealKey,
const Maybe<uint32_t>& aAlternateFlags)
const Maybe<SurfaceFlags>& aAlternateFlags)
: mIdealKey(aIdealKey)
, mAlternateFlags(aAlternateFlags)
{ }
const SurfaceKey& mIdealKey;
const Maybe<uint32_t> mAlternateFlags;
const Maybe<SurfaceFlags> mAlternateFlags;
nsRefPtr<CachedSurface> mBestMatch;
};
@@ -468,8 +462,7 @@ public:
InsertOutcome Insert(imgFrame* aSurface,
const Cost aCost,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
Lifetime aLifetime)
const SurfaceKey& aSurfaceKey)
{
// If this is a duplicate surface, refuse to replace the original.
// XXX(seth): Calling Lookup() and then RemoveSurface() does the lookup
@@ -510,12 +503,12 @@ public:
}
nsRefPtr<CachedSurface> surface =
new CachedSurface(aSurface, aCost, aImageKey, aSurfaceKey, aLifetime);
new CachedSurface(aSurface, aCost, aImageKey, aSurfaceKey);
// We require that locking succeed if the image is locked and the surface is
// persistent; the caller may need to know this to handle errors correctly.
if (cache->IsLocked() && aLifetime == Lifetime::Persistent) {
MOZ_ASSERT(!surface->IsPlaceholder(), "Placeholders should be transient");
// We require that locking succeed if the image is locked and we're not
// inserting a placeholder; the caller may need to know this to handle
// errors correctly.
if (cache->IsLocked() && !surface->IsPlaceholder()) {
surface->SetLocked(true);
if (!surface->IsLocked()) {
return InsertOutcome::FAILURE;
@@ -538,8 +531,8 @@ public:
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(imageKey);
MOZ_ASSERT(cache, "Shouldn't try to remove a surface with no image cache");
// If the surface was persistent, tell its image that we discarded it.
if (aSurface->GetLifetime() == Lifetime::Persistent) {
// If the surface was not a placeholder, tell its image that we discarded it.
if (!aSurface->IsPlaceholder()) {
static_cast<Image*>(imageKey)->OnSurfaceDiscarded();
}
@@ -640,7 +633,7 @@ public:
LookupResult LookupBestMatch(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
const Maybe<uint32_t>& aAlternateFlags)
const Maybe<SurfaceFlags>& aAlternateFlags)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache) {
@@ -658,11 +651,8 @@ public:
DrawableFrameRef ref;
MatchType matchType = MatchType::NOT_FOUND;
while (true) {
// XXX(seth): This code is begging for std::tie. See bug 1184385.
Pair<already_AddRefed<CachedSurface>, MatchType> lookupResult =
Tie(surface, matchType) =
cache->LookupBestMatch(aSurfaceKey, aAlternateFlags);
surface = lookupResult.first();
matchType = lookupResult.second();
if (!surface) {
return LookupResult(matchType); // Lookup in the per-image cache missed.
@@ -776,9 +766,8 @@ public:
void DiscardAll()
{
// Remove in order of cost because mCosts is an array and the other data
// structures are all hash tables. Note that locked surfaces (persistent
// surfaces belonging to locked images) are not removed, since they aren't
// present in mCosts.
// structures are all hash tables. Note that locked surfaces are not
// removed, since they aren't present in mCosts.
while (!mCosts.IsEmpty()) {
Remove(mCosts.LastElement().GetSurface());
}
@@ -812,8 +801,7 @@ public:
void LockSurface(CachedSurface* aSurface)
{
if (aSurface->GetLifetime() == Lifetime::Transient ||
aSurface->IsLocked()) {
if (aSurface->IsPlaceholder() || aSurface->IsLocked()) {
return;
}
@@ -836,8 +824,7 @@ public:
CachedSurface* aSurface,
void* aCache)
{
if (aSurface->GetLifetime() == Lifetime::Transient ||
!aSurface->IsLocked()) {
if (aSurface->IsPlaceholder() || !aSurface->IsLocked()) {
return PL_DHASH_NEXT;
}
@@ -912,9 +899,9 @@ private:
// This is similar to CanHold() except that it takes into account the costs of
// locked surfaces. It's used internally in Insert(), but it's not exposed
// publicly because if we start permitting multithreaded access to the surface
// cache, which seems likely, then the result would be meaningless: another
// thread could insert a persistent surface or lock an image at any time.
// publicly because we permit multithreaded access to the surface cache, which
// means that the result would be meaningless: another thread could insert a
// surface or lock an image at any time.
bool CanHoldAfterDiscarding(const Cost aCost) const
{
return aCost <= mMaxCost - mLockedCost;
@@ -1051,7 +1038,8 @@ SurfaceCache::Shutdown()
/* static */ LookupResult
SurfaceCache::Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
const Maybe<uint32_t>& aAlternateFlags /* = Nothing() */)
const Maybe<SurfaceFlags>& aAlternateFlags
/* = Nothing() */)
{
if (!sInstance) {
return LookupResult(MatchType::NOT_FOUND);
@@ -1071,7 +1059,7 @@ SurfaceCache::Lookup(const ImageKey aImageKey,
/* static */ LookupResult
SurfaceCache::LookupBestMatch(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
const Maybe<uint32_t>& aAlternateFlags
const Maybe<SurfaceFlags>& aAlternateFlags
/* = Nothing() */)
{
if (!sInstance) {
@@ -1085,8 +1073,7 @@ SurfaceCache::LookupBestMatch(const ImageKey aImageKey,
/* static */ InsertOutcome
SurfaceCache::Insert(imgFrame* aSurface,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey,
Lifetime aLifetime)
const SurfaceKey& aSurfaceKey)
{
if (!sInstance) {
return InsertOutcome::FAILURE;
@@ -1094,7 +1081,7 @@ SurfaceCache::Insert(imgFrame* aSurface,
MutexAutoLock lock(sInstance->GetMutex());
Cost cost = ComputeCost(aSurface->GetSize(), aSurface->GetBytesPerPixel());
return sInstance->Insert(aSurface, cost, aImageKey, aSurfaceKey, aLifetime);
return sInstance->Insert(aSurface, cost, aImageKey, aSurfaceKey);
}
/* static */ InsertOutcome
@@ -1106,8 +1093,7 @@ SurfaceCache::InsertPlaceholder(const ImageKey aImageKey,
}
MutexAutoLock lock(sInstance->GetMutex());
return sInstance->Insert(nullptr, sPlaceholderCost, aImageKey, aSurfaceKey,
Lifetime::Transient);
return sInstance->Insert(nullptr, sPlaceholderCost, aImageKey, aSurfaceKey);
}
/* static */ bool