From: Adeel Kazmi Date: Tue, 23 Jul 2019 15:34:03 +0000 (+0100) Subject: Pass surface into scene constructor X-Git-Tag: dali_1.4.30~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=7dbf40bfe8bc0c503e94e3943553a697384d1a3c Pass surface into scene constructor Change-Id: I8676ca5d99df13f4e47f23a8443075343cd0e049 --- diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp index 7ffb5e5..f3029fa 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp @@ -78,8 +78,7 @@ void TestApplication::CreateCore() void TestApplication::CreateScene() { mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) ); - mScene = Dali::Integration::Scene::New( Vector2( static_cast( mSurfaceWidth ), static_cast( mSurfaceHeight ) ) ); - mScene.SetSurface( *mRenderSurface ); + mScene = Dali::Integration::Scene::New( *mRenderSurface ); mScene.SetDpi( Vector2( static_cast( mDpi.x ), static_cast( mDpi.y ) ) ); } diff --git a/automated-tests/src/dali/utc-Dali-Scene.cpp b/automated-tests/src/dali/utc-Dali-Scene.cpp index 0a4c13b..6e44ca7 100644 --- a/automated-tests/src/dali/utc-Dali-Scene.cpp +++ b/automated-tests/src/dali/utc-Dali-Scene.cpp @@ -141,7 +141,8 @@ struct TouchFunctor if ( signalData.createNewScene ) { - Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); + TestRenderSurface* surface = new TestRenderSurface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); // This is a leak, but we need to keep the surface alive till the end + Dali::Integration::Scene scene = Dali::Integration::Scene::New( *surface ); DALI_TEST_CHECK( scene ); signalData.newSceneCreated = true; @@ -361,7 +362,8 @@ int UtcDaliSceneDiscard(void) tet_infoline("Testing Dali::Scene::Discard"); // Create a new Scene - Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); + TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); + Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface ); DALI_TEST_CHECK( scene ); // One reference of scene kept here and the other one kept in the Core @@ -431,13 +433,10 @@ int UtcDaliSceneRootLayerAndSceneAlignment(void) TestApplication application; // Create a Scene - Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); + TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); + Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface ); DALI_TEST_CHECK( scene ); - // Create the render surface for the scene - TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) ); - scene.SetSurface( *renderSurface ); - // One reference of scene kept here and the other one kept in the Core DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 ); @@ -470,7 +469,8 @@ int UtcDaliSceneRootLayerAndSceneAlignment(void) DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 ); // Create a new Scene while the root layer of the deleted scene is still alive - Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); + TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); + Dali::Integration::Scene newScene = Dali::Integration::Scene::New( surface2 ); DALI_TEST_CHECK( newScene ); // Render and notify. @@ -495,13 +495,12 @@ int UtcDaliSceneDeleteSurface(void) { TestApplication application; - // Create a Scene - Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); - DALI_TEST_CHECK( scene ); - // Create the render surface for the scene TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) ); - scene.SetSurface( *renderSurface ); + + // Create a Scene + Dali::Integration::Scene scene = Dali::Integration::Scene::New( *renderSurface ); + DALI_TEST_CHECK( scene ); // Render and notify. application.SendNotification(); @@ -882,7 +881,8 @@ int UtcDaliSceneEnsureEmptySceneCleared(void) auto defaultScene = application.GetScene(); defaultScene.SetBackgroundColor( Color::WHITE ); - auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) ); + TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); + auto newScene = Integration::Scene::New( surface ); newScene.SetBackgroundColor( Color::RED ); // Need to create a renderable as we don't start rendering until we have at least one @@ -905,7 +905,8 @@ int UtcDaliSceneEnsureEmptySceneCleared(void) // Add another scene and set its background color, ensure we clear it to the appropriate color - auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) ); + TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); + auto thirdScene = Integration::Scene::New( surface2 ); thirdScene.SetBackgroundColor( Color::BLUE ); clearCountBefore = glAbstraction.GetClearCountCalled(); @@ -951,9 +952,8 @@ int UtcDaliSceneSurfaceResizedAdditionalScene(void) TestApplication application; Vector2 originalSurfaceSize( 500.0f, 1000.0f ); - auto scene = Integration::Scene::New( Vector2::ZERO ); TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) ); - scene.SetSurface( surface ); + auto scene = Integration::Scene::New( surface ); // Ensure stage size does NOT match the surface size auto stage = Stage::GetCurrent(); @@ -973,3 +973,31 @@ int UtcDaliSceneSurfaceResizedAdditionalScene(void) END_TEST; } + +int UtcDaliSceneSetSurface(void) +{ + tet_infoline( "Scene::SetSurface test" ); + + TestApplication application; + + // Create a scene with a surface and ensure the size and surface is set correctly on the scene + Vector2 surfaceSize( 480.0f, 800.0f ); + TestRenderSurface surface( PositionSize( 0.0f, 0.0f, surfaceSize.width, surfaceSize.height ) ); + auto scene = Integration::Scene::New( surface ); + DALI_TEST_EQUALS( scene.GetSize(), surfaceSize, TEST_LOCATION ); + DALI_TEST_CHECK( scene.GetSurface() == &surface ); + + // Create a new surface and set that on the scene + Vector2 newSurfaceSize( 1000.0f, 1000.0f ); + TestRenderSurface newSurface( PositionSize( 0.0f, 0.0f, newSurfaceSize.width, newSurfaceSize.height ) ); + scene.SetSurface( newSurface ); + DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION ); + DALI_TEST_CHECK( scene.GetSurface() == &newSurface ); + + // Ensure setting the same surface again doesn't have any side effects + scene.SetSurface( newSurface ); + DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION ); + DALI_TEST_CHECK( scene.GetSurface() == &newSurface ); + + END_TEST; +} diff --git a/dali/integration-api/scene.cpp b/dali/integration-api/scene.cpp index 5860a3a..38e2477 100644 --- a/dali/integration-api/scene.cpp +++ b/dali/integration-api/scene.cpp @@ -29,9 +29,9 @@ namespace Dali namespace Integration { -Scene Scene::New( const Size& size ) +Scene Scene::New( Integration::RenderSurface& surface ) { - Internal::ScenePtr internal = Internal::Scene::New( size ); + Internal::ScenePtr internal = Internal::Scene::New( surface ); return Scene( internal.Get() ); } diff --git a/dali/integration-api/scene.h b/dali/integration-api/scene.h index dcc95b3..c53c413 100755 --- a/dali/integration-api/scene.h +++ b/dali/integration-api/scene.h @@ -61,11 +61,11 @@ public: /** * @brief Create an initialized Scene handle. * - * @param[in] size The size of the scene in pixels as a Vector + * @param[in] surface Binds this rendering surface to this scene * * @return a handle to a newly allocated Dali resource. */ - static Scene New( const Size& size ); + static Scene New( Integration::RenderSurface& surface ); /** * @brief Downcast an Object handle to Scene handle. diff --git a/dali/internal/event/common/scene-impl.cpp b/dali/internal/event/common/scene-impl.cpp index 19be8cc..6055dc6 100644 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -48,21 +48,20 @@ 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( Integration::RenderSurface& surface ) { - ScenePtr scene = new Scene( size ); + ScenePtr scene = new Scene; // Second-phase construction - scene->Initialize(); + scene->Initialize( surface ); return scene; } -Scene::Scene( const Size& size ) +Scene::Scene() : mSurface( nullptr ), - mSize( size ), - mSurfaceSize( Vector2::ZERO ), - mDpi( Vector2::ZERO ), + 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() ) @@ -95,11 +94,11 @@ Scene::~Scene() mFrameBuffer.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( Integration::RenderSurface& surface ) { ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); @@ -125,7 +124,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())); @@ -134,6 +135,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) @@ -198,9 +202,10 @@ Actor& Scene::GetDefaultRootActor() void Scene::SetSurface( Integration::RenderSurface& surface ) { - mSurface = &surface; - if ( mSurface ) + if( mSurface != &surface ) { + mSurface = &surface; + RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u ); mFrameBuffer = Dali::Internal::FrameBuffer::New( surface, Dali::FrameBuffer::Attachment::NONE ); @@ -214,21 +219,19 @@ void Scene::SurfaceResized() { if( mSurface ) { - const float fWidth = static_cast( mSurface->GetPositionSize().width ); - const float fHeight = static_cast( mSurface->GetPositionSize().height ); + const PositionSize surfacePositionSize = mSurface->GetPositionSize(); + const float fWidth = static_cast< float >( surfacePositionSize.width ); + const float fHeight = static_cast< float >( surfacePositionSize.height ); - if( ( fabsf( mSurfaceSize.width - fWidth ) > Math::MACHINE_EPSILON_1 ) || ( fabsf( mSurfaceSize.height - fHeight ) > Math::MACHINE_EPSILON_1 ) ) + if( ( fabsf( mSize.width - fWidth ) > Math::MACHINE_EPSILON_1 ) || ( fabsf( mSize.height - fHeight ) > Math::MACHINE_EPSILON_1 ) ) { - Rect newSize( 0, 0, static_cast( mSurface->GetPositionSize().width ), static_cast( mSurface->GetPositionSize().height ) ); - - mSurfaceSize.width = fWidth; - mSurfaceSize.height = fHeight; + Rect< int32_t > newSize( 0, 0, static_cast< int32_t >( surfacePositionSize.width ), static_cast< int32_t >( surfacePositionSize.height ) ); - mSize.width = mSurfaceSize.width; - mSize.height = mSurfaceSize.height; + mSize.width = fWidth; + mSize.height = fHeight; // 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 ); @@ -254,6 +257,7 @@ void Scene::SurfaceResized() void Scene::SurfaceDeleted() { + mSurface = nullptr; if ( mFrameBuffer ) { // The frame buffer doesn't have a valid render surface any more. diff --git a/dali/internal/event/common/scene-impl.h b/dali/internal/event/common/scene-impl.h index 6671fa3..2c93c84 100644 --- a/dali/internal/event/common/scene-impl.h +++ b/dali/internal/event/common/scene-impl.h @@ -62,7 +62,7 @@ public: /** * @copydoc Dali::Integration::Scene::New */ - static ScenePtr New( const Size& size ); + static ScenePtr New( Integration::RenderSurface& surface ); /** * virtual destructor @@ -251,12 +251,12 @@ public: private: // Constructor - Scene( const Size& size ); + Scene(); /** * Second-phase constructor. */ - void Initialize(); + void Initialize( Integration::RenderSurface& surface ); // Undefined Scene(const Scene&) = delete; @@ -267,9 +267,7 @@ private: private: Integration::RenderSurface* mSurface; - // The scene-size may be different with the surface-size Size mSize; - Size mSurfaceSize; Vector2 mDpi;