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 // Force a call to Quit even if adaptor is not running.
93 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle(MakeCallback(this, &OffscreenApplication::QuitFromMainLoop), false, true);
96 Dali::OffscreenWindow OffscreenApplication::GetWindow()
98 return mDefaultWindow;
101 void OffscreenApplication::RenderOnce()
103 mAdaptor->RenderOnce();
106 Any OffscreenApplication::GetFrameworkContext() const
108 return mFramework->GetMainLoopContext();
111 void OffscreenApplication::OnInit()
116 Dali::OffscreenApplication application(this);
118 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnInit);
120 mAdaptor->NotifySceneCreated();
123 void OffscreenApplication::OnTerminate()
125 Dali::OffscreenApplication application(this);
126 mTerminateSignal.Emit();
127 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnTerminate);
132 mDefaultWindow.Reset();
135 void OffscreenApplication::OnPause()
137 Dali::OffscreenApplication application(this);
139 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnPause);
142 void OffscreenApplication::OnResume()
144 Dali::OffscreenApplication application(this);
145 mResumeSignal.Emit();
146 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnResume);
148 // DALi just delivers the framework Resume event to the application.
149 // Resuming DALi core only occurs on the Window Show framework event
151 // Trigger processing of events queued up while paused
152 Internal::Adaptor::CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor);
153 coreEventInterface.ProcessCoreEvents();
156 void OffscreenApplication::OnReset()
159 * usually, reset callback was called when a caller request to launch this application via aul.
160 * because Application class already handled initialization in OnInit(), OnReset do nothing.
162 Dali::OffscreenApplication application(this);
164 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnReset);
167 void OffscreenApplication::OnLanguageChanged()
169 mAdaptor->NotifyLanguageChanged();
171 Dali::OffscreenApplication application(this);
172 mLanguageChangedSignal.Emit();
173 EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnLanguageChanged);
176 void OffscreenApplication::QuitFromMainLoop()
181 // This will trigger OnTerminate(), below, after the main loop has completed.
184 } // namespace Internal