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