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 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
32 using namespace Dali::Toolkit::Internal;
34 void utc_dali_toolkit_texture_manager_startup(void)
36 setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
37 test_return_value = TET_UNDEF;
38 DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
41 void utc_dali_toolkit_texture_manager_cleanup(void)
43 test_return_value = TET_PASS;
49 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
53 class TestObserver : public Dali::Toolkit::TextureUploadObserver
56 enum class CompleteType
65 : mCompleteType( CompleteType::NOT_COMPLETED ),
67 mObserverCalled(false)
71 virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
72 bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
74 mCompleteType = CompleteType::UPLOAD_COMPLETE;
75 mLoaded = loadSuccess;
76 mObserverCalled = true;
79 virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
81 mCompleteType = CompleteType::LOAD_COMPLETE;
82 mLoaded = loadSuccess;
83 mObserverCalled = true;
86 CompleteType mCompleteType;
92 int UtcTextureManagerRequestLoad(void)
94 ToolkitTestApplication application;
96 TextureManager textureManager; // Create new texture manager
98 TestObserver observer;
99 std::string filename("image.png");
100 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
101 TextureManager::TextureId textureId = textureManager.RequestLoad(
104 FittingMode::SCALE_TO_FILL,
105 SamplingMode::BOX_THEN_LINEAR,
106 TextureManager::NO_ATLAS,
109 TextureManager::ReloadPolicy::CACHED,
112 VisualUrl url = textureManager.GetVisualUrl( textureId );
114 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
119 int UtcTextureManagerGenerateHash(void)
121 ToolkitTestApplication application;
123 TextureManager textureManager; // Create new texture manager
125 TestObserver observer;
126 std::string filename( "image.png" );
127 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
128 TextureManager::TextureId textureId = textureManager.RequestLoad(
131 FittingMode::SCALE_TO_FILL,
132 SamplingMode::BOX_THEN_LINEAR,
133 TextureManager::USE_ATLAS,
136 TextureManager::ReloadPolicy::CACHED,
139 VisualUrl url = textureManager.GetVisualUrl( textureId );
141 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
146 int UtcTextureManagerCachingForDifferentLoadingType(void)
148 ToolkitTestApplication application;
149 tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" );
151 TextureManager textureManager; // Create new texture manager
153 TestObserver observer1;
154 std::string filename( TEST_IMAGE_FILE_NAME );
155 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
156 textureManager.RequestLoad(
159 FittingMode::SCALE_TO_FILL,
160 SamplingMode::BOX_THEN_LINEAR,
161 TextureManager::NO_ATLAS,
164 TextureManager::ReloadPolicy::CACHED,
167 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
168 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
170 application.SendNotification();
171 application.Render();
173 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
175 application.SendNotification();
176 application.Render();
178 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
179 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
180 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
182 TestObserver observer2;
183 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
186 FittingMode::SCALE_TO_FILL,
187 SamplingMode::BOX_THEN_LINEAR,
193 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
194 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
196 application.SendNotification();
197 application.Render();
199 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
201 application.SendNotification();
202 application.Render();
204 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
205 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
206 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
211 int UtcTextureManagerUseInvalidMask(void)
213 ToolkitTestApplication application;
214 tet_infoline( "UtcTextureManagerUseInvalidMask" );
216 TextureManager textureManager; // Create new texture manager
218 TestObserver observer;
219 std::string filename( TEST_IMAGE_FILE_NAME );
220 std::string maskname("");
221 TextureManager::MaskingDataPointer maskInfo = nullptr;
222 maskInfo.reset(new TextureManager::MaskingData());
223 maskInfo->mAlphaMaskUrl = maskname;
224 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
225 maskInfo->mCropToMask = true;
226 maskInfo->mContentScaleFactor = 1.0f;
228 auto textureId( TextureManager::INVALID_TEXTURE_ID );
229 Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
230 Dali::ImageDimensions atlasRectSize( 0,0 );
231 bool synchronousLoading(false);
232 bool atlasingStatus(false);
233 bool loadingStatus(false);
234 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
235 ImageAtlasManagerPtr atlasManager = nullptr;
236 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
238 textureManager.LoadTexture(
241 FittingMode::SCALE_TO_FILL,
242 SamplingMode::BOX_THEN_LINEAR,
256 TextureManager::ReloadPolicy::CACHED,
260 DALI_TEST_EQUALS( observer.mLoaded, false, TEST_LOCATION );
261 DALI_TEST_EQUALS( observer.mObserverCalled, false, TEST_LOCATION );
263 application.SendNotification();
264 application.Render();
266 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
268 application.SendNotification();
269 application.Render();
271 DALI_TEST_EQUALS( observer.mLoaded, true, TEST_LOCATION );
272 DALI_TEST_EQUALS( observer.mObserverCalled, true, TEST_LOCATION );
273 DALI_TEST_EQUALS( observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );