1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SkDrawProcs_DEFINED
9cb93a386Sopenharmony_ci#define SkDrawProcs_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "src/core/SkDraw.h"
12cb93a386Sopenharmony_ci#include "src/core/SkGlyph.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cibool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&,
15cb93a386Sopenharmony_ci                                   SkScalar* coverage);
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ci/**
18cb93a386Sopenharmony_ci *  If the current paint is set to stroke and the stroke-width when applied to
19cb93a386Sopenharmony_ci *  the matrix is <= 1.0, then this returns true, and sets coverage (simulating
20cb93a386Sopenharmony_ci *  a stroke by drawing a hairline with partial coverage). If any of these
21cb93a386Sopenharmony_ci *  conditions are false, then this returns false and coverage is ignored.
22cb93a386Sopenharmony_ci */
23cb93a386Sopenharmony_ciinline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix,
24cb93a386Sopenharmony_ci                                  SkScalar* coverage) {
25cb93a386Sopenharmony_ci    if (SkPaint::kStroke_Style != paint.getStyle()) {
26cb93a386Sopenharmony_ci        return false;
27cb93a386Sopenharmony_ci    }
28cb93a386Sopenharmony_ci
29cb93a386Sopenharmony_ci    SkScalar strokeWidth = paint.getStrokeWidth();
30cb93a386Sopenharmony_ci    if (0 == strokeWidth) {
31cb93a386Sopenharmony_ci        *coverage = SK_Scalar1;
32cb93a386Sopenharmony_ci        return true;
33cb93a386Sopenharmony_ci    }
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ci    if (!paint.isAntiAlias()) {
36cb93a386Sopenharmony_ci        return false;
37cb93a386Sopenharmony_ci    }
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
40cb93a386Sopenharmony_ci}
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_ci#endif
43