1 /* 2 * Copyright (c) 2021-2022 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_COMMAND_H 17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_COMMAND_H 18 19 #include "command/rs_command_templates.h" 20 #include "pipeline/rs_render_node.h" 21 #include "property/rs_properties.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 26 enum RSNodeCommandType : uint16_t { 27 SET_BOUNDS, 28 SET_BOUNDS_SIZE, 29 SET_BOUNDS_WIDTH, 30 SET_BOUNDS_HEIGHT, 31 SET_BOUNDS_POSITION, 32 SET_BOUNDS_POSITION_X, 33 SET_BOUNDS_POSITION_Y, 34 SET_FRAME, 35 SET_FRAME_SIZE, 36 SET_FRAME_WIDTH, 37 SET_FRAME_HEIGHT, 38 SET_FRAME_POSITION, 39 SET_FRAME_POSITION_X, 40 SET_FRAME_POSITION_Y, 41 SET_POSITION_Z, 42 SET_PIVOT, 43 SET_PIVOT_X, 44 SET_PIVOT_Y, 45 SET_CORNER_RADIUS, 46 SET_QUATERNION, 47 SET_ROTATION, 48 SET_ROTATION_X, 49 SET_ROTATION_Y, 50 SET_SCALE, 51 SET_SCALE_X, 52 SET_SCALE_Y, 53 SET_TRANSLATE, 54 SET_TRANSLATE_X, 55 SET_TRANSLATE_Y, 56 SET_TRANSLATE_Z, 57 SET_ALPHA, 58 SET_FG_COLOR, 59 SET_BG_COLOR, 60 SET_BG_SHADER, 61 SET_BG_IMAGE, 62 SET_BG_IMAGE_WIDTH, 63 SET_BG_IMAGE_HEIGHT, 64 SET_BG_IMAGE_POSITION_X, 65 SET_BG_IMAGE_POSITION_Y, 66 SET_BORDER_COLOR, 67 SET_BORDER_WIDTH, 68 SET_BORDER_STYLE, 69 SET_SUBLAYER_TRANSFORM, 70 SET_BG_FILTER, 71 SET_FILTER, 72 SET_COMPOSITING_FILTER, 73 SET_FRAME_GRAVITY, 74 SET_CLIP_BOUNDS, 75 SET_CLIP_TO_BOUNDS, 76 SET_CLIP_TO_FRAME, 77 SET_VISIBLE, 78 SET_SHADOW_COLOR, 79 SET_SHADOW_OFFSET_X, 80 SET_SHADOW_OFFSET_Y, 81 SET_SHADOW_ALPHA, 82 SET_SHADOW_ELEVATION, 83 SET_SHADOW_RADIUS, 84 SET_SHADOW_PATH, 85 SET_MASK, 86 87 SET_BOUNDS_DELTA, 88 SET_BOUNDS_SIZE_DELTA, 89 SET_BOUNDS_WIDTH_DELTA, 90 SET_BOUNDS_HEIGHT_DELTA, 91 SET_BOUNDS_POSITION_DELTA, 92 SET_BOUNDS_POSITION_X_DELTA, 93 SET_BOUNDS_POSITION_Y_DELTA, 94 SET_FRAME_DELTA, 95 SET_FRAME_SIZE_DELTA, 96 SET_FRAME_WIDTH_DELTA, 97 SET_FRAME_HEIGHT_DELTA, 98 SET_FRAME_POSITION_DELTA, 99 SET_FRAME_POSITION_X_DELTA, 100 SET_FRAME_POSITION_Y_DELTA, 101 SET_POSITION_Z_DELTA, 102 SET_PIVOT_DELTA, 103 SET_PIVOT_X_DELTA, 104 SET_PIVOT_Y_DELTA, 105 SET_CORNER_RADIUS_DELTA, 106 SET_QUATERNION_DELTA, 107 SET_ROTATION_DELTA, 108 SET_ROTATION_X_DELTA, 109 SET_ROTATION_Y_DELTA, 110 SET_SCALE_DELTA, 111 SET_SCALE_X_DELTA, 112 SET_SCALE_Y_DELTA, 113 SET_TRANSLATE_DELTA, 114 SET_TRANSLATE_X_DELTA, 115 SET_TRANSLATE_Y_DELTA, 116 SET_TRANSLATE_Z_DELTA, 117 SET_ALPHA_DELTA, 118 SET_FG_COLOR_DELTA, 119 SET_BG_COLOR_DELTA, 120 SET_BG_SHADER_DELTA, 121 SET_BG_IMAGE_WIDTH_DELTA, 122 SET_BG_IMAGE_HEIGHT_DELTA, 123 SET_BG_IMAGE_POSITION_X_DELTA, 124 SET_BG_IMAGE_POSITION_Y_DELTA, 125 SET_BORDER_COLOR_DELTA, 126 SET_BORDER_WIDTH_DELTA, 127 SET_SUBLAYER_TRANSFORM_DELTA, 128 SET_BG_FILTER_DELTA, 129 SET_FILTER_DELTA, 130 SET_COMPOSITING_FILTER_DELTA, 131 SET_FRAME_GRAVITY_DELTA, 132 SET_SHADOW_COLOR_DELTA, 133 SET_SHADOW_OFFSET_X_DELTA, 134 SET_SHADOW_OFFSET_Y_DELTA, 135 SET_SHADOW_ALPHA_DELTA, 136 SET_SHADOW_ELEVATION_DELTA, 137 SET_SHADOW_RADIUS_DELTA, 138 }; 139 140 class RSRenderNodeCommandHelper { 141 public: 142 // second parameter of SETTER is useless, should be removed 143 template<typename T, auto setter> SetProperty(RSContext & context,NodeId nodeId,const T & value)144 static void SetProperty(RSContext& context, NodeId nodeId, const T& value) 145 { 146 if (auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId)) { 147 (node->GetMutableRenderProperties().*setter)(value); 148 } 149 } 150 151 template<typename T, auto setter, auto getter> SetPropertyDelta(RSContext & context,NodeId nodeId,const T & value)152 static void SetPropertyDelta(RSContext& context, NodeId nodeId, const T& value) 153 { 154 if (auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId)) { 155 T newValue = (node->GetRenderProperties().*getter)() + value; 156 (node->GetMutableRenderProperties().*setter)(newValue); 157 } 158 } 159 }; 160 161 // declare commands like RSPropertyRenderNodeAlphaChanged and RSPropertyRenderNodeAlphaDelta 162 #define DECLARE_SET_COMMAND(COMMAND_NAME, SUBCOMMAND, TYPE, SETTER) \ 163 ADD_COMMAND(COMMAND_NAME, \ 164 ARG(RS_NODE, SUBCOMMAND, RSRenderNodeCommandHelper::SetProperty<TYPE, &RSProperties::SETTER>, NodeId, TYPE)) 165 #define DECLARE_DELTA_COMMAND(COMMAND_NAME, SUBCOMMAND, TYPE, SETTER, GETTER) \ 166 ADD_COMMAND(COMMAND_NAME, \ 167 ARG(RS_NODE, SUBCOMMAND, \ 168 RSRenderNodeCommandHelper::SetPropertyDelta<TYPE, &RSProperties::SETTER, &RSProperties::GETTER>, NodeId, \ 169 TYPE)) 170 171 #include "rs_node_command.in" 172 173 #undef DECLARE_SET_COMMAND 174 #undef DECLARE_DELTA_COMMAND 175 176 } // namespace Rosen 177 } // namespace OHOS 178 179 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_NODE_COMMAND_H 180