[NUI] Fix Svace issue (#949)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Image.cs
1 /*
2  * Copyright(c) 2017 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 namespace Tizen.NUI
19 {
20
21     using System;
22     using System.Runtime.InteropServices;
23
24
25     internal class Image : BaseHandle
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal Image(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Image.Image_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Image obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         protected override void Dispose(DisposeTypes type)
40         {
41             if (disposed)
42             {
43                 return;
44             }
45
46             if (type == DisposeTypes.Explicit)
47             {
48                 //Called by User
49                 //Release your own managed resources here.
50                 //You should release all of your own disposable objects here.
51
52             }
53
54             //Release your own unmanaged resources here.
55             //You should not access any managed member here except static instance.
56             //because the execution order of Finalizes is non-deterministic.
57
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63                     Interop.Image.delete_Image(swigCPtr);
64                 }
65                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66             }
67
68             base.Dispose(type);
69         }
70
71
72
73         /**
74           * @brief Event arguments that passed via Uploaded signal
75           *
76           */
77         /// <since_tizen> 3 </since_tizen>
78         public class UploadedEventArgs : EventArgs
79         {
80             private Image _image;
81             /**
82               * @brief Image - is the image data that gets uploaded to GL.
83               *
84               */
85             /// <since_tizen> 3 </since_tizen>
86             public Image Image
87             {
88                 get
89                 {
90                     return _image;
91                 }
92                 set
93                 {
94                     _image = value;
95                 }
96             }
97         }
98
99         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
100         private delegate void UploadedEventCallbackDelegate(IntPtr image);
101         private DaliEventHandler<object, UploadedEventArgs> _imageUploadedEventHandler;
102         private UploadedEventCallbackDelegate _imageUploadedEventCallbackDelegate;
103
104         /**
105           * @brief Event for Uploaded signal which can be used to subscribe/unsubscribe the event handler
106           * provided by the user. Uploaded signal is emitted when the image data gets uploaded to GL.
107           */
108         public event DaliEventHandler<object, UploadedEventArgs> Uploaded
109         {
110             add
111             {
112                 lock (this)
113                 {
114                     // Restricted to only one listener
115                     if (_imageUploadedEventHandler == null)
116                     {
117                         _imageUploadedEventHandler += value;
118
119                         _imageUploadedEventCallbackDelegate = new UploadedEventCallbackDelegate(OnUploaded);
120                         this.UploadedSignal().Connect(_imageUploadedEventCallbackDelegate);
121                     }
122                 }
123             }
124
125             remove
126             {
127                 lock (this)
128                 {
129                     if (_imageUploadedEventHandler != null)
130                     {
131                         this.UploadedSignal().Disconnect(_imageUploadedEventCallbackDelegate);
132                     }
133
134                     _imageUploadedEventHandler -= value;
135                 }
136             }
137         }
138
139         // Callback for Image UploadedSignal
140         private void OnUploaded(IntPtr data)
141         {
142             UploadedEventArgs e = new UploadedEventArgs();
143
144             // Populate all members of "e" (UploadedEventArgs) with real data
145             e.Image = Image.GetImageFromPtr(data);
146
147             if (_imageUploadedEventHandler != null)
148             {
149                 //here we send all data to user event handlers
150                 _imageUploadedEventHandler(this, e);
151             }
152         }
153
154
155         public static Image GetImageFromPtr(global::System.IntPtr cPtr)
156         {
157             Image ret = new Image(cPtr, false);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162
163         public Image() : this(Interop.Image.new_Image__SWIG_0(), true)
164         {
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166         }
167
168         public Image(Image handle) : this(Interop.Image.new_Image__SWIG_1(Image.getCPtr(handle)), true)
169         {
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171         }
172
173         public Image Assign(Image rhs)
174         {
175             Image ret = new Image(Interop.Image.Image_Assign(swigCPtr, Image.getCPtr(rhs)), false);
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177             return ret;
178         }
179
180         public static Image DownCast(BaseHandle handle)
181         {
182             Image ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as Image;
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184             return ret;
185         }
186
187         public uint GetWidth()
188         {
189             uint ret = Interop.Image.Image_GetWidth(swigCPtr);
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191             return ret;
192         }
193
194         public uint GetHeight()
195         {
196             uint ret = Interop.Image.Image_GetHeight(swigCPtr);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201         public ImageSignal UploadedSignal()
202         {
203             ImageSignal ret = new ImageSignal(Interop.Image.Image_UploadedSignal(swigCPtr), false);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             return ret;
206         }
207
208     }
209
210 }