1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkDraw_DEFINED 18 #define SkDraw_DEFINED 19 20 #include "SkBitmap.h" 21 #include "SkCanvas.h" 22 #include "SkMask.h" 23 #include "SkMatrix.h" 24 #include "SkPaint.h" 25 #include "SkRect.h" 26 #include "SkAutoKern.h" 27 28 class SkBounder; 29 class SkDevice; 30 class SkPath; 31 class SkRegion; 32 struct SkDrawProcs; 33 34 class SkDraw { 35 public: SkDraw()36 SkDraw() : fDevice(NULL), fBounder(NULL), fProcs(NULL) {} 37 SkDraw(const SkDraw& src); 38 39 void drawPaint(const SkPaint&) const; 40 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], 41 const SkPaint&) const; 42 void drawRect(const SkRect&, const SkPaint&) const; 43 /* To save on mallocs, we allow a flag that tells us that srcPath is 44 mutable, so that we don't have to make copies of it as we transform it. 45 */ 46 void drawPath(const SkPath& srcPath, const SkPaint&, 47 const SkMatrix* prePathMatrix, bool pathIsMutable) const; 48 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; 49 void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; 50 void drawText(const char text[], size_t byteLength, SkScalar x, 51 SkScalar y, const SkPaint& paint) const; 52 void drawPosText(const char text[], size_t byteLength, 53 const SkScalar pos[], SkScalar constY, 54 int scalarsPerPosition, const SkPaint& paint) const; 55 void drawTextOnPath(const char text[], size_t byteLength, 56 const SkPath&, const SkMatrix*, const SkPaint&) const; 57 void drawVertices(SkCanvas::VertexMode mode, int count, 58 const SkPoint vertices[], const SkPoint textures[], 59 const SkColor colors[], SkXfermode* xmode, 60 const uint16_t indices[], int ptCount, 61 const SkPaint& paint) const; 62 drawPath(const SkPath & src,const SkPaint & paint)63 void drawPath(const SkPath& src, const SkPaint& paint) const { 64 this->drawPath(src, paint, NULL, false); 65 } 66 67 /** Helper function that creates a mask from a path and an optional maskfilter. 68 Note however, that the resulting mask will not have been actually filtered, 69 that must be done afterwards (by calling filterMask). The maskfilter is provided 70 solely to assist in computing the mask's bounds (if the mode requests that). 71 */ 72 static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 73 SkMaskFilter* filter, const SkMatrix* filterMatrix, 74 SkMask* mask, SkMask::CreateMode mode); 75 76 private: 77 void drawText_asPaths(const char text[], size_t byteLength, 78 SkScalar x, SkScalar y, const SkPaint&) const; 79 void drawDevMask(const SkMask& mask, const SkPaint&) const; 80 void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; 81 82 public: 83 const SkBitmap* fBitmap; // required 84 const SkMatrix* fMatrix; // required 85 const SkRegion* fClip; // required 86 SkDevice* fDevice; // optional 87 SkBounder* fBounder; // optional 88 SkDrawProcs* fProcs; // optional 89 90 #ifdef SK_DEBUG 91 void validate() const; 92 #endif 93 }; 94 95 class SkGlyphCache; 96 97 class SkTextToPathIter { 98 public: 99 SkTextToPathIter(const char text[], size_t length, const SkPaint&, 100 bool applyStrokeAndPathEffects, bool forceLinearTextOn); 101 ~SkTextToPathIter(); 102 getPaint()103 const SkPaint& getPaint() const { return fPaint; } getPathScale()104 SkScalar getPathScale() const { return fScale; } 105 106 const SkPath* next(SkScalar* xpos); //!< returns nil when there are no more paths 107 108 private: 109 SkGlyphCache* fCache; 110 SkPaint fPaint; 111 SkScalar fScale; 112 SkFixed fPrevAdvance; 113 const char* fText; 114 const char* fStop; 115 SkMeasureCacheProc fGlyphCacheProc; 116 117 const SkPath* fPath; // returned in next 118 SkScalar fXPos; // accumulated xpos, returned in next 119 SkAutoKern fAutoKern; 120 }; 121 122 #endif 123 124 125