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/thread-controller-interface.h>
29 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
30 #include <dali/internal/system/common/environment-variables.h>
31 #include <dali/internal/window-system/common/window-system.h>
37 using RenderMode = Dali::OffscreenApplication::RenderMode;
39 IntrusivePtr<OffscreenApplication> OffscreenApplication::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
41 IntrusivePtr<OffscreenApplication> offscreenApplication = new OffscreenApplication(width, height, surface, isTranslucent, renderMode);
42 return offscreenApplication;
45 OffscreenApplication::OffscreenApplication(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
47 // Disable partial update
48 EnvironmentVariable::SetEnvironmentVariable(DALI_ENV_DISABLE_PARTIAL_UPDATE, "1");
51 Dali::Accessibility::Bridge::DisableAutoInit();
53 // Now we assume separated main loop for the offscreen application
54 mFrameworkFactory = std::unique_ptr<Adaptor::FrameworkFactory>(Dali::Internal::Adaptor::CreateFrameworkFactory());
55 mFramework = mFrameworkFactory->CreateFramework(Internal::Adaptor::FrameworkBackend::GLIB, *this, *this, nullptr, nullptr, Adaptor::Framework::NORMAL, false);
57 // Generate a default window
58 IntrusivePtr<Internal::OffscreenWindow> impl = Internal::OffscreenWindow::New(width, height, surface, isTranslucent);
59 mDefaultWindow = Dali::OffscreenWindow(impl.Get());
61 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));
63 // Initialize default window
64 impl->Initialize(true);
67 OffscreenApplication::~OffscreenApplication()
71 void OffscreenApplication::MainLoop()
76 void OffscreenApplication::Quit()
78 // Actually quit the application.
79 // Force a call to Quit even if adaptor is not running.
80 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle(MakeCallback(this, &OffscreenApplication::QuitFromMainLoop), false, true);
83 Dali::OffscreenWindow OffscreenApplication::GetWindow()
85 return mDefaultWindow;
88 void OffscreenApplication::RenderOnce()
90 mAdaptor->RenderOnce();
93 Any OffscreenApplication::GetFrameworkContext() const
95 return mFramework->GetMainLoopContext();
98 void OffscreenApplication::OnInit()
105 mAdaptor->NotifySceneCreated();
108 void OffscreenApplication::OnTerminate()
110 mTerminateSignal.Emit();
115 mDefaultWindow.Reset();
118 void OffscreenApplication::QuitFromMainLoop()
123 // This will trigger OnTerminate(), below, after the main loop has completed.
126 } // namespace Internal