| 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 const SnapshotOptions& options) const override;
59
60 private:
61 std::shared_ptr<Texture> CreateFilterTexture(
62 const ContentContext& renderer) const;
63
64 SamplerDescriptor CreateSamplerDescriptor(
65 const Capabilities& capabilities) const;
66
67 bool UsesEmulatedTileMode(const Capabilities& capabilities) const;
68
69 std::shared_ptr<Texture> texture_;
70 SamplerDescriptor sampler_descriptor_ = {};
71 Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
72 Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
73 ColorFilterProc color_filter_ = nullptr;
74
75 TiledTextureContents(const TiledTextureContents&) = delete;
76
77 TiledTextureContents& operator=(const TiledTextureContents&) = delete;
78 };
79
80 } // namespace impeller
81
82 #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:122
impeller::Contents::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
impeller::Entity
Definition: entity.h:26
impeller::Entity::TileMode
TileMode
Definition: entity.h:48
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:112
impeller::TiledTextureContents::RenderToSnapshot
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
Definition: tiled_texture_contents.cc:218
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:101
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::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:312
impeller
Definition: allocation.cc:12
impeller::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:36
sampler_descriptor.h
impeller::Contents::SnapshotOptions
Definition: contents.h:85
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:14