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 
14 #include "impeller/entity/entity.h"
16 
17 namespace impeller {
18 
20  public:
22 
24 
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_ = {};
77  ColorFilterProc color_filter_ = nullptr;
78 
80 
81  TiledTextureContents& operator=(const TiledTextureContents&) = delete;
82 };
83 
84 } // namespace impeller
85 
86 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TILED_TEXTURE_CONTENTS_H_
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetSamplerDescriptor(const SamplerDescriptor &desc)
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled texture.
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
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,...
void SetTexture(std::shared_ptr< Texture > texture)
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:36
A 4x4 matrix using column-major storage.
Definition: matrix.h:37