Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
skiagm::PolygonOffsetGM Class Reference
Inheritance diagram for skiagm::PolygonOffsetGM:
skiagm::GM

Public Member Functions

 PolygonOffsetGM (bool convexOnly)
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
bool runAsBench () const override
 
void drawPolygon (SkCanvas *canvas, int index, SkPoint *position)
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Static Protected Member Functions

static void GetConvexPolygon (int index, SkPathDirection dir, std::unique_ptr< SkPoint[]> *data, int *numPts)
 
static void GetSimplePolygon (int index, SkPathDirection dir, std::unique_ptr< SkPoint[]> *data, int *numPts)
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 424 of file polygonoffset.cpp.

Constructor & Destructor Documentation

◆ PolygonOffsetGM()

skiagm::PolygonOffsetGM::PolygonOffsetGM ( bool  convexOnly)
inline

Definition at line 426 of file polygonoffset.cpp.

427 : fConvexOnly(convexOnly) {
428 this->setBGColor(0xFFFFFFFF);
429 }
void setBGColor(SkColor)
Definition gm.cpp:159

Member Function Documentation

◆ drawPolygon()

void skiagm::PolygonOffsetGM::drawPolygon ( SkCanvas canvas,
int  index,
SkPoint position 
)
inlineprotected

Definition at line 511 of file polygonoffset.cpp.

511 {
512
514 {
515 std::unique_ptr<SkPoint[]> data(nullptr);
516 int numPts;
517 if (fConvexOnly) {
518 GetConvexPolygon(index, SkPathDirection::kCW, &data, &numPts);
519 } else {
520 GetSimplePolygon(index, SkPathDirection::kCW, &data, &numPts);
521 }
523 bounds.setBounds(data.get(), numPts);
524 if (!fConvexOnly) {
525 bounds.outset(kMaxOutset, kMaxOutset);
526 }
527 if (position->fX + bounds.width() > kGMWidth) {
528 position->fX = 0;
529 position->fY += kMaxPathHeight;
530 }
531 center = { position->fX + SkScalarHalf(bounds.width()), position->fY };
532 position->fX += bounds.width();
533 }
534
536 const float insets[] = { 5, 10, 15, 20, 25, 30, 35, 40 };
537 const float offsets[] = { 2, 5, 9, 14, 20, 27, 35, 44, -2, -5, -9 };
538 const SkColor colors[] = { 0xFF901313, 0xFF8D6214, 0xFF698B14, 0xFF1C8914,
539 0xFF148755, 0xFF146C84, 0xFF142482, 0xFF4A1480,
540 0xFF901313, 0xFF8D6214, 0xFF698B14 };
541
543 paint.setAntiAlias(true);
545 paint.setStrokeWidth(1);
546
547 std::unique_ptr<SkPoint[]> data(nullptr);
548 int numPts;
549 if (fConvexOnly) {
550 GetConvexPolygon(index, dirs[index % 2], &data, &numPts);
551 } else {
552 GetSimplePolygon(index, dirs[index % 2], &data, &numPts);
553 }
554
555 {
556 SkPath path;
557 path.moveTo(data.get()[0]);
558 for (int i = 1; i < numPts; ++i) {
559 path.lineTo(data.get()[i]);
560 }
561 path.close();
562 canvas->save();
563 canvas->translate(center.fX, center.fY);
564 canvas->drawPath(path, paint);
565 canvas->restore();
566 }
567
568 SkTDArray<SkPoint> offsetPoly;
569 size_t count = fConvexOnly ? std::size(insets) : std::size(offsets);
570 for (size_t i = 0; i < count; ++i) {
571 SkScalar offset = fConvexOnly ? insets[i] : offsets[i];
572 std::function<SkScalar(const SkPoint&)> offsetFunc;
573
574 bool result;
575 if (fConvexOnly) {
576 result = SkInsetConvexPolygon(data.get(), numPts, offset, &offsetPoly);
577 } else {
579 bounds.setBoundsCheck(data.get(), numPts);
580 result = SkOffsetSimplePolygon(data.get(), numPts, bounds, offset, &offsetPoly);
581 }
582 if (result) {
583 SkPath path;
584 path.moveTo(offsetPoly[0]);
585 for (int j = 1; j < offsetPoly.size(); ++j) {
586 path.lineTo(offsetPoly[j]);
587 }
588 path.close();
589
590 paint.setColor(ToolUtils::color_to_565(colors[i]));
591 canvas->save();
592 canvas->translate(center.fX, center.fY);
593 canvas->drawPath(path, paint);
594 canvas->restore();
595 }
596 }
597 }
int count
uint32_t SkColor
Definition SkColor.h:37
SkPathDirection
Definition SkPathTypes.h:34
bool SkOffsetSimplePolygon(const SkPoint *inputPolygonVerts, int inputPolygonSize, const SkRect &bounds, SkScalar offset, SkTDArray< SkPoint > *offsetPolygon, SkTDArray< int > *polygonIndices)
bool SkInsetConvexPolygon(const SkPoint *inputPolygonVerts, int inputPolygonSize, SkScalar inset, SkTDArray< SkPoint > *insetPolygon)
#define SkScalarHalf(a)
Definition SkScalar.h:75
static SkScalar center(float pos0, float pos1)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
int size() const
Definition SkTDArray.h:138
static void GetConvexPolygon(int index, SkPathDirection dir, std::unique_ptr< SkPoint[]> *data, int *numPts)
static void GetSimplePolygon(int index, SkPathDirection dir, std::unique_ptr< SkPoint[]> *data, int *numPts)
const Paint & paint
float SkScalar
Definition extension.cpp:12
GAsyncResult * result
Optional< SkRect > bounds
Definition SkRecords.h:189
PODArray< SkColor > colors
Definition SkRecords.h:276
SkColor color_to_565(SkColor color)
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
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
Definition ref_ptr.h:256
Point offset
float fX
x-axis value
float fY
y-axis value

◆ GetConvexPolygon()

static void skiagm::PolygonOffsetGM::GetConvexPolygon ( int  index,
SkPathDirection  dir,
std::unique_ptr< SkPoint[]> *  data,
int numPts 
)
inlinestaticprotected

Definition at line 442 of file polygonoffset.cpp.

443 {
444 if (index < (int)std::size(PolygonOffsetData::gConvexPoints)) {
445 // manually specified
446 *numPts = (int)PolygonOffsetData::gConvexSizes[index];
447 *data = std::make_unique<SkPoint[]>(*numPts);
448 if (SkPathDirection::kCW == dir) {
449 for (int i = 0; i < *numPts; ++i) {
450 (*data)[i] = PolygonOffsetData::gConvexPoints[index][i];
451 }
452 } else {
453 for (int i = 0; i < *numPts; ++i) {
454 (*data)[i] = PolygonOffsetData::gConvexPoints[index][*numPts - i - 1];
455 }
456 }
457 } else {
458 // procedurally generated
459 SkScalar width = kMaxPathHeight / 2;
460 SkScalar height = kMaxPathHeight / 2;
461 int numPtsArray[] = { 3, 4, 5, 5, 6, 8, 8, 20, 100 };
462
463 size_t arrayIndex = index - std::size(PolygonOffsetData::gConvexPoints);
464 SkASSERT(arrayIndex < std::size(numPtsArray));
465 *numPts = numPtsArray[arrayIndex];
466 if (arrayIndex == 3 || arrayIndex == 6) {
467 // squashed pentagon and octagon
468 width = kMaxPathHeight / 5;
469 }
470
471 *data = std::make_unique<SkPoint[]>(*numPts);
472
473 create_ngon(*numPts, data->get(), width, height, dir);
474 }
475 }
#define SkASSERT(cond)
Definition SkAssert.h:116
Type::kYUV Type::kRGBA() int(0.7 *637)
SkScalar width()
Definition gm.h:159
SkScalar height()
Definition gm.h:162
static void create_ngon(int n, SkPoint *pts, SkScalar width, SkScalar height)
const size_t gConvexSizes[]
const SkPoint * gConvexPoints[]

◆ getISize()

SkISize skiagm::PolygonOffsetGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 439 of file polygonoffset.cpp.

439{ return SkISize::Make(kGMWidth, kGMHeight); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString skiagm::PolygonOffsetGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 432 of file polygonoffset.cpp.

432 {
433 if (fConvexOnly) {
434 return SkString("convex-polygon-inset");
435 } else {
436 return SkString("simple-polygon-offset");
437 }
438 }

◆ GetSimplePolygon()

static void skiagm::PolygonOffsetGM::GetSimplePolygon ( int  index,
SkPathDirection  dir,
std::unique_ptr< SkPoint[]> *  data,
int numPts 
)
inlinestaticprotected

Definition at line 477 of file polygonoffset.cpp.

478 {
479 if (index < (int)std::size(PolygonOffsetData::gSimplePoints)) {
480 // manually specified
481 *numPts = (int)PolygonOffsetData::gSimpleSizes[index];
482 *data = std::make_unique<SkPoint[]>(*numPts);
483 if (SkPathDirection::kCW == dir) {
484 for (int i = 0; i < *numPts; ++i) {
485 (*data)[i] = PolygonOffsetData::gSimplePoints[index][i];
486 }
487 } else {
488 for (int i = 0; i < *numPts; ++i) {
489 (*data)[i] = PolygonOffsetData::gSimplePoints[index][*numPts - i - 1];
490 }
491 }
492 } else {
493 // procedurally generated
494 SkScalar width = kMaxPathHeight / 2;
495 SkScalar height = kMaxPathHeight / 2;
496 int numPtsArray[] = { 5, 7, 8, 20, 100 };
497
498 size_t arrayIndex = index - std::size(PolygonOffsetData::gSimplePoints);
499 arrayIndex = std::min(arrayIndex, std::size(numPtsArray) - 1);
500 SkASSERT(arrayIndex < std::size(numPtsArray));
501 *numPts = numPtsArray[arrayIndex];
502 // squash horizontally
503 width = kMaxPathHeight / 5;
504
505 *data = std::make_unique<SkPoint[]>(*numPts);
506
507 create_ngon(*numPts, data->get(), width, height, dir);
508 }
509 }
const SkPoint * gSimplePoints[]
const size_t gSimpleSizes[]

◆ onDraw()

void skiagm::PolygonOffsetGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 599 of file polygonoffset.cpp.

599 {
600 // the right edge of the last drawn path
601 SkPoint offset = { 0, SkScalarHalf(kMaxPathHeight) };
602 if (!fConvexOnly) {
603 offset.fY += kMaxOutset;
604 }
605
606 for (int i = 0; i < kNumPaths; ++i) {
607 this->drawPolygon(canvas, i, &offset);
608 }
609 }
void drawPolygon(SkCanvas *canvas, int index, SkPoint *position)

◆ runAsBench()

bool skiagm::PolygonOffsetGM::runAsBench ( ) const
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 440 of file polygonoffset.cpp.

440{ return true; }

The documentation for this class was generated from the following file: