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 "SkBitmap.h" 14 #include "SkCanvas.h" 15 #include "SkMask.h" 16 #include "SkMatrix.h" 17 #include "SkPaint.h" 18 #include "SkRect.h" 19 #include "SkAutoKern.h" 20 21 class SkBounder; 22 class SkClipStack; 23 class SkDevice; 24 class SkPath; 25 class SkRegion; 26 class SkRasterClip; 27 struct SkDrawProcs; 28 29 class SkDraw { 30 public: 31 SkDraw(); 32 SkDraw(const SkDraw& src); 33 34 void drawPaint(const SkPaint&) const; 35 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], 36 const SkPaint&, bool forceUseDevice = false) const; 37 void drawRect(const SkRect&, const SkPaint&) const; 38 /** 39 * To save on mallocs, we allow a flag that tells us that srcPath is 40 * mutable, so that we don't have to make copies of it as we transform it. 41 * 42 * If prePathMatrix is not null, it should logically be applied before any 43 * stroking or other effects. If there are no effects on the paint that 44 * affect the geometry/rasterization, then the pre matrix can just be 45 * pre-concated with the current matrix. 46 */ 47 void drawPath(const SkPath& srcPath, const SkPaint&, 48 const SkMatrix* prePathMatrix, bool pathIsMutable) const; 49 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; 50 void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; 51 void drawText(const char text[], size_t byteLength, SkScalar x, 52 SkScalar y, const SkPaint& paint) const; 53 void drawPosText(const char text[], size_t byteLength, 54 const SkScalar pos[], SkScalar constY, 55 int scalarsPerPosition, const SkPaint& paint) const; 56 void drawTextOnPath(const char text[], size_t byteLength, 57 const SkPath&, const SkMatrix*, const SkPaint&) const; 58 #ifdef SK_BUILD_FOR_ANDROID 59 void drawPosTextOnPath(const char text[], size_t byteLength, 60 const SkPoint pos[], const SkPaint& paint, 61 const SkPath& path, const SkMatrix* matrix) const; 62 #endif 63 void drawVertices(SkCanvas::VertexMode mode, int count, 64 const SkPoint vertices[], const SkPoint textures[], 65 const SkColor colors[], SkXfermode* xmode, 66 const uint16_t indices[], int ptCount, 67 const SkPaint& paint) const; 68 69 void drawPath(const SkPath& src, const SkPaint& paint) const { 70 this->drawPath(src, paint, NULL, false); 71 } 72 73 /** Helper function that creates a mask from a path and an optional maskfilter. 74 Note however, that the resulting mask will not have been actually filtered, 75 that must be done afterwards (by calling filterMask). The maskfilter is provided 76 solely to assist in computing the mask's bounds (if the mode requests that). 77 */ 78 static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 79 const SkMaskFilter*, const SkMatrix* filterMatrix, 80 SkMask* mask, SkMask::CreateMode mode, 81 SkPaint::Style style); 82 83 enum RectType { 84 kHair_RectType, 85 kFill_RectType, 86 kStroke_RectType, 87 kPath_RectType 88 }; 89 90 /** 91 * Based on the paint's style, strokeWidth, and the matrix, classify how 92 * to draw the rect. If no special-case is available, returns 93 * kPath_RectType. 94 * 95 * Iff RectType == kStroke_RectType, then strokeSize is set to the device 96 * width and height of the stroke. 97 */ 98 static RectType ComputeRectType(const SkPaint&, const SkMatrix&, 99 SkPoint* strokeSize); 100 101 private: 102 void drawText_asPaths(const char text[], size_t byteLength, 103 SkScalar x, SkScalar y, const SkPaint&) const; 104 void drawDevMask(const SkMask& mask, const SkPaint&) const; 105 void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; 106 107 /** 108 * Return the current clip bounds, in local coordinates, with slop to account 109 * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then 110 * run through the inverse of the matrix). 111 * 112 * If the matrix cannot be inverted, or the current clip is empty, return 113 * false and ignore bounds parameter. 114 */ 115 bool SK_WARN_UNUSED_RESULT 116 computeConservativeLocalClipBounds(SkRect* bounds) const; 117 118 public: 119 const SkBitmap* fBitmap; // required 120 const SkMatrix* fMatrix; // required 121 const SkRegion* fClip; // DEPRECATED 122 const SkRasterClip* fRC; // required 123 124 const SkClipStack* fClipStack; // optional 125 SkDevice* fDevice; // optional 126 SkBounder* fBounder; // optional 127 SkDrawProcs* fProcs; // optional 128 129 #ifdef SK_DEBUG 130 void validate() const; 131 #else 132 void validate() const {} 133 #endif 134 }; 135 136 #endif 137