Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 32ab06e

Browse files
authored
[Impeller] Remove Rect field accesses from aiks subdirectory (#47628)
These changes move any code in `impeller/aiks` that accessed the internal fields of `Rect` to using either the appropriate convenience methods for the operation or the getters for those properties. This is a simple code refactoring and should be covered by existing tests.
1 parent 677040f commit 32ab06e

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

impeller/aiks/canvas.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,11 @@ void Canvas::ClipRRect(const Rect& rect,
326326
.SetBounds(rect)
327327
.TakePath();
328328

329-
std::optional<Rect> inner_rect = (corner_radius * 2 < rect.size.width &&
330-
corner_radius * 2 < rect.size.height)
329+
auto size = rect.GetSize();
330+
// Does the rounded rect have a flat part on the top/bottom or left/right?
331+
bool flat_on_TB = corner_radius * 2 < size.width;
332+
bool flat_on_LR = corner_radius * 2 < size.height;
333+
std::optional<Rect> inner_rect = (flat_on_LR && flat_on_TB)
331334
? rect.Expand(-corner_radius)
332335
: std::make_optional<Rect>();
333336
auto geometry = Geometry::MakeFillPath(path, inner_rect);
@@ -353,12 +356,12 @@ void Canvas::ClipRRect(const Rect& rect,
353356
// without involving the curved corners
354357
// Since this is a subtract operation, we can subtract each
355358
// rectangle piece individually without fear of interference.
356-
if (corner_radius * 2 < rect.size.width) {
359+
if (flat_on_TB) {
357360
SubtractCulling(Rect::MakeLTRB(
358361
rect.GetLeft() + corner_radius, rect.GetTop(),
359362
rect.GetRight() - corner_radius, rect.GetBottom()));
360363
}
361-
if (corner_radius * 2 < rect.size.height) {
364+
if (flat_on_LR) {
362365
SubtractCulling(Rect::MakeLTRB(
363366
rect.GetLeft(), rect.GetTop() + corner_radius, //
364367
rect.GetRight(), rect.GetBottom() - corner_radius));
@@ -479,8 +482,7 @@ void Canvas::DrawImage(const std::shared_ptr<Image>& image,
479482
}
480483

481484
const auto source = Rect::MakeSize(image->GetSize());
482-
const auto dest =
483-
Rect::MakeXYWH(offset.x, offset.y, source.size.width, source.size.height);
485+
const auto dest = source.Shift(offset);
484486

485487
DrawImageRect(image, source, dest, paint, std::move(sampler));
486488
}
@@ -490,7 +492,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
490492
Rect dest,
491493
const Paint& paint,
492494
SamplerDescriptor sampler) {
493-
if (!image || source.size.IsEmpty() || dest.size.IsEmpty()) {
495+
if (!image || source.IsEmpty() || dest.IsEmpty()) {
494496
return;
495497
}
496498

impeller/aiks/color_source.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ColorSource ColorSource::MakeLinearGradient(Point start_point,
6464
std::vector<Point> bounds{start_point, end_point};
6565
auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
6666
if (intrinsic_size.has_value()) {
67-
contents->SetColorSourceSize(intrinsic_size->size);
67+
contents->SetColorSourceSize(intrinsic_size->GetSize());
6868
}
6969
return contents;
7070
};
@@ -98,7 +98,7 @@ ColorSource ColorSource::MakeConicalGradient(Point center,
9898
std::vector<Point> bounds{center + radius_pt, center - radius_pt};
9999
auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
100100
if (intrinsic_size.has_value()) {
101-
contents->SetColorSourceSize(intrinsic_size->size);
101+
contents->SetColorSourceSize(intrinsic_size->GetSize());
102102
}
103103
return contents;
104104
};
@@ -128,7 +128,7 @@ ColorSource ColorSource::MakeRadialGradient(Point center,
128128
std::vector<Point> bounds{center + radius_pt, center - radius_pt};
129129
auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
130130
if (intrinsic_size.has_value()) {
131-
contents->SetColorSourceSize(intrinsic_size->size);
131+
contents->SetColorSourceSize(intrinsic_size->GetSize());
132132
}
133133
return contents;
134134
};

impeller/aiks/picture.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ std::optional<Snapshot> Picture::Snapshot(AiksContext& context) {
2020
return std::nullopt;
2121
}
2222

23-
const auto translate = Matrix::MakeTranslation(-coverage.value().origin);
23+
const auto translate = Matrix::MakeTranslation(-coverage->GetOrigin());
2424
auto texture =
25-
RenderToTexture(context, ISize(coverage.value().size), translate);
25+
RenderToTexture(context, ISize(coverage->GetSize()), translate);
2626
return impeller::Snapshot{
2727
.texture = std::move(texture),
28-
.transform = Matrix::MakeTranslation(coverage.value().origin)};
28+
.transform = Matrix::MakeTranslation(coverage->GetOrigin())};
2929
}
3030

3131
std::shared_ptr<Image> Picture::ToImage(AiksContext& context,

0 commit comments

Comments
 (0)