From be2b6ca2080aa2cbde23c25e8babfd0545b223ca Mon Sep 17 00:00:00 2001 From: liqiang Date: Tue, 16 Mar 2021 15:14:31 +0800 Subject: [PATCH] add alwaysInvoke attribute to accelerate ui Change-Id: I366332f4ac2a661cb6f32b2638224c4a573eea32 --- frameworks/ims/input_event_client_proxy.h | 2 ++ frameworks/ims/input_event_listener_proxy.cpp | 1 + interfaces/innerkits/input_event_listener_proxy.h | 14 ++++++++++++++ services/ims/input_event_client_proxy.cpp | 8 ++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frameworks/ims/input_event_client_proxy.h b/frameworks/ims/input_event_client_proxy.h index 5f45063..21fb3be 100755 --- a/frameworks/ims/input_event_client_proxy.h +++ b/frameworks/ims/input_event_client_proxy.h @@ -51,10 +51,12 @@ private: struct ClientInfo { SvcIdentity svc; uint32_t cdId; + bool alwaysInvoke; }; std::map clientInfoMap_; static pthread_mutex_t lock_; + int16_t lastState_ = 0; InputEventClientProxy(const InputEventClientProxy&) = delete; InputEventClientProxy& operator=(const InputEventClientProxy&) = delete; diff --git a/frameworks/ims/input_event_listener_proxy.cpp b/frameworks/ims/input_event_listener_proxy.cpp index 8456f2b..55c752e 100755 --- a/frameworks/ims/input_event_listener_proxy.cpp +++ b/frameworks/ims/input_event_listener_proxy.cpp @@ -81,6 +81,7 @@ bool InputEventListenerProxy::RegisterInputEventListener(RawEventListener* liste return false; } IpcIoPushSvc(&io, &svc); + IpcIoPushBool(&io, listener->IsAlwaysInvoke()); int32_t ret = proxy_->Invoke(proxy_, LITEIMS_CLIENT_REGISTER, &io, NULL, NULL); if (ret != 0) { GRAPHIC_LOGE("Client register failed, ret=%d", ret); diff --git a/interfaces/innerkits/input_event_listener_proxy.h b/interfaces/innerkits/input_event_listener_proxy.h index 08d4ac2..56bd732 100755 --- a/interfaces/innerkits/input_event_listener_proxy.h +++ b/interfaces/innerkits/input_event_listener_proxy.h @@ -31,7 +31,21 @@ public: class RawEventListener { public: + RawEventListener() : alwaysInvoke_(false) {} + virtual ~RawEventListener() {} + + void EnableAlwaysInvoke(bool alwaysInvoke) + { + alwaysInvoke_ = alwaysInvoke; + } + + bool IsAlwaysInvoke() + { + return alwaysInvoke_; + } virtual void OnRawEvent(const RawEvent& event) = 0; + protected: + bool alwaysInvoke_; }; bool RegisterInputEventListener(RawEventListener* listener); diff --git a/services/ims/input_event_client_proxy.cpp b/services/ims/input_event_client_proxy.cpp index b627579..0a5fa4a 100755 --- a/services/ims/input_event_client_proxy.cpp +++ b/services/ims/input_event_client_proxy.cpp @@ -44,6 +44,7 @@ void InputEventClientProxy::AddListener(const void* origin, IpcIo* req, IpcIo* r } pid_t pid = GetCallingPid(origin); SvcIdentity* sid = IpcIoPopSvc(req); + bool alwaysInvoke = IpcIoPopBool(req); if (sid == nullptr) { GRAPHIC_LOGE("Pop Svc failed."); return; @@ -59,7 +60,7 @@ void InputEventClientProxy::AddListener(const void* origin, IpcIo* req, IpcIo* r GRAPHIC_LOGE("Register death callback failed!"); return; } - struct ClientInfo clientInfo = { svc, cbId }; + struct ClientInfo clientInfo = { svc, cbId, alwaysInvoke }; pthread_mutex_lock(&lock_); clientInfoMap_.insert(std::make_pair(pid, clientInfo)); pthread_mutex_unlock(&lock_); @@ -97,8 +98,11 @@ void InputEventClientProxy::OnRawEvent(const RawEvent& event) pthread_mutex_lock(&lock_); std::map::iterator it; for (it = clientInfoMap_.begin(); it != clientInfoMap_.end(); it++) { - SendRequest(nullptr, it->second.svc, 0, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr); + if (it->second.alwaysInvoke || (event.state != lastState_)) { + SendRequest(nullptr, it->second.svc, 0, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr); + } } + lastState_ = event.state; pthread_mutex_unlock(&lock_); } } // namespace OHOS -- Gitee