1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkPaintPriv_DEFINED 9 #define SkPaintPriv_DEFINED 10 11 #include "SkImageInfo.h" 12 #include "SkPaint.h" 13 #include "SkMatrix.h" 14 15 class SkBitmap; 16 class SkImage; 17 18 class SkPaintPriv { 19 public: 20 enum ShaderOverrideOpacity { 21 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image) 22 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque 23 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque 24 }; 25 26 /** 27 * Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels. 28 * 29 * Note: returns conservative true, meaning it may return false even though the paint might 30 * in fact overwrite its pixels. 31 */ 32 static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity); 33 Overwrites(const SkPaint & paint)34 static bool Overwrites(const SkPaint& paint) { 35 return Overwrites(&paint, kNone_ShaderOverrideOpacity); 36 } 37 38 /** 39 * Returns true if drawing this bitmap with this paint (or nullptr) will ovewrite all affected 40 * pixels. 41 */ 42 static bool Overwrites(const SkBitmap&, const SkPaint* paint); 43 44 /** 45 * Returns true if drawing this image with this paint (or nullptr) will ovewrite all affected 46 * pixels. 47 */ 48 static bool Overwrites(const SkImage*, const SkPaint* paint); 49 50 static void ScaleFontMetrics(SkPaint::FontMetrics*, SkScalar); 51 52 /** 53 * Return a matrix that applies the paint's text values: size, scale, skew 54 */ MakeTextMatrix(SkMatrix * matrix,SkScalar size,SkScalar scaleX,SkScalar skewX)55 static void MakeTextMatrix(SkMatrix* matrix, SkScalar size, SkScalar scaleX, SkScalar skewX) { 56 matrix->setScale(size * scaleX, size); 57 if (skewX) { 58 matrix->postSkew(skewX, 0); 59 } 60 } 61 MakeTextMatrix(SkMatrix * matrix,const SkPaint & paint)62 static void MakeTextMatrix(SkMatrix* matrix, const SkPaint& paint) { 63 MakeTextMatrix(matrix, paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX()); 64 } 65 66 static bool ShouldDither(const SkPaint&, SkColorType); 67 68 // returns 0 if buffer is invalid for specified encoding 69 static int ValidCountText(const void* text, size_t length, SkPaint::TextEncoding); 70 }; 71 72 #endif 73