| Flutter Impeller |

tiled_texture_contents.h
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 #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_TILED_TEXTURE_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_TILED_TEXTURE_CONTENTS_H_
7
8 #include <functional>
9 #include <memory>
10
11 #include "impeller/core/sampler_descriptor.h"
12 #include "impeller/entity/contents/color_source_contents.h"
13 #include "impeller/entity/contents/filters/color_filter_contents.h"
14 #include "impeller/entity/entity.h"
15 #include "impeller/renderer/capabilities.h"
16
17 namespace impeller {
18
19 class TiledTextureContents final : public ColorSourceContents {
20 public:
21 TiledTextureContents();
22
23 ~TiledTextureContents() override;
24
25 using ColorFilterProc =
26 std::function<std::shared_ptr<ColorFilterContents>(FilterInput::Ref)>;
27
28 // |Contents|
29 bool IsOpaque(const Matrix& transform) const override;
30
31 // |Contents|
32 bool Render(const ContentContext& renderer,
33 const Entity& entity,
34 RenderPass& pass) const override;
35
36 void SetTexture(std::shared_ptr<Texture> texture);
37
38 void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode);
39
40 void SetSamplerDescriptor(const SamplerDescriptor& desc);
41
42 /// @brief Set a color filter to apply directly to this tiled texture
43 /// @param color_filter
44 ///
45 /// When applying a color filter to a tiled texture, we can reduce the
46 /// size and number of the subpasses required and the shader workload by
47 /// applying the filter to the untiled image and absorbing the opacity before
48 /// tiling it into the final location.
49 ///
50 /// This may not be a performance improvement if the image is tiled into a
51 /// much smaller size that its original texture size.
52 void SetColorFilter(ColorFilterProc color_filter);
53
54 // |Contents|
55 std::optional<Snapshot> RenderToSnapshot(
56 const ContentContext& renderer,
57 const Entity& entity,
58 std::optional<Rect> coverage_limit = std::nullopt,
59 const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
60 bool msaa_enabled = true,
61 int32_t mip_count = 1,
62 std::string_view label = "Tiled Texture Snapshot") const override;
63
64 private:
65 std::shared_ptr<Texture> CreateFilterTexture(
66 const ContentContext& renderer) const;
67
68 SamplerDescriptor CreateSamplerDescriptor(
69 const Capabilities& capabilities) const;
70
71 bool UsesEmulatedTileMode(const Capabilities& capabilities) const;
72
73 std::shared_ptr<Texture> texture_;
74 SamplerDescriptor sampler_descriptor_ = {};
75 Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
76 Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
77 ColorFilterProc color_filter_ = nullptr;
78
79 TiledTextureContents(const TiledTextureContents&) = delete;
80
81 TiledTextureContents& operator=(const TiledTextureContents&) = delete;
82 };
83
84 } // namespace impeller
85
86 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TILED_TEXTURE_CONTENTS_H_
capabilities.h
impeller::Capabilities
Definition: capabilities.h:14
impeller::ColorSourceContents
Definition: color_source_contents.h:38
impeller::ContentContext
Definition: content_context.h:138
impeller::Contents::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
impeller::Entity
Definition: entity.h:20
impeller::Entity::TileMode
TileMode
Definition: entity.h:42
impeller::Entity::TileMode::kClamp
@ kClamp
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::TiledTextureContents
Definition: tiled_texture_contents.h:19
impeller::TiledTextureContents::~TiledTextureContents
~TiledTextureContents() override
impeller::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:111
impeller::TiledTextureContents::TiledTextureContents
TiledTextureContents()
impeller::TiledTextureContents::IsOpaque
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
Definition: tiled_texture_contents.cc:100
impeller::TiledTextureContents::SetSamplerDescriptor
void SetSamplerDescriptor(const SamplerDescriptor &desc)
Definition: tiled_texture_contents.cc:51
impeller::TiledTextureContents::SetColorFilter
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled texture.
Definition: tiled_texture_contents.cc:55
impeller::TiledTextureContents::SetTileModes
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
Definition: tiled_texture_contents.cc:45
impeller::TiledTextureContents::RenderToSnapshot
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, std::string_view label="Tiled Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
Definition: tiled_texture_contents.cc:216
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:41
color_filter_contents.h
color_source_contents.h
entity.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller
Definition: allocation.cc:12
impeller::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:36
sampler_descriptor.h
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:14