Flutter Engine
The Flutter Engine
SKPAnimationBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/GpuTools.h"
12
13
15 sk_sp<Animation> animation, bool doLooping)
16 : INHERITED(name, pic, clip, 1.0, doLooping)
17 , fAnimation(std::move(animation)) {
18 fUniqueName.printf("%s_%s", name, fAnimation->getTag());
19}
20
22 return fUniqueName.c_str();
23}
24
27 fDevBounds = canvas->getDeviceClipBounds();
28 SkAssertResult(!fDevBounds.isEmpty());
29}
30
32 for (int j = 0; j < this->tileRects().size(); ++j) {
33 SkMatrix trans = SkMatrix::Translate(-1.f * this->tileRects()[j].fLeft,
34 -1.f * this->tileRects()[j].fTop);
35 fAnimation->preConcatFrameMatrix(fAnimationTime.nextRangeF(0, 1000), fDevBounds, &trans);
36 this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &trans, nullptr);
37 }
38
39 for (int j = 0; j < this->tileRects().size(); ++j) {
40 skgpu::Flush(this->surfaces()[j].get());
41 }
42}
43
45public:
46 ZoomAnimation(SkScalar zoomMax, double zoomPeriodMs)
47 : fZoomMax(zoomMax)
48 , fZoomPeriodMs(zoomPeriodMs) {
49 }
50
51 const char* getTag() override { return "zoom"; }
52
53 void preConcatFrameMatrix(double animationTimeMs, const SkIRect& devBounds,
54 SkMatrix* drawMatrix) override {
55 double t = fmod(animationTimeMs / fZoomPeriodMs, 1.0); // t is in [0, 1).
56 t = fabs(2 * t - 1); // Make t ping-pong between 0 and 1
57 SkScalar zoom = static_cast<SkScalar>(pow(fZoomMax, t));
58
59 SkPoint center = SkPoint::Make((devBounds.fLeft + devBounds.fRight) / 2.0f,
60 (devBounds.fTop + devBounds.fBottom) / 2.0f);
61 drawMatrix->preTranslate(center.fX, center.fY);
62 drawMatrix->preScale(zoom, zoom);
63 drawMatrix->preTranslate(-center.fX, -center.fY);
64 }
65
66private:
67 double fZoomMax;
68 double fZoomPeriodMs;
69};
70
72 double zoomPeriodMs) {
73 return sk_make_sp<ZoomAnimation>(zoomMax, zoomPeriodMs);
74}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
static SkScalar center(float pos0, float pos1)
SKPAnimationBench(const char *name, const SkPicture *, const SkIRect &devClip, sk_sp< Animation >, bool doLooping)
const char * onGetUniqueName() override
void drawPicture() override
void onPerCanvasPreDraw(SkCanvas *canvas) override
static sk_sp< Animation > MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs)
const skia_private::TArray< sk_sp< SkSurface > > & surfaces() const
Definition: SKPBench.h:49
void onPerCanvasPreDraw(SkCanvas *) override
Definition: SKPBench.cpp:56
const SkPicture * picture() const
Definition: SKPBench.h:48
const SkTDArray< SkIRect > & tileRects() const
Definition: SKPBench.h:50
SkIRect getDeviceClipBounds() const
Definition: SkCanvas.cpp:1607
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
int size() const
Definition: SkTDArray.h:138
const char * getTag() override
ZoomAnimation(SkScalar zoomMax, double zoomPeriodMs)
void preConcatFrameMatrix(double animationTimeMs, const SkIRect &devBounds, SkMatrix *drawMatrix) override
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
const myers::Point & get(const myers::Segment &)
void Flush(SkSurface *surface)
Definition: GpuTools.h:25
Definition: ref_ptr.h:256
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
bool isEmpty() const
Definition: SkRect.h:202
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173