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