diff options
author | Joe Gregorio <jcgregorio@google.com> | 2017-04-19 14:05:14 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-19 18:46:52 +0000 |
commit | 1e735c0256c5512a48cdd97cbb53141c81ac9539 (patch) | |
tree | e67bbe6aa3d2ba233d46eb9751ab7e6ff703d7c8 /tools/fiddle | |
parent | b82fdc70b5d1323b3a6c367895ec8689acaed118 (diff) |
[fiddle] Add simple animation support.
BUG=skia:
Change-Id: I6453afb1fe18e210d3c505b56777b8b19501ca2f
Reviewed-on: https://skia-review.googlesource.com/13810
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Diffstat (limited to 'tools/fiddle')
-rwxr-xr-x | tools/fiddle/animate.sh | 17 | ||||
-rw-r--r-- | tools/fiddle/draw.cpp | 2 | ||||
-rw-r--r-- | tools/fiddle/fiddle_main.cpp | 12 | ||||
-rw-r--r-- | tools/fiddle/fiddle_main.h | 2 |
4 files changed, 31 insertions, 2 deletions
diff --git a/tools/fiddle/animate.sh b/tools/fiddle/animate.sh new file mode 100755 index 0000000000..cbd62bbcc9 --- /dev/null +++ b/tools/fiddle/animate.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Copyright 2017 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Create a 3 second long animation from the Raster output of fiddle at 15 fps. +FPS=15 +DURATION=3 +FRAMES=$((DURATION * FPS)) +mkdir -p /tmp/animation +for i in $(seq -f "%05g" 0 $FRAMES) +do + ./out/Release/fiddle --duration $DURATION --frame `bc -l <<< "$i/$FRAMES"` | ./tools/fiddle/parse-fiddle-output + cp /tmp/fiddle_Raster.png /tmp/animation/image-"$i".png +done +cd /tmp/animation; ffmpeg -r $FPS -pattern_type glob -i '*.png' -c:v libvpx-vp9 -lossless 1 output.webm diff --git a/tools/fiddle/draw.cpp b/tools/fiddle/draw.cpp index 9eabd3b77c..8e94883313 100644 --- a/tools/fiddle/draw.cpp +++ b/tools/fiddle/draw.cpp @@ -19,7 +19,7 @@ void draw(SkCanvas* canvas) { canvas->clear(SK_ColorWHITE); SkMatrix matrix; matrix.setScale(0.75f, 0.75f); - matrix.preRotate(30.0f); + matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s. SkPaint paint; paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index 62289d20e9..2ce9beb944 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -10,11 +10,18 @@ #include <sstream> #include <string> +#include "SkCommandLineFlags.h" + #include "fiddle_main.h" +DEFINE_double(duration, 1.0, "The total duration, in seconds, of the animation we are drawing."); +DEFINE_double(frame, 1.0, "A double value in [0, 1] that specifies the point in animation to draw."); + // Globals externed in fiddle_main.h SkBitmap source; sk_sp<SkImage> image; +double duration; // The total duration of the animation in seconds. +double frame; // A value in [0, 1] of where we are in the animation. // Global used by the local impl of SkDebugf. std::ostringstream gTextOutput; @@ -111,7 +118,10 @@ static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) { -int main() { +int main(int argc, char** argv) { + SkCommandLineFlags::Parse(argc, argv); + duration = FLAGS_duration; + frame = FLAGS_frame; DrawOptions options = GetDrawOptions(); // If textOnly then only do one type of image, otherwise the text // output is duplicated for each type. diff --git a/tools/fiddle/fiddle_main.h b/tools/fiddle/fiddle_main.h index 078c26c3fd..7be317b8c1 100644 --- a/tools/fiddle/fiddle_main.h +++ b/tools/fiddle/fiddle_main.h @@ -22,6 +22,8 @@ extern SkBitmap source; extern sk_sp<SkImage> image; +extern double duration; // The total duration of the animation in seconds. +extern double frame; // A value in [0, 1] of where we are in the animation. struct DrawOptions { DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16, bool textOnly, const char* s) |