[Tizen] 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 // EXTERNAL INCLUDES
19 #include <dali/integration-api/adaptor-framework/adaptor.h>
20 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
21
22 // INTERNAL INCLUDES
23 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
24 #include <dali/internal/offscreen/common/offscreen-window-factory.h>
25
26 // CLASS HEADER
27 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 IntrusivePtr< OffscreenApplication > OffscreenApplication::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
36 {
37   IntrusivePtr< OffscreenApplication > offscreenApplication = new OffscreenApplication( width, height, surface, isTranslucent );
38   return offscreenApplication;
39 }
40
41 OffscreenApplication::OffscreenApplication( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent )
42 : mState( READY )
43 {
44   // Generate a default window
45   auto windowFactory = Dali::Internal::GetOffscreenWindowFactory();
46   IntrusivePtr <Internal::OffscreenWindow > windowPtr = windowFactory->CreateOffscreenWindow( width, height, surface, isTranslucent ).release();
47   mDefaultWindow = Dali::OffscreenWindow( windowPtr.Get() );
48
49   // Generate DALi adaptor
50   NativeRenderSurface* naitveSurface = static_cast<NativeRenderSurface*>( windowPtr->GetSurface() );
51
52   mAdaptor = &Dali::Adaptor::New( Dali::Integration::SceneHolder( windowPtr.Get() ), *naitveSurface, Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS );
53
54   // Initialize default window
55   windowPtr->Initialize( this, true );
56 }
57
58 OffscreenApplication::~OffscreenApplication()
59 {
60   delete mAdaptor;
61   mAdaptor = nullptr;
62 }
63
64 Dali::Adaptor* OffscreenApplication::GetAdaptor()
65 {
66   return mAdaptor;
67 }
68
69 void OffscreenApplication::Run()
70 {
71   if( READY == mState )
72   {
73     // Start the adaptor
74     mAdaptor->Start();
75
76     mState = RUNNING;
77
78     mPreInitSignal.Emit();
79
80     mInitSignal.Emit();
81
82     mAdaptor->NotifySceneCreated();
83   }
84 }
85
86 void OffscreenApplication::Stop()
87 {
88   if( mState != STOPPED )
89   {
90     // Stop the adaptor
91     mAdaptor->Stop();
92     mState = STOPPED;
93
94     mTerminateSignal.Emit();
95   }
96 }
97
98 Dali::OffscreenWindow OffscreenApplication::GetWindow()
99 {
100   return mDefaultWindow;
101 }
102
103 } // namespace Internal
104
105 } // namespace Dali