SkMatrix Class Reference

#include <SkMatrix.h>

Inherited by SkTRefCnt< SkMatrix >.

List of all members.

Public Types

enum  TypeMask {
  kIdentity_Mask = 0, kTranslate_Mask = 0x01, kScale_Mask = 0x02, kAffine_Mask = 0x04,
  kPerspective_Mask = 0x08
}
enum  {
  kMScaleX, kMSkewX, kMTransX, kMSkewY,
  kMScaleY, kMTransY, kMPersp0, kMPersp1,
  kMPersp2
}
enum  ScaleToFit { kFill_ScaleToFit, kStart_ScaleToFit, kCenter_ScaleToFit, kEnd_ScaleToFit }
enum  { kMaxFlattenSize = 9 * sizeof(SkScalar) + sizeof(uint32_t) }
typedef void(* MapXYProc )(const SkMatrix &mat, SkScalar x, SkScalar y, SkPoint *result)
typedef void(* MapPtsProc )(const SkMatrix &mat, SkPoint dst[], const SkPoint src[], int count)

Public Member Functions

TypeMask getType () const
bool isIdentity () const
bool rectStaysRect () const
SkScalar operator[] (int index) const
SkScalar get (int index) const
SkScalar getScaleX () const
SkScalar getScaleY () const
SkScalar getSkewY () const
SkScalar getSkewX () const
SkScalar getTranslateX () const
SkScalar getTranslateY () const
SkScalar getPerspX () const
SkScalar getPerspY () const
void set (int index, SkScalar value)
void setScaleX (SkScalar v)
void setScaleY (SkScalar v)
void setSkewY (SkScalar v)
void setSkewX (SkScalar v)
void setTranslateX (SkScalar v)
void setTranslateY (SkScalar v)
void setPerspX (SkScalar v)
void setPerspY (SkScalar v)
void reset ()
void setTranslate (SkScalar dx, SkScalar dy)
void setScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
void setScale (SkScalar sx, SkScalar sy)
void setRotate (SkScalar degrees, SkScalar px, SkScalar py)
void setRotate (SkScalar degrees)
void setSinCos (SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
void setSinCos (SkScalar sinValue, SkScalar cosValue)
void setSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
void setSkew (SkScalar kx, SkScalar ky)
bool setConcat (const SkMatrix &a, const SkMatrix &b)
bool preTranslate (SkScalar dx, SkScalar dy)
bool preScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
bool preScale (SkScalar sx, SkScalar sy)
bool preRotate (SkScalar degrees, SkScalar px, SkScalar py)
bool preRotate (SkScalar degrees)
bool preSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
bool preSkew (SkScalar kx, SkScalar ky)
bool preConcat (const SkMatrix &other)
bool postTranslate (SkScalar dx, SkScalar dy)
bool postScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
bool postScale (SkScalar sx, SkScalar sy)
bool postIDiv (int divx, int divy)
bool postRotate (SkScalar degrees, SkScalar px, SkScalar py)
bool postRotate (SkScalar degrees)
bool postSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
bool postSkew (SkScalar kx, SkScalar ky)
bool postConcat (const SkMatrix &other)
bool setRectToRect (const SkRect &src, const SkRect &dst, ScaleToFit stf)
bool setPolyToPoly (const SkPoint src[], const SkPoint dst[], int count)
bool invert (SkMatrix *inverse) const
void mapPoints (SkPoint dst[], const SkPoint src[], int count) const
void mapPoints (SkPoint pts[], int count) const
void mapXY (SkScalar x, SkScalar y, SkPoint *result) const
void mapVectors (SkVector dst[], const SkVector src[], int count) const
void mapVectors (SkVector vecs[], int count) const
bool mapRect (SkRect *dst, const SkRect &src) const
bool mapRect (SkRect *rect) const
SkScalar mapRadius (SkScalar radius) const
MapXYProc getMapXYProc () const
MapPtsProc getMapPtsProc () const
bool fixedStepInX (SkScalar y, SkFixed *stepX, SkFixed *stepY) const
uint32_t flatten (void *buffer) const
uint32_t unflatten (const void *buffer)
void dump () const
void toDumpString (SkString *) const

Static Public Member Functions

static MapXYProc GetMapXYProc (TypeMask mask)
static MapPtsProc GetMapPtsProc (TypeMask mask)

Friends

class SkPerspIter
bool operator== (const SkMatrix &a, const SkMatrix &b)
bool operator!= (const SkMatrix &a, const SkMatrix &b)

Detailed Description

The SkMatrix class holds a 3x3 matrix for transforming coordinates. SkMatrix does not have a constructor, so it must be explicitly initialized using either reset() - to construct an identity matrix, or one of the set functions (e.g. setTranslate, setRotate, etc.).

Definition at line 31 of file SkMatrix.h.


Member Typedef Documentation

typedef void(* SkMatrix::MapPtsProc)(const SkMatrix &mat, SkPoint dst[], const SkPoint src[], int count)

Definition at line 377 of file SkMatrix.h.

typedef void(* SkMatrix::MapXYProc)(const SkMatrix &mat, SkScalar x, SkScalar y, SkPoint *result)

Definition at line 365 of file SkMatrix.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
kMScaleX 
kMSkewX 
kMTransX 
kMSkewY 
kMScaleY 
kMTransY 
kMPersp0 
kMPersp1 
kMPersp2 

Definition at line 74 of file SkMatrix.h.

anonymous enum
Enumerator:
kMaxFlattenSize 

Definition at line 403 of file SkMatrix.h.

Enumerator:
kFill_ScaleToFit 

Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.

kStart_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. kStart aligns the result to the left and top edges of dst.

kCenter_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

kEnd_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. kEnd aligns the result to the right and bottom edges of dst.

Definition at line 236 of file SkMatrix.h.

Enum of bit fields for the mask return by getType(). Use this to identify the complexity of the matrix.

Enumerator:
kIdentity_Mask 
kTranslate_Mask 

set if the matrix has translation

kScale_Mask 

set if the matrix has X or Y scale

kAffine_Mask 

set if the matrix skews or rotates

kPerspective_Mask 

set if the matrix is in perspective

Definition at line 36 of file SkMatrix.h.


Member Function Documentation

void SkMatrix::dump (  )  const
bool SkMatrix::fixedStepInX ( SkScalar  y,
SkFixed stepX,
SkFixed stepY 
) const

If the matrix can be stepped in X (not complex perspective) then return true and if step[XY] is not null, return the step[XY] value. If it cannot, return false and ignore step.

uint32_t SkMatrix::flatten ( void *  buffer  )  const
SkScalar SkMatrix::get ( int  index  )  const [inline]

Definition at line 91 of file SkMatrix.h.

MapPtsProc SkMatrix::getMapPtsProc (  )  const [inline]

Definition at line 385 of file SkMatrix.h.

static MapPtsProc SkMatrix::GetMapPtsProc ( TypeMask  mask  )  [inline, static]

Definition at line 380 of file SkMatrix.h.

MapXYProc SkMatrix::getMapXYProc (  )  const [inline]

Definition at line 373 of file SkMatrix.h.

static MapXYProc SkMatrix::GetMapXYProc ( TypeMask  mask  )  [inline, static]

Definition at line 368 of file SkMatrix.h.

SkScalar SkMatrix::getPerspX (  )  const [inline]

Definition at line 102 of file SkMatrix.h.

SkScalar SkMatrix::getPerspY (  )  const [inline]

Definition at line 103 of file SkMatrix.h.

SkScalar SkMatrix::getScaleX (  )  const [inline]

Definition at line 96 of file SkMatrix.h.

SkScalar SkMatrix::getScaleY (  )  const [inline]

Definition at line 97 of file SkMatrix.h.

SkScalar SkMatrix::getSkewX (  )  const [inline]

Definition at line 99 of file SkMatrix.h.

SkScalar SkMatrix::getSkewY (  )  const [inline]

Definition at line 98 of file SkMatrix.h.

SkScalar SkMatrix::getTranslateX (  )  const [inline]

Definition at line 100 of file SkMatrix.h.

SkScalar SkMatrix::getTranslateY (  )  const [inline]

Definition at line 101 of file SkMatrix.h.

TypeMask SkMatrix::getType (  )  const [inline]

Returns a mask bitfield describing the types of transformations that the matrix will perform. This information is used by routines like mapPoints, to optimize its inner loops to only perform as much arithmetic as is necessary.

Definition at line 49 of file SkMatrix.h.

bool SkMatrix::invert ( SkMatrix inverse  )  const

If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false

bool SkMatrix::isIdentity (  )  const [inline]

Returns true if the matrix is identity.

Definition at line 59 of file SkMatrix.h.

void SkMatrix::mapPoints ( SkPoint  pts[],
int  count 
) const [inline]

Apply this matrix to the array of points, overwriting it with the transformed values. dst[] = M * pts[]

Parameters:
pts The points to be transformed. It must contain at least count entries
count The number of points in pts.

Definition at line 308 of file SkMatrix.h.

void SkMatrix::mapPoints ( SkPoint  dst[],
const SkPoint  src[],
int  count 
) const

Apply this matrix to the array of points specified by src, and write the transformed points into the array of points specified by dst. dst[] = M * src[]

Parameters:
dst Where the transformed coordinates are written. It must contain at least count entries
src The original coordinates that are to be transformed. It must contain at least count entries
count The number of points in src to read, and then transform into dst.
SkScalar SkMatrix::mapRadius ( SkScalar  radius  )  const

Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origin.

bool SkMatrix::mapRect ( SkRect rect  )  const [inline]

Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points

Parameters:
rect The rectangle to transform.
Returns:
the result of calling rectStaysRect()

Definition at line 355 of file SkMatrix.h.

bool SkMatrix::mapRect ( SkRect dst,
const SkRect src 
) const

Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.

Parameters:
dst Where the transformed rectangle is written.
src The original rectangle to be transformed.
Returns:
the result of calling rectStaysRect()
void SkMatrix::mapVectors ( SkVector  vecs[],
int  count 
) const [inline]

Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.

Parameters:
vecs The vectors to be transformed. It must contain at least count entries
count The number of vectors in vecs.

Definition at line 336 of file SkMatrix.h.

void SkMatrix::mapVectors ( SkVector  dst[],
const SkVector  src[],
int  count 
) const

Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.

Parameters:
dst Where the transformed coordinates are written. It must contain at least count entries
src The original coordinates that are to be transformed. It must contain at least count entries
count The number of vectors in src to read, and then transform into dst.
void SkMatrix::mapXY ( SkScalar  x,
SkScalar  y,
SkPoint result 
) const [inline]

Definition at line 312 of file SkMatrix.h.

SkScalar SkMatrix::operator[] ( int  index  )  const [inline]

Definition at line 86 of file SkMatrix.h.

bool SkMatrix::postConcat ( const SkMatrix other  ) 

Postconcats the matrix with the specified matrix. M' = other * M

bool SkMatrix::postIDiv ( int  divx,
int  divy 
)

Postconcats the matrix by dividing it by the specified integers. M' = S(1/divx, 1/divy, 0, 0) * M

bool SkMatrix::postRotate ( SkScalar  degrees  ) 

Postconcats the matrix with the specified rotation. M' = R(degrees) * M

bool SkMatrix::postRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M

bool SkMatrix::postScale ( SkScalar  sx,
SkScalar  sy 
)

Postconcats the matrix with the specified scale. M' = S(sx, sy) * M

bool SkMatrix::postScale ( SkScalar  sx,
SkScalar  sy,
SkScalar  px,
SkScalar  py 
)

Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M

bool SkMatrix::postSkew ( SkScalar  kx,
SkScalar  ky 
)

Postconcats the matrix with the specified skew. M' = K(kx, ky) * M

bool SkMatrix::postSkew ( SkScalar  kx,
SkScalar  ky,
SkScalar  px,
SkScalar  py 
)

Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M

bool SkMatrix::postTranslate ( SkScalar  dx,
SkScalar  dy 
)

Postconcats the matrix with the specified translation. M' = T(dx, dy) * M

bool SkMatrix::preConcat ( const SkMatrix other  ) 

Preconcats the matrix with the specified matrix. M' = M * other

bool SkMatrix::preRotate ( SkScalar  degrees  ) 

Preconcats the matrix with the specified rotation. M' = M * R(degrees)

bool SkMatrix::preRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py)

bool SkMatrix::preScale ( SkScalar  sx,
SkScalar  sy 
)

Preconcats the matrix with the specified scale. M' = M * S(sx, sy)

bool SkMatrix::preScale ( SkScalar  sx,
SkScalar  sy,
SkScalar  px,
SkScalar  py 
)

Preconcats the matrix with the specified scale. M' = M * S(sx, sy, px, py)

bool SkMatrix::preSkew ( SkScalar  kx,
SkScalar  ky 
)

Preconcats the matrix with the specified skew. M' = M * K(kx, ky)

bool SkMatrix::preSkew ( SkScalar  kx,
SkScalar  ky,
SkScalar  px,
SkScalar  py 
)

Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py)

bool SkMatrix::preTranslate ( SkScalar  dx,
SkScalar  dy 
)

Preconcats the matrix with the specified translation. M' = M * T(dx, dy)

bool SkMatrix::rectStaysRect (  )  const [inline]

Returns true if will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.

Definition at line 67 of file SkMatrix.h.

void SkMatrix::reset (  ) 

Set the matrix to identity

void SkMatrix::set ( int  index,
SkScalar  value 
) [inline]

Definition at line 105 of file SkMatrix.h.

bool SkMatrix::setConcat ( const SkMatrix a,
const SkMatrix b 
)

Set the matrix to the concatenation of the two specified matrices, returning true if the the result can be represented. Either of the two matrices may also be the target matrix. *this = a * b;

void SkMatrix::setPerspX ( SkScalar  v  )  [inline]

Definition at line 117 of file SkMatrix.h.

void SkMatrix::setPerspY ( SkScalar  v  )  [inline]

Definition at line 118 of file SkMatrix.h.

bool SkMatrix::setPolyToPoly ( const SkPoint  src[],
const SkPoint  dst[],
int  count 
)

Set the matrix such that the specified src points would map to the specified dst points. count must be within [0..4].

Parameters:
src The array of src points
dst The array of dst points
count The number of points to use for the transformation
Returns:
true if the matrix was set to the specified transformation
bool SkMatrix::setRectToRect ( const SkRect src,
const SkRect dst,
ScaleToFit  stf 
)

Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the the result can be represented.

Parameters:
src the source rectangle to map from.
dst the destination rectangle to map to.
stf the ScaleToFit option
Returns:
true if the matrix can be represented by the rectangle mapping.
void SkMatrix::setRotate ( SkScalar  degrees  ) 

Set the matrix to rotate about (0,0) by the specified number of degrees.

void SkMatrix::setRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

void SkMatrix::setScale ( SkScalar  sx,
SkScalar  sy 
)

Set the matrix to scale by sx and sy.

void SkMatrix::setScale ( SkScalar  sx,
SkScalar  sy,
SkScalar  px,
SkScalar  py 
)

Set the matrix to scale by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

void SkMatrix::setScaleX ( SkScalar  v  )  [inline]

Definition at line 111 of file SkMatrix.h.

void SkMatrix::setScaleY ( SkScalar  v  )  [inline]

Definition at line 112 of file SkMatrix.h.

void SkMatrix::setSinCos ( SkScalar  sinValue,
SkScalar  cosValue 
)

Set the matrix to rotate by the specified sine and cosine values.

void SkMatrix::setSinCos ( SkScalar  sinValue,
SkScalar  cosValue,
SkScalar  px,
SkScalar  py 
)

Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

void SkMatrix::setSkew ( SkScalar  kx,
SkScalar  ky 
)

Set the matrix to skew by sx and sy.

void SkMatrix::setSkew ( SkScalar  kx,
SkScalar  ky,
SkScalar  px,
SkScalar  py 
)

Set the matrix to skew by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

void SkMatrix::setSkewX ( SkScalar  v  )  [inline]

Definition at line 114 of file SkMatrix.h.

void SkMatrix::setSkewY ( SkScalar  v  )  [inline]

Definition at line 113 of file SkMatrix.h.

void SkMatrix::setTranslate ( SkScalar  dx,
SkScalar  dy 
)

Set the matrix to translate by (dx, dy).

void SkMatrix::setTranslateX ( SkScalar  v  )  [inline]

Definition at line 115 of file SkMatrix.h.

void SkMatrix::setTranslateY ( SkScalar  v  )  [inline]

Definition at line 116 of file SkMatrix.h.

void SkMatrix::toDumpString ( SkString  )  const
uint32_t SkMatrix::unflatten ( const void *  buffer  ) 

Friends And Related Function Documentation

bool operator!= ( const SkMatrix a,
const SkMatrix b 
) [friend]

Definition at line 399 of file SkMatrix.h.

bool operator== ( const SkMatrix a,
const SkMatrix b 
) [friend]

Definition at line 395 of file SkMatrix.h.

friend class SkPerspIter [friend]

Definition at line 477 of file SkMatrix.h.


The documentation for this class was generated from the following file:

Generated on Tue Oct 20 11:03:42 2009 for Skia by  doxygen 1.6.1