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:
21  explicit TiledTextureContents(const Geometry* geometry);
22 
24 
25  const Geometry* GetGeometry() const override;
26 
28  std::function<std::shared_ptr<ColorFilterContents>(FilterInput::Ref)>;
29 
30  // |Contents|
31  bool IsOpaque(const Matrix& transform) 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 
42  void SetSamplerDescriptor(const SamplerDescriptor& desc);
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  const SnapshotOptions& options) const override;
61 
62  private:
63  std::shared_ptr<Texture> CreateFilterTexture(
64  const ContentContext& renderer) const;
65 
66  SamplerDescriptor CreateSamplerDescriptor(
67  const Capabilities& capabilities) const;
68 
69  bool UsesEmulatedTileMode(const Capabilities& capabilities) const;
70 
71  const Geometry* geometry_ = nullptr;
72  std::shared_ptr<Texture> texture_;
73  SamplerDescriptor sampler_descriptor_ = {};
76  ColorFilterProc color_filter_ = nullptr;
77 
79 
80  TiledTextureContents& operator=(const TiledTextureContents&) = delete;
81 };
82 
83 } // namespace impeller
84 
85 #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
TiledTextureContents(const Geometry *geometry)
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)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
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