c0bd9f9fe5
Current strategy: everything from the top Things to look at first are the manual changes: - added tools/rewrite_includes.py - removed -Idirectives from BUILD.gn - various compile.sh simplifications - tweak tools/embed_resources.py - update gn/find_headers.py to write paths from the top - update gn/gn_to_bp.py SkUserConfig.h layout so that #include "include/config/SkUserConfig.h" always gets the header we want. No-Presubmit: true Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
77 lines
2.7 KiB
C++
77 lines
2.7 KiB
C++
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "bench/SKPAnimationBench.h"
|
|
#include "include/core/SkMultiPictureDraw.h"
|
|
#include "include/core/SkSurface.h"
|
|
#include "tools/flags/CommandLineFlags.h"
|
|
|
|
SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, const SkIRect& clip,
|
|
Animation* animation, bool doLooping)
|
|
: INHERITED(name, pic, clip, 1.0, false, doLooping)
|
|
, fAnimation(SkRef(animation)) {
|
|
fUniqueName.printf("%s_%s", name, fAnimation->getTag());
|
|
}
|
|
|
|
const char* SKPAnimationBench::onGetUniqueName() {
|
|
return fUniqueName.c_str();
|
|
}
|
|
|
|
void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) {
|
|
INHERITED::onPerCanvasPreDraw(canvas);
|
|
fDevBounds = canvas->getDeviceClipBounds();
|
|
SkAssertResult(!fDevBounds.isEmpty());
|
|
fAnimationTimer.start();
|
|
}
|
|
|
|
void SKPAnimationBench::drawPicture() {
|
|
fAnimationTimer.end();
|
|
|
|
for (int j = 0; j < this->tileRects().count(); ++j) {
|
|
SkMatrix trans = SkMatrix::MakeTrans(-1.f * this->tileRects()[j].fLeft,
|
|
-1.f * this->tileRects()[j].fTop);
|
|
fAnimation->preConcatFrameMatrix(fAnimationTimer.fWall, fDevBounds, &trans);
|
|
this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &trans, nullptr);
|
|
}
|
|
|
|
for (int j = 0; j < this->tileRects().count(); ++j) {
|
|
this->surfaces()[j]->getCanvas()->flush();
|
|
}
|
|
}
|
|
|
|
class ZoomAnimation : public SKPAnimationBench::Animation {
|
|
public:
|
|
ZoomAnimation(SkScalar zoomMax, double zoomPeriodMs)
|
|
: fZoomMax(zoomMax)
|
|
, fZoomPeriodMs(zoomPeriodMs) {
|
|
}
|
|
|
|
virtual const char* getTag() { return "zoom"; }
|
|
|
|
virtual void preConcatFrameMatrix(double animationTimeMs, const SkIRect& devBounds,
|
|
SkMatrix* drawMatrix) {
|
|
double t = fmod(animationTimeMs / fZoomPeriodMs, 1.0); // t is in [0, 1).
|
|
t = fabs(2 * t - 1); // Make t ping-pong between 0 and 1
|
|
SkScalar zoom = static_cast<SkScalar>(pow(fZoomMax, t));
|
|
|
|
SkPoint center = SkPoint::Make((devBounds.fLeft + devBounds.fRight) / 2.0f,
|
|
(devBounds.fTop + devBounds.fBottom) / 2.0f);
|
|
drawMatrix->preTranslate(center.fX, center.fY);
|
|
drawMatrix->preScale(zoom, zoom);
|
|
drawMatrix->preTranslate(-center.fX, -center.fY);
|
|
}
|
|
|
|
private:
|
|
double fZoomMax;
|
|
double fZoomPeriodMs;
|
|
};
|
|
|
|
SKPAnimationBench::Animation* SKPAnimationBench::CreateZoomAnimation(SkScalar zoomMax,
|
|
double zoomPeriodMs) {
|
|
return new ZoomAnimation(zoomMax, zoomPeriodMs);
|
|
}
|