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 
15 #include "impeller/entity/entity.h"
16 #include "impeller/geometry/path.h"
18 
19 namespace impeller {
20 
22  public:
24 
25  ~TiledTextureContents() override;
26 
27  using ColorFilterProc =
28  std::function<std::shared_ptr<ColorFilterContents>(FilterInput::Ref)>;
29 
30  // |Contents|
31  bool IsOpaque() const override;
32 
33  // |Contents|
34  bool Render(const ContentContext& renderer,
35  const Entity& entity,
36  RenderPass& pass) const override;
37 
38  void SetTexture(std::shared_ptr<Texture> texture);
39 
40  void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode);
41 
43 
44  /// @brief Set a color filter to apply directly to this tiled texture
45  /// @param color_filter
46  ///
47  /// When applying a color filter to a tiled texture, we can reduce the
48  /// size and number of the subpasses required and the shader workload by
49  /// applying the filter to the untiled image and absorbing the opacity before
50  /// tiling it into the final location.
51  ///
52  /// This may not be a performance improvement if the image is tiled into a
53  /// much smaller size that its original texture size.
54  void SetColorFilter(ColorFilterProc color_filter);
55 
56  // |Contents|
57  std::optional<Snapshot> RenderToSnapshot(
58  const ContentContext& renderer,
59  const Entity& entity,
60  std::optional<Rect> coverage_limit = std::nullopt,
61  const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
62  bool msaa_enabled = true,
63  int32_t mip_count = 1,
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_ = {};
79  ColorFilterProc color_filter_ = nullptr;
80 
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:99
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:50
impeller::TiledTextureContents::ColorFilterProc
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
Definition: tiled_texture_contents.h:28
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::Entity
Definition: entity.h:20
impeller::Capabilities
Definition: capabilities.h:14
color_source_contents.h
impeller::Contents::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
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:54
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:21
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:213
impeller::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:110
impeller::TiledTextureContents::SetTileModes
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
Definition: tiled_texture_contents.cc:44
impeller::TiledTextureContents::~TiledTextureContents
~TiledTextureContents() override
impeller::ColorSourceContents
Definition: color_source_contents.h:37
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ContentContext
Definition: content_context.h:366
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:40