My favorites | Sign in
Project Home Wiki Issues Source
Search
for
SkScalar  
SkScalar - specifying fractional values
Updated Mar 4, 2011

Skia specifies all of its device-independent coordinates using the type SkScalar. This type is defined at compile time to be either a 32bit integer (treated as 16.16 - see SkFixed) or defined to be a IEEE 32bit float. With the provided macros/inlines in SkScalar.h, it is possible to write Skia code w/o knowing how SkScalar is actually defined.

   SkScalar x, y;

   // all of these work fine as floats or SkFixed
   x = SkIntToScalar(35);
   y = x * 5;
   x = y / 3;
   y += x;

   // these give drastically different results between floats and SkFixed
   x += 1;
   x = y * y;
   // This won't compile if scalar == float
   y >>= 2;

SkScalar.h defines macros/inlines to abstract away knowledge for most operations

   SkScalarMul(a, b)  // mulitplies two scalars, returning a scalar
   SkScalarDiv(a, b)  // divides two scalars, returning a scalar
   SkScalarCos(a)     // returns the cosine as a scalar [0 .. SK_Scalar1] given a scalar radians
   SkScalarRound(a)   // returns the nearest int to the specified scalar
Powered by Google Project Hosting