gfx/skia/trunk/include/utils/SkInterpolator.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkInterpolator_DEFINED
michael@0 11 #define SkInterpolator_DEFINED
michael@0 12
michael@0 13 #include "SkScalar.h"
michael@0 14
michael@0 15 class SkInterpolatorBase : SkNoncopyable {
michael@0 16 public:
michael@0 17 enum Result {
michael@0 18 kNormal_Result,
michael@0 19 kFreezeStart_Result,
michael@0 20 kFreezeEnd_Result
michael@0 21 };
michael@0 22 protected:
michael@0 23 SkInterpolatorBase();
michael@0 24 ~SkInterpolatorBase();
michael@0 25 public:
michael@0 26 void reset(int elemCount, int frameCount);
michael@0 27
michael@0 28 /** Return the start and end time for this interpolator.
michael@0 29 If there are no key frames, return false.
michael@0 30 @param startTime If not null, returns the time (in milliseconds) of the
michael@0 31 first keyframe. If there are no keyframes, this param
michael@0 32 is ignored (left unchanged).
michael@0 33 @param endTime If not null, returns the time (in milliseconds) of the
michael@0 34 last keyframe. If there are no keyframes, this parameter
michael@0 35 is ignored (left unchanged).
michael@0 36 @return True if there are key frames, or false if there are none.
michael@0 37 */
michael@0 38 bool getDuration(SkMSec* startTime, SkMSec* endTime) const;
michael@0 39
michael@0 40
michael@0 41 /** Set the whether the repeat is mirrored.
michael@0 42 @param mirror If true, the odd repeats interpolate from the last key
michael@0 43 frame and the first.
michael@0 44 */
michael@0 45 void setMirror(bool mirror) {
michael@0 46 fFlags = SkToU8((fFlags & ~kMirror) | (int)mirror);
michael@0 47 }
michael@0 48
michael@0 49 /** Set the repeat count. The repeat count may be fractional.
michael@0 50 @param repeatCount Multiplies the total time by this scalar.
michael@0 51 */
michael@0 52 void setRepeatCount(SkScalar repeatCount) { fRepeat = repeatCount; }
michael@0 53
michael@0 54 /** Set the whether the repeat is mirrored.
michael@0 55 @param reset If true, the odd repeats interpolate from the last key
michael@0 56 frame and the first.
michael@0 57 */
michael@0 58 void setReset(bool reset) {
michael@0 59 fFlags = SkToU8((fFlags & ~kReset) | (int)reset);
michael@0 60 }
michael@0 61
michael@0 62 Result timeToT(SkMSec time, SkScalar* T, int* index, SkBool* exact) const;
michael@0 63
michael@0 64 protected:
michael@0 65 enum Flags {
michael@0 66 kMirror = 1,
michael@0 67 kReset = 2,
michael@0 68 kHasBlend = 4
michael@0 69 };
michael@0 70 static SkScalar ComputeRelativeT(SkMSec time, SkMSec prevTime,
michael@0 71 SkMSec nextTime, const SkScalar blend[4] = NULL);
michael@0 72 int16_t fFrameCount;
michael@0 73 uint8_t fElemCount;
michael@0 74 uint8_t fFlags;
michael@0 75 SkScalar fRepeat;
michael@0 76 struct SkTimeCode {
michael@0 77 SkMSec fTime;
michael@0 78 SkScalar fBlend[4];
michael@0 79 };
michael@0 80 SkTimeCode* fTimes; // pointer into fStorage
michael@0 81 void* fStorage;
michael@0 82 #ifdef SK_DEBUG
michael@0 83 SkTimeCode(* fTimesArray)[10];
michael@0 84 #endif
michael@0 85 };
michael@0 86
michael@0 87 class SkInterpolator : public SkInterpolatorBase {
michael@0 88 public:
michael@0 89 SkInterpolator();
michael@0 90 SkInterpolator(int elemCount, int frameCount);
michael@0 91 void reset(int elemCount, int frameCount);
michael@0 92
michael@0 93 /** Add or replace a key frame, copying the values[] data into the
michael@0 94 interpolator.
michael@0 95 @param index The index of this frame (frames must be ordered by time)
michael@0 96 @param time The millisecond time for this frame
michael@0 97 @param values The array of values [elemCount] for this frame. The data
michael@0 98 is copied into the interpolator.
michael@0 99 @param blend A positive scalar specifying how to blend between this
michael@0 100 and the next key frame. [0...1) is a cubic lag/log/lag
michael@0 101 blend (slow to change at the beginning and end)
michael@0 102 1 is a linear blend (default)
michael@0 103 */
michael@0 104 bool setKeyFrame(int index, SkMSec time, const SkScalar values[],
michael@0 105 const SkScalar blend[4] = NULL);
michael@0 106
michael@0 107 /** Return the computed values given the specified time. Return whether
michael@0 108 those values are the result of pinning to either the first
michael@0 109 (kFreezeStart) or last (kFreezeEnd), or from interpolated the two
michael@0 110 nearest key values (kNormal).
michael@0 111 @param time The time to sample (in milliseconds)
michael@0 112 @param (may be null) where to write the computed values.
michael@0 113 */
michael@0 114 Result timeToValues(SkMSec time, SkScalar values[] = NULL) const;
michael@0 115
michael@0 116 SkDEBUGCODE(static void UnitTest();)
michael@0 117 private:
michael@0 118 SkScalar* fValues; // pointer into fStorage
michael@0 119 #ifdef SK_DEBUG
michael@0 120 SkScalar(* fScalarsArray)[10];
michael@0 121 #endif
michael@0 122 typedef SkInterpolatorBase INHERITED;
michael@0 123 };
michael@0 124
michael@0 125 /** Given all the parameters are [0...1], apply the cubic specified by (0,0)
michael@0 126 (bx,by) (cx,cy) (1,1) to value, returning the answer, also [0...1].
michael@0 127 */
michael@0 128 SkScalar SkUnitCubicInterp(SkScalar value, SkScalar bx, SkScalar by,
michael@0 129 SkScalar cx, SkScalar cy);
michael@0 130
michael@0 131 #endif

mercurial