2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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.
19 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
22 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
23 #include <dali/devel-api/adaptor-framework/environment-variable.h>
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
26 #include <dali/internal/adaptor/common/adaptor-impl.h>
27 #include <dali/internal/adaptor/common/framework-factory.h>
28 #include <dali/internal/adaptor/common/lifecycle-controller-impl.h>
29 #include <dali/internal/adaptor/common/thread-controller-interface.h>
30 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
31 #include <dali/internal/system/common/environment-variables.h>
32 #include <dali/internal/window-system/common/window-system.h>
40 void EmitLifecycleControllerSignal(void (Internal::Adaptor::LifecycleController::*member)(Dali::Application&))
42 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
43 if(DALI_LIKELY(lifecycleController))
45 Dali::Application dummyApplication;
46 (GetImplementation(lifecycleController).*member)(dummyApplication);
50 using RenderMode = Dali::OffscreenApplication::RenderMode;
52 IntrusivePtr<OffscreenApplication> OffscreenApplication::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
54 IntrusivePtr<OffscreenApplication> offscreenApplication = new OffscreenApplication(width, height, surface, isTranslucent, renderMode);
55 return offscreenApplication;
58 OffscreenApplication::OffscreenApplication(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
60 // Disable partial update
61 EnvironmentVariable::SetEnvironmentVariable(DALI_ENV_DISABLE_PARTIAL_UPDATE, "1");
64 Dali::Accessibility::Bridge::DisableAutoInit();
66 // Now we assume separated main loop for the offscreen application
67 mFrameworkFactory = std::unique_ptr<Adaptor::FrameworkFactory>(Dali::Internal::Adaptor::CreateFrameworkFactory());
68 mFramework = mFrameworkFactory->CreateFramework(Internal::Adaptor::FrameworkBackend::GLIB, *this, *this, nullptr, nullptr, Adaptor::Framework::NORMAL, false);
70 // Generate a default window
71 IntrusivePtr<Internal::OffscreenWindow> impl = Internal::OffscreenWindow::New(width, height, surface, isTranslucent);
72 mDefaultWindow = Dali::OffscreenWindow(impl.Get());
74 mAdaptor.reset(Dali::Internal::Adaptor::Adaptor::New(Dali::Integration::SceneHolder(impl.Get()), impl->GetSurface(), NULL, renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED));
76 // Initialize default window
77 impl->Initialize(true);
80 OffscreenApplication::~OffscreenApplication()
84 void OffscreenApplication::MainLoop()
89 void OffscreenApplication::Quit()
91 // Actually quit the application.
92 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle(MakeCallback(this, &OffscreenApplication::QuitFromMainLoop), false);
95 Dali::OffscreenWindow OffscreenApplication::GetWindow()
97 return mDefaultWindow;
100 void OffscreenApplication::RenderOnce()
102 mAdaptor->RenderOnce();
105 Any OffscreenApplication::GetFrameworkContext() const
107 return mFramework->GetMainLoopContext();
110 void OffscreenApplication::OnInit()
115 Dali::OffscreenApplication application(this);
117 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnInit);
119 mAdaptor->NotifySceneCreated();
122 void OffscreenApplication::OnTerminate()
124 Dali::OffscreenApplication application(this);
125 mTerminateSignal.Emit();
126 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnTerminate);
131 mDefaultWindow.Reset();
134 void OffscreenApplication::OnPause()
136 Dali::OffscreenApplication application(this);
138 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnPause);
141 void OffscreenApplication::OnResume()
143 Dali::OffscreenApplication application(this);
144 mResumeSignal.Emit();
145 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnResume);
147 // DALi just delivers the framework Resume event to the application.
148 // Resuming DALi core only occurs on the Window Show framework event
150 // Trigger processing of events queued up while paused
151 Internal::Adaptor::CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor);
152 coreEventInterface.ProcessCoreEvents();
155 void OffscreenApplication::OnReset()
158 * usually, reset callback was called when a caller request to launch this application via aul.
159 * because Application class already handled initialization in OnInit(), OnReset do nothing.
161 Dali::OffscreenApplication application(this);
163 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnReset);
166 void OffscreenApplication::OnLanguageChanged()
168 mAdaptor->NotifyLanguageChanged();
170 Dali::OffscreenApplication application(this);
171 mLanguageChangedSignal.Emit();
172 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnLanguageChanged);
175 void OffscreenApplication::QuitFromMainLoop()
180 // This will trigger OnTerminate(), below, after the main loop has completed.
183 } // namespace Internal