| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkDrawProcs_DEFINED | 8 #ifndef SkDrawProcs_DEFINED |
| 9 #define SkDrawProcs_DEFINED | 9 #define SkDrawProcs_DEFINED |
| 10 | 10 |
| 11 #include "SkBlitter.h" | 11 #include "SkBlitter.h" |
| 12 #include "SkDraw.h" | 12 #include "SkDraw.h" |
| 13 #include "SkGlyph.h" | 13 #include "SkGlyph.h" |
| 14 | 14 |
| 15 class SkAAClip; | 15 class SkAAClip; |
| 16 class SkBlitter; | 16 class SkBlitter; |
| 17 | 17 |
| 18 struct SkDraw1Glyph { | 18 struct SkDraw1Glyph { |
| 19 const SkDraw* fDraw; | 19 const SkDraw* fDraw; |
| 20 const SkRegion* fClip; | 20 const SkRegion* fClip; |
| 21 const SkAAClip* fAAClip; | 21 const SkAAClip* fAAClip; |
| 22 SkBlitter* fBlitter; | 22 SkBlitter* fBlitter; |
| 23 SkGlyphCache* fCache; | 23 SkGlyphCache* fCache; |
| 24 const SkPaint* fPaint; | 24 const SkPaint* fPaint; |
| 25 SkIRect fClipBounds; | 25 SkIRect fClipBounds; |
| 26 /** Half the sampling frequency of the rasterized glyph in x. */ | 26 /** Half the sampling frequency of the rasterized glyph in x. */ |
| 27 SkFixed fHalfSampleX; | 27 SkScalar fHalfSampleX; |
| 28 /** Half the sampling frequency of the rasterized glyph in y. */ | 28 /** Half the sampling frequency of the rasterized glyph in y. */ |
| 29 SkFixed fHalfSampleY; | 29 SkScalar fHalfSampleY; |
| 30 | 30 |
| 31 /** Draws one glyph. | 31 /** Draws one glyph. |
| 32 * | 32 * |
| 33 * The x and y are pre-biased, so implementations may just truncate them. | 33 * The x and y are pre-biased, so implementations may just truncate them. |
| 34 * i.e. half the sampling frequency has been added. | 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. | 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. | 36 * This added bias can be found in fHalfSampleX,Y. |
| 37 */ | 37 */ |
| 38 typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyp
h&); | 38 typedef void (*Proc)(const SkDraw1Glyph&, Sk48Dot16 x, Sk48Dot16 y, const Sk
Glyph&); |
| 39 | 39 |
| 40 Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, | 40 Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, |
| 41 const SkPaint&); | 41 const SkPaint&); |
| 42 | 42 |
| 43 // call this instead of fBlitter->blitMask() since this wrapper will handle | 43 // call this instead of fBlitter->blitMask() since this wrapper will handle |
| 44 // the case when the mask is ARGB32_Format | 44 // the case when the mask is ARGB32_Format |
| 45 // | 45 // |
| 46 void blitMask(const SkMask& mask, const SkIRect& clip) const { | 46 void blitMask(const SkMask& mask, const SkIRect& clip) const { |
| 47 if (SkMask::kARGB32_Format == mask.fFormat) { | 47 if (SkMask::kARGB32_Format == mask.fFormat) { |
| 48 this->blitMaskAsSprite(mask); | 48 this->blitMaskAsSprite(mask); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); | 87 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage); |
| 88 } | 88 } |
| 89 | 89 |
| 90 class SkTextAlignProc { | 90 class SkTextAlignProc { |
| 91 public: | 91 public: |
| 92 SkTextAlignProc(SkPaint::Align align) | 92 SkTextAlignProc(SkPaint::Align align) |
| 93 : fAlign(align) { | 93 : fAlign(align) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Returns the position of the glyph in fixed point, which may be rounded or
not | |
| 97 // by the caller e.g. subpixel doesn't round. | |
| 98 // @param point interpreted as SkFixed [x, y]. | |
| 99 void operator()(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) { | |
| 100 if (SkPaint::kLeft_Align == fAlign) { | |
| 101 dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); | |
| 102 } else if (SkPaint::kCenter_Align == fAlign) { | |
| 103 dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), | |
| 104 SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); | |
| 105 } else { | |
| 106 SkASSERT(SkPaint::kRight_Align == fAlign); | |
| 107 dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, | |
| 108 SkScalarToFixed(loc.fY) - glyph.fAdvanceY); | |
| 109 } | |
| 110 } | |
| 111 private: | |
| 112 const SkPaint::Align fAlign; | |
| 113 }; | |
| 114 | |
| 115 class SkTextAlignProcScalar { | |
| 116 public: | |
| 117 SkTextAlignProcScalar(SkPaint::Align align) | |
| 118 : fAlign(align) { | |
| 119 } | |
| 120 | |
| 121 // Returns the glyph position, which may be rounded or not by the caller | 96 // Returns the glyph position, which may be rounded or not by the caller |
| 122 // e.g. subpixel doesn't round. | 97 // e.g. subpixel doesn't round. |
| 123 void operator()(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) { | 98 void operator()(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) { |
| 124 if (SkPaint::kLeft_Align == fAlign) { | 99 if (SkPaint::kLeft_Align == fAlign) { |
| 125 dst->set(loc.fX, loc.fY); | 100 dst->set(loc.fX, loc.fY); |
| 126 } else if (SkPaint::kCenter_Align == fAlign) { | 101 } else if (SkPaint::kCenter_Align == fAlign) { |
| 127 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX >> 1), | 102 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX >> 1), |
| 128 loc.fY - SkFixedToScalar(glyph.fAdvanceY >> 1)); | 103 loc.fY - SkFixedToScalar(glyph.fAdvanceY >> 1)); |
| 129 } else { | 104 } else { |
| 130 SkASSERT(SkPaint::kRight_Align == fAlign); | 105 SkASSERT(SkPaint::kRight_Align == fAlign); |
| 131 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX), | 106 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX), |
| 132 loc.fY - SkFixedToScalar(glyph.fAdvanceY)); | 107 loc.fY - SkFixedToScalar(glyph.fAdvanceY)); |
| 133 } | 108 } |
| 134 } | 109 } |
| 135 private: | 110 private: |
| 136 const SkPaint::Align fAlign; | 111 const SkPaint::Align fAlign; |
| 137 }; | 112 }; |
| 138 | 113 |
| 139 #endif | 114 #endif |
| OLD | NEW |