[NUI] Remove apis which are using internal APIs (#324)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Texture.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     /// <summary>
21     /// Texture represents a texture object used as input or output by shaders.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class Texture : BaseHandle
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal Texture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Texture_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Texture obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         /// <summary>
39         /// Dispose.
40         /// </summary>
41         /// <since_tizen> 3 </since_tizen>
42         protected override void Dispose(DisposeTypes type)
43         {
44             if (disposed)
45             {
46                 return;
47             }
48
49             if (type == DisposeTypes.Explicit)
50             {
51                 //Called by User
52                 //Release your own managed resources here.
53                 //You should release all of your own disposable objects here.
54
55             }
56
57             //Release your own unmanaged resources here.
58             //You should not access any managed member here except static instance.
59             //because the execution order of Finalizes is non-deterministic.
60
61             if (swigCPtr.Handle != global::System.IntPtr.Zero)
62             {
63                 if (swigCMemOwn)
64                 {
65                     swigCMemOwn = false;
66                     NDalicPINVOKE.delete_Texture(swigCPtr);
67                 }
68                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69             }
70
71             base.Dispose(type);
72         }
73
74         /// <summary>
75         /// Creates a new Texture object.
76         /// </summary>
77         /// <param name="type">The type of the texture.</param>
78         /// <param name="format">The format of the pixel data.</param>
79         /// <param name="width">The width of the texture.</param>
80         /// <param name="height">The height of the texture.</param>
81         /// <since_tizen> 3 </since_tizen>
82         public Texture(TextureType type, PixelFormat format, uint width, uint height) : this(NDalicPINVOKE.Texture_New__SWIG_0((int)type, (int)format, width, height), true)
83         {
84             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85
86         }
87         internal Texture(NativeImageInterface nativeImageInterface) : this(NDalicPINVOKE.Texture_New__SWIG_1(NativeImageInterface.getCPtr(nativeImageInterface)), true)
88         {
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90
91         }
92
93         /// <summary>
94         /// Uploads data to the texture from a PixelData object.
95         /// </summary>
96         /// <param name="pixelData">The pixelData object.</param>
97         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
98         /// <since_tizen> 3 </since_tizen>
99         public bool Upload(PixelData pixelData)
100         {
101             bool ret = NDalicPINVOKE.Texture_Upload__SWIG_0(swigCPtr, PixelData.getCPtr(pixelData));
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103             return ret;
104         }
105
106         /// <summary>
107         /// Uploads data to the texture from a PixelData object.
108         /// </summary>
109         /// <param name="pixelData">The pixelData object.</param>
110         /// <param name="layer">The layer of a cube map or array texture.</param>
111         /// <param name="mipmap">The level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.</param>
112         /// <param name="xOffset">The horizontal offset of the rectangular area in the texture that will be updated.</param>
113         /// <param name="yOffset">The vertical offset of the rectangular area in the texture that will be updated.</param>
114         /// <param name="width">The width of the rectangular area in the texture that will be updated.</param>
115         /// <param name="height">height of the rectangular area in the texture that will be updated.</param>
116         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
117         /// <since_tizen> 3 </since_tizen>
118         public bool Upload(PixelData pixelData, uint layer, uint mipmap, uint xOffset, uint yOffset, uint width, uint height)
119         {
120             bool ret = NDalicPINVOKE.Texture_Upload__SWIG_1(swigCPtr, PixelData.getCPtr(pixelData), layer, mipmap, xOffset, yOffset, width, height);
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122             return ret;
123         }
124
125         /// <summary>
126         /// Generates mipmaps for the texture.<br />
127         /// This will auto generate all the mipmaps for the texture based on the data in the base level.
128         /// </summary>
129         /// <since_tizen> 3 </since_tizen>
130         public void GenerateMipmaps()
131         {
132             NDalicPINVOKE.Texture_GenerateMipmaps(swigCPtr);
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         /// <summary>
137         /// Returns the width of the texture.<br />
138         /// </summary>
139         /// <returns>The width, in pixels, of the texture.</returns>
140         /// <since_tizen> 3 </since_tizen>
141         public uint GetWidth()
142         {
143             uint ret = NDalicPINVOKE.Texture_GetWidth(swigCPtr);
144             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145             return ret;
146         }
147
148         /// <summary>
149         /// Returns the height of the texture..<br />
150         /// </summary>
151         /// <returns>The height, in pixels, of the texture.</returns>
152         /// <since_tizen> 3 </since_tizen>
153         public uint GetHeight()
154         {
155             uint ret = NDalicPINVOKE.Texture_GetHeight(swigCPtr);
156             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157             return ret;
158         }
159
160     }
161
162 }