1 /* 2 * Copyright (c) 2021-2023 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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H 16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H 17 18 #include "include/core/SkColorFilter.h" 19 #ifdef NEW_SKIA 20 #include "include/effects/SkRuntimeEffect.h" 21 #endif 22 23 #include "property/rs_properties_painter.h" 24 #include "common/rs_macros.h" 25 #include "render/rs_skia_filter.h" 26 #include "render/rs_kawase_blur.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 #ifndef USE_ROSEN_DRAWING 31 class RSB_EXPORT RSBlurFilter : public RSSkiaFilter { 32 #else 33 class RSB_EXPORT RSBlurFilter : public RSDrawingFilter { 34 #endif 35 public: 36 RSBlurFilter(float blurRadiusX, float blurRadiusY); 37 RSBlurFilter(const RSBlurFilter&) = delete; 38 RSBlurFilter operator=(const RSBlurFilter&) = delete; 39 ~RSBlurFilter() override; 40 float GetBlurRadiusX(); 41 float GetBlurRadiusY(); 42 bool IsValid() const override; 43 #ifndef USE_ROSEN_DRAWING 44 std::shared_ptr<RSSkiaFilter> Compose(const std::shared_ptr<RSSkiaFilter>& other) const override; 45 #else 46 std::shared_ptr<RSDrawingFilter> Compose(const std::shared_ptr<RSDrawingFilter>& other) const override; 47 #endif 48 std::string GetDescription() override; 49 50 std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) override; 51 std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) override; 52 std::shared_ptr<RSFilter> Multiply(float rhs) override; 53 std::shared_ptr<RSFilter> Negate() override; 54 #ifndef USE_ROSEN_DRAWING 55 void DrawImageRect( 56 SkCanvas& canvas, const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst) const override; 57 #else 58 void DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image, 59 const Drawing::Rect& src, const Drawing::Rect& dst) const override; 60 #endif 61 void SetGreyCoef(float greyCoef1, float greyCoef2, bool isGreyCoefValid) override; 62 63 bool CanSkipFrame() const override; 64 65 bool IsNearEqual( 66 const std::shared_ptr<RSFilter>& other, float threshold = std::numeric_limits<float>::epsilon()) const override; 67 bool IsNearZero(float threshold = std::numeric_limits<float>::epsilon()) const override; 68 69 private: 70 float blurRadiusX_; 71 float blurRadiusY_; 72 float greyCoef1_ = 0.f; 73 float greyCoef2_ = 0.f; 74 bool isGreyCoefValid_ = false; 75 bool useKawase_ = false; 76 }; 77 } // namespace Rosen 78 } // namespace OHOS 79 80 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H