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/integration-api/debug.h>
30 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
36 OffscreenWindow* OffscreenWindow::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
38 OffscreenWindow* window = new OffscreenWindow(width, height, surface, isTranslucent);
42 OffscreenWindow::OffscreenWindow(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
43 : mRenderNotification()
46 mSurface = std::unique_ptr<RenderSurfaceInterface>(CreateNativeSurface(SurfaceSize(width, height), surface, isTranslucent));
49 void OffscreenWindow::Initialize(bool isDefaultWindow)
56 Dali::Integration::SceneHolder sceneHolderHandler = Dali::Integration::SceneHolder(this);
57 Dali::Adaptor::Get().AddWindow(sceneHolderHandler);
60 OffscreenWindow::~OffscreenWindow()
62 NativeRenderSurface* surface = GetNativeRenderSurface();
66 // To prevent notification triggering in NativeRenderSurface::PostRender while deleting SceneHolder
67 surface->SetRenderNotification(nullptr);
71 uint32_t OffscreenWindow::GetLayerCount() const
73 return mScene.GetLayerCount();
76 Dali::Layer OffscreenWindow::GetLayer(uint32_t depth) const
78 return mScene.GetLayer(depth);
81 OffscreenWindow::WindowSize OffscreenWindow::GetSize() const
83 Size size = mScene.GetSize();
85 return OffscreenWindow::WindowSize(static_cast<uint16_t>(size.width), static_cast<uint16_t>(size.height));
88 Dali::Any OffscreenWindow::GetNativeHandle() const
90 NativeRenderSurface* surface = GetNativeRenderSurface();
91 DALI_ASSERT_ALWAYS(surface && "surface handle is empty");
93 return surface->GetNativeRenderable();
96 void OffscreenWindow::SetPostRenderCallback(CallbackBase* callback)
98 // Connect callback to be notified when the surface is rendered
99 mPostRenderCallback = std::unique_ptr<CallbackBase>(callback);
100 TriggerEventFactory triggerEventFactory;
102 if(!mRenderNotification)
104 mRenderNotification = std::unique_ptr<TriggerEventInterface>(triggerEventFactory.CreateTriggerEvent(MakeCallback(this, &OffscreenWindow::OnPostRender), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER));
107 NativeRenderSurface* surface = GetNativeRenderSurface();
111 DALI_LOG_ERROR("NativeRenderSurface is null.");
115 surface->SetRenderNotification(mRenderNotification.get());
118 NativeRenderSurface* OffscreenWindow::GetNativeRenderSurface() const
120 return dynamic_cast<NativeRenderSurface*>(mSurface.get());
123 void OffscreenWindow::OnPostRender()
125 NativeRenderSurface* surface = GetNativeRenderSurface();
129 DALI_LOG_ERROR("NativeRenderSurface is null.");
133 Dali::OffscreenWindow handle(this);
134 CallbackBase::Execute(*mPostRenderCallback, handle, surface->GetNativeRenderable());
136 surface->ReleaseLock();
139 } // namespace Internal