blob: cefd2cce02ccac1aedf0d674203300ceb8b77445 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
reed868074b2014-06-03 10:53:59 -07007
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;
bungeman@google.com2211b622012-01-13 15:02:58 +000019 const SkRegion* fClip;
20 const SkAAClip* fAAClip;
21 SkBlitter* fBlitter;
22 SkGlyphCache* fCache;
reed@google.com5bdfb332013-05-02 18:55:44 +000023 const SkPaint* fPaint;
bungeman@google.com2211b622012-01-13 15:02:58 +000024 SkIRect fClipBounds;
bungeman@google.com94471032013-02-25 15:55:13 +000025 /** Half the sampling frequency of the rasterized glyph in x. */
26 SkFixed fHalfSampleX;
27 /** Half the sampling frequency of the rasterized glyph in y. */
28 SkFixed fHalfSampleY;
bungeman@google.com2211b622012-01-13 15:02:58 +000029
bungeman@google.com94471032013-02-25 15:55:13 +000030 /** Draws one glyph.
31 *
32 * The x and y are pre-biased, so implementations may just truncate them.
33 * i.e. half the sampling frequency has been added.
34 * e.g. 1/2 or 1/(2^(SkGlyph::kSubBits+1)) has already been added.
35 * This added bias can be found in fHalfSampleX,Y.
36 */
bungeman@google.com2211b622012-01-13 15:02:58 +000037 typedef void (*Proc)(const SkDraw1Glyph&, SkFixed x, SkFixed y, const SkGlyph&);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000038
reed@google.com5bdfb332013-05-02 18:55:44 +000039 Proc init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache,
40 const SkPaint&);
41
42 // call this instead of fBlitter->blitMask() since this wrapper will handle
43 // the case when the mask is ARGB32_Format
44 //
45 void blitMask(const SkMask& mask, const SkIRect& clip) const {
46 if (SkMask::kARGB32_Format == mask.fFormat) {
47 this->blitMaskAsSprite(mask);
48 } else {
49 fBlitter->blitMask(mask, clip);
50 }
51 }
52
53 // mask must be kARGB32_Format
54 void blitMaskAsSprite(const SkMask& mask) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000055};
56
57struct SkDrawProcs {
58 SkDraw1Glyph::Proc fD1GProc;
59};
60
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +000061bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&,
62 SkScalar* coverage);
63
reed@google.comecadf992011-09-19 19:18:18 +000064/**
rmistry@google.comfbfcd562012-08-23 18:09:54 +000065 * If the current paint is set to stroke and the stroke-width when applied to
bsalomon@google.comdd1be602012-01-18 20:34:00 +000066 * the matrix is <= 1.0, then this returns true, and sets coverage (simulating
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067 * a stroke by drawing a hairline with partial coverage). If any of these
bsalomon@google.comdd1be602012-01-18 20:34:00 +000068 * conditions are false, then this returns false and coverage is ignored.
reed@google.comecadf992011-09-19 19:18:18 +000069 */
commit-bot@chromium.orge0a868c2013-11-22 07:02:11 +000070inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix,
71 SkScalar* coverage) {
72 if (SkPaint::kStroke_Style != paint.getStyle()) {
73 return false;
74 }
75
76 SkScalar strokeWidth = paint.getStrokeWidth();
77 if (0 == strokeWidth) {
78 *coverage = SK_Scalar1;
79 return true;
80 }
81
82 if (!paint.isAntiAlias()) {
83 return false;
84 }
85
86 return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
87}
reed@google.comecadf992011-09-19 19:18:18 +000088
reed@android.com8a1c16f2008-12-17 15:59:43 +000089#endif