2 * Copyright (c) 2014 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/integration-api/bitmap.h>
23 #include <dali/devel-api/images/atlas.h>
24 #include <dali/devel-api/images/pixel-data.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-native-image.h>
32 static const char* gTestImageFilename = "icon_wrt.png";
34 void PrepareResourceImage( TestApplication& application, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
36 TestPlatformAbstraction& platform = application.GetPlatform();
37 platform.SetClosestImageSize(Vector2( imageWidth, imageHeight));
39 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
40 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
41 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
42 unsigned int initialColor = 0xFF;
43 memset( pixbuffer, initialColor, imageHeight*imageWidth*bytesPerPixel);
45 Integration::ResourcePointer resourcePtr(bitmap);
46 platform.SetSynchronouslyLoadedResource( resourcePtr );
49 PixelDataPtr CreatePixelData(unsigned int width, unsigned int height, Pixel::Format pixelFormat)
51 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( pixelFormat );
52 unsigned char* buffer = new unsigned char [ bufferSize ];
54 return new PixelData( buffer, width, height, pixelFormat, PixelData::DELETE_ARRAY );
59 void utc_dali_atlas_startup(void)
61 test_return_value = TET_UNDEF;
64 void utc_dali_atlas_cleanup(void)
66 test_return_value = TET_PASS;
69 int UtcDaliAtlasNew(void)
71 TestApplication application;
73 // invoke default handle constructor
76 DALI_TEST_CHECK( !atlas );
79 atlas = Atlas::New( 16, 16 );
81 DALI_TEST_CHECK( atlas );
85 int UtcDaliAtlasCopyConstructor(void)
87 TestApplication application;
89 Atlas atlas = Atlas::New( 16, 16);
90 Atlas atlasCopy(atlas);
93 DALI_TEST_EQUALS( (bool)atlasCopy, true, TEST_LOCATION );
97 int UtcDaliAtlasAssignmentOperator(void)
99 TestApplication application;
101 Atlas atlas = Atlas::New( 16, 16);
104 DALI_TEST_EQUALS( (bool)atlas2, false, TEST_LOCATION );
107 DALI_TEST_EQUALS( (bool)atlas2, true, TEST_LOCATION );
112 int UtcDaliAtlasDownCast(void)
114 TestApplication application;
116 Atlas atlas = Atlas::New( 16, 16);
118 BaseHandle handle(atlas);
119 Atlas atlasDowncast = Atlas::DownCast(handle);
120 DALI_TEST_EQUALS( (bool)atlasDowncast, true, TEST_LOCATION );
122 Handle handle2 = Handle::New(); // Create a custom object
123 Atlas atlas2 = Atlas::DownCast(handle2);
124 DALI_TEST_EQUALS( (bool)atlas2, false, TEST_LOCATION );
129 int UtcDaliAtlasClear(void)
131 TestApplication application;
133 Atlas atlas = Atlas::New( 16, 32, Pixel::RGBA8888 );
134 DALI_TEST_CHECK( atlas );
136 atlas.Clear(Color::TRANSPARENT);
138 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
140 callStack.Enable(true);
141 application.SendNotification();
142 application.Render(16);
143 application.Render(16);
144 application.SendNotification();
145 application.Render(16);
146 application.SendNotification();
147 callStack.Enable(false);
149 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 32") );
155 // Upload resource image, buffer image & pixel data with same pixel format
156 int UtcDaliAtlasUpload01P(void)
158 TestApplication application;
160 Atlas atlas = Atlas::New( 16, 40, Pixel::RGBA8888 );
161 DALI_TEST_CHECK( atlas );
163 // Using same pixel format
164 PixelBuffer* buffer = new PixelBuffer[16 * 16 * 4];
165 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGBA8888 );
166 DALI_TEST_CHECK( atlas.Upload( image, 0, 0 ) );
168 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
169 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 0, 16 ) );
171 PixelDataPtr pixelData = CreatePixelData( 6,8,Pixel::RGBA8888 );
172 DALI_TEST_CHECK( atlas.Upload( pixelData, 2, 32 ) );
174 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
176 callStack.Enable(true);
177 application.SendNotification();
178 application.Render(16);
179 application.Render(16);
180 application.SendNotification();
181 application.Render(16);
182 application.SendNotification();
183 callStack.Enable(false);
185 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 16") );
186 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 16, 16, 16") );
187 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "2, 32, 6, 8") );
192 // Upload resource image, buffer image & pixel data with different pixel format
193 int UtcDaliAtlasUpload02P(void)
195 TestApplication application;
197 Atlas atlas = Atlas::New( 20, 20, Pixel::RGBA8888 );
198 DALI_TEST_CHECK( atlas );
200 // Using different pixel format
201 PixelBuffer* buffer = new PixelBuffer[16 * 16 * 3];
202 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGB888 );
203 DALI_TEST_CHECK( atlas.Upload( image, 0, 0 ) );
205 PrepareResourceImage( application, 12, 12, Pixel::A8 );
206 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 6, 6 ) );
208 PixelDataPtr pixelData = CreatePixelData( 8,8,Pixel::LA88 );
209 DALI_TEST_CHECK( atlas.Upload( pixelData, 10, 10 ) );
211 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
213 callStack.Enable(true);
214 application.SendNotification();
215 application.Render(16);
216 application.Render(16);
217 application.SendNotification();
218 application.Render(16);
219 application.SendNotification();
220 callStack.Enable(false);
222 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 16") );
223 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "6, 6, 12, 12") );
224 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "10, 10, 8, 8") );
229 // Upload resource image, buffer image & pixel data which cannot fit into the atlas with given offset
230 int UtcDaliAtlasUploadN(void)
232 TestApplication application;
234 Atlas atlas = Atlas::New( 16, 16, Pixel::RGBA8888 );
235 DALI_TEST_CHECK( atlas );
237 // Using image cannot fit into atlas at the given offsets
238 PixelBuffer* buffer = new PixelBuffer[24 * 24 * 4];
239 BufferImage image = BufferImage::New( buffer, 24, 24, Pixel::RGBA8888 );
240 DALI_TEST_CHECK( !atlas.Upload( image, 0, 0 ) );
242 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
243 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 10, 10 ) );
245 PixelDataPtr pixelData = CreatePixelData( 6,6,Pixel::RGBA8888 );
246 DALI_TEST_CHECK( !atlas.Upload( pixelData, 11, 11 ) );
248 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
250 callStack.Enable(true);
251 application.SendNotification();
252 application.Render(16);
253 application.Render(16);
254 application.SendNotification();
255 application.Render(16);
256 application.SendNotification();
257 callStack.Enable(false);
259 // none of these three upload() call sends texture to GPU
260 DALI_TEST_CHECK( ! callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 24, 24") );
261 DALI_TEST_CHECK( ! callStack.FindMethodAndParams("TexSubImage2D", "10, 10, 16, 16") );
262 DALI_TEST_CHECK( ! callStack.FindMethodAndParams("TexSubImage2D", "11, 11, 6, 6") );