Flutter Impeller
tiled_texture_contents_unittests.cc
Go to the documentation of this file.
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 <memory>
6 
9 #include "impeller/entity/contents/test/recording_render_pass.h"
14 #include "third_party/googletest/googletest/include/gtest/gtest.h"
15 
16 namespace impeller {
17 namespace testing {
18 
20 
21 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipeline) {
22  TextureDescriptor texture_desc;
23  texture_desc.size = {100, 100};
24  texture_desc.type = TextureType::kTexture2D;
27  auto texture =
28  GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
29 
30  auto geom = Geometry::MakeCover();
31  TiledTextureContents contents(geom.get());
32  contents.SetTexture(texture);
33 
34  auto content_context = GetContentContext();
35  auto buffer = content_context->GetContext()->CreateCommandBuffer();
36  auto render_target =
37  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
38  *content_context->GetContext(), {100, 100},
39  /*mip_count=*/1);
40  auto render_pass = buffer->CreateRenderPass(render_target);
41  auto recording_pass = std::make_shared<RecordingRenderPass>(
42  render_pass, GetContext(), render_target);
43 
44  ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *recording_pass));
45  const std::vector<Command>& commands = recording_pass->GetCommands();
46 
47  ASSERT_EQ(commands.size(), 1u);
48 #ifdef IMPELLER_DEBUG
49  EXPECT_TRUE(commands[0].pipeline->GetDescriptor().GetLabel().find(
50  "TextureFill Pipeline") != std::string::npos);
51 #endif // IMPELLER_DEBUG
52  auto options = OptionsFromPassAndEntity(*recording_pass, {});
54  EXPECT_EQ(commands[0].pipeline,
55  GetContentContext()->GetTiledTexturePipeline(options));
56 
57  if (GetParam() == PlaygroundBackend::kMetal) {
58  recording_pass->EncodeCommands();
59  }
60 }
61 
62 // GL_OES_EGL_image_external isn't supported on MacOS hosts.
63 #if !defined(FML_OS_MACOSX)
64 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipelineExternalOES) {
65  if (GetParam() != PlaygroundBackend::kOpenGLES) {
66  GTEST_SKIP()
67  << "External OES textures are only valid for the OpenGLES backend.";
68  }
69 
70  TextureDescriptor texture_desc;
71  texture_desc.size = {100, 100};
75  auto texture =
76  GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
77  auto contents = TextureContents::MakeRect(Rect::MakeSize(texture->GetSize()));
78  contents->SetTexture(texture);
79  contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
80  contents->SetStrictSourceRect(false);
81 
82  auto content_context = GetContentContext();
83  auto buffer = content_context->GetContext()->CreateCommandBuffer();
84  auto render_target =
85  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
86  *content_context->GetContext(), {100, 100},
87  /*mip_count=*/1);
88  auto render_pass = buffer->CreateRenderPass(render_target);
89 
90  ASSERT_TRUE(contents->Render(*GetContentContext(), {}, *render_pass));
91  const std::vector<Command>& commands = render_pass->GetCommands();
92 
93  ASSERT_EQ(commands.size(), 1u);
94 
95  auto options = OptionsFromPassAndEntity(*render_pass, {});
97  EXPECT_EQ(commands[0].pipeline,
98  GetContentContext()->GetTiledTextureExternalPipeline(options));
99 }
100 #endif
101 
102 } // namespace testing
103 } // namespace impeller
static std::unique_ptr< Geometry > MakeCover()
Definition: geometry.cc:79
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetTexture(std::shared_ptr< Texture > texture)
TEST_P(AiksTest, DrawAtlasNoColor)
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...