epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkDrawProcs_DEFINED |
| 9 | #define SkDrawProcs_DEFINED |
| 10 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 11 | #include "SkBlitter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkDraw.h" |
| 13 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 14 | class SkAAClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | class SkBlitter; |
| 16 | |
| 17 | struct SkDraw1Glyph { |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 18 | const SkDraw* fDraw; |
| 19 | SkBounder* fBounder; |
| 20 | const SkRegion* fClip; |
| 21 | const SkAAClip* fAAClip; |
| 22 | SkBlitter* fBlitter; |
| 23 | SkGlyphCache* fCache; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 24 | const SkPaint* fPaint; |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 25 | SkIRect fClipBounds; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 26 | /** 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.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 30 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 31 | /** 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.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 38 | typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 39 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 40 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct SkDrawProcs { |
| 59 | SkDraw1Glyph::Proc fD1GProc; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 60 | #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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame^] | 78 | bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&, |
| 79 | SkScalar* coverage); |
| 80 | |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 81 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 82 | * If the current paint is set to stroke and the stroke-width when applied to |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 83 | * the matrix is <= 1.0, then this returns true, and sets coverage (simulating |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 84 | * a stroke by drawing a hairline with partial coverage). If any of these |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 85 | * conditions are false, then this returns false and coverage is ignored. |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 86 | */ |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame^] | 87 | inline 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.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 105 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | #endif |