| 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 const std::string& label = "Tiled Texture Snapshot") const override;
65
66 private:
67 std::shared_ptr<Texture> CreateFilterTexture(
68 const ContentContext& renderer) const;
69
70 SamplerDescriptor CreateSamplerDescriptor(
71 const Capabilities& capabilities) const;
72
73 bool UsesEmulatedTileMode(const Capabilities& capabilities) const;
74
75 std::shared_ptr<Texture> texture_;
76 SamplerDescriptor sampler_descriptor_ = {};
77 Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
78 Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
79 ColorFilterProc color_filter_ = nullptr;
80
81 TiledTextureContents(const TiledTextureContents&) = delete;
82
83 TiledTextureContents& operator=(const TiledTextureContents&) = delete;
84 };
85
86 } // namespace impeller
87
88 #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:101
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:53
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
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, 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:234
color_filter_contents.h
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::TiledTextureContents::SetColorFilter
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled texture.
Definition: tiled_texture_contents.cc:57
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
sampler_descriptor.h
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::TiledTextureContents::SetTileModes
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
Definition: tiled_texture_contents.cc:47
impeller::TiledTextureContents::~TiledTextureContents
~TiledTextureContents() override
impeller::ColorSourceContents
Definition: color_source_contents.h:34
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:43