To provide past performance in case that pixel data is needed without stroing image
Remove unnecessary params such as scale, quality.
Change-Id: Ibc6db0b33375a8597b576ba410eb520126335ef5
/**
* @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
/**
* @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()
* @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.
* @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.
return false;
}
-bool MockDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
+bool MockDeviceImpl::takeScreenshot(std::string path, bool asPixels, void **pixels)
{
return true;
}
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);
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)
bool UiDevice::registerCallback(const A11yEvent type, EventHandler cb, void *data) const
{
return AccessibleWatcher::getInstance()->registerCallback(type, cb, data);
-}
\ No newline at end of file
+}
::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;
}
}
message ReqTakeScreenshot{
+ bool getPixels = 1;
}
message RspTakeScreenshot{
bytes image = 1;