epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkDraw_DEFINED |
| 11 | #define SkDraw_DEFINED |
| 12 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
| 14 | #include "SkMask.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkPaint.h" |
Florin Malita | ab244f0 | 2017-05-03 19:16:58 +0000 | [diff] [blame] | 16 | #include "SkPixmap.h" |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame] | 17 | #include "SkStrokeRec.h" |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 18 | #include "SkVertices.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 20 | class SkBitmap; |
reed@google.com | 7d7ca79 | 2011-02-23 22:39:18 +0000 | [diff] [blame] | 21 | class SkClipStack; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 22 | class SkBaseDevice; |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 23 | class SkBlitter; |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 24 | class SkMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | class SkPath; |
| 26 | class SkRegion; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 27 | class SkRasterClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | struct SkDrawProcs; |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 29 | struct SkRect; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 30 | class SkRRect; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
| 32 | class SkDraw { |
| 33 | public: |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 34 | SkDraw(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
| 36 | void drawPaint(const SkPaint&) const; |
| 37 | void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 38 | const SkPaint&, SkBaseDevice*) const; |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 39 | void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix, |
| 40 | const SkRect* postPaintRect) const; |
| 41 | void drawRect(const SkRect& rect, const SkPaint& paint) const { |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 42 | this->drawRect(rect, paint, nullptr, nullptr); |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 43 | } |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 44 | void drawRRect(const SkRRect&, const SkPaint&) const; |
reed@google.com | 7ff8d81 | 2011-03-25 15:08:16 +0000 | [diff] [blame] | 45 | /** |
| 46 | * To save on mallocs, we allow a flag that tells us that srcPath is |
| 47 | * mutable, so that we don't have to make copies of it as we transform it. |
| 48 | * |
| 49 | * If prePathMatrix is not null, it should logically be applied before any |
| 50 | * stroking or other effects. If there are no effects on the paint that |
| 51 | * affect the geometry/rasterization, then the pre matrix can just be |
| 52 | * pre-concated with the current matrix. |
| 53 | */ |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 54 | void drawPath(const SkPath& path, const SkPaint& paint, |
Yuqian Li | 7b6d64a | 2017-09-01 14:42:49 -0400 | [diff] [blame] | 55 | const SkMatrix* prePathMatrix = nullptr, bool pathIsMutable = false) const { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 56 | this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); |
| 57 | } |
| 58 | |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 59 | /* If dstOrNull is null, computes a dst by mapping the bitmap's bounds through the matrix. */ |
| 60 | void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull, |
| 61 | const SkPaint&) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; |
| 63 | void drawText(const char text[], size_t byteLength, SkScalar x, |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 64 | SkScalar y, const SkPaint& paint, const SkSurfaceProps*) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | void drawPosText(const char text[], size_t byteLength, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 66 | const SkScalar pos[], int scalarsPerPosition, |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 67 | const SkPoint& offset, const SkPaint&, const SkSurfaceProps*) const; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 68 | void drawVertices(SkVertices::VertexMode mode, int count, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | const SkPoint vertices[], const SkPoint textures[], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 70 | const SkColor colors[], SkBlendMode bmode, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | const uint16_t indices[], int ptCount, |
| 72 | const SkPaint& paint) const; |
reed@google.com | 7d7ca79 | 2011-02-23 22:39:18 +0000 | [diff] [blame] | 73 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Overwrite the target with the path's coverage (i.e. its mask). |
| 76 | * Will overwrite the entire device, so it need not be zero'd first. |
| 77 | * |
| 78 | * Only device A8 is supported right now. |
| 79 | */ |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 80 | void drawPathCoverage(const SkPath& src, const SkPaint& paint, |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 81 | SkBlitter* customBlitter = nullptr) const { |
Mike Reed | 65cfb5e | 2017-06-07 13:03:36 -0400 | [diff] [blame] | 82 | bool isHairline = paint.getStyle() == SkPaint::kStroke_Style && |
| 83 | paint.getStrokeWidth() > 0; |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 84 | this->drawPath(src, paint, nullptr, false, !isHairline, customBlitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** Helper function that creates a mask from a path and an optional maskfilter. |
| 88 | Note however, that the resulting mask will not have been actually filtered, |
| 89 | that must be done afterwards (by calling filterMask). The maskfilter is provided |
| 90 | solely to assist in computing the mask's bounds (if the mode requests that). |
| 91 | */ |
| 92 | static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 93 | const SkMaskFilter*, const SkMatrix* filterMatrix, |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 94 | SkMask* mask, SkMask::CreateMode mode, |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame] | 95 | SkStrokeRec::InitStyle style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 97 | void drawDevMask(const SkMask& mask, const SkPaint&) const; |
| 98 | |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 99 | enum RectType { |
| 100 | kHair_RectType, |
| 101 | kFill_RectType, |
| 102 | kStroke_RectType, |
| 103 | kPath_RectType |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * Based on the paint's style, strokeWidth, and the matrix, classify how |
| 108 | * to draw the rect. If no special-case is available, returns |
| 109 | * kPath_RectType. |
| 110 | * |
| 111 | * Iff RectType == kStroke_RectType, then strokeSize is set to the device |
| 112 | * width and height of the stroke. |
| 113 | */ |
| 114 | static RectType ComputeRectType(const SkPaint&, const SkMatrix&, |
| 115 | SkPoint* strokeSize); |
| 116 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 117 | static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&); |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 118 | void drawText_asPaths(const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 119 | const SkPaint&) const; |
| 120 | void drawPosText_asPaths(const char text[], size_t byteLength, const SkScalar pos[], |
| 121 | int scalarsPerPosition, const SkPoint& offset, |
| 122 | const SkPaint&, const SkSurfaceProps*) const; |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 123 | static SkScalar ComputeResScaleForStroking(const SkMatrix& ); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 124 | private: |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 125 | void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; |
| 126 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 127 | void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix, |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 128 | bool pathIsMutable, bool drawCoverage, |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 129 | SkBlitter* customBlitter = nullptr) const; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 130 | |
reed | 82595b6 | 2016-05-09 17:48:46 -0700 | [diff] [blame] | 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; |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 134 | /** |
| 135 | * Return the current clip bounds, in local coordinates, with slop to account |
| 136 | * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then |
| 137 | * run through the inverse of the matrix). |
| 138 | * |
| 139 | * If the matrix cannot be inverted, or the current clip is empty, return |
| 140 | * false and ignore bounds parameter. |
| 141 | */ |
| 142 | bool SK_WARN_UNUSED_RESULT |
| 143 | computeConservativeLocalClipBounds(SkRect* bounds) const; |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 144 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 145 | /** Returns the current setting for using fake gamma and contrast. */ |
| 146 | uint32_t SK_WARN_UNUSED_RESULT scalerContextFlags() const; |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 147 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 148 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 149 | SkPixmap fDst; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | const SkMatrix* fMatrix; // required |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 151 | const SkRasterClip* fRC; // required |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | |
| 153 | #ifdef SK_DEBUG |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 154 | void validate() const; |
| 155 | #else |
| 156 | void validate() const {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | #endif |
| 158 | }; |
| 159 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 160 | #endif |