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 ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_SHOWING_COMMAND_H
17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_SHOWING_COMMAND_H
18 
19 #include <map>
20 
21 #include "command/rs_command.h"
22 #include "command/rs_command_factory.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSRenderPropertyBase;
27 
28 enum RSNodeShowingCommandType : uint16_t {
29     GET_RENDER_PROPERTY,
30     GET_RENDER_PROPERTIES,
31     GET_VALUE_FRACTION,
32 };
33 
34 class RSB_EXPORT RSNodeGetShowingPropertyAndCancelAnimation : public RSSyncTask {
35     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_READ_PROPERTY;
36     constexpr static uint16_t commandSubType = GET_RENDER_PROPERTY;
37 
38 public:
39     explicit RSNodeGetShowingPropertyAndCancelAnimation(
40         NodeId targetId, std::shared_ptr<RSRenderPropertyBase> property, uint64_t timeoutNS = 1e8)
41         : RSSyncTask(timeoutNS), targetId_(targetId), property_(property)
42     {}
43     ~RSNodeGetShowingPropertyAndCancelAnimation() override = default;
44 
45     bool Marshalling(Parcel& parcel) const override;
46     static RSCommand* Unmarshalling(Parcel& parcel);
47 
48     bool CheckHeader(Parcel& parcel) const override;
49     bool ReadFromParcel(Parcel& parcel) override;
50 
51     void Process(RSContext& context) override;
GetProperty()52     std::shared_ptr<RSRenderPropertyBase> GetProperty() const
53     {
54         return property_;
55     }
IsTimeout()56     bool IsTimeout() const
57     {
58         return isTimeout_;
59     }
60 
61 private:
62     NodeId targetId_ = 0;
63     std::shared_ptr<RSRenderPropertyBase> property_;
64     bool isTimeout_ = true;
65     using Registrar = RSCommandRegister<commandType, commandSubType, Unmarshalling>;
66     static Registrar instance_;
67 };
68 
69 class RSB_EXPORT RSNodeGetShowingPropertiesAndCancelAnimation : public RSSyncTask {
70     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_READ_PROPERTY;
71     constexpr static uint16_t commandSubType = GET_RENDER_PROPERTIES;
72 
73 public:
74     using PropertiesMap = std::map<std::pair<NodeId, PropertyId>,
75         std::pair<std::shared_ptr<RSRenderPropertyBase>, std::vector<AnimationId>>>;
RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS,PropertiesMap && map)76     explicit RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS, PropertiesMap&& map)
77         : RSSyncTask(timeoutNS), propertiesMap_(std::move(map))
78     {}
79     ~RSNodeGetShowingPropertiesAndCancelAnimation() override = default;
80 
81     bool Marshalling(Parcel& parcel) const override;
82     static RSCommand* Unmarshalling(Parcel& parcel);
83 
84     bool CheckHeader(Parcel& parcel) const override;
85     bool ReadFromParcel(Parcel& parcel) override;
86 
87     void Process(RSContext& context) override;
88 
GetProperties()89     const PropertiesMap& GetProperties() const
90     {
91         return this->propertiesMap_;
92     }
93 
94 private:
RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS)95     RSNodeGetShowingPropertiesAndCancelAnimation(uint64_t timeoutNS): RSSyncTask(timeoutNS) {}
96     PropertiesMap propertiesMap_;
97     using Registrar = RSCommandRegister<commandType, commandSubType, Unmarshalling>;
98     static Registrar instance_;
99 };
100 
101 class RSB_EXPORT RSNodeGetAnimationsValueFraction: public RSSyncTask {
102     constexpr static uint16_t commandType = RS_NODE_SYNCHRONOUS_GET_VALUE_FRACTION;
103     constexpr static uint16_t commandSubType = GET_VALUE_FRACTION;
104 
105 public:
RSNodeGetAnimationsValueFraction(uint64_t timeoutNS,NodeId nodeId,AnimationId animationId)106     explicit RSNodeGetAnimationsValueFraction(uint64_t timeoutNS, NodeId nodeId, AnimationId animationId)
107         : RSSyncTask(timeoutNS), nodeId_(nodeId), animationId_(animationId)
108     {}
109     ~RSNodeGetAnimationsValueFraction() override = default;
110 
111     bool Marshalling(Parcel& parcel) const override;
112     static RSCommand* Unmarshalling(Parcel& parcel);
113 
114     bool CheckHeader(Parcel& parcel) const override;
115     bool ReadFromParcel(Parcel& parcel) override;
116 
117     void Process(RSContext& context) override;
118 
GetFraction()119     float GetFraction() const
120     {
121         return fraction_;
122     }
123 
124 private:
RSNodeGetAnimationsValueFraction(uint64_t timeoutNS)125     RSNodeGetAnimationsValueFraction(uint64_t timeoutNS): RSSyncTask(timeoutNS) {}
126     NodeId nodeId_;
127     AnimationId animationId_;
128     float fraction_ { 0.0f };
129     static inline RSCommandRegister<commandType, commandSubType, Unmarshalling> registry;
130 };
131 } // namespace Rosen
132 } // namespace OHOS
133 
134 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_SHOWING_COMMAND_H