[NUI] Fixing the emtpy finalizers(CA1821)
[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 using System;
18 using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// Texture represents a texture object used as input or output by shaders.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Texture : BaseHandle
27     {
28
29         /// <summary>
30         /// Creates a new Texture object.
31         /// </summary>
32         /// <param name="type">The type of the texture.</param>
33         /// <param name="format">The format of the pixel data.</param>
34         /// <param name="width">The width of the texture.</param>
35         /// <param name="height">The height of the texture.</param>
36         /// <since_tizen> 3 </since_tizen>
37         public Texture(TextureType type, PixelFormat format, uint width, uint height) : this(Interop.Texture.New((int)type, (int)format, width, height), true)
38         {
39             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
40
41         }
42
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public Texture(NativeImageInterface nativeImageInterface) : this(Interop.Texture.New(NativeImageInterface.getCPtr(nativeImageInterface)), true)
45         {
46             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47
48         }
49
50         internal Texture(IntPtr tbmSurface) : this(Interop.Texture.NewTbmSurface(tbmSurface), true)
51         {
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53         }
54
55         internal Texture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Texture.Upcast(cPtr), cMemoryOwn)
56         {
57         }
58
59         /// <summary>
60         /// Uploads data to the texture from a PixelData object.
61         /// </summary>
62         /// <param name="pixelData">The pixelData object.</param>
63         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
64         /// <since_tizen> 3 </since_tizen>
65         public bool Upload(PixelData pixelData)
66         {
67             bool ret = Interop.Texture.Upload(SwigCPtr, PixelData.getCPtr(pixelData));
68             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69             return ret;
70         }
71
72         /// <summary>
73         /// Uploads data to the texture from a PixelData object.
74         /// </summary>
75         /// <param name="pixelData">The pixelData object.</param>
76         /// <param name="layer">The layer of a cube map or array texture.</param>
77         /// <param name="mipmap">The level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.</param>
78         /// <param name="xOffset">The horizontal offset of the rectangular area in the texture that will be updated.</param>
79         /// <param name="yOffset">The vertical offset of the rectangular area in the texture that will be updated.</param>
80         /// <param name="width">The width of the rectangular area in the texture that will be updated.</param>
81         /// <param name="height">height of the rectangular area in the texture that will be updated.</param>
82         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
83         /// <since_tizen> 3 </since_tizen>
84         public bool Upload(PixelData pixelData, uint layer, uint mipmap, uint xOffset, uint yOffset, uint width, uint height)
85         {
86             bool ret = Interop.Texture.Upload(SwigCPtr, PixelData.getCPtr(pixelData), layer, mipmap, xOffset, yOffset, width, height);
87             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88             return ret;
89         }
90
91         /// <summary>
92         /// Generates mipmaps for the texture.<br />
93         /// This will auto generate all the mipmaps for the texture based on the data in the base level.
94         /// </summary>
95         /// <since_tizen> 3 </since_tizen>
96         public void GenerateMipmaps()
97         {
98             Interop.Texture.GenerateMipmaps(SwigCPtr);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100         }
101
102         /// <summary>
103         /// Returns the width of the texture.<br />
104         /// </summary>
105         /// <returns>The width, in pixels, of the texture.</returns>
106         /// <since_tizen> 3 </since_tizen>
107         public uint GetWidth()
108         {
109             uint ret = Interop.Texture.GetWidth(SwigCPtr);
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111             return ret;
112         }
113
114         /// <summary>
115         /// Returns the height of the texture..<br />
116         /// </summary>
117         /// <returns>The height, in pixels, of the texture.</returns>
118         /// <since_tizen> 3 </since_tizen>
119         public uint GetHeight()
120         {
121             uint ret = Interop.Texture.GetHeight(SwigCPtr);
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123             return ret;
124         }
125
126         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Texture obj)
127         {
128             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
129         }
130
131         /// This will not be public opened.
132         [EditorBrowsable(EditorBrowsableState.Never)]
133         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
134         {
135             Interop.Texture.DeleteTexture(swigCPtr);
136         }
137     }
138 }