1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_UTILS_H 17 #define RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_UTILS_H 18 19 #include "property/rs_properties.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 class RSPropertyDrawableUtils { 24 public: 25 static Drawing::RoundRect RRect2DrawingRRect(const RRect& rr); 26 static Drawing::Rect Rect2DrawingRect(const RectF& r); 27 static RRect GetRRectForDrawingBorder( 28 const RSProperties& properties, const std::shared_ptr<RSBorder>& border, const bool& isOutline); 29 static RRect GetInnerRRectForDrawingBorder( 30 const RSProperties& properties, const std::shared_ptr<RSBorder>& border, const bool& isOutline); 31 static Color GetColorForShadowSyn(Drawing::Canvas* canvas, Drawing::Path& path, const Color& color, 32 const int& colorStrategy); 33 static std::shared_ptr<Drawing::Image> GetShadowRegionImage(Drawing::Canvas* canvas, 34 Drawing::Path& drPath, Drawing::Matrix& matrix); 35 static bool PickColorSyn(Drawing::Canvas* canvas, Drawing::Path& drPath, Drawing::Matrix& matrix, 36 RSColor& colorPicked, const int& colorStrategy); 37 static std::shared_ptr<Drawing::Image> GpuScaleImage(Drawing::Canvas* canvas, 38 const std::shared_ptr<Drawing::Image> image); 39 static void GetDarkColor(RSColor& color); 40 static void CeilMatrixTrans(Drawing::Canvas* canvas); 41 static void BeginForegroundFilter(RSPaintFilterCanvas& canvas, const RectF& bounds); 42 static void DrawForegroundFilter(RSPaintFilterCanvas& canvas, const std::shared_ptr<RSFilter>& rsFilter); 43 static void DrawFilter(Drawing::Canvas* canvas, const std::shared_ptr<RSFilter>& rsFilter, 44 const std::unique_ptr<RSFilterCacheManager>& cacheManager, const bool isForegroundFilter); 45 static void DrawBackgroundEffect(RSPaintFilterCanvas* canvas, const std::shared_ptr<RSFilter>& rsFilter, 46 const std::unique_ptr<RSFilterCacheManager>& cacheManager, 47 Drawing::RectI& bounds, bool behindWindow = false); 48 static void DrawColorFilter(Drawing::Canvas* canvas, const std::shared_ptr<Drawing::ColorFilter>& colorFilter); 49 static void DrawLightUpEffect(Drawing::Canvas* canvas, const float lightUpEffectDegree); 50 static std::shared_ptr<Drawing::Blender> MakeLightUpEffectBlender(const float lightUpDeg); 51 static void DrawDynamicDim(Drawing::Canvas* canvas, const float dynamicDimDegree); 52 static std::shared_ptr<Drawing::ShaderEffect> MakeDynamicDimShader(float dynamicDimDeg, 53 std::shared_ptr<Drawing::ShaderEffect> imageShader); 54 static std::shared_ptr<Drawing::ShaderEffect> MakeBinarizationShader(float low, float high, float thresholdLow, 55 float thresholdHigh, std::shared_ptr<Drawing::ShaderEffect> imageShader); 56 static std::shared_ptr<Drawing::RuntimeBlenderBuilder> MakeDynamicBrightnessBuilder(); 57 static std::shared_ptr<Drawing::Blender> MakeDynamicBrightnessBlender(const RSDynamicBrightnessPara& params, 58 float ratio = 1.0f); 59 static void DrawBinarization(Drawing::Canvas* canvas, const std::optional<Vector4f>& aiInvert); 60 static void DrawPixelStretch(Drawing::Canvas* canvas, const std::optional<Vector4f>& pixelStretch, 61 const RectF& boundsRect, const bool boundsGeoValid, const Drawing::TileMode pixelStretchTileMode); 62 static Drawing::Path CreateShadowPath(const std::shared_ptr<RSPath> rsPath, 63 const std::shared_ptr<RSPath>& clipBounds, const RRect& rrect); 64 static void DrawShadow(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, const float& offsetY, 65 const float& elevation, const bool& isFilled, Color spotColor); 66 static void DrawShadowMaskFilter(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, 67 const float& offsetY, const float& radius, const bool& isFilled, Color spotColor); 68 static void DrawUseEffect(RSPaintFilterCanvas* canvas, UseEffectType useEffectType); 69 70 static bool IsDangerousBlendMode(int blendMode, int blendApplyType); 71 static void BeginBlender(RSPaintFilterCanvas& canvas, std::shared_ptr<Drawing::Blender> blender, 72 int blendModeApplyType, bool isDangerous); 73 static void EndBlender(RSPaintFilterCanvas& canvas, int blendModeApplyType); 74 75 static Color CalculateInvertColor(const Color& backgroundColor); 76 static Color GetInvertBackgroundColor(RSPaintFilterCanvas& canvas, bool needClipToBounds, 77 const Vector4f& boundsRect, const Color& backgroundColor); 78 RSB_EXPORT static int GetAndResetBlurCnt(); 79 static bool GetGravityMatrix(const Gravity& gravity, const Drawing::Rect& rect, const float& w, const float& h, 80 Drawing::Matrix& mat); 81 static bool RSFilterSetPixelStretch(const RSProperties& property, const std::shared_ptr<RSFilter>& filter); 82 static void RSFilterRemovePixelStretch(const std::shared_ptr<RSFilter>& filter); 83 static void DrawFilterWithDRM(Drawing::Canvas* canvas, bool isDark); 84 85 static std::shared_ptr<RSFilter> GenerateBehindWindowFilter(float radius, float saturation, float brightness, 86 RSColor maskColor); 87 88 static bool IsBlurFilterType(const RSFilter::FilterType& filterType); 89 90 static float GetBlurFilterRadius(const std::shared_ptr<RSFilter>& rsFilter); 91 private: 92 static std::shared_ptr<Drawing::ColorFilter> GenerateMaterialColorFilter(float sat, float brt); 93 static std::shared_ptr<Drawing::RuntimeEffect> binarizationShaderEffect_; 94 static std::shared_ptr<Drawing::RuntimeEffect> dynamicDimShaderEffect_; 95 static std::shared_ptr<Drawing::RuntimeEffect> dynamicBrightnessBlenderEffect_; 96 static std::shared_ptr<Drawing::RuntimeEffect> lightUpEffectBlender_; 97 inline static int g_blurCnt = 0; 98 }; 99 } // namespace Rosen 100 } // namespace OHOS 101 102 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_UTILS_H 103