blob: 1c2c66efb3a7eace2d8e343583fbf8747ba4cb56 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkDraw_DEFINED
11#define SkDraw_DEFINED
12
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkCanvas.h"
14#include "SkMask.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkPaint.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016
tomhudson@google.coma9e18242013-04-03 10:18:17 +000017class SkBitmap;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkBounder;
reed@google.com7d7ca792011-02-23 22:39:18 +000019class SkClipStack;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000020class SkBaseDevice;
tomhudson@google.coma9e18242013-04-03 10:18:17 +000021class SkMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +000022class SkPath;
23class SkRegion;
reed@google.com045e62d2011-10-24 12:19:46 +000024class SkRasterClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +000025struct SkDrawProcs;
tomhudson@google.coma9e18242013-04-03 10:18:17 +000026struct SkRect;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027
28class SkDraw {
29public:
reed@android.comf2b98d62010-12-20 18:26:13 +000030 SkDraw();
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 SkDraw(const SkDraw& src);
32
33 void drawPaint(const SkPaint&) const;
34 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
reed@android.comf2b98d62010-12-20 18:26:13 +000035 const SkPaint&, bool forceUseDevice = false) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 void drawRect(const SkRect&, const SkPaint&) const;
reed@google.com7ff8d812011-03-25 15:08:16 +000037 /**
38 * To save on mallocs, we allow a flag that tells us that srcPath is
39 * mutable, so that we don't have to make copies of it as we transform it.
40 *
41 * If prePathMatrix is not null, it should logically be applied before any
42 * stroking or other effects. If there are no effects on the paint that
43 * affect the geometry/rasterization, then the pre matrix can just be
44 * pre-concated with the current matrix.
45 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 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;
djsollen@google.com56c69772011-11-08 19:00:26 +000057#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.comcd9d69b2011-03-14 20:30:14 +000058 void drawPosTextOnPath(const char text[], size_t byteLength,
59 const SkPoint pos[], const SkPaint& paint,
60 const SkPath& path, const SkMatrix* matrix) const;
61#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 void drawVertices(SkCanvas::VertexMode mode, int count,
63 const SkPoint vertices[], const SkPoint textures[],
64 const SkColor colors[], SkXfermode* xmode,
65 const uint16_t indices[], int ptCount,
66 const SkPaint& paint) const;
reed@google.com7d7ca792011-02-23 22:39:18 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 void drawPath(const SkPath& src, const SkPaint& paint) const {
69 this->drawPath(src, paint, NULL, false);
70 }
71
72 /** Helper function that creates a mask from a path and an optional maskfilter.
73 Note however, that the resulting mask will not have been actually filtered,
74 that must be done afterwards (by calling filterMask). The maskfilter is provided
75 solely to assist in computing the mask's bounds (if the mode requests that).
76 */
77 static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
reed@google.com30711b72012-12-18 19:18:39 +000078 const SkMaskFilter*, const SkMatrix* filterMatrix,
junov@chromium.org2ac4ef52012-04-04 15:16:51 +000079 SkMask* mask, SkMask::CreateMode mode,
80 SkPaint::Style style);
reed@android.com8a1c16f2008-12-17 15:59:43 +000081
reed@google.com62ab7ad2011-04-05 14:08:25 +000082 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
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100private:
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
reed@google.comed43dff2013-06-04 16:56:27 +0000106 void drawPosText_asPaths(const char text[], size_t byteLength,
107 const SkScalar pos[], SkScalar constY,
108 int scalarsPerPosition, const SkPaint&) const;
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000109
reed@google.com4bbdeac2013-01-24 21:03:11 +0000110 /**
111 * Return the current clip bounds, in local coordinates, with slop to account
112 * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
113 * run through the inverse of the matrix).
114 *
115 * If the matrix cannot be inverted, or the current clip is empty, return
116 * false and ignore bounds parameter.
117 */
118 bool SK_WARN_UNUSED_RESULT
119 computeConservativeLocalClipBounds(SkRect* bounds) const;
skia.committer@gmail.com4024f322013-01-25 07:06:46 +0000120
reed@google.comed43dff2013-06-04 16:56:27 +0000121 static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
122
reed@android.com8a1c16f2008-12-17 15:59:43 +0000123public:
124 const SkBitmap* fBitmap; // required
125 const SkMatrix* fMatrix; // required
reed@google.com045e62d2011-10-24 12:19:46 +0000126 const SkRegion* fClip; // DEPRECATED
127 const SkRasterClip* fRC; // required
reed@android.comf2b98d62010-12-20 18:26:13 +0000128
reed@google.com7d7ca792011-02-23 22:39:18 +0000129 const SkClipStack* fClipStack; // optional
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000130 SkBaseDevice* fDevice; // optional
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131 SkBounder* fBounder; // optional
132 SkDrawProcs* fProcs; // optional
133
134#ifdef SK_DEBUG
reed@android.comf2b98d62010-12-20 18:26:13 +0000135 void validate() const;
136#else
137 void validate() const {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000138#endif
139};
140
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141#endif