1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DRAG_SMOOTH_PROCESSOR_H 17 #define DRAG_SMOOTH_PROCESSOR_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <optional> 22 #include <vector> 23 24 namespace OHOS { 25 namespace Msdp { 26 namespace DeviceStatus { 27 struct DragMoveEvent { 28 float displayX { 0.0f }; 29 float displayY { 0.0f }; 30 int32_t displayId { -1 }; 31 uint64_t timestamp { 0 }; 32 }; 33 34 class DragSmoothProcessor { 35 public: 36 void InsertEvent(const DragMoveEvent &event); 37 DragMoveEvent SmoothMoveEvent(uint64_t nanoTimestamp, uint64_t vSyncPeriod); 38 void ResetParameters(); 39 40 private: 41 std::optional<DragMoveEvent> GetInterpolatedEvent(const DragMoveEvent &historyAvgEvent, 42 const DragMoveEvent ¤tAvgEvent, uint64_t nanoTimestamp); 43 std::optional<DragMoveEvent> Resample(const std::vector<DragMoveEvent>& history, 44 const std::vector<DragMoveEvent>& current, uint64_t nanoTimestamp); 45 void DumpMoveEvent(const std::vector<DragMoveEvent>& history, 46 const std::vector<DragMoveEvent>& current, const DragMoveEvent &historyAvgEvent, 47 const DragMoveEvent ¤tAvgEvent, const DragMoveEvent &latestEvent); 48 DragMoveEvent GetNearestEvent(const std::vector<DragMoveEvent>& events, uint64_t nanoTimestamp); 49 DragMoveEvent GetAvgCoordinate(const std::vector<DragMoveEvent>& events); 50 std::optional<DragMoveEvent> GetResampleEvent(const std::vector<DragMoveEvent>& history, 51 const std::vector<DragMoveEvent>& current, uint64_t nanoTimestamp); 52 std::vector<DragMoveEvent> moveEvents_; 53 std::vector<DragMoveEvent> historyEvents_; 54 uint64_t resampleTimeStamp_ { 0 }; 55 std::mutex mtx_; 56 }; 57 } // namespace DeviceStatus 58 } // namespace Msdp 59 } // namespace OHOS 60 #endif // DRAG_SMOOTH_PROCESSOR_H