From a1ff9815592052b51ffcef36915baf978431fcbe Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 17 Mar 2022 10:23:03 -0700 Subject: [PATCH] Transform clips by the entity's transform (flutter/engine#87) --- .../flutter/impeller/aiks/aiks_unittests.cc | 21 +++++++++++++++++++ .../impeller/entity/contents/clip_contents.cc | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index e8ab4e8b8d..a16e727c5a 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include "flutter/testing/testing.h" #include "impeller/aiks/aiks_playground.h" #include "impeller/aiks/canvas.h" @@ -122,6 +123,26 @@ TEST_F(AiksTest, CanRenderNestedClips) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_F(AiksTest, ClipsUseCurrentTransform) { + std::array colors = {Color::White(), Color::Black(), + Color::SkyBlue(), Color::Red(), + Color::Yellow()}; + Canvas canvas; + Paint paint; + + canvas.Translate(Vector3(300, 300)); + for (int i = 0; i < 15; i++) { + canvas.Translate(-Vector3(300, 300)); + canvas.Scale(Vector3(0.8, 0.8)); + canvas.Translate(Vector3(300, 300)); + + paint.color = colors[i % colors.size()]; + canvas.ClipPath(PathBuilder{}.AddCircle({0, 0}, 300).TakePath()); + canvas.DrawRect(Rect(-300, -300, 600, 600), paint); + } + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_F(AiksTest, CanSaveLayerStandalone) { Canvas canvas; diff --git a/engine/src/flutter/impeller/entity/contents/clip_contents.cc b/engine/src/flutter/impeller/entity/contents/clip_contents.cc index 07921a3356..df82089264 100644 --- a/engine/src/flutter/impeller/entity/contents/clip_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/clip_contents.cc @@ -35,7 +35,8 @@ bool ClipContents::Render(const ContentContext& renderer, VS::FrameInfo info; // The color really doesn't matter. info.color = Color::SkyBlue(); - info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()); + info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * + entity.GetTransformation(); VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));