1 /* 2 * Copyright 2017 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 SkAndroidFrameworkUtils_DEFINED 9 #define SkAndroidFrameworkUtils_DEFINED 10 11 #include "include/core/SkColor.h" 12 #include "include/core/SkPoint.h" 13 #include "include/core/SkRefCnt.h" 14 #include "include/core/SkTileMode.h" 15 16 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 17 18 class SkCanvas; 19 struct SkIRect; 20 struct SkRect; 21 class SkSurface; 22 class SkShader; 23 24 /** 25 * SkAndroidFrameworkUtils expose private APIs used only by Android framework. 26 */ 27 class SkAndroidFrameworkUtils { 28 public: 29 30 #if defined(SK_GANESH) 31 /** 32 * clipWithStencil draws the current clip into a stencil buffer with reference value and mask 33 * set to 0x1. This function works only on a GPU canvas. 34 * 35 * @param canvas A GPU canvas that has a non-empty clip. 36 * 37 * @return true on success or false if clip is empty or not a GPU canvas. 38 */ 39 static bool clipWithStencil(SkCanvas* canvas); 40 #endif //defined(SK_GANESH) 41 42 static void SafetyNetLog(const char*); 43 44 static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas); 45 46 static int SaveBehind(SkCanvas* canvas, const SkRect* subset); 47 48 // Operating within the canvas' clip stack, this resets the geometry of the clip to be wide 49 // open modula any device clip restriction that was set outside of the clip stack. 50 static void ResetClip(SkCanvas* canvas); 51 52 /** 53 * Unrolls a chain of nested SkPaintFilterCanvas to return the base wrapped canvas. 54 * 55 * @param canvas A SkPaintFilterCanvas or any other SkCanvas subclass. 56 * 57 * @return SkCanvas that was found in the innermost SkPaintFilterCanvas. 58 */ 59 static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); 60 61 /** 62 * If the shader represents a linear gradient ShaderAsALinearGradient 63 * returns true and if info is not null, ShaderAsALinearGradient populates 64 * info with the parameters for the gradient. fColorCount is both an input 65 * and output parameter. On input, it indicates how many entries in 66 * fColors and fColorOffsets can be used, if they are not nullptr. After 67 * asAGradient has run, fColorCount indicates how many color-offset pairs 68 * there are in the gradient. fColorOffsets specifies where on the range of 69 * 0 to 1 to transition to the given color. fPoints represent the endpoints 70 * of the gradient. 71 */ 72 struct LinearGradientInfo { 73 int fColorCount = 0; //!< In-out parameter, specifies passed size 74 // of fColors/fColorOffsets on input, and 75 // actual number of colors/offsets on 76 // output. 77 SkColor* fColors = nullptr; //!< The colors in the gradient. 78 SkScalar* fColorOffsets = nullptr; //!< The unit offset for color transitions. 79 SkPoint fPoints[2]; //!< Type specific, see above. 80 SkTileMode fTileMode; 81 uint32_t fGradientFlags = 0; //!< see SkGradientShader::Flags 82 }; 83 84 static bool ShaderAsALinearGradient(SkShader* shader, LinearGradientInfo*); 85 }; 86 87 #endif // SK_BUILD_FOR_ANDROID_ANDROID 88 89 #endif // SkAndroidFrameworkUtils_DEFINED 90