aurum: Add screen size getter and fix screen capture file naming rule 97/263797/6
authorWoochanlee <wc0917.lee@samsung.com>
Fri, 10 Sep 2021 07:17:25 +0000 (16:17 +0900)
committerWoochanlee <wc0917.lee@samsung.com>
Thu, 30 Sep 2021 02:08:01 +0000 (11:08 +0900)
gets screen size from system API.
puts system date time for screenshot file name.

Change-Id: I9a2ad8ebefd8f09421b2cb0de70ea0167d6feba3

libaurum/inc/Aurum.h
libaurum/inc/Impl/MockDeviceImpl.h
libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/inc/Interface/IDevice.h
libaurum/inc/Misc/Size2D.h [new file with mode: 0644]
libaurum/inc/UiDevice.h
libaurum/meson.build
libaurum/src/Impl/MockDeviceImpl.cc
libaurum/src/Impl/TizenDeviceImpl.cc
libaurum/src/UiDevice.cc
org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc

index ae9a89ec170ba84963e0b5800220403e61379da9..afa55681c91a324fd6188ea2938cdf00dd20533b 100644 (file)
@@ -36,6 +36,7 @@
 #include "IDevice.h"
 #include "Accessible.h"
 #include "Point2D.h"
+#include "Size2D.h"
 #include "Rect.h"
 #include "PartialMatch.h"
 #include "Comparer.h"
index b2cd9f1ba35661a22ddb0f01233ee1be45000ac6..9c0968c5726aac6fca9317a18315d7533ad0694c 100644 (file)
@@ -137,6 +137,12 @@ public:
      */
     long long getSystemTime(TimeRequestType type) override;
 
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    const Size2D<int> getScreenSize() override;
+
 protected:
     /**
      * @brief TBD
@@ -263,4 +269,9 @@ public:
      * @brief TBD
      */
     int mWheelDevice;
+
+    /**
+     * @brief TBD
+     */
+    Size2D<int> mScreenSize;
 };
\ No newline at end of file
index 79db52ce61d7dcbd39bf7f20dda9a703dfa87146..8245332a93c125224d23d2ca9ccce2faa7e029da 100644 (file)
@@ -98,6 +98,15 @@ public:
      */
     long long getSystemTime(TimeRequestType type) override;
 
+    /**
+     * @brief Gets device screen size.
+     *
+     * @return @Size2D
+     *
+     * @since_tizen 6.5
+     */
+    const Size2D<int> getScreenSize() override;
+
 protected:
     /**
      * @brief Press and release given key during duration time.
@@ -164,4 +173,9 @@ private:
     struct timespec tStart;
     bool isTimerStarted;
     std::set<int> mTouchSeq;
+
+    /**
+     * @brief TBD
+     */
+    Size2D<int> mScreenSize;
 };
\ No newline at end of file
index ab8a058e98f39ac8dc382b7056a70f9eb8ab84cd..8affc507e8cc7a207ebbb7c901f379f472ab2de9 100644 (file)
@@ -1,7 +1,8 @@
 #pragma once
 
 #include "config.h"
-
+#include "Rect.h"
+#include "Size2D.h"
 #include <string>
 
 /**
@@ -247,4 +248,13 @@ public:
      * @since_tizen 5.5
      */
     virtual long long getSystemTime(TimeRequestType type) = 0;
+
+    /**
+     * @brief Gets device screen size.
+     *
+     * @return @Size2D
+     *
+     * @since_tizen 6.5
+     */
+    virtual const Size2D<int> getScreenSize() = 0;
 };
\ No newline at end of file
diff --git a/libaurum/inc/Misc/Size2D.h b/libaurum/inc/Misc/Size2D.h
new file mode 100644 (file)
index 0000000..746f47f
--- /dev/null
@@ -0,0 +1,63 @@
+#pragma once
+
+/**
+ * @brief Size2D Class.
+ *        This class for represent specific obejct's size as width and height.
+ *
+ * @since_tizen 6.5
+ */
+template <typename T>
+class Size2D {
+public:
+    /**
+     * @brief Size2D contructor with value.
+     *
+     * @since_tizen 6.5
+     */
+    Size2D() : width{0}, height{0} {}
+
+    /**
+     * @brief Size2D contructor with source.
+     *
+     * @since_tizen 6.5
+     */
+    Size2D(const Size2D &src)
+    {
+        width = src.width;
+        height = src.height;
+    }
+
+    /**
+     * @brief Size2D contructor with type.
+     *
+     * @since_tizen 6.5
+     */
+    Size2D(const T &width, const T &height)
+    {
+        this->width = width;
+        this->height = height;
+    }
+
+    /**
+     * @brief Size2D operator for "==".
+     *
+     * @since_tizen 6.5
+     */
+    inline bool operator==(const Size2D<T>& rhs)
+    {
+        return this->width == rhs.width && this->height == rhs.height;
+    }
+
+    /**
+     * @brief Size2D operator for "!=".
+     *
+     * @since_tizen 6.5
+     */
+    inline bool operator!=(const Size2D<T>& rhs)
+    {
+        return !(*this == rhs);
+    }
+
+    T width;
+    T height;
+};
index ac2e642549dd9a751d991244a6fe6fbf0c4f7b5b..132f4cb29336373438087f95ea741863f5bee08f 100644 (file)
@@ -234,6 +234,14 @@ public:
      */
     long long getSystemTime(TimeRequestType type) override;
 
+    /**
+     * @brief Gets device screen size.
+     *
+     * @return @Size2D
+     *
+     * @since_tizen 6.5
+     */
+    const Size2D<int> getScreenSize() override;
 public:
 
     /**
index d55c9ee57ab26d69970de8da54e97c3184da5f74..82deeeee3377a003cccf938ce55ac0f0dd7a41f9 100644 (file)
@@ -15,6 +15,7 @@ libaurum_install_inc = [
   './inc/Misc/bitmask.h',
   './inc/Misc/Point2D.h',
   './inc/Misc/Rect.h',
+  './inc/Misc/Size2D.h',
   './inc/Aurum.h',
 ]
 
index 2170536b304bfa3cceb994e2b9fbf405ca6d7eab..8a4ce23b50c7fadaa84c5e6ff1bf8f7453caf1ff 100644 (file)
@@ -1,3 +1,5 @@
+#include "Aurum.h"
+
 #include "MockDeviceImpl.h"
 
 #include <functional>
@@ -186,6 +188,11 @@ long long MockDeviceImpl::getSystemTime(TimeRequestType type)
     return (long long)t.tv_sec * 1000L + (long long)(t.tv_nsec / MICRO_SEC);
 }
 
+const Size2D<int> MockDeviceImpl::getScreenSize()
+{
+    return mScreenSize;
+}
+
 bool MockDeviceImpl::strokeKeyCode(std::string keycode, unsigned int intv)
 {
     return false;
index 101cf06d5f2d265b8780a42238f9c6fa4d22382e..96846e1705e54ef093705c76e4f33d7b4e90971c 100644 (file)
@@ -26,6 +26,13 @@ TizenDeviceImpl::TizenDeviceImpl()
     obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN);
     obj->mFakeKeyboardHandle =
        efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD);
+
+    int width = 0;
+    int height = 0;
+    system_info_get_platform_int("http://tizen.org/feature/screen.width", &width);
+    system_info_get_platform_int("http://tizen.org/feature/screen.height", &height);
+
+    mScreenSize = Size2D<int>{width, height};
 }
 
 TizenDeviceImpl::~TizenDeviceImpl()
@@ -248,12 +255,7 @@ bool TizenDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
     efl_util_screenshot_h screenshot = NULL;
     tbm_surface_h tbm_surface = NULL;
 
-    int width = 0, height = 0;
-    if (system_info_get_platform_int("http://tizen.org/feature/screen.width", &width) ||
-        system_info_get_platform_int("http://tizen.org/feature/screen.height", &height))
-        return false;
-
-    screenshot = efl_util_screenshot_initialize(width, height);
+    screenshot = efl_util_screenshot_initialize(mScreenSize.width, mScreenSize.height);
 
     if (screenshot) {
         tbm_surface = efl_util_screenshot_take_tbm_surface(screenshot);
@@ -319,6 +321,12 @@ long long TizenDeviceImpl::getSystemTime(TimeRequestType type)
 
 }
 
+const Size2D<int> TizenDeviceImpl::getScreenSize()
+{
+    TizenDeviceImpl *obj = static_cast<TizenDeviceImpl *>(this);
+    return obj->mScreenSize;
+}
+
 int TizenDeviceImpl::grabTouchSeqNumber()
 {
     for (unsigned int i = 0 ; i < MAX_FINGER_NUMBER; i++) {
index 2fdeb2ec6839733a2468be9b3faf0db1aac616f4..644d5807e9c9170df64c95d5aadf5a33401bbb0e 100644 (file)
@@ -254,3 +254,8 @@ long long UiDevice::getSystemTime(TimeRequestType type)
 {
     return mDeviceImpl->getSystemTime(type);
 }
+
+const Size2D<int> UiDevice::getScreenSize()
+{
+    return mDeviceImpl->getScreenSize();
+}
index e3cc296584f99a249623bcd1cd463b02f18962bd..a34b3525d0c48c071baa7dc54fbff25042043f41 100644 (file)
@@ -15,13 +15,24 @@ TakeScreenshotCommand::TakeScreenshotCommand(
 {
     LOGI("TakeScreenshot --------------- ");
 
-    std::string path = "/tmp/screenshot.png";
+    struct tm timeinfo;
+    time_t now = time(0);
+    if (!localtime_r(&now, &timeinfo)) {
+        LOGE("fail to get localtime. Screenshot cancelled");
+        return grpc::Status::CANCELLED;
+    }
+
+    char name[128];
+    std::snprintf(name, 128, "/tmp/screenshot-%d-%d-%d-%d:%d:%d.png",
+                              (timeinfo.tm_year + 1900), (timeinfo.tm_mon + 1), timeinfo.tm_mday,
+                              timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
+    std::string path(name);
     std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
     mDevice->takeScreenshot(path, 1.0, 1);
 
     std::ifstream ifs(path, std::ifstream::binary);
     ::aurum::RspTakeScreenshot rsp;
-    int size = 1920 * 1080;
+    int size = mDevice->getScreenSize().width * mDevice->getScreenSize().height;
     char buf[size];
 
     while (!ifs.eof()) {