DALi Version 1.4.26
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / render-tasks / render-task-list-api.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 "render-task-list-api.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL INCLUDES
25 #include <v8-utils.h>
26 #include <render-tasks/render-task-list-wrapper.h>
27 #include <render-tasks/render-task-wrapper.h>
28 #include <render-tasks/render-task-api.h>
29 #include <object/property-value-wrapper.h>
30
31 namespace Dali
32 {
33
34 namespace V8Plugin
35 {
36
37 namespace // un named namespace
38 {
39
40 /**
41  *
42 ## RenderTaskList API
43
44
45 An ordered list of Dali::RenderTasks
46
47 These tasks describe how the Dali scene should be rendered;
48 See {{#crossLink "RenderTask"}}{{/crossLink}}
49
50  @class RenderTaskList
51 */
52
53
54 RenderTaskList GetRenderTaskList( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
55 {
56   v8::HandleScope handleScope( isolate );
57
58   v8::Local<v8::Object> object = args.This();
59   v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
60   void* ptr = field->Value();
61
62   RenderTaskListWrapper* wrapper = static_cast<RenderTaskListWrapper *>( ptr );
63   return wrapper->GetRenderTaskList();
64 }
65
66
67 } // un-named namespace
68
69 /**
70  * Create a new RenderTask.
71  * This will be appended to the list of render-tasks.
72  * @method createTask
73  * @for RenderTaskList
74  * @return {Object} RenderTask
75  */
76 void RenderTaskListApi::CreateTask( const v8::FunctionCallbackInfo< v8::Value >& args )
77 {
78   v8::Isolate* isolate = args.GetIsolate();
79   v8::HandleScope handleScope( isolate );
80   RenderTaskList taskList = GetRenderTaskList( isolate, args);
81
82   RenderTask renderTask = taskList.CreateTask();
83
84   v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
85   args.GetReturnValue().Set( wrappedTask  );
86
87 }
88
89 /**
90  * Remove a RenderTask from the list of render-tasks.
91  * @method removeTask
92  * @for RenderTaskList
93  * @param{Object} RenderTask to remove
94  */
95 void RenderTaskListApi::RemoveTask( const v8::FunctionCallbackInfo< v8::Value >& args )
96 {
97   v8::Isolate* isolate = args.GetIsolate();
98   v8::HandleScope handleScope( isolate );
99   RenderTaskList taskList = GetRenderTaskList( isolate, args );
100
101   bool found( false );
102   RenderTask renderTask = V8Utils::GetRenderTaskParameter( PARAMETER_0, found, isolate, args );
103   if(! found )
104   {
105     DALI_SCRIPT_EXCEPTION( isolate, "render-task parameter missing" );
106     return;
107   }
108   taskList.RemoveTask( renderTask );
109 }
110 /**
111  * Query the number of render-tasks in the list.
112  * This is ordered i.e. the task with index 0 is the first to be processed each frame.
113  * @method getTaskCount
114  * @for RenderTaskList
115  * @return {Number}  The number of render-tasks.
116  */
117 void RenderTaskListApi::GetTaskCount( const v8::FunctionCallbackInfo< v8::Value >& args )
118 {
119   v8::Isolate* isolate = args.GetIsolate();
120   v8::HandleScope handleScope( isolate );
121   RenderTaskList taskList = GetRenderTaskList( isolate, args );
122
123   args.GetReturnValue().Set( v8::Integer::New( isolate, taskList.GetTaskCount() ) );
124
125 }
126 /**
127  * Retrieve a render-task.
128  * index should be in range i.e. less than GetTaskCount().
129  * @method getTask
130  * @for RenderTaskList
131  * @param {Number} index The index of the render task to retrieve
132  * @return {Object}  The render-task
133  */
134 void RenderTaskListApi::GetTask( const v8::FunctionCallbackInfo< v8::Value >& args )
135 {
136   v8::Isolate* isolate = args.GetIsolate();
137   v8::HandleScope handleScope( isolate );
138   RenderTaskList taskList = GetRenderTaskList( isolate, args );
139
140   bool found( false );
141   int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
142   if( !found )
143   {
144      DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
145      return;
146   }
147   RenderTask renderTask = taskList.GetTask( index );
148
149   v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
150   args.GetReturnValue().Set( wrappedTask  );
151 }
152
153 } // namespace V8Plugin
154
155 } // namespace Dali