From: Woochan Lee Date: Thu, 23 Mar 2023 09:14:15 +0000 (+0900) Subject: libaurum: Reduce dbus method call for performance X-Git-Tag: accepted/tizen/unified/20230327.143735~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9beafbbe8daff59a1d81c628c40d7df4e239392;p=platform%2Fcore%2Fuifw%2Faurum.git libaurum: Reduce dbus method call for performance Change-Id: Icd2695fbf24937bd9be624db5b261badb3090d5d --- diff --git a/libaurum/src/AurumXML.cc b/libaurum/src/AurumXML.cc index ea41c31..e6ef9f6 100644 --- a/libaurum/src/AurumXML.cc +++ b/libaurum/src/AurumXML.cc @@ -41,7 +41,11 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr { if (!node) return; - node->refresh(false); + node->updateUniqueId(); + node->updateName(); + node->updateRoleName(); + node->updateAttributes(); + node->updateToolkitName(); std::string name; if (node->getType().empty()) @@ -57,45 +61,18 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr element.set_name(name.c_str()); element.append_attribute("name") = node->getText().c_str(); - element.append_attribute("type") = node->getType().c_str(); element.append_attribute("id") = node->getId().c_str(); element.append_attribute("automationid") = node->getAutomationId().c_str(); - element.append_attribute("package") = node->getPkg().c_str(); - - const Rect &size = node->getScreenBoundingBox(); - element.append_attribute("x") = size.mTopLeft.x; - element.append_attribute("y") = size.mTopLeft.y; - element.append_attribute("width") = size.width(); - element.append_attribute("height") = size.height(); - - const std::vector> attributes = { - {"checked", node->isChecked()}, - {"checkable", node->isCheckable()}, - {"clickable", node->isClickable()}, - {"enabled", node->isEnabled()}, - {"focused", node->isFocused()}, - {"focusable", node->isFocusable()}, - {"scrollable", node->isScrollable()}, - {"selected", node->isSelected()}, - {"showing", node->isShowing()}, - {"active", node->isActive()}, - {"visible", node->isVisible()}, - {"selectable", node->isSelectable()}, - {"highlightable", node->isHighlightable()} - }; - for (const auto& attribute : attributes) { - element.append_attribute(attribute.first.c_str()) = attribute.second; - } mXNodeMap[node->getId()] = node; - int childCnt = node->getChildCount(); - for (int i = 0; i < childCnt; i++) { - const std::shared_ptr& childNode = node->getChildAt(i); - if (childNode->getRawHandler() == nullptr) continue; + auto children = node->getChildren(); + for (auto &child : children) + { + if (child->getRawHandler() == nullptr) continue; xml_node childElement = element.append_child(""); - traverse(childElement, childNode); + traverse(childElement, child); } } @@ -188,13 +165,12 @@ std::shared_ptr AurumXML::checkParentNode(const std::shared_ptr< xml_node xmlNode = mDoc->select_node(query.c_str()).node(); if (xmlNode) { - int childCnt = parent->getChildCount(); - for (int i = 0; i < childCnt; i++) { - const std::shared_ptr& childNode = parent->getChildAt(i); - if (childNode->getRawHandler() == nullptr) continue; + auto children = node->getChildren(); + for (auto &child : children) { + if (child->getRawHandler() == nullptr) continue; xml_node childElement = xmlNode.append_child(""); - traverse(childElement, childNode); + traverse(childElement, child); } return parent; } diff --git a/libaurum/src/Comparer.cc b/libaurum/src/Comparer.cc index 3082249..ec1e402 100644 --- a/libaurum/src/Comparer.cc +++ b/libaurum/src/Comparer.cc @@ -97,13 +97,13 @@ std::vector> Comparer::findObjects( if (currentMatch) partialMatches.push_front(currentMatch); if (!(mSelector->mMaxDepth && (depth+1 > mSelector->mMaxDepth))) { - int childCnt = root->getChildCount(); - for (int i = 0; i < childCnt; i++) { - std::shared_ptr childNode = root->getChildAt(i); - if (childNode->getRawHandler() == nullptr) continue; + auto children = root->getChildren(); + for (int i = 0; i < (int)children.size(); i++) { + auto child = children[i]; + if (child->getRawHandler() == nullptr) continue; std::vector> childret = - findObjects(childNode, i, depth + 1, partialMatches); + findObjects(child, i, depth + 1, partialMatches); std::move(std::begin(childret), std::end(childret), std::back_inserter(ret)); if (!ret.empty() && mEarlyReturn) { LOGI("Object found and earlyReturn"); diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index 2dc48ce..1301c8b 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -33,7 +33,6 @@ AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node) watcher->attach(shared_from_this()); if (mNode) { - this->updateApplication(); this->updateUniqueId(); this->updateStates(); } else { @@ -70,11 +69,20 @@ std::shared_ptr AtspiAccessibleNode::getChildAt(int index) const std::vector> AtspiAccessibleNode::getChildren() const { std::vector> ret{}; - int nchild = this->getChildCount(); - for (int i = 0; i < nchild; i++) { - auto child = getChildAt(i); - if (child) ret.push_back(child); + + GArray *children = AtspiWrapper::Atspi_accessible_get_children(mNode, NULL); + if (children) { + ret.reserve(children->len); + AtspiAccessible *child = nullptr; + for (unsigned int i = 0; i < children->len; i++) { + child = g_array_index(children, AtspiAccessible *, i); + if (child) { + ret.push_back(std::make_shared(child)); + } + } + g_array_free(children, true); } + return ret; } @@ -109,6 +117,8 @@ void* AtspiAccessibleNode::getRawHandler(void) const void AtspiAccessibleNode::updateRoleName() { + if (!mRole.empty()) return; + AtspiWrapper::Atspi_accessible_clear_cache(mNode); gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL); @@ -120,6 +130,8 @@ void AtspiAccessibleNode::updateRoleName() void AtspiAccessibleNode::updateUniqueId() { + if (!mId.empty()) return; + AtspiWrapper::Atspi_accessible_clear_cache(mNode); #ifdef TIZEN @@ -146,6 +158,8 @@ void AtspiAccessibleNode::updateName() void AtspiAccessibleNode::updateToolkitName() { + if (!mToolkitName.empty()) return; + AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL); if (app) { gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(app, NULL); @@ -159,6 +173,8 @@ void AtspiAccessibleNode::updateToolkitName() void AtspiAccessibleNode::updateApplication() { + if (!mPkg.empty()) return; + AtspiWrapper::Atspi_accessible_clear_cache(mNode); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL); @@ -174,6 +190,8 @@ void AtspiAccessibleNode::updateApplication() void AtspiAccessibleNode::updateAttributes() { + if (!mType.empty()) return; + AtspiWrapper::Atspi_accessible_clear_cache(mNode); GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL); @@ -218,8 +236,6 @@ void AtspiAccessibleNode::updateStates() void AtspiAccessibleNode::updateExtents() { - AtspiWrapper::Atspi_accessible_clear_cache(mNode); - AtspiComponent *component = AtspiWrapper::Atspi_accessible_get_component_iface(mNode); if (component) { AtspiRect *screenExtent = AtspiWrapper::Atspi_component_get_extents( @@ -267,15 +283,13 @@ void AtspiAccessibleNode::updateValue() void AtspiAccessibleNode::updatePid() { - AtspiWrapper::Atspi_accessible_clear_cache(mNode); + if (mPid > 0) return; mPid = AtspiWrapper::Atspi_accessible_get_process_id(mNode, NULL); } void AtspiAccessibleNode::updateTextMinBoundingRect() { - AtspiWrapper::Atspi_accessible_clear_cache(mNode); - AtspiText *text = atspi_accessible_get_text_iface(mNode); if (text) { @@ -310,57 +324,66 @@ void AtspiAccessibleNode::refresh(bool updateAll) AtspiWrapper::Atspi_accessible_clear_cache(mNode); if (isValid()) { - gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL); - if (rolename) { - mRole = rolename; - g_free(rolename); + if (mRole.empty()) { + gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL); + if (rolename) { + mRole = rolename; + g_free(rolename); + } } #ifdef TIZEN - gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL); - if (uID) { - mId = uID; - g_free(uID); + if (mId.empty()) { + gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL); + if (uID) { + mId = uID; + g_free(uID); + } } #else mId = std::string{"N/A"}; #endif - gchar *name = AtspiWrapper::Atspi_accessible_get_name(mNode, NULL); if (name) { mText = name; g_free(name); } - gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(mNode, NULL); - if (toolkitName) { - mToolkitName = toolkitName; - g_free(toolkitName); + if (mToolkitName.empty()) { + gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(mNode, NULL); + if (toolkitName) { + mToolkitName = toolkitName; + g_free(toolkitName); + } } - AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL); - if (app) { - gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL); - if (pkg) { - mPkg = pkg; - g_free(pkg); + if (mPkg.empty()) { + AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL); + if (app) { + gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL); + if (pkg) { + mPkg = pkg; + g_free(pkg); + } + g_object_unref(app); } - g_object_unref(app); } - GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL); - if (attributes) { - char *t = (char*)g_hash_table_lookup(attributes, "type"); - if (!t) t = (char*)g_hash_table_lookup(attributes, "t"); - if (!t) t = (char*)g_hash_table_lookup(attributes, "class"); - char *s = (char*)g_hash_table_lookup(attributes, "style"); - char *a = (char*)g_hash_table_lookup(attributes, "automationId"); - - if (t) mType = std::string(t); - else mType = mRole; - if (s) mStyle = std::string(s); - if (a) mAutomationId = std::string(a); - - g_hash_table_unref(attributes); + if (mType.empty()) { + GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL); + if (attributes) { + char *t = (char*)g_hash_table_lookup(attributes, "type"); + if (!t) t = (char*)g_hash_table_lookup(attributes, "t"); + if (!t) t = (char*)g_hash_table_lookup(attributes, "class"); + char *s = (char*)g_hash_table_lookup(attributes, "style"); + char *a = (char*)g_hash_table_lookup(attributes, "automationId"); + + if (t) mType = std::string(t); + else mType = mRole; + if (s) mStyle = std::string(s); + if (a) mAutomationId = std::string(a); + + g_hash_table_unref(attributes); + } } AtspiStateSet *st = AtspiWrapper::Atspi_accessible_get_state_set(mNode); diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index 1f1ef65..25feacf 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -139,6 +139,8 @@ AtspiAccessibleWatcher::AtspiAccessibleWatcher() atspi_init(); + AtspiWrapper::Atspi_accessible_set_cache_mask(AtspiWrapper::Atspi_get_desktop(0), ATSPI_CACHE_ALL); + mEventThread = g_thread_new("AtspiEventThread", eventThreadLoop, this); mDbusProxy = g_dbus_proxy_new_for_bus_sync( @@ -191,7 +193,6 @@ AtspiAccessibleWatcher::~AtspiAccessibleWatcher() void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg) { - AtspiWrapper::Atspi_accessible_set_cache_mask(app, ATSPI_CACHE_ALL); LOGI("window activated in app(%s)", pkg); if (!instance->mActiveAppMap.count(app)) { LOGI("add activated window's app in map"); diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index 82fa073..41ef208 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -144,8 +144,14 @@ std::shared_ptr UiObject::getChildAt(int index) const { std::vector> UiObject::getChildren() const { - auto sel = Sel::depth(2); - return this->findObjects(sel); + std::vector> ret{}; + + auto children = getAccessibleNode()->getChildren(); + for (auto &child : children) { + ret.push_back(std::make_shared(mDevice, mSelector, child)); + } + + return ret; } std::shared_ptr UiObject::getDescendant()