Flutter Impeller
impeller::DlAtlasGeometry Class Reference

A wrapper around data provided by a drawAtlas call. More...

#include <dl_atlas_geometry.h>

Inheritance diagram for impeller::DlAtlasGeometry:
impeller::AtlasGeometry

Public Member Functions

 DlAtlasGeometry (const std::shared_ptr< Texture > &atlas, const RSTransform *xform, const flutter::DlRect *tex, const flutter::DlColor *colors, size_t count, BlendMode mode, const SamplerDescriptor &sampling, std::optional< Rect > cull_rect)
 
 ~DlAtlasGeometry ()
 
bool ShouldUseBlend () const override
 Whether the blend shader should be used. More...
 
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
 
- Public Member Functions inherited from impeller::AtlasGeometry
virtual bool ShouldInvertBlendMode () const
 
virtual std::optional< RectGetStrictSrcRect () const
 The source rect of the draw if a strict source rect should be applied, or nullopt. More...
 

Detailed Description

A wrapper around data provided by a drawAtlas call.

Definition at line 17 of file dl_atlas_geometry.h.

Constructor & Destructor Documentation

◆ DlAtlasGeometry()

impeller::DlAtlasGeometry::DlAtlasGeometry ( const std::shared_ptr< Texture > &  atlas,
const RSTransform xform,
const flutter::DlRect *  tex,
const flutter::DlColor *  colors,
size_t  count,
BlendMode  mode,
const SamplerDescriptor sampling,
std::optional< Rect cull_rect 
)

Definition at line 17 of file dl_atlas_geometry.cc.

25  : atlas_(atlas),
26  xform_(xform),
27  tex_(tex),
28  colors_(colors),
29  count_(count),
30  mode_(mode),
31  sampling_(sampling),
32  cull_rect_(cull_rect) {}

◆ ~DlAtlasGeometry()

impeller::DlAtlasGeometry::~DlAtlasGeometry ( )
default

Member Function Documentation

◆ ComputeBoundingBox()

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

Implements impeller::AtlasGeometry.

Definition at line 44 of file dl_atlas_geometry.cc.

44  {
45  if (cull_rect_.has_value()) {
46  return cull_rect_.value();
47  }
48  Rect bounding_box;
49  for (size_t i = 0; i < count_; i++) {
50  auto bounds = xform_[i].GetBounds(tex_[i].GetSize());
51  bounding_box = Rect::Union(bounding_box, bounds);
52  }
53  cull_rect_ = bounding_box;
54  return bounding_box;
55 }
TRect< Scalar > Rect
Definition: rect.h:792
std::optional< Rect > GetBounds(Scalar width, Scalar height) const
Definition: rstransform.cc:49
constexpr TRect Union(const TRect &o) const
Definition: rect.h:517

References impeller::RSTransform::GetBounds(), and impeller::TRect< Scalar >::Union().

◆ CreateBlendVertexBuffer()

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

Implements impeller::AtlasGeometry.

Definition at line 101 of file dl_atlas_geometry.cc.

102  {
103  using VS = PorterDuffBlendVertexShader;
104  constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
105 
106  BufferView buffer_view = host_buffer.Emplace(
107  sizeof(VS::PerVertexData) * count_ * 6, alignof(VS::PerVertexData),
108  [&](uint8_t* raw_data) {
109  VS::PerVertexData* data =
110  reinterpret_cast<VS::PerVertexData*>(raw_data);
111  int offset = 0;
112  ISize texture_size = atlas_->GetSize();
113  for (auto i = 0u; i < count_; i++) {
114  flutter::DlRect sample_rect = tex_[i];
115  auto points = sample_rect.GetPoints();
116  auto transformed_points = xform_[i].GetQuad(sample_rect.GetSize());
117  for (size_t j = 0; j < 6; j++) {
118  data[offset].vertices = transformed_points[indices[j]];
119  data[offset].texture_coords = points[indices[j]] / texture_size;
120  data[offset].color =
122  offset += 1;
123  }
124  }
125  });
126 
127  return VertexBuffer{
128  .vertex_buffer = buffer_view,
129  .index_buffer = {},
130  .vertex_count = count_ * 6,
131  .index_type = IndexType::kNone,
132  };
133 }
BufferView buffer_view
Color ToColor(const flutter::DlColor &color)
@ kNone
Does not use the index buffer.
flutter::DlRect DlRect
Definition: dl_dispatcher.h:25
LinePipeline::VertexShader VS
ISize64 ISize
Definition: size.h:162
constexpr Color Premultiply() const
Definition: color.h:212
void GetQuad(Scalar width, Scalar height, Quad &quad) const
Definition: rstransform.cc:24
std::vector< Point > points
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::RSTransform::GetQuad(), impeller::kNone, points, impeller::Color::Premultiply(), impeller::skia_conversions::ToColor(), and impeller::VertexBuffer::vertex_buffer.

Referenced by impeller::testing::TEST_P().

◆ CreateSimpleVertexBuffer()

VertexBuffer impeller::DlAtlasGeometry::CreateSimpleVertexBuffer ( HostBuffer host_buffer) const
overridevirtual

Implements impeller::AtlasGeometry.

Definition at line 69 of file dl_atlas_geometry.cc.

70  {
71  using VS = TextureFillVertexShader;
72  constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
73 
74  BufferView buffer_view = host_buffer.Emplace(
75  sizeof(VS::PerVertexData) * count_ * 6, alignof(VS::PerVertexData),
76  [&](uint8_t* raw_data) {
77  VS::PerVertexData* data =
78  reinterpret_cast<VS::PerVertexData*>(raw_data);
79  int offset = 0;
80  ISize texture_size = atlas_->GetSize();
81  for (auto i = 0u; i < count_; i++) {
82  flutter::DlRect sample_rect = tex_[i];
83  auto points = sample_rect.GetPoints();
84  auto transformed_points = xform_[i].GetQuad(sample_rect.GetSize());
85  for (size_t j = 0; j < 6; j++) {
86  data[offset].position = transformed_points[indices[j]];
87  data[offset].texture_coords = points[indices[j]] / texture_size;
88  offset += 1;
89  }
90  }
91  });
92 
93  return VertexBuffer{
94  .vertex_buffer = buffer_view,
95  .index_buffer = {},
96  .vertex_count = count_ * 6,
97  .index_type = IndexType::kNone,
98  };
99 }

References buffer_view, data, impeller::HostBuffer::Emplace(), impeller::RSTransform::GetQuad(), impeller::kNone, points, and impeller::VertexBuffer::vertex_buffer.

Referenced by impeller::testing::TEST_P().

◆ GetAtlas()

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

Implements impeller::AtlasGeometry.

Definition at line 57 of file dl_atlas_geometry.cc.

57  {
58  return atlas_;
59 }

◆ GetBlendMode()

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

Implements impeller::AtlasGeometry.

Definition at line 65 of file dl_atlas_geometry.cc.

65  {
66  return mode_;
67 }

◆ GetSamplerDescriptor()

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

Implements impeller::AtlasGeometry.

Definition at line 61 of file dl_atlas_geometry.cc.

61  {
62  return sampling_;
63 }

◆ ShouldSkip()

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

Implements impeller::AtlasGeometry.

Definition at line 40 of file dl_atlas_geometry.cc.

40  {
41  return atlas_ == nullptr || (ShouldUseBlend() && mode_ == BlendMode::kClear);
42 }
bool ShouldUseBlend() const override
Whether the blend shader should be used.

References impeller::kClear, and ShouldUseBlend().

Referenced by impeller::testing::TEST_P().

◆ ShouldUseBlend()

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

Whether the blend shader should be used.

Implements impeller::AtlasGeometry.

Definition at line 36 of file dl_atlas_geometry.cc.

36  {
37  return colors_ != nullptr && mode_ != BlendMode::kSrc;
38 }

References impeller::kSrc.

Referenced by ShouldSkip(), and impeller::testing::TEST_P().


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