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>
29 using namespace Dali::Toolkit::Internal;
32 void utc_dali_toolkit_texture_manager_startup(void)
34 setenv( "LOG_TEXTURE_MANAGER", "3", 1 );
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_texture_manager_cleanup(void)
40 test_return_value = TET_PASS;
46 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
50 class TestObserver : public Dali::Toolkit::TextureUploadObserver
53 enum class CompleteType
62 : mCompleteType( CompleteType::NOT_COMPLETED ),
64 mObserverCalled(false)
68 virtual void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet,
69 bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override
71 mCompleteType = CompleteType::UPLOAD_COMPLETE;
72 mLoaded = loadSuccess;
73 mObserverCalled = true;
76 virtual void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override
78 mCompleteType = CompleteType::LOAD_COMPLETE;
79 mLoaded = loadSuccess;
80 mObserverCalled = true;
83 CompleteType mCompleteType;
89 int UtcTextureManagerRequestLoad(void)
91 ToolkitTestApplication application;
93 TextureManager textureManager; // Create new texture manager
95 TestObserver observer;
96 std::string filename("image.png");
97 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
98 TextureManager::TextureId textureId = textureManager.RequestLoad(
101 FittingMode::SCALE_TO_FILL,
102 SamplingMode::BOX_THEN_LINEAR,
103 TextureManager::NO_ATLAS,
106 TextureManager::ReloadPolicy::CACHED,
109 VisualUrl url = textureManager.GetVisualUrl( textureId );
111 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
116 int UtcTextureManagerGenerateHash(void)
118 ToolkitTestApplication application;
120 TextureManager textureManager; // Create new texture manager
122 TestObserver observer;
123 std::string filename( "image.png" );
124 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
125 TextureManager::TextureId textureId = textureManager.RequestLoad(
128 FittingMode::SCALE_TO_FILL,
129 SamplingMode::BOX_THEN_LINEAR,
130 TextureManager::USE_ATLAS,
133 TextureManager::ReloadPolicy::CACHED,
136 VisualUrl url = textureManager.GetVisualUrl( textureId );
138 DALI_TEST_EQUALS( url.GetUrl().compare( filename ), 0, TEST_LOCATION );
143 int UtcTextureManagerCachingForDifferentLoadingType(void)
145 ToolkitTestApplication application;
146 tet_infoline( "UtcTextureManagerCachingForDifferentLoadingType" );
148 TextureManager textureManager; // Create new texture manager
150 TestObserver observer1;
151 std::string filename( TEST_IMAGE_FILE_NAME );
152 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
153 textureManager.RequestLoad(
156 FittingMode::SCALE_TO_FILL,
157 SamplingMode::BOX_THEN_LINEAR,
158 TextureManager::NO_ATLAS,
161 TextureManager::ReloadPolicy::CACHED,
164 DALI_TEST_EQUALS( observer1.mLoaded, false, TEST_LOCATION );
165 DALI_TEST_EQUALS( observer1.mObserverCalled, false, TEST_LOCATION );
167 application.SendNotification();
168 application.Render();
170 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
172 application.SendNotification();
173 application.Render();
175 DALI_TEST_EQUALS( observer1.mLoaded, true, TEST_LOCATION );
176 DALI_TEST_EQUALS( observer1.mObserverCalled, true, TEST_LOCATION );
177 DALI_TEST_EQUALS( observer1.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION );
179 TestObserver observer2;
180 Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
183 FittingMode::SCALE_TO_FILL,
184 SamplingMode::BOX_THEN_LINEAR,
190 DALI_TEST_EQUALS( observer2.mLoaded, false, TEST_LOCATION );
191 DALI_TEST_EQUALS( observer2.mObserverCalled, false, TEST_LOCATION );
193 application.SendNotification();
194 application.Render();
196 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS( observer2.mLoaded, true, TEST_LOCATION );
202 DALI_TEST_EQUALS( observer2.mObserverCalled, true, TEST_LOCATION );
203 DALI_TEST_EQUALS( observer2.mCompleteType, TestObserver::CompleteType::LOAD_COMPLETE, TEST_LOCATION );