implement screenshot feature accepted/tizen/unified/20200729.165607 submit/tizen/20200728.225405
authorJaeun Choi <jaeun12.choi@samsung.com>
Wed, 6 May 2020 11:49:32 +0000 (20:49 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 28 Jul 2020 22:41:26 +0000 (07:41 +0900)
Change-Id: I9e7ffd96449ba6329994ad2d985c280dfe1f6449

libaurum/meson.build
libaurum/src/DeviceImpl/TizenImpl.cc
org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/Commands.h
org.tizen.aurum-bootstrap/inc/Commands/TakeScreenshotCommand.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc [new file with mode: 0644]
protocol/aurum.proto
protocol/examples/python/testFeatures.py

index e5e3584..c2e2eb8 100644 (file)
@@ -25,6 +25,8 @@ libaurum_src +=[
 endif
 
 libaurum_dep = [
+  dependency('capi-system-info'),
+  dependency('libtdm'),
   dependency('atspi-2'),
   dependency('gio-2.0'),
   dependency('threads'),
index fc9f057..7e469d7 100644 (file)
 #include <time.h>
 #include <Ecore.h>
 
+#include <tdm_helper.h>
+#include <tbm_surface.h>
+#include <system_info.h>
+
 TizenImpl::TizenImpl()
 : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, isTimerStarted{false}, mTouchSeq{}
 {
@@ -277,7 +281,27 @@ bool TizenImpl::releaseKeyCode(std::string keycode)
 
 bool TizenImpl::takeScreenshot(std::string path, float scale, int quality)
 {
-    return false;
+    efl_util_screenshot_h screenshot = NULL;
+    tbm_surface_h tbm_surface = NULL;
+
+    int width, height;
+    system_info_get_platform_int("http://tizen.org/feature/screen.width", &width);
+    system_info_get_platform_int("http://tizen.org/feature/screen.height", &height);
+
+    screenshot = efl_util_screenshot_initialize(width, height);
+
+    if (screenshot) {
+        tbm_surface = efl_util_screenshot_take_tbm_surface(screenshot);
+        if (tbm_surface) {
+            char path_cstr[PATH_MAX];
+            strcpy(path_cstr, path.c_str());
+            tdm_helper_dump_buffer(tbm_surface, path_cstr);
+            sync();
+        }
+        efl_util_screenshot_deinitialize(screenshot);
+    }
+
+    return true;
 }
 
 class Clock {
index 789c3fc..a44efe6 100644 (file)
@@ -86,6 +86,10 @@ public:
     ::grpc::Status sendKey(::grpc::ServerContext *context,
                            const ::aurum::ReqKey *request,
                            ::aurum::RspKey *      response) override;
+    ::grpc::Status takeScreenshot(
+        ::grpc::ServerContext *context,
+        const ::aurum::ReqTakeScreenshot *                 request,
+        ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer) override;
 };
 
-#endif
\ No newline at end of file
+#endif
index 7a5acd8..1999f95 100644 (file)
@@ -31,4 +31,5 @@
 #include "Commands/GetLocationCommand.h"
 #include "Commands/SendKeyCommand.h"
 
+#include "Commands/TakeScreenshotCommand.h"
 #endif
\ No newline at end of file
diff --git a/org.tizen.aurum-bootstrap/inc/Commands/TakeScreenshotCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/TakeScreenshotCommand.h
new file mode 100644 (file)
index 0000000..035fe38
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef TAKE_SCREENSHOT_COMMAND_H
+#define TAKE_SCREENSHOT_COMMAND_H
+
+#include <gio/gio.h>
+#include <grpcpp/grpcpp.h>
+#include "Commands/Command.h"
+#include "ObjectMapper.h"
+#include <aurum.grpc.pb.h>
+#include "config.h"
+
+class TakeScreenshotCommand : public Command {
+private:
+    const ::aurum::ReqTakeScreenshot*                  mRequest;
+    ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* mWriter;
+
+public:
+    TakeScreenshotCommand(const ::aurum::ReqTakeScreenshot*                  request,
+                          ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer);
+    ::grpc::Status execute() override;
+};
+
+#endif
index cf76b02..2661436 100644 (file)
@@ -35,6 +35,7 @@ bootstrap_svr_src += [
    files('src/Commands/TouchUpCommand.cc'),
    files('src/Commands/SyncCommand.cc'),
    files('src/Commands/KillServerCommand.cc'),
+   files('src/Commands/TakeScreenshotCommand.cc'),
    files('src/Commands/Command.cc'),
    files('src/Commands/PreCommand.cc'),
    files('src/Commands/PostCommand.cc'),
index ae7da19..74c3727 100644 (file)
@@ -181,3 +181,11 @@ aurumServiceImpl::~aurumServiceImpl() {}
     std::unique_ptr<SendKeyCommand> cmd = std::make_unique<SendKeyCommand>(request, response);
     return execute(cmd.get());
 }
+::grpc::Status aurumServiceImpl::takeScreenshot(
+    ::grpc::ServerContext* context,
+    const ::aurum::ReqTakeScreenshot*                  request,
+    ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer)
+{
+    std::unique_ptr<TakeScreenshotCommand> cmd = std::make_unique<TakeScreenshotCommand>(request, writer);
+    return execute(cmd.get());
+}
diff --git a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc
new file mode 100644 (file)
index 0000000..47eb9d0
--- /dev/null
@@ -0,0 +1,35 @@
+#include "TakeScreenshotCommand.h"
+#include <loguru.hpp>
+#include "UiObject.h"
+#include "UiDevice.h"
+#include <fstream>
+
+TakeScreenshotCommand::TakeScreenshotCommand(
+    const ::aurum::ReqTakeScreenshot*                  request,
+    ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer)
+    : mRequest{request}, mWriter{writer}
+{
+}
+
+::grpc::Status TakeScreenshotCommand::execute()
+{
+    LOG_SCOPE_F(INFO, "TakeScreenshot --------------- ");
+
+    std::string path = "/tmp/screenshot.png";
+    UiDevice* mDevice = UiDevice::getInstance(DeviceType::DEFAULT);
+    mDevice->takeScreenshot(path, 1.0, 1);
+
+    std::ifstream ifs(path, std::ifstream::binary);
+    ::aurum::RspTakeScreenshot rsp;
+    int size = 1024 * 1024;
+    char buf[size];
+
+    while (!ifs.eof()) {
+        ifs.read(buf, size);
+        rsp.set_image(buf, ifs.gcount());
+        mWriter->Write(rsp);
+    }
+    ifs.close();
+
+    return grpc::Status::OK;
+}
index 60b5e61..2eed21d 100644 (file)
@@ -28,6 +28,7 @@ service Bootstrap {
    rpc getDeviceTime(ReqGetDeviceTime) returns (RspGetDeviceTime) {}
    rpc getLocation(ReqGetLocation) returns (RspGetLocation) {}
    rpc sendKey(ReqKey) returns (RspKey) {}
+   rpc takeScreenshot(ReqTakeScreenshot) returns (stream RspTakeScreenshot) {}
 }
 
 // ------------------------------------ //
@@ -357,6 +358,12 @@ message RspKey{
    RspStatus status = 1;
 }
 
+message ReqTakeScreenshot{
+}
+message RspTakeScreenshot{
+   bytes image = 1;
+}
+
 // ------------------------------------ //
 
 message ReqEmpty {
index 39aeba3..a4d95e6 100644 (file)
@@ -269,6 +269,14 @@ def getLocationTest(stub):
     if response.lat < 0: return False
     return True
 
+def takeScreenshotTest(stub):
+    responses = stub.takeScreenshot(ReqTakeScreenshot())
+    image = open("screenshot.png", "wb")
+    for response in responses:
+        image.write(response.image)
+    image.close()
+    return True;
+
 def defaultSetup(stub):
     if stub.getAppInfo(ReqGetAppInfo(packageName='com.samsung.ui-widget-sample')).isRunning:
         stub.closeApp(ReqCloseApp(packageName='com.samsung.ui-widget-sample'))
@@ -310,6 +318,7 @@ def run():
         runTest(stub, touchTest)
         runTest(stub, sendKeyTest)
         runTest(stub, setValueClearTest)
+        runTest(stub, takeScreenshotTest)
         runTestWithoutSetupAndTearDown(stub, installAppTest)
         runTestWithoutSetupAndTearDown(stub, launchAppTest)
         runTestWithoutSetupAndTearDown(stub, getAppInfoTest)