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>
34 RenderInstruction::RenderInstruction()
36 mProjectionMatrix( 0 ),
37 mRenderTracker( NULL ),
39 mIsViewportSet( false ),
40 mIsClearColorSet( false ),
42 mOffscreenTextureId( 0 ),
43 mNextFreeRenderList( 0 )
45 // reserve 6 lists, which is enough for three layers with opaque and transparent things on
46 mRenderLists.Reserve( 6 );
49 RenderInstruction::~RenderInstruction()
50 { // pointer container releases the renderlists
53 RenderList& RenderInstruction::GetNextFreeRenderList( size_t capacityRequired )
55 // check if we have enough lists, we can only be one behind at worst
56 if( mRenderLists.Count() <= mNextFreeRenderList )
58 mRenderLists.PushBack( new RenderList ); // Push a new empty render list
61 // check capacity of the list and reserve if not big enough
62 if( mRenderLists[ mNextFreeRenderList ]->Capacity() < capacityRequired )
64 mRenderLists[ mNextFreeRenderList ]->Reserve( capacityRequired );
67 // return the list mNextFreeRenderList points to and increase by one
68 return *mRenderLists[ mNextFreeRenderList++ ];
71 void RenderInstruction::UpdateCompleted()
73 // lets do some housekeeping, remove any lists that were not needed because
74 // application might have removed a layer permanently
75 RenderListContainer::Iterator iter = mRenderLists.Begin();
76 RenderListContainer::ConstIterator end = mRenderLists.End();
77 for( ;iter != end; ++iter )
79 // tell the list to do its housekeeping
80 (*iter)->ReleaseUnusedItems();
83 // release any extra lists
84 if( mRenderLists.Count() > mNextFreeRenderList )
86 mRenderLists.Resize( mNextFreeRenderList );
90 RenderListContainer::SizeType RenderInstruction::RenderListCount() const
92 return mNextFreeRenderList;
95 const RenderList* RenderInstruction::GetRenderList( RenderListContainer::SizeType index ) const
97 DALI_ASSERT_ALWAYS( (index < mNextFreeRenderList ) && "Renderlist index out of scope" );
98 return mRenderLists[ index ];
101 void RenderInstruction::Reset( const Matrix* viewMatrix,
102 const Matrix* projectionMatrix,
103 unsigned int offscreenTextureId,
104 const Viewport* viewport,
105 const Vector4* clearColor)
107 mViewMatrix = viewMatrix;
108 mProjectionMatrix = projectionMatrix;
109 mViewport = viewport ? *viewport : Viewport();
110 mIsViewportSet = NULL != viewport;
111 mClearColor = clearColor ? *clearColor : Color::BLACK;
112 mIsClearColorSet = NULL != clearColor;
114 mOffscreenTextureId = offscreenTextureId;
115 mRenderTracker = NULL;
116 mNextFreeRenderList = 0;
118 RenderListContainer::Iterator iter = mRenderLists.Begin();
119 RenderListContainer::ConstIterator end = mRenderLists.End();
120 for( ;iter != end; ++iter )
122 // since mRenderLists is a vector of RenderLists we dont want to clear it
123 // as it ends up releasing and later reallocating loads of vectors
124 // reset the renderlist
129 } // namespace SceneGraph
131 } // namespace Internal