• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "render/rs_material_filter.h"
16 
17 #include <unordered_map>
18 
19 #include "src/core/SkOpts.h"
20 
21 #include "common/rs_common_def.h"
22 #include "pipeline/rs_paint_filter_canvas.h"
23 #include "platform/common/rs_log.h"
24 #include "property/rs_properties_painter.h"
25 #include "platform/common/rs_system_properties.h"
26 
27 #if defined(NEW_SKIA)
28 #include "include/effects/SkImageFilters.h"
29 #include "include/core/SkTileMode.h"
30 #else
31 #include "include/effects/SkBlurImageFilter.h"
32 #endif
33 
34 namespace OHOS {
35 namespace Rosen {
36 namespace {
37 constexpr float BLUR_SIGMA_SCALE = 0.57735f;
38 // style to MaterialParam map
39 static const std::unordered_map<MATERIAL_BLUR_STYLE, MaterialParam> MATERIAL_PARAM {
40     // card blur params
41     { STYLE_CARD_THIN_LIGHT,         { 23.0f,  1.05, 1.05, RSColor(0xFFFFFF33) } },
42     { STYLE_CARD_LIGHT,              { 50.0f,  1.8,  1.0,  RSColor(0xFAFAFA99) } },
43     { STYLE_CARD_THICK_LIGHT,        { 57.0f,  1.2,  1.1,  RSColor(0xFFFFFF8C) } },
44     { STYLE_CARD_THIN_DARK,          { 75.0f,  1.35, 1.0,  RSColor(0x1A1A1A6B) } },
45     { STYLE_CARD_DARK,               { 50.0f,  2.15, 1.0,  RSColor(0x1F1F1FD1) } },
46     { STYLE_CARD_THICK_DARK,         { 75.0f,  2.15, 1.0,  RSColor(0x1F1F1FD1) } },
47     // background blur params
48     { STYLE_BACKGROUND_SMALL_LIGHT,  { 23.0f,  1.05, 1.0,  RSColor(0x80808033) } },
49     { STYLE_BACKGROUND_MEDIUM_LIGHT, { 29.0f,  1.1,  1.0,  RSColor(0x80808033) } },
50     { STYLE_BACKGROUND_LARGE_LIGHT,  { 57.0f,  1.2,  1.0,  RSColor(0x80808033) } },
51     { STYLE_BACKGROUND_XLARGE_LIGHT, { 120.0f, 1.3,  1.0,  RSColor(0x6666664C) } },
52     { STYLE_BACKGROUND_SMALL_DARK,   { 15.0f,  1.1,  1.0,  RSColor(0x0D0D0D80) } },
53     { STYLE_BACKGROUND_MEDIUM_DARK,  { 55.0f,  1.15, 1.0,  RSColor(0x0D0D0D80) } },
54     { STYLE_BACKGROUND_LARGE_DARK,   { 75.0f,  1.5,  1.0,  RSColor(0x0D0D0D80) } },
55     { STYLE_BACKGROUND_XLARGE_DARK,  { 130.0f, 1.3,  1.0,  RSColor(0x0D0D0D80) } },
56 };
57 
58 static const std::unordered_map<MATERIAL_BLUR_STYLE, MaterialParam> KAWASE_MATERIAL_PARAM {
59     // card blur params
60     { STYLE_CARD_THIN_LIGHT,         { 23.0f,  1.05, 1.05, RSColor(0xFFFFFF33) } },
61     { STYLE_CARD_LIGHT,              { 50.0f,  1.8,  1.0,  RSColor(0xFAFAFA99) } },
62     { STYLE_CARD_THICK_LIGHT,        { 57.0f,  1.2,  1.1,  RSColor(0xFFFFFF8C) } },
63     { STYLE_CARD_THIN_DARK,          { 75.0f,  1.35, 1.0,  RSColor(0x1A1A1A6B) } },
64     { STYLE_CARD_DARK,               { 50.0f,  2.15, 1.0,  RSColor(0x1F1F1FD1) } },
65     { STYLE_CARD_THICK_DARK,         { 75.0f,  2.15, 1.0,  RSColor(0x1F1F1FD1) } },
66     // background blur params
67     { STYLE_BACKGROUND_SMALL_LIGHT,  { 12.0f,  1.05, 1.0,  RSColor(0x80808033) } },
68     { STYLE_BACKGROUND_MEDIUM_LIGHT, { 29.0f,  1.1,  1.0,  RSColor(0x80808033) } },
69     { STYLE_BACKGROUND_LARGE_LIGHT,  { 45.0f,  1.2,  1.0,  RSColor(0x80808033) } },
70     { STYLE_BACKGROUND_XLARGE_LIGHT, { 120.0f, 1.3,  1.0,  RSColor(0x6666664C) } },
71     { STYLE_BACKGROUND_SMALL_DARK,   { 15.0f,  1.1,  1.0,  RSColor(0x0D0D0D80) } },
72     { STYLE_BACKGROUND_MEDIUM_DARK,  { 55.0f,  1.15, 1.0,  RSColor(0x0D0D0D80) } },
73     { STYLE_BACKGROUND_LARGE_DARK,   { 75.0f,  1.5,  1.0,  RSColor(0x0D0D0D80) } },
74     { STYLE_BACKGROUND_XLARGE_DARK,  { 130.0f, 1.3,  1.0,  RSColor(0x0D0D0D80) } },
75 };
76 } // namespace
77 
78 const bool KAWASE_BLUR_ENABLED = RSSystemProperties::GetKawaseEnabled();
79 
RSMaterialFilter(int style,float dipScale,BLUR_COLOR_MODE mode,float ratio)80 RSMaterialFilter::RSMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode, float ratio)
81 #ifndef USE_ROSEN_DRAWING
82     : RSSkiaFilter(nullptr), colorMode_(mode)
83 #else
84     : RSDrawingFilter(nullptr), colorMode_(mode)
85 #endif
86 {
87     imageFilter_ = RSMaterialFilter::CreateMaterialStyle(static_cast<MATERIAL_BLUR_STYLE>(style), dipScale, ratio);
88     type_ = FilterType::MATERIAL;
89 
90     hash_ = SkOpts::hash(&type_, sizeof(type_), 0);
91     hash_ = SkOpts::hash(&style, sizeof(style), hash_);
92     hash_ = SkOpts::hash(&colorMode_, sizeof(colorMode_), hash_);
93     hash_ = SkOpts::hash(&ratio, sizeof(ratio), hash_);
94 }
95 
RSMaterialFilter(MaterialParam materialParam,BLUR_COLOR_MODE mode)96 RSMaterialFilter::RSMaterialFilter(MaterialParam materialParam, BLUR_COLOR_MODE mode)
97 #ifndef USE_ROSEN_DRAWING
98     : RSSkiaFilter(nullptr), colorMode_(mode), radius_(materialParam.radius), saturation_(materialParam.saturation),
99 #else
100     : RSDrawingFilter(nullptr), colorMode_(mode), radius_(materialParam.radius), saturation_(materialParam.saturation),
101 #endif
102       brightness_(materialParam.brightness), maskColor_(materialParam.maskColor)
103 {
104     imageFilter_ = RSMaterialFilter::CreateMaterialFilter(
105         materialParam.radius, materialParam.saturation, materialParam.brightness);
106     type_ = FilterType::MATERIAL;
107     if (colorMode_ == FASTAVERAGE) {
108         colorPickerTask_ = std::make_shared<RSColorPickerCacheTask>();
109     }
110 
111     hash_ = SkOpts::hash(&type_, sizeof(type_), 0);
112     hash_ = SkOpts::hash(&materialParam, sizeof(materialParam), hash_);
113     hash_ = SkOpts::hash(&colorMode_, sizeof(colorMode_), hash_);
114 }
115 
116 RSMaterialFilter::~RSMaterialFilter() = default;
117 
RadiusVp2Sigma(float radiusVp,float dipScale)118 float RSMaterialFilter::RadiusVp2Sigma(float radiusVp, float dipScale)
119 {
120     float radiusPx = radiusVp * dipScale;
121 #ifndef USE_ROSEN_DRAWING
122     return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + SK_ScalarHalf : 0.0f;
123 #else
124     return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f;
125 #endif
126 }
127 
GetDescription()128 std::string RSMaterialFilter::GetDescription()
129 {
130     return "RSMaterialFilter blur radius is " + std::to_string(radius_) + " sigma";
131 }
132 
133 #ifndef USE_ROSEN_DRAWING
Compose(const std::shared_ptr<RSSkiaFilter> & other) const134 std::shared_ptr<RSSkiaFilter> RSMaterialFilter::Compose(const std::shared_ptr<RSSkiaFilter>& other) const
135 #else
136 std::shared_ptr<RSDrawingFilter> RSMaterialFilter::Compose(const std::shared_ptr<RSDrawingFilter>& other) const
137 #endif
138 {
139     if (other == nullptr) {
140         return nullptr;
141     }
142     MaterialParam materialParam = {radius_, saturation_, brightness_, maskColor_};
143     std::shared_ptr<RSMaterialFilter> result = std::make_shared<RSMaterialFilter>(materialParam, colorMode_);
144 #ifndef USE_ROSEN_DRAWING
145     result->imageFilter_ = SkImageFilters::Compose(imageFilter_, other->GetImageFilter());
146 #else
147     result->imageFilter_ = Drawing::ImageFilter::CreateComposeImageFilter(imageFilter_, other->GetImageFilter());
148 #endif
149     auto otherHash = other->Hash();
150     result->hash_ = SkOpts::hash(&otherHash, sizeof(otherHash), hash_);
151     return result;
152 }
153 
154 #ifndef USE_ROSEN_DRAWING
GetColorFilter(float sat,float brightness)155 sk_sp<SkColorFilter> RSMaterialFilter::GetColorFilter(float sat, float brightness)
156 #else
157 std::shared_ptr<Drawing::ColorFilter> RSMaterialFilter::GetColorFilter(float sat, float brightness)
158 #endif
159 {
160     float normalizedDegree = brightness - 1.0;
161     const float brightnessMat[] = {
162         1.000000f, 0.000000f, 0.000000f, 0.000000f, normalizedDegree,
163         0.000000f, 1.000000f, 0.000000f, 0.000000f, normalizedDegree,
164         0.000000f, 0.000000f, 1.000000f, 0.000000f, normalizedDegree,
165         0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
166     };
167 
168 #ifndef USE_ROSEN_DRAWING
169     sk_sp<SkColorFilter> brightnessFilter = SkColorFilters::Matrix(brightnessMat); // brightness
170     SkColorMatrix cm;
171     cm.setSaturation(sat);
172     sk_sp<SkColorFilter> satFilter = SkColorFilters::Matrix(cm); // saturation
173     sk_sp<SkColorFilter> filterCompose = SkColorFilters::Compose(satFilter, brightnessFilter);
174 #else
175     Drawing::ColorMatrix cm;
176     cm.SetSaturation(sat);
177     float cmArray[Drawing::ColorMatrix::MATRIX_SIZE];
178     cm.GetArray(cmArray);
179     std::shared_ptr<Drawing::ColorFilter> filterCompose =
180         Drawing::ColorFilter::CreateComposeColorFilter(cmArray, brightnessMat);
181 #endif
182     return filterCompose;
183 }
184 
185 #ifndef USE_ROSEN_DRAWING
CreateMaterialFilter(float radius,float sat,float brightness)186 sk_sp<SkImageFilter> RSMaterialFilter::CreateMaterialFilter(float radius, float sat, float brightness)
187 {
188     colorFilter_ = GetColorFilter(sat, brightness);
189 #if defined(NEW_SKIA)
190     sk_sp<SkImageFilter> blurFilter = SkImageFilters::Blur(radius, radius, SkTileMode::kClamp, nullptr); // blur
191 #else
192     sk_sp<SkImageFilter> blurFilter = SkBlurImageFilter::Make(radius, radius, nullptr, nullptr,
193         SkBlurImageFilter::kClamp_TileMode); // blur
194 #endif
195 
196     return SkImageFilters::ColorFilter(colorFilter_, blurFilter);
197 }
198 #else
CreateMaterialFilter(float radius,float sat,float brightness)199 std::shared_ptr<Drawing::ImageFilter> RSMaterialFilter::CreateMaterialFilter(float radius, float sat, float brightness)
200 {
201     colorFilter_ = GetColorFilter(sat, brightness);
202     return Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter_, radius, radius);
203 }
204 #endif
205 
206 #ifndef USE_ROSEN_DRAWING
CreateMaterialStyle(MATERIAL_BLUR_STYLE style,float dipScale,float ratio)207 sk_sp<SkImageFilter> RSMaterialFilter::CreateMaterialStyle(MATERIAL_BLUR_STYLE style, float dipScale, float ratio)
208 #else
209 std::shared_ptr<Drawing::ImageFilter> RSMaterialFilter::CreateMaterialStyle(
210     MATERIAL_BLUR_STYLE style, float dipScale, float ratio)
211 #endif
212 {
213     const auto& materialParams = KAWASE_BLUR_ENABLED ? KAWASE_MATERIAL_PARAM : MATERIAL_PARAM;
214     if (materialParams.find(style) != materialParams.end()) {
215         const auto& materialParam = materialParams.at(style);
216         maskColor_ = RSColor(materialParam.maskColor.AsRgbaInt());
217         maskColor_.MultiplyAlpha(ratio);
218         radius_ = RSMaterialFilter::RadiusVp2Sigma(materialParam.radius, dipScale) * ratio;
219         saturation_ = (materialParam.saturation - 1) * ratio + 1.0;
220         brightness_ = (materialParam.brightness - 1) * ratio + 1.0;
221         return RSMaterialFilter::CreateMaterialFilter(radius_, saturation_, brightness_);
222     }
223     return nullptr;
224 }
225 
226 #ifndef USE_ROSEN_DRAWING
PreProcess(sk_sp<SkImage> imageSnapshot)227 void RSMaterialFilter::PreProcess(sk_sp<SkImage> imageSnapshot)
228 {
229     if (colorMode_ == AVERAGE && imageSnapshot != nullptr) {
230         // update maskColor while persevere alpha
231         SkColor colorPicker = RSPropertiesPainter::CalcAverageColor(imageSnapshot);
232         maskColor_ = RSColor(
233             SkColorGetR(colorPicker), SkColorGetG(colorPicker), SkColorGetB(colorPicker), maskColor_.GetAlpha());
234     } else if (colorMode_ == FASTAVERAGE && RSColorPickerCacheTask::ColorPickerPartialEnabled
235         && imageSnapshot != nullptr) {
236         RSColor color;
237         if (colorPickerTask_->GetWaitRelease()) {
238             if (colorPickerTask_->GetColor(color) && colorPickerTask_->GetFirstGetColorFinished()) {
239                 maskColor_ = RSColor(color.GetRed(), color.GetGreen(), color.GetBlue(), maskColor_.GetAlpha());
240             }
241             return;
242         }
243         if (RSColorPickerCacheTask::PostPartialColorPickerTask(colorPickerTask_, imageSnapshot)) {
244             if (colorPickerTask_->GetColor(color)) {
245                 maskColor_ = RSColor(color.GetRed(), color.GetGreen(), color.GetBlue(), maskColor_.GetAlpha());
246             }
247             colorPickerTask_->SetStatus(CacheProcessStatus::WAITING);
248         }
249     }
250 }
251 #else
PreProcess(std::shared_ptr<Drawing::Image> imageSnapshot)252 void RSMaterialFilter::PreProcess(std::shared_ptr<Drawing::Image> imageSnapshot)
253 {
254     if (colorMode_ == AVERAGE && imageSnapshot != nullptr) {
255         // update maskColor while persevere alpha
256         auto colorPicker = RSPropertiesPainter::CalcAverageColor(imageSnapshot);
257         maskColor_ = RSColor(Drawing::Color::ColorQuadGetR(colorPicker), Drawing::Color::ColorQuadGetG(colorPicker),
258             Drawing::Color::ColorQuadGetB(colorPicker), maskColor_.GetAlpha());
259     } else if (colorMode_ == FASTAVERAGE && RSColorPickerCacheTask::ColorPickerPartialEnabled &&
260         imageSnapshot != nullptr) {
261         RSColor color;
262         if (colorPickerTask_->GetWaitRelease()) {
263             if (colorPickerTask_->GetColor(color) && colorPickerTask_->GetFirstGetColorFinished()) {
264                 maskColor_ = RSColor(color.GetRed(), color.GetGreen(), color.GetBlue(), maskColor_.GetAlpha());
265             }
266             return;
267         }
268         if (RSColorPickerCacheTask::PostPartialColorPickerTask(colorPickerTask_, imageSnapshot)) {
269             if (colorPickerTask_->GetColor(color)) {
270                 maskColor_ = RSColor(color.GetRed(), color.GetGreen(), color.GetBlue(), maskColor_.GetAlpha());
271             }
272             colorPickerTask_->SetStatus(CacheProcessStatus::WAITING);
273         }
274     }
275 }
276 #endif
277 
PostProcess(RSPaintFilterCanvas & canvas)278 void RSMaterialFilter::PostProcess(RSPaintFilterCanvas& canvas)
279 {
280 #ifndef USE_ROSEN_DRAWING
281     SkPaint paint;
282     paint.setColor(maskColor_.AsArgbInt());
283     canvas.drawPaint(paint);
284 #else
285     Drawing::Brush brush;
286     brush.SetColor(maskColor_.AsArgbInt());
287     canvas.DrawBackground(brush);
288 #endif
289 }
290 
TransformFilter(float fraction) const291 std::shared_ptr<RSFilter> RSMaterialFilter::TransformFilter(float fraction) const
292 {
293     MaterialParam materialParam;
294     materialParam.radius = radius_ * fraction;
295     materialParam.saturation = (saturation_ - 1) * fraction + 1.0;
296     materialParam.brightness = (brightness_ - 1) * fraction + 1.0;
297     materialParam.maskColor = RSColor(maskColor_.GetRed(), maskColor_.GetGreen(),
298         maskColor_.GetBlue(), maskColor_.GetAlpha() * fraction);
299     return std::make_shared<RSMaterialFilter>(materialParam, colorMode_);
300 }
301 
IsValid() const302 bool RSMaterialFilter::IsValid() const
303 {
304     constexpr float epsilon = 0.999f;
305     return radius_ > epsilon;
306 }
307 
Add(const std::shared_ptr<RSFilter> & rhs)308 std::shared_ptr<RSFilter> RSMaterialFilter::Add(const std::shared_ptr<RSFilter>& rhs)
309 {
310     if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::MATERIAL)) {
311         return shared_from_this();
312     }
313     auto materialR = std::static_pointer_cast<RSMaterialFilter>(rhs);
314 
315     MaterialParam materialParam;
316     materialParam.radius = radius_ + materialR->radius_;
317     materialParam.saturation = saturation_ + materialR->saturation_;
318     materialParam.brightness = brightness_ + materialR->brightness_;
319     materialParam.maskColor = maskColor_ + materialR->maskColor_;
320     return std::make_shared<RSMaterialFilter>(materialParam, materialR->colorMode_);
321 }
322 
Sub(const std::shared_ptr<RSFilter> & rhs)323 std::shared_ptr<RSFilter> RSMaterialFilter::Sub(const std::shared_ptr<RSFilter>& rhs)
324 {
325     if ((rhs == nullptr) || (rhs->GetFilterType() != FilterType::MATERIAL)) {
326         return shared_from_this();
327     }
328     auto materialR = std::static_pointer_cast<RSMaterialFilter>(rhs);
329     MaterialParam materialParam;
330     materialParam.radius = radius_ - materialR->radius_;
331     materialParam.saturation = saturation_ - materialR->saturation_;
332     materialParam.brightness = brightness_ - materialR->brightness_;
333     materialParam.maskColor = maskColor_ - materialR->maskColor_;
334     return std::make_shared<RSMaterialFilter>(materialParam, materialR->colorMode_);
335 }
336 
Multiply(float rhs)337 std::shared_ptr<RSFilter> RSMaterialFilter::Multiply(float rhs)
338 {
339     MaterialParam materialParam;
340     materialParam.radius = radius_ * rhs;
341     materialParam.saturation = saturation_ * rhs;
342     materialParam.brightness = brightness_ * rhs;
343     materialParam.maskColor = maskColor_ * rhs;
344     return std::make_shared<RSMaterialFilter>(materialParam, colorMode_);
345 }
346 
Negate()347 std::shared_ptr<RSFilter> RSMaterialFilter::Negate()
348 {
349     MaterialParam materialParam;
350     materialParam.radius = -radius_;
351     materialParam.saturation = -saturation_;
352     materialParam.brightness = -brightness_;
353     materialParam.maskColor = RSColor(0x00000000) - maskColor_;
354     return std::make_shared<RSMaterialFilter>(materialParam, colorMode_);
355 }
356 
357 #ifndef USE_ROSEN_DRAWING
DrawImageRect(SkCanvas & canvas,const sk_sp<SkImage> & image,const SkRect & src,const SkRect & dst) const358 void RSMaterialFilter::DrawImageRect(
359     SkCanvas& canvas, const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst) const
360 #else
361 void RSMaterialFilter::DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
362     const Drawing::Rect& src, const Drawing::Rect& dst) const
363 #endif
364 {
365 #ifndef USE_ROSEN_DRAWING
366     auto paint = GetPaint();
367 #ifdef NEW_SKIA
368     sk_sp<SkImage> greyImage = image;
369     if (isGreyCoefValid_) {
370         greyImage = RSPropertiesPainter::DrawGreyAdjustment(canvas, image, greyCoef1_, greyCoef2_);
371     }
372     if (greyImage == nullptr) {
373         greyImage = image;
374     }
375     // if kawase blur failed, use gauss blur
376     KawaseParameter param = KawaseParameter(src, dst, radius_, colorFilter_, paint.getAlphaf());
377     if (KAWASE_BLUR_ENABLED && KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, greyImage, param)) {
378         return;
379     }
380     canvas.drawImageRect(greyImage.get(), src, dst, SkSamplingOptions(), &paint, SkCanvas::kStrict_SrcRectConstraint);
381 #else
382     canvas.drawImageRect(greyImage.get(), src, dst, &paint);
383 #endif
384 #else
385     auto brush = GetBrush();
386     // if kawase blur failed, use gauss blur
387     std::shared_ptr<Drawing::Image> greyImage = image;
388     if (isGreyCoefValid_) {
389         greyImage = RSPropertiesPainter::DrawGreyAdjustment(canvas, image, greyCoef1_, greyCoef2_);
390     }
391     if (greyImage == nullptr) {
392         greyImage = image;
393     }
394     KawaseParameter param = KawaseParameter(src, dst, radius_, colorFilter_, brush.GetColor().GetAlphaF());
395     if (KAWASE_BLUR_ENABLED && KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, greyImage, param)) {
396         return;
397     }
398     canvas.AttachBrush(brush);
399     canvas.DrawImageRect(*greyImage, src, dst, Drawing::SamplingOptions());
400     canvas.DetachBrush();
401 #endif
402 }
403 
SetGreyCoef(float greyCoef1,float greyCoef2,bool isGreyCoefValid)404 void RSMaterialFilter::SetGreyCoef(float greyCoef1, float greyCoef2, bool isGreyCoefValid)
405 {
406     if (!isGreyCoefValid) {
407         isGreyCoefValid_ = isGreyCoefValid;
408         return;
409     }
410     greyCoef1_ = greyCoef1;
411     greyCoef2_ = greyCoef2;
412     isGreyCoefValid_ = isGreyCoefValid;
413 }
414 
GetRadius() const415 float RSMaterialFilter::GetRadius() const
416 {
417     return radius_;
418 }
419 
CanSkipFrame() const420 bool RSMaterialFilter::CanSkipFrame() const
421 {
422     constexpr float HEAVY_BLUR_THRESHOLD = 25.0f;
423     return radius_ > HEAVY_BLUR_THRESHOLD;
424 };
425 
IsNearEqual(const std::shared_ptr<RSFilter> & other,float threshold) const426 bool RSMaterialFilter::IsNearEqual(const std::shared_ptr<RSFilter>& other, float threshold) const
427 {
428     auto otherMaterialFilter = std::static_pointer_cast<RSMaterialFilter>(other);
429     if (otherMaterialFilter == nullptr) {
430         ROSEN_LOGE("RSMaterialFilter::IsNearEqual: the types of filters are different.");
431         return true;
432     }
433     return ROSEN_EQ(radius_, otherMaterialFilter->radius_, 1.0f) &&
434            ROSEN_EQ(saturation_, otherMaterialFilter->saturation_, threshold) &&
435            ROSEN_EQ(brightness_, otherMaterialFilter->brightness_, threshold) &&
436            maskColor_.IsNearEqual(otherMaterialFilter->maskColor_, 0);
437 }
438 
IsNearZero(float threshold) const439 bool RSMaterialFilter::IsNearZero(float threshold) const
440 {
441     return ROSEN_EQ(radius_, 0.0f, threshold);
442 }
443 
GetColorPickerCacheTask() const444 const std::shared_ptr<RSColorPickerCacheTask>& RSMaterialFilter::GetColorPickerCacheTask() const
445 {
446     return colorPickerTask_;
447 }
448 
ReleaseColorPickerFilter()449 void RSMaterialFilter::ReleaseColorPickerFilter()
450 {
451     if (colorPickerTask_ == nullptr) {
452         return;
453     }
454     colorPickerTask_->ReleaseColorPicker();
455 }
456 
457 } // namespace Rosen
458 } // namespace OHOS
459