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