1 /* 2 * Copyright (c) 2021 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_MATERIAL_FILTER_H 16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_MATERIAL_FILTER_H 17 18 #include "render/rs_skia_filter.h" 19 20 #include "include/core/SkColorFilter.h" 21 #include "include/core/SkColor.h" 22 #include "include/effects/SkColorMatrix.h" 23 #include "include/effects/SkImageFilters.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 enum MATERIAL_BLUR_STYLE : int { 28 // card blur style 29 STYLE_CARD_THIN_LIGHT = 1, 30 STYLE_CARD_LIGHT = 2, 31 STYLE_CARD_THICK_LIGHT = 3, 32 STYLE_CARD_THIN_DARK = 4, 33 STYLE_CARD_DARK = 5, 34 STYLE_CARD_THICK_DARK = 6, 35 36 // background blur style 37 STYLE_BACKGROUND_SMALL_LIGHT = 101, 38 STYLE_BACKGROUND_MEDIUM_LIGHT = 102, 39 STYLE_BACKGROUND_LARGE_LIGHT = 103, 40 STYLE_BACKGROUND_XLARGE_LIGHT = 104, 41 STYLE_BACKGROUND_SMALL_DARK = 105, 42 STYLE_BACKGROUND_MEDIUM_DARK = 106, 43 STYLE_BACKGROUND_LARGE_DARK = 107, 44 STYLE_BACKGROUND_XLARGE_DARK = 108 45 }; 46 47 class RSMaterialFilter : public RSSkiaFilter { 48 public: 49 RSMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode); 50 ~RSMaterialFilter() override; 51 void PreProcess(sk_sp<SkImage> image) override; 52 void PostProcess(RSPaintFilterCanvas& canvas) override; 53 54 std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) override; 55 std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) override; 56 std::shared_ptr<RSFilter> Multiply(float rhs) override; 57 std::shared_ptr<RSFilter> Negate() override; 58 private: 59 float dipScale_; 60 MATERIAL_BLUR_STYLE style_; 61 BLUR_COLOR_MODE colorMode_; 62 SkColor maskColor_; 63 64 sk_sp<SkImageFilter> CreateMaterialStyle(MATERIAL_BLUR_STYLE style, float dipScale); 65 sk_sp<SkImageFilter> CreateMaterialFilter(float radius, float sat, SkColor maskColor); 66 static float RadiusVp2Sigma(float radiusVp, float dipScale); 67 68 friend class RSMarshallingHelper; 69 }; 70 } // namespace Rosen 71 } // namespace OHOS 72 73 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H