2 * Copyright (c) 2015 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 "render-task-list-api.h"
22 #include <dali/integration-api/debug.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>
37 namespace // un named namespace
45 An ordered list of Dali::RenderTasks
47 These tasks describe how the Dali scene should be rendered;
48 See {{#crossLink "RenderTask"}}{{/crossLink}}
54 RenderTaskList GetRenderTaskList( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
56 v8::HandleScope handleScope( isolate );
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();
62 RenderTaskListWrapper* wrapper = static_cast<RenderTaskListWrapper *>( ptr );
63 return wrapper->GetRenderTaskList();
67 } // un-named namespace
70 * Create a new RenderTask.
71 * This will be appended to the list of render-tasks.
74 * @return {Object} RenderTask
76 void RenderTaskListApi::CreateTask( const v8::FunctionCallbackInfo< v8::Value >& args )
78 v8::Isolate* isolate = args.GetIsolate();
79 v8::HandleScope handleScope( isolate );
80 RenderTaskList taskList = GetRenderTaskList( isolate, args);
82 RenderTask renderTask = taskList.CreateTask();
84 v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
85 args.GetReturnValue().Set( wrappedTask );
90 * Remove a RenderTask from the list of render-tasks.
93 * @param{Object} RenderTask to remove
95 void RenderTaskListApi::RemoveTask( const v8::FunctionCallbackInfo< v8::Value >& args )
97 v8::Isolate* isolate = args.GetIsolate();
98 v8::HandleScope handleScope( isolate );
99 RenderTaskList taskList = GetRenderTaskList( isolate, args );
102 RenderTask renderTask = V8Utils::GetRenderTaskParameter( PARAMETER_0, found, isolate, args );
105 DALI_SCRIPT_EXCEPTION( isolate, "render-task parameter missing" );
108 taskList.RemoveTask( renderTask );
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.
117 void RenderTaskListApi::GetTaskCount( const v8::FunctionCallbackInfo< v8::Value >& args )
119 v8::Isolate* isolate = args.GetIsolate();
120 v8::HandleScope handleScope( isolate );
121 RenderTaskList taskList = GetRenderTaskList( isolate, args );
123 args.GetReturnValue().Set( v8::Integer::New( isolate, taskList.GetTaskCount() ) );
127 * Retrieve a render-task.
128 * index should be in range i.e. less than GetTaskCount().
130 * @for RenderTaskList
131 * @param {Number} index The index of the render task to retrieve
132 * @return {Object} The render-task
134 void RenderTaskListApi::GetTask( const v8::FunctionCallbackInfo< v8::Value >& args )
136 v8::Isolate* isolate = args.GetIsolate();
137 v8::HandleScope handleScope( isolate );
138 RenderTaskList taskList = GetRenderTaskList( isolate, args );
141 int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
144 DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
147 RenderTask renderTask = taskList.GetTask( index );
149 v8::Handle<v8::Object> wrappedTask = RenderTaskWrapper::WrapRenderTask(isolate, renderTask);
150 args.GetReturnValue().Set( wrappedTask );
153 } // namespace V8Plugin