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 #include "include/effects/SkRuntimeEffect.h" 23 24 #ifdef RS_ENABLE_GPU 25 #include "image/gpu_context.h" 26 #endif 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace Drawing { 31 class SkiaShaderEffect : public ShaderEffectImpl { 32 public: 33 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 34 35 SkiaShaderEffect() noexcept; 36 ~SkiaShaderEffect() override; 37 GetType()38 AdapterType GetType() const override 39 { 40 return AdapterType::SKIA_ADAPTER; 41 } 42 43 void InitWithColor(ColorQuad color) override; 44 45 void InitWithColorSpace(const Color4f& color, std::shared_ptr<ColorSpace> colorSpace) override; 46 47 void InitWithBlend(const ShaderEffect& s1, const ShaderEffect& s2, BlendMode mode) override; 48 49 void InitWithImage(const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling, 50 const Matrix& matrix) override; 51 52 void InitWithPicture(const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, const Matrix& matrix, 53 const Rect& rect) override; 54 55 void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors, 56 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override; 57 58 void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<Color4f>& colors, 59 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, 60 const Matrix *matrix) override; 61 62 void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors, 63 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override; 64 65 void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<Color4f>& colors, 66 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, 67 const Matrix *matrix) override; 68 69 void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPt, 70 scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, 71 const Matrix *matrix) override; 72 73 void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPtr, 74 scalar endRadius, const std::vector<Color4f>& colors, std::shared_ptr<ColorSpace> colorSpace, 75 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override; 76 77 void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors, 78 const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle, 79 const Matrix *matrix) override; 80 81 void InitWithSweepGradient(const Point& centerPt, const std::vector<Color4f>& colors, 82 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, scalar startAngle, 83 scalar endAngle, const Matrix *matrix) override; 84 85 void InitWithSdf(const SDFShapeBase& shape) override; 86 87 sk_sp<SkShader> GetShader() const; 88 /* 89 * @brief Update the member variable to skShader, adaptation layer calls. 90 */ 91 void SetSkShader(const sk_sp<SkShader>& skShader); 92 93 #ifdef RS_ENABLE_GPU 94 void SetGPUContext(std::shared_ptr<GPUContext> gpuContext) override; 95 #endif 96 97 std::shared_ptr<Data> Serialize() const override; 98 bool Deserialize(std::shared_ptr<Data> data) override; 99 private: 100 sk_sp<SkShader> shader_; 101 #ifdef RS_ENABLE_GPU 102 std::shared_ptr<GPUContext> gpuContext_ = nullptr; 103 #endif 104 }; 105 } // namespace Drawing 106 } // namespace Rosen 107 } // namespace OHOS 108 #endif