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 "shader-effect-wrapper.h"
23 #include <shader-effects/shader-effect-api.h>
24 #include <shared/api-function.h>
25 #include <shared/object-template-helper.h>
26 #include <signals/signal-manager.h>
27 #include <dali-wrapper.h>
35 v8::Persistent<v8::ObjectTemplate> ShaderEffectWrapper::mShaderEffectTemplate;
37 namespace // un-named name space
41 * Contains a list of all functions that can be called
43 const ApiFunction ShaderEffectFunctionTable[]=
45 /**************************************
46 * ShaderEffect API (in order of shaderEffect.h)
47 **************************************/
49 { "SetEffectImage" , ShaderEffectApi::SetEffectImage },
50 { "SetUniform" , ShaderEffectApi::SetUniform },
53 const unsigned int ShaderEffectFunctionTableCount = sizeof(ShaderEffectFunctionTable)/sizeof(ShaderEffectFunctionTable[0]);
57 ShaderEffectWrapper::ShaderEffectWrapper( const Dali::ShaderEffect& shaderEffect, GarbageCollectorInterface& gc )
58 : HandleWrapper( BaseWrappedObject::SHADER_EFFECT , shaderEffect, gc )
60 mShaderEffect = shaderEffect;
63 v8::Handle<v8::Object> ShaderEffectWrapper::WrapShaderEffect(v8::Isolate* isolate, const Dali::ShaderEffect& shaderEffect )
65 v8::EscapableHandleScope handleScope( isolate );
66 v8::Local<v8::ObjectTemplate> objectTemplate;
68 objectTemplate = GetShaderEffectTemplate( isolate);
70 // create an instance of the template
71 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
73 // create the ShaderEffect wrapper
74 ShaderEffectWrapper* pointer = new ShaderEffectWrapper( shaderEffect, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
76 // assign the JavaScript object to the wrapper.
77 pointer->SetJavascriptObject( isolate, localObject );
79 return handleScope.Escape( localObject );
82 v8::Local<v8::ObjectTemplate> ShaderEffectWrapper::GetShaderEffectTemplate( v8::Isolate* isolate)
84 v8::EscapableHandleScope handleScope( isolate );
85 v8::Local<v8::ObjectTemplate> objectTemplate;
87 if( mShaderEffectTemplate.IsEmpty() )
89 objectTemplate = MakeShaderEffectTemplate( isolate );
90 mShaderEffectTemplate.Reset( isolate, objectTemplate );
94 // get the object template
95 objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mShaderEffectTemplate );
97 return handleScope.Escape( objectTemplate );
100 v8::Handle<v8::ObjectTemplate> ShaderEffectWrapper::MakeShaderEffectTemplate( v8::Isolate* isolate )
102 v8::EscapableHandleScope handleScope( isolate );
104 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
106 // property handle intercepts property getters and setters and signals
107 HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
109 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
111 // add our function properties
112 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ShaderEffectFunctionTable, ShaderEffectFunctionTableCount );
114 return handleScope.Escape( objTemplate );
117 void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args)
119 v8::Isolate* isolate = args.GetIsolate();
120 v8::HandleScope handleScope( isolate);
122 if(!args.IsConstructCall())
124 DALI_SCRIPT_EXCEPTION( isolate, "ShaderEffect constructor called without 'new'");
127 Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
131 v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
132 args.GetReturnValue().Set( localObject );
137 ShaderEffect ShaderEffectWrapper::GetShaderEffect()
139 return mShaderEffect;
143 } // namespace V8Plugin