Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
skiagm::BezierQuadEffects Class Reference
Inheritance diagram for skiagm::BezierQuadEffects:

Public Member Functions

 BezierQuadEffects ()
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
DrawResult onDraw (GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
 

Static Protected Attributes

static const int kNumQuads = 5
 
static const int kCellWidth = 128
 
static const int kCellHeight = 128
 

Detailed Description

This GM directly exercises effects that draw Bezier quad curves in the GPU backend.

Definition at line 414 of file beziereffects.cpp.

Constructor & Destructor Documentation

◆ BezierQuadEffects()

skiagm::BezierQuadEffects::BezierQuadEffects ( )
inline

Definition at line 416 of file beziereffects.cpp.

416 {
417 this->setBGColor(0xFFFFFFFF);
418 }

Member Function Documentation

◆ getISize()

SkISize skiagm::BezierQuadEffects::getISize ( )
inlineoverrideprotected

Definition at line 427 of file beziereffects.cpp.

static const int kCellWidth
static const int kNumQuads
static const int kCellHeight
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::BezierQuadEffects::getName ( ) const
inlineoverrideprotected

Definition at line 425 of file beziereffects.cpp.

425{ return SkString("bezier_quad_effects"); }

◆ onDraw()

DrawResult skiagm::BezierQuadEffects::onDraw ( GrRecordingContext rContext,
SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotected

Definition at line 429 of file beziereffects.cpp.

429 {
431 if (!sdc) {
432 *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
433 return DrawResult::kSkip;
434 }
435
436 const SkScalar w = kCellWidth, h = kCellHeight;
438
439 const SkPoint baseControlPts[kNumQuads][3] = {
440 { { 0.31f * w, 0.01f * h}, { 0.48f * w, 0.74f * h }, { 0.19f * w, 0.33f * h } },
441 { { 0.00f * w, 0.07f * h}, { 0.30f * w, 0.70f * h }, { 0.47f * w, 0.37f * h } },
442 { { 0.15f * w, 0.23f * h}, { 0.49f * w, 0.87f * h }, { 0.85f * w, 0.66f * h } },
443 { { 0.09f * w, 0.15f * h}, { 0.42f * w, 0.33f * h }, { 0.17f * w, 0.38f * h } },
444 { { 0.98f * w, 0.54f * h}, { 0.83f * w, 0.91f * h }, { 0.62f * w, 0.40f * h } },
445 };
446
447 SkPaint ctrlPtPaint;
448 ctrlPtPaint.setColor(SK_ColorRED);
449
450 SkPaint choppedPtPaint;
451 choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
452
453 SkPaint polyPaint;
454 polyPaint.setColor(0xffA0A0A0);
455 polyPaint.setStrokeWidth(0);
457
458 SkPaint boundsPaint;
459 boundsPaint.setColor(0xff808080);
460 boundsPaint.setStrokeWidth(0);
461 boundsPaint.setStyle(SkPaint::kStroke_Style);
462
463 for (int row = 0; row < kNumQuads; ++row) {
464 SkScalar x = 0;
465 SkScalar y = row * h;
466 SkPoint controlPts[] = {
467 {x + baseControlPts[row][0].fX, y + baseControlPts[row][0].fY},
468 {x + baseControlPts[row][1].fX, y + baseControlPts[row][1].fY},
469 {x + baseControlPts[row][2].fX, y + baseControlPts[row][2].fY}
470 };
471
472 for (int i = 0; i < 3; ++i) {
473 canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
474 }
475
476 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
477
478 SkPoint chopped[5];
479 int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped);
480
481 for (int c = 0; c < cnt; ++c) {
482 SkPoint* pts = chopped + 2 * c;
483
484 for (int i = 0; i < 3; ++i) {
485 canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
486 }
487
489 bounds.setBounds(pts, 3);
490
491 canvas->drawRect(bounds, boundsPaint);
492
493 GrPathUtils::QuadUVMatrix DevToUV(pts);
494
496 kOpaqueBlack, DevToUV);
497 sdc->addDrawOp(std::move(op));
498 }
499 }
500
501 return DrawResult::kOk;
502 }
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
int SkChopQuadAtMaxCurvature(const SkPoint src[3], SkPoint dst[5])
Definition: SkGeometry.cpp:367
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition: SkCanvas.h:1243
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
SkColor getColor() const
Definition: SkPaint.h:225
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
static GrOp::Owner Make(GrRecordingContext *context, const SkRect &rect, const SkPMColor4f &color, const GrPathUtils::QuadUVMatrix &devToUV)
float SkScalar
Definition: extension.cpp:12
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
constexpr int kOpaqueBlack
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
SkScalar w
SkScalar h
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static SkRGBA4f FromBytes_RGBA(uint32_t color)

Member Data Documentation

◆ kCellHeight

const int skiagm::BezierQuadEffects::kCellHeight = 128
staticprotected

Definition at line 423 of file beziereffects.cpp.

◆ kCellWidth

const int skiagm::BezierQuadEffects::kCellWidth = 128
staticprotected

Definition at line 422 of file beziereffects.cpp.

◆ kNumQuads

const int skiagm::BezierQuadEffects::kNumQuads = 5
staticprotected

Definition at line 421 of file beziereffects.cpp.


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