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 24 /* 25 Feature: 26 NodeGroup recommendation:ROUND_STATIC_CAST_INT 27 HardwareComposer recommendation: clip hole-ROUND_IN, draw-ROUND_OUT 28 RSUniRenderComposerAdapter: ROUND_IN 29 Dirty Region and Occlusion: 30 Dirty Region: ROUND_OUT 31 Occlusion: ROUND_IN 32 Roration and Drag: ROUND_OFF 33 SnapShot and Draw: 34 SnapShot:ROUND_IN 35 Draw:ROUND_OUT 36 Default:ROUND_BUTT(ROUND_OUT) 37 */ 38 enum class RoundingStrategyType : uint8_t { 39 ROUND_IN = 0, 40 ROUND_OUT, 41 ROUND_OFF, 42 ROUND_STATIC_CAST_INT, 43 ROUND_BUTT, 44 }; 45 46 class RSPropertyDrawableUtils { 47 public: 48 static Drawing::RoundRect RRect2DrawingRRect(const RRect& rr); 49 static Drawing::Rect Rect2DrawingRect(const RectF& r); 50 static RRect GetRRectForDrawingBorder( 51 const RSProperties& properties, const std::shared_ptr<RSBorder>& border, const bool& isOutline); 52 static RRect GetInnerRRectForDrawingBorder( 53 const RSProperties& properties, const std::shared_ptr<RSBorder>& border, const bool& isOutline); 54 static Color GetColorForShadowSyn(Drawing::Canvas* canvas, Drawing::Path& path, const Color& color, 55 const int& colorStrategy); 56 static std::shared_ptr<Drawing::Image> GetShadowRegionImage(Drawing::Canvas* canvas, 57 Drawing::Path& drPath, Drawing::Matrix& matrix); 58 static bool PickColorSyn(Drawing::Canvas* canvas, Drawing::Path& drPath, Drawing::Matrix& matrix, 59 RSColor& colorPicked, const int& colorStrategy); 60 static std::shared_ptr<Drawing::Image> GpuScaleImage(Drawing::Canvas* canvas, 61 const std::shared_ptr<Drawing::Image> image); 62 static void GetDarkColor(RSColor& color); 63 static void BeginForegroundFilter(RSPaintFilterCanvas& canvas, const RectF& bounds); 64 static void DrawForegroundFilter(RSPaintFilterCanvas& canvas, const std::shared_ptr<RSFilter>& rsFilter); 65 static void DrawFilter(Drawing::Canvas* canvas, const std::shared_ptr<RSFilter>& rsFilter, 66 const std::unique_ptr<RSFilterCacheManager>& cacheManager, NodeId id, const bool isForegroundFilter); 67 static void DrawBackgroundEffect(RSPaintFilterCanvas* canvas, const std::shared_ptr<RSFilter>& rsFilter, 68 const std::unique_ptr<RSFilterCacheManager>& cacheManager, 69 Drawing::RectI& bounds, bool behindWindow = false); 70 static void DrawColorFilter(Drawing::Canvas* canvas, const std::shared_ptr<Drawing::ColorFilter>& colorFilter); 71 static void DrawLightUpEffect(Drawing::Canvas* canvas, const float lightUpEffectDegree); 72 static std::shared_ptr<Drawing::ShaderEffect> MakeLightUpShader(float lightUpDeg, 73 std::shared_ptr<Drawing::ShaderEffect> imageShader); 74 static void DrawDynamicDim(Drawing::Canvas* canvas, const float dynamicDimDegree); 75 static std::shared_ptr<Drawing::ShaderEffect> MakeDynamicDimShader(float dynamicDimDeg, 76 std::shared_ptr<Drawing::ShaderEffect> imageShader); 77 static std::shared_ptr<Drawing::ShaderEffect> MakeBinarizationShader(float low, float high, float thresholdLow, 78 float thresholdHigh, std::shared_ptr<Drawing::ShaderEffect> imageShader); 79 static std::shared_ptr<Drawing::RuntimeBlenderBuilder> MakeDynamicBrightnessBuilder(); 80 static std::shared_ptr<Drawing::RuntimeBlenderBuilder> MakeDynamicBrightnessLinearBuilder(); 81 static std::shared_ptr<Drawing::Blender> MakeDynamicBrightnessBlender(const RSDynamicBrightnessPara& params); 82 static std::shared_ptr<Drawing::Blender> MakeShadowBlender(const RSShadowBlenderPara& params); 83 static void DrawBinarization(Drawing::Canvas* canvas, const std::optional<Vector4f>& aiInvert); 84 static void DrawPixelStretch(Drawing::Canvas* canvas, const std::optional<Vector4f>& pixelStretch, 85 const RectF& boundsRect, const bool boundsGeoValid, const Drawing::TileMode pixelStretchTileMode); 86 static Drawing::Path CreateShadowPath(const std::shared_ptr<RSPath> rsPath, 87 const std::shared_ptr<RSPath>& clipBounds, const RRect& rrect); 88 static void DrawShadow(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, const float& offsetY, 89 const float& elevation, const bool& isFilled, Color spotColor); 90 static void DrawShadowMaskFilter(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, 91 const float& offsetY, const float& radius, const bool& isFilled, Color spotColor); 92 static void DrawUseEffect(RSPaintFilterCanvas* canvas, UseEffectType useEffectType); 93 94 static bool IsDangerousBlendMode(int blendMode, int blendApplyType); 95 static void BeginBlender(RSPaintFilterCanvas& canvas, std::shared_ptr<Drawing::Blender> blender, 96 int blendModeApplyType, bool isDangerous); 97 static void EndBlender(RSPaintFilterCanvas& canvas, int blendModeApplyType); 98 99 static Color CalculateInvertColor(const Color& backgroundColor); 100 static Color GetInvertBackgroundColor(RSPaintFilterCanvas& canvas, bool needClipToBounds, 101 const Vector4f& boundsRect, const Color& backgroundColor); 102 RSB_EXPORT static int GetAndResetBlurCnt(); 103 static bool GetGravityMatrix(const Gravity& gravity, const Drawing::Rect& rect, const float& w, const float& h, 104 Drawing::Matrix& mat); 105 static bool RSFilterSetPixelStretch(const RSProperties& property, const std::shared_ptr<RSFilter>& filter); 106 static void RSFilterRemovePixelStretch(const std::shared_ptr<RSFilter>& filter); 107 static void DrawFilterWithDRM(Drawing::Canvas* canvas, bool isDark); 108 109 static std::shared_ptr<RSFilter> GenerateBehindWindowFilter(float radius, float saturation, float brightness, 110 RSColor maskColor); 111 112 static bool IsBlurFilterType(const RSFilter::FilterType& filterType); 113 114 static float GetBlurFilterRadius(const std::shared_ptr<RSFilter>& rsFilter); 115 116 RSB_EXPORT static Drawing::RectI GetRectByStrategy( 117 const Drawing::Rect& rect, RoundingStrategyType roundingStrategy); 118 RSB_EXPORT static Drawing::RectI GetAbsRectByStrategy(const Drawing::Surface* surface, 119 const Drawing::Matrix& totalMatrix, const Drawing::Rect& relativeRect, RoundingStrategyType roundingStrategy); 120 RSB_EXPORT static std::tuple<Drawing::RectI, Drawing::RectI> GetAbsRectByStrategyForImage( 121 const Drawing::Surface* surface, const Drawing::Matrix& totalMatrix, const Drawing::Rect& relativeRect); 122 123 private: 124 static std::shared_ptr<Drawing::ColorFilter> GenerateMaterialColorFilter(float sat, float brt); 125 static std::shared_ptr<Drawing::RuntimeEffect> binarizationShaderEffect_; 126 static std::shared_ptr<Drawing::RuntimeEffect> dynamicDimShaderEffect_; 127 static std::shared_ptr<Drawing::RuntimeEffect> dynamicBrightnessBlenderEffect_; 128 static std::shared_ptr<Drawing::RuntimeEffect> dynamicBrightnessLinearBlenderEffect_; 129 static std::shared_ptr<Drawing::RuntimeEffect> lightUpShaderEffect_; 130 static std::shared_ptr<Drawing::RuntimeEffect> shadowBlenderEffect_; 131 inline static std::atomic<int> g_blurCnt = 0; 132 }; 133 } // namespace Rosen 134 } // namespace OHOS 135 136 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_UTILS_H 137