/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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/internal/event/common/object-registry-impl.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/manager/update-manager.h>
+#include <dali/internal/update/common/scene-graph-scene.h>
+#include <dali/public-api/common/constants.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/render-tasks/render-task-list.h>
#include <dali/internal/event/rendering/frame-buffer-impl.h>
namespace Internal
{
-namespace
+ScenePtr Scene::New(Size size, int orientation)
{
-
-const Vector4 DEFAULT_BACKGROUND_COLOR(0.0f, 0.0f, 0.0f, 1.0f); // Default background color
-
-} //Unnamed namespace
-
-ScenePtr Scene::New( const Size& size )
-{
- ScenePtr scene = new Scene( size );
+ ScenePtr scene = new Scene;
// Second-phase construction
- scene->Initialize();
+ scene->Initialize(size, orientation);
return scene;
}
-Scene::Scene( const Size& size )
-: mSurface( nullptr ),
- mSize( size ),
- mSurfaceSize( Vector2::ZERO ),
- mDpi( Vector2::ZERO ),
- mDepthTreeDirty( false ),
- mEventProcessor( *this, ThreadLocalStorage::GetInternal()->GetGestureEventProcessor() )
+Scene::Scene()
+: mSceneObject(nullptr),
+ mSize(), // Don't set the proper value here, this will be set when the surface is set later
+ mDpi(),
+ mBackgroundColor(DEFAULT_BACKGROUND_COLOR),
+ mDepthTreeDirty(false),
+ mEventProcessor(*this, ThreadLocalStorage::GetInternal()->GetGestureEventProcessor()),
+ mSurfaceOrientation(0)
{
}
Scene::~Scene()
{
+ if( EventThreadServices::IsCoreRunning() && mSceneObject )
+ {
+ ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+ RemoveSceneMessage( tls->GetUpdateManager(), *mSceneObject );
+ }
+
if( mDefaultCamera )
{
// its enough to release the handle so the object is released
mRenderTaskList.Reset();
}
- // Discard this Scene from the Core
- Discard();
+ // No need to discard this Scene from Core, as Core stores an intrusive_ptr to this scene
+ // When this destructor is called, the scene has either already been removed from Core or Core has already been destroyed
}
-void Scene::Initialize()
+void Scene::Initialize(Size size, int orientation)
{
ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
// Create the default camera actor first; this is needed by the RenderTaskList
// The default camera attributes and position is such that children of the default layer,
// can be positioned at (0,0) and be at the top-left of the viewport.
- mDefaultCamera = CameraActor::New( mSize );
+ mDefaultCamera = CameraActor::New( size );
mDefaultCamera->SetParentOrigin(ParentOrigin::CENTER);
Add(*(mDefaultCamera.Get()));
// Create the list of render-tasks
mRenderTaskList = RenderTaskList::New();
- // Create the default render-task
- mRenderTaskList->CreateTask( mRootLayer.Get(), mDefaultCamera.Get() );
+ // Create the default render-task and ensure clear is enabled on it to show the background color
+ RenderTaskPtr renderTask = mRenderTaskList->CreateTask( mRootLayer.Get(), mDefaultCamera.Get() );
+ renderTask->SetClearEnabled(true);
+ mSurfaceOrientation = orientation;
+
+ SurfaceRotated( size.width, size.height, mSurfaceOrientation );
+
+ // Create scene graph object
+ mSceneObject = new SceneGraph::Scene();
+ OwnerPointer< SceneGraph::Scene > transferOwnership( const_cast< SceneGraph::Scene* >( mSceneObject ) );
+ AddSceneMessage( updateManager, transferOwnership );
}
void Scene::Add(Actor& actor)
return *mRootLayer;
}
-void Scene::SetSurface( Integration::RenderSurface& surface )
+void Scene::SurfaceResized(float width, float height)
{
- mSurface = &surface;
- if ( mSurface )
+ if((fabsf(mSize.width - width) > Math::MACHINE_EPSILON_1) || (fabsf(mSize.height - height) > Math::MACHINE_EPSILON_1))
{
- mSurfaceSize.width = static_cast<float>( mSurface->GetPositionSize().width );
- mSurfaceSize.height = static_cast<float>( mSurface->GetPositionSize().height );
-
- mSize.width = mSurfaceSize.width;
- mSize.height = mSurfaceSize.height;
-
- // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
- mDefaultCamera->SetPerspectiveProjection( mSurfaceSize );
-
- mRootLayer->SetSize( mSize.width, mSize.height );
-
- ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
- SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager();
- SetDefaultSurfaceRectMessage( updateManager, Rect<int32_t>( 0, 0, static_cast<int32_t>( mSurfaceSize.width ), static_cast<int32_t>( mSurfaceSize.height ) ) ); // truncated
-
- RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u );
-
- // if single render task to screen then set its viewport parameters
- if( 1 == mRenderTaskList->GetTaskCount() )
- {
- if( !defaultRenderTask->GetTargetFrameBuffer() )
- {
- defaultRenderTask->SetViewport( Viewport( 0, 0, static_cast<int32_t>( mSurfaceSize.width ), static_cast<int32_t>( mSurfaceSize.height ) ) ); // truncated
- }
- }
-
- mFrameBuffer = Dali::Internal::FrameBuffer::New( surface, Dali::FrameBuffer::Attachment::NONE );
- defaultRenderTask->SetFrameBuffer( mFrameBuffer );
+ ChangedSurface(width, height, mSurfaceOrientation);
}
}
-Integration::RenderSurface* Scene::GetSurface() const
+void Scene::SurfaceReplaced()
{
- return mSurface;
+ if ( mSceneObject )
+ {
+ ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+ SurfaceReplacedMessage( tls->GetUpdateManager(), *mSceneObject );
+ }
}
void Scene::Discard()
}
}
-void Scene::SetBackgroundColor(Vector4 color)
+void Scene::SetBackgroundColor( const Vector4& color )
{
- if( mSurface )
+ mBackgroundColor = color;
+
+ mRenderTaskList->GetTask( 0u )->SetClearColor( color );
+ mRenderTaskList->GetTask( 0u )->SetClearEnabled( true );
+}
+
+Vector4 Scene::GetBackgroundColor() const
+{
+ return mBackgroundColor;
+}
+
+SceneGraph::Scene* Scene::GetSceneObject() const
+{
+ return mSceneObject;
+}
+
+void Scene::EmitKeyEventSignal(const Dali::KeyEvent& event)
+{
+ if ( !mKeyEventSignal.Empty() )
{
- mSurface->SetBackgroundColor( color );
+ Dali::Integration::Scene handle( this );
+ mKeyEventSignal.Emit( event );
}
}
-Vector4 Scene::GetBackgroundColor() const
+void Scene::SurfaceRotated(float width, float height, int orientation)
+{
+ mSurfaceOrientation = orientation;
+ ChangedSurface(width, height, orientation);
+}
+
+int Scene::GetSurfaceOrientation()
+{
+ return mSurfaceOrientation;
+}
+
+void Scene::ChangedSurface(float width, float height, int orientation)
{
- return mSurface ? mSurface->GetBackgroundColor() : DEFAULT_BACKGROUND_COLOR;
+ Rect<int32_t> newSize(0, 0, static_cast<int32_t>(width), static_cast<int32_t>(height)); // truncated
+
+ mSize.width = width;
+ mSize.height = height;
+
+ // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
+ mDefaultCamera->SetPerspectiveProjection(mSize);
+ // Set the surface orientation to Default camera for window/screen rotation
+ mDefaultCamera->RotateProjection(orientation);
+
+ mRootLayer->SetSize(width, height);
+
+ ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+ SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager();
+ SetDefaultSurfaceRectMessage(updateManager, newSize);
+
+ // Send the surface orientation to render manager for calculating glViewport/Scissor
+ SetDefaultSurfaceOrientationMessage(updateManager, orientation);
+
+ // set default render-task viewport parameters
+ RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask(0u);
+ defaultRenderTask->SetViewport(newSize);
}
-void Scene::EmitKeyEventSignal(const KeyEvent& event)
+bool Scene::EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event)
{
- mKeyEventSignal.Emit( event );
+ // Emit the KeyEventGenerated signal when KeyEvent is generated
+ Dali::Integration::Scene handle( this );
+ return mKeyEventGeneratedSignal.Emit( event );
}
void Scene::EmitEventProcessingFinishedSignal()
{
- mEventProcessingFinishedSignal.Emit();
+ if ( !mEventProcessingFinishedSignal.Empty() )
+ {
+ Dali::Integration::Scene handle( this );
+ mEventProcessingFinishedSignal.Emit();
+ }
+}
+
+void Scene::EmitTouchedSignal( const Dali::TouchEvent& touch )
+{
+ Dali::Integration::Scene handle( this );
+ if ( !mTouchedSignal.Empty() )
+ {
+ mTouchedSignal.Emit( touch );
+ }
}
-void Scene::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch )
+void Scene::EmitWheelEventSignal(const Dali::WheelEvent& event)
{
- mTouchedSignal.Emit( touchEvent );
- mTouchSignal.Emit( touch );
+ if ( !mWheelEventSignal.Empty() )
+ {
+ Dali::Integration::Scene handle( this );
+ mWheelEventSignal.Emit( event );
+ }
}
-void Scene::EmitWheelEventSignal(const WheelEvent& event)
+void Scene::AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId )
{
- mWheelEventSignal.Emit( event );
+ ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+ AddFrameRenderedCallbackMessage( tls->GetEventThreadServices(), *mSceneObject, callback.release(), frameId );
+}
+
+void Scene::AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId )
+{
+ ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+ AddFramePresentedCallbackMessage( tls->GetEventThreadServices(), *mSceneObject, callback.release(), frameId );
+}
+
+void Scene::GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks )
+{
+ mSceneObject->GetFrameRenderedCallback( callbacks );
+}
+
+void Scene::GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks )
+{
+ mSceneObject->GetFramePresentedCallback( callbacks );
}
Integration::Scene::KeyEventSignalType& Scene::KeyEventSignal()
return mKeyEventSignal;
}
+Integration::Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal()
+{
+ return mKeyEventGeneratedSignal;
+}
+
Integration::Scene::EventProcessingFinishedSignalType& Scene::EventProcessingFinishedSignal()
{
return mEventProcessingFinishedSignal;
}
-Scene::TouchedSignalType& Scene::TouchedSignal()
+Integration::Scene::TouchEventSignalType& Scene::TouchedSignal()
{
return mTouchedSignal;
}
-Integration::Scene::TouchSignalType& Scene::TouchSignal()
+Integration::Scene::WheelEventSignalType& Scene::WheelEventSignal()
{
- return mTouchSignal;
+ return mWheelEventSignal;
}
-Integration::Scene::WheelEventSignalType& Scene::WheelEventSignal()
+std::vector<Dali::Internal::SceneGraph::DirtyRect>& Scene::GetItemsDirtyRects()
{
- return mWheelEventSignal;
+ return mItemsDirtyRects;
}
} // Internal