1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#include "drag_drawing.h" 17f857971dSopenharmony_ci 18f857971dSopenharmony_ci#include <atomic> 19f857971dSopenharmony_ci#include <cstdint> 20f857971dSopenharmony_ci#include <fstream> 21f857971dSopenharmony_ci#include <limits> 22f857971dSopenharmony_ci#include <string> 23f857971dSopenharmony_ci#include <unistd.h> 24f857971dSopenharmony_ci 25f857971dSopenharmony_ci#include <dlfcn.h> 26f857971dSopenharmony_ci 27f857971dSopenharmony_ci#include "include/core/SkTextBlob.h" 28f857971dSopenharmony_ci#include "image_source.h" 29f857971dSopenharmony_ci#include "image_type.h" 30f857971dSopenharmony_ci#include "image_utils.h" 31f857971dSopenharmony_ci#include "input_manager.h" 32f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 33f857971dSopenharmony_ci#include "parameters.h" 34f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 35f857971dSopenharmony_ci#include "pointer_event.h" 36f857971dSopenharmony_ci#include "pointer_style.h" 37f857971dSopenharmony_ci#include "render/rs_filter.h" 38f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 39f857971dSopenharmony_ci#include "screen_manager.h" 40f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 41f857971dSopenharmony_ci#include "string_ex.h" 42f857971dSopenharmony_ci#include "transaction/rs_interfaces.h" 43f857971dSopenharmony_ci#include "ui/rs_surface_extractor.h" 44f857971dSopenharmony_ci#include "ui/rs_surface_node.h" 45f857971dSopenharmony_ci#include "ui/rs_ui_director.h" 46f857971dSopenharmony_ci 47f857971dSopenharmony_ci#include "animation_curve.h" 48f857971dSopenharmony_ci#include "devicestatus_define.h" 49f857971dSopenharmony_ci#include "drag_data_manager.h" 50f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 51f857971dSopenharmony_ci#include "drag_hisysevent.h" 52f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 53f857971dSopenharmony_ci#include "include/util.h" 54f857971dSopenharmony_ci 55f857971dSopenharmony_ci#undef LOG_TAG 56f857971dSopenharmony_ci#define LOG_TAG "DragDrawing" 57f857971dSopenharmony_ci 58f857971dSopenharmony_cinamespace OHOS { 59f857971dSopenharmony_cinamespace Msdp { 60f857971dSopenharmony_cinamespace DeviceStatus { 61f857971dSopenharmony_cinamespace { 62f857971dSopenharmony_ciconstexpr int32_t BASELINE_DENSITY { 160 }; 63f857971dSopenharmony_ciconstexpr int32_t DEVICE_INDEPENDENT_PIXEL { 40 }; 64f857971dSopenharmony_ciconstexpr int32_t MAGIC_INDEPENDENT_PIXEL { 25 }; 65f857971dSopenharmony_ciconstexpr int32_t MAGIC_STYLE_OPT { 1 }; 66f857971dSopenharmony_ciconstexpr int32_t DRAG_NUM_ONE { 1 }; 67f857971dSopenharmony_ciconstexpr int32_t STRING_PX_LENGTH { 2 }; 68f857971dSopenharmony_ciconstexpr int32_t EIGHT_SIZE { 8 }; 69f857971dSopenharmony_ciconstexpr int32_t TWELVE_SIZE { 12 }; 70f857971dSopenharmony_ciconstexpr int64_t START_TIME { 181154000809 }; 71f857971dSopenharmony_ciconstexpr int64_t INTERVAL_TIME { 16666667 }; 72f857971dSopenharmony_ciconstexpr int32_t SVG_WIDTH { 40 }; 73f857971dSopenharmony_ciconstexpr float SCALE_THRESHOLD_EIGHT { 1.0F * INT32_MAX / (SVG_WIDTH + EIGHT_SIZE) }; 74f857971dSopenharmony_ciconstexpr float SCALE_THRESHOLD_TWELVE { 1.0F * INT32_MAX / (SVG_WIDTH + TWELVE_SIZE) }; 75f857971dSopenharmony_ciconstexpr int32_t SUCCESS_ANIMATION_DURATION { 300 }; 76f857971dSopenharmony_ciconstexpr int32_t ANIMATION_DURATION { 400 }; 77f857971dSopenharmony_ciconstexpr int32_t VIEW_BOX_POS { 2 }; 78f857971dSopenharmony_ciconstexpr int32_t BACKGROUND_FILTER_INDEX { 0 }; 79f857971dSopenharmony_ciconstexpr int32_t ASYNC_ROTATE_TIME { 150 }; 80f857971dSopenharmony_ciconstexpr int32_t PIXEL_MAP_INDEX { 1 }; 81f857971dSopenharmony_ciconstexpr int32_t DRAG_STYLE_INDEX { 2 }; 82f857971dSopenharmony_ciconstexpr int32_t MOUSE_ICON_INDEX { 3 }; 83f857971dSopenharmony_ciconstexpr int32_t SHORT_DURATION { 55 }; 84f857971dSopenharmony_ciconstexpr int32_t LONG_DURATION { 90 }; 85f857971dSopenharmony_ciconstexpr int32_t FIRST_PIXELMAP_INDEX { 0 }; 86f857971dSopenharmony_ciconstexpr int32_t SECOND_PIXELMAP_INDEX { 1 }; 87f857971dSopenharmony_ciconstexpr int32_t LAST_SECOND_PIXELMAP { 2 }; 88f857971dSopenharmony_ciconstexpr int32_t LAST_THIRD_PIXELMAP { 3 }; 89f857971dSopenharmony_ciconstexpr size_t TOUCH_NODE_MIN_COUNT { 3 }; 90f857971dSopenharmony_ciconstexpr size_t MOUSE_NODE_MIN_COUNT { 4 }; 91f857971dSopenharmony_ciconstexpr float DEFAULT_SCALING { 1.0f }; 92f857971dSopenharmony_ciconstexpr float BEGIN_ALPHA { 1.0f }; 93f857971dSopenharmony_ciconstexpr float END_ALPHA { 0.0f }; 94f857971dSopenharmony_ciconstexpr float START_STYLE_ALPHA { 1.0f }; 95f857971dSopenharmony_ciconstexpr float END_STYLE_ALPHA { 0.0f }; 96f857971dSopenharmony_ciconstexpr float BEGIN_SCALE { 1.0f }; 97f857971dSopenharmony_ciconstexpr float END_SCALE_FAIL { 1.2f }; 98f857971dSopenharmony_ciconstexpr float END_SCALE_SUCCESS { 0.0f }; 99f857971dSopenharmony_ciconstexpr float DEFAULT_PIVOT { 0.0f }; 100f857971dSopenharmony_ciconstexpr float HALF_PIVOT { 0.5f }; 101f857971dSopenharmony_ciconstexpr float START_STYLE_SCALE { 1.0f }; 102f857971dSopenharmony_ciconstexpr float STYLE_CHANGE_SCALE { 1.1f }; 103f857971dSopenharmony_ciconstexpr float STYLE_MAX_SCALE { 1.2f }; 104f857971dSopenharmony_ciconstexpr float STYLE_END_SCALE { 1.0f }; 105f857971dSopenharmony_ciconstexpr float SVG_ORIGINAL_SIZE { 40.0f }; 106f857971dSopenharmony_ciconstexpr float DEFAULT_POSITION_X { 0.0f }; 107f857971dSopenharmony_ciconstexpr float BLUR_SIGMA_SCALE { 0.57735f }; 108f857971dSopenharmony_ciconstexpr float RADIUS_VP { 23.0f }; 109f857971dSopenharmony_ciconstexpr float DEFAULT_SATURATION { 1.05f }; 110f857971dSopenharmony_ciconstexpr float DEFAULT_BRIGHTNESS { 1.05f }; 111f857971dSopenharmony_ciconstexpr float INCREASE_RATIO { 1.22f }; 112f857971dSopenharmony_ciconstexpr float DRAG_WINDOW_POSITION_Z { 6999.0f }; 113f857971dSopenharmony_ciconstexpr float DEFAULT_ANGLE { 0.0f }; 114f857971dSopenharmony_ciconstexpr float POSITIVE_ANGLE { 8.0f }; 115f857971dSopenharmony_ciconstexpr float NEGATIVE_ANGLE { -8.0f }; 116f857971dSopenharmony_ciconstexpr float DEFAULT_ALPHA { 1.0f }; 117f857971dSopenharmony_ciconstexpr float FIRST_PIXELMAP_ALPHA { 0.6f }; 118f857971dSopenharmony_ciconstexpr float SECOND_PIXELMAP_ALPHA { 0.3f }; 119f857971dSopenharmony_ciconstexpr float HALF_RATIO { 0.5f }; 120f857971dSopenharmony_ciconstexpr float ROTATION_0 { 0.0f }; 121f857971dSopenharmony_ciconstexpr float ROTATION_90 { 90.0f }; 122f857971dSopenharmony_ciconstexpr float ROTATION_360 { 360.0f }; 123f857971dSopenharmony_ciconstexpr float ROTATION_270 { 270.0f }; 124f857971dSopenharmony_ciconstexpr uint32_t TRANSPARENT_COLOR_ARGB { 0x00000000 }; 125f857971dSopenharmony_ciconstexpr int32_t DEFAULT_MOUSE_SIZE { 1 }; 126f857971dSopenharmony_ciconstexpr int32_t DEFAULT_COLOR_VALUE { 0 }; 127f857971dSopenharmony_ciconstexpr int32_t INVALID_COLOR_VALUE { -1 }; 128f857971dSopenharmony_ciconstexpr int32_t GLOBAL_WINDOW_ID { -1 }; 129f857971dSopenharmony_ciconstexpr int32_t MOUSE_DRAG_CURSOR_CIRCLE_STYLE { 41 }; 130f857971dSopenharmony_ciconstexpr int32_t CURSOR_CIRCLE_MIDDLE { 2 }; 131f857971dSopenharmony_ciconstexpr int32_t TWICE_SIZE { 2 }; 132f857971dSopenharmony_ciconstexpr int32_t NUM_ONE { 1 }; 133f857971dSopenharmony_ciconstexpr int32_t NUM_TWO { 2 }; 134f857971dSopenharmony_ciconstexpr int32_t NUM_FOUR { 4 }; 135f857971dSopenharmony_ciconstexpr int32_t HEX_FF { 0xFF }; 136f857971dSopenharmony_ciconst Rosen::RSAnimationTimingCurve SPRING = Rosen::RSAnimationTimingCurve::CreateSpring(0.347f, 0.99f, 0.0f); 137f857971dSopenharmony_ciconst std::string RENDER_THREAD_NAME { "os_dargRenderRunner" }; 138f857971dSopenharmony_ciconstexpr float BEZIER_000 { 0.00f }; 139f857971dSopenharmony_ciconstexpr float BEZIER_020 { 0.20f }; 140f857971dSopenharmony_ciconstexpr float BEZIER_030 { 0.30f }; 141f857971dSopenharmony_ciconstexpr float BEZIER_033 { 0.33f }; 142f857971dSopenharmony_ciconstexpr float BEZIER_040 { 0.40f }; 143f857971dSopenharmony_ciconstexpr float BEZIER_060 { 0.60f }; 144f857971dSopenharmony_ciconstexpr float BEZIER_067 { 0.67f }; 145f857971dSopenharmony_ciconstexpr float BEZIER_100 { 1.00f }; 146f857971dSopenharmony_ciconstexpr float MIN_OPACITY { 0.0f }; 147f857971dSopenharmony_ciconstexpr float MAX_OPACITY { 1.0f }; 148f857971dSopenharmony_ciconstexpr int32_t TIME_DRAG_CHANGE_STYLE { 50 }; 149f857971dSopenharmony_ciconstexpr int32_t TIME_DRAG_STYLE { 100 }; 150f857971dSopenharmony_ciconstexpr int32_t TIME_STOP_FAIL_WINDOW { 125 }; 151f857971dSopenharmony_ciconstexpr int32_t TIME_STOP_SUCCESS_WINDOW { 250 }; 152f857971dSopenharmony_ciconstexpr int32_t TIME_STOP_SUCCESS_STYLE { 150 }; 153f857971dSopenharmony_ciconstexpr int32_t TIME_STOP { 0 }; 154f857971dSopenharmony_ciconstexpr int64_t TIME_SLEEP { 30000 }; 155f857971dSopenharmony_ciconstexpr int32_t INTERRUPT_SCALE { 15 }; 156f857971dSopenharmony_ciconstexpr int32_t TIMEOUT_MS { 500 }; 157f857971dSopenharmony_ciconstexpr float MAX_SCREEN_WIDTH_SM { 320.0f }; 158f857971dSopenharmony_ciconstexpr float MAX_SCREEN_WIDTH_MD { 600.0f }; 159f857971dSopenharmony_ciconstexpr float MAX_SCREEN_WIDTH_LG { 840.0f }; 160f857971dSopenharmony_ciconstexpr float MAX_SCREEN_WIDTH_XL { 1024.0f }; 161f857971dSopenharmony_ciconstexpr float SCALE_SM { 3.0f / 4 }; 162f857971dSopenharmony_ciconstexpr float SCALE_MD { 4.0f / 8 }; 163f857971dSopenharmony_ciconstexpr float SCALE_LG { 5.0f / 12 }; 164f857971dSopenharmony_ciconst std::string THREAD_NAME { "os_AnimationEventRunner" }; 165f857971dSopenharmony_ciconst std::string SUPER_HUB_THREAD_NAME { "os_SuperHubEventRunner" }; 166f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 167f857971dSopenharmony_ciconst std::string COPY_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_Drag.svg" }; 168f857971dSopenharmony_ciconst std::string COPY_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_One_Drag.svg" }; 169f857971dSopenharmony_ciconst std::string FORBID_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_Drag.svg" }; 170f857971dSopenharmony_ciconst std::string FORBID_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_One_Drag.svg" }; 171f857971dSopenharmony_ciconst std::string MOVE_DRAG_PATH { "/system/etc/device_status/drag_icon/Move_Drag.svg" }; 172f857971dSopenharmony_ci#else 173f857971dSopenharmony_ciconst std::string COPY_DRAG_NAME { "/base/media/Copy_Drag.svg" }; 174f857971dSopenharmony_ciconst std::string COPY_ONE_DRAG_NAME { "/base/media/Copy_One_Drag.svg" }; 175f857971dSopenharmony_ciconst std::string FORBID_DRAG_NAME { "/base/media/Forbid_Drag.svg" }; 176f857971dSopenharmony_ciconst std::string FORBID_ONE_DRAG_NAME { "/base/media/Forbid_One_Drag.svg" }; 177f857971dSopenharmony_ciconst std::string MOVE_DRAG_NAME { "/base/media/Move_Drag.svg" }; 178f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 179f857971dSopenharmony_ciconst std::string MOUSE_DRAG_DEFAULT_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Default.svg" }; 180f857971dSopenharmony_ciconst std::string MOUSE_DRAG_MAGIC_DEFAULT_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Magic_Default.svg" }; 181f857971dSopenharmony_ciconst std::string MOUSE_DRAG_CURSOR_CIRCLE_PATH { "/system/etc/device_status/drag_icon/Mouse_Drag_Cursor_Circle.png" }; 182f857971dSopenharmony_ciconst std::string DRAG_DROP_EXTENSION_SO_PATH { "/system/lib64/drag_drop_ext/libdrag_drop_ext.z.so" }; 183f857971dSopenharmony_ciconst std::string BIG_FOLDER_LABEL { "scb_folder" }; 184f857971dSopenharmony_cistruct DrawingInfo g_drawingInfo; 185f857971dSopenharmony_cistruct DragData g_dragData; 186f857971dSopenharmony_ci 187f857971dSopenharmony_cibool CheckNodesValid() 188f857971dSopenharmony_ci{ 189f857971dSopenharmony_ci FI_HILOGD("enter"); 190f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 191f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 192f857971dSopenharmony_ci return false; 193f857971dSopenharmony_ci } else if (g_drawingInfo.nodes.empty() || g_drawingInfo.nodes[DRAG_STYLE_INDEX] == nullptr) { 194f857971dSopenharmony_ci FI_HILOGE("Nodes invalid"); 195f857971dSopenharmony_ci return false; 196f857971dSopenharmony_ci } 197f857971dSopenharmony_ci if ((g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) && 198f857971dSopenharmony_ci (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT)) { 199f857971dSopenharmony_ci FI_HILOGE("Nodes size invalid when mouse type, node size:%{public}zu", g_drawingInfo.nodes.size()); 200f857971dSopenharmony_ci return false; 201f857971dSopenharmony_ci } 202f857971dSopenharmony_ci if ((g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && 203f857971dSopenharmony_ci (g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { 204f857971dSopenharmony_ci FI_HILOGE("Nodes size invalid when touchscreen type, node size:%{public}zu", g_drawingInfo.nodes.size()); 205f857971dSopenharmony_ci return false; 206f857971dSopenharmony_ci } 207f857971dSopenharmony_ci return true; 208f857971dSopenharmony_ci} 209f857971dSopenharmony_ci 210f857971dSopenharmony_cifloat GetScaling() 211f857971dSopenharmony_ci{ 212f857971dSopenharmony_ci if (g_drawingInfo.isExistScalingValue) { 213f857971dSopenharmony_ci return g_drawingInfo.scalingValue; 214f857971dSopenharmony_ci } 215f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 216f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 217f857971dSopenharmony_ci if (display == nullptr) { 218f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 219f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 220f857971dSopenharmony_ci if (display == nullptr) { 221f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 222f857971dSopenharmony_ci return DEFAULT_SCALING; 223f857971dSopenharmony_ci } 224f857971dSopenharmony_ci } 225f857971dSopenharmony_ci 226f857971dSopenharmony_ci int32_t deviceDpi = display->GetDpi(); 227f857971dSopenharmony_ci#else 228f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); 229f857971dSopenharmony_ci if (display == nullptr) { 230f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 231f857971dSopenharmony_ci return DEFAULT_SCALING; 232f857971dSopenharmony_ci } 233f857971dSopenharmony_ci sptr<Rosen::DisplayInfo> info = display->GetDisplayInfo(); 234f857971dSopenharmony_ci if (info == nullptr) { 235f857971dSopenharmony_ci FI_HILOGE("Get info failed, info is nullptr"); 236f857971dSopenharmony_ci return DEFAULT_SCALING; 237f857971dSopenharmony_ci } 238f857971dSopenharmony_ci int32_t deviceDpi = info->GetDensityDpi(); 239f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 240f857971dSopenharmony_ci FI_HILOGD("displayId:%{public}d, deviceDpi:%{public}d", g_drawingInfo.displayId, deviceDpi); 241f857971dSopenharmony_ci if (deviceDpi < -std::numeric_limits<float>::epsilon()) { 242f857971dSopenharmony_ci FI_HILOGE("Invalid deviceDpi:%{public}d", deviceDpi); 243f857971dSopenharmony_ci return DEFAULT_SCALING; 244f857971dSopenharmony_ci } 245f857971dSopenharmony_ci g_drawingInfo.scalingValue = (1.0 * deviceDpi * DEVICE_INDEPENDENT_PIXEL / BASELINE_DENSITY) / SVG_ORIGINAL_SIZE; 246f857971dSopenharmony_ci g_drawingInfo.isExistScalingValue = true; 247f857971dSopenharmony_ci return g_drawingInfo.scalingValue; 248f857971dSopenharmony_ci} 249f857971dSopenharmony_ci} // namespace 250f857971dSopenharmony_ci 251f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 252f857971dSopenharmony_ciint32_t DragDrawing::Init(const DragData &dragData, IContext* context) 253f857971dSopenharmony_ci#else 254f857971dSopenharmony_ciint32_t DragDrawing::Init(const DragData &dragData) 255f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 256f857971dSopenharmony_ci{ 257f857971dSopenharmony_ci FI_HILOGI("enter"); 258f857971dSopenharmony_ci int32_t checkDragDataResult = CheckDragData(dragData); 259f857971dSopenharmony_ci if (INIT_SUCCESS != checkDragDataResult) { 260f857971dSopenharmony_ci return checkDragDataResult; 261f857971dSopenharmony_ci } 262f857971dSopenharmony_ci InitDrawingInfo(dragData); 263f857971dSopenharmony_ci g_dragData = dragData; 264f857971dSopenharmony_ci CreateWindow(); 265f857971dSopenharmony_ci CHKPR(g_drawingInfo.surfaceNode, INIT_FAIL); 266f857971dSopenharmony_ci if (InitLayer() != RET_OK) { 267f857971dSopenharmony_ci FI_HILOGE("Init layer failed"); 268f857971dSopenharmony_ci return INIT_FAIL; 269f857971dSopenharmony_ci } 270f857971dSopenharmony_ci DragAnimationData dragAnimationData; 271f857971dSopenharmony_ci if (!CheckNodesValid() || InitDragAnimationData(dragAnimationData) != RET_OK) { 272f857971dSopenharmony_ci FI_HILOGE("Init drag animation data or check nodes valid failed"); 273f857971dSopenharmony_ci return INIT_FAIL; 274f857971dSopenharmony_ci } 275f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX || g_drawingInfo.nodes.size() <= PIXEL_MAP_INDEX) { 276f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 277f857971dSopenharmony_ci return INIT_FAIL; 278f857971dSopenharmony_ci } 279f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 280f857971dSopenharmony_ci CHKPR(shadowNode, INIT_FAIL); 281f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 282f857971dSopenharmony_ci CHKPR(dragStyleNode, INIT_FAIL); 283f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 284f857971dSopenharmony_ci LoadDragDropLib(); 285f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 286f857971dSopenharmony_ci OnStartDrag(dragAnimationData, shadowNode, dragStyleNode); 287f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty()) { 288f857971dSopenharmony_ci g_drawingInfo.isCurrentDefaultStyle = true; 289f857971dSopenharmony_ci UpdateDragStyle(DragCursorStyle::MOVE); 290f857971dSopenharmony_ci } 291f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 292f857971dSopenharmony_ci context_ = context; 293f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 294f857971dSopenharmony_ci CHKPR(rsUiDirector_, INIT_FAIL); 295f857971dSopenharmony_ci if (g_drawingInfo.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 296f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 297f857971dSopenharmony_ci return INIT_SUCCESS; 298f857971dSopenharmony_ci } 299f857971dSopenharmony_ci if (DrawMouseIcon() != RET_OK) { 300f857971dSopenharmony_ci FI_HILOGE("Draw mouse icon failed"); 301f857971dSopenharmony_ci return INIT_FAIL; 302f857971dSopenharmony_ci } 303f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 304f857971dSopenharmony_ci FI_HILOGI("leave"); 305f857971dSopenharmony_ci return INIT_SUCCESS; 306f857971dSopenharmony_ci} 307f857971dSopenharmony_ci 308f857971dSopenharmony_ciint32_t DragDrawing::CheckDragData(const DragData &dragData) 309f857971dSopenharmony_ci{ 310f857971dSopenharmony_ci if (g_drawingInfo.isRunning) { 311f857971dSopenharmony_ci FI_HILOGE("Drag drawing is running, can not init again"); 312f857971dSopenharmony_ci return INIT_CANCEL; 313f857971dSopenharmony_ci } 314f857971dSopenharmony_ci if (dragData.shadowInfos.empty()) { 315f857971dSopenharmony_ci FI_HILOGE("ShadowInfos is empty"); 316f857971dSopenharmony_ci return INIT_FAIL; 317f857971dSopenharmony_ci } 318f857971dSopenharmony_ci for (const auto &shadowInfo : dragData.shadowInfos) { 319f857971dSopenharmony_ci CHKPR(shadowInfo.pixelMap, INIT_FAIL); 320f857971dSopenharmony_ci } 321f857971dSopenharmony_ci if ((dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) && 322f857971dSopenharmony_ci (dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) { 323f857971dSopenharmony_ci FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); 324f857971dSopenharmony_ci return INIT_FAIL; 325f857971dSopenharmony_ci } 326f857971dSopenharmony_ci if (dragData.dragNum < 0) { 327f857971dSopenharmony_ci FI_HILOGE("Invalid dragNum:%{public}d", dragData.dragNum); 328f857971dSopenharmony_ci return INIT_FAIL; 329f857971dSopenharmony_ci } 330f857971dSopenharmony_ci return INIT_SUCCESS; 331f857971dSopenharmony_ci} 332f857971dSopenharmony_ci 333f857971dSopenharmony_civoid DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY, bool isNeedAdjustDisplayXY, 334f857971dSopenharmony_ci bool isMultiSelectedAnimation) 335f857971dSopenharmony_ci{ 336f857971dSopenharmony_ci if (isRunningRotateAnimation_) { 337f857971dSopenharmony_ci FI_HILOGD("Doing rotate drag window animate, ignore draw drag window"); 338f857971dSopenharmony_ci return; 339f857971dSopenharmony_ci } 340f857971dSopenharmony_ci if (displayId < 0) { 341f857971dSopenharmony_ci FI_HILOGE("Invalid displayId:%{public}d", displayId); 342f857971dSopenharmony_ci return; 343f857971dSopenharmony_ci } 344f857971dSopenharmony_ci int32_t mousePositionX = displayX; 345f857971dSopenharmony_ci int32_t mousePositionY = displayY; 346f857971dSopenharmony_ci if (isNeedAdjustDisplayXY) { 347f857971dSopenharmony_ci RotateDisplayXY(displayX, displayY); 348f857971dSopenharmony_ci mousePositionX = displayX; 349f857971dSopenharmony_ci mousePositionY = displayY; 350f857971dSopenharmony_ci g_drawingInfo.currentPositionX = static_cast<float>(displayX); 351f857971dSopenharmony_ci g_drawingInfo.currentPositionY = static_cast<float>(displayY); 352f857971dSopenharmony_ci AdjustRotateDisplayXY(displayX, displayY); 353f857971dSopenharmony_ci } 354f857971dSopenharmony_ci g_drawingInfo.displayId = displayId; 355f857971dSopenharmony_ci g_drawingInfo.displayX = displayX; 356f857971dSopenharmony_ci g_drawingInfo.displayY = displayY; 357f857971dSopenharmony_ci if (displayX < 0) { 358f857971dSopenharmony_ci g_drawingInfo.displayX = 0; 359f857971dSopenharmony_ci } 360f857971dSopenharmony_ci if (displayY < 0) { 361f857971dSopenharmony_ci g_drawingInfo.displayY = 0; 362f857971dSopenharmony_ci } 363f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 364f857971dSopenharmony_ci int32_t positionX = g_drawingInfo.displayX + g_drawingInfo.pixelMapX; 365f857971dSopenharmony_ci int32_t positionY = g_drawingInfo.displayY + g_drawingInfo.pixelMapY - adjustSize; 366f857971dSopenharmony_ci CHKPV(g_drawingInfo.parentNode); 367f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 368f857971dSopenharmony_ci g_drawingInfo.parentNode->SetBounds(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(), 369f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight() + adjustSize); 370f857971dSopenharmony_ci g_drawingInfo.parentNode->SetFrame(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(), 371f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight() + adjustSize); 372f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 373f857971dSopenharmony_ci DoDrawMouse(mousePositionX, mousePositionY); 374f857971dSopenharmony_ci } 375f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty() && !g_drawingInfo.multiSelectedPixelMaps.empty()) { 376f857971dSopenharmony_ci MultiSelectedAnimation(positionX, positionY, adjustSize, isMultiSelectedAnimation); 377f857971dSopenharmony_ci } 378f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 379f857971dSopenharmony_ci} 380f857971dSopenharmony_ci 381f857971dSopenharmony_civoid DragDrawing::UpdateDragPosition(int32_t displayId, float displayX, float displayY) 382f857971dSopenharmony_ci{ 383f857971dSopenharmony_ci if (displayId < 0) { 384f857971dSopenharmony_ci FI_HILOGE("Invalid displayId:%{public}d", displayId); 385f857971dSopenharmony_ci return; 386f857971dSopenharmony_ci } 387f857971dSopenharmony_ci RotatePosition(displayX, displayY); 388f857971dSopenharmony_ci g_drawingInfo.currentPositionX = displayX; 389f857971dSopenharmony_ci g_drawingInfo.currentPositionY = displayY; 390f857971dSopenharmony_ci g_drawingInfo.displayId = displayId; 391f857971dSopenharmony_ci g_drawingInfo.displayX = static_cast<int32_t>(displayX); 392f857971dSopenharmony_ci g_drawingInfo.displayY = static_cast<int32_t>(displayY); 393f857971dSopenharmony_ci float mousePositionX = displayX; 394f857971dSopenharmony_ci float mousePositionY = displayY; 395f857971dSopenharmony_ci AdjustRotateDisplayXY(displayX, displayY); 396f857971dSopenharmony_ci g_drawingInfo.x = displayX; 397f857971dSopenharmony_ci g_drawingInfo.y = displayY; 398f857971dSopenharmony_ci if (displayX < 0) { 399f857971dSopenharmony_ci g_drawingInfo.displayX = 0; 400f857971dSopenharmony_ci } 401f857971dSopenharmony_ci if (displayY < 0) { 402f857971dSopenharmony_ci g_drawingInfo.displayY = 0; 403f857971dSopenharmony_ci } 404f857971dSopenharmony_ci float adjustSize = TWELVE_SIZE * GetScaling(); 405f857971dSopenharmony_ci float positionX = g_drawingInfo.x + g_drawingInfo.pixelMapX; 406f857971dSopenharmony_ci float positionY = g_drawingInfo.y + g_drawingInfo.pixelMapY - adjustSize; 407f857971dSopenharmony_ci auto parentNode = g_drawingInfo.parentNode; 408f857971dSopenharmony_ci auto pixelMap = g_drawingInfo.pixelMap; 409f857971dSopenharmony_ci CHKPV(parentNode); 410f857971dSopenharmony_ci CHKPV(pixelMap); 411f857971dSopenharmony_ci parentNode->SetBounds(positionX, positionY, pixelMap->GetWidth(), 412f857971dSopenharmony_ci pixelMap->GetHeight() + adjustSize); 413f857971dSopenharmony_ci parentNode->SetFrame(positionX, positionY, pixelMap->GetWidth(), 414f857971dSopenharmony_ci pixelMap->GetHeight() + adjustSize); 415f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 416f857971dSopenharmony_ci UpdateMousePosition(mousePositionX, mousePositionY); 417f857971dSopenharmony_ci } 418f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty() && !g_drawingInfo.multiSelectedPixelMaps.empty()) { 419f857971dSopenharmony_ci DoMultiSelectedAnimation(positionX, positionY, adjustSize); 420f857971dSopenharmony_ci } 421f857971dSopenharmony_ci if (rsUiDirector_ != nullptr) { 422f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 423f857971dSopenharmony_ci } else { 424f857971dSopenharmony_ci FI_HILOGE("rsUiDirector_ is nullptr"); 425f857971dSopenharmony_ci } 426f857971dSopenharmony_ci} 427f857971dSopenharmony_ci 428f857971dSopenharmony_civoid DragDrawing::DoMultiSelectedAnimation(float positionX, float positionY, float adjustSize, 429f857971dSopenharmony_ci bool isMultiSelectedAnimation) 430f857971dSopenharmony_ci{ 431f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 432f857971dSopenharmony_ci size_t multiSelectedPixelMapsSize = g_drawingInfo.multiSelectedPixelMaps.size(); 433f857971dSopenharmony_ci for (size_t i = 0; (i < multiSelectedNodesSize) && (i < multiSelectedPixelMapsSize); ++i) { 434f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = g_drawingInfo.multiSelectedNodes[i]; 435f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> multiSelectedPixelMap = g_drawingInfo.multiSelectedPixelMaps[i]; 436f857971dSopenharmony_ci auto pixelMap = g_drawingInfo.pixelMap; 437f857971dSopenharmony_ci CHKPV(pixelMap); 438f857971dSopenharmony_ci CHKPV(multiSelectedNode); 439f857971dSopenharmony_ci CHKPV(multiSelectedPixelMap); 440f857971dSopenharmony_ci float multiSelectedPositionX = positionX + (static_cast<float>(pixelMap->GetWidth()) / TWICE_SIZE) - 441f857971dSopenharmony_ci (static_cast<float>(multiSelectedPixelMap->GetWidth()) / TWICE_SIZE); 442f857971dSopenharmony_ci float multiSelectedPositionY = positionY + (static_cast<float>(pixelMap->GetHeight()) / TWICE_SIZE) - 443f857971dSopenharmony_ci (static_cast<float>(multiSelectedPixelMap->GetHeight()) / TWICE_SIZE - adjustSize); 444f857971dSopenharmony_ci if (isMultiSelectedAnimation) { 445f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 446f857971dSopenharmony_ci if (i == FIRST_PIXELMAP_INDEX) { 447f857971dSopenharmony_ci protocol.SetDuration(SHORT_DURATION); 448f857971dSopenharmony_ci } else { 449f857971dSopenharmony_ci protocol.SetDuration(LONG_DURATION); 450f857971dSopenharmony_ci } 451f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { 452f857971dSopenharmony_ci multiSelectedNode->SetBounds(multiSelectedPositionX, multiSelectedPositionY, 453f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 454f857971dSopenharmony_ci multiSelectedNode->SetFrame(multiSelectedPositionX, multiSelectedPositionY, 455f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 456f857971dSopenharmony_ci }, []() { FI_HILOGD("DoMultiSelectedAnimation end"); }); 457f857971dSopenharmony_ci } else { 458f857971dSopenharmony_ci multiSelectedNode->SetBounds(multiSelectedPositionX, multiSelectedPositionY, 459f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 460f857971dSopenharmony_ci multiSelectedNode->SetFrame(multiSelectedPositionX, multiSelectedPositionY, 461f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 462f857971dSopenharmony_ci } 463f857971dSopenharmony_ci } 464f857971dSopenharmony_ci} 465f857971dSopenharmony_ci 466f857971dSopenharmony_ciint32_t DragDrawing::UpdateDragStyle(DragCursorStyle style) 467f857971dSopenharmony_ci{ 468f857971dSopenharmony_ci FI_HILOGD("style:%{public}d", style); 469f857971dSopenharmony_ci if ((style < DragCursorStyle::DEFAULT) || (style > DragCursorStyle::MOVE)) { 470f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 471f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 472f857971dSopenharmony_ci DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); 473f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 474f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 475f857971dSopenharmony_ci FI_HILOGE("Invalid style:%{public}d", style); 476f857971dSopenharmony_ci return RET_ERR; 477f857971dSopenharmony_ci } 478f857971dSopenharmony_ci if ((style == DragCursorStyle::DEFAULT) || 479f857971dSopenharmony_ci ((style == DragCursorStyle::MOVE) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE))) { 480f857971dSopenharmony_ci return UpdateDefaultDragStyle(style); 481f857971dSopenharmony_ci } 482f857971dSopenharmony_ci return UpdateValidDragStyle(style); 483f857971dSopenharmony_ci} 484f857971dSopenharmony_ci 485f857971dSopenharmony_ciint32_t DragDrawing::UpdateShadowPic(const ShadowInfo &shadowInfo) 486f857971dSopenharmony_ci{ 487f857971dSopenharmony_ci FI_HILOGD("enter"); 488f857971dSopenharmony_ci CHKPR(shadowInfo.pixelMap, RET_ERR); 489f857971dSopenharmony_ci g_drawingInfo.pixelMap = shadowInfo.pixelMap; 490f857971dSopenharmony_ci g_drawingInfo.pixelMapX = shadowInfo.x; 491f857971dSopenharmony_ci g_drawingInfo.pixelMapY = shadowInfo.y; 492f857971dSopenharmony_ci if (!CheckNodesValid()) { 493f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 494f857971dSopenharmony_ci return RET_ERR; 495f857971dSopenharmony_ci } 496f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= PIXEL_MAP_INDEX) { 497f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 498f857971dSopenharmony_ci return RET_ERR; 499f857971dSopenharmony_ci } 500f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 501f857971dSopenharmony_ci CHKPR(shadowNode, RET_ERR); 502f857971dSopenharmony_ci DrawShadow(shadowNode); 503f857971dSopenharmony_ci float scalingValue = GetScaling(); 504f857971dSopenharmony_ci if (SCALE_THRESHOLD_TWELVE < scalingValue || fabsf(SCALE_THRESHOLD_TWELVE - scalingValue) < EPSILON) { 505f857971dSopenharmony_ci FI_HILOGE("Invalid scalingValue:%{public}f", scalingValue); 506f857971dSopenharmony_ci return RET_ERR; 507f857971dSopenharmony_ci } 508f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 509f857971dSopenharmony_ci DrawMouseIcon(); 510f857971dSopenharmony_ci } 511f857971dSopenharmony_ci ProcessFilter(); 512f857971dSopenharmony_ci Draw(g_drawingInfo.displayId, g_drawingInfo.displayX, g_drawingInfo.displayY, false); 513f857971dSopenharmony_ci RotateDragWindow(rotation_); 514f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 515f857971dSopenharmony_ci CHKPR(rsUiDirector_, RET_ERR); 516f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 517f857971dSopenharmony_ci FI_HILOGD("leave"); 518f857971dSopenharmony_ci return RET_OK; 519f857971dSopenharmony_ci} 520f857971dSopenharmony_ci 521f857971dSopenharmony_ciint32_t DragDrawing::UpdatePixelMapsAngleAndAlpha() 522f857971dSopenharmony_ci{ 523f857971dSopenharmony_ci FI_HILOGD("enter"); 524f857971dSopenharmony_ci size_t mulNodesSize = g_drawingInfo.multiSelectedNodes.size(); 525f857971dSopenharmony_ci if (mulNodesSize <= 0) { 526f857971dSopenharmony_ci FI_HILOGE("No pixelmap add"); 527f857971dSopenharmony_ci return RET_ERR; 528f857971dSopenharmony_ci } 529f857971dSopenharmony_ci if (mulNodesSize == 1) { 530f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.front()->SetRotation(POSITIVE_ANGLE); 531f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.front()->SetAlpha(FIRST_PIXELMAP_ALPHA); 532f857971dSopenharmony_ci } else if (mulNodesSize == LAST_SECOND_PIXELMAP) { 533f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.back()->SetRotation(NEGATIVE_ANGLE); 534f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.back()->SetAlpha(SECOND_PIXELMAP_ALPHA); 535f857971dSopenharmony_ci } else { 536f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveChild(g_drawingInfo.multiSelectedNodes[mulNodesSize - LAST_THIRD_PIXELMAP]); 537f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes[mulNodesSize - LAST_SECOND_PIXELMAP ]->SetRotation(POSITIVE_ANGLE); 538f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes[mulNodesSize - LAST_SECOND_PIXELMAP ]->SetAlpha(FIRST_PIXELMAP_ALPHA); 539f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.back()->SetRotation(NEGATIVE_ANGLE); 540f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.back()->SetAlpha(SECOND_PIXELMAP_ALPHA); 541f857971dSopenharmony_ci } 542f857971dSopenharmony_ci FI_HILOGD("leave"); 543f857971dSopenharmony_ci return RET_OK; 544f857971dSopenharmony_ci} 545f857971dSopenharmony_ci 546f857971dSopenharmony_ciint32_t DragDrawing::UpdatePixeMapDrawingOrder() 547f857971dSopenharmony_ci{ 548f857971dSopenharmony_ci FI_HILOGD("enter"); 549f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 550f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 551f857971dSopenharmony_ci CHKPR(pixelMapNode, RET_ERR); 552f857971dSopenharmony_ci CHKPR(dragStyleNode, RET_ERR); 553f857971dSopenharmony_ci CHKPR(g_drawingInfo.parentNode, RET_ERR); 554f857971dSopenharmony_ci CHKPR(g_drawingInfo.rootNode, RET_ERR); 555f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.emplace_back(pixelMapNode); 556f857971dSopenharmony_ci g_drawingInfo.parentNode->RemoveChild(dragStyleNode); 557f857971dSopenharmony_ci g_drawingInfo.parentNode->RemoveChild(pixelMapNode); 558f857971dSopenharmony_ci 559f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 560f857971dSopenharmony_ci int32_t positionX = g_drawingInfo.displayX + g_drawingInfo.pixelMapX; 561f857971dSopenharmony_ci int32_t positionY = g_drawingInfo.displayY + g_drawingInfo.pixelMapY - adjustSize; 562f857971dSopenharmony_ci int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); 563f857971dSopenharmony_ci int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight(); 564f857971dSopenharmony_ci pixelMapNode->SetBounds(positionX, positionY + adjustSize, pixelMapWidth, pixelMapHeight); 565f857971dSopenharmony_ci pixelMapNode->SetFrame(positionX, positionY + adjustSize, pixelMapWidth, pixelMapHeight); 566f857971dSopenharmony_ci 567f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> addSelectedNode = Rosen::RSCanvasNode::Create(); 568f857971dSopenharmony_ci CHKPR(addSelectedNode, RET_ERR); 569f857971dSopenharmony_ci g_drawingInfo.nodes[PIXEL_MAP_INDEX] = addSelectedNode; 570f857971dSopenharmony_ci g_drawingInfo.parentNode->AddChild(addSelectedNode); 571f857971dSopenharmony_ci g_drawingInfo.parentNode->AddChild(dragStyleNode); 572f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(g_drawingInfo.multiSelectedNodes.back()); 573f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveChild(g_drawingInfo.parentNode); 574f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(g_drawingInfo.parentNode); 575f857971dSopenharmony_ci 576f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 577f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 578f857971dSopenharmony_ci CHKPR(mouseIconNode, RET_ERR); 579f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveChild(mouseIconNode); 580f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(mouseIconNode); 581f857971dSopenharmony_ci } 582f857971dSopenharmony_ci 583f857971dSopenharmony_ci if (UpdatePixelMapsAngleAndAlpha() != RET_OK) { 584f857971dSopenharmony_ci FI_HILOGE("setPixelMapsAngleAndAlpha failed"); 585f857971dSopenharmony_ci return RET_ERR; 586f857971dSopenharmony_ci } 587f857971dSopenharmony_ci DrawShadow(pixelMapNode); 588f857971dSopenharmony_ci FI_HILOGD("leave"); 589f857971dSopenharmony_ci return RET_OK; 590f857971dSopenharmony_ci} 591f857971dSopenharmony_ci 592f857971dSopenharmony_ciint32_t DragDrawing::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) 593f857971dSopenharmony_ci{ 594f857971dSopenharmony_ci FI_HILOGD("enter"); 595f857971dSopenharmony_ci CHKPR(pixelMap, RET_ERR); 596f857971dSopenharmony_ci if (!CheckNodesValid()) { 597f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 598f857971dSopenharmony_ci return RET_ERR; 599f857971dSopenharmony_ci } 600f857971dSopenharmony_ci 601f857971dSopenharmony_ci g_drawingInfo.multiSelectedPixelMaps.emplace_back(g_drawingInfo.pixelMap); 602f857971dSopenharmony_ci g_drawingInfo.pixelMap = pixelMap; 603f857971dSopenharmony_ci if (UpdatePixeMapDrawingOrder() != RET_OK) { 604f857971dSopenharmony_ci FI_HILOGE("Update pixeMap drawing order failed"); 605f857971dSopenharmony_ci return RET_ERR; 606f857971dSopenharmony_ci } 607f857971dSopenharmony_ci Draw(g_drawingInfo.displayId, g_drawingInfo.displayX, g_drawingInfo.displayY, false); 608f857971dSopenharmony_ci g_drawingInfo.currentDragNum = g_drawingInfo.multiSelectedPixelMaps.size() + 1; 609f857971dSopenharmony_ci if (UpdateDragStyle(g_drawingInfo.currentStyle) != RET_OK) { 610f857971dSopenharmony_ci FI_HILOGE("Update drag style failed"); 611f857971dSopenharmony_ci return RET_ERR; 612f857971dSopenharmony_ci } 613f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 614f857971dSopenharmony_ci FI_HILOGD("leave"); 615f857971dSopenharmony_ci return RET_OK; 616f857971dSopenharmony_ci} 617f857971dSopenharmony_ci 618f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 619f857971dSopenharmony_civoid DragDrawing::OnDragSuccess(IContext* context) 620f857971dSopenharmony_ci#else 621f857971dSopenharmony_civoid DragDrawing::OnDragSuccess() 622f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 623f857971dSopenharmony_ci{ 624f857971dSopenharmony_ci FI_HILOGI("enter"); 625f857971dSopenharmony_ci if (!CheckNodesValid()) { 626f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 627f857971dSopenharmony_ci return; 628f857971dSopenharmony_ci } 629f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= PIXEL_MAP_INDEX || g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 630f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 631f857971dSopenharmony_ci return; 632f857971dSopenharmony_ci } 633f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> shadowNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 634f857971dSopenharmony_ci CHKPV(shadowNode); 635f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> styleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 636f857971dSopenharmony_ci CHKPV(styleNode); 637f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 638f857971dSopenharmony_ci g_drawingInfo.context = context; 639f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 640f857971dSopenharmony_ci OnStopDragSuccess(shadowNode, styleNode); 641f857971dSopenharmony_ci FI_HILOGI("leave"); 642f857971dSopenharmony_ci} 643f857971dSopenharmony_ci 644f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 645f857971dSopenharmony_civoid DragDrawing::OnDragFail(IContext* context) 646f857971dSopenharmony_ci#else 647f857971dSopenharmony_civoid DragDrawing::OnDragFail() 648f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 649f857971dSopenharmony_ci{ 650f857971dSopenharmony_ci FI_HILOGI("enter"); 651f857971dSopenharmony_ci std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode = g_drawingInfo.surfaceNode; 652f857971dSopenharmony_ci CHKPV(surfaceNode); 653f857971dSopenharmony_ci std::shared_ptr<Rosen::RSNode> rootNode = g_drawingInfo.rootNode; 654f857971dSopenharmony_ci CHKPV(rootNode); 655f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 656f857971dSopenharmony_ci g_drawingInfo.context = context; 657f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 658f857971dSopenharmony_ci OnStopDragFail(surfaceNode, rootNode); 659f857971dSopenharmony_ci FI_HILOGI("leave"); 660f857971dSopenharmony_ci} 661f857971dSopenharmony_ci 662f857971dSopenharmony_civoid DragDrawing::EraseMouseIcon() 663f857971dSopenharmony_ci{ 664f857971dSopenharmony_ci FI_HILOGI("enter"); 665f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { 666f857971dSopenharmony_ci FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); 667f857971dSopenharmony_ci return; 668f857971dSopenharmony_ci } 669f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) { 670f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 671f857971dSopenharmony_ci return; 672f857971dSopenharmony_ci } 673f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 674f857971dSopenharmony_ci CHKPV(mouseIconNode); 675f857971dSopenharmony_ci if (drawMouseIconModifier_ != nullptr) { 676f857971dSopenharmony_ci mouseIconNode->RemoveModifier(drawMouseIconModifier_); 677f857971dSopenharmony_ci drawMouseIconModifier_ = nullptr; 678f857971dSopenharmony_ci } 679f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 680f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveChild(mouseIconNode); 681f857971dSopenharmony_ci CHKPV(rsUiDirector_); 682f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 683f857971dSopenharmony_ci FI_HILOGI("leave"); 684f857971dSopenharmony_ci} 685f857971dSopenharmony_ci 686f857971dSopenharmony_civoid DragDrawing::DestroyDragWindow() 687f857971dSopenharmony_ci{ 688f857971dSopenharmony_ci FI_HILOGI("enter"); 689f857971dSopenharmony_ci ResetParameter(); 690f857971dSopenharmony_ci RemoveModifier(); 691f857971dSopenharmony_ci ClearMultiSelectedData(); 692f857971dSopenharmony_ci if (!g_drawingInfo.nodes.empty()) { 693f857971dSopenharmony_ci g_drawingInfo.nodes.clear(); 694f857971dSopenharmony_ci g_drawingInfo.nodes.shrink_to_fit(); 695f857971dSopenharmony_ci } 696f857971dSopenharmony_ci if (g_drawingInfo.parentNode != nullptr) { 697f857971dSopenharmony_ci g_drawingInfo.parentNode->ClearChildren(); 698f857971dSopenharmony_ci g_drawingInfo.parentNode.reset(); 699f857971dSopenharmony_ci g_drawingInfo.parentNode = nullptr; 700f857971dSopenharmony_ci } 701f857971dSopenharmony_ci if (g_drawingInfo.rootNode != nullptr) { 702f857971dSopenharmony_ci g_drawingInfo.rootNode->ClearChildren(); 703f857971dSopenharmony_ci g_drawingInfo.rootNode.reset(); 704f857971dSopenharmony_ci g_drawingInfo.rootNode = nullptr; 705f857971dSopenharmony_ci } 706f857971dSopenharmony_ci if (g_drawingInfo.surfaceNode != nullptr) { 707f857971dSopenharmony_ci g_drawingInfo.surfaceNode->DetachToDisplay(screenId_); 708f857971dSopenharmony_ci screenId_ = 0; 709f857971dSopenharmony_ci g_drawingInfo.displayId = -1; 710f857971dSopenharmony_ci g_drawingInfo.surfaceNode = nullptr; 711f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 712f857971dSopenharmony_ci } 713f857971dSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ARKUI_X 714f857971dSopenharmony_ci CHKPV(callback_); 715f857971dSopenharmony_ci callback_(); 716f857971dSopenharmony_ci window_ = nullptr; 717f857971dSopenharmony_ci g_dragData = {}; 718f857971dSopenharmony_ci g_drawingInfo.pixelMap = nullptr; 719f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 720f857971dSopenharmony_ci CHKPV(rsUiDirector_); 721f857971dSopenharmony_ci rsUiDirector_->SetRoot(-1); 722f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 723f857971dSopenharmony_ci FI_HILOGI("leave"); 724f857971dSopenharmony_ci} 725f857971dSopenharmony_ci 726f857971dSopenharmony_civoid DragDrawing::UpdateDrawingState() 727f857971dSopenharmony_ci{ 728f857971dSopenharmony_ci FI_HILOGD("enter"); 729f857971dSopenharmony_ci g_drawingInfo.isRunning = false; 730f857971dSopenharmony_ci FI_HILOGD("leave"); 731f857971dSopenharmony_ci} 732f857971dSopenharmony_ci 733f857971dSopenharmony_civoid DragDrawing::UpdateDragWindowState(bool visible) 734f857971dSopenharmony_ci{ 735f857971dSopenharmony_ci CHKPV(g_drawingInfo.surfaceNode); 736f857971dSopenharmony_ci if (visible) { 737f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetVisible(true); 738f857971dSopenharmony_ci FI_HILOGI("Drag surfaceNode show success"); 739f857971dSopenharmony_ci } else { 740f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetVisible(false); 741f857971dSopenharmony_ci FI_HILOGI("Drag surfaceNode hide success"); 742f857971dSopenharmony_ci } 743f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 744f857971dSopenharmony_ci} 745f857971dSopenharmony_ci 746f857971dSopenharmony_civoid DragDrawing::OnStartDrag(const DragAnimationData &dragAnimationData, 747f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> shadowNode, std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode) 748f857971dSopenharmony_ci{ 749f857971dSopenharmony_ci FI_HILOGI("enter"); 750f857971dSopenharmony_ci CHKPV(shadowNode); 751f857971dSopenharmony_ci if (DrawShadow(shadowNode) != RET_OK) { 752f857971dSopenharmony_ci FI_HILOGE("Draw shadow failed"); 753f857971dSopenharmony_ci return; 754f857971dSopenharmony_ci } 755f857971dSopenharmony_ci g_drawingInfo.isCurrentDefaultStyle = true; 756f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 757f857971dSopenharmony_ci if (dragExtHandler_ == nullptr) { 758f857971dSopenharmony_ci FI_HILOGE("Fail to open drag drop extension library"); 759f857971dSopenharmony_ci return; 760f857971dSopenharmony_ci } 761f857971dSopenharmony_ci auto dragDropStartExtFunc = reinterpret_cast<DragStartExtFunc>(dlsym(dragExtHandler_, "OnStartDragExt")); 762f857971dSopenharmony_ci if (dragDropStartExtFunc == nullptr) { 763f857971dSopenharmony_ci FI_HILOGE("Fail to get drag drop extension function"); 764f857971dSopenharmony_ci CHKPV(dragExtHandler_); 765f857971dSopenharmony_ci dlclose(dragExtHandler_); 766f857971dSopenharmony_ci dragExtHandler_ = nullptr; 767f857971dSopenharmony_ci return; 768f857971dSopenharmony_ci } 769f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_ANIMATION 770f857971dSopenharmony_ci if (!GetSuperHubHandler()->PostTask([dragDropStartExtFunc] { return dragDropStartExtFunc(g_dragData); })) { 771f857971dSopenharmony_ci FI_HILOGE("Start style animation failed"); 772f857971dSopenharmony_ci } 773f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_ANIMATION 774f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 775f857971dSopenharmony_ci FI_HILOGI("leave"); 776f857971dSopenharmony_ci} 777f857971dSopenharmony_ci 778f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 779f857971dSopenharmony_civoid DragDrawing::NotifyDragInfo(const std::string &sourceName, const std::string &targetName) 780f857971dSopenharmony_ci{ 781f857971dSopenharmony_ci FI_HILOGI("NotifyDragInfo"); 782f857971dSopenharmony_ci if (dragExtHandler_ == nullptr) { 783f857971dSopenharmony_ci FI_HILOGE("Fail to open drag drop extension library"); 784f857971dSopenharmony_ci return; 785f857971dSopenharmony_ci } 786f857971dSopenharmony_ci auto dragDropExtFunc = reinterpret_cast<DragNotifyExtFunc>(dlsym(dragExtHandler_, "OnNotifyDragInfo")); 787f857971dSopenharmony_ci if (dragDropExtFunc == nullptr) { 788f857971dSopenharmony_ci FI_HILOGE("Fail to get drag drop extension function"); 789f857971dSopenharmony_ci CHKPV(dragExtHandler_); 790f857971dSopenharmony_ci dlclose(dragExtHandler_); 791f857971dSopenharmony_ci dragExtHandler_ = nullptr; 792f857971dSopenharmony_ci return; 793f857971dSopenharmony_ci } 794f857971dSopenharmony_ci struct DragEventInfo dragEventInfo; 795f857971dSopenharmony_ci dragEventInfo.sourcePkgName = sourceName; 796f857971dSopenharmony_ci dragEventInfo.targetPkgName = targetName; 797f857971dSopenharmony_ci if (!GetSuperHubHandler()->PostTask([dragDropExtFunc, dragEventInfo] () 798f857971dSopenharmony_ci mutable { return dragDropExtFunc(dragEventInfo); })) { 799f857971dSopenharmony_ci FI_HILOGE("notify drag info failed"); 800f857971dSopenharmony_ci } 801f857971dSopenharmony_ci} 802f857971dSopenharmony_ci 803f857971dSopenharmony_cistd::shared_ptr<AppExecFwk::EventHandler> DragDrawing::GetSuperHubHandler() 804f857971dSopenharmony_ci{ 805f857971dSopenharmony_ci if (superHubHandler_ == nullptr) { 806f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(SUPER_HUB_THREAD_NAME); 807f857971dSopenharmony_ci superHubHandler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 808f857971dSopenharmony_ci } 809f857971dSopenharmony_ci return superHubHandler_; 810f857971dSopenharmony_ci} 811f857971dSopenharmony_ci 812f857971dSopenharmony_civoid DragDrawing::ResetSuperHubHandler() 813f857971dSopenharmony_ci{ 814f857971dSopenharmony_ci if (superHubHandler_ != nullptr) { 815f857971dSopenharmony_ci superHubHandler_->RemoveAllEvents(); 816f857971dSopenharmony_ci superHubHandler_ = nullptr; 817f857971dSopenharmony_ci } 818f857971dSopenharmony_ci} 819f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 820f857971dSopenharmony_ci 821f857971dSopenharmony_cifloat DragDrawing::AdjustDoubleValue(double doubleValue) 822f857971dSopenharmony_ci{ 823f857971dSopenharmony_ci FI_HILOGI("doubleValue is %{public}f", doubleValue); 824f857971dSopenharmony_ci float dragOriginDpi = DRAG_DATA_MGR.GetDragOriginDpi(); 825f857971dSopenharmony_ci if (dragOriginDpi > EPSILON) { 826f857971dSopenharmony_ci float scalingValue = GetScaling() / dragOriginDpi; 827f857971dSopenharmony_ci doubleValue = doubleValue * scalingValue; 828f857971dSopenharmony_ci if (fabs(scalingValue - 1.0f) > EPSILON) { 829f857971dSopenharmony_ci float widthScale = CalculateWidthScale(); 830f857971dSopenharmony_ci doubleValue = doubleValue * widthScale; 831f857971dSopenharmony_ci } 832f857971dSopenharmony_ci } 833f857971dSopenharmony_ci float floatValue = static_cast<float>(doubleValue); 834f857971dSopenharmony_ci FI_HILOGI("floatValue is %{public}f", floatValue); 835f857971dSopenharmony_ci return floatValue; 836f857971dSopenharmony_ci} 837f857971dSopenharmony_ci 838f857971dSopenharmony_civoid DragDrawing::CheckStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode) 839f857971dSopenharmony_ci{ 840f857971dSopenharmony_ci FI_HILOGD("enter"); 841f857971dSopenharmony_ci CHKPV(styleNode); 842f857971dSopenharmony_ci if (drawStyleChangeModifier_ != nullptr) { 843f857971dSopenharmony_ci styleNode->RemoveModifier(drawStyleChangeModifier_); 844f857971dSopenharmony_ci drawStyleChangeModifier_ = nullptr; 845f857971dSopenharmony_ci } 846f857971dSopenharmony_ci if (drawStyleScaleModifier_ != nullptr && hasRunningScaleAnimation_) { 847f857971dSopenharmony_ci needBreakStyleScaleAnimation_ = true; 848f857971dSopenharmony_ci } 849f857971dSopenharmony_ci styleNode->RemoveAllAnimations(); 850f857971dSopenharmony_ci FI_HILOGD("leave"); 851f857971dSopenharmony_ci} 852f857971dSopenharmony_ci 853f857971dSopenharmony_civoid DragDrawing::RemoveStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> styleNode) 854f857971dSopenharmony_ci{ 855f857971dSopenharmony_ci FI_HILOGD("enter"); 856f857971dSopenharmony_ci CHKPV(styleNode); 857f857971dSopenharmony_ci if (drawStyleChangeModifier_ != nullptr) { 858f857971dSopenharmony_ci styleNode->RemoveModifier(drawStyleChangeModifier_); 859f857971dSopenharmony_ci drawStyleChangeModifier_ = nullptr; 860f857971dSopenharmony_ci } 861f857971dSopenharmony_ci if (drawStyleScaleModifier_ != nullptr) { 862f857971dSopenharmony_ci styleNode->RemoveModifier(drawStyleScaleModifier_); 863f857971dSopenharmony_ci drawStyleScaleModifier_ = nullptr; 864f857971dSopenharmony_ci } 865f857971dSopenharmony_ci FI_HILOGD("leave"); 866f857971dSopenharmony_ci} 867f857971dSopenharmony_ci 868f857971dSopenharmony_civoid DragDrawing::UpdateAnimationProtocol(Rosen::RSAnimationTimingProtocol protocol) 869f857971dSopenharmony_ci{ 870f857971dSopenharmony_ci FI_HILOGD("enter"); 871f857971dSopenharmony_ci g_drawingInfo.startNum = START_TIME; 872f857971dSopenharmony_ci interruptNum_ = START_TIME * INTERRUPT_SCALE; 873f857971dSopenharmony_ci hasRunningAnimation_ = true; 874f857971dSopenharmony_ci bool stopSignal = true; 875f857971dSopenharmony_ci CHKPV(rsUiDirector_); 876f857971dSopenharmony_ci while (hasRunningAnimation_) { 877f857971dSopenharmony_ci hasRunningAnimation_ = rsUiDirector_->FlushAnimation(g_drawingInfo.startNum); 878f857971dSopenharmony_ci rsUiDirector_->FlushModifier(); 879f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 880f857971dSopenharmony_ci if ((g_drawingInfo.startNum >= interruptNum_) && stopSignal) { 881f857971dSopenharmony_ci protocol.SetDuration(TIME_STOP); 882f857971dSopenharmony_ci stopSignal = false; 883f857971dSopenharmony_ci } 884f857971dSopenharmony_ci g_drawingInfo.startNum += INTERVAL_TIME; 885f857971dSopenharmony_ci usleep(TIME_SLEEP); 886f857971dSopenharmony_ci } 887f857971dSopenharmony_ci FI_HILOGD("leave"); 888f857971dSopenharmony_ci} 889f857971dSopenharmony_ci 890f857971dSopenharmony_civoid DragDrawing::StartStyleAnimation(float startScale, float endScale, int32_t duration) 891f857971dSopenharmony_ci{ 892f857971dSopenharmony_ci FI_HILOGI("StartStyleAnimation, startScale is %{public}lf", startScale); 893f857971dSopenharmony_ci if (!CheckNodesValid() || needBreakStyleScaleAnimation_ || hasRunningStopAnimation_) { 894f857971dSopenharmony_ci FI_HILOGE("needBreakStyleScaleAnimation_ or hasRunningStopAnimation_, return"); 895f857971dSopenharmony_ci return; 896f857971dSopenharmony_ci } 897f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 898f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 899f857971dSopenharmony_ci return; 900f857971dSopenharmony_ci } 901f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 902f857971dSopenharmony_ci CHKPV(dragStyleNode); 903f857971dSopenharmony_ci RemoveStyleNodeModifier(dragStyleNode); 904f857971dSopenharmony_ci drawStyleScaleModifier_ = std::make_shared<DrawStyleScaleModifier>(); 905f857971dSopenharmony_ci dragStyleNode->AddModifier(drawStyleScaleModifier_); 906f857971dSopenharmony_ci CHKPV(drawStyleScaleModifier_); 907f857971dSopenharmony_ci drawStyleScaleModifier_->SetScale(startScale); 908f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 909f857971dSopenharmony_ci protocol.SetDuration(duration); 910f857971dSopenharmony_ci auto springCurveStyle = endScale == STYLE_END_SCALE 911f857971dSopenharmony_ci ? Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_030, BEZIER_000, BEZIER_040, BEZIER_100) 912f857971dSopenharmony_ci : Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_020, BEZIER_000, BEZIER_060, BEZIER_100); 913f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, springCurveStyle, [&]() { 914f857971dSopenharmony_ci if (drawStyleScaleModifier_ != nullptr) { 915f857971dSopenharmony_ci drawStyleScaleModifier_->SetScale(endScale); 916f857971dSopenharmony_ci } 917f857971dSopenharmony_ci }, []() { FI_HILOGD("StartStyleAnimation end"); }); 918f857971dSopenharmony_ci UpdateAnimationProtocol(protocol); 919f857971dSopenharmony_ci if (endScale == STYLE_CHANGE_SCALE) { 920f857971dSopenharmony_ci if (drawStyleChangeModifier_ != nullptr) { 921f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawStyleChangeModifier_); 922f857971dSopenharmony_ci drawStyleChangeModifier_ = nullptr; 923f857971dSopenharmony_ci } 924f857971dSopenharmony_ci if (drawStyleScaleModifier_ != nullptr) { 925f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawStyleScaleModifier_); 926f857971dSopenharmony_ci drawStyleScaleModifier_ = nullptr; 927f857971dSopenharmony_ci } 928f857971dSopenharmony_ci drawStyleChangeModifier_ = std::make_shared<DrawStyleChangeModifier>(g_drawingInfo.stylePixelMap); 929f857971dSopenharmony_ci dragStyleNode->AddModifier(drawStyleChangeModifier_); 930f857971dSopenharmony_ci } 931f857971dSopenharmony_ci if (endScale == STYLE_END_SCALE && drawStyleScaleModifier_ != nullptr) { 932f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawStyleScaleModifier_); 933f857971dSopenharmony_ci drawStyleScaleModifier_ = nullptr; 934f857971dSopenharmony_ci } 935f857971dSopenharmony_ci} 936f857971dSopenharmony_ci 937f857971dSopenharmony_civoid DragDrawing::ChangeStyleAnimation() 938f857971dSopenharmony_ci{ 939f857971dSopenharmony_ci FI_HILOGD("enter"); 940f857971dSopenharmony_ci hasRunningScaleAnimation_ = true; 941f857971dSopenharmony_ci StartStyleAnimation(START_STYLE_SCALE, STYLE_CHANGE_SCALE, TIME_DRAG_CHANGE_STYLE); 942f857971dSopenharmony_ci StartStyleAnimation(STYLE_CHANGE_SCALE, STYLE_MAX_SCALE, TIME_DRAG_CHANGE_STYLE); 943f857971dSopenharmony_ci StartStyleAnimation(STYLE_MAX_SCALE, STYLE_END_SCALE, TIME_DRAG_STYLE); 944f857971dSopenharmony_ci needBreakStyleScaleAnimation_ = false; 945f857971dSopenharmony_ci hasRunningScaleAnimation_ = false; 946f857971dSopenharmony_ci FI_HILOGD("leave"); 947f857971dSopenharmony_ci} 948f857971dSopenharmony_ci 949f857971dSopenharmony_civoid DragDrawing::OnDragStyleAnimation() 950f857971dSopenharmony_ci{ 951f857971dSopenharmony_ci FI_HILOGD("enter"); 952f857971dSopenharmony_ci if (!CheckNodesValid()) { 953f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 954f857971dSopenharmony_ci return; 955f857971dSopenharmony_ci } 956f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 957f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 958f857971dSopenharmony_ci return; 959f857971dSopenharmony_ci } 960f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 961f857971dSopenharmony_ci CHKPV(dragStyleNode); 962f857971dSopenharmony_ci needBreakStyleScaleAnimation_ = false; 963f857971dSopenharmony_ci if (g_drawingInfo.isPreviousDefaultStyle == true || g_drawingInfo.isCurrentDefaultStyle == true) { 964f857971dSopenharmony_ci FI_HILOGE("Has DefaultStyle, change style and return"); 965f857971dSopenharmony_ci CheckStyleNodeModifier(dragStyleNode); 966f857971dSopenharmony_ci drawStyleChangeModifier_ = std::make_shared<DrawStyleChangeModifier>(g_drawingInfo.stylePixelMap); 967f857971dSopenharmony_ci dragStyleNode->AddModifier(drawStyleChangeModifier_); 968f857971dSopenharmony_ci return; 969f857971dSopenharmony_ci } 970f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 971f857971dSopenharmony_ci if (handler_ == nullptr) { 972f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); 973f857971dSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 974f857971dSopenharmony_ci } 975f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 976f857971dSopenharmony_ci CheckStyleNodeModifier(dragStyleNode); 977f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 978f857971dSopenharmony_ci handler_->PostTask(std::bind(&DragDrawing::ChangeStyleAnimation, this)); 979f857971dSopenharmony_ci#else 980f857971dSopenharmony_ci ChangeStyleAnimation(); 981f857971dSopenharmony_ci#endif 982f857971dSopenharmony_ci FI_HILOGD("leave"); 983f857971dSopenharmony_ci} 984f857971dSopenharmony_ci 985f857971dSopenharmony_civoid DragDrawing::OnDragStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode, 986f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> stylePixelMap) 987f857971dSopenharmony_ci{ 988f857971dSopenharmony_ci FI_HILOGD("enter"); 989f857971dSopenharmony_ci CHKPV(dragStyleNode); 990f857971dSopenharmony_ci CHKPV(stylePixelMap); 991f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_ANIMATION 992f857971dSopenharmony_ci if (handler_ == nullptr) { 993f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); 994f857971dSopenharmony_ci CHKPV(runner); 995f857971dSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 996f857971dSopenharmony_ci } 997f857971dSopenharmony_ci if (drawSVGModifier_ != nullptr) { 998f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawSVGModifier_); 999f857971dSopenharmony_ci drawSVGModifier_ = nullptr; 1000f857971dSopenharmony_ci } 1001f857971dSopenharmony_ci if (!handler_->PostTask([this] { this->OnDragStyleAnimation(); })) { 1002f857971dSopenharmony_ci FI_HILOGE("Drag style animation failed"); 1003f857971dSopenharmony_ci DrawStyle(dragStyleNode, stylePixelMap); 1004f857971dSopenharmony_ci } 1005f857971dSopenharmony_ci#else // OHOS_DRAG_ENABLE_ANIMATION 1006f857971dSopenharmony_ci DrawStyle(dragStyleNode, stylePixelMap); 1007f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_ANIMATION 1008f857971dSopenharmony_ci FI_HILOGD("leave"); 1009f857971dSopenharmony_ci} 1010f857971dSopenharmony_ci 1011f857971dSopenharmony_civoid DragDrawing::OnStopAnimationSuccess() 1012f857971dSopenharmony_ci{ 1013f857971dSopenharmony_ci FI_HILOGI("enter"); 1014f857971dSopenharmony_ci if (!CheckNodesValid()) { 1015f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 1016f857971dSopenharmony_ci return; 1017f857971dSopenharmony_ci } 1018f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 1019f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 1020f857971dSopenharmony_ci return; 1021f857971dSopenharmony_ci } 1022f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 1023f857971dSopenharmony_ci if (dragStyleNode != nullptr && drawStyleScaleModifier_ != nullptr) { 1024f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawStyleScaleModifier_); 1025f857971dSopenharmony_ci dragStyleNode->RemoveAllAnimations(); 1026f857971dSopenharmony_ci drawStyleScaleModifier_ = nullptr; 1027f857971dSopenharmony_ci needBreakStyleScaleAnimation_ = true; 1028f857971dSopenharmony_ci } 1029f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 1030f857971dSopenharmony_ci hasRunningStopAnimation_ = true; 1031f857971dSopenharmony_ci if (drawDragStopModifier_ != nullptr) { 1032f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveModifier(drawDragStopModifier_); 1033f857971dSopenharmony_ci drawDragStopModifier_ = nullptr; 1034f857971dSopenharmony_ci } 1035f857971dSopenharmony_ci drawDragStopModifier_ = std::make_shared<DrawDragStopModifier>(); 1036f857971dSopenharmony_ci g_drawingInfo.rootNode->AddModifier(drawDragStopModifier_); 1037f857971dSopenharmony_ci drawDragStopModifier_->SetAlpha(BEGIN_ALPHA); 1038f857971dSopenharmony_ci drawDragStopModifier_->SetScale(BEGIN_SCALE); 1039f857971dSopenharmony_ci drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE); 1040f857971dSopenharmony_ci drawDragStopModifier_->SetStyleAlpha(START_STYLE_ALPHA); 1041f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol windowProtocol; 1042f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol styleProtocol; 1043f857971dSopenharmony_ci windowProtocol.SetDuration(TIME_STOP_SUCCESS_WINDOW); 1044f857971dSopenharmony_ci styleProtocol.SetDuration(TIME_STOP_SUCCESS_STYLE); 1045f857971dSopenharmony_ci auto springCurveSuccessWindow = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_040, BEZIER_000, 1046f857971dSopenharmony_ci BEZIER_100, BEZIER_100); 1047f857971dSopenharmony_ci auto springCurveSuccessStyle = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_000, BEZIER_000, 1048f857971dSopenharmony_ci BEZIER_100, BEZIER_100); 1049f857971dSopenharmony_ci Rosen::RSNode::Animate(windowProtocol, springCurveSuccessWindow, [&]() { 1050f857971dSopenharmony_ci drawDragStopModifier_->SetAlpha(BEGIN_ALPHA); 1051f857971dSopenharmony_ci drawDragStopModifier_->SetScale(END_SCALE_SUCCESS); 1052f857971dSopenharmony_ci Rosen::RSNode::Animate(styleProtocol, springCurveSuccessStyle, [&]() { 1053f857971dSopenharmony_ci drawDragStopModifier_->SetStyleAlpha(END_STYLE_ALPHA); 1054f857971dSopenharmony_ci drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE); 1055f857971dSopenharmony_ci }); 1056f857971dSopenharmony_ci }, []() { FI_HILOGD("OnStopAnimationSuccess end"); }); 1057f857971dSopenharmony_ci DoEndAnimation(); 1058f857971dSopenharmony_ci FI_HILOGI("leave"); 1059f857971dSopenharmony_ci} 1060f857971dSopenharmony_ci 1061f857971dSopenharmony_civoid DragDrawing::OnStopDragSuccess(std::shared_ptr<Rosen::RSCanvasNode> shadowNode, 1062f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode) 1063f857971dSopenharmony_ci{ 1064f857971dSopenharmony_ci FI_HILOGD("enter"); 1065f857971dSopenharmony_ci auto animateCb = [this] { return this->InitVSync(END_ALPHA, END_SCALE_SUCCESS); }; 1066f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_ANIMATION 1067f857971dSopenharmony_ci ResetAnimationParameter(); 1068f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); 1069f857971dSopenharmony_ci CHKPV(runner); 1070f857971dSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 1071f857971dSopenharmony_ci if (!handler_->PostTask([this] { return this->OnStopAnimationSuccess(); })) { 1072f857971dSopenharmony_ci FI_HILOGE("Failed to stop style animation"); 1073f857971dSopenharmony_ci RunAnimation(animateCb); 1074f857971dSopenharmony_ci } 1075f857971dSopenharmony_ci#else // OHOS_DRAG_ENABLE_ANIMATION 1076f857971dSopenharmony_ci RunAnimation(animateCb); 1077f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_ANIMATION 1078f857971dSopenharmony_ci FI_HILOGD("leave"); 1079f857971dSopenharmony_ci} 1080f857971dSopenharmony_ci 1081f857971dSopenharmony_civoid DragDrawing::OnStopAnimationFail() 1082f857971dSopenharmony_ci{ 1083f857971dSopenharmony_ci FI_HILOGI("enter"); 1084f857971dSopenharmony_ci if (!CheckNodesValid()) { 1085f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 1086f857971dSopenharmony_ci return; 1087f857971dSopenharmony_ci } 1088f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 1089f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 1090f857971dSopenharmony_ci return; 1091f857971dSopenharmony_ci } 1092f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 1093f857971dSopenharmony_ci if (dragStyleNode != nullptr && drawStyleScaleModifier_ != nullptr) { 1094f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawStyleScaleModifier_); 1095f857971dSopenharmony_ci dragStyleNode->RemoveAllAnimations(); 1096f857971dSopenharmony_ci drawStyleScaleModifier_ = nullptr; 1097f857971dSopenharmony_ci needBreakStyleScaleAnimation_ = true; 1098f857971dSopenharmony_ci } 1099f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 1100f857971dSopenharmony_ci if (drawDragStopModifier_ != nullptr) { 1101f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveModifier(drawDragStopModifier_); 1102f857971dSopenharmony_ci drawDragStopModifier_ = nullptr; 1103f857971dSopenharmony_ci } 1104f857971dSopenharmony_ci drawDragStopModifier_ = std::make_shared<DrawDragStopModifier>(); 1105f857971dSopenharmony_ci hasRunningStopAnimation_ = true; 1106f857971dSopenharmony_ci g_drawingInfo.rootNode->AddModifier(drawDragStopModifier_); 1107f857971dSopenharmony_ci drawDragStopModifier_->SetAlpha(BEGIN_ALPHA); 1108f857971dSopenharmony_ci drawDragStopModifier_->SetScale(BEGIN_SCALE); 1109f857971dSopenharmony_ci drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE); 1110f857971dSopenharmony_ci drawDragStopModifier_->SetStyleAlpha(START_STYLE_ALPHA); 1111f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 1112f857971dSopenharmony_ci protocol.SetDuration(TIME_STOP_FAIL_WINDOW); 1113f857971dSopenharmony_ci auto springCurveFail = Rosen::RSAnimationTimingCurve::CreateCubicCurve(BEZIER_033, BEZIER_000, 1114f857971dSopenharmony_ci BEZIER_067, BEZIER_100); 1115f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, springCurveFail, [&]() { 1116f857971dSopenharmony_ci drawDragStopModifier_->SetAlpha(END_ALPHA); 1117f857971dSopenharmony_ci drawDragStopModifier_->SetScale(END_SCALE_FAIL); 1118f857971dSopenharmony_ci drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE); 1119f857971dSopenharmony_ci drawDragStopModifier_->SetStyleAlpha(END_STYLE_ALPHA); 1120f857971dSopenharmony_ci }, []() { FI_HILOGD("OnStopAnimationFail end"); }); 1121f857971dSopenharmony_ci DoEndAnimation(); 1122f857971dSopenharmony_ci FI_HILOGI("leave"); 1123f857971dSopenharmony_ci} 1124f857971dSopenharmony_ci 1125f857971dSopenharmony_civoid DragDrawing::OnStopDragFail(std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode, 1126f857971dSopenharmony_ci std::shared_ptr<Rosen::RSNode> rootNode) 1127f857971dSopenharmony_ci{ 1128f857971dSopenharmony_ci FI_HILOGD("enter"); 1129f857971dSopenharmony_ci auto animateCb = [this] { return this->InitVSync(END_ALPHA, END_SCALE_FAIL); }; 1130f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_ANIMATION 1131f857971dSopenharmony_ci ResetAnimationParameter(); 1132f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); 1133f857971dSopenharmony_ci CHKPV(runner); 1134f857971dSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 1135f857971dSopenharmony_ci if (!handler_->PostTask([this] { this->OnStopAnimationFail(); })) { 1136f857971dSopenharmony_ci FI_HILOGE("Failed to stop style animation"); 1137f857971dSopenharmony_ci RunAnimation(animateCb); 1138f857971dSopenharmony_ci } 1139f857971dSopenharmony_ci#else // OHOS_DRAG_ENABLE_ANIMATION 1140f857971dSopenharmony_ci RunAnimation(animateCb); 1141f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_ANIMATION 1142f857971dSopenharmony_ci FI_HILOGD("leave"); 1143f857971dSopenharmony_ci} 1144f857971dSopenharmony_ci 1145f857971dSopenharmony_civoid DragDrawing::OnStopAnimation() 1146f857971dSopenharmony_ci{ 1147f857971dSopenharmony_ci FI_HILOGD("enter"); 1148f857971dSopenharmony_ci} 1149f857971dSopenharmony_ci 1150f857971dSopenharmony_ciint32_t DragDrawing::RunAnimation(std::function<int32_t()> cb) 1151f857971dSopenharmony_ci{ 1152f857971dSopenharmony_ci FI_HILOGD("enter"); 1153f857971dSopenharmony_ci ResetAnimationParameter(); 1154f857971dSopenharmony_ci#ifndef IOS_PLATFORM 1155f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); 1156f857971dSopenharmony_ci#else 1157f857971dSopenharmony_ci auto runner = AppExecFwk::EventRunner::Current(); // IOS animation can run main thread 1158f857971dSopenharmony_ci#endif // IOS_PLATFORM 1159f857971dSopenharmony_ci CHKPR(runner, RET_ERR); 1160f857971dSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner)); 1161f857971dSopenharmony_ci if (!handler_->PostTask(cb)) { 1162f857971dSopenharmony_ci FI_HILOGE("Send vsync event failed"); 1163f857971dSopenharmony_ci return RET_ERR; 1164f857971dSopenharmony_ci } 1165f857971dSopenharmony_ci FI_HILOGD("leave"); 1166f857971dSopenharmony_ci return RET_OK; 1167f857971dSopenharmony_ci} 1168f857971dSopenharmony_ci 1169f857971dSopenharmony_ciint32_t DragDrawing::DrawShadow(std::shared_ptr<Rosen::RSCanvasNode> shadowNode) 1170f857971dSopenharmony_ci{ 1171f857971dSopenharmony_ci FI_HILOGD("enter"); 1172f857971dSopenharmony_ci CHKPR(shadowNode, RET_ERR); 1173f857971dSopenharmony_ci if (drawPixelMapModifier_ != nullptr) { 1174f857971dSopenharmony_ci shadowNode->RemoveModifier(drawPixelMapModifier_); 1175f857971dSopenharmony_ci drawPixelMapModifier_ = nullptr; 1176f857971dSopenharmony_ci } 1177f857971dSopenharmony_ci drawPixelMapModifier_ = std::make_shared<DrawPixelMapModifier>(); 1178f857971dSopenharmony_ci shadowNode->AddModifier(drawPixelMapModifier_); 1179f857971dSopenharmony_ci FilterInfo filterInfo = g_drawingInfo.filterInfo; 1180f857971dSopenharmony_ci Rosen::Vector4f cornerRadiusVector = { filterInfo.cornerRadius1, filterInfo.cornerRadius2, 1181f857971dSopenharmony_ci filterInfo.cornerRadius3, filterInfo.cornerRadius4 }; 1182f857971dSopenharmony_ci shadowNode->SetCornerRadius(cornerRadiusVector * filterInfo.dipScale * filterInfo.scale); 1183f857971dSopenharmony_ci shadowNode->SetAlpha(filterInfo.opacity); 1184f857971dSopenharmony_ci FI_HILOGD("leave"); 1185f857971dSopenharmony_ci return RET_OK; 1186f857971dSopenharmony_ci} 1187f857971dSopenharmony_ci 1188f857971dSopenharmony_ciint32_t DragDrawing::DrawMouseIcon() 1189f857971dSopenharmony_ci{ 1190f857971dSopenharmony_ci FI_HILOGD("enter"); 1191f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() < MOUSE_NODE_MIN_COUNT) { 1192f857971dSopenharmony_ci FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); 1193f857971dSopenharmony_ci return RET_ERR; 1194f857971dSopenharmony_ci } 1195f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) { 1196f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 1197f857971dSopenharmony_ci return RET_ERR; 1198f857971dSopenharmony_ci } 1199f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 1200f857971dSopenharmony_ci CHKPR(mouseIconNode, RET_ERR); 1201f857971dSopenharmony_ci if (drawMouseIconModifier_ != nullptr) { 1202f857971dSopenharmony_ci mouseIconNode->RemoveModifier(drawMouseIconModifier_); 1203f857971dSopenharmony_ci drawMouseIconModifier_ = nullptr; 1204f857971dSopenharmony_ci } 1205f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1206f857971dSopenharmony_ci int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle_); 1207f857971dSopenharmony_ci if (ret != RET_OK) { 1208f857971dSopenharmony_ci FI_HILOGE("Get pointer style failed, ret:%{public}d", ret); 1209f857971dSopenharmony_ci return RET_ERR; 1210f857971dSopenharmony_ci } 1211f857971dSopenharmony_ci drawMouseIconModifier_ = std::make_shared<DrawMouseIconModifier>(pointerStyle_); 1212f857971dSopenharmony_ci mouseIconNode->AddModifier(drawMouseIconModifier_); 1213f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1214f857971dSopenharmony_ci FI_HILOGD("leave"); 1215f857971dSopenharmony_ci return RET_OK; 1216f857971dSopenharmony_ci} 1217f857971dSopenharmony_ci 1218f857971dSopenharmony_civoid DragDrawing::FlushDragPosition(uint64_t nanoTimestamp) 1219f857971dSopenharmony_ci{ 1220f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1221f857971dSopenharmony_ci if (rsUiDirector_ != nullptr) { 1222f857971dSopenharmony_ci rsUiDirector_->SetTimeStamp(nanoTimestamp, RENDER_THREAD_NAME); 1223f857971dSopenharmony_ci } else { 1224f857971dSopenharmony_ci FI_HILOGE("rsUiDirector_ is nullptr"); 1225f857971dSopenharmony_ci } 1226f857971dSopenharmony_ci DragMoveEvent event = dragSmoothProcessor_.SmoothMoveEvent(nanoTimestamp, 1227f857971dSopenharmony_ci vSyncStation_.GetVSyncPeriod()); 1228f857971dSopenharmony_ci FI_HILOGD("Move position x:%{private}f, y:%{private}f, timestamp:%{public}" PRId64 1229f857971dSopenharmony_ci "displayId:%{public}d", event.displayX, event.displayY, event.timestamp, event.displayId); 1230f857971dSopenharmony_ci UpdateDragPosition(event.displayId, event.displayX, event.displayY); 1231f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1232f857971dSopenharmony_ci} 1233f857971dSopenharmony_ci 1234f857971dSopenharmony_civoid DragDrawing::OnDragMove(int32_t displayId, int32_t displayX, int32_t displayY, int64_t actionTime) 1235f857971dSopenharmony_ci{ 1236f857971dSopenharmony_ci if (isRunningRotateAnimation_) { 1237f857971dSopenharmony_ci FI_HILOGD("Doing rotate drag window animate, ignore draw drag window"); 1238f857971dSopenharmony_ci return; 1239f857971dSopenharmony_ci } 1240f857971dSopenharmony_ci#ifdef IOS_PLATFORM 1241f857971dSopenharmony_ci actionTime_ = actionTime; 1242f857971dSopenharmony_ci#endif // IOS_PLATFORM 1243f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1244f857971dSopenharmony_ci std::chrono::microseconds microseconds(actionTime); 1245f857971dSopenharmony_ci TimeStamp time(microseconds); 1246f857971dSopenharmony_ci uint64_t actionTimeCount = static_cast<uint64_t>(time.time_since_epoch().count()); 1247f857971dSopenharmony_ci DragMoveEvent event = { 1248f857971dSopenharmony_ci .displayX = displayX, 1249f857971dSopenharmony_ci .displayY = displayY, 1250f857971dSopenharmony_ci .displayId = displayId, 1251f857971dSopenharmony_ci .timestamp = actionTimeCount, 1252f857971dSopenharmony_ci }; 1253f857971dSopenharmony_ci dragSmoothProcessor_.InsertEvent(event); 1254f857971dSopenharmony_ci if (frameCallback_ == nullptr) { 1255f857971dSopenharmony_ci frameCallback_ = std::make_shared<DragFrameCallback>([this](uint64_t nanoTimestamp) { 1256f857971dSopenharmony_ci this->FlushDragPosition(nanoTimestamp); 1257f857971dSopenharmony_ci }); 1258f857971dSopenharmony_ci } 1259f857971dSopenharmony_ci vSyncStation_.RequestFrame(TYPE_FLUSH_DRAG_POSITION, frameCallback_); 1260f857971dSopenharmony_ci#else 1261f857971dSopenharmony_ci UpdateDragPosition(displayId, displayX, displayY); 1262f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1263f857971dSopenharmony_ci} 1264f857971dSopenharmony_ci 1265f857971dSopenharmony_ciint32_t DragDrawing::DrawStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode, 1266f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> stylePixelMap) 1267f857971dSopenharmony_ci{ 1268f857971dSopenharmony_ci FI_HILOGD("enter"); 1269f857971dSopenharmony_ci CHKPR(dragStyleNode, RET_ERR); 1270f857971dSopenharmony_ci CHKPR(stylePixelMap, RET_ERR); 1271f857971dSopenharmony_ci if (drawSVGModifier_ != nullptr) { 1272f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawSVGModifier_); 1273f857971dSopenharmony_ci drawSVGModifier_ = nullptr; 1274f857971dSopenharmony_ci } 1275f857971dSopenharmony_ci drawSVGModifier_ = std::make_shared<DrawSVGModifier>(stylePixelMap); 1276f857971dSopenharmony_ci dragStyleNode->AddModifier(drawSVGModifier_); 1277f857971dSopenharmony_ci FI_HILOGD("leave"); 1278f857971dSopenharmony_ci return RET_OK; 1279f857971dSopenharmony_ci} 1280f857971dSopenharmony_ci 1281f857971dSopenharmony_ciint32_t DragDrawing::InitVSync(float endAlpha, float endScale) 1282f857971dSopenharmony_ci{ 1283f857971dSopenharmony_ci FI_HILOGD("enter"); 1284f857971dSopenharmony_ci CHKPR(g_drawingInfo.rootNode, RET_ERR); 1285f857971dSopenharmony_ci if (drawDynamicEffectModifier_ != nullptr) { 1286f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); 1287f857971dSopenharmony_ci drawDynamicEffectModifier_ = nullptr; 1288f857971dSopenharmony_ci } 1289f857971dSopenharmony_ci drawDynamicEffectModifier_ = std::make_shared<DrawDynamicEffectModifier>(); 1290f857971dSopenharmony_ci g_drawingInfo.rootNode->AddModifier(drawDynamicEffectModifier_); 1291f857971dSopenharmony_ci drawDynamicEffectModifier_->SetAlpha(BEGIN_ALPHA); 1292f857971dSopenharmony_ci drawDynamicEffectModifier_->SetScale(BEGIN_SCALE); 1293f857971dSopenharmony_ci 1294f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 1295f857971dSopenharmony_ci protocol.SetDuration(SUCCESS_ANIMATION_DURATION); 1296f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { 1297f857971dSopenharmony_ci drawDynamicEffectModifier_->SetAlpha(endAlpha); 1298f857971dSopenharmony_ci drawDynamicEffectModifier_->SetScale(endScale); 1299f857971dSopenharmony_ci }, []() { FI_HILOGD("InitVSync end"); }); 1300f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 1301f857971dSopenharmony_ci DoEndAnimation(); 1302f857971dSopenharmony_ci FI_HILOGD("leave"); 1303f857971dSopenharmony_ci return RET_OK; 1304f857971dSopenharmony_ci} 1305f857971dSopenharmony_ci 1306f857971dSopenharmony_ciint32_t DragDrawing::StartVsync() 1307f857971dSopenharmony_ci{ 1308f857971dSopenharmony_ci FI_HILOGI("enter"); 1309f857971dSopenharmony_ci if (receiver_ == nullptr) { 1310f857971dSopenharmony_ci CHKPR(handler_, RET_ERR); 1311f857971dSopenharmony_ci receiver_ = Rosen::RSInterfaces::GetInstance().CreateVSyncReceiver("DragDrawing", handler_); 1312f857971dSopenharmony_ci CHKPR(receiver_, RET_ERR); 1313f857971dSopenharmony_ci } 1314f857971dSopenharmony_ci#ifdef IOS_PLATFORM 1315f857971dSopenharmony_ci rsUiDirector_->FlushAnimation(g_drawingInfo.startNum); 1316f857971dSopenharmony_ci#endif // IOS_PLATFORM 1317f857971dSopenharmony_ci int32_t ret = receiver_->Init(); 1318f857971dSopenharmony_ci if (ret != RET_OK) { 1319f857971dSopenharmony_ci FI_HILOGE("Receiver init failed"); 1320f857971dSopenharmony_ci return RET_ERR; 1321f857971dSopenharmony_ci } 1322f857971dSopenharmony_ci Rosen::VSyncReceiver::FrameCallback fcb = { 1323f857971dSopenharmony_ci .userData_ = this, 1324f857971dSopenharmony_ci .callback_ = [this](int64_t parm1, void *parm2) { this->OnVsync(); } 1325f857971dSopenharmony_ci }; 1326f857971dSopenharmony_ci ret = receiver_->RequestNextVSync(fcb); 1327f857971dSopenharmony_ci if (ret != RET_OK) { 1328f857971dSopenharmony_ci FI_HILOGE("Request next vsync failed"); 1329f857971dSopenharmony_ci } 1330f857971dSopenharmony_ci FI_HILOGI("leave"); 1331f857971dSopenharmony_ci return ret; 1332f857971dSopenharmony_ci} 1333f857971dSopenharmony_ci 1334f857971dSopenharmony_civoid DragDrawing::OnVsync() 1335f857971dSopenharmony_ci{ 1336f857971dSopenharmony_ci FI_HILOGD("enter"); 1337f857971dSopenharmony_ci CHKPV(rsUiDirector_); 1338f857971dSopenharmony_ci bool hasRunningAnimation = rsUiDirector_->FlushAnimation(g_drawingInfo.startNum); 1339f857971dSopenharmony_ci rsUiDirector_->FlushModifier(); 1340f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 1341f857971dSopenharmony_ci if (!hasRunningAnimation) { 1342f857971dSopenharmony_ci FI_HILOGI("Stop runner, hasRunningAnimation:%{public}d, needDestroyDragWindow:%{public}d", 1343f857971dSopenharmony_ci hasRunningAnimation, g_drawingInfo.needDestroyDragWindow.load()); 1344f857971dSopenharmony_ci if (g_drawingInfo.needDestroyDragWindow) { 1345f857971dSopenharmony_ci ResetAnimationFlag(); 1346f857971dSopenharmony_ci } 1347f857971dSopenharmony_ci return; 1348f857971dSopenharmony_ci } 1349f857971dSopenharmony_ci Rosen::VSyncReceiver::FrameCallback fcb = { 1350f857971dSopenharmony_ci .userData_ = this, 1351f857971dSopenharmony_ci .callback_ = [this](int64_t parm1, void *parm2) { this->OnVsync(); } 1352f857971dSopenharmony_ci }; 1353f857971dSopenharmony_ci CHKPV(receiver_); 1354f857971dSopenharmony_ci int32_t ret = receiver_->RequestNextVSync(fcb); 1355f857971dSopenharmony_ci if (ret != RET_OK) { 1356f857971dSopenharmony_ci FI_HILOGE("Request next vsync failed"); 1357f857971dSopenharmony_ci } 1358f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 1359f857971dSopenharmony_ci g_drawingInfo.startNum += INTERVAL_TIME; 1360f857971dSopenharmony_ci FI_HILOGD("leave"); 1361f857971dSopenharmony_ci} 1362f857971dSopenharmony_ci 1363f857971dSopenharmony_civoid DragDrawing::InitDrawingInfo(const DragData &dragData) 1364f857971dSopenharmony_ci{ 1365f857971dSopenharmony_ci g_drawingInfo.isRunning = true; 1366f857971dSopenharmony_ci if (dragData.shadowInfos.empty()) { 1367f857971dSopenharmony_ci FI_HILOGE("ShadowInfos is empty"); 1368f857971dSopenharmony_ci return; 1369f857971dSopenharmony_ci } 1370f857971dSopenharmony_ci g_drawingInfo.pixelMap = dragData.shadowInfos.front().pixelMap; 1371f857971dSopenharmony_ci g_drawingInfo.pixelMapX = dragData.shadowInfos.front().x; 1372f857971dSopenharmony_ci g_drawingInfo.pixelMapY = dragData.shadowInfos.front().y; 1373f857971dSopenharmony_ci float dragOriginDpi = DRAG_DATA_MGR.GetDragOriginDpi(); 1374f857971dSopenharmony_ci if (dragOriginDpi > EPSILON) { 1375f857971dSopenharmony_ci float scalingValue = GetScaling() / dragOriginDpi; 1376f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 1377f857971dSopenharmony_ci g_drawingInfo.pixelMap->scale(scalingValue, scalingValue, Media::AntiAliasingOption::HIGH); 1378f857971dSopenharmony_ci g_drawingInfo.pixelMapX = g_drawingInfo.pixelMapX * scalingValue; 1379f857971dSopenharmony_ci g_drawingInfo.pixelMapY = g_drawingInfo.pixelMapY * scalingValue; 1380f857971dSopenharmony_ci if (fabs(scalingValue - 1.0f) > EPSILON) { 1381f857971dSopenharmony_ci float widthScale = CalculateWidthScale(); 1382f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 1383f857971dSopenharmony_ci g_drawingInfo.pixelMap->scale(widthScale, widthScale, Media::AntiAliasingOption::HIGH); 1384f857971dSopenharmony_ci g_drawingInfo.pixelMapX = g_drawingInfo.pixelMapX * widthScale; 1385f857971dSopenharmony_ci g_drawingInfo.pixelMapY = g_drawingInfo.pixelMapY * widthScale; 1386f857971dSopenharmony_ci } 1387f857971dSopenharmony_ci } 1388f857971dSopenharmony_ci g_drawingInfo.currentDragNum = dragData.dragNum; 1389f857971dSopenharmony_ci g_drawingInfo.sourceType = dragData.sourceType; 1390f857971dSopenharmony_ci g_drawingInfo.displayId = dragData.displayId; 1391f857971dSopenharmony_ci g_drawingInfo.displayX = dragData.displayX; 1392f857971dSopenharmony_ci g_drawingInfo.displayY = dragData.displayY; 1393f857971dSopenharmony_ci RotateDisplayXY(g_drawingInfo.displayX, g_drawingInfo.displayY); 1394f857971dSopenharmony_ci if (!ParserExtraInfo(dragData.extraInfo, g_drawingInfo.extraInfo)) { 1395f857971dSopenharmony_ci FI_HILOGI("No parser valid extraInfo data"); 1396f857971dSopenharmony_ci } 1397f857971dSopenharmony_ci if (!ParserFilterInfo(dragData.filterInfo, g_drawingInfo.filterInfo)) { 1398f857971dSopenharmony_ci FI_HILOGI("No parser valid filterInfo data"); 1399f857971dSopenharmony_ci } 1400f857971dSopenharmony_ci size_t shadowInfosSize = dragData.shadowInfos.size(); 1401f857971dSopenharmony_ci for (size_t i = 1; i < shadowInfosSize; ++i) { 1402f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap = dragData.shadowInfos[i].pixelMap; 1403f857971dSopenharmony_ci if (dragOriginDpi > EPSILON) { 1404f857971dSopenharmony_ci float scalingValue = GetScaling() / dragOriginDpi; 1405f857971dSopenharmony_ci CHKPV(pixelMap); 1406f857971dSopenharmony_ci pixelMap->scale(scalingValue, scalingValue, Media::AntiAliasingOption::HIGH); 1407f857971dSopenharmony_ci } 1408f857971dSopenharmony_ci g_drawingInfo.multiSelectedPixelMaps.emplace_back(pixelMap); 1409f857971dSopenharmony_ci } 1410f857971dSopenharmony_ci} 1411f857971dSopenharmony_ci 1412f857971dSopenharmony_ciint32_t DragDrawing::InitDragAnimationData(DragAnimationData &dragAnimationData) 1413f857971dSopenharmony_ci{ 1414f857971dSopenharmony_ci CHKPR(g_drawingInfo.pixelMap, RET_ERR); 1415f857971dSopenharmony_ci dragAnimationData.pixelMap = g_drawingInfo.pixelMap; 1416f857971dSopenharmony_ci dragAnimationData.displayX = g_drawingInfo.displayX; 1417f857971dSopenharmony_ci dragAnimationData.displayY = g_drawingInfo.displayY; 1418f857971dSopenharmony_ci dragAnimationData.offsetX = g_drawingInfo.pixelMapX; 1419f857971dSopenharmony_ci dragAnimationData.offsetY = g_drawingInfo.pixelMapY; 1420f857971dSopenharmony_ci return RET_OK; 1421f857971dSopenharmony_ci} 1422f857971dSopenharmony_ci 1423f857971dSopenharmony_ciint32_t DragDrawing::InitLayer() 1424f857971dSopenharmony_ci{ 1425f857971dSopenharmony_ci FI_HILOGI("enter"); 1426f857971dSopenharmony_ci if (g_drawingInfo.surfaceNode == nullptr) { 1427f857971dSopenharmony_ci FI_HILOGE("Init layer failed, surfaceNode is nullptr"); 1428f857971dSopenharmony_ci return RET_ERR; 1429f857971dSopenharmony_ci } 1430f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1431f857971dSopenharmony_ci auto surface = g_drawingInfo.surfaceNode->GetSurface(); 1432f857971dSopenharmony_ci if (surface == nullptr) { 1433f857971dSopenharmony_ci g_drawingInfo.surfaceNode->DetachToDisplay(g_drawingInfo.displayId); 1434f857971dSopenharmony_ci g_drawingInfo.surfaceNode = nullptr; 1435f857971dSopenharmony_ci FI_HILOGE("Init layer failed, surface is nullptr"); 1436f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 1437f857971dSopenharmony_ci return RET_ERR; 1438f857971dSopenharmony_ci } 1439f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1440f857971dSopenharmony_ci if (g_drawingInfo.isInitUiDirector) { 1441f857971dSopenharmony_ci g_drawingInfo.isInitUiDirector = false; 1442f857971dSopenharmony_ci rsUiDirector_ = Rosen::RSUIDirector::Create(); 1443f857971dSopenharmony_ci CHKPR(rsUiDirector_, RET_ERR); 1444f857971dSopenharmony_ci rsUiDirector_->Init(); 1445f857971dSopenharmony_ci rsUiDirector_->SetUITaskRunner([this](const std::function<void()> &task, uint32_t delay = 0) { 1446f857971dSopenharmony_ci CHKPV(this->handler_); 1447f857971dSopenharmony_ci this->handler_->PostTask(task, delay); 1448f857971dSopenharmony_ci }); 1449f857971dSopenharmony_ci } 1450f857971dSopenharmony_ci rsUiDirector_->SetRSSurfaceNode(g_drawingInfo.surfaceNode); 1451f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1452f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 1453f857971dSopenharmony_ci if (display == nullptr) { 1454f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 1455f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 1456f857971dSopenharmony_ci if (display == nullptr) { 1457f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 1458f857971dSopenharmony_ci return RET_ERR; 1459f857971dSopenharmony_ci } 1460f857971dSopenharmony_ci } 1461f857971dSopenharmony_ci int32_t rootNodeSize = std::max(display->GetWidth(), display->GetHeight()); 1462f857971dSopenharmony_ci InitCanvas(rootNodeSize, rootNodeSize); 1463f857971dSopenharmony_ci#else 1464f857971dSopenharmony_ci CHKPR(window_, RET_ERR); 1465f857971dSopenharmony_ci InitCanvas(window_->GetRect().width_, window_->GetRect().height_); 1466f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1467f857971dSopenharmony_ci if (rotation_ != Rosen::Rotation::ROTATION_0) { 1468f857971dSopenharmony_ci RotateDragWindow(rotation_); 1469f857971dSopenharmony_ci } else { 1470f857971dSopenharmony_ci DragWindowRotateInfo_.rotation = ROTATION_0; 1471f857971dSopenharmony_ci } 1472f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 1473f857971dSopenharmony_ci FI_HILOGI("leave"); 1474f857971dSopenharmony_ci return RET_OK; 1475f857971dSopenharmony_ci} 1476f857971dSopenharmony_ci 1477f857971dSopenharmony_civoid DragDrawing::InitCanvas(int32_t width, int32_t height) 1478f857971dSopenharmony_ci{ 1479f857971dSopenharmony_ci FI_HILOGI("enter"); 1480f857971dSopenharmony_ci if (g_drawingInfo.rootNode == nullptr) { 1481f857971dSopenharmony_ci g_drawingInfo.rootNode = Rosen::RSRootNode::Create(); 1482f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 1483f857971dSopenharmony_ci } 1484f857971dSopenharmony_ci g_drawingInfo.rootNode->SetBounds(0, 0, width, height); 1485f857971dSopenharmony_ci g_drawingInfo.rootNode->SetFrame(0, 0, width, height); 1486f857971dSopenharmony_ci g_drawingInfo.rootNode->SetBackgroundColor(SK_ColorTRANSPARENT); 1487f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> filterNode = Rosen::RSCanvasNode::Create(); 1488f857971dSopenharmony_ci CHKPV(filterNode); 1489f857971dSopenharmony_ci g_drawingInfo.nodes.emplace_back(filterNode); 1490f857971dSopenharmony_ci ProcessFilter(); 1491f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = Rosen::RSCanvasNode::Create(); 1492f857971dSopenharmony_ci CHKPV(pixelMapNode); 1493f857971dSopenharmony_ci pixelMapNode->SetForegroundColor(TRANSPARENT_COLOR_ARGB); 1494f857971dSopenharmony_ci pixelMapNode->SetGrayScale(g_drawingInfo.filterInfo.dragNodeGrayscale); 1495f857971dSopenharmony_ci g_drawingInfo.nodes.emplace_back(pixelMapNode); 1496f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = Rosen::RSCanvasNode::Create(); 1497f857971dSopenharmony_ci CHKPV(dragStyleNode); 1498f857971dSopenharmony_ci g_drawingInfo.nodes.emplace_back(dragStyleNode); 1499f857971dSopenharmony_ci if (g_drawingInfo.parentNode == nullptr) { 1500f857971dSopenharmony_ci g_drawingInfo.parentNode = Rosen::RSCanvasNode::Create(); 1501f857971dSopenharmony_ci CHKPV(g_drawingInfo.parentNode); 1502f857971dSopenharmony_ci } 1503f857971dSopenharmony_ci g_drawingInfo.parentNode->AddChild(filterNode); 1504f857971dSopenharmony_ci g_drawingInfo.parentNode->AddChild(pixelMapNode); 1505f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedPixelMaps.empty()) { 1506f857971dSopenharmony_ci InitMultiSelectedNodes(); 1507f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty()) { 1508f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 1509f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedNodesSize; ++i) { 1510f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(g_drawingInfo.multiSelectedNodes[i]); 1511f857971dSopenharmony_ci } 1512f857971dSopenharmony_ci } 1513f857971dSopenharmony_ci } 1514f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(g_drawingInfo.parentNode); 1515f857971dSopenharmony_ci CHKPV(rsUiDirector_); 1516f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 1517f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = Rosen::RSCanvasNode::Create(); 1518f857971dSopenharmony_ci CHKPV(mouseIconNode); 1519f857971dSopenharmony_ci g_drawingInfo.nodes.emplace_back(mouseIconNode); 1520f857971dSopenharmony_ci g_drawingInfo.rootNode->AddChild(mouseIconNode); 1521f857971dSopenharmony_ci rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); 1522f857971dSopenharmony_ci return; 1523f857971dSopenharmony_ci } 1524f857971dSopenharmony_ci rsUiDirector_->SetRoot(g_drawingInfo.rootNode->GetId()); 1525f857971dSopenharmony_ci FI_HILOGI("leave"); 1526f857971dSopenharmony_ci} 1527f857971dSopenharmony_ci 1528f857971dSopenharmony_civoid DragDrawing::CreateWindow() 1529f857971dSopenharmony_ci{ 1530f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1531f857971dSopenharmony_ci FI_HILOGD("Parameter screen number:%{public}llu", static_cast<unsigned long long>(screenId_)); 1532f857971dSopenharmony_ci Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 1533f857971dSopenharmony_ci surfaceNodeConfig.SurfaceNodeName = "drag window"; 1534f857971dSopenharmony_ci Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 1535f857971dSopenharmony_ci g_drawingInfo.surfaceNode = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType); 1536f857971dSopenharmony_ci CHKPV(g_drawingInfo.surfaceNode); 1537f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 1538f857971dSopenharmony_ci if (display == nullptr) { 1539f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 1540f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 1541f857971dSopenharmony_ci if (display == nullptr) { 1542f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 1543f857971dSopenharmony_ci return; 1544f857971dSopenharmony_ci } 1545f857971dSopenharmony_ci } 1546f857971dSopenharmony_ci uint64_t rsScreenId = screenId_; 1547f857971dSopenharmony_ci sptr<Rosen::Screen> screen = Rosen::ScreenManager::GetInstance().GetScreenById(screenId_); 1548f857971dSopenharmony_ci if ((screen != nullptr) && (!screen->IsReal())) { 1549f857971dSopenharmony_ci if (!Rosen::DisplayManager::GetInstance().ConvertScreenIdToRsScreenId(screenId_, rsScreenId)) { 1550f857971dSopenharmony_ci FI_HILOGE("ConvertScreenIdToRsScreenId failed"); 1551f857971dSopenharmony_ci return; 1552f857971dSopenharmony_ci } 1553f857971dSopenharmony_ci } 1554f857971dSopenharmony_ci screenId_ = rsScreenId; 1555f857971dSopenharmony_ci int32_t surfaceNodeSize = std::max(display->GetWidth(), display->GetHeight()); 1556f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetBounds(0, 0, surfaceNodeSize, surfaceNodeSize); 1557f857971dSopenharmony_ci#else 1558f857971dSopenharmony_ci CHKPV(window_); 1559f857971dSopenharmony_ci g_drawingInfo.surfaceNode = window_->GetSurfaceNode(); 1560f857971dSopenharmony_ci CHKPV(g_drawingInfo.surfaceNode); 1561f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetBounds(0, 0, window_->GetRect().width_, window_->GetRect().height_); 1562f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1563f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetFrameGravity(Rosen::Gravity::RESIZE_ASPECT_FILL); 1564f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetPositionZ(DRAG_WINDOW_POSITION_Z); 1565f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetBackgroundColor(SK_ColorTRANSPARENT); 1566f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1567f857971dSopenharmony_ci g_drawingInfo.surfaceNode->AttachToDisplay(rsScreenId); 1568f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1569f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetVisible(false); 1570f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 1571f857971dSopenharmony_ci} 1572f857971dSopenharmony_ci 1573f857971dSopenharmony_civoid DragDrawing::RemoveModifier() 1574f857971dSopenharmony_ci{ 1575f857971dSopenharmony_ci FI_HILOGD("enter"); 1576f857971dSopenharmony_ci if ((g_drawingInfo.nodes.size() < TOUCH_NODE_MIN_COUNT)) { 1577f857971dSopenharmony_ci FI_HILOGE("Nodes size invalid, node size:%{public}zu", g_drawingInfo.nodes.size()); 1578f857971dSopenharmony_ci return; 1579f857971dSopenharmony_ci } 1580f857971dSopenharmony_ci 1581f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= PIXEL_MAP_INDEX || g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 1582f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 1583f857971dSopenharmony_ci return; 1584f857971dSopenharmony_ci } 1585f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 1586f857971dSopenharmony_ci CHKPV(pixelMapNode); 1587f857971dSopenharmony_ci if (drawPixelMapModifier_ != nullptr) { 1588f857971dSopenharmony_ci pixelMapNode->RemoveModifier(drawPixelMapModifier_); 1589f857971dSopenharmony_ci drawPixelMapModifier_ = nullptr; 1590f857971dSopenharmony_ci } 1591f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 1592f857971dSopenharmony_ci CHKPV(dragStyleNode); 1593f857971dSopenharmony_ci if (drawSVGModifier_ != nullptr) { 1594f857971dSopenharmony_ci dragStyleNode->RemoveModifier(drawSVGModifier_); 1595f857971dSopenharmony_ci drawSVGModifier_ = nullptr; 1596f857971dSopenharmony_ci } 1597f857971dSopenharmony_ci FI_HILOGD("leave"); 1598f857971dSopenharmony_ci} 1599f857971dSopenharmony_ci 1600f857971dSopenharmony_ciint32_t DragDrawing::UpdateSvgNodeInfo(xmlNodePtr curNode, int32_t extendSvgWidth) 1601f857971dSopenharmony_ci{ 1602f857971dSopenharmony_ci FI_HILOGD("enter"); 1603f857971dSopenharmony_ci if (xmlStrcmp(curNode->name, BAD_CAST "svg")) { 1604f857971dSopenharmony_ci FI_HILOGE("Svg format invalid"); 1605f857971dSopenharmony_ci return RET_ERR; 1606f857971dSopenharmony_ci } 1607f857971dSopenharmony_ci std::ostringstream oStrStream; 1608f857971dSopenharmony_ci oStrStream << xmlGetProp(curNode, BAD_CAST "width"); 1609f857971dSopenharmony_ci std::string srcSvgWidth = oStrStream.str(); 1610f857971dSopenharmony_ci if (srcSvgWidth.length() < STRING_PX_LENGTH) { 1611f857971dSopenharmony_ci FI_HILOGE("Svg width invalid, srcSvgWidth:%{public}s", srcSvgWidth.c_str()); 1612f857971dSopenharmony_ci return RET_ERR; 1613f857971dSopenharmony_ci } 1614f857971dSopenharmony_ci srcSvgWidth = srcSvgWidth.substr(0, srcSvgWidth.length() - STRING_PX_LENGTH); 1615f857971dSopenharmony_ci if (!IsNum(srcSvgWidth)) { 1616f857971dSopenharmony_ci FI_HILOGE("srcSvgWidth is not digital, srcSvgWidth:%{public}s", srcSvgWidth.c_str()); 1617f857971dSopenharmony_ci return RET_ERR; 1618f857971dSopenharmony_ci } 1619f857971dSopenharmony_ci int32_t number = std::stoi(srcSvgWidth) + extendSvgWidth; 1620f857971dSopenharmony_ci std::string tgtSvgWidth = std::to_string(number); 1621f857971dSopenharmony_ci tgtSvgWidth.append("px"); 1622f857971dSopenharmony_ci xmlSetProp(curNode, BAD_CAST "width", BAD_CAST tgtSvgWidth.c_str()); 1623f857971dSopenharmony_ci oStrStream.str(""); 1624f857971dSopenharmony_ci oStrStream << xmlGetProp(curNode, BAD_CAST "viewBox"); 1625f857971dSopenharmony_ci std::string srcViewBox = oStrStream.str(); 1626f857971dSopenharmony_ci std::istringstream iStrStream(srcViewBox); 1627f857971dSopenharmony_ci std::string tmpString; 1628f857971dSopenharmony_ci std::string tgtViewBox; 1629f857971dSopenharmony_ci int32_t i = 0; 1630f857971dSopenharmony_ci while (iStrStream >> tmpString) { 1631f857971dSopenharmony_ci if (i == VIEW_BOX_POS) { 1632f857971dSopenharmony_ci if (!IsNum(tmpString)) { 1633f857971dSopenharmony_ci FI_HILOGE("tmpString is not digital, tmpString:%{public}s", tmpString.c_str()); 1634f857971dSopenharmony_ci return RET_ERR; 1635f857971dSopenharmony_ci } 1636f857971dSopenharmony_ci number = std::stoi(tmpString) + extendSvgWidth; 1637f857971dSopenharmony_ci tmpString = std::to_string(number); 1638f857971dSopenharmony_ci } 1639f857971dSopenharmony_ci tgtViewBox.append(tmpString); 1640f857971dSopenharmony_ci tgtViewBox += " "; 1641f857971dSopenharmony_ci ++i; 1642f857971dSopenharmony_ci } 1643f857971dSopenharmony_ci 1644f857971dSopenharmony_ci xmlSetProp(curNode, BAD_CAST "viewBox", BAD_CAST tgtViewBox.c_str()); 1645f857971dSopenharmony_ci FI_HILOGD("leave"); 1646f857971dSopenharmony_ci return RET_OK; 1647f857971dSopenharmony_ci} 1648f857971dSopenharmony_ci 1649f857971dSopenharmony_cixmlNodePtr DragDrawing::GetRectNode(xmlNodePtr curNode) 1650f857971dSopenharmony_ci{ 1651f857971dSopenharmony_ci FI_HILOGD("enter"); 1652f857971dSopenharmony_ci curNode = curNode->xmlChildrenNode; 1653f857971dSopenharmony_ci while (curNode != nullptr) { 1654f857971dSopenharmony_ci if (!xmlStrcmp(curNode->name, BAD_CAST "g")) { 1655f857971dSopenharmony_ci while (!xmlStrcmp(curNode->name, BAD_CAST "g")) { 1656f857971dSopenharmony_ci curNode = curNode->xmlChildrenNode; 1657f857971dSopenharmony_ci } 1658f857971dSopenharmony_ci break; 1659f857971dSopenharmony_ci } 1660f857971dSopenharmony_ci curNode = curNode->next; 1661f857971dSopenharmony_ci } 1662f857971dSopenharmony_ci FI_HILOGD("leave"); 1663f857971dSopenharmony_ci return curNode; 1664f857971dSopenharmony_ci} 1665f857971dSopenharmony_ci 1666f857971dSopenharmony_cixmlNodePtr DragDrawing::UpdateRectNode(int32_t extendSvgWidth, xmlNodePtr curNode) 1667f857971dSopenharmony_ci{ 1668f857971dSopenharmony_ci FI_HILOGD("enter"); 1669f857971dSopenharmony_ci while (curNode != nullptr) { 1670f857971dSopenharmony_ci if (!xmlStrcmp(curNode->name, BAD_CAST "rect")) { 1671f857971dSopenharmony_ci std::ostringstream oStrStream; 1672f857971dSopenharmony_ci oStrStream << xmlGetProp(curNode, BAD_CAST "width"); 1673f857971dSopenharmony_ci std::string srcRectWidth = oStrStream.str(); 1674f857971dSopenharmony_ci if (!IsNum(srcRectWidth)) { 1675f857971dSopenharmony_ci FI_HILOGE("srcRectWidth is not digital, srcRectWidth:%{public}s", srcRectWidth.c_str()); 1676f857971dSopenharmony_ci return nullptr; 1677f857971dSopenharmony_ci } 1678f857971dSopenharmony_ci int32_t number = std::stoi(srcRectWidth) + extendSvgWidth; 1679f857971dSopenharmony_ci xmlSetProp(curNode, BAD_CAST "width", BAD_CAST std::to_string(number).c_str()); 1680f857971dSopenharmony_ci } 1681f857971dSopenharmony_ci if (!xmlStrcmp(curNode->name, BAD_CAST "text")) { 1682f857971dSopenharmony_ci return curNode->xmlChildrenNode; 1683f857971dSopenharmony_ci } 1684f857971dSopenharmony_ci curNode = curNode->next; 1685f857971dSopenharmony_ci } 1686f857971dSopenharmony_ci FI_HILOGE("Empty node of XML"); 1687f857971dSopenharmony_ci return nullptr; 1688f857971dSopenharmony_ci} 1689f857971dSopenharmony_ci 1690f857971dSopenharmony_civoid DragDrawing::UpdateTspanNode(xmlNodePtr curNode) 1691f857971dSopenharmony_ci{ 1692f857971dSopenharmony_ci FI_HILOGD("enter"); 1693f857971dSopenharmony_ci while (curNode != nullptr) { 1694f857971dSopenharmony_ci if (!xmlStrcmp(curNode->name, BAD_CAST "tspan")) { 1695f857971dSopenharmony_ci xmlNodeSetContent(curNode, BAD_CAST std::to_string(g_drawingInfo.currentDragNum).c_str()); 1696f857971dSopenharmony_ci } 1697f857971dSopenharmony_ci curNode = curNode->next; 1698f857971dSopenharmony_ci } 1699f857971dSopenharmony_ci FI_HILOGD("leave"); 1700f857971dSopenharmony_ci} 1701f857971dSopenharmony_ci 1702f857971dSopenharmony_ciint32_t DragDrawing::ParseAndAdjustSvgInfo(xmlNodePtr curNode) 1703f857971dSopenharmony_ci{ 1704f857971dSopenharmony_ci FI_HILOGD("enter"); 1705f857971dSopenharmony_ci CHKPR(curNode, RET_ERR); 1706f857971dSopenharmony_ci std::string strStyle = std::to_string(g_drawingInfo.currentDragNum); 1707f857971dSopenharmony_ci if (strStyle.empty()) { 1708f857971dSopenharmony_ci FI_HILOGE("strStyle size:%{public}zu invalid", strStyle.size()); 1709f857971dSopenharmony_ci return RET_ERR; 1710f857971dSopenharmony_ci } 1711f857971dSopenharmony_ci int32_t extendSvgWidth = (static_cast<int32_t>(strStyle.size()) - 1) * EIGHT_SIZE; 1712f857971dSopenharmony_ci xmlKeepBlanksDefault(0); 1713f857971dSopenharmony_ci int32_t ret = UpdateSvgNodeInfo(curNode, extendSvgWidth); 1714f857971dSopenharmony_ci if (ret != RET_OK) { 1715f857971dSopenharmony_ci FI_HILOGE("Update svg node info failed, ret:%{public}d", ret); 1716f857971dSopenharmony_ci return RET_ERR; 1717f857971dSopenharmony_ci } 1718f857971dSopenharmony_ci curNode = GetRectNode(curNode); 1719f857971dSopenharmony_ci CHKPR(curNode, RET_ERR); 1720f857971dSopenharmony_ci curNode = UpdateRectNode(extendSvgWidth, curNode); 1721f857971dSopenharmony_ci CHKPR(curNode, RET_ERR); 1722f857971dSopenharmony_ci UpdateTspanNode(curNode); 1723f857971dSopenharmony_ci FI_HILOGD("leave"); 1724f857971dSopenharmony_ci return RET_OK; 1725f857971dSopenharmony_ci} 1726f857971dSopenharmony_ci 1727f857971dSopenharmony_cistd::shared_ptr<Media::PixelMap> DragDrawing::DecodeSvgToPixelMap( 1728f857971dSopenharmony_ci const std::string &filePath) 1729f857971dSopenharmony_ci{ 1730f857971dSopenharmony_ci FI_HILOGD("enter"); 1731f857971dSopenharmony_ci xmlDocPtr xmlDoc = xmlReadFile(filePath.c_str(), 0, XML_PARSE_NOBLANKS); 1732f857971dSopenharmony_ci if (NeedAdjustSvgInfo()) { 1733f857971dSopenharmony_ci xmlNodePtr node = xmlDocGetRootElement(xmlDoc); 1734f857971dSopenharmony_ci CHKPP(node); 1735f857971dSopenharmony_ci int32_t ret = ParseAndAdjustSvgInfo(node); 1736f857971dSopenharmony_ci if (ret != RET_OK) { 1737f857971dSopenharmony_ci FI_HILOGE("Parse and adjust svg info failed, ret:%{public}d", ret); 1738f857971dSopenharmony_ci return nullptr; 1739f857971dSopenharmony_ci } 1740f857971dSopenharmony_ci } 1741f857971dSopenharmony_ci xmlChar *xmlbuff = nullptr; 1742f857971dSopenharmony_ci int32_t buffersize = 0; 1743f857971dSopenharmony_ci xmlDocDumpFormatMemory(xmlDoc, &xmlbuff, &buffersize, 1); 1744f857971dSopenharmony_ci std::ostringstream oStrStream; 1745f857971dSopenharmony_ci oStrStream << xmlbuff; 1746f857971dSopenharmony_ci std::string content = oStrStream.str(); 1747f857971dSopenharmony_ci xmlFree(xmlbuff); 1748f857971dSopenharmony_ci xmlFreeDoc(xmlDoc); 1749f857971dSopenharmony_ci Media::SourceOptions opts; 1750f857971dSopenharmony_ci opts.formatHint = "image/svg+xml"; 1751f857971dSopenharmony_ci uint32_t errCode = 0; 1752f857971dSopenharmony_ci auto imageSource = Media::ImageSource::CreateImageSource(reinterpret_cast<const uint8_t*>(content.c_str()), 1753f857971dSopenharmony_ci content.size(), opts, errCode); 1754f857971dSopenharmony_ci CHKPP(imageSource); 1755f857971dSopenharmony_ci Media::DecodeOptions decodeOpts; 1756f857971dSopenharmony_ci SetDecodeOptions(decodeOpts); 1757f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode); 1758f857971dSopenharmony_ci FI_HILOGD("leave"); 1759f857971dSopenharmony_ci return pixelMap; 1760f857971dSopenharmony_ci} 1761f857971dSopenharmony_ci 1762f857971dSopenharmony_cibool DragDrawing::NeedAdjustSvgInfo() 1763f857971dSopenharmony_ci{ 1764f857971dSopenharmony_ci FI_HILOGD("enter"); 1765f857971dSopenharmony_ci if (g_drawingInfo.currentStyle == DragCursorStyle::DEFAULT) { 1766f857971dSopenharmony_ci return false; 1767f857971dSopenharmony_ci } 1768f857971dSopenharmony_ci if ((g_drawingInfo.currentStyle == DragCursorStyle::COPY) && 1769f857971dSopenharmony_ci (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) { 1770f857971dSopenharmony_ci return false; 1771f857971dSopenharmony_ci } 1772f857971dSopenharmony_ci if ((g_drawingInfo.currentStyle == DragCursorStyle::MOVE) && 1773f857971dSopenharmony_ci (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) { 1774f857971dSopenharmony_ci return false; 1775f857971dSopenharmony_ci } 1776f857971dSopenharmony_ci if ((g_drawingInfo.currentStyle == DragCursorStyle::FORBIDDEN) && 1777f857971dSopenharmony_ci (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) { 1778f857971dSopenharmony_ci return false; 1779f857971dSopenharmony_ci } 1780f857971dSopenharmony_ci FI_HILOGD("leave"); 1781f857971dSopenharmony_ci return true; 1782f857971dSopenharmony_ci} 1783f857971dSopenharmony_ci 1784f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 1785f857971dSopenharmony_ciint32_t DragDrawing::GetFilePath(std::string &filePath) 1786f857971dSopenharmony_ci{ 1787f857971dSopenharmony_ci FI_HILOGD("enter"); 1788f857971dSopenharmony_ci switch (g_drawingInfo.currentStyle) { 1789f857971dSopenharmony_ci case DragCursorStyle::COPY: { 1790f857971dSopenharmony_ci if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) { 1791f857971dSopenharmony_ci filePath = COPY_ONE_DRAG_PATH; 1792f857971dSopenharmony_ci } else { 1793f857971dSopenharmony_ci filePath = COPY_DRAG_PATH; 1794f857971dSopenharmony_ci } 1795f857971dSopenharmony_ci break; 1796f857971dSopenharmony_ci } 1797f857971dSopenharmony_ci case DragCursorStyle::MOVE: { 1798f857971dSopenharmony_ci filePath = MOVE_DRAG_PATH; 1799f857971dSopenharmony_ci break; 1800f857971dSopenharmony_ci } 1801f857971dSopenharmony_ci case DragCursorStyle::FORBIDDEN: { 1802f857971dSopenharmony_ci if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) { 1803f857971dSopenharmony_ci filePath = FORBID_ONE_DRAG_PATH; 1804f857971dSopenharmony_ci } else { 1805f857971dSopenharmony_ci filePath = FORBID_DRAG_PATH; 1806f857971dSopenharmony_ci } 1807f857971dSopenharmony_ci break; 1808f857971dSopenharmony_ci } 1809f857971dSopenharmony_ci case DragCursorStyle::DEFAULT: 1810f857971dSopenharmony_ci default: { 1811f857971dSopenharmony_ci FI_HILOGW("Not need draw svg style, DragCursorStyle:%{public}d", g_drawingInfo.currentStyle); 1812f857971dSopenharmony_ci break; 1813f857971dSopenharmony_ci } 1814f857971dSopenharmony_ci } 1815f857971dSopenharmony_ci FI_HILOGD("leave"); 1816f857971dSopenharmony_ci return RET_OK; 1817f857971dSopenharmony_ci} 1818f857971dSopenharmony_ci#else 1819f857971dSopenharmony_ciint32_t DragDrawing::GetFilePath(std::string &filePath) 1820f857971dSopenharmony_ci{ 1821f857971dSopenharmony_ci FI_HILOGD("enter"); 1822f857971dSopenharmony_ci switch (g_drawingInfo.currentStyle) { 1823f857971dSopenharmony_ci case DragCursorStyle::COPY: { 1824f857971dSopenharmony_ci if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) { 1825f857971dSopenharmony_ci filePath = svgFilePath_ + COPY_ONE_DRAG_NAME; 1826f857971dSopenharmony_ci } else { 1827f857971dSopenharmony_ci filePath = svgFilePath_ + COPY_DRAG_NAME; 1828f857971dSopenharmony_ci } 1829f857971dSopenharmony_ci break; 1830f857971dSopenharmony_ci } 1831f857971dSopenharmony_ci case DragCursorStyle::MOVE: { 1832f857971dSopenharmony_ci filePath = svgFilePath_ + MOVE_DRAG_NAME; 1833f857971dSopenharmony_ci break; 1834f857971dSopenharmony_ci } 1835f857971dSopenharmony_ci case DragCursorStyle::FORBIDDEN: { 1836f857971dSopenharmony_ci if (g_drawingInfo.currentDragNum == DRAG_NUM_ONE) { 1837f857971dSopenharmony_ci filePath = svgFilePath_ + FORBID_ONE_DRAG_NAME; 1838f857971dSopenharmony_ci } else { 1839f857971dSopenharmony_ci filePath = svgFilePath_ + FORBID_DRAG_NAME; 1840f857971dSopenharmony_ci } 1841f857971dSopenharmony_ci break; 1842f857971dSopenharmony_ci } 1843f857971dSopenharmony_ci case DragCursorStyle::DEFAULT: 1844f857971dSopenharmony_ci default: { 1845f857971dSopenharmony_ci FI_HILOGW("Not need draw svg style, DragCursorStyle:%{public}d", g_drawingInfo.currentStyle); 1846f857971dSopenharmony_ci break; 1847f857971dSopenharmony_ci } 1848f857971dSopenharmony_ci } 1849f857971dSopenharmony_ci FI_HILOGD("leave"); 1850f857971dSopenharmony_ci return RET_OK; 1851f857971dSopenharmony_ci} 1852f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 1853f857971dSopenharmony_ci 1854f857971dSopenharmony_civoid DragDrawing::SetDecodeOptions(Media::DecodeOptions &decodeOpts) 1855f857971dSopenharmony_ci{ 1856f857971dSopenharmony_ci FI_HILOGD("enter"); 1857f857971dSopenharmony_ci std::string strStyle = std::to_string(g_drawingInfo.currentDragNum); 1858f857971dSopenharmony_ci if (strStyle.empty()) { 1859f857971dSopenharmony_ci FI_HILOGE("strStyle size:%{public}zu invalid", strStyle.size()); 1860f857971dSopenharmony_ci return; 1861f857971dSopenharmony_ci } 1862f857971dSopenharmony_ci int32_t extendSvgWidth = (static_cast<int32_t>(strStyle.size()) - 1) * EIGHT_SIZE; 1863f857971dSopenharmony_ci if ((g_drawingInfo.currentStyle == DragCursorStyle::COPY) && (g_drawingInfo.currentDragNum == DRAG_NUM_ONE)) { 1864f857971dSopenharmony_ci decodeOpts.desiredSize = { 1865f857971dSopenharmony_ci .width = DEVICE_INDEPENDENT_PIXEL * GetScaling(), 1866f857971dSopenharmony_ci .height = DEVICE_INDEPENDENT_PIXEL * GetScaling() 1867f857971dSopenharmony_ci }; 1868f857971dSopenharmony_ci } else { 1869f857971dSopenharmony_ci decodeOpts.desiredSize = { 1870f857971dSopenharmony_ci .width = (DEVICE_INDEPENDENT_PIXEL + extendSvgWidth) * GetScaling(), 1871f857971dSopenharmony_ci .height = DEVICE_INDEPENDENT_PIXEL * GetScaling() 1872f857971dSopenharmony_ci }; 1873f857971dSopenharmony_ci } 1874f857971dSopenharmony_ci FI_HILOGD("leave"); 1875f857971dSopenharmony_ci} 1876f857971dSopenharmony_ci 1877f857971dSopenharmony_civoid DragDrawing::ParserDragShadowInfo(cJSON* filterInfoParser, FilterInfo &filterInfo) 1878f857971dSopenharmony_ci{ 1879f857971dSopenharmony_ci CHKPV(filterInfoParser); 1880f857971dSopenharmony_ci cJSON *offsetX = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "drag_shadow_offsetX"); 1881f857971dSopenharmony_ci if (cJSON_IsNumber(offsetX)) { 1882f857971dSopenharmony_ci filterInfo.offsetX = static_cast<float>(offsetX->valuedouble); 1883f857971dSopenharmony_ci } 1884f857971dSopenharmony_ci cJSON *offsetY = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "drag_shadow_offsetY"); 1885f857971dSopenharmony_ci if (cJSON_IsNumber(offsetY)) { 1886f857971dSopenharmony_ci filterInfo.offsetY = static_cast<float>(offsetY->valuedouble); 1887f857971dSopenharmony_ci } 1888f857971dSopenharmony_ci cJSON *argb = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "drag_shadow_argb"); 1889f857971dSopenharmony_ci if (cJSON_IsNumber(argb)) { 1890f857971dSopenharmony_ci filterInfo.argb = static_cast<uint32_t>(argb->valueint); 1891f857971dSopenharmony_ci } 1892f857971dSopenharmony_ci cJSON *shadowIsFilled = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "shadow_is_filled"); 1893f857971dSopenharmony_ci if (cJSON_IsBool(shadowIsFilled)) { 1894f857971dSopenharmony_ci filterInfo.shadowIsFilled = cJSON_IsTrue(shadowIsFilled); 1895f857971dSopenharmony_ci } 1896f857971dSopenharmony_ci cJSON *shadowMask = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "shadow_mask"); 1897f857971dSopenharmony_ci if (cJSON_IsBool(shadowMask)) { 1898f857971dSopenharmony_ci filterInfo.shadowMask = cJSON_IsTrue(shadowMask); 1899f857971dSopenharmony_ci } 1900f857971dSopenharmony_ci cJSON *shadowColorStrategy = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "shadow_color_strategy"); 1901f857971dSopenharmony_ci if (cJSON_IsNumber(shadowColorStrategy)) { 1902f857971dSopenharmony_ci filterInfo.shadowColorStrategy = shadowColorStrategy->valueint; 1903f857971dSopenharmony_ci } 1904f857971dSopenharmony_ci cJSON *isHardwareAcceleration = cJSON_GetObjectItemCaseSensitive( 1905f857971dSopenharmony_ci filterInfoParser, "shadow_is_hardwareacceleration"); 1906f857971dSopenharmony_ci if (cJSON_IsBool(isHardwareAcceleration)) { 1907f857971dSopenharmony_ci filterInfo.isHardwareAcceleration = cJSON_IsTrue(isHardwareAcceleration); 1908f857971dSopenharmony_ci } 1909f857971dSopenharmony_ci if (filterInfo.isHardwareAcceleration) { 1910f857971dSopenharmony_ci cJSON *elevation = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "shadow_elevation"); 1911f857971dSopenharmony_ci if (cJSON_IsNumber(elevation)) { 1912f857971dSopenharmony_ci filterInfo.elevation = static_cast<float>(elevation->valuedouble); 1913f857971dSopenharmony_ci } 1914f857971dSopenharmony_ci } else { 1915f857971dSopenharmony_ci cJSON *shadowCorner = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "shadow_corner"); 1916f857971dSopenharmony_ci if (cJSON_IsNumber(shadowCorner)) { 1917f857971dSopenharmony_ci filterInfo.shadowCorner = static_cast<float>(shadowCorner->valuedouble); 1918f857971dSopenharmony_ci } 1919f857971dSopenharmony_ci } 1920f857971dSopenharmony_ci} 1921f857971dSopenharmony_ci 1922f857971dSopenharmony_civoid DragDrawing::ParserTextDragShadowInfo(cJSON* filterInfoParser, FilterInfo &filterInfo) 1923f857971dSopenharmony_ci{ 1924f857971dSopenharmony_ci CHKPV(filterInfoParser); 1925f857971dSopenharmony_ci cJSON *path = cJSON_GetObjectItemCaseSensitive(filterInfoParser, "drag_shadow_path"); 1926f857971dSopenharmony_ci if (cJSON_IsString(path)) { 1927f857971dSopenharmony_ci float dragOriginDpi = DRAG_DATA_MGR.GetDragOriginDpi(); 1928f857971dSopenharmony_ci if (dragOriginDpi > EPSILON) { 1929f857971dSopenharmony_ci filterInfo.path = ""; 1930f857971dSopenharmony_ci } else { 1931f857971dSopenharmony_ci filterInfo.path = path->valuestring; 1932f857971dSopenharmony_ci } 1933f857971dSopenharmony_ci } 1934f857971dSopenharmony_ci} 1935f857971dSopenharmony_ci 1936f857971dSopenharmony_civoid DragDrawing::PrintDragShadowInfo() 1937f857971dSopenharmony_ci{ 1938f857971dSopenharmony_ci FilterInfo filterInfo = g_drawingInfo.filterInfo; 1939f857971dSopenharmony_ci if (!filterInfo.shadowEnable) { 1940f857971dSopenharmony_ci FI_HILOGI("Not supported shadow"); 1941f857971dSopenharmony_ci return; 1942f857971dSopenharmony_ci } 1943f857971dSopenharmony_ci FI_HILOGI("dragType:%{public}s, shadowIsFilled:%{public}s, shadowMask:%{public}s, shadowColorStrategy :%{public}d, " 1944f857971dSopenharmony_ci "shadowCorner:%{public}f, offsetX:%{private}f, offsetY:%{private}f, argb:%{public}u, elevation:%{public}f, " 1945f857971dSopenharmony_ci "isHardwareAcceleration:%{public}s", filterInfo.dragType.c_str(), 1946f857971dSopenharmony_ci filterInfo.shadowIsFilled ? "true" : "false", filterInfo.shadowMask ? "true" : "false", 1947f857971dSopenharmony_ci filterInfo.shadowColorStrategy, filterInfo.shadowCorner, filterInfo.offsetX, filterInfo.offsetY, 1948f857971dSopenharmony_ci filterInfo.argb, filterInfo.elevation, filterInfo.isHardwareAcceleration ? "true" : "false"); 1949f857971dSopenharmony_ci if (!filterInfo.path.empty()) { 1950f857971dSopenharmony_ci FI_HILOGI("path:%{private}s", filterInfo.path.c_str()); 1951f857971dSopenharmony_ci } 1952f857971dSopenharmony_ci} 1953f857971dSopenharmony_ci 1954f857971dSopenharmony_cibool DragDrawing::ParserFilterInfo(const std::string &filterInfoStr, FilterInfo &filterInfo) 1955f857971dSopenharmony_ci{ 1956f857971dSopenharmony_ci FI_HILOGD("FilterInfo size:%{public}zu, filterInfo:%{public}s", filterInfoStr.size(), filterInfoStr.c_str()); 1957f857971dSopenharmony_ci if (filterInfoStr.empty()) { 1958f857971dSopenharmony_ci FI_HILOGD("FilterInfo is empty"); 1959f857971dSopenharmony_ci return false; 1960f857971dSopenharmony_ci } 1961f857971dSopenharmony_ci JsonParser filterInfoParser; 1962f857971dSopenharmony_ci filterInfoParser.json = cJSON_Parse(filterInfoStr.c_str()); 1963f857971dSopenharmony_ci if (!cJSON_IsObject(filterInfoParser.json)) { 1964f857971dSopenharmony_ci FI_HILOGE("FilterInfo is not json object"); 1965f857971dSopenharmony_ci return false; 1966f857971dSopenharmony_ci } 1967f857971dSopenharmony_ci cJSON *dipScale = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "dip_scale"); 1968f857971dSopenharmony_ci if (cJSON_IsNumber(dipScale)) { 1969f857971dSopenharmony_ci filterInfo.dipScale = AdjustDoubleValue(dipScale->valuedouble); 1970f857971dSopenharmony_ci } 1971f857971dSopenharmony_ci cJSON *scale = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "scale"); 1972f857971dSopenharmony_ci if (cJSON_IsNumber(scale)) { 1973f857971dSopenharmony_ci filterInfo.scale = AdjustDoubleValue(scale->valuedouble); 1974f857971dSopenharmony_ci } 1975f857971dSopenharmony_ci ParserCornerRadiusInfo(filterInfoParser.json, g_drawingInfo.filterInfo); 1976f857971dSopenharmony_ci cJSON *dragType = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_type"); 1977f857971dSopenharmony_ci if (cJSON_IsString(dragType)) { 1978f857971dSopenharmony_ci filterInfo.dragType = dragType->valuestring; 1979f857971dSopenharmony_ci } 1980f857971dSopenharmony_ci cJSON *shadowEnable = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_enable"); 1981f857971dSopenharmony_ci if (cJSON_IsBool(shadowEnable)) { 1982f857971dSopenharmony_ci filterInfo.shadowEnable = cJSON_IsTrue(shadowEnable); 1983f857971dSopenharmony_ci } 1984f857971dSopenharmony_ci if (filterInfo.shadowEnable) { 1985f857971dSopenharmony_ci ParserDragShadowInfo(filterInfoParser.json, filterInfo); 1986f857971dSopenharmony_ci if (filterInfo.dragType == "text") { 1987f857971dSopenharmony_ci ParserTextDragShadowInfo(filterInfoParser.json, filterInfo); 1988f857971dSopenharmony_ci } 1989f857971dSopenharmony_ci PrintDragShadowInfo(); 1990f857971dSopenharmony_ci } 1991f857971dSopenharmony_ci ParserBlurInfo(filterInfoParser.json, g_drawingInfo.filterInfo); 1992f857971dSopenharmony_ci cJSON *dragNodeGrayscale = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_node_gray_scale"); 1993f857971dSopenharmony_ci if (cJSON_IsNumber(dragNodeGrayscale)) { 1994f857971dSopenharmony_ci filterInfo.dragNodeGrayscale = static_cast<float>(dragNodeGrayscale->valuedouble); 1995f857971dSopenharmony_ci } 1996f857971dSopenharmony_ci return true; 1997f857971dSopenharmony_ci} 1998f857971dSopenharmony_ci 1999f857971dSopenharmony_civoid DragDrawing::ParserCornerRadiusInfo(const cJSON *cornerRadiusInfoStr, FilterInfo &filterInfo) 2000f857971dSopenharmony_ci{ 2001f857971dSopenharmony_ci CHKPV(cornerRadiusInfoStr); 2002f857971dSopenharmony_ci cJSON *cornerRadius1 = cJSON_GetObjectItemCaseSensitive(cornerRadiusInfoStr, "drag_corner_radius1"); 2003f857971dSopenharmony_ci if (cJSON_IsNumber(cornerRadius1)) { 2004f857971dSopenharmony_ci filterInfo.cornerRadius1 = static_cast<float>(cornerRadius1->valuedouble); 2005f857971dSopenharmony_ci } 2006f857971dSopenharmony_ci cJSON *cornerRadius2 = cJSON_GetObjectItemCaseSensitive(cornerRadiusInfoStr, "drag_corner_radius2"); 2007f857971dSopenharmony_ci if (cJSON_IsNumber(cornerRadius2)) { 2008f857971dSopenharmony_ci filterInfo.cornerRadius2 = static_cast<float>(cornerRadius2->valuedouble); 2009f857971dSopenharmony_ci } 2010f857971dSopenharmony_ci cJSON *cornerRadius3 = cJSON_GetObjectItemCaseSensitive(cornerRadiusInfoStr, "drag_corner_radius3"); 2011f857971dSopenharmony_ci if (cJSON_IsNumber(cornerRadius3)) { 2012f857971dSopenharmony_ci filterInfo.cornerRadius3 = static_cast<float>(cornerRadius3->valuedouble); 2013f857971dSopenharmony_ci } 2014f857971dSopenharmony_ci cJSON *cornerRadius4 = cJSON_GetObjectItemCaseSensitive(cornerRadiusInfoStr, "drag_corner_radius4"); 2015f857971dSopenharmony_ci if (cJSON_IsNumber(cornerRadius4)) { 2016f857971dSopenharmony_ci filterInfo.cornerRadius4 = static_cast<float>(cornerRadius4->valuedouble); 2017f857971dSopenharmony_ci } 2018f857971dSopenharmony_ci} 2019f857971dSopenharmony_ci 2020f857971dSopenharmony_civoid DragDrawing::ParserBlurInfo(const cJSON *BlurInfoInfoStr, FilterInfo &filterInfo) 2021f857971dSopenharmony_ci{ 2022f857971dSopenharmony_ci CHKPV(BlurInfoInfoStr); 2023f857971dSopenharmony_ci cJSON *opacity = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "dip_opacity"); 2024f857971dSopenharmony_ci if (cJSON_IsNumber(opacity)) { 2025f857971dSopenharmony_ci if ((opacity->valuedouble) > MAX_OPACITY || (opacity->valuedouble) <= MIN_OPACITY) { 2026f857971dSopenharmony_ci FI_HILOGE("Parser opacity limits abnormal, opacity:%{public}f", opacity->valuedouble); 2027f857971dSopenharmony_ci } else { 2028f857971dSopenharmony_ci filterInfo.opacity = static_cast<float>(opacity->valuedouble); 2029f857971dSopenharmony_ci } 2030f857971dSopenharmony_ci } 2031f857971dSopenharmony_ci float tempCoef1 = 0.0f; 2032f857971dSopenharmony_ci cJSON *coef1 = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_coef1"); 2033f857971dSopenharmony_ci if (cJSON_IsNumber(coef1)) { 2034f857971dSopenharmony_ci tempCoef1 = static_cast<float>(coef1->valuedouble); 2035f857971dSopenharmony_ci } 2036f857971dSopenharmony_ci float tempCoef2 = 0.0f; 2037f857971dSopenharmony_ci cJSON *coef2 = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_coef2"); 2038f857971dSopenharmony_ci if (cJSON_IsNumber(coef2)) { 2039f857971dSopenharmony_ci tempCoef2 = static_cast<float>(coef2->valuedouble); 2040f857971dSopenharmony_ci } 2041f857971dSopenharmony_ci filterInfo.coef = { tempCoef1, tempCoef2 }; 2042f857971dSopenharmony_ci cJSON *blurRadius = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_radius"); 2043f857971dSopenharmony_ci if (cJSON_IsNumber(blurRadius)) { 2044f857971dSopenharmony_ci filterInfo.blurRadius = AdjustDoubleValue(blurRadius->valuedouble); 2045f857971dSopenharmony_ci } 2046f857971dSopenharmony_ci cJSON *blurStaturation = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_staturation"); 2047f857971dSopenharmony_ci if (cJSON_IsNumber(blurStaturation)) { 2048f857971dSopenharmony_ci filterInfo.blurStaturation = static_cast<float>(blurStaturation->valuedouble); 2049f857971dSopenharmony_ci } 2050f857971dSopenharmony_ci cJSON *blurBrightness = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_brightness"); 2051f857971dSopenharmony_ci if (cJSON_IsNumber(blurBrightness)) { 2052f857971dSopenharmony_ci filterInfo.blurBrightness = static_cast<float>(blurBrightness->valuedouble); 2053f857971dSopenharmony_ci } 2054f857971dSopenharmony_ci cJSON *blurColor = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_color"); 2055f857971dSopenharmony_ci if (cJSON_IsNumber(blurColor)) { 2056f857971dSopenharmony_ci filterInfo.blurColor = static_cast<uint32_t>(blurColor->valueint); 2057f857971dSopenharmony_ci } 2058f857971dSopenharmony_ci cJSON *blurStyle = cJSON_GetObjectItemCaseSensitive(BlurInfoInfoStr, "blur_style"); 2059f857971dSopenharmony_ci if (cJSON_IsNumber(blurStyle)) { 2060f857971dSopenharmony_ci filterInfo.blurStyle = blurStyle->valueint; 2061f857971dSopenharmony_ci } 2062f857971dSopenharmony_ci return; 2063f857971dSopenharmony_ci} 2064f857971dSopenharmony_ci 2065f857971dSopenharmony_cibool DragDrawing::ParserExtraInfo(const std::string &extraInfoStr, ExtraInfo &extraInfo) 2066f857971dSopenharmony_ci{ 2067f857971dSopenharmony_ci FI_HILOGD("ExtraInfo size:%{public}zu, extraInfo:%{public}s", 2068f857971dSopenharmony_ci extraInfoStr.size(), extraInfoStr.c_str()); 2069f857971dSopenharmony_ci if (extraInfoStr.empty()) { 2070f857971dSopenharmony_ci FI_HILOGD("ExtraInfo is empty"); 2071f857971dSopenharmony_ci return false; 2072f857971dSopenharmony_ci } 2073f857971dSopenharmony_ci JsonParser extraInfoParser; 2074f857971dSopenharmony_ci extraInfoParser.json = cJSON_Parse(extraInfoStr.c_str()); 2075f857971dSopenharmony_ci if (!cJSON_IsObject(extraInfoParser.json)) { 2076f857971dSopenharmony_ci FI_HILOGE("ExtraInfo is not json object"); 2077f857971dSopenharmony_ci return false; 2078f857971dSopenharmony_ci } 2079f857971dSopenharmony_ci cJSON *componentType = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_data_type"); 2080f857971dSopenharmony_ci if (cJSON_IsString(componentType)) { 2081f857971dSopenharmony_ci extraInfo.componentType = componentType->valuestring; 2082f857971dSopenharmony_ci } 2083f857971dSopenharmony_ci cJSON *blurStyle = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_blur_style"); 2084f857971dSopenharmony_ci if (cJSON_IsNumber(blurStyle)) { 2085f857971dSopenharmony_ci extraInfo.blurStyle = blurStyle->valueint; 2086f857971dSopenharmony_ci } 2087f857971dSopenharmony_ci cJSON *cornerRadius = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_corner_radius"); 2088f857971dSopenharmony_ci if (cJSON_IsNumber(cornerRadius)) { 2089f857971dSopenharmony_ci extraInfo.cornerRadius = static_cast<float>(cornerRadius->valuedouble); 2090f857971dSopenharmony_ci } 2091f857971dSopenharmony_ci cJSON *allowDistributed = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "drag_allow_distributed"); 2092f857971dSopenharmony_ci if (cJSON_IsBool(allowDistributed)) { 2093f857971dSopenharmony_ci extraInfo.allowDistributed = cJSON_IsTrue(allowDistributed) ? true : false; 2094f857971dSopenharmony_ci } 2095f857971dSopenharmony_ci float tempCoef1 = 0.0f; 2096f857971dSopenharmony_ci cJSON *coef1 = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "blur_coef1"); 2097f857971dSopenharmony_ci if (cJSON_IsNumber(coef1)) { 2098f857971dSopenharmony_ci tempCoef1 = static_cast<float>(coef1->valuedouble); 2099f857971dSopenharmony_ci } 2100f857971dSopenharmony_ci float tempCoef2 = 0.0f; 2101f857971dSopenharmony_ci cJSON *coef2 = cJSON_GetObjectItemCaseSensitive(extraInfoParser.json, "blur_coef2"); 2102f857971dSopenharmony_ci if (cJSON_IsNumber(coef2)) { 2103f857971dSopenharmony_ci tempCoef2 = static_cast<float>(coef2->valuedouble); 2104f857971dSopenharmony_ci } 2105f857971dSopenharmony_ci extraInfo.coef = { tempCoef1, tempCoef2 }; 2106f857971dSopenharmony_ci return true; 2107f857971dSopenharmony_ci} 2108f857971dSopenharmony_ci 2109f857971dSopenharmony_cibool DragDrawing::GetAllowDragState() 2110f857971dSopenharmony_ci{ 2111f857971dSopenharmony_ci return g_drawingInfo.extraInfo.allowDistributed; 2112f857971dSopenharmony_ci} 2113f857971dSopenharmony_ci 2114f857971dSopenharmony_civoid DragDrawing::SetScreenId(uint64_t screenId) 2115f857971dSopenharmony_ci{ 2116f857971dSopenharmony_ci FI_HILOGD("enter"); 2117f857971dSopenharmony_ci screenId_ = screenId; 2118f857971dSopenharmony_ci} 2119f857971dSopenharmony_ci 2120f857971dSopenharmony_ciint32_t DragDrawing::RotateDragWindow(Rosen::Rotation rotation, 2121f857971dSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction, bool isAnimated) 2122f857971dSopenharmony_ci{ 2123f857971dSopenharmony_ci if (needRotatePixelMapXY_) { 2124f857971dSopenharmony_ci CHKPR(g_drawingInfo.pixelMap, RET_ERR); 2125f857971dSopenharmony_ci g_drawingInfo.pixelMapX = -(HALF_RATIO * g_drawingInfo.pixelMap->GetWidth()); 2126f857971dSopenharmony_ci g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling()); 2127f857971dSopenharmony_ci } 2128f857971dSopenharmony_ci float rotateAngle = (rotation == Rosen::Rotation::ROTATION_0) ? ROTATION_0 : 2129f857971dSopenharmony_ci ROTATION_360 - (ROTATION_90 * static_cast<int32_t>(rotation)); 2130f857971dSopenharmony_ci FI_HILOGI("rotateAngle:%{public}f, isAnimated:%{public}d", rotateAngle, isAnimated); 2131f857971dSopenharmony_ci return DoRotateDragWindow(rotateAngle, rsTransaction, isAnimated); 2132f857971dSopenharmony_ci} 2133f857971dSopenharmony_ci 2134f857971dSopenharmony_civoid DragDrawing::RotateCanvasNode(float pivotX, float pivotY, float rotation) 2135f857971dSopenharmony_ci{ 2136f857971dSopenharmony_ci FI_HILOGD("enter"); 2137f857971dSopenharmony_ci CHKPV(g_drawingInfo.parentNode); 2138f857971dSopenharmony_ci g_drawingInfo.parentNode->SetPivot(pivotX, pivotY); 2139f857971dSopenharmony_ci g_drawingInfo.parentNode->SetRotation(rotation); 2140f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty()) { 2141f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 2142f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedNodesSize; ++i) { 2143f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = g_drawingInfo.multiSelectedNodes[i]; 2144f857971dSopenharmony_ci CHKPV(multiSelectedNode); 2145f857971dSopenharmony_ci float degrees = DEFAULT_ANGLE; 2146f857971dSopenharmony_ci if (i == FIRST_PIXELMAP_INDEX) { 2147f857971dSopenharmony_ci degrees = rotation + POSITIVE_ANGLE; 2148f857971dSopenharmony_ci } else if (i == SECOND_PIXELMAP_INDEX) { 2149f857971dSopenharmony_ci degrees = rotation + NEGATIVE_ANGLE; 2150f857971dSopenharmony_ci } 2151f857971dSopenharmony_ci multiSelectedNode->SetPivot(HALF_PIVOT, HALF_PIVOT); 2152f857971dSopenharmony_ci multiSelectedNode->SetRotation(degrees); 2153f857971dSopenharmony_ci } 2154f857971dSopenharmony_ci } 2155f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 2156f857971dSopenharmony_ci if (!CheckNodesValid()) { 2157f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2158f857971dSopenharmony_ci return; 2159f857971dSopenharmony_ci } 2160f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 2161f857971dSopenharmony_ci CHKPV(mouseIconNode); 2162f857971dSopenharmony_ci mouseIconNode->SetPivot(DEFAULT_PIVOT, DEFAULT_PIVOT); 2163f857971dSopenharmony_ci mouseIconNode->SetRotation(rotation); 2164f857971dSopenharmony_ci } 2165f857971dSopenharmony_ci float positionX = g_drawingInfo.currentPositionX; 2166f857971dSopenharmony_ci float positionY = g_drawingInfo.currentPositionY; 2167f857971dSopenharmony_ci AdjustRotateDisplayXY(positionX, positionY); 2168f857971dSopenharmony_ci DrawRotateDisplayXY(positionX, positionY); 2169f857971dSopenharmony_ci FI_HILOGD("leave"); 2170f857971dSopenharmony_ci} 2171f857971dSopenharmony_ci 2172f857971dSopenharmony_civoid DragDrawing::SetRotation(Rosen::Rotation rotation) 2173f857971dSopenharmony_ci{ 2174f857971dSopenharmony_ci rotation_ = rotation; 2175f857971dSopenharmony_ci} 2176f857971dSopenharmony_ci 2177f857971dSopenharmony_civoid DragDrawing::ProcessFilter() 2178f857971dSopenharmony_ci{ 2179f857971dSopenharmony_ci FI_HILOGD("enter"); 2180f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= BACKGROUND_FILTER_INDEX) { 2181f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 2182f857971dSopenharmony_ci return; 2183f857971dSopenharmony_ci } 2184f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> filterNode = g_drawingInfo.nodes[BACKGROUND_FILTER_INDEX]; 2185f857971dSopenharmony_ci CHKPV(filterNode); 2186f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2187f857971dSopenharmony_ci FilterInfo filterInfo = g_drawingInfo.filterInfo; 2188f857971dSopenharmony_ci ExtraInfo extraInfo = g_drawingInfo.extraInfo; 2189f857971dSopenharmony_ci if (filterInfo.blurStyle != -1) { 2190f857971dSopenharmony_ci SetCustomDragBlur(filterInfo, filterNode); 2191f857971dSopenharmony_ci } else if (extraInfo.componentType == BIG_FOLDER_LABEL) { 2192f857971dSopenharmony_ci SetComponentDragBlur(filterInfo, extraInfo, filterNode); 2193f857971dSopenharmony_ci } 2194f857971dSopenharmony_ci FI_HILOGD("Add filter successfully"); 2195f857971dSopenharmony_ci FI_HILOGD("leave"); 2196f857971dSopenharmony_ci} 2197f857971dSopenharmony_ci 2198f857971dSopenharmony_civoid DragDrawing::SetCustomDragBlur(const FilterInfo &filterInfo, std::shared_ptr<Rosen::RSCanvasNode> filterNode) 2199f857971dSopenharmony_ci{ 2200f857971dSopenharmony_ci CHKPV(filterNode); 2201f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2202f857971dSopenharmony_ci Rosen::BLUR_COLOR_MODE mode = (Rosen::BLUR_COLOR_MODE)filterInfo.blurStyle; 2203f857971dSopenharmony_ci std::shared_ptr<Rosen::RSFilter> backFilter = Rosen::RSFilter::CreateMaterialFilter( 2204f857971dSopenharmony_ci RadiusVp2Sigma(filterInfo.blurRadius, filterInfo.dipScale), 2205f857971dSopenharmony_ci filterInfo.blurStaturation, filterInfo.blurBrightness, filterInfo.blurColor, mode); 2206f857971dSopenharmony_ci if (backFilter == nullptr) { 2207f857971dSopenharmony_ci FI_HILOGE("Create backgroundFilter failed"); 2208f857971dSopenharmony_ci return; 2209f857971dSopenharmony_ci } 2210f857971dSopenharmony_ci filterNode->SetBackgroundFilter(backFilter); 2211f857971dSopenharmony_ci filterNode->SetGreyCoef(filterInfo.coef); 2212f857971dSopenharmony_ci filterNode->SetAlpha(filterInfo.opacity); 2213f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 2214f857971dSopenharmony_ci filterNode->SetBounds(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(), 2215f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight()); 2216f857971dSopenharmony_ci filterNode->SetFrame(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(), 2217f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight()); 2218f857971dSopenharmony_ci if ((filterInfo.blurRadius < 0) || (filterInfo.dipScale < 0) || 2219f857971dSopenharmony_ci (fabs(filterInfo.dipScale) < EPSILON) || ((std::numeric_limits<float>::max() 2220f857971dSopenharmony_ci / filterInfo.dipScale) < filterInfo.blurRadius)) { 2221f857971dSopenharmony_ci FI_HILOGE("Invalid parameters, cornerRadius:%{public}f, dipScale:%{public}f", 2222f857971dSopenharmony_ci filterInfo.blurRadius, filterInfo.dipScale); 2223f857971dSopenharmony_ci return; 2224f857971dSopenharmony_ci } 2225f857971dSopenharmony_ci Rosen::Vector4f cornerRadiusVector = { filterInfo.cornerRadius1, filterInfo.cornerRadius2, 2226f857971dSopenharmony_ci filterInfo.cornerRadius3, filterInfo.cornerRadius4 }; 2227f857971dSopenharmony_ci filterNode->SetCornerRadius(cornerRadiusVector * filterInfo.dipScale); 2228f857971dSopenharmony_ci FI_HILOGD("Set custom drag blur successfully"); 2229f857971dSopenharmony_ci} 2230f857971dSopenharmony_ci 2231f857971dSopenharmony_civoid DragDrawing::SetComponentDragBlur(const FilterInfo &filterInfo, const ExtraInfo &extraInfo, 2232f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> filterNode) 2233f857971dSopenharmony_ci{ 2234f857971dSopenharmony_ci CHKPV(filterNode); 2235f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2236f857971dSopenharmony_ci std::shared_ptr<Rosen::RSFilter> backFilter = Rosen::RSFilter::CreateMaterialFilter( 2237f857971dSopenharmony_ci RadiusVp2Sigma(RADIUS_VP, filterInfo.dipScale), 2238f857971dSopenharmony_ci DEFAULT_SATURATION, DEFAULT_BRIGHTNESS, DEFAULT_COLOR_VALUE); 2239f857971dSopenharmony_ci if (backFilter == nullptr) { 2240f857971dSopenharmony_ci FI_HILOGE("Create backgroundFilter failed"); 2241f857971dSopenharmony_ci return; 2242f857971dSopenharmony_ci } 2243f857971dSopenharmony_ci filterNode->SetBackgroundFilter(backFilter); 2244f857971dSopenharmony_ci filterNode->SetGreyCoef(extraInfo.coef); 2245f857971dSopenharmony_ci filterNode->SetAlpha(filterInfo.opacity); 2246f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 2247f857971dSopenharmony_ci filterNode->SetBounds(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(), 2248f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight()); 2249f857971dSopenharmony_ci filterNode->SetFrame(DEFAULT_POSITION_X, adjustSize, g_drawingInfo.pixelMap->GetWidth(), 2250f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight()); 2251f857971dSopenharmony_ci if ((extraInfo.cornerRadius < 0) || (filterInfo.dipScale < 0) || 2252f857971dSopenharmony_ci (fabs(filterInfo.dipScale) < EPSILON) || ((std::numeric_limits<float>::max() 2253f857971dSopenharmony_ci / filterInfo.dipScale) < extraInfo.cornerRadius)) { 2254f857971dSopenharmony_ci FI_HILOGE("Invalid parameters, cornerRadius:%{public}f, dipScale:%{public}f", 2255f857971dSopenharmony_ci extraInfo.cornerRadius, filterInfo.dipScale); 2256f857971dSopenharmony_ci return; 2257f857971dSopenharmony_ci } 2258f857971dSopenharmony_ci filterNode->SetCornerRadius(extraInfo.cornerRadius * filterInfo.dipScale); 2259f857971dSopenharmony_ci FI_HILOGD("Set component drag blur successfully"); 2260f857971dSopenharmony_ci return; 2261f857971dSopenharmony_ci} 2262f857971dSopenharmony_ci 2263f857971dSopenharmony_ciint32_t DragDrawing::SetNodesLocation(int32_t positionX, int32_t positionY) 2264f857971dSopenharmony_ci{ 2265f857971dSopenharmony_ci FI_HILOGD("enter"); 2266f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 2267f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 2268f857971dSopenharmony_ci CHKPR(g_drawingInfo.parentNode, RET_ERR); 2269f857971dSopenharmony_ci CHKPR(g_drawingInfo.pixelMap, RET_ERR); 2270f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, SPRING, [&]() { 2271f857971dSopenharmony_ci g_drawingInfo.parentNode->SetBounds(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(), 2272f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight() + adjustSize); 2273f857971dSopenharmony_ci g_drawingInfo.parentNode->SetFrame(positionX, positionY, g_drawingInfo.pixelMap->GetWidth(), 2274f857971dSopenharmony_ci g_drawingInfo.pixelMap->GetHeight() + adjustSize); 2275f857971dSopenharmony_ci }, []() { FI_HILOGD("SetNodesLocation end"); }); 2276f857971dSopenharmony_ci#ifdef IOS_PLATFORM 2277f857971dSopenharmony_ci g_drawingInfo.startNum = actionTime_; // IOS animation starts time 2278f857971dSopenharmony_ci#else 2279f857971dSopenharmony_ci g_drawingInfo.startNum = START_TIME; 2280f857971dSopenharmony_ci#endif // IOS_PLATFORM 2281f857971dSopenharmony_ci g_drawingInfo.needDestroyDragWindow = false; 2282f857971dSopenharmony_ci StartVsync(); 2283f857971dSopenharmony_ci FI_HILOGD("leave"); 2284f857971dSopenharmony_ci return RET_OK; 2285f857971dSopenharmony_ci} 2286f857971dSopenharmony_ci 2287f857971dSopenharmony_ci 2288f857971dSopenharmony_ciint32_t DragDrawing::EnterTextEditorArea(bool enable) 2289f857971dSopenharmony_ci{ 2290f857971dSopenharmony_ci FI_HILOGD("enter"); 2291f857971dSopenharmony_ci if (enable) { 2292f857971dSopenharmony_ci DRAG_DATA_MGR.SetInitialPixelMapLocation({ g_drawingInfo.pixelMapX, g_drawingInfo.pixelMapY }); 2293f857971dSopenharmony_ci needRotatePixelMapXY_ = true; 2294f857971dSopenharmony_ci RotatePixelMapXY(); 2295f857971dSopenharmony_ci } else { 2296f857971dSopenharmony_ci needRotatePixelMapXY_ = false; 2297f857971dSopenharmony_ci auto initialPixelMapLocation = DRAG_DATA_MGR.GetInitialPixelMapLocation(); 2298f857971dSopenharmony_ci g_drawingInfo.pixelMapX = initialPixelMapLocation.first; 2299f857971dSopenharmony_ci g_drawingInfo.pixelMapY = initialPixelMapLocation.second; 2300f857971dSopenharmony_ci } 2301f857971dSopenharmony_ci DRAG_DATA_MGR.SetPixelMapLocation({ g_drawingInfo.pixelMapX, g_drawingInfo.pixelMapY }); 2302f857971dSopenharmony_ci float displayX = g_drawingInfo.currentPositionX; 2303f857971dSopenharmony_ci float displayY = g_drawingInfo.currentPositionY; 2304f857971dSopenharmony_ci AdjustRotateDisplayXY(displayX, displayY); 2305f857971dSopenharmony_ci int32_t positionX = displayX + g_drawingInfo.pixelMapX; 2306f857971dSopenharmony_ci int32_t positionY = displayY + g_drawingInfo.pixelMapY - TWELVE_SIZE * GetScaling(); 2307f857971dSopenharmony_ci if (RunAnimation([this, positionX, positionY] { 2308f857971dSopenharmony_ci return this->SetNodesLocation(positionX, positionY); 2309f857971dSopenharmony_ci }) != RET_OK) { 2310f857971dSopenharmony_ci FI_HILOGE("RunAnimation to SetNodesLocation failed"); 2311f857971dSopenharmony_ci return RET_ERR; 2312f857971dSopenharmony_ci } 2313f857971dSopenharmony_ci DRAG_DATA_MGR.SetTextEditorAreaFlag(enable); 2314f857971dSopenharmony_ci FI_HILOGI("EnterTextEditorArea %{public}s successfully", (enable ? "true" : "false")); 2315f857971dSopenharmony_ci return RET_OK; 2316f857971dSopenharmony_ci} 2317f857971dSopenharmony_ci 2318f857971dSopenharmony_cifloat DragDrawing::RadiusVp2Sigma(float radiusVp, float dipScale) 2319f857971dSopenharmony_ci{ 2320f857971dSopenharmony_ci float radiusPx = radiusVp * dipScale; 2321f857971dSopenharmony_ci return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f; 2322f857971dSopenharmony_ci} 2323f857971dSopenharmony_ci 2324f857971dSopenharmony_ciint32_t DragDrawing::UpdatePreviewStyle(const PreviewStyle &previewStyle) 2325f857971dSopenharmony_ci{ 2326f857971dSopenharmony_ci FI_HILOGD("enter"); 2327f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= PIXEL_MAP_INDEX) { 2328f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 2329f857971dSopenharmony_ci return RET_ERR; 2330f857971dSopenharmony_ci } else if (ModifyPreviewStyle(g_drawingInfo.nodes[PIXEL_MAP_INDEX], previewStyle) != RET_OK) { 2331f857971dSopenharmony_ci FI_HILOGE("ModifyPreviewStyle failed"); 2332f857971dSopenharmony_ci return RET_ERR; 2333f857971dSopenharmony_ci } 2334f857971dSopenharmony_ci if (ModifyMultiPreviewStyle(std::vector<PreviewStyle>(g_drawingInfo.multiSelectedNodes.size(), previewStyle)) != 2335f857971dSopenharmony_ci RET_OK) { 2336f857971dSopenharmony_ci FI_HILOGE("ModifyPreviewStyle failed"); 2337f857971dSopenharmony_ci return RET_ERR; 2338f857971dSopenharmony_ci } 2339f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 2340f857971dSopenharmony_ci FI_HILOGD("leave"); 2341f857971dSopenharmony_ci return RET_OK; 2342f857971dSopenharmony_ci} 2343f857971dSopenharmony_ci 2344f857971dSopenharmony_ciint32_t DragDrawing::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 2345f857971dSopenharmony_ci const PreviewAnimation &animation) 2346f857971dSopenharmony_ci{ 2347f857971dSopenharmony_ci FI_HILOGD("enter"); 2348f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 2349f857971dSopenharmony_ci CHKPR(pixelMapNode, RET_ERR); 2350f857971dSopenharmony_ci PreviewStyle originStyle; 2351f857971dSopenharmony_ci originStyle.types = previewStyle.types; 2352f857971dSopenharmony_ci if (auto color = pixelMapNode->GetShowingProperties().GetForegroundColor(); color.has_value()) { 2353f857971dSopenharmony_ci originStyle.foregroundColor = color->AsArgbInt(); 2354f857971dSopenharmony_ci originStyle.radius = previewStyle.radius; 2355f857971dSopenharmony_ci } 2356f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 2357f857971dSopenharmony_ci std::vector<PreviewStyle> multiOriginStyles; 2358f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedNodesSize; ++i) { 2359f857971dSopenharmony_ci if (auto color = g_drawingInfo.multiSelectedNodes[i]->GetShowingProperties().GetForegroundColor(); 2360f857971dSopenharmony_ci color.has_value()) { 2361f857971dSopenharmony_ci PreviewStyle currentStyle; 2362f857971dSopenharmony_ci currentStyle.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS }; 2363f857971dSopenharmony_ci currentStyle.foregroundColor = color->AsArgbInt(); 2364f857971dSopenharmony_ci currentStyle.radius = previewStyle.radius; 2365f857971dSopenharmony_ci multiOriginStyles.push_back(currentStyle); 2366f857971dSopenharmony_ci } 2367f857971dSopenharmony_ci } 2368f857971dSopenharmony_ci if (ModifyPreviewStyle(pixelMapNode, originStyle) != RET_OK) { 2369f857971dSopenharmony_ci FI_HILOGE("ModifyPreviewStyle failed"); 2370f857971dSopenharmony_ci return RET_ERR; 2371f857971dSopenharmony_ci } 2372f857971dSopenharmony_ci if (ModifyMultiPreviewStyle(multiOriginStyles) != RET_OK) { 2373f857971dSopenharmony_ci FI_HILOGE("ModifyMultiPreviewStyle failed"); 2374f857971dSopenharmony_ci return RET_ERR; 2375f857971dSopenharmony_ci } 2376f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 2377f857971dSopenharmony_ci protocol.SetDuration(animation.duration); 2378f857971dSopenharmony_ci auto curve = AnimationCurve::CreateCurve(animation.curveName, animation.curve); 2379f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, curve, [&]() { 2380f857971dSopenharmony_ci if (ModifyPreviewStyle(pixelMapNode, previewStyle) != RET_OK) { 2381f857971dSopenharmony_ci FI_HILOGE("ModifyPreviewStyle failed"); 2382f857971dSopenharmony_ci } 2383f857971dSopenharmony_ci if (ModifyMultiPreviewStyle(std::vector<PreviewStyle>(multiSelectedNodesSize, previewStyle)) != RET_OK) { 2384f857971dSopenharmony_ci FI_HILOGE("ModifyMultiPreviewStyle failed"); 2385f857971dSopenharmony_ci } 2386f857971dSopenharmony_ci }, []() { FI_HILOGD("UpdatePreviewStyleWithAnimation end"); }); 2387f857971dSopenharmony_ci FI_HILOGD("leave"); 2388f857971dSopenharmony_ci return RET_OK; 2389f857971dSopenharmony_ci} 2390f857971dSopenharmony_ci 2391f857971dSopenharmony_civoid DragDrawing::UpdateMousePosition(float mousePositionX, float mousePositionY) 2392f857971dSopenharmony_ci{ 2393f857971dSopenharmony_ci if (!CheckNodesValid()) { 2394f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2395f857971dSopenharmony_ci return; 2396f857971dSopenharmony_ci } 2397f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) { 2398f857971dSopenharmony_ci FI_HILOGE("The index out of bounds, node size:%{public}zu", g_drawingInfo.nodes.size()); 2399f857971dSopenharmony_ci return; 2400f857971dSopenharmony_ci } 2401f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 2402f857971dSopenharmony_ci CHKPV(mouseIconNode); 2403f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2404f857971dSopenharmony_ci if (pointerStyle_.id == MOUSE_DRAG_CURSOR_CIRCLE_STYLE || pointerStyle_.options == MAGIC_STYLE_OPT) { 2405f857971dSopenharmony_ci float positionX = mousePositionX - (static_cast<float>(g_drawingInfo.mouseWidth) / CURSOR_CIRCLE_MIDDLE); 2406f857971dSopenharmony_ci float positionY = mousePositionY - (static_cast<float>(g_drawingInfo.mouseHeight) / CURSOR_CIRCLE_MIDDLE); 2407f857971dSopenharmony_ci mouseIconNode->SetBounds(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2408f857971dSopenharmony_ci mouseIconNode->SetFrame(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2409f857971dSopenharmony_ci } else { 2410f857971dSopenharmony_ci mouseIconNode->SetBounds(mousePositionX, mousePositionY, 2411f857971dSopenharmony_ci g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2412f857971dSopenharmony_ci mouseIconNode->SetFrame(mousePositionX, mousePositionY, 2413f857971dSopenharmony_ci g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2414f857971dSopenharmony_ci } 2415f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2416f857971dSopenharmony_ci} 2417f857971dSopenharmony_ci 2418f857971dSopenharmony_ciint32_t DragDrawing::RotateDragWindowAsync(Rosen::Rotation rotation) 2419f857971dSopenharmony_ci{ 2420f857971dSopenharmony_ci isRunningRotateAnimation_ = true; 2421f857971dSopenharmony_ci int32_t repeatTime = 1; 2422f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2423f857971dSopenharmony_ci CHKPR(context_, RET_ERR); 2424f857971dSopenharmony_ci timerId_ = context_->GetTimerManager().AddTimer(ASYNC_ROTATE_TIME, repeatTime, [this]() { 2425f857971dSopenharmony_ci RotateDragWindow(rotation_, nullptr, true); 2426f857971dSopenharmony_ci isRunningRotateAnimation_ = false; 2427f857971dSopenharmony_ci }); 2428f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2429f857971dSopenharmony_ci if (timerId_ < 0) { 2430f857971dSopenharmony_ci FI_HILOGE("Add timer failed, timerId_:%{public}d", timerId_); 2431f857971dSopenharmony_ci isRunningRotateAnimation_ = false; 2432f857971dSopenharmony_ci return RET_ERR; 2433f857971dSopenharmony_ci } 2434f857971dSopenharmony_ci return RET_OK; 2435f857971dSopenharmony_ci} 2436f857971dSopenharmony_ci 2437f857971dSopenharmony_ciint32_t DragDrawing::RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) 2438f857971dSopenharmony_ci{ 2439f857971dSopenharmony_ci FI_HILOGD("enter"); 2440f857971dSopenharmony_ci isRunningRotateAnimation_ = true; 2441f857971dSopenharmony_ci RotateDragWindow(rotation_, rsTransaction, true); 2442f857971dSopenharmony_ci isRunningRotateAnimation_ = false; 2443f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2444f857971dSopenharmony_ci if ((context_ != nullptr) && (timerId_ >= 0)) { 2445f857971dSopenharmony_ci context_->GetTimerManager().RemoveTimer(timerId_); 2446f857971dSopenharmony_ci timerId_ = -1; 2447f857971dSopenharmony_ci } 2448f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2449f857971dSopenharmony_ci return RET_OK; 2450f857971dSopenharmony_ci} 2451f857971dSopenharmony_ci 2452f857971dSopenharmony_civoid DragDrawing::DoDrawMouse(int32_t mousePositionX, int32_t mousePositionY) 2453f857971dSopenharmony_ci{ 2454f857971dSopenharmony_ci if (!CheckNodesValid()) { 2455f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2456f857971dSopenharmony_ci return; 2457f857971dSopenharmony_ci } 2458f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) { 2459f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 2460f857971dSopenharmony_ci return; 2461f857971dSopenharmony_ci } 2462f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2463f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 2464f857971dSopenharmony_ci CHKPV(mouseIconNode); 2465f857971dSopenharmony_ci if (pointerStyle_.id == MOUSE_DRAG_CURSOR_CIRCLE_STYLE || pointerStyle_.options == MAGIC_STYLE_OPT) { 2466f857971dSopenharmony_ci int32_t positionX = mousePositionX - (g_drawingInfo.mouseWidth / CURSOR_CIRCLE_MIDDLE); 2467f857971dSopenharmony_ci int32_t positionY = mousePositionY - (g_drawingInfo.mouseHeight / CURSOR_CIRCLE_MIDDLE); 2468f857971dSopenharmony_ci mouseIconNode->SetBounds(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2469f857971dSopenharmony_ci mouseIconNode->SetFrame(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2470f857971dSopenharmony_ci } else { 2471f857971dSopenharmony_ci mouseIconNode->SetBounds(mousePositionX, mousePositionY, 2472f857971dSopenharmony_ci g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2473f857971dSopenharmony_ci mouseIconNode->SetFrame(mousePositionX, mousePositionY, 2474f857971dSopenharmony_ci g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight); 2475f857971dSopenharmony_ci } 2476f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2477f857971dSopenharmony_ci} 2478f857971dSopenharmony_ci 2479f857971dSopenharmony_ciint32_t DragDrawing::UpdateDefaultDragStyle(DragCursorStyle style) 2480f857971dSopenharmony_ci{ 2481f857971dSopenharmony_ci if (!CheckNodesValid()) { 2482f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2483f857971dSopenharmony_ci return RET_ERR; 2484f857971dSopenharmony_ci } 2485f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 2486f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 2487f857971dSopenharmony_ci return RET_ERR; 2488f857971dSopenharmony_ci } 2489f857971dSopenharmony_ci if (!g_drawingInfo.isCurrentDefaultStyle) { 2490f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 2491f857971dSopenharmony_ci CHKPR(dragStyleNode, RET_ERR); 2492f857971dSopenharmony_ci CHKPR(g_drawingInfo.parentNode, RET_ERR); 2493f857971dSopenharmony_ci g_drawingInfo.parentNode->RemoveChild(dragStyleNode); 2494f857971dSopenharmony_ci CHKPR(rsUiDirector_, RET_ERR); 2495f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 2496f857971dSopenharmony_ci } 2497f857971dSopenharmony_ci g_drawingInfo.currentStyle = style; 2498f857971dSopenharmony_ci bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle; 2499f857971dSopenharmony_ci g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle; 2500f857971dSopenharmony_ci g_drawingInfo.isCurrentDefaultStyle = true; 2501f857971dSopenharmony_ci return RET_OK; 2502f857971dSopenharmony_ci} 2503f857971dSopenharmony_ci 2504f857971dSopenharmony_ciint32_t DragDrawing::UpdateValidDragStyle(DragCursorStyle style) 2505f857971dSopenharmony_ci{ 2506f857971dSopenharmony_ci g_drawingInfo.currentStyle = style; 2507f857971dSopenharmony_ci if (g_drawingInfo.isCurrentDefaultStyle) { 2508f857971dSopenharmony_ci if (!CheckNodesValid()) { 2509f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2510f857971dSopenharmony_ci return RET_ERR; 2511f857971dSopenharmony_ci } 2512f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 2513f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 2514f857971dSopenharmony_ci return RET_ERR; 2515f857971dSopenharmony_ci } 2516f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 2517f857971dSopenharmony_ci CHKPR(dragStyleNode, RET_ERR); 2518f857971dSopenharmony_ci CHKPR(g_drawingInfo.parentNode, RET_ERR); 2519f857971dSopenharmony_ci g_drawingInfo.parentNode->AddChild(dragStyleNode); 2520f857971dSopenharmony_ci } 2521f857971dSopenharmony_ci std::string filePath; 2522f857971dSopenharmony_ci if (GetFilePath(filePath) != RET_OK) { 2523f857971dSopenharmony_ci FI_HILOGD("Get file path failed"); 2524f857971dSopenharmony_ci return RET_ERR; 2525f857971dSopenharmony_ci } 2526f857971dSopenharmony_ci if (!IsValidSvgFile(filePath)) { 2527f857971dSopenharmony_ci FI_HILOGE("Svg file is invalid"); 2528f857971dSopenharmony_ci return RET_ERR; 2529f857971dSopenharmony_ci } 2530f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap = DecodeSvgToPixelMap(filePath); 2531f857971dSopenharmony_ci CHKPR(pixelMap, RET_ERR); 2532f857971dSopenharmony_ci bool isPreviousDefaultStyle = g_drawingInfo.isCurrentDefaultStyle; 2533f857971dSopenharmony_ci g_drawingInfo.isPreviousDefaultStyle = isPreviousDefaultStyle; 2534f857971dSopenharmony_ci g_drawingInfo.isCurrentDefaultStyle = false; 2535f857971dSopenharmony_ci g_drawingInfo.stylePixelMap = pixelMap; 2536f857971dSopenharmony_ci if (!CheckNodesValid()) { 2537f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 2538f857971dSopenharmony_ci return RET_ERR; 2539f857971dSopenharmony_ci } 2540f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 2541f857971dSopenharmony_ci CHKPR(dragStyleNode, RET_ERR); 2542f857971dSopenharmony_ci OnDragStyle(dragStyleNode, pixelMap); 2543f857971dSopenharmony_ci CHKPR(rsUiDirector_, RET_ERR); 2544f857971dSopenharmony_ci rsUiDirector_->SendMessages(); 2545f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2546f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 2547f857971dSopenharmony_ci DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR); 2548f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 2549f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2550f857971dSopenharmony_ci return RET_OK; 2551f857971dSopenharmony_ci} 2552f857971dSopenharmony_ci 2553f857971dSopenharmony_ciint32_t DragDrawing::ModifyPreviewStyle(std::shared_ptr<Rosen::RSCanvasNode> node, const PreviewStyle &previewStyle) 2554f857971dSopenharmony_ci{ 2555f857971dSopenharmony_ci FI_HILOGD("enter"); 2556f857971dSopenharmony_ci CHKPR(node, RET_ERR); 2557f857971dSopenharmony_ci if (float radius = 0.0F; ParserRadius(radius)) { 2558f857971dSopenharmony_ci node->SetCornerRadius(radius); 2559f857971dSopenharmony_ci FI_HILOGD("SetCornerRadius by radius:%{public}f", radius); 2560f857971dSopenharmony_ci } 2561f857971dSopenharmony_ci for (const auto &type : previewStyle.types) { 2562f857971dSopenharmony_ci switch (type) { 2563f857971dSopenharmony_ci case PreviewType::FOREGROUND_COLOR: { 2564f857971dSopenharmony_ci node->SetForegroundColor(previewStyle.foregroundColor); 2565f857971dSopenharmony_ci break; 2566f857971dSopenharmony_ci } 2567f857971dSopenharmony_ci case PreviewType::OPACITY: { 2568f857971dSopenharmony_ci node->SetAlpha(previewStyle.opacity / static_cast<float>(HEX_FF)); 2569f857971dSopenharmony_ci break; 2570f857971dSopenharmony_ci } 2571f857971dSopenharmony_ci case PreviewType::RADIUS: { 2572f857971dSopenharmony_ci node->SetCornerRadius(previewStyle.radius); 2573f857971dSopenharmony_ci break; 2574f857971dSopenharmony_ci } 2575f857971dSopenharmony_ci case PreviewType::SCALE: { 2576f857971dSopenharmony_ci node->SetScale(previewStyle.scale); 2577f857971dSopenharmony_ci break; 2578f857971dSopenharmony_ci } 2579f857971dSopenharmony_ci default: { 2580f857971dSopenharmony_ci FI_HILOGE("Unsupported type"); 2581f857971dSopenharmony_ci break; 2582f857971dSopenharmony_ci } 2583f857971dSopenharmony_ci } 2584f857971dSopenharmony_ci } 2585f857971dSopenharmony_ci FI_HILOGD("leave"); 2586f857971dSopenharmony_ci return RET_OK; 2587f857971dSopenharmony_ci} 2588f857971dSopenharmony_ci 2589f857971dSopenharmony_ciint32_t DragDrawing::ModifyMultiPreviewStyle(const std::vector<PreviewStyle> &previewStyles) 2590f857971dSopenharmony_ci{ 2591f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 2592f857971dSopenharmony_ci if (previewStyles.size() != multiSelectedNodesSize) { 2593f857971dSopenharmony_ci FI_HILOGE("Size of previewStyles:%{public}zu does not match multiSelectedNodesSize:%{public}zu", 2594f857971dSopenharmony_ci previewStyles.size(), multiSelectedNodesSize); 2595f857971dSopenharmony_ci return RET_ERR; 2596f857971dSopenharmony_ci } 2597f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedNodesSize; ++i) { 2598f857971dSopenharmony_ci if (ModifyPreviewStyle(g_drawingInfo.multiSelectedNodes[i], previewStyles[i]) != RET_OK) { 2599f857971dSopenharmony_ci FI_HILOGW("ModifyPreviewStyle No.%{public}zu failed", i); 2600f857971dSopenharmony_ci } 2601f857971dSopenharmony_ci } 2602f857971dSopenharmony_ci return RET_OK; 2603f857971dSopenharmony_ci} 2604f857971dSopenharmony_ci 2605f857971dSopenharmony_civoid DragDrawing::MultiSelectedAnimation(int32_t positionX, int32_t positionY, int32_t adjustSize, 2606f857971dSopenharmony_ci bool isMultiSelectedAnimation) 2607f857971dSopenharmony_ci{ 2608f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 2609f857971dSopenharmony_ci size_t multiSelectedPixelMapsSize = g_drawingInfo.multiSelectedPixelMaps.size(); 2610f857971dSopenharmony_ci for (size_t i = 0; (i < multiSelectedNodesSize) && (i < multiSelectedPixelMapsSize); ++i) { 2611f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = g_drawingInfo.multiSelectedNodes[i]; 2612f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> multiSelectedPixelMap = g_drawingInfo.multiSelectedPixelMaps[i]; 2613f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2614f857971dSopenharmony_ci CHKPV(multiSelectedNode); 2615f857971dSopenharmony_ci CHKPV(multiSelectedPixelMap); 2616f857971dSopenharmony_ci int32_t multiSelectedPositionX = positionX + (g_drawingInfo.pixelMap->GetWidth() / TWICE_SIZE) - 2617f857971dSopenharmony_ci (multiSelectedPixelMap->GetWidth() / TWICE_SIZE); 2618f857971dSopenharmony_ci int32_t multiSelectedPositionY = positionY + (g_drawingInfo.pixelMap->GetHeight() / TWICE_SIZE) - 2619f857971dSopenharmony_ci ((multiSelectedPixelMap->GetHeight() / TWICE_SIZE) - adjustSize); 2620f857971dSopenharmony_ci if (isMultiSelectedAnimation) { 2621f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 2622f857971dSopenharmony_ci if (i == FIRST_PIXELMAP_INDEX) { 2623f857971dSopenharmony_ci protocol.SetDuration(SHORT_DURATION); 2624f857971dSopenharmony_ci } else { 2625f857971dSopenharmony_ci protocol.SetDuration(LONG_DURATION); 2626f857971dSopenharmony_ci } 2627f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, Rosen::RSAnimationTimingCurve::EASE_IN_OUT, [&]() { 2628f857971dSopenharmony_ci multiSelectedNode->SetBounds(multiSelectedPositionX, multiSelectedPositionY, 2629f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 2630f857971dSopenharmony_ci multiSelectedNode->SetFrame(multiSelectedPositionX, multiSelectedPositionY, 2631f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 2632f857971dSopenharmony_ci }, []() { FI_HILOGD("MultiSelectedAnimation end"); }); 2633f857971dSopenharmony_ci } else { 2634f857971dSopenharmony_ci multiSelectedNode->SetBounds(multiSelectedPositionX, multiSelectedPositionY, 2635f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 2636f857971dSopenharmony_ci multiSelectedNode->SetFrame(multiSelectedPositionX, multiSelectedPositionY, 2637f857971dSopenharmony_ci multiSelectedPixelMap->GetWidth(), multiSelectedPixelMap->GetHeight()); 2638f857971dSopenharmony_ci } 2639f857971dSopenharmony_ci } 2640f857971dSopenharmony_ci} 2641f857971dSopenharmony_ci 2642f857971dSopenharmony_civoid DragDrawing::InitMultiSelectedNodes() 2643f857971dSopenharmony_ci{ 2644f857971dSopenharmony_ci FI_HILOGD("enter"); 2645f857971dSopenharmony_ci size_t multiSelectedPixelMapsSize = g_drawingInfo.multiSelectedPixelMaps.size(); 2646f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedPixelMapsSize; ++i) { 2647f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> multiSelectedPixelMap = g_drawingInfo.multiSelectedPixelMaps[i]; 2648f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = Rosen::RSCanvasNode::Create(); 2649f857971dSopenharmony_ci multiSelectedNode->SetBgImageWidth(multiSelectedPixelMap->GetWidth()); 2650f857971dSopenharmony_ci multiSelectedNode->SetBgImageHeight(multiSelectedPixelMap->GetHeight()); 2651f857971dSopenharmony_ci multiSelectedNode->SetBgImagePositionX(0); 2652f857971dSopenharmony_ci multiSelectedNode->SetBgImagePositionY(0); 2653f857971dSopenharmony_ci multiSelectedNode->SetForegroundColor(TRANSPARENT_COLOR_ARGB); 2654f857971dSopenharmony_ci auto rosenImage = std::make_shared<Rosen::RSImage>(); 2655f857971dSopenharmony_ci rosenImage->SetPixelMap(multiSelectedPixelMap); 2656f857971dSopenharmony_ci rosenImage->SetImageRepeat(0); 2657f857971dSopenharmony_ci multiSelectedNode->SetBgImage(rosenImage); 2658f857971dSopenharmony_ci float alpha = DEFAULT_ALPHA; 2659f857971dSopenharmony_ci float degrees = DEFAULT_ANGLE; 2660f857971dSopenharmony_ci if (i == FIRST_PIXELMAP_INDEX) { 2661f857971dSopenharmony_ci alpha = FIRST_PIXELMAP_ALPHA; 2662f857971dSopenharmony_ci degrees = POSITIVE_ANGLE; 2663f857971dSopenharmony_ci } else if (i == SECOND_PIXELMAP_INDEX) { 2664f857971dSopenharmony_ci alpha = SECOND_PIXELMAP_ALPHA; 2665f857971dSopenharmony_ci degrees = NEGATIVE_ANGLE; 2666f857971dSopenharmony_ci } 2667f857971dSopenharmony_ci multiSelectedNode->SetRotation(degrees); 2668f857971dSopenharmony_ci multiSelectedNode->SetCornerRadius(g_drawingInfo.filterInfo.cornerRadius1 * g_drawingInfo.filterInfo.dipScale * 2669f857971dSopenharmony_ci g_drawingInfo.filterInfo.scale); 2670f857971dSopenharmony_ci multiSelectedNode->SetAlpha(alpha); 2671f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.emplace_back(multiSelectedNode); 2672f857971dSopenharmony_ci } 2673f857971dSopenharmony_ci FI_HILOGD("leave"); 2674f857971dSopenharmony_ci} 2675f857971dSopenharmony_ci 2676f857971dSopenharmony_civoid DragDrawing::ClearMultiSelectedData() 2677f857971dSopenharmony_ci{ 2678f857971dSopenharmony_ci FI_HILOGD("enter"); 2679f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty()) { 2680f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.clear(); 2681f857971dSopenharmony_ci g_drawingInfo.multiSelectedNodes.shrink_to_fit(); 2682f857971dSopenharmony_ci } 2683f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedPixelMaps.empty()) { 2684f857971dSopenharmony_ci g_drawingInfo.multiSelectedPixelMaps.clear(); 2685f857971dSopenharmony_ci g_drawingInfo.multiSelectedPixelMaps.shrink_to_fit(); 2686f857971dSopenharmony_ci } 2687f857971dSopenharmony_ci FI_HILOGD("leave"); 2688f857971dSopenharmony_ci} 2689f857971dSopenharmony_ci 2690f857971dSopenharmony_civoid DragDrawing::RotateDisplayXY(int32_t &displayX, int32_t &displayY) 2691f857971dSopenharmony_ci{ 2692f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2693f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 2694f857971dSopenharmony_ci if (display == nullptr) { 2695f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 2696f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 2697f857971dSopenharmony_ci CHKPV(display); 2698f857971dSopenharmony_ci } 2699f857971dSopenharmony_ci int32_t width = display->GetWidth(); 2700f857971dSopenharmony_ci int32_t height = display->GetHeight(); 2701f857971dSopenharmony_ci#else 2702f857971dSopenharmony_ci CHKPV(window_); 2703f857971dSopenharmony_ci int32_t width = window_->GetRect().width_; 2704f857971dSopenharmony_ci int32_t height = window_->GetRect().height_; 2705f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2706f857971dSopenharmony_ci switch (rotation_) { 2707f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_0: { 2708f857971dSopenharmony_ci break; 2709f857971dSopenharmony_ci } 2710f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_90: { 2711f857971dSopenharmony_ci int32_t temp = displayY; 2712f857971dSopenharmony_ci displayY = width - displayX; 2713f857971dSopenharmony_ci displayX = temp; 2714f857971dSopenharmony_ci break; 2715f857971dSopenharmony_ci } 2716f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_180: { 2717f857971dSopenharmony_ci displayX = width - displayX; 2718f857971dSopenharmony_ci displayY = height - displayY; 2719f857971dSopenharmony_ci break; 2720f857971dSopenharmony_ci } 2721f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_270: { 2722f857971dSopenharmony_ci int32_t temp = displayX; 2723f857971dSopenharmony_ci displayX = height - displayY; 2724f857971dSopenharmony_ci displayY = temp; 2725f857971dSopenharmony_ci break; 2726f857971dSopenharmony_ci } 2727f857971dSopenharmony_ci default: { 2728f857971dSopenharmony_ci FI_HILOGW("Unknown parameter, rotation:%{public}d", static_cast<int32_t>(rotation_)); 2729f857971dSopenharmony_ci break; 2730f857971dSopenharmony_ci } 2731f857971dSopenharmony_ci } 2732f857971dSopenharmony_ci} 2733f857971dSopenharmony_ci 2734f857971dSopenharmony_civoid DragDrawing::RotatePosition(float &displayX, float &displayY) 2735f857971dSopenharmony_ci{ 2736f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2737f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 2738f857971dSopenharmony_ci if (display == nullptr) { 2739f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 2740f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 2741f857971dSopenharmony_ci CHKPV(display); 2742f857971dSopenharmony_ci } 2743f857971dSopenharmony_ci int32_t width = display->GetWidth(); 2744f857971dSopenharmony_ci int32_t height = display->GetHeight(); 2745f857971dSopenharmony_ci#else 2746f857971dSopenharmony_ci CHKPV(window_); 2747f857971dSopenharmony_ci int32_t width = window_->GetRect().width_; 2748f857971dSopenharmony_ci int32_t height = window_->GetRect().height_; 2749f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2750f857971dSopenharmony_ci switch (rotation_) { 2751f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_0: { 2752f857971dSopenharmony_ci break; 2753f857971dSopenharmony_ci } 2754f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_90: { 2755f857971dSopenharmony_ci int32_t temp = displayY; 2756f857971dSopenharmony_ci displayY = width - displayX; 2757f857971dSopenharmony_ci displayX = temp; 2758f857971dSopenharmony_ci break; 2759f857971dSopenharmony_ci } 2760f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_180: { 2761f857971dSopenharmony_ci displayX = width - displayX; 2762f857971dSopenharmony_ci displayY = height - displayY; 2763f857971dSopenharmony_ci break; 2764f857971dSopenharmony_ci } 2765f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_270: { 2766f857971dSopenharmony_ci int32_t temp = displayX; 2767f857971dSopenharmony_ci displayX = height - displayY; 2768f857971dSopenharmony_ci displayY = temp; 2769f857971dSopenharmony_ci break; 2770f857971dSopenharmony_ci } 2771f857971dSopenharmony_ci default: { 2772f857971dSopenharmony_ci FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation_)); 2773f857971dSopenharmony_ci break; 2774f857971dSopenharmony_ci } 2775f857971dSopenharmony_ci } 2776f857971dSopenharmony_ci} 2777f857971dSopenharmony_ci 2778f857971dSopenharmony_civoid DragDrawing::RotatePixelMapXY() 2779f857971dSopenharmony_ci{ 2780f857971dSopenharmony_ci FI_HILOGI("rotation:%{public}d", static_cast<int32_t>(rotation_)); 2781f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2782f857971dSopenharmony_ci switch (rotation_) { 2783f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_0: 2784f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_180: { 2785f857971dSopenharmony_ci g_drawingInfo.pixelMapX = -(HALF_RATIO * g_drawingInfo.pixelMap->GetWidth()); 2786f857971dSopenharmony_ci g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling()); 2787f857971dSopenharmony_ci break; 2788f857971dSopenharmony_ci } 2789f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_90: 2790f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_270: { 2791f857971dSopenharmony_ci g_drawingInfo.pixelMapX = -(HALF_RATIO * g_drawingInfo.pixelMap->GetHeight()); 2792f857971dSopenharmony_ci g_drawingInfo.pixelMapY = -(EIGHT_SIZE * GetScaling()); 2793f857971dSopenharmony_ci break; 2794f857971dSopenharmony_ci } 2795f857971dSopenharmony_ci default: { 2796f857971dSopenharmony_ci FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation_)); 2797f857971dSopenharmony_ci break; 2798f857971dSopenharmony_ci } 2799f857971dSopenharmony_ci } 2800f857971dSopenharmony_ci} 2801f857971dSopenharmony_ci 2802f857971dSopenharmony_civoid DragDrawing::ResetAnimationParameter() 2803f857971dSopenharmony_ci{ 2804f857971dSopenharmony_ci FI_HILOGI("enter"); 2805f857971dSopenharmony_ci hasRunningScaleAnimation_ = false; 2806f857971dSopenharmony_ci CHKPV(handler_); 2807f857971dSopenharmony_ci#ifndef IOS_PLATFORM 2808f857971dSopenharmony_ci handler_->RemoveAllEvents(); 2809f857971dSopenharmony_ci handler_->RemoveAllFileDescriptorListeners(); 2810f857971dSopenharmony_ci#endif // IOS_PLATFORM 2811f857971dSopenharmony_ci handler_ = nullptr; 2812f857971dSopenharmony_ci receiver_ = nullptr; 2813f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2814f857971dSopenharmony_ci ResetSuperHubHandler(); 2815f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2816f857971dSopenharmony_ci FI_HILOGI("leave"); 2817f857971dSopenharmony_ci} 2818f857971dSopenharmony_ci 2819f857971dSopenharmony_civoid DragDrawing::ResetAnimationFlag(bool isForce) 2820f857971dSopenharmony_ci{ 2821f857971dSopenharmony_ci FI_HILOGI("enter"); 2822f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2823f857971dSopenharmony_ci if (!isForce && (g_drawingInfo.context != nullptr) && (g_drawingInfo.timerId >= 0)) { 2824f857971dSopenharmony_ci g_drawingInfo.context->GetTimerManager().RemoveTimer(g_drawingInfo.timerId); 2825f857971dSopenharmony_ci g_drawingInfo.timerId = -1; 2826f857971dSopenharmony_ci } 2827f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2828f857971dSopenharmony_ci if (drawDynamicEffectModifier_ != nullptr) { 2829f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 2830f857971dSopenharmony_ci g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_); 2831f857971dSopenharmony_ci drawDynamicEffectModifier_ = nullptr; 2832f857971dSopenharmony_ci } 2833f857971dSopenharmony_ci DestroyDragWindow(); 2834f857971dSopenharmony_ci g_drawingInfo.isRunning = false; 2835f857971dSopenharmony_ci g_drawingInfo.timerId = -1; 2836f857971dSopenharmony_ci ResetAnimationParameter(); 2837f857971dSopenharmony_ci FI_HILOGI("leave"); 2838f857971dSopenharmony_ci} 2839f857971dSopenharmony_ci 2840f857971dSopenharmony_civoid DragDrawing::DoEndAnimation() 2841f857971dSopenharmony_ci{ 2842f857971dSopenharmony_ci FI_HILOGI("enter"); 2843f857971dSopenharmony_ci#ifdef IOS_PLATFORM 2844f857971dSopenharmony_ci g_drawingInfo.startNum = actionTime_; 2845f857971dSopenharmony_ci#else 2846f857971dSopenharmony_ci g_drawingInfo.startNum = START_TIME; 2847f857971dSopenharmony_ci#endif // IOS_PLATFORM 2848f857971dSopenharmony_ci g_drawingInfo.needDestroyDragWindow = true; 2849f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2850f857971dSopenharmony_ci if (g_drawingInfo.context != nullptr) { 2851f857971dSopenharmony_ci int32_t repeatCount = 1; 2852f857971dSopenharmony_ci g_drawingInfo.timerId = g_drawingInfo.context->GetTimerManager().AddTimer(TIMEOUT_MS, repeatCount, [this]() { 2853f857971dSopenharmony_ci FI_HILOGW("Timeout, automatically reset animation flag"); 2854f857971dSopenharmony_ci ResetAnimationFlag(true); 2855f857971dSopenharmony_ci }); 2856f857971dSopenharmony_ci } 2857f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2858f857971dSopenharmony_ci StartVsync(); 2859f857971dSopenharmony_ci FI_HILOGI("leave"); 2860f857971dSopenharmony_ci} 2861f857971dSopenharmony_ci 2862f857971dSopenharmony_civoid DragDrawing::ResetParameter() 2863f857971dSopenharmony_ci{ 2864f857971dSopenharmony_ci FI_HILOGI("enter"); 2865f857971dSopenharmony_ci g_drawingInfo.startNum = START_TIME; 2866f857971dSopenharmony_ci g_drawingInfo.needDestroyDragWindow = false; 2867f857971dSopenharmony_ci needRotatePixelMapXY_ = false; 2868f857971dSopenharmony_ci hasRunningStopAnimation_ = false; 2869f857971dSopenharmony_ci pointerStyle_ = {}; 2870f857971dSopenharmony_ci g_drawingInfo.currentPositionX = -1.0f; 2871f857971dSopenharmony_ci g_drawingInfo.currentPositionY = -1.0f; 2872f857971dSopenharmony_ci g_drawingInfo.sourceType = -1; 2873f857971dSopenharmony_ci g_drawingInfo.currentDragNum = -1; 2874f857971dSopenharmony_ci g_drawingInfo.pixelMapX = -1; 2875f857971dSopenharmony_ci g_drawingInfo.pixelMapY = -1; 2876f857971dSopenharmony_ci g_drawingInfo.displayX = -1; 2877f857971dSopenharmony_ci g_drawingInfo.displayY = -1; 2878f857971dSopenharmony_ci g_drawingInfo.mouseWidth = 0; 2879f857971dSopenharmony_ci g_drawingInfo.mouseHeight = 0; 2880f857971dSopenharmony_ci g_drawingInfo.rootNodeWidth = -1; 2881f857971dSopenharmony_ci g_drawingInfo.rootNodeHeight = -1; 2882f857971dSopenharmony_ci g_drawingInfo.pixelMap = nullptr; 2883f857971dSopenharmony_ci g_drawingInfo.stylePixelMap = nullptr; 2884f857971dSopenharmony_ci g_drawingInfo.isPreviousDefaultStyle = false; 2885f857971dSopenharmony_ci g_drawingInfo.isCurrentDefaultStyle = false; 2886f857971dSopenharmony_ci g_drawingInfo.currentStyle = DragCursorStyle::DEFAULT; 2887f857971dSopenharmony_ci g_drawingInfo.filterInfo = {}; 2888f857971dSopenharmony_ci g_drawingInfo.extraInfo = {}; 2889f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2890f857971dSopenharmony_ci dragSmoothProcessor_.ResetParameters(); 2891f857971dSopenharmony_ci vSyncStation_.StopVSyncRequest(); 2892f857971dSopenharmony_ci frameCallback_ = nullptr; 2893f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2894f857971dSopenharmony_ci FI_HILOGI("leave"); 2895f857971dSopenharmony_ci} 2896f857971dSopenharmony_ci 2897f857971dSopenharmony_ciint32_t DragDrawing::DoRotateDragWindow(float rotation, 2898f857971dSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction, bool isAnimated) 2899f857971dSopenharmony_ci{ 2900f857971dSopenharmony_ci FI_HILOGD("rotation:%{public}f, isAnimated:%{public}d", rotation, isAnimated); 2901f857971dSopenharmony_ci CHKPR(g_drawingInfo.pixelMap, RET_ERR); 2902f857971dSopenharmony_ci if ((g_drawingInfo.pixelMap->GetWidth() <= 0) || (g_drawingInfo.pixelMap->GetHeight() <= 0)) { 2903f857971dSopenharmony_ci FI_HILOGE("Invalid parameter pixelmap"); 2904f857971dSopenharmony_ci return RET_ERR; 2905f857971dSopenharmony_ci } 2906f857971dSopenharmony_ci float adjustSize = TWELVE_SIZE * GetScaling(); 2907f857971dSopenharmony_ci float pivotX = HALF_PIVOT; 2908f857971dSopenharmony_ci float pivotY = 0.0f; 2909f857971dSopenharmony_ci if (fabsf(adjustSize + g_drawingInfo.pixelMap->GetHeight()) < EPSILON) { 2910f857971dSopenharmony_ci pivotY = HALF_PIVOT; 2911f857971dSopenharmony_ci } else { 2912f857971dSopenharmony_ci pivotY = ((g_drawingInfo.pixelMap->GetHeight() * 1.0 / TWICE_SIZE) + adjustSize) / 2913f857971dSopenharmony_ci (adjustSize + g_drawingInfo.pixelMap->GetHeight()); 2914f857971dSopenharmony_ci } 2915f857971dSopenharmony_ci if (!isAnimated) { 2916f857971dSopenharmony_ci DragWindowRotateInfo_.rotation = rotation; 2917f857971dSopenharmony_ci DragWindowRotateInfo_.pivotX = pivotX; 2918f857971dSopenharmony_ci DragWindowRotateInfo_.pivotY = pivotY; 2919f857971dSopenharmony_ci RotateCanvasNode(pivotX, pivotY, rotation); 2920f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 2921f857971dSopenharmony_ci return RET_OK; 2922f857971dSopenharmony_ci } 2923f857971dSopenharmony_ci return DoRotateDragWindowAnimation(rotation, pivotX, pivotY, rsTransaction); 2924f857971dSopenharmony_ci} 2925f857971dSopenharmony_ci 2926f857971dSopenharmony_citemplate <typename T> 2927f857971dSopenharmony_civoid DragDrawing::AdjustRotateDisplayXY(T &displayX, T &displayY) 2928f857971dSopenharmony_ci{ 2929f857971dSopenharmony_ci FI_HILOGD("rotation:%{public}d", static_cast<int32_t>(rotation_)); 2930f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 2931f857971dSopenharmony_ci switch (rotation_) { 2932f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_0: { 2933f857971dSopenharmony_ci break; 2934f857971dSopenharmony_ci } 2935f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_90: { 2936f857971dSopenharmony_ci displayX -= (g_drawingInfo.pixelMap->GetWidth() - g_drawingInfo.pixelMap->GetHeight()) / TWICE_SIZE + 2937f857971dSopenharmony_ci g_drawingInfo.pixelMapX - g_drawingInfo.pixelMapY; 2938f857971dSopenharmony_ci displayY -= (g_drawingInfo.pixelMap->GetWidth() - g_drawingInfo.pixelMap->GetHeight()) / TWICE_SIZE + 2939f857971dSopenharmony_ci g_drawingInfo.pixelMapX + g_drawingInfo.pixelMap->GetHeight() + g_drawingInfo.pixelMapY; 2940f857971dSopenharmony_ci break; 2941f857971dSopenharmony_ci } 2942f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_180: { 2943f857971dSopenharmony_ci displayX -= g_drawingInfo.pixelMap->GetWidth() + (g_drawingInfo.pixelMapX * TWICE_SIZE); 2944f857971dSopenharmony_ci displayY -= g_drawingInfo.pixelMap->GetHeight() + (g_drawingInfo.pixelMapY * TWICE_SIZE); 2945f857971dSopenharmony_ci break; 2946f857971dSopenharmony_ci } 2947f857971dSopenharmony_ci case Rosen::Rotation::ROTATION_270: { 2948f857971dSopenharmony_ci displayX -= (g_drawingInfo.pixelMap->GetWidth() - g_drawingInfo.pixelMap->GetHeight()) / TWICE_SIZE + 2949f857971dSopenharmony_ci g_drawingInfo.pixelMapX + g_drawingInfo.pixelMap->GetHeight() + g_drawingInfo.pixelMapY; 2950f857971dSopenharmony_ci displayY += (g_drawingInfo.pixelMap->GetWidth() - g_drawingInfo.pixelMap->GetHeight()) / TWICE_SIZE + 2951f857971dSopenharmony_ci g_drawingInfo.pixelMapX - g_drawingInfo.pixelMapY; 2952f857971dSopenharmony_ci break; 2953f857971dSopenharmony_ci } 2954f857971dSopenharmony_ci default: { 2955f857971dSopenharmony_ci FI_HILOGE("Invalid parameter, rotation:%{public}d", static_cast<int32_t>(rotation_)); 2956f857971dSopenharmony_ci break; 2957f857971dSopenharmony_ci } 2958f857971dSopenharmony_ci } 2959f857971dSopenharmony_ci} 2960f857971dSopenharmony_ci 2961f857971dSopenharmony_civoid DragDrawing::DrawRotateDisplayXY(float positionX, float positionY) 2962f857971dSopenharmony_ci{ 2963f857971dSopenharmony_ci FI_HILOGD("enter"); 2964f857971dSopenharmony_ci float adjustSize = TWELVE_SIZE * GetScaling(); 2965f857971dSopenharmony_ci float parentPositionX = positionX + g_drawingInfo.pixelMapX; 2966f857971dSopenharmony_ci float parentPositionY = positionY + g_drawingInfo.pixelMapY - adjustSize; 2967f857971dSopenharmony_ci auto parentNode = g_drawingInfo.parentNode; 2968f857971dSopenharmony_ci auto pixelMap = g_drawingInfo.pixelMap; 2969f857971dSopenharmony_ci CHKPV(parentNode); 2970f857971dSopenharmony_ci CHKPV(pixelMap); 2971f857971dSopenharmony_ci parentNode->SetBounds(parentPositionX, parentPositionY, pixelMap->GetWidth(), 2972f857971dSopenharmony_ci pixelMap->GetHeight() + adjustSize); 2973f857971dSopenharmony_ci parentNode->SetFrame(parentPositionX, parentPositionY, pixelMap->GetWidth(), 2974f857971dSopenharmony_ci pixelMap->GetHeight() + adjustSize); 2975f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty() && !g_drawingInfo.multiSelectedPixelMaps.empty()) { 2976f857971dSopenharmony_ci DoMultiSelectedAnimation(parentPositionX, parentPositionY, adjustSize, false); 2977f857971dSopenharmony_ci } 2978f857971dSopenharmony_ci FI_HILOGD("leave"); 2979f857971dSopenharmony_ci} 2980f857971dSopenharmony_ci 2981f857971dSopenharmony_civoid DragDrawing::ScreenRotateAdjustDisplayXY( 2982f857971dSopenharmony_ci Rosen::Rotation rotation, Rosen::Rotation lastRotation, float &displayX, float &displayY) 2983f857971dSopenharmony_ci{ 2984f857971dSopenharmony_ci FI_HILOGI("enter"); 2985f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 2986f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 2987f857971dSopenharmony_ci if (display == nullptr) { 2988f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 2989f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 2990f857971dSopenharmony_ci CHKPV(display); 2991f857971dSopenharmony_ci } 2992f857971dSopenharmony_ci int32_t width = display->GetWidth(); 2993f857971dSopenharmony_ci int32_t height = display->GetHeight(); 2994f857971dSopenharmony_ci#else 2995f857971dSopenharmony_ci CHKPV(window_); 2996f857971dSopenharmony_ci int32_t width = window_->GetRect().width_; 2997f857971dSopenharmony_ci int32_t height = window_->GetRect().height_; 2998f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 2999f857971dSopenharmony_ci if ((static_cast<int32_t>(lastRotation) + NUM_ONE) % NUM_FOUR == static_cast<int32_t>(rotation)) { 3000f857971dSopenharmony_ci int32_t temp = displayX; 3001f857971dSopenharmony_ci displayX = width - displayY; 3002f857971dSopenharmony_ci displayY = temp; 3003f857971dSopenharmony_ci } else if ((static_cast<int32_t>(lastRotation) + NUM_TWO) % NUM_FOUR == static_cast<int32_t>(rotation)) { 3004f857971dSopenharmony_ci displayX = width - displayX; 3005f857971dSopenharmony_ci displayY = height - displayY; 3006f857971dSopenharmony_ci } else { 3007f857971dSopenharmony_ci int32_t temp = displayY; 3008f857971dSopenharmony_ci displayY = height - displayX; 3009f857971dSopenharmony_ci displayX = temp; 3010f857971dSopenharmony_ci } 3011f857971dSopenharmony_ci FI_HILOGI("leave"); 3012f857971dSopenharmony_ci} 3013f857971dSopenharmony_ci 3014f857971dSopenharmony_civoid DragDrawing::ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation) 3015f857971dSopenharmony_ci{ 3016f857971dSopenharmony_ci FI_HILOGI("enter, rotation:%{public}d, lastRotation:%{public}d", static_cast<int32_t>(rotation), 3017f857971dSopenharmony_ci static_cast<int32_t>(lastRotation)); 3018f857971dSopenharmony_ci ScreenRotateAdjustDisplayXY(rotation, lastRotation, g_drawingInfo.x, g_drawingInfo.y); 3019f857971dSopenharmony_ci DrawRotateDisplayXY(g_drawingInfo.x, g_drawingInfo.y); 3020f857971dSopenharmony_ci 3021f857971dSopenharmony_ci if (g_drawingInfo.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { 3022f857971dSopenharmony_ci ScreenRotateAdjustDisplayXY( 3023f857971dSopenharmony_ci rotation, lastRotation, g_drawingInfo.currentPositionX, g_drawingInfo.currentPositionY); 3024f857971dSopenharmony_ci UpdateMousePosition(g_drawingInfo.currentPositionX, g_drawingInfo.currentPositionY); 3025f857971dSopenharmony_ci } 3026f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3027f857971dSopenharmony_ci FI_HILOGI("leave"); 3028f857971dSopenharmony_ci} 3029f857971dSopenharmony_ci 3030f857971dSopenharmony_ciint32_t DragDrawing::DoRotateDragWindowAnimation(float rotation, float pivotX, float pivotY, 3031f857971dSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) 3032f857971dSopenharmony_ci{ 3033f857971dSopenharmony_ci FI_HILOGD("enter"); 3034f857971dSopenharmony_ci if (rsTransaction != nullptr) { 3035f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3036f857971dSopenharmony_ci rsTransaction->Begin(); 3037f857971dSopenharmony_ci } 3038f857971dSopenharmony_ci if ((rotation == ROTATION_0) && (DragWindowRotateInfo_.rotation == ROTATION_270)) { 3039f857971dSopenharmony_ci RotateCanvasNode(DragWindowRotateInfo_.pivotX, DragWindowRotateInfo_.pivotY, -ROTATION_90); 3040f857971dSopenharmony_ci } else if ((rotation == ROTATION_270) && (DragWindowRotateInfo_.rotation == ROTATION_0)) { 3041f857971dSopenharmony_ci RotateCanvasNode(DragWindowRotateInfo_.pivotX, DragWindowRotateInfo_.pivotY, ROTATION_360); 3042f857971dSopenharmony_ci } 3043f857971dSopenharmony_ci 3044f857971dSopenharmony_ci Rosen::RSAnimationTimingProtocol protocol; 3045f857971dSopenharmony_ci protocol.SetDuration(ANIMATION_DURATION); 3046f857971dSopenharmony_ci Rosen::RSNode::Animate(protocol, SPRING, [&]() { 3047f857971dSopenharmony_ci RotateCanvasNode(pivotX, pivotY, rotation); 3048f857971dSopenharmony_ci DragWindowRotateInfo_.rotation = rotation; 3049f857971dSopenharmony_ci DragWindowRotateInfo_.pivotX = pivotX; 3050f857971dSopenharmony_ci DragWindowRotateInfo_.pivotY = pivotY; 3051f857971dSopenharmony_ci return RET_OK; 3052f857971dSopenharmony_ci }, []() { FI_HILOGD("DoRotateDragWindowAnimation end"); }); 3053f857971dSopenharmony_ci if (rsTransaction != nullptr) { 3054f857971dSopenharmony_ci rsTransaction->Commit(); 3055f857971dSopenharmony_ci } else { 3056f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3057f857971dSopenharmony_ci } 3058f857971dSopenharmony_ci FI_HILOGD("leave"); 3059f857971dSopenharmony_ci return RET_OK; 3060f857971dSopenharmony_ci} 3061f857971dSopenharmony_ci 3062f857971dSopenharmony_cibool DragDrawing::ParserRadius(float &radius) 3063f857971dSopenharmony_ci{ 3064f857971dSopenharmony_ci FilterInfo filterInfo = g_drawingInfo.filterInfo; 3065f857971dSopenharmony_ci ExtraInfo extraInfo = g_drawingInfo.extraInfo; 3066f857971dSopenharmony_ci if ((extraInfo.cornerRadius < 0) || (filterInfo.dipScale < 0) || 3067f857971dSopenharmony_ci (fabs(filterInfo.dipScale) < EPSILON) || ((std::numeric_limits<float>::max() 3068f857971dSopenharmony_ci / filterInfo.dipScale) < extraInfo.cornerRadius)) { 3069f857971dSopenharmony_ci FI_HILOGE("Invalid parameters, cornerRadius:%{public}f, dipScale:%{public}f", 3070f857971dSopenharmony_ci extraInfo.cornerRadius, filterInfo.dipScale); 3071f857971dSopenharmony_ci return false; 3072f857971dSopenharmony_ci } 3073f857971dSopenharmony_ci radius = extraInfo.cornerRadius * filterInfo.dipScale; 3074f857971dSopenharmony_ci return true; 3075f857971dSopenharmony_ci} 3076f857971dSopenharmony_ci 3077f857971dSopenharmony_ciDragDrawing::~DragDrawing() 3078f857971dSopenharmony_ci{ 3079f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3080f857971dSopenharmony_ci if (dragExtHandler_ != nullptr) { 3081f857971dSopenharmony_ci dlclose(dragExtHandler_); 3082f857971dSopenharmony_ci dragExtHandler_ = nullptr; 3083f857971dSopenharmony_ci } 3084f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3085f857971dSopenharmony_ci} 3086f857971dSopenharmony_ci 3087f857971dSopenharmony_civoid DrawSVGModifier::Draw(Rosen::RSDrawingContext& context) const 3088f857971dSopenharmony_ci{ 3089f857971dSopenharmony_ci FI_HILOGD("enter"); 3090f857971dSopenharmony_ci CHKPV(stylePixelMap_); 3091f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 3092f857971dSopenharmony_ci float scalingValue = GetScaling(); 3093f857971dSopenharmony_ci if (SCALE_THRESHOLD_EIGHT < scalingValue || fabsf(SCALE_THRESHOLD_EIGHT - scalingValue) < EPSILON) { 3094f857971dSopenharmony_ci FI_HILOGE("Invalid scalingValue:%{public}f", scalingValue); 3095f857971dSopenharmony_ci return; 3096f857971dSopenharmony_ci } 3097f857971dSopenharmony_ci int32_t adjustSize = EIGHT_SIZE * scalingValue; 3098f857971dSopenharmony_ci int32_t svgTouchPositionX = g_drawingInfo.pixelMap->GetWidth() + adjustSize - stylePixelMap_->GetWidth(); 3099f857971dSopenharmony_ci if (!CheckNodesValid()) { 3100f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3101f857971dSopenharmony_ci return; 3102f857971dSopenharmony_ci } 3103f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 3104f857971dSopenharmony_ci CHKPV(dragStyleNode); 3105f857971dSopenharmony_ci adjustSize = (TWELVE_SIZE - EIGHT_SIZE) * scalingValue; 3106f857971dSopenharmony_ci dragStyleNode->SetBounds(svgTouchPositionX, adjustSize, stylePixelMap_->GetWidth() + adjustSize, 3107f857971dSopenharmony_ci stylePixelMap_->GetHeight()); 3108f857971dSopenharmony_ci dragStyleNode->SetFrame(svgTouchPositionX, adjustSize, stylePixelMap_->GetWidth() + adjustSize, 3109f857971dSopenharmony_ci stylePixelMap_->GetHeight()); 3110f857971dSopenharmony_ci dragStyleNode->SetBgImageWidth(stylePixelMap_->GetWidth()); 3111f857971dSopenharmony_ci dragStyleNode->SetBgImageHeight(stylePixelMap_->GetHeight()); 3112f857971dSopenharmony_ci dragStyleNode->SetBgImagePositionX(0); 3113f857971dSopenharmony_ci dragStyleNode->SetBgImagePositionY(0); 3114f857971dSopenharmony_ci auto rosenImage = std::make_shared<Rosen::RSImage>(); 3115f857971dSopenharmony_ci rosenImage->SetPixelMap(stylePixelMap_); 3116f857971dSopenharmony_ci rosenImage->SetImageRepeat(0); 3117f857971dSopenharmony_ci dragStyleNode->SetBgImage(rosenImage); 3118f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3119f857971dSopenharmony_ci FI_HILOGD("leave"); 3120f857971dSopenharmony_ci} 3121f857971dSopenharmony_ci 3122f857971dSopenharmony_ciRosen::SHADOW_COLOR_STRATEGY DrawPixelMapModifier::ConvertShadowColorStrategy(int32_t shadowColorStrategy) const 3123f857971dSopenharmony_ci{ 3124f857971dSopenharmony_ci if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE)) { 3125f857971dSopenharmony_ci return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ; 3126f857971dSopenharmony_ci } else if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_AVERAGE)) { 3127f857971dSopenharmony_ci return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_AVERAGE ; 3128f857971dSopenharmony_ci } else if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_MAIN)) { 3129f857971dSopenharmony_ci return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_MAIN ; 3130f857971dSopenharmony_ci } else { 3131f857971dSopenharmony_ci return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE; 3132f857971dSopenharmony_ci } 3133f857971dSopenharmony_ci} 3134f857971dSopenharmony_ci 3135f857971dSopenharmony_civoid DrawPixelMapModifier::SetTextDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const 3136f857971dSopenharmony_ci{ 3137f857971dSopenharmony_ci if (!g_drawingInfo.filterInfo.path.empty()) { 3138f857971dSopenharmony_ci FI_HILOGD("path:%{private}s", g_drawingInfo.filterInfo.path.c_str()); 3139f857971dSopenharmony_ci pixelMapNode->SetShadowPath(Rosen::RSPath::CreateRSPath(g_drawingInfo.filterInfo.path)); 3140f857971dSopenharmony_ci } else { 3141f857971dSopenharmony_ci FI_HILOGW("path is empty"); 3142f857971dSopenharmony_ci } 3143f857971dSopenharmony_ci} 3144f857971dSopenharmony_ci 3145f857971dSopenharmony_civoid DrawPixelMapModifier::SetDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const 3146f857971dSopenharmony_ci{ 3147f857971dSopenharmony_ci if ((g_drawingInfo.filterInfo.dragType == "text") && (g_drawingInfo.filterInfo.path.empty())) { 3148f857971dSopenharmony_ci FI_HILOGI("path is empty"); 3149f857971dSopenharmony_ci return; 3150f857971dSopenharmony_ci } 3151f857971dSopenharmony_ci pixelMapNode->SetShadowOffset(g_drawingInfo.filterInfo.offsetX, g_drawingInfo.filterInfo.offsetY); 3152f857971dSopenharmony_ci pixelMapNode->SetShadowColor(g_drawingInfo.filterInfo.argb); 3153f857971dSopenharmony_ci pixelMapNode->SetShadowMask(g_drawingInfo.filterInfo.shadowMask); 3154f857971dSopenharmony_ci pixelMapNode->SetShadowIsFilled(g_drawingInfo.filterInfo.shadowIsFilled); 3155f857971dSopenharmony_ci pixelMapNode->SetShadowColorStrategy(ConvertShadowColorStrategy(g_drawingInfo.filterInfo.shadowColorStrategy)); 3156f857971dSopenharmony_ci if (g_drawingInfo.filterInfo.isHardwareAcceleration) { 3157f857971dSopenharmony_ci pixelMapNode->SetShadowElevation(g_drawingInfo.filterInfo.elevation); 3158f857971dSopenharmony_ci } else { 3159f857971dSopenharmony_ci pixelMapNode->SetShadowRadius(g_drawingInfo.filterInfo.shadowCorner); 3160f857971dSopenharmony_ci } 3161f857971dSopenharmony_ci if (g_drawingInfo.filterInfo.dragType == "text") { 3162f857971dSopenharmony_ci SetTextDragShadow(pixelMapNode); 3163f857971dSopenharmony_ci } 3164f857971dSopenharmony_ci} 3165f857971dSopenharmony_ci 3166f857971dSopenharmony_civoid DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const 3167f857971dSopenharmony_ci{ 3168f857971dSopenharmony_ci FI_HILOGD("enter"); 3169f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 3170f857971dSopenharmony_ci int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); 3171f857971dSopenharmony_ci int32_t pixelMapHeight = g_drawingInfo.pixelMap->GetHeight(); 3172f857971dSopenharmony_ci if (!CheckNodesValid()) { 3173f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3174f857971dSopenharmony_ci return; 3175f857971dSopenharmony_ci } 3176f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX]; 3177f857971dSopenharmony_ci CHKPV(pixelMapNode); 3178f857971dSopenharmony_ci if (g_drawingInfo.filterInfo.shadowEnable) { 3179f857971dSopenharmony_ci SetDragShadow(pixelMapNode); 3180f857971dSopenharmony_ci } 3181f857971dSopenharmony_ci int32_t adjustSize = TWELVE_SIZE * GetScaling(); 3182f857971dSopenharmony_ci pixelMapNode->SetBounds(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight); 3183f857971dSopenharmony_ci pixelMapNode->SetFrame(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight); 3184f857971dSopenharmony_ci pixelMapNode->SetBgImageWidth(pixelMapWidth); 3185f857971dSopenharmony_ci pixelMapNode->SetBgImageHeight(pixelMapHeight); 3186f857971dSopenharmony_ci pixelMapNode->SetBgImagePositionX(0); 3187f857971dSopenharmony_ci pixelMapNode->SetBgImagePositionY(0); 3188f857971dSopenharmony_ci Rosen::Drawing::AdaptiveImageInfo rsImageInfo = { 1, 0, {}, 1, 0, pixelMapWidth, pixelMapHeight }; 3189f857971dSopenharmony_ci auto cvs = pixelMapNode->BeginRecording(pixelMapWidth, pixelMapHeight); 3190f857971dSopenharmony_ci CHKPV(cvs); 3191f857971dSopenharmony_ci Rosen::Drawing::Brush brush; 3192f857971dSopenharmony_ci cvs->AttachBrush(brush); 3193f857971dSopenharmony_ci FilterInfo filterInfo = g_drawingInfo.filterInfo; 3194f857971dSopenharmony_ci if (g_drawingInfo.filterInfo.shadowEnable && !filterInfo.path.empty() && 3195f857971dSopenharmony_ci g_drawingInfo.filterInfo.dragType == "text") { 3196f857971dSopenharmony_ci auto rsPath = Rosen::RSPath::CreateRSPath(filterInfo.path); 3197f857971dSopenharmony_ci cvs->Save(); 3198f857971dSopenharmony_ci cvs->ClipPath(rsPath->GetDrawingPath(), Rosen::Drawing::ClipOp::INTERSECT, true); 3199f857971dSopenharmony_ci cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions()); 3200f857971dSopenharmony_ci cvs->Restore(); 3201f857971dSopenharmony_ci } else { 3202f857971dSopenharmony_ci cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions()); 3203f857971dSopenharmony_ci } 3204f857971dSopenharmony_ci cvs->DetachBrush(); 3205f857971dSopenharmony_ci pixelMapNode->SetClipToBounds(true); 3206f857971dSopenharmony_ci pixelMapNode->FinishRecording(); 3207f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3208f857971dSopenharmony_ci FI_HILOGD("leave"); 3209f857971dSopenharmony_ci} 3210f857971dSopenharmony_ci 3211f857971dSopenharmony_civoid DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const 3212f857971dSopenharmony_ci{ 3213f857971dSopenharmony_ci FI_HILOGD("enter"); 3214f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3215f857971dSopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap = std::make_shared<Media::PixelMap>(); 3216f857971dSopenharmony_ci int32_t ret = RET_ERR; 3217f857971dSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 3218f857971dSopenharmony_ci ret = MMI::InputManager::GetInstance()->GetPointerSnapshot(&pixelMap); 3219f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_MAGICCURSOR 3220f857971dSopenharmony_ci if (ret != RET_OK) { 3221f857971dSopenharmony_ci FI_HILOGE("Get pointer snapshot failed, ret:%{public}d", ret); 3222f857971dSopenharmony_ci pixelMap = DrawFromSVG(); 3223f857971dSopenharmony_ci } 3224f857971dSopenharmony_ci CHKPV(pixelMap); 3225f857971dSopenharmony_ci OnDraw(pixelMap); 3226f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3227f857971dSopenharmony_ci FI_HILOGD("leave"); 3228f857971dSopenharmony_ci} 3229f857971dSopenharmony_ci 3230f857971dSopenharmony_cistd::shared_ptr<Media::PixelMap> DrawMouseIconModifier::DrawFromSVG() const 3231f857971dSopenharmony_ci{ 3232f857971dSopenharmony_ci std::string imagePath; 3233f857971dSopenharmony_ci if (pointerStyle_.id == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) { 3234f857971dSopenharmony_ci imagePath = MOUSE_DRAG_CURSOR_CIRCLE_PATH; 3235f857971dSopenharmony_ci } else { 3236f857971dSopenharmony_ci imagePath = MOUSE_DRAG_DEFAULT_PATH; 3237f857971dSopenharmony_ci } 3238f857971dSopenharmony_ci int32_t pointerSize = pointerStyle_.size; 3239f857971dSopenharmony_ci int32_t pointerColor = pointerStyle_.color; 3240f857971dSopenharmony_ci int32_t cursorPixel = DEVICE_INDEPENDENT_PIXEL; 3241f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3242f857971dSopenharmony_ci if (pointerStyle_.options == MAGIC_STYLE_OPT) { 3243f857971dSopenharmony_ci imagePath = MOUSE_DRAG_MAGIC_DEFAULT_PATH; 3244f857971dSopenharmony_ci int32_t ret = MMI::InputManager::GetInstance()->GetPointerSize(pointerSize); 3245f857971dSopenharmony_ci if (ret != RET_OK) { 3246f857971dSopenharmony_ci FI_HILOGW("Get pointer size failed, ret:%{public}d", ret); 3247f857971dSopenharmony_ci } 3248f857971dSopenharmony_ci ret = MMI::InputManager::GetInstance()->GetPointerColor(pointerColor); 3249f857971dSopenharmony_ci if (ret != RET_OK) { 3250f857971dSopenharmony_ci FI_HILOGW("Get pointer color failed, ret:%{public}d", ret); 3251f857971dSopenharmony_ci } 3252f857971dSopenharmony_ci cursorPixel = MAGIC_INDEPENDENT_PIXEL; 3253f857971dSopenharmony_ci } 3254f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3255f857971dSopenharmony_ci Media::SourceOptions opts; 3256f857971dSopenharmony_ci opts.formatHint = "image/svg+xml"; 3257f857971dSopenharmony_ci uint32_t errCode = 0; 3258f857971dSopenharmony_ci auto imageSource = Media::ImageSource::CreateImageSource(imagePath, opts, errCode); 3259f857971dSopenharmony_ci if (imageSource == nullptr) { 3260f857971dSopenharmony_ci FI_HILOGW("imageSource is null"); 3261f857971dSopenharmony_ci return nullptr; 3262f857971dSopenharmony_ci } 3263f857971dSopenharmony_ci if (pointerSize < DEFAULT_MOUSE_SIZE) { 3264f857971dSopenharmony_ci FI_HILOGD("Invalid pointerSize:%{public}d", pointerSize); 3265f857971dSopenharmony_ci pointerSize = DEFAULT_MOUSE_SIZE; 3266f857971dSopenharmony_ci } 3267f857971dSopenharmony_ci Media::DecodeOptions decodeOpts; 3268f857971dSopenharmony_ci decodeOpts.desiredSize = { 3269f857971dSopenharmony_ci .width = pow(INCREASE_RATIO, pointerSize - 1) * cursorPixel * GetScaling(), 3270f857971dSopenharmony_ci .height = pow(INCREASE_RATIO, pointerSize - 1) * cursorPixel * GetScaling() 3271f857971dSopenharmony_ci }; 3272f857971dSopenharmony_ci if (pointerColor != INVALID_COLOR_VALUE) { 3273f857971dSopenharmony_ci decodeOpts.SVGOpts.fillColor = {.isValidColor = true, .color = pointerColor}; 3274f857971dSopenharmony_ci } 3275f857971dSopenharmony_ci return imageSource->CreatePixelMap(decodeOpts, errCode); 3276f857971dSopenharmony_ci} 3277f857971dSopenharmony_ci 3278f857971dSopenharmony_civoid DrawMouseIconModifier::OnDraw(std::shared_ptr<Media::PixelMap> pixelMap) const 3279f857971dSopenharmony_ci{ 3280f857971dSopenharmony_ci FI_HILOGD("enter"); 3281f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3282f857971dSopenharmony_ci CHKPV(pixelMap); 3283f857971dSopenharmony_ci if (!CheckNodesValid()) { 3284f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3285f857971dSopenharmony_ci return; 3286f857971dSopenharmony_ci } 3287f857971dSopenharmony_ci g_drawingInfo.mouseWidth = pixelMap->GetWidth(); 3288f857971dSopenharmony_ci g_drawingInfo.mouseHeight = pixelMap->GetHeight(); 3289f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) { 3290f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 3291f857971dSopenharmony_ci return; 3292f857971dSopenharmony_ci } 3293f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX]; 3294f857971dSopenharmony_ci CHKPV(mouseIconNode); 3295f857971dSopenharmony_ci mouseIconNode->SetBgImageWidth(pixelMap->GetWidth()); 3296f857971dSopenharmony_ci mouseIconNode->SetBgImageHeight(pixelMap->GetHeight()); 3297f857971dSopenharmony_ci mouseIconNode->SetBgImagePositionX(0); 3298f857971dSopenharmony_ci mouseIconNode->SetBgImagePositionY(0); 3299f857971dSopenharmony_ci auto rosenImage = std::make_shared<Rosen::RSImage>(); 3300f857971dSopenharmony_ci rosenImage->SetPixelMap(pixelMap); 3301f857971dSopenharmony_ci rosenImage->SetImageRepeat(0); 3302f857971dSopenharmony_ci mouseIconNode->SetBgImage(rosenImage); 3303f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3304f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3305f857971dSopenharmony_ci FI_HILOGD("leave"); 3306f857971dSopenharmony_ci} 3307f857971dSopenharmony_ci 3308f857971dSopenharmony_civoid DrawDynamicEffectModifier::Draw(Rosen::RSDrawingContext &context) const 3309f857971dSopenharmony_ci{ 3310f857971dSopenharmony_ci FI_HILOGD("enter"); 3311f857971dSopenharmony_ci CHKPV(alpha_); 3312f857971dSopenharmony_ci CHKPV(g_drawingInfo.parentNode); 3313f857971dSopenharmony_ci g_drawingInfo.parentNode->SetAlpha(alpha_->Get()); 3314f857971dSopenharmony_ci CHKPV(scale_); 3315f857971dSopenharmony_ci g_drawingInfo.parentNode->SetScale(scale_->Get(), scale_->Get()); 3316f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3317f857971dSopenharmony_ci FI_HILOGD("leave"); 3318f857971dSopenharmony_ci} 3319f857971dSopenharmony_ci 3320f857971dSopenharmony_civoid DrawDynamicEffectModifier::SetAlpha(float alpha) 3321f857971dSopenharmony_ci{ 3322f857971dSopenharmony_ci FI_HILOGD("enter"); 3323f857971dSopenharmony_ci if (alpha_ == nullptr) { 3324f857971dSopenharmony_ci alpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha); 3325f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(alpha_); 3326f857971dSopenharmony_ci return; 3327f857971dSopenharmony_ci } 3328f857971dSopenharmony_ci alpha_->Set(alpha); 3329f857971dSopenharmony_ci FI_HILOGD("leave"); 3330f857971dSopenharmony_ci} 3331f857971dSopenharmony_ci 3332f857971dSopenharmony_civoid DrawDynamicEffectModifier::SetScale(float scale) 3333f857971dSopenharmony_ci{ 3334f857971dSopenharmony_ci FI_HILOGD("enter"); 3335f857971dSopenharmony_ci if (scale_ == nullptr) { 3336f857971dSopenharmony_ci scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale); 3337f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(scale_); 3338f857971dSopenharmony_ci return; 3339f857971dSopenharmony_ci } 3340f857971dSopenharmony_ci scale_->Set(scale); 3341f857971dSopenharmony_ci FI_HILOGD("leave"); 3342f857971dSopenharmony_ci} 3343f857971dSopenharmony_ci 3344f857971dSopenharmony_civoid DrawStyleChangeModifier::Draw(Rosen::RSDrawingContext &context) const 3345f857971dSopenharmony_ci{ 3346f857971dSopenharmony_ci FI_HILOGD("enter"); 3347f857971dSopenharmony_ci if (!CheckNodesValid()) { 3348f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3349f857971dSopenharmony_ci return; 3350f857971dSopenharmony_ci } 3351f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 3352f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 3353f857971dSopenharmony_ci return; 3354f857971dSopenharmony_ci } 3355f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 3356f857971dSopenharmony_ci CHKPV(dragStyleNode); 3357f857971dSopenharmony_ci CHKPV(g_drawingInfo.pixelMap); 3358f857971dSopenharmony_ci float pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); 3359f857971dSopenharmony_ci if (stylePixelMap_ == nullptr) { 3360f857971dSopenharmony_ci if (scale_ == nullptr) { 3361f857971dSopenharmony_ci return; 3362f857971dSopenharmony_ci } 3363f857971dSopenharmony_ci dragStyleNode->SetScale(scale_->Get()); 3364f857971dSopenharmony_ci return; 3365f857971dSopenharmony_ci } 3366f857971dSopenharmony_ci float scalingValue = GetScaling(); 3367f857971dSopenharmony_ci if ((1.0 * INT_MAX / EIGHT_SIZE) <= scalingValue) { 3368f857971dSopenharmony_ci return; 3369f857971dSopenharmony_ci } 3370f857971dSopenharmony_ci int32_t adjustSize = EIGHT_SIZE * scalingValue; 3371f857971dSopenharmony_ci int32_t svgTouchPositionX = pixelMapWidth + adjustSize - stylePixelMap_->GetWidth(); 3372f857971dSopenharmony_ci dragStyleNode->SetBounds(svgTouchPositionX, (TWELVE_SIZE-EIGHT_SIZE)*scalingValue, stylePixelMap_->GetWidth(), 3373f857971dSopenharmony_ci stylePixelMap_->GetHeight()); 3374f857971dSopenharmony_ci dragStyleNode->SetFrame(svgTouchPositionX, (TWELVE_SIZE-EIGHT_SIZE)*scalingValue, stylePixelMap_->GetWidth(), 3375f857971dSopenharmony_ci stylePixelMap_->GetHeight()); 3376f857971dSopenharmony_ci dragStyleNode->SetBgImageWidth(stylePixelMap_->GetWidth()); 3377f857971dSopenharmony_ci dragStyleNode->SetBgImageHeight(stylePixelMap_->GetHeight()); 3378f857971dSopenharmony_ci dragStyleNode->SetBgImagePositionX(0); 3379f857971dSopenharmony_ci dragStyleNode->SetBgImagePositionY(0); 3380f857971dSopenharmony_ci auto rosenImage = std::make_shared<Rosen::RSImage>(); 3381f857971dSopenharmony_ci rosenImage->SetPixelMap(stylePixelMap_); 3382f857971dSopenharmony_ci rosenImage->SetImageRepeat(0); 3383f857971dSopenharmony_ci dragStyleNode->SetBgImage(rosenImage); 3384f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3385f857971dSopenharmony_ci FI_HILOGD("leave"); 3386f857971dSopenharmony_ci} 3387f857971dSopenharmony_ci 3388f857971dSopenharmony_civoid DrawStyleChangeModifier::SetScale(float scale) 3389f857971dSopenharmony_ci{ 3390f857971dSopenharmony_ci FI_HILOGD("enter"); 3391f857971dSopenharmony_ci if (scale_ == nullptr) { 3392f857971dSopenharmony_ci scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale); 3393f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(scale_); 3394f857971dSopenharmony_ci } else { 3395f857971dSopenharmony_ci scale_->Set(scale); 3396f857971dSopenharmony_ci } 3397f857971dSopenharmony_ci FI_HILOGD("leave"); 3398f857971dSopenharmony_ci} 3399f857971dSopenharmony_ci 3400f857971dSopenharmony_civoid DrawStyleScaleModifier::Draw(Rosen::RSDrawingContext &context) const 3401f857971dSopenharmony_ci{ 3402f857971dSopenharmony_ci FI_HILOGD("enter"); 3403f857971dSopenharmony_ci if (!CheckNodesValid()) { 3404f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3405f857971dSopenharmony_ci return; 3406f857971dSopenharmony_ci } 3407f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 3408f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 3409f857971dSopenharmony_ci return; 3410f857971dSopenharmony_ci } 3411f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 3412f857971dSopenharmony_ci CHKPV(dragStyleNode); 3413f857971dSopenharmony_ci CHKPV(scale_); 3414f857971dSopenharmony_ci dragStyleNode->SetScale(scale_->Get()); 3415f857971dSopenharmony_ci FI_HILOGD("leave"); 3416f857971dSopenharmony_ci} 3417f857971dSopenharmony_ci 3418f857971dSopenharmony_civoid DrawStyleScaleModifier::SetScale(float scale) 3419f857971dSopenharmony_ci{ 3420f857971dSopenharmony_ci FI_HILOGD("enter"); 3421f857971dSopenharmony_ci if (scale_ == nullptr) { 3422f857971dSopenharmony_ci scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale); 3423f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(scale_); 3424f857971dSopenharmony_ci } else { 3425f857971dSopenharmony_ci scale_->Set(scale); 3426f857971dSopenharmony_ci } 3427f857971dSopenharmony_ci FI_HILOGD("leave"); 3428f857971dSopenharmony_ci} 3429f857971dSopenharmony_ci 3430f857971dSopenharmony_civoid DrawDragStopModifier::Draw(Rosen::RSDrawingContext &context) const 3431f857971dSopenharmony_ci{ 3432f857971dSopenharmony_ci FI_HILOGD("enter"); 3433f857971dSopenharmony_ci CHKPV(alpha_); 3434f857971dSopenharmony_ci CHKPV(scale_); 3435f857971dSopenharmony_ci if (!CheckNodesValid()) { 3436f857971dSopenharmony_ci FI_HILOGE("Check nodes valid failed"); 3437f857971dSopenharmony_ci return; 3438f857971dSopenharmony_ci } 3439f857971dSopenharmony_ci CHKPV(g_drawingInfo.parentNode); 3440f857971dSopenharmony_ci g_drawingInfo.parentNode->SetAlpha(alpha_->Get()); 3441f857971dSopenharmony_ci g_drawingInfo.parentNode->SetScale(scale_->Get(), scale_->Get()); 3442f857971dSopenharmony_ci if (!g_drawingInfo.multiSelectedNodes.empty()) { 3443f857971dSopenharmony_ci size_t multiSelectedNodesSize = g_drawingInfo.multiSelectedNodes.size(); 3444f857971dSopenharmony_ci for (size_t i = 0; i < multiSelectedNodesSize; ++i) { 3445f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> multiSelectedNode = g_drawingInfo.multiSelectedNodes[i]; 3446f857971dSopenharmony_ci CHKPV(multiSelectedNode); 3447f857971dSopenharmony_ci multiSelectedNode->SetAlpha(alpha_->Get()); 3448f857971dSopenharmony_ci multiSelectedNode->SetScale(scale_->Get(), scale_->Get()); 3449f857971dSopenharmony_ci } 3450f857971dSopenharmony_ci } 3451f857971dSopenharmony_ci if (g_drawingInfo.nodes.size() <= DRAG_STYLE_INDEX) { 3452f857971dSopenharmony_ci FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size()); 3453f857971dSopenharmony_ci return; 3454f857971dSopenharmony_ci } 3455f857971dSopenharmony_ci std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX]; 3456f857971dSopenharmony_ci CHKPV(dragStyleNode); 3457f857971dSopenharmony_ci dragStyleNode->SetScale(styleScale_->Get()); 3458f857971dSopenharmony_ci dragStyleNode->SetAlpha(styleAlpha_->Get()); 3459f857971dSopenharmony_ci FI_HILOGD("leave"); 3460f857971dSopenharmony_ci} 3461f857971dSopenharmony_ci 3462f857971dSopenharmony_civoid DrawDragStopModifier::SetAlpha(float alpha) 3463f857971dSopenharmony_ci{ 3464f857971dSopenharmony_ci FI_HILOGD("enter"); 3465f857971dSopenharmony_ci if (alpha_ == nullptr) { 3466f857971dSopenharmony_ci alpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha); 3467f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(alpha_); 3468f857971dSopenharmony_ci } else { 3469f857971dSopenharmony_ci alpha_->Set(alpha); 3470f857971dSopenharmony_ci } 3471f857971dSopenharmony_ci FI_HILOGD("leave"); 3472f857971dSopenharmony_ci} 3473f857971dSopenharmony_ci 3474f857971dSopenharmony_civoid DrawDragStopModifier::SetScale(float scale) 3475f857971dSopenharmony_ci{ 3476f857971dSopenharmony_ci FI_HILOGD("enter"); 3477f857971dSopenharmony_ci if (scale_ == nullptr) { 3478f857971dSopenharmony_ci scale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale); 3479f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(scale_); 3480f857971dSopenharmony_ci } else { 3481f857971dSopenharmony_ci scale_->Set(scale); 3482f857971dSopenharmony_ci } 3483f857971dSopenharmony_ci FI_HILOGD("leave"); 3484f857971dSopenharmony_ci} 3485f857971dSopenharmony_ci 3486f857971dSopenharmony_civoid DrawDragStopModifier::SetStyleScale(float scale) 3487f857971dSopenharmony_ci{ 3488f857971dSopenharmony_ci FI_HILOGD("enter"); 3489f857971dSopenharmony_ci if (styleScale_ == nullptr) { 3490f857971dSopenharmony_ci styleScale_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(scale); 3491f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(styleScale_); 3492f857971dSopenharmony_ci } else { 3493f857971dSopenharmony_ci styleScale_->Set(scale); 3494f857971dSopenharmony_ci } 3495f857971dSopenharmony_ci FI_HILOGD("leave"); 3496f857971dSopenharmony_ci} 3497f857971dSopenharmony_ci 3498f857971dSopenharmony_civoid DrawDragStopModifier::SetStyleAlpha(float alpha) 3499f857971dSopenharmony_ci{ 3500f857971dSopenharmony_ci FI_HILOGD("enter"); 3501f857971dSopenharmony_ci if (styleAlpha_ == nullptr) { 3502f857971dSopenharmony_ci styleAlpha_ = std::make_shared<Rosen::RSAnimatableProperty<float>>(alpha); 3503f857971dSopenharmony_ci Rosen::RSModifier::AttachProperty(styleAlpha_); 3504f857971dSopenharmony_ci } else { 3505f857971dSopenharmony_ci styleAlpha_->Set(alpha); 3506f857971dSopenharmony_ci } 3507f857971dSopenharmony_ci FI_HILOGD("leave"); 3508f857971dSopenharmony_ci} 3509f857971dSopenharmony_ci 3510f857971dSopenharmony_cifloat DragDrawing::CalculateWidthScale() 3511f857971dSopenharmony_ci{ 3512f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3513f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(g_drawingInfo.displayId); 3514f857971dSopenharmony_ci if (display == nullptr) { 3515f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", g_drawingInfo.displayId); 3516f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 3517f857971dSopenharmony_ci if (display == nullptr) { 3518f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 3519f857971dSopenharmony_ci return DEFAULT_SCALING; 3520f857971dSopenharmony_ci } 3521f857971dSopenharmony_ci } 3522f857971dSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 3523f857971dSopenharmony_ci if (defaultDisplay == nullptr) { 3524f857971dSopenharmony_ci FI_HILOGE("defaultDisplay is nullptr"); 3525f857971dSopenharmony_ci return DEFAULT_SCALING; 3526f857971dSopenharmony_ci } 3527f857971dSopenharmony_ci int32_t width = display->GetWidth(); 3528f857971dSopenharmony_ci float density = defaultDisplay->GetVirtualPixelRatio(); 3529f857971dSopenharmony_ci#else 3530f857971dSopenharmony_ci if (window_ == nullptr) { 3531f857971dSopenharmony_ci FI_HILOGE("window_ is nullptr"); 3532f857971dSopenharmony_ci return DEFAULT_SCALING; 3533f857971dSopenharmony_ci } 3534f857971dSopenharmony_ci int32_t width = window_->GetRect().width_; 3535f857971dSopenharmony_ci float density = window_->GetDensity(); 3536f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3537f857971dSopenharmony_ci FI_HILOGD("density:%{public}f, width:%{public}d", density, width); 3538f857971dSopenharmony_ci if (width < MAX_SCREEN_WIDTH_SM * density) { 3539f857971dSopenharmony_ci currentScreenSize_ = ScreenSizeType::XS; 3540f857971dSopenharmony_ci } else if (width < MAX_SCREEN_WIDTH_MD * density) { 3541f857971dSopenharmony_ci currentScreenSize_ = ScreenSizeType::SM; 3542f857971dSopenharmony_ci } else if (width < MAX_SCREEN_WIDTH_LG * density) { 3543f857971dSopenharmony_ci currentScreenSize_ = ScreenSizeType::MD; 3544f857971dSopenharmony_ci } else if (width < MAX_SCREEN_WIDTH_XL * density) { 3545f857971dSopenharmony_ci currentScreenSize_ = ScreenSizeType::LG; 3546f857971dSopenharmony_ci } else { 3547f857971dSopenharmony_ci currentScreenSize_ = ScreenSizeType::XL; 3548f857971dSopenharmony_ci } 3549f857971dSopenharmony_ci float widthScale = GetMaxWidthScale(width); 3550f857971dSopenharmony_ci return widthScale; 3551f857971dSopenharmony_ci} 3552f857971dSopenharmony_ci 3553f857971dSopenharmony_cifloat DragDrawing::GetMaxWidthScale(int32_t width) 3554f857971dSopenharmony_ci{ 3555f857971dSopenharmony_ci float scale = 1.0; 3556f857971dSopenharmony_ci float widthScale = 1.0; 3557f857971dSopenharmony_ci if (g_drawingInfo.pixelMap == nullptr) { 3558f857971dSopenharmony_ci FI_HILOGE("pixelMap is nullptr"); 3559f857971dSopenharmony_ci return DEFAULT_SCALING; 3560f857971dSopenharmony_ci } 3561f857971dSopenharmony_ci int32_t pixelMapWidth = g_drawingInfo.pixelMap->GetWidth(); 3562f857971dSopenharmony_ci if (pixelMapWidth == 0) { 3563f857971dSopenharmony_ci FI_HILOGW("pixelMapWidth is 0"); 3564f857971dSopenharmony_ci return DEFAULT_SCALING; 3565f857971dSopenharmony_ci } 3566f857971dSopenharmony_ci switch (currentScreenSize_) { 3567f857971dSopenharmony_ci case ScreenSizeType::XS: { 3568f857971dSopenharmony_ci return widthScale; 3569f857971dSopenharmony_ci } 3570f857971dSopenharmony_ci case ScreenSizeType::SM: { 3571f857971dSopenharmony_ci scale = width * SCALE_SM; 3572f857971dSopenharmony_ci if (pixelMapWidth > scale) { 3573f857971dSopenharmony_ci widthScale = scale / pixelMapWidth; 3574f857971dSopenharmony_ci return widthScale; 3575f857971dSopenharmony_ci } 3576f857971dSopenharmony_ci return widthScale; 3577f857971dSopenharmony_ci } 3578f857971dSopenharmony_ci case ScreenSizeType::MD: { 3579f857971dSopenharmony_ci scale = width * SCALE_MD; 3580f857971dSopenharmony_ci if (pixelMapWidth > scale) { 3581f857971dSopenharmony_ci widthScale = scale / pixelMapWidth; 3582f857971dSopenharmony_ci return widthScale; 3583f857971dSopenharmony_ci } 3584f857971dSopenharmony_ci return widthScale; 3585f857971dSopenharmony_ci } 3586f857971dSopenharmony_ci case ScreenSizeType::LG: { 3587f857971dSopenharmony_ci scale = width * SCALE_LG; 3588f857971dSopenharmony_ci if (pixelMapWidth > scale) { 3589f857971dSopenharmony_ci widthScale = scale / pixelMapWidth; 3590f857971dSopenharmony_ci return widthScale; 3591f857971dSopenharmony_ci } 3592f857971dSopenharmony_ci return widthScale; 3593f857971dSopenharmony_ci } 3594f857971dSopenharmony_ci default: { 3595f857971dSopenharmony_ci FI_HILOGI("Screen Size Type is XL"); 3596f857971dSopenharmony_ci break; 3597f857971dSopenharmony_ci } 3598f857971dSopenharmony_ci } 3599f857971dSopenharmony_ci return widthScale; 3600f857971dSopenharmony_ci} 3601f857971dSopenharmony_ci 3602f857971dSopenharmony_civoid DragDrawing::UpdateDragWindowDisplay(int32_t displayId) 3603f857971dSopenharmony_ci{ 3604f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 3605f857971dSopenharmony_ci CHKPV(g_drawingInfo.surfaceNode); 3606f857971dSopenharmony_ci CHKPV(g_drawingInfo.rootNode); 3607f857971dSopenharmony_ci sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); 3608f857971dSopenharmony_ci if (display == nullptr) { 3609f857971dSopenharmony_ci FI_HILOGD("Get display info failed, display:%{public}d", displayId); 3610f857971dSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDisplayById(0); 3611f857971dSopenharmony_ci if (display == nullptr) { 3612f857971dSopenharmony_ci FI_HILOGE("Get display info failed, display is nullptr"); 3613f857971dSopenharmony_ci } 3614f857971dSopenharmony_ci return; 3615f857971dSopenharmony_ci } 3616f857971dSopenharmony_ci int32_t surfaceNodeSize = std::max(display->GetWidth(), display->GetHeight()); 3617f857971dSopenharmony_ci g_drawingInfo.surfaceNode->SetBounds(0, 0, surfaceNodeSize, surfaceNodeSize); 3618f857971dSopenharmony_ci g_drawingInfo.rootNode->SetBounds(0, 0, surfaceNodeSize, surfaceNodeSize); 3619f857971dSopenharmony_ci g_drawingInfo.rootNode->SetFrame(0, 0, surfaceNodeSize, surfaceNodeSize); 3620f857971dSopenharmony_ci g_drawingInfo.surfaceNode->DetachToDisplay(screenId_); 3621f857971dSopenharmony_ci g_drawingInfo.surfaceNode->AttachToDisplay(displayId); 3622f857971dSopenharmony_ci Rosen::RSTransaction::FlushImplicitTransaction(); 3623f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 3624f857971dSopenharmony_ci} 3625f857971dSopenharmony_ci 3626f857971dSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ARKUI_X 3627f857971dSopenharmony_civoid DragDrawing::SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window) 3628f857971dSopenharmony_ci{ 3629f857971dSopenharmony_ci CALL_INFO_TRACE; 3630f857971dSopenharmony_ci window_ = window; 3631f857971dSopenharmony_ci} 3632f857971dSopenharmony_ci 3633f857971dSopenharmony_civoid DragDrawing::AddDragDestroy(std::function<void()> cb) 3634f857971dSopenharmony_ci{ 3635f857971dSopenharmony_ci CALL_INFO_TRACE; 3636f857971dSopenharmony_ci callback_ = cb; 3637f857971dSopenharmony_ci} 3638f857971dSopenharmony_ci 3639f857971dSopenharmony_civoid DragDrawing::SetSVGFilePath(const std::string &filePath) 3640f857971dSopenharmony_ci{ 3641f857971dSopenharmony_ci CALL_INFO_TRACE; 3642f857971dSopenharmony_ci svgFilePath_ = filePath; 3643f857971dSopenharmony_ci} 3644f857971dSopenharmony_ci#endif 3645f857971dSopenharmony_ci 3646f857971dSopenharmony_civoid DragDrawing::LoadDragDropLib() 3647f857971dSopenharmony_ci{ 3648f857971dSopenharmony_ci FI_HILOGI("Begin to open drag drop extension library"); 3649f857971dSopenharmony_ci if (dragExtHandler_ == nullptr) { 3650f857971dSopenharmony_ci dragExtHandler_ = dlopen(DRAG_DROP_EXTENSION_SO_PATH.c_str(), RTLD_LAZY); 3651f857971dSopenharmony_ci } 3652f857971dSopenharmony_ci CHKPL(dragExtHandler_); 3653f857971dSopenharmony_ci FI_HILOGI("End to open drag drop extension library"); 3654f857971dSopenharmony_ci} 3655f857971dSopenharmony_ci} // namespace DeviceStatus 3656f857971dSopenharmony_ci} // namespace Msdp 3657f857971dSopenharmony_ci} // namespace OHOS 3658