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>
27 void utc_dali_image_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_image_cleanup(void)
34 test_return_value = TET_PASS;
37 static const char* gTestImageFilename = "icon_wrt.png";
41 int UtcDaliImageNew01(void)
43 TestApplication application;
45 tet_infoline("UtcDaliImageNew01 - Image::New(const std::string&)");
47 // invoke default handle constructor
50 DALI_TEST_CHECK( !image );
53 image = ResourceImage::New(gTestImageFilename);
55 DALI_TEST_CHECK( image );
60 int UtcDaliImageNew02(void)
62 TestApplication application;
64 tet_infoline("UtcDaliImageNew02 - Image::New(const std::string&, const ImageAttributes&)");
66 // invoke default handle constructor
69 DALI_TEST_CHECK( !image );
72 Dali::ImageAttributes imageAttributes;
73 imageAttributes.SetSize(128, 256);
74 imageAttributes.SetScalingMode(Dali::ImageAttributes::FitHeight);
75 image = ResourceImage::New(gTestImageFilename, imageAttributes);
77 DALI_TEST_CHECK( image );
82 int UtcDaliImageNew03(void)
84 TestApplication application;
86 tet_infoline("UtcDaliImageNew03 - Image::New(NativeImage&)");
88 // invoke default handle constructor
90 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
92 DALI_TEST_CHECK( !image );
95 image = Image::New(*(nativeImage.Get()));
97 DALI_TEST_CHECK( image );
102 int UtcDaliImageNewWithPolicies01(void)
104 TestApplication application;
106 // testing delayed loading
107 tet_infoline("UtcDaliImageNewWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
108 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
109 Image image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::NEVER);
111 DALI_TEST_CHECK( image );
113 application.SendNotification();
114 application.Render(16);
116 // request file loading only when actor added to stage
117 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
119 ImageActor actor = ImageActor::New(image);
121 Stage::GetCurrent().Add(actor);
123 application.SendNotification();
124 application.Render(16);
126 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
128 // testing ReleasePolicy::Never
129 // fake loading image
130 std::vector<GLuint> ids;
132 application.GetGlAbstraction().SetNextTextureIds( ids );
133 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
134 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
135 Integration::ResourcePointer resource(bitmap);
136 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
140 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
142 application.Render(16);
143 application.SendNotification();
145 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
147 // never discard texture
148 Stage::GetCurrent().Remove(actor);
149 application.Render(16);
150 application.SendNotification();
151 application.Render(16);
152 application.SendNotification();
153 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
158 int UtcDaliImageNewWithPolicies02(void)
160 TestApplication application;
161 const Vector2 closestImageSize( 80, 45);
162 application.GetPlatform().SetClosestImageSize(closestImageSize);
164 // testing resource deletion when taken off stage
165 tet_infoline("UtcDaliImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
167 Image image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::UNUSED);
169 DALI_TEST_CHECK( image );
171 application.SendNotification();
172 application.Render(16);
174 // request file loading only when actor added to stage
175 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
177 ImageActor actor = ImageActor::New(image);
179 Stage::GetCurrent().Add(actor);
181 application.SendNotification();
182 application.Render(16);
184 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
186 // testing ReleasePolicy::Unused
187 // fake loading image
188 std::vector<GLuint> ids;
190 application.GetGlAbstraction().SetNextTextureIds( ids );
191 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
192 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
193 Integration::ResourcePointer resource(bitmap);
194 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
198 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
200 application.Render(16);
201 application.SendNotification();
203 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
205 // discard texture when actor comes off stage
206 Stage::GetCurrent().Remove(actor);
207 application.Render(16);
208 application.SendNotification();
209 application.Render(16);
210 application.SendNotification();
211 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
216 int UtcDaliImageNewWithPolicies03(void)
218 TestApplication application;
219 const Vector2 closestImageSize( 80, 45);
220 application.GetPlatform().SetClosestImageSize(closestImageSize);
222 // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
223 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
225 Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED);
227 DALI_TEST_CHECK( image );
229 application.SendNotification();
230 application.Render(16);
232 // request file loading immediately
233 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
235 ImageActor actor = ImageActor::New(image);
237 Stage::GetCurrent().Add(actor);
239 application.SendNotification();
240 application.Render(16);
242 // testing ReleasePolicy::Unused
243 // fake loading image
244 std::vector<GLuint> ids;
246 application.GetGlAbstraction().SetNextTextureIds( ids );
247 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
248 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
249 Integration::ResourcePointer resource(bitmap);
250 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
254 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
256 application.Render(16);
257 application.SendNotification();
259 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
261 // discard texture when actor comes off stage
262 Stage::GetCurrent().Remove(actor);
263 application.Render(16);
264 application.SendNotification();
265 application.Render(16);
266 application.SendNotification();
267 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
269 // check load request when actor added back to stage
270 application.GetPlatform().ResetTrace();
272 Stage::GetCurrent().Add(actor);
274 application.SendNotification();
275 application.Render(16);
276 application.SendNotification();
277 application.Render(16);
279 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
284 int UtcDaliImageNewWithPolicies04(void)
286 TestApplication application;
288 // load immediately, don't release texture when off stage
289 tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
291 Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::NEVER);
293 DALI_TEST_CHECK( image );
295 application.SendNotification();
296 application.Render(16);
298 // request file loading immediately
299 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
301 ImageActor actor = ImageActor::New(image);
303 Stage::GetCurrent().Add(actor);
305 application.SendNotification();
306 application.Render(16);
308 // testing ReleasePolicy::Never
309 // fake loading image
310 std::vector<GLuint> ids;
312 application.GetGlAbstraction().SetNextTextureIds( ids );
313 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
314 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
315 Integration::ResourcePointer resource(bitmap);
316 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
320 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
322 application.Render(16);
323 application.SendNotification();
325 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
327 // texture is not discarded
328 Stage::GetCurrent().Remove(actor);
329 application.Render(16);
330 application.SendNotification();
331 application.Render(16);
332 application.SendNotification();
333 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
335 // no load request when actor added back to stage
336 application.GetPlatform().ResetTrace();
338 Stage::GetCurrent().Add(actor);
340 application.SendNotification();
341 application.Render(16);
342 application.SendNotification();
343 application.Render(16);
345 DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
350 int UtcDaliImageDownCast(void)
352 TestApplication application;
353 tet_infoline("Testing Dali::Image::DownCast()");
355 Image image = ResourceImage::New(gTestImageFilename);
357 BaseHandle object(image);
359 Image image2 = Image::DownCast(object);
360 DALI_TEST_CHECK(image2);
362 Image image3 = DownCast< Image >(object);
363 DALI_TEST_CHECK(image3);
365 BaseHandle unInitializedObject;
366 Image image4 = Image::DownCast(unInitializedObject);
367 DALI_TEST_CHECK(!image4);
369 Image image5 = DownCast< Image >(unInitializedObject);
370 DALI_TEST_CHECK(!image5);
375 int UtcDaliImageGetImageSize(void)
377 TestApplication application;
378 TestPlatformAbstraction& platform = application.GetPlatform();
380 tet_infoline("UtcDaliImageGetImageSize - Image::GetImageSize()");
382 Vector2 testSize(8.0f, 16.0f);
383 platform.SetClosestImageSize(testSize);
385 Vector2 size = ResourceImage::GetImageSize(gTestImageFilename);
387 DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
388 DALI_TEST_EQUALS( size, testSize, TEST_LOCATION);
393 int UtcDaliImageGetUrl(void)
395 TestApplication application;
397 tet_infoline("UtcDaliImageGetFilename");
399 // invoke default handle constructor
402 DALI_TEST_CHECK( !image );
405 image = ResourceImage::New(gTestImageFilename);
407 DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION);
412 int UtcDaliImageGetLoadingState01(void)
414 TestApplication application;
415 tet_infoline("UtcDaliImageGetLoadingState01");
417 ResourceImage image = ResourceImage::New(gTestImageFilename);
418 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
419 application.SendNotification();
420 application.Render(16);
422 // simulate load success
423 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
424 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
425 Integration::ResourcePointer resource(bitmap);
426 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
430 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
432 application.Render(16);
433 application.SendNotification();
435 // Test state == ResourceLoadingSucceeded
436 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
441 int UtcDaliImageGetLoadingState02(void)
443 TestApplication application;
445 tet_infoline("UtcDaliImageGetLoadingState02");
447 // invoke default handle constructor
450 DALI_TEST_CHECK( !image );
453 image = ResourceImage::New(gTestImageFilename);
455 // Test state == ResourceLoading
456 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
457 application.SendNotification();
458 application.Render(16);
460 // simulate load failure
461 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
464 application.GetPlatform().SetResourceLoadFailed(request->GetId(), Integration::FailureUnknown);
466 application.Render(16);
467 application.SendNotification();
469 // Test state == ResourceLoadingFailed
470 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
475 int UtcDaliImageGetReleasePolicy(void)
477 TestApplication application;
479 tet_infoline("UtcDaliImageGetReleasePolicy");
481 Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED);
483 DALI_TEST_CHECK( image );
485 DALI_TEST_CHECK( Image::UNUSED == image.GetReleasePolicy() );
491 int UtcDaliImageGetLoadPolicy(void)
493 TestApplication application;
495 tet_infoline("UtcDaliImageGetLoadPolicy");
497 ResourceImage image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::NEVER);
499 DALI_TEST_CHECK( image );
501 DALI_TEST_CHECK( ResourceImage::ON_DEMAND == image.GetLoadPolicy());
505 static bool SignalLoadFlag = false;
507 static void SignalLoadHandler(ResourceImage image)
509 tet_infoline("Received image load finished signal");
511 SignalLoadFlag = true;
514 static bool SignalUploadedFlag = false;
516 static void SignalUploadedHandler(Image image)
518 tet_infoline("Received image uploaded signal");
520 SignalUploadedFlag = true;
524 int UtcDaliImageSignalLoadingFinished(void)
526 TestApplication application;
528 tet_infoline("UtcDaliImageSignalLoadingFinished");
530 SignalLoadFlag = false;
532 ResourceImage image = ResourceImage::New(gTestImageFilename);
534 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
535 application.SendNotification();
536 application.Render(16);
538 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
541 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD)));
544 application.Render(16);
545 application.SendNotification();
547 DALI_TEST_CHECK( SignalLoadFlag == true );
552 int UtcDaliImageSignalUploaded(void)
554 TestApplication application;
555 tet_infoline("UtcDaliImageSignalUploaded - Image::SignalUploaded()");
557 // set up image in fake platform abstraction
558 Vector2 testSize(80.0f, 80.0f);
559 application.GetPlatform().SetClosestImageSize(testSize);
561 ResourceImage image = ResourceImage::New(gTestImageFilename);
562 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
565 application.SendNotification();
566 application.Render(16);
567 std::vector<GLuint> ids;
569 application.GetGlAbstraction().SetNextTextureIds( ids );
570 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
571 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
572 Integration::ResourcePointer resource(bitmap);
573 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
576 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
578 application.Render(16);
579 application.SendNotification();
581 image.UploadedSignal().Connect( SignalUploadedHandler );
583 Dali::ImageActor imageActor = ImageActor::New(image);
584 Stage::GetCurrent().Add(imageActor);
585 imageActor.SetSize(80, 80);
586 imageActor.SetVisible(true);
588 application.SendNotification();
589 application.Render(0);
590 application.Render(16);
591 application.SendNotification();
592 application.Render(16);
593 application.SendNotification();
594 application.Render(16);
595 application.SendNotification();
596 application.Render(16);
597 application.SendNotification();
599 DALI_TEST_CHECK( SignalLoadFlag == true );
600 DALI_TEST_CHECK( SignalUploadedFlag == true );
601 SignalLoadFlag = false;
602 SignalUploadedFlag = false;
605 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 160, 160, 160, 160);
607 application.SendNotification();
608 application.Render(16);
609 application.Render(16);
610 application.SendNotification();
611 DALI_TEST_CHECK( SignalLoadFlag == true );
613 application.Render(16);
614 application.SendNotification();
615 application.Render(16);
616 application.SendNotification();
617 DALI_TEST_CHECK( SignalUploadedFlag == true );
622 int UtcDaliImageDiscard01(void)
624 TestApplication application;
625 tet_infoline("UtcDaliImageDiscard01 - no actors");
628 Image image = ResourceImage::New(gTestImageFilename);
631 application.SendNotification();
632 application.Render(16);
633 std::vector<GLuint> ids;
635 application.GetGlAbstraction().SetNextTextureIds( ids );
636 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
637 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
638 Integration::ResourcePointer resource(bitmap);
639 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
642 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
644 application.Render(16);
645 application.SendNotification();
646 } // Drop image handle
648 application.SendNotification();
649 application.Render(16);
650 application.Render(16);
651 application.SendNotification();
653 // Shouldn't have been sent to GL...
654 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
655 DALI_TEST_CHECK( texIds.size() == 1 );
656 DALI_TEST_CHECK( texIds[0] == 23 );
661 int UtcDaliImageDiscard02(void)
663 TestApplication application;
664 application.GetGlAbstraction().EnableTextureCallTrace( true );
665 tet_infoline("UtcDaliImageDiscard02 - one actor, tests TextureCache::DiscardTexture");
671 ImageAttributes attrs;
672 const Vector2 requestedSize( 40, 30 );
673 attrs.SetSize( requestedSize.width, requestedSize.height );
674 Image image = ResourceImage::New(gTestImageFilename, attrs);
675 actor = ImageActor::New(image);
676 Stage::GetCurrent().Add(actor);
678 application.SendNotification();
679 application.Render(16);
681 std::vector<GLuint> ids;
683 application.GetGlAbstraction().SetNextTextureIds( ids );
685 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
686 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
687 Integration::ResourcePointer resource(bitmap);
688 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
691 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
693 application.Render(16);
694 application.SendNotification();
695 DALI_TEST_CHECK( application.GetGlAbstraction().GetTextureTrace().FindMethod("BindTexture") );
696 } // lose image handle, actor should still keep one
697 application.SendNotification();
698 application.Render(16);
700 Stage::GetCurrent().Remove(actor);
701 application.SendNotification();
702 application.Render(16);
704 application.SendNotification();
705 application.Render(16);
709 application.SendNotification();
710 application.Render(16);
711 application.Render(16);
712 application.SendNotification();
714 // texture should have been removed:
715 DALI_TEST_CHECK( application.GetGlAbstraction().CheckTextureDeleted( 23 ));
720 int UtcDaliImageDiscard03(void)
722 TestApplication application;
723 tet_infoline("UtcDaliImageDiscard03 - one actor, tests TextureCache::RemoveObserver");
725 const Vector2 closestImageSize( 1, 1);
726 application.GetPlatform().SetClosestImageSize(closestImageSize);
728 Image image = ResourceImage::New(gTestImageFilename);
729 ImageActor actor = ImageActor::New(image);
730 Stage::GetCurrent().Add(actor);
732 application.SendNotification();
733 application.Render(16);
735 std::vector<GLuint> ids;
737 application.GetGlAbstraction().SetNextTextureIds( ids );
739 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
740 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
742 Integration::ResourcePointer resource(bitmap);
743 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
746 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
748 application.Render(16);
749 application.SendNotification();
750 application.SendNotification();
751 application.Render(16);
753 const std::vector<GLuint>& texIds = application.GetGlAbstraction().GetNextTextureIds();
754 DALI_TEST_CHECK( texIds.size() == 0 );
755 const std::vector<GLuint>& boundTexIds = application.GetGlAbstraction().GetBoundTextures();
756 DALI_TEST_CHECK( boundTexIds[0] == 23 );
758 Stage::GetCurrent().Remove(actor);
759 application.SendNotification();
760 application.Render(16);
761 application.SendNotification();
762 application.Render(16);
763 application.SendNotification();
764 application.Render(16); // Should remove image renderer
772 void LoadBitmapResource(TestPlatformAbstraction& platform)
774 Integration::ResourceRequest* request = platform.GetRequest();
775 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
776 Integration::ResourcePointer resource(bitmap);
777 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
781 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
787 int UtcDaliImageContextLoss(void)
789 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
791 const Vector2 closestImageSize( 80, 80 );
792 TestPlatformAbstraction& platform = application.GetPlatform();
793 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
795 platform.SetClosestImageSize(closestImageSize);
797 tet_infoline("UtcDaliImageContextLoss - Load image with LoadPolicy::Immediate, ReleasePolicy::Never, bitmap discard. Check that the image is re-requested on context regain\n");
799 Image image = ResourceImage::New("image.png", ResourceImage::IMMEDIATE, Image::NEVER);
801 DALI_TEST_CHECK( image );
803 application.SendNotification();
804 application.Render(16);
806 // request file loading immediately
808 DALI_TEST_CHECK( platform.WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
809 ImageActor actor = ImageActor::New(image);
810 Stage::GetCurrent().Add(actor);
812 application.SendNotification();
813 application.Render(16);
815 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
816 textureTrace.Enable(true);
818 std::vector<GLuint> ids;
820 glAbstraction.SetNextTextureIds( ids );
822 LoadBitmapResource(platform);
824 application.Render(16);
825 application.SendNotification();
827 DALI_TEST_CHECK( textureTrace.FindMethod("GenTextures") );
829 textureTrace.Reset();
830 textureTrace.Enable(true);
831 platform.ResetTrace();
832 platform.EnableTrace(true);
834 // Lose & regain context (in render 'thread')
835 application.ResetContext();
837 application.GetCore().RecoverFromContextLoss(); // start the recovery process
838 application.SendNotification();
840 // Run update/render loop
841 application.Render(16);
842 application.SendNotification();
844 // Expect new load request
845 DALI_TEST_CHECK( platform.WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
847 // Finish loading image
848 LoadBitmapResource(platform);
851 glAbstraction.SetNextTextureIds(ids);
853 // Run update/render loop
854 application.Render(16);
855 application.SendNotification();
857 // Expect new GenTextures
858 DALI_TEST_CHECK( textureTrace.FindMethod("GenTextures") );