[Tizen] Add OffscreenApplication
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / tizen / offscreen-window-impl-tizen.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/devel-api/adaptor-framework/clipboard.h>
20 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
21 #include <dali/integration-api/adaptor-framework/adaptor.h>
22 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
23 #include <dali/integration-api/adaptor-framework/native-render-surface-factory.h>
24 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <tbm_surface.h>
28 #include <tbm_surface_queue.h>
29
30 // INTERNAL INCLUDES
31 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
32
33 // CLASS HEADER
34 #include <dali/internal/offscreen/tizen/offscreen-window-impl-tizen.h>
35
36 namespace Dali
37 {
38
39 namespace Internal
40 {
41
42 OffscreenWindowTizen* OffscreenWindowTizen::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent )
43 {
44   OffscreenWindowTizen* window = new OffscreenWindowTizen( width, height, surface, isTranslucent );
45   return window;
46 }
47
48 OffscreenWindowTizen::OffscreenWindowTizen( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent )
49 : mRenderNotification(),
50   mIsTranslucent( isTranslucent )
51 {
52   // Create surface
53   if ( surface.Empty() )
54   {
55     mSurface = std::unique_ptr< RenderSurfaceInterface >( CreateNativeSurface( SurfaceSize( width, height ), surface, isTranslucent ) );
56   }
57   else
58   {
59     width = static_cast<uint16_t>( tbm_surface_queue_get_width( AnyCast< tbm_surface_queue_h > ( surface ) ) );
60     height = static_cast<uint16_t>( tbm_surface_queue_get_height( AnyCast< tbm_surface_queue_h > ( surface ) ) );
61     mSurface = std::unique_ptr< RenderSurfaceInterface >( CreateNativeSurface( SurfaceSize( width, height ), surface, isTranslucent ) );
62   }
63 }
64
65 void OffscreenWindowTizen::Initialize( bool isDefaultWindow )
66 {
67   if( isDefaultWindow )
68   {
69     Initialize();
70     return;
71   }
72
73   Dali::Integration::SceneHolder sceneHolderHandler = Dali::Integration::SceneHolder( this );
74   Dali::Adaptor::Get().AddWindow( sceneHolderHandler );
75
76   Initialize();
77 }
78
79 void OffscreenWindowTizen::Initialize()
80 {
81   // Connect callback to be notified when the surface is rendered
82   TriggerEventFactory triggerEventFactory;
83
84   mRenderNotification = std::unique_ptr< TriggerEventInterface >( triggerEventFactory.CreateTriggerEvent( MakeCallback( this, &OffscreenWindowTizen::OnPostRender ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ) );
85
86   NativeRenderSurface* surface = GetNativeRenderSurface();
87
88   if( !surface )
89   {
90     return;
91   }
92
93   surface->SetRenderNotification( mRenderNotification.get() );
94 }
95
96 OffscreenWindowTizen::~OffscreenWindowTizen()
97 {
98   NativeRenderSurface* surface = GetNativeRenderSurface();
99
100   if( surface )
101   {
102     // To prevent notification triggering in NativeRenderSurface::PostRender while deleting SceneHolder
103     surface->SetRenderNotification( nullptr );
104   }
105 }
106
107 uint32_t OffscreenWindowTizen::GetLayerCount() const
108 {
109   return mScene.GetLayerCount();
110 }
111
112 Dali::Layer OffscreenWindowTizen::GetLayer( uint32_t depth ) const
113 {
114   return mScene.GetLayer( depth );
115 }
116
117 OffscreenWindow::WindowSize OffscreenWindowTizen::GetSize() const
118 {
119   Size size = mScene.GetSize();
120
121   return OffscreenWindow::WindowSize( static_cast<uint16_t>( size.width ), static_cast<uint16_t>( size.height ) );
122 }
123
124 Dali::Any OffscreenWindowTizen::GetNativeHandle() const
125 {
126   return GetNativeRenderSurface()->GetNativeHandle();
127 }
128
129 NativeRenderSurface* OffscreenWindowTizen::GetNativeRenderSurface() const
130 {
131   return dynamic_cast< NativeRenderSurface* >( mSurface.get() );
132 }
133
134 void OffscreenWindowTizen::OnPostRender()
135 {
136   mPostRenderSignal.Emit( Dali::OffscreenWindow( this ), nullptr );
137 }
138
139 OffscreenWindow::PostRenderSignalType& OffscreenWindowTizen::PostRenderSignal()
140 {
141   return mPostRenderSignal;
142 }
143
144 } // namespace Internal
145
146 } // namespace Dali