#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/public-api/controls/render-effects/background-blur-effect.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
using namespace Dali;
using namespace Dali::Toolkit;
Integration::Scene scene = application.GetScene();
Control control = Control::New();
control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
- control.SetProperty(Actor::Property::SIZE, Vector2(3.0f, 3.0f));
scene.Add(control);
control.SetRenderEffect(BackgroundBlurEffect::New());
Renderer renderer = control.GetRendererAt(1u);
Vector4 radius = Vector4::ZERO;
- renderer.GetProperty(renderer.GetPropertyIndex(std::string("uRadius"))).Get(radius);
+ renderer.GetProperty(renderer.GetPropertyIndex(std::string("uCornerRadius"))).Get(radius);
+
+ Toolkit::Visual::Transform::Policy::Type policy;
+ renderer.GetProperty(renderer.GetPropertyIndex(std::string("uCornerRadiusPolicy"))).Get(policy);
+ DALI_TEST_CHECK(policy == 1);
DALI_TEST_CHECK(radius.x == 30.0f);
DALI_TEST_CHECK(radius.y == 30.0f);
END_TEST;
}
+
+int UtcDaliRenderEffectInvalidTargetSize(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliRenderEffectInvalidTargetSize");
+
+ Integration::Scene scene = application.GetScene();
+ const uint32_t maxTextureSize = Dali::GetMaxTextureSize();
+
+ Control control = Control::New();
+ control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ control.SetProperty(Actor::Property::SIZE_WIDTH, maxTextureSize + 1000.0f);
+ control.SetProperty(Actor::Property::SIZE_HEIGHT, maxTextureSize + 1000.0f);
+ scene.Add(control);
+ control.SetRenderEffect(BackgroundBlurEffect::New(0.4f, 40));
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK(true); // no error
+
+ control.SetProperty(Actor::Property::SIZE_WIDTH, -10.0f);
+ control.SetProperty(Actor::Property::SIZE_HEIGHT, -10.0f);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK(true); // no error
+
+ END_TEST;
+}
mInternalRoot.Add(mVerticalBlurActor);
}
+Vector2 BlurEffectImpl::GetTargetSizeForValidTexture()
+{
+ Vector2 size = GetTargetSize();
+ if(size == Vector2::ZERO)
+ {
+ size = GetOwnerControl().GetNaturalSize();
+ }
+
+ if(size == Vector2::ZERO || size.x < 0.0f || size.y < 0.0f)
+ {
+ return Vector2::ZERO;
+ }
+
+ const uint32_t maxTextureSize = Dali::GetMaxTextureSize();
+ if(uint32_t(size.x) > maxTextureSize || uint32_t(size.y) > maxTextureSize)
+ {
+ uint32_t denominator = std::max(size.x, size.y);
+ size.x = (size.x * maxTextureSize / denominator);
+ size.y = (size.y * maxTextureSize / denominator);
+ }
+ return size;
+}
+
void BlurEffectImpl::Activate()
{
if(mIsActivated)
Toolkit::Control ownerControl = GetOwnerControl();
DALI_ASSERT_ALWAYS(ownerControl && "Set the owner of RenderEffect before you activate.");
- // Get input texture size
- Vector2 size = GetTargetSize();
+ // Get/Set sizes
+ Vector2 size = GetTargetSizeForValidTexture();
if(size == Vector2::ZERO)
{
- size = ownerControl.GetNaturalSize();
- if(size == Vector2::ZERO)
- {
- return;
- }
+ return;
}
- DALI_ASSERT_ALWAYS(!(size.x < 0.0f || size.y < 0.0f || uint32_t(size.x) > Dali::GetMaxTextureSize() || uint32_t(size.y) > Dali::GetMaxTextureSize()) && "You need to pass a valid texture size.");
-
uint32_t downsampledWidth = static_cast<uint32_t>(size.width * mDownscaleFactor);
uint32_t downsampledHeight = static_cast<uint32_t>(size.height * mDownscaleFactor);
+ if(downsampledWidth == 0u)
+ {
+ downsampledWidth = 1u;
+ }
+ if(downsampledHeight == 0u)
+ {
+ downsampledHeight = 1u;
+ }
RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
Vector4 radius = Vector4::ZERO;
map[Toolkit::DevelVisual::Property::CORNER_RADIUS].Get(radius);
+ Visual::Transform::Policy::Type policy;
+ map[Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY].Get(policy);
+
Renderer renderer = GetTargetRenderer();
- renderer.RegisterProperty("uRadius", radius);
+ renderer.RegisterProperty("uCornerRadius", radius);
+ renderer.RegisterProperty("uCornerRadiusPolicy", static_cast<float>(policy));
}
} // namespace Internal
private:
// Inner functions
+ /**
+ * @brief Gets or Calculates a valid target size for texture.
+ * Invalid cases include: zero vector, minus numbers or large numbers(larger than the maximum).
+ * @return A valid version of mTargetSize, Vector2::ZERO otherwise.
+ * @note The return value is a copy, not mTargetSize itself.
+ */
+ Vector2 GetTargetSizeForValidTexture();
/**
* @brief Calculates gaussian weight
{
if(mOwnerControl)
{
- mTargetSize = mOwnerControl.GetProperty<Vector2>(Actor::Property::SIZE);
+ mTargetSize = mOwnerControl.GetCurrentProperty<Vector2>(Actor::Property::SIZE);
Deactivate();
Activate();
}
precision highp float;
varying highp vec2 vFragCoord;
varying highp vec2 vTexCoord;
+varying highp vec4 vCornerRadius;
uniform highp vec3 uSize;
uniform sampler2D sTexture;
-uniform highp vec4 uRadius;
highp float nrand(const in vec2 uv)
{
- Radius;
}
-float getCurrentRadius()
-{
- if(vTexCoord.x < 0.5 && vTexCoord.y < 0.5)
- {
- return uRadius.x;
- }
- else if(vTexCoord.x < 0.5 && vTexCoord.y > 0.5)
- {
- return uRadius.y;
- }
- else if(vTexCoord.x > 0.5 && vTexCoord.y > 0.5)
- {
- return uRadius.z;
- }
- else
- {
- return uRadius.w;
- }
-}
-
void main()
{
gl_FragColor = texture2D(sTexture, vTexCoord);
- float radius = getCurrentRadius();
+ highp vec2 location = vTexCoord.xy - vec2(0.5);
+ float radius =
+ mix(
+ mix(vCornerRadius.x, vCornerRadius.y, sign(location.x)*0.5 + 0.5),
+ mix(vCornerRadius.w, vCornerRadius.z, sign(location.x)*0.5 + 0.5),
+ sign(location.y) * 0.5 + 0.5
+ );
+
float edgeSoftness = min(1.0, radius);
float distance = roundedBoxSDF(vFragCoord.xy - (uSize.xy/2.0), uSize.xy/2.0, radius);
attribute highp vec2 aPosition;
varying highp vec2 vFragCoord;
varying highp vec2 vTexCoord;
+varying highp vec4 vCornerRadius; //output
uniform highp mat4 uMvpMatrix;
uniform highp vec3 uSize;
+uniform highp vec4 uCornerRadius; //input
+uniform highp float uCornerRadiusPolicy;
void main()
{
vFragCoord = vertexPosition.xy + uSize.xy/2.0;
vTexCoord = aPosition + vec2(0.5);
gl_Position = uMvpMatrix * vertexPosition;
+
+ highp float minSize = min(uSize.x, uSize.y);
+ vCornerRadius = mix(uCornerRadius * minSize, uCornerRadius, uCornerRadiusPolicy);
+ vCornerRadius = min(vCornerRadius, minSize * 0.5);
}