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 "builder-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <toolkit/builder/builder-api.h>
25 #include <shared/api-function.h>
26 #include <shared/object-template-helper.h>
36 * Contains a list of all functions that can be called
38 const ApiFunction BuilderFunctionTable[]=
40 /**************************************
41 * Builder API (in order of builder.h)
42 **************************************/
44 { "LoadFromString" , BuilderApi::LoadFromString },
45 { "LoadFromFile" , BuilderApi::LoadFromFile },
46 { "AddConstants" , BuilderApi::AddConstants },
47 { "GetConstants" , BuilderApi::GetConstants },
48 { "CreateAnimation" , BuilderApi::CreateAnimation },
49 { "Create" , BuilderApi::Create },
50 { "ApplyStyle" , BuilderApi::ApplyStyle },
51 { "ApplyFromJson" , BuilderApi::ApplyFromJson },
52 { "AddActors" , BuilderApi::AddActors },
53 { "CreateRenderTask" , BuilderApi::CreateRenderTask },
54 { "GetShaderEffect" , BuilderApi::GetShaderEffect },
55 { "GetFrameBufferImage" , BuilderApi::GetFrameBufferImage }
58 const unsigned int BuilderFunctionTableCount = sizeof(BuilderFunctionTable)/sizeof(BuilderFunctionTable[0]);
62 BuilderWrapper::BuilderWrapper( const Dali::Toolkit::Builder& builder, GarbageCollectorInterface& gc )
63 : BaseWrappedObject( BaseWrappedObject::BUILDER , gc )
68 BuilderWrapper::~BuilderWrapper()
73 v8::Handle<v8::Object> BuilderWrapper::WrapBuilder(v8::Isolate* isolate, const Dali::Toolkit::Builder& builder )
75 v8::EscapableHandleScope handleScope( isolate );
76 v8::Local<v8::ObjectTemplate> objectTemplate;
78 objectTemplate = GetBuilderTemplate( isolate);
80 // create an instance of the template
81 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
83 // create the Builder wrapper
84 BuilderWrapper* pointer = new BuilderWrapper( builder, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
86 // assign the JavaScript object to the wrapper.
87 pointer->SetJavascriptObject( isolate, localObject );
89 return handleScope.Escape( localObject );
92 v8::Local<v8::ObjectTemplate> BuilderWrapper::GetBuilderTemplate( v8::Isolate* isolate)
94 v8::EscapableHandleScope handleScope( isolate );
95 v8::Local<v8::ObjectTemplate> objectTemplate;
97 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
99 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
101 // add our function properties
102 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, BuilderFunctionTable, BuilderFunctionTableCount );
104 return handleScope.Escape( objTemplate );
108 void BuilderWrapper::NewBuilder( const v8::FunctionCallbackInfo< v8::Value >& args)
110 v8::Isolate* isolate = args.GetIsolate();
111 v8::HandleScope handleScope( isolate);
113 if( !args.IsConstructCall() )
115 DALI_SCRIPT_EXCEPTION( isolate, "Builder constructor called without 'new'" );
119 Dali::Toolkit::Builder builder = BuilderApi::New( args );
120 v8::Local<v8::Object> localObject = WrapBuilder( isolate, builder );
121 args.GetReturnValue().Set( localObject );
125 Dali::Toolkit::Builder BuilderWrapper::GetBuilder()
131 } // namespace V8Plugin