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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  * Copyright 2013 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  */
     8 #ifndef SkMatrixUtils_DEFINED
     9 #define SkMatrixUtils_DEFINED
    11 #include "SkMatrix.h"
    13 /**
    14  *  Number of subpixel bits used in skia's bilerp.
    15  *  See SkBitmapProcState_procs.h and SkBitmapProcState_filter.h
    16  */
    17 #define kSkSubPixelBitsForBilerp   4
    19 /**
    20  *  Given a matrix and width/height, return true if the computed dst-rect would
    21  *  align such that there is a 1-to-1 coorspondence between src and dst pixels.
    22  *  This can be called by drawing code to see if drawBitmap can be turned into
    23  *  drawSprite (which is faster).
    24  *
    25  *  The src-rect is defined to be { 0, 0, width, height }
    26  *
    27  *  The "closeness" test is based on the subpixelBits parameter. Pass 0 for
    28  *  round-to-nearest behavior (e.g. nearest neighbor sampling). Pass the number
    29  *  of subpixel-bits to simulate filtering.
    30  */
    31 bool SkTreatAsSprite(const SkMatrix&, int width, int height,
    32                      unsigned subpixelBits);
    34 /**
    35  *  Calls SkTreatAsSprite() with default subpixelBits value to match Skia's
    36  *  filter-bitmap implementation (i.e. kSkSubPixelBitsForBilerp).
    37  */
    38 static inline bool SkTreatAsSpriteFilter(const SkMatrix& matrix,
    39                                          int width, int height) {
    40     return SkTreatAsSprite(matrix, width, height, kSkSubPixelBitsForBilerp);
    41 }
    43 /** Decomposes the upper-left 2x2 of the matrix into a rotation (represented by
    44     the cosine and sine of the rotation angle), followed by a non-uniform scale,
    45     followed by another rotation. If there is a reflection, one of the scale
    46     factors will be negative.
    47     Returns true if successful. Returns false if the matrix is degenerate.
    48     */
    49 bool SkDecomposeUpper2x2(const SkMatrix& matrix,
    50                          SkPoint* rotation1,
    51                          SkPoint* scale,
    52                          SkPoint* rotation2);
    54 #endif

mercurial