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  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_ = {};
73  ColorFilterProc color_filter_ = nullptr;
74 
76 
77  TiledTextureContents& operator=(const TiledTextureContents&) = delete;
78 };
79 
80 } // namespace impeller
81 
82 #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
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,...
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)
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