1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkDraw.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,153 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkDraw_DEFINED 1.14 +#define SkDraw_DEFINED 1.15 + 1.16 +#include "SkCanvas.h" 1.17 +#include "SkMask.h" 1.18 +#include "SkPaint.h" 1.19 + 1.20 +class SkBitmap; 1.21 +class SkBounder; 1.22 +class SkClipStack; 1.23 +class SkBaseDevice; 1.24 +class SkMatrix; 1.25 +class SkPath; 1.26 +class SkRegion; 1.27 +class SkRasterClip; 1.28 +struct SkDrawProcs; 1.29 +struct SkRect; 1.30 +class SkRRect; 1.31 + 1.32 +class SkDraw { 1.33 +public: 1.34 + SkDraw(); 1.35 + SkDraw(const SkDraw& src); 1.36 + 1.37 + void drawPaint(const SkPaint&) const; 1.38 + void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[], 1.39 + const SkPaint&, bool forceUseDevice = false) const; 1.40 + void drawRect(const SkRect&, const SkPaint&) const; 1.41 + void drawRRect(const SkRRect&, const SkPaint&) const; 1.42 + /** 1.43 + * To save on mallocs, we allow a flag that tells us that srcPath is 1.44 + * mutable, so that we don't have to make copies of it as we transform it. 1.45 + * 1.46 + * If prePathMatrix is not null, it should logically be applied before any 1.47 + * stroking or other effects. If there are no effects on the paint that 1.48 + * affect the geometry/rasterization, then the pre matrix can just be 1.49 + * pre-concated with the current matrix. 1.50 + */ 1.51 + void drawPath(const SkPath& path, const SkPaint& paint, 1.52 + const SkMatrix* prePathMatrix, bool pathIsMutable) const { 1.53 + this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); 1.54 + } 1.55 + 1.56 + void drawPath(const SkPath& path, const SkPaint& paint) const { 1.57 + this->drawPath(path, paint, NULL, false, false); 1.58 + } 1.59 + 1.60 + void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; 1.61 + void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; 1.62 + void drawText(const char text[], size_t byteLength, SkScalar x, 1.63 + SkScalar y, const SkPaint& paint) const; 1.64 + void drawPosText(const char text[], size_t byteLength, 1.65 + const SkScalar pos[], SkScalar constY, 1.66 + int scalarsPerPosition, const SkPaint& paint) const; 1.67 + void drawTextOnPath(const char text[], size_t byteLength, 1.68 + const SkPath&, const SkMatrix*, const SkPaint&) const; 1.69 + void drawVertices(SkCanvas::VertexMode mode, int count, 1.70 + const SkPoint vertices[], const SkPoint textures[], 1.71 + const SkColor colors[], SkXfermode* xmode, 1.72 + const uint16_t indices[], int ptCount, 1.73 + const SkPaint& paint) const; 1.74 + 1.75 + /** 1.76 + * Overwrite the target with the path's coverage (i.e. its mask). 1.77 + * Will overwrite the entire device, so it need not be zero'd first. 1.78 + * 1.79 + * Only device A8 is supported right now. 1.80 + */ 1.81 + void drawPathCoverage(const SkPath& src, const SkPaint& paint) const { 1.82 + this->drawPath(src, paint, NULL, false, true); 1.83 + } 1.84 + 1.85 + /** Helper function that creates a mask from a path and an optional maskfilter. 1.86 + Note however, that the resulting mask will not have been actually filtered, 1.87 + that must be done afterwards (by calling filterMask). The maskfilter is provided 1.88 + solely to assist in computing the mask's bounds (if the mode requests that). 1.89 + */ 1.90 + static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 1.91 + const SkMaskFilter*, const SkMatrix* filterMatrix, 1.92 + SkMask* mask, SkMask::CreateMode mode, 1.93 + SkPaint::Style style); 1.94 + 1.95 + enum RectType { 1.96 + kHair_RectType, 1.97 + kFill_RectType, 1.98 + kStroke_RectType, 1.99 + kPath_RectType 1.100 + }; 1.101 + 1.102 + /** 1.103 + * Based on the paint's style, strokeWidth, and the matrix, classify how 1.104 + * to draw the rect. If no special-case is available, returns 1.105 + * kPath_RectType. 1.106 + * 1.107 + * Iff RectType == kStroke_RectType, then strokeSize is set to the device 1.108 + * width and height of the stroke. 1.109 + */ 1.110 + static RectType ComputeRectType(const SkPaint&, const SkMatrix&, 1.111 + SkPoint* strokeSize); 1.112 + 1.113 + static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&); 1.114 + void drawText_asPaths(const char text[], size_t byteLength, 1.115 + SkScalar x, SkScalar y, const SkPaint&) const; 1.116 + void drawPosText_asPaths(const char text[], size_t byteLength, 1.117 + const SkScalar pos[], SkScalar constY, 1.118 + int scalarsPerPosition, const SkPaint&) const; 1.119 + 1.120 +private: 1.121 + void drawDevMask(const SkMask& mask, const SkPaint&) const; 1.122 + void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; 1.123 + 1.124 + void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix, 1.125 + bool pathIsMutable, bool drawCoverage) const; 1.126 + 1.127 + /** 1.128 + * Return the current clip bounds, in local coordinates, with slop to account 1.129 + * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then 1.130 + * run through the inverse of the matrix). 1.131 + * 1.132 + * If the matrix cannot be inverted, or the current clip is empty, return 1.133 + * false and ignore bounds parameter. 1.134 + */ 1.135 + bool SK_WARN_UNUSED_RESULT 1.136 + computeConservativeLocalClipBounds(SkRect* bounds) const; 1.137 + 1.138 +public: 1.139 + const SkBitmap* fBitmap; // required 1.140 + const SkMatrix* fMatrix; // required 1.141 + const SkRegion* fClip; // DEPRECATED 1.142 + const SkRasterClip* fRC; // required 1.143 + 1.144 + const SkClipStack* fClipStack; // optional 1.145 + SkBaseDevice* fDevice; // optional 1.146 + SkBounder* fBounder; // optional 1.147 + SkDrawProcs* fProcs; // optional 1.148 + 1.149 +#ifdef SK_DEBUG 1.150 + void validate() const; 1.151 +#else 1.152 + void validate() const {} 1.153 +#endif 1.154 +}; 1.155 + 1.156 +#endif