[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 // 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 RenderMode = Dali::OffscreenApplication::RenderMode;
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 IntrusivePtr< OffscreenApplication > OffscreenApplication::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
37 {
38   IntrusivePtr< OffscreenApplication > offscreenApplication = new OffscreenApplication( width, height, surface, isTranslucent, renderMode );
39   return offscreenApplication;
40 }
41
42 OffscreenApplication::OffscreenApplication( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
43 {
44   // Generate a default window
45   IntrusivePtr< Internal::OffscreenWindow > impl = Internal::OffscreenWindow::New( width, height, surface, isTranslucent );
46   mDefaultWindow = Dali::OffscreenWindow( impl.Get() );
47
48   mAdaptor.reset( Dali::Internal::Adaptor::Adaptor::New( Dali::Integration::SceneHolder( impl.Get() ), impl->GetSurface(), NULL,
49                             renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED ) );
50
51   // Initialize default window
52   impl->Initialize( true );
53 }
54
55 void OffscreenApplication::Start()
56 {
57    // Start the adaptor
58    mAdaptor->Start();
59    mInitSignal.Emit();
60    mAdaptor->NotifySceneCreated();
61 }
62
63 void OffscreenApplication::Stop()
64 {
65   // Stop the adaptor
66   mAdaptor->Stop();
67   mTerminateSignal.Emit();
68 }
69
70 Dali::OffscreenWindow OffscreenApplication::GetWindow()
71 {
72   return mDefaultWindow;
73 }
74
75 void OffscreenApplication::RenderOnce()
76 {
77   mAdaptor->RenderOnce();
78 }
79
80 } // namespace Internal
81
82 } // namespace Dali