Flutter Impeller
snapshot.cc
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 
6 
7 #include <optional>
8 
9 namespace impeller {
10 
11 std::optional<Rect> Snapshot::GetCoverage() const {
12  if (!texture) {
13  return std::nullopt;
14  }
15  return Rect::MakeSize(texture->GetSize()).TransformBounds(transform);
16 }
17 
18 std::optional<Matrix> Snapshot::GetUVTransform() const {
19  if (!texture || texture->GetSize().IsEmpty()) {
20  return std::nullopt;
21  }
22  return Matrix::MakeScale(1 / Vector2(texture->GetSize())) *
23  transform.Invert();
24 }
25 
26 std::optional<std::array<Point, 4>> Snapshot::GetCoverageUVs(
27  const Rect& coverage) const {
28  auto uv_transform = GetUVTransform();
29  if (!uv_transform.has_value()) {
30  return std::nullopt;
31  }
32  return coverage.GetTransformedPoints(uv_transform.value());
33 }
34 
35 } // namespace impeller
Point Vector2
Definition: point.h:331
Matrix Invert() const
Definition: matrix.cc:97
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
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
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
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:430
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150