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

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
 

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
 
- 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
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 120 of file pictureimagegenerator.cpp.

Member Function Documentation

◆ getISize()

SkISize PictureGeneratorGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 124 of file pictureimagegenerator.cpp.

124{ return SkISize::Make(1160, 860); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString PictureGeneratorGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 122 of file pictureimagegenerator.cpp.

122{ return SkString("pictureimagegenerator"); }

◆ onDraw()

void PictureGeneratorGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 134 of file pictureimagegenerator.cpp.

134 {
135 const struct {
137 SkScalar scaleX, scaleY;
138 SkScalar opacity;
139 } configs[] = {
140 { SkISize::Make(200, 100), 1, 1, 1 },
141 { SkISize::Make(200, 200), 1, 1, 1 },
142 { SkISize::Make(200, 200), 1, 2, 1 },
143 { SkISize::Make(400, 200), 2, 2, 1 },
144
145 { SkISize::Make(200, 100), 1, 1, 0.9f },
146 { SkISize::Make(200, 200), 1, 1, 0.75f },
147 { SkISize::Make(200, 200), 1, 2, 0.5f },
148 { SkISize::Make(400, 200), 2, 2, 0.25f },
149
150 { SkISize::Make(200, 200), 0.5f, 1, 1 },
151 { SkISize::Make(200, 200), 1, 0.5f, 1 },
152 { SkISize::Make(200, 200), 0.5f, 0.5f, 1 },
153 { SkISize::Make(200, 200), 2, 2, 1 },
154
155 { SkISize::Make(200, 100), -1, 1, 1 },
156 { SkISize::Make(200, 100), 1, -1, 1 },
157 { SkISize::Make(200, 100), -1, -1, 1 },
158 { SkISize::Make(200, 100), -1, -1, 0.5f },
159 };
160
161 auto srgbColorSpace = SkColorSpace::MakeSRGB();
162 const unsigned kDrawsPerRow = 4;
163 const SkScalar kDrawSize = 250;
164
165 for (size_t i = 0; i < std::size(configs); ++i) {
166 SkPaint p;
167 p.setAlphaf(configs[i].opacity);
168
169 SkMatrix m = SkMatrix::Scale(configs[i].scaleX, configs[i].scaleY);
170 if (configs[i].scaleX < 0) {
171 m.postTranslate(SkIntToScalar(configs[i].size.width()), 0);
172 }
173 if (configs[i].scaleY < 0) {
174 m.postTranslate(0, SkIntToScalar(configs[i].size.height()));
175 }
176 std::unique_ptr<SkImageGenerator> gen =
178 fPicture,
179 &m,
180 p.getAlpha() != 255 ? &p : nullptr,
182 srgbColorSpace);
183
184 SkImageInfo bmInfo = gen->getInfo().makeColorSpace(canvas->imageInfo().refColorSpace());
185
186 SkBitmap bm;
187 bm.allocPixels(bmInfo);
188 SkAssertResult(gen->getPixels(bm.info(), bm.getPixels(), bm.rowBytes()));
189
190 const SkScalar x = kDrawSize * (i % kDrawsPerRow);
191 const SkScalar y = kDrawSize * (i / kDrawsPerRow);
192
193 p.setColor(0xfff0f0f0);
194 p.setAlphaf(1.0f);
195 canvas->drawRect(SkRect::MakeXYWH(x, y,
196 SkIntToScalar(bm.width()),
197 SkIntToScalar(bm.height())), p);
198 canvas->drawImage(bm.asImage(), x, y);
199 }
200 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
int width() const
Definition: SkBitmap.h:149
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
const SkImageInfo & info() const
Definition: SkBitmap.h:139
int height() const
Definition: SkBitmap.h:158
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorSpace > MakeSRGB()
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
float SkScalar
Definition: extension.cpp:12
double y
double x
std::unique_ptr< SkImageGenerator > MakeFromPicture(const SkISize &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, SkImages::BitDepth, sk_sp< SkColorSpace >, SkSurfaceProps props)
@ kU8
uses 8-bit unsigned int per color component
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: gen.py:1
Definition: SkSize.h:16
sk_sp< SkColorSpace > refColorSpace() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onOnceBeforeDraw()

void PictureGeneratorGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 126 of file pictureimagegenerator.cpp.

126 {
127 const SkRect rect = SkRect::MakeWH(kPictureWidth, kPictureHeight);
128 SkPictureRecorder recorder;
129 SkCanvas* canvas = recorder.beginRecording(rect);
130 draw_vector_logo(canvas, rect);
131 fPicture = recorder.finishRecordingAsPicture();
132 }
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static void draw_vector_logo(SkCanvas *canvas, const SkRect &viewBox)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

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