2 * Copyright (c) 2020 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-window-impl.h>
22 #include <dali/public-api/actors/layer.h>
25 #include <dali/integration-api/adaptor-framework/adaptor.h>
26 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
27 #include <dali/integration-api/adaptor-framework/native-render-surface-factory.h>
28 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
29 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
37 OffscreenWindow* OffscreenWindow::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent )
39 OffscreenWindow* window = new OffscreenWindow( width, height, surface, isTranslucent );
43 OffscreenWindow::OffscreenWindow( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent )
44 : mRenderNotification()
47 mSurface = std::unique_ptr< RenderSurfaceInterface >( CreateNativeSurface( SurfaceSize( width, height ), surface, isTranslucent ) );
50 void OffscreenWindow::Initialize( bool isDefaultWindow )
58 Dali::Integration::SceneHolder sceneHolderHandler = Dali::Integration::SceneHolder( this );
59 Dali::Adaptor::Get().AddWindow( sceneHolderHandler );
64 void OffscreenWindow::Initialize()
66 // Connect callback to be notified when the surface is rendered
67 TriggerEventFactory triggerEventFactory;
69 mRenderNotification = std::unique_ptr< TriggerEventInterface >( triggerEventFactory.CreateTriggerEvent( MakeCallback( this, &OffscreenWindow::OnPostRender ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ) );
71 NativeRenderSurface* surface = GetNativeRenderSurface();
78 surface->SetRenderNotification( mRenderNotification.get() );
81 OffscreenWindow::~OffscreenWindow()
83 NativeRenderSurface* surface = GetNativeRenderSurface();
87 // To prevent notification triggering in NativeRenderSurface::PostRender while deleting SceneHolder
88 surface->SetRenderNotification( nullptr );
92 uint32_t OffscreenWindow::GetLayerCount() const
94 return mScene.GetLayerCount();
97 Dali::Layer OffscreenWindow::GetLayer( uint32_t depth ) const
99 return mScene.GetLayer( depth );
102 OffscreenWindow::WindowSize OffscreenWindow::GetSize() const
104 Size size = mScene.GetSize();
106 return OffscreenWindow::WindowSize( static_cast<uint16_t>( size.width ), static_cast<uint16_t>( size.height ) );
109 Dali::Any OffscreenWindow::GetNativeHandle() const
111 NativeRenderSurface* surface = GetNativeRenderSurface();
112 DALI_ASSERT_ALWAYS( surface && "surface handle is empty" );
114 return surface->GetNativeRenderable();
117 NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
119 return dynamic_cast< NativeRenderSurface* >( mSurface.get() );
122 void OffscreenWindow::OnPostRender()
124 Dali::OffscreenWindow handle( this );
125 mPostRenderSignal.Emit( handle, GetNativeHandle() );
128 OffscreenWindow::PostRenderSignalType& OffscreenWindow::PostRenderSignal()
130 return mPostRenderSignal;
133 } // namespace Internal