mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
f1d1e16669
- 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)
249 lines
7.0 KiB
C++
249 lines
7.0 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "Common.h"
|
|
#include "Decoder.h"
|
|
#include "DecoderFactory.h"
|
|
#include "decoders/nsBMPDecoder.h"
|
|
#include "imgIContainer.h"
|
|
#include "imgITools.h"
|
|
#include "ImageFactory.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIInputStream.h"
|
|
#include "nsIRunnable.h"
|
|
#include "nsIThread.h"
|
|
#include "mozilla/nsRefPtr.h"
|
|
#include "nsStreamUtils.h"
|
|
#include "nsString.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "ProgressTracker.h"
|
|
#include "SourceBuffer.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::gfx;
|
|
using namespace mozilla::image;
|
|
|
|
TEST(ImageDecoders, ImageModuleAvailable)
|
|
{
|
|
// We can run into problems if XPCOM modules get initialized in the wrong
|
|
// order. It's important that this test run first, both as a sanity check and
|
|
// to ensure we get the module initialization order we want.
|
|
nsCOMPtr<imgITools> imgTools =
|
|
do_CreateInstance("@mozilla.org/image/tools;1");
|
|
EXPECT_TRUE(imgTools != nullptr);
|
|
}
|
|
|
|
static void
|
|
CheckDecoderResults(const ImageTestCase& aTestCase, Decoder* aDecoder)
|
|
{
|
|
EXPECT_TRUE(aDecoder->GetDecodeDone());
|
|
EXPECT_EQ(bool(aTestCase.mFlags & TEST_CASE_HAS_ERROR),
|
|
aDecoder->HasError());
|
|
EXPECT_TRUE(!aDecoder->WasAborted());
|
|
|
|
// Verify that the decoder made the expected progress.
|
|
Progress progress = aDecoder->TakeProgress();
|
|
EXPECT_EQ(bool(aTestCase.mFlags & TEST_CASE_HAS_ERROR),
|
|
bool(progress & FLAG_HAS_ERROR));
|
|
|
|
if (aTestCase.mFlags & TEST_CASE_HAS_ERROR) {
|
|
return; // That's all we can check for bad images.
|
|
}
|
|
|
|
EXPECT_TRUE(bool(progress & FLAG_SIZE_AVAILABLE));
|
|
EXPECT_TRUE(bool(progress & FLAG_DECODE_COMPLETE));
|
|
EXPECT_TRUE(bool(progress & FLAG_FRAME_COMPLETE));
|
|
EXPECT_EQ(bool(aTestCase.mFlags & TEST_CASE_IS_TRANSPARENT),
|
|
bool(progress & FLAG_HAS_TRANSPARENCY));
|
|
EXPECT_EQ(bool(aTestCase.mFlags & TEST_CASE_IS_ANIMATED),
|
|
bool(progress & FLAG_IS_ANIMATED));
|
|
|
|
// The decoder should get the correct size.
|
|
IntSize size = aDecoder->GetSize();
|
|
EXPECT_EQ(aTestCase.mSize.width, size.width);
|
|
EXPECT_EQ(aTestCase.mSize.height, size.height);
|
|
|
|
// Get the current frame, which is always the first frame of the image
|
|
// because CreateAnonymousDecoder() forces a first-frame-only decode.
|
|
RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
|
|
nsRefPtr<SourceSurface> surface = currentFrame->GetSurface();
|
|
|
|
// Verify that the resulting surfaces matches our expectations.
|
|
EXPECT_EQ(SurfaceType::DATA, surface->GetType());
|
|
EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
|
|
surface->GetFormat() == SurfaceFormat::B8G8R8A8);
|
|
EXPECT_EQ(aTestCase.mSize, surface->GetSize());
|
|
EXPECT_TRUE(IsSolidColor(surface, BGRAColor::Green(),
|
|
aTestCase.mFlags & TEST_CASE_IS_FUZZY));
|
|
}
|
|
|
|
static void
|
|
CheckDecoderSingleChunk(const ImageTestCase& aTestCase)
|
|
{
|
|
nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
|
|
ASSERT_TRUE(inputStream != nullptr);
|
|
|
|
// Figure out how much data we have.
|
|
uint64_t length;
|
|
nsresult rv = inputStream->Available(&length);
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
// Write the data into a SourceBuffer.
|
|
nsRefPtr<SourceBuffer> sourceBuffer = new SourceBuffer();
|
|
sourceBuffer->ExpectLength(length);
|
|
rv = sourceBuffer->AppendFromInputStream(inputStream, length);
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
sourceBuffer->Complete(NS_OK);
|
|
|
|
// Create a decoder.
|
|
DecoderType decoderType =
|
|
DecoderFactory::GetDecoderType(aTestCase.mMimeType);
|
|
nsRefPtr<Decoder> decoder =
|
|
DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer,
|
|
DefaultSurfaceFlags());
|
|
ASSERT_TRUE(decoder != nullptr);
|
|
|
|
// Run the full decoder synchronously.
|
|
decoder->Decode();
|
|
|
|
CheckDecoderResults(aTestCase, decoder);
|
|
}
|
|
|
|
class NoResume : public IResumable
|
|
{
|
|
public:
|
|
NS_INLINE_DECL_REFCOUNTING(NoResume, override)
|
|
virtual void Resume() override { }
|
|
|
|
private:
|
|
~NoResume() { }
|
|
};
|
|
|
|
static void
|
|
CheckDecoderMultiChunk(const ImageTestCase& aTestCase)
|
|
{
|
|
nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
|
|
ASSERT_TRUE(inputStream != nullptr);
|
|
|
|
// Figure out how much data we have.
|
|
uint64_t length;
|
|
nsresult rv = inputStream->Available(&length);
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
// Create a SourceBuffer and a decoder.
|
|
nsRefPtr<SourceBuffer> sourceBuffer = new SourceBuffer();
|
|
sourceBuffer->ExpectLength(length);
|
|
DecoderType decoderType =
|
|
DecoderFactory::GetDecoderType(aTestCase.mMimeType);
|
|
nsRefPtr<Decoder> decoder =
|
|
DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer,
|
|
DefaultSurfaceFlags());
|
|
ASSERT_TRUE(decoder != nullptr);
|
|
|
|
// Decode synchronously, using a |NoResume| IResumable so the Decoder doesn't
|
|
// attempt to schedule itself on a nonexistent DecodePool when we write more
|
|
// data into the SourceBuffer.
|
|
nsRefPtr<NoResume> noResume = new NoResume();
|
|
for (uint64_t read = 0; read < length ; ++read) {
|
|
uint64_t available = 0;
|
|
rv = inputStream->Available(&available);
|
|
ASSERT_TRUE(available > 0);
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
rv = sourceBuffer->AppendFromInputStream(inputStream, 1);
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
decoder->Decode(noResume);
|
|
}
|
|
|
|
sourceBuffer->Complete(NS_OK);
|
|
decoder->Decode(noResume);
|
|
|
|
CheckDecoderResults(aTestCase, decoder);
|
|
}
|
|
|
|
TEST(ImageDecoders, PNGSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenPNGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, PNGMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenPNGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, GIFSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenGIFTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, GIFMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenGIFTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, JPGSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenJPGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, JPGMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenJPGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, BMPSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenBMPTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, BMPMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenBMPTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, ICOSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenICOTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, ICOMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenICOTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, AnimatedGIFSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenFirstFrameAnimatedGIFTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, AnimatedGIFMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenFirstFrameAnimatedGIFTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, AnimatedPNGSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(GreenFirstFrameAnimatedPNGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, AnimatedPNGMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(GreenFirstFrameAnimatedPNGTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, CorruptSingleChunk)
|
|
{
|
|
CheckDecoderSingleChunk(CorruptTestCase());
|
|
}
|
|
|
|
TEST(ImageDecoders, CorruptMultiChunk)
|
|
{
|
|
CheckDecoderMultiChunk(CorruptTestCase());
|
|
}
|