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-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <render-tasks/render-task-list-api.h>
25 #include <shared/api-function.h>
26 #include <shared/object-template-helper.h>
33 v8::Persistent<v8::ObjectTemplate> RenderTaskListWrapper::mRenderTaskListTemplate;
39 * Contains a list of all functions that can be called
41 const ApiFunction RenderTaskListFunctionTable[]=
43 /**************************************
44 * RenderTaskList API (in order of renderTaskList.h)
45 **************************************/
47 { "CreateTask" , RenderTaskListApi::CreateTask },
48 { "RemoveTask" , RenderTaskListApi::RemoveTask },
49 { "GetTaskCount" , RenderTaskListApi::GetTaskCount },
50 { "GetTask" , RenderTaskListApi::GetTask },
55 const unsigned int RenderTaskListFunctionTableCount = sizeof(RenderTaskListFunctionTable)/sizeof(RenderTaskListFunctionTable[0]);
59 RenderTaskListWrapper::RenderTaskListWrapper( const Dali::RenderTaskList& renderTaskList, GarbageCollectorInterface& gc )
60 : BaseWrappedObject( BaseWrappedObject::RENDER_TASK_LIST , gc )
62 mRenderTaskList = renderTaskList;
65 RenderTaskListWrapper::~RenderTaskListWrapper()
70 v8::Handle<v8::Object> RenderTaskListWrapper::WrapRenderTaskList(v8::Isolate* isolate, const Dali::RenderTaskList& renderTaskList )
72 v8::EscapableHandleScope handleScope( isolate );
73 v8::Local<v8::ObjectTemplate> objectTemplate;
75 objectTemplate = GetRenderTaskListTemplate( isolate);
77 // create an instance of the template
78 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
80 // create the RenderTaskList wrapper
81 RenderTaskListWrapper* pointer = new RenderTaskListWrapper( renderTaskList, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
83 // assign the JavaScript object to the wrapper.
84 pointer->SetJavascriptObject( isolate, localObject );
86 return handleScope.Escape( localObject );
89 v8::Local<v8::ObjectTemplate> RenderTaskListWrapper::GetRenderTaskListTemplate( v8::Isolate* isolate)
91 v8::EscapableHandleScope handleScope( isolate );
92 v8::Local<v8::ObjectTemplate> objectTemplate;
94 if( mRenderTaskListTemplate.IsEmpty() )
96 objectTemplate = MakeRenderTaskListTemplate( isolate );
97 mRenderTaskListTemplate.Reset( isolate, objectTemplate );
101 // get the object template
102 objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mRenderTaskListTemplate );
104 return handleScope.Escape( objectTemplate );
107 v8::Handle<v8::ObjectTemplate> RenderTaskListWrapper::MakeRenderTaskListTemplate( v8::Isolate* isolate )
109 v8::EscapableHandleScope handleScope( isolate );
111 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
113 // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because RenderTaskList doesn't inherit
114 // from Handle ( just baseHandle)
115 ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
117 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
119 // add our function properties
120 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, RenderTaskListFunctionTable, RenderTaskListFunctionTableCount );
122 return handleScope.Escape( objTemplate );
125 // v8::Local<v8::Object> localObject = WrapRenderTaskList( isolate, renderTaskList );
126 // args.GetReturnValue().Set( localObject );
130 RenderTaskList RenderTaskListWrapper::GetRenderTaskList()
132 return mRenderTaskList;
136 } // namespace V8Plugin