Add OffscreenApplication
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-application-impl.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/adaptor/common/adaptor-impl.h>
23 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
24 #include <dali/internal/adaptor/common/thread-controller-interface.h>
25 #include <dali/integration-api/adaptor-framework/adaptor.h>
26 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
27
28 using Dali::Internal::Adaptor::ThreadMode;
29 using RenderMode = Dali::OffscreenApplication::RenderMode;
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 IntrusivePtr< OffscreenApplication > OffscreenApplication::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
38 {
39   IntrusivePtr< OffscreenApplication > offscreenApplication = new OffscreenApplication( width, height, surface, isTranslucent, renderMode );
40   return offscreenApplication;
41 }
42
43 OffscreenApplication::OffscreenApplication( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
44 {
45   // Generate a default window
46   IntrusivePtr< Internal::OffscreenWindow > impl = Internal::OffscreenWindow::New( width, height, surface, isTranslucent );
47   mDefaultWindow = Dali::OffscreenWindow( impl.Get() );
48
49   mAdaptor.reset( Dali::Internal::Adaptor::Adaptor::New( Dali::Integration::SceneHolder( impl.Get() ), impl->GetSurface(), NULL,
50                             renderMode == RenderMode::AUTO ?
51                             Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED ) );
52
53   // Initialize default window
54   impl->Initialize( true );
55 }
56
57 void OffscreenApplication::Start()
58 {
59    // Start the adaptor
60    mAdaptor->Start();
61    mInitSignal.Emit();
62    mAdaptor->NotifySceneCreated();
63 }
64
65 void OffscreenApplication::Stop()
66 {
67   // Stop the adaptor
68   mAdaptor->Stop();
69   mTerminateSignal.Emit();
70 }
71
72 Dali::OffscreenWindow OffscreenApplication::GetWindow()
73 {
74   return mDefaultWindow;
75 }
76
77 void OffscreenApplication::RenderOnce()
78 {
79   mAdaptor->RenderOnce();
80 }
81
82 } // namespace Internal
83
84 } // namespace Dali