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