Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | List of all members
DegenerateQuadSlide Class Reference
Inheritance diagram for DegenerateQuadSlide:
ClickHandlerSlide Slide SkRefCnt SkRefCntBase

Classes

class  Click
 

Public Member Functions

 DegenerateQuadSlide (const SkRect &rect)
 
void draw (SkCanvas *canvas) override
 
bool onChar (SkUnichar) override
 
- Public Member Functions inherited from ClickHandlerSlide
bool onMouse (SkScalar x, SkScalar y, skui::InputState clickState, skui::ModifierKey modifierKeys) final
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (Click *) override
 
- Protected Member Functions inherited from ClickHandlerSlide
virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 240 of file DegenerateQuadsSlide.cpp.

Constructor & Destructor Documentation

◆ DegenerateQuadSlide()

DegenerateQuadSlide::DegenerateQuadSlide ( const SkRect rect)
inline

Definition at line 242 of file DegenerateQuadsSlide.cpp.

243 : fOuterRect(rect)
244 , fCoverageMode(CoverageMode::kArea) {
245 fOuterRect.toQuad(fCorners);
246 for (int i = 0; i < 4; ++i) {
247 fEdgeAA[i] = true;
248 }
249 fName = "DegenerateQuad";
250 }
SkString fName
Definition: Slide.h:54
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
void toQuad(SkPoint quad[4]) const
Definition: SkRect.cpp:50

Member Function Documentation

◆ draw()

void DegenerateQuadSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 252 of file DegenerateQuadsSlide.cpp.

252 {
253 static const SkScalar kDotParams[2] = {1.f / kViewScale, 12.f / kViewScale};
254 sk_sp<SkPathEffect> dots = SkDashPathEffect::Make(kDotParams, 2, 0.f);
255 static const SkScalar kDashParams[2] = {8.f / kViewScale, 12.f / kViewScale};
256 sk_sp<SkPathEffect> dashes = SkDashPathEffect::Make(kDashParams, 2, 0.f);
257
258 SkPaint circlePaint;
259 circlePaint.setAntiAlias(true);
260
261 SkPaint linePaint;
262 linePaint.setAntiAlias(true);
264 linePaint.setStrokeWidth(4.f / kViewScale);
267
269 canvas->scale(kViewScale, kViewScale);
270
271 // Draw the outer rectangle as a dotted line
272 linePaint.setPathEffect(dots);
273 canvas->drawRect(fOuterRect, linePaint);
274
275 bool valid = this->isValid();
276
277 if (valid) {
278 SkPoint outsets[8];
279 SkPoint insets[8];
280 // Calculate inset and outset lines for edge-distance visualization
281 for (int i = 0; i < 4; ++i) {
282 make_aa_line(fCorners[i], fCorners[(i + 1) % 4], fEdgeAA[i], true, outsets + i * 2);
283 make_aa_line(fCorners[i], fCorners[(i + 1) % 4], fEdgeAA[i], false, insets + i * 2);
284 }
285
286 // Calculate inner and outer meshes for GPU visualization
287 SkPoint gpuOutset[4];
288 SkScalar gpuOutsetCoverage[4];
289 SkPoint gpuInset[4];
290 SkScalar gpuInsetCoverage[4];
291 SkRect gpuDomain;
292 this->getTessellatedPoints(gpuInset, gpuInsetCoverage, gpuOutset, gpuOutsetCoverage,
293 &gpuDomain);
294
295 // Visualize the coverage values across the clamping rectangle, but test pixels outside
296 // of the "outer" rect since some quad edges can be outset extra far.
297 SkPaint pixelPaint;
298 pixelPaint.setAntiAlias(true);
299 SkRect covRect = fOuterRect.makeOutset(2.f, 2.f);
300 for (SkScalar py = covRect.fTop; py < covRect.fBottom; py += 1.f) {
301 for (SkScalar px = covRect.fLeft; px < covRect.fRight; px += 1.f) {
302 // px and py are the top-left corner of the current pixel, so get center's
303 // coordinate
304 SkPoint pixelCenter = {px + 0.5f, py + 0.5f};
306 if (fCoverageMode == CoverageMode::kArea) {
307 coverage = get_area_coverage(fEdgeAA, fCorners, pixelCenter);
308 } else if (fCoverageMode == CoverageMode::kEdgeDistance) {
309 coverage = get_edge_dist_coverage(fEdgeAA, fCorners, outsets, insets,
310 pixelCenter);
311 } else {
312 SkASSERT(fCoverageMode == CoverageMode::kGPUMesh);
313 coverage = get_framed_coverage(gpuOutset, gpuOutsetCoverage,
314 gpuInset, gpuInsetCoverage, gpuDomain,
315 pixelCenter);
316 }
317
318 SkRect pixelRect = SkRect::MakeXYWH(px, py, 1.f, 1.f);
319 pixelRect.inset(0.1f, 0.1f);
320
321 SkScalar a = 1.f - 0.5f * coverage;
322 pixelPaint.setColor4f({a, a, a, 1.f}, nullptr);
323 canvas->drawRect(pixelRect, pixelPaint);
324
325 pixelPaint.setColor(coverage > 0.f ? SK_ColorGREEN : SK_ColorRED);
326 pixelRect.inset(0.38f, 0.38f);
327 canvas->drawRect(pixelRect, pixelPaint);
328 }
329 }
330
331 linePaint.setPathEffect(dashes);
332 // Draw the inset/outset "infinite" lines
333 if (fCoverageMode == CoverageMode::kEdgeDistance) {
334 for (int i = 0; i < 4; ++i) {
335 if (fEdgeAA[i]) {
336 linePaint.setColor(SK_ColorBLUE);
337 draw_extended_line(canvas, linePaint, outsets[i * 2], outsets[i * 2 + 1]);
338 linePaint.setColor(SK_ColorGREEN);
339 draw_extended_line(canvas, linePaint, insets[i * 2], insets[i * 2 + 1]);
340 } else {
341 // Both outset and inset are the same line, so only draw one in cyan
342 linePaint.setColor(SK_ColorCYAN);
343 draw_extended_line(canvas, linePaint, outsets[i * 2], outsets[i * 2 + 1]);
344 }
345 }
346 }
347
348 linePaint.setPathEffect(nullptr);
349 // What is tessellated using GrQuadPerEdgeAA
350 if (fCoverageMode == CoverageMode::kGPUMesh) {
351 SkPath outsetPath;
352 outsetPath.addPoly(gpuOutset, 4, true);
353 linePaint.setColor(SK_ColorBLUE);
354 canvas->drawPath(outsetPath, linePaint);
355
356 SkPath insetPath;
357 insetPath.addPoly(gpuInset, 4, true);
358 linePaint.setColor(SK_ColorGREEN);
359 canvas->drawPath(insetPath, linePaint);
360
361 SkPaint domainPaint = linePaint;
362 domainPaint.setStrokeWidth(2.f / kViewScale);
363 domainPaint.setPathEffect(dashes);
364 domainPaint.setColor(SK_ColorMAGENTA);
365 canvas->drawRect(gpuDomain, domainPaint);
366 }
367
368 // Draw the edges of the true quad as a solid line
369 SkPath path;
370 path.addPoly(fCorners, 4, true);
371 linePaint.setColor(SK_ColorBLACK);
372 canvas->drawPath(path, linePaint);
373 } else {
374 // Draw the edges of the true quad as a solid *red* line
375 SkPath path;
376 path.addPoly(fCorners, 4, true);
377 linePaint.setColor(SK_ColorRED);
378 linePaint.setPathEffect(nullptr);
379 canvas->drawPath(path, linePaint);
380 }
381
382 // Draw the four clickable corners as circles
383 circlePaint.setColor(valid ? SK_ColorBLACK : SK_ColorRED);
384 for (int i = 0; i < 4; ++i) {
385 canvas->drawCircle(fCorners[i], 5.f / kViewScale, circlePaint);
386 }
387 }
static constexpr SkScalar kViewScale
static SkScalar get_area_coverage(const bool edgeAA[4], const SkPoint corners[4], const SkPoint &point)
static SkScalar get_edge_dist_coverage(const bool edgeAA[4], const SkPoint corners[4], const SkPoint outsetLines[8], const SkPoint insetLines[8], const SkPoint &point)
static void make_aa_line(const SkPoint &p0, const SkPoint &p1, bool aaOn, bool outset, SkPoint line[2])
static void draw_extended_line(SkCanvas *canvas, const SkPaint &paint, const SkPoint &p0, const SkPoint &p1)
static constexpr SkScalar kViewOffset
static SkScalar get_framed_coverage(const SkPoint outer[4], const SkScalar outerCoverages[4], const SkPoint inner[4], const SkScalar innerCoverages[4], const SkRect &geomDomain, const SkPoint &point)
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
void setColor4f(const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
Definition: SkPaint.h:253
void setPathEffect(sk_sp< SkPathEffect > pathEffect)
@ kRound_Join
adds circle
Definition: SkPaint.h:360
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
SkPath & addPoly(const SkPoint pts[], int count, bool close)
Definition: SkPath.cpp:890
float SkScalar
Definition: extension.cpp:12
struct MyStruct a[10]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
void inset(float dx, float dy)
Definition: SkRect.h:1060
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkRect makeOutset(float dx, float dy) const
Definition: SkRect.h:1002
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ onChar()

bool DegenerateQuadSlide::onChar ( SkUnichar  code)
overridevirtual

Reimplemented from Slide.

Definition at line 505 of file DegenerateQuadsSlide.cpp.

505 {
506 switch(code) {
507 case '1':
508 fEdgeAA[0] = !fEdgeAA[0];
509 return true;
510 case '2':
511 fEdgeAA[1] = !fEdgeAA[1];
512 return true;
513 case '3':
514 fEdgeAA[2] = !fEdgeAA[2];
515 return true;
516 case '4':
517 fEdgeAA[3] = !fEdgeAA[3];
518 return true;
519 case 'q':
520 fCoverageMode = CoverageMode::kArea;
521 return true;
522 case 'w':
523 fCoverageMode = CoverageMode::kEdgeDistance;
524 return true;
525 case 'e':
526 fCoverageMode = CoverageMode::kGPUMesh;
527 return true;
528 }
529 return false;
530}

◆ onClick()

bool DegenerateQuadSlide::onClick ( Click )
overrideprotected

Definition at line 499 of file DegenerateQuadsSlide.cpp.

499 {
500 Click* myClick = (Click*) click;
501 myClick->doClick(fCorners);
502 return true;
503}

◆ onFindClickHandler()

ClickHandlerSlide::Click * DegenerateQuadSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
overrideprotectedvirtual

Return a Click object to handle the click. onClick will be called repeatedly with the latest mouse state tracked on the Click object until it returns false.

Implements ClickHandlerSlide.

Definition at line 488 of file DegenerateQuadsSlide.cpp.

489 {
491 for (int i = 0; i < 4; ++i) {
492 if ((fCorners[i] - inCTM).length() < 10.f / kViewScale) {
493 return new Click(fOuterRect, i);
494 }
495 }
496 return new Click(fOuterRect, -1);
497}
size_t length
double y
double x
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

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