• 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 "SkCanvas.h"
14 #include "SkMask.h"
15 #include "SkPaint.h"
16 
17 class SkBitmap;
18 class SkClipStack;
19 class SkBaseDevice;
20 class SkMatrix;
21 class SkPath;
22 class SkRegion;
23 class SkRasterClip;
24 struct SkDrawProcs;
25 struct SkRect;
26 class SkRRect;
27 
28 class SkDraw {
29 public:
30     SkDraw();
31     SkDraw(const SkDraw& src);
32 
33     void    drawPaint(const SkPaint&) const;
34     void    drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
35                        const SkPaint&, bool forceUseDevice = false) const;
36     void    drawRect(const SkRect&, const SkPaint&) const;
37     void    drawRRect(const SkRRect&, 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      */
drawPath(const SkPath & path,const SkPaint & paint,const SkMatrix * prePathMatrix,bool pathIsMutable)47     void    drawPath(const SkPath& path, const SkPaint& paint,
48                      const SkMatrix* prePathMatrix, bool pathIsMutable) const {
49         this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
50     }
51 
drawPath(const SkPath & path,const SkPaint & paint)52     void drawPath(const SkPath& path, const SkPaint& paint) const {
53         this->drawPath(path, paint, NULL, false, false);
54     }
55 
56     void    drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const;
57     void    drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
58     void    drawText(const char text[], size_t byteLength, SkScalar x,
59                      SkScalar y, const SkPaint& paint) const;
60     void    drawPosText(const char text[], size_t byteLength,
61                         const SkScalar pos[], SkScalar constY,
62                         int scalarsPerPosition, const SkPaint& paint) const;
63     void    drawTextOnPath(const char text[], size_t byteLength,
64                         const SkPath&, const SkMatrix*, const SkPaint&) const;
65     void    drawVertices(SkCanvas::VertexMode mode, int count,
66                          const SkPoint vertices[], const SkPoint textures[],
67                          const SkColor colors[], SkXfermode* xmode,
68                          const uint16_t indices[], int ptCount,
69                          const SkPaint& paint) const;
70 
71     /**
72      *  Overwrite the target with the path's coverage (i.e. its mask).
73      *  Will overwrite the entire device, so it need not be zero'd first.
74      *
75      *  Only device A8 is supported right now.
76      */
drawPathCoverage(const SkPath & src,const SkPaint & paint)77     void drawPathCoverage(const SkPath& src, const SkPaint& paint) const {
78         this->drawPath(src, paint, NULL, false, true);
79     }
80 
81     /** Helper function that creates a mask from a path and an optional maskfilter.
82         Note however, that the resulting mask will not have been actually filtered,
83         that must be done afterwards (by calling filterMask). The maskfilter is provided
84         solely to assist in computing the mask's bounds (if the mode requests that).
85     */
86     static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
87                            const SkMaskFilter*, const SkMatrix* filterMatrix,
88                            SkMask* mask, SkMask::CreateMode mode,
89                            SkPaint::Style style);
90 
91     enum RectType {
92         kHair_RectType,
93         kFill_RectType,
94         kStroke_RectType,
95         kPath_RectType
96     };
97 
98     /**
99      *  Based on the paint's style, strokeWidth, and the matrix, classify how
100      *  to draw the rect. If no special-case is available, returns
101      *  kPath_RectType.
102      *
103      *  Iff RectType == kStroke_RectType, then strokeSize is set to the device
104      *  width and height of the stroke.
105      */
106     static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
107                                     SkPoint* strokeSize);
108 
109     static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
110     void        drawText_asPaths(const char text[], size_t byteLength,
111                                  SkScalar x, SkScalar y, const SkPaint&) const;
112     void        drawPosText_asPaths(const char text[], size_t byteLength,
113                                     const SkScalar pos[], SkScalar constY,
114                                     int scalarsPerPosition, const SkPaint&) const;
115 
116 private:
117     void    drawDevMask(const SkMask& mask, const SkPaint&) const;
118     void    drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
119 
120     void    drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix,
121                      bool pathIsMutable, bool drawCoverage) const;
122 
123     /**
124      *  Return the current clip bounds, in local coordinates, with slop to account
125      *  for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
126      *  run through the inverse of the matrix).
127      *
128      *  If the matrix cannot be inverted, or the current clip is empty, return
129      *  false and ignore bounds parameter.
130      */
131     bool SK_WARN_UNUSED_RESULT
132     computeConservativeLocalClipBounds(SkRect* bounds) const;
133 
134 public:
135     const SkBitmap* fBitmap;        // required
136     const SkMatrix* fMatrix;        // required
137     const SkRegion* fClip;          // DEPRECATED
138     const SkRasterClip* fRC;        // required
139 
140     const SkClipStack* fClipStack;  // optional
141     SkBaseDevice*   fDevice;        // optional
142     SkDrawProcs*    fProcs;         // optional
143 
144 #ifdef SK_DEBUG
145     void validate() const;
146 #else
validate()147     void validate() const {}
148 #endif
149 };
150 
151 #endif
152