Merge branch devel/master (1.0.49) into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-buffer.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dali/internal/update/common/scene-graph-property-buffer.h>
18
19 namespace Dali
20 {
21 namespace Internal
22 {
23 namespace SceneGraph
24 {
25
26 PropertyBuffer::PropertyBuffer()
27 : mBufferData(NULL),
28   mDataChanged(false),
29   mSize(0u)
30 {
31 }
32
33 PropertyBuffer::~PropertyBuffer()
34 {
35 }
36
37 void PropertyBuffer::SetFormat( PropertyBufferMetadata::Format* format )
38 {
39   mFormat = format;
40 }
41
42 void PropertyBuffer::SetSize( BufferIndex bufferIndex, unsigned int size )
43 {
44   mSize.Set(bufferIndex, size);
45 }
46
47 void PropertyBuffer::SetData(  BufferIndex bufferIndex, PropertyBufferDataProvider::BufferType* data )
48 {
49   mBufferData[bufferIndex] = data;
50   mDataChanged[bufferIndex] = true;
51 }
52
53 void PropertyBuffer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
54 {
55 }
56
57 void PropertyBuffer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
58 {
59 }
60
61 bool PropertyBuffer::HasDataChanged( BufferIndex bufferIndex ) const
62 {
63   return mDataChanged[ bufferIndex ];
64 }
65
66 unsigned int PropertyBuffer::GetAttributeCount( BufferIndex bufferIndex ) const
67 {
68   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
69   return mFormat->components.size();
70 }
71
72 const std::string& PropertyBuffer::GetAttributeName( BufferIndex bufferIndex, unsigned int index ) const
73 {
74   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
75   return mFormat->components[index].name;
76 }
77
78 size_t PropertyBuffer::GetAttributeSize( BufferIndex bufferIndex, unsigned int index ) const
79 {
80   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
81
82   return mFormat->components[index].size;
83 }
84
85 Property::Type PropertyBuffer::GetAttributeType( BufferIndex bufferIndex, unsigned int index ) const
86 {
87   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
88
89   return mFormat->components[index].type;
90 }
91
92 size_t PropertyBuffer::GetAttributeOffset( BufferIndex bufferIndex, unsigned int index ) const
93 {
94   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
95
96   return mFormat->components[index].offset;
97 }
98
99 const PropertyBufferDataProvider::BufferType& PropertyBuffer::GetData( BufferIndex bufferIndex ) const
100 {
101   DALI_ASSERT_DEBUG( mBufferData[bufferIndex] && "Should have some data.");
102
103   return *mBufferData[bufferIndex];
104 }
105
106 std::size_t PropertyBuffer::GetDataSize( BufferIndex bufferIndex ) const
107 {
108   DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
109
110   return mFormat->size * mSize[ bufferIndex ];
111 }
112
113
114 std::size_t PropertyBuffer::GetElementSize( BufferIndex bufferIndex ) const
115 {
116   return mFormat->size;
117 }
118
119 unsigned int PropertyBuffer::GetElementCount( BufferIndex bufferIndex ) const
120 {
121   return mSize[bufferIndex];
122 }
123
124 unsigned int PropertyBuffer::GetGpuBufferId( BufferIndex bufferIndex ) const
125 {
126   //TODO: MESH_REWORK fix this
127   DALI_ASSERT_DEBUG(false && "FIX THIS");
128
129   return 0;
130 }
131
132 void PropertyBuffer::ResetDefaultProperties( BufferIndex updateBufferIndex )
133 {
134   // Age the double buffered properties
135   mSize.CopyPrevious(updateBufferIndex);
136
137   // Update double buffered value
138   mBufferData.CopyPrevious(updateBufferIndex);
139
140   // The flag should be reset each frame
141   mDataChanged[updateBufferIndex] = false;
142 }
143
144 } // namespace SceneGraph
145 } // namespace Internal
146 } // namespace Dali