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 GeometryResult RectGeometry::GetPositionBuffer(const ContentContext& renderer,
12  const Entity& entity,
13  RenderPass& pass) const {
14  auto& host_buffer = pass.GetTransientsBuffer();
15  return GeometryResult{
17  .vertex_buffer =
18  {
19  .vertex_buffer = host_buffer.Emplace(
20  rect_.GetPoints().data(), 8 * sizeof(float), alignof(float)),
21  .vertex_count = 4,
22  .index_type = IndexType::kNone,
23  },
24  .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
25  .prevent_overdraw = false,
26  };
27 }
28 
29 // |Geometry|
30 GeometryResult RectGeometry::GetPositionUVBuffer(Rect texture_coverage,
31  Matrix effect_transform,
32  const ContentContext& renderer,
33  const Entity& entity,
34  RenderPass& pass) const {
35  return ComputeUVGeometryForRect(rect_, texture_coverage, effect_transform,
36  renderer, entity, pass);
37 }
38 
39 GeometryVertexType RectGeometry::GetVertexType() const {
41 }
42 
43 std::optional<Rect> RectGeometry::GetCoverage(const Matrix& transform) const {
44  return rect_.TransformBounds(transform);
45 }
46 
47 bool RectGeometry::CoversArea(const Matrix& transform, const Rect& rect) const {
48  if (!transform.IsTranslationScaleOnly()) {
49  return false;
50  }
51  Rect coverage = rect_.TransformBounds(transform);
52  return coverage.Contains(rect);
53 }
54 
56  return true;
57 }
58 
59 } // namespace impeller
impeller::Entity::GetTransform
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:49
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:264
rect_geometry.h
impeller::RenderPass::GetOrthographicTransform
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:51
impeller::RectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: rect_geometry.cc:55
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:34
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:247
impeller::Entity
Definition: entity.h:21
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:21
impeller::RectGeometry::RectGeometry
RectGeometry(Rect rect)
Definition: rect_geometry.cc:9
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:360
impeller::GeometryResult
Definition: geometry.h:20
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:488
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Definition: rect.h:127
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
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:47
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:111
impeller
Definition: aiks_context.cc:10
impeller::kPosition
@ kPosition
Definition: geometry.h:35
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::RenderPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: render_pass.cc:55