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 using namespace Dali::Toolkit::Internal;
33 void utc_dali_toolkit_texture_manager_startup(void)
35 setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
36 test_return_value = TET_UNDEF;
39 void utc_dali_toolkit_texture_manager_cleanup(void)
41 test_return_value = TET_PASS;
47 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
51 class TestObserver : public Dali::Toolkit::TextureUploadObserver
54 enum class CompleteType
63 : mCompleteType( CompleteType::NOT_COMPLETED ),
65 mObserverCalled(false)
69 virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
70 bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
72 mCompleteType = CompleteType::UPLOAD_COMPLETE;
73 mLoaded = loadSuccess;
74 mObserverCalled = true;
77 virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
79 mCompleteType = CompleteType::LOAD_COMPLETE;
80 mLoaded = loadSuccess;
81 mObserverCalled = true;
84 CompleteType mCompleteType;
90 int UtcTextureManagerRequestLoad(void)
92 ToolkitTestApplication application;
94 TextureManager textureManager; // Create new texture manager
96 TestObserver observer;
97 std::string filename("image.png");
98 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
99 TextureManager::TextureId textureId = textureManager.RequestLoad(
102 FittingMode::SCALE_TO_FILL,
103 SamplingMode::BOX_THEN_LINEAR,
104 TextureManager::NO_ATLAS,
107 TextureManager::ReloadPolicy::CACHED,
110 VisualUrl url = textureManager.GetVisualUrl( textureId );
112 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
117 int UtcTextureManagerGenerateHash(void)
119 ToolkitTestApplication application;
121 TextureManager textureManager; // Create new texture manager
123 TestObserver observer;
124 std::string filename( "image.png" );
125 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
126 TextureManager::TextureId textureId = textureManager.RequestLoad(
129 FittingMode::SCALE_TO_FILL,
130 SamplingMode::BOX_THEN_LINEAR,
131 TextureManager::USE_ATLAS,
134 TextureManager::ReloadPolicy::CACHED,
137 VisualUrl url = textureManager.GetVisualUrl( textureId );
139 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
144 int UtcTextureManagerCachingForDifferentLoadingType(void)
146 ToolkitTestApplication application;
147 tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" );
149 TextureManager textureManager; // Create new texture manager
151 TestObserver observer1;
152 std::string filename( TEST_IMAGE_FILE_NAME );
153 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
154 textureManager.RequestLoad(
157 FittingMode::SCALE_TO_FILL,
158 SamplingMode::BOX_THEN_LINEAR,
159 TextureManager::NO_ATLAS,
162 TextureManager::ReloadPolicy::CACHED,
165 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
166 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
168 application.SendNotification();
169 application.Render();
171 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
173 application.SendNotification();
174 application.Render();
176 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
177 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
178 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
180 TestObserver observer2;
181 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
184 FittingMode::SCALE_TO_FILL,
185 SamplingMode::BOX_THEN_LINEAR,
191 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
192 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
194 application.SendNotification();
195 application.Render();
197 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
199 application.SendNotification();
200 application.Render();
202 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
203 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
204 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );
209 int UtcTextureManagerUseInvalidMask(void)
211 ToolkitTestApplication application;
212 tet_infoline( "UtcTextureManagerUseInvalidMask" );
214 TextureManager textureManager; // Create new texture manager
216 TestObserver observer;
217 std::string filename( TEST_IMAGE_FILE_NAME );
218 std::string maskname("");
219 TextureManager::MaskingDataPointer maskInfo = nullptr;
220 maskInfo.reset(new TextureManager::MaskingData());
221 maskInfo->mAlphaMaskUrl = maskname;
222 maskInfo->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
223 maskInfo->mCropToMask = true;
224 maskInfo->mContentScaleFactor = 1.0f;
226 auto textureId( TextureManager::INVALID_TEXTURE_ID );
227 Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
228 Dali::ImageDimensions atlasRectSize( 0,0 );
229 bool synchronousLoading(false);
230 bool atlasingStatus(false);
231 bool loadingStatus(false);
232 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
233 ImageAtlasManagerPtr atlasManager = nullptr;
234 Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
236 textureManager.LoadTexture(
239 FittingMode::SCALE_TO_FILL,
240 SamplingMode::BOX_THEN_LINEAR,
254 TextureManager::ReloadPolicy::CACHED,
258 DALI_TEST_EQUALS( observer.mLoaded, false, TEST_LOCATION );
259 DALI_TEST_EQUALS( observer.mObserverCalled, false, TEST_LOCATION );
261 application.SendNotification();
262 application.Render();
264 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
266 application.SendNotification();
267 application.Render();
269 DALI_TEST_EQUALS( observer.mLoaded, true, TEST_LOCATION );
270 DALI_TEST_EQUALS( observer.mObserverCalled, true, TEST_LOCATION );
271 DALI_TEST_EQUALS( observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );