/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
return true;
}
-
void TestShaderCodeContainSubstrings(Control control, std::vector<std::pair<std::string, bool>> substringCheckList, const char* location)
{
Renderer renderer = control.GetRendererAt(0);
Property::Map* map = value.GetMap();
DALI_TEST_CHECK(map);
+ Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
+ std::string vertexShader;
+ DALI_TEST_CHECK(vertex->Get(vertexShader));
+ for(const auto& checkPair : substringCheckList)
+ {
+ const auto& keyword = checkPair.first;
+ const auto& expect = checkPair.second;
+ tet_printf("check [%s] %s exist in vertex shader\n", keyword.c_str(), expect ? "is" : "is not");
+ DALI_TEST_EQUALS((vertexShader.find(keyword.c_str()) != std::string::npos), expect, location);
+ }
+
Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
DALI_TEST_CHECK(fragment);
std::string fragmentShader;
tet_printf("check [%s] %s exist in fragment shader\n", keyword.c_str(), expect ? "is" : "is not");
DALI_TEST_EQUALS((fragmentShader.find(keyword.c_str()) != std::string::npos), expect, location);
}
+}
+
+void TestShaderCodeContainSubstringsForEachShader(Control control, std::vector<std::pair<std::string, std::pair<bool, bool>>> substringCheckList, const char* location)
+{
+ Renderer renderer = control.GetRendererAt(0);
+ Shader shader = renderer.GetShader();
+ Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
+ Property::Map* map = value.GetMap();
+ DALI_TEST_CHECK(map);
Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
std::string vertexShader;
for(const auto& checkPair : substringCheckList)
{
const auto& keyword = checkPair.first;
- const auto& expect = checkPair.second;
+ const auto& expect = checkPair.second.first;
tet_printf("check [%s] %s exist in vertex shader\n", keyword.c_str(), expect ? "is" : "is not");
DALI_TEST_EQUALS((vertexShader.find(keyword.c_str()) != std::string::npos), expect, location);
}
+
+ Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
+ DALI_TEST_CHECK(fragment);
+ std::string fragmentShader;
+ DALI_TEST_CHECK(fragment->Get(fragmentShader));
+ for(const auto& checkPair : substringCheckList)
+ {
+ const auto& keyword = checkPair.first;
+ const auto& expect = checkPair.second.second;
+ tet_printf("check [%s] %s exist in fragment shader\n", keyword.c_str(), expect ? "is" : "is not");
+ DALI_TEST_EQUALS((fragmentShader.find(keyword.c_str()) != std::string::npos), expect, location);
+ }
}
} //namespace
properties["cornerRadius"] = Vector4(1.0f, 100.0f, 10.0f, 0.1f); // Dummy Input
properties["cornerRadius"] = cornerRadius;
properties[DevelVisual::Property::CORNER_RADIUS_POLICY] = Toolkit::Visual::Transform::Policy::RELATIVE;
+ properties["synchronousLoading"] = false;
Visual::Base visual = factory.CreateVisual(properties);
properties[DevelVisual::Property::BORDERLINE_WIDTH] = borderlineWidth;
properties["borderlineColor"] = borderlineColor;
properties[DevelVisual::Property::BORDERLINE_OFFSET] = borderlineOffset;
+ properties[ImageVisual::Property::SYNCHRONOUS_LOADING] = false;
Visual::Base visual = factory.CreateVisual(properties);
static std::vector<UniformData> customUniforms =
{
+ UniformData("pixelArea", Property::Type::VECTOR4),
UniformData("cornerRadius", Property::Type::VECTOR4),
UniformData("borderlineWidth", Property::Type::FLOAT),
UniformData("borderlineColor", Property::Type::VECTOR4),
application.Render();
float targetOpacity = 0.5f;
+ Vector4 targetPixelArea(0.0f, 1.0f, 2.0f, -0.5f);
Vector4 targetCornerRadius(20.0f, 20.0f, 0.0f, 0.0f);
float targetBorderlineWidth = 10.0f;
Vector4 targetBorderlineColor(1.0f, 0.0f, 1.0f, 0.5f);
Animation animation = Animation::New(1.0f);
animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, Visual::Property::OPACITY), targetOpacity);
+ animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::PIXEL_AREA), targetPixelArea);
animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::CORNER_RADIUS), targetCornerRadius);
animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_WIDTH), targetBorderlineWidth);
animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_COLOR), targetBorderlineColor);
DALI_TEST_CHECK(colorValue);
DALI_TEST_EQUALS(colorValue->Get<Vector4>(), Vector4(1.0f, 1.0f, 1.0f, targetOpacity), TEST_LOCATION);
+ Property::Value* pixelAreaValue = resultMap.Find(ImageVisual::Property::PIXEL_AREA, Property::VECTOR4);
+ DALI_TEST_CHECK(pixelAreaValue);
+ DALI_TEST_EQUALS(pixelAreaValue->Get<Vector4>(), targetPixelArea, TEST_LOCATION);
+
Property::Value* cornerRadiusValue = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
DALI_TEST_CHECK(cornerRadiusValue);
DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), targetCornerRadius, TEST_LOCATION);
DALI_TEST_EQUALS(borderlineOffsetValue->Get<float>(), targetBorderlineOffset, TEST_LOCATION);
// Test uniform value
+ DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", targetPixelArea), true, TEST_LOCATION);
DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("cornerRadius", targetCornerRadius), true, TEST_LOCATION);
DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineWidth", targetBorderlineWidth), true, TEST_LOCATION);
DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("borderlineColor", targetBorderlineColor), true, TEST_LOCATION);
DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineOffset", targetBorderlineOffset), true, TEST_LOCATION);
+ // Test non-animatable index, for coverage.
+ DALI_TEST_EQUALS(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::URL).propertyIndex, Property::INVALID_INDEX, TEST_LOCATION);
+
END_TEST;
}
Property::Map propertyMap;
propertyMap.Insert(Visual::Property::TYPE, DevelVisual::Type::ANIMATED_VECTOR_IMAGE);
propertyMap.Insert(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME);
+ propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
Visual::Base animatedVectorVisual = factory.CreateVisual(propertyMap);
END_TEST;
}
+
+int UtcDaliVisualUpdatePropertyChangeShader05(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliVisualUpdatePropertyChangeShader05: Test update property under glsl version is under 300");
+
+ auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
+
+ // Change the shader language version forcely!
+ application.GetGlAbstraction().mShaderLanguageVersion = 200;
+
+ try
+ {
+ TraceCallStack& callStack = application.GetGraphicsController().mCallStack;
+
+ VisualFactory factory = VisualFactory::Get();
+ Property::Map propertyMap;
+ // Case ImageVisual
+ propertyMap[Visual::Property::TYPE] = Visual::Type::COLOR;
+ propertyMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE;
+
+ Visual::Base imageVisual = factory.CreateVisual(propertyMap);
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+ dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
+ dummyControl[Actor::Property::SIZE] = Vector2(200.f, 200.f);
+ application.GetScene().Add(dummyControl);
+
+ application.SendNotification();
+ application.Render();
+
+ application.SendNotification();
+ application.Render();
+
+ TestShaderCodeContainSubstrings(
+ dummyControl,
+ {
+ {"#define IS_REQUIRED_BLUR", false},
+ {"#define IS_REQUIRED_BORDERLINE", false},
+ {"#define IS_REQUIRED_ROUNDED_CORNER", false},
+ },
+ TEST_LOCATION);
+
+ float targetBlurRadius = 15.0f;
+ Vector4 targetCornerRadius = Vector4(1.0f, 0.1f, 1.1f, 0.0f);
+
+ Property::Map targetPropertyMap;
+ targetPropertyMap[DevelColorVisual::Property::BLUR_RADIUS] = targetBlurRadius;
+ targetPropertyMap[DevelVisual::Property::CORNER_RADIUS] = targetCornerRadius;
+ targetPropertyMap[DevelVisual::Property::BORDERLINE_WIDTH] = 10.0f; // Don't care. just dummy
+
+ callStack.Reset();
+ callStack.Enable(true);
+
+ // Update Properties with CornerRadius
+ DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Action::UPDATE_PROPERTY, targetPropertyMap);
+
+ Property::Map resultMap;
+ imageVisual.CreatePropertyMap(resultMap);
+
+ // Test property values: they should be updated
+ Property::Value* blurRadiusValue = resultMap.Find(DevelColorVisual::Property::BLUR_RADIUS, Property::FLOAT);
+ DALI_TEST_CHECK(blurRadiusValue);
+ DALI_TEST_EQUALS(blurRadiusValue->Get<float>(), targetBlurRadius, TEST_LOCATION);
+
+ Property::Value* cornerRadiusValue = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
+ DALI_TEST_CHECK(cornerRadiusValue);
+ DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), targetCornerRadius, TEST_LOCATION);
+
+ TestShaderCodeContainSubstringsForEachShader(
+ dummyControl,
+ {
+ {"#define IS_REQUIRED_BLUR", {true, true}},
+ {"#define IS_REQUIRED_BORDERLINE", {false, false}}, // Note : We ignore borderline when blur radius occured
+ {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}},
+ {"#define SL_VERSION_LOW", {false, true}},
+ },
+ TEST_LOCATION);
+
+ // Send shader compile signal
+ application.SendNotification();
+ application.Render();
+
+ callStack.Enable(false);
+
+ // Shader changed
+ DALI_TEST_CHECK((callStack.FindMethod("CreateShader")));
+ callStack.Reset();
+ callStack.Enable(true);
+
+ Property::Map targetPropertyMap2;
+ targetPropertyMap2[DevelColorVisual::Property::BLUR_RADIUS] = 0.0f;
+ targetPropertyMap2[DevelVisual::Property::CORNER_RADIUS] = Vector4::ZERO;
+ targetPropertyMap2[DevelVisual::Property::BORDERLINE_WIDTH] = 15.0f; // Don't care. just dummy
+
+ // Update Properties with CornerRadius
+ DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Action::UPDATE_PROPERTY, targetPropertyMap2);
+
+ Property::Map resultMap2;
+ imageVisual.CreatePropertyMap(resultMap2);
+
+ // Test property values: they should be updated
+ blurRadiusValue = resultMap2.Find(DevelColorVisual::Property::BLUR_RADIUS, Property::FLOAT);
+ DALI_TEST_CHECK(blurRadiusValue);
+ DALI_TEST_EQUALS(blurRadiusValue->Get<float>(), 0.0f, TEST_LOCATION);
+
+ cornerRadiusValue = resultMap2.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
+ DALI_TEST_CHECK(cornerRadiusValue);
+ DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
+
+ TestShaderCodeContainSubstringsForEachShader(
+ dummyControl,
+ {
+ {"#define IS_REQUIRED_BLUR", {true, true}}, // Note : mAlwaysUsingBlurRadius is true.
+ {"#define IS_REQUIRED_BORDERLINE", {false, false}}, // Note : We ignore borderline when blur radius occured
+ {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}}, // Note : mAlwaysUsingCornerRadius is true.
+ {"#define SL_VERSION_LOW", {false, true}},
+ },
+ TEST_LOCATION);
+
+ // Send shader compile signal
+ application.SendNotification();
+ application.Render();
+
+ callStack.Enable(false);
+
+ // Shader not changed
+ DALI_TEST_CHECK(!(callStack.FindMethod("CreateShader")));
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(false);
+ }
+
+ // Revert shader version. We should revert it even if UTC failed.
+ application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
+
+ END_TEST;
+}
\ No newline at end of file