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;
101 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
103 Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Internal::ImageAttributes::DEFAULT_ATTRIBUTES );
104 application.SendNotification(); // Flush update messages
105 application.Render(); // Process resource request
106 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
107 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
108 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
109 Integration::ResourcePointer resourcePtr(bitmap); // reference it
110 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
111 application.Render(); // Process LoadComplete
112 application.SendNotification(); // Process event messages
113 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
115 application.GetPlatform().ResetTrace();
120 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
122 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
123 Integration::BitmapResourceType bitmapRequest;
124 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
125 ticket->AddObserver(testTicketObserver);
126 application.SendNotification(); // Flush update messages
127 application.Render(); // Process resource request
128 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
129 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
130 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
131 Integration::ResourcePointer resourcePtr(bitmap); // reference it
132 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
133 application.Render(); // Process LoadComplete
134 application.SendNotification(); // Process event messages
135 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
136 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
138 application.GetPlatform().ResetTrace();
143 } //anonymous namespace
146 void utc_dali_internal_resource_client_startup()
148 test_return_value = TET_UNDEF;
151 void utc_dali_internal_resource_client_cleanup()
153 test_return_value = TET_PASS;
156 // Load a bitmap resource successfully, then discard it's ticket
157 int UtcDaliInternalRequestResourceBitmapRequests01(void)
159 TestApplication application; // Reset all test adapter return codes
161 tet_infoline("Testing bitmap requests");
163 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
164 Integration::BitmapResourceType bitmapRequest;
165 Internal::ResourceId id(0);
167 testTicketObserver.Reset();
170 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
171 /************************************************************
172 * FUNCTION UNDER TEST
173 ***********************************************************/
174 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
175 ticket->AddObserver(testTicketObserver);
177 // Update thread will request the bitmap resource:
178 // Sets application.GetPlatform().mRequest
179 application.SendNotification(); // Run flush update queue
180 application.Render(1); // Process update messages
181 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
183 application.SendNotification(); // Send any event messages
184 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
185 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
186 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
188 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
189 DALI_TEST_CHECK( imageTicket );
190 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
191 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
194 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
195 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
196 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
197 Integration::ResourcePointer resourcePtr(bitmap); // reference it
199 // Set up platform abstraction to load it
201 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
203 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
205 // load the cache, which will immediately have the loaded resource
206 application.Render(0);
208 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
210 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
211 Internal::TextureMetadata* bitmapData = NULL;
212 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
213 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
214 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
216 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
217 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
219 // Trigger the event thread to process notify messages. Should then trigger the signals
220 // in the ticket observer
221 application.SendNotification();
223 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
224 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
226 // Check that the image ticket was updated with the image attributes
227 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
228 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
231 application.SendNotification(); // Flush update queue (with ticket discarded message
232 application.Render(1); // Process update messages
233 application.SendNotification(); // Send event notifications
234 application.Render(1); // Process update messages
236 // Resource should have been discarded.
237 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
238 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
240 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
241 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
245 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
246 int UtcDaliInternalRequestResourceBitmapRequests02(void)
248 TestApplication application; // Reset all test adapter return codes
250 tet_infoline("Testing bitmap request ticket discard before load complete");
252 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
253 Integration::BitmapResourceType bitmapRequest;
254 Internal::ResourceId id(0);
256 testTicketObserver.Reset();
259 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
260 /************************************************************
261 * FUNCTION UNDER TEST
262 ***********************************************************/
263 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
264 ticket->AddObserver(testTicketObserver);
265 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
266 DALI_TEST_CHECK( imageTicket );
267 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
268 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
270 // Update thread will request the bitmap resource:
271 // Sets application.GetPlatform().mRequest
272 application.SendNotification(); // Run flush update queue
273 application.Render(1);
274 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
275 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
278 application.SendNotification(); // Should produce no messages
279 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
280 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
282 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
284 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
285 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
286 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
290 // Ensure ticket discarded message is sent to update thread
291 application.SendNotification(); // Flush update queue
292 application.Render(0); // Process update messages
294 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
295 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
297 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
299 // Trigger the event thread to process notify messages. Should then trigger the signals
300 // in the ticket observer
301 application.SendNotification();
303 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
304 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
308 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
309 int UtcDaliInternalRequestResourceBitmapRequests03(void)
311 TestApplication application; // Reset all test adapter return codes
313 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
315 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
316 Integration::BitmapResourceType bitmapRequest;
317 Internal::ResourceId id(0);
319 testTicketObserver.Reset();
320 { // Scope lifetime of ticket
321 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
323 /************************************************************
324 * FUNCTION UNDER TEST
325 ***********************************************************/
326 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
327 ticket->AddObserver(testTicketObserver);
328 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
329 DALI_TEST_CHECK( imageTicket );
330 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
331 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
333 // Update thread will request the bitmap resource:
334 // Sets application.GetPlatform().mRequest
335 application.SendNotification(); // Run flush update queue
336 application.Render(1); // process update messages
337 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
338 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
340 application.SendNotification(); // Should produce no messages
341 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
342 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
344 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
346 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
348 application.Render(0); // Get failed result
349 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
350 application.SendNotification(); // send failed
351 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
352 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
354 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
355 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
356 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
358 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
361 application.Render(0); // Send DiscardTicket
362 application.SendNotification();
364 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
370 // Load a bitmap resource successfully, then reload it
371 int UtcDaliInternalRequestReloadBitmapRequests01(void)
373 TestApplication application; // Reset all test adapter return codes
375 tet_infoline("Testing bitmap reload after successful load");
377 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
378 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
380 Internal::ResourceId id(0);
381 testTicketObserver.Reset();
384 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
385 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
386 id = ticket->GetId();
388 // Reset call statistics - test that resource is reloaded
389 application.GetPlatform().ResetTrace();
391 /************************************************************
392 * FUNCTION UNDER TEST
393 ***********************************************************/
394 resourceClient.ReloadResource( ticket->GetId() );
396 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
397 application.SendNotification(); // Flush update messages
398 application.Render(0); // Process update messages
399 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
400 application.SendNotification(); // Process event messages
402 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
403 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
404 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
405 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
407 // Create a new resource - the image size could have changed in the meantime
408 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
409 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
410 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
411 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
412 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
413 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
415 application.Render(0 , TEST_LOCATION ); // Process update messages / UpdateCache
416 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
418 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
419 Internal::TextureMetadata* bitmapData = NULL;
420 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
421 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
422 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
424 // Ticket can't have been updated yet - it should still have old values
425 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
426 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
428 application.SendNotification(); // Process event messages
429 application.Render(0, TEST_LOCATION ); // Process update messages / UpdateCache
430 application.SendNotification(); // Process event messages
432 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
433 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 1, TEST_LOCATION );
434 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
435 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
436 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
440 application.SendNotification(); // Flush update queue (with ticket discarded message
441 application.Render(1, TEST_LOCATION ); // Process update messages
442 application.SendNotification(); // Send event notifications
444 // Resource should have been discarded.
445 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
446 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
448 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
449 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
450 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 1, TEST_LOCATION );
455 int UtcDaliInternalRequestReloadBitmapRequests02(void)
457 TestApplication application; // Reset all test adapter return codes
459 tet_infoline("Testing bitmap reload during first load");
461 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
462 Integration::BitmapResourceType bitmapRequest;
463 Internal::ResourceId id(0);
465 testTicketObserver.Reset();
468 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
469 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
470 ticket->AddObserver(testTicketObserver);
472 // Update thread will request the bitmap resource:
473 // Sets application.GetPlatform().mRequest
474 application.SendNotification(); // Run flush update queue
475 application.Render(1); // Process update messages
476 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
478 application.SendNotification(); // Send any event messages
479 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
480 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
482 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
483 DALI_TEST_CHECK( imageTicket );
484 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
485 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
488 /************************************************************
489 * FUNCTION UNDER TEST
490 ***********************************************************/
491 resourceClient.ReloadResource( ticket->GetId() );
492 /************************************************************
493 * Expected result - current load completes as usual, no reload requested
494 ************************************************************/
496 application.SendNotification(); // Flush update methods
498 // Reset call statistics - test that resource is not reloaded
499 application.GetPlatform().ResetTrace();
501 application.Render(0); // Process reload message (nothing for UpdateCache yet)
503 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
504 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
506 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
507 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
508 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
509 Integration::ResourcePointer resourcePtr(bitmap); // reference it
511 // Set up platform abstraction to load it
514 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
516 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
518 application.GetPlatform().ResetTrace();
519 // load the cache, which will immediately have the loaded resource
520 application.Render(0);
521 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
522 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
523 Internal::TextureMetadata* bitmapData = NULL;
524 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
525 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
526 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
528 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
529 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
531 // Trigger the event thread to process notify messages. Should then trigger the signals
532 // in the ticket observer
533 application.SendNotification();
535 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
536 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
537 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
539 // Check that the image ticket was updated with the image attributes
540 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
541 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
543 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
545 application.SendNotification(); // Flush update messages
546 application.Render(0); // Process update messages
548 // There should be no reload
549 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
550 application.SendNotification(); // Process event messages
552 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
553 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
554 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
555 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
557 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
558 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
559 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
560 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
561 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
562 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
569 int UtcDaliInternalRequestReloadBitmapRequests03(void)
571 TestApplication application; // Reset all test adapter return codes
573 tet_infoline("Testing bitmap reload at end of first load");
575 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
576 Integration::BitmapResourceType bitmapRequest;
577 Internal::ResourceId id(0);
579 testTicketObserver.Reset();
582 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
583 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
584 ticket->AddObserver(testTicketObserver);
586 // Update thread will request the bitmap resource:
587 // Sets application.GetPlatform().mRequest
588 application.SendNotification(); // Run flush update queue
589 application.Render(1); // Process update messages
590 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
592 application.SendNotification(); // Send any event messages
593 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
594 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
596 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
597 DALI_TEST_CHECK( imageTicket );
598 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
599 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
602 /************************************************************
603 * FUNCTION UNDER TEST
604 ***********************************************************/
605 resourceClient.ReloadResource( ticket->GetId() );
606 /************************************************************
607 * Expected result - current load completes as usual, no reload requested
608 ************************************************************/
610 application.SendNotification(); // Flush update methods
612 // Reset call statistics - test that resource is not reloaded
613 application.GetPlatform().ResetTrace();
616 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
617 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
618 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
619 Integration::ResourcePointer resourcePtr(bitmap); // reference it
621 // Set up platform abstraction to load it
624 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
626 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
628 application.GetPlatform().ResetTrace();
629 // load the cache, which will immediately have the loaded resource
630 application.Render(0);
632 // UpdateCache runs before ProcessMessages, so the loading resource completes before
633 // the reload request is handled.
634 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
635 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
637 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
638 Internal::TextureMetadata* bitmapData = NULL;
639 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
640 DALI_TEST_CHECK( bitmapData->GetWidth() == 80 );
641 DALI_TEST_CHECK( bitmapData->GetHeight() == 80 );
643 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
644 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
646 // Trigger the event thread to process notify messages. Should then trigger the signals
647 // in the ticket observer
648 application.SendNotification();
650 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
651 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
652 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
654 // Check that the image ticket was updated with the image attributes
655 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
656 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
658 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
660 // Create a new resource - the image size could have changed in the meantime
661 req = application.GetPlatform().GetRequest();
662 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
663 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
664 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
665 DALI_TEST_CHECK( req->GetId() == id );
666 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
668 application.Render(0); // Process update messages / UpdateCache
670 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
671 DALI_TEST_CHECK( resourceManager.GetTextureMetadata(req->GetId(), bitmapData ) );
672 DALI_TEST_CHECK( bitmapData->GetWidth() == 120 );
673 DALI_TEST_CHECK( bitmapData->GetHeight() == 120 );
674 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
675 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
677 application.SendNotification(); // Process event messages
679 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
681 // Not staged - no GL upload
682 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
684 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
685 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
686 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
687 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
692 int UtcDaliInternalRequestResourceTicket01(void)
694 TestApplication application;
695 tet_infoline("Testing RequestResourceTicket() with valid id");
697 testTicketObserver.Reset();
699 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
701 // First, load a bitmap resource
702 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
704 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
705 DALI_TEST_CHECK( newTicket );
706 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
707 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
711 int UtcDaliInternalRequestResourceTicket02(void)
713 TestApplication application;
714 tet_infoline("Testing RequestResourceTicket() with invalid id");
716 testTicketObserver.Reset();
718 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
720 // First, load a bitmap resource
721 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
723 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
724 DALI_TEST_CHECK( ! newTicket );
728 int UtcDaliInternalAddBitmapImage01(void)
730 TestApplication application;
731 tet_infoline("Testing AddBitmap with reserved buffer()");
732 testTicketObserver.Reset();
733 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
734 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
735 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
737 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
738 DALI_TEST_CHECK( imageTicket );
739 imageTicket->AddObserver( testTicketObserver );
741 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
742 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
743 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
745 application.SendNotification(); // Flush update queue
746 application.Render(0); // Process message
747 application.SendNotification(); // Send message to tickets
749 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
750 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
751 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
752 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
756 int UtcDaliInternalAddBitmapImage02(void)
758 TestApplication application;
759 tet_infoline("Testing AddBitmap without reserved buffer()");
760 testTicketObserver.Reset();
761 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
762 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
764 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
765 DALI_TEST_CHECK( imageTicket );
766 imageTicket->AddObserver( testTicketObserver );
768 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
769 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
770 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
771 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
773 application.SendNotification(); // Flush update queue
774 application.Render(0); // Process message
775 application.SendNotification(); // Send message to tickets
777 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
778 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
779 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
780 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
785 int UtcDaliInternalAddBitmapImage03(void)
787 TestApplication application;
788 tet_infoline("Testing AddBitmap() with invalid bitmap");
789 testTicketObserver.Reset();
791 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
792 Internal::ImageTicketPtr imageTicket;
793 bool exceptionRaised=false;
796 imageTicket = resourceClient.AddBitmapImage( NULL );
798 catch( DaliException& e )
800 exceptionRaised = true;
802 DALI_TEST_CHECK( exceptionRaised );
803 DALI_TEST_CHECK( ! imageTicket );
807 int UtcDaliInternalAllocateTexture01(void)
809 TestApplication application;
810 tet_infoline("Testing AllocateTexture()");
811 testTicketObserver.Reset();
813 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
814 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
815 resourceTicket->AddObserver( testTicketObserver );
817 DALI_TEST_CHECK( resourceTicket );
818 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
819 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
821 application.SendNotification(); // Flush update queue
822 application.Render(0); // Process message
823 application.SendNotification(); // Send message to tickets
825 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
826 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
830 int UtcDaliInternalAddNativeImage(void)
832 TestApplication application;
833 tet_infoline("Testing AddNativeImage()");
835 testTicketObserver.Reset();
836 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
837 Internal::ResourceTicketPtr ticket;
838 Internal::ImageTicketPtr imageTicket;
839 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
840 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
841 ticket = resourceClient.AddNativeImage( *nativeImage );
842 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
843 DALI_TEST_CHECK( imageTicket );
844 imageTicket->AddObserver( testTicketObserver );
847 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
848 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
849 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
850 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
852 application.SendNotification(); // Flush update queue
853 application.Render(0); // Process message
854 application.SendNotification(); // Send message to tickets
856 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
857 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
858 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
859 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
863 int UtcDaliInternalAddFrameBufferImage(void)
865 TestApplication application;
866 tet_infoline("Testing AddFrameBufferImage()");
868 testTicketObserver.Reset();
869 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
870 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8, RenderBuffer::COLOR );
871 DALI_TEST_CHECK( imageTicket );
872 imageTicket->AddObserver( testTicketObserver );
874 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
875 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
876 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
877 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
879 application.SendNotification(); // Flush update queue
880 application.Render(0); // Process message
881 application.SendNotification(); // Send message to tickets
883 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
884 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
885 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
886 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent