Flutter Engine
 
Loading...
Searching...
No Matches
dl_atlas_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
10#include "impeller/entity/porter_duff_blend.vert.h"
11#include "impeller/entity/texture_fill.vert.h"
14
15namespace impeller {
16
17DlAtlasGeometry::DlAtlasGeometry(const std::shared_ptr<Texture>& atlas,
18 const RSTransform* xform,
19 const flutter::DlRect* tex,
20 const flutter::DlColor* colors,
21 size_t count,
22 BlendMode mode,
23 const SamplerDescriptor& sampling,
24 std::optional<Rect> cull_rect)
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) {}
33
35
37 return colors_ != nullptr && mode_ != BlendMode::kSrc;
38}
39
41 return atlas_ == nullptr || (ShouldUseBlend() && mode_ == BlendMode::kClear);
42}
43
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}
56
57const std::shared_ptr<Texture>& DlAtlasGeometry::GetAtlas() const {
58 return atlas_;
59}
60
62 return sampling_;
63}
64
66 return mode_;
67}
68
70 HostBuffer& data_host_buffer) const {
71 using VS = TextureFillVertexShader;
72 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
73
74 BufferView buffer_view = data_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{
95 .index_buffer = {},
96 .vertex_count = count_ * 6,
97 .index_type = IndexType::kNone,
98 };
99}
100
102 HostBuffer& data_host_buffer) const {
103 using VS = PorterDuffBlendVertexShader;
104 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
105
106 BufferView buffer_view = data_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{
129 .index_buffer = {},
130 .vertex_count = count_ * 6,
131 .index_type = IndexType::kNone,
132 };
133}
134
135} // namespace impeller
BufferView buffer_view
const std::shared_ptr< Texture > & GetAtlas() const override
BlendMode GetBlendMode() const override
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
const SamplerDescriptor & GetSamplerDescriptor() const override
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)
bool ShouldUseBlend() const override
Whether the blend shader should be used.
bool ShouldSkip() const override
Rect ComputeBoundingBox() const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition host_buffer.h:92
Color ToColor(const flutter::DlColor &color)
@ kNone
Does not use the index buffer.
BlendMode
Definition color.h:58
LinePipeline::VertexShader VS
constexpr Color Premultiply() const
Definition color.h:212
std::optional< Rect > GetBounds(Scalar width, Scalar height) const
void GetQuad(Scalar width, Scalar height, Quad &quad) const
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:414
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:327
constexpr TRect Union(const TRect &o) const
Definition rect.h:513
std::vector< Point > points
std::shared_ptr< const fml::Mapping > data