| 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
5 #include "impeller/entity/geometry/rect_geometry.h"
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) const {
16 auto& host_buffer = renderer.GetTransientsBuffer();
17 return GeometryResult{
18 .type = PrimitiveType::kTriangleStrip,
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 = entity.GetShaderTransform(pass),
27 };
28 }
29
30 std::optional<Rect> RectGeometry::GetCoverage(const Matrix& transform) const {
31 return rect_.TransformBounds(transform);
32 }
33
34 bool RectGeometry::CoversArea(const Matrix& transform, const Rect& rect) const {
35 if (!transform.IsTranslationScaleOnly()) {
36 return false;
37 }
38 Rect coverage = rect_.TransformBounds(transform);
39 return coverage.Contains(rect);
40 }
41
42 bool RectGeometry::IsAxisAlignedRect() const {
43 return true;
44 }
45
46 } // namespace impeller
impeller::ContentContext
Definition: content_context.h:371
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:866
impeller::Entity
Definition: entity.h:20
impeller::Entity::GetShaderTransform
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:48
impeller::RectGeometry::~RectGeometry
~RectGeometry() override
impeller::RectGeometry::RectGeometry
RectGeometry(Rect rect)
Definition: rect_geometry.cc:9
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:34
impeller::RectGeometry::GetCoverage
std::optional< Rect > GetCoverage(const Matrix &transform) const override
Definition: rect_geometry.cc:30
impeller::RectGeometry::GetPositionBuffer
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: rect_geometry.cc:13
impeller::RectGeometry::IsAxisAlignedRect
bool IsAxisAlignedRect() const override
Definition: rect_geometry.cc:42
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller
Definition: allocation.cc:12
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
rect_geometry.h
impeller::GeometryResult
Definition: geometry.h:21
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:37
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TRect< Scalar >
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476
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:235
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:418