[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  ### GLES 
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,8 +369,6 @@ static bool BindVertexBuffer(const ProcTableGLES& gl,
|
||||
scissor.GetWidth(), // width
|
||||
scissor.GetHeight() // height
|
||||
);
|
||||
} else {
|
||||
gl.Disable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user