[NUI] Add ImageUrl
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Images / NativeImageSource.cs
1 /*
2  * Copyright(c) 2021 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 using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22     using global::System;
23
24     [EditorBrowsable(EditorBrowsableState.Never)]
25     public class NativeImageSource : NativeImageInterface
26     {
27         private IntPtr handle;
28
29         [EditorBrowsable(EditorBrowsableState.Never)]
30         public NativeImageSource(uint width, uint height, ColorDepth depth) : this(Interop.NativeImageSource.NewHandle(width, height, (int)depth), true)
31         {
32             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
33         }
34
35         internal NativeImageSource(IntPtr cPtr, bool cMemoryOwn) : base(Interop.NativeImageSource.New(cPtr), cMemoryOwn)
36         {
37             handle = cPtr;
38         }
39
40         /// <summary>
41         /// Generate Url from native image source.
42         /// </summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public ImageUrl GenerateUrl()
45         {
46             ImageUrl ret = new ImageUrl(Interop.NativeImageSource.GenerateUrl(this.SwigCPtr.Handle), true);
47             if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
48             return ret;
49         }
50
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
53         {
54             Interop.NativeImageSource.Delete(handle);
55             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56         }
57
58         [EditorBrowsable(EditorBrowsableState.Never)]
59         public enum ColorDepth
60         {
61             Default,
62             Bits8,
63             Bits16,
64             Bits24,
65             Bits32,
66         }
67
68         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NativeImageSource obj)
69         {
70             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
71         }
72
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public IntPtr AcquireBuffer(ref int width, ref int height, ref int stride)
75         {
76             IntPtr ret = Interop.NativeImageSource.AcquireBuffer(this.SwigCPtr.Handle, ref width, ref height, ref stride);
77             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78             return ret;
79         }
80
81         [EditorBrowsable(EditorBrowsableState.Never)]
82         public bool ReleaseBuffer()
83         {
84             bool ret = Interop.NativeImageSource.ReleaseBuffer(this.SwigCPtr.Handle);
85             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86             return ret;
87         }
88     }
89 }