• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PATH_EFFECT_CMD_LILST_H
17 #define PATH_EFFECT_CMD_LILST_H
18 
19 #include "effect/path_effect.h"
20 #include "recording/cmd_list.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 class PathEffectCmdList : public CmdList {
26 public:
27     PathEffectCmdList() = default;
28     ~PathEffectCmdList() override = default;
29 
GetType()30     uint32_t GetType() const override
31     {
32         return Type::PATH_EFFECT_CMD_LIST;
33     }
34 
35     /*
36      * @brief       Creates a PathEffectCmdList with contiguous buffers.
37      * @param data  A contiguous buffsers.
38      */
39     static std::shared_ptr<PathEffectCmdList> CreateFromData(const CmdListData& data, bool isCopy = false);
40 
41     /*
42      * @brief  Creates a PathEffect by the ShaderEffectCmdList playback operation.
43      */
44     std::shared_ptr<PathEffect> Playback() const;
45 };
46 
47 /* OpItem */
48 class PathEffectOpItem : public OpItem {
49 public:
PathEffectOpItem(uint32_t type)50     explicit PathEffectOpItem(uint32_t type) : OpItem(type) {}
51     ~PathEffectOpItem() = default;
52 
53     enum Type : uint32_t {
54         OPITEM_HEAD = 0, // OPITEM_HEAD must be 0
55         CREATE_DASH,
56         CREATE_PATH_DASH,
57         CREATE_CORNER,
58         CREATE_SUM,
59         CREATE_COMPOSE,
60     };
61 };
62 
63 class CreateDashPathEffectOpItem : public PathEffectOpItem {
64 public:
65     CreateDashPathEffectOpItem(const std::pair<uint32_t, size_t>& intervals, scalar phase);
66     ~CreateDashPathEffectOpItem() = default;
67 
68     /*
69      * @brief            Restores arguments from contiguous memory and plays back the OpItem to create PathEffect.
70      * @param cmdList  A contiguous memory.
71      */
72     std::shared_ptr<PathEffect> Playback(const CmdList& cmdList) const;
73 private:
74     std::pair<uint32_t, size_t> intervals_;
75     scalar phase_;
76 };
77 
78 class CreatePathDashEffectOpItem : public PathEffectOpItem {
79 public:
80     CreatePathDashEffectOpItem(const CmdListHandle& path, scalar advance, scalar phase, PathDashStyle style);
81     ~CreatePathDashEffectOpItem() = default;
82 
83     /*
84      * @brief            Restores arguments from contiguous memory and plays back the OpItem to create PathEffect.
85      * @param cmdList  A contiguous memory.
86      */
87     std::shared_ptr<PathEffect> Playback(const CmdList& cmdList) const;
88 private:
89     CmdListHandle path_;
90     scalar advance_;
91     scalar phase_;
92     PathDashStyle style_;
93 };
94 
95 class CreateCornerPathEffectOpItem : public PathEffectOpItem {
96 public:
97     explicit CreateCornerPathEffectOpItem(scalar radius);
98     ~CreateCornerPathEffectOpItem() = default;
99 
100     /*
101      * @brief   Plays back the OpItem to create PathEffect.
102      */
103     std::shared_ptr<PathEffect> Playback() const;
104 private:
105     scalar radius_;
106 };
107 
108 class CreateSumPathEffectOpItem : public PathEffectOpItem {
109 public:
110     CreateSumPathEffectOpItem(const CmdListHandle& effect1, const CmdListHandle& effect2);
111     ~CreateSumPathEffectOpItem() = default;
112 
113     /*
114      * @brief            Restores arguments from contiguous memory and plays back the OpItem to create PathEffect.
115      * @param cmdList  A contiguous memory.
116      */
117     std::shared_ptr<PathEffect> Playback(const CmdList& cmdList) const;
118 private:
119     CmdListHandle effect1_;
120     CmdListHandle effect2_;
121 };
122 
123 class CreateComposePathEffectOpItem : public PathEffectOpItem {
124 public:
125     CreateComposePathEffectOpItem(const CmdListHandle& effect1, const CmdListHandle& effect2);
126     ~CreateComposePathEffectOpItem() = default;
127 
128     /*
129      * @brief            Restores arguments from contiguous memory and plays back the OpItem to create PathEffect.
130      * @param cmdList  A contiguous memory.
131      */
132     std::shared_ptr<PathEffect> Playback(const CmdList& cmdList) const;
133 private:
134     CmdListHandle effect1_;
135     CmdListHandle effect2_;
136 };
137 } // namespace Drawing
138 } // namespace Rosen
139 } // namespace OHOS
140 #endif
141