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 "include/core/SkCanvas.h" 14 #include "include/core/SkPaint.h" 15 #include "include/core/SkPixmap.h" 16 #include "include/core/SkStrokeRec.h" 17 #include "src/core/SkGlyphRunPainter.h" 18 #include "src/core/SkMask.h" 19 20 class SkBitmap; 21 class SkClipStack; 22 class SkBaseDevice; 23 class SkBlitter; 24 class SkMatrix; 25 class SkMatrixProvider; 26 class SkPath; 27 class SkRegion; 28 class SkRasterClip; 29 struct SkRect; 30 class SkRRect; 31 class SkVertices; 32 33 class SkDraw : public SkGlyphRunListPainter::BitmapDevicePainter { 34 public: 35 SkDraw(); 36 37 void drawPaint(const SkPaint&) const; 38 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], 39 const SkPaint&, SkBaseDevice*) const; 40 void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix, 41 const SkRect* postPaintRect) const; drawRect(const SkRect & rect,const SkPaint & paint)42 void drawRect(const SkRect& rect, const SkPaint& paint) const { 43 this->drawRect(rect, paint, nullptr, nullptr); 44 } 45 void drawRRect(const SkRRect&, const SkPaint&) const; 46 /** 47 * To save on mallocs, we allow a flag that tells us that srcPath is 48 * mutable, so that we don't have to make copies of it as we transform it. 49 * 50 * If prePathMatrix is not null, it should logically be applied before any 51 * stroking or other effects. If there are no effects on the paint that 52 * affect the geometry/rasterization, then the pre matrix can just be 53 * pre-concated with the current matrix. 54 */ 55 void drawPath(const SkPath& path, const SkPaint& paint, 56 const SkMatrix* prePathMatrix = nullptr, bool pathIsMutable = false) const { 57 this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); 58 } 59 60 /* If dstOrNull is null, computes a dst by mapping the bitmap's bounds through the matrix. */ 61 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull, 62 const SkSamplingOptions&, const SkPaint&) const override; 63 void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; 64 void drawGlyphRunList(SkCanvas* canvas, 65 SkGlyphRunListPainter* glyphPainter, 66 const SkGlyphRunList& glyphRunList, 67 const SkPaint& paint) const; 68 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&) const; 69 void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, 70 sk_sp<SkBlender>, const SkPaint&); 71 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, 79 SkBlitter* customBlitter = nullptr) const { 80 bool isHairline = paint.getStyle() == SkPaint::kStroke_Style && 81 paint.getStrokeWidth() > 0; 82 this->drawPath(src, paint, nullptr, false, !isHairline, customBlitter); 83 } 84 85 void paintMasks(SkDrawableGlyphBuffer* accepted, const SkPaint& paint) const override; 86 87 static bool ComputeMaskBounds(const SkRect& devPathBounds, const SkIRect& clipBounds, 88 const SkMaskFilter* filter, const SkMatrix* filterMatrix, 89 SkIRect* bounds); 90 91 /** Helper function that creates a mask from a path and an optional maskfilter. 92 Note however, that the resulting mask will not have been actually filtered, 93 that must be done afterwards (by calling filterMask). The maskfilter is provided 94 solely to assist in computing the mask's bounds (if the mode requests that). 95 */ 96 static bool DrawToMask(const SkPath& devPath, const SkIRect& clipBounds, 97 const SkMaskFilter*, const SkMatrix* filterMatrix, 98 SkMask* mask, SkMask::CreateMode mode, 99 SkStrokeRec::InitStyle style); 100 101 #if defined(SK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE) 102 void drawDevMask(const SkMask& mask, const SkPaint&) const; 103 #endif 104 105 enum RectType { 106 kHair_RectType, 107 kFill_RectType, 108 kStroke_RectType, 109 kPath_RectType 110 }; 111 112 /** 113 * Based on the paint's style, strokeWidth, and the matrix, classify how 114 * to draw the rect. If no special-case is available, returns 115 * kPath_RectType. 116 * 117 * Iff RectType == kStroke_RectType, then strokeSize is set to the device 118 * width and height of the stroke. 119 */ 120 static RectType ComputeRectType(const SkRect&, const SkPaint&, const SkMatrix&, 121 SkPoint* strokeSize); 122 123 private: 124 #if defined(SK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE) 125 void drawBitmapAsMask(const SkBitmap&, const SkSamplingOptions&, const SkPaint&) const; 126 #endif 127 void drawFixedVertices(const SkVertices* vertices, 128 sk_sp<SkBlender> blender, 129 const SkPaint& paint, 130 const SkMatrix& ctmInverse, 131 const SkPoint* dev2, 132 const SkPoint3* dev3, 133 SkArenaAlloc* outerAlloc) const; 134 135 void drawPath(const SkPath&, 136 const SkPaint&, 137 const SkMatrix* preMatrix, 138 bool pathIsMutable, 139 bool drawCoverage, 140 SkBlitter* customBlitter = nullptr) const; 141 142 void drawLine(const SkPoint[2], const SkPaint&) const; 143 144 void drawDevPath(const SkPath& devPath, 145 const SkPaint& paint, 146 bool drawCoverage, 147 SkBlitter* customBlitter, 148 bool doFill) const; 149 /** 150 * Return the current clip bounds, in local coordinates, with slop to account 151 * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then 152 * run through the inverse of the matrix). 153 * 154 * If the matrix cannot be inverted, or the current clip is empty, return 155 * false and ignore bounds parameter. 156 */ 157 bool SK_WARN_UNUSED_RESULT computeConservativeLocalClipBounds(SkRect* bounds) const; 158 159 public: 160 SkPixmap fDst; 161 const SkMatrixProvider* fMatrixProvider{nullptr}; // required 162 const SkRasterClip* fRC{nullptr}; // required 163 164 #ifdef SK_DEBUG 165 void validate() const; 166 #else validate()167 void validate() const {} 168 #endif 169 }; 170 171 #endif 172