Make display_list/... compatible with .clang_tidy. (flutter/engine#48147)

This commit is contained in:
Matan Lurey
2023-11-17 16:21:14 -08:00
committed by GitHub
parent ddce052e36
commit 8ee0e2f7e1
11 changed files with 54 additions and 53 deletions

View File

@@ -23,23 +23,23 @@ namespace testing {
DlPaint GetPaintForRun(unsigned attributes) {
DlPaint paint;
if (attributes & kStrokedStyle_Flag && attributes & kFilledStyle_Flag) {
if (attributes & kStrokedStyle && attributes & kFilledStyle) {
// Not currently exposed by Flutter, but we can probably benchmark this in
// the future
paint.setDrawStyle(DlDrawStyle::kStrokeAndFill);
} else if (attributes & kStrokedStyle_Flag) {
} else if (attributes & kStrokedStyle) {
paint.setDrawStyle(DlDrawStyle::kStroke);
} else if (attributes & kFilledStyle_Flag) {
} else if (attributes & kFilledStyle) {
paint.setDrawStyle(DlDrawStyle::kFill);
}
if (attributes & kHairlineStroke_Flag) {
if (attributes & kHairlineStroke) {
paint.setStrokeWidth(0.0f);
} else {
paint.setStrokeWidth(1.0f);
}
paint.setAntiAlias(attributes & kAntiAliasing_Flag);
paint.setAntiAlias(attributes & kAntiAliasing);
return paint;
}
@@ -57,17 +57,15 @@ void AnnotateAttributes(unsigned attributes,
benchmark::State& state,
const DisplayListAttributeFlags flags) {
if (flags.always_stroked()) {
state.counters["HairlineStroke"] =
attributes & kHairlineStroke_Flag ? 1 : 0;
state.counters["HairlineStroke"] = attributes & kHairlineStroke ? 1 : 0;
}
if (flags.applies_style()) {
state.counters["HairlineStroke"] =
attributes & kHairlineStroke_Flag ? 1 : 0;
state.counters["StrokedStyle"] = attributes & kStrokedStyle_Flag ? 1 : 0;
state.counters["FilledStyle"] = attributes & kFilledStyle_Flag ? 1 : 0;
state.counters["HairlineStroke"] = attributes & kHairlineStroke ? 1 : 0;
state.counters["StrokedStyle"] = attributes & kStrokedStyle ? 1 : 0;
state.counters["FilledStyle"] = attributes & kFilledStyle ? 1 : 0;
}
if (flags.applies_anti_alias()) {
state.counters["AntiAliasing"] = attributes & kAntiAliasing_Flag ? 1 : 0;
state.counters["AntiAliasing"] = attributes & kAntiAliasing ? 1 : 0;
}
}

View File

@@ -21,11 +21,11 @@ namespace flutter {
namespace testing {
enum BenchmarkAttributes {
kEmpty_Flag = 0,
kStrokedStyle_Flag = 1 << 0,
kFilledStyle_Flag = 1 << 1,
kHairlineStroke_Flag = 1 << 2,
kAntiAliasing_Flag = 1 << 3
kEmpty = 0,
kStrokedStyle = 1 << 0,
kFilledStyle = 1 << 1,
kHairlineStroke = 1 << 2,
kAntiAliasing = 1 << 3
};
DlPaint GetPaintForRun(unsigned attributes);
@@ -570,17 +570,17 @@ void BM_SaveLayer(benchmark::State& state,
DRAW_SHADOW_BENCHMARKS(BACKEND, ATTRIBUTES) \
SAVE_LAYER_BENCHMARKS(BACKEND, ATTRIBUTES)
#define RUN_DISPLAYLIST_BENCHMARKS(BACKEND) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle_Flag) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle_Flag | kAntiAliasing_Flag) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle_Flag | kHairlineStroke_Flag) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle_Flag | kHairlineStroke_Flag | \
kAntiAliasing_Flag) \
FILL_BENCHMARKS(BACKEND, kFilledStyle_Flag) \
FILL_BENCHMARKS(BACKEND, kFilledStyle_Flag | kAntiAliasing_Flag) \
ANTI_ALIASING_BENCHMARKS(BACKEND, kEmpty_Flag) \
ANTI_ALIASING_BENCHMARKS(BACKEND, kAntiAliasing_Flag) \
OTHER_BENCHMARKS(BACKEND, kEmpty_Flag)
#define RUN_DISPLAYLIST_BENCHMARKS(BACKEND) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle | kAntiAliasing) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle | kHairlineStroke) \
STROKE_BENCHMARKS(BACKEND, kStrokedStyle | kHairlineStroke | \
kAntiAliasing) \
FILL_BENCHMARKS(BACKEND, kFilledStyle) \
FILL_BENCHMARKS(BACKEND, kFilledStyle | kAntiAliasing) \
ANTI_ALIASING_BENCHMARKS(BACKEND, kEmpty) \
ANTI_ALIASING_BENCHMARKS(BACKEND, kAntiAliasing) \
OTHER_BENCHMARKS(BACKEND, kEmpty)
// clang-format on

View File

@@ -33,9 +33,7 @@ class DisplayListGLComplexityCalculator
class GLHelper : public ComplexityCalculatorHelper {
public:
explicit GLHelper(unsigned int ceiling)
: ComplexityCalculatorHelper(ceiling),
save_layer_count_(0),
draw_text_blob_count_(0) {}
: ComplexityCalculatorHelper(ceiling) {}
void saveLayer(const SkRect* bounds,
const SaveLayerOptions options,
@@ -88,8 +86,8 @@ class DisplayListGLComplexityCalculator
unsigned int BatchedComplexity() override;
private:
unsigned int save_layer_count_;
unsigned int draw_text_blob_count_;
unsigned int save_layer_count_ = 0;
unsigned int draw_text_blob_count_ = 0;
};
DisplayListGLComplexityCalculator()

View File

@@ -1075,7 +1075,7 @@ TEST_F(DisplayListTest, SingleOpsMightSupportGroupOpacityBlendMode) {
SkPath().addOval({0, 0, 10, 10}).addOval({5, 5, 15, 15})););
RUN_TESTS(receiver.drawArc({0, 0, 10, 10}, 0, math::kPi, true););
RUN_TESTS2(
receiver.drawPoints(PointMode::kPoints, TestPointCount, TestPoints);
receiver.drawPoints(PointMode::kPoints, TestPointCount, kTestPoints);
, false);
RUN_TESTS2(receiver.drawVertices(TestVertices1.get(), DlBlendMode::kSrc);
, false);

View File

@@ -203,8 +203,7 @@ DlVertices::Builder::Builder(DlVertexMode mode,
int vertex_count,
Flags flags,
int index_count)
: needs_vertices_(true),
needs_texture_coords_(flags.has_texture_coordinates),
: needs_texture_coords_(flags.has_texture_coordinates),
needs_colors_(flags.has_colors),
needs_indices_(index_count > 0) {
vertex_count = std::max(vertex_count, 0);

View File

@@ -165,7 +165,7 @@ class DlVertices {
private:
std::shared_ptr<DlVertices> vertices_;
bool needs_vertices_;
bool needs_vertices_ = true;
bool needs_texture_coords_;
bool needs_colors_;
bool needs_indices_;

View File

@@ -14,7 +14,7 @@ DlRTree::DlRTree(const SkRect rects[],
const int ids[],
bool p(int),
int invalid_id)
: leaf_count_(0), invalid_id_(invalid_id) {
: invalid_id_(invalid_id) {
if (N <= 0) {
FML_DCHECK(N >= 0);
return;

View File

@@ -144,7 +144,7 @@ class DlRTree : public SkRefCnt {
std::vector<int>* results) const;
std::vector<Node> nodes_;
int leaf_count_;
int leaf_count_ = 0;
int invalid_id_;
mutable std::optional<DlRegion> region_;
};

View File

@@ -79,7 +79,8 @@ inline SkCanvas::PointMode ToSk(DlCanvas::PointMode mode) {
}
extern sk_sp<SkShader> ToSk(const DlColorSource* source);
inline sk_sp<SkShader> ToSk(std::shared_ptr<const DlColorSource> source) {
inline sk_sp<SkShader> ToSk(
const std::shared_ptr<const DlColorSource>& source) {
return ToSk(source.get());
}
inline sk_sp<SkShader> ToSk(const DlColorSource& source) {
@@ -87,7 +88,8 @@ inline sk_sp<SkShader> ToSk(const DlColorSource& source) {
}
extern sk_sp<SkImageFilter> ToSk(const DlImageFilter* filter);
inline sk_sp<SkImageFilter> ToSk(std::shared_ptr<const DlImageFilter> filter) {
inline sk_sp<SkImageFilter> ToSk(
const std::shared_ptr<const DlImageFilter>& filter) {
return ToSk(filter.get());
}
inline sk_sp<SkImageFilter> ToSk(const DlImageFilter& filter) {
@@ -95,7 +97,8 @@ inline sk_sp<SkImageFilter> ToSk(const DlImageFilter& filter) {
}
extern sk_sp<SkColorFilter> ToSk(const DlColorFilter* filter);
inline sk_sp<SkColorFilter> ToSk(std::shared_ptr<const DlColorFilter> filter) {
inline sk_sp<SkColorFilter> ToSk(
const std::shared_ptr<const DlColorFilter>& filter) {
return ToSk(filter.get());
}
inline sk_sp<SkColorFilter> ToSk(const DlColorFilter& filter) {
@@ -103,7 +106,8 @@ inline sk_sp<SkColorFilter> ToSk(const DlColorFilter& filter) {
}
extern sk_sp<SkMaskFilter> ToSk(const DlMaskFilter* filter);
inline sk_sp<SkMaskFilter> ToSk(std::shared_ptr<const DlMaskFilter> filter) {
inline sk_sp<SkMaskFilter> ToSk(
const std::shared_ptr<const DlMaskFilter>& filter) {
return ToSk(filter.get());
}
inline sk_sp<SkMaskFilter> ToSk(const DlMaskFilter& filter) {
@@ -111,7 +115,8 @@ inline sk_sp<SkMaskFilter> ToSk(const DlMaskFilter& filter) {
}
extern sk_sp<SkPathEffect> ToSk(const DlPathEffect* effect);
inline sk_sp<SkPathEffect> ToSk(std::shared_ptr<const DlPathEffect> effect) {
inline sk_sp<SkPathEffect> ToSk(
const std::shared_ptr<const DlPathEffect>& effect) {
return ToSk(effect.get());
}
inline sk_sp<SkPathEffect> ToSk(const DlPathEffect& effect) {
@@ -119,7 +124,8 @@ inline sk_sp<SkPathEffect> ToSk(const DlPathEffect& effect) {
}
extern sk_sp<SkVertices> ToSk(const DlVertices* vertices);
inline sk_sp<SkVertices> ToSk(std::shared_ptr<const DlVertices> vertices) {
inline sk_sp<SkVertices> ToSk(
const std::shared_ptr<const DlVertices>& vertices) {
return ToSk(vertices.get());
}
inline sk_sp<SkVertices> ToSk(const DlVertices& vertices) {

View File

@@ -640,22 +640,22 @@ std::vector<DisplayListInvocationGroup> CreateAllRenderingOps() {
{1, 8 + TestPointCount * 8, 1, 8 + TestPointCount * 8,
[](DlOpReceiver& r) {
r.drawPoints(DlCanvas::PointMode::kPoints, TestPointCount,
TestPoints);
kTestPoints);
}},
{1, 8 + (TestPointCount - 1) * 8, 1, 8 + (TestPointCount - 1) * 8,
[](DlOpReceiver& r) {
r.drawPoints(DlCanvas::PointMode::kPoints, TestPointCount - 1,
TestPoints);
kTestPoints);
}},
{1, 8 + TestPointCount * 8, 1, 8 + TestPointCount * 8,
[](DlOpReceiver& r) {
r.drawPoints(DlCanvas::PointMode::kLines, TestPointCount,
TestPoints);
kTestPoints);
}},
{1, 8 + TestPointCount * 8, 1, 8 + TestPointCount * 8,
[](DlOpReceiver& r) {
r.drawPoints(DlCanvas::PointMode::kPolygon, TestPointCount,
TestPoints);
kTestPoints);
}},
}},
{"DrawVertices",

View File

@@ -57,13 +57,13 @@ constexpr float kInvertColorMatrix[20] = {
const SkScalar kTestDashes1[] = {4.0, 2.0};
const SkScalar kTestDashes2[] = {1.0, 1.5};
constexpr SkPoint TestPoints[] = {
constexpr SkPoint kTestPoints[] = {
{10, 10},
{20, 20},
{10, 20},
{20, 10},
};
#define TestPointCount sizeof(TestPoints) / (sizeof(TestPoints[0]))
#define TestPointCount sizeof(kTestPoints) / (sizeof(kTestPoints[0]))
static DlImageSampling kNearestSampling = DlImageSampling::kNearestNeighbor;
static DlImageSampling kLinearSampling = DlImageSampling::kLinear;
@@ -203,13 +203,13 @@ static const SkMatrix kTestMatrix2 = SkMatrix::RotateDeg(45);
static std::shared_ptr<const DlVertices> TestVertices1 =
DlVertices::Make(DlVertexMode::kTriangles, //
3,
TestPoints,
kTestPoints,
nullptr,
kColors);
static std::shared_ptr<const DlVertices> TestVertices2 =
DlVertices::Make(DlVertexMode::kTriangleFan, //
3,
TestPoints,
kTestPoints,
nullptr,
kColors);