Remove SetTextureAffectsTransparency as it is not needed
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / shader-effects / shader-effect-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 "shader-effect-wrapper.h"
20
21 // INTERNAL INCLUDES
22 #include <v8-utils.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>
28
29 namespace Dali
30 {
31
32 namespace V8Plugin
33 {
34
35 v8::Persistent<v8::ObjectTemplate> ShaderEffectWrapper::mShaderEffectTemplate;
36
37 namespace // un-named name space
38 {
39
40 /**
41  * Contains a list of all functions that can be called
42  */
43 const ApiFunction ShaderEffectFunctionTable[]=
44 {
45     /**************************************
46     * ShaderEffect API (in order of shaderEffect.h)
47     **************************************/
48
49    { "SetEffectImage"             , ShaderEffectApi::SetEffectImage },
50    { "SetUniform"                 , ShaderEffectApi::SetUniform     },
51 };
52
53 const unsigned int ShaderEffectFunctionTableCount = sizeof(ShaderEffectFunctionTable)/sizeof(ShaderEffectFunctionTable[0]);
54 } //un-named space
55
56
57 ShaderEffectWrapper::ShaderEffectWrapper( const Dali::ShaderEffect& shaderEffect, GarbageCollectorInterface& gc )
58 :  HandleWrapper(  BaseWrappedObject::SHADER_EFFECT , shaderEffect, gc )
59 {
60     mShaderEffect = shaderEffect;
61 }
62
63 v8::Handle<v8::Object> ShaderEffectWrapper::WrapShaderEffect(v8::Isolate* isolate, const Dali::ShaderEffect& shaderEffect )
64 {
65   v8::EscapableHandleScope handleScope( isolate );
66   v8::Local<v8::ObjectTemplate> objectTemplate;
67
68   objectTemplate = GetShaderEffectTemplate( isolate);
69
70   // create an instance of the template
71   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
72
73   // create the ShaderEffect wrapper
74   ShaderEffectWrapper* pointer =  new ShaderEffectWrapper( shaderEffect, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
75
76   // assign the JavaScript object to the wrapper.
77   pointer->SetJavascriptObject( isolate, localObject );
78
79   return handleScope.Escape( localObject );
80 }
81
82 v8::Local<v8::ObjectTemplate> ShaderEffectWrapper::GetShaderEffectTemplate( v8::Isolate* isolate)
83 {
84   v8::EscapableHandleScope handleScope( isolate );
85   v8::Local<v8::ObjectTemplate> objectTemplate;
86
87   if( mShaderEffectTemplate.IsEmpty() )
88   {
89     objectTemplate = MakeShaderEffectTemplate( isolate );
90     mShaderEffectTemplate.Reset( isolate, objectTemplate );
91   }
92   else
93   {
94     // get the object template
95     objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mShaderEffectTemplate );
96   }
97   return handleScope.Escape( objectTemplate );
98 }
99
100 v8::Handle<v8::ObjectTemplate> ShaderEffectWrapper::MakeShaderEffectTemplate( v8::Isolate* isolate )
101 {
102   v8::EscapableHandleScope handleScope( isolate );
103
104   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
105
106   // property handle intercepts property getters and setters and signals
107   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
108
109   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
110
111   // add our function properties
112   ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ShaderEffectFunctionTable, ShaderEffectFunctionTableCount );
113
114   return handleScope.Escape( objTemplate );
115 }
116
117 void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args)
118 {
119   v8::Isolate* isolate = args.GetIsolate();
120   v8::HandleScope handleScope( isolate);
121
122   if(!args.IsConstructCall())
123   {
124       DALI_SCRIPT_EXCEPTION( isolate, "ShaderEffect constructor called without 'new'");
125       return;
126   }
127   Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
128
129   if(shaderEffect)
130   {
131     v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
132     args.GetReturnValue().Set( localObject );
133   }
134 }
135
136
137 ShaderEffect ShaderEffectWrapper::GetShaderEffect()
138 {
139   return mShaderEffect;
140 }
141
142
143 } // namespace V8Plugin
144
145 } // namespace Dali