Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDraw.h
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 #include "SkStrokeRec.h"
17 
18 class SkBitmap;
19 class SkClipStack;
20 class SkBaseDevice;
21 class SkBlitter;
22 class SkMatrix;
23 class SkPath;
24 class SkRegion;
25 class SkRasterClip;
26 struct SkDrawProcs;
27 struct SkRect;
28 class SkRRect;
29 
30 class SkDraw {
31 public:
32  SkDraw();
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& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
38  const SkRect* postPaintRect) const;
39  void drawRect(const SkRect& rect, const SkPaint& paint) const {
40  this->drawRect(rect, paint, NULL, NULL);
41  }
42  void drawRRect(const SkRRect&, const SkPaint&) const;
52  void drawPath(const SkPath& path, const SkPaint& paint,
53  const SkMatrix* prePathMatrix, bool pathIsMutable) const {
54  this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
55  }
56 
57  void drawPath(const SkPath& path, const SkPaint& paint,
58  SkBlitter* customBlitter = NULL) const {
59  this->drawPath(path, paint, NULL, false, false, customBlitter);
60  }
61 
62  /* If dstOrNull is null, computes a dst by mapping the bitmap's bounds through the matrix. */
63  void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
64  const SkPaint&) const;
65  void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
66  void drawText(const char text[], size_t byteLength, SkScalar x,
67  SkScalar y, const SkPaint& paint) const;
68  void drawPosText(const char text[], size_t byteLength,
69  const SkScalar pos[], int scalarsPerPosition,
70  const SkPoint& offset, const SkPaint& paint) const;
71  void drawVertices(SkCanvas::VertexMode mode, int count,
72  const SkPoint vertices[], const SkPoint textures[],
73  const SkColor colors[], SkXfermode* xmode,
74  const uint16_t indices[], int ptCount,
75  const SkPaint& paint) const;
76 
83  void drawPathCoverage(const SkPath& src, const SkPaint& paint,
84  SkBlitter* customBlitter = NULL) const {
85  this->drawPath(src, paint, NULL, false, true, customBlitter);
86  }
87 
93  static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
94  const SkMaskFilter*, const SkMatrix* filterMatrix,
95  SkMask* mask, SkMask::CreateMode mode,
96  SkStrokeRec::InitStyle style);
97 
98  enum RectType {
99  kHair_RectType,
100  kFill_RectType,
101  kStroke_RectType,
102  kPath_RectType
103  };
104 
113  static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
114  SkPoint* strokeSize);
115 
116  static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
117  void drawText_asPaths(const char text[], size_t byteLength,
118  SkScalar x, SkScalar y, const SkPaint&) const;
119  void drawPosText_asPaths(const char text[], size_t byteLength,
120  const SkScalar pos[], int scalarsPerPosition,
121  const SkPoint& offset, const SkPaint&) const;
122  static SkScalar ComputeResScaleForStroking(const SkMatrix& );
123 private:
124  void drawDevMask(const SkMask& mask, const SkPaint&) const;
125  void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
126 
127  void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix,
128  bool pathIsMutable, bool drawCoverage,
129  SkBlitter* customBlitter = NULL) const;
130 
131  void drawLine(const SkPoint[2], const SkPaint&) const;
132  void drawDevPath(const SkPath& devPath, const SkPaint& paint, bool drawCoverage,
133  SkBlitter* customBlitter, bool doFill) const;
142  bool SK_WARN_UNUSED_RESULT
144 
146  uint32_t SK_WARN_UNUSED_RESULT scalerContextFlags() const;
147 
148 public:
149  SkPixmap fDst;
150  const SkMatrix* fMatrix; // required
151  const SkRasterClip* fRC; // required
152 
153  const SkClipStack* fClipStack; // optional, may be null
154  SkBaseDevice* fDevice; // optional, may be null
155 
156 #ifdef SK_DEBUG
157  void validate() const;
158 #else
159  void validate() const {}
160 #endif
161 };
162 
163 #endif
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
void drawPathCoverage(const SkPath &src, const SkPaint &paint, SkBlitter *customBlitter=NULL) const
Overwrite the target with the path's coverage (i.e.
Definition: SkDraw.h:83
uint32_t SK_WARN_UNUSED_RESULT scalerContextFlags() const
Returns the current setting for using fake gamma and contrast.
CreateMode
Definition: SkMask.h:120
PointMode
Definition: SkCanvas.h:620
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
Definition: SkPoint.h:156
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
bool SK_WARN_UNUSED_RESULT computeConservativeLocalClipBounds(SkRect *bounds) const
Return the current clip bounds, in local coordinates, with slop to account for antialiasing or hairli...
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
SkMask is used to describe alpha bitmaps, either 1bit, 8bit, or the 3-channel 3D format.
Definition: SkMask.h:19
SkXfermode is the base class for objects that are called to implement custom "transfer-modes" in the ...
Definition: SkXfermode.h:34
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
static RectType ComputeRectType(const SkPaint &, const SkMatrix &, SkPoint *strokeSize)
Based on the paint's style, strokeWidth, and the matrix, classify how to draw the rect...
SkMaskFilter is the base class for object that perform transformations on an alpha-channel mask befor...
Definition: SkMaskFilter.h:44
static bool DrawToMask(const SkPath &devPath, const SkIRect *clipBounds, const SkMaskFilter *, const SkMatrix *filterMatrix, SkMask *mask, SkMask::CreateMode mode, SkStrokeRec::InitStyle style)
Helper function that creates a mask from a path and an optional maskfilter.
The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing...
Definition: SkRegion.h:30
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
Definition: SkDevice.h:28
Definition: SkDraw.h:30
Definition: SkRect.h:390
void drawPath(const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix, bool pathIsMutable) const
To save on mallocs, we allow a flag that tells us that srcPath is mutable, so that we don't have to m...
Definition: SkDraw.h:52
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: SkClipStack.h:26