From 77956e051d31d97d2def00ff55cd7bb980baa996 Mon Sep 17 00:00:00 2001 From: Daekwang Ryu Date: Fri, 14 Apr 2023 11:45:37 +0900 Subject: [PATCH] Introduce WindowData The application class had to add new consructors whenever the Window class added a new constructor. Becuase the class has a default window. To simplify this process, WindowData is introduced that contains all the data of the window. Change-Id: Ib7a334e5d705628b4498e7775cd810f1f3ba50d8 --- automated-tests/src/dali-adaptor/CMakeLists.txt | 1 + .../src/dali-adaptor/utc-Dali-Application.cpp | 18 +++- .../src/dali-adaptor/utc-Dali-WindowData.cpp | 73 ++++++++++++++ dali/dali.h | 5 +- dali/public-api/adaptor-framework/application.cpp | 28 ++++++ dali/public-api/adaptor-framework/application.h | 21 +++- dali/public-api/adaptor-framework/window-data.cpp | 74 ++++++++++++++ dali/public-api/adaptor-framework/window-data.h | 109 +++++++++++++++++++++ dali/public-api/file.list | 2 + 9 files changed, 327 insertions(+), 4 deletions(-) create mode 100644 automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp create mode 100644 dali/public-api/adaptor-framework/window-data.cpp create mode 100644 dali/public-api/adaptor-framework/window-data.h diff --git a/automated-tests/src/dali-adaptor/CMakeLists.txt b/automated-tests/src/dali-adaptor/CMakeLists.txt index f4c425e..ecbe6f8 100644 --- a/automated-tests/src/dali-adaptor/CMakeLists.txt +++ b/automated-tests/src/dali-adaptor/CMakeLists.txt @@ -8,6 +8,7 @@ SET(TC_SOURCES utc-Dali-Application.cpp utc-Dali-EncodedImageBuffer.cpp utc-Dali-Capture.cpp + utc-Dali-WindowData.cpp utc-Dali-FileLoader.cpp utc-Dali-GifLoading.cpp utc-Dali-Gl-Window.cpp diff --git a/automated-tests/src/dali-adaptor/utc-Dali-Application.cpp b/automated-tests/src/dali-adaptor/utc-Dali-Application.cpp index a760954..7261b37 100644 --- a/automated-tests/src/dali-adaptor/utc-Dali-Application.cpp +++ b/automated-tests/src/dali-adaptor/utc-Dali-Application.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -181,6 +181,22 @@ int UtcDaliApplicationNew07P(void) END_TEST; } +int UtcDaliApplicationNew08P(void) +{ + int argc(1); + const char* argList[1] = {"program"}; + char** argv = const_cast(argList); + WindowData windowData; + + Application application = Application::New(&argc, &argv, "stylesheet", false, windowData); + + MyTestApp testApp(application); + + DALI_TEST_CHECK(application); + + END_TEST; +} + int UtcDaliApplicationCopyAndAssignment(void) { Application application = Application::New(); diff --git a/automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp b/automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp new file mode 100644 index 0000000..abe4286 --- /dev/null +++ b/automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 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 + +using namespace Dali; + +int UtcDaliWindowData01(void) +{ + // Test default values + WindowData windowData; + + DALI_TEST_CHECK(windowData.GetWindowType() == WindowType::NORMAL); + DALI_TEST_CHECK(windowData.GetTransparency() == true); + DALI_TEST_CHECK(windowData.GetPositionSize().x == 0); + DALI_TEST_CHECK(windowData.GetPositionSize().y == 0); + DALI_TEST_CHECK(windowData.GetPositionSize().width == 0); + DALI_TEST_CHECK(windowData.GetPositionSize().height == 0); + + END_TEST; +} + +int UtcDaliWindowData02(void) +{ + // Test SetTransparency and GetTransparency + WindowData windowData; + windowData.SetTransparency(false); + + DALI_TEST_CHECK(windowData.GetTransparency() == false); + + END_TEST; +} + +int UtcDaliWindowData03(void) +{ + // Test SetWindowType and GetWindowType + WindowData windowData; + windowData.SetWindowType(WindowType::UTILITY); + + DALI_TEST_CHECK(windowData.GetWindowType() == WindowType::UTILITY); + + END_TEST; +} + +int UtcDaliWindowData04(void) +{ + // Test SetPositionSize and GetPositionSize + WindowData windowData; + Dali::Rect rect(100, 200, 300, 400); + windowData.SetPositionSize(rect); + + DALI_TEST_CHECK(windowData.GetPositionSize().x == 100); + DALI_TEST_CHECK(windowData.GetPositionSize().y == 200); + DALI_TEST_CHECK(windowData.GetPositionSize().width == 300); + DALI_TEST_CHECK(windowData.GetPositionSize().height == 400); + + END_TEST; +} diff --git a/dali/dali.h b/dali/dali.h index ff3b7df..db4687d 100644 --- a/dali/dali.h +++ b/dali/dali.h @@ -2,7 +2,7 @@ #define DALI_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -32,6 +32,7 @@ #include #include #include +#include #include -#endif //DALI_H +#endif // DALI_H diff --git a/dali/public-api/adaptor-framework/application.cpp b/dali/public-api/adaptor-framework/application.cpp index 8ed1f90..36db754 100644 --- a/dali/public-api/adaptor-framework/application.cpp +++ b/dali/public-api/adaptor-framework/application.cpp @@ -123,6 +123,34 @@ Application Application::New(int* argc, char** argv[], const std::string& styles return Application(internal.Get()); } +Application Application::New(int* argc, char** argv[], const std::string& stylesheet, bool useUiThread, WindowData& windowData) +{ + Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication(); + if(internal) + { + // pre-initialized application + internal->SetCommandLineOptions(argc, argv); + internal->SetStyleSheet(stylesheet); + + // Set defaut Window type + internal->SetDefaultWindowType(windowData.GetWindowType()); + internal->GetWindow().SetTransparency(windowData.GetTransparency()); + + // Store only the value before adaptor is created + internal->StoreWindowPositionSize(windowData.GetPositionSize()); + } + else + { + // clang-format off + internal = Internal::Adaptor::Application::New(argc, argv, stylesheet, + windowData.GetTransparency() ? WINDOW_MODE::TRANSPARENT : WINDOW_MODE::OPAQUE, + windowData.GetPositionSize(), Internal::Adaptor::Framework::NORMAL, + windowData.GetWindowType(), useUiThread); + // clang-format on + } + return Application(internal.Get()); +} + Application::~Application() { } diff --git a/dali/public-api/adaptor-framework/application.h b/dali/public-api/adaptor-framework/application.h index 1971c4d..c8ca3be 100644 --- a/dali/public-api/adaptor-framework/application.h +++ b/dali/public-api/adaptor-framework/application.h @@ -2,7 +2,7 @@ #define DALI_APPLICATION_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include +#include #include namespace Dali @@ -224,6 +225,24 @@ public: static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize, bool useUiThread); /** + * @brief This is the constructor for applications. + * + * @SINCE_2_2.23 + * @PRIVLEVEL_PUBLIC + * @PRIVILEGE_DISPLAY + * @param[in,out] argc A pointer to the number of arguments + * @param[in,out] argv A pointer to the argument list + * @param[in] stylesheet The path to user defined theme file + * @param[in] useUiThread True if the application would create a UI thread + * @param[in] windowData The window data for the application + * @return A handle to the Application + * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
+ * UI thread is an additional thread that DALi creates for UI events. + * The UI thread isn't blocked from the system events(AppControl, LanguageChanged, RegionChanged, LowMemory, LowBattery task signals). + */ + static Application New(int* argc, char** argv[], const std::string& stylesheet, bool useUiThread, WindowData& windowData); + + /** * @brief Constructs an empty handle. * @SINCE_1_0.0 */ diff --git a/dali/public-api/adaptor-framework/window-data.cpp b/dali/public-api/adaptor-framework/window-data.cpp new file mode 100644 index 0000000..6d329bb --- /dev/null +++ b/dali/public-api/adaptor-framework/window-data.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 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. + * + */ + +// CLASS HEADER +#include + +namespace Dali +{ +struct WindowData::Impl +{ + Impl() + : mPositionSize(0, 0, 0, 0), + mIsTransparent(true), + mWindowType(WindowType::NORMAL) + { + } + + Dali::Rect mPositionSize; ///< The position and size of the Window + bool mIsTransparent; ///< The transparency of the Window + WindowType mWindowType; ///< The window type of the Window +}; + +WindowData::WindowData() +: mImpl(std::make_unique()) +{ +} + +WindowData::~WindowData() = default; + +void WindowData::SetPositionSize(Dali::Rect& positionSize) +{ + mImpl->mPositionSize = positionSize; +} + +Dali::Rect WindowData::GetPositionSize() const +{ + return mImpl->mPositionSize; +} + +void WindowData::SetTransparency(bool transparent) +{ + mImpl->mIsTransparent = transparent; +} + +bool WindowData::GetTransparency() const +{ + return mImpl->mIsTransparent; +} + +void WindowData::SetWindowType(WindowType type) +{ + mImpl->mWindowType = type; +} + +WindowType WindowData::GetWindowType() const +{ + return mImpl->mWindowType; +} + +} // namespace Dali diff --git a/dali/public-api/adaptor-framework/window-data.h b/dali/public-api/adaptor-framework/window-data.h new file mode 100644 index 0000000..b7bf089 --- /dev/null +++ b/dali/public-api/adaptor-framework/window-data.h @@ -0,0 +1,109 @@ +#ifndef DALI_WINDOW_DATA_H +#define DALI_WINDOW_DATA_H + +/* + * Copyright (c) 2023 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include +#include +#include + +namespace Dali +{ +/** + * The WindowData class is used as a parameter for the constructors of the Application class. + * The data from the WindowData object is used to customize the default window created by the Application class. + * + * The default values are below: + * PositionSize : x:0, y:0, w:0, h:0 (full-screen window) + * Transparency : true (Window is created with 32-bit color depth) + * WindowType : NORMAL + * + * If you want to customize the window, you can modify the values of the WindowData object as needed. + * @SINCE_2_2.23 + */ +class DALI_ADAPTOR_API WindowData +{ +public: + /** + * @brief Creates a WindowData object. + */ + WindowData(); + + /** + * @brief Destructor. + */ + ~WindowData(); + + /** + * @brief Sets the position and size + * + * @SINCE_2_2.23 + * @param[in] positionSize Position and Size + */ + void SetPositionSize(Dali::Rect& positionSize); + + /** + * @brief Gets the PositionSize + * + * @SINCE_2_2.23 + * @return The position and size + */ + Dali::Rect GetPositionSize() const; + + /** + * @brief Sets the transparency + * + * @SINCE_2_2.23 + * @param[in] transparent transparency + */ + void SetTransparency(bool transparent); + + /** + * @brief Gets the transparency + * + * @SINCE_2_2.23 + * @return whether transparency + */ + bool GetTransparency() const; + + /** + * @brief Sets the window type + * + * @SINCE_2_2.23 + * @param[in] type the window type + */ + void SetWindowType(WindowType type); + + /** + * @brief Gets the window type + * + * @SINCE_2_2.23 + * @return the window type + */ + WindowType GetWindowType() const; + +private: + struct Impl; + std::unique_ptr mImpl; +}; + +} // namespace Dali + +#endif // DALI_WINDOW_DATA_H diff --git a/dali/public-api/file.list b/dali/public-api/file.list index f13b5ff..4fbbab1 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -12,6 +12,7 @@ SET( adaptor_public_api_src_files ${adaptor_public_api_dir}/adaptor-framework/widget-application.cpp ${adaptor_public_api_dir}/adaptor-framework/widget-impl.cpp ${adaptor_public_api_dir}/adaptor-framework/async-task-manager.cpp + ${adaptor_public_api_dir}/adaptor-framework/window-data.cpp ${adaptor_public_api_dir}/capture/capture.cpp ${adaptor_public_api_dir}/dali-adaptor-version.cpp ) @@ -41,6 +42,7 @@ SET( public_api_adaptor_framework_header_files ${adaptor_public_api_dir}/adaptor-framework/window-enumerations.h ${adaptor_public_api_dir}/adaptor-framework/round-robin-container-view.h ${adaptor_public_api_dir}/adaptor-framework/async-task-manager.h + ${adaptor_public_api_dir}/adaptor-framework/window-data.h ) SET( public_dali_capture_header_files -- 2.7.4