Skip to content

Commit

Permalink
Bug 1279611 - Document and test the fact that SurfacePipe::WriteEmpty…
Browse files Browse the repository at this point in the history
…Row() overwrites the entire row. r=njn
  • Loading branch information
sethfowler committed Jun 17, 2016
1 parent 0b6af32 commit bf26782
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
6 changes: 4 additions & 2 deletions image/SurfacePipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ class SurfaceFilter
}

/**
* Write an empty row to the surface.
* Write an empty row to the surface. If some pixels have already been written
* to this row, they'll be discarded.
*
* @return WriteState::FINISHED if the entire surface has been written to.
* Otherwise, returns WriteState::NEED_MORE_DATA.
Expand Down Expand Up @@ -575,7 +576,8 @@ class SurfacePipe
}

/**
* Write an empty row to the surface.
* Write an empty row to the surface. If some pixels have already been written
* to this row, they'll be discarded.
*
* @see SurfaceFilter::WriteEmptyRow() for the canonical documentation.
*/
Expand Down
50 changes: 50 additions & 0 deletions image/test/gtest/TestSurfaceSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,31 @@ TEST(ImageSurfaceSink, SurfaceSinkWriteEmptyRow)

ResetForNextPass(aSink);

{
// Write a partial row before we begin calling WriteEmptyRow(). We check
// that the generated image is entirely transparent, which is to be
// expected since WriteEmptyRow() overwrites the current row even if some
// data has already been written to it.
uint32_t count = 0;
auto result = aSink->WritePixels<uint32_t>([&]() -> NextPixel<uint32_t> {
if (count == 50) {
return AsVariant(WriteState::NEED_MORE_DATA);
}
++count;
return AsVariant(BGRAColor::Green().AsPixel());
});

EXPECT_EQ(WriteState::NEED_MORE_DATA, result);
EXPECT_EQ(50u, count);
EXPECT_FALSE(aSink->IsSurfaceFinished());

CheckIterativeWrite(aDecoder, aSink, IntRect(0, 0, 0, 0), [&]{
return aSink->WriteEmptyRow();
});
}

ResetForNextPass(aSink);

{
// Create a buffer the same size as one row of the surface, containing all
// green pixels.
Expand Down Expand Up @@ -931,6 +956,31 @@ TEST(ImageSurfaceSink, PalettedSurfaceSinkWriteEmptyRow)

ResetForNextPass(aSink);

{
// Write a partial row before we begin calling WriteEmptyRow(). We check
// that the generated image is entirely 0, which is to be expected since
// WriteEmptyRow() overwrites the current row even if some data has
// already been written to it.
uint32_t count = 0;
auto result = aSink->WritePixels<uint8_t>([&]() -> NextPixel<uint8_t> {
if (count == 50) {
return AsVariant(WriteState::NEED_MORE_DATA);
}
++count;
return AsVariant(uint8_t(255));
});

EXPECT_EQ(WriteState::NEED_MORE_DATA, result);
EXPECT_EQ(50u, count);
EXPECT_FALSE(aSink->IsSurfaceFinished());

CheckPalettedIterativeWrite(aDecoder, aSink, IntRect(0, 0, 0, 0), [&]{
return aSink->WriteEmptyRow();
});
}

ResetForNextPass(aSink);

{
// Create a buffer the same size as one row of the surface, containing all
// 255 pixels.
Expand Down

0 comments on commit bf26782

Please sign in to comment.