| Flutter Impeller |

snapshot.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_RENDERER_SNAPSHOT_H_
6 #define FLUTTER_IMPELLER_RENDERER_SNAPSHOT_H_
7
8 #include <functional>
9 #include <memory>
10 #include <vector>
11
12 #include "impeller/core/formats.h"
13 #include "impeller/core/sampler_descriptor.h"
14 #include "impeller/core/texture.h"
15 #include "impeller/geometry/matrix.h"
16 #include "impeller/geometry/rect.h"
17
18 namespace impeller {
19
20 class ContentContext;
21 class Entity;
22
23 /// Represents a texture and its intended draw transform/sampler configuration.
24 struct Snapshot {
25 std::shared_ptr<Texture> texture;
26 /// The transform that should be applied to this texture for rendering.
27 Matrix transform;
28
29 SamplerDescriptor sampler_descriptor =
30 SamplerDescriptor("Default Snapshot Sampler",
31 MinMagFilter::kLinear,
32 MinMagFilter::kLinear,
33 MipFilter::kNearest);
34
35 Scalar opacity = 1.0f;
36
37 /// @brief Whether this snapshot needs to be re-rasterized when used as an
38 /// input to a runtime effect.
39 /// @details This is required because there is no good heuristic to determine
40 /// if a `Snapshot` needs to be rerasterized before applying a RuntimeFilter.
41 /// In particular the GaussianBlurContents will return a Snapshot that
42 /// includes padding for the blur halo which is not possible for the
43 /// RuntimeEffectContents to know about. This value will tell
44 /// RuntimeEffectContents that the Snapshot will have to be rerasterized to
45 /// capture the padding.
46 bool needs_rasterization_for_runtime_effects = false;
47
48 /// Any snapshot that is scaled should rerasterize because we should be
49 /// performing the RuntimeEffect at the resolution of the screen, not the
50 /// scaled up or scaled down version of the snapshot.
51 bool ShouldRasterizeForRuntimeEffects() const {
52 return !transform.IsTranslationOnly() ||
53 needs_rasterization_for_runtime_effects;
54 }
55
56 std::optional<Rect> GetCoverage() const;
57
58 /// @brief Get the transform that converts screen space coordinates to the UV
59 /// space of this snapshot.
60 std::optional<Matrix> GetUVTransform() const;
61
62 /// @brief Map a coverage rect to this filter input's UV space.
63 /// Result order: Top left, top right, bottom left, bottom right.
64 std::optional<std::array<Point, 4>> GetCoverageUVs(
65 const Rect& coverage) const;
66 };
67
68 } // namespace impeller
69
70 #endif // FLUTTER_IMPELLER_RENDERER_SNAPSHOT_H_
formats.h
texture.h
matrix.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::MipFilter::kNearest
@ kNearest
The nearst mipmap level is selected.
impeller::MinMagFilter::kLinear
@ kLinear
rect.h
sampler_descriptor.h
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Matrix::IsTranslationOnly
constexpr bool IsTranslationOnly() const
Returns true if the matrix has no entries other than translation components. Note that an identity ma...
Definition: matrix.h:480
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:14
impeller::Snapshot
Represents a texture and its intended draw transform/sampler configuration.
Definition: snapshot.h:24
impeller::Snapshot::needs_rasterization_for_runtime_effects
bool needs_rasterization_for_runtime_effects
Whether this snapshot needs to be re-rasterized when used as an input to a runtime effect.
Definition: snapshot.h:46
impeller::Snapshot::transform
Matrix transform
The transform that should be applied to this texture for rendering.
Definition: snapshot.h:27
impeller::Snapshot::texture
std::shared_ptr< Texture > texture
Definition: snapshot.h:25
impeller::Snapshot::GetCoverageUVs
std::optional< std::array< Point, 4 > > GetCoverageUVs(const Rect &coverage) const
Map a coverage rect to this filter input's UV space. Result order: Top left, top right,...
Definition: snapshot.cc:26
impeller::Snapshot::sampler_descriptor
SamplerDescriptor sampler_descriptor
Definition: snapshot.h:29
impeller::Snapshot::GetCoverage
std::optional< Rect > GetCoverage() const
Definition: snapshot.cc:11
impeller::Snapshot::opacity
Scalar opacity
Definition: snapshot.h:35
impeller::Snapshot::GetUVTransform
std::optional< Matrix > GetUVTransform() const
Get the transform that converts screen space coordinates to the UV space of this snapshot.
Definition: snapshot.cc:18
impeller::Snapshot::ShouldRasterizeForRuntimeEffects
bool ShouldRasterizeForRuntimeEffects() const
Definition: snapshot.h:51
impeller::TRect< Scalar >