X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fscene-impl.cpp;h=2cc2cdcd404a3b384903bf4742c0bb418b06ad00;hb=79881246746f65474b24ea4fe14151ccef8df3f4;hp=4d00fd0d60a3a1788ad481fc4e5ac4f32c0ed2ac;hpb=094df0544050c853dd5114b13ad582a7fa2f8d06;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/scene-impl.cpp b/dali/internal/event/common/scene-impl.cpp index 4d00fd0..2cc2cdc 100644 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -48,21 +49,21 @@ const Vector4 DEFAULT_BACKGROUND_COLOR(0.0f, 0.0f, 0.0f, 1.0f); // Default backg } //Unnamed namespace -ScenePtr Scene::New( const Size& size ) +ScenePtr Scene::New( Size size ) { - ScenePtr scene = new Scene( size ); + ScenePtr scene = new Scene; // Second-phase construction - scene->Initialize(); + scene->Initialize( size ); return scene; } -Scene::Scene( const Size& size ) -: mSurface( nullptr ), - mSize( size ), - mSurfaceSize( Vector2::ZERO ), - mDpi( Vector2::ZERO ), +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() ) { @@ -70,6 +71,12 @@ Scene::Scene( const Size& size ) 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 @@ -89,11 +96,11 @@ Scene::~Scene() 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 ) { ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); @@ -119,7 +126,7 @@ void Scene::Initialize() // 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())); @@ -128,6 +135,13 @@ void Scene::Initialize() // Create the default render-task mRenderTaskList->CreateTask( mRootLayer.Get(), mDefaultCamera.Get() ); + + SurfaceResized( size.width, size.height ); + + // 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) @@ -190,45 +204,37 @@ Actor& Scene::GetDefaultRootActor() 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( mSurface->GetPositionSize().width ); - mSurfaceSize.height = static_cast( mSurface->GetPositionSize().height ); + Rect< int32_t > newSize( 0, 0, static_cast< int32_t >( width ), static_cast< int32_t >( height ) ); // truncated - mSize.width = mSurfaceSize.width; - mSize.height = mSurfaceSize.height; + mSize.width = width; + mSize.height = height; // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position. - mDefaultCamera->SetPerspectiveProjection( mSurfaceSize ); + mDefaultCamera->SetPerspectiveProjection( mSize ); mRootLayer->SetSize( mSize.width, mSize.height ); ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager(); - SetDefaultSurfaceRectMessage( updateManager, Rect( 0, 0, static_cast( mSurfaceSize.width ), static_cast( mSurfaceSize.height ) ) ); // truncated + SetDefaultSurfaceRectMessage( updateManager, newSize ); + // set default render-task viewport parameters 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( mSurfaceSize.width ), static_cast( mSurfaceSize.height ) ) ); // truncated - } - } - - mFrameBuffer = Dali::Internal::FrameBuffer::New( surface, Dali::FrameBuffer::Attachment::NONE ); - defaultRenderTask->SetFrameBuffer( mFrameBuffer ); + defaultRenderTask->SetViewport( newSize ); } } -Integration::RenderSurface* Scene::GetSurface() const +void Scene::SurfaceReplaced() { - return mSurface; + if ( mSceneObject ) + { + ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); + SurfaceReplacedMessage( tls->GetUpdateManager(), *mSceneObject ); + } } void Scene::Discard() @@ -266,38 +272,68 @@ void Scene::RebuildDepthTree() } } -void Scene::SetBackgroundColor(Vector4 color) +void Scene::SetBackgroundColor( const Vector4& color ) { - if( mSurface ) - { - mSurface->SetBackgroundColor( color ); - } + mBackgroundColor = color; + + mRenderTaskList->GetTask( 0u )->SetClearColor( color ); + mRenderTaskList->GetTask( 0u )->SetClearEnabled( true ); } Vector4 Scene::GetBackgroundColor() const { - return mSurface ? mSurface->GetBackgroundColor() : DEFAULT_BACKGROUND_COLOR; + return mBackgroundColor; +} + +SceneGraph::Scene* Scene::GetSceneObject() const +{ + return mSceneObject; } void Scene::EmitKeyEventSignal(const KeyEvent& event) { - mKeyEventSignal.Emit( event ); + if ( !mKeyEventSignal.Empty() ) + { + Dali::Integration::Scene handle( this ); + mKeyEventSignal.Emit( event ); + } +} + +bool Scene::EmitKeyEventGeneratedSignal(const KeyEvent& event) +{ + // Emit the KeyEventGenerated signal when KeyEvent is generated + return mKeyEventGeneratedSignal.Emit( event ); } void Scene::EmitEventProcessingFinishedSignal() { - mEventProcessingFinishedSignal.Emit(); + if ( !mEventProcessingFinishedSignal.Empty() ) + { + Dali::Integration::Scene handle( this ); + mEventProcessingFinishedSignal.Emit(); + } } void Scene::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch ) { - mTouchedSignal.Emit( touchEvent ); - mTouchSignal.Emit( touch ); + Dali::Integration::Scene handle( this ); + if ( !mTouchedSignal.Empty() ) + { + mTouchedSignal.Emit( touchEvent ); + } + if ( !mTouchSignal.Empty() ) + { + mTouchSignal.Emit( touch ); + } } void Scene::EmitWheelEventSignal(const WheelEvent& event) { - mWheelEventSignal.Emit( event ); + if ( !mWheelEventSignal.Empty() ) + { + Dali::Integration::Scene handle( this ); + mWheelEventSignal.Emit( event ); + } } Integration::Scene::KeyEventSignalType& Scene::KeyEventSignal() @@ -305,6 +341,11 @@ Integration::Scene::KeyEventSignalType& Scene::KeyEventSignal() return mKeyEventSignal; } +Integration::Scene::KeyEventGeneratedSignalType& Scene::KeyEventGeneratedSignal() +{ + return mKeyEventGeneratedSignal; +} + Integration::Scene::EventProcessingFinishedSignalType& Scene::EventProcessingFinishedSignal() { return mEventProcessingFinishedSignal;