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 16 #ifndef SHADER_EFFECT_IMPL_H 17 #define SHADER_EFFECT_IMPL_H 18 19 #include <memory> 20 21 #include "base_impl.h" 22 23 #include "draw/blend_mode.h" 24 #include "draw/color.h" 25 #include "draw/sdf_shaper_base.h" 26 #include "image/picture.h" 27 #include "utils/matrix.h" 28 #include "utils/point.h" 29 #include "utils/point3.h" 30 #include "utils/rect.h" 31 #include "utils/sampling_options.h" 32 #include "utils/scalar.h" 33 34 namespace OHOS { 35 namespace Rosen { 36 namespace Drawing { 37 class Data; 38 class Image; 39 class ShaderEffect; 40 #ifdef RS_ENABLE_GPU 41 class GPUContext; 42 #endif 43 enum class TileMode; 44 class ShaderEffectImpl : public BaseImpl { 45 public: ShaderEffectImpl()46 ShaderEffectImpl() noexcept {} ~ShaderEffectImpl()47 ~ShaderEffectImpl() override {} 48 49 virtual void InitWithColor(ColorQuad color) = 0; 50 51 virtual void InitWithColorSpace(const Color4f& color, std::shared_ptr<ColorSpace> colorSpace) = 0; 52 53 virtual void InitWithBlend(const ShaderEffect& s1, const ShaderEffect& s2, BlendMode mode) = 0; 54 55 virtual void InitWithImage(const Image& image, TileMode tileX, TileMode tileY, 56 const SamplingOptions& sampling, const Matrix& matrix) = 0; 57 58 virtual void InitWithPicture(const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, 59 const Matrix& matrix, const Rect& rect) = 0; 60 61 virtual void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors, 62 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) = 0; 63 64 virtual void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<Color4f>& colors, 65 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, 66 const Matrix *matrix) = 0; 67 68 virtual void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors, 69 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) = 0; 70 71 virtual void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<Color4f>& colors, 72 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, 73 const Matrix *matrix) = 0; 74 75 virtual void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPtr, 76 scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, 77 const Matrix *matrix) = 0; 78 79 virtual void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPtr, 80 scalar endRadius, const std::vector<Color4f>& colors, std::shared_ptr<ColorSpace> colorSpace, 81 const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) = 0; 82 83 virtual void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors, 84 const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle, const Matrix *matrix) = 0; 85 86 virtual void InitWithSweepGradient(const Point& centerPt, const std::vector<Color4f>& colors, 87 std::shared_ptr<ColorSpace> colorSpace, const std::vector<scalar>& pos, TileMode mode, scalar startAngle, 88 scalar endAngle, const Matrix *matrix) = 0; 89 90 virtual void InitWithSdf(const SDFShapeBase& shape) = 0; 91 92 #ifdef RS_ENABLE_GPU 93 virtual void SetGPUContext(std::shared_ptr<GPUContext> gpuContext) = 0; 94 #endif 95 96 virtual std::shared_ptr<Data> Serialize() const = 0; 97 virtual bool Deserialize(std::shared_ptr<Data> data) = 0; 98 }; 99 } // namespace Drawing 100 } // namespace Rosen 101 } // namespace OHOS 102 #endif 103