From: Hosang Kim Date: Tue, 16 Apr 2024 07:39:41 +0000 (+0900) Subject: AtspiAccessibleWatcher: refactoring processing event for performance. X-Git-Tag: accepted/tizen/unified/20240424.063514~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd82f54a4cb8b7e3c07042e5796bfd033e9fe4b4;p=platform%2Fcore%2Fuifw%2Faurum.git AtspiAccessibleWatcher: refactoring processing event for performance. 1. add processWindowEvent 2. add processPostRender 3. only call dbus function when necessary. Change-Id: I1e99244f868c7b540b8c7448328f7cbac4f84bbd --- diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index e751791..56706a2 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -160,10 +160,12 @@ private: bool addToWindowSet(AtspiAccessible *node); static gpointer eventThreadLoop(gpointer data); static gpointer timerThread(gpointer data); - void appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid); - void removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid); + void appendApp(AtspiAccessible *app, char *pkg, int pid); + void removeApp(char *pkg, int pid); void setXMLsync(); void processCallback(char *type, char *name, char *pkg); + void processWindowEvent(AtspiEvent *event); + void processPostRender(); private: GDBusProxy *mDbusProxy; diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index be37001..eef77e1 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -236,7 +236,7 @@ AtspiAccessibleWatcher::~AtspiAccessibleWatcher() atspi_exit(); } -void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid) +void AtspiAccessibleWatcher::appendApp(AtspiAccessible *app, char *pkg, int pid) { LOGI("window activated in app(%s:%d)", pkg, pid); if (mXMLSync) @@ -244,30 +244,30 @@ void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAc std::string package(pkg); if (!package.empty()) { - if (instance->mXMLDocMap.count({package, pid})) { + if (mXMLDocMap.count({package, pid})) { mAppCount--; mAppXMLLoadedCount--; - instance->mXMLDocMap.erase({package, pid}); + mXMLDocMap.erase({package, pid}); } mAppCount++; - instance->mXMLDocMap.insert({{package, pid}, + mXMLDocMap.insert({{package, pid}, std::make_shared(std::make_shared(app), &mAppXMLLoadedCount, &mXMLMutex, &mXMLConditionVar)}); g_object_ref(app); } } } -void AtspiAccessibleWatcher::removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid) +void AtspiAccessibleWatcher::removeApp(char *pkg, int pid) { LOGI("window deactivate in app(%s:%d)", pkg, pid); if (mXMLSync) { std::string package(pkg); - if (instance->mXMLDocMap.count({package, pid})) { + if (mXMLDocMap.count({package, pid})) { mAppCount--; mAppXMLLoadedCount--; - instance->mXMLDocMap.erase({package, pid}); + mXMLDocMap.erase({package, pid}); } } } @@ -318,7 +318,52 @@ void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg) else ++it; } } +} + +void AtspiAccessibleWatcher::processPostRender() +{ + if (isIdle == IdleEventState::IDLE_LISTEN_START) + { + if (mTimerThread == nullptr) + { + LOGI("Timer Thread Start"); + mTimerThread = g_thread_new("TimerThread", timerThread, nullptr); + } + else + { + mStartTime = std::chrono::system_clock::now(); + } + + mRenderCount--; + if (mRenderCount == 0) + { + LOGI("RenderCount is 0. Stop to listen RenderPost"); + isIdle = IdleEventState::IDLE_LISTEN_DONE; + } + } +} +void AtspiAccessibleWatcher::processWindowEvent(AtspiEvent *event) +{ + char *name = NULL, *pkg = NULL; + int pid = 0; + name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL); + pkg = AtspiWrapper::Atspi_accessible_get_name(event->sender, NULL); + pid = AtspiWrapper::Atspi_accessible_get_process_id(event->sender, NULL); + + if (!strncmp(event->type, "window:create", 13)) appendApp(event->sender, pkg, pid); + else if (!strncmp(event->type, "window:activate", 15) && mXMLDocMap.count({pkg, pid}) == 0) appendApp(event->sender, pkg, pid); + else if (!strncmp(event->type, "window:destroy", 14)) removeApp(pkg, pid); + + // To support focus skipped window + if (isTv) { + if (!strncmp(event->type, "window:restore", 14) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9))) + appendApp(event->sender, pkg, pid); + else if (!strncmp(event->type, "window:minimize", 15) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9))) + removeApp(pkg, pid); + } + if (name) g_free(name); + if (pkg) g_free(pkg); } void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher) @@ -338,77 +383,38 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher) return; } - if (!strncmp(event->type, "w", 1)) - isWindowEventEmitted = true; - - char *name = NULL, *pkg = NULL; - int pid = 0; AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)watcher; - name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL); - if (isIdle == IdleEventState::IDLE_LISTEN_START && !strncmp(event->type, "window:post-render", 18)) - { - if (mTimerThread == nullptr) - { - LOGI("Timer Thread Start"); - mTimerThread = g_thread_new("TimerThread", timerThread, instance); - } - else - { - mStartTime = std::chrono::system_clock::now(); - } - - mRenderCount--; - if (mRenderCount == 0) - { - LOGI("RenderCount is 0. Stop to listen RenderPost"); - isIdle = IdleEventState::IDLE_LISTEN_DONE; - } - - if (name) free(name); + if (!strncmp(event->type, "object:state-changed:defunct", 28)) { + instance->onObjectDefunct( + static_cast(event->source)); g_boxed_free(ATSPI_TYPE_EVENT, event); return; } - else if (isIdle == IdleEventState::IDLE_LISTEN_DONE && !strncmp(event->type, "window:post-render", 18)) + + if (!strncmp(event->type, "window:post-render", 18)) { - if (name) free(name); + instance->processPostRender(); g_boxed_free(ATSPI_TYPE_EVENT, event); return; } - AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(event->source, NULL); - if (name && app) + if (!strncmp(event->type, "w", 1)) { - pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL); - pid = AtspiWrapper::Atspi_accessible_get_process_id(app, NULL); - if (!strncmp(event->type, "window:create", 13)) instance->appendApp(instance, app, pkg, pid); - else if (!strncmp(event->type, "window:activate", 15) && instance->mXMLDocMap.count({pkg, pid}) == 0) instance->appendApp(instance, app, pkg, pid); - else if (!strncmp(event->type, "window:destroy", 14)) instance->removeApp(instance, app, pkg, pid); - - // To support focus skipped window - if (instance->isTv) { - if (!strncmp(event->type, "window:restore", 14) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9))) - instance->appendApp(instance, app, pkg, pid); - else if (!strncmp(event->type, "window:minimize", 15) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9))) - instance->removeApp(instance, app, pkg, pid); - } + isWindowEventEmitted = true; + instance->processWindowEvent(event); } - else - pkg = strdup(""); - if(app) + if (mWaitingForEvent || !instance->mHandlers.empty()) { - g_object_unref(app); + char *name = NULL, *pkg = NULL; + name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL); + pkg = AtspiWrapper::Atspi_accessible_get_name(event->sender, NULL); + instance->processCallback(event->type, name, pkg); + if (name) g_free(name); + if (pkg) g_free(pkg); } - instance->processCallback(event->type, name, pkg); - - if (!strcmp(event->type, "object:state-changed:defunct")) { - instance->onObjectDefunct( - static_cast(event->source)); - } - if (name) free(name); - if (pkg) free(pkg); g_boxed_free(ATSPI_TYPE_EVENT, event); }