2 * Copyright (c) 2021 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-factory.h>
27 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
28 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
29 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
35 OffscreenWindow* OffscreenWindow::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
37 OffscreenWindow* window = new OffscreenWindow(width, height, surface, isTranslucent);
41 OffscreenWindow::OffscreenWindow(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
42 : mRenderNotification()
45 mSurface = std::unique_ptr<RenderSurfaceInterface>(CreateNativeSurface(SurfaceSize(width, height), surface, isTranslucent));
48 void OffscreenWindow::Initialize(bool isDefaultWindow)
56 Dali::Integration::SceneHolder sceneHolderHandler = Dali::Integration::SceneHolder(this);
57 Dali::Adaptor::Get().AddWindow(sceneHolderHandler);
62 void OffscreenWindow::Initialize()
64 // Connect callback to be notified when the surface is rendered
65 TriggerEventFactory triggerEventFactory;
67 mRenderNotification = std::unique_ptr<TriggerEventInterface>(triggerEventFactory.CreateTriggerEvent(MakeCallback(this, &OffscreenWindow::OnPostRender), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
69 NativeRenderSurface* surface = GetNativeRenderSurface();
76 surface->SetRenderNotification(mRenderNotification.get());
79 OffscreenWindow::~OffscreenWindow()
81 NativeRenderSurface* surface = GetNativeRenderSurface();
85 // To prevent notification triggering in NativeRenderSurface::PostRender while deleting SceneHolder
86 surface->SetRenderNotification(nullptr);
90 uint32_t OffscreenWindow::GetLayerCount() const
92 return mScene.GetLayerCount();
95 Dali::Layer OffscreenWindow::GetLayer(uint32_t depth) const
97 return mScene.GetLayer(depth);
100 OffscreenWindow::WindowSize OffscreenWindow::GetSize() const
102 Size size = mScene.GetSize();
104 return OffscreenWindow::WindowSize(static_cast<uint16_t>(size.width), static_cast<uint16_t>(size.height));
107 Dali::Any OffscreenWindow::GetNativeHandle() const
109 NativeRenderSurface* surface = GetNativeRenderSurface();
110 DALI_ASSERT_ALWAYS(surface && "surface handle is empty");
112 return surface->GetNativeRenderable();
115 NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
117 return dynamic_cast<NativeRenderSurface*>(mSurface.get());
120 void OffscreenWindow::OnPostRender()
122 Dali::OffscreenWindow handle(this);
123 mPostRenderSignal.Emit(handle, GetNativeHandle());
126 OffscreenWindow::PostRenderSignalType& OffscreenWindow::PostRenderSignal()
128 return mPostRenderSignal;
131 } // namespace Internal