• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RENDER_RENDER_RS_HPS_BLUR_H
17 #define RENDER_SERVICE_BASE_RENDER_RENDER_RS_HPS_BLUR_H
18 
19 #include "common/rs_color_palette.h"
20 #include "draw/canvas.h"
21 #include "effect/color_filter.h"
22 #include "effect/runtime_effect.h"
23 #include "image/image.h"
24 #include "utils/matrix.h"
25 #include "utils/rect.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class RSB_EXPORT HpsBlurFilter {
30 public:
31     ~HpsBlurFilter() = default;
32     bool ApplyHpsBlur(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
33         const Drawing::HpsBlurParameter& param, float alpha,
34         std::shared_ptr<Drawing::ColorFilter> colorFilter = nullptr,
35         const RSColor& color = RSColor()) const;
GetHpsBlurFilter()36     const static HpsBlurFilter& GetHpsBlurFilter()
37     {
38         static HpsBlurFilter filter;
39         return filter;
40     }
41 
42 private:
43     HpsBlurFilter() = default;
44     static Drawing::Matrix GetShaderTransform(const Drawing::Rect& blurRect, float scaleW = 1.0f, float scaleH = 1.0f);
45     std::shared_ptr<Drawing::RuntimeEffect> GetMixEffect() const;
46     bool SetShaderEffect(Drawing::Brush& brush, std::shared_ptr<Drawing::ShaderEffect> blurShader,
47         std::shared_ptr<Drawing::Image> imageCache) const;
48     float ApplyMaskColorFilter(Drawing::Canvas& offscreenCanvas, float alpha, const RSColor& maskColor) const;
49 };
50 } // namespace Rosen
51 } // namespace OHOS
52 #endif // RENDER_SERVICE_BASE_RENDER_RENDER_RS_HPS_BLUR_H