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()
35 : mRenderTracker( NULL ),
37 mIsViewportSet( false ),
38 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_ALWAYS( (index < mNextFreeRenderList ) && "Renderlist index out of scope" );
97 return mRenderLists[ index ];
100 void RenderInstruction::Reset( CameraAttachment* cameraAttachment,
101 unsigned int offscreenTextureId,
102 const Viewport* viewport,
103 const Vector4* clearColor )
105 mCameraAttachment = cameraAttachment;
106 mViewport = viewport ? *viewport : Viewport();
107 mIsViewportSet = NULL != viewport;
108 mClearColor = clearColor ? *clearColor : Color::BLACK;
109 mIsClearColorSet = NULL != clearColor;
111 mOffscreenTextureId = offscreenTextureId;
112 mRenderTracker = NULL;
113 mNextFreeRenderList = 0;
115 RenderListContainer::Iterator iter = mRenderLists.Begin();
116 RenderListContainer::ConstIterator end = mRenderLists.End();
117 for( ;iter != end; ++iter )
119 // since mRenderLists is a vector of RenderLists we dont want to clear it
120 // as it ends up releasing and later reallocating loads of vectors
121 // reset the renderlist
126 } // namespace SceneGraph
128 } // namespace Internal