| 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/tiled_texture_contents.h"
10 #include "impeller/entity/entity_playground.h"
11 #include "impeller/playground/playground_test.h"
12 #include "third_party/googletest/googletest/include/gtest/gtest.h"
13
14 namespace impeller {
15 namespace testing {
16
17 using EntityTest = EntityPlayground;
18
19 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipeline) {
20 TextureDescriptor texture_desc;
21 texture_desc.size = {100, 100};
22 texture_desc.type = TextureType::kTexture2D;
23 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
24 texture_desc.storage_mode = StorageMode::kDevicePrivate;
25 auto texture =
26 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
27
28 TiledTextureContents contents;
29 contents.SetTexture(texture);
30 contents.SetGeometry(Geometry::MakeCover());
31
32 auto content_context = GetContentContext();
33 auto buffer = content_context->GetContext()->CreateCommandBuffer();
34 auto render_target = RenderTarget::CreateOffscreenMSAA(
35 *content_context->GetContext(),
36 *GetContentContext()->GetRenderTargetCache(), {100, 100});
37 auto render_pass = buffer->CreateRenderPass(render_target);
38
39 ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *render_pass));
40 const std::vector<Command>& commands = render_pass->GetCommands();
41
42 ASSERT_EQ(commands.size(), 1u);
43 ASSERT_STREQ(commands[0].pipeline->GetDescriptor().GetLabel().c_str(),
44 "TextureFill Pipeline V#1");
45 }
46
47 // GL_OES_EGL_image_external isn't supported on MacOS hosts.
48 #if !defined(FML_OS_MACOSX)
49 TEST_P(EntityTest, TiledTextureContentsRendersWithCorrectPipelineExternalOES) {
50 if (GetParam() != PlaygroundBackend::kOpenGLES) {
51 GTEST_SKIP_(
52 "External OES textures are only valid for the OpenGLES backend.");
53 }
54
55 TextureDescriptor texture_desc;
56 texture_desc.size = {100, 100};
57 texture_desc.type = TextureType::kTextureExternalOES;
58 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
59 texture_desc.storage_mode = StorageMode::kDevicePrivate;
60 auto texture =
61 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
62
63 TiledTextureContents contents;
64 contents.SetTexture(texture);
65 contents.SetGeometry(Geometry::MakeCover());
66
67 auto content_context = GetContentContext();
68 auto buffer = content_context->GetContext()->CreateCommandBuffer();
69 auto render_target = RenderTarget::CreateOffscreenMSAA(
70 *content_context->GetContext(),
71 *GetContentContext()->GetRenderTargetCache(), {100, 100});
72 auto render_pass = buffer->CreateRenderPass(render_target);
73
74 ASSERT_TRUE(contents.Render(*GetContentContext(), {}, *render_pass));
75 const std::vector<Command>& commands = render_pass->GetCommands();
76
77 ASSERT_EQ(commands.size(), 1u);
78 ASSERT_STREQ(commands[0].pipeline->GetDescriptor().GetLabel().c_str(),
79 "TextureFill Pipeline V#1");
80 }
81 #endif
82
83 } // namespace testing
84 } // 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:17
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
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:19
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::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:112
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::testing::TEST_P
TEST_P(AiksTest, CanRenderLinearGradientClamp)
Definition: aiks_gradient_unittests.cc:48
impeller
Definition: aiks_context.cc:10
playground_test.h
impeller::RenderTarget::CreateOffscreenMSAA
static RenderTarget CreateOffscreenMSAA(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen MSAA", AttachmentConfigMSAA color_attachment_config=kDefaultColorAttachmentConfigMSAA, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:265
impeller::Geometry::MakeCover
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:175
entity_playground.h
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:43