Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Prev Previous commit
Next Next commit
fix texture layer death tests and enable DCHECK in TextureLayer::Paint
  • Loading branch information
flar committed Nov 13, 2020
commit c0b7c3b4861f80e8e6b62cda5dab81d7d7582b67
2 changes: 1 addition & 1 deletion flow/layers/texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void TextureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {

void TextureLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "TextureLayer::Paint");
// FML_DCHECK(needs_painting(context));
FML_DCHECK(needs_painting(context));

std::shared_ptr<Texture> texture =
context.texture_registry.GetTexture(texture_id_);
Expand Down
25 changes: 19 additions & 6 deletions flow/layers/texture_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TEST_F(TextureLayerTest, InvalidTexture) {
EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
}

#ifndef NDEBUG
TEST_F(TextureLayerTest, PaintingEmptyLayerDies) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
const SkSize layer_size = SkSize::Make(0.0f, 0.0f);
Expand All @@ -46,13 +47,25 @@ TEST_F(TextureLayerTest, PaintingEmptyLayerDies) {
EXPECT_EQ(layer->paint_bounds(), kEmptyRect);
EXPECT_FALSE(layer->needs_painting(paint_context()));

layer->Paint(paint_context());
EXPECT_EQ(mock_texture->paint_calls(),
std::vector({MockTexture::PaintCall{
mock_canvas(), layer->paint_bounds(), false, nullptr,
kNone_SkFilterQuality}}));
EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"needs_painting\\(context\\)");
}

TEST_F(TextureLayerTest, PaintBeforePreollDies) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
const int64_t texture_id = 0;
auto mock_texture = std::make_shared<MockTexture>(texture_id);
auto layer = std::make_shared<TextureLayer>(
layer_offset, layer_size, texture_id, false, kLow_SkFilterQuality);

// Ensure the texture is located by the Layer.
preroll_context()->texture_registry.RegisterTexture(mock_texture);

EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"needs_painting\\(context\\)");
}
#endif

TEST_F(TextureLayerTest, PaintingWithLowFilterQuality) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
Expand Down