Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skiagm::ThinAASlide Class Reference
Inheritance diagram for skiagm::ThinAASlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 ThinAASlide ()
 
void load (SkScalar w, SkScalar h) override
 
void draw (SkCanvas *canvas) override
 
bool animate (double nanos) override
 
bool onChar (SkUnichar key) override
 
- 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
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 245 of file ThinAASlide.cpp.

Constructor & Destructor Documentation

◆ ThinAASlide()

skiagm::ThinAASlide::ThinAASlide ( )
inline

Definition at line 247 of file ThinAASlide.cpp.

247{ fName = "Thin-AA"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool skiagm::ThinAASlide::animate ( double  nanos)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 316 of file ThinAASlide.cpp.

316 {
317 SkScalar t = 1e-9 * nanos;
318 SkScalar dt = fLastFrameTime < 0.f ? 0.f : t - fLastFrameTime;
319 fLastFrameTime = t;
320
321 if (!fAnimRotate && !fAnimTranslate) {
322 // Keep returning true so that the last frame time is tracked
323 fLastFrameTime = -1.f;
324 return false;
325 }
326
327 switch(fCurrentStage) {
328 case AnimStage::kMoveLeft:
329 fSubpixelX += 2.f * dt;
330 if (fSubpixelX >= 1.f) {
331 fSubpixelX = 1.f;
332 fCurrentStage = AnimStage::kMoveDown;
333 }
334 break;
335 case AnimStage::kMoveDown:
336 fSubpixelY += 2.f * dt;
337 if (fSubpixelY >= 1.f) {
338 fSubpixelY = 1.f;
339 fCurrentStage = AnimStage::kMoveRight;
340 }
341 break;
342 case AnimStage::kMoveRight:
343 fSubpixelX -= 2.f * dt;
344 if (fSubpixelX <= -1.f) {
345 fSubpixelX = -1.f;
346 fCurrentStage = AnimStage::kMoveUp;
347 }
348 break;
349 case AnimStage::kMoveUp:
350 fSubpixelY -= 2.f * dt;
351 if (fSubpixelY <= -1.f) {
352 fSubpixelY = -1.f;
353 fCurrentStage = fAnimRotate ? AnimStage::kRotate : AnimStage::kMoveLeft;
354 }
355 break;
356 case AnimStage::kRotate: {
357 SkScalar newAngle = fAngle + dt * 15.f;
358 bool completed = SkScalarMod(newAngle, 15.f) < SkScalarMod(fAngle, 15.f);
359 fAngle = SkScalarMod(newAngle, 360.f);
360 if (completed) {
361 // Make sure we're on a 15 degree boundary
362 fAngle = 15.f * SkScalarRoundToScalar(fAngle / 15.f);
363 if (fAnimTranslate) {
364 fCurrentStage = this->getTranslationStage();
365 }
366 }
367 } break;
368 }
369
370 return true;
371 }
#define SkScalarMod(x, y)
Definition: SkScalar.h:41
#define SkScalarRoundToScalar(x)
Definition: SkScalar.h:32
float SkScalar
Definition: extension.cpp:12

◆ draw()

void skiagm::ThinAASlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 281 of file ThinAASlide.cpp.

281 {
282 canvas->clear(0xFFFFFFFF);
283 // Move away from screen edge and add instructions
286 canvas->translate(60.f, 20.f);
287 canvas->drawString("Each row features a rendering command under different AA strategies. "
288 "Native refers to the current backend of the viewer, e.g. OpenGL.",
289 0, 0, font, text);
290
291 canvas->drawString(SkStringPrintf("Stroke width: %.2f ('-' to decrease, '=' to increase)",
292 fStrokeWidth), 0, 24, font, text);
293 canvas->drawString(SkStringPrintf("Rotation: %.3f ('r' to animate, 'y' sets to 90, 'u' sets"
294 " to 0, 'space' adds 15)", fAngle), 0, 36, font, text);
295 canvas->drawString(SkStringPrintf("Translation: %.3f, %.3f ('t' to animate)",
296 fSubpixelX, fSubpixelY), 0, 48, font, text);
297
298 canvas->translate(0.f, 100.f);
299
300 // Draw with surface matching current viewer surface type
301 this->drawShapes(canvas, "Native", 0, fNative);
302
303 // Draw with forced raster backend so it's easy to compare side-by-side
304 this->drawShapes(canvas, "Raster", 1, fRaster);
305
306 // Draw paths as hairlines + alpha hack
307 this->drawShapes(canvas, "Hairline", 2, fHairline);
308
309 // Draw at 4x supersampling in bottom left
310 this->drawShapes(canvas, "SSx16", 3, fSS4);
311
312 // And lastly 16x supersampling in bottom right
313 this->drawShapes(canvas, "SSx64", 4, fSS16);
314 }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
std::u16string text
sk_sp< SkTypeface > DefaultTypeface()
font
Font Metadata and Metrics.

◆ load()

void skiagm::ThinAASlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 249 of file ThinAASlide.cpp.

249 {
250 // Setup all base renderers
251 fShapes.push_back(RectRenderer::Make());
252 fShapes.push_back(PathRenderer::MakeLine());
253 fShapes.push_back(PathRenderer::MakeLines(4.f)); // 2 segments
254 fShapes.push_back(PathRenderer::MakeCurve(2.f)); // Shallow curve
255 fShapes.push_back(PathRenderer::MakeCurve(8.f)); // Deep curve
256
257 for (int i = 0; i < fShapes.size(); ++i) {
258 fNative.push_back(OffscreenShapeRenderer::Make(fShapes[i], 1));
259 fRaster.push_back(OffscreenShapeRenderer::Make(fShapes[i], 1, /* raster */ true));
260 fSS4.push_back(OffscreenShapeRenderer::Make(fShapes[i], 4)); // 4x4 -> 16 samples
261 fSS16.push_back(OffscreenShapeRenderer::Make(fShapes[i], 8)); // 8x8 -> 64 samples
262
263 fHairline.push_back(OffscreenShapeRenderer::Make(fRaster[i]->toHairline(), 1));
264 }
265
266 // Start it at something subpixel
267 fStrokeWidth = 0.5f;
268
269 fSubpixelX = 0.f;
270 fSubpixelY = 0.f;
271 fAngle = 0.f;
272
273 fCurrentStage = AnimStage::kMoveLeft;
274 fLastFrameTime = -1.f;
275
276 // Don't animate in the beginning
277 fAnimTranslate = false;
278 fAnimRotate = false;
279 }
static sk_sp< OffscreenShapeRenderer > Make(sk_sp< ShapeRenderer > renderer, int supersample, bool forceRaster=false)
static sk_sp< ShapeRenderer > MakeCurve(SkScalar depth, bool hairline=false)
Definition: ThinAASlide.cpp:81
static sk_sp< ShapeRenderer > MakeLine(bool hairline=false)
Definition: ThinAASlide.cpp:73
static sk_sp< ShapeRenderer > MakeLines(SkScalar depth, bool hairline=false)
Definition: ThinAASlide.cpp:77
static sk_sp< ShapeRenderer > Make()
Definition: ThinAASlide.cpp:46

◆ onChar()

bool skiagm::ThinAASlide::onChar ( SkUnichar  key)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 373 of file ThinAASlide.cpp.

373 {
374 switch(key) {
375 case 't':
376 // Toggle translation animation.
377 fAnimTranslate = !fAnimTranslate;
378 if (!fAnimTranslate && fAnimRotate && fCurrentStage != AnimStage::kRotate) {
379 // Turned off an active translation so go to rotating
380 fCurrentStage = AnimStage::kRotate;
381 } else if (fAnimTranslate && !fAnimRotate &&
382 fCurrentStage == AnimStage::kRotate) {
383 // Turned on translation, rotation had been paused too, so reset the stage
384 fCurrentStage = this->getTranslationStage();
385 }
386 return true;
387 case 'r':
388 // Toggle rotation animation.
389 fAnimRotate = !fAnimRotate;
390 if (!fAnimRotate && fAnimTranslate && fCurrentStage == AnimStage::kRotate) {
391 // Turned off an active rotation so go back to translation
392 fCurrentStage = this->getTranslationStage();
393 } else if (fAnimRotate && !fAnimTranslate &&
394 fCurrentStage != AnimStage::kRotate) {
395 // Turned on rotation, translation had been paused too, so reset to rotate
396 fCurrentStage = AnimStage::kRotate;
397 }
398 return true;
399 case 'u': fAngle = 0.f; return true;
400 case 'y': fAngle = 90.f; return true;
401 case ' ': fAngle = SkScalarMod(fAngle + 15.f, 360.f); return true;
402 case '-': fStrokeWidth = std::max(0.1f, fStrokeWidth - 0.05f); return true;
403 case '=': fStrokeWidth = std::min(1.f, fStrokeWidth + 0.05f); return true;
404 }
405 return false;
406 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

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