• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkDraw_DEFINED
18 #define SkDraw_DEFINED
19 
20 #include "SkBitmap.h"
21 #include "SkCanvas.h"
22 #include "SkMask.h"
23 #include "SkMatrix.h"
24 #include "SkPaint.h"
25 #include "SkRect.h"
26 #include "SkAutoKern.h"
27 
28 class SkBounder;
29 class SkDevice;
30 class SkPath;
31 class SkRegion;
32 struct SkDrawProcs;
33 
34 class SkDraw {
35 public:
SkDraw()36     SkDraw() : fDevice(NULL), fBounder(NULL), fProcs(NULL) {}
37     SkDraw(const SkDraw& src);
38 
39     void    drawPaint(const SkPaint&) const;
40     void    drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
41                        const SkPaint&) const;
42     void    drawRect(const SkRect&, const SkPaint&) const;
43     /*  To save on mallocs, we allow a flag that tells us that srcPath is
44         mutable, so that we don't have to make copies of it as we transform it.
45     */
46     void    drawPath(const SkPath& srcPath, const SkPaint&,
47                      const SkMatrix* prePathMatrix, bool pathIsMutable) const;
48     void    drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const;
49     void    drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
50     void    drawText(const char text[], size_t byteLength, SkScalar x,
51                      SkScalar y, const SkPaint& paint) const;
52     void    drawPosText(const char text[], size_t byteLength,
53                         const SkScalar pos[], SkScalar constY,
54                         int scalarsPerPosition, const SkPaint& paint) const;
55     void    drawTextOnPath(const char text[], size_t byteLength,
56                         const SkPath&, const SkMatrix*, const SkPaint&) const;
57     void    drawPosTextOnPath(const char text[], size_t byteLength,
58                               const SkPoint pos[], const SkPaint& paint,
59                               const SkPath& path, const SkMatrix* matrix) const;
60     void    drawVertices(SkCanvas::VertexMode mode, int count,
61                          const SkPoint vertices[], const SkPoint textures[],
62                          const SkColor colors[], SkXfermode* xmode,
63                          const uint16_t indices[], int ptCount,
64                          const SkPaint& paint) const;
65 
drawPath(const SkPath & src,const SkPaint & paint)66     void drawPath(const SkPath& src, const SkPaint& paint) const {
67         this->drawPath(src, paint, NULL, false);
68     }
69 
70     /** Helper function that creates a mask from a path and an optional maskfilter.
71         Note however, that the resulting mask will not have been actually filtered,
72         that must be done afterwards (by calling filterMask). The maskfilter is provided
73         solely to assist in computing the mask's bounds (if the mode requests that).
74     */
75     static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
76                            SkMaskFilter* filter, const SkMatrix* filterMatrix,
77                            SkMask* mask, SkMask::CreateMode mode);
78 
79 private:
80     void    drawText_asPaths(const char text[], size_t byteLength,
81                              SkScalar x, SkScalar y, const SkPaint&) const;
82     void    drawDevMask(const SkMask& mask, const SkPaint&) const;
83     void    drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
84 
85 public:
86     const SkBitmap* fBitmap;        // required
87     const SkMatrix* fMatrix;        // required
88     const SkRegion* fClip;          // required
89     SkDevice*       fDevice;        // optional
90     SkBounder*      fBounder;       // optional
91     SkDrawProcs*    fProcs;         // optional
92 
93 #ifdef SK_DEBUG
94     void    validate() const;
95 #endif
96 };
97 
98 class SkGlyphCache;
99 
100 class SkTextToPathIter {
101 public:
102     SkTextToPathIter(const char text[], size_t length, const SkPaint&,
103                      bool applyStrokeAndPathEffects, bool forceLinearTextOn);
104     ~SkTextToPathIter();
105 
getPaint()106     const SkPaint&  getPaint() const { return fPaint; }
getPathScale()107     SkScalar        getPathScale() const { return fScale; }
108 
109     const SkPath*   next(SkScalar* xpos);   //!< returns nil when there are no more paths
110 
111 private:
112     SkGlyphCache*   fCache;
113     SkPaint         fPaint;
114     SkScalar        fScale;
115     SkFixed         fPrevAdvance;
116     const char*     fText;
117     const char*     fStop;
118     SkMeasureCacheProc fGlyphCacheProc;
119 
120     const SkPath*   fPath;      // returned in next
121     SkScalar        fXPos;      // accumulated xpos, returned in next
122     SkAutoKern      fAutoKern;
123 };
124 
125 #endif
126 
127 
128