2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/render/common/render-instruction.h>
22 #include <dali/public-api/common/constants.h> // for Color::BLACK
23 #include <dali/internal/render/common/render-tracker.h>
24 #include <dali/integration-api/debug.h>
35 RenderInstruction::RenderInstruction()
36 : mRenderTracker( NULL ),
38 mIsViewportSet( false ),
39 mIsClearColorSet( false ),
40 mOffscreenTextureId( 0 ),
41 mCameraAttachment( 0 ),
42 mNextFreeRenderList( 0 )
44 // reserve 6 lists, which is enough for three layers with opaque and transparent things on
45 mRenderLists.Reserve( 6 );
48 RenderInstruction::~RenderInstruction()
49 { // pointer container releases the renderlists
52 RenderList& RenderInstruction::GetNextFreeRenderList( size_t capacityRequired )
54 // check if we have enough lists, we can only be one behind at worst
55 if( mRenderLists.Count() <= mNextFreeRenderList )
57 mRenderLists.PushBack( new RenderList ); // Push a new empty render list
60 // check capacity of the list and reserve if not big enough
61 if( mRenderLists[ mNextFreeRenderList ]->Capacity() < capacityRequired )
63 mRenderLists[ mNextFreeRenderList ]->Reserve( capacityRequired );
66 // return the list mNextFreeRenderList points to and increase by one
67 return *mRenderLists[ mNextFreeRenderList++ ];
70 void RenderInstruction::UpdateCompleted()
72 // lets do some housekeeping, remove any lists that were not needed because
73 // application might have removed a layer permanently
74 RenderListContainer::Iterator iter = mRenderLists.Begin();
75 RenderListContainer::ConstIterator end = mRenderLists.End();
76 for( ;iter != end; ++iter )
78 // tell the list to do its housekeeping
79 (*iter)->ReleaseUnusedItems();
82 // release any extra lists
83 if( mRenderLists.Count() > mNextFreeRenderList )
85 mRenderLists.Resize( mNextFreeRenderList );
89 RenderListContainer::SizeType RenderInstruction::RenderListCount() const
91 return mNextFreeRenderList;
94 const RenderList* RenderInstruction::GetRenderList( RenderListContainer::SizeType index ) const
96 DALI_ASSERT_DEBUG( (index < mNextFreeRenderList ) && (index < mRenderLists.Size()) && "Renderlist index out of container bounds" );
98 // Return null if the caller has passed an invalid index:
99 if( index >= std::min( mNextFreeRenderList, mRenderLists.Size() ) )
104 return mRenderLists[ index ];
107 void RenderInstruction::Reset( CameraAttachment* cameraAttachment,
108 unsigned int offscreenTextureId,
109 const Viewport* viewport,
110 const Vector4* clearColor )
112 mCameraAttachment = cameraAttachment;
113 mViewport = viewport ? *viewport : Viewport();
114 mIsViewportSet = NULL != viewport;
115 mClearColor = clearColor ? *clearColor : Color::BLACK;
116 mIsClearColorSet = NULL != clearColor;
117 mOffscreenTextureId = offscreenTextureId;
118 mRenderTracker = NULL;
119 mNextFreeRenderList = 0;
121 RenderListContainer::Iterator iter = mRenderLists.Begin();
122 RenderListContainer::ConstIterator end = mRenderLists.End();
123 for( ;iter != end; ++iter )
125 // since mRenderLists is a vector of RenderLists we dont want to clear it
126 // as it ends up releasing and later reallocating loads of vectors
127 // reset the renderlist
132 } // namespace SceneGraph
134 } // namespace Internal