Flutter Impeller
impeller::DrawImageRectAtlasGeometry Class Reference

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

#include <atlas_contents.h>

Inheritance diagram for impeller::DrawImageRectAtlasGeometry:
impeller::AtlasGeometry

Public Member Functions

 DrawImageRectAtlasGeometry (std::shared_ptr< Texture > texture, const Rect &source, const Rect &destination, const Color &color, BlendMode blend_mode, const SamplerDescriptor &desc)
 
 ~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 SamplerDescriptorGetSamplerDescriptor () const override
 
BlendMode GetBlendMode () const override
 
bool ShouldInvertBlendMode () const override
 

Detailed Description

An atlas geometry that adapts for drawImageRect.

Definition at line 43 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 
)

Definition at line 20 of file atlas_contents.cc.

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

◆ ~DrawImageRectAtlasGeometry()

impeller::DrawImageRectAtlasGeometry::~DrawImageRectAtlasGeometry ( )
default

Member Function Documentation

◆ ComputeBoundingBox()

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

Implements impeller::AtlasGeometry.

Definition at line 105 of file atlas_contents.cc.

105  {
106  return destination_;
107 }

◆ CreateBlendVertexBuffer()

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

Implements impeller::AtlasGeometry.

Definition at line 74 of file atlas_contents.cc.

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

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetPoints(), impeller::kNone, impeller::TRect< Scalar >::MakeSize(), offset, 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 44 of file atlas_contents.cc.

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

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetPoints(), impeller::kNone, impeller::TRect< Scalar >::MakeSize(), offset, 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 109 of file atlas_contents.cc.

109  {
110  return texture_;
111 }

◆ GetBlendMode()

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

Implements impeller::AtlasGeometry.

Definition at line 118 of file atlas_contents.cc.

118  {
119  return blend_mode_;
120 }

◆ GetSamplerDescriptor()

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

Implements impeller::AtlasGeometry.

Definition at line 113 of file atlas_contents.cc.

114  {
115  return desc_;
116 }

◆ ShouldInvertBlendMode()

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

Reimplemented from impeller::AtlasGeometry.

Definition at line 122 of file atlas_contents.cc.

122  {
123  return false;
124 }

◆ ShouldSkip()

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

Implements impeller::AtlasGeometry.

Definition at line 40 of file atlas_contents.cc.

40  {
41  return false;
42 }

◆ ShouldUseBlend()

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

Implements impeller::AtlasGeometry.

Definition at line 36 of file atlas_contents.cc.

36  {
37  return true;
38 }

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