From: mk5004.lee Date: Tue, 11 Feb 2020 11:00:13 +0000 (+0900) Subject: Update ambient-viewer func implementation X-Git-Tag: accepted/tizen/unified/20200302.125805~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F224553%2F13;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Update ambient-viewer func implementation - monitor/unmonitor stub Change-Id: I7d9d1ec0608f6eea891f834d115aea02055b732c Signed-off-by: mk5004.lee Signed-off-by: Inkyun Kil --- diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 86bbc61..8839756 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,9 @@ ADD_SUBDIRECTORY(frame-broker) ADD_SUBDIRECTORY(frame-provider) ADD_SUBDIRECTORY(ambient-viewer) ADD_SUBDIRECTORY(tool) -ADD_SUBDIRECTORY(unittest) +#ADD_SUBDIRECTORY(unittest) -ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas) +#ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas) ADD_DEPENDENCIES(widget_viewer_sdk widget_viewer_evas) ADD_DEPENDENCIES(widget_viewer_sdk watch-holder) diff --git a/ambient-viewer/CMakeLists.txt b/ambient-viewer/CMakeLists.txt index 5bd5b44..00a2613 100644 --- a/ambient-viewer/CMakeLists.txt +++ b/ambient-viewer/CMakeLists.txt @@ -43,3 +43,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/ambient_viewer.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/ambient_viewer_surface.h DESTINATION include/${PROJECT_NAME}) +#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION include/${PROJECT_NAME} +# FILES_MATCHING PATTERN "*.h") +#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src DESTINATION include/${PROJECT_NAME} +# FILES_MATCHING PATTERN "*.h") diff --git a/ambient-viewer/ambient-viewer.pc.in b/ambient-viewer/ambient-viewer.pc.in index c775d15..be7378b 100644 --- a/ambient-viewer/ambient-viewer.pc.in +++ b/ambient-viewer/ambient-viewer.pc.in @@ -6,7 +6,7 @@ includedir=@INCLUDEDIR@ Name: ui_app_ambient_viewer Description: Support development of the ambient viewer Version: @VERSION@ -Libs: -L${libdir} -lambient_viewer +Libs: -L${libdir} -lambient-viewer Cflags: -I${includedir} cppflags: -I${includedir} diff --git a/ambient-viewer/include/ambient_viewer.h b/ambient-viewer/include/ambient_viewer.h old mode 100755 new mode 100644 index 32f9b98..a5c283b --- a/ambient-viewer/include/ambient_viewer.h +++ b/ambient-viewer/include/ambient_viewer.h @@ -39,14 +39,15 @@ extern "C" { typedef void *ambient_viewer_h; typedef enum { + AMBIENT_VIEWER_EVENT_AOD_PREPARE, AMBIENT_VIEWER_EVENT_AOD_READY, AMBIENT_VIEWER_EVENT_WATCH_CHANGED, } ambient_event_type_e; typedef enum { - AMBIENT_VIEWER_DIRECTION_WATCH, - AMBIENT_VIEWER_DIRECTION_TOP_APP, - AMBIENT_VIEWER_DIRECTION_BOTH, + AMBIENT_VIEWER_DIRECTION_VIEWER_AND_WATCH, + AMBIENT_VIEWER_DIRECTION_VIEWER_TOP_APP, + AMBIENT_VIEWER_DIRECTION_ALL, } ambient_viewer_direction_e; typedef void (*ambient_viewer_lifecycle_added_cb)( @@ -60,7 +61,7 @@ typedef void (*ambient_viewer_lifecycle_updated_cb)( typedef struct _ambient_viewer_lifecycle{ ambient_viewer_lifecycle_added_cb added; - ambient_viewer_lifecycle_removed_cb deleted; + ambient_viewer_lifecycle_removed_cb removed; ambient_viewer_lifecycle_updated_cb updated; } ambient_viewer_lifecycle_s; diff --git a/ambient-viewer/include/ambient_viewer_common.h b/ambient-viewer/include/ambient_viewer_common.h old mode 100755 new mode 100644 index 0208df7..850a950 --- a/ambient-viewer/include/ambient_viewer_common.h +++ b/ambient-viewer/include/ambient_viewer_common.h @@ -29,6 +29,20 @@ extern "C" { #endif +/** + * @brief Enumeration for ambient_viewer error. + * @since_tizen 5.5 + */ + +typedef enum _ambient_viewer_error { + AMBIENT_VIEWER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Success */ + AMBIENT_VIEWER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + AMBIENT_VIEWER_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /** #include "ambient-viewer.h" +#include "top-app-surface.h" +#include "watch-surface.h" namespace ambient_viewer { -AmbientViewer::AmbientViewer() { +AmbientViewer::AmbientViewer(std::shared_ptr win) + : win_(win) { } AmbientViewer::~AmbientViewer() = default; void AmbientViewer::Monitor() { + //top_app_surface_listener_ = new IAmbientViewer; + //watch_surface_listener_ = new Event; + + //top_app_surface_ = std::make_shared(win_, top_app_surface_listener_); + //To do + //WatchSurface got error, need to check + //watch_surface_ = std::make_shared(win_, watch_surface_listener_); } void AmbientViewer::Unmonitor() { + top_app_surface_.reset(); + //watch_surface_.reset(); } void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender, @@ -37,32 +49,17 @@ void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender, int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir, bundle* extra) { - /* - bundle* b = bundle_create(); - bundle_raw* raw; - int len; - - //watch - - //top app - - //both - - bundle_add_byte(b, "enter", enter); - bundle_encode(extra, &raw, &len); - bundle_add_str(b, "extra", raw); - aul_app_com_send("endpoint", b); - */ - return 0; } + const ISurface& AmbientViewer::GetWatchSurface() const { return *watch_surface_; } const ISurface& AmbientViewer::GetTopAppSurface() const { - return *app_surface_; + return *top_app_surface_; } + } // namespace ambient_viewer diff --git a/ambient-viewer/src/ambient-viewer.h b/ambient-viewer/src/ambient-viewer.h old mode 100755 new mode 100644 index 131a189..48adc80 --- a/ambient-viewer/src/ambient-viewer.h +++ b/ambient-viewer/src/ambient-viewer.h @@ -22,6 +22,7 @@ #include #include +#include "iambient-viewer.h" #include "isurface.h" #ifndef EXPORT_API @@ -30,7 +31,7 @@ namespace ambient_viewer { -class EXPORT_API AmbientViewer { +class EXPORT_API AmbientViewer : public IAmbientViewer { public: enum EventType { EVENT_AOD_PREPARE, @@ -45,14 +46,7 @@ class EXPORT_API AmbientViewer { }; public: - class IEvent { - public: - virtual void OnAdded(const ISurface& surface) = 0; - virtual void OnUpdated(const ISurface& surface) = 0; - virtual void OnRemoved(const ISurface& surface) = 0; - }; - - AmbientViewer(); + AmbientViewer(std::shared_ptr win); virtual ~AmbientViewer(); void Monitor(); void Unmonitor(); @@ -62,8 +56,9 @@ class EXPORT_API AmbientViewer { const ISurface& GetTopAppSurface() const; private: + std::shared_ptr win_; std::shared_ptr watch_surface_; - std::shared_ptr app_surface_; + std::shared_ptr top_app_surface_; }; } // namespace ambient_viewer diff --git a/ambient-viewer/src/iambient-viewer.h b/ambient-viewer/src/iambient-viewer.h new file mode 100644 index 0000000..04c3e79 --- /dev/null +++ b/ambient-viewer/src/iambient-viewer.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __AMBIENT_VIEWER_IAMBIENTVIEWER_H__ +#define __AMBIENT_VIEWER_IAMBIENTVIEWER_H__ + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +#include + +#include "isurface.h" + +namespace ambient_viewer { + +class EXPORT_API IAmbientViewer { + public: + virtual ~IAmbientViewer() = default; + virtual void OnAdded(const ISurface& surface) = 0; + virtual void OnUpdated(const ISurface& surface) = 0; + virtual void OnRemoved(const ISurface& surface) = 0; +}; + +} //namespace ambient_viewer + +#endif // __AMBIENT_VIEWER_IAMBIENTVIEWER_H__ diff --git a/ambient-viewer/src/internal.cc b/ambient-viewer/src/internal.cc new file mode 100644 index 0000000..a986620 --- /dev/null +++ b/ambient-viewer/src/internal.cc @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "internal.h" + +#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle" + +namespace ambient_viewer::internal { + +float _GetOpr(void* source_data, int width, int height) { + int *source; + int x; + int y; + int idx; + int max_rad; + int rad; + int pos; + unsigned int r = 0; + unsigned int g = 0; + unsigned int b = 0; + unsigned int pixel_sum; + float opr; + float max_opr; + bool shape_circle = false; + + system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);; + + source = static_cast(source_data); + pos = width / 2; + max_rad = (height * height) >> 2; + + for (y = 0; y < height; ++y) { + for (x = 0; x < width; ++x) { + if (shape_circle) { + rad = (pos - x) * (pos - x) + (pos - y) * (pos - y); + if (rad <= max_rad) { + idx = y * width + x; + r += ((source[idx] & 0x00ff0000) >> 16); + g += ((source[idx] & 0x0000ff00) >> 8); + b += (source[idx] & 0x000000ff); + } + } else { + idx = y * width + x; + r += ((source[idx] & 0x00ff0000) >> 16); + g += ((source[idx] & 0x0000ff00) >> 8); + b += (source[idx] & 0x000000ff); + } + } + } + + if (shape_circle) + max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255; + else + max_opr = width * height * 3 * 255; + + pixel_sum = r + g + b; + opr = ((float)pixel_sum) / max_opr; + + return opr; +} + +} // namespace ambient_viewer::internal diff --git a/ambient-viewer/src/internal.h b/ambient-viewer/src/internal.h new file mode 100644 index 0000000..a0c2259 --- /dev/null +++ b/ambient-viewer/src/internal.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __AMBIENT_VIEWER_INTERNAL_H__ +#define __AMBIENT_VIEWER_INTERNAL_H__ + +namespace ambient_viewer::internal { + + float _GetOpr(void* source_data, int width, int height); + +} // namespace ambient_viewer::internal + +#endif // __AMBIENT_VIEWER_INTERNAL_H__ + + + diff --git a/ambient-viewer/src/isurface.h b/ambient-viewer/src/isurface.h index 850105b..5d940f2 100644 --- a/ambient-viewer/src/isurface.h +++ b/ambient-viewer/src/isurface.h @@ -38,4 +38,5 @@ class EXPORT_API ISurface { }; } //namespace ambient_viewer + #endif // __AMBIENT_VIEWER_ISURFACE_H__ diff --git a/ambient-viewer/src/stub.cc b/ambient-viewer/src/stub.cc old mode 100755 new mode 100644 index f64e6a8..8e0f2b5 --- a/ambient-viewer/src/stub.cc +++ b/ambient-viewer/src/stub.cc @@ -14,112 +14,337 @@ * limitations under the License. */ +#include +#include #include "ambient_viewer.h" #include "ambient_viewer_surface.h" #include "ambient_viewer_common.h" #include "ambient-viewer.h" +#include "isurface.h" -namespace ambient_viewer { +using namespace std; +using namespace ambient_viewer; +using namespace screen_connector; -class AmbientViewerStub : public AmbientViewer { +class MonitorCallbackInfo { public: - AmbientViewerStub() - : AmbientViewer() { + MonitorCallbackInfo(ambient_viewer_lifecycle_s cb, void* user_data) + : user_data_(user_data) { + cb_.added = cb.added; + cb_.updated = cb.updated; + cb_.removed = cb.removed; + } + + void InvokeAdded(const ISurface& surface) { + if (cb_.added) + cb_.added(static_cast(&surface), user_data_); } + + void InvokeUpdated(const ISurface& surface) { + if (cb_.updated) + cb_.updated(static_cast(&surface), user_data_); + } + + void InvokeRemoved(const ISurface& surface) { + if (cb_.removed) + cb_.removed(static_cast(&surface), user_data_); + } + + private: + ambient_viewer_lifecycle_s cb_; + void* user_data_; }; -} // namespace ambient_viewer +class EventCallbackInfo { + public: + EventCallbackInfo(ambient_viewer_event_cb cb, void* user_data) + : cb_(cb), user_data_(user_data) { + } + + void InvokeEventCallback(AmbientViewer::EventType event, std::string sender, + bundle *extra) { + cb_(static_cast(event), sender.c_str(), extra, + user_data_); + } + + private: + ambient_viewer_event_cb cb_; + void* user_data_; +}; + +class AmbientViewerStub : public AmbientViewer { + public: + AmbientViewerStub(std::shared_ptr win) + : AmbientViewer(win) { + } + + void OnAdded(const ISurface& surface) { + monitor_cb_->InvokeAdded(surface); + } + + void OnUpdated(const ISurface& surface) { + monitor_cb_->InvokeUpdated(surface); + } + + void OnRemoved(const ISurface& surface) { + monitor_cb_->InvokeRemoved(surface); + } + + void OnEvent(EventType ev, string sender, bundle* extra) { + event_cb_->InvokeEventCallback(ev, sender, extra); + } + + int SetMonitorCallbackInfo(unique_ptr info) { + monitor_cb_ = move(info); + return AMBIENT_VIEWER_ERROR_NONE; + } + + int ClearMonitorCallbackInfo() { + monitor_cb_.reset(); + return AMBIENT_VIEWER_ERROR_NONE; + } + + int SetEventCallbackInfo (unique_ptr info) { + event_cb_ = move(info); + return AMBIENT_VIEWER_ERROR_NONE; + } + + int ClearEventCallbackInfo() { + event_cb_.reset(); + return AMBIENT_VIEWER_ERROR_NONE; + } + + private: + unique_ptr monitor_cb_; + unique_ptr event_cb_; +}; extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win, ambient_viewer_h *handle) { - ambient_viewer_h ambient_viewer = NULL; + if (win == nullptr || handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } - *handle = ambient_viewer; + AmbientViewerStub* h = new (std::nothrow) AmbientViewerStub( + shared_ptr(new EvasObject(win, false))); + if (h == nullptr) { + LOGE("out of memory"); + return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY; + } + + *handle = static_cast(h); - return 0; + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_destroy(ambient_viewer_h handle) { - free (handle); + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } - return 0; + AmbientViewerStub* stub = static_cast(handle); + delete stub; + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_notify_ambient_event( ambient_viewer_h handle, bool enter, ambient_viewer_direction_e dir, bundle *extra) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + stub->NotifyAmbientEvent(enter, static_cast(dir), extra); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_monitor(ambient_viewer_h handle, ambient_viewer_lifecycle_s lifecycle, void *user_data) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + + unique_ptr info ( + new (nothrow)MonitorCallbackInfo(lifecycle, user_data)); + if (info.get() == nullptr) { + LOGE("out of memory"); + return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY; + } + + stub->SetMonitorCallbackInfo(move(info)); + stub->Monitor(); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_unmonitor(ambient_viewer_h handle) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + stub->ClearMonitorCallbackInfo(); + stub->Unmonitor(); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_set_event_listener( ambient_viewer_h handle, ambient_viewer_event_cb callback, void *user_data) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + + unique_ptr info ( + new (nothrow)EventCallbackInfo(callback, user_data)); + if (info.get() == nullptr) { + LOGE("out of memory"); + return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY; + } + + stub->SetEventCallbackInfo(move(info)); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_unset_event_listener( ambient_viewer_h handle) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + stub->ClearEventCallbackInfo(); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_get_watch_surface( ambient_viewer_h handle, ambient_viewer_surface_h *surface) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + *surface = static_cast(&(stub->GetWatchSurface())); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_get_top_app_surface( ambient_viewer_h handle, ambient_viewer_surface_h *surface) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + AmbientViewerStub* stub = static_cast(handle); + *surface = static_cast(&(stub->GetTopAppSurface())); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_surface_get_cur_image( - ambient_viewer_surface_h handle, Evas_Object *image) + ambient_viewer_surface_h handle, Evas_Object **image) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + const ISurface* surface = static_cast(handle); + *image = surface->GetCurrentImage().GetRaw(); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_surface_is_watch( ambient_viewer_surface_h handle, bool *is_watch) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + const ISurface* surface = static_cast(handle); + *is_watch = surface->IsWatch(); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_surface_get_app_id( ambient_viewer_surface_h handle, char **app_id) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + const ISurface* surface = static_cast(handle); + if (surface->GetAppId().empty()) + *app_id = nullptr; + else + *app_id = strdup(surface->GetAppId().c_str()); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_surface_get_inst_id( ambient_viewer_surface_h handle, char **inst_id) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + const ISurface* surface = static_cast(handle); + if (surface->GetInstId().empty()) + *inst_id = nullptr; + else + *inst_id = strdup(surface->GetInstId().c_str()); + + return AMBIENT_VIEWER_ERROR_NONE; } extern "C" EXPORT_API int ambient_viewer_surface_get_opr( ambient_viewer_surface_h handle, float *opr) { - return 0; + if (handle == nullptr) { + LOGE("Invalid parameter"); + return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; + } + + const ISurface* surface = static_cast(handle); + *opr = surface->GetOpr(); + + return AMBIENT_VIEWER_ERROR_NONE; } diff --git a/ambient-viewer/src/top-app-surface.cc b/ambient-viewer/src/top-app-surface.cc index f39dc76..825b289 100644 --- a/ambient-viewer/src/top-app-surface.cc +++ b/ambient-viewer/src/top-app-surface.cc @@ -14,17 +14,17 @@ * limitations under the License. */ -#include #include "top-app-surface.h" +#include "internal.h" -#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle" +using namespace ambient_viewer::internal; namespace ambient_viewer { TopAppSurface::TopAppSurface( std::shared_ptr surface, - AmbientViewer::IEvent* listener) + IAmbientViewer* listener) : RemoteSurfaceWatcher(screen_connector::RemoteSurface::Type::UI, surface), listener_(listener) { } @@ -47,58 +47,6 @@ std::string TopAppSurface::GetInstId() const { return inst_id_; } -static float _GetOpr(void* source_data, int width, int height) { - int *source; - int x; - int y; - int idx; - int max_rad; - int rad; - int pos; - unsigned int r = 0; - unsigned int g = 0; - unsigned int b = 0; - unsigned int pixel_sum; - float opr; - float max_opr; - bool shape_circle = false; - - system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);; - - source = static_cast(source_data); - pos = width / 2; - max_rad = (height * height) >> 2; - - for (y = 0; y < height; ++y) { - for (x = 0; x < width; ++x) { - if (shape_circle) { - rad = (pos - x) * (pos - x) + (pos - y) * (pos - y); - if (rad <= max_rad) { - idx = y * width + x; - r += ((source[idx] & 0x00ff0000) >> 16); - g += ((source[idx] & 0x0000ff00) >> 8); - b += (source[idx] & 0x000000ff); - } - } else { - idx = y * width + x; - r += ((source[idx] & 0x00ff0000) >> 16); - g += ((source[idx] & 0x0000ff00) >> 8); - b += (source[idx] & 0x000000ff); - } - } - } - - if (shape_circle) - max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255; - else - max_opr = width * height * 3 * 255; - - pixel_sum = r + g + b; - opr = ((float)pixel_sum) / max_opr; - - return opr; -} - float TopAppSurface::GetOpr() const { float opr = 0.0f; int width; @@ -149,19 +97,19 @@ void TopAppSurface::OnWatcherAdded(const std::string& appId, app_id_ = appId; inst_id_ = instId; - listener_->OnAdded(*surface_); + listener_->OnAdded(*this); } void TopAppSurface::OnWatcherChanged(const std::string& appId, const std::string& instId, const int pid, const screen_connector::EvasObject& image) { - //image_ = image; - listener_->OnUpdated(*surface_); + *image_ = image; + listener_->OnUpdated(*this); } void TopAppSurface::OnWatcherRemoved(const std::string& appId, const std::string& instId, const int pid) { - listener_->OnRemoved(*surface_); + listener_->OnRemoved(*this); image_ = nullptr; } diff --git a/ambient-viewer/src/top-app-surface.h b/ambient-viewer/src/top-app-surface.h index d200cde..400257b 100644 --- a/ambient-viewer/src/top-app-surface.h +++ b/ambient-viewer/src/top-app-surface.h @@ -22,13 +22,10 @@ #include #include +#include "iambient-viewer.h" #include "isurface.h" #include "ambient-viewer.h" -#define WATCH_SMART_SIGNAL_ADDED "watch,added" -#define WATCH_SMART_SIGNAL_REMOVED "watch,removed" -#define WATCH_SMART_SIGNAL_UPDATED "watch,updated" - namespace ambient_viewer { class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISurface { @@ -39,7 +36,7 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISur std::string GetInstId() const override; float GetOpr() const override; - TopAppSurface(std::shared_ptr surface, AmbientViewer::IEvent* listener); + TopAppSurface(std::shared_ptr surface, IAmbientViewer* listener); virtual ~TopAppSurface(); private: @@ -55,9 +52,9 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISur std::string app_id_; std::string inst_id_; - std::shared_ptr surface_; - AmbientViewer::IEvent* listener_; + IAmbientViewer* listener_; }; } // namespace ambient_viewer + #endif // __AMBIENT_VIEWER_TOP_APP_SURFACE_H__ diff --git a/ambient-viewer/src/watch-surface.cc b/ambient-viewer/src/watch-surface.cc index e68fa57..8d95d94 100644 --- a/ambient-viewer/src/watch-surface.cc +++ b/ambient-viewer/src/watch-surface.cc @@ -14,17 +14,16 @@ * limitations under the License. */ -#include - #include "watch-surface.h" +#include "internal.h" -#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle" +using namespace ambient_viewer::internal; namespace ambient_viewer { WatchSurface::WatchSurface( std::shared_ptr surface, - AmbientViewer::IEvent* listener) + IAmbientViewer* listener) : screen_connector::RemoteSurfaceEvas("", screen_connector::RemoteSurface::Type::WATCH, surface), listener_(listener) { @@ -48,58 +47,6 @@ std::string WatchSurface::GetInstId() const { return inst_id_; } -static float _GetOpr(void* source_data, int width, int height) { - int *source; - int x; - int y; - int idx; - int max_rad; - int rad; - int pos; - unsigned int r = 0; - unsigned int g = 0; - unsigned int b = 0; - unsigned int pixel_sum; - float opr; - float max_opr; - bool shape_circle = false; - - system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);; - - source = static_cast(source_data); - pos = width / 2; - max_rad = (height * height) >> 2; - - for (y = 0; y < height; ++y) { - for (x = 0; x < width; ++x) { - if (shape_circle) { - rad = (pos - x) * (pos - x) + (pos - y) * (pos - y); - if (rad <= max_rad) { - idx = y * width + x; - r += ((source[idx] & 0x00ff0000) >> 16); - g += ((source[idx] & 0x0000ff00) >> 8); - b += (source[idx] & 0x000000ff); - } - } else { - idx = y * width + x; - r += ((source[idx] & 0x00ff0000) >> 16); - g += ((source[idx] & 0x0000ff00) >> 8); - b += (source[idx] & 0x000000ff); - } - } - } - - if (shape_circle) - max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255; - else - max_opr = width * height * 3 * 255; - - pixel_sum = r + g + b; - opr = ((float)pixel_sum) / max_opr; - - return opr; -} - float WatchSurface::GetOpr() const { float opr = 0.0f; int width; @@ -150,22 +97,23 @@ void WatchSurface::OnEvasAdded(const std::string& appId, const screen_connector::EvasObject& image) { app_id_ = appId; inst_id_ = instId; - //image_ = image; + *image_ = image; - listener_->OnAdded(*surface_); + listener_->OnAdded(*this); } void WatchSurface::OnEvasRemoved(const std::string& appId, const std::string& instId, int pid, const screen_connector::EvasObject& image) { - listener_->OnRemoved(*surface_); image_ = nullptr; + listener_->OnRemoved(*this); } void WatchSurface::OnEvasChanged(const std::string& appId, const std::string& instId, int pid, const screen_connector::EvasObject& image) { - listener_->OnUpdated(*surface_); + *image_ = image; + listener_->OnUpdated(*this); } } // namespace ambient_viewer diff --git a/ambient-viewer/src/watch-surface.h b/ambient-viewer/src/watch-surface.h index 7c50e23..e0bd36d 100644 --- a/ambient-viewer/src/watch-surface.h +++ b/ambient-viewer/src/watch-surface.h @@ -22,6 +22,7 @@ #include #include +#include "iambient-viewer.h" #include "isurface.h" #include "ambient-viewer.h" @@ -35,7 +36,7 @@ class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface std::string GetInstId() const override; float GetOpr() const override; - WatchSurface(std::shared_ptr surface, AmbientViewer::IEvent* listener); + WatchSurface(std::shared_ptr surface, IAmbientViewer* listener); virtual ~WatchSurface(); private: @@ -51,9 +52,9 @@ class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface std::string app_id_; std::string inst_id_; - std::shared_ptr surface_; - AmbientViewer::IEvent* listener_; + IAmbientViewer* listener_; }; } // namespace ambient_viewer + #endif // __AMBIENT_VIEWER_WATCH_SURFACE_H__ diff --git a/packaging/ambient-viewer.manifest b/packaging/ambient-viewer.manifest old mode 100755 new mode 100644 diff --git a/packaging/libwidget_viewer.spec b/packaging/libwidget_viewer.spec old mode 100755 new mode 100644 index fd08d8c..9f20600 --- a/packaging/libwidget_viewer.spec +++ b/packaging/libwidget_viewer.spec @@ -142,15 +142,15 @@ While developing the widget applications, this viewer will load it and execute i ################################################# # widget-viewer_unittests ################################################# -%package -n widget-viewer_unittests -Summary: GTest for widget-viewer -Group: Development/Libraries +# %package -n widget-viewer_unittests +# Summary: GTest for widget-viewer +# Group: Development/Libraries -%description -n widget-viewer_unittests -GTest for widget-viewer +# %description -n widget-viewer_unittests +# GTest for widget-viewer -%files -n widget-viewer_unittests -%{_bindir}/widget-viewer_unittests +# %files -n widget-viewer_unittests +# %{_bindir}/widget-viewer_unittests ################################################# # widget-viewer-gcov diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index b7ef50e..784421b 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -17,6 +17,7 @@ pkg_check_modules(widget-viewer_unittests REQUIRED capi-appfw-application cynara-client screen_connector_watcher_evas + screen_connector_remote_surface_evas appcore-efl ecore edje @@ -43,16 +44,20 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_C_FLAGS_RELEASE "-O2") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../unittest/mock) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TEST_SOURCES) AUX_SOURCE_DIRECTORY(src SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/src WIDGET_VIEWER_EVAS_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src AMBIENT_VIEWER_SOURCES) ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES} ${WIDGET_VIEWER_EVAS_SOURCES} ${UNIT_TEST_SOURCES} + ${AMBIENT_VIEWER_SOURCES} ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS} @@ -60,6 +65,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS} ${pkgs_LIBRARIES} gmock widget_viewer_evas + ambient-viewer ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/unittest/src/test_ambient_viewer.cc b/unittest/src/test_ambient_viewer.cc new file mode 100644 index 0000000..f2fc94a --- /dev/null +++ b/unittest/src/test_ambient_viewer.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +using namespace std; +using namespace ambient_viewer; +using namespace screen_connector; + + +class AmbientViewerTest : public ::testing::Test { + public: + AmbientViewer* stub; + virtual void SetUp() { + Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC); + stub = new AmbientViewer(shared_ptr(new EvasObject(win, false))); + } + virtual void TearDown() { + delete stub; + } +}; + +TEST_F(AmbientViewerTest, create) { + EXPECT_NE(AmbientViewerTest::stub, nullptr); +} + +TEST_F(AmbientViewerTest, Monitor) { + AmbientViewerTest::stub->Monitor(); + AmbientViewerTest::stub->Unmonitor(); + + //EXPECT_EQ(); +} + +TEST_F(AmbientViewerTest, Get) { + AmbientViewerTest::stub->Monitor(); + + AmbientViewerTest::stub->GetTopAppSurface(); + + AmbientViewerTest::stub->Unmonitor(); + + //EXPECT_EQ(); +} \ No newline at end of file diff --git a/unittest/src/test_top_app_surface.cc b/unittest/src/test_top_app_surface.cc new file mode 100644 index 0000000..9605abf --- /dev/null +++ b/unittest/src/test_top_app_surface.cc @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +class TopAppSurfaceTest : public ::testing::Test { + public: + TopAppSurface* surface; + + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(TopAppSurfaceTest, create) { +} + diff --git a/unittest/src/test_watch_surface.cc b/unittest/src/test_watch_surface.cc new file mode 100644 index 0000000..03922af --- /dev/null +++ b/unittest/src/test_watch_surface.cc @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + + +class WatchSurfaceTest : public ::testing::Test { + public: + WatchSurface* surface; + + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(WatchSurfaceTest, create) { +} +