Add support for Texture url in ImageVisual 65/150465/4
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 15 Sep 2017 13:41:25 +0000 (14:41 +0100)
committerFrancisco Santos <f1.santos@samsung.com>
Wed, 27 Sep 2017 09:22:25 +0000 (10:22 +0100)
Change-Id: If06957574b0c27b068e8e8181b339149837eaa9b

dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h

index ee0042a..ab956e8 100644 (file)
@@ -258,7 +258,6 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
                           Dali::SamplingMode::Type samplingMode )
 : Visual::Base( factoryCache ),
   mImage(),
                           Dali::SamplingMode::Type samplingMode )
 : Visual::Base( factoryCache ),
   mImage(),
-  mPixels(),
   mPixelArea( FULL_TEXTURE_RECT ),
   mPlacementActor(),
   mImageUrl( imageUrl ),
   mPixelArea( FULL_TEXTURE_RECT ),
   mPlacementActor(),
   mImageUrl( imageUrl ),
@@ -277,7 +276,6 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
 ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image )
 : Visual::Base( factoryCache ),
   mImage( image ),
 ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image )
 : Visual::Base( factoryCache ),
   mImage( image ),
-  mPixels(),
   mPixelArea( FULL_TEXTURE_RECT ),
   mPlacementActor(),
   mImageUrl(),
   mPixelArea( FULL_TEXTURE_RECT ),
   mPlacementActor(),
   mImageUrl(),
@@ -361,14 +359,6 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap )
     }
   }
 
     }
   }
 
-  if( ( mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING ) && mImageUrl.IsValid() )
-  {
-    // if sync loading is required, the loading should start
-    // immediately when new image url is set or the actor is off stage
-    // ( for on-stage actor with image url unchanged, resource loading
-    // is already finished )
-    LoadResourceSynchronously();
-  }
 }
 
 void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& value )
 }
 
 void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& value )
@@ -685,30 +675,27 @@ bool ImageVisual::IsSynchronousResourceLoading() const
   return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
 }
 
   return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
 }
 
-void ImageVisual::LoadResourceSynchronously()
-{
-  if( mImageUrl.IsValid() )
-  {
-    Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode );
-
-    if( pixelBuffer )
-    {
-      mPixels = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
-    }
-    mTextureLoading = false;
-  }
-}
-
 TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing )
 {
   TextureSet textureSet;
 
   mTextureLoading = false;
 TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing )
 {
   TextureSet textureSet;
 
   mTextureLoading = false;
-
   textureRect = FULL_TEXTURE_RECT;
   textureRect = FULL_TEXTURE_RECT;
+
   if( synchronousLoading )
   {
   if( synchronousLoading )
   {
-    if( !mPixels )
+    PixelData data;
+    if( mImageUrl.IsValid() )
+    {
+      // if sync loading is required, the loading should immediately when actor is on stage
+      Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode );
+
+      if( pixelBuffer )
+      {
+        data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
+      }
+    }
+    if( !data )
     {
       // use broken image
       textureSet = TextureSet::New();
     {
       // use broken image
       textureSet = TextureSet::New();
@@ -718,15 +705,15 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronous
     {
       if( attemptAtlasing )
       {
     {
       if( attemptAtlasing )
       {
-        textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, mPixels );
+        textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, data );
         mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
       }
       if( !textureSet ) // big image, no atlasing or atlasing failed
       {
         mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
         mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
       }
       if( !textureSet ) // big image, no atlasing or atlasing failed
       {
         mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
-        Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, mPixels.GetPixelFormat(),
-                                        mPixels.GetWidth(), mPixels.GetHeight() );
-        texture.Upload( mPixels );
+        Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
+                                        data.GetWidth(), data.GetHeight() );
+        texture.Upload( data );
         textureSet = TextureSet::New();
         textureSet.SetTexture( 0u, texture );
       }
         textureSet = TextureSet::New();
         textureSet.SetTexture( 0u, texture );
       }
@@ -734,11 +721,11 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronous
   }
   else
   {
   }
   else
   {
+    mTextureLoading = true;
     if( attemptAtlasing )
     {
       textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, mImageUrl.GetUrl(), mDesiredSize, mFittingMode, true, this );
       mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
     if( attemptAtlasing )
     {
       textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, mImageUrl.GetUrl(), mDesiredSize, mFittingMode, true, this );
       mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
-      mTextureLoading = true;
     }
     if( !textureSet ) // big image, no atlasing or atlasing failed
     {
     }
     if( !textureSet ) // big image, no atlasing or atlasing failed
     {
@@ -762,7 +749,6 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronous
       }
 
       TextureManager::LoadState loadState = textureManager.GetTextureState( mTextureId );
       }
 
       TextureManager::LoadState loadState = textureManager.GetTextureState( mTextureId );
-
       mTextureLoading = ( loadState == TextureManager::LOADING );
 
       if( loadState == TextureManager::UPLOADED )
       mTextureLoading = ( loadState == TextureManager::LOADING );
 
       if( loadState == TextureManager::UPLOADED )
index 334406f..0c2f756 100644 (file)
@@ -286,11 +286,6 @@ private:
   bool IsSynchronousResourceLoading() const;
 
   /**
   bool IsSynchronousResourceLoading() const;
 
   /**
-   * @brief Load the resource synchronously
-   */
-  void LoadResourceSynchronously();
-
-  /**
    * Creates the texture set and adds the texture to it
    * @param[out] textureRect The texture area of the texture in the atlas.
    * @param[in] url The URL of the image resource to use.
    * Creates the texture set and adds the texture to it
    * @param[out] textureRect The texture area of the texture in the atlas.
    * @param[in] url The URL of the image resource to use.
@@ -333,7 +328,6 @@ private:
   };
 
   Image mImage;
   };
 
   Image mImage;
-  PixelData mPixels;
   Vector4 mPixelArea;
   WeakHandle<Actor> mPlacementActor;
   VisualUrl mImageUrl;
   Vector4 mPixelArea;
   WeakHandle<Actor> mPlacementActor;
   VisualUrl mImageUrl;