/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
auto textureSet = mImpl->mRenderer.GetTextures();
- if(textureSet)
+ if(textureSet && textureSet.GetTextureCount())
{
auto texture = textureSet.GetTexture(0);
if(texture)
}
else
{
- Texture brokenImage = 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 brokenImage = mImpl->mRenderer.GetTextures().GetTexture(0);
naturalSize.x = brokenImage.GetWidth();
naturalSize.y = brokenImage.GetWidth();
}
textureManager.UseExternalResource(mImageUrl.GetUrl());
}
- Shader shader = GetShader();
+ Shader shader = GenerateShader();
// Create the renderer
mImpl->mRenderer = Renderer::New(geometry, shader);
}
else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
{
- Texture brokenImage = mFactoryCache.GetBrokenVisualImage();
-
- mTextures = TextureSet::New();
- mTextures.SetTexture(0u, brokenImage);
- mImpl->mRenderer.SetTextures(mTextures);
-
+ Vector2 imageSize = Vector2::ZERO;
+ if(actor)
+ {
+ imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
+ }
+ mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
actor.AddRenderer(mImpl->mRenderer);
mPlacementActor.Reset();
map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
bool sync = IsSynchronousLoadingRequired();
- map.Insert(SYNCHRONOUS_LOADING, sync);
+ map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync);
if(mImageUrl.IsValid())
{
map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl());
}
}
-void ImageVisual::OnDoAction(const Dali::Property::Index actionName, const Dali::Property::Value& attributes)
+void ImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes)
{
// Check if action is valid for this visual type and perform action if possible
- switch(actionName)
+ switch(actionId)
{
case DevelImageVisual::Action::RELOAD:
{
{
if(mImpl->mRenderer)
{
- Shader shader = GetShader();
+ Shader shader = GenerateShader();
mImpl->mRenderer.SetShader(shader);
}
}
}
// From Texture Manager
-void ImageVisual::UploadComplete(bool loadingSuccess, int32_t textureId, TextureSet textureSet, bool usingAtlas, const Vector4& atlasRectangle, bool preMultiplied)
+void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation)
{
Toolkit::Visual::ResourceStatus resourceStatus;
if(mImpl->mRenderer)
{
- if(usingAtlas)
+ if(textureInformation.useAtlasing)
{
mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect);
}
- EnablePreMultipliedAlpha(preMultiplied);
+ EnablePreMultipliedAlpha(textureInformation.preMultiplied);
Actor actor = mPlacementActor.GetHandle();
+ if(!loadingSuccess)
+ {
+ Vector2 imageSize = Vector2::ZERO;
+ if(actor)
+ {
+ imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
+ }
+ mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+ textureInformation.textureSet = mImpl->mRenderer.GetTextures();
+ }
+ else
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode(mWrapModeU, mWrapModeV);
+ textureInformation.textureSet.SetSampler(0u, sampler);
+ mImpl->mRenderer.SetTextures(textureInformation.textureSet);
+ }
+
if(actor)
{
actor.AddRenderer(mImpl->mRenderer);
// reset the weak handle so that the renderer only get added to actor once
mPlacementActor.Reset();
}
-
- if(!loadingSuccess)
- {
- Texture brokenImage = mFactoryCache.GetBrokenVisualImage();
-
- textureSet = TextureSet::New();
- textureSet.SetTexture(0u, brokenImage);
- mImpl->mRenderer.SetTextures(textureSet);
- }
-
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode(mWrapModeU, mWrapModeV);
- textureSet.SetSampler(0u, sampler);
- mImpl->mRenderer.SetTextures(textureSet);
}
// Storing TextureSet needed when renderer staged.
if(!mImpl->mRenderer)
{
- mTextures = textureSet;
+ mTextures = textureInformation.textureSet;
}
// Image loaded, set status regardless of staged status.
}
}
-Shader ImageVisual::GetShader()
+Shader ImageVisual::GenerateShader() const
{
Shader shader;
- std::string_view vertexShaderView;
- bool usesWholeTexture = true;
- if(mImpl->mCustomShader && !mImpl->mCustomShader->mVertexShader.empty())
- {
- vertexShaderView = mImpl->mCustomShader->mVertexShader;
- usesWholeTexture = false; // Impossible to tell.
- }
- else
- {
- vertexShaderView = mImageVisualShaderFactory.GetVertexShaderSource();
- }
+ bool usesWholeTexture = true;
+ const bool useStandardShader = !mImpl->mCustomShader;
+ const bool useNativeImage = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0)));
- std::string_view fragmentShaderView;
- if(mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty())
- {
- fragmentShaderView = mImpl->mCustomShader->mFragmentShader;
- }
- else
- {
- fragmentShaderView = mImageVisualShaderFactory.GetFragmentShaderSource();
- }
-
- // If the texture is native, we may need to change prefix and sampler in
- // the fragment shader
- bool modifiedFragmentShader = false;
- std::string fragmentShaderString;
- if(mTextures && DevelTexture::IsNative(mTextures.GetTexture(0)))
- {
- Texture nativeTexture = mTextures.GetTexture(0);
- fragmentShaderString = std::string(fragmentShaderView);
- modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragmentShaderString);
- fragmentShaderView = fragmentShaderString;
- }
-
- const bool useStandardShader = !mImpl->mCustomShader && !modifiedFragmentShader;
if(useStandardShader)
{
// Create and cache the standard shader
shader = mImageVisualShaderFactory.GetShader(
mFactoryCache,
- mImpl->mFlags & Impl::IS_ATLASING_APPLIED ? TextureAtlas::ENABLED : TextureAtlas::DISABLED,
- mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE ? DefaultTextureWrapMode::APPLY : DefaultTextureWrapMode::DO_NOT_APPLY,
- IsRoundedCornerRequired() ? RoundedCorner::ENABLED : RoundedCorner::DISABLED,
- IsBorderlineRequired() ? Borderline::ENABLED : Borderline::DISABLED
+ ImageVisualShaderFeature::FeatureBuilder()
+ .EnableTextureAtlas(mImpl->mFlags & Impl::IS_ATLASING_APPLIED && !useNativeImage)
+ .ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE)
+ .EnableRoundedCorner(IsRoundedCornerRequired())
+ .EnableBorderline(IsBorderlineRequired())
+ .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture())
);
}
- else if(mImpl->mCustomShader)
- {
- shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
- }
else
{
- shader = Shader::New(vertexShaderView, fragmentShaderView);
+ std::string_view vertexShaderView;
+ std::string_view fragmentShaderView;
+
+ if(mImpl->mCustomShader && !mImpl->mCustomShader->mVertexShader.empty())
+ {
+ vertexShaderView = mImpl->mCustomShader->mVertexShader;
+ usesWholeTexture = false; // Impossible to tell.
+ }
+ else
+ {
+ vertexShaderView = mImageVisualShaderFactory.GetVertexShaderSource();
+ }
+
+ if(mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty())
+ {
+ fragmentShaderView = mImpl->mCustomShader->mFragmentShader;
+ }
+ else
+ {
+ fragmentShaderView = mImageVisualShaderFactory.GetFragmentShaderSource();
+ }
+
+ // If the texture is native, we may need to change prefix and sampler in
+ // the fragment shader
+ if(useNativeImage)
+ {
+ bool modifiedFragmentShader = false;
+ Texture nativeTexture = mTextures.GetTexture(0);
+ std::string fragmentShaderString = std::string(fragmentShaderView);
+
+ modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragmentShaderString);
+ if(modifiedFragmentShader)
+ {
+ fragmentShaderView = fragmentShaderString;
+ }
+
+ // Create shader here cause fragmentShaderString scope issue
+ shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
+ }
+ else
+ {
+ shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
+ }
}
if(usesWholeTexture)