• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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  */
7 
8 #include "SkFontPriv.h"
9 #include "SkGraphics.h"
10 #include "SkMatrix.h"
11 
mag2(SkScalar x,SkScalar y)12 static SkScalar mag2(SkScalar x, SkScalar y) {
13     return x * x + y * y;
14 }
15 
tooBig(const SkMatrix & m,SkScalar ma2max)16 static bool tooBig(const SkMatrix& m, SkScalar ma2max) {
17     return  mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max
18             ||
19             mag2(m[SkMatrix::kMSkewX], m[SkMatrix::kMScaleY]) > ma2max;
20 }
21 
TooBigToUseCache(const SkMatrix & ctm,const SkMatrix & textM,SkScalar maxLimit)22 bool SkFontPriv::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit) {
23     SkASSERT(!ctm.hasPerspective());
24     SkASSERT(!textM.hasPerspective());
25 
26     SkMatrix matrix;
27     matrix.setConcat(ctm, textM);
28     return tooBig(matrix, MaxCacheSize2(maxLimit));
29 }
30 
MaxCacheSize2(SkScalar maxLimit)31 SkScalar SkFontPriv::MaxCacheSize2(SkScalar maxLimit) {
32     // we have a self-imposed maximum, just for memory-usage sanity
33     const int limit = SkMin32(SkGraphics::GetFontCachePointSizeLimit(), maxLimit);
34     const SkScalar maxSize = SkIntToScalar(limit);
35     return maxSize * maxSize;
36 }
37