Disable texture atlas in svg visual 98/159298/4
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 8 Nov 2017 05:30:02 +0000 (14:30 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 9 Nov 2017 02:59:38 +0000 (11:59 +0900)
Change-Id: Ia984806dedbad41ff5d26510a28898aa57fe7c38

automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.h

index e64a216..121d5f4 100644 (file)
@@ -826,6 +826,7 @@ int UtcDaliVisualGetPropertyMap7(void)
   propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::SVG );
   propertyMap.Insert( Visual::Property::MIX_COLOR, Color::WHITE );
   propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
+  propertyMap.Insert( ImageVisual::Property::ATLASING, false );
   Visual::Base svgVisual = factory.CreateVisual( propertyMap );
 
   Property::Map resultMap;
@@ -839,6 +840,33 @@ int UtcDaliVisualGetPropertyMap7(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
 
+  value = resultMap.Find( ImageVisual::Property::ATLASING, Property::BOOLEAN );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<bool>() == false );
+
+  // request SvgVisual with a property map 2
+  propertyMap.Clear();
+  propertyMap[ "visualType" ] = Visual::SVG;
+  propertyMap[ "mixColor" ] = Color::WHITE;
+  propertyMap[ "url" ] = TEST_SVG_FILE_NAME;
+  propertyMap[ "atlasing" ] = true;
+  Visual::Base svgVisual1 = factory.CreateVisual( propertyMap );
+
+  resultMap.Clear();
+  svgVisual1.CreatePropertyMap( resultMap );
+  // check the property values from the returned map from a visual
+  value = resultMap.Find( Toolkit::Visual::Property::TYPE,  Property::INTEGER );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<int>() == Visual::SVG );
+
+  value = resultMap.Find( ImageVisual::Property::URL,  Property::STRING );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<std::string>() == TEST_SVG_FILE_NAME );
+
+  value = resultMap.Find( ImageVisual::Property::ATLASING, Property::BOOLEAN );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<bool>() == true );
+
   // request SvgVisual with an URL
   Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
   resultMap.Clear();
index 91c25fd..950b3e1 100644 (file)
@@ -1023,6 +1023,52 @@ int UtcDaliVisualFactoryGetSvgVisualLarge(void)
   END_TEST;
 }
 
+int UtcDaliVisualFactoryGetSvgVisualAtlas(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with enabled atlas" );
+
+  VisualFactory factory = VisualFactory::Get();
+
+  Property::Map propertyMap;
+  propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::SVG );
+  propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
+  propertyMap.Insert( ImageVisual::Property::ATLASING, true );
+
+  Visual::Base visual = factory.CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+  TraceCallStack& textureTrace = gl.GetTextureTrace();
+  textureTrace.Enable(true);
+
+  DummyControl actor = DummyControl::New(true);
+  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+  actor.SetSize( 200.f, 200.f );
+  Stage::GetCurrent().Add( actor );
+  visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
+
+  application.SendNotification();
+  application.Render();
+
+  // renderer is not added to actor until the rasterization is completed.
+  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
+  DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+  // renderer is added to actor
+  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+
+  // waiting for the resource uploading
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
+
+  END_TEST;
+}
+
 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
 //This is expected to succeed, which will then pass the test.
 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
index 295aeb8..7ef4669 100644 (file)
@@ -508,8 +508,7 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v
 
     case Toolkit::ImageVisual::Property::ATLASING:
     {
-      bool atlasing = false;
-      mAttemptAtlasing = value.Get( atlasing );
+      value.Get( mAttemptAtlasing );
       break;
     }
 
index a9d0c0c..eef883c 100644 (file)
@@ -41,6 +41,9 @@ namespace
 {
 const char * const UNITS("px");
 
+// property name
+const char * const IMAGE_ATLASING( "atlasing" );
+
 const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 }
 
@@ -76,7 +79,8 @@ SvgVisual::SvgVisual( VisualFactoryCache& factoryCache )
   mImageUrl( ),
   mParsedImage( NULL ),
   mPlacementActor(),
-  mVisualSize(Vector2::ZERO)
+  mVisualSize(Vector2::ZERO),
+  mAttemptAtlasing( false )
 {
   // the rasterized image is with pre-multiplied alpha format
   mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
@@ -93,11 +97,35 @@ SvgVisual::~SvgVisual()
 void SvgVisual::DoSetProperties( const Property::Map& propertyMap )
 {
   // url already passed in from constructor
+  for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter )
+  {
+    KeyValuePair keyValue = propertyMap.GetKeyValue( iter );
+    if( keyValue.first.type == Property::Key::INDEX )
+    {
+      DoSetProperty( keyValue.first.indexKey, keyValue.second );
+    }
+    else if( keyValue.first == IMAGE_ATLASING )
+    {
+      DoSetProperty( Toolkit::ImageVisual::Property::ATLASING, keyValue.second );
+    }
+  }
+}
+
+void SvgVisual::DoSetProperty( Property::Index index, const Property::Value& value )
+{
+  switch( index )
+  {
+    case Toolkit::ImageVisual::Property::ATLASING:
+    {
+      value.Get( mAttemptAtlasing );
+      break;
+    }
+  }
 }
 
 void SvgVisual::DoSetOnStage( Actor& actor )
 {
-  Shader shader = ImageVisual::GetImageShader( mFactoryCache, true, true );
+  Shader shader = ImageVisual::GetImageShader( mFactoryCache, mAttemptAtlasing, true );
   Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
   TextureSet textureSet = TextureSet::New();
   mImpl->mRenderer = Renderer::New( geometry, shader );
@@ -144,6 +172,7 @@ void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const
   if( mImageUrl.IsValid() )
   {
     map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
+    map.Insert( Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing );
   }
 }
 
@@ -180,24 +209,30 @@ void SvgVisual::ApplyRasterizedImage( PixelData rasterizedPixelData )
   if( IsOnStage()  )
   {
     TextureSet currentTextureSet = mImpl->mRenderer.GetTextures();
-    if( mAtlasRect != FULL_TEXTURE_RECT )
+    if( mImpl->mFlags |= Impl::IS_ATLASING_APPLIED )
     {
       mFactoryCache.GetAtlasManager()->Remove( currentTextureSet, mAtlasRect );
     }
 
-    Vector4 atlasRect;
-    TextureSet textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData );
-    if( textureSet ) // atlasing
+    TextureSet textureSet;
+
+    if( mAttemptAtlasing )
     {
-      if( textureSet != currentTextureSet )
+      Vector4 atlasRect;
+      textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData );
+      if( textureSet ) // atlasing
       {
-        mImpl->mRenderer.SetTextures( textureSet );
+        if( textureSet != currentTextureSet )
+        {
+          mImpl->mRenderer.SetTextures( textureSet );
+        }
+        mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
+        mAtlasRect = atlasRect;
+        mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
       }
-      mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
-      mAtlasRect = atlasRect;
-      mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
     }
-    else // no atlasing
+
+    if( !textureSet ) // no atlasing - mAttemptAtlasing is false or adding to atlas is failed
     {
       Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888,
                                       rasterizedPixelData.GetWidth(), rasterizedPixelData.GetHeight() );
index 0bce4b0..7852bfc 100644 (file)
@@ -155,6 +155,13 @@ private:
    */
   void AddRasterizationTask( const Vector2& size );
 
+  /**
+   * Helper method to set individual values by index key.
+   * @param[in] index The index key of the value
+   * @param[in] value The value
+   */
+  void DoSetProperty( Property::Index index, const Property::Value& value );
+
 
   // Undefined
   SvgVisual( const SvgVisual& svgRenderer );
@@ -168,6 +175,7 @@ private:
   NSVGimage*           mParsedImage;
   WeakHandle<Actor>    mPlacementActor;
   Vector2              mVisualSize;
+  bool                 mAttemptAtlasing;  ///< If true will attempt atlasing, otherwise create unique texture
 };
 
 } // namespace Internal