2 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "wrt/src/browser/basic_splash_screen.h"
19 #include "wrt/src/browser/basic_splash_screen_off_screen.h"
20 #include "wrt/src/browser/basic_splash_screen_on_screen.h"
21 #include "wrt/src/browser/wrt_native_window.h"
26 SplashScreen* BasicSplashScreen::Create(
27 std::unique_ptr<SplashScreenDelegate> delegate) {
28 if (WRTNativeWindow::UseOnscreenRendering())
29 return new BasicSplashScreenOnScreen(std::move(delegate));
31 return new BasicSplashScreenOffScreen(std::move(delegate));
34 BasicSplashScreen::BasicSplashScreen(
35 std::unique_ptr<SplashScreenDelegate> delegate)
36 : delegate_(std::move(delegate)) {}
38 wgt::parse::ReadyWhen BasicSplashScreen::GetReadyWhen() {
39 auto& app_data = ApplicationData::GetInstance();
40 return app_data.launch_screen_info().ready_when();
43 BasicSplashScreen::SplashScreenData* BasicSplashScreen::GetSplashScreenData() {
44 auto orientation = wgt::parse::ScreenOrientation::AUTO;
46 orientation = delegate_->GetScreenOrientation();
48 auto& app_data = ApplicationData::GetInstance();
49 auto& screen_info = app_data.launch_screen_info();
50 auto* splash_screen_data = screen_info.GetLaunchScreenData(orientation);
51 // get default images if fail to get LANDSCAPE/PORTRAIT images
52 if (!splash_screen_data || splash_screen_data->images.empty()) {
54 screen_info.GetLaunchScreenData(wgt::parse::ScreenOrientation::AUTO);
57 return splash_screen_data;
60 gfx::Insets BasicSplashScreen::ParseImageBorder(
61 const std::vector<std::string>& borders,
62 std::vector<BorderOption>* border_options) {
63 std::map<std::string, BorderOption> scaling_string;
64 scaling_string["repeat"] = BorderOption::REPEAT;
65 scaling_string["stretch"] = BorderOption::STRETCH;
66 scaling_string["round"] = BorderOption::ROUND;
68 std::vector<int> border_values;
69 for (const auto& border : borders) {
70 std::string::size_type px_index = border.find("px");
71 if (px_index != std::string::npos) {
72 std::string border_value(border.begin(), border.begin() + px_index);
73 border_values.push_back(std::atoi(border_value.c_str()));
75 for (const auto& border_string_val : scaling_string) {
76 std::string::size_type index = border.find(border_string_val.first);
77 if (index != std::string::npos) {
78 border_options->push_back(border_string_val.second);
83 LOG(INFO) << "Image border values:";
84 for (const auto& border_value : border_values)
85 LOG(INFO) << border_value;
86 LOG(INFO) << "Image border scaling values:";
87 for (const auto& border_option : *border_options)
88 LOG(INFO) << static_cast<int>(border_option);
90 if (border_values.empty() || border_options->empty())
93 switch (border_values.size()) {
95 return gfx::Insets::VH(border_values[0], border_values[1]);
97 return gfx::Insets::TLBR(border_values[0], border_values[3],
98 border_values[2], border_values[1]);
100 return gfx::Insets(border_values[0]);
104 std::string BasicSplashScreen::GetImagePath(
105 SplashScreenData* splash_screen_data) {
106 std::string raw_image_path = splash_screen_data->images.front().first;
107 std::string image_path;
109 image_path = delegate_->ConvertAliasPath(raw_image_path);
111 if (image_path.empty()) {
112 auto app_path = ApplicationData::GetInstance().application_path();
113 image_path = app_path + raw_image_path;
116 LOG(INFO) << "image_path: " << image_path;