Bug 1276061 (Part 2) - Remove SurfaceFilter::WriteRows(). r=njn

--HG--
extra : rebase_source : f7d65f2cb1398c49f10a5b2849672661c74f1163
This commit is contained in:
Seth Fowler 2016-06-01 23:01:50 -07:00
parent 28eebc3a4a
commit b65d22bc5c
8 changed files with 62 additions and 931 deletions

View File

@ -16,8 +16,7 @@
* Writing to the SurfacePipe is done using lambdas that act as generator
* functions. Because the SurfacePipe machinery controls where the writes take
* place, a bug in an image decoder cannot cause a buffer overflow of the
* underlying surface. In particular, when using WritePixels() a buffer overflow
* is impossible as long as the SurfacePipe code is correct.
* underlying surface.
*/
#ifndef mozilla_image_SurfacePipe_h
@ -50,8 +49,8 @@ struct SurfaceInvalidRect
};
/**
* An enum used to allow the lambdas passed to WritePixels() and WriteRows() to
* communicate their state to the caller.
* An enum used to allow the lambdas passed to WritePixels() to communicate
* their state to the caller.
*/
enum class WriteState : uint8_t
{
@ -69,16 +68,14 @@ enum class WriteState : uint8_t
/**
* A template alias used to make the return value of WritePixels() lambdas
* (which may return either a pixel value or a WriteState) easier to specify.
* WriteRows() doesn't need such a template alias since WriteRows() lambdas
* don't return a pixel value.
*/
template <typename PixelType>
using NextPixel = Variant<PixelType, WriteState>;
/**
* SurfaceFilter is the abstract superclass of SurfacePipe pipeline stages.
* It implements the the code that actually writes to the surface -
* WritePixels() and WriteRows() - which are non-virtual for efficiency.
* SurfaceFilter is the abstract superclass of SurfacePipe pipeline stages. It
* implements the the code that actually writes to the surface - WritePixels()
* and the other Write*() methods - which are non-virtual for efficiency.
*
* SurfaceFilter's API is nonpublic; only SurfacePipe and other SurfaceFilters
* should use it. Non-SurfacePipe code should use the methods on SurfacePipe.
@ -92,8 +89,8 @@ using NextPixel = Variant<PixelType, WriteState>;
* Config structs, passes the tail of the list to the next filter in the chain's
* Configure() method, and then uses the head of the list to configure itself. A
* SurfaceFilter's Configure() method must also call
* SurfaceFilter::ConfigureFilter() to provide WritePixels() and WriteRows()
* with the information they need to do their jobs.
* SurfaceFilter::ConfigureFilter() to provide the Write*() methods with the
* information they need to do their jobs.
*/
class SurfaceFilter
{
@ -121,8 +118,7 @@ public:
}
/**
* Called by WritePixels() and WriteRows() to advance this filter to the next
* row.
* Called by WritePixels() to advance this filter to the next row.
*
* @return a pointer to the buffer for the next row, or nullptr to indicate
* that we've finished the entire surface.
@ -145,9 +141,7 @@ public:
/**
* Write pixels to the surface one at a time by repeatedly calling a lambda
* that yields pixels. WritePixels() should be preferred over WriteRows()
* whenever using it will not introduce additional copies or other performance
* penalties, because it is completely memory safe.
* that yields pixels. WritePixels() is completely memory safe.
*
* Writing continues until every pixel in the surface has been written to
* (i.e., IsSurfaceFinished() returns true) or the lambda returns a WriteState
@ -213,73 +207,6 @@ public:
return WriteState::FINISHED;
}
/**
* Write rows to the surface one at a time by repeatedly calling a lambda
* that yields rows. Because WriteRows() is not completely memory safe,
* WritePixels() should be preferred whenever it can be used without
* introducing additional copies or other performance penalties.
*
* Writing continues until every row in the surface has been written to (i.e.,
* IsSurfaceFinished() returns true) or the lambda returns a WriteState which
* WriteRows() will return to the caller.
*
* The template parameter PixelType must be uint8_t (for paletted surfaces) or
* uint32_t (for BGRA/BGRX surfaces) and must be in agreement with the pixel
* size passed to ConfigureFilter().
*
* XXX(seth): We'll remove all support for paletted surfaces in bug 1247520,
* which means we can remove the PixelType template parameter from this
* method.
*
* @param aFunc A lambda that functions as a generator, yielding the next
* row in the surface each time it's called. The lambda must
* return a Maybe<WriteState> value; if Some(), the return value
* indicates a WriteState to return to the caller, while
* Nothing() indicates that the lambda can generate more rows.
*
* @return A WriteState value indicating the lambda generator's state.
* WriteRows() itself will return WriteState::FINISHED if writing
* has finished, regardless of the lambda's internal state.
*/
template <typename PixelType, typename Func>
WriteState WriteRows(Func aFunc)
{
MOZ_ASSERT(mPixelSize == 1 || mPixelSize == 4);
MOZ_ASSERT_IF(mPixelSize == 1, sizeof(PixelType) == sizeof(uint8_t));
MOZ_ASSERT_IF(mPixelSize == 4, sizeof(PixelType) == sizeof(uint32_t));
if (IsSurfaceFinished()) {
return WriteState::FINISHED; // Already done.
}
while (true) {
PixelType* rowPtr = reinterpret_cast<PixelType*>(mRowPointer);
Maybe<WriteState> result = aFunc(rowPtr, mInputSize.width);
if (result != Some(WriteState::FAILURE)) {
AdvanceRow(); // We've finished the row.
}
if (IsSurfaceFinished()) {
break;
}
if (result == Some(WriteState::FINISHED)) {
// Make sure that IsSurfaceFinished() returns true so the caller can't
// write anything else to the pipeline.
mRowPointer = nullptr;
mCol = 0;
}
if (result) {
return *result;
}
}
// We've finished the entire surface.
return WriteState::FINISHED;
}
/**
* Write a row to the surface by copying from a buffer. This is bounds checked
* and memory safe with respect to the surface, but care must still be taken
@ -604,9 +531,7 @@ public:
/**
* Write pixels to the surface one at a time by repeatedly calling a lambda
* that yields pixels. WritePixels() should be preferred over WriteRows()
* whenever using it will not introduce additional copies or other performance
* penalties, because it is completely memory safe.
* that yields pixels. WritePixels() is completely memory safe.
*
* @see SurfaceFilter::WritePixels() for the canonical documentation.
*/
@ -616,20 +541,6 @@ public:
return mHead->WritePixels<PixelType>(Forward<Func>(aFunc));
}
/**
* Write rows to the surface one at a time by repeatedly calling a lambda
* that yields rows. Because WriteRows() is not completely memory safe,
* WritePixels() should be preferred whenever it can be used without
* introducing additional copies or other performance penalties.
*
* @see SurfaceFilter::WriteRows() for the canonical documentation.
*/
template <typename PixelType, typename Func>
WriteState WriteRows(Func aFunc)
{
return mHead->WriteRows<PixelType>(Forward<Func>(aFunc));
}
/**
* Write a row to the surface by copying from a buffer. This is bounds checked
* and memory safe with respect to the surface, but care must still be taken

View File

@ -224,15 +224,14 @@ CheckGeneratedImage(Decoder* aDecoder,
BGRAColor::Transparent(), aFuzz));
}
template <typename Func> void
CheckSurfacePipeWrite(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect,
Maybe<IntRect> aInputRect,
Maybe<IntRect> aInputWriteRect,
Maybe<IntRect> aOutputWriteRect,
uint8_t aFuzz,
Func aFunc)
void
CheckWritePixels(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0 */)
{
IntRect outputRect = aOutputRect.valueOr(IntRect(0, 0, 100, 100));
IntRect inputRect = aInputRect.valueOr(IntRect(0, 0, 100, 100));
@ -241,7 +240,10 @@ CheckSurfacePipeWrite(Decoder* aDecoder,
// Fill the image.
int32_t count = 0;
auto result = aFunc(count);
auto result = aFilter->WritePixels<uint32_t>([&] {
++count;
return AsVariant(BGRAColor::Green().AsPixel());
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(inputWriteRect.width * inputWriteRect.height, count);
@ -249,7 +251,10 @@ CheckSurfacePipeWrite(Decoder* aDecoder,
// Attempt to write more data and make sure nothing changes.
const int32_t oldCount = count;
result = aFunc(count);
result = aFilter->WritePixels<uint32_t>([&] {
++count;
return AsVariant(BGRAColor::Green().AsPixel());
});
EXPECT_EQ(oldCount, count);
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_TRUE(aFilter->IsSurfaceFinished());
@ -267,58 +272,13 @@ CheckSurfacePipeWrite(Decoder* aDecoder,
}
void
CheckWritePixels(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0 */)
{
CheckSurfacePipeWrite(aDecoder, aFilter,
aOutputRect, aInputRect,
aInputWriteRect, aOutputWriteRect,
aFuzz,
[&](int32_t& aCount) {
return aFilter->WritePixels<uint32_t>([&] {
++aCount;
return AsVariant(BGRAColor::Green().AsPixel());
});
});
}
void
CheckWriteRows(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0 */)
{
CheckSurfacePipeWrite(aDecoder, aFilter,
aOutputRect, aInputRect,
aInputWriteRect, aOutputWriteRect,
aFuzz,
[&](int32_t& aCount) {
return aFilter->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
for (; aLength > 0; --aLength, ++aRow, ++aCount) {
*aRow = BGRAColor::Green().AsPixel();
}
return Nothing();
});
});
}
template <typename Func> void
CheckPalettedSurfacePipeWrite(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect,
Maybe<IntRect> aInputRect,
Maybe<IntRect> aInputWriteRect,
Maybe<IntRect> aOutputWriteRect,
uint8_t aFuzz,
Func aFunc)
CheckPalettedWritePixels(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0 */)
{
IntRect outputRect = aOutputRect.valueOr(IntRect(0, 0, 100, 100));
IntRect inputRect = aInputRect.valueOr(IntRect(0, 0, 100, 100));
@ -327,7 +287,10 @@ CheckPalettedSurfacePipeWrite(Decoder* aDecoder,
// Fill the image.
int32_t count = 0;
auto result = aFunc(count);
auto result = aFilter->WritePixels<uint8_t>([&] {
++count;
return AsVariant(uint8_t(255));
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(inputWriteRect.width * inputWriteRect.height, count);
@ -335,7 +298,10 @@ CheckPalettedSurfacePipeWrite(Decoder* aDecoder,
// Attempt to write more data and make sure nothing changes.
const int32_t oldCount = count;
result = aFunc(count);
result = aFilter->WritePixels<uint8_t>([&] {
++count;
return AsVariant(uint8_t(255));
});
EXPECT_EQ(oldCount, count);
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_TRUE(aFilter->IsSurfaceFinished());
@ -360,50 +326,6 @@ CheckPalettedSurfacePipeWrite(Decoder* aDecoder,
}
}
void
CheckPalettedWritePixels(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0 */)
{
CheckPalettedSurfacePipeWrite(aDecoder, aFilter,
aOutputRect, aInputRect,
aInputWriteRect, aOutputWriteRect,
aFuzz,
[&](int32_t& aCount) {
return aFilter->WritePixels<uint8_t>([&] {
++aCount;
return AsVariant(uint8_t(255));
});
});
}
void
CheckPalettedWriteRows(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<IntRect> aOutputRect /* = Nothing() */,
Maybe<IntRect> aInputRect /* = Nothing() */,
Maybe<IntRect> aInputWriteRect /* = Nothing() */,
Maybe<IntRect> aOutputWriteRect /* = Nothing() */,
uint8_t aFuzz /* = 0*/)
{
CheckPalettedSurfacePipeWrite(aDecoder, aFilter,
aOutputRect, aInputRect,
aInputWriteRect, aOutputWriteRect,
aFuzz,
[&](int32_t& aCount) {
return aFilter->WriteRows<uint8_t>([&](uint8_t* aRow, uint32_t aLength) {
for (; aLength > 0; --aLength, ++aRow, ++aCount) {
*aRow = uint8_t(255);
}
return Nothing();
});
});
}
///////////////////////////////////////////////////////////////////////////////
// Test Data

View File

@ -262,19 +262,6 @@ void CheckWritePixels(Decoder* aDecoder,
Maybe<gfx::IntRect> aOutputWriteRect = Nothing(),
uint8_t aFuzz = 0);
/**
* Tests the result of calling WriteRows() using the provided SurfaceFilter
* pipeline. The pipeline must be a normal (i.e., non-paletted) pipeline.
* @see CheckWritePixels() for documentation of the arguments.
*/
void CheckWriteRows(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<gfx::IntRect> aOutputRect = Nothing(),
Maybe<gfx::IntRect> aInputRect = Nothing(),
Maybe<gfx::IntRect> aInputWriteRect = Nothing(),
Maybe<gfx::IntRect> aOutputWriteRect = Nothing(),
uint8_t aFuzz = 0);
/**
* Tests the result of calling WritePixels() using the provided SurfaceFilter
* pipeline. The pipeline must be a paletted pipeline.
@ -288,19 +275,6 @@ void CheckPalettedWritePixels(Decoder* aDecoder,
Maybe<gfx::IntRect> aOutputWriteRect = Nothing(),
uint8_t aFuzz = 0);
/**
* Tests the result of calling WriteRows() using the provided SurfaceFilter
* pipeline. The pipeline must be a paletted pipeline.
* @see CheckWritePixels() for documentation of the arguments.
*/
void CheckPalettedWriteRows(Decoder* aDecoder,
SurfaceFilter* aFilter,
Maybe<gfx::IntRect> aOutputRect = Nothing(),
Maybe<gfx::IntRect> aInputRect = Nothing(),
Maybe<gfx::IntRect> aInputWriteRect = Nothing(),
Maybe<gfx::IntRect> aOutputWriteRect = Nothing(),
uint8_t aFuzz = 0);
///////////////////////////////////////////////////////////////////////////////
// Test Data

View File

@ -69,16 +69,6 @@ TEST(ImageDeinterlacingFilter, WritePixels100_100)
});
}
TEST(ImageDeinterlacingFilter, WriteRows100_100)
{
WithDeinterlacingFilter(IntSize(100, 100), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)));
});
}
TEST(ImageDeinterlacingFilter, WritePixels99_99)
{
WithDeinterlacingFilter(IntSize(99, 99), /* aProgressiveDisplay = */ true,
@ -89,16 +79,6 @@ TEST(ImageDeinterlacingFilter, WritePixels99_99)
});
}
TEST(ImageDeinterlacingFilter, WriteRows99_99)
{
WithDeinterlacingFilter(IntSize(99, 99), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 99, 99)),
/* aInputRect = */ Some(IntRect(0, 0, 99, 99)));
});
}
TEST(ImageDeinterlacingFilter, WritePixels8_8)
{
WithDeinterlacingFilter(IntSize(8, 8), /* aProgressiveDisplay = */ true,
@ -109,16 +89,6 @@ TEST(ImageDeinterlacingFilter, WritePixels8_8)
});
}
TEST(ImageDeinterlacingFilter, WriteRows8_8)
{
WithDeinterlacingFilter(IntSize(8, 8), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 8, 8)),
/* aInputRect = */ Some(IntRect(0, 0, 8, 8)));
});
}
TEST(ImageDeinterlacingFilter, WritePixels7_7)
{
WithDeinterlacingFilter(IntSize(7, 7), /* aProgressiveDisplay = */ true,
@ -129,16 +99,6 @@ TEST(ImageDeinterlacingFilter, WritePixels7_7)
});
}
TEST(ImageDeinterlacingFilter, WriteRows7_7)
{
WithDeinterlacingFilter(IntSize(7, 7), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 7, 7)),
/* aInputRect = */ Some(IntRect(0, 0, 7, 7)));
});
}
TEST(ImageDeinterlacingFilter, WritePixels3_3)
{
WithDeinterlacingFilter(IntSize(3, 3), /* aProgressiveDisplay = */ true,
@ -149,16 +109,6 @@ TEST(ImageDeinterlacingFilter, WritePixels3_3)
});
}
TEST(ImageDeinterlacingFilter, WriteRows3_3)
{
WithDeinterlacingFilter(IntSize(3, 3), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 3, 3)),
/* aInputRect = */ Some(IntRect(0, 0, 3, 3)));
});
}
TEST(ImageDeinterlacingFilter, WritePixels1_1)
{
WithDeinterlacingFilter(IntSize(1, 1), /* aProgressiveDisplay = */ true,
@ -169,16 +119,6 @@ TEST(ImageDeinterlacingFilter, WritePixels1_1)
});
}
TEST(ImageDeinterlacingFilter, WriteRows1_1)
{
WithDeinterlacingFilter(IntSize(1, 1), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 1, 1)),
/* aInputRect = */ Some(IntRect(0, 0, 1, 1)));
});
}
TEST(ImageDeinterlacingFilter, PalettedWritePixels)
{
WithPalettedDeinterlacingFilter(IntSize(100, 100),
@ -187,14 +127,6 @@ TEST(ImageDeinterlacingFilter, PalettedWritePixels)
});
}
TEST(ImageDeinterlacingFilter, PalettedWriteRows)
{
WithPalettedDeinterlacingFilter(IntSize(100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckPalettedWriteRows(aDecoder, aFilter);
});
}
TEST(ImageDeinterlacingFilter, WritePixelsNonProgressiveOutput51_52)
{
WithDeinterlacingFilter(IntSize(51, 52), /* aProgressiveDisplay = */ false,
@ -375,7 +307,7 @@ TEST(ImageDeinterlacingFilter, WritePixelsOutput20_20)
});
}
TEST(ImageDeinterlacingFilter, WriteRowsOutput7_7)
TEST(ImageDeinterlacingFilter, WritePixelsOutput7_7)
{
WithDeinterlacingFilter(IntSize(7, 7), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
@ -383,55 +315,41 @@ TEST(ImageDeinterlacingFilter, WriteRowsOutput7_7)
// rows followed by two red rows but we need to write the rows in the order
// that the deinterlacer expects them.
uint32_t count = 0;
uint32_t row = 0;
auto result = aFilter->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
uint32_t color = 0;
auto result = aFilter->WritePixels<uint32_t>([&]() {
uint32_t row = count / 7; // Integer division.
++count;
switch (row) {
// First pass. Output rows are positioned at 8n + 0.
case 0: // Output row 0.
color = BGRAColor::Green().AsPixel();
break;
return AsVariant(BGRAColor::Green().AsPixel());
// Second pass. Rows are positioned at 8n + 4.
case 1: // Output row 4.
color = BGRAColor::Green().AsPixel();
break;
return AsVariant(BGRAColor::Green().AsPixel());
// Third pass. Rows are positioned at 4n + 2.
case 2: // Output row 2.
case 3: // Output row 6.
color = BGRAColor::Red().AsPixel();
break;
return AsVariant(BGRAColor::Red().AsPixel());
// Fourth pass. Rows are positioned at 2n + 1.
case 4: // Output row 1.
color = BGRAColor::Green().AsPixel();
break;
return AsVariant(BGRAColor::Green().AsPixel());
case 5: // Output row 3.
color = BGRAColor::Red().AsPixel();
break;
return AsVariant(BGRAColor::Red().AsPixel());
case 6: // Output row 5.
color = BGRAColor::Green().AsPixel();
break;
return AsVariant(BGRAColor::Green().AsPixel());
default:
MOZ_ASSERT_UNREACHABLE("Unexpected row");
return AsVariant(BGRAColor::Transparent().AsPixel());
}
++row;
for (; aLength > 0; --aLength, ++aRow, ++count) {
*aRow = color;
}
return Nothing();
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(7u * 7u, count);
EXPECT_EQ(7u, row);
AssertCorrectPipelineFinalState(aFilter,
IntRect(0, 0, 7, 7),
@ -541,11 +459,12 @@ WriteRowAndCheckInterlacerOutput(Decoder* aDecoder,
{
uint32_t count = 0;
auto result = aFilter->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
for (; aLength > 0; --aLength, ++aRow, ++count) {
*aRow = aColor.AsPixel();
auto result = aFilter->WritePixels<uint32_t>([&]() -> NextPixel<uint32_t> {
if (count < 7) {
++count;
return AsVariant(aColor.AsPixel());
}
return Some(WriteState::NEED_MORE_DATA);
return AsVariant(WriteState::NEED_MORE_DATA);
});
EXPECT_EQ(aNextState, result);
@ -571,7 +490,7 @@ WriteRowAndCheckInterlacerOutput(Decoder* aDecoder,
}
}
TEST(ImageDeinterlacingFilter, WriteRowsIntermediateOutput7_7)
TEST(ImageDeinterlacingFilter, WritePixelsIntermediateOutput7_7)
{
WithDeinterlacingFilter(IntSize(7, 7), /* aProgressiveDisplay = */ true,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
@ -652,7 +571,7 @@ TEST(ImageDeinterlacingFilter, WriteRowsIntermediateOutput7_7)
});
}
TEST(ImageDeinterlacingFilter, WriteRowsNonProgressiveIntermediateOutput7_7)
TEST(ImageDeinterlacingFilter, WritePixelsNonProgressiveIntermediateOutput7_7)
{
WithDeinterlacingFilter(IntSize(7, 7), /* aProgressiveDisplay = */ false,
[](Decoder* aDecoder, SurfaceFilter* aFilter) {

View File

@ -56,15 +56,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to99_99)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to99_99)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(99, 99),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 99, 99)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to33_33)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(33, 33),
@ -74,15 +65,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to33_33)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to33_33)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(33, 33),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 33, 33)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to1_1)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(1, 1),
@ -92,15 +74,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to1_1)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to1_1)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(1, 1),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 1, 1)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to33_99)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(33, 99),
@ -110,15 +83,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to33_99)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to33_99)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(33, 99),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 33, 99)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to99_33)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(99, 33),
@ -128,15 +92,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to99_33)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to99_33)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(99, 33),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 99, 33)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to99_1)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(99, 1),
@ -146,15 +101,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to99_1)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to99_1)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(99, 1),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 99, 1)));
});
}
TEST(ImageDownscalingFilter, WritePixels100_100to1_99)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(1, 99),
@ -164,15 +110,6 @@ TEST(ImageDownscalingFilter, WritePixels100_100to1_99)
});
}
TEST(ImageDownscalingFilter, WriteRows100_100to1_99)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(1, 99),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 1, 99)));
});
}
TEST(ImageDownscalingFilter, DownscalingFailsFor100_100to101_101)
{
// Upscaling is disallowed.
@ -243,41 +180,6 @@ TEST(ImageDownscalingFilter, WritePixelsOutput100_100to20_20)
});
}
TEST(ImageDownscalingFilter, WriteRowsOutput100_100to20_20)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(20, 20),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Fill the image. It consists of 25 lines of green, followed by 25 lines of
// red, followed by 25 lines of green, followed by 25 more lines of red.
uint32_t count = 0;
auto result = aFilter->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
uint32_t color = (count <= 25 * 100) || (count > 50 * 100 && count <= 75 * 100)
? BGRAColor::Green().AsPixel()
: BGRAColor::Red().AsPixel();
for (; aLength > 0; --aLength, ++aRow, ++count) {
*aRow = color;
}
return Nothing();
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(100u * 100u, count);
AssertCorrectPipelineFinalState(aFilter,
IntRect(0, 0, 100, 100),
IntRect(0, 0, 20, 20));
// Check that the generated image is correct. (Note that we skip rows near
// the transitions between colors, since the downscaler does not produce a
// sharp boundary at these points.)
RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
RefPtr<SourceSurface> surface = currentFrame->GetSurface();
EXPECT_TRUE(RowsAreSolidColor(surface, 0, 4, BGRAColor::Green(), /* aFuzz = */ 2));
EXPECT_TRUE(RowsAreSolidColor(surface, 6, 3, BGRAColor::Red(), /* aFuzz = */ 3));
EXPECT_TRUE(RowsAreSolidColor(surface, 11, 3, BGRAColor::Green(), /* aFuzz = */ 3));
EXPECT_TRUE(RowsAreSolidColor(surface, 16, 4, BGRAColor::Red(), /* aFuzz = */ 3));
});
}
TEST(ImageDownscalingFilter, WritePixelsOutput100_100to10_20)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(10, 20),
@ -312,41 +214,6 @@ TEST(ImageDownscalingFilter, WritePixelsOutput100_100to10_20)
});
}
TEST(ImageDownscalingFilter, WriteRowsOutput100_100to10_20)
{
WithDownscalingFilter(IntSize(100, 100), IntSize(10, 20),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Fill the image. It consists of 25 lines of green, followed by 25 lines of
// red, followed by 25 lines of green, followed by 25 more lines of red.
uint32_t count = 0;
auto result = aFilter->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
uint32_t color = (count <= 25 * 100) || (count > 50 * 100 && count <= 75 * 100)
? BGRAColor::Green().AsPixel()
: BGRAColor::Red().AsPixel();
for (; aLength > 0; --aLength, ++aRow, ++count) {
*aRow = color;
}
return Nothing();
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(100u * 100u, count);
AssertCorrectPipelineFinalState(aFilter,
IntRect(0, 0, 100, 100),
IntRect(0, 0, 10, 20));
// Check that the generated image is correct. (Note that we skip rows near
// the transitions between colors, since the downscaler does not produce a
// sharp boundary at these points.)
RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
RefPtr<SourceSurface> surface = currentFrame->GetSurface();
EXPECT_TRUE(RowsAreSolidColor(surface, 0, 4, BGRAColor::Green(), /* aFuzz = */ 2));
EXPECT_TRUE(RowsAreSolidColor(surface, 6, 3, BGRAColor::Red(), /* aFuzz = */ 3));
EXPECT_TRUE(RowsAreSolidColor(surface, 11, 3, BGRAColor::Green(), /* aFuzz = */ 3));
EXPECT_TRUE(RowsAreSolidColor(surface, 16, 4, BGRAColor::Red(), /* aFuzz = */ 3));
});
}
TEST(ImageDownscalingFilter, ConfiguringPalettedDownscaleFails)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();

View File

@ -57,18 +57,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_0_0_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_0_0_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(0, 0, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 100, 100)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_0_0_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -82,19 +70,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_0_0_0_0)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_0_0_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(0, 0, 0, 0),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -108,19 +83,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_50_0_0)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_Minus50_50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(-50, 50, 0, 0),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_Minus50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -134,19 +96,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_Minus50_0_0)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_50_Minus50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(50, -50, 0, 0),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_150_50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -160,19 +109,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_150_50_0_0)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_150_50_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(150, 50, 0, 0),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_150_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -186,19 +122,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_150_0_0)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_50_150_0_0)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(50, 150, 0, 0),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_200_200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -215,22 +138,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_200_200_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_200_200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(200, 200, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is zero-size because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus200_25_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -247,22 +154,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus200_25_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_Minus200_25_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(-200, 25, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is zero-size because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_Minus200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -279,22 +170,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_Minus200_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_25_Minus200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(25, -200, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is zero-size because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_200_25_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -311,22 +186,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_200_25_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_200_25_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(200, 25, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is zero-size because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -343,22 +202,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_200_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_25_200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(25, 200, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is zero-size because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus200_Minus200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -372,19 +215,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus200_Minus200_100_100
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_Minus200_Minus200_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(-200, -200, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 0, 0)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 0, 0)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_Minus50_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -398,19 +228,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_Minus50_100_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_Minus50_Minus50_100_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(-50, -50, 100, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 100, 100)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 50, 50)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_25_100_50)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -424,19 +241,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_Minus50_25_100_50)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_Minus50_25_100_50)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(-50, 25, 100, 50),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 100, 50)),
/* aOutputWriteRect = */ Some(IntRect(0, 25, 50, 50)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_Minus50_50_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -450,19 +254,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_Minus50_50_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_25_Minus50_50_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(25, -50, 50, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 50, 100)),
/* aOutputWriteRect = */ Some(IntRect(25, 0, 50, 50)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_25_100_50)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -476,19 +267,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_50_25_100_50)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_50_25_100_50)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(50, 25, 100, 50),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 100, 50)),
/* aOutputWriteRect = */ Some(IntRect(50, 25, 50, 50)));
});
}
TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_50_50_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
@ -505,22 +283,6 @@ TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_25_50_50_100)
});
}
TEST(ImageRemoveFrameRectFilter, WriteRows100_100_to_25_50_50_100)
{
WithRemoveFrameRectFilter(IntSize(100, 100),
IntRect(25, 50, 50, 100),
[](Decoder* aDecoder, SurfaceFilter* aFilter) {
// Note that aInputRect is 50x50 because RemoveFrameRectFilter ignores
// trailing rows that don't show up in the output. (Leading rows
// unfortunately can't be ignored.)
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(25, 50, 50, 100)));
});
}
TEST(ImageRemoveFrameRectFilter, RemoveFrameRectFailsFor0_0_to_0_0_100_100)
{
// A zero-size image is disallowed.

View File

@ -106,24 +106,6 @@ TEST(ImageSurfacePipeIntegration, DeinterlaceDownscaleWritePixels)
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, DeinterlaceDownscaleWriteRows)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
ASSERT_TRUE(decoder != nullptr);
auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 25, 25)));
};
WithFilterPipeline(decoder, test,
DeinterlacingConfig<uint32_t> { /* mProgressiveDisplay = */ true },
DownscalingConfig { IntSize(100, 100),
SurfaceFormat::B8G8R8A8 },
SurfaceConfig { decoder, 0, IntSize(25, 25),
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, RemoveFrameRectBottomRightDownscaleWritePixels)
{
// This test case uses a frame rect that extends beyond the borders of the
@ -180,31 +162,6 @@ TEST(ImageSurfacePipeIntegration, RemoveFrameRectBottomRightDownscaleWritePixels
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, RemoveFrameRectBottomRightDownscaleWriteRows)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
ASSERT_TRUE(decoder != nullptr);
// See the WritePixels version of this test for a discussion of where the
// numbers below come from.
auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 20, 20)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(50, 50, 100, 50)),
/* aOutputWriteRect = */ Some(IntRect(10, 10, 10, 10)),
/* aFuzz = */ 0x33);
};
WithFilterPipeline(decoder, test,
RemoveFrameRectConfig { IntRect(50, 50, 100, 100) },
DownscalingConfig { IntSize(100, 100),
SurfaceFormat::B8G8R8A8 },
SurfaceConfig { decoder, 0, IntSize(20, 20),
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, RemoveFrameRectTopLeftDownscaleWritePixels)
{
// This test case uses a frame rect that extends beyond the borders of the
@ -239,29 +196,6 @@ TEST(ImageSurfacePipeIntegration, RemoveFrameRectTopLeftDownscaleWritePixels)
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, RemoveFrameRectTopLeftDownscaleWriteRows)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
ASSERT_TRUE(decoder != nullptr);
auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 20, 20)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(0, 0, 100, 100)),
/* aOutputWriteRect = */ Some(IntRect(0, 0, 10, 10)),
/* aFuzz = */ 0x21);
};
WithFilterPipeline(decoder, test,
RemoveFrameRectConfig { IntRect(-50, -50, 100, 100) },
DownscalingConfig { IntSize(100, 100),
SurfaceFormat::B8G8R8A8 },
SurfaceConfig { decoder, 0, IntSize(20, 20),
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectWritePixels)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
@ -286,30 +220,6 @@ TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectWritePixels)
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectWriteRows)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
ASSERT_TRUE(decoder != nullptr);
// Note that aInputRect is the full 100x100 size even though
// RemoveFrameRectFilter is part of this pipeline, because deinterlacing
// requires reading every row.
auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(50, 50, 100, 100)),
/* aOutputWriteRect = */ Some(IntRect(50, 50, 50, 50)));
};
WithFilterPipeline(decoder, test,
DeinterlacingConfig<uint32_t> { /* mProgressiveDisplay = */ true },
RemoveFrameRectConfig { IntRect(50, 50, 100, 100) },
SurfaceConfig { decoder, 0, IntSize(100, 100),
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectDownscaleWritePixels)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
@ -333,29 +243,6 @@ TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectDownscaleWritePixels
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectDownscaleWriteRows)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();
ASSERT_TRUE(decoder != nullptr);
auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
CheckWriteRows(aDecoder, aFilter,
/* aOutputRect = */ Some(IntRect(0, 0, 20, 20)),
/* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
/* aInputWriteRect = */ Some(IntRect(50, 50, 100, 100)),
/* aOutputWriteRect = */ Some(IntRect(10, 10, 10, 10)),
/* aFuzz = */ 33);
};
WithFilterPipeline(decoder, test,
DeinterlacingConfig<uint32_t> { /* mProgressiveDisplay = */ true },
RemoveFrameRectConfig { IntRect(50, 50, 100, 100) },
DownscalingConfig { IntSize(100, 100),
SurfaceFormat::B8G8R8A8 },
SurfaceConfig { decoder, 0, IntSize(20, 20),
SurfaceFormat::B8G8R8A8, false });
}
TEST(ImageSurfacePipeIntegration, ConfiguringPalettedRemoveFrameRectDownscaleFails)
{
RefPtr<Decoder> decoder = CreateTrivialDecoder();

View File

@ -68,12 +68,9 @@ TEST(ImageSurfaceSink, NullSurfaceSink)
Maybe<SurfaceInvalidRect> invalidRect = sink.TakeInvalidRect();
EXPECT_TRUE(invalidRect.isNothing());
result = sink.WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
result = sink.WritePixels<uint32_t>([&]() {
gotCalled = true;
for (; aLength > 0; --aLength, ++aRow) {
*aRow = BGRAColor::Green().AsPixel();
}
return Nothing();
return AsVariant(BGRAColor::Red().AsPixel());
});
EXPECT_FALSE(gotCalled);
EXPECT_EQ(WriteState::FINISHED, result);
@ -118,13 +115,6 @@ TEST(ImageSurfaceSink, SurfaceSinkWritePixels)
});
}
TEST(ImageSurfaceSink, SurfaceSinkWriteRows)
{
WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
CheckWriteRows(aDecoder, aSink);
});
}
TEST(ImageSurfaceSink, SurfaceSinkWritePixelsFinish)
{
WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
@ -155,39 +145,6 @@ TEST(ImageSurfaceSink, SurfaceSinkWritePixelsFinish)
});
}
TEST(ImageSurfaceSink, SurfaceSinkWriteRowsFinish)
{
WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
// Write nothing into the surface; just finish immediately.
uint32_t count = 0;
auto result = aSink->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
count++;
return Some(WriteState::FINISHED);
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(1u, count);
EXPECT_TRUE(aSink->IsSurfaceFinished());
// Attempt to write more and make sure that nothing gets written.
count = 0;
result = aSink->WriteRows<uint32_t>([&](uint32_t* aRow, uint32_t aLength) {
count++;
for (; aLength > 0; --aLength, ++aRow) {
*aRow = BGRAColor::Green().AsPixel();
}
return Nothing();
});
EXPECT_EQ(WriteState::FINISHED, result);
EXPECT_EQ(0u, count);
EXPECT_TRUE(aSink->IsSurfaceFinished());
// Check that the generated image is correct.
RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
RefPtr<SourceSurface> surface = currentFrame->GetSurface();
EXPECT_TRUE(IsSolidColor(surface, BGRAColor::Transparent()));
});
}
TEST(ImageSurfaceSink, SurfaceSinkProgressivePasses)
{
WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
@ -488,14 +445,6 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor0_0_100_100)
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsFor0_0_100_100)
{
WithPalettedSurfaceSink(IntRect(0, 0, 100, 100),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink);
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor25_25_50_50)
{
WithPalettedSurfaceSink(IntRect(25, 25, 50, 50),
@ -508,18 +457,6 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor25_25_50_50)
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsFor25_25_50_50)
{
WithPalettedSurfaceSink(IntRect(25, 25, 50, 50),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink,
/* aOutputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputWriteRect = */ Some(IntRect(25, 25, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(25, 25, 50, 50)));
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsForMinus25_Minus25_50_50)
{
WithPalettedSurfaceSink(IntRect(-25, -25, 50, 50),
@ -532,18 +469,6 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsForMinus25_Minus25_50_50)
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsForMinus25_Minus25_50_50)
{
WithPalettedSurfaceSink(IntRect(-25, -25, 50, 50),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink,
/* aOutputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputWriteRect = */ Some(IntRect(-25, -25, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(-25, -25, 50, 50)));
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor75_Minus25_50_50)
{
WithPalettedSurfaceSink(IntRect(75, -25, 50, 50),
@ -556,18 +481,6 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor75_Minus25_50_50)
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsFor75_Minus25_50_50)
{
WithPalettedSurfaceSink(IntRect(75, -25, 50, 50),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink,
/* aOutputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputWriteRect = */ Some(IntRect(75, -25, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(75, -25, 50, 50)));
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsForMinus25_75_50_50)
{
WithPalettedSurfaceSink(IntRect(-25, 75, 50, 50),
@ -580,18 +493,6 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsForMinus25_75_50_50)
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsForMinus25_75_50_50)
{
WithPalettedSurfaceSink(IntRect(-25, 75, 50, 50),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink,
/* aOutputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputWriteRect = */ Some(IntRect(-25, 75, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(-25, 75, 50, 50)));
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor75_75_50_50)
{
WithPalettedSurfaceSink(IntRect(75, 75, 50, 50),
@ -603,15 +504,3 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor75_75_50_50)
/* aOutputWriteRect = */ Some(IntRect(75, 75, 50, 50)));
});
}
TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteRowsFor75_75_50_50)
{
WithPalettedSurfaceSink(IntRect(75, 75, 50, 50),
[](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
CheckPalettedWriteRows(aDecoder, aSink,
/* aOutputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputRect = */ Some(IntRect(0, 0, 50, 50)),
/* aInputWriteRect = */ Some(IntRect(75, 75, 50, 50)),
/* aOutputWriteRect = */ Some(IntRect(75, 75, 50, 50)));
});
}