Flutter Impeller
rect_geometry.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 namespace impeller {
8 
9 RectGeometry::RectGeometry(Rect rect) : rect_(rect) {}
10 
11 RectGeometry::~RectGeometry() = default;
12 
13 GeometryResult RectGeometry::GetPositionBuffer(const ContentContext& renderer,
14  const Entity& entity,
15  RenderPass& pass) {
16  auto& host_buffer = pass.GetTransientsBuffer();
17  return GeometryResult{
19  .vertex_buffer =
20  {
21  .vertex_buffer = host_buffer.Emplace(
22  rect_.GetPoints().data(), 8 * sizeof(float), alignof(float)),
23  .vertex_count = 4,
24  .index_type = IndexType::kNone,
25  },
26  .transform = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
27  entity.GetTransformation(),
28  .prevent_overdraw = false,
29  };
30 }
31 
32 // |Geometry|
33 GeometryResult RectGeometry::GetPositionUVBuffer(Rect texture_coverage,
34  Matrix effect_transform,
35  const ContentContext& renderer,
36  const Entity& entity,
37  RenderPass& pass) {
38  return ComputeUVGeometryForRect(rect_, texture_coverage, effect_transform,
39  renderer, entity, pass);
40 }
41 
42 GeometryVertexType RectGeometry::GetVertexType() const {
44 }
45 
46 std::optional<Rect> RectGeometry::GetCoverage(const Matrix& transform) const {
47  return rect_.TransformBounds(transform);
48 }
49 
50 bool RectGeometry::CoversArea(const Matrix& transform, const Rect& rect) const {
51  if (!transform.IsTranslationScaleOnly()) {
52  return false;
53  }
54  Rect coverage = rect_.TransformBounds(transform);
55  return coverage.Contains(rect);
56 }
57 
58 } // namespace impeller
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:204
rect_geometry.h
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:25
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::TRect::GetPoints
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle. The order is: Top left,...
Definition: rect.h:187
impeller::Entity::GetTransformation
const Matrix & GetTransformation() const
Definition: entity.cc:49
impeller::Entity
Definition: entity.h:21
impeller::RenderPass::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_pass.cc:30
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:19
impeller::RectGeometry::RectGeometry
RectGeometry(Rect rect)
Definition: rect_geometry.cc:9
impeller::RectGeometry::~RectGeometry
~RectGeometry()
impeller::Matrix::IsTranslationScaleOnly
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:358
impeller::GeometryResult
Definition: geometry.h:18
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:306
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Definition: rect.h:122
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:448
impeller::RectGeometry::CoversArea
bool CoversArea(const Matrix &transform, const Rect &rect) const override
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Definition: rect_geometry.cc:50
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:70
impeller
Definition: aiks_context.cc:10
impeller::kPosition
@ kPosition
Definition: geometry.h:26
impeller::ContentContext
Definition: content_context.h:344
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::RenderPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: render_pass.cc:34