[Impeller] fix line/polygon depth and GLES scissor state. (flutter/engine#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)
This commit is contained in:
Jonah Williams
2024-11-11 11:59:53 -08:00
committed by GitHub
parent ef5c2fc014
commit 0489b6bbab
6 changed files with 80 additions and 8 deletions

View File

@@ -3,12 +3,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "display_list/dl_sampling_options.h"
#include "display_list/dl_tile_mode.h"
#include "display_list/effects/dl_color_filter.h"
#include "display_list/effects/dl_color_source.h"
#include "display_list/effects/dl_image_filter.h"
#include "display_list/geometry/dl_geometry_types.h"
#include "display_list/geometry/dl_path.h"
#include "display_list/image/dl_image.h"
#include "flutter/impeller/display_list/aiks_unittests.h"
@@ -21,7 +23,9 @@
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/display_list/dl_image_impeller.h"
#include "impeller/geometry/scalar.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPath.h"
#include "include/core/SkRSXform.h"
#include "include/core/SkRefCnt.h"
@@ -982,5 +986,63 @@ TEST_P(AiksTest, CanEmptyPictureConvertToImage) {
ASSERT_TRUE(OpenPlaygroundHere(recorder_builder.Build()));
}
TEST_P(AiksTest, DepthValuesForLineMode) {
// Ensures that the additional draws created by line/polygon mode all
// have the same depth values.
DisplayListBuilder builder;
SkPath path = SkPath::Circle(100, 100, 100);
builder.DrawPath(path, DlPaint()
.setColor(DlColor::kRed())
.setDrawStyle(DlDrawStyle::kStroke)
.setStrokeWidth(5));
builder.Save();
builder.ClipPath(path);
std::vector<DlPoint> points = {
DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
builder.DrawPoints(DisplayListBuilder::PointMode::kLines, points.size(),
points.data(),
DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
builder.Restore();
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(AiksTest, DepthValuesForPolygonMode) {
// Ensures that the additional draws created by line/polygon mode all
// have the same depth values.
DisplayListBuilder builder;
SkPath path = SkPath::Circle(100, 100, 100);
builder.DrawPath(path, DlPaint()
.setColor(DlColor::kRed())
.setDrawStyle(DlDrawStyle::kStroke)
.setStrokeWidth(5));
builder.Save();
builder.ClipPath(path);
std::vector<DlPoint> points = {
DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
builder.DrawPoints(DisplayListBuilder::PointMode::kPolygon, points.size(),
points.data(),
DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
builder.Restore();
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
} // namespace testing
} // namespace impeller

View File

@@ -446,13 +446,17 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
return true;
}
void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
void Canvas::DrawLine(const Point& p0,
const Point& p1,
const Paint& paint,
bool reuse_depth) {
Entity entity;
entity.SetTransform(GetCurrentTransform());
entity.SetBlendMode(paint.blend_mode);
LineGeometry geom(p0, p1, paint.stroke_width, paint.stroke_cap);
AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint,
/*reuse_depth=*/reuse_depth);
}
void Canvas::DrawRect(const Rect& rect, const Paint& paint) {
@@ -572,7 +576,6 @@ void Canvas::ClipGeometry(const Geometry& geometry,
// See https://github.com/flutter/flutter/issues/147021
FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
<< current_depth_ << " <=? " << transform_stack_.back().clip_depth;
uint32_t clip_depth = transform_stack_.back().clip_depth;
const Matrix clip_transform =

View File

@@ -187,7 +187,10 @@ class Canvas {
void DrawPaint(const Paint& paint);
void DrawLine(const Point& p0, const Point& p1, const Paint& paint);
void DrawLine(const Point& p0,
const Point& p1,
const Paint& paint,
bool reuse_depth = false);
void DrawRect(const Rect& rect, const Paint& paint);

View File

@@ -676,7 +676,7 @@ void DlDispatcherBase::drawPoints(PointMode mode,
for (uint32_t i = 1; i < count; i += 2) {
Point p0 = points[i - 1];
Point p1 = points[i];
GetCanvas().DrawLine(p0, p1, paint);
GetCanvas().DrawLine(p0, p1, paint, /*reuse_depth=*/i > 1);
}
break;
case flutter::DlCanvas::PointMode::kPolygon:
@@ -684,7 +684,7 @@ void DlDispatcherBase::drawPoints(PointMode mode,
Point p0 = points[0];
for (uint32_t i = 1; i < count; i++) {
Point p1 = points[i];
GetCanvas().DrawLine(p0, p1, paint);
GetCanvas().DrawLine(p0, p1, paint, /*reuse_depth=*/i > 1);
p0 = p1;
}
}

View File

@@ -369,8 +369,6 @@ static bool BindVertexBuffer(const ProcTableGLES& gl,
scissor.GetWidth(), // width
scissor.GetHeight() // height
);
} else {
gl.Disable(GL_SCISSOR_TEST);
}
//--------------------------------------------------------------------------

View File

@@ -575,6 +575,12 @@ impeller_Play_AiksTest_CoordinateConversionsAreCorrect_Vulkan.png
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Metal.png
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_OpenGLES.png
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Vulkan.png
impeller_Play_AiksTest_DepthValuesForLineMode_Metal.png
impeller_Play_AiksTest_DepthValuesForLineMode_OpenGLES.png
impeller_Play_AiksTest_DepthValuesForLineMode_Vulkan.png
impeller_Play_AiksTest_DepthValuesForPolygonMode_Metal.png
impeller_Play_AiksTest_DepthValuesForPolygonMode_OpenGLES.png
impeller_Play_AiksTest_DepthValuesForPolygonMode_Vulkan.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Metal.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_OpenGLES.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Vulkan.png