| 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
7 #include "impeller/core/formats.h"
8 #include "impeller/core/texture_descriptor.h"
9 #include "impeller/entity/contents/test/recording_render_pass.h"
10 #include "impeller/entity/contents/tiled_texture_contents.h"
11 #include "impeller/entity/entity_playground.h"
12 #include "impeller/playground/playground_test.h"
13 #include "third_party/googletest/googletest/include/gtest/gtest.h"
14
15 namespace impeller {
16 namespace testing {
17
18 using EntityTest = EntityPlayground;
19
20 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipeline) {
21 TextureDescriptor texture_desc;
22 texture_desc.size = {100, 100};
23 texture_desc.type = TextureType::kTexture2D;
24 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
25 texture_desc.storage_mode = StorageMode::kDevicePrivate;
26 auto texture =
27 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
28
29 TiledTextureContents contents;
30 contents.SetTexture(texture);
31 contents.SetGeometry(Geometry::MakeCover());
32
33 auto content_context = GetContentContext();
34 auto buffer = content_context->GetContext()->CreateCommandBuffer();
35 auto render_target =
36 GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
37 *content_context->GetContext(), {100, 100},
38 /*mip_count=*/1);
39 auto render_pass = buffer->CreateRenderPass(render_target);
40 auto recording_pass = std::make_shared<RecordingRenderPass>(
41 render_pass, GetContext(), render_target);
42
43 ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *recording_pass));
44 const std::vector<Command>& commands = recording_pass->GetCommands();
45
46 ASSERT_EQ(commands.size(), 1u);
47 EXPECT_TRUE(commands[0].pipeline->GetDescriptor().GetLabel().find(
48 "TextureFill Pipeline") != std::string::npos);
49
50 if (GetParam() == PlaygroundBackend::kMetal) {
51 recording_pass->EncodeCommands();
52 }
53 }
54
55 // GL_OES_EGL_image_external isn't supported on MacOS hosts.
56 #if !defined(FML_OS_MACOSX)
57 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipelineExternalOES) {
58 if (GetParam() != PlaygroundBackend::kOpenGLES) {
59 GTEST_SKIP_(
60 "External OES textures are only valid for the OpenGLES backend.");
61 }
62
63 TextureDescriptor texture_desc;
64 texture_desc.size = {100, 100};
65 texture_desc.type = TextureType::kTextureExternalOES;
66 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
67 texture_desc.storage_mode = StorageMode::kDevicePrivate;
68 auto texture =
69 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
70
71 TiledTextureContents contents;
72 contents.SetTexture(texture);
73 contents.SetGeometry(Geometry::MakeCover());
74
75 auto content_context = GetContentContext();
76 auto buffer = content_context->GetContext()->CreateCommandBuffer();
77 auto render_target =
78 GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
79 *content_context->GetContext(), {100, 100},
80 /*mip_count=*/1);
81 auto render_pass = buffer->CreateRenderPass(render_target);
82
83 ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *render_pass));
84 const std::vector<Command>& commands = render_pass->GetCommands();
85
86 ASSERT_EQ(commands.size(), 1u);
87 EXPECT_TRUE(commands[0].pipeline->GetDescriptor().GetLabel().find(
88 "TiledTextureFillExternal Pipeline") != std::string::npos);
89 }
90 #endif
91
92 } // namespace testing
93 } // namespace impeller
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::ColorSourceContents::SetGeometry
void SetGeometry(std::shared_ptr< Geometry > geometry)
Set the geometry that this contents will use to render.
Definition: color_source_contents.cc:16
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
texture_descriptor.h
formats.h
tiled_texture_contents.h
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:39
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::testing::EntityTest
EntityPlayground EntityTest
Definition: checkerboard_contents_unittests.cc:20
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
impeller::EntityPlayground
Definition: entity_playground.h:18
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::TiledTextureContents
Definition: tiled_texture_contents.h:22
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderMaskBlurHugeSigma)
Definition: aiks_blur_unittests.cc:23
impeller::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:111
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:38
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
impeller
Definition: aiks_blur_unittests.cc:20
playground_test.h
impeller::Geometry::MakeCover
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:200
entity_playground.h
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:41