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

Public Member Functions

 Poly2PolyGM ()
 
- 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)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
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
 
void onOnceBeforeDraw () override
 
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 void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Static Protected Member Functions

static void doDraw (SkCanvas *canvas, const SkFont &font, SkPaint *paint, const int isrc[], const int idst[], int count)
 

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 29 of file poly2poly.cpp.

Constructor & Destructor Documentation

◆ Poly2PolyGM()

Poly2PolyGM::Poly2PolyGM ( )
inline

Definition at line 31 of file poly2poly.cpp.

31{}

Member Function Documentation

◆ doDraw()

static void Poly2PolyGM::doDraw ( SkCanvas canvas,
const SkFont font,
SkPaint paint,
const int  isrc[],
const int  idst[],
int  count 
)
inlinestaticprotected

Definition at line 38 of file poly2poly.cpp.

39 {
41 SkPoint src[4], dst[4];
42
43 for (int i = 0; i < count; i++) {
44 src[i].set(SkIntToScalar(isrc[2*i+0]), SkIntToScalar(isrc[2*i+1]));
45 dst[i].set(SkIntToScalar(idst[2*i+0]), SkIntToScalar(idst[2*i+1]));
46 }
47
48 canvas->save();
49 matrix.setPolyToPoly(src, dst, count);
50 canvas->concat(matrix);
51
52 paint->setColor(SK_ColorGRAY);
54 const SkScalar D = 64;
55 canvas->drawRect(SkRect::MakeWH(D, D), *paint);
56 canvas->drawLine(0, 0, D, D, *paint);
57 canvas->drawLine(0, D, D, 0, *paint);
58
60 font.getMetrics(&fm);
61 paint->setColor(SK_ColorRED);
62 paint->setStyle(SkPaint::kFill_Style);
63 SkScalar x = D/2;
64 SkScalar y = D/2 - (fm.fAscent + fm.fDescent)/2;
65 uint16_t glyphID = 3; // X
66 SkTextUtils::Draw(canvas, &glyphID, sizeof(glyphID), SkTextEncoding::kGlyphID, x, y,
68 canvas->restore();
69 }
int count
Definition: FontMgrTest.cpp:50
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
@ kGlyphID
uses two byte words to represent glyph indices
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
static void Draw(SkCanvas *, const void *text, size_t size, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, const SkPaint &, Align=kLeft_Align)
Definition: SkTextUtils.cpp:24
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
font
Font Metadata and Metrics.
dst
Definition: cp.py:12
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ getISize()

SkISize Poly2PolyGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 36 of file poly2poly.cpp.

36{ return SkISize::Make(835, 840); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString Poly2PolyGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 34 of file poly2poly.cpp.

34{ return SkString("poly2poly"); }

◆ onDraw()

void Poly2PolyGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 78 of file poly2poly.cpp.

78 {
80 paint.setAntiAlias(true);
81 paint.setStrokeWidth(SkIntToScalar(4));
82 SkFont font(fEmFace, 40);
83
84 canvas->save();
85 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
86 // translate (1 point)
87 const int src1[] = { 0, 0 };
88 const int dst1[] = { 5, 5 };
89 doDraw(canvas, font, &paint, src1, dst1, 1);
90 canvas->restore();
91
92 canvas->save();
93 canvas->translate(SkIntToScalar(160), SkIntToScalar(10));
94 // rotate/uniform-scale (2 points)
95 const int src2[] = { 32, 32, 64, 32 };
96 const int dst2[] = { 32, 32, 64, 48 };
97 doDraw(canvas, font, &paint, src2, dst2, 2);
98 canvas->restore();
99
100 canvas->save();
101 canvas->translate(SkIntToScalar(10), SkIntToScalar(110));
102 // rotate/skew (3 points)
103 const int src3[] = { 0, 0, 64, 0, 0, 64 };
104 const int dst3[] = { 0, 0, 96, 0, 24, 64 };
105 doDraw(canvas, font, &paint, src3, dst3, 3);
106 canvas->restore();
107
108 canvas->save();
109 canvas->translate(SkIntToScalar(160), SkIntToScalar(110));
110 // perspective (4 points)
111 const int src4[] = { 0, 0, 64, 0, 64, 64, 0, 64 };
112 const int dst4[] = { 0, 0, 96, 0, 64, 96, 0, 64 };
113 doDraw(canvas, font, &paint, src4, dst4, 4);
114 canvas->restore();
115 }
static void doDraw(SkCanvas *canvas, const SkFont &font, SkPaint *paint, const int isrc[], const int idst[], int count)
Definition: poly2poly.cpp:38
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
Definition: SkFont.h:35

◆ onOnceBeforeDraw()

void Poly2PolyGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 71 of file poly2poly.cpp.

71 {
72 fEmFace = ToolUtils::CreateTypefaceFromResource("fonts/Em.ttf");
73 if (!fEmFace) {
75 }
76 }
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)

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