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"
14 #include "impeller/core/texture.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.
28 
30  SamplerDescriptor("Default Snapshot Sampler",
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.
47 
48  /// Any snapshot that is scaled should re-rasterize 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.
52  // If the transform has a rotation we don't re-rasterize because we'll lose
53  // the rotation.
54  // TODO(tbd): We should re-rasterize scaled and rotated snapshots.
55  return (!transform.IsTranslationOnly() &&
58  }
59 
60  std::optional<Rect> GetCoverage() const;
61 
62  /// @brief Get the transform that converts screen space coordinates to the UV
63  /// space of this snapshot.
64  std::optional<Matrix> GetUVTransform() const;
65 
66  /// @brief Map a coverage rect to this filter input's UV space.
67  /// Result order: Top left, top right, bottom left, bottom right.
68  std::optional<std::array<Point, 4>> GetCoverageUVs(
69  const Rect& coverage) const;
70 };
71 
72 } // namespace impeller
73 
74 #endif // FLUTTER_IMPELLER_RENDERER_SNAPSHOT_H_
float Scalar
Definition: scalar.h:19
@ kNearest
The nearst mipmap level is selected.
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
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
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
Definition: matrix.h:493
Represents a texture and its intended draw transform/sampler configuration.
Definition: snapshot.h:24
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
Matrix transform
The transform that should be applied to this texture for rendering.
Definition: snapshot.h:27
std::shared_ptr< Texture > texture
Definition: snapshot.h:25
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
SamplerDescriptor sampler_descriptor
Definition: snapshot.h:29
std::optional< Rect > GetCoverage() const
Definition: snapshot.cc:11
std::optional< Matrix > GetUVTransform() const
Get the transform that converts screen space coordinates to the UV space of this snapshot.
Definition: snapshot.cc:18
bool ShouldRasterizeForRuntimeEffects() const
Definition: snapshot.h:51