[NUI] Add NativeImageQueue
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Images / NativeImageQueue.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     /// <summary>
25     /// NativeImageQueue is a class for displaying an image resource using queue.
26     /// </summary>
27     /// <example>
28     /// <code>
29     /// NativeImageQueue queue = new NativeImageQueue(width,height,ColorDepth.Default);
30     /// if(queue.CanDequeueBuffer())
31     /// {
32     ///   var buffer = queue.DequeueBuffer(ref bufferWidth,ref bufferHeight,ref bufferStride);
33     ///
34     ///   /* Use buffer */
35     ///
36     ///   queue.EnqueueBuffer(buffer);
37     /// }
38     /// </code>
39     /// </example>
40     [EditorBrowsable(EditorBrowsableState.Never)]
41     public class NativeImageQueue : NativeImageInterface
42     {
43         private IntPtr handle;
44
45         /// <summary>
46         /// Creates an initialized NativeImageQueue with size and color depth.
47         /// </summary>
48         /// <param name="width">A Width of queue.</param>
49         /// <param name="height">A Height of queue.</param>
50         /// <param name="depth">A color depth of queue.</param>
51         /// <returns>A NativeImageQueue.</returns>
52         [EditorBrowsable(EditorBrowsableState.Never)]
53         public NativeImageQueue(uint width, uint height, NativeImageSource.ColorDepth depth) : this(Interop.NativeImageQueue.NewHandle(width, height, (int)depth), true)
54         {
55             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56         }
57
58         internal NativeImageQueue(IntPtr cPtr, bool cMemoryOwn) : base(Interop.NativeImageQueue.Get(cPtr), cMemoryOwn)
59         {
60             handle = cPtr;
61         }
62
63         /// <summary>
64         /// Generate Url from native image queue.
65         /// </summary>
66         /// <returns>The ImageUrl of NativeImageQueue.</returns>
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public ImageUrl GenerateUrl()
69         {
70             ImageUrl ret = new ImageUrl(Interop.NativeImageSource.GenerateUrl(this.SwigCPtr.Handle), true);
71             if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
72             return ret;
73         }
74
75         [EditorBrowsable(EditorBrowsableState.Never)]
76         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
77         {
78             Interop.NativeImageQueue.Delete(handle);
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80         }
81
82         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NativeImageQueue obj)
83         {
84             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
85         }
86
87         /// <summary>
88         /// Checks if the buffer can be got from the queue.
89         /// </summary>
90         /// <returns>True if the buffer can be got from the queue.</returns>
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         public bool CanDequeueBuffer()
93         {
94             bool ret = Interop.NativeImageQueue.CanDequeueBuffer(this.SwigCPtr.Handle);
95             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96             return ret;
97         }
98
99         /// <summary>
100         /// Dequeue buffer from the queue.
101         /// </summary>
102         /// <param name="width">A reference to the buffer's width.</param>
103         /// <param name="height">A reference to the buffer's height.</param>
104         /// <param name="stride">A reference to the buffer's stride.</param>
105         /// <returns>A handle of buffer.</returns>
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public IntPtr DequeueBuffer(ref int width, ref int height, ref int stride)
108         {
109             IntPtr ret = Interop.NativeImageQueue.DequeueBuffer(this.SwigCPtr.Handle, ref width, ref height, ref stride);
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111             return ret;
112         }
113
114         /// <summary>
115         /// Enqueue buffer to the queue.
116         /// </summary>
117         /// <param name="buffer">A Handle of buffer to be enqueued.</param>
118         /// <returns>True if success.</returns>
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public bool EnqueueBuffer(IntPtr buffer)
121         {
122             bool ret = Interop.NativeImageQueue.EnqueueBuffer(this.SwigCPtr.Handle, buffer);
123             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124             return ret;
125         }
126     }
127 }