Flutter Engine
The Flutter Engine
strokerect_anisotropic.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
10#include "include/core/SkPath.h"
11
12static void draw_sqooshed_rect(SkCanvas* canvas, SkVector xlate, const SkPaint& p) {
13 canvas->save();
14 canvas->translate(xlate.fX, xlate.fY);
15 canvas->scale(0.03f, 2.0f);
16 canvas->drawRect(SkRect::MakeLTRB(-500, -10, 500, 10), p);
17 canvas->restore();
18}
19
20/*
21 * This GM is intended to wring out any lingering anisotropic
22 * stroke rect bugs. It contains a repro case for crbug.com/935303
23 * The pattern is:
24 *
25 * miter @ miter @ bevel @ bevel @
26 * whole pixels half pixels whole pixels half pixels
27 *
28 * AA
29 *
30 * non-AA
31 *
32 */
34public:
36
37protected:
38 SkString getName() const override { return SkString("strokerect_anisotropic"); }
39
40 SkISize getISize() override { return SkISize::Make(160, 160); }
41
42 void onDraw(SkCanvas* canvas) override {
43
44 SkPaint aaPaint;
45 aaPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
46 aaPaint.setAntiAlias(true);
47 aaPaint.setStrokeWidth(10);
49
50 SkPaint bwPaint;
51 bwPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
52 bwPaint.setStrokeWidth(10);
54
55 // The two miter columns
56 draw_sqooshed_rect(canvas, { 20.0f, 40.5f }, aaPaint); // whole pixels
57 draw_sqooshed_rect(canvas, { 20.0f, 110.5f }, bwPaint); // whole pixels
58
59 draw_sqooshed_rect(canvas, { 60.5f, 40.0f }, aaPaint); // half pixels
60 draw_sqooshed_rect(canvas, { 60.5f, 110.0f }, bwPaint); // half pixels
61
64
65 // The two bevel columns
66 draw_sqooshed_rect(canvas, { 100.0f, 40.5f }, aaPaint); // whole pixels
67 draw_sqooshed_rect(canvas, { 100.0f, 110.5f }, bwPaint); // whole pixels
68
69 draw_sqooshed_rect(canvas, { 140.5f, 40.0f }, aaPaint); // half pixels
70 draw_sqooshed_rect(canvas, { 140.5f, 110.0f }, bwPaint); // half pixels
71 }
72
73private:
74 using INHERITED = GM;
75};
77
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
SkString getName() const override
void onDraw(SkCanvas *canvas) override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
#define DEF_GM(CODE)
Definition: gm.h:40
static void draw_sqooshed_rect(SkCanvas *canvas, SkVector xlate, const SkPaint &p)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646