michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkMatrixUtils_DEFINED michael@0: #define SkMatrixUtils_DEFINED michael@0: michael@0: #include "SkMatrix.h" michael@0: michael@0: /** michael@0: * Number of subpixel bits used in skia's bilerp. michael@0: * See SkBitmapProcState_procs.h and SkBitmapProcState_filter.h michael@0: */ michael@0: #define kSkSubPixelBitsForBilerp 4 michael@0: michael@0: /** michael@0: * Given a matrix and width/height, return true if the computed dst-rect would michael@0: * align such that there is a 1-to-1 coorspondence between src and dst pixels. michael@0: * This can be called by drawing code to see if drawBitmap can be turned into michael@0: * drawSprite (which is faster). michael@0: * michael@0: * The src-rect is defined to be { 0, 0, width, height } michael@0: * michael@0: * The "closeness" test is based on the subpixelBits parameter. Pass 0 for michael@0: * round-to-nearest behavior (e.g. nearest neighbor sampling). Pass the number michael@0: * of subpixel-bits to simulate filtering. michael@0: */ michael@0: bool SkTreatAsSprite(const SkMatrix&, int width, int height, michael@0: unsigned subpixelBits); michael@0: michael@0: /** michael@0: * Calls SkTreatAsSprite() with default subpixelBits value to match Skia's michael@0: * filter-bitmap implementation (i.e. kSkSubPixelBitsForBilerp). michael@0: */ michael@0: static inline bool SkTreatAsSpriteFilter(const SkMatrix& matrix, michael@0: int width, int height) { michael@0: return SkTreatAsSprite(matrix, width, height, kSkSubPixelBitsForBilerp); michael@0: } michael@0: michael@0: /** Decomposes the upper-left 2x2 of the matrix into a rotation (represented by michael@0: the cosine and sine of the rotation angle), followed by a non-uniform scale, michael@0: followed by another rotation. If there is a reflection, one of the scale michael@0: factors will be negative. michael@0: Returns true if successful. Returns false if the matrix is degenerate. michael@0: */ michael@0: bool SkDecomposeUpper2x2(const SkMatrix& matrix, michael@0: SkPoint* rotation1, michael@0: SkPoint* scale, michael@0: SkPoint* rotation2); michael@0: michael@0: #endif