Refactoring TextureUploadObserver.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch / npatch-visual.cpp
index bb8571d..b9e046a 100644 (file)
@@ -153,10 +153,10 @@ void NPatchVisual::LoadImages()
   TextureManager& textureManager     = mFactoryCache.GetTextureManager();
   bool            synchronousLoading = mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
 
-  if(mId == NPatchData::INVALID_NPATCH_DATA_ID && mImageUrl.IsLocalResource())
+  if(mId == NPatchData::INVALID_NPATCH_DATA_ID && (mImageUrl.IsLocalResource() || mImageUrl.IsBufferResource()))
   {
     bool preMultiplyOnLoad = IsPreMultipliedAlphaEnabled() && !mImpl->mCustomShader ? true : false;
-    mId                    = mLoader.Load(textureManager, this, mImageUrl.GetUrl(), mBorder, preMultiplyOnLoad, synchronousLoading);
+    mId                    = mLoader.Load(textureManager, this, mImageUrl, mBorder, preMultiplyOnLoad, synchronousLoading);
 
     const NPatchData* data;
     if(mLoader.GetNPatchData(mId, data) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
@@ -165,7 +165,7 @@ void NPatchVisual::LoadImages()
     }
   }
 
-  if(!mAuxiliaryPixelBuffer && mAuxiliaryUrl.IsValid() && mAuxiliaryUrl.IsLocalResource())
+  if(!mAuxiliaryPixelBuffer && mAuxiliaryUrl.IsValid() && (mAuxiliaryUrl.IsLocalResource() || mAuxiliaryUrl.IsBufferResource()))
   {
     // Load the auxiliary image
     auto preMultiplyOnLoading = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
@@ -376,7 +376,10 @@ void NPatchVisual::OnInitialize()
 {
   // Get basic geometry and shader
   Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
-  Shader   shader   = mImageVisualShaderFactory.GetShader(mFactoryCache, false, true, false);
+  Shader   shader   = mImageVisualShaderFactory.GetShader(
+    mFactoryCache,
+    ImageVisualShaderFeature::FeatureBuilder()
+  );
 
   mImpl->mRenderer = Renderer::New(geometry, shader);
 
@@ -556,7 +559,14 @@ void NPatchVisual::ApplyTextureAndUniforms()
     DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str());
     textureSet = TextureSet::New();
 
-    Texture croppedImage = mFactoryCache.GetBrokenVisualImage();
+    Actor actor = mPlacementActor.GetHandle();
+    Vector2 imageSize = Vector2::ZERO;
+    if(actor)
+    {
+      imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
+    }
+    mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+    Texture croppedImage = mImpl->mRenderer.GetTextures().GetTexture(0);
     textureSet.SetTexture(0u, croppedImage);
     mImpl->mRenderer.RegisterProperty("uFixed[0]", Vector2::ZERO);
     mImpl->mRenderer.RegisterProperty("uFixed[1]", Vector2::ZERO);
@@ -767,32 +777,34 @@ void NPatchVisual::SetResource()
   }
 }
 
-void NPatchVisual::UploadComplete(bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied)
+void NPatchVisual::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
 {
-  EnablePreMultipliedAlpha(preMultiplied);
-  if(!loadSuccess)
+  if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE)
   {
-    // Image loaded and ready to display
-    ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
-  }
-
-  if(mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid())
-  {
-    SetResource();
-  }
-}
+    EnablePreMultipliedAlpha(textureInformation.preMultiplied);
+    if(!loadSuccess)
+    {
+      // Image loaded and ready to display
+      ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+    }
 
-void NPatchVisual::LoadComplete(bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied)
-{
-  if(loadSuccess && url.GetUrl() == mAuxiliaryUrl.GetUrl())
-  {
-    mAuxiliaryPixelBuffer = pixelBuffer;
-    SetResource();
+    if(mAuxiliaryPixelBuffer || !mAuxiliaryUrl.IsValid())
+    {
+      SetResource();
+    }
   }
-  else
+  else  // for the ReturnType::PIXEL_BUFFER
   {
-    // Image loaded and ready to display
-    ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+    if(loadSuccess && textureInformation.url == mAuxiliaryUrl.GetUrl())
+    {
+      mAuxiliaryPixelBuffer = textureInformation.pixelBuffer;
+      SetResource();
+    }
+    else
+    {
+      // Image loaded and ready to display
+      ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+    }
   }
 }