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 16 #ifndef SKIA_SHADER_EFFECT_H 17 #define SKIA_SHADER_EFFECT_H 18 19 #include "include/core/SkShader.h" 20 21 #include "impl_interface/shader_effect_impl.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 class SkiaShaderEffect : public ShaderEffectImpl { 27 public: 28 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 29 30 SkiaShaderEffect() noexcept; ~SkiaShaderEffect()31 ~SkiaShaderEffect() override {}; 32 GetType()33 AdapterType GetType() const override 34 { 35 return AdapterType::SKIA_ADAPTER; 36 } 37 38 void InitWithColor(ColorQuad color) override; 39 void InitWithBlend(const ShaderEffect& s1, const ShaderEffect& s2, BlendMode mode) override; 40 void InitWithImage(const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling, 41 const Matrix& matrix) override; 42 void InitWithPicture(const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, const Matrix& matrix, 43 const Rect& rect) override; 44 void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors, 45 const std::vector<scalar>& pos, TileMode mode) override; 46 void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors, 47 const std::vector<scalar>& pos, TileMode mode) override; 48 void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPt, 49 scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, 50 const Matrix *matrix) override; 51 void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors, 52 const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle, 53 const Matrix *matrix) override; 54 sk_sp<SkShader> GetShader() const; 55 /* 56 * @brief Update the member variable to skShader, adaptation layer calls. 57 */ 58 void SetSkShader(const sk_sp<SkShader>& skShader); 59 60 std::shared_ptr<Data> Serialize() const override; 61 bool Deserialize(std::shared_ptr<Data> data) override; 62 private: 63 sk_sp<SkShader> shader_; 64 }; 65 } // namespace Drawing 66 } // namespace Rosen 67 } // namespace OHOS 68 #endif