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 40 void InitWithColorSpace(const Color4f& color, std::shared_ptr<ColorSpace> colorSpace) override; 41 42 void InitWithBlend(const ShaderEffect& s1, const ShaderEffect& s2, BlendMode mode) override; 43 44 void InitWithImage(const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling, 45 const Matrix& matrix) override; 46 47 void InitWithPicture(const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, const Matrix& matrix, 48 const Rect& rect) override; 49 50 void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors, 51 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override; 52 53 void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors, 54 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override; 55 56 void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPt, 57 scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, 58 const Matrix *matrix) override; 59 60 void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors, 61 const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle, 62 const Matrix *matrix) override; 63 64 void InitWithLightUp(const float& lightUpDeg, const ShaderEffect& imageShader) override; 65 66 sk_sp<SkShader> GetShader() const; 67 /* 68 * @brief Update the member variable to skShader, adaptation layer calls. 69 */ 70 void SetSkShader(const sk_sp<SkShader>& skShader); 71 72 std::shared_ptr<Data> Serialize() const override; 73 bool Deserialize(std::shared_ptr<Data> data) override; 74 private: 75 sk_sp<SkShader> shader_; 76 }; 77 } // namespace Drawing 78 } // namespace Rosen 79 } // namespace OHOS 80 #endif