gfx/skia/trunk/src/core/SkMatrixUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkMatrixUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkMatrixUtils_DEFINED
    1.12 +#define SkMatrixUtils_DEFINED
    1.13 +
    1.14 +#include "SkMatrix.h"
    1.15 +
    1.16 +/**
    1.17 + *  Number of subpixel bits used in skia's bilerp.
    1.18 + *  See SkBitmapProcState_procs.h and SkBitmapProcState_filter.h
    1.19 + */
    1.20 +#define kSkSubPixelBitsForBilerp   4
    1.21 +
    1.22 +/**
    1.23 + *  Given a matrix and width/height, return true if the computed dst-rect would
    1.24 + *  align such that there is a 1-to-1 coorspondence between src and dst pixels.
    1.25 + *  This can be called by drawing code to see if drawBitmap can be turned into
    1.26 + *  drawSprite (which is faster).
    1.27 + *
    1.28 + *  The src-rect is defined to be { 0, 0, width, height }
    1.29 + *
    1.30 + *  The "closeness" test is based on the subpixelBits parameter. Pass 0 for
    1.31 + *  round-to-nearest behavior (e.g. nearest neighbor sampling). Pass the number
    1.32 + *  of subpixel-bits to simulate filtering.
    1.33 + */
    1.34 +bool SkTreatAsSprite(const SkMatrix&, int width, int height,
    1.35 +                     unsigned subpixelBits);
    1.36 +
    1.37 +/**
    1.38 + *  Calls SkTreatAsSprite() with default subpixelBits value to match Skia's
    1.39 + *  filter-bitmap implementation (i.e. kSkSubPixelBitsForBilerp).
    1.40 + */
    1.41 +static inline bool SkTreatAsSpriteFilter(const SkMatrix& matrix,
    1.42 +                                         int width, int height) {
    1.43 +    return SkTreatAsSprite(matrix, width, height, kSkSubPixelBitsForBilerp);
    1.44 +}
    1.45 +
    1.46 +/** Decomposes the upper-left 2x2 of the matrix into a rotation (represented by
    1.47 +    the cosine and sine of the rotation angle), followed by a non-uniform scale,
    1.48 +    followed by another rotation. If there is a reflection, one of the scale
    1.49 +    factors will be negative.
    1.50 +    Returns true if successful. Returns false if the matrix is degenerate.
    1.51 +    */
    1.52 +bool SkDecomposeUpper2x2(const SkMatrix& matrix,
    1.53 +                         SkPoint* rotation1,
    1.54 +                         SkPoint* scale,
    1.55 +                         SkPoint* rotation2);
    1.56 +
    1.57 +#endif

mercurial