| Flutter Impeller |

Public Member Functions | List of all members
impeller::DrawImageRectAtlasGeometry Class Reference

An atlas geometry that adapts for drawImageRect. More...

`#include <atlas_contents.h>`

Inheritance diagram for impeller::DrawImageRectAtlasGeometry:

## Public Member Functions
| DrawImageRectAtlasGeometry (std::shared_ptr< Texture > texture, const Rect &source, const Rect &destination, const Color &color, BlendMode blend_mode, const SamplerDescriptor &desc, bool use_strict_src_rect=false)
| ~DrawImageRectAtlasGeometry ()
bool | ShouldUseBlend () const override
bool | ShouldSkip () const override
VertexBuffer | CreateSimpleVertexBuffer (HostBuffer &host_buffer) const override
VertexBuffer | CreateBlendVertexBuffer (HostBuffer &host_buffer) const override
Rect | ComputeBoundingBox () const override
const std::shared_ptr< Texture > & | GetAtlas () const override
const SamplerDescriptor & | GetSamplerDescriptor () const override
BlendMode | GetBlendMode () const override
bool | ShouldInvertBlendMode () const override
std::optional< Rect > | GetStrictSrcRect () const override
| The source rect of the draw if a strict source rect should be applied, or nullopt. More...

## Detailed Description

An atlas geometry that adapts for drawImageRect.

Definition at line 51 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ DrawImageRectAtlasGeometry()

impeller::DrawImageRectAtlasGeometry::DrawImageRectAtlasGeometry | ( | std::shared_ptr< Texture > | texture,
|  | const Rect & | source,
|  | const Rect & | destination,
|  | const Color & | color,
|  | BlendMode | blend_mode,
|  | const SamplerDescriptor & | desc,
|  | bool | use_strict_src_rect = `false`
| ) |  |

Definition at line 20 of file atlas_contents.cc.

28 : texture_(std::move(texture)),
29 source_(source),
30 destination_(destination),
31 color_(color),
32 blend_mode_(blend_mode),
33 desc_(desc),
34 use_strict_src_rect_(use_strict_src_rect) {}

## ◆ ~DrawImageRectAtlasGeometry()

impeller::DrawImageRectAtlasGeometry::~DrawImageRectAtlasGeometry | ( |  | ) |
| default

## Member Function Documentation

## ◆ ComputeBoundingBox()

Rect impeller::DrawImageRectAtlasGeometry::ComputeBoundingBox | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 107 of file atlas_contents.cc.

107 {
108 return destination_;
109 }

## ◆ CreateBlendVertexBuffer()

VertexBuffer impeller::DrawImageRectAtlasGeometry::CreateBlendVertexBuffer | ( | HostBuffer & | host_buffer | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 76 of file atlas_contents.cc.

77 {
78 using VS = PorterDuffBlendVertexShader;
79 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
80
81 BufferView buffer_view = host_buffer.Emplace(
82 sizeof(VS::PerVertexData) * 6, alignof(VS::PerVertexData),
83 [&](uint8_t* raw_data) {
84 VS::PerVertexData* data =
85 reinterpret_cast<VS::PerVertexData*>(raw_data);
86 int offset = 0;
87 std::array<TPoint<float>, 4> texture_coords =
88 Rect::MakeSize(texture_->GetSize()).Project(source_).GetPoints();
89 std::array<TPoint<float>, 4> destination_points =
90 destination_.GetPoints();
91 for (size_t j = 0; j < 6; j++) {
92 data[offset].vertices = destination_points[indices[j]];
93 data[offset].texture_coords = texture_coords[indices[j]];
94 data[offset].color = color_.Premultiply();
95 offset++;
96 }
97 });
98
99 return VertexBuffer{
100 .vertex_buffer = buffer_view,
101 .index_buffer = {},
102 .vertex_count = 6,
103 .index_type = IndexType::kNone,
104 };
105 }
buffer_view
BufferView buffer_view
Definition: blit_command_gles.cc:154
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::Color::Premultiply
constexpr Color Premultiply() const
Definition: color.h:212
impeller::TRect::Project
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
Definition: rect.h:673
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
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetPoints(), impeller::kNone, impeller::TRect< Scalar >::MakeSize(), impeller::Color::Premultiply(), impeller::TRect< T >::Project(), and impeller::VertexBuffer::vertex_buffer.

## ◆ CreateSimpleVertexBuffer()

VertexBuffer impeller::DrawImageRectAtlasGeometry::CreateSimpleVertexBuffer | ( | HostBuffer & | host_buffer | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 46 of file atlas_contents.cc.

47 {
48 using VS = TextureFillVertexShader;
49 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
50
51 BufferView buffer_view = host_buffer.Emplace(
52 sizeof(VS::PerVertexData) * 6, alignof(VS::PerVertexData),
53 [&](uint8_t* raw_data) {
54 VS::PerVertexData* data =
55 reinterpret_cast<VS::PerVertexData*>(raw_data);
56 int offset = 0;
57 std::array<TPoint<float>, 4> destination_points =
58 destination_.GetPoints();
59 std::array<TPoint<float>, 4> texture_coords =
60 Rect::MakeSize(texture_->GetSize()).Project(source_).GetPoints();
61 for (size_t j = 0; j < 6; j++) {
62 data[offset].position = destination_points[indices[j]];
63 data[offset].texture_coords = texture_coords[indices[j]];
64 offset++;
65 }
66 });
67
68 return VertexBuffer{
69 .vertex_buffer = buffer_view,
70 .index_buffer = {},
71 .vertex_count = 6,
72 .index_type = IndexType::kNone,
73 };
74 }

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetPoints(), impeller::kNone, impeller::TRect< Scalar >::MakeSize(), impeller::TRect< T >::Project(), and impeller::VertexBuffer::vertex_buffer.

## ◆ GetAtlas()

const std::shared_ptr< Texture > & impeller::DrawImageRectAtlasGeometry::GetAtlas | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 111 of file atlas_contents.cc.

111 {
112 return texture_;
113 }

## ◆ GetBlendMode()

BlendMode impeller::DrawImageRectAtlasGeometry::GetBlendMode | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 120 of file atlas_contents.cc.

120 {
121 return blend_mode_;
122 }

## ◆ GetSamplerDescriptor()

const SamplerDescriptor & impeller::DrawImageRectAtlasGeometry::GetSamplerDescriptor | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 115 of file atlas_contents.cc.

116 {
117 return desc_;
118 }

## ◆ GetStrictSrcRect()

std::optional< Rect > impeller::DrawImageRectAtlasGeometry::GetStrictSrcRect | ( |  | ) | const
| overridevirtual

The source rect of the draw if a strict source rect should be applied, or nullopt.

See also `Canvas::AttemptColorFilterOptimization`

Reimplemented from impeller::AtlasGeometry.

Definition at line 128 of file atlas_contents.cc.

128 {
129 if (use_strict_src_rect_) {
130 return source_;
131 }
132 return std::nullopt;
133 }

## ◆ ShouldInvertBlendMode()

bool impeller::DrawImageRectAtlasGeometry::ShouldInvertBlendMode | ( |  | ) | const
| overridevirtual

Reimplemented from impeller::AtlasGeometry.

Definition at line 124 of file atlas_contents.cc.

124 {
125 return false;
126 }

## ◆ ShouldSkip()

bool impeller::DrawImageRectAtlasGeometry::ShouldSkip | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 42 of file atlas_contents.cc.

42 {
43 return false;
44 }

## ◆ ShouldUseBlend()

bool impeller::DrawImageRectAtlasGeometry::ShouldUseBlend | ( |  | ) | const
| overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 38 of file atlas_contents.cc.

38 {
39 return true;
40 }

The documentation for this class was generated from the following files:

- impeller/entity/contents/atlas_contents.h
- impeller/entity/contents/atlas_contents.cc