1 /* 2 * Copyright 2011 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 #ifndef SkClampRange_DEFINED 9 #define SkClampRange_DEFINED 10 11 #include "SkFixed.h" 12 #include "SkScalar.h" 13 14 #define SkGradFixed SkFixed3232 15 #define SkScalarToGradFixed SkScalarToFixed3232 16 #define SkFixedToGradFixed SkFixedToFixed3232 17 #define SkGradFixedToFixed(x) (SkFixed)((x) >> 16) 18 #define kFracMax_SkGradFixed 0xFFFFFFFFLL 19 20 /** 21 * Iteration fixed fx by dx, clamping as you go to [0..kFracMax_SkGradFixed], this class 22 * computes the (up to) 3 spans there are: 23 * 24 * range0: use constant value V0 25 * range1: iterate as usual fx += dx 26 * range2: use constant value V1 27 */ 28 struct SkClampRange { 29 int fCount0; // count for fV0 30 int fCount1; // count for interpolating (fV0...fV1) 31 int fCount2; // count for fV1 32 SkGradFixed fFx1; // initial fx value for the fCount1 range. 33 // only valid if fCount1 > 0 34 int fV0, fV1; 35 36 void init(SkGradFixed fx, SkGradFixed dx, int count, int v0, int v1); 37 validateSkClampRange38 void validate(int count) const { 39 #ifdef SK_DEBUG 40 SkASSERT(fCount0 >= 0); 41 SkASSERT(fCount1 >= 0); 42 SkASSERT(fCount2 >= 0); 43 SkASSERT(fCount0 + fCount1 + fCount2 == count); 44 #endif 45 } 46 47 private: 48 void initFor1(SkGradFixed fx); 49 }; 50 51 #endif 52