Dali 3D User Interface Engine
utc-Dali-RendererFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #include <iostream>
18 #include <stdlib.h>
24 
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27 
28 namespace
29 {
31 
32 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
33 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.jpg";
34 
35 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
36 {
38  Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
39  unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
40 
41  memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
42 
43  return bitmap;
44 }
45 
46 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
47 {
48  PixelBuffer* pixbuffer = image->GetBuffer();
49  unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
50 
51  for( unsigned int row = 0; row < imageWidth; ++row )
52  {
53  unsigned int pixelOffset = row * bytesPerPixel;
54  pixbuffer[ pixelOffset + 3 ] = 0x00;
55  pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
56  pixbuffer[ pixelOffset + 3 ] = 0x00;
57  }
58 
59  for ( unsigned int column = 0; column < imageHeight; ++column )
60  {
61  unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
62  pixbuffer[ pixelOffset + 3 ] = 0x00;
63  pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
64  pixbuffer[ pixelOffset + 3 ] = 0x00;
65  }
66 }
67 
68 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
69 {
70  PixelBuffer* pixbuffer = image->GetBuffer();
71  unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
72 
73  for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
74  {
75  const Uint16Pair& range = *it;
76  //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
77  for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
78  {
79  unsigned int pixelOffset = column * bytesPerPixel;
80  pixbuffer[ pixelOffset ] = 0x00;
81  pixbuffer[ pixelOffset + 1 ] = 0x00;
82  pixbuffer[ pixelOffset + 2 ] = 0x00;
83  pixbuffer[ pixelOffset + 3 ] = 0xFF;
84  }
85  }
86 
87 
88  for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
89  {
90  const Uint16Pair& range = *it;
91  //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
92  for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
93  {
94  unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
95  pixbuffer[ pixelOffset ] = 0x00;
96  pixbuffer[ pixelOffset + 1 ] = 0x00;
97  pixbuffer[ pixelOffset + 2 ] = 0x00;
98  pixbuffer[ pixelOffset + 3 ] = 0xFF;
99  }
100  }
101 }
102 
103 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
104 {
105  PixelBuffer* pixbuffer = image->GetBuffer();
106  unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
107 
109  unsigned int bufferStride = srcProfile->GetBufferStride();
110 
111  // Add bottom child region
112  for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
113  {
114  unsigned int pixelOffset = column * bytesPerPixel;
115  pixelOffset += ( imageHeight - 1 ) * bufferStride;
116  pixbuffer[ pixelOffset ] = 0x00;
117  pixbuffer[ pixelOffset + 1 ] = 0x00;
118  pixbuffer[ pixelOffset + 2 ] = 0x00;
119  pixbuffer[ pixelOffset + 3 ] = 0xFF;
120  }
121 
122  // Add right child region
123  for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
124  {
125  unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
126  pixbuffer[ pixelOffset ] = 0x00;
127  pixbuffer[ pixelOffset + 1 ] = 0x00;
128  pixbuffer[ pixelOffset + 2 ] = 0x00;
129  pixbuffer[ pixelOffset + 3 ] = 0xFF;
130  }
131 }
132 
134  unsigned int ninePatchImageWidth,
135  unsigned int ninePatchImageHeight,
136  const StretchRanges& stretchRangesX,
137  const StretchRanges& stretchRangesY,
138  bool addChildRegion = false,
139  Vector4 requiredChildRegion = Vector4::ZERO )
140 {
141  TestPlatformAbstraction& platform = application.GetPlatform();
142 
143  Pixel::Format pixelFormat = Pixel::RGBA8888;
144 
145  tet_infoline("Create Bitmap");
146  platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
147  Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
148 
149  tet_infoline("Clear border regions");
150  InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
151 
152  tet_infoline("Add Stretch regions to Bitmap");
153  AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
154 
155  if( addChildRegion )
156  {
157  tet_infoline("Add Child regions to Bitmap");
158  AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
159  }
160 
161  tet_infoline("Getting resource");
162  Integration::ResourcePointer resourcePtr(bitmap);
163  platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
164 
165  return resourcePtr;
166 }
167 
169  Actor& actor,
170  ControlRenderer& controlRenderer,
171  std::size_t expectedSamplers = 0,
172  ImageDimensions imageDimensions = ImageDimensions(),
174 {
175  if( resourcePtr )
176  {
177  // set the image size, for test case, this needs to be set before loading started
178  application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
179  }
180 
181  actor.SetSize( 200.f, 200.f );
182  Stage::GetCurrent().Add( actor );
183  controlRenderer.SetSize( Vector2(200.f, 200.f) );
184  controlRenderer.SetOnStage( actor );
185 
186  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
187  DALI_TEST_CHECK( actor.GetRendererAt(0u).GetMaterial().GetNumberOfTextures() == expectedSamplers );
188 
189  application.SendNotification();
190  application.Render();
191 
192  if( resourcePtr )
193  {
194  Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
195  if(request)
196  {
197  application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
198  }
199  }
200 
201  application.Render();
202  application.SendNotification();
203 
204  if( resourcePtr )
205  {
207  }
208 
209  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
210 
211 }
212 
213 } // namespace
214 
215 
217 {
219 }
220 
222 {
224 }
225 
227 {
228  ToolkitTestApplication application;
229  tet_infoline( "UtcDaliRendererFactory" );
230 
231  //Register type
232  TypeInfo type;
233  type = TypeRegistry::Get().GetTypeInfo( "RendererFactory" );
234  DALI_TEST_CHECK( type );
235  BaseHandle handle = type.CreateInstance();
236  DALI_TEST_CHECK( handle );
237 
238  RendererFactory factory;
239  factory = RendererFactory::Get();
240  DALI_TEST_CHECK( factory );
241 
242  RendererFactory newFactory = RendererFactory::Get();
243  DALI_TEST_CHECK( newFactory );
244 
245  // Check that renderer factory is a singleton
246  DALI_TEST_CHECK(factory == newFactory);
247 
248  END_TEST;
249 }
250 
252 {
253  ToolkitTestApplication application;
254  tet_infoline( "UtcDaliRendererFactoryCopyAndAssignment" );
256 
257  RendererFactory factoryCopy( factory );
258  DALI_TEST_CHECK(factory == factoryCopy);
259 
260  RendererFactory emptyFactory;
261  RendererFactory emptyFactoryCopy( emptyFactory );
262  DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
263 
264  RendererFactory factoryEquals;
265  factoryEquals = factory;
266  DALI_TEST_CHECK(factory == factoryEquals);
267 
268  RendererFactory emptyFactoryEquals;
269  emptyFactoryEquals = emptyFactory;
270  DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
271 
272  //self assignment
273  factory = factory;
274  DALI_TEST_CHECK( factory = factoryCopy );
275 
276  END_TEST;
277 }
278 
280 {
281  ToolkitTestApplication application;
282  tet_infoline( "UtcDaliRendererFactoryGetColorRenderer1: Request color renderer with a Property::Map" );
283 
285  DALI_TEST_CHECK( factory );
286 
287  Property::Map propertyMap;
288  Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
289  propertyMap.Insert("rendererType", "color");
290  propertyMap.Insert("blendColor", testColor);
291 
292  ControlRenderer controlRenderer = factory.GetControlRenderer(propertyMap);
293  DALI_TEST_CHECK( controlRenderer );
294 
295  Actor actor = Actor::New();
296  TestControlRendererRender( application, actor, controlRenderer );
297 
298  Vector4 actualValue(Vector4::ZERO);
299  TestGlAbstraction& gl = application.GetGlAbstraction();
300  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "blendColor", actualValue ) );
301  DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
302 
303  END_TEST;
304 }
305 
307 {
308  ToolkitTestApplication application;
309  tet_infoline( "UtcDaliRendererFactoryGetColorRenderer2: Request color renderer with a Vector4" );
310 
312  DALI_TEST_CHECK( factory );
313 
314  Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
315  ControlRenderer controlRenderer = factory.GetControlRenderer(testColor);
316  DALI_TEST_CHECK( controlRenderer );
317 
318  Actor actor = Actor::New();
319  TestControlRendererRender( application, actor, controlRenderer );
320 
321  Vector4 actualValue(Vector4::ZERO);
322  TestGlAbstraction& gl = application.GetGlAbstraction();
323  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "blendColor", actualValue ) );
324  DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
325 
326  controlRenderer.SetOffStage( actor );
327  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
328 
329  END_TEST;
330 }
331 
333 {
334  ToolkitTestApplication application;
335  tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer1: Request border renderer with a Property::Map" );
336 
338  DALI_TEST_CHECK( factory );
339 
340  Property::Map propertyMap;
341  Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
342  float testSize = 5.f;
343  propertyMap.Insert("rendererType", "border");
344  propertyMap.Insert("borderColor", testColor);
345  propertyMap.Insert("borderSize", testSize);
346 
347  ControlRenderer controlRenderer = factory.GetControlRenderer(propertyMap);
348  DALI_TEST_CHECK( controlRenderer );
349 
350  Actor actor = Actor::New();
351  actor.SetSize(200.f, 200.f);
352  Stage::GetCurrent().Add( actor );
353  controlRenderer.SetSize(Vector2(200.f, 200.f));
354  controlRenderer.SetOnStage( actor );
355 
356  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
357  int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLENDING_MODE );
358  DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
359 
360  TestGlAbstraction& gl = application.GetGlAbstraction();
361 
362  application.SendNotification();
363  application.Render(0);
364 
365  Vector4 actualColor(Vector4::ZERO);
366  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
367  DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
368 
369  float actualSize = 0.f;
370  DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
371  DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
372 
373  controlRenderer.SetOffStage( actor );
374  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
375 
376  END_TEST;
377 }
378 
380 {
381  ToolkitTestApplication application;
382  tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer2: Request border renderer with a borderSize and a borderColor" );
383 
385  DALI_TEST_CHECK( factory );
386 
387  Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
388  float testSize = 5.f;
389 
390  ControlRenderer controlRenderer = factory.GetControlRenderer(testSize, testColor );
391  DALI_TEST_CHECK( controlRenderer );
392 
393  Actor actor = Actor::New();
394  actor.SetSize(200.f, 200.f);
395  Stage::GetCurrent().Add( actor );
396  controlRenderer.SetSize(Vector2(200.f, 200.f));
397  controlRenderer.SetOnStage( actor );
398 
399  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
400 
401  TestGlAbstraction& gl = application.GetGlAbstraction();
402 
403  application.SendNotification();
404  application.Render(0);
405 
406  int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLENDING_MODE );
407  DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::AUTO, TEST_LOCATION );
408 
409  Vector4 actualColor(Vector4::ZERO);
410  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
411  DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
412 
413  float actualSize = 0.f;
414  DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
415  DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
416 
417  controlRenderer.SetOffStage( actor );
418 
419  // enable the anti-aliasing
420  controlRenderer = factory.GetControlRenderer(testSize, testColor, true );
421  controlRenderer.SetOnStage( actor );
422 
423  application.SendNotification();
424  application.Render(0);
425  blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLENDING_MODE );
426  DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
427 
428  END_TEST;
429 }
430 
432 {
433  ToolkitTestApplication application;
434  tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
435 
437  DALI_TEST_CHECK( factory );
438 
439  Property::Map propertyMap;
440  propertyMap.Insert("rendererType", "gradient");
441 
442  Vector2 start(-1.f, -1.f);
443  Vector2 end(1.f, 1.f);
444  propertyMap.Insert("gradientStartPosition", start);
445  propertyMap.Insert("gradientEndPosition", end);
446  propertyMap.Insert("gradientSpreadMethod", "repeat");
447 
448  Property::Array stopOffsets;
449  stopOffsets.PushBack( 0.2f );
450  stopOffsets.PushBack( 0.8f );
451  propertyMap.Insert("gradientStopOffset", stopOffsets);
452 
453  Property::Array stopColors;
454  stopColors.PushBack( Color::RED );
455  stopColors.PushBack( Color::GREEN );
456  propertyMap.Insert("gradientStopColor", stopColors);
457 
458  ControlRenderer controlRenderer = factory.GetControlRenderer(propertyMap);
459  DALI_TEST_CHECK( controlRenderer );
460 
461  // A lookup texture is generated and pass to shader as sampler
462  Actor actor = Actor::New();
463  TestControlRendererRender( application, actor, controlRenderer, 1u );
464 
465  controlRenderer.SetOffStage( actor );
466  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
467 
468  END_TEST;
469 }
470 
472 {
473  ToolkitTestApplication application;
474  tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
475 
477  DALI_TEST_CHECK( factory );
478 
479  Property::Map propertyMap;
480  propertyMap.Insert("rendererType", "gradient");
481 
482  Vector2 center(100.f, 100.f);
483  float radius = 100.f;
484  propertyMap.Insert("gradientUnits", "userSpace");
485  propertyMap.Insert("gradientCenter", center);
486  propertyMap.Insert("gradientRadius", radius);
487 
488  Property::Array stopOffsets;
489  stopOffsets.PushBack( 0.0f );
490  stopOffsets.PushBack( 1.f );
491  propertyMap.Insert("gradientStopOffset", stopOffsets);
492 
493  Property::Array stopColors;
494  stopColors.PushBack( Color::RED );
495  stopColors.PushBack( Color::GREEN );
496  propertyMap.Insert("gradientStopColor", stopColors);
497 
498  ControlRenderer controlRenderer = factory.GetControlRenderer(propertyMap);
499  DALI_TEST_CHECK( controlRenderer );
500 
501  // A lookup texture is generated and pass to shader as sampler
502  Actor actor = Actor::New();
503  TestControlRendererRender( application, actor, controlRenderer, 1u );
504 
505  Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
506  alignMatrix.Invert();
507 
508  Matrix3 actualValue( Matrix3::IDENTITY );
509  TestGlAbstraction& gl = application.GetGlAbstraction();
510  DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
511  DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
512 
513  END_TEST;
514 }
515 
517 {
518  ToolkitTestApplication application;
519  tet_infoline( "UtcDaliRendererFactoryGetImageRenderer1: Request image renderer with a Property::Map" );
520 
522  DALI_TEST_CHECK( factory );
523 
524  Property::Map propertyMap;
525  propertyMap.Insert( "rendererType", "image" );
526  propertyMap.Insert( "imageUrl", TEST_IMAGE_FILE_NAME );
527 
528  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
529  DALI_TEST_CHECK( controlRenderer );
530 
531  Actor actor = Actor::New();
532  // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
533  // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
534  TestControlRendererRender( application, actor, controlRenderer, 1u,
535  ImageDimensions(512, 513),
537 
538  TestGlAbstraction& gl = application.GetGlAbstraction();
539  int textureUnit = -1;
540  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
541  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
542 
543  controlRenderer.SetOffStage( actor );
544  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
545 
546  END_TEST;
547 }
548 
550 {
551  ToolkitTestApplication application;
552  tet_infoline( "UtcDaliRendererFactoryGetImageRenderer2: Request image renderer with an image handle" );
553 
555  DALI_TEST_CHECK( factory );
556 
557  Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
558  ControlRenderer controlRenderer = factory.GetControlRenderer( image );
559 
560  Actor actor = Actor::New();
561  // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
562  // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
563  TestControlRendererRender( application, actor, controlRenderer, 1u,
564  ImageDimensions(512, 513),
566 
567  TestGlAbstraction& gl = application.GetGlAbstraction();
568  int textureUnit = -1;
569  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
570  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
571 
572  END_TEST;
573 }
574 
576 {
577  ToolkitTestApplication application;
578  tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer1: Request 9-patch renderer with a Property::Map" );
579 
581  DALI_TEST_CHECK( factory );
582 
583  const unsigned int ninePatchImageHeight = 18;
584  const unsigned int ninePatchImageWidth = 28;
585  StretchRanges stretchRangesX;
586  stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
587  StretchRanges stretchRangesY;
588  stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
589  Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
590 
591  Property::Map propertyMap;
592  propertyMap.Insert( "rendererType", "nPatch" );
593  propertyMap.Insert( "imageUrl", TEST_NPATCH_FILE_NAME );
594  {
595  tet_infoline( "whole grid" );
596  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
597  DALI_TEST_CHECK( controlRenderer );
598 
599  Actor actor = Actor::New();
600  TestControlRendererRender( application, actor, controlRenderer, 1u,
601  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
602  ninePatchResource );
603 
604  TestGlAbstraction& gl = application.GetGlAbstraction();
605  int textureUnit = -1;
606  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
607  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
608  }
609 
610  propertyMap.Insert( "borderOnly", true );
611  {
612  tet_infoline( "border only" );
613  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
614  DALI_TEST_CHECK( controlRenderer );
615 
616  Actor actor = Actor::New();
617  TestControlRendererRender( application, actor, controlRenderer, 1u,
618  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
619  ninePatchResource );
620 
621  TestGlAbstraction& gl = application.GetGlAbstraction();
622  int textureUnit = -1;
623  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
624  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
625  }
626 
627  END_TEST;
628 }
629 
631 {
632  ToolkitTestApplication application;
633  tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer2: Request n-patch renderer with a Property::Map" );
634 
636  DALI_TEST_CHECK( factory );
637 
638  const unsigned int ninePatchImageWidth = 18;
639  const unsigned int ninePatchImageHeight = 28;
640  StretchRanges stretchRangesX;
641  stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
642  stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
643  stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
644  StretchRanges stretchRangesY;
645  stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
646  stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
647  stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
648  stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
649  Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
650 
651  Property::Map propertyMap;
652  propertyMap.Insert( "rendererType", "nPatch" );
653  propertyMap.Insert( "imageUrl", TEST_NPATCH_FILE_NAME );
654  {
655  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
656  DALI_TEST_CHECK( controlRenderer );
657 
658  Actor actor = Actor::New();
659  TestControlRendererRender( application, actor, controlRenderer, 1u,
660  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
661  ninePatchResource );
662 
663  TestGlAbstraction& gl = application.GetGlAbstraction();
664  int textureUnit = -1;
665  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
666  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
667 
668  controlRenderer.SetOffStage( actor );
669  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
670  }
671 
672  propertyMap.Insert( "borderOnly", true );
673  {
674  tet_infoline( "border only" );
675  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
676  DALI_TEST_CHECK( controlRenderer );
677 
678  Actor actor = Actor::New();
679  TestControlRendererRender( application, actor, controlRenderer, 1u,
680  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
681  ninePatchResource );
682 
683  TestGlAbstraction& gl = application.GetGlAbstraction();
684  int textureUnit = -1;
685  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
686  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
687 
688  controlRenderer.SetOffStage( actor );
689  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
690  }
691 
692  END_TEST;
693 }
694 
696 {
697  ToolkitTestApplication application;
698  tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer3: Request 9-patch renderer with an image url" );
699 
701  DALI_TEST_CHECK( factory );
702 
703  const unsigned int ninePatchImageHeight = 18;
704  const unsigned int ninePatchImageWidth = 28;
705  StretchRanges stretchRangesX;
706  stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
707  StretchRanges stretchRangesY;
708  stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
709  Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
710 
711  ControlRenderer controlRenderer = factory.GetControlRenderer( TEST_NPATCH_FILE_NAME );
712  DALI_TEST_CHECK( controlRenderer );
713 
714  Actor actor = Actor::New();
715  TestControlRendererRender( application, actor, controlRenderer, 1u,
716  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
717  ninePatchResource );
718 
719  TestGlAbstraction& gl = application.GetGlAbstraction();
720  int textureUnit = -1;
721  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
722  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
723 
724  END_TEST;
725 }
726 
728 {
729  ToolkitTestApplication application;
730  tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer4: Request n-patch renderer with an image url" );
731 
733  DALI_TEST_CHECK( factory );
734 
735  const unsigned int ninePatchImageHeight = 18;
736  const unsigned int ninePatchImageWidth = 28;
737  StretchRanges stretchRangesX;
738  stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
739  stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
740  stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
741  StretchRanges stretchRangesY;
742  stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
743  stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
744  stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
745  stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
746  Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
747 
748  ControlRenderer controlRenderer = factory.GetControlRenderer( TEST_NPATCH_FILE_NAME );
749  DALI_TEST_CHECK( controlRenderer );
750 
751  Actor actor = Actor::New();
752  TestControlRendererRender( application, actor, controlRenderer, 1u,
753  ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
754  ninePatchResource );
755 
756  TestGlAbstraction& gl = application.GetGlAbstraction();
757  int textureUnit = -1;
758  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
759  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
760 
761  END_TEST;
762 }
763 
765 {
766  //This should still load but display an error image
767 
768  ToolkitTestApplication application;
769  tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid image url" );
770 
772  DALI_TEST_CHECK( factory );
773 
774  ControlRenderer controlRenderer = factory.GetControlRenderer( "ERROR.9.jpg" );
775  DALI_TEST_CHECK( controlRenderer );
776 
777  Actor actor = Actor::New();
778  //The testkit still has to load a bitmap for the broken renderer image
779  TestControlRendererRender( application, actor, controlRenderer, 1u,
780  ImageDimensions(),
782 
783  TestGlAbstraction& gl = application.GetGlAbstraction();
784  int textureUnit = -1;
785  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
786  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
787 
788  END_TEST;
789 }
790 
792 {
793  //This should still load but display an error image
794 
795  ToolkitTestApplication application;
796  tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid Property::Map" );
797 
799  DALI_TEST_CHECK( factory );
800 
801  Property::Map propertyMap;
802  propertyMap.Insert( "rendererType", "nPatch" );
803  propertyMap.Insert( "imageUrl", 111 );
804 
805  ControlRenderer controlRenderer = factory.GetControlRenderer( propertyMap );
806  DALI_TEST_CHECK( controlRenderer );
807 
808  Actor actor = Actor::New();
809  //The testkit still has to load a bitmap for the broken renderer image
810  TestControlRendererRender( application, actor, controlRenderer, 1u,
811  ImageDimensions(),
813 
814  TestGlAbstraction& gl = application.GetGlAbstraction();
815  int textureUnit = -1;
816  DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
817  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
818 
819  END_TEST;
820 }
821 
823 {
824  ToolkitTestApplication application;
825  tet_infoline( "UtcDaliRendererFactoryResetRenderer1" );
826 
828  DALI_TEST_CHECK( factory );
829 
830  ControlRenderer controlRenderer = factory.GetControlRenderer( Color::RED );
831  DALI_TEST_CHECK( controlRenderer );
832 
833  Actor actor = Actor::New();
834  TestControlRendererRender( application, actor, controlRenderer );
835 
836  Vector4 actualValue(Vector4::ZERO);
837  TestGlAbstraction& gl = application.GetGlAbstraction();
838  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "blendColor", actualValue ) );
839  DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
840 
841  factory.ResetRenderer( controlRenderer, actor, Color::GREEN );
842  application.SendNotification();
843  application.Render(0);
844  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "blendColor", actualValue ) );
846 
847  Image bufferImage = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
848  factory.ResetRenderer( controlRenderer, actor, bufferImage );
849 
850  Actor actor2 = Actor::New();
851  actor2.SetSize(200.f, 200.f);
852  Stage::GetCurrent().Add( actor2 );
853  controlRenderer.SetSize(Vector2(200.f, 200.f));
854  controlRenderer.SetOnStage( actor2 );
855  application.SendNotification();
856  application.Render(0);
857 
858  END_TEST;
859 }
860 
862 {
863  ToolkitTestApplication application;
864  tet_infoline( "UtcDaliRendererFactoryResetRenderer2" );
865 
866  Actor actor = Actor::New();
867  actor.SetSize(200.f, 200.f);
868  Stage::GetCurrent().Add( actor );
870  DALI_TEST_CHECK( factory );
871 
872  Image resourceImage = ResourceImage::New(TEST_IMAGE_FILE_NAME);
873  ControlRenderer controlRenderer = factory.GetControlRenderer( resourceImage );
874  DALI_TEST_CHECK( controlRenderer );
875  controlRenderer.SetSize(Vector2(200.f, 200.f));
876  controlRenderer.SetOnStage( actor );
877  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
878 
879  application.SendNotification();
880  application.Render(0);
881 
882  Image bufferImage = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
883  factory.ResetRenderer( controlRenderer, actor, bufferImage );
884  application.SendNotification();
885  application.Render(0);
886 
887  factory.ResetRenderer( controlRenderer, actor, Color::RED );
888 
889  Actor actor2 = Actor::New();
890  actor2.SetSize(200.f, 200.f);
891  Stage::GetCurrent().Add( actor2 );
892  controlRenderer.SetSize(Vector2(200.f, 200.f));
893  controlRenderer.SetOnStage( actor2 );
894  TestGlAbstraction& gl = application.GetGlAbstraction();
895  application.SendNotification();
896  application.Render(0);
897  Vector4 actualValue(Vector4::ZERO);
898  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "blendColor", actualValue ) );
899  DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
900 
901  END_TEST;
902 }
Dali Docs Home
Read more about Dali