2013-06-20 16:54:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#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/SkFloatBits.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
2013-06-20 16:54:31 +00:00
|
|
|
|
2015-01-01 04:07:01 +00:00
|
|
|
class ConicPathsGM : public skiagm::GM {
|
2013-06-20 16:54:31 +00:00
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-06-20 16:54:31 +00:00
|
|
|
return SkString("conicpaths");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2015-01-05 18:01:25 +00:00
|
|
|
return SkISize::Make(920, 960);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2013-06-20 16:54:31 +00:00
|
|
|
{
|
2015-01-01 04:07:01 +00:00
|
|
|
const SkScalar w = SkScalarSqrt(2)/2;
|
2013-06-20 16:54:31 +00:00
|
|
|
SkPath* conicCirlce = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
conicCirlce->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
conicCirlce->conicTo(0, 50, 50, 50, w);
|
|
|
|
conicCirlce->rConicTo(50, 0, 50, -50, w);
|
|
|
|
conicCirlce->rConicTo(0, -50, -50, -50, w);
|
|
|
|
conicCirlce->rConicTo(-50, 0, -50, 50, w);
|
2013-06-20 16:54:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* hyperbola = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
hyperbola->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
hyperbola->conicTo(0, 100, 100, 100, 2);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* thinHyperbola = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
thinHyperbola->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
thinHyperbola->conicTo(100, 100, 5, 0, 2);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* veryThinHyperbola = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
veryThinHyperbola->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
veryThinHyperbola->conicTo(100, 100, 1, 0, 2);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* closedHyperbola = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
closedHyperbola->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
closedHyperbola->conicTo(100, 100, 0, 0, 2);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// using 1 as weight defaults to using quadTo
|
|
|
|
SkPath* nearParabola = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
nearParabola->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
nearParabola->conicTo(0, 100, 100, 100, 0.999f);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* thinEllipse = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
thinEllipse->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
thinEllipse->conicTo(100, 100, 5, 0, SK_ScalarHalf);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* veryThinEllipse = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
veryThinEllipse->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
veryThinEllipse->conicTo(100, 100, 1, 0, SK_ScalarHalf);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkPath* closedEllipse = &fPaths.push_back();
|
2015-01-05 18:01:25 +00:00
|
|
|
closedEllipse->moveTo(0, 0);
|
2015-01-01 04:07:01 +00:00
|
|
|
closedEllipse->conicTo(100, 100, 0, 0, SK_ScalarHalf);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
2015-02-25 14:41:47 +00:00
|
|
|
{
|
|
|
|
const SkScalar w = SkScalarSqrt(2)/2;
|
|
|
|
fGiantCircle.moveTo(2.1e+11f, -1.05e+11f);
|
|
|
|
fGiantCircle.conicTo(2.1e+11f, 0, 1.05e+11f, 0, w);
|
|
|
|
fGiantCircle.conicTo(0, 0, 0, -1.05e+11f, w);
|
|
|
|
fGiantCircle.conicTo(0, -2.1e+11f, 1.05e+11f, -2.1e+11f, w);
|
|
|
|
fGiantCircle.conicTo(2.1e+11f, -2.1e+11f, 2.1e+11f, -1.05e+11f, w);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGiantCircle(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawPath(fGiantCircle, paint);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-01-01 04:07:01 +00:00
|
|
|
const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
|
2013-06-20 16:54:31 +00:00
|
|
|
|
2015-01-01 04:07:01 +00:00
|
|
|
const SkScalar margin = 15;
|
|
|
|
canvas->translate(margin, margin);
|
2013-06-20 16:54:31 +00:00
|
|
|
|
2015-01-05 18:01:25 +00:00
|
|
|
SkPaint paint;
|
2013-06-20 16:54:31 +00:00
|
|
|
for (int p = 0; p < fPaths.count(); ++p) {
|
2015-01-05 18:01:25 +00:00
|
|
|
canvas->save();
|
2013-06-20 16:54:31 +00:00
|
|
|
for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
|
2015-01-05 18:01:25 +00:00
|
|
|
paint.setARGB(kAlphaValue[a], 0, 0, 0);
|
2013-06-20 16:54:31 +00:00
|
|
|
for (int aa = 0; aa < 2; ++aa) {
|
2015-01-05 18:01:25 +00:00
|
|
|
paint.setAntiAlias(SkToBool(aa));
|
2013-06-20 16:54:31 +00:00
|
|
|
for (int fh = 0; fh < 2; ++fh) {
|
2015-01-05 18:01:25 +00:00
|
|
|
paint.setStyle(fh ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
|
2013-06-20 16:54:31 +00:00
|
|
|
|
|
|
|
const SkRect& bounds = fPaths[p].getBounds();
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(-bounds.fLeft, -bounds.fTop);
|
|
|
|
canvas->drawPath(fPaths[p], paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
2015-01-05 18:01:25 +00:00
|
|
|
canvas->translate(110, 0);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-05 18:01:25 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, 110);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2015-02-25 14:41:47 +00:00
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
this->drawGiantCircle(canvas);
|
2013-06-20 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkTArray<SkPath> fPaths;
|
2015-02-25 14:41:47 +00:00
|
|
|
SkPath fGiantCircle;
|
2015-01-01 04:07:01 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2013-06-20 16:54:31 +00:00
|
|
|
};
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new ConicPathsGM;)
|
2013-06-20 16:54:31 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-01-20 15:46:05 +00:00
|
|
|
/* arc should be on top of circle */
|
|
|
|
DEF_SIMPLE_GM(arccirclegap, canvas, 250, 250) {
|
|
|
|
canvas->translate(50, 100);
|
|
|
|
SkPoint c = { 1052.5390625f, 506.8760978034711f };
|
|
|
|
SkScalar radius = 1096.702150363923f;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(c, radius, paint);
|
2016-01-20 15:46:05 +00:00
|
|
|
SkPath path;
|
|
|
|
path.moveTo(288.88884710654133f, -280.26680862609f);
|
|
|
|
path.arcTo(0, 0, -39.00216443306411f, 400.6058925796476f, radius);
|
|
|
|
paint.setColor(0xff007f00);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
2016-08-24 18:59:30 +00:00
|
|
|
|
2016-12-19 19:45:19 +00:00
|
|
|
/* circle should be antialiased */
|
|
|
|
DEF_SIMPLE_GM(largecircle, canvas, 250, 250) {
|
|
|
|
canvas->translate(50, 100);
|
|
|
|
SkPoint c = { 1052.5390625f, 506.8760978034711f };
|
|
|
|
SkScalar radius = 1096.702150363923f;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2017-05-15 17:35:35 +00:00
|
|
|
canvas->drawCircle(c, radius, paint);
|
2016-12-19 19:45:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 12:50:41 +00:00
|
|
|
/* ovals should not be blurry */
|
|
|
|
DEF_SIMPLE_GM(largeovals, canvas, 250, 250) {
|
|
|
|
// Test EllipseOp
|
|
|
|
SkRect r = SkRect::MakeXYWH(-520, -520, 5000, 4000);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(100);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
r.offset(-15, -15);
|
|
|
|
paint.setColor(SK_ColorDKGRAY);
|
|
|
|
// we use stroke and fill to avoid falling into the SimpleFill path
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
|
|
|
|
// Test DIEllipseOp
|
|
|
|
canvas->rotate(1.0f);
|
|
|
|
r.offset(55, 55);
|
|
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(100);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
r.offset(-15, -15);
|
|
|
|
paint.setColor(SK_ColorLTGRAY);
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:59:30 +00:00
|
|
|
DEF_SIMPLE_GM(crbug_640176, canvas, 250, 250) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
|
|
|
|
path.lineTo(SkBits2Float(0x42cfd89a), SkBits2Float(0xc2700000)); // 103.923f, -60
|
|
|
|
path.lineTo(SkBits2Float(0x42cfd899), SkBits2Float(0xc2700006)); // 103.923f, -60
|
|
|
|
path.conicTo(SkBits2Float(0x42f00000), SkBits2Float(0xc2009d9c),
|
|
|
|
SkBits2Float(0x42f00001), SkBits2Float(0x00000000),
|
|
|
|
SkBits2Float(0x3f7746ea)); // 120, -32.1539f, 120, 0, 0.965926f
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
canvas->translate(125, 125);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|