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

Public Member Functions

 LatticeGM2 ()
 
SkString getName () const override
 
SkISize getISize () override
 
sk_sp< SkImagemakeImage (SkCanvas *root, int padLeft, int padTop, int padRight, int padBottom)
 
void onDrawHelper (SkCanvas *canvas, int padLeft, int padTop, int padRight, int padBottom, SkPaint &paint)
 
void onDraw (SkCanvas *canvas) override
 
- 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
 

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 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
 

Detailed Description

Definition at line 226 of file lattice.cpp.

Constructor & Destructor Documentation

◆ LatticeGM2()

LatticeGM2::LatticeGM2 ( )
inline

Definition at line 228 of file lattice.cpp.

228{}

Member Function Documentation

◆ getISize()

SkISize LatticeGM2::getISize ( )
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 231 of file lattice.cpp.

231{ return SkISize::Make(800, 800); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString LatticeGM2::getName ( ) const
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 229 of file lattice.cpp.

229{ return SkString("lattice2"); }

◆ makeImage()

sk_sp< SkImage > LatticeGM2::makeImage ( SkCanvas root,
int  padLeft,
int  padTop,
int  padRight,
int  padBottom 
)
inline

Definition at line 233 of file lattice.cpp.

233 {
234 const int kSize = 80;
235 auto surface(make_surface(root, kSize, padLeft, padTop, padRight, padBottom));
236 SkCanvas* canvas = surface->getCanvas();
238 paint.setAntiAlias(false);
239 SkRect r;
240
241 //first line
242 r.setXYWH(0, 0, 4, 1); //4x1 green rect
243 paint.setColor(0xFF00FF00);
244 canvas->drawRect(r, paint);
245
246 r.setXYWH(4, 0, 1, 1); //1x1 blue pixel -> draws as rectangle
247 paint.setColor(0xFF0000FF);
248 canvas->drawRect(r, paint);
249
250 r.setXYWH(5, 0, kSize-5, 1); //the rest of the line is red
251 paint.setColor(0xFFFF0000);
252 canvas->drawRect(r, paint);
253
254
255 //second line -> draws as fixed color rectangles
256 r.setXYWH(0, 1, 4, 1); //4x1 red rect
257 paint.setColor(0xFFFF0000);
258 canvas->drawRect(r, paint);
259
260 r.setXYWH(4, 1, 1, 1); //1x1 blue pixel with alpha
261 paint.setColor(0x880000FF);
262 canvas->drawRect(r, paint);
263
264 r.setXYWH(5, 1, kSize-5, 1); //the rest of the line is green
265 paint.setColor(0xFF00FF00);
266 canvas->drawRect(r, paint);
267
268
269 //third line - does not draw, because it is transparent
270 r.setXYWH(0, 2, 4, kSize-2); //4x78 green rect
271 paint.setColor(0xFF00FF00);
272 canvas->drawRect(r, paint);
273
274 r.setXYWH(4, 2, 1, kSize-2); //1x78 red pixel with alpha
275 paint.setColor(0x88FF0000);
276 canvas->drawRect(r, paint);
277
278 r.setXYWH(5, 2, kSize-5, kSize-2); //the rest of the image is blue
279 paint.setColor(0xFF0000FF);
280 canvas->drawRect(r, paint);
281
282 return surface->makeImageSnapshot();
283 }
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
constexpr int kSize
static sk_sp< SkSurface > make_surface(SkCanvas *root, int N, int padLeft, int padTop, int padRight, int padBottom)
Definition: lattice.cpp:26
string root
Definition: scale_cpu.py:20
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931

◆ onDraw()

void LatticeGM2::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 333 of file lattice.cpp.

333 {
334
335 //draw a rectangle in the background with transparent pixels
337 paint.setColor(0x7F123456);
338 paint.setBlendMode(SkBlendMode::kSrc);
339 canvas->drawRect( SkRect::MakeXYWH(300, 0, 300, 800), paint);
340
341 //draw image lattice with kSrcOver blending
342 paint.setBlendMode(SkBlendMode::kSrcOver);
343 this->onDrawHelper(canvas, 0, 0, 0, 0, paint);
344
345 //draw image lattice with kSrcATop blending
346 canvas->translate(0.0f, 400.0f);
347 paint.setBlendMode(SkBlendMode::kSrcATop);
348 this->onDrawHelper(canvas, 0, 0, 0, 0, paint);
349 }
@ kSrcOver
r = s + (1-sa)*d
@ kSrcATop
r = s*da + d*(1-sa)
void onDrawHelper(SkCanvas *canvas, int padLeft, int padTop, int padRight, int padBottom, SkPaint &paint)
Definition: lattice.cpp:285
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onDrawHelper()

void LatticeGM2::onDrawHelper ( SkCanvas canvas,
int  padLeft,
int  padTop,
int  padRight,
int  padBottom,
SkPaint paint 
)
inline

Definition at line 285 of file lattice.cpp.

286 {
287 int xDivs[2] = {4, 5};
288 int yDivs[2] = {1, 2};
289
290 canvas->save();
291
292 sk_sp<SkImage> image = makeImage(canvas, padLeft, padTop, padRight, padBottom);
293
294 canvas->drawImage(image, 10, 10);
295
296 SkCanvas::Lattice lattice;
297 lattice.fXCount = 2;
298 lattice.fXDivs = xDivs;
299 lattice.fYCount = 2;
300 lattice.fYDivs = yDivs;
301 lattice.fBounds = nullptr;
302
308
312 lattice.fRectTypes = flags;
313
315 0xFFFF0000, 0x880000FF, 0xFF00FF00,
317 lattice.fColors = colors;
318 paint.setColor(0xFFFFFFFF);
319 canvas->drawImageLattice(image.get(), lattice,
320 SkRect::MakeXYWH(100, 100, 200, 200),
322
323 //draw the same content with alpha
324 canvas->translate(400, 0);
325 paint.setColor(0x80000FFF);
326 canvas->drawImageLattice(image.get(), lattice,
327 SkRect::MakeXYWH(100, 100, 200, 200),
329
330 canvas->restore();
331 }
sk_bzero(glyphs, sizeof(glyphs))
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
sk_sp< SkImage > makeImage(SkCanvas *root, int padLeft, int padTop, int padRight, int padBottom)
Definition: lattice.cpp:233
void restore()
Definition: SkCanvas.cpp:461
void drawImageLattice(const SkImage *image, const Lattice &lattice, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
Definition: SkCanvas.cpp:1786
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
T * get() const
Definition: SkRefCnt.h:303
FlutterSemanticsFlag flags
sk_sp< const SkImage > image
Definition: SkRecords.h:269
PODArray< int > xDivs
Definition: SkRecords.h:271
PODArray< SkColor > colors
Definition: SkRecords.h:276
PODArray< int > yDivs
Definition: SkRecords.h:273
int fYCount
number of y-coordinates
Definition: SkCanvas.h:1617
const SkIRect * fBounds
source bounds to draw from
Definition: SkCanvas.h:1618
@ kFixedColor
draws one of fColors into lattice rectangle
Definition: SkCanvas.h:1610
@ kTransparent
skips lattice rectangle by making it transparent
Definition: SkCanvas.h:1609
const int * fYDivs
y-axis values dividing bitmap
Definition: SkCanvas.h:1614
int fXCount
number of x-coordinates
Definition: SkCanvas.h:1616
const RectType * fRectTypes
array of fill types
Definition: SkCanvas.h:1615
const SkColor * fColors
array of colors
Definition: SkCanvas.h:1619
const int * fXDivs
x-axis values dividing bitmap
Definition: SkCanvas.h:1613

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