JavaScript support for DALi
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / render-tasks / render-task-list-wrapper.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-wrapper.h"
20
21 // INTERNAL INCLUDES
22 #include <v8-utils.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>
27
28 namespace Dali
29 {
30 namespace V8Plugin
31 {
32
33 v8::Persistent<v8::ObjectTemplate> RenderTaskListWrapper::mRenderTaskListTemplate;
34
35 namespace
36 {
37
38 /**
39  * Contains a list of all functions that can be called
40  */
41 const ApiFunction RenderTaskListFunctionTable[]=
42 {
43     /**************************************
44     * RenderTaskList API (in order of renderTaskList.h)
45     **************************************/
46
47     { "CreateTask"             , RenderTaskListApi::CreateTask     },
48     { "RemoveTask"             , RenderTaskListApi::RemoveTask     },
49     { "GetTaskCount"           , RenderTaskListApi::GetTaskCount   },
50     { "GetTask"                , RenderTaskListApi::GetTask        },
51
52
53 };
54
55 const unsigned int RenderTaskListFunctionTableCount = sizeof(RenderTaskListFunctionTable)/sizeof(RenderTaskListFunctionTable[0]);
56 } //un-named space
57
58
59 RenderTaskListWrapper::RenderTaskListWrapper( const Dali::RenderTaskList& renderTaskList, GarbageCollectorInterface& gc )
60 : BaseWrappedObject( BaseWrappedObject::RENDER_TASK_LIST , gc )
61 {
62     mRenderTaskList = renderTaskList;
63 }
64
65 RenderTaskListWrapper::~RenderTaskListWrapper()
66 {
67
68 }
69
70 v8::Handle<v8::Object> RenderTaskListWrapper::WrapRenderTaskList(v8::Isolate* isolate, const Dali::RenderTaskList& renderTaskList )
71 {
72   v8::EscapableHandleScope handleScope( isolate );
73   v8::Local<v8::ObjectTemplate> objectTemplate;
74
75   objectTemplate = GetRenderTaskListTemplate( isolate);
76
77   // create an instance of the template
78   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
79
80   // create the RenderTaskList wrapper
81   RenderTaskListWrapper* pointer =  new RenderTaskListWrapper( renderTaskList, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
82
83   // assign the JavaScript object to the wrapper.
84   pointer->SetJavascriptObject( isolate, localObject );
85
86   return handleScope.Escape( localObject );
87 }
88
89 v8::Local<v8::ObjectTemplate> RenderTaskListWrapper::GetRenderTaskListTemplate( v8::Isolate* isolate)
90 {
91   v8::EscapableHandleScope handleScope( isolate );
92   v8::Local<v8::ObjectTemplate> objectTemplate;
93
94   if( mRenderTaskListTemplate.IsEmpty() )
95   {
96     objectTemplate = MakeRenderTaskListTemplate( isolate );
97     mRenderTaskListTemplate.Reset( isolate, objectTemplate );
98   }
99   else
100   {
101     // get the object template
102     objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mRenderTaskListTemplate );
103   }
104   return handleScope.Escape( objectTemplate );
105 }
106
107 v8::Handle<v8::ObjectTemplate> RenderTaskListWrapper::MakeRenderTaskListTemplate( v8::Isolate* isolate )
108 {
109   v8::EscapableHandleScope handleScope( isolate );
110
111   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
112
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 );
116
117   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
118
119   // add our function properties
120   ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, RenderTaskListFunctionTable, RenderTaskListFunctionTableCount );
121
122   return handleScope.Escape( objTemplate );
123 }
124
125 //  v8::Local<v8::Object> localObject = WrapRenderTaskList( isolate, renderTaskList );
126  // args.GetReturnValue().Set( localObject );
127
128
129
130 RenderTaskList RenderTaskListWrapper::GetRenderTaskList()
131 {
132   return mRenderTaskList;
133 }
134
135
136 } // namespace V8Plugin
137
138 } // namespace Dali