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