| 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 #pragma once
6
7 #include <functional>
8 #include <memory>
9 #include <vector>
10
11 #include "flutter/fml/macros.h"
12 #include "impeller/core/sampler_descriptor.h"
13 #include "impeller/entity/contents/color_source_contents.h"
14 #include "impeller/entity/contents/filters/color_filter_contents.h"
15 #include "impeller/entity/entity.h"
16 #include "impeller/geometry/path.h"
17 #include "impeller/renderer/capabilities.h"
18
19 namespace impeller {
20
21 class TiledTextureContents final : public ColorSourceContents {
22 public:
23 TiledTextureContents();
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
42 void SetSamplerDescriptor(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 workloadby
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 const std::string& label = "Tiled Texture Snapshot") const override;
64
65 private:
66 std::shared_ptr<Texture> CreateFilterTexture(
67 const ContentContext& renderer) const;
68
69 SamplerDescriptor CreateDescriptor(const Capabilities& capabilities) const;
70
71 bool UsesEmulatedTileMode(const Capabilities& capabilities) const;
72
73 std::shared_ptr<Texture> texture_;
74 SamplerDescriptor sampler_descriptor_ = {};
75 Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
76 Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
77 ColorFilterProc color_filter_ = nullptr;
78
79 FML_DISALLOW_COPY_AND_ASSIGN(TiledTextureContents);
80 };
81
82 } // namespace impeller
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:102
impeller::Entity::TileMode::kClamp
@ kClamp
impeller::TiledTextureContents::TiledTextureContents
TiledTextureContents()
entity.h
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:31
impeller::TiledTextureContents::SetSamplerDescriptor
void SetSamplerDescriptor(SamplerDescriptor desc)
Definition: tiled_texture_contents.cc:54
impeller::TiledTextureContents::ColorFilterProc
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
Definition: tiled_texture_contents.h:28
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:18
impeller::Entity
Definition: entity.h:21
impeller::Capabilities
Definition: capabilities.h:14
color_source_contents.h
impeller::Contents::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:37
capabilities.h
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, const std::string &label="Tiled Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, stencil depth,...
Definition: tiled_texture_contents.cc:198
color_filter_contents.h
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::TiledTextureContents::SetColorFilter
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled texture.
Definition: tiled_texture_contents.cc:58
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
sampler_descriptor.h
impeller::TiledTextureContents
Definition: tiled_texture_contents.h:21
impeller::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:113
impeller::TiledTextureContents::SetTileModes
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
Definition: tiled_texture_contents.cc:48
impeller::TiledTextureContents::~TiledTextureContents
~TiledTextureContents() override
impeller::ColorSourceContents
Definition: color_source_contents.h:33
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:344
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:44