libaurum: Add cache when gets target windows 47/300647/3 accepted/tizen/unified/20231101.174502
authorWoochan Lee <wc0917.lee@samsung.com>
Mon, 30 Oct 2023 12:04:48 +0000 (21:04 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Tue, 31 Oct 2023 03:29:49 +0000 (03:29 +0000)
If a windows related event does not com from at-spi, We can reuse existing information.

Each operation can remove at least 200ms up to 500ms.
Usually, repeated data is requested in one window(app), so in the actual test it can improve great performance.

Change-Id: I25d6b3a1f06548f05a03fce517dfa0b37e6bccb6

libaurum/inc/Accessibility/AccessibleWatcher.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h
libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc
libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc
libaurum/src/Impl/TizenDeviceImpl.cc

index dd026a4..e2f7c2b 100644 (file)
@@ -152,6 +152,15 @@ public:
      */
     virtual void setXMLsync(bool sync) = 0;
 
+    /**
+     * @brief Gets the window related event has been emitted or not for window info cache
+     *
+     * @return true if window related event emitted, else false
+     *
+     * @since_tizen 8.0
+     */
+    virtual bool getWindowEventEmitted() = 0;
+
 public:
     /**
      * @brief Gets active application vector.
index e827d95..2838827 100644 (file)
@@ -142,6 +142,11 @@ public:
      */
     virtual void setXMLsync(bool sync) override;
 
+    /**
+     * @copydoc @AccessibleWatcher::getWindowEventEmitted()
+    */
+    virtual bool getWindowEventEmitted() override;
+
 public:
     /**
      * @brief Listen atspi events.
@@ -202,6 +207,7 @@ private:
     static std::chrono::system_clock::time_point mStartTime;
     static IdleEventState isIdle;
     static int mRenderCount;
+    static bool isWindowEventEmitted;
 };
 
 }
index cbfa21e..2cff4ae 100644 (file)
@@ -81,6 +81,7 @@ public:
 
     void setXMLsync(bool sync);
 
+    bool getWindowEventEmitted();
 public:
     /**
      * @brief TBD
index e62b7a6..a437838 100644 (file)
@@ -225,6 +225,7 @@ private:
      */
     Size2D<int> mScreenSize;
     static std::mutex CaptureMutex;
+    static std::vector<std::shared_ptr<AccessibleNode>> mCachedNode;
 };
 
 }
index 81cdb20..77cfcb7 100644 (file)
@@ -44,6 +44,7 @@ std::chrono::system_clock::time_point AtspiAccessibleWatcher::mStartTime;
 IdleEventState AtspiAccessibleWatcher::isIdle = IdleEventState::IDLE_LISTEN_READY;
 static const unsigned int WAIT_FOR_IDLE_MILLI_SEC = 1000; // 1sec
 int AtspiAccessibleWatcher::mRenderCount = 10;
+bool AtspiAccessibleWatcher::isWindowEventEmitted = false;
 
 static bool iShowingNode(AtspiAccessible *node)
 {
@@ -284,6 +285,10 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher)
     {
         return;
     }
+
+    if (!strncmp(event->type, "w", 1))
+        isWindowEventEmitted = true;
+
     char *name = NULL, *pkg = NULL;
     AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)watcher;
     name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL);
@@ -584,3 +589,11 @@ void AtspiAccessibleWatcher::setXMLsync(bool sync)
         }
     }
 }
+
+bool AtspiAccessibleWatcher::getWindowEventEmitted()
+{
+    bool ret = isWindowEventEmitted;
+    isWindowEventEmitted = false;
+
+    return ret;
+}
index d08c76e..a3b2f61 100644 (file)
@@ -82,3 +82,8 @@ bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler
 void MockAccessibleWatcher::setXMLsync(bool sync)
 {
 }
+
+bool MockAccessibleWatcher::getWindowEventEmitted()
+{
+    return true;
+}
index 47fc3b6..cb06f34 100644 (file)
@@ -46,6 +46,7 @@ using namespace AurumInternal;
 
 std::mutex TizenDeviceImpl::CaptureMutex = std::mutex{};
 static GDBusConnection *system_conn;
+std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::mCachedNode;
 
 TizenDeviceImpl::TizenDeviceImpl()
 : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, tStart{}, isTimerStarted{false}, mTouchSeq{}
@@ -440,7 +441,12 @@ bool TizenDeviceImpl::releaseTouchSeqNumber(int seq)
 
 std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() const
 {
-    LOGI("Request window info");
+    if (!AccessibleWatcher::getInstance()->getWindowEventEmitted() && mCachedNode.size() > 0)
+    {
+        for (auto &win : mCachedNode)
+            LOGI("Cache hit pkg: (%s)", win->getPkg().c_str());
+        return mCachedNode;
+    }
 
     std::vector<std::shared_ptr<TizenWindow>> mTizenWindows{};
     getTizenWindowInfo(mTizenWindows);
@@ -480,6 +486,8 @@ std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() co
         pidToAppNode.erase(tWin->getPid());
     }
 
+    mCachedNode = ret;
+
     return ret;
 }