libaurum: Add option to receive pixel data of screenshot image 87/290787/3
authorWoochan Lee <wc0917.lee@samsung.com>
Mon, 3 Apr 2023 07:56:07 +0000 (16:56 +0900)
committerWoochan Lee <wc0917.lee@samsung.com>
Mon, 3 Apr 2023 08:03:25 +0000 (17:03 +0900)
To provide past performance in case that pixel data is needed without stroing image

Remove unnecessary params such as scale, quality.

Change-Id: Ibc6db0b33375a8597b576ba410eb520126335ef5

libaurum/inc/Impl/MockDeviceImpl.h
libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/inc/Interface/IDevice.h
libaurum/inc/UiDevice.h
libaurum/src/Impl/MockDeviceImpl.cc
libaurum/src/Impl/TizenDeviceImpl.cc
libaurum/src/UiDevice.cc
org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc
protocol/aurum.proto

index e7ef2ce..4631912 100644 (file)
@@ -157,9 +157,9 @@ public:
 
     /**
      * @brief TBD
-     * @since_tizen 6.5
+     * @since_tizen 7.0
      */
-    bool takeScreenshot(std::string path, float scale, int quality) override;
+    bool takeScreenshot(std::string path, bool asPixels, void **pixels) override;
 
     /**
      * @brief TBD
index 1dd946c..774841c 100644 (file)
@@ -119,7 +119,7 @@ public:
     /**
      * @copydoc IDevice::takeScreenshot()
      */
-    bool takeScreenshot(std::string path, float scale, int quality) override;
+    bool takeScreenshot(std::string path, bool asPixels, void **pixels) override;
 
     /**
      * @copydoc IDevice::getSystemTime()
index 23058c6..e501b7e 100644 (file)
@@ -262,14 +262,14 @@ public:
      * @brief Take a screenshot of current window and store it as image file.
      *
      * @param[in] path where the image file should be written to
-     * @param[in] scale scale the screenshot down if needed; 1.0f for original size
-     * @param[in] quality quality of the PNG compression; range: 0-100
+     * @param[in] asPixels asPixels wheter to receive screen pixel data
+     * @param[in] pixels pixel pixel buffer data pointer
      *
      * @return true if screen shot is created successfully, false otherwise
      *
      * @since_tizen 6.5
      */
-    virtual bool takeScreenshot(std::string path, float scale, int quality) = 0;
+    virtual bool takeScreenshot(std::string path, bool asPixels, void **pixels) = 0;
 
     /**
      * @brief Gets device system time.
index 46a43f2..1c6a49b 100644 (file)
@@ -253,14 +253,14 @@ public:
      * @brief Take a screenshot of current window and store it as image file.
      *
      * @param[in] path where the image file should be written to
-     * @param[in] scale scale the screenshot down if needed; 1.0f for original size
-     * @param[in] quality quality of the PNG compression; range: 0-100
+     * @param[in] asPixels asPixels wheter to receive screen pixel data
+     * @param[in] pixels pixel pixel buffer data pointer
      *
      * @return true if screen shot is created successfully, false otherwise
      *
-     * @since_tizen 6.5
+     * @since_tizen 7.0
      */
-    bool takeScreenshot(std::string path, float scale, int quality) override;
+    bool takeScreenshot(std::string path, bool asPixels, void **pixels) override;
 
     /**
      * @brief Gets device system time.
index 4820f11..3d3ea8f 100644 (file)
@@ -195,7 +195,7 @@ bool MockDeviceImpl::repeatKeyCode(std::string keycode, int intervalMs, int dura
     return false;
 }
 
-bool MockDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
+bool MockDeviceImpl::takeScreenshot(std::string path, bool asPixels, void **pixels)
 {
     return true;
 }
index 819ec1b..273bd9c 100644 (file)
@@ -299,19 +299,40 @@ bool TizenDeviceImpl::releaseKeyCode(std::string keycode)
     return result == EFL_UTIL_ERROR_NONE;
 }
 
-bool TizenDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
+bool TizenDeviceImpl::takeScreenshot(std::string path, bool asPixels, void **pixels)
 {
     efl_util_screenshot_h screenshot = NULL;
     tbm_surface_h tbm_surface = NULL;
 
+    void *ptr = NULL;
+    const int WIDTH = mScreenSize.width;
+    const int HEIGHT = mScreenSize.height;
+
     CaptureMutex.lock();
-    screenshot = efl_util_screenshot_initialize(mScreenSize.width, mScreenSize.height);
+    screenshot = efl_util_screenshot_initialize(WIDTH, HEIGHT);
 
     if (screenshot) {
         tbm_surface = efl_util_screenshot_take_tbm_surface(screenshot);
         if (tbm_surface) {
-            tdm_helper_dump_buffer(tbm_surface, path.c_str());
-            sync();
+            if (asPixels) {
+                tbm_surface_info_s info;
+
+                unsigned char *src = NULL;
+                unsigned char *dst = NULL;
+                tbm_surface_map(tbm_surface, TBM_SURF_OPTION_READ, &info);
+
+                ptr = malloc( WIDTH * HEIGHT * 4 );
+                src = (unsigned char *)info.planes[0].ptr;
+                dst = (unsigned char *)ptr;
+
+                memcpy(dst, src, WIDTH * HEIGHT * 4);
+                *pixels = ptr;
+
+                tbm_surface_unmap(tbm_surface);
+            } else {
+                tdm_helper_dump_buffer(tbm_surface, path.c_str());
+                sync();
+            }
             tbm_surface_destroy(tbm_surface);
         } else {
             efl_util_screenshot_deinitialize(screenshot);
index e6e24fe..1cac2bb 100644 (file)
@@ -416,9 +416,9 @@ bool UiDevice::repeatKeyCode(std::string keycode, int intervalMs, int durationMs
     return result;
 }
 
-bool UiDevice::takeScreenshot(std::string path, float scale, int quality)
+bool UiDevice::takeScreenshot(std::string path, bool asPixels, void **pixels)
 {
-    return mDeviceImpl->takeScreenshot(path, scale, quality);
+    return mDeviceImpl->takeScreenshot(path, asPixels, pixels);
 }
 
 long long UiDevice::getSystemTime(TimeRequestType type)
@@ -469,4 +469,4 @@ bool UiDevice::getWithScreenAnalyzer()
 bool UiDevice::registerCallback(const A11yEvent type, EventHandler cb, void *data) const
 {
     return AccessibleWatcher::getInstance()->registerCallback(type, cb, data);
-}
\ No newline at end of file
+}
index 5825eef..a536684 100644 (file)
@@ -30,36 +30,51 @@ TakeScreenshotCommand::TakeScreenshotCommand(
 
 ::grpc::Status TakeScreenshotCommand::execute()
 {
-    LOGI("TakeScreenshot --------------- ");
+    LOGI("TakeScreenshot (getPixels : %d)--------------- ", mRequest->getpixels());
 
-    struct tm timeinfo;
-    time_t now = time(0);
-    if (!localtime_r(&now, &timeinfo)) {
-        LOGE("fail to get localtime. Screenshot cancelled");
-        return grpc::Status::CANCELLED;
-    }
+    if (!mRequest->getpixels()) {
+        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, false, NULL);
 
-    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;
+        const Size2D<int> screenSize = mDevice->getScreenSize();
+        int size = screenSize.width * screenSize.height;
+        char *buf = new char[size];
 
-    std::ifstream ifs(path, std::ifstream::binary);
-    ::aurum::RspTakeScreenshot rsp;
-    const Size2D<int> screenSize = mDevice->getScreenSize();
-    int size = screenSize.width * screenSize.height;
-    char *buf = new char[size];
+        while (!ifs.eof()) {
+            ifs.read(buf, size);
+            rsp.set_image(buf, ifs.gcount());
+            mWriter->Write(rsp);
+        }
+        ifs.close();
+        delete[] buf;
+    }
+    else {
+        void *pixels = NULL;
+        std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
+        mDevice->takeScreenshot("", true, &pixels);
+        ::aurum::RspTakeScreenshot rsp;
+        const Size2D<int> screenSize = mDevice->getScreenSize();
+        int size = screenSize.width * screenSize.height;
 
-    while (!ifs.eof()) {
-        ifs.read(buf, size);
-        rsp.set_image(buf, ifs.gcount());
+        rsp.set_image(pixels, size * 4);
         mWriter->Write(rsp);
+
+        free(pixels);
     }
-    ifs.close();
-    delete[] buf;
 
     return grpc::Status::OK;
 }
index 2f087d5..da7bee5 100644 (file)
@@ -549,6 +549,7 @@ message RspKey{
 }
 
 message ReqTakeScreenshot{
+   bool getPixels = 1;
 }
 message RspTakeScreenshot{
    bytes image = 1;