Merge "fix buffer GpuBuffer" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBufferImage.cpp
1 /*
2  * Copyright (c) 2014 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 #include <iostream>
19 #include <algorithm>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24 #include <test-native-image.h>
25 #include <dali/integration-api/gl-abstraction.h>
26
27 using std::max;
28 using namespace Dali;
29
30 void utc_dali_framebuffer_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_framebuffer_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 int UtcDaliFrameBufferImageNew01(void)
41 {
42   TestApplication application;
43
44   tet_infoline("UtcDaliFrameBufferImageNew01 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format)");
45
46   // invoke default handle constructor
47   FrameBufferImage image;
48   Vector2 stageSize = Stage::GetCurrent().GetSize();
49
50   // initialise handle
51   image = FrameBufferImage::New();            // create framebuffer with the same dimensions as the stage
52   ImageActor actor=ImageActor::New(image);
53   Stage::GetCurrent().Add(actor);
54
55   application.SendNotification();
56   application.Render();
57   application.Render();
58   application.SendNotification();
59
60   DALI_TEST_CHECK( image );
61   DALI_TEST_EQUALS((float)image.GetWidth(), stageSize.width, TEST_LOCATION);
62   DALI_TEST_EQUALS((float)image.GetHeight(), stageSize.height, TEST_LOCATION);
63
64   image = FrameBufferImage::New(16, 16);      // create framebuffer with dimensions of 16x16
65   actor.SetImage(image);
66
67   application.SendNotification();
68   application.Render();
69   application.Render();
70   application.SendNotification();
71
72   DALI_TEST_CHECK( image );
73   DALI_TEST_EQUALS(image.GetWidth(), 16u, TEST_LOCATION);
74   DALI_TEST_EQUALS(image.GetHeight(), 16u, TEST_LOCATION);
75   END_TEST;
76 }
77
78 int UtcDaliFrameBufferImageNew02(void)
79 {
80   TestApplication application;
81
82   tet_infoline("UtcDaliFrameBufferImageNew02 - FrameBufferImage::New(NativeImageInterface&)");
83
84   // invoke default handle constructor
85   FrameBufferImage image;
86   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
87
88   DALI_TEST_CHECK( !image );
89
90   // initialise handle
91   image = FrameBufferImage::New(*(nativeImage.Get()));
92
93   DALI_TEST_CHECK( image );
94   END_TEST;
95 }
96
97 int UtcDaliFrameBufferImageNew03(void)
98 {
99   TestApplication application;
100
101   tet_infoline("UtcDaliFrameBufferImageNew03 - FrameBufferImage::New(NativeImageInterface&, ReleasePolicy)");
102
103   // invoke default handle constructor
104   FrameBufferImage image;
105   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
106
107   DALI_TEST_CHECK( !image );
108
109   // initialise handle with UNUSED release policy
110   image = FrameBufferImage::New(*(nativeImage.Get()), Image::UNUSED);
111
112   DALI_TEST_CHECK( image );
113
114   //ReleasePolicy is always never for framebuffer images
115   DALI_TEST_EQUALS( image.GetReleasePolicy(), Image::NEVER, TEST_LOCATION );
116
117   // initialise handle with NEVER release policy
118   image.Reset();
119   DALI_TEST_CHECK( !image );
120
121   image = FrameBufferImage::New(*(nativeImage.Get()), Image::NEVER);
122
123   DALI_TEST_CHECK( image );
124
125   //ReleasePolicy is always never for framebuffer images
126   DALI_TEST_EQUALS( image.GetReleasePolicy(), Image::NEVER, TEST_LOCATION );
127
128   END_TEST;
129 }
130
131 int UtcDaliFrameBufferImageAttachments01(void)
132 {
133   TestApplication application;
134
135   tet_infoline("UtcDaliFrameBufferImageAttachments01 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
136
137   // invoke default handle constructor
138   FrameBufferImage image;
139
140   // initialise handle
141   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR);       // create framebuffer with Color buffer
142   ImageActor actor=ImageActor::New(image);
143   Stage::GetCurrent().Add(actor);
144
145   application.SendNotification();
146   application.Render();
147   application.Render();
148   application.SendNotification();
149
150   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
151   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
152   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
153
154   END_TEST;
155 }
156
157 int UtcDaliFrameBufferImageAttachments02(void)
158 {
159   TestApplication application;
160
161   tet_infoline("UtcDaliFrameBufferImageAttachments02 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
162
163   // invoke default handle constructor
164   FrameBufferImage image;
165
166   // initialise handle
167   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_DEPTH); // create framebuffer with Color and Depth buffer
168   ImageActor actor=ImageActor::New(image);
169   Stage::GetCurrent().Add(actor);
170
171   application.SendNotification();
172   application.Render();
173   application.Render();
174   application.SendNotification();
175
176   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
177   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
178   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
179
180   END_TEST;
181 }
182
183 int UtcDaliFrameBufferImageAttachments03(void)
184 {
185   TestApplication application;
186
187   tet_infoline("UtcDaliFrameBufferImageAttachments03 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
188
189   // invoke default handle constructor
190   FrameBufferImage image;
191
192   // initialise handle
193   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_STENCIL);  // create framebuffer with Color and Stencil
194   ImageActor actor=ImageActor::New(image);
195   Stage::GetCurrent().Add(actor);
196
197   application.SendNotification();
198   application.Render();
199   application.Render();
200   application.SendNotification();
201
202   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
203   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
204   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
205
206   END_TEST;
207 }
208
209 int UtcDaliFrameBufferImageAttachments04(void)
210 {
211   TestApplication application;
212
213   tet_infoline("UtcDaliFrameBufferImageAttachments04 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
214
215   // invoke default handle constructor
216   FrameBufferImage image;
217
218   // initialise handle
219   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_DEPTH_STENCIL);  // create framebuffer with Color, Depth and Stencil buffers
220   ImageActor actor=ImageActor::New(image);
221   Stage::GetCurrent().Add(actor);
222
223   application.SendNotification();
224   application.Render();
225   application.Render();
226   application.SendNotification();
227
228   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
229   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
230   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
231
232   END_TEST;
233 }
234
235 int UtcDaliFrameBufferImageDownCast(void)
236 {
237   TestApplication application;
238   tet_infoline("Testing Dali::FrameBufferImage::DownCast()");
239
240   FrameBufferImage image = FrameBufferImage::New();
241
242   BaseHandle object(image);
243
244   FrameBufferImage image2 = FrameBufferImage::DownCast(object);
245   DALI_TEST_CHECK(image2);
246
247   FrameBufferImage image3 = DownCast< FrameBufferImage >(object);
248   DALI_TEST_CHECK(image3);
249
250   BaseHandle unInitializedObject;
251   FrameBufferImage image4 = FrameBufferImage::DownCast(unInitializedObject);
252   DALI_TEST_CHECK(!image4);
253
254   FrameBufferImage image5 = DownCast< FrameBufferImage >(unInitializedObject);
255   DALI_TEST_CHECK(!image5);
256
257   Image image6 = FrameBufferImage::New();
258   FrameBufferImage image7 = FrameBufferImage::DownCast(image6);
259   DALI_TEST_CHECK(image7);
260   END_TEST;
261 }