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  ContentContext& 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  GetParam() != PlaygroundBackend::kOpenGLESSDF) {
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  ContentContext& 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
std::shared_ptr< Context > GetContext() const
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
std::shared_ptr< RenderPass > render_pass
std::shared_ptr< PipelineGLES > pipeline
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...