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 bool shouldClearFilteredCache); 46 static void DrawBackgroundEffect(RSPaintFilterCanvas* canvas, const std::shared_ptr<RSFilter>& rsFilter, 47 const std::unique_ptr<RSFilterCacheManager>& cacheManager, bool shouldClearFilteredCache, 48 Drawing::RectI& bounds, bool behindWindow = false); 49 static void DrawColorFilter(Drawing::Canvas* canvas, const std::shared_ptr<Drawing::ColorFilter>& colorFilter); 50 static void DrawLightUpEffect(Drawing::Canvas* canvas, const float lightUpEffectDegree); 51 static std::shared_ptr<Drawing::Blender> MakeLightUpEffectBlender(const float lightUpDeg); 52 static void DrawDynamicDim(Drawing::Canvas* canvas, const float dynamicDimDegree); 53 static std::shared_ptr<Drawing::ShaderEffect> MakeDynamicDimShader(float dynamicDimDeg, 54 std::shared_ptr<Drawing::ShaderEffect> imageShader); 55 static std::shared_ptr<Drawing::ShaderEffect> MakeBinarizationShader(float low, float high, float thresholdLow, 56 float thresholdHigh, std::shared_ptr<Drawing::ShaderEffect> imageShader); 57 static std::shared_ptr<Drawing::RuntimeBlenderBuilder> MakeDynamicBrightnessBuilder(); 58 static std::shared_ptr<Drawing::Blender> MakeDynamicBrightnessBlender(const RSDynamicBrightnessPara& params, 59 float ratio = 1.0f); 60 static void DrawBinarization(Drawing::Canvas* canvas, const std::optional<Vector4f>& aiInvert); 61 static void DrawPixelStretch(Drawing::Canvas* canvas, const std::optional<Vector4f>& pixelStretch, 62 const RectF& boundsRect, const bool boundsGeoValid, const Drawing::TileMode pixelStretchTileMode); 63 static Drawing::Path CreateShadowPath(const std::shared_ptr<RSPath> rsPath, 64 const std::shared_ptr<RSPath>& clipBounds, const RRect& rrect); 65 static void DrawShadow(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, const float& offsetY, 66 const float& elevation, const bool& isFilled, Color spotColor); 67 static void DrawShadowMaskFilter(Drawing::Canvas* canvas, Drawing::Path& path, const float& offsetX, 68 const float& offsetY, const float& radius, const bool& isFilled, Color spotColor); 69 static void DrawUseEffect(RSPaintFilterCanvas* canvas, UseEffectType useEffectType); 70 71 static bool IsDangerousBlendMode(int blendMode, int blendApplyType); 72 static void BeginBlender(RSPaintFilterCanvas& canvas, std::shared_ptr<Drawing::Blender> blender, 73 int blendModeApplyType, bool isDangerous); 74 static void EndBlender(RSPaintFilterCanvas& canvas, int blendModeApplyType); 75 76 static Color CalculateInvertColor(const Color& backgroundColor); 77 static Color GetInvertBackgroundColor(RSPaintFilterCanvas& canvas, bool needClipToBounds, 78 const Vector4f& boundsRect, const Color& backgroundColor); 79 RSB_EXPORT static int GetAndResetBlurCnt(); 80 static bool GetGravityMatrix(const Gravity& gravity, const Drawing::Rect& rect, const float& w, const float& h, 81 Drawing::Matrix& mat); 82 static bool RSFilterSetPixelStretch(const RSProperties& property, const std::shared_ptr<RSFilter>& filter); 83 static void RSFilterRemovePixelStretch(const std::shared_ptr<RSFilter>& filter); 84 static void DrawFilterWithDRM(Drawing::Canvas* canvas, bool isDark); 85 86 static std::shared_ptr<RSFilter> GenerateBehindWindowFilter(float radius, float saturation, float brightness, 87 RSColor maskColor); 88 private: 89 static std::shared_ptr<Drawing::ColorFilter> GenerateMaterialColorFilter(float sat, float brt); 90 static std::shared_ptr<Drawing::RuntimeEffect> binarizationShaderEffect_; 91 static std::shared_ptr<Drawing::RuntimeEffect> dynamicDimShaderEffect_; 92 static std::shared_ptr<Drawing::RuntimeEffect> dynamicBrightnessBlenderEffect_; 93 static std::shared_ptr<Drawing::RuntimeEffect> lightUpEffectBlender_; 94 inline static int g_blurCnt = 0; 95 }; 96 } // namespace Rosen 97 } // namespace OHOS 98 99 #endif // RENDER_SERVICE_BASE_DRAWABLE_RS_PROPERTY_DRAWABLE_UTILS_H 100