blob: 6911e5b017609c535524e45d872cd06c1b681389 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkDrawProcs_DEFINED
9#define SkDrawProcs_DEFINED
10
reed@google.com5bdfb332013-05-02 18:55:44 +000011#include "SkBlitter.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkDraw.h"
13
reed@google.com045e62d2011-10-24 12:19:46 +000014class SkAAClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +000015class SkBlitter;
16
17struct SkDraw1Glyph {
bungeman@google.com2211b622012-01-13 15:02:58 +000018 const SkDraw* fDraw;
19 SkBounder* fBounder;
20 const SkRegion* fClip;
21 const SkAAClip* fAAClip;
22 SkBlitter* fBlitter;
23 SkGlyphCache* fCache;
reed@google.com5bdfb332013-05-02 18:55:44 +000024 const SkPaint* fPaint;
bungeman@google.com2211b622012-01-13 15:02:58 +000025 SkIRect fClipBounds;
bungeman@google.com94471032013-02-25 15:55:13 +000026 /** Half the sampling frequency of the rasterized glyph in x. */
27 SkFixed fHalfSampleX;
28 /** Half the sampling frequency of the rasterized glyph in y. */
29 SkFixed fHalfSampleY;
bungeman@google.com2211b622012-01-13 15:02:58 +000030
bungeman@google.com94471032013-02-25 15:55:13 +000031 /** Draws one glyph.
32 *
33 * The x and y are pre-biased, so implementations may just truncate them.
34 * i.e. half the sampling frequency has been added.
35 * e.g. 1/2 or 1/(2^(SkGlyph::kSubBits+1)) has already been added.
36 * This added bias can be found in fHalfSampleX,Y.
37 */
bungeman@google.com2211b622012-01-13 15:02:58 +000038 typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000039
reed@google.com5bdfb332013-05-02 18:55:44 +000040 Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache,
41 const SkPaint&);
42
43 // call this instead of fBlitter->blitMask() since this wrapper will handle
44 // the case when the mask is ARGB32_Format
45 //
46 void blitMask(const SkMask& mask, const SkIRect& clip) const {
47 if (SkMask::kARGB32_Format == mask.fFormat) {
48 this->blitMaskAsSprite(mask);
49 } else {
50 fBlitter->blitMask(mask, clip);
51 }
52 }
53
54 // mask must be kARGB32_Format
55 void blitMaskAsSprite(const SkMask& mask) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000056};
57
58struct SkDrawProcs {
59 SkDraw1Glyph::Proc fD1GProc;
jvanverth@google.comd830d132013-11-11 20:54:09 +000060#if SK_DISTANCEFIELD_FONTS
61 uint32_t fFlags;
62
63 enum Flags {
64 /**
65 * Disable baked glyph transforms
66 */
67 kSkipBakedGlyphTransform_Flag = 0x1,
68 /**
69 * Scale glyphs to get different point sizes
70 */
71 kUseScaledGlyphs_Flag = 0x2,
72 };
73
74 static const int kBaseDFFontSize = 32;
75#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000076};
77
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +000078bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&,
79 SkScalar* coverage);
80
reed@google.comecadf992011-09-19 19:18:18 +000081/**
rmistry@google.comfbfcd562012-08-23 18:09:54 +000082 * If the current paint is set to stroke and the stroke-width when applied to
bsalomon@google.comdd1be602012-01-18 20:34:00 +000083 * the matrix is <= 1.0, then this returns true, and sets coverage (simulating
rmistry@google.comfbfcd562012-08-23 18:09:54 +000084 * a stroke by drawing a hairline with partial coverage). If any of these
bsalomon@google.comdd1be602012-01-18 20:34:00 +000085 * conditions are false, then this returns false and coverage is ignored.
reed@google.comecadf992011-09-19 19:18:18 +000086 */
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +000087inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix,
88 SkScalar* coverage) {
89 if (SkPaint::kStroke_Style != paint.getStyle()) {
90 return false;
91 }
92
93 SkScalar strokeWidth = paint.getStrokeWidth();
94 if (0 == strokeWidth) {
95 *coverage = SK_Scalar1;
96 return true;
97 }
98
99 if (!paint.isAntiAlias()) {
100 return false;
101 }
102
103 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
104}
reed@google.comecadf992011-09-19 19:18:18 +0000105
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106#endif