| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "flutter/flow/layers/texture_layer.h" |
| 6 | |
| 7 | #include "flutter/flow/testing/layer_test.h" |
| 8 | #include "flutter/flow/testing/mock_layer.h" |
| 9 | #include "flutter/flow/testing/mock_texture.h" |
| 10 | #include "flutter/fml/macros.h" |
| 11 | #include "flutter/testing/mock_canvas.h" |
| 12 | |
| 13 | namespace flutter { |
| 14 | namespace testing { |
| 15 | |
| 16 | using TextureLayerTest = LayerTest; |
| 17 | |
| 18 | TEST_F(TextureLayerTest, InvalidTexture) { |
| 19 | const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); |
| 20 | const SkSize layer_size = SkSize::Make(8.0f, 8.0f); |
| 21 | auto layer = std::make_shared<TextureLayer>(layer_offset, layer_size, 0, |
| 22 | false, kNone_SkFilterQuality); |
| 23 | |
| 24 | layer->Preroll(preroll_context(), SkMatrix()); |
| 25 | EXPECT_EQ(layer->paint_bounds(), |
| 26 | (SkRect::MakeSize(layer_size) |
| 27 | .makeOffset(layer_offset.fX, layer_offset.fY))); |
| 28 | EXPECT_TRUE(layer->needs_painting()); |
| 29 | |
| 30 | layer->Paint(paint_context()); |
| 31 | EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>()); |
| 32 | } |
| 33 | |
| 34 | TEST_F(TextureLayerTest, PaintingEmptyLayerDies) { |
| 35 | const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); |
| 36 | const SkSize layer_size = SkSize::Make(0.0f, 0.0f); |
| 37 | const int64_t texture_id = 0; |
| 38 | auto mock_texture = std::make_shared<MockTexture>(texture_id); |
| 39 | auto layer = std::make_shared<TextureLayer>( |
| 40 | layer_offset, layer_size, texture_id, false, kNone_SkFilterQuality); |
| 41 | |
| 42 | // Ensure the texture is located by the Layer. |
| 43 | preroll_context()->texture_registry.RegisterTexture(mock_texture); |
| 44 | |
| 45 | layer->Preroll(preroll_context(), SkMatrix()); |
| 46 | EXPECT_EQ(layer->paint_bounds(), kEmptyRect); |
| 47 | EXPECT_FALSE(layer->needs_painting()); |
| 48 | |
| 49 | layer->Paint(paint_context()); |
| 50 | EXPECT_EQ(mock_texture->paint_calls(), |
| 51 | std::vector({MockTexture::PaintCall{ |
| 52 | mock_canvas(), layer->paint_bounds(), false, nullptr, |
| 53 | kNone_SkFilterQuality}})); |
| 54 | EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>()); |
| 55 | } |
| 56 | |
| 57 | TEST_F(TextureLayerTest, PaintingWithLowFilterQuality) { |
| 58 | const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); |
| 59 | const SkSize layer_size = SkSize::Make(8.0f, 8.0f); |
| 60 | const int64_t texture_id = 0; |
| 61 | auto mock_texture = std::make_shared<MockTexture>(texture_id); |
| 62 | auto layer = std::make_shared<TextureLayer>( |
| 63 | layer_offset, layer_size, texture_id, false, kLow_SkFilterQuality); |
| 64 | |
| 65 | // Ensure the texture is located by the Layer. |
| 66 | preroll_context()->texture_registry.RegisterTexture(mock_texture); |
| 67 | |
| 68 | layer->Preroll(preroll_context(), SkMatrix()); |
| 69 | EXPECT_EQ(layer->paint_bounds(), |
| 70 | (SkRect::MakeSize(layer_size) |
| 71 | .makeOffset(layer_offset.fX, layer_offset.fY))); |
| 72 | EXPECT_TRUE(layer->needs_painting()); |
| 73 | |
| 74 | layer->Paint(paint_context()); |
| 75 | EXPECT_EQ(mock_texture->paint_calls(), |
| 76 | std::vector({MockTexture::PaintCall{ |
| 77 | mock_canvas(), layer->paint_bounds(), false, nullptr, |
| 78 | kLow_SkFilterQuality}})); |
| 79 | EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>()); |
| 80 | } |
| 81 | |
| 82 | } // namespace testing |
| 83 | } // namespace flutter |
| 84 | |