2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
24 #include <test-intrusive-ptr.h>
28 void utc_dali_native_image_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_native_image_cleanup(void)
35 test_return_value = TET_PASS;
38 IntrusivePtr<TestNativeImage> Creator()
40 return TestNativeImage::New(10,10);
43 int UtcDaliIntrusivePtrTestNativeImage(void)
45 UtcCoverageIntrusivePtr<TestNativeImage> pointer;
47 pointer.Check(Creator);
52 int UtcDaliNativeImageNew(void)
54 TestApplication application;
56 tet_infoline("UtcDaliNativeImageNew - NativeImage::New(NativeImageInterface&)");
58 // invoke default handle constructor
60 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
62 DALI_TEST_CHECK( !image );
65 image = NativeImage::New(*(nativeImage.Get()));
67 DALI_TEST_CHECK( image );
71 int UtcDaliNativeImageCopyConstructor(void)
73 TestApplication application;
75 tet_infoline("UtcDaliNativeImageCopyConstructor - NativeImage::NativeImage( const NativeImage& )");
78 DALI_TEST_CHECK( !image1 );
80 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
81 image1 = NativeImage::New(*(nativeImage.Get()));
82 NativeImage image2( image1 );
84 DALI_TEST_CHECK( image2 );
85 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
90 int UtcDaliNativeImageDownCast(void)
92 TestApplication application;
93 tet_infoline("Testing Dali::Image::DownCast()");
95 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
96 NativeImage image = NativeImage::New(*(nativeImage.Get()));
98 BaseHandle object(image);
100 NativeImage image2 = NativeImage::DownCast(object);
101 DALI_TEST_CHECK(image2);
103 NativeImage image3 = DownCast< NativeImage >(object);
104 DALI_TEST_CHECK(image3);
106 BaseHandle unInitializedObject;
107 NativeImage image4 = NativeImage::DownCast(unInitializedObject);
108 DALI_TEST_CHECK(!image4);
110 NativeImage image5 = DownCast< NativeImage >(unInitializedObject);
111 DALI_TEST_CHECK(!image5);
113 Image image6 = NativeImage::New(*(nativeImage.Get()));
114 NativeImage image7 = NativeImage::DownCast(image6);
115 DALI_TEST_CHECK(image7);
119 int UtcDaliNativeImageCreateGlTextureN(void)
121 TestApplication application;
122 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
127 image.CreateGlTexture();
128 tet_printf( "Assertion test failed - no Exception\n" );
129 tet_result( TET_FAIL );
131 catch( Dali::DaliException& e )
133 DALI_TEST_PRINT_ASSERT( e );
134 DALI_TEST_ASSERT( e, "image &&", TEST_LOCATION );
139 int UtcDaliNativeImageCreateGlTextureP(void)
141 TestApplication application;
142 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
144 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
145 NativeImage image = NativeImage::New( *(imageInterface.Get()) );
146 DALI_TEST_CHECK( image );
148 image.CreateGlTexture();
150 application.SendNotification();
151 application.Render(16);
153 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
154 DALI_TEST_EQUALS( imageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
159 int UtcDaliNativeImageContextLoss(void)
161 TestApplication application;
162 tet_infoline( "Testing Dali::NativeImage behaviour through a context lost/regained cycle." );
164 // Build an image that is expected to have a GL texture created for it and
165 // recreated in a GL context recovery:
166 TestNativeImagePointer eagerImageInterface = TestNativeImage::New( 16, 16 );
167 NativeImage eagerImage = NativeImage::New( *(eagerImageInterface.Get()) );
168 DALI_TEST_CHECK( eagerImage );
170 // Build a regular lazy-allocated image for comparison:
171 TestNativeImagePointer lazyImageInterface = TestNativeImage::New( 16, 16 );
172 NativeImage lazyImage = NativeImage::New( *(lazyImageInterface.Get()) );
173 DALI_TEST_CHECK( lazyImage );
175 eagerImage.CreateGlTexture();
177 application.SendNotification();
178 application.Render(16);
180 // Cycle through a context loss and regain, asserting that the texture is
181 // not reallocated if it already existed before the cycle and is never allocated
182 // throughout the cycle if of the regular lazy kind:
184 // Call render thread context destroyed / created functions:
185 application.ResetContext();
187 // Call event thread function:
188 application.GetCore().RecoverFromContextLoss();
190 // Run update/render loop
191 application.SendNotification();
192 application.Render(16);
194 DALI_TEST_EQUALS( eagerImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
195 DALI_TEST_EQUALS( eagerImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
197 DALI_TEST_EQUALS( lazyImageInterface->mExtensionCreateCalls, 0, TEST_LOCATION );
198 DALI_TEST_EQUALS( lazyImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
203 int UtcDaliNativeImageExtensionP(void)
205 TestApplication application;
206 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
208 TestNativeImagePointer testNativeImage = TestNativeImage::New( 16, 16 );
209 DALI_TEST_CHECK( testNativeImage );
210 DALI_TEST_CHECK( NULL != testNativeImage->GetExtension() );
212 TestNativeImageNoExtPointer testNativeImage2 = TestNativeImageNoExt::New( 16, 16 );
213 DALI_TEST_CHECK( testNativeImage2 );
214 DALI_TEST_CHECK( NULL == testNativeImage2->GetExtension() );
219 int UtcDaliNativeImageGetCustomFragmentPreFixP(void)
221 TestApplication application;
222 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
223 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
225 const char* preFix = "#extension GL_OES_EGL_image_external:require\n";
226 DALI_TEST_EQUALS( nativeImage.GetCustomFragmentPreFix(), preFix, TEST_LOCATION );
230 int UtcDaliNativeImageGetCustomSamplerTypenameP(void)
232 TestApplication application;
233 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
234 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
236 const char* samplerTypename = "samplerExternalOES";
237 DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
243 int UtcDaliNativeImageTestCreationFailure(void)
245 TestApplication application;
246 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
247 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
249 tet_printf("Test what happens when GlExtensionCreate is called, and returns false to indicate an error\n");
251 nativeImageInterface->SetGlExtensionCreateResult( false );
253 Actor actor = CreateRenderableActor( nativeImage );
254 actor.SetParentOrigin( ParentOrigin::CENTER );
255 Stage::GetCurrent().Add( actor );
257 TestGlAbstraction& gl = application.GetGlAbstraction();
258 TraceCallStack& textureTrace = gl.GetTextureTrace();
259 textureTrace.Reset();
260 textureTrace.Enable(true);
262 TraceCallStack& drawTrace = gl.GetDrawTrace();
264 drawTrace.Enable(true);
266 application.SendNotification();
267 application.Render();
269 // Test that nothing was rendered
270 DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
271 DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
272 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
273 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
275 textureTrace.Reset();
278 nativeImageInterface->SetGlExtensionCreateResult( true );
279 actor.SetPosition( 0, 0, 1 );
280 application.SendNotification();
281 application.Render();
283 // This time around, the bind and draw should occur following the call to nativeImage->GlExtensionCreate.
284 DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
285 DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
286 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
287 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );