diff --git a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.cpp b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.cpp index 62e828e42b2fe916ba3c88f485dae17c4a8e8a2b..b406c79ef799a742bfce22d824f60e6855209bbe 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.cpp +++ b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.cpp @@ -17,12 +17,15 @@ #include "drawing/engine_adapter/skia_adapter/skia_canvas.h" +#include "base/ressched/ressched_report.h" +#include "base/utils/time_util.h" #include "base/utils/utils.h" #include "core/common/ace_application_info.h" #include "core/components_ng/pattern/custom_paint/canvas_paint_method.h" #include "core/components_ng/pattern/custom_paint/offscreen_canvas_pattern.h" #include "core/components_ng/pattern/custom_paint/rendering_context2d_modifier.h" #include "core/components_ng/render/adapter/rosen_render_context.h" +#include "core/event/touch_event.h" namespace { constexpr int32_t PLATFORM_VERSION_TEN = 10; @@ -30,6 +33,9 @@ constexpr int32_t PLATFORM_VERSION_TEN = 10; namespace OHOS::Ace::NG { class RosenRenderContext; +#ifdef OHOS_PLATFORM +constexpr int64_t INCREASE_CPU_TIME_ONCE = 4000000000; // 4s(unit: ns) +#endif void CustomPaintPattern::OnAttachToFrameNode() { auto host = GetHost(); @@ -44,6 +50,7 @@ void CustomPaintPattern::OnAttachToFrameNode() AceType::MakeRefPtr(); } paintMethod_ = MakeRefPtr(context, contentModifier_); + InitEvent(); } RefPtr CustomPaintPattern::CreateNodePaintMethod() @@ -79,6 +86,55 @@ bool CustomPaintPattern::OnDirtyLayoutWrapperSwap(const RefPtr& d return false; } +void CustomPaintPattern::InitEvent() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + auto gestureHub = eventHub->GetOrCreateGestureEventHub(); + CHECK_NULL_VOID(gestureHub); + InitTouchEvent(gestureHub); +} + +void CustomPaintPattern::InitTouchEvent(const RefPtr& gestureHub) +{ + CHECK_NULL_VOID_NOLOG(!touchEvent_); + + auto touchTask = [weak = WeakClaim(this)](const TouchEventInfo& info) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->HandleTouchEvent(info); + }; + + touchEvent_ = MakeRefPtr(std::move(touchTask)); + gestureHub->AddTouchEvent(touchEvent_); +} + +void CustomPaintPattern::HandleTouchEvent(const TouchEventInfo& info) +{ +#ifdef OHOS_PLATFORM + auto touchInfoList = info.GetChangedTouches(); + if (touchInfoList.empty()) { + return; + } + auto touchType = touchInfoList.front().GetTouchType(); + // increase cpu frequency + if (touchType == TouchType::MOVE) { + auto currentTime = GetSysTimestamp(); + auto increaseCpuTime = currentTime - startIncreaseTime_; + if (increaseCpuTime >= INCREASE_CPU_TIME_ONCE) { + LOGD("HandleTouchEvent increase cpu frequency"); + startIncreaseTime_ = currentTime; + ResSchedReport::GetInstance().ResSchedDataReport("slide_on"); + } + } else if (touchType == TouchType::UP) { + startIncreaseTime_ = 0; + ResSchedReport::GetInstance().ResSchedDataReport("slide_off"); + } +#endif +} + void CustomPaintPattern::SetAntiAlias(bool isEnabled) { auto task = [isEnabled](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) { diff --git a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.h b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.h index 3e14ad2965bd6e4d6225be62b61bdb8aafff312f..2331aff071d590114437ac9e28d969c9d9389a40 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.h +++ b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_pattern.h @@ -143,13 +143,19 @@ public: private: void OnAttachToFrameNode() override; bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; + void InitEvent(); + void InitTouchEvent(const RefPtr& gestureHub); + void HandleTouchEvent(const TouchEventInfo& info); RefPtr paintMethod_; std::optional canvasSize_; bool isCanvasInit_ = false; RefPtr contentModifier_; - + RefPtr touchEvent_; +#ifdef OHOS_PLATFORM + int64_t startIncreaseTime_ = 0; +#endif ACE_DISALLOW_COPY_AND_MOVE(CustomPaintPattern); }; } // namespace OHOS::Ace::NG