/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
// CLASS HEADER
#include <dali/internal/update/common/scene-graph-scene.h>
+// INTERNAL INCLUDES
+#include <dali/integration-api/core-enumerations.h>
#include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
namespace Dali
{
namespace SceneGraph
{
-
Scene::Scene()
-: mContext( nullptr )
+: mFrameRenderedCallbacks(),
+ mFramePresentedCallbacks(),
+ mSkipRendering(false),
+ mSurfaceRect(),
+ mSurfaceOrientation(0),
+ mScreenOrientation(0),
+ mSurfaceRectChanged(false),
+ mRotationCompletedAcknowledgement(false)
{
}
Scene::~Scene()
{
- if ( mContext )
+ mFrameRenderedCallbacks.clear();
+ mFramePresentedCallbacks.clear();
+}
+
+void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
+{
+ mGraphicsController = &graphicsController;
+
+ // Create the render target for the surface. It should already have been sent via message.
+ mRenderTarget = graphicsController.CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
+
+ // Create the render pass for the surface
+ std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
+
+ // Default behaviour for color attachments is to CLEAR and STORE
+ mClearValues.clear();
+ mClearValues.emplace_back();
+
+ // Assume single color attachment
+ Graphics::AttachmentDescription desc{};
+ desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
+ desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
+ attachmentDescriptions.push_back(desc);
+
+ if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
+ stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
{
- mContext->GlContextDestroyed();
+ // Depth
+ desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
+ desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
+
+ // Stencil
+ desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
+ desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
+ attachmentDescriptions.push_back(desc);
- delete mContext;
- mContext = nullptr;
+ mClearValues.emplace_back();
+ mClearValues.back().depthStencil.depth = 0;
+ mClearValues.back().depthStencil.stencil = 0;
}
+
+ Graphics::RenderPassCreateInfo rpInfo{};
+ rpInfo.SetAttachments(attachmentDescriptions);
+
+ // Add default render pass (loadOp = clear)
+ mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
+
+ desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
+ attachmentDescriptions[0] = desc;
+ if(attachmentDescriptions.size() > 1)
+ {
+ desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
+ desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
+ attachmentDescriptions.back() = desc;
+ }
+
+ mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
}
-void Scene::GlContextDestroyed()
+RenderInstructionContainer& Scene::GetRenderInstructions()
{
- if ( mContext )
+ return mInstructions;
+}
+
+void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
+{
+ mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
+}
+
+void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
+{
+ mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
+}
+
+void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
+{
+ // Transfer owership of the callbacks
+ for(auto&& iter : mFrameRenderedCallbacks)
{
- mContext->GlContextDestroyed();
+ callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
}
+
+ mFrameRenderedCallbacks.clear();
}
-void Scene::Initialize( Context& context )
+void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
{
- if ( mContext != &context )
+ // Transfer owership of the callbacks
+ for(auto&& iter : mFramePresentedCallbacks)
{
- if ( mContext )
- {
- mContext->GlContextDestroyed();
- delete mContext;
- }
+ callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
+ }
+
+ mFramePresentedCallbacks.clear();
+}
+
+void Scene::SetSkipRendering(bool skip)
+{
+ mSkipRendering = skip;
+}
+
+bool Scene::IsRenderingSkipped() const
+{
+ return mSkipRendering;
+}
- mContext = &context;
- mContext->GlContextCreated();
+void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
+{
+ mSurfaceRect = rect;
+ mSurfaceRectChanged = true;
+
+ DALI_LOG_RELEASE_INFO("update surfce rect in scene-graph, width[%d], height[%d]\n", mSurfaceRect.width, mSurfaceRect.height);
+
+ if(mRoot)
+ {
+ mRoot->SetUpdated(true);
}
}
-Context* Scene::GetContext()
+const Rect<int32_t>& Scene::GetSurfaceRect() const
{
- return mContext;
+ return mSurfaceRect;
}
-RenderInstructionContainer& Scene::GetRenderInstructions()
+bool Scene::IsSurfaceRectChanged()
{
- return mInstructions;
+ bool surfaceRectChanged = mSurfaceRectChanged;
+ mSurfaceRectChanged = false;
+
+ return surfaceRectChanged;
+}
+
+void Scene::SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation)
+{
+ mSurfaceOrientation = windowOrientation;
+ mScreenOrientation = screenOrienation;
+
+ if(mRoot)
+ {
+ mRoot->SetUpdated(true);
+ }
+
+ DALI_LOG_RELEASE_INFO("update orientation in scene-graph, surface [%d], screen[%d]\n", mSurfaceOrientation, mScreenOrientation);
+}
+
+int32_t Scene::GetSurfaceOrientation() const
+{
+ return mSurfaceOrientation;
+}
+
+int32_t Scene::GetScreenOrientation() const
+{
+ return mScreenOrientation;
+}
+
+void Scene::SetRotationCompletedAcknowledgement()
+{
+ mRotationCompletedAcknowledgement = true;
+}
+
+bool Scene::IsRotationCompletedAcknowledgementSet()
+{
+ bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
+ mRotationCompletedAcknowledgement = false;
+ return setRotationCompletedAcknowledgement;
+}
+
+Scene::ItemsDirtyRectsContainer& Scene::GetItemsDirtyRects()
+{
+ return mItemsDirtyRects;
+}
+
+void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
+{
+ if(mRenderTarget != nullptr &&
+ mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
+ {
+ // Only recreate if the surface has changed.
+ mRenderTargetCreateInfo = renderTargetCreateInfo;
+ if(mGraphicsController) // shouldn't be null, as we can't have already set mRenderTarget unless graphics controller exists.
+ {
+ mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
+ }
+ }
+ else
+ {
+ // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
+ mRenderTargetCreateInfo = renderTargetCreateInfo;
+ }
}
-} //SceneGraph
+} // namespace SceneGraph
-} //Internal
+} // namespace Internal
-} //Dali
+} // namespace Dali