2 * Copyright (c) 2016 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/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/update/resources/texture-metadata.h>
28 #include <dali/internal/update/resources/resource-manager.h>
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/internal/event/resources/resource-client.h>
31 #include <dali/internal/event/resources/resource-ticket.h>
32 #include <dali/internal/event/resources/image-ticket.h>
33 #include <dali/internal/event/resources/resource-ticket-observer.h>
34 #include <dali/internal/event/images/resource-image-impl.h>
35 #include <dali/integration-api/resource-cache.h>
36 #include <dali/internal/render/gl-resources/texture-declarations.h>
37 #include <dali/internal/render/shaders/scene-graph-shader.h>
38 #include <dali/internal/common/owner-pointer.h>
39 #include <dali/internal/common/image-attributes.h>
43 #include <mesh-builder.h>
48 class TestTicketObserver : public Internal::ResourceTicketObserver
52 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
56 int LoadFailedCalled() {
57 tet_printf("TicketObserver: LoadingFailed() called %d times\n", mLoadingFailedCalled);
58 return mLoadingFailedCalled;
60 int LoadSucceededCalled() {
61 tet_printf("TicketObserver: LoadingSucceeded() called %d times\n", mLoadingSucceededCalled);
62 return mLoadingSucceededCalled;
65 tet_printf("TicketObserver: Uploaded() called %d times\n", mUploadedCount);
66 return mUploadedCount;
69 mLoadingFailedCalled = 0;
70 mLoadingSucceededCalled = 0;
74 public: // From ResourceTicketObserver
75 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
76 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
77 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
80 int mLoadingFailedCalled;
81 int mLoadingSucceededCalled;
85 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
88 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
90 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
91 { resourceTicketDiscarded = true; }
93 void Reset() { resourceTicketDiscarded = false; }
94 bool resourceTicketDiscarded;
97 static TestTicketObserver testTicketObserver;
98 static TestTicketLifetimeObserver testTicketLifetimeObserver;
100 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
102 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
103 Integration::BitmapResourceType bitmapRequest;
104 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
105 ticket->AddObserver(testTicketObserver);
106 application.SendNotification(); // Flush update messages
107 application.Render(); // Process resource request
108 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
109 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
110 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
111 Integration::ResourcePointer resourcePtr(bitmap); // reference it
112 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
113 application.Render(); // Process LoadComplete
114 application.SendNotification(); // Process event messages
115 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
116 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
118 application.GetPlatform().ResetTrace();
123 } //anonymous namespace
126 void utc_dali_internal_resource_client_startup()
128 test_return_value = TET_UNDEF;
131 void utc_dali_internal_resource_client_cleanup()
133 test_return_value = TET_PASS;
136 // Load a bitmap resource successfully, then discard it's ticket
137 int UtcDaliInternalRequestResourceBitmapRequests01(void)
139 TestApplication application; // Reset all test adapter return codes
141 tet_infoline("Testing bitmap requests");
143 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
144 Integration::BitmapResourceType bitmapRequest;
145 Internal::ResourceId id(0);
147 testTicketObserver.Reset();
150 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
151 /************************************************************
152 * FUNCTION UNDER TEST
153 ***********************************************************/
154 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
155 ticket->AddObserver(testTicketObserver);
157 // Update thread will request the bitmap resource:
158 // Sets application.GetPlatform().mRequest
159 application.SendNotification(); // Run flush update queue
160 application.Render(1); // Process update messages
161 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
163 application.SendNotification(); // Send any event messages
164 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
165 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
166 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
168 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
169 DALI_TEST_CHECK( imageTicket );
170 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
171 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
174 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
175 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
176 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
177 Integration::ResourcePointer resourcePtr(bitmap); // reference it
179 // Set up platform abstraction to load it
181 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
183 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
185 // load the cache, which will immediately have the loaded resource
186 application.Render(0);
188 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
190 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
191 Internal::TextureMetadata* bitmapData = NULL;
192 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
193 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
194 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
196 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
197 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
199 // Trigger the event thread to process notify messages. Should then trigger the signals
200 // in the ticket observer
201 application.SendNotification();
203 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
204 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
206 // Check that the image ticket was updated with the image attributes
207 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
208 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
211 application.SendNotification(); // Flush update queue (with ticket discarded message
212 application.Render(1); // Process update messages
213 application.SendNotification(); // Send event notifications
214 application.Render(1); // Process update messages
216 // Resource should have been discarded.
217 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
218 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
220 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
221 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
225 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
226 int UtcDaliInternalRequestResourceBitmapRequests02(void)
228 TestApplication application; // Reset all test adapter return codes
230 tet_infoline("Testing bitmap request ticket discard before load complete");
232 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
233 Integration::BitmapResourceType bitmapRequest;
234 Internal::ResourceId id(0);
236 testTicketObserver.Reset();
239 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
240 /************************************************************
241 * FUNCTION UNDER TEST
242 ***********************************************************/
243 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
244 ticket->AddObserver(testTicketObserver);
245 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
246 DALI_TEST_CHECK( imageTicket );
247 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
248 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
250 // Update thread will request the bitmap resource:
251 // Sets application.GetPlatform().mRequest
252 application.SendNotification(); // Run flush update queue
253 application.Render(1);
254 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
255 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
258 application.SendNotification(); // Should produce no messages
259 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
260 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
262 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
264 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
265 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
266 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
270 // Ensure ticket discarded message is sent to update thread
271 application.SendNotification(); // Flush update queue
272 application.Render(0); // Process update messages
274 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
275 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
277 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
279 // Trigger the event thread to process notify messages. Should then trigger the signals
280 // in the ticket observer
281 application.SendNotification();
283 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
284 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
288 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
289 int UtcDaliInternalRequestResourceBitmapRequests03(void)
291 TestApplication application; // Reset all test adapter return codes
293 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
295 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
296 Integration::BitmapResourceType bitmapRequest;
297 Internal::ResourceId id(0);
299 testTicketObserver.Reset();
300 { // Scope lifetime of ticket
301 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
303 /************************************************************
304 * FUNCTION UNDER TEST
305 ***********************************************************/
306 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
307 ticket->AddObserver(testTicketObserver);
308 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
309 DALI_TEST_CHECK( imageTicket );
310 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
311 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
313 // Update thread will request the bitmap resource:
314 // Sets application.GetPlatform().mRequest
315 application.SendNotification(); // Run flush update queue
316 application.Render(1); // process update messages
317 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
318 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
320 application.SendNotification(); // Should produce no messages
321 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
322 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
324 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
326 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
328 application.Render(0); // Get failed result
329 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
330 application.SendNotification(); // send failed
331 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
332 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
334 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
335 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
336 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
338 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
341 application.Render(0); // Send DiscardTicket
342 application.SendNotification();
344 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
350 // Load a bitmap resource successfully, then reload it
351 int UtcDaliInternalRequestReloadBitmapRequests01(void)
353 TestApplication application; // Reset all test adapter return codes
355 tet_infoline("Testing bitmap reload after successful load");
357 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
358 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
360 Internal::ResourceId id(0);
361 testTicketObserver.Reset();
364 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
365 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
366 id = ticket->GetId();
368 // Reset call statistics - test that resource is reloaded
369 application.GetPlatform().ResetTrace();
371 /************************************************************
372 * FUNCTION UNDER TEST
373 ***********************************************************/
374 resourceClient.ReloadResource( ticket->GetId() );
376 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
377 application.SendNotification(); // Flush update messages
378 application.Render(0); // Process update messages
379 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
380 application.SendNotification(); // Process event messages
382 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
383 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
384 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
385 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
387 // Create a new resource - the image size could have changed in the meantime
388 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
389 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
390 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
391 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
392 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
393 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
395 application.Render(0 , TEST_LOCATION ); // Process update messages / UpdateCache
396 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
398 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
399 Internal::TextureMetadata* bitmapData = NULL;
400 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
401 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
402 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
404 // Ticket can't have been updated yet - it should still have old values
405 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
406 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
408 application.SendNotification(); // Process event messages
409 application.Render(0, TEST_LOCATION ); // Process update messages / UpdateCache
410 application.SendNotification(); // Process event messages
412 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
413 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 1, TEST_LOCATION );
414 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
415 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
416 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
420 application.SendNotification(); // Flush update queue (with ticket discarded message
421 application.Render(1, TEST_LOCATION ); // Process update messages
422 application.SendNotification(); // Send event notifications
424 // Resource should have been discarded.
425 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
426 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
428 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
429 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
430 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 1, TEST_LOCATION );
435 int UtcDaliInternalRequestReloadBitmapRequests02(void)
437 TestApplication application; // Reset all test adapter return codes
439 tet_infoline("Testing bitmap reload during first load");
441 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
442 Integration::BitmapResourceType bitmapRequest;
443 Internal::ResourceId id(0);
445 testTicketObserver.Reset();
448 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
449 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
450 ticket->AddObserver(testTicketObserver);
452 // Update thread will request the bitmap resource:
453 // Sets application.GetPlatform().mRequest
454 application.SendNotification(); // Run flush update queue
455 application.Render(1); // Process update messages
456 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
458 application.SendNotification(); // Send any event messages
459 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
460 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
462 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
463 DALI_TEST_CHECK( imageTicket );
464 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
465 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
468 /************************************************************
469 * FUNCTION UNDER TEST
470 ***********************************************************/
471 resourceClient.ReloadResource( ticket->GetId() );
472 /************************************************************
473 * Expected result - current load completes as usual, no reload requested
474 ************************************************************/
476 application.SendNotification(); // Flush update methods
478 // Reset call statistics - test that resource is not reloaded
479 application.GetPlatform().ResetTrace();
481 application.Render(0); // Process reload message (nothing for UpdateCache yet)
483 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
484 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
486 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
487 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
488 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
489 Integration::ResourcePointer resourcePtr(bitmap); // reference it
491 // Set up platform abstraction to load it
494 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
496 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
498 application.GetPlatform().ResetTrace();
499 // load the cache, which will immediately have the loaded resource
500 application.Render(0);
501 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
502 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
503 Internal::TextureMetadata* bitmapData = NULL;
504 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
505 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
506 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
508 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
509 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
511 // Trigger the event thread to process notify messages. Should then trigger the signals
512 // in the ticket observer
513 application.SendNotification();
515 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
516 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
517 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
519 // Check that the image ticket was updated with the image attributes
520 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
521 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
523 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
525 application.SendNotification(); // Flush update messages
526 application.Render(0); // Process update messages
528 // There should be no reload
529 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
530 application.SendNotification(); // Process event messages
532 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
533 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
534 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
535 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
537 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
538 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
539 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
540 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
541 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
542 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
549 int UtcDaliInternalRequestReloadBitmapRequests03(void)
551 TestApplication application; // Reset all test adapter return codes
553 tet_infoline("Testing bitmap reload at end of first load");
555 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
556 Integration::BitmapResourceType bitmapRequest;
557 Internal::ResourceId id(0);
559 testTicketObserver.Reset();
562 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
563 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
564 ticket->AddObserver(testTicketObserver);
566 // Update thread will request the bitmap resource:
567 // Sets application.GetPlatform().mRequest
568 application.SendNotification(); // Run flush update queue
569 application.Render(1); // Process update messages
570 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
572 application.SendNotification(); // Send any event messages
573 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
574 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
576 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
577 DALI_TEST_CHECK( imageTicket );
578 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
579 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
582 /************************************************************
583 * FUNCTION UNDER TEST
584 ***********************************************************/
585 resourceClient.ReloadResource( ticket->GetId() );
586 /************************************************************
587 * Expected result - current load completes as usual, no reload requested
588 ************************************************************/
590 application.SendNotification(); // Flush update methods
592 // Reset call statistics - test that resource is not reloaded
593 application.GetPlatform().ResetTrace();
596 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
597 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
598 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
599 Integration::ResourcePointer resourcePtr(bitmap); // reference it
601 // Set up platform abstraction to load it
604 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
606 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
608 application.GetPlatform().ResetTrace();
609 // load the cache, which will immediately have the loaded resource
610 application.Render(0);
612 // UpdateCache runs before ProcessMessages, so the loading resource completes before
613 // the reload request is handled.
614 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
615 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
617 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
618 Internal::TextureMetadata* bitmapData = NULL;
619 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
620 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
621 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
623 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
624 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
626 // Trigger the event thread to process notify messages. Should then trigger the signals
627 // in the ticket observer
628 application.SendNotification();
630 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
631 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
632 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
634 // Check that the image ticket was updated with the image attributes
635 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
636 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
638 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
640 // Create a new resource - the image size could have changed in the meantime
641 req = application.GetPlatform().GetRequest();
642 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
643 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
644 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
645 DALI_TEST_CHECK( req->GetId() == id );
646 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
648 application.Render(0); // Process update messages / UpdateCache
650 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
651 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
652 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
653 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
654 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
655 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
657 application.SendNotification(); // Process event messages
659 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
661 // Not staged - no GL upload
662 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
664 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
665 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
666 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
667 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
672 int UtcDaliInternalRequestResourceTicket01(void)
674 TestApplication application;
675 tet_infoline("Testing RequestResourceTicket() with valid id");
677 testTicketObserver.Reset();
679 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
681 // First, load a bitmap resource
682 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
684 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
685 DALI_TEST_CHECK( newTicket );
686 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
687 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
691 int UtcDaliInternalRequestResourceTicket02(void)
693 TestApplication application;
694 tet_infoline("Testing RequestResourceTicket() with invalid id");
696 testTicketObserver.Reset();
698 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
700 // First, load a bitmap resource
701 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
703 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
704 DALI_TEST_CHECK( ! newTicket );
708 int UtcDaliInternalAddBitmapImage01(void)
710 TestApplication application;
711 tet_infoline("Testing AddBitmap with reserved buffer()");
712 testTicketObserver.Reset();
713 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
714 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
715 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
717 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
718 DALI_TEST_CHECK( imageTicket );
719 imageTicket->AddObserver( testTicketObserver );
721 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
722 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
723 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
725 application.SendNotification(); // Flush update queue
726 application.Render(0); // Process message
727 application.SendNotification(); // Send message to tickets
729 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
730 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
731 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
732 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
736 int UtcDaliInternalAddBitmapImage02(void)
738 TestApplication application;
739 tet_infoline("Testing AddBitmap without reserved buffer()");
740 testTicketObserver.Reset();
741 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
742 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
744 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
745 DALI_TEST_CHECK( imageTicket );
746 imageTicket->AddObserver( testTicketObserver );
748 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
749 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
750 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
751 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
753 application.SendNotification(); // Flush update queue
754 application.Render(0); // Process message
755 application.SendNotification(); // Send message to tickets
757 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
758 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
759 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
760 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
765 int UtcDaliInternalAddBitmapImage03(void)
767 TestApplication application;
768 tet_infoline("Testing AddBitmap() with invalid bitmap");
769 testTicketObserver.Reset();
771 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
772 Internal::ImageTicketPtr imageTicket;
773 bool exceptionRaised=false;
776 imageTicket = resourceClient.AddBitmapImage( NULL );
778 catch( DaliException& e )
780 exceptionRaised = true;
782 DALI_TEST_CHECK( exceptionRaised );
783 DALI_TEST_CHECK( ! imageTicket );
787 int UtcDaliInternalAllocateTexture01(void)
789 TestApplication application;
790 tet_infoline("Testing AllocateTexture()");
791 testTicketObserver.Reset();
793 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
794 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
795 resourceTicket->AddObserver( testTicketObserver );
797 DALI_TEST_CHECK( resourceTicket );
798 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
799 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
801 application.SendNotification(); // Flush update queue
802 application.Render(0); // Process message
803 application.SendNotification(); // Send message to tickets
805 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
806 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
810 int UtcDaliInternalAddNativeImage(void)
812 TestApplication application;
813 tet_infoline("Testing AddNativeImage()");
815 testTicketObserver.Reset();
816 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
817 Internal::ResourceTicketPtr ticket;
818 Internal::ImageTicketPtr imageTicket;
819 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
820 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
821 ticket = resourceClient.AddNativeImage( *nativeImage );
822 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
823 DALI_TEST_CHECK( imageTicket );
824 imageTicket->AddObserver( testTicketObserver );
827 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
828 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
829 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
830 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
832 application.SendNotification(); // Flush update queue
833 application.Render(0); // Process message
834 application.SendNotification(); // Send message to tickets
836 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
837 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
838 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
839 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
843 int UtcDaliInternalAddFrameBufferImage(void)
845 TestApplication application;
846 tet_infoline("Testing AddFrameBufferImage()");
848 testTicketObserver.Reset();
849 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
850 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8, RenderBuffer::COLOR );
851 DALI_TEST_CHECK( imageTicket );
852 imageTicket->AddObserver( testTicketObserver );
854 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
855 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
856 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
857 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
859 application.SendNotification(); // Flush update queue
860 application.Render(0); // Process message
861 application.SendNotification(); // Send message to tickets
863 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
864 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
865 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
866 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent