Dali 3D User Interface Engine
utc-Dali-NativeImage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #include <stdlib.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
24 #include <test-intrusive-ptr.h>
25 
26 using namespace Dali;
27 
29 {
31 }
32 
34 {
36 }
37 
39 {
40  return TestNativeImage::New(10,10);
41 }
42 
44 {
46 
47  pointer.Check(Creator);
48 
49  END_TEST;
50 }
51 
53 {
54  TestApplication application;
55 
56  tet_infoline("UtcDaliNativeImageNew - NativeImage::New(NativeImageInterface&)");
57 
58  // invoke default handle constructor
59  NativeImage image;
60  TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
61 
62  DALI_TEST_CHECK( !image );
63 
64  // initialise handle
65  image = NativeImage::New(*(nativeImage.Get()));
66 
67  DALI_TEST_CHECK( image );
68  END_TEST;
69 }
70 
72 {
73  TestApplication application;
74 
75  tet_infoline("UtcDaliNativeImageCopyConstructor - NativeImage::NativeImage( const NativeImage& )");
76 
77  NativeImage image1;
78  DALI_TEST_CHECK( !image1 );
79 
80  TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
81  image1 = NativeImage::New(*(nativeImage.Get()));
82  NativeImage image2( image1 );
83 
84  DALI_TEST_CHECK( image2 );
85  DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
86 
87  END_TEST;
88 }
89 
91 {
92  TestApplication application;
93  tet_infoline("Testing Dali::Image::DownCast()");
94 
95  TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
96  NativeImage image = NativeImage::New(*(nativeImage.Get()));
97 
98  BaseHandle object(image);
99 
100  NativeImage image2 = NativeImage::DownCast(object);
101  DALI_TEST_CHECK(image2);
102 
103  NativeImage image3 = DownCast< NativeImage >(object);
104  DALI_TEST_CHECK(image3);
105 
106  BaseHandle unInitializedObject;
107  NativeImage image4 = NativeImage::DownCast(unInitializedObject);
108  DALI_TEST_CHECK(!image4);
109 
110  NativeImage image5 = DownCast< NativeImage >(unInitializedObject);
111  DALI_TEST_CHECK(!image5);
112 
113  Image image6 = NativeImage::New(*(nativeImage.Get()));
114  NativeImage image7 = NativeImage::DownCast(image6);
115  DALI_TEST_CHECK(image7);
116  END_TEST;
117 }
118 
120 {
121  TestApplication application;
122  tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
123 
124  NativeImage image;
125  try
126  {
127  image.CreateGlTexture();
128  tet_printf( "Assertion test failed - no Exception\n" );
129  tet_result( TET_FAIL );
130  }
131  catch( Dali::DaliException& e )
132  {
134  DALI_TEST_ASSERT( e, "image &&", TEST_LOCATION );
135  }
136  END_TEST;
137 }
138 
140 {
141  TestApplication application;
142  tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
143 
144  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
145  NativeImage image = NativeImage::New( *(imageInterface.Get()) );
146  DALI_TEST_CHECK( image );
147 
148  image.CreateGlTexture();
149 
150  application.SendNotification();
151  application.Render(16);
152 
153  DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
154  DALI_TEST_EQUALS( imageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
155 
156  END_TEST;
157 }
158 
160 {
161  TestApplication application;
162  tet_infoline( "Testing Dali::NativeImage behaviour through a context lost/regained cycle." );
163 
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 );
169 
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 );
174 
175  eagerImage.CreateGlTexture();
176 
177  application.SendNotification();
178  application.Render(16);
179 
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:
183 
184  // Call render thread context destroyed / created functions:
185  application.ResetContext();
186 
187  // Call event thread function:
188  application.GetCore().RecoverFromContextLoss();
189 
190  // Run update/render loop
191  application.SendNotification();
192  application.Render(16);
193 
194  DALI_TEST_EQUALS( eagerImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
195  DALI_TEST_EQUALS( eagerImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
196 
197  DALI_TEST_EQUALS( lazyImageInterface->mExtensionCreateCalls, 0, TEST_LOCATION );
198  DALI_TEST_EQUALS( lazyImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
199 
200  END_TEST;
201 }
202 
204 {
205  TestApplication application;
206  tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
207 
208  TestNativeImagePointer testNativeImage = TestNativeImage::New( 16, 16 );
209  DALI_TEST_CHECK( testNativeImage );
210 
211  DALI_TEST_CHECK( NULL != testNativeImage->GetExtension() );
212 
213  END_TEST;
214 }
215 
217 {
218  TestApplication application;
219  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
220  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
221 
222  const char* preFix = "#extension GL_OES_EGL_image_external:require\n";
223  DALI_TEST_EQUALS( nativeImage.GetCustomFragmentPreFix(), preFix, TEST_LOCATION );
224  END_TEST;
225 }
226 
228 {
229  TestApplication application;
230  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
231  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
232 
233  const char* samplerTypename = "samplerExternalOES";
234  DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
235  END_TEST;
236 }
Dali Docs Home
Read more about Dali