2 * Copyright (c) 2020 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.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <toolkit-timer.h>
24 #include <toolkit-event-thread-callback.h>
25 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
26 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
27 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
28 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
30 #if defined(ELDBUS_ENABLED)
31 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
34 using namespace Dali::Toolkit::Internal;
36 void utc_dali_toolkit_texture_manager_startup(void)
38 setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
39 test_return_value = TET_UNDEF;
40 #if defined(ELDBUS_ENABLED)
41 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
45 void utc_dali_toolkit_texture_manager_cleanup(void)
47 test_return_value = TET_PASS;
53 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
57 class TestObserver : public Dali::Toolkit::TextureUploadObserver
60 enum class CompleteType
69 : mCompleteType( CompleteType::NOT_COMPLETED ),
71 mObserverCalled(false)
75 virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
76 bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
78 mCompleteType = CompleteType::UPLOAD_COMPLETE;
79 mLoaded = loadSuccess;
80 mObserverCalled = true;
83 virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
85 mCompleteType = CompleteType::LOAD_COMPLETE;
86 mLoaded = loadSuccess;
87 mObserverCalled = true;
90 CompleteType mCompleteType;
96 int UtcTextureManagerRequestLoad(void)
98 ToolkitTestApplication application;
100 TextureManager textureManager; // Create new texture manager
102 TestObserver observer;
103 std::string filename("image.png");
104 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
105 TextureManager::TextureId textureId = textureManager.RequestLoad(
108 FittingMode::SCALE_TO_FILL,
109 SamplingMode::BOX_THEN_LINEAR,
110 TextureManager::NO_ATLAS,
113 TextureManager::ReloadPolicy::CACHED,
116 VisualUrl url = textureManager.GetVisualUrl( textureId );
118 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
123 int UtcTextureManagerGenerateHash(void)
125 ToolkitTestApplication application;
127 TextureManager textureManager; // Create new texture manager
129 TestObserver observer;
130 std::string filename( "image.png" );
131 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
132 TextureManager::TextureId textureId = textureManager.RequestLoad(
135 FittingMode::SCALE_TO_FILL,
136 SamplingMode::BOX_THEN_LINEAR,
137 TextureManager::USE_ATLAS,
140 TextureManager::ReloadPolicy::CACHED,
143 VisualUrl url = textureManager.GetVisualUrl( textureId );
145 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
150 int UtcTextureManagerCachingForDifferentLoadingType(void)
152 ToolkitTestApplication application;
153 tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" );
155 TextureManager textureManager; // Create new texture manager
157 TestObserver observer1;
158 std::string filename( TEST_IMAGE_FILE_NAME );
159 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
160 textureManager.RequestLoad(
163 FittingMode::SCALE_TO_FILL,
164 SamplingMode::BOX_THEN_LINEAR,
165 TextureManager::NO_ATLAS,
168 TextureManager::ReloadPolicy::CACHED,
171 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
172 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
174 application.SendNotification();
175 application.Render();
177 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
179 application.SendNotification();
180 application.Render();
182 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
183 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
184 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
186 TestObserver observer2;
187 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
190 FittingMode::SCALE_TO_FILL,
191 SamplingMode::BOX_THEN_LINEAR,
197 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
198 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
200 application.SendNotification();
201 application.Render();
203 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
205 application.SendNotification();
206 application.Render();
208 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
209 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
210 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
215 int UtcTextureManagerUseInvalidMask(void)
217 ToolkitTestApplication application;
218 tet_infoline( "UtcTextureManagerUseInvalidMask" );
220 TextureManager textureManager; // Create new texture manager
222 TestObserver observer;
223 std::string filename( TEST_IMAGE_FILE_NAME );
224 std::string maskname("");
225 TextureManager::MaskingDataPointer maskInfo = nullptr;
226 maskInfo.reset(new TextureManager::MaskingData());
227 maskInfo->mAlphaMaskUrl = maskname;
228 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
229 maskInfo->mCropToMask = true;
230 maskInfo->mContentScaleFactor = 1.0f;
232 auto textureId( TextureManager::INVALID_TEXTURE_ID );
233 Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
234 Dali::ImageDimensions atlasRectSize( 0,0 );
235 bool synchronousLoading(false);
236 bool atlasingStatus(false);
237 bool loadingStatus(false);
238 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
239 ImageAtlasManagerPtr atlasManager = nullptr;
240 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
242 textureManager.LoadTexture(
245 FittingMode::SCALE_TO_FILL,
246 SamplingMode::BOX_THEN_LINEAR,
260 TextureManager::ReloadPolicy::CACHED,
264 DALI_TEST_EQUALS( observer.mLoaded, false, TEST_LOCATION );
265 DALI_TEST_EQUALS( observer.mObserverCalled, false, TEST_LOCATION );
267 application.SendNotification();
268 application.Render();
270 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
272 application.SendNotification();
273 application.Render();
275 DALI_TEST_EQUALS( observer.mLoaded, true, TEST_LOCATION );
276 DALI_TEST_EQUALS( observer.mObserverCalled, true, TEST_LOCATION );
277 DALI_TEST_EQUALS( observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );