From: Woochanlee Date: Fri, 10 Sep 2021 07:17:25 +0000 (+0900) Subject: aurum: Add screen size getter and fix screen capture file naming rule X-Git-Tag: submit/tizen/20211007.062212~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F97%2F263797%2F6;p=platform%2Fcore%2Fuifw%2Faurum.git aurum: Add screen size getter and fix screen capture file naming rule gets screen size from system API. puts system date time for screenshot file name. Change-Id: I9a2ad8ebefd8f09421b2cb0de70ea0167d6feba3 --- diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index ae9a89e..afa5568 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -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" diff --git a/libaurum/inc/Impl/MockDeviceImpl.h b/libaurum/inc/Impl/MockDeviceImpl.h index b2cd9f1..9c0968c 100644 --- a/libaurum/inc/Impl/MockDeviceImpl.h +++ b/libaurum/inc/Impl/MockDeviceImpl.h @@ -137,6 +137,12 @@ public: */ long long getSystemTime(TimeRequestType type) override; + /** + * @brief TBD + * @since_tizen 6.5 + */ + const Size2D getScreenSize() override; + protected: /** * @brief TBD @@ -263,4 +269,9 @@ public: * @brief TBD */ int mWheelDevice; + + /** + * @brief TBD + */ + Size2D mScreenSize; }; \ No newline at end of file diff --git a/libaurum/inc/Impl/TizenDeviceImpl.h b/libaurum/inc/Impl/TizenDeviceImpl.h index 79db52c..8245332 100644 --- a/libaurum/inc/Impl/TizenDeviceImpl.h +++ b/libaurum/inc/Impl/TizenDeviceImpl.h @@ -98,6 +98,15 @@ public: */ long long getSystemTime(TimeRequestType type) override; + /** + * @brief Gets device screen size. + * + * @return @Size2D + * + * @since_tizen 6.5 + */ + const Size2D getScreenSize() override; + protected: /** * @brief Press and release given key during duration time. @@ -164,4 +173,9 @@ private: struct timespec tStart; bool isTimerStarted; std::set mTouchSeq; + + /** + * @brief TBD + */ + Size2D mScreenSize; }; \ No newline at end of file diff --git a/libaurum/inc/Interface/IDevice.h b/libaurum/inc/Interface/IDevice.h index ab8a058..8affc50 100644 --- a/libaurum/inc/Interface/IDevice.h +++ b/libaurum/inc/Interface/IDevice.h @@ -1,7 +1,8 @@ #pragma once #include "config.h" - +#include "Rect.h" +#include "Size2D.h" #include /** @@ -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 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 index 0000000..746f47f --- /dev/null +++ b/libaurum/inc/Misc/Size2D.h @@ -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 +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& rhs) + { + return this->width == rhs.width && this->height == rhs.height; + } + + /** + * @brief Size2D operator for "!=". + * + * @since_tizen 6.5 + */ + inline bool operator!=(const Size2D& rhs) + { + return !(*this == rhs); + } + + T width; + T height; +}; diff --git a/libaurum/inc/UiDevice.h b/libaurum/inc/UiDevice.h index ac2e642..132f4cb 100644 --- a/libaurum/inc/UiDevice.h +++ b/libaurum/inc/UiDevice.h @@ -234,6 +234,14 @@ public: */ long long getSystemTime(TimeRequestType type) override; + /** + * @brief Gets device screen size. + * + * @return @Size2D + * + * @since_tizen 6.5 + */ + const Size2D getScreenSize() override; public: /** diff --git a/libaurum/meson.build b/libaurum/meson.build index d55c9ee..82deeee 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -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', ] diff --git a/libaurum/src/Impl/MockDeviceImpl.cc b/libaurum/src/Impl/MockDeviceImpl.cc index 2170536..8a4ce23 100644 --- a/libaurum/src/Impl/MockDeviceImpl.cc +++ b/libaurum/src/Impl/MockDeviceImpl.cc @@ -1,3 +1,5 @@ +#include "Aurum.h" + #include "MockDeviceImpl.h" #include @@ -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 MockDeviceImpl::getScreenSize() +{ + return mScreenSize; +} + bool MockDeviceImpl::strokeKeyCode(std::string keycode, unsigned int intv) { return false; diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index 101cf06..96846e1 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -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{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 TizenDeviceImpl::getScreenSize() +{ + TizenDeviceImpl *obj = static_cast(this); + return obj->mScreenSize; +} + int TizenDeviceImpl::grabTouchSeqNumber() { for (unsigned int i = 0 ; i < MAX_FINGER_NUMBER; i++) { diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index 2fdeb2e..644d580 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -254,3 +254,8 @@ long long UiDevice::getSystemTime(TimeRequestType type) { return mDeviceImpl->getSystemTime(type); } + +const Size2D UiDevice::getScreenSize() +{ + return mDeviceImpl->getScreenSize(); +} diff --git a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc index e3cc296..a34b352 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc @@ -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 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()) {