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 
12  const Entity& entity,
13  RenderPass& pass) const {
14  auto& host_buffer = renderer.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 = entity.GetShaderTransform(pass),
25  };
26 }
27 
28 // |Geometry|
30  Matrix effect_transform,
31  const ContentContext& renderer,
32  const Entity& entity,
33  RenderPass& pass) const {
34  return ComputeUVGeometryForRect(rect_, texture_coverage, effect_transform,
35  renderer, entity, pass);
36 }
37 
40 }
41 
42 std::optional<Rect> RectGeometry::GetCoverage(const Matrix& transform) const {
43  return rect_.TransformBounds(transform);
44 }
45 
46 bool RectGeometry::CoversArea(const Matrix& transform, const Rect& rect) const {
47  if (!transform.IsTranslationScaleOnly()) {
48  return false;
49  }
50  Rect coverage = rect_.TransformBounds(transform);
51  return coverage.Contains(rect);
52 }
53 
55  return true;
56 }
57 
58 } // namespace impeller
impeller::Entity::GetShaderTransform
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:53
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:405
rect_geometry.h
impeller::RectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: rect_geometry.cc:54
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:49
impeller::TRect::GetPoints
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with tr...
Definition: rect.h:382
impeller::Entity
Definition: entity.h:21
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:36
impeller::RectGeometry::RectGeometry
RectGeometry(Rect rect)
Definition: rect_geometry.cc:9
impeller::RectGeometry::GetPositionBuffer
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: rect_geometry.cc:11
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:363
impeller::GeometryResult
Definition: geometry.h:20
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::RectGeometry::GetPositionUVBuffer
GeometryResult GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: rect_geometry.cc:29
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition: rect.h:217
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::RectGeometry::GetVertexType
GeometryVertexType GetVertexType() const override
Definition: rect_geometry.cc:38
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_bounds, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Computes geometry and UV coordinates for a rectangle to be rendered.
Definition: geometry.cc:113
impeller::RectGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: rect_geometry.cc:42
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:46
impeller
Definition: aiks_blur_unittests.cc:20
impeller::kPosition
@ kPosition
Definition: geometry.h:50
impeller::ContentContext
Definition: content_context.h:392
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:833