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

Commit 950e240

Browse files
[Impeller] fix line/polygon depth and GLES scissor state. (#56494)
Two problems: 1. We were incorrectly clearing scissor state in the GLES render pass. I suspect this is the cause of all of the clipping problems in wonderous. 2. We were incrementing the depth value in drawPoints with line/polygon mode: these actually need to use the same depth values. Fixed in the same PR because the golden actually demonstrates both problems with GLES, and luckily I found 2. when I noticed 1. ## Before ### Metal/Vulkan ![image](https://github.com/user-attachments/assets/a5541a51-bdf6-4a47-9638-610d9562df6f) ### GLES ![image](https://github.com/user-attachments/assets/9f3ad7e1-8193-405d-98c0-49141c8ab662)
1 parent f9c6c6b commit 950e240

File tree

6 files changed

+80
-8
lines changed

6 files changed

+80
-8
lines changed

impeller/display_list/aiks_dl_unittests.cc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// Use of this source code is governed by a BSD-style license that can be
44
// found in the LICENSE file.
55

6+
#include <vector>
67
#include "display_list/dl_sampling_options.h"
78
#include "display_list/dl_tile_mode.h"
89
#include "display_list/effects/dl_color_filter.h"
910
#include "display_list/effects/dl_color_source.h"
1011
#include "display_list/effects/dl_image_filter.h"
1112
#include "display_list/geometry/dl_geometry_types.h"
13+
#include "display_list/geometry/dl_path.h"
1214
#include "display_list/image/dl_image.h"
1315
#include "flutter/impeller/display_list/aiks_unittests.h"
1416

@@ -21,7 +23,9 @@
2123
#include "impeller/display_list/dl_dispatcher.h"
2224
#include "impeller/display_list/dl_image_impeller.h"
2325
#include "impeller/geometry/scalar.h"
26+
#include "include/core/SkCanvas.h"
2427
#include "include/core/SkMatrix.h"
28+
#include "include/core/SkPath.h"
2529
#include "include/core/SkRSXform.h"
2630
#include "include/core/SkRefCnt.h"
2731

@@ -982,5 +986,63 @@ TEST_P(AiksTest, CanEmptyPictureConvertToImage) {
982986
ASSERT_TRUE(OpenPlaygroundHere(recorder_builder.Build()));
983987
}
984988

989+
TEST_P(AiksTest, DepthValuesForLineMode) {
990+
// Ensures that the additional draws created by line/polygon mode all
991+
// have the same depth values.
992+
DisplayListBuilder builder;
993+
994+
SkPath path = SkPath::Circle(100, 100, 100);
995+
996+
builder.DrawPath(path, DlPaint()
997+
.setColor(DlColor::kRed())
998+
.setDrawStyle(DlDrawStyle::kStroke)
999+
.setStrokeWidth(5));
1000+
builder.Save();
1001+
builder.ClipPath(path);
1002+
1003+
std::vector<DlPoint> points = {
1004+
DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
1005+
DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
1006+
DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
1007+
DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
1008+
DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
1009+
1010+
builder.DrawPoints(DisplayListBuilder::PointMode::kLines, points.size(),
1011+
points.data(),
1012+
DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
1013+
builder.Restore();
1014+
1015+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1016+
}
1017+
1018+
TEST_P(AiksTest, DepthValuesForPolygonMode) {
1019+
// Ensures that the additional draws created by line/polygon mode all
1020+
// have the same depth values.
1021+
DisplayListBuilder builder;
1022+
1023+
SkPath path = SkPath::Circle(100, 100, 100);
1024+
1025+
builder.DrawPath(path, DlPaint()
1026+
.setColor(DlColor::kRed())
1027+
.setDrawStyle(DlDrawStyle::kStroke)
1028+
.setStrokeWidth(5));
1029+
builder.Save();
1030+
builder.ClipPath(path);
1031+
1032+
std::vector<DlPoint> points = {
1033+
DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
1034+
DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
1035+
DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
1036+
DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
1037+
DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
1038+
1039+
builder.DrawPoints(DisplayListBuilder::PointMode::kPolygon, points.size(),
1040+
points.data(),
1041+
DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
1042+
builder.Restore();
1043+
1044+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1045+
}
1046+
9851047
} // namespace testing
9861048
} // namespace impeller

impeller/display_list/canvas.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,17 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
446446
return true;
447447
}
448448

449-
void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
449+
void Canvas::DrawLine(const Point& p0,
450+
const Point& p1,
451+
const Paint& paint,
452+
bool reuse_depth) {
450453
Entity entity;
451454
entity.SetTransform(GetCurrentTransform());
452455
entity.SetBlendMode(paint.blend_mode);
453456

454457
LineGeometry geom(p0, p1, paint.stroke_width, paint.stroke_cap);
455-
AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
458+
AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint,
459+
/*reuse_depth=*/reuse_depth);
456460
}
457461

458462
void Canvas::DrawRect(const Rect& rect, const Paint& paint) {
@@ -572,7 +576,6 @@ void Canvas::ClipGeometry(const Geometry& geometry,
572576
// See https://github.com/flutter/flutter/issues/147021
573577
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
574578
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
575-
576579
uint32_t clip_depth = transform_stack_.back().clip_depth;
577580

578581
const Matrix clip_transform =

impeller/display_list/canvas.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ class Canvas {
187187

188188
void DrawPaint(const Paint& paint);
189189

190-
void DrawLine(const Point& p0, const Point& p1, const Paint& paint);
190+
void DrawLine(const Point& p0,
191+
const Point& p1,
192+
const Paint& paint,
193+
bool reuse_depth = false);
191194

192195
void DrawRect(const Rect& rect, const Paint& paint);
193196

impeller/display_list/dl_dispatcher.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,15 @@ void DlDispatcherBase::drawPoints(PointMode mode,
676676
for (uint32_t i = 1; i < count; i += 2) {
677677
Point p0 = points[i - 1];
678678
Point p1 = points[i];
679-
GetCanvas().DrawLine(p0, p1, paint);
679+
GetCanvas().DrawLine(p0, p1, paint, /*reuse_depth=*/i > 1);
680680
}
681681
break;
682682
case flutter::DlCanvas::PointMode::kPolygon:
683683
if (count > 1) {
684684
Point p0 = points[0];
685685
for (uint32_t i = 1; i < count; i++) {
686686
Point p1 = points[i];
687-
GetCanvas().DrawLine(p0, p1, paint);
687+
GetCanvas().DrawLine(p0, p1, paint, /*reuse_depth=*/i > 1);
688688
p0 = p1;
689689
}
690690
}

impeller/renderer/backend/gles/render_pass_gles.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ static bool BindVertexBuffer(const ProcTableGLES& gl,
369369
scissor.GetWidth(), // width
370370
scissor.GetHeight() // height
371371
);
372-
} else {
373-
gl.Disable(GL_SCISSOR_TEST);
374372
}
375373

376374
//--------------------------------------------------------------------------

testing/impeller_golden_tests_output.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ impeller_Play_AiksTest_CoordinateConversionsAreCorrect_Vulkan.png
575575
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Metal.png
576576
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_OpenGLES.png
577577
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Vulkan.png
578+
impeller_Play_AiksTest_DepthValuesForLineMode_Metal.png
579+
impeller_Play_AiksTest_DepthValuesForLineMode_OpenGLES.png
580+
impeller_Play_AiksTest_DepthValuesForLineMode_Vulkan.png
581+
impeller_Play_AiksTest_DepthValuesForPolygonMode_Metal.png
582+
impeller_Play_AiksTest_DepthValuesForPolygonMode_OpenGLES.png
583+
impeller_Play_AiksTest_DepthValuesForPolygonMode_Vulkan.png
578584
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Metal.png
579585
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_OpenGLES.png
580586
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Vulkan.png

0 commit comments

Comments
 (0)