Skip to content

Commit

Permalink
Fix lint errors in lib/ui (#19988)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gspencergoog committed Jul 31, 2020
1 parent 357b155 commit a6cd3eb
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 148 deletions.
131 changes: 90 additions & 41 deletions lib/ui/painting/canvas.cc
@@ -1,7 +1,6 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// FLUTTER_NOLINT

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

Expand Down Expand Up @@ -77,9 +76,11 @@ fml::RefPtr<Canvas> Canvas::Create(PictureRecorder* recorder,
double top,
double right,
double bottom) {
if (!recorder)
if (!recorder) {
Dart_ThrowException(
ToDart("Canvas constructor called with non-genuine PictureRecorder."));
return nullptr;
}
fml::RefPtr<Canvas> canvas = fml::MakeRefCounted<Canvas>(
recorder->BeginRecording(SkRect::MakeLTRB(left, top, right, bottom)));
recorder->set_canvas(canvas);
Expand All @@ -91,15 +92,17 @@ Canvas::Canvas(SkCanvas* canvas) : canvas_(canvas) {}
Canvas::~Canvas() {}

void Canvas::save() {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->save();
}

void Canvas::saveLayerWithoutBounds(const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->saveLayer(nullptr, paint.paint());
}

Expand All @@ -109,51 +112,59 @@ void Canvas::saveLayer(double left,
double bottom,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
canvas_->saveLayer(&bounds, paint.paint());
}

void Canvas::restore() {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->restore();
}

int Canvas::getSaveCount() {
if (!canvas_)
if (!canvas_) {
return 0;
}
return canvas_->getSaveCount();
}

void Canvas::translate(double dx, double dy) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->translate(dx, dy);
}

void Canvas::scale(double sx, double sy) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->scale(sx, sy);
}

void Canvas::rotate(double radians) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->rotate(radians * 180.0 / M_PI);
}

void Canvas::skew(double sx, double sy) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->skew(sx, sy);
}

void Canvas::transform(const tonic::Float64List& matrix4) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->concat(ToSkMatrix(matrix4));
}

Expand All @@ -163,31 +174,37 @@ void Canvas::clipRect(double left,
double bottom,
SkClipOp clipOp,
bool doAntiAlias) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp,
doAntiAlias);
}

void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->clipRRect(rrect.sk_rrect, doAntiAlias);
}

void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
if (!canvas_)
if (!canvas_) {
return;
if (!path)
}
if (!path) {
Dart_ThrowException(
ToDart("Canvas.clipPath called with non-genuine Path."));
return;
}
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->clipPath(path->path(), doAntiAlias);
}

void Canvas::drawColor(SkColor color, SkBlendMode blend_mode) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawColor(color, blend_mode);
}

Expand All @@ -197,14 +214,16 @@ void Canvas::drawLine(double x1,
double y2,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawLine(x1, y1, x2, y2, *paint.paint());
}

void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawPaint(*paint.paint());
}

Expand All @@ -214,25 +233,28 @@ void Canvas::drawRect(double left,
double bottom,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
}

void Canvas::drawRRect(const RRect& rrect,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawRRect(rrect.sk_rrect, *paint.paint());
}

void Canvas::drawDRRect(const RRect& outer,
const RRect& inner,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
}

Expand All @@ -242,8 +264,9 @@ void Canvas::drawOval(double left,
double bottom,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
}

Expand All @@ -252,8 +275,9 @@ void Canvas::drawCircle(double x,
double radius,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawCircle(x, y, radius, *paint.paint());
}

Expand All @@ -266,8 +290,9 @@ void Canvas::drawArc(double left,
bool useCenter,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
}
canvas_->drawArc(SkRect::MakeLTRB(left, top, right, bottom),
startAngle * 180.0 / M_PI, sweepAngle * 180.0 / M_PI,
useCenter, *paint.paint());
Expand All @@ -276,11 +301,14 @@ void Canvas::drawArc(double left,
void Canvas::drawPath(const CanvasPath* path,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
if (!path)
}
if (!path) {
Dart_ThrowException(
ToDart("Canvas.drawPath called with non-genuine Path."));
return;
}
external_allocation_size_ += path->path().approximateBytesUsed();
canvas_->drawPath(path->path(), *paint.paint());
}
Expand All @@ -290,11 +318,14 @@ void Canvas::drawImage(const CanvasImage* image,
double y,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
if (!image)
}
if (!image) {
Dart_ThrowException(
ToDart("Canvas.drawImage called with non-genuine Image."));
return;
}
external_allocation_size_ += image->GetAllocationSize();
canvas_->drawImage(image->image(), x, y, paint.paint());
}
Expand All @@ -310,11 +341,14 @@ void Canvas::drawImageRect(const CanvasImage* image,
double dst_bottom,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
if (!image)
}
if (!image) {
Dart_ThrowException(
ToDart("Canvas.drawImageRect called with non-genuine Image."));
return;
}
SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom);
SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
external_allocation_size_ += image->GetAllocationSize();
Expand All @@ -333,11 +367,14 @@ void Canvas::drawImageNine(const CanvasImage* image,
double dst_bottom,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
if (!image)
}
if (!image) {
Dart_ThrowException(
ToDart("Canvas.drawImageNine called with non-genuine Image."));
return;
}
SkRect center =
SkRect::MakeLTRB(center_left, center_top, center_right, center_bottom);
SkIRect icenter;
Expand All @@ -348,11 +385,14 @@ void Canvas::drawImageNine(const CanvasImage* image,
}

void Canvas::drawPicture(Picture* picture) {
if (!canvas_)
if (!canvas_) {
return;
if (!picture)
}
if (!picture) {
Dart_ThrowException(
ToDart("Canvas.drawPicture called with non-genuine Picture."));
return;
}
external_allocation_size_ += picture->GetAllocationSize();
canvas_->drawPicture(picture->picture().get());
}
Expand All @@ -361,8 +401,9 @@ void Canvas::drawPoints(const Paint& paint,
const PaintData& paint_data,
SkCanvas::PointMode point_mode,
const tonic::Float32List& points) {
if (!canvas_)
if (!canvas_) {
return;
}

static_assert(sizeof(SkPoint) == sizeof(float) * 2,
"SkPoint doesn't use floats.");
Expand All @@ -377,11 +418,14 @@ void Canvas::drawVertices(const Vertices* vertices,
SkBlendMode blend_mode,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
if (!canvas_) {
return;
if (!vertices)
}
if (!vertices) {
Dart_ThrowException(
ToDart("Canvas.drawVertices called with non-genuine Vertices."));
return;
}
external_allocation_size_ += vertices->GetAllocationSize();
canvas_->drawVertices(vertices->vertices(), blend_mode, *paint.paint());
}
Expand All @@ -394,12 +438,15 @@ void Canvas::drawAtlas(const Paint& paint,
const tonic::Int32List& colors,
SkBlendMode blend_mode,
const tonic::Float32List& cull_rect) {
if (!canvas_)
if (!canvas_) {
return;
if (!atlas)
}
if (!atlas) {
Dart_ThrowException(
ToDart("Canvas.drawAtlas or Canvas.drawRawAtlas called with "
"non-genuine Image."));
return;
}

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

Expand All @@ -422,9 +469,11 @@ void Canvas::drawShadow(const CanvasPath* path,
SkColor color,
double elevation,
bool transparentOccluder) {
if (!path)
if (!path) {
Dart_ThrowException(
ToDart("Canvas.drawShader called with non-genuine Path."));
return;
}
SkScalar dpr =
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
external_allocation_size_ += path->path().approximateBytesUsed();
Expand Down
5 changes: 2 additions & 3 deletions lib/ui/painting/image_decoder_unittests.cc
@@ -1,7 +1,6 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// FLUTTER_NOLINT

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

class TestIOManager final : public IOManager {
public:
TestIOManager(fml::RefPtr<fml::TaskRunner> task_runner,
bool has_gpu_context = true)
explicit TestIOManager(fml::RefPtr<fml::TaskRunner> task_runner,
bool has_gpu_context = true)
: gl_surface_(SkISize::Make(1, 1)),
gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
weak_gl_context_factory_(
Expand Down

0 comments on commit a6cd3eb

Please sign in to comment.