Added Texture object and FrameBuffer object to rendering API
[platform/core/uifw/dali-core.git] / dali / public-api / render-tasks / render-task.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
18 // CLASS HEADER
19 #include <dali/public-api/render-tasks/render-task.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/internal/event/actors/camera-actor-impl.h>
25 #include <dali/internal/event/render-tasks/render-task-impl.h>
26 #include <dali/devel-api/rendering/frame-buffer.h>
27
28 namespace Dali
29 {
30
31 static bool DefaultScreenToFrameBufferFunction( Vector2& coordinates )
32 {
33   return false;
34 }
35
36 static bool FullScreenFrameBufferFunction( Vector2& coordinates )
37 {
38   // Don't need to modify frameBufferCoords
39   return true;
40 }
41
42 RenderTask::ConstScreenToFrameBufferFunction RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION = DefaultScreenToFrameBufferFunction;
43 RenderTask::ConstScreenToFrameBufferFunction RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION        = FullScreenFrameBufferFunction;
44
45 const bool         RenderTask::DEFAULT_EXCLUSIVE     = false;
46 const bool         RenderTask::DEFAULT_INPUT_ENABLED = true;
47 const Vector4      RenderTask::DEFAULT_CLEAR_COLOR   = Vector4( 0.0f, 0.0f, 0.0f, 1.0f ); // cannot use Color::Black because it may or may not be initialized yet
48 const bool         RenderTask::DEFAULT_CLEAR_ENABLED = false;
49 const bool         RenderTask::DEFAULT_CULL_MODE     = true;
50 const unsigned int RenderTask::DEFAULT_REFRESH_RATE  = REFRESH_ALWAYS;
51
52 RenderTask::RenderTask()
53 {
54 }
55
56 RenderTask RenderTask::DownCast( BaseHandle handle )
57 {
58   return RenderTask( dynamic_cast<Dali::Internal::RenderTask*>( handle.GetObjectPtr() ) );
59 }
60
61 RenderTask::~RenderTask()
62 {
63 }
64
65 RenderTask::RenderTask(const RenderTask& handle)
66 : Handle(handle)
67 {
68 }
69
70 RenderTask& RenderTask::operator=(const RenderTask& rhs)
71 {
72   BaseHandle::operator=(rhs);
73   return *this;
74 }
75
76 void RenderTask::SetSourceActor( Actor actor )
77 {
78   // NULL handle is allowed
79   Internal::Actor* actorImpl( NULL );
80   if ( actor )
81   {
82     actorImpl = &GetImplementation( actor );
83   }
84
85   GetImplementation(*this).SetSourceActor( actorImpl );
86 }
87
88 Actor RenderTask::GetSourceActor() const
89 {
90   return Dali::Actor(GetImplementation(*this).GetSourceActor());
91 }
92
93 void RenderTask::SetExclusive( bool exclusive )
94 {
95   GetImplementation(*this).SetExclusive( exclusive );
96 }
97
98 bool RenderTask::IsExclusive() const
99 {
100   return GetImplementation(*this).IsExclusive();
101 }
102
103 void RenderTask::SetCameraActor( CameraActor cameraActor )
104 {
105   // NULL handle is allowed
106   Internal::CameraActor* actorImpl( NULL );
107   if ( cameraActor )
108   {
109     actorImpl = &GetImplementation( cameraActor );
110   }
111
112   GetImplementation(*this).SetCameraActor( actorImpl );
113 }
114
115 CameraActor RenderTask::GetCameraActor() const
116 {
117   return Dali::CameraActor(GetImplementation(*this).GetCameraActor());
118 }
119
120 void RenderTask::SetTargetFrameBuffer( FrameBufferImage frameBuffer )
121 {
122   GetImplementation(*this).SetTargetFrameBuffer( frameBuffer );
123 }
124
125 FrameBufferImage RenderTask::GetTargetFrameBuffer() const
126 {
127   return GetImplementation(*this).GetTargetFrameBuffer();
128 }
129
130 void RenderTask::SetFrameBuffer( FrameBuffer frameBuffer )
131 {
132   GetImplementation(*this).SetFrameBuffer( frameBuffer );
133 }
134
135 FrameBuffer RenderTask::GetFrameBuffer() const
136 {
137   Internal::FrameBuffer* frameBufferPtr( GetImplementation(*this).GetFrameBuffer() );
138   return FrameBuffer( frameBufferPtr );
139 }
140
141 void RenderTask::SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction )
142 {
143   GetImplementation(*this).SetScreenToFrameBufferFunction( conversionFunction );
144 }
145
146 RenderTask::ScreenToFrameBufferFunction RenderTask::GetScreenToFrameBufferFunction() const
147 {
148   return GetImplementation(*this).GetScreenToFrameBufferFunction();
149 }
150
151 void RenderTask::SetScreenToFrameBufferMappingActor( Dali::Actor mappingActor )
152 {
153   // NULL handle is allowed
154   Internal::Actor* actorImpl( NULL );
155   if ( mappingActor )
156   {
157     actorImpl = &GetImplementation( mappingActor );
158   }
159
160   GetImplementation(*this).SetScreenToFrameBufferMappingActor( actorImpl );
161 }
162
163 Dali::Actor RenderTask::GetScreenToFrameBufferMappingActor() const
164 {
165   return Dali::Actor(GetImplementation(*this).GetScreenToFrameBufferMappingActor());
166 }
167
168 void RenderTask::SetViewportPosition( Vector2 position )
169 {
170   GetImplementation(*this).SetViewportPosition( position );
171 }
172
173 Vector2 RenderTask::GetCurrentViewportPosition() const
174 {
175   return GetImplementation(*this).GetCurrentViewportPosition();
176 }
177
178 void RenderTask::SetViewportSize( Vector2 size )
179 {
180   GetImplementation(*this).SetViewportSize( size );
181 }
182
183 Vector2 RenderTask::GetCurrentViewportSize() const
184 {
185   return GetImplementation(*this).GetCurrentViewportSize();
186 }
187
188 void RenderTask::SetViewport( Viewport viewport )
189 {
190   GetImplementation(*this).SetViewport( viewport );
191 }
192
193 Viewport RenderTask::GetViewport() const
194 {
195   Viewport result;
196   GetImplementation(*this).GetViewport( result );
197   return result;
198 }
199
200 void RenderTask::SetClearColor( const Vector4& color )
201 {
202   GetImplementation(*this).SetClearColor( color );
203 }
204
205 Vector4 RenderTask::GetClearColor() const
206 {
207   return GetImplementation(*this).GetClearColor();
208 }
209
210 void RenderTask::SetClearEnabled( bool enabled )
211 {
212   GetImplementation(*this).SetClearEnabled( enabled );
213 }
214
215 bool RenderTask::GetClearEnabled() const
216 {
217   return GetImplementation(*this).GetClearEnabled();
218 }
219
220 void RenderTask::SetCullMode( bool mode )
221 {
222   GetImplementation(*this).SetCullMode( mode );
223 }
224
225 bool RenderTask::GetCullMode() const
226 {
227   return GetImplementation(*this).GetCullMode();
228 }
229
230 void RenderTask::SetRefreshRate( unsigned int refreshRate )
231 {
232   GetImplementation(*this).SetRefreshRate( refreshRate );
233 }
234
235 unsigned int RenderTask::GetRefreshRate() const
236 {
237   return GetImplementation(*this).GetRefreshRate();
238 }
239
240 RenderTask::RenderTaskSignalType& RenderTask::FinishedSignal()
241 {
242   return GetImplementation(*this).FinishedSignal();
243 }
244
245 void RenderTask::SetInputEnabled( bool enabled )
246 {
247   GetImplementation(*this).SetInputEnabled( enabled );
248 }
249
250 bool RenderTask::GetInputEnabled() const
251 {
252   return GetImplementation(*this).GetInputEnabled();
253 }
254
255 bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
256 {
257   return GetImplementation(*this).WorldToViewport(position, viewportX, viewportY);
258 }
259
260 bool RenderTask::ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const
261 {
262   if( actor )
263   {
264     Internal::Actor* actorImpl( &GetImplementation( actor ) );
265     return GetImplementation(*this).ViewportToLocal( actorImpl, viewportX, viewportY, localX, localY );
266   }
267   else
268   {
269     return false;
270   }
271 }
272
273
274 RenderTask::RenderTask( Internal::RenderTask* internal )
275 : Handle(internal)
276 {
277 }
278
279 } // namespace Dali