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

Public Member Functions

 TextBlobShaderGM ()
 
- 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 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
 

Private Member Functions

void onOnceBeforeDraw () override
 
SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 

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 []
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Detailed Description

Definition at line 33 of file textblobshader.cpp.

Constructor & Destructor Documentation

◆ TextBlobShaderGM()

TextBlobShaderGM::TextBlobShaderGM ( )
inline

Definition at line 35 of file textblobshader.cpp.

35{}

Member Function Documentation

◆ getISize()

SkISize TextBlobShaderGM::getISize ( )
inlineoverrideprivatevirtual

Implements skiagm::GM.

Definition at line 93 of file textblobshader.cpp.

93{ return SkISize::Make(640, 480); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString TextBlobShaderGM::getName ( ) const
inlineoverrideprivatevirtual

Implements skiagm::GM.

Definition at line 91 of file textblobshader.cpp.

91{ return SkString("textblobshader"); }

◆ onDraw()

void TextBlobShaderGM::onDraw ( SkCanvas canvas)
inlineoverrideprivatevirtual

Reimplemented from skiagm::GM.

Definition at line 95 of file textblobshader.cpp.

95 {
96 SkPaint p;
97 p.setAntiAlias(true);
98 p.setStyle(SkPaint::kFill_Style);
99 p.setShader(fShader);
100
101 SkISize sz = this->getISize();
102 constexpr int kXCount = 4;
103 constexpr int kYCount = 3;
104 for (int i = 0; i < kXCount; ++i) {
105 for (int j = 0; j < kYCount; ++j) {
106 canvas->drawTextBlob(fBlob,
107 SkIntToScalar(i * sz.width() / kXCount),
108 SkIntToScalar(j * sz.height() / kYCount),
109 p);
110 }
111 }
112 }
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
SkISize getISize() override
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ onOnceBeforeDraw()

void TextBlobShaderGM::onOnceBeforeDraw ( )
inlineoverrideprivatevirtual

Reimplemented from skiagm::GM.

Definition at line 38 of file textblobshader.cpp.

38 {
39 {
41 const char* txt = "Blobber";
42 size_t txtLen = strlen(txt);
43 fGlyphs.append(font.countText(txt, txtLen, SkTextEncoding::kUTF8));
44 font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), fGlyphs.size());
45 }
46
48 font.setSubpixel(true);
50 font.setSize(30);
51
53 int glyphCount = fGlyphs.size();
55
56 run = &builder.allocRun(font, glyphCount, 10, 10, nullptr);
57 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
58
59 run = &builder.allocRunPosH(font, glyphCount, 80, nullptr);
60 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
61 for (int i = 0; i < glyphCount; ++i) {
62 run->pos[i] = font.getSize() * i * .75f;
63 }
64
65 run = &builder.allocRunPos(font, glyphCount, nullptr);
66 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
67 for (int i = 0; i < glyphCount; ++i) {
68 run->pos[i * 2] = font.getSize() * i * .75f;
69 run->pos[i * 2 + 1] = 150 + 5 * sinf((float)i * 8 / glyphCount);
70 }
71
72 fBlob = builder.make();
73
74 SkColor colors[2];
77
78 SkScalar pos[std::size(colors)];
79 for (unsigned i = 0; i < std::size(pos); ++i) {
80 pos[i] = (float)i / (std::size(pos) - 1);
81 }
82
83 SkISize sz = this->getISize();
85 SkIntToScalar(sz.height() / 2)),
86 sz.width() * .66f, colors, pos,
87 std::size(colors),
89 }
SkPoint pos
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
@ kUTF8
uses bytes to represent UTF-8 or ASCII
@ kAntiAlias
may have transparent pixels on glyph edges
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
int size() const
Definition SkTDArray.h:138
T * begin()
Definition SkTDArray.h:150
T * append()
Definition SkTDArray.h:191
float SkScalar
Definition extension.cpp:12
PODArray< SkColor > colors
Definition SkRecords.h:276
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
Definition run.py:1
static constexpr SkPoint Make(float x, float y)

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