Removed unused SkInterpolator
Bug: skia:11852
Change-Id: I7a9eb2e0594bc1bdf6e7ba5355b6f00cc177253f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/395476
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/gn/samples.gni b/gn/samples.gni
index 2cd42aa..a248613 100644
--- a/gn/samples.gni
+++ b/gn/samples.gni
@@ -25,7 +25,6 @@
"$_samplecode/SampleChineseFling.cpp",
"$_samplecode/SampleCircle.cpp",
"$_samplecode/SampleClip.cpp",
- "$_samplecode/SampleClipDrawMatch.cpp",
"$_samplecode/SampleClock.cpp",
"$_samplecode/SampleComplexClip.cpp",
"$_samplecode/SampleCowboy.cpp",
@@ -37,12 +36,10 @@
"$_samplecode/SampleFatBits.cpp",
"$_samplecode/SampleFillType.cpp",
"$_samplecode/SampleFilterBounds.cpp",
- "$_samplecode/SampleFilterQuality.cpp",
"$_samplecode/SampleFitCubicToCircle.cpp",
"$_samplecode/SampleFlutterAnimate.cpp",
"$_samplecode/SampleGlyphTransform.cpp",
"$_samplecode/SampleGradients.cpp",
- "$_samplecode/SampleHT.cpp",
"$_samplecode/SampleHairCurves.cpp",
"$_samplecode/SampleHairModes.cpp",
"$_samplecode/SampleImageFilterDAG.cpp",
diff --git a/gn/tests.gni b/gn/tests.gni
index 7fda740..5b56c58 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -139,7 +139,6 @@
"$_tests/IndexedPngOverflowTest.cpp",
"$_tests/InfRectTest.cpp",
"$_tests/InsetConvexPolyTest.cpp",
- "$_tests/InterpolatorTest.cpp",
"$_tests/InvalidIndexedPngTest.cpp",
"$_tests/IsClosedSingleContourTest.cpp",
"$_tests/JSONTest.cpp",
diff --git a/gn/utils.gni b/gn/utils.gni
index 06b8bbb..afdd675 100644
--- a/gn/utils.gni
+++ b/gn/utils.gni
@@ -14,7 +14,6 @@
"$_include/utils/SkCanvasStateUtils.h",
"$_include/utils/SkCustomTypeface.h",
"$_include/utils/SkEventTracer.h",
- "$_include/utils/SkInterpolator.h",
"$_include/utils/SkNWayCanvas.h",
"$_include/utils/SkNoDrawCanvas.h",
"$_include/utils/SkNullCanvas.h",
@@ -48,7 +47,6 @@
"$_src/utils/SkFloatToDecimal.cpp",
"$_src/utils/SkFloatToDecimal.h",
"$_src/utils/SkFloatUtils.h",
- "$_src/utils/SkInterpolator.cpp",
"$_src/utils/SkJSON.cpp",
"$_src/utils/SkJSON.h",
"$_src/utils/SkJSONWriter.cpp",
diff --git a/include/utils/SkInterpolator.h b/include/utils/SkInterpolator.h
deleted file mode 100644
index be13909..0000000
--- a/include/utils/SkInterpolator.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkInterpolator_DEFINED
-#define SkInterpolator_DEFINED
-
-#include "include/core/SkScalar.h"
-#include "include/private/SkNoncopyable.h"
-#include "include/private/SkTo.h"
-
-class SK_API SkInterpolatorBase : SkNoncopyable {
-public:
- enum Result {
- kNormal_Result,
- kFreezeStart_Result,
- kFreezeEnd_Result
- };
-protected:
- SkInterpolatorBase();
- ~SkInterpolatorBase();
-public:
- void reset(int elemCount, int frameCount);
-
- /** Return the start and end time for this interpolator.
- If there are no key frames, return false.
- @param startTime If not null, returns the time (in milliseconds) of the
- first keyframe. If there are no keyframes, this param
- is ignored (left unchanged).
- @param endTime If not null, returns the time (in milliseconds) of the
- last keyframe. If there are no keyframes, this parameter
- is ignored (left unchanged).
- @return True if there are key frames, or false if there are none.
- */
- bool getDuration(SkMSec* startTime, SkMSec* endTime) const;
-
-
- /** Set the whether the repeat is mirrored.
- @param mirror If true, the odd repeats interpolate from the last key
- frame and the first.
- */
- void setMirror(bool mirror) {
- fFlags = SkToU8((fFlags & ~kMirror) | (int)mirror);
- }
-
- /** Set the repeat count. The repeat count may be fractional.
- @param repeatCount Multiplies the total time by this scalar.
- */
- void setRepeatCount(SkScalar repeatCount) { fRepeat = repeatCount; }
-
- /** Set the whether the repeat is mirrored.
- @param reset If true, the odd repeats interpolate from the last key
- frame and the first.
- */
- void setReset(bool reset) {
- fFlags = SkToU8((fFlags & ~kReset) | (int)reset);
- }
-
- Result timeToT(SkMSec time, SkScalar* T, int* index, bool* exact) const;
-
-protected:
- enum Flags {
- kMirror = 1,
- kReset = 2,
- kHasBlend = 4
- };
- static SkScalar ComputeRelativeT(SkMSec time, SkMSec prevTime, SkMSec nextTime,
- const SkScalar blend[4] = nullptr);
- int16_t fFrameCount;
- uint8_t fElemCount;
- uint8_t fFlags;
- SkScalar fRepeat;
- struct SkTimeCode {
- SkMSec fTime;
- SkScalar fBlend[4];
- };
- SkTimeCode* fTimes; // pointer into fStorage
- void* fStorage;
-#ifdef SK_DEBUG
- SkTimeCode(* fTimesArray)[10];
-#endif
-};
-
-class SK_API SkInterpolator : public SkInterpolatorBase {
-public:
- SkInterpolator();
- SkInterpolator(int elemCount, int frameCount);
- void reset(int elemCount, int frameCount);
-
- /** Add or replace a key frame, copying the values[] data into the
- interpolator.
- @param index The index of this frame (frames must be ordered by time)
- @param time The millisecond time for this frame
- @param values The array of values [elemCount] for this frame. The data
- is copied into the interpolator.
- @param blend A positive scalar specifying how to blend between this
- and the next key frame. [0...1) is a cubic lag/log/lag
- blend (slow to change at the beginning and end)
- 1 is a linear blend (default)
- */
- bool setKeyFrame(int index, SkMSec time, const SkScalar values[],
- const SkScalar blend[4] = nullptr);
-
- /** Return the computed values given the specified time. Return whether
- those values are the result of pinning to either the first
- (kFreezeStart) or last (kFreezeEnd), or from interpolated the two
- nearest key values (kNormal).
- @param time The time to sample (in milliseconds)
- @param (may be null) where to write the computed values.
- */
- Result timeToValues(SkMSec time, SkScalar values[] = nullptr) const;
-
-private:
- SkScalar* fValues; // pointer into fStorage
-#ifdef SK_DEBUG
- SkScalar(* fScalarsArray)[10];
-#endif
- using INHERITED = SkInterpolatorBase;
-};
-
-/** Interpolate a cubic curve, typically to provide an ease-in ease-out transition.
- All the parameters are in the range of [0...1].
- The input value is treated as the x-coordinate of the cubic.
- The output value is the y-coordinate on the cubic at the x-coordinate.
-
- @param value The x-coordinate pinned between [0..1].
- @param bx,by,cx,cy The cubic control points where the cubic is specified
- as (0,0) (bx,by) (cx,cy) (1,1)
- @return the corresponding y-coordinate value, from [0..1].
-*/
-SkScalar SkUnitCubicInterp(SkScalar value, SkScalar bx, SkScalar by,
- SkScalar cx, SkScalar cy);
-
-#endif
diff --git a/samplecode/SampleClipDrawMatch.cpp b/samplecode/SampleClipDrawMatch.cpp
deleted file mode 100644
index bdbb54b..0000000
--- a/samplecode/SampleClipDrawMatch.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * 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 "include/core/SkCanvas.h"
-#include "include/core/SkPath.h"
-#include "include/core/SkRRect.h"
-#include "include/core/SkTime.h"
-#include "include/utils/SkInterpolator.h"
-#include "samplecode/Sample.h"
-
-// This slide tests out the match up between BW clipping and rendering. It can
-// draw a large rect through some clip geometry and draw the same geometry
-// normally. Which one is drawn first can be toggled. The pair of objects is translated
-// fractionally (via an animator) to expose snapping bugs. The key bindings are:
-// 1-9: the different geometries
-// t: toggle which is drawn first the clip or the normal geometry
-// f: flip-flops which corner the bottom AA clip rect occupies in the complex clip cases
-
-// The possible geometric combinations to test
-enum Geometry {
- kRect_Geometry,
- kRRect_Geometry,
- kCircle_Geometry,
- kConvexPath_Geometry,
- kConcavePath_Geometry,
- kRectAndRect_Geometry,
- kRectAndRRect_Geometry,
- kRectAndConvex_Geometry,
- kRectAndConcave_Geometry
-};
-
-// The basic rect used is [kMin,kMin]..[kMax,kMax]
-static const float kMin = 100.5f;
-static const float kMid = 200.0f;
-static const float kMax = 299.5f;
-
-// The translation applied to the base AA rect in the combination cases
-// (i.e., kRectAndRect through kRectAndConcave)
-static const float kXlate = 100.0f;
-
-SkRect create_rect(const SkPoint& offset) {
- SkRect r = SkRect::MakeLTRB(kMin, kMin, kMax, kMax);
- r.offset(offset);
- return r;
-}
-
-SkRRect create_rrect(const SkPoint& offset) {
- SkRRect rrect;
- rrect.setRectXY(create_rect(offset), 10, 10);
- return rrect;
-}
-
-SkRRect create_circle(const SkPoint& offset) {
- SkRRect circle;
- circle.setOval(create_rect(offset));
- return circle;
-}
-
-SkPath create_convex_path(const SkPoint& offset) {
- SkPath convexPath;
- convexPath.moveTo(kMin, kMin);
- convexPath.lineTo(kMax, kMax);
- convexPath.lineTo(kMin, kMax);
- convexPath.close();
- convexPath.offset(offset.fX, offset.fY);
- return convexPath;
-}
-
-SkPath create_concave_path(const SkPoint& offset) {
- SkPath concavePath;
- concavePath.moveTo(kMin, kMin);
- concavePath.lineTo(kMid, 105.0f);
- concavePath.lineTo(kMax, kMin);
- concavePath.lineTo(295.0f, kMid);
- concavePath.lineTo(kMax, kMax);
- concavePath.lineTo(kMid, 295.0f);
- concavePath.lineTo(kMin, kMax);
- concavePath.lineTo(105.0f, kMid);
- concavePath.close();
-
- concavePath.offset(offset.fX, offset.fY);
- return concavePath;
-}
-
-static void draw_normal_geom(SkCanvas* canvas, const SkPoint& offset, int geom, bool useAA) {
- SkPaint p;
- p.setAntiAlias(useAA);
- p.setColor(SK_ColorBLACK);
-
- switch (geom) {
- case kRect_Geometry: // fall thru
- case kRectAndRect_Geometry:
- canvas->drawRect(create_rect(offset), p);
- break;
- case kRRect_Geometry: // fall thru
- case kRectAndRRect_Geometry:
- canvas->drawRRect(create_rrect(offset), p);
- break;
- case kCircle_Geometry:
- canvas->drawRRect(create_circle(offset), p);
- break;
- case kConvexPath_Geometry: // fall thru
- case kRectAndConvex_Geometry:
- canvas->drawPath(create_convex_path(offset), p);
- break;
- case kConcavePath_Geometry: // fall thru
- case kRectAndConcave_Geometry:
- canvas->drawPath(create_concave_path(offset), p);
- break;
- }
-}
-
-class ClipDrawMatchView : public Sample {
- SkInterpolator fTrans;
- Geometry fGeom;
- bool fClipFirst = true;
- int fSign = 1;
- const double fStart = SkTime::GetMSecs();
-
-public:
- ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry) {}
-
-private:
- void onOnceBeforeDraw() override {
- SkScalar values[2];
-
- fTrans.setRepeatCount(999);
- values[0] = values[1] = 0;
- fTrans.setKeyFrame(0, GetMSecs() + 1000, values);
- values[1] = 1;
- fTrans.setKeyFrame(1, GetMSecs() + 2000, values);
- values[0] = values[1] = 1;
- fTrans.setKeyFrame(2, GetMSecs() + 3000, values);
- values[1] = 0;
- fTrans.setKeyFrame(3, GetMSecs() + 4000, values);
- values[0] = 0;
- fTrans.setKeyFrame(4, GetMSecs() + 5000, values);
- }
-
- SkString name() override { return SkString("ClipDrawMatch"); }
-
- bool onChar(SkUnichar uni) override {
- switch (uni) {
- case '1': fGeom = kRect_Geometry; return true;
- case '2': fGeom = kRRect_Geometry; return true;
- case '3': fGeom = kCircle_Geometry; return true;
- case '4': fGeom = kConvexPath_Geometry; return true;
- case '5': fGeom = kConcavePath_Geometry; return true;
- case '6': fGeom = kRectAndRect_Geometry; return true;
- case '7': fGeom = kRectAndRRect_Geometry; return true;
- case '8': fGeom = kRectAndConvex_Geometry; return true;
- case '9': fGeom = kRectAndConcave_Geometry; return true;
- case 'f': fSign = -fSign; return true;
- case 't': fClipFirst = !fClipFirst; return true;
- default: break;
- }
- return false;
- }
-
- void drawClippedGeom(SkCanvas* canvas, const SkPoint& offset, bool useAA) {
-
- int count = canvas->save();
-
- switch (fGeom) {
- case kRect_Geometry:
- canvas->clipRect(create_rect(offset), useAA);
- break;
- case kRRect_Geometry:
- canvas->clipRRect(create_rrect(offset), useAA);
- break;
- case kCircle_Geometry:
- canvas->clipRRect(create_circle(offset), useAA);
- break;
- case kConvexPath_Geometry:
- canvas->clipPath(create_convex_path(offset), useAA);
- break;
- case kConcavePath_Geometry:
- canvas->clipPath(create_concave_path(offset), useAA);
- break;
- case kRectAndRect_Geometry: {
- SkRect r = create_rect(offset);
- r.offset(fSign * kXlate, fSign * kXlate);
- canvas->clipRect(r, true); // AA here forces shader clips
- canvas->clipRect(create_rect(offset), useAA);
- } break;
- case kRectAndRRect_Geometry: {
- SkRect r = create_rect(offset);
- r.offset(fSign * kXlate, fSign * kXlate);
- canvas->clipRect(r, true); // AA here forces shader clips
- canvas->clipRRect(create_rrect(offset), useAA);
- } break;
- case kRectAndConvex_Geometry: {
- SkRect r = create_rect(offset);
- r.offset(fSign * kXlate, fSign * kXlate);
- canvas->clipRect(r, true); // AA here forces shader clips
- canvas->clipPath(create_convex_path(offset), useAA);
- } break;
- case kRectAndConcave_Geometry: {
- SkRect r = create_rect(offset);
- r.offset(fSign * kXlate, fSign * kXlate);
- canvas->clipRect(r, true); // AA here forces shader clips
- canvas->clipPath(create_concave_path(offset), useAA);
- } break;
- }
-
- SkISize size = canvas->getBaseLayerSize();
- SkRect bigR = SkRect::MakeWH(SkIntToScalar(size.width()), SkIntToScalar(size.height()));
-
- SkPaint p;
- p.setColor(SK_ColorRED);
-
- canvas->drawRect(bigR, p);
- canvas->restoreToCount(count);
- }
-
- // Draw a big red rect through some clip geometry and also draw that same
- // geometry in black. The order in which they are drawn can be swapped.
- // This tests whether the clip and normally drawn geometry match up.
- void drawGeometry(SkCanvas* canvas, const SkPoint& offset, bool useAA) {
- if (fClipFirst) {
- this->drawClippedGeom(canvas, offset, useAA);
- }
-
- draw_normal_geom(canvas, offset, fGeom, useAA);
-
- if (!fClipFirst) {
- this->drawClippedGeom(canvas, offset, useAA);
- }
- }
-
- void onDrawContent(SkCanvas* canvas) override {
- SkScalar trans[2];
- fTrans.timeToValues(GetMSecs(), trans);
-
- SkPoint offset;
- offset.set(trans[0], trans[1]);
-
- int saveCount = canvas->save();
- this->drawGeometry(canvas, offset, false);
- canvas->restoreToCount(saveCount);
- }
-
- SkMSec GetMSecs() const {
- return static_cast<SkMSec>(SkTime::GetMSecs() - fStart);
- }
-};
-
-DEF_SAMPLE( return new ClipDrawMatchView(); )
diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp
deleted file mode 100644
index 546ff7c..0000000
--- a/samplecode/SampleFilterQuality.cpp
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * 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 "include/core/SkCanvas.h"
-#include "include/core/SkData.h"
-#include "include/core/SkFont.h"
-#include "include/core/SkPath.h"
-#include "include/core/SkSurface.h"
-#include "include/core/SkTime.h"
-#include "include/effects/SkGradientShader.h"
-#include "include/utils/SkInterpolator.h"
-#include "include/utils/SkRandom.h"
-#include "samplecode/Sample.h"
-#include "tools/Resources.h"
-#include "tools/timer/TimeUtils.h"
-
-static sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info) {
- auto surface = canvas->makeSurface(info);
- if (!surface) {
- surface = SkSurface::MakeRaster(info);
- }
- return surface;
-}
-
-static sk_sp<SkShader> make_shader(const SkRect& bounds) {
- sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_128.png"));
- return image ? image->makeShader(SkSamplingOptions()) : nullptr;
-}
-
-#define N 128
-#define ANGLE_DELTA 3
-#define SCALE_DELTA (SK_Scalar1 / 32)
-
-static sk_sp<SkImage> make_image() {
- SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType);
- auto surface(SkSurface::MakeRaster(info));
- SkCanvas* canvas = surface->getCanvas();
- canvas->drawColor(SK_ColorWHITE);
-
- SkPath path;
- path.setFillType(SkPathFillType::kEvenOdd);
-
- path.addRect(SkRect::MakeWH(N/2, N));
- path.addRect(SkRect::MakeWH(N, N/2));
- path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close();
-
- SkPaint paint;
- paint.setShader(make_shader(SkRect::MakeWH(N, N)));
-
- canvas->drawPath(path, paint);
- return surface->makeImageSnapshot();
-}
-
-static sk_sp<SkImage> zoom_up(SkSurface* origSurf, SkImage* orig) {
- const SkScalar S = 16; // amount to scale up
- const int D = 2; // dimension scaling for the offscreen
- // since we only view the center, don't need to produce the entire thing
-
- SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D,
- kOpaque_SkAlphaType);
- auto surface(origSurf->makeSurface(info));
- SkCanvas* canvas = surface->getCanvas();
- canvas->drawColor(SK_ColorWHITE);
- canvas->scale(S, S);
- canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S,
- -SkScalarHalf(orig->height()) * (S - D) / S);
- canvas->drawImage(orig, 0, 0);
-
- if (S > 3) {
- SkPaint paint;
- paint.setColor(SK_ColorWHITE);
- for (int i = 1; i < orig->height(); ++i) {
- SkScalar y = SkIntToScalar(i);
- canvas->drawLine(0, y, SkIntToScalar(orig->width()), y, paint);
- }
- for (int i = 1; i < orig->width(); ++i) {
- SkScalar x = SkIntToScalar(i);
- canvas->drawLine(x, 0, x, SkIntToScalar(orig->height()), paint);
- }
- }
- return surface->makeImageSnapshot();
-}
-
-struct AnimValue {
- SkScalar fValue;
- SkScalar fMin;
- SkScalar fMax;
- SkScalar fMod;
-
- operator SkScalar() const { return fValue; }
-
- void set(SkScalar value, SkScalar min, SkScalar max) {
- fValue = value;
- fMin = min;
- fMax = max;
- fMod = 0;
- }
-
- void setMod(SkScalar value, SkScalar mod) {
- fValue = value;
- fMin = 0;
- fMax = 0;
- fMod = mod;
- }
-
- SkScalar inc(SkScalar delta) {
- fValue += delta;
- return this->fixUp();
- }
-
- SkScalar fixUp() {
- if (fMod) {
- fValue = SkScalarMod(fValue, fMod);
- } else {
- if (fValue > fMax) {
- fValue = fMax;
- } else if (fValue < fMin) {
- fValue = fMin;
- }
- }
- return fValue;
- }
-};
-
-static void draw_box_frame(SkCanvas* canvas, int width, int height) {
- SkPaint p;
- p.setStyle(SkPaint::kStroke_Style);
- p.setColor(SK_ColorRED);
- SkRect r = SkRect::MakeIWH(width, height);
- r.inset(0.5f, 0.5f);
- canvas->drawRect(r, p);
- canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), p);
- canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), p);
-}
-
-class FilterQualityView : public Sample {
- sk_sp<SkImage> fImage;
- AnimValue fScale, fAngle;
- SkSize fCell;
- SkInterpolator fTrans;
- SkMSec fCurrTime;
- bool fShowFatBits;
-
-public:
- FilterQualityView() : fTrans(2, 2), fShowFatBits(true) {
- fCell.set(256, 256);
-
- fScale.set(1, SK_Scalar1 / 8, 1);
- fAngle.setMod(0, 360);
-
- SkScalar values[2];
- fTrans.setMirror(true);
- fTrans.setReset(true);
-
- fCurrTime = 0;
-
- fTrans.setRepeatCount(999);
- values[0] = values[1] = 0;
- fTrans.setKeyFrame(0, fCurrTime, values);
- values[0] = values[1] = 1;
- fTrans.setKeyFrame(1, fCurrTime + 2000, values);
- }
-
-protected:
- SkString name() override { return SkString("FilterQuality"); }
-
- bool onChar(SkUnichar uni) override {
- switch (uni) {
- case '1': fAngle.inc(-ANGLE_DELTA); return true;
- case '2': fAngle.inc( ANGLE_DELTA); return true;
- case '3': fScale.inc(-SCALE_DELTA); return true;
- case '4': fScale.inc( SCALE_DELTA); return true;
- case '5': fShowFatBits = !fShowFatBits; return true;
- default: break;
- }
- return false;
- }
-
- void drawTheImage(SkCanvas* canvas, const SkISize& size, SkFilterQuality filter,
- SkScalar dx, SkScalar dy) {
- SkPaint paint;
- paint.setAntiAlias(true);
-
- SkAutoCanvasRestore acr(canvas, true);
-
- canvas->translate(dx, dy);
-
- canvas->translate(SkScalarHalf(size.width()), SkScalarHalf(size.height()));
- canvas->scale(fScale, fScale);
- canvas->rotate(fAngle);
- canvas->drawImage(fImage.get(), -SkScalarHalf(fImage->width()), -SkScalarHalf(fImage->height()),
- SkSamplingOptions(filter), &paint);
-
- if (false) {
- acr.restore();
- draw_box_frame(canvas, size.width(), size.height());
- }
- }
-
- void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScalar dy) {
- SkCanvas* origCanvas = canvas;
- SkAutoCanvasRestore acr(canvas, true);
-
- SkISize size = SkISize::Make(fImage->width(), fImage->height());
-
- sk_sp<SkSurface> surface;
- if (fShowFatBits) {
- // scale up so we don't clip rotations
- SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage->height() * 2,
- kOpaque_SkAlphaType);
- surface = make_surface(canvas, info);
- canvas = surface->getCanvas();
- canvas->drawColor(SK_ColorWHITE);
- size.set(info.width(), info.height());
- } else {
- canvas->translate(SkScalarHalf(fCell.width() - fImage->width()),
- SkScalarHalf(fCell.height() - fImage->height()));
- }
- this->drawTheImage(canvas, size, filter, dx, dy);
-
- if (surface) {
- sk_sp<SkImage> orig(surface->makeImageSnapshot());
- sk_sp<SkImage> zoomed(zoom_up(surface.get(), orig.get()));
- origCanvas->drawImage(zoomed.get(),
- SkScalarHalf(fCell.width() - zoomed->width()),
- SkScalarHalf(fCell.height() - zoomed->height()));
- }
- }
-
- void drawBorders(SkCanvas* canvas) {
- SkPaint p;
- p.setStyle(SkPaint::kStroke_Style);
- p.setColor(SK_ColorBLUE);
-
- SkRect r = SkRect::MakeWH(fCell.width() * 2, fCell.height() * 2);
- r.inset(SK_ScalarHalf, SK_ScalarHalf);
- canvas->drawRect(r, p);
- canvas->drawLine(r.left(), r.centerY(), r.right(), r.centerY(), p);
- canvas->drawLine(r.centerX(), r.top(), r.centerX(), r.bottom(), p);
- }
-
- void onOnceBeforeDraw() override {
- fImage = make_image();
- }
-
- void onDrawContent(SkCanvas* canvas) override {
- fCell.set(this->height() / 2, this->height() / 2);
-
- SkScalar trans[2];
- fTrans.timeToValues(fCurrTime, trans);
-
- for (int y = 0; y < 2; ++y) {
- for (int x = 0; x < 2; ++x) {
- int index = y * 2 + x;
- SkAutoCanvasRestore acr(canvas, true);
- canvas->translate(fCell.width() * x, fCell.height() * y);
- SkRect r = SkRect::MakeWH(fCell.width(), fCell.height());
- r.inset(4, 4);
- canvas->clipRect(r);
- this->drawHere(canvas, SkFilterQuality(index), trans[0], trans[1]);
- }
- }
-
- this->drawBorders(canvas);
-
- const SkScalar textX = fCell.width() * 2 + 30;
-
- SkFont font(nullptr, 36);
- SkPaint paint;
- canvas->drawString(SkStringPrintf("%.8g", (float)fScale), textX, 100, font, paint);
- canvas->drawString(SkStringPrintf("%.8g", (float)fAngle), textX, 150, font, paint);
- canvas->drawString(SkStringPrintf("%.8g", trans[0] ), textX, 200, font, paint);
- canvas->drawString(SkStringPrintf("%.8g", trans[1] ), textX, 250, font, paint);
- }
-
- bool onAnimate(double nanos) override {
- fCurrTime = TimeUtils::NanosToMSec(nanos);
- return true;
- }
-
-private:
- using INHERITED = Sample;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_SAMPLE( return new FilterQualityView(); )
diff --git a/samplecode/SampleHT.cpp b/samplecode/SampleHT.cpp
deleted file mode 100644
index 5547b31..0000000
--- a/samplecode/SampleHT.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/core/SkCanvas.h"
-#include "include/core/SkDrawable.h"
-#include "include/core/SkPictureRecorder.h"
-#include "include/utils/SkInterpolator.h"
-#include "include/utils/SkRandom.h"
-#include "samplecode/Sample.h"
-#include "src/core/SkPointPriv.h"
-#include "tools/timer/TimeUtils.h"
-
-const SkRect gUnitSquare = { -1, -1, 1, 1 };
-
-static void color_to_floats(SkColor c, SkScalar f[4]) {
- f[0] = SkIntToScalar(SkColorGetA(c));
- f[1] = SkIntToScalar(SkColorGetR(c));
- f[2] = SkIntToScalar(SkColorGetG(c));
- f[3] = SkIntToScalar(SkColorGetB(c));
-}
-
-static SkColor floats_to_color(const SkScalar f[4]) {
- return SkColorSetARGB(SkScalarRoundToInt(f[0]),
- SkScalarRoundToInt(f[1]),
- SkScalarRoundToInt(f[2]),
- SkScalarRoundToInt(f[3]));
-}
-
-static bool oval_contains(const SkRect& r, SkScalar x, SkScalar y) {
- SkPoint pt = SkMatrix::RectToRect(r, gUnitSquare).mapXY(x, y);
- return SkPointPriv::LengthSqd(pt) <= 1;
-}
-
-static SkColor rand_opaque_color(uint32_t seed) {
- SkRandom rand(seed);
- return rand.nextU() | (0xFF << 24);
-}
-
-class HTDrawable : public SkDrawable {
- SkRect fR;
- SkColor fColor;
- SkInterpolator* fInterp;
- SkMSec fTime;
-
-public:
- HTDrawable(SkRandom& rand) {
- fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480),
- rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
- fColor = rand_opaque_color(rand.nextU());
- fInterp = nullptr;
- fTime = 0;
- }
-
- void spawnAnimation(SkMSec now) {
- this->setTime(now);
-
- delete fInterp;
- fInterp = new SkInterpolator(5, 3);
- SkScalar values[5];
- color_to_floats(fColor, values); values[4] = 0;
- fInterp->setKeyFrame(0, now, values);
- values[0] = 0; values[4] = 180;
- fInterp->setKeyFrame(1, now + 1000, values);
- color_to_floats(rand_opaque_color(fColor), values); values[4] = 360;
- fInterp->setKeyFrame(2, now + 2000, values);
-
- fInterp->setMirror(true);
- fInterp->setRepeatCount(3);
-
- this->notifyDrawingChanged();
- }
-
- bool hitTest(SkScalar x, SkScalar y) {
- return oval_contains(fR, x, y);
- }
-
- void setTime(SkMSec time) { fTime = time; }
-
- void onDraw(SkCanvas* canvas) override {
- SkAutoCanvasRestore acr(canvas, false);
-
- SkPaint paint;
- paint.setAntiAlias(true);
-
- if (fInterp) {
- SkScalar values[5];
- SkInterpolator::Result res = fInterp->timeToValues(fTime, values);
- fColor = floats_to_color(values);
-
- canvas->save();
- canvas->rotate(values[4], fR.centerX(), fR.centerY());
-
- switch (res) {
- case SkInterpolator::kFreezeEnd_Result:
- delete fInterp;
- fInterp = nullptr;
- break;
- default:
- break;
- }
- }
- paint.setColor(fColor);
- canvas->drawRect(fR, paint);
- }
-
- SkRect onGetBounds() override { return fR; }
-};
-
-class HTView : public Sample {
-public:
- enum {
- N = 50,
- W = 640,
- H = 480,
- };
-
- struct Rec {
- HTDrawable* fDrawable;
- };
- Rec fArray[N];
- sk_sp<SkDrawable> fRoot;
- SkMSec fTime;
-
- HTView() {
- SkRandom rand;
-
- SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H));
- for (int i = 0; i < N; ++i) {
- fArray[i].fDrawable = new HTDrawable(rand);
- canvas->drawDrawable(fArray[i].fDrawable);
- fArray[i].fDrawable->unref();
- }
- fRoot = recorder.finishRecordingAsDrawable();
- }
-
-protected:
- SkString name() override { return SkString("HT"); }
-
- void onDrawContent(SkCanvas* canvas) override {
- canvas->drawDrawable(fRoot.get());
- }
-
- bool onAnimate(double nanos) override {
- fTime = TimeUtils::NanosToMSec(nanos);
- for (int i = 0; i < N; ++i) {
- fArray[i].fDrawable->setTime(fTime);
- }
- return true;
- }
-
- Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
- // search backwards to find the top-most
- for (int i = N - 1; i >= 0; --i) {
- if (fArray[i].fDrawable->hitTest(x, y)) {
- fArray[i].fDrawable->spawnAnimation(fTime);
- break;
- }
- }
- return nullptr;
- }
-
-private:
- using INHERITED = Sample;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_SAMPLE( return new HTView(); )
diff --git a/samplecode/SampleLayers.cpp b/samplecode/SampleLayers.cpp
index 39282f9..4ddb9a5 100644
--- a/samplecode/SampleLayers.cpp
+++ b/samplecode/SampleLayers.cpp
@@ -17,7 +17,6 @@
#include "include/core/SkTypeface.h"
#include "include/effects/SkGradientShader.h"
#include "include/utils/SkCamera.h"
-#include "include/utils/SkInterpolator.h"
#include "samplecode/Sample.h"
#include "src/core/SkClipOpPriv.h"
#include "src/utils/SkUTF.h"
diff --git a/src/utils/SkInterpolator.cpp b/src/utils/SkInterpolator.cpp
deleted file mode 100644
index 6bf2335..0000000
--- a/src/utils/SkInterpolator.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright 2008 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/utils/SkInterpolator.h"
-
-#include "include/core/SkMath.h"
-#include "include/private/SkFixed.h"
-#include "include/private/SkMalloc.h"
-#include "include/private/SkTo.h"
-#include "src/core/SkTSearch.h"
-
-SkInterpolatorBase::SkInterpolatorBase() {
- fStorage = nullptr;
- fTimes = nullptr;
- SkDEBUGCODE(fTimesArray = nullptr;)
-}
-
-SkInterpolatorBase::~SkInterpolatorBase() {
- if (fStorage) {
- sk_free(fStorage);
- }
-}
-
-void SkInterpolatorBase::reset(int elemCount, int frameCount) {
- fFlags = 0;
- fElemCount = SkToU8(elemCount);
- fFrameCount = SkToS16(frameCount);
- fRepeat = SK_Scalar1;
- if (fStorage) {
- sk_free(fStorage);
- fStorage = nullptr;
- fTimes = nullptr;
- SkDEBUGCODE(fTimesArray = nullptr);
- }
-}
-
-/* Each value[] run is formated as:
- <time (in msec)>
- <blend>
- <data[fElemCount]>
-
- Totaling fElemCount+2 entries per keyframe
-*/
-
-bool SkInterpolatorBase::getDuration(SkMSec* startTime, SkMSec* endTime) const {
- if (fFrameCount == 0) {
- return false;
- }
-
- if (startTime) {
- *startTime = fTimes[0].fTime;
- }
- if (endTime) {
- *endTime = fTimes[fFrameCount - 1].fTime;
- }
- return true;
-}
-
-SkScalar SkInterpolatorBase::ComputeRelativeT(SkMSec time, SkMSec prevTime,
- SkMSec nextTime, const SkScalar blend[4]) {
- SkASSERT(time > prevTime && time < nextTime);
-
- SkScalar t = (SkScalar)(time - prevTime) / (SkScalar)(nextTime - prevTime);
- return blend ?
- SkUnitCubicInterp(t, blend[0], blend[1], blend[2], blend[3]) : t;
-}
-
-SkInterpolatorBase::Result SkInterpolatorBase::timeToT(SkMSec time, SkScalar* T,
- int* indexPtr, bool* exactPtr) const {
- SkASSERT(fFrameCount > 0);
- Result result = kNormal_Result;
- if (fRepeat != SK_Scalar1) {
- SkMSec startTime = 0, endTime = 0; // initialize to avoid warning
- this->getDuration(&startTime, &endTime);
- SkMSec totalTime = endTime - startTime;
- SkMSec offsetTime = time - startTime;
- endTime = SkScalarFloorToInt(fRepeat * totalTime);
- if (offsetTime >= endTime) {
- SkScalar fraction = SkScalarFraction(fRepeat);
- offsetTime = fraction == 0 && fRepeat > 0 ? totalTime :
- (SkMSec) SkScalarFloorToInt(fraction * totalTime);
- result = kFreezeEnd_Result;
- } else {
- int mirror = fFlags & kMirror;
- offsetTime = offsetTime % (totalTime << mirror);
- if (offsetTime > totalTime) { // can only be true if fMirror is true
- offsetTime = (totalTime << 1) - offsetTime;
- }
- }
- time = offsetTime + startTime;
- }
-
- int index = SkTSearch<SkMSec>(&fTimes[0].fTime, fFrameCount, time,
- sizeof(SkTimeCode));
-
- bool exact = true;
-
- if (index < 0) {
- index = ~index;
- if (index == 0) {
- result = kFreezeStart_Result;
- } else if (index == fFrameCount) {
- if (fFlags & kReset) {
- index = 0;
- } else {
- index -= 1;
- }
- result = kFreezeEnd_Result;
- } else {
- exact = false;
- }
- }
- SkASSERT(index < fFrameCount);
- const SkTimeCode* nextTime = &fTimes[index];
- SkMSec nextT = nextTime[0].fTime;
- if (exact) {
- *T = 0;
- } else {
- SkMSec prevT = nextTime[-1].fTime;
- *T = ComputeRelativeT(time, prevT, nextT, nextTime[-1].fBlend);
- }
- *indexPtr = index;
- *exactPtr = exact;
- return result;
-}
-
-
-SkInterpolator::SkInterpolator() {
- INHERITED::reset(0, 0);
- fValues = nullptr;
- SkDEBUGCODE(fScalarsArray = nullptr;)
-}
-
-SkInterpolator::SkInterpolator(int elemCount, int frameCount) {
- SkASSERT(elemCount > 0);
- this->reset(elemCount, frameCount);
-}
-
-void SkInterpolator::reset(int elemCount, int frameCount) {
- INHERITED::reset(elemCount, frameCount);
- fStorage = sk_malloc_throw((sizeof(SkScalar) * elemCount +
- sizeof(SkTimeCode)) * frameCount);
- fTimes = (SkTimeCode*) fStorage;
- fValues = (SkScalar*) ((char*) fStorage + sizeof(SkTimeCode) * frameCount);
-#ifdef SK_DEBUG
- fTimesArray = (SkTimeCode(*)[10]) fTimes;
- fScalarsArray = (SkScalar(*)[10]) fValues;
-#endif
-}
-
-#define SK_Fixed1Third (SK_Fixed1/3)
-#define SK_Fixed2Third (SK_Fixed1*2/3)
-
-static const SkScalar gIdentityBlend[4] = {
- 0.33333333f, 0.33333333f, 0.66666667f, 0.66666667f
-};
-
-bool SkInterpolator::setKeyFrame(int index, SkMSec time,
- const SkScalar values[], const SkScalar blend[4]) {
- SkASSERT(values != nullptr);
-
- if (blend == nullptr) {
- blend = gIdentityBlend;
- }
-
- bool success = ~index == SkTSearch<SkMSec>(&fTimes->fTime, index, time,
- sizeof(SkTimeCode));
- SkASSERT(success);
- if (success) {
- SkTimeCode* timeCode = &fTimes[index];
- timeCode->fTime = time;
- memcpy(timeCode->fBlend, blend, sizeof(timeCode->fBlend));
- SkScalar* dst = &fValues[fElemCount * index];
- memcpy(dst, values, fElemCount * sizeof(SkScalar));
- }
- return success;
-}
-
-SkInterpolator::Result SkInterpolator::timeToValues(SkMSec time,
- SkScalar values[]) const {
- SkScalar T;
- int index;
- bool exact;
- Result result = timeToT(time, &T, &index, &exact);
- if (values) {
- const SkScalar* nextSrc = &fValues[index * fElemCount];
-
- if (exact) {
- memcpy(values, nextSrc, fElemCount * sizeof(SkScalar));
- } else {
- SkASSERT(index > 0);
-
- const SkScalar* prevSrc = nextSrc - fElemCount;
-
- for (int i = fElemCount - 1; i >= 0; --i) {
- values[i] = SkScalarInterp(prevSrc[i], nextSrc[i], T);
- }
- }
- }
- return result;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-typedef int Dot14;
-#define Dot14_ONE (1 << 14)
-#define Dot14_HALF (1 << 13)
-
-#define Dot14ToFloat(x) ((x) / 16384.f)
-
-static inline Dot14 Dot14Mul(Dot14 a, Dot14 b) {
- return (a * b + Dot14_HALF) >> 14;
-}
-
-static inline Dot14 eval_cubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C) {
- return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t);
-}
-
-static inline Dot14 pin_and_convert(SkScalar x) {
- if (x <= 0) {
- return 0;
- }
- if (x >= SK_Scalar1) {
- return Dot14_ONE;
- }
- return SkScalarToFixed(x) >> 2;
-}
-
-SkScalar SkUnitCubicInterp(SkScalar value, SkScalar bx, SkScalar by,
- SkScalar cx, SkScalar cy) {
- // pin to the unit-square, and convert to 2.14
- Dot14 x = pin_and_convert(value);
-
- if (x == 0) return 0;
- if (x == Dot14_ONE) return SK_Scalar1;
-
- Dot14 b = pin_and_convert(bx);
- Dot14 c = pin_and_convert(cx);
-
- // Now compute our coefficients from the control points
- // t -> 3b
- // t^2 -> 3c - 6b
- // t^3 -> 3b - 3c + 1
- Dot14 A = 3*b;
- Dot14 B = 3*(c - 2*b);
- Dot14 C = 3*(b - c) + Dot14_ONE;
-
- // Now search for a t value given x
- Dot14 t = Dot14_HALF;
- Dot14 dt = Dot14_HALF;
- for (int i = 0; i < 13; i++) {
- dt >>= 1;
- Dot14 guess = eval_cubic(t, A, B, C);
- if (x < guess) {
- t -= dt;
- } else {
- t += dt;
- }
- }
-
- // Now we have t, so compute the coeff for Y and evaluate
- b = pin_and_convert(by);
- c = pin_and_convert(cy);
- A = 3*b;
- B = 3*(c - 2*b);
- C = 3*(b - c) + Dot14_ONE;
- return SkFixedToScalar(eval_cubic(t, A, B, C) << 2);
-}
diff --git a/tests/InterpolatorTest.cpp b/tests/InterpolatorTest.cpp
deleted file mode 100644
index 2bb5180..0000000
--- a/tests/InterpolatorTest.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "include/private/SkTPin.h"
-#include "include/utils/SkInterpolator.h"
-
-#include "tests/Test.h"
-
-static SkScalar* iset(SkScalar array[3], int a, int b, int c) {
- array[0] = SkIntToScalar(a);
- array[1] = SkIntToScalar(b);
- array[2] = SkIntToScalar(c);
- return array;
-}
-
-DEF_TEST(Interpolator, reporter) {
- SkInterpolator inter(3, 2);
- SkScalar v1[3], v2[3], v[3];
- SkInterpolator::Result result;
-
- inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), nullptr);
- inter.setKeyFrame(1, 200, iset(v2, 110, 220, 330));
-
- result = inter.timeToValues(0, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeStart_Result);
- REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0);
-
- result = inter.timeToValues(99, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeStart_Result);
- REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0);
-
- result = inter.timeToValues(100, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
- REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0);
-
- result = inter.timeToValues(200, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
- REPORTER_ASSERT(reporter, memcmp(v, v2, sizeof(v)) == 0);
-
- result = inter.timeToValues(201, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeEnd_Result);
- REPORTER_ASSERT(reporter, memcmp(v, v2, sizeof(v)) == 0);
-
- result = inter.timeToValues(150, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
-
-// Found failing when we re-enabled this test:
-#if 0
- SkScalar vv[3];
- REPORTER_ASSERT(reporter, memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0);
-#endif
-
- result = inter.timeToValues(125, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
- result = inter.timeToValues(175, v);
- REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
-
- for (SkScalar val = -0.1f; val <= 1.1f; val += 0.1f) {
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkTPin(0.f, val, 1.f),
- SkUnitCubicInterp(val, 1.f/3, 1.f/3, 2.f/3, 2.f/3)));
- }
-
- // These numbers come from
- // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
- const SkScalar testTransitions[][4] = {
- { 0.25f, 0.1f, 0.25f, 1 }, // ease
- { 0.42f, 0, 1, 1 }, // ease in
- { 0, 0, 0.58f, 1 }, // ease out
- { 0.42f, 0, 0.58f, 1 }, // ease in out
- };
-
- const SkScalar expectedOutput[][5] = {
- { 0.0947876f, 0.513367f, 0.80249f, 0.940796f, 0.994263f }, // ease
- { 0.0170288f, 0.129639f, 0.31543f, 0.554749f, 0.839417f }, // ease in
- { 0.160583f, 0.445251f, 0.684692f, 0.870361f, 0.982971f }, // ease out
- { 0.0197144f, 0.187439f, 0.500122f, 0.812561f, 0.980286f }, // ease in out
- };
-
- int i = 0;
- for (const SkScalar* t : testTransitions) {
- int j = 0;
- for (SkScalar val = 0.1f; val < 1; val += 0.2f) {
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(expectedOutput[i][j++],
- SkUnitCubicInterp(val, t[0], t[1], t[2], t[3])));
- }
- ++i;
- }
-}