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;
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
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 );
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.
{
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();
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
// 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();
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();
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;
+}
} //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() )
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();
// 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()));
// Create the default render-task
mRenderTaskList->CreateTask( mRootLayer.Get(), mDefaultCamera.Get() );
+
+ // Set the surface
+ SetSurface( surface );
}
void Scene::Add(Actor& actor)
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 );
{
if( mSurface )
{
- const float fWidth = static_cast<float>( mSurface->GetPositionSize().width );
- const float fHeight = static_cast<float>( 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<int32_t> newSize( 0, 0, static_cast<int32_t>( mSurface->GetPositionSize().width ), static_cast<int32_t>( 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 );
void Scene::SurfaceDeleted()
{
+ mSurface = nullptr;
if ( mFrameBuffer )
{
// The frame buffer doesn't have a valid render surface any more.