Flutter Engine
The Flutter Engine
Classes | Macros | Functions
addarc.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkPathMeasure.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkFloatingPoint.h"
#include "src/base/SkRandom.h"
#include "tools/ToolUtils.h"
#include "tools/timer/TimeUtils.h"

Go to the source code of this file.

Classes

class  AddArcGM
 
class  StrokeCircleGM
 
class  FillCircleGM
 

Macros

#define R   400
 

Functions

 DEF_SIMPLE_GM (addarc_meas, canvas, 2 *R+40, 2 *R+40)
 
static void html_canvas_arc (SkPathBuilder *path, SkScalar x, SkScalar y, SkScalar r, SkScalar start, SkScalar end, bool ccw, bool callArcTo)
 
 DEF_SIMPLE_GM (manyarcs, canvas, 620, 330)
 
 DEF_SIMPLE_GM (tinyanglearcs, canvas, 620, 330)
 

Macro Definition Documentation

◆ R

#define R   400

Definition at line 78 of file addarc.cpp.

Function Documentation

◆ DEF_SIMPLE_GM() [1/3]

DEF_SIMPLE_GM ( addarc_meas  ,
canvas  ,
2 *R 40,
2 *R 40 
)

Definition at line 80 of file addarc.cpp.

80 {
81 canvas->translate(R + 20, R + 20);
82
84 paint.setAntiAlias(true);
85 paint.setStroke(true);
86
87 SkPaint measPaint;
88 measPaint.setAntiAlias(true);
89 measPaint.setColor(SK_ColorRED);
90
91 const SkRect oval = SkRect::MakeLTRB(-R, -R, R, R);
92 canvas->drawOval(oval, paint);
93
94 for (SkScalar deg = 0; deg < 360; deg += 10) {
95 const SkScalar rad = SkDegreesToRadians(deg);
96 SkScalar rx = SkScalarCos(rad) * R;
97 SkScalar ry = SkScalarSin(rad) * R;
98
99 canvas->drawLine(0, 0, rx, ry, paint);
100
101 SkPathMeasure meas(SkPathBuilder().addArc(oval, 0, deg).detach(), false);
102 SkScalar arcLen = rad * R;
103 SkPoint pos;
104 if (meas.getPosTan(arcLen, &pos, nullptr)) {
105 canvas->drawLine({0, 0}, pos, measPaint);
106 }
107 }
108}
SkPoint pos
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define R
Definition: addarc.cpp:78
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
SkRect oval
Definition: SkRecords.h:249
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ DEF_SIMPLE_GM() [2/3]

DEF_SIMPLE_GM ( manyarcs  ,
canvas  ,
620  ,
330   
)

Definition at line 227 of file addarc.cpp.

227 {
229 paint.setAntiAlias(true);
230 paint.setStroke(true);
231
232 canvas->translate(10, 10);
233
234 // 20 angles.
235 SkScalar sweepAngles[] = {
236 -123.7f, -2.3f, -2, -1, -0.3f, -0.000001f, 0, 0.000001f, 0.3f, 0.7f,
237 1, 1.3f, 1.5f, 1.7f, 1.99999f, 2, 2.00001f, 2.3f, 4.3f, 3934723942837.3f
238 };
239 for (size_t i = 0; i < std::size(sweepAngles); ++i) {
240 sweepAngles[i] *= 180;
241 }
242
243 SkScalar startAngles[] = { -1, -0.5f, 0, 0.5f };
244 for (size_t i = 0; i < std::size(startAngles); ++i) {
245 startAngles[i] *= 180;
246 }
247
248 bool anticlockwise = false;
249 SkScalar sign = 1;
250 for (size_t i = 0; i < std::size(startAngles) * 2; ++i) {
251 if (i == std::size(startAngles)) {
252 anticlockwise = true;
253 sign = -1;
254 }
255 SkScalar startAngle = startAngles[i % std::size(startAngles)] * sign;
256 canvas->save();
257 for (size_t j = 0; j < std::size(sweepAngles); ++j) {
259 path.moveTo(0, 2);
260 html_canvas_arc(&path, 18, 15, 10, startAngle, startAngle + (sweepAngles[j] * sign),
261 anticlockwise, true);
262 path.lineTo(0, 28);
263 canvas->drawPath(path.detach().setIsVolatile(true), paint);
264 canvas->translate(30, 0);
265 }
266 canvas->restore();
267 canvas->translate(0, 40);
268 }
269}
static int sign(SkScalar x)
Definition: SkPath.cpp:2205
static void html_canvas_arc(SkPathBuilder *path, SkScalar x, SkScalar y, SkScalar r, SkScalar start, SkScalar end, bool ccw, bool callArcTo)
Definition: addarc.cpp:216
SkScalar startAngle
Definition: SkRecords.h:250
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ DEF_SIMPLE_GM() [3/3]

DEF_SIMPLE_GM ( tinyanglearcs  ,
canvas  ,
620  ,
330   
)

Definition at line 272 of file addarc.cpp.

272 {
274 paint.setAntiAlias(true);
275 paint.setStroke(true);
276
277 canvas->translate(50, 50);
278
279 SkScalar outerRadius = 100000.0f;
280 SkScalar innerRadius = outerRadius - 20.0f;
281 SkScalar centerX = 50;
282 SkScalar centerY = outerRadius;
283 SkScalar startAngles[] = { 1.5f * SK_ScalarPI , 1.501f * SK_ScalarPI };
284 SkScalar sweepAngle = 10.0f / outerRadius;
285
286 for (size_t i = 0; i < std::size(startAngles); ++i) {
288 SkScalar endAngle = startAngles[i] + sweepAngle;
289 path.moveTo(centerX + innerRadius * std::cos(startAngles[i]),
290 centerY + innerRadius * std::sin(startAngles[i]));
291 path.lineTo(centerX + outerRadius * std::cos(startAngles[i]),
292 centerY + outerRadius * std::sin(startAngles[i]));
293 // A combination of tiny sweepAngle + large radius, we should draw a line.
294 html_canvas_arc(&path, centerX, outerRadius, outerRadius,
295 startAngles[i] * 180 / SK_ScalarPI, endAngle * 180 / SK_ScalarPI,
296 true, true);
297 path.lineTo(centerX + innerRadius * std::cos(endAngle),
298 centerY + innerRadius * std::sin(endAngle));
299 html_canvas_arc(&path, centerX, outerRadius, innerRadius,
300 endAngle * 180 / SK_ScalarPI, startAngles[i] * 180 / SK_ScalarPI,
301 true, false);
302 canvas->drawPath(path.detach(), paint);
303 canvas->translate(20, 0);
304 }
305}
#define SK_ScalarPI
Definition: SkScalar.h:21
SkScalar sweepAngle
Definition: SkRecords.h:251

◆ html_canvas_arc()

static void html_canvas_arc ( SkPathBuilder path,
SkScalar  x,
SkScalar  y,
SkScalar  r,
SkScalar  start,
SkScalar  end,
bool  ccw,
bool  callArcTo 
)
static

Definition at line 216 of file addarc.cpp.

217 {
218 SkRect bounds = { x - r, y - r, x + r, y + r };
219 SkScalar sweep = ccw ? end - start : start - end;
220 if (callArcTo)
221 path->arcTo(bounds, start, sweep, false);
222 else
223 path->addArc(bounds, start, sweep);
224}
glong glong end
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189