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-test-suite-utils.h>
23 #include <test-native-image.h>
25 // Internal headers are allowed here
26 #include <dali/public-api/shader-effects/shader-effect.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/update/resources/texture-metadata.h>
29 #include <dali/internal/update/resources/resource-manager.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/event/resources/resource-client.h>
32 #include <dali/internal/event/resources/resource-ticket.h>
33 #include <dali/internal/event/resources/image-ticket.h>
34 #include <dali/internal/event/resources/resource-ticket-observer.h>
35 #include <dali/internal/event/images/resource-image-impl.h>
36 #include <dali/integration-api/resource-cache.h>
37 #include <dali/internal/render/gl-resources/texture-declarations.h>
38 #include <dali/internal/render/shaders/scene-graph-shader.h>
39 #include <dali/internal/common/owner-pointer.h>
40 #include <dali/internal/common/image-attributes.h>
44 #include <mesh-builder.h>
49 class TestTicketObserver : public Internal::ResourceTicketObserver
53 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
57 int LoadFailedCalled() {
58 tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
59 return mLoadingFailedCalled;
61 int LoadSucceededCalled() {
62 tet_printf("TicketObserver: LoadingSucceeded() called %d times", mLoadingSucceededCalled);
63 return mLoadingSucceededCalled;
66 tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
67 return mUploadedCount;
70 mLoadingFailedCalled = 0;
71 mLoadingSucceededCalled = 0;
75 public: // From ResourceTicketObserver
76 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
77 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
78 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
81 int mLoadingFailedCalled;
82 int mLoadingSucceededCalled;
86 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
89 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
91 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
92 { resourceTicketDiscarded = true; }
94 void Reset() { resourceTicketDiscarded = false; }
95 bool resourceTicketDiscarded;
98 static TestTicketObserver testTicketObserver;
99 static TestTicketLifetimeObserver testTicketLifetimeObserver;
102 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
104 Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Internal::ImageAttributes::DEFAULT_ATTRIBUTES );
105 application.SendNotification(); // Flush update messages
106 application.Render(); // Process resource request
107 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
108 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
109 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
110 Integration::ResourcePointer resourcePtr(bitmap); // reference it
111 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
112 application.Render(); // Process LoadComplete
113 application.SendNotification(); // Process event messages
114 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
116 application.GetPlatform().ResetTrace();
121 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
123 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
124 Integration::BitmapResourceType bitmapRequest;
125 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
126 ticket->AddObserver(testTicketObserver);
127 application.SendNotification(); // Flush update messages
128 application.Render(); // Process resource request
129 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
130 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
131 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
132 Integration::ResourcePointer resourcePtr(bitmap); // reference it
133 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
134 application.Render(); // Process LoadComplete
135 application.SendNotification(); // Process event messages
136 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
137 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
139 application.GetPlatform().ResetTrace();
144 } //anonymous namespace
147 void utc_dali_internal_resource_client_startup()
149 test_return_value = TET_UNDEF;
152 void utc_dali_internal_resource_client_cleanup()
154 test_return_value = TET_PASS;
157 // Load a bitmap resource successfully, then discard it's ticket
158 int UtcDaliInternalRequestResourceBitmapRequests01(void)
160 TestApplication application; // Reset all test adapter return codes
162 tet_infoline("Testing bitmap requests");
164 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
165 Integration::BitmapResourceType bitmapRequest;
166 Internal::ResourceId id(0);
168 testTicketObserver.Reset();
171 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
172 /************************************************************
173 * FUNCTION UNDER TEST
174 ***********************************************************/
175 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
176 ticket->AddObserver(testTicketObserver);
178 // Update thread will request the bitmap resource:
179 // Sets application.GetPlatform().mRequest
180 application.SendNotification(); // Run flush update queue
181 application.Render(1); // Process update messages
182 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
184 application.SendNotification(); // Send any event messages
185 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
186 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
187 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
189 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
190 DALI_TEST_CHECK( imageTicket );
191 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
192 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
195 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
196 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
197 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
198 Integration::ResourcePointer resourcePtr(bitmap); // reference it
200 // Set up platform abstraction to load it
202 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
204 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
206 // load the cache, which will immediately have the loaded resource
207 application.Render(0);
209 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
211 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
212 Internal::TextureMetadata* bitmapData = NULL;
213 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
214 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
215 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
217 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
218 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
220 // Trigger the event thread to process notify messages. Should then trigger the signals
221 // in the ticket observer
222 application.SendNotification();
224 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
225 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
227 // Check that the image ticket was updated with the image attributes
228 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
229 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
232 application.SendNotification(); // Flush update queue (with ticket discarded message
233 application.Render(1); // Process update messages
234 application.SendNotification(); // Send event notifications
235 application.Render(1); // Process update messages
237 // Resource should have been discarded.
238 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
239 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
241 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
242 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
246 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
247 int UtcDaliInternalRequestResourceBitmapRequests02(void)
249 TestApplication application; // Reset all test adapter return codes
251 tet_infoline("Testing bitmap request ticket discard before load complete");
253 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
254 Integration::BitmapResourceType bitmapRequest;
255 Internal::ResourceId id(0);
257 testTicketObserver.Reset();
260 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
261 /************************************************************
262 * FUNCTION UNDER TEST
263 ***********************************************************/
264 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
265 ticket->AddObserver(testTicketObserver);
266 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
267 DALI_TEST_CHECK( imageTicket );
268 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
269 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
271 // Update thread will request the bitmap resource:
272 // Sets application.GetPlatform().mRequest
273 application.SendNotification(); // Run flush update queue
274 application.Render(1);
275 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
276 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
279 application.SendNotification(); // Should produce no messages
280 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
281 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
283 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
285 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
286 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
287 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
291 // Ensure ticket discarded message is sent to update thread
292 application.SendNotification(); // Flush update queue
293 application.Render(0); // Process update messages
295 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
296 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
298 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
300 // Trigger the event thread to process notify messages. Should then trigger the signals
301 // in the ticket observer
302 application.SendNotification();
304 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
305 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
309 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
310 int UtcDaliInternalRequestResourceBitmapRequests03(void)
312 TestApplication application; // Reset all test adapter return codes
314 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
316 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
317 Integration::BitmapResourceType bitmapRequest;
318 Internal::ResourceId id(0);
320 testTicketObserver.Reset();
321 { // Scope lifetime of ticket
322 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
324 /************************************************************
325 * FUNCTION UNDER TEST
326 ***********************************************************/
327 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
328 ticket->AddObserver(testTicketObserver);
329 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
330 DALI_TEST_CHECK( imageTicket );
331 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
332 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
334 // Update thread will request the bitmap resource:
335 // Sets application.GetPlatform().mRequest
336 application.SendNotification(); // Run flush update queue
337 application.Render(1); // process update messages
338 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
339 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
341 application.SendNotification(); // Should produce no messages
342 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
343 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
345 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
347 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
349 application.Render(0); // Get failed result
350 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
351 application.SendNotification(); // send failed
352 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
353 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
355 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
356 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
357 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
359 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
362 application.Render(0); // Send DiscardTicket
363 application.SendNotification();
365 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
371 // Load a bitmap resource successfully, then reload it
372 int UtcDaliInternalRequestReloadBitmapRequests01(void)
374 TestApplication application; // Reset all test adapter return codes
376 tet_infoline("Testing bitmap reload after successful load");
378 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
379 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
381 Internal::ResourceId id(0);
382 testTicketObserver.Reset();
385 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
386 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
387 id = ticket->GetId();
389 // Reset call statistics - test that resource is reloaded
390 application.GetPlatform().ResetTrace();
392 /************************************************************
393 * FUNCTION UNDER TEST
394 ***********************************************************/
395 resourceClient.ReloadResource( ticket->GetId() );
397 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
398 application.SendNotification(); // Flush update messages
399 application.Render(0); // Process update messages
400 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
401 application.SendNotification(); // Process event messages
403 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
404 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
405 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
406 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
408 // Create a new resource - the image size could have changed in the meantime
409 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
410 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
411 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
412 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
413 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
414 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
416 application.Render(0); // Process update messages / UpdateCache
417 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
419 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
420 Internal::TextureMetadata* bitmapData = NULL;
421 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
422 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
423 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
425 // Ticket can't have been updated yet - it should still have old values
426 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
427 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
429 application.SendNotification(); // Process event messages
430 application.Render(0); // Process update messages / UpdateCache
431 application.SendNotification(); // Process event messages
433 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
434 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
435 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
436 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
437 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
441 application.SendNotification(); // Flush update queue (with ticket discarded message
442 application.Render(1); // Process update messages
443 application.SendNotification(); // Send event notifications
444 application.Render(1); // Process update messages
446 // Resource should have been discarded.
447 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
448 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
450 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
451 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
452 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
457 int UtcDaliInternalRequestReloadBitmapRequests02(void)
459 TestApplication application; // Reset all test adapter return codes
461 tet_infoline("Testing bitmap reload during first load");
463 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
464 Integration::BitmapResourceType bitmapRequest;
465 Internal::ResourceId id(0);
467 testTicketObserver.Reset();
470 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
471 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
472 ticket->AddObserver(testTicketObserver);
474 // Update thread will request the bitmap resource:
475 // Sets application.GetPlatform().mRequest
476 application.SendNotification(); // Run flush update queue
477 application.Render(1); // Process update messages
478 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
480 application.SendNotification(); // Send any event messages
481 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
482 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
484 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
485 DALI_TEST_CHECK( imageTicket );
486 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
487 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
490 /************************************************************
491 * FUNCTION UNDER TEST
492 ***********************************************************/
493 resourceClient.ReloadResource( ticket->GetId() );
494 /************************************************************
495 * Expected result - current load completes as usual, no reload requested
496 ************************************************************/
498 application.SendNotification(); // Flush update methods
500 // Reset call statistics - test that resource is not reloaded
501 application.GetPlatform().ResetTrace();
503 application.Render(0); // Process reload message (nothing for UpdateCache yet)
505 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
506 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
508 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
509 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
510 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
511 Integration::ResourcePointer resourcePtr(bitmap); // reference it
513 // Set up platform abstraction to load it
516 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
518 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
520 application.GetPlatform().ResetTrace();
521 // load the cache, which will immediately have the loaded resource
522 application.Render(0);
523 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
524 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
525 Internal::TextureMetadata* bitmapData = NULL;
526 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
527 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
528 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
530 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
531 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
533 // Trigger the event thread to process notify messages. Should then trigger the signals
534 // in the ticket observer
535 application.SendNotification();
537 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
538 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
539 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
541 // Check that the image ticket was updated with the image attributes
542 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
543 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
545 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
547 application.SendNotification(); // Flush update messages
548 application.Render(0); // Process update messages
550 // There should be no reload
551 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
552 application.SendNotification(); // Process event messages
554 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
555 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
556 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
557 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
559 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
560 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
561 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
562 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
563 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
564 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
571 int UtcDaliInternalRequestReloadBitmapRequests03(void)
573 TestApplication application; // Reset all test adapter return codes
575 tet_infoline("Testing bitmap reload at end of first load");
577 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
578 Integration::BitmapResourceType bitmapRequest;
579 Internal::ResourceId id(0);
581 testTicketObserver.Reset();
584 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
585 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
586 ticket->AddObserver(testTicketObserver);
588 // Update thread will request the bitmap resource:
589 // Sets application.GetPlatform().mRequest
590 application.SendNotification(); // Run flush update queue
591 application.Render(1); // Process update messages
592 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
594 application.SendNotification(); // Send any event messages
595 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
596 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
598 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
599 DALI_TEST_CHECK( imageTicket );
600 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
601 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
604 /************************************************************
605 * FUNCTION UNDER TEST
606 ***********************************************************/
607 resourceClient.ReloadResource( ticket->GetId() );
608 /************************************************************
609 * Expected result - current load completes as usual, no reload requested
610 ************************************************************/
612 application.SendNotification(); // Flush update methods
614 // Reset call statistics - test that resource is not reloaded
615 application.GetPlatform().ResetTrace();
618 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
619 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
620 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
621 Integration::ResourcePointer resourcePtr(bitmap); // reference it
623 // Set up platform abstraction to load it
626 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
628 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
630 application.GetPlatform().ResetTrace();
631 // load the cache, which will immediately have the loaded resource
632 application.Render(0);
634 // UpdateCache runs before ProcessMessages, so the loading resource completes before
635 // the reload request is handled.
636 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
637 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
639 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
640 Internal::TextureMetadata* bitmapData = NULL;
641 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
642 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
643 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
645 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
646 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
648 // Trigger the event thread to process notify messages. Should then trigger the signals
649 // in the ticket observer
650 application.SendNotification();
652 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
653 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
654 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
656 // Check that the image ticket was updated with the image attributes
657 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
658 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
660 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
662 // Create a new resource - the image size could have changed in the meantime
663 req = application.GetPlatform().GetRequest();
664 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
665 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
666 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
667 DALI_TEST_CHECK( req->GetId() == id );
668 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
670 application.Render(0); // Process update messages / UpdateCache
672 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
673 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
674 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
675 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
676 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
677 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
679 application.SendNotification(); // Process event messages
681 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
683 // Not staged - no GL upload
684 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
686 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
687 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
688 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
689 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
694 int UtcDaliInternalRequestResourceTicket01(void)
696 TestApplication application;
697 tet_infoline("Testing RequestResourceTicket() with valid id");
699 testTicketObserver.Reset();
701 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
703 // First, load a bitmap resource
704 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
706 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
707 DALI_TEST_CHECK( newTicket );
708 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
709 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
713 int UtcDaliInternalRequestResourceTicket02(void)
715 TestApplication application;
716 tet_infoline("Testing RequestResourceTicket() with invalid id");
718 testTicketObserver.Reset();
720 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
722 // First, load a bitmap resource
723 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
725 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
726 DALI_TEST_CHECK( ! newTicket );
730 int UtcDaliInternalAddBitmapImage01(void)
732 TestApplication application;
733 tet_infoline("Testing AddBitmap with reserved buffer()");
734 testTicketObserver.Reset();
735 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
736 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
737 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
739 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
740 DALI_TEST_CHECK( imageTicket );
741 imageTicket->AddObserver( testTicketObserver );
743 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
744 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
745 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
747 application.SendNotification(); // Flush update queue
748 application.Render(0); // Process message
749 application.SendNotification(); // Send message to tickets
751 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
752 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
753 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
754 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
758 int UtcDaliInternalAddBitmapImage02(void)
760 TestApplication application;
761 tet_infoline("Testing AddBitmap without reserved buffer()");
762 testTicketObserver.Reset();
763 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
764 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
766 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
767 DALI_TEST_CHECK( imageTicket );
768 imageTicket->AddObserver( testTicketObserver );
770 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
771 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
772 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
773 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
775 application.SendNotification(); // Flush update queue
776 application.Render(0); // Process message
777 application.SendNotification(); // Send message to tickets
779 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
780 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
781 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
782 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
787 int UtcDaliInternalAddBitmapImage03(void)
789 TestApplication application;
790 tet_infoline("Testing AddBitmap() with invalid bitmap");
791 testTicketObserver.Reset();
793 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
794 Internal::ImageTicketPtr imageTicket;
795 bool exceptionRaised=false;
798 imageTicket = resourceClient.AddBitmapImage( NULL );
800 catch( DaliException& e )
802 exceptionRaised = true;
804 DALI_TEST_CHECK( exceptionRaised );
805 DALI_TEST_CHECK( ! imageTicket );
809 int UtcDaliInternalAllocateTexture01(void)
811 TestApplication application;
812 tet_infoline("Testing AllocateTexture()");
813 testTicketObserver.Reset();
815 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
816 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
817 resourceTicket->AddObserver( testTicketObserver );
819 DALI_TEST_CHECK( resourceTicket );
820 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
821 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
823 application.SendNotification(); // Flush update queue
824 application.Render(0); // Process message
825 application.SendNotification(); // Send message to tickets
827 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
828 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
832 int UtcDaliInternalAddNativeImage(void)
834 TestApplication application;
835 tet_infoline("Testing AddNativeImage()");
837 testTicketObserver.Reset();
838 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
839 Internal::ResourceTicketPtr ticket;
840 Internal::ImageTicketPtr imageTicket;
841 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
842 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
843 ticket = resourceClient.AddNativeImage( *nativeImage );
844 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
845 DALI_TEST_CHECK( imageTicket );
846 imageTicket->AddObserver( testTicketObserver );
849 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
850 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
851 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
852 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
854 application.SendNotification(); // Flush update queue
855 application.Render(0); // Process message
856 application.SendNotification(); // Send message to tickets
858 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
859 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
860 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
861 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
865 int UtcDaliInternalAddFrameBufferImage(void)
867 TestApplication application;
868 tet_infoline("Testing AddFrameBufferImage()");
870 testTicketObserver.Reset();
871 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
872 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8, RenderBuffer::COLOR );
873 DALI_TEST_CHECK( imageTicket );
874 imageTicket->AddObserver( testTicketObserver );
876 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
877 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
878 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
879 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
881 application.SendNotification(); // Flush update queue
882 application.Render(0); // Process message
883 application.SendNotification(); // Send message to tickets
885 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
886 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
887 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
888 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent