Skip to content

Commit 685ae23

Browse files
bderodnfield
authored andcommitted
Add explicit scaling methods for Point/Vector2 (flutter#119)
1 parent 8075d38 commit 685ae23

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

impeller/aiks/canvas.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ void Canvas::Translate(const Vector3& offset) {
8080
Concat(Matrix::MakeTranslation(offset));
8181
}
8282

83+
void Canvas::Scale(const Vector2& scale) {
84+
Concat(Matrix::MakeScale(scale));
85+
}
86+
8387
void Canvas::Scale(const Vector3& scale) {
8488
Concat(Matrix::MakeScale(scale));
8589
}
@@ -283,7 +287,7 @@ void Canvas::DrawTextFrame(TextFrame text_frame, Point position, Paint paint) {
283287
auto text_contents = std::make_shared<TextContents>();
284288
text_contents->SetTextFrame(std::move(text_frame));
285289
text_contents->SetGlyphAtlas(std::move(lazy_glyph_atlas));
286-
text_contents->SetColor(paint.color.Premultiply());
290+
text_contents->SetColor(paint.color);
287291

288292
Entity entity;
289293
entity.SetTransformation(GetCurrentTransformation() *

impeller/aiks/canvas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Canvas {
5252

5353
void Translate(const Vector3& offset);
5454

55+
void Scale(const Vector2& scale);
56+
5557
void Scale(const Vector3& scale);
5658

5759
void Skew(Scalar sx, Scalar sy);

impeller/entity/contents/text_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool TextContents::Render(const ContentContext& renderer,
8080
frame_info.atlas_size =
8181
Point{static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
8282
static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
83-
frame_info.text_color = ToVector(color_);
83+
frame_info.text_color = ToVector(color_.Premultiply());
8484
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
8585

8686
// Common fragment uniforms for all glyphs.

impeller/geometry/geometry_unittests.cc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,24 @@ TEST(GeometryTest, RotationMatrix) {
3737
}
3838

3939
TEST(GeometryTest, InvertMultMatrix) {
40-
auto rotation = Matrix::MakeRotationZ(Radians{M_PI_4});
41-
auto invert = rotation.Invert();
42-
auto expect = Matrix{0.707, -0.707, 0, 0, //
43-
0.707, 0.707, 0, 0, //
44-
0, 0, 1, 0, //
45-
0, 0, 0, 1};
46-
ASSERT_MATRIX_NEAR(invert, expect);
40+
{
41+
auto rotation = Matrix::MakeRotationZ(Radians{M_PI_4});
42+
auto invert = rotation.Invert();
43+
auto expect = Matrix{0.707, -0.707, 0, 0, //
44+
0.707, 0.707, 0, 0, //
45+
0, 0, 1, 0, //
46+
0, 0, 0, 1};
47+
ASSERT_MATRIX_NEAR(invert, expect);
48+
}
49+
{
50+
auto scale = Matrix::MakeScale(Vector2{2, 4});
51+
auto invert = scale.Invert();
52+
auto expect = Matrix{0.5, 0, 0, 0, //
53+
0, 0.25, 0, 0, //
54+
0, 0, 1, 0, //
55+
0, 0, 0, 1};
56+
ASSERT_MATRIX_NEAR(invert, expect);
57+
}
4758
}
4859

4960
TEST(GeometryTest, MutliplicationMatrix) {

impeller/geometry/matrix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ struct Matrix {
8080
// clang-format on
8181
}
8282

83+
static constexpr Matrix MakeScale(const Vector2& s) {
84+
return MakeScale(Vector3(s.x, s.y, 1.0));
85+
}
86+
8387
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy) {
8488
// clang-format off
8589
return Matrix(1.0, sy , 0.0, 0.0,

0 commit comments

Comments
 (0)