libaurum: Add cache when gets target windows 08/301308/2
authorWoochan Lee <wc0917.lee@samsung.com>
Mon, 30 Oct 2023 12:04:48 +0000 (21:04 +0900)
committerChun <jykeon@samsung.com>
Tue, 14 Nov 2023 02:19:25 +0000 (02:19 +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
(cherry picked from commit 39981eed22d6f4695eddd0a69950a31f9b0a4257)

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 dd026a4e5ffffcbd8d061d4863310f1f323047bf..e2f7c2b378691492c16a25b12bb70f3276ac0f69 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 e827d95189e5eb390c78816b395cfcbf0c2fb0f3..283882712a6f021b95f953f6bb6422480afe1003 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 cbfa21e66fea0dad7e322b928076236c658ee8c4..2cff4ae8057c7ba347aea7fc0ce1244bb41b0be3 100644 (file)
@@ -81,6 +81,7 @@ public:
 
     void setXMLsync(bool sync);
 
+    bool getWindowEventEmitted();
 public:
     /**
      * @brief TBD
index e62b7a6c027d6b879bd965fd8cc8fe3ae9db90da..a437838902b03d5d12a0ca7acca469b8384fdcb5 100644 (file)
@@ -225,6 +225,7 @@ private:
      */
     Size2D<int> mScreenSize;
     static std::mutex CaptureMutex;
+    static std::vector<std::shared_ptr<AccessibleNode>> mCachedNode;
 };
 
 }
index 81cdb20d1484316a7190eb7d7542086e376c9c9d..77cfcb734d4b2adc252e3edab7811d801c0fbac0 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 d08c76e0437be1884bd468fbbc8e5f5046a910b0..a3b2f613abd186f0967d5a3fdbbe7def61d1281e 100644 (file)
@@ -82,3 +82,8 @@ bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler
 void MockAccessibleWatcher::setXMLsync(bool sync)
 {
 }
+
+bool MockAccessibleWatcher::getWindowEventEmitted()
+{
+    return true;
+}
index 47fc3b6aa7e665742a5fbb176dc76bb06a0110f2..cb06f34cbdf31d58380c6be06f05479d0b3de5f1 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;
 }