e57d3a3b623bbe1ad66077666fd0fc9afebf0dea
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / image / image-api.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 "image-api.h"
20
21 // INTERNAL INCLUDES
22 #include <v8-utils.h>
23 #include <image/image-wrapper.h>
24
25 namespace Dali
26 {
27
28 namespace V8Plugin
29 {
30
31 Image ImageApi::GetImage( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
32 {
33   v8::HandleScope handleScope( isolate );
34
35   v8::Local<v8::Object> object = args.This();
36   v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
37   void* ptr = field->Value();
38
39   ImageWrapper* wrapper = static_cast< ImageWrapper *>(ptr);
40   return wrapper->GetImage();
41 }
42
43 /**
44  * @constructor Image
45  * @method Image
46  * @for Image
47  * @return {Object} Image
48  */
49 Image ImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
50 {
51   v8::Isolate* isolate = args.GetIsolate();
52   v8::HandleScope handleScope( isolate );
53   DALI_SCRIPT_EXCEPTION( isolate, "Image base class can not be constructed, try new dali.ResourceImage()");
54   return Image();
55 }
56
57 /**
58  * Return the image release policy
59  * @method getReleasePolicy
60  * @return dali.IMAGE_RELEASE_POLICY_UNUSED or dali.IMAGE_RELEASE_POLICY_NEVER
61  * @for Image
62  */
63 void ImageApi::GetReleasePolicy( const v8::FunctionCallbackInfo< v8::Value >& args )
64 {
65   v8::Isolate* isolate = args.GetIsolate();
66   v8::HandleScope handleScope( isolate );
67
68   Image image = GetImage( isolate, args );
69
70   args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetReleasePolicy() ) );
71 }
72
73 /**
74  * Return the image width in pixels
75  * @method getWidth
76  * @for Image
77  */
78 void ImageApi::GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args )
79 {
80   v8::Isolate* isolate = args.GetIsolate();
81   v8::HandleScope handleScope( isolate );
82
83   Image image = GetImage( isolate, args );
84
85   args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetWidth() ) );
86 }
87 /**
88  * Return the image height in pixels
89  * @method getHeight
90  * @for Image
91  */
92 void ImageApi::GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args )
93 {
94   v8::Isolate* isolate = args.GetIsolate();
95   v8::HandleScope handleScope( isolate );
96
97   Image image = GetImage( isolate, args );
98
99   args.GetReturnValue().Set( v8::Integer::New( isolate, image.GetHeight() ) );
100 }
101
102 } // namespace V8Plugin
103
104 } // namespace Dali