/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/actors/actor.h>
#include <dali/public-api/actors/layer.h>
#include <dali/public-api/common/dali-common.h>
-#include <sys/time.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
// INTERNAL INCLUDES
#include <dali/internal/adaptor/common/adaptor-impl.h>
#include <dali/internal/graphics/gles/egl-graphics.h>
#include <dali/internal/input/common/key-impl.h>
#include <dali/internal/input/common/physical-keyboard-impl.h>
+#include <dali/internal/system/common/time-service.h>
namespace Dali
{
#if defined(DEBUG_ENABLED)
Debug::Filter* gSceneHolderLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SCENE_HOLDER");
#endif
-
-// Copied from x server
-static uint32_t GetCurrentMilliSeconds(void)
-{
- struct timeval tv;
-
- struct timespec tp;
- static clockid_t clockid;
-
- if(!clockid)
- {
-#ifdef CLOCK_MONOTONIC_COARSE
- if(clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
- (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
- {
- clockid = CLOCK_MONOTONIC_COARSE;
- }
- else
-#endif
- if(clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
- {
- clockid = CLOCK_MONOTONIC;
- }
- else
- {
- clockid = ~0L;
- }
- }
- if(clockid != ~0L && clock_gettime(clockid, &tp) == 0)
- {
- return static_cast<uint32_t>((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L));
- }
-
- gettimeofday(&tv, NULL);
- return static_cast<uint32_t>((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
-}
-
} // unnamed namespace
uint32_t SceneHolder::mSceneHolderCounter = 0;
SceneHolder::~SceneHolder()
{
+ if(mScene)
+ {
+ // The scene graph object should be removed first.
+ mScene.RemoveSceneObject();
+ }
+
if(mAdaptor)
{
mAdaptor->RemoveObserver(*mLifeCycleObserver.get());
mAdaptor->RemoveWindow(this);
+ // The event queue is flushed and we wait for the completion of the surface removal
mAdaptor->DeleteSurface(*mSurface.get());
mAdaptor = nullptr;
if(mScene)
{
+ // We should remove the surface from the Core last
mScene.Discard();
}
}
return mScene ? mScene.GetRootLayer() : Dali::Layer();
}
+Dali::Layer SceneHolder::GetOverlayLayer()
+{
+ return mScene ? mScene.GetOverlayLayer() : Dali::Layer();
+}
+
uint32_t SceneHolder::GetId() const
{
return mId;
mScene.SurfaceReplaced();
- SurfaceResized(false);
+ PositionSize surfacePositionSize = surface->GetPositionSize();
+
+ SurfaceResized(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height));
InitializeDpi();
mSurface->SetAdaptor(*mAdaptor);
mSurface->SetScene(mScene);
+ // Recreate the render target
+ CreateRenderTarget();
+
OnSurfaceSet(surface);
}
-void SceneHolder::SurfaceResized(bool forceUpdate)
+void SceneHolder::SurfaceResized(float width, float height)
{
- PositionSize surfacePositionSize = mSurface->GetPositionSize();
- int orientation = mSurface->GetOrientation();
- mScene.SurfaceResized(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height), orientation, forceUpdate);
+ if(DALI_LIKELY(mScene))
+ {
+ mScene.SurfaceResized(width, height);
+ }
mSurface->SetFullSwapNextFrame();
+
+ // Recreate the render target
+ CreateRenderTarget();
}
Dali::RenderSurfaceInterface* SceneHolder::GetSurface() const
// Create the scene
PositionSize surfacePositionSize = mSurface->GetPositionSize();
- int orientation = mSurface->GetOrientation();
- mScene = Dali::Integration::Scene::New( Size(static_cast<float>( surfacePositionSize.width ), static_cast<float>( surfacePositionSize.height )), orientation );
+ int windowOrientation = mSurface->GetSurfaceOrientation();
+ int screenOrientation = mSurface->GetScreenOrientation();
+
+ mScene = Dali::Integration::Scene::New(Size(static_cast<float>(surfacePositionSize.width), static_cast<float>(surfacePositionSize.height)), windowOrientation, screenOrientation);
Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
mAdaptor = &adaptorImpl;
mSurface->SetAdaptor(*mAdaptor);
mSurface->SetScene(mScene);
+ // Create the render target
+ CreateRenderTarget();
+
OnAdaptorSet(adaptor);
+
+ // Scene is newly created. Let we increase resize counter
+ mAdaptor->IncreaseSurfaceResizeCounter();
+}
+
+void SceneHolder::CreateRenderTarget()
+{
+ Graphics::RenderTargetCreateInfo rtInfo{};
+ rtInfo
+ .SetSurface(mSurface.get())
+ .SetExtent({static_cast<uint32_t>(mSurface->GetPositionSize().width), static_cast<uint32_t>(mSurface->GetPositionSize().height)})
+ .SetPreTransform(0 | Graphics::RenderTargetTransformFlagBits::TRANSFORM_IDENTITY_BIT);
+
+ mScene.SetSurfaceRenderTarget(rtInfo);
}
void SceneHolder::Pause()
OnResume();
}
+void SceneHolder::SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation)
+{
+ if(DALI_LIKELY(mScene))
+ {
+ mScene.SurfaceRotated(width, height, windowOrientation, screenOrientation);
+ }
+}
+
+void SceneHolder::SetRotationCompletedAcknowledgement()
+{
+ if(DALI_LIKELY(mScene))
+ {
+ mScene.SetRotationCompletedAcknowledgement();
+ }
+}
+
void SceneHolder::FeedTouchPoint(Dali::Integration::Point& point, int timeStamp)
{
if(timeStamp < 1)
{
- timeStamp = GetCurrentMilliSeconds();
+ timeStamp = TimeService::GetMilliSeconds();
}
- RecalculateTouchPosition(point);
+ Vector2 convertedPosition = RecalculatePosition(point.GetScreenPosition());
+ point.SetScreenPosition(convertedPosition);
Integration::TouchEvent touchEvent;
Integration::HoverEvent hoverEvent;
// Keep the handle alive until the core events are processed.
Dali::BaseHandle sceneHolder(this);
+ Vector2 convertedPosition = RecalculatePosition(wheelEvent.point);
+ wheelEvent.point = convertedPosition;
+
mScene.QueueEvent(wheelEvent);
mAdaptor->ProcessCoreEvents();
}
{
mScene.AddFrameRenderedCallback(std::move(callback), frameId);
- DALI_LOG_INFO(gSceneHolderLogFilter, Debug::General, "SceneHolder::AddFrameRenderedCallback:: Added [%d]\n", frameId);
+ DALI_LOG_RELEASE_INFO("SceneHolder::AddFrameRenderedCallback:: Added [%d]\n", frameId);
}
void SceneHolder::AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId)
{
mScene.AddFramePresentedCallback(std::move(callback), frameId);
- DALI_LOG_INFO(gSceneHolderLogFilter, Debug::General, "SceneHolder::AddFramePresentedCallback:: Added [%d]\n", frameId);
+ DALI_LOG_RELEASE_INFO("SceneHolder::AddFramePresentedCallback:: Added [%d]\n", frameId);
+}
+
+Dali::RenderTaskList SceneHolder::GetRenderTaskList() const
+{
+ return mScene.GetRenderTaskList();
}
Dali::Integration::SceneHolder SceneHolder::Get(Dali::Actor actor)