From 70dee6f95b89f5de698fbe9cbbe3dd0f547ea481 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Mon, 10 Jul 2017 17:47:05 +0100 Subject: [PATCH] Add devel api to support C++11 for loop: for ( auto i : container ) Change-Id: I4167e6b160f0134648d23bb1e9c10da214d68017 --- automated-tests/src/dali/utc-Dali-FrameBuffer.cpp | 4 + .../src/dali/utc-Dali-PropertyBuffer.cpp | 58 +++--- automated-tests/src/dali/utc-Dali-Vector.cpp | 25 ++- dali/devel-api/common/dali-vector-devel.h | 54 ++++++ dali/devel-api/common/owner-container.h | 1 + dali/devel-api/file.list | 1 + dali/internal/render/common/render-manager.cpp | 121 +++++-------- dali/internal/update/manager/update-manager.cpp | 195 ++++++++------------- 8 files changed, 237 insertions(+), 222 deletions(-) create mode 100644 dali/devel-api/common/dali-vector-devel.h diff --git a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp index 6278193..041e1bb 100644 --- a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp @@ -326,6 +326,10 @@ int UtcDaliFramebufferContextLoss(void) DALI_TEST_CHECK( frameBuffer ); frameBuffer.AttachColorTexture( texture, 0u, 1u ); + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + application.SendNotification(); application.Render(16); diff --git a/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp b/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp index 4da91dc..3d70484 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyBuffer.cpp @@ -118,40 +118,46 @@ int UtcDaliPropertyBufferSetData01(void) texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; - PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat ); - DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION ); + { + PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat ); + DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION ); - const float halfQuadSize = .5f; - struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; - TexturedQuadVertex texturedQuadVertexData[4] = { - { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, - { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, - { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, - { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + const float halfQuadSize = .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; - propertyBuffer.SetData( texturedQuadVertexData, 4 ); + propertyBuffer.SetData( texturedQuadVertexData, 4 ); - Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( propertyBuffer ); + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( propertyBuffer ); - Shader shader = CreateShader(); - Renderer renderer = Renderer::New(geometry, shader); - Actor actor = Actor::New(); - actor.SetSize(Vector3::ONE * 100.f); - actor.AddRenderer(renderer); - Stage::GetCurrent().Add(actor); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetSize(Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - application.Render(); - application.SendNotification(); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); - const TestGlAbstraction::BufferDataCalls& bufferDataCalls = - application.GetGlAbstraction().GetBufferDataCalls(); + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION ); - DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION ); + } + // end of scope to let the buffer and geometry die; do another notification and render to get the deletion processed + application.SendNotification(); + application.Render(0); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-Vector.cpp b/automated-tests/src/dali/utc-Dali-Vector.cpp index 6677cea..28fe6b6 100644 --- a/automated-tests/src/dali/utc-Dali-Vector.cpp +++ b/automated-tests/src/dali/utc-Dali-Vector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -20,6 +20,7 @@ #include #include #include +#include #include using namespace Dali; @@ -1339,6 +1340,28 @@ int UtcDaliVectorMatrixP(void) END_TEST; } +int UtcDaliVectorCpp11ForP(void) +{ + Vector< Vector3 > classvector; + for ( auto i : classvector ) + { + std::ignore = i; + tet_result( TET_FAIL ); + } + + classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) ); + classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) ); + classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) ); + + for ( auto i : classvector ) + { + DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), i, TEST_LOCATION ); + } + + END_TEST; +} + + /* * this does not compile at the moment * Vector< Actor > classvector; this does not compile yet either diff --git a/dali/devel-api/common/dali-vector-devel.h b/dali/devel-api/common/dali-vector-devel.h new file mode 100644 index 0000000..08e3abf --- /dev/null +++ b/dali/devel-api/common/dali-vector-devel.h @@ -0,0 +1,54 @@ +#ifndef DALI_VECTOR_DEVEL_H +#define DALI_VECTOR_DEVEL_H + +/* + * Copyright (c) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * Dali::Vector support for C++11 Range-based for loop: for( item : container ) + * + * @param vector The vector to iterate + * @return The start iterator + */ +template< class T > +typename T::Iterator begin( T& vector ) +{ + return vector.Begin(); +} + +/** + * Dali::Vector support for C++11 Range-based for loop: for( item : container ) + * + * @param vector The vector to iterate + * @return The end iterator + */ +template< class T > +typename T::Iterator end( T& vector ) +{ + return vector.End(); +} + +} // namespace Dali + +#endif /* DALI_VECTOR_DEVEL_H */ diff --git a/dali/devel-api/common/owner-container.h b/dali/devel-api/common/owner-container.h index f35b278..b5ac951 100644 --- a/dali/devel-api/common/owner-container.h +++ b/dali/devel-api/common/owner-container.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index d30f932..8702875 100644 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -34,6 +34,7 @@ devel_api_core_animation_header_files = \ $(devel_api_src_dir)/animation/animation-devel.h devel_api_core_common_header_files = \ + $(devel_api_src_dir)/common/dali-vector-devel.h \ $(devel_api_src_dir)/common/hash.h \ $(devel_api_src_dir)/common/map-wrapper.h \ $(devel_api_src_dir)/common/owner-container.h \ diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index c980d74..b391961 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -48,28 +48,6 @@ namespace Internal namespace SceneGraph { -typedef OwnerContainer< Render::Renderer* > RendererOwnerContainer; -typedef RendererOwnerContainer::Iterator RendererOwnerIter; - -typedef OwnerContainer< Render::Geometry* > GeometryOwnerContainer; -typedef GeometryOwnerContainer::Iterator GeometryOwnerIter; - -typedef OwnerContainer< Render::Sampler* > SamplerOwnerContainer; -typedef SamplerOwnerContainer::Iterator SamplerOwnerIter; - -typedef OwnerContainer< Render::Texture* > TextureOwnerContainer; -typedef TextureOwnerContainer::Iterator TextureOwnerIter; - -typedef OwnerContainer< Render::FrameBuffer* > FrameBufferOwnerContainer; -typedef FrameBufferOwnerContainer::Iterator FrameBufferOwnerIter; - -typedef OwnerContainer< Render::PropertyBuffer* > PropertyBufferOwnerContainer; -typedef PropertyBufferOwnerContainer::Iterator PropertyBufferOwnerIter; - -typedef OwnerContainer< Render::RenderTracker* > RenderTrackerContainer; -typedef RenderTrackerContainer::Iterator RenderTrackerIter; -typedef RenderTrackerContainer::ConstIterator RenderTrackerConstIter; - /** * Structure to contain internal data */ @@ -111,41 +89,41 @@ struct RenderManager::Impl void UpdateTrackers() { - for(RenderTrackerIter iter = mRenderTrackers.Begin(), end = mRenderTrackers.End(); iter != end; ++iter) + for( auto&& iter : mRenderTrackers ) { - (*iter)->PollSyncObject(); + iter->PollSyncObject(); } } // the order is important for destruction, // programs are owned by context at the moment. - Context context; ///< holds the GL state - Integration::GlSyncAbstraction& glSyncAbstraction; ///< GL sync abstraction - RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread. + Context context; ///< holds the GL state + Integration::GlSyncAbstraction& glSyncAbstraction; ///< GL sync abstraction + RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread. // Render instructions describe what should be rendered during RenderManager::Render() // Owned by RenderManager. Update manager updates instructions for the next frame while we render the current one - RenderInstructionContainer instructions; + RenderInstructionContainer instructions; - Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame. + Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame. - unsigned int frameCount; ///< The current frame count - BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer + unsigned int frameCount; ///< The current frame count + BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer - Rect defaultSurfaceRect; ///< Rectangle for the default surface we are rendering to + Rect defaultSurfaceRect; ///< Rectangle for the default surface we are rendering to - RendererOwnerContainer rendererContainer; ///< List of owned renderers - SamplerOwnerContainer samplerContainer; ///< List of owned samplers - TextureOwnerContainer textureContainer; ///< List of owned textures - FrameBufferOwnerContainer frameBufferContainer; ///< List of owned framebuffers - PropertyBufferOwnerContainer propertyBufferContainer; ///< List of owned property buffers - GeometryOwnerContainer geometryContainer; ///< List of owned Geometries + OwnerContainer< Render::Renderer* > rendererContainer; ///< List of owned renderers + OwnerContainer< Render::Sampler* > samplerContainer; ///< List of owned samplers + OwnerContainer< Render::Texture* > textureContainer; ///< List of owned textures + OwnerContainer< Render::FrameBuffer* > frameBufferContainer; ///< List of owned framebuffers + OwnerContainer< Render::PropertyBuffer* > propertyBufferContainer; ///< List of owned property buffers + OwnerContainer< Render::Geometry* > geometryContainer; ///< List of owned Geometries - bool lastFrameWasRendered; ///< Keeps track of the last frame being rendered due to having render instructions + bool lastFrameWasRendered; ///< Keeps track of the last frame being rendered due to having render instructions - RenderTrackerContainer mRenderTrackers; ///< List of render trackers + OwnerContainer< Render::RenderTracker* > mRenderTrackers; ///< List of render trackers - ProgramController programController; ///< Owner of the GL programs + ProgramController programController; ///< Owner of the GL programs }; @@ -188,24 +166,21 @@ void RenderManager::ContextDestroyed() mImpl->programController.GlContextDestroyed(); //Inform textures - for( TextureOwnerIter iter = mImpl->textureContainer.Begin(); iter != mImpl->textureContainer.End(); ++iter ) + for( auto&& texture : mImpl->textureContainer ) { - (*iter)->GlContextDestroyed(); + texture->GlContextDestroyed(); } //Inform framebuffers - for( FrameBufferOwnerIter iter = mImpl->frameBufferContainer.Begin(); iter != mImpl->frameBufferContainer.End(); ++iter ) + for( auto&& framebuffer : mImpl->frameBufferContainer ) { - (*iter)->GlContextDestroyed(); + framebuffer->GlContextDestroyed(); } // inform renderers - RendererOwnerContainer::Iterator end = mImpl->rendererContainer.End(); - RendererOwnerContainer::Iterator iter = mImpl->rendererContainer.Begin(); - for( ; iter != end; ++iter ) + for( auto&& renderer : mImpl->rendererContainer ) { - GlResourceOwner* renderer = *iter; - renderer->GlContextDestroyed(); // Clear up vertex buffers + renderer->GlContextDestroyed(); } } @@ -262,16 +237,14 @@ void RenderManager::RemoveTexture( Render::Texture* texture ) { DALI_ASSERT_DEBUG( NULL != texture ); - TextureOwnerContainer& textures = mImpl->textureContainer; - - // Find the texture - for ( TextureOwnerIter iter = textures.Begin(); iter != textures.End(); ++iter ) + // Find the texture, use reference to pointer so we can do the erase safely + for ( auto&& iter : mImpl->textureContainer ) { - if ( *iter == texture ) + if ( iter == texture ) { texture->Destroy( mImpl->context ); - textures.Erase( iter ); // Texture found; now destroy it - break; + mImpl->textureContainer.Erase( &iter ); // Texture found; now destroy it + return; } } } @@ -309,15 +282,13 @@ void RenderManager::RemoveFrameBuffer( Render::FrameBuffer* frameBuffer ) { DALI_ASSERT_DEBUG( NULL != frameBuffer ); - FrameBufferOwnerContainer& framebuffers = mImpl->frameBufferContainer; - - // Find the sampler - for ( FrameBufferOwnerIter iter = framebuffers.Begin(); iter != framebuffers.End(); ++iter ) + // Find the sampler, use reference so we can safely do the erase + for ( auto&& iter : mImpl->frameBufferContainer ) { - if ( *iter == frameBuffer ) + if ( iter == frameBuffer ) { frameBuffer->Destroy( mImpl->context ); - framebuffers.Erase( iter ); // frameBuffer found; now destroy it + mImpl->frameBufferContainer.Erase( &iter ); // frameBuffer found; now destroy it break; } } @@ -367,14 +338,12 @@ void RenderManager::AttachVertexBuffer( Render::Geometry* geometry, Render::Prop { DALI_ASSERT_DEBUG( NULL != geometry ); - GeometryOwnerContainer& geometries = mImpl->geometryContainer; - - // Find the renderer - for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter ) + // Find the geometry + for ( auto&& iter : mImpl->geometryContainer ) { - if ( *iter == geometry ) + if ( iter == geometry ) { - (*iter)->AddPropertyBuffer( propertyBuffer ); + iter->AddPropertyBuffer( propertyBuffer ); break; } } @@ -384,14 +353,12 @@ void RenderManager::RemoveVertexBuffer( Render::Geometry* geometry, Render::Prop { DALI_ASSERT_DEBUG( NULL != geometry ); - GeometryOwnerContainer& geometries = mImpl->geometryContainer; - - // Find the renderer - for ( GeometryOwnerIter iter = geometries.Begin(); iter != geometries.End(); ++iter ) + // Find the geometry + for ( auto&& iter : mImpl->geometryContainer ) { - if ( *iter == geometry ) + if ( iter == geometry ) { - (*iter)->RemovePropertyBuffer( propertyBuffer ); + iter->RemovePropertyBuffer( propertyBuffer ); break; } } @@ -481,9 +448,9 @@ void RenderManager::Render( Integration::RenderStatus& status ) mImpl->UpdateTrackers(); //Notify RenderGeometries that rendering has finished - for ( GeometryOwnerIter iter = mImpl->geometryContainer.Begin(); iter != mImpl->geometryContainer.End(); ++iter ) + for ( auto&& iter : mImpl->geometryContainer ) { - (*iter)->OnRenderFinished(); + iter->OnRenderFinished(); } } diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index 64bf05f..cf23bc2 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -108,11 +108,10 @@ template< class T > inline void ResetToBaseValues( OwnerContainer& container, BufferIndex updateBufferIndex ) { // Reset animatable properties to base values - typename OwnerContainer::Iterator iter = container.Begin(); - const typename OwnerContainer::ConstIterator endIter = container.End(); - for ( ; iter != endIter; ++iter ) + // use reference to avoid extra copies of the iterator + for( auto&& iter : container ) { - (*iter)->ResetToBaseValues( updateBufferIndex ); + iter->ResetToBaseValues( updateBufferIndex ); } } @@ -128,34 +127,20 @@ inline void EraseUsingDiscardQueue( OwnerContainer& container, T* object, Di { DALI_ASSERT_DEBUG( object && "NULL object not allowed" ); - typename OwnerContainer::Iterator iter = container.Begin(); - const typename OwnerContainer::ConstIterator endIter = container.End(); - for ( ; iter != endIter; ++iter ) + // need to use the reference version of auto as we need the pointer to the pointer for the Release call below + for( auto&& iter : container ) { - if ( *iter == object ) + if ( iter == object ) { // Transfer ownership to the discard queue, this keeps the object alive, until the render-thread has finished with it - discardQueue.Add( updateBufferIndex, container.Release( iter ) ); - return; + discardQueue.Add( updateBufferIndex, container.Release( &iter ) ); // take the address of the reference to a pointer (iter) + return; // return as we only ever remove one object. Iterators to container are now invalidated as well so cannot continue } } } } -typedef OwnerContainer< Shader* > ShaderOwner; -typedef ShaderOwner::Iterator ShaderIter; -typedef std::vector ShaderDataBinaryQueue; - -typedef OwnerContainer< TextureSet* > TextureSetOwner; -typedef TextureSetOwner::Iterator TextureSetIter; - -typedef OwnerContainer RendererOwner; -typedef RendererOwner::Iterator RendererIter; - -typedef OwnerContainer< Camera* > CameraOwner; -typedef OwnerContainer< PropertyOwner* > CustomObjectOwner; - /** * Structure to contain UpdateManager internal data */ @@ -211,15 +196,15 @@ struct UpdateManager::Impl { // Disconnect render tasks from nodes, before destroying the nodes RenderTaskList::RenderTaskContainer& tasks = taskList.GetTasks(); - for (RenderTaskList::RenderTaskContainer::Iterator iter = tasks.Begin(); iter != tasks.End(); ++iter) + for ( auto&& iter : tasks ) { - (*iter)->SetSourceNode( NULL ); + iter->SetSourceNode( NULL ); } // ..repeat for system level RenderTasks RenderTaskList::RenderTaskContainer& systemLevelTasks = systemLevelTaskList.GetTasks(); - for (RenderTaskList::RenderTaskContainer::Iterator iter = systemLevelTasks.Begin(); iter != systemLevelTasks.End(); ++iter) + for ( auto&& iter : systemLevelTasks ) { - (*iter)->SetSourceNode( NULL ); + iter->SetSourceNode( NULL ); } // UpdateManager owns the Nodes. Although Nodes are pool allocated they contain heap allocated parts @@ -252,58 +237,58 @@ struct UpdateManager::Impl delete sceneController; } - SceneGraphBuffers sceneGraphBuffers; ///< Used to keep track of which buffers are being written or read - RenderMessageDispatcher renderMessageDispatcher; ///< Used for passing messages to the render-thread - NotificationManager& notificationManager; ///< Queues notification messages for the event-thread. - TransformManager transformManager; ///< Used to update the transformation matrices of the nodes - CompleteNotificationInterface& animationPlaylist; ///< Holds handles to all the animations - PropertyNotifier& propertyNotifier; ///< Provides notification to applications when properties are modified. - ShaderSaver* shaderSaver; ///< Saves shader binaries. - DiscardQueue& discardQueue; ///< Nodes are added here when disconnected from the scene-graph. - RenderController& renderController; ///< render controller - SceneControllerImpl* sceneController; ///< scene controller - RenderManager& renderManager; ///< This is responsible for rendering the results of each "update" - RenderQueue& renderQueue; ///< Used to queue messages for the next render - RenderInstructionContainer& renderInstructions; ///< Used to prepare the render instructions - RenderTaskProcessor& renderTaskProcessor; ///< Handles RenderTasks and RenderInstrucitons + SceneGraphBuffers sceneGraphBuffers; ///< Used to keep track of which buffers are being written or read + RenderMessageDispatcher renderMessageDispatcher; ///< Used for passing messages to the render-thread + NotificationManager& notificationManager; ///< Queues notification messages for the event-thread. + TransformManager transformManager; ///< Used to update the transformation matrices of the nodes + CompleteNotificationInterface& animationPlaylist; ///< Holds handles to all the animations + PropertyNotifier& propertyNotifier; ///< Provides notification to applications when properties are modified. + ShaderSaver* shaderSaver; ///< Saves shader binaries. + DiscardQueue& discardQueue; ///< Nodes are added here when disconnected from the scene-graph. + RenderController& renderController; ///< render controller + SceneControllerImpl* sceneController; ///< scene controller + RenderManager& renderManager; ///< This is responsible for rendering the results of each "update" + RenderQueue& renderQueue; ///< Used to queue messages for the next render + RenderInstructionContainer& renderInstructions; ///< Used to prepare the render instructions + RenderTaskProcessor& renderTaskProcessor; ///< Handles RenderTasks and RenderInstrucitons - Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame. + Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame. - RenderTaskList taskList; ///< The list of scene graph render-tasks - RenderTaskList systemLevelTaskList; ///< Separate render-tasks for system-level content + RenderTaskList taskList; ///< The list of scene graph render-tasks + RenderTaskList systemLevelTaskList; ///< Separate render-tasks for system-level content - Layer* root; ///< The root node (root is a layer) - Layer* systemLevelRoot; ///< A separate root-node for system-level content + Layer* root; ///< The root node (root is a layer) + Layer* systemLevelRoot; ///< A separate root-node for system-level content - Vector nodes; ///< A container of all instantiated nodes + Vector nodes; ///< A container of all instantiated nodes - SortedLayerPointers sortedLayers; ///< A container of Layer pointers sorted by depth - SortedLayerPointers systemLevelSortedLayers; ///< A separate container of system-level Layers + SortedLayerPointers sortedLayers; ///< A container of Layer pointers sorted by depth + SortedLayerPointers systemLevelSortedLayers; ///< A separate container of system-level Layers - CameraOwner cameras; ///< A container of cameras - CustomObjectOwner customObjects; ///< A container of owned objects (with custom properties) + OwnerContainer< Camera* > cameras; ///< A container of cameras + OwnerContainer< PropertyOwner* > customObjects; ///< A container of owned objects (with custom properties) - AnimationContainer animations; ///< A container of owned animations - PropertyNotificationContainer propertyNotifications; ///< A container of owner property notifications. + AnimationContainer animations; ///< A container of owned animations + PropertyNotificationContainer propertyNotifications; ///< A container of owner property notifications. - RendererOwner renderers; ///< A container of owned renderers - TextureSetOwner textureSets; ///< A container of owned texture sets - ShaderOwner shaders; ///< A container of owned shaders - OwnerPointer panGestureProcessor; ///< Owned pan gesture processor; it lives for the lifecycle of UpdateManager + OwnerContainer< Renderer* > renderers; ///< A container of owned renderers + OwnerContainer< TextureSet* > textureSets; ///< A container of owned texture sets + OwnerContainer< Shader* > shaders; ///< A container of owned shaders + OwnerPointer< PanGesture > panGestureProcessor; ///< Owned pan gesture processor; it lives for the lifecycle of UpdateManager - MessageQueue messageQueue; ///< The messages queued from the event-thread - ShaderDataBinaryQueue renderCompiledShaders; ///< Shaders compiled on Render thread are inserted here for update thread to pass on to event thread. - ShaderDataBinaryQueue updateCompiledShaders; ///< Shaders to be sent from Update to Event - Mutex compiledShaderMutex; ///< lock to ensure no corruption on the renderCompiledShaders + MessageQueue messageQueue; ///< The messages queued from the event-thread + std::vector renderCompiledShaders; ///< Shaders compiled on Render thread are inserted here for update thread to pass on to event thread. + std::vector updateCompiledShaders; ///< Shaders to be sent from Update to Event + Mutex compiledShaderMutex; ///< lock to ensure no corruption on the renderCompiledShaders - float keepRenderingSeconds; ///< Set via Dali::Stage::KeepRendering - int nodeDirtyFlags; ///< cumulative node dirty flags from previous frame - int frameCounter; ///< Frame counter used in debugging to choose which frame to debug and which to ignore. + float keepRenderingSeconds; ///< Set via Dali::Stage::KeepRendering + int nodeDirtyFlags; ///< cumulative node dirty flags from previous frame + int frameCounter; ///< Frame counter used in debugging to choose which frame to debug and which to ignore. - bool animationFinishedDuringUpdate; ///< Flag whether any animations finished during the Update() - bool previousUpdateScene; ///< True if the scene was updated in the previous frame (otherwise it was optimized out) - bool renderTaskWaiting; ///< A REFRESH_ONCE render task is waiting to be rendered - bool renderersAdded; ///< Flag to keep track when renderers have been added to avoid unnecessary processing + bool animationFinishedDuringUpdate; ///< Flag whether any animations finished during the Update() + bool previousUpdateScene; ///< True if the scene was updated in the previous frame (otherwise it was optimized out) + bool renderTaskWaiting; ///< A REFRESH_ONCE render task is waiting to be rendered + bool renderersAdded; ///< Flag to keep track when renderers have been added to avoid unnecessary processing private: @@ -464,24 +449,19 @@ void UpdateManager::RemoveAnimation( Animation* animation ) bool UpdateManager::IsAnimationRunning() const { - bool isRunning(false); - AnimationContainer& animations = mImpl->animations; - // Find any animation that isn't stopped or paused - - const AnimationIter endIter = animations.End(); - for ( AnimationIter iter = animations.Begin(); !isRunning && iter != endIter; ++iter ) + for ( auto&& iter : mImpl->animations ) { - const Animation::State state = (*iter)->GetState(); + const Animation::State state = iter->GetState(); if (state != Animation::Stopped && state != Animation::Paused) { - isRunning = true; + return true; // stop iteration as soon as first one is found } } - return isRunning; + return false; } void UpdateManager::AddPropertyNotification( OwnerPointer< PropertyNotification >& propertyNotification ) @@ -703,12 +683,9 @@ void UpdateManager::Animate( BufferIndex bufferIndex, float elapsedSeconds ) void UpdateManager::ConstrainCustomObjects( BufferIndex bufferIndex ) { //Constrain custom objects (in construction order) - OwnerContainer< PropertyOwner* >& customObjects = mImpl->customObjects; - const OwnerContainer< PropertyOwner* >::Iterator endIter = customObjects.End(); - for ( OwnerContainer< PropertyOwner* >::Iterator iter = customObjects.Begin(); endIter != iter; ++iter ) + for ( auto&& object : mImpl->customObjects ) { - PropertyOwner& object = **iter; - ConstrainPropertyOwner( object, bufferIndex ); + ConstrainPropertyOwner( *object, bufferIndex ); } } @@ -716,46 +693,37 @@ void UpdateManager::ConstrainRenderTasks( BufferIndex bufferIndex ) { // Constrain system-level render-tasks const RenderTaskList::RenderTaskContainer& systemLevelTasks = mImpl->systemLevelTaskList.GetTasks(); - for ( RenderTaskList::RenderTaskContainer::ConstIterator iter = systemLevelTasks.Begin(); iter != systemLevelTasks.End(); ++iter ) + for ( auto&& task : systemLevelTasks ) { - RenderTask& task = **iter; - ConstrainPropertyOwner( task, bufferIndex ); + ConstrainPropertyOwner( *task, bufferIndex ); } // Constrain render-tasks const RenderTaskList::RenderTaskContainer& tasks = mImpl->taskList.GetTasks(); - for ( RenderTaskList::RenderTaskContainer::ConstIterator iter = tasks.Begin(); iter != tasks.End(); ++iter ) + for ( auto&& task : tasks ) { - RenderTask& task = **iter; - ConstrainPropertyOwner( task, bufferIndex ); + ConstrainPropertyOwner( *task, bufferIndex ); } } void UpdateManager::ConstrainShaders( BufferIndex bufferIndex ) { // constrain shaders... (in construction order) - ShaderOwner& shaders = mImpl->shaders; - for ( ShaderIter iter = shaders.Begin(); iter != shaders.End(); ++iter ) + for ( auto&& shader : mImpl->shaders ) { - Shader& shader = **iter; - ConstrainPropertyOwner( shader, bufferIndex ); + ConstrainPropertyOwner( *shader, bufferIndex ); } } void UpdateManager::ProcessPropertyNotifications( BufferIndex bufferIndex ) { - PropertyNotificationContainer ¬ifications = mImpl->propertyNotifications; - PropertyNotificationIter iter = notifications.Begin(); - - while ( iter != notifications.End() ) + for( auto&& notification : mImpl->propertyNotifications ) { - PropertyNotification* notification = *iter; bool valid = notification->Check( bufferIndex ); if(valid) { mImpl->notificationManager.QueueMessage( PropertyChangedMessage( mImpl->propertyNotifier, notification, notification->GetValidity() ) ); } - ++iter; } } @@ -774,11 +742,9 @@ void UpdateManager::ForwardCompiledShadersToEventThread() if( mImpl->updateCompiledShaders.size() > 0 ) { ShaderSaver& factory = *mImpl->shaderSaver; - ShaderDataBinaryQueue::iterator i = mImpl->updateCompiledShaders.begin(); - ShaderDataBinaryQueue::iterator end = mImpl->updateCompiledShaders.end(); - for( ; i != end; ++i ) + for( auto&& shader : mImpl->updateCompiledShaders ) { - mImpl->notificationManager.QueueMessage( ShaderCompiledMessage( factory, *i ) ); + mImpl->notificationManager.QueueMessage( ShaderCompiledMessage( factory, shader ) ); } // we don't need them in update anymore mImpl->updateCompiledShaders.clear(); @@ -897,10 +863,9 @@ unsigned int UpdateManager::Update( float elapsedSeconds, ProcessPropertyNotifications( bufferIndex ); //Update cameras - const CameraOwner::Iterator endCameraIterator = mImpl->cameras.End(); - for( CameraOwner::Iterator cameraIterator = mImpl->cameras.Begin(); endCameraIterator != cameraIterator; ++cameraIterator ) + for( auto&& cameraIterator : mImpl->cameras ) { - ( *cameraIterator )->Update( bufferIndex ); + cameraIterator->Update( bufferIndex ); } //Process the RenderTasks if renderers exist. This creates the instructions for rendering the next frame. @@ -934,21 +899,17 @@ unsigned int UpdateManager::Update( float elapsedSeconds, // check the countdown and notify (note, at the moment this is only done for normal tasks, not for systemlevel tasks) bool doRenderOnceNotify = false; mImpl->renderTaskWaiting = false; - const RenderTaskList::RenderTaskContainer& tasks = mImpl->taskList.GetTasks(); - for ( RenderTaskList::RenderTaskContainer::ConstIterator iter = tasks.Begin(), endIter = tasks.End(); - endIter != iter; ++iter ) + for ( auto&& renderTask : mImpl->taskList.GetTasks() ) { - RenderTask& renderTask(*(*iter)); - - renderTask.UpdateState(); + renderTask->UpdateState(); - if( renderTask.IsWaitingToRender() && - renderTask.ReadyToRender( bufferIndex ) /*avoid updating forever when source actor is off-stage*/ ) + if( renderTask->IsWaitingToRender() && + renderTask->ReadyToRender( bufferIndex ) /*avoid updating forever when source actor is off-stage*/ ) { mImpl->renderTaskWaiting = true; // keep update/render threads alive } - if( renderTask.HasRendered() ) + if( renderTask->HasRendered() ) { doRenderOnceNotify = true; } @@ -1057,11 +1018,9 @@ void UpdateManager::SetDepthIndices( OwnerPointer< NodeDepths >& nodeDepths ) { // note,this vector is already in depth order. It could be used as-is to // remove sorting in update algorithm. However, it lacks layer boundary markers. - for( std::vector::iterator iter = nodeDepths->nodeDepths.begin(), - end = nodeDepths->nodeDepths.end() ; - iter != end ; ++iter ) + for( auto&& iter : nodeDepths->nodeDepths ) { - iter->node->SetDepthIndex( iter->sortedDepth ); + iter.node->SetDepthIndex( iter.sortedDepth ); } } -- 2.7.4