xref: /aosp_15_r20/external/skia/src/core/SkDrawProcs.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2011 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 #ifndef SkDrawProcs_DEFINED
9 #define SkDrawProcs_DEFINED
10 
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkScalar.h"
13 class SkMatrix;
14 
15 bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&,
16                                    SkScalar* coverage);
17 
18 /**
19  *  If the current paint is set to stroke and the stroke-width when applied to
20  *  the matrix is <= 1.0, then this returns true, and sets coverage (simulating
21  *  a stroke by drawing a hairline with partial coverage). If any of these
22  *  conditions are false, then this returns false and coverage is ignored.
23  */
SkDrawTreatAsHairline(const SkPaint & paint,const SkMatrix & matrix,SkScalar * coverage)24 inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix,
25                                   SkScalar* coverage) {
26     if (SkPaint::kStroke_Style != paint.getStyle()) {
27         return false;
28     }
29 
30     SkScalar strokeWidth = paint.getStrokeWidth();
31     if (0 == strokeWidth) {
32         *coverage = SK_Scalar1;
33         return true;
34     }
35 
36     if (!paint.isAntiAlias()) {
37         return false;
38     }
39 
40     return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
41 }
42 
43 #endif
44