Skip to content

Commit a6cd3eb

Browse files
authored
Fix lint errors in lib/ui (flutter#19988)
This fixes all of the lint errors in lib/ui, except for a few (three, I think) where it would have changed the API, converting non-const references to pointers. For those, I just did NOLINT on the particular line instead of ignoring the whole file.
1 parent 357b155 commit a6cd3eb

22 files changed

+244
-148
lines changed

lib/ui/painting/canvas.cc

Lines changed: 90 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/lib/ui/painting/canvas.h"
76

@@ -77,9 +76,11 @@ fml::RefPtr<Canvas> Canvas::Create(PictureRecorder* recorder,
7776
double top,
7877
double right,
7978
double bottom) {
80-
if (!recorder)
79+
if (!recorder) {
8180
Dart_ThrowException(
8281
ToDart("Canvas constructor called with non-genuine PictureRecorder."));
82+
return nullptr;
83+
}
8384
fml::RefPtr<Canvas> canvas = fml::MakeRefCounted<Canvas>(
8485
recorder->BeginRecording(SkRect::MakeLTRB(left, top, right, bottom)));
8586
recorder->set_canvas(canvas);
@@ -91,15 +92,17 @@ Canvas::Canvas(SkCanvas* canvas) : canvas_(canvas) {}
9192
Canvas::~Canvas() {}
9293

9394
void Canvas::save() {
94-
if (!canvas_)
95+
if (!canvas_) {
9596
return;
97+
}
9698
canvas_->save();
9799
}
98100

99101
void Canvas::saveLayerWithoutBounds(const Paint& paint,
100102
const PaintData& paint_data) {
101-
if (!canvas_)
103+
if (!canvas_) {
102104
return;
105+
}
103106
canvas_->saveLayer(nullptr, paint.paint());
104107
}
105108

@@ -109,51 +112,59 @@ void Canvas::saveLayer(double left,
109112
double bottom,
110113
const Paint& paint,
111114
const PaintData& paint_data) {
112-
if (!canvas_)
115+
if (!canvas_) {
113116
return;
117+
}
114118
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
115119
canvas_->saveLayer(&bounds, paint.paint());
116120
}
117121

118122
void Canvas::restore() {
119-
if (!canvas_)
123+
if (!canvas_) {
120124
return;
125+
}
121126
canvas_->restore();
122127
}
123128

124129
int Canvas::getSaveCount() {
125-
if (!canvas_)
130+
if (!canvas_) {
126131
return 0;
132+
}
127133
return canvas_->getSaveCount();
128134
}
129135

130136
void Canvas::translate(double dx, double dy) {
131-
if (!canvas_)
137+
if (!canvas_) {
132138
return;
139+
}
133140
canvas_->translate(dx, dy);
134141
}
135142

136143
void Canvas::scale(double sx, double sy) {
137-
if (!canvas_)
144+
if (!canvas_) {
138145
return;
146+
}
139147
canvas_->scale(sx, sy);
140148
}
141149

142150
void Canvas::rotate(double radians) {
143-
if (!canvas_)
151+
if (!canvas_) {
144152
return;
153+
}
145154
canvas_->rotate(radians * 180.0 / M_PI);
146155
}
147156

148157
void Canvas::skew(double sx, double sy) {
149-
if (!canvas_)
158+
if (!canvas_) {
150159
return;
160+
}
151161
canvas_->skew(sx, sy);
152162
}
153163

154164
void Canvas::transform(const tonic::Float64List& matrix4) {
155-
if (!canvas_)
165+
if (!canvas_) {
156166
return;
167+
}
157168
canvas_->concat(ToSkMatrix(matrix4));
158169
}
159170

@@ -163,31 +174,37 @@ void Canvas::clipRect(double left,
163174
double bottom,
164175
SkClipOp clipOp,
165176
bool doAntiAlias) {
166-
if (!canvas_)
177+
if (!canvas_) {
167178
return;
179+
}
168180
canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp,
169181
doAntiAlias);
170182
}
171183

172184
void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) {
173-
if (!canvas_)
185+
if (!canvas_) {
174186
return;
187+
}
175188
canvas_->clipRRect(rrect.sk_rrect, doAntiAlias);
176189
}
177190

178191
void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
179-
if (!canvas_)
192+
if (!canvas_) {
180193
return;
181-
if (!path)
194+
}
195+
if (!path) {
182196
Dart_ThrowException(
183197
ToDart("Canvas.clipPath called with non-genuine Path."));
198+
return;
199+
}
184200
external_allocation_size_ += path->path().approximateBytesUsed();
185201
canvas_->clipPath(path->path(), doAntiAlias);
186202
}
187203

188204
void Canvas::drawColor(SkColor color, SkBlendMode blend_mode) {
189-
if (!canvas_)
205+
if (!canvas_) {
190206
return;
207+
}
191208
canvas_->drawColor(color, blend_mode);
192209
}
193210

@@ -197,14 +214,16 @@ void Canvas::drawLine(double x1,
197214
double y2,
198215
const Paint& paint,
199216
const PaintData& paint_data) {
200-
if (!canvas_)
217+
if (!canvas_) {
201218
return;
219+
}
202220
canvas_->drawLine(x1, y1, x2, y2, *paint.paint());
203221
}
204222

205223
void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) {
206-
if (!canvas_)
224+
if (!canvas_) {
207225
return;
226+
}
208227
canvas_->drawPaint(*paint.paint());
209228
}
210229

@@ -214,25 +233,28 @@ void Canvas::drawRect(double left,
214233
double bottom,
215234
const Paint& paint,
216235
const PaintData& paint_data) {
217-
if (!canvas_)
236+
if (!canvas_) {
218237
return;
238+
}
219239
canvas_->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
220240
}
221241

222242
void Canvas::drawRRect(const RRect& rrect,
223243
const Paint& paint,
224244
const PaintData& paint_data) {
225-
if (!canvas_)
245+
if (!canvas_) {
226246
return;
247+
}
227248
canvas_->drawRRect(rrect.sk_rrect, *paint.paint());
228249
}
229250

230251
void Canvas::drawDRRect(const RRect& outer,
231252
const RRect& inner,
232253
const Paint& paint,
233254
const PaintData& paint_data) {
234-
if (!canvas_)
255+
if (!canvas_) {
235256
return;
257+
}
236258
canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
237259
}
238260

@@ -242,8 +264,9 @@ void Canvas::drawOval(double left,
242264
double bottom,
243265
const Paint& paint,
244266
const PaintData& paint_data) {
245-
if (!canvas_)
267+
if (!canvas_) {
246268
return;
269+
}
247270
canvas_->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
248271
}
249272

@@ -252,8 +275,9 @@ void Canvas::drawCircle(double x,
252275
double radius,
253276
const Paint& paint,
254277
const PaintData& paint_data) {
255-
if (!canvas_)
278+
if (!canvas_) {
256279
return;
280+
}
257281
canvas_->drawCircle(x, y, radius, *paint.paint());
258282
}
259283

@@ -266,8 +290,9 @@ void Canvas::drawArc(double left,
266290
bool useCenter,
267291
const Paint& paint,
268292
const PaintData& paint_data) {
269-
if (!canvas_)
293+
if (!canvas_) {
270294
return;
295+
}
271296
canvas_->drawArc(SkRect::MakeLTRB(left, top, right, bottom),
272297
startAngle * 180.0 / M_PI, sweepAngle * 180.0 / M_PI,
273298
useCenter, *paint.paint());
@@ -276,11 +301,14 @@ void Canvas::drawArc(double left,
276301
void Canvas::drawPath(const CanvasPath* path,
277302
const Paint& paint,
278303
const PaintData& paint_data) {
279-
if (!canvas_)
304+
if (!canvas_) {
280305
return;
281-
if (!path)
306+
}
307+
if (!path) {
282308
Dart_ThrowException(
283309
ToDart("Canvas.drawPath called with non-genuine Path."));
310+
return;
311+
}
284312
external_allocation_size_ += path->path().approximateBytesUsed();
285313
canvas_->drawPath(path->path(), *paint.paint());
286314
}
@@ -290,11 +318,14 @@ void Canvas::drawImage(const CanvasImage* image,
290318
double y,
291319
const Paint& paint,
292320
const PaintData& paint_data) {
293-
if (!canvas_)
321+
if (!canvas_) {
294322
return;
295-
if (!image)
323+
}
324+
if (!image) {
296325
Dart_ThrowException(
297326
ToDart("Canvas.drawImage called with non-genuine Image."));
327+
return;
328+
}
298329
external_allocation_size_ += image->GetAllocationSize();
299330
canvas_->drawImage(image->image(), x, y, paint.paint());
300331
}
@@ -310,11 +341,14 @@ void Canvas::drawImageRect(const CanvasImage* image,
310341
double dst_bottom,
311342
const Paint& paint,
312343
const PaintData& paint_data) {
313-
if (!canvas_)
344+
if (!canvas_) {
314345
return;
315-
if (!image)
346+
}
347+
if (!image) {
316348
Dart_ThrowException(
317349
ToDart("Canvas.drawImageRect called with non-genuine Image."));
350+
return;
351+
}
318352
SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom);
319353
SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
320354
external_allocation_size_ += image->GetAllocationSize();
@@ -333,11 +367,14 @@ void Canvas::drawImageNine(const CanvasImage* image,
333367
double dst_bottom,
334368
const Paint& paint,
335369
const PaintData& paint_data) {
336-
if (!canvas_)
370+
if (!canvas_) {
337371
return;
338-
if (!image)
372+
}
373+
if (!image) {
339374
Dart_ThrowException(
340375
ToDart("Canvas.drawImageNine called with non-genuine Image."));
376+
return;
377+
}
341378
SkRect center =
342379
SkRect::MakeLTRB(center_left, center_top, center_right, center_bottom);
343380
SkIRect icenter;
@@ -348,11 +385,14 @@ void Canvas::drawImageNine(const CanvasImage* image,
348385
}
349386

350387
void Canvas::drawPicture(Picture* picture) {
351-
if (!canvas_)
388+
if (!canvas_) {
352389
return;
353-
if (!picture)
390+
}
391+
if (!picture) {
354392
Dart_ThrowException(
355393
ToDart("Canvas.drawPicture called with non-genuine Picture."));
394+
return;
395+
}
356396
external_allocation_size_ += picture->GetAllocationSize();
357397
canvas_->drawPicture(picture->picture().get());
358398
}
@@ -361,8 +401,9 @@ void Canvas::drawPoints(const Paint& paint,
361401
const PaintData& paint_data,
362402
SkCanvas::PointMode point_mode,
363403
const tonic::Float32List& points) {
364-
if (!canvas_)
404+
if (!canvas_) {
365405
return;
406+
}
366407

367408
static_assert(sizeof(SkPoint) == sizeof(float) * 2,
368409
"SkPoint doesn't use floats.");
@@ -377,11 +418,14 @@ void Canvas::drawVertices(const Vertices* vertices,
377418
SkBlendMode blend_mode,
378419
const Paint& paint,
379420
const PaintData& paint_data) {
380-
if (!canvas_)
421+
if (!canvas_) {
381422
return;
382-
if (!vertices)
423+
}
424+
if (!vertices) {
383425
Dart_ThrowException(
384426
ToDart("Canvas.drawVertices called with non-genuine Vertices."));
427+
return;
428+
}
385429
external_allocation_size_ += vertices->GetAllocationSize();
386430
canvas_->drawVertices(vertices->vertices(), blend_mode, *paint.paint());
387431
}
@@ -394,12 +438,15 @@ void Canvas::drawAtlas(const Paint& paint,
394438
const tonic::Int32List& colors,
395439
SkBlendMode blend_mode,
396440
const tonic::Float32List& cull_rect) {
397-
if (!canvas_)
441+
if (!canvas_) {
398442
return;
399-
if (!atlas)
443+
}
444+
if (!atlas) {
400445
Dart_ThrowException(
401446
ToDart("Canvas.drawAtlas or Canvas.drawRawAtlas called with "
402447
"non-genuine Image."));
448+
return;
449+
}
403450

404451
sk_sp<SkImage> skImage = atlas->image();
405452

@@ -422,9 +469,11 @@ void Canvas::drawShadow(const CanvasPath* path,
422469
SkColor color,
423470
double elevation,
424471
bool transparentOccluder) {
425-
if (!path)
472+
if (!path) {
426473
Dart_ThrowException(
427474
ToDart("Canvas.drawShader called with non-genuine Path."));
475+
return;
476+
}
428477
SkScalar dpr =
429478
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
430479
external_allocation_size_ += path->path().approximateBytesUsed();

lib/ui/painting/image_decoder_unittests.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/common/task_runners.h"
76
#include "flutter/fml/mapping.h"
@@ -23,8 +22,8 @@ namespace testing {
2322

2423
class TestIOManager final : public IOManager {
2524
public:
26-
TestIOManager(fml::RefPtr<fml::TaskRunner> task_runner,
27-
bool has_gpu_context = true)
25+
explicit TestIOManager(fml::RefPtr<fml::TaskRunner> task_runner,
26+
bool has_gpu_context = true)
2827
: gl_surface_(SkISize::Make(1, 1)),
2928
gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
3029
weak_gl_context_factory_(

0 commit comments

Comments
 (0)