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" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 17 | class SkBitmap; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | class SkBounder; |
reed@google.com | 7d7ca79 | 2011-02-23 22:39:18 +0000 | [diff] [blame] | 19 | class SkClipStack; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 20 | class SkBaseDevice; |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 21 | class SkMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | class SkPath; |
| 23 | class SkRegion; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 24 | class SkRasterClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | struct SkDrawProcs; |
tomhudson@google.com | a9e1824 | 2013-04-03 10:18:17 +0000 | [diff] [blame] | 26 | struct SkRect; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 27 | class SkRRect; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | |
| 29 | class SkDraw { |
| 30 | public: |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 31 | SkDraw(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | SkDraw(const SkDraw& src); |
| 33 | |
| 34 | void drawPaint(const SkPaint&) const; |
| 35 | void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 36 | const SkPaint&, bool forceUseDevice = false) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | void drawRect(const SkRect&, const SkPaint&) const; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 38 | void drawRRect(const SkRRect&, const SkPaint&) const; |
reed@google.com | 7ff8d81 | 2011-03-25 15:08:16 +0000 | [diff] [blame] | 39 | /** |
| 40 | * To save on mallocs, we allow a flag that tells us that srcPath is |
| 41 | * mutable, so that we don't have to make copies of it as we transform it. |
| 42 | * |
| 43 | * If prePathMatrix is not null, it should logically be applied before any |
| 44 | * stroking or other effects. If there are no effects on the paint that |
| 45 | * affect the geometry/rasterization, then the pre matrix can just be |
| 46 | * pre-concated with the current matrix. |
| 47 | */ |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 48 | void drawPath(const SkPath& path, const SkPaint& paint, |
| 49 | const SkMatrix* prePathMatrix, bool pathIsMutable) const { |
| 50 | this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); |
| 51 | } |
| 52 | |
| 53 | void drawPath(const SkPath& path, const SkPaint& paint) const { |
| 54 | this->drawPath(path, paint, NULL, false, false); |
| 55 | } |
| 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; |
| 58 | void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; |
| 59 | void drawText(const char text[], size_t byteLength, SkScalar x, |
| 60 | SkScalar y, const SkPaint& paint) const; |
| 61 | void drawPosText(const char text[], size_t byteLength, |
| 62 | const SkScalar pos[], SkScalar constY, |
| 63 | int scalarsPerPosition, const SkPaint& paint) const; |
| 64 | void drawTextOnPath(const char text[], size_t byteLength, |
| 65 | const SkPath&, const SkMatrix*, const SkPaint&) const; |
| 66 | void drawVertices(SkCanvas::VertexMode mode, int count, |
| 67 | const SkPoint vertices[], const SkPoint textures[], |
| 68 | const SkColor colors[], SkXfermode* xmode, |
| 69 | const uint16_t indices[], int ptCount, |
| 70 | const SkPaint& paint) const; |
reed@google.com | 7d7ca79 | 2011-02-23 22:39:18 +0000 | [diff] [blame] | 71 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 72 | /** |
| 73 | * Overwrite the target with the path's coverage (i.e. its mask). |
| 74 | * Will overwrite the entire device, so it need not be zero'd first. |
| 75 | * |
| 76 | * Only device A8 is supported right now. |
| 77 | */ |
| 78 | void drawPathCoverage(const SkPath& src, const SkPaint& paint) const { |
| 79 | this->drawPath(src, paint, NULL, false, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** Helper function that creates a mask from a path and an optional maskfilter. |
| 83 | Note however, that the resulting mask will not have been actually filtered, |
| 84 | that must be done afterwards (by calling filterMask). The maskfilter is provided |
| 85 | solely to assist in computing the mask's bounds (if the mode requests that). |
| 86 | */ |
| 87 | static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 88 | const SkMaskFilter*, const SkMatrix* filterMatrix, |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 89 | SkMask* mask, SkMask::CreateMode mode, |
| 90 | SkPaint::Style style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 91 | |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 92 | enum RectType { |
| 93 | kHair_RectType, |
| 94 | kFill_RectType, |
| 95 | kStroke_RectType, |
| 96 | kPath_RectType |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * Based on the paint's style, strokeWidth, and the matrix, classify how |
| 101 | * to draw the rect. If no special-case is available, returns |
| 102 | * kPath_RectType. |
| 103 | * |
| 104 | * Iff RectType == kStroke_RectType, then strokeSize is set to the device |
| 105 | * width and height of the stroke. |
| 106 | */ |
| 107 | static RectType ComputeRectType(const SkPaint&, const SkMatrix&, |
| 108 | SkPoint* strokeSize); |
| 109 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame^] | 110 | static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&); |
| 111 | void drawText_asPaths(const char text[], size_t byteLength, |
| 112 | SkScalar x, SkScalar y, const SkPaint&) const; |
| 113 | void drawPosText_asPaths(const char text[], size_t byteLength, |
| 114 | const SkScalar pos[], SkScalar constY, |
| 115 | int scalarsPerPosition, const SkPaint&) const; |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 116 | |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 117 | private: |
| 118 | void drawDevMask(const SkMask& mask, const SkPaint&) const; |
| 119 | void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; |
| 120 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 121 | void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix, |
| 122 | bool pathIsMutable, bool drawCoverage) const; |
| 123 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 124 | /** |
| 125 | * Return the current clip bounds, in local coordinates, with slop to account |
| 126 | * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then |
| 127 | * run through the inverse of the matrix). |
| 128 | * |
| 129 | * If the matrix cannot be inverted, or the current clip is empty, return |
| 130 | * false and ignore bounds parameter. |
| 131 | */ |
| 132 | bool SK_WARN_UNUSED_RESULT |
| 133 | computeConservativeLocalClipBounds(SkRect* bounds) const; |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 134 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | public: |
| 136 | const SkBitmap* fBitmap; // required |
| 137 | const SkMatrix* fMatrix; // required |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 138 | const SkRegion* fClip; // DEPRECATED |
| 139 | const SkRasterClip* fRC; // required |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 140 | |
reed@google.com | 7d7ca79 | 2011-02-23 22:39:18 +0000 | [diff] [blame] | 141 | const SkClipStack* fClipStack; // optional |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 142 | SkBaseDevice* fDevice; // optional |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | SkBounder* fBounder; // optional |
| 144 | SkDrawProcs* fProcs; // optional |
| 145 | |
| 146 | #ifdef SK_DEBUG |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 147 | void validate() const; |
| 148 | #else |
| 149 | void validate() const {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | #endif |
| 151 | }; |
| 152 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | #endif |