• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkDraw_DEFINED
11 #define SkDraw_DEFINED
12 
13 #include "SkBitmap.h"
14 #include "SkCanvas.h"
15 #include "SkMask.h"
16 #include "SkMatrix.h"
17 #include "SkPaint.h"
18 #include "SkRect.h"
19 #include "SkAutoKern.h"
20 
21 class SkBounder;
22 class SkClipStack;
23 class SkDevice;
24 class SkPath;
25 class SkRegion;
26 class SkRasterClip;
27 struct SkDrawProcs;
28 
29 class SkDraw {
30 public:
31     SkDraw();
32     SkDraw(const SkDraw& src);
33 
34     void    drawPaint(const SkPaint&) const;
35     void    drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
36                        const SkPaint&, bool forceUseDevice = false) const;
37     void    drawRect(const SkRect&, const SkPaint&) const;
38     /**
39      *  To save on mallocs, we allow a flag that tells us that srcPath is
40      *  mutable, so that we don't have to make copies of it as we transform it.
41      *
42      *  If prePathMatrix is not null, it should logically be applied before any
43      *  stroking or other effects. If there are no effects on the paint that
44      *  affect the geometry/rasterization, then the pre matrix can just be
45      *  pre-concated with the current matrix.
46      */
47     void    drawPath(const SkPath& srcPath, const SkPaint&,
48                      const SkMatrix* prePathMatrix, bool pathIsMutable) const;
49     void    drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const;
50     void    drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
51     void    drawText(const char text[], size_t byteLength, SkScalar x,
52                      SkScalar y, const SkPaint& paint) const;
53     void    drawPosText(const char text[], size_t byteLength,
54                         const SkScalar pos[], SkScalar constY,
55                         int scalarsPerPosition, const SkPaint& paint) const;
56     void    drawTextOnPath(const char text[], size_t byteLength,
57                         const SkPath&, const SkMatrix*, const SkPaint&) const;
58 #ifdef SK_BUILD_FOR_ANDROID
59     void    drawPosTextOnPath(const char text[], size_t byteLength,
60                               const SkPoint pos[], const SkPaint& paint,
61                               const SkPath& path, const SkMatrix* matrix) const;
62 #endif
63     void    drawVertices(SkCanvas::VertexMode mode, int count,
64                          const SkPoint vertices[], const SkPoint textures[],
65                          const SkColor colors[], SkXfermode* xmode,
66                          const uint16_t indices[], int ptCount,
67                          const SkPaint& paint) const;
68 
drawPath(const SkPath & src,const SkPaint & paint)69     void drawPath(const SkPath& src, const SkPaint& paint) const {
70         this->drawPath(src, paint, NULL, false);
71     }
72 
73     /** Helper function that creates a mask from a path and an optional maskfilter.
74         Note however, that the resulting mask will not have been actually filtered,
75         that must be done afterwards (by calling filterMask). The maskfilter is provided
76         solely to assist in computing the mask's bounds (if the mode requests that).
77     */
78     static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
79                            SkMaskFilter* filter, const SkMatrix* filterMatrix,
80                            SkMask* mask, SkMask::CreateMode mode);
81 
82     enum RectType {
83         kHair_RectType,
84         kFill_RectType,
85         kStroke_RectType,
86         kPath_RectType
87     };
88 
89     /**
90      *  Based on the paint's style, strokeWidth, and the matrix, classify how
91      *  to draw the rect. If no special-case is available, returns
92      *  kPath_RectType.
93      *
94      *  Iff RectType == kStroke_RectType, then strokeSize is set to the device
95      *  width and height of the stroke.
96      */
97     static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
98                                     SkPoint* strokeSize);
99 
100 private:
101     void    drawText_asPaths(const char text[], size_t byteLength,
102                              SkScalar x, SkScalar y, const SkPaint&) const;
103     void    drawDevMask(const SkMask& mask, const SkPaint&) const;
104     void    drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
105 
106 public:
107     const SkBitmap* fBitmap;        // required
108     const SkMatrix* fMatrix;        // required
109     const SkRegion* fClip;          // DEPRECATED
110     const SkRasterClip* fRC;        // required
111 
112     const SkClipStack* fClipStack;  // optional
113     SkDevice*       fDevice;        // optional
114     SkBounder*      fBounder;       // optional
115     SkDrawProcs*    fProcs;         // optional
116 
117     const SkMatrix* fMVMatrix;      // optional
118     const SkMatrix* fExtMatrix;     // optional
119 
120 #ifdef SK_DEBUG
121     void validate() const;
122 #else
validate()123     void validate() const {}
124 #endif
125 };
126 
127 class SkGlyphCache;
128 
129 class SkTextToPathIter {
130 public:
131     SkTextToPathIter(const char text[], size_t length, const SkPaint&,
132                      bool applyStrokeAndPathEffects, bool forceLinearTextOn);
133     ~SkTextToPathIter();
134 
getPaint()135     const SkPaint&  getPaint() const { return fPaint; }
getPathScale()136     SkScalar        getPathScale() const { return fScale; }
137 
138     const SkPath*   next(SkScalar* xpos);   //!< returns nil when there are no more paths
139 
140 private:
141     SkGlyphCache*   fCache;
142     SkPaint         fPaint;
143     SkScalar        fScale;
144     SkFixed         fPrevAdvance;
145     const char*     fText;
146     const char*     fStop;
147     SkMeasureCacheProc fGlyphCacheProc;
148 
149     const SkPath*   fPath;      // returned in next
150     SkScalar        fXPos;      // accumulated xpos, returned in next
151     SkAutoKern      fAutoKern;
152     int             fXYIndex;   // cache for horizontal -vs- vertical text
153 };
154 
155 #endif
156 
157 
158