[NUI] Fix some incorrect implements when we get Texture relative items
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / FrameBuffer.cs
1 /*
2  * Copyright(c) 2019 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     /// This will be released at Tizen.NET API Level 6, so currently this would be used as inhouse API.
23     [EditorBrowsable(EditorBrowsableState.Never)]
24     public class FrameBuffer : BaseHandle
25     {
26
27         internal FrameBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
28         {
29         }
30
31         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
32         {
33             Interop.FrameBuffer.DeleteFrameBuffer(swigCPtr);
34         }
35
36         /// <since_tizen> 3 </since_tizen>
37         public sealed class Attachment
38         {
39             /// <since_tizen> 3 </since_tizen>
40             public enum Mask
41             {
42                 NONE = 0,
43                 DEPTH = 1 << 0,
44                 STENCIL = 1 << 1,
45                 DEPTH_STENCIL = DEPTH | STENCIL
46             }
47         }
48
49         public FrameBuffer(uint width, uint height, uint attachments) : this(Interop.FrameBuffer.New(width, height, attachments), true)
50         {
51             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52
53         }
54
55         public void AttachColorTexture(Texture texture)
56         {
57             Interop.FrameBuffer.AttachColorTexture(SwigCPtr, Texture.getCPtr(texture));
58             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59         }
60
61         public void AttachColorTexture(Texture texture, uint mipmapLevel, uint layer)
62         {
63             Interop.FrameBuffer.AttachColorTexture(SwigCPtr, Texture.getCPtr(texture), mipmapLevel, layer);
64             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65         }
66
67         public Texture GetColorTexture()
68         {
69             global::System.IntPtr cPtr = Interop.FrameBuffer.GetColorTexture(SwigCPtr);
70             Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture;
71             if (ret != null)
72             {
73                 Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
74             }
75             else
76             {
77                 ret = new Texture(cPtr, true);
78             }
79             NDalicPINVOKE.ThrowExceptionIfExists();
80             return ret;
81         }
82
83         /// <summary>
84         /// Generate URI from current buffer.
85         /// </summary>
86         /// <param name="pixelFormat">The pixel format for this frame buffer</param>
87         /// <param name="width">The width for this frame buffer</param>
88         /// <param name="height">The height for this frame buffer</param>
89         public ImageUrl GenerateUrl(PixelFormat pixelFormat, int width, int height)
90         {
91             return new ImageUrl(Interop.FrameBuffer.GenerateUrl(this.SwigCPtr.Handle, (int)pixelFormat, width, height), true);
92         }
93     }
94 }