Make n-patch image show broken image
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch / npatch-visual.cpp
index c251193..98d6d30 100644 (file)
@@ -46,7 +46,7 @@ namespace Internal
 {
 namespace
 {
-const int CUSTOM_PROPERTY_COUNT(10); // 5 transform properties + fixed(3),stretch,aux
+const int CUSTOM_PROPERTY_COUNT(5); // fixed(3),stretch,aux
 }
 
 /////////////////NPatchVisual////////////////
@@ -236,7 +236,7 @@ void NPatchVisual::OnSetTransform()
 {
   if(mImpl->mRenderer)
   {
-    mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+    mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
   }
 }
 
@@ -300,11 +300,11 @@ void NPatchVisual::OnInitialize()
     mFactoryCache,
     ImageVisualShaderFeature::FeatureBuilder());
 
-  mImpl->mRenderer = Renderer::New(geometry, shader);
+  mImpl->mRenderer = VisualRenderer::New(geometry, shader);
   mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
 
   //Register transform properties
-  mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+  mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
 }
 
 Geometry NPatchVisual::CreateGeometry()
@@ -451,6 +451,32 @@ void NPatchVisual::ApplyTextureAndUniforms()
   {
     textureSet = data->GetTextures();
     NPatchHelper::ApplyTextureAndUniforms(mImpl->mRenderer, data);
+
+    if(mAuxiliaryPixelBuffer)
+    {
+      // If the auxiliary image is smaller than the un-stretched NPatch, use CPU resizing to enlarge it to the
+      // same size as the unstretched NPatch. This will give slightly higher quality results than just relying
+      // on GL interpolation alone.
+      if(mAuxiliaryPixelBuffer.GetWidth() < data->GetCroppedWidth() &&
+         mAuxiliaryPixelBuffer.GetHeight() < data->GetCroppedHeight())
+      {
+        mAuxiliaryPixelBuffer.Resize(data->GetCroppedWidth(), data->GetCroppedHeight());
+      }
+
+      // Note, this resets mAuxiliaryPixelBuffer handle
+      auto auxiliaryPixelData = Devel::PixelBuffer::Convert(mAuxiliaryPixelBuffer);
+
+      auto texture = Texture::New(TextureType::TEXTURE_2D,
+                                  auxiliaryPixelData.GetPixelFormat(),
+                                  auxiliaryPixelData.GetWidth(),
+                                  auxiliaryPixelData.GetHeight());
+      texture.Upload(auxiliaryPixelData);
+      textureSet.SetTexture(1, texture);
+      mImpl->mRenderer.RegisterProperty(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA,
+                                        AUXILIARY_IMAGE_ALPHA_NAME,
+                                        mAuxiliaryImageAlpha);
+    }
+    mImpl->mRenderer.SetTextures(textureSet);
   }
   else
   {
@@ -463,43 +489,11 @@ void NPatchVisual::ApplyTextureAndUniforms()
     {
       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);
-    mImpl->mRenderer.RegisterProperty("uFixed[2]", Vector2::ZERO);
-    mImpl->mRenderer.RegisterProperty("uStretchTotal", Vector2(croppedImage.GetWidth(), croppedImage.GetHeight()));
-  }
-
-  if(mAuxiliaryPixelBuffer)
-  {
-    // If the auxiliary image is smaller than the un-stretched NPatch, use CPU resizing to enlarge it to the
-    // same size as the unstretched NPatch. This will give slightly higher quality results than just relying
-    // on GL interpolation alone.
-    if(mAuxiliaryPixelBuffer.GetWidth() < data->GetCroppedWidth() &&
-       mAuxiliaryPixelBuffer.GetHeight() < data->GetCroppedHeight())
-    {
-      mAuxiliaryPixelBuffer.Resize(data->GetCroppedWidth(), data->GetCroppedHeight());
-    }
-
-    // Note, this resets mAuxiliaryPixelBuffer handle
-    auto auxiliaryPixelData = Devel::PixelBuffer::Convert(mAuxiliaryPixelBuffer);
-
-    auto texture = Texture::New(TextureType::TEXTURE_2D,
-                                auxiliaryPixelData.GetPixelFormat(),
-                                auxiliaryPixelData.GetWidth(),
-                                auxiliaryPixelData.GetHeight());
-    texture.Upload(auxiliaryPixelData);
-    textureSet.SetTexture(1, texture);
-    mImpl->mRenderer.RegisterProperty(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA,
-                                      AUXILIARY_IMAGE_ALPHA_NAME,
-                                      mAuxiliaryImageAlpha);
+    mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
   }
-  mImpl->mRenderer.SetTextures(textureSet);
 
   // Register transform properties
-  mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+  mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
 }
 
 Geometry NPatchVisual::GetNinePatchGeometry(VisualFactoryCache::GeometryType subType)