X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fscene-impl.cpp;h=82f519604aca66dc5eb6f132c64677478d7c785d;hb=55827866fcb8c7ee47581ac4335a3390472090e8;hp=f68060ea533392e43bf01d713f020b966d0c25a0;hpb=da298bea0d5f6dd40092511fcd255b423ceb79e3;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 old mode 100644 new mode 100755 index f68060e..82f5196 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -48,22 +48,24 @@ const Vector4 DEFAULT_BACKGROUND_COLOR(0.0f, 0.0f, 0.0f, 1.0f); // Default backg } //Unnamed namespace -ScenePtr Scene::New( Size size ) +ScenePtr Scene::New( Integration::RenderSurface& surface ) { - ScenePtr scene = new Scene( size ); + ScenePtr scene = new Scene; // Second-phase construction - scene->Initialize(); + scene->Initialize( surface ); return scene; } -Scene::Scene( Size size ) +Scene::Scene() : mSurface( nullptr ), - mSize( size ), - mSurfaceSize( Vector2::ZERO ), - mDpi( Vector2::ZERO ), - mDepthTreeDirty( false ) + mSize(), // Don't set the proper value here, this will be set when the surface is set later + mDpi(), + mBackgroundColor( DEFAULT_BACKGROUND_COLOR ), + mSurfaceOrientation( 0 ), + mDepthTreeDirty( false ), + mEventProcessor( *this, ThreadLocalStorage::GetInternal()->GetGestureEventProcessor() ) { } @@ -88,14 +90,16 @@ Scene::~Scene() mRenderTaskList.Reset(); } - if( ThreadLocalStorage::Created() ) + if ( mFrameBuffer ) { - ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); - tls->RemoveScene( this ); + mFrameBuffer.Reset(); } + + // 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( Integration::RenderSurface& surface ) { ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); @@ -108,8 +112,8 @@ void Scene::Initialize() // Create the ordered list of layers mLayerList = LayerList::New( updateManager ); - // The stage owns the default layer - mRootLayer = Layer::NewRoot( *mLayerList, updateManager ); + // The scene owns the default layer + mRootLayer = Layer::NewRoot( *mLayerList ); mRootLayer->SetName("RootLayer"); mRootLayer->SetScene( *this ); @@ -121,7 +125,9 @@ 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 ); + const PositionSize positionSize = surface.GetPositionSize(); + const Vector2 surfaceSize( static_cast< float >( positionSize.width ), static_cast< float >( positionSize.height ) ); + mDefaultCamera = CameraActor::New( surfaceSize ); mDefaultCamera->SetParentOrigin(ParentOrigin::CENTER); Add(*(mDefaultCamera.Get())); @@ -130,6 +136,9 @@ void Scene::Initialize() // Create the default render-task mRenderTaskList->CreateTask( mRootLayer.Get(), mDefaultCamera.Get() ); + + // Set the surface + SetSurface( surface ); } void Scene::Add(Actor& actor) @@ -140,6 +149,10 @@ void Scene::Add(Actor& actor) void Scene::Remove(Actor& actor) { mRootLayer->Remove( actor ); + if( mSurface ) + { + mRenderTaskList->GetTask( 0u )->GetFrameBuffer()->SetPartialUpdateEnabled( false ); + } } Size Scene::GetSize() const @@ -194,37 +207,64 @@ Actor& Scene::GetDefaultRootActor() void Scene::SetSurface( Integration::RenderSurface& surface ) { - mSurface = &surface; - if ( mSurface ) + if( mSurface != &surface ) { - mSurfaceSize.width = static_cast( mSurface->GetPositionSize().width ); - mSurfaceSize.height = static_cast( mSurface->GetPositionSize().height ); + mSurface = &surface; + + RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u ); + + mFrameBuffer = Dali::Internal::FrameBuffer::New( surface, Dali::FrameBuffer::Attachment::NONE ); + defaultRenderTask->SetFrameBuffer( mFrameBuffer ); - mSize.width = mSurfaceSize.width; - mSize.height = mSurfaceSize.height; + SurfaceResized( false ); + } +} - // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position. - mDefaultCamera->SetPerspectiveProjection( mSurfaceSize ); +void Scene::SurfaceResized( bool forceUpdate ) +{ + if( mSurface ) + { + const PositionSize surfacePositionSize = mSurface->GetPositionSize(); + const float fWidth = static_cast< float >( surfacePositionSize.width ); + const float fHeight = static_cast< float >( surfacePositionSize.height ); + const int orientation = mSurface->GetOrientation(); + + if( ( ( fabsf( mSize.width - fWidth ) > Math::MACHINE_EPSILON_1 ) || ( fabsf( mSize.height - fHeight ) > Math::MACHINE_EPSILON_1 ) ) + || ( orientation != mSurfaceOrientation ) + || ( forceUpdate ) ) + { + Rect< int32_t > newSize( 0, 0, static_cast< int32_t >( surfacePositionSize.width ), static_cast< int32_t >( surfacePositionSize.height ) ); // truncated - mRootLayer->SetSize( mSize.width, mSize.height ); + mSize.width = fWidth; + mSize.height = fHeight; + mSurfaceOrientation = orientation; - ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); - SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager(); - SetDefaultSurfaceRectMessage( updateManager, Rect( 0, 0, static_cast( mSurfaceSize.width ), static_cast( mSurfaceSize.height ) ) ); // truncated + // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position. + mDefaultCamera->SetPerspectiveProjection( mSize ); + mDefaultCamera->RotateProjection( mSurfaceOrientation ); - RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u ); + mRootLayer->SetSize( mSize.width, mSize.height ); - // 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 - } + ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); + SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager(); + SetDefaultSurfaceRectMessage( updateManager, newSize ); + SetDefaultSurfaceOrientationMessage( updateManager, mSurfaceOrientation ); + + // set default render-task viewport parameters + RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u ); + defaultRenderTask->SetViewport( newSize ); + defaultRenderTask->GetFrameBuffer()->SetSize( static_cast( newSize.width ), static_cast( newSize.height ) ); } + } +} - mFrameBuffer = Dali::Internal::FrameBuffer::New( surface, Dali::FrameBuffer::Attachment::NONE ); - defaultRenderTask->SetFrameBuffer( mFrameBuffer ); +void Scene::SurfaceDeleted() +{ + mSurface = nullptr; + if ( mFrameBuffer ) + { + // The frame buffer doesn't have a valid render surface any more. + mFrameBuffer->MarkSurfaceAsInvalid(); } } @@ -233,11 +273,30 @@ Integration::RenderSurface* Scene::GetSurface() const return mSurface; } +void Scene::Discard() +{ + if( ThreadLocalStorage::Created() ) + { + ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); + tls->RemoveScene( this ); + } +} + void Scene::RequestRebuildDepthTree() { mDepthTreeDirty = true; } +void Scene::QueueEvent( const Integration::Event& event ) +{ + mEventProcessor.QueueEvent( event ); +} + +void Scene::ProcessEvents() +{ + mEventProcessor.ProcessEvents(); +} + void Scene::RebuildDepthTree() { // If the depth tree needs rebuilding, do it in this frame only. @@ -249,19 +308,96 @@ void Scene::RebuildDepthTree() } } -void Scene::SetBackgroundColor(Vector4 color) +void Scene::SetBackgroundColor( const Vector4& color ) { + mBackgroundColor = color; + if( mSurface ) { - mSurface->SetBackgroundColor( color ); + mRenderTaskList->GetTask( 0u )->GetFrameBuffer()->SetBackgroundColor( color ); } } Vector4 Scene::GetBackgroundColor() const { - return mSurface ? mSurface->GetBackgroundColor() : DEFAULT_BACKGROUND_COLOR; + return mBackgroundColor; +} + +void Scene::EmitKeyEventSignal(const KeyEvent& 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() +{ + if ( !mEventProcessingFinishedSignal.Empty() ) + { + Dali::Integration::Scene handle( this ); + mEventProcessingFinishedSignal.Emit(); + } } +void Scene::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch ) +{ + Dali::Integration::Scene handle( this ); + if ( !mTouchedSignal.Empty() ) + { + mTouchedSignal.Emit( touchEvent ); + } + if ( !mTouchSignal.Empty() ) + { + mTouchSignal.Emit( touch ); + } +} + +void Scene::EmitWheelEventSignal(const WheelEvent& event) +{ + if ( !mWheelEventSignal.Empty() ) + { + Dali::Integration::Scene handle( this ); + mWheelEventSignal.Emit( event ); + } +} + +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() +{ + return mTouchedSignal; +} + +Integration::Scene::TouchSignalType& Scene::TouchSignal() +{ + return mTouchSignal; +} + +Integration::Scene::WheelEventSignalType& Scene::WheelEventSignal() +{ + return mWheelEventSignal; +} } // Internal