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;
32  contents.SetTexture(texture);
33  contents.SetGeometry(geom.get());
34 
35  auto content_context = GetContentContext();
36  auto buffer = content_context->GetContext()->CreateCommandBuffer();
37  auto render_target =
38  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
39  *content_context->GetContext(), {100, 100},
40  /*mip_count=*/1);
41  auto render_pass = buffer->CreateRenderPass(render_target);
42  auto recording_pass = std::make_shared<RecordingRenderPass>(
43  render_pass, GetContext(), render_target);
44 
45  ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *recording_pass));
46  const std::vector<Command>& commands = recording_pass->GetCommands();
47 
48  ASSERT_EQ(commands.size(), 1u);
49 #ifdef IMPELLER_DEBUG
50  EXPECT_TRUE(commands[0].pipeline->GetDescriptor().GetLabel().find(
51  "TextureFill Pipeline") != std::string::npos);
52 #endif // IMPELLER_DEBUG
53  auto options = OptionsFromPassAndEntity(*recording_pass, {});
55  EXPECT_EQ(commands[0].pipeline,
56  GetContentContext()->GetTiledTexturePipeline(options));
57 
58  if (GetParam() == PlaygroundBackend::kMetal) {
59  recording_pass->EncodeCommands();
60  }
61 }
62 
63 // GL_OES_EGL_image_external isn't supported on MacOS hosts.
64 #if !defined(FML_OS_MACOSX)
65 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipelineExternalOES) {
66  if (GetParam() != PlaygroundBackend::kOpenGLES) {
67  GTEST_SKIP()
68  << "External OES textures are only valid for the OpenGLES backend.";
69  }
70 
71  TextureDescriptor texture_desc;
72  texture_desc.size = {100, 100};
76  auto texture =
77  GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
78  auto contents = TextureContents::MakeRect(Rect::MakeSize(texture->GetSize()));
79  contents->SetTexture(texture);
80  contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
81  contents->SetStrictSourceRect(false);
82 
83  auto content_context = GetContentContext();
84  auto buffer = content_context->GetContext()->CreateCommandBuffer();
85  auto render_target =
86  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
87  *content_context->GetContext(), {100, 100},
88  /*mip_count=*/1);
89  auto render_pass = buffer->CreateRenderPass(render_target);
90 
91  ASSERT_TRUE(contents->Render(*GetContentContext(), {}, *render_pass));
92  const std::vector<Command>& commands = render_pass->GetCommands();
93 
94  ASSERT_EQ(commands.size(), 1u);
95 
96  auto options = OptionsFromPassAndEntity(*render_pass, {});
98  EXPECT_EQ(commands[0].pipeline,
99  GetContentContext()->GetTiledTextureExternalPipeline(options));
100 }
101 #endif
102 
103 } // namespace testing
104 } // namespace impeller
void SetGeometry(const Geometry *geometry)
Set the geometry that this contents will use to render.
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...