|
7 | 7 | #include <memory> |
8 | 8 | #include <optional> |
9 | 9 | #include <unordered_map> |
| 10 | +#include <utility> |
10 | 11 | #include <vector> |
11 | 12 |
|
12 | 13 | #include "flutter/testing/testing.h" |
13 | 14 | #include "fml/logging.h" |
14 | 15 | #include "fml/time/time_point.h" |
15 | 16 | #include "gtest/gtest.h" |
| 17 | +#include "impeller/core/texture_descriptor.h" |
16 | 18 | #include "impeller/entity/contents/atlas_contents.h" |
17 | 19 | #include "impeller/entity/contents/clip_contents.h" |
18 | 20 | #include "impeller/entity/contents/conical_gradient_contents.h" |
|
42 | 44 | #include "impeller/geometry/geometry_asserts.h" |
43 | 45 | #include "impeller/geometry/path_builder.h" |
44 | 46 | #include "impeller/geometry/sigma.h" |
| 47 | +#include "impeller/geometry/vector.h" |
45 | 48 | #include "impeller/playground/playground.h" |
46 | 49 | #include "impeller/playground/widgets.h" |
47 | 50 | #include "impeller/renderer/command.h" |
@@ -2441,6 +2444,89 @@ TEST_P(EntityTest, TextContentsCeilsGlyphScaleToDecimal) { |
2441 | 2444 | ASSERT_EQ(TextFrame::RoundScaledFontSize(0.0f, 12), 0.0f); |
2442 | 2445 | } |
2443 | 2446 |
|
| 2447 | +class TestRenderTargetAllocator : public RenderTargetAllocator { |
| 2448 | + public: |
| 2449 | + explicit TestRenderTargetAllocator(std::shared_ptr<Allocator> allocator) |
| 2450 | + : RenderTargetAllocator(std::move(allocator)) {} |
| 2451 | + |
| 2452 | + ~TestRenderTargetAllocator() = default; |
| 2453 | + |
| 2454 | + std::shared_ptr<Texture> CreateTexture( |
| 2455 | + const TextureDescriptor& desc) override { |
| 2456 | + allocated_.push_back(desc); |
| 2457 | + return RenderTargetAllocator::CreateTexture(desc); |
| 2458 | + } |
| 2459 | + |
| 2460 | + void Start() override { RenderTargetAllocator::Start(); } |
| 2461 | + |
| 2462 | + void End() override { RenderTargetAllocator::End(); } |
| 2463 | + |
| 2464 | + std::vector<TextureDescriptor> GetDescriptors() const { return allocated_; } |
| 2465 | + |
| 2466 | + private: |
| 2467 | + std::vector<TextureDescriptor> allocated_; |
| 2468 | +}; |
| 2469 | + |
| 2470 | +TEST_P(EntityTest, AdvancedBlendCoverageHintIsNotResetByEntityPass) { |
| 2471 | + if (GetContext()->GetCapabilities()->SupportsFramebufferFetch()) { |
| 2472 | + GTEST_SKIP() << "Backends that support framebuffer fetch dont use coverage " |
| 2473 | + "for advanced blends."; |
| 2474 | + } |
| 2475 | + |
| 2476 | + auto contents = std::make_shared<SolidColorContents>(); |
| 2477 | + contents->SetGeometry(Geometry::MakeRect({100, 100, 100, 100})); |
| 2478 | + contents->SetColor(Color::Red()); |
| 2479 | + |
| 2480 | + Entity entity; |
| 2481 | + entity.SetTransformation(Matrix::MakeScale(Vector3(2, 2, 1))); |
| 2482 | + entity.SetBlendMode(BlendMode::kColorBurn); |
| 2483 | + entity.SetContents(contents); |
| 2484 | + |
| 2485 | + auto coverage = entity.GetCoverage(); |
| 2486 | + EXPECT_TRUE(coverage.has_value()); |
| 2487 | + |
| 2488 | + auto pass = std::make_unique<EntityPass>(); |
| 2489 | + auto test_allocator = std::make_shared<TestRenderTargetAllocator>( |
| 2490 | + GetContext()->GetResourceAllocator()); |
| 2491 | + auto stencil_config = RenderTarget::AttachmentConfig{ |
| 2492 | + .storage_mode = StorageMode::kDevicePrivate, |
| 2493 | + .load_action = LoadAction::kClear, |
| 2494 | + .store_action = StoreAction::kDontCare, |
| 2495 | + .clear_color = Color::BlackTransparent()}; |
| 2496 | + auto rt = RenderTarget::CreateOffscreen( |
| 2497 | + *GetContext(), *test_allocator, ISize::MakeWH(1000, 1000), "Offscreen", |
| 2498 | + RenderTarget::kDefaultColorAttachmentConfig, stencil_config); |
| 2499 | + auto content_context = ContentContext( |
| 2500 | + GetContext(), TypographerContextSkia::Make(), test_allocator); |
| 2501 | + pass->AddEntity(entity); |
| 2502 | + |
| 2503 | + EXPECT_TRUE(pass->Render(content_context, rt)); |
| 2504 | + |
| 2505 | + if (test_allocator->GetDescriptors().size() == 6u) { |
| 2506 | + EXPECT_EQ(test_allocator->GetDescriptors()[0].size, ISize(1000, 1000)); |
| 2507 | + EXPECT_EQ(test_allocator->GetDescriptors()[1].size, ISize(1000, 1000)); |
| 2508 | + |
| 2509 | + EXPECT_EQ(test_allocator->GetDescriptors()[2].size, ISize(200, 200)); |
| 2510 | + EXPECT_EQ(test_allocator->GetDescriptors()[3].size, ISize(200, 200)); |
| 2511 | + EXPECT_EQ(test_allocator->GetDescriptors()[4].size, ISize(200, 200)); |
| 2512 | + EXPECT_EQ(test_allocator->GetDescriptors()[5].size, ISize(200, 200)); |
| 2513 | + } else if (test_allocator->GetDescriptors().size() == 9u) { |
| 2514 | + // Onscreen render target. |
| 2515 | + EXPECT_EQ(test_allocator->GetDescriptors()[0].size, ISize(1000, 1000)); |
| 2516 | + EXPECT_EQ(test_allocator->GetDescriptors()[1].size, ISize(1000, 1000)); |
| 2517 | + EXPECT_EQ(test_allocator->GetDescriptors()[2].size, ISize(1000, 1000)); |
| 2518 | + EXPECT_EQ(test_allocator->GetDescriptors()[3].size, ISize(1000, 1000)); |
| 2519 | + EXPECT_EQ(test_allocator->GetDescriptors()[4].size, ISize(1000, 1000)); |
| 2520 | + |
| 2521 | + EXPECT_EQ(test_allocator->GetDescriptors()[5].size, ISize(200, 200)); |
| 2522 | + EXPECT_EQ(test_allocator->GetDescriptors()[5].size, ISize(200, 200)); |
| 2523 | + EXPECT_EQ(test_allocator->GetDescriptors()[6].size, ISize(200, 200)); |
| 2524 | + EXPECT_EQ(test_allocator->GetDescriptors()[7].size, ISize(200, 200)); |
| 2525 | + } else { |
| 2526 | + EXPECT_TRUE(false); |
| 2527 | + } |
| 2528 | +} |
| 2529 | + |
2444 | 2530 | } // namespace testing |
2445 | 2531 | } // namespace impeller |
2446 | 2532 |
|
|
0 commit comments