1 /* 2 * Copyright (c) 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 SHADER_EFFECT_CMD_LILST_H 17 #define SHADER_EFFECT_CMD_LILST_H 18 19 #include "effect/shader_effect.h" 20 #include "recording/cmd_list.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 class ShaderEffectCmdList : public CmdList { 26 public: 27 ShaderEffectCmdList() = default; 28 ~ShaderEffectCmdList() override = default; 29 GetType()30 uint32_t GetType() const override 31 { 32 return Type::SHADER_EFFECT_CMD_LIST; 33 } 34 35 /* 36 * @brief Creates a ShaderEffectCmdList with contiguous buffers. 37 * @param data A contiguous buffers. 38 */ 39 static std::shared_ptr<ShaderEffectCmdList> CreateFromData(const CmdListData& data, bool isCopy = false); 40 41 /* 42 * @brief Create a ShaderEffect by the ShaderEffectCmdList playback operation. 43 */ 44 std::shared_ptr<ShaderEffect> Playback() const; 45 46 private: 47 MemAllocator largeObjectAllocator_; 48 }; 49 50 /* OpItem */ 51 class ShaderEffectOpItem : public OpItem { 52 public: ShaderEffectOpItem(uint32_t type)53 explicit ShaderEffectOpItem(uint32_t type) : OpItem(type) {} 54 ~ShaderEffectOpItem() = default; 55 56 enum Type : uint32_t { 57 OPITEM_HEAD = 0, // OPITEM_HEAD must be 0 58 CREATE_COLOR_SHADER, 59 CREATE_BLEND_SHADER, 60 CREATE_IMAGE_SHADER, 61 CREATE_PICTURE_SHADER, 62 CREATE_LINEAR_GRADIENT, 63 CREATE_RADIAL_GRADIENT, 64 CREATE_TWO_POINT_CONICAL, 65 CREATE_SWEEP_GRADIENT 66 }; 67 }; 68 69 class CreateColorShaderOpItem : public ShaderEffectOpItem { 70 public: 71 explicit CreateColorShaderOpItem(ColorQuad color); 72 ~CreateColorShaderOpItem() = default; 73 74 std::shared_ptr<ShaderEffect> Playback() const; 75 private: 76 ColorQuad color_; 77 }; 78 79 class CreateBlendShaderOpItem : public ShaderEffectOpItem { 80 public: 81 CreateBlendShaderOpItem(const CmdListHandle& dst, const CmdListHandle& src, BlendMode mode); 82 ~CreateBlendShaderOpItem() = default; 83 84 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 85 private: 86 CmdListHandle dst_; 87 CmdListHandle src_; 88 BlendMode mode_; 89 }; 90 91 class CreateImageShaderOpItem : public ShaderEffectOpItem { 92 public: 93 CreateImageShaderOpItem(const ImageHandle& image, TileMode tileX, TileMode tileY, 94 const SamplingOptions& sampling, const Matrix& matrix); 95 ~CreateImageShaderOpItem() = default; 96 97 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 98 private: 99 ImageHandle image_; 100 TileMode tileX_; 101 TileMode tileY_; 102 SamplingOptions samplingOptions_; 103 Matrix matrix_; 104 }; 105 106 class CreatePictureShaderOpItem : public ShaderEffectOpItem { 107 public: 108 CreatePictureShaderOpItem(const ImageHandle& picture, TileMode tileX, TileMode tileY, 109 FilterMode mode, const Matrix& matrix, const Rect& rect); 110 ~CreatePictureShaderOpItem() = default; 111 112 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 113 private: 114 ImageHandle picture_; 115 TileMode tileX_; 116 TileMode tileY_; 117 FilterMode filterMode_; 118 Matrix matrix_; 119 Rect rect_; 120 }; 121 122 class CreateLinearGradientOpItem : public ShaderEffectOpItem { 123 public: 124 CreateLinearGradientOpItem(const Point& startPt, const Point& endPt, 125 const std::pair<uint32_t, size_t>& colors, const std::pair<uint32_t, size_t>& pos, TileMode mode); 126 ~CreateLinearGradientOpItem() = default; 127 128 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 129 private: 130 Point startPt_; 131 Point endPt_; 132 std::pair<uint32_t, size_t> colors_; 133 std::pair<uint32_t, size_t> pos_; 134 TileMode mode_; 135 }; 136 class CreateRadialGradientOpItem : public ShaderEffectOpItem { 137 public: 138 CreateRadialGradientOpItem(const Point& centerPt, scalar radius, 139 const std::pair<uint32_t, size_t>& colors, const std::pair<uint32_t, size_t>& pos, TileMode mode); 140 ~CreateRadialGradientOpItem() = default; 141 142 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 143 private: 144 Point centerPt_; 145 scalar radius_; 146 std::pair<uint32_t, size_t> colors_; 147 std::pair<uint32_t, size_t> pos_; 148 TileMode mode_; 149 }; 150 151 class CreateTwoPointConicalOpItem : public ShaderEffectOpItem { 152 public: 153 CreateTwoPointConicalOpItem(const Point& startPt, scalar startRadius, const Point& endPt, scalar endRadius, 154 const std::pair<uint32_t, size_t>& colors, const std::pair<uint32_t, size_t>& pos, TileMode mode); 155 ~CreateTwoPointConicalOpItem() = default; 156 157 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 158 private: 159 Point startPt_; 160 scalar startRadius_; 161 Point endPt_; 162 scalar endRadius_; 163 std::pair<uint32_t, size_t> colors_; 164 std::pair<uint32_t, size_t> pos_; 165 TileMode mode_; 166 }; 167 168 class CreateSweepGradientOpItem : public ShaderEffectOpItem { 169 public: 170 CreateSweepGradientOpItem(const Point& centerPt, const std::pair<uint32_t, size_t>& colors, 171 const std::pair<uint32_t, size_t>& pos, TileMode mode, scalar startAngle, scalar endAngle); 172 ~CreateSweepGradientOpItem() = default; 173 174 std::shared_ptr<ShaderEffect> Playback(const CmdList& cmdList) const; 175 private: 176 Point centerPt_; 177 std::pair<uint32_t, size_t> colors_; 178 std::pair<uint32_t, size_t> pos_; 179 TileMode mode_; 180 scalar startAngle_; 181 scalar endAngle_; 182 }; 183 } // namespace Drawing 184 } // namespace Rosen 185 } // namespace OHOS 186 #endif 187