From: Eunki, Hong Date: Tue, 17 May 2022 09:51:37 +0000 (+0900) Subject: Delete useless define of default shaders X-Git-Tag: dali_2.1.26~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F275156%2F5;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Delete useless define of default shaders We can use #if defined(~~) instead of #ifndef ~~ #define ~~ 0 Now we can check the shader more clean environment. Change-Id: Icaf79367ccdeb0a3bd53d47aaacd00ad8f352a64 Signed-off-by: Eunki, Hong --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 175e834..7c13fc1 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -141,6 +141,38 @@ bool DaliTestCheckMaps(const Property::Map& fontStyleMapGet, const Property::Map return true; } +void TestShaderCodeContainSubstrings(Control control, std::vector> 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* 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; + 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); + } + + 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); + } +} + } //namespace void dali_visual_startup(void) @@ -906,7 +938,7 @@ int UtcDaliVisualGetPropertyMap6(void) value = resultMap.Find(ImageVisual::Property::BORDER, Property::RECTANGLE); DALI_TEST_CHECK(value); - DALI_TEST_CHECK(value->Get >() == border); + DALI_TEST_CHECK(value->Get>() == border); value = resultMap.Find(DevelImageVisual::Property::AUXILIARY_IMAGE, Property::STRING); DALI_TEST_CHECK(value); @@ -947,7 +979,7 @@ int UtcDaliVisualGetPropertyMap6(void) value = resultMap.Find(ImageVisual::Property::BORDER, Property::RECTANGLE); DALI_TEST_CHECK(value); - DALI_TEST_CHECK(value->Get >() == border); + DALI_TEST_CHECK(value->Get>() == border); END_TEST; } @@ -5671,27 +5703,14 @@ int UtcDaliVisualUpdatePropertyChangeShader01(void) application.SendNotification(); application.Render(); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", false}, + }, + TEST_LOCATION); + callStack.Reset(); callStack.Enable(true); @@ -5716,27 +5735,13 @@ int UtcDaliVisualUpdatePropertyChangeShader01(void) DALI_TEST_CHECK(cornerRadiusPolicyValue); DALI_TEST_EQUALS(cornerRadiusPolicyValue->Get(), static_cast(Toolkit::Visual::Transform::Policy::RELATIVE), TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -5786,29 +5791,13 @@ int UtcDaliVisualUpdatePropertyChangeShader01(void) DALI_TEST_CHECK(borderlineOffsetValue); DALI_TEST_EQUALS(borderlineOffsetValue->Get(), targetBorderlineOffset, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", true}, + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, // Note : mAlwaysUsingCornerRadius is true. + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -5854,29 +5843,13 @@ int UtcDaliVisualUpdatePropertyChangeShader01(void) DALI_TEST_CHECK(borderlineOffsetValue); DALI_TEST_EQUALS(borderlineOffsetValue->Get(), 0.0f, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - // Note : mAlwaysUsingBorderline and mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - // Note : mAlwaysUsingBorderline and mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", true}, // Note : mAlwaysUsingBorderline is true. + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, // Note : mAlwaysUsingCornerRadius is true. + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -5919,27 +5892,13 @@ int UtcDaliVisualUpdatePropertyChangeShader02(void) application.SendNotification(); application.Render(); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", false}, + }, + TEST_LOCATION); Vector4 targetCornerRadius = Vector4(0.0f, 0.0f, 0.0f, 0.0f); @@ -5960,29 +5919,13 @@ int UtcDaliVisualUpdatePropertyChangeShader02(void) DALI_TEST_CHECK(cornerRadiusValue); DALI_TEST_EQUALS(cornerRadiusValue->Get(), targetCornerRadius, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - // Note : corner radius is zero. so we don't change shader! - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - // Note : corner radius is zero. so we don't change shader! - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", false}, // Note : corner radius is zero. so we don't change shader! + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -6023,29 +5966,13 @@ int UtcDaliVisualUpdatePropertyChangeShader02(void) DALI_TEST_CHECK(borderlineOffsetValue); DALI_TEST_EQUALS(borderlineOffsetValue->Get(), targetBorderlineOffset, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - // Note : borderline width is zero. so we don't change shader! - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - // Note : borderline width is zero. so we don't change shader! - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, // Note : borderline width is zero. so we don't change shader! + {"#define IS_REQUIRED_ROUNDED_CORNER", false}, + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -6086,29 +6013,14 @@ int UtcDaliVisualUpdatePropertyChangeShader03(void) application.SendNotification(); application.Render(); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BLUR 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BLUR 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") == std::string::npos); - } + 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); @@ -6136,31 +6048,14 @@ int UtcDaliVisualUpdatePropertyChangeShader03(void) DALI_TEST_CHECK(cornerRadiusValue); DALI_TEST_EQUALS(cornerRadiusValue->Get(), targetCornerRadius, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BLUR 1") != std::string::npos); - // Note : We ignore borderline when blur radius occured - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BLUR 1") != std::string::npos); - // Note : We ignore borderline when blur radius occured - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BLUR", true}, + {"#define IS_REQUIRED_BORDERLINE", false}, // Note : We ignore borderline when blur radius occured + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -6193,33 +6088,14 @@ int UtcDaliVisualUpdatePropertyChangeShader03(void) DALI_TEST_CHECK(cornerRadiusValue); DALI_TEST_EQUALS(cornerRadiusValue->Get(), Vector4::ZERO, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - // Note : mAlwaysUsingBlurRadius and mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BLUR 1") != std::string::npos); - // Note : We ignore borderline when blur radius occured - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - // Note : mAlwaysUsingBlurRadius and mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BLUR 1") != std::string::npos); - // Note : We ignore borderline when blur radius occured - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BLUR", true}, // Note : mAlwaysUsingBlurRadius is true. + {"#define IS_REQUIRED_BORDERLINE", false}, // Note : We ignore borderline when blur radius occured + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, // Note : mAlwaysUsingCornerRadius is true. + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); @@ -6264,27 +6140,14 @@ int UtcDaliVisualUpdatePropertyChangeShader04(void) application.SendNotification(); application.Render(); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, + }, + TEST_LOCATION); + callStack.Reset(); callStack.Enable(true); @@ -6298,29 +6161,14 @@ int UtcDaliVisualUpdatePropertyChangeShader04(void) application.Render(); application.Render(1001u); // End of animation - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") == std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", false}, + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, // Note : mAlwaysUsingCornerRadius is true. + }, + TEST_LOCATION); + callStack.Enable(false); // Shader not changed DALI_TEST_CHECK(!callStack.FindMethod("CreateShader")); @@ -6350,29 +6198,13 @@ int UtcDaliVisualUpdatePropertyChangeShader04(void) DALI_TEST_CHECK(borderlineWidthValue); DALI_TEST_EQUALS(borderlineWidthValue->Get(), targetBorderlineWidth, TEST_LOCATION); - // Get shader - { - Renderer renderer = dummyControl.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* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp - DALI_TEST_CHECK(fragment); - std::string fragmentShader; - DALI_TEST_CHECK(fragment->Get(fragmentShader)); - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(fragmentShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - - Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp - std::string vertexShader; - DALI_TEST_CHECK(vertex->Get(vertexShader)); - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_BORDERLINE 1") != std::string::npos); - // Note : mAlwaysUsingCornerRadius is true. - DALI_TEST_CHECK(vertexShader.find("#define IS_REQUIRED_ROUNDED_CORNER 1") != std::string::npos); - } + TestShaderCodeContainSubstrings( + dummyControl, + { + {"#define IS_REQUIRED_BORDERLINE", true}, + {"#define IS_REQUIRED_ROUNDED_CORNER", true}, // Note : mAlwaysUsingCornerRadius is true. + }, + TEST_LOCATION); // Send shader compile signal application.SendNotification(); diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index 33202a2..db23361 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -1,36 +1,26 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef IS_REQUIRED_BLUR -#define IS_REQUIRED_BLUR 0 -#endif - -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE || IS_REQUIRED_BLUR +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif #endif uniform lowp vec4 uColor; uniform lowp vec3 mixColor; -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif -#if IS_REQUIRED_BLUR +#ifdef IS_REQUIRED_BLUR uniform mediump float blurRadius; #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE || IS_REQUIRED_BLUR +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) // Global values both rounded corner and borderline use // radius of rounded corner on this quadrant @@ -54,7 +44,7 @@ mediump float gMinInlinePotential = 0.0; void calculateCornerRadius() { -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER gRadius = mix( mix(vCornerRadius.x, vCornerRadius.y, sign(vPosition.x) * 0.5 + 0.5), @@ -68,7 +58,7 @@ void calculatePosition() { gFragmentPosition = abs(vPosition) - vRectSize; gCenterPosition = -gRadius; -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5; #endif gDiff = gFragmentPosition - gCenterPosition; @@ -86,7 +76,7 @@ void setupMinMaxPotential() gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth; gMinInlinePotential = gMinOutlinePotential - borderlineWidth; #else @@ -109,7 +99,7 @@ void PreprocessPotential() } #endif -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { mediump float potential = gPotential; @@ -173,7 +163,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) } #endif -#if !IS_REQUIRED_BLUR && IS_REQUIRED_ROUNDED_CORNER +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_ROUNDED_CORNER) mediump float calculateCornerOpacity() { mediump float potential = gPotential; @@ -195,7 +185,7 @@ mediump float calculateCornerOpacity() } #endif -#if IS_REQUIRED_BLUR +#ifdef IS_REQUIRED_BLUR mediump float calculateBlurOpacity() { // Don't use borderline! @@ -203,7 +193,7 @@ mediump float calculateBlurOpacity() mediump float cy = gRadius + blurRadius; mediump float cr = gRadius + blurRadius; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER // This routine make perfect circle. If corner radius is not exist, we don't consider prefect circle. cy = min(cy, min(vRectSize.x, vRectSize.y) - gRadius); #endif @@ -240,7 +230,7 @@ mediump float calculateBlurOpacity() // highest point of that circle is (x, x + r) and potential is x + r // solve (v.x - x)^2 + (v.y - x)^2 = (cr / cy * x)^2 -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER // Note : lowspec HW cannot calculate here. need to reduce numeric error highp float A = (cr * cr - 2.0 * cy * cy); highp float B = cy * (v.x + v.y); @@ -268,7 +258,7 @@ void main() { lowp vec4 targetColor = vec4(mixColor, 1.0) * uColor; -#if IS_REQUIRED_BLUR || IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_BLUR) || defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // skip most potential calculate for performance if(abs(vPosition.x) < vOptRectSize.x && abs(vPosition.y) < vOptRectSize.y) { @@ -279,20 +269,20 @@ void main() PreprocessPotential(); #endif -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) targetColor = convertBorderlineColor(targetColor); #endif OUT_COLOR = targetColor; -#if IS_REQUIRED_BLUR +#ifdef IS_REQUIRED_BLUR mediump float opacity = calculateBlurOpacity(); OUT_COLOR.a *= opacity; -#elif IS_REQUIRED_ROUNDED_CORNER +#elif defined(IS_REQUIRED_ROUNDED_CORNER) mediump float opacity = calculateCornerOpacity(); OUT_COLOR.a *= opacity; #endif -#if IS_REQUIRED_BLUR || IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_BLUR) || defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) } #endif } diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert index 2798185..ea72bab 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert @@ -1,19 +1,9 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef IS_REQUIRED_BLUR -#define IS_REQUIRED_BLUR 0 -#endif - INPUT mediump vec2 aPosition; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE || IS_REQUIRED_BLUR +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif #endif @@ -27,14 +17,14 @@ uniform highp vec2 size; uniform mediump vec4 offsetSizeMode; uniform mediump vec2 origin; uniform mediump vec2 anchorPoint; -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; #endif -#if IS_REQUIRED_BLUR +#ifdef IS_REQUIRED_BLUR uniform mediump float blurRadius; #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER uniform mediump vec4 cornerRadius; uniform mediump float cornerRadiusPolicy; #endif @@ -45,13 +35,13 @@ vec4 ComputeVertexPosition() vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize; vec2 visualOffset = mix(offset, offset/uSize.xy, offsetSizeMode.xy); -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE || IS_REQUIRED_BLUR +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; #endif -#if IS_REQUIRED_ROUNDED_CORNER -#if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_ROUNDED_CORNER +#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) mediump float minSize = min(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; #else mediump float minSize = min(visualSize.x, visualSize.y); @@ -63,13 +53,13 @@ vec4 ComputeVertexPosition() vOptRectSize -= 0.2929 * maxRadius + 1.0; #endif -#if IS_REQUIRED_BLUR +#ifdef IS_REQUIRED_BLUR vPosition = aPosition * (visualSize + 2.0 * blurRadius); vOptRectSize -= blurRadius + 1.0; -#elif IS_REQUIRED_BORDERLINE +#elif defined(IS_REQUIRED_BORDERLINE) vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0))* borderlineWidth); vOptRectSize -= (1.0 - clamp(borderlineOffset, -1.0, 1.0)) * 0.5 * borderlineWidth + 1.0; -#elif IS_REQUIRED_ROUNDED_CORNER +#elif defined(IS_REQUIRED_ROUNDED_CORNER) vPosition = aPosition * visualSize; #else mediump vec2 vPosition = aPosition * visualSize; diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag index a30bf5e..febc776 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag @@ -1,19 +1,9 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef RADIAL -#define RADIAL 0 -#endif - INPUT mediump vec2 vTexCoord; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif #endif @@ -21,14 +11,14 @@ INPUT mediump vec4 vCornerRadius; uniform sampler2D sTexture; // sampler1D? uniform lowp vec4 uColor; uniform lowp vec3 mixColor; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // Global values both rounded corner and borderline use // radius of rounded corner on this quadrant @@ -52,7 +42,7 @@ mediump float gMinInlinePotential = 0.0; void calculateCornerRadius() { -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER gRadius = mix( mix(vCornerRadius.x, vCornerRadius.y, sign(vPosition.x) * 0.5 + 0.5), @@ -66,7 +56,7 @@ void calculatePosition() { gFragmentPosition = abs(vPosition) - vRectSize; gCenterPosition = -gRadius; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5; #endif gDiff = gFragmentPosition - gCenterPosition; @@ -84,7 +74,7 @@ void setupMinMaxPotential() gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth; gMinInlinePotential = gMinOutlinePotential - borderlineWidth; #else @@ -108,7 +98,7 @@ void PreprocessPotential() #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { mediump float potential = gPotential; @@ -172,7 +162,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) } #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER mediump float calculateCornerOpacity() { mediump float potential = gPotential; @@ -196,13 +186,13 @@ mediump float calculateCornerOpacity() void main() { -#if RADIAL +#ifdef RADIAL lowp vec4 textureColor = TEXTURE(sTexture, vec2(length(vTexCoord), 0.5)) * vec4(mixColor, 1.0) * uColor; #else lowp vec4 textureColor = TEXTURE(sTexture, vec2(vTexCoord.y, 0.5)) * vec4(mixColor, 1.0) * uColor; #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // skip most potential calculate for performance if(abs(vPosition.x) < vOptRectSize.x && abs(vPosition.y) < vOptRectSize.y) { @@ -213,17 +203,17 @@ void main() PreprocessPotential(); #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE textureColor = convertBorderlineColor(textureColor); #endif OUT_COLOR = textureColor; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER mediump float opacity = calculateCornerOpacity(); OUT_COLOR *= opacity; #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) } #endif } diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert index edaf643..9ea1a17 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert @@ -1,20 +1,10 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef USER_SPACE -#define USER_SPACE 0 -#endif - INPUT mediump vec2 aPosition; OUTPUT mediump vec2 vTexCoord; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif #endif @@ -29,11 +19,11 @@ uniform highp vec2 size; uniform mediump vec4 offsetSizeMode; uniform mediump vec2 origin; uniform mediump vec2 anchorPoint; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER uniform mediump vec4 cornerRadius; uniform mediump float cornerRadiusPolicy; #endif @@ -43,13 +33,13 @@ vec4 ComputeVertexPosition() vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ); vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy); -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; #endif -#if IS_REQUIRED_ROUNDED_CORNER -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_BORDERLINE mediump float minSize = min(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; #else mediump float minSize = min(visualSize.x, visualSize.y); @@ -62,17 +52,17 @@ vec4 ComputeVertexPosition() #endif mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth); vertexPosition.xy *= (1.0 + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth / visualSize); vOptRectSize -= (1.0 - clamp(borderlineOffset, -1.0, 1.0)) * 0.5 * borderlineWidth + 1.0; -#elif IS_REQUIRED_ROUNDED_CORNER +#elif defined(IS_REQUIRED_ROUNDED_CORNER) vPosition = aPosition * visualSize; #else mediump vec2 vPosition = aPosition * visualSize; #endif -#if USER_SPACE +#ifdef USER_SPACE vertexPosition.xyz *= uSize; #endif diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag index c2324e7..3694280 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag @@ -1,39 +1,23 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef IS_REQUIRED_ALPHA_MASKING -#define IS_REQUIRED_ALPHA_MASKING 0 -#endif -#ifndef ATLAS_DEFAULT_WARP -#define ATLAS_DEFAULT_WARP 0 -#endif -#ifndef ATLAS_CUSTOM_WARP -#define ATLAS_CUSTOM_WARP 0 -#endif - INPUT mediump vec2 vTexCoord; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif #endif uniform sampler2D sTexture; -#if IS_REQUIRED_ALPHA_MASKING +#ifdef IS_REQUIRED_ALPHA_MASKING uniform sampler2D sMaskTexture; INPUT mediump vec2 vMaskTexCoord; #endif -#if ATLAS_DEFAULT_WARP +#ifdef ATLAS_DEFAULT_WARP uniform mediump vec4 uAtlasRect; -#elif ATLAS_CUSTOM_WARP +#elif defined(ATLAS_CUSTOM_WARP) // WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT; uniform lowp vec2 wrapMode; #endif @@ -41,14 +25,14 @@ uniform lowp vec2 wrapMode; uniform lowp vec4 uColor; uniform lowp vec3 mixColor; uniform lowp float preMultipliedAlpha; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif -#if ATLAS_CUSTOM_WARP +#ifdef ATLAS_CUSTOM_WARP mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap ) { mediump float coord; @@ -60,7 +44,7 @@ mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp } #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // Global values both rounded corner and borderline use // radius of rounded corner on this quadrant @@ -84,7 +68,7 @@ mediump float gMinInlinePotential = 0.0; void calculateCornerRadius() { -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER gRadius = mix( mix(vCornerRadius.x, vCornerRadius.y, sign(vPosition.x) * 0.5 + 0.5), @@ -98,7 +82,7 @@ void calculatePosition() { gFragmentPosition = abs(vPosition) - vRectSize; gCenterPosition = -gRadius; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5; #endif gDiff = gFragmentPosition - gCenterPosition; @@ -116,7 +100,7 @@ void setupMinMaxPotential() gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth; gMinInlinePotential = gMinOutlinePotential - borderlineWidth; #else @@ -139,7 +123,7 @@ void PreprocessPotential() } #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { mediump float potential = gPotential; @@ -202,7 +186,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) } #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER mediump float calculateCornerOpacity() { mediump float potential = gPotential; @@ -226,9 +210,9 @@ mediump float calculateCornerOpacity() void main() { -#if ATLAS_DEFAULT_WARP +#ifdef ATLAS_DEFAULT_WARP mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw ); -#elif ATLAS_CUSTOM_WARP +#elif defined(ATLAS_CUSTOM_WARP) mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ), wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) ); #else @@ -237,13 +221,13 @@ void main() lowp vec4 textureColor = TEXTURE( sTexture, texCoord ) * vec4( mixColor, 1.0 ) * uColor; -#if IS_REQUIRED_ALPHA_MASKING +#ifdef IS_REQUIRED_ALPHA_MASKING mediump float maskAlpha = TEXTURE(sMaskTexture, vMaskTexCoord).a; textureColor.a *= maskAlpha; textureColor.rgb *= mix(1.0, maskAlpha, preMultipliedAlpha); #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // skip most potential calculate for performance if(abs(vPosition.x) < vOptRectSize.x && abs(vPosition.y) < vOptRectSize.y) { @@ -254,18 +238,18 @@ void main() PreprocessPotential(); #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE textureColor = convertBorderlineColor(textureColor); #endif OUT_COLOR = textureColor; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER mediump float opacity = calculateCornerOpacity(); OUT_COLOR.a *= opacity; OUT_COLOR.rgb *= mix(1.0, opacity, preMultipliedAlpha); #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) } #endif } diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert index d563c78..e4db9ee 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert @@ -1,20 +1,10 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef IS_REQUIRED_ALPHA_MASKING -#define IS_REQUIRED_ALPHA_MASKING 0 -#endif - INPUT mediump vec2 aPosition; OUTPUT mediump vec2 vTexCoord; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif #endif @@ -29,15 +19,15 @@ uniform highp vec2 size; uniform mediump vec4 offsetSizeMode; uniform mediump vec2 origin; uniform mediump vec2 anchorPoint; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER uniform mediump vec4 cornerRadius; uniform mediump float cornerRadiusPolicy; #endif -#if IS_REQUIRED_ALPHA_MASKING +#ifdef IS_REQUIRED_ALPHA_MASKING OUTPUT mediump vec2 vMaskTexCoord; uniform lowp float cropToMask; uniform mediump vec2 maskTextureRatio; @@ -49,13 +39,13 @@ vec4 ComputeVertexPosition() vec2 visualSize = mix(uSize.xy * size, size, offsetSizeMode.zw) + extraSize; vec2 visualOffset = mix(offset, offset/uSize.xy, offsetSizeMode.xy); -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; #endif -#if IS_REQUIRED_ROUNDED_CORNER -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_BORDERLINE mediump float minSize = min(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; #else mediump float minSize = min(visualSize.x, visualSize.y); @@ -67,17 +57,17 @@ vec4 ComputeVertexPosition() vOptRectSize -= 0.2929 * maxRadius + 1.0; #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth); vOptRectSize -= (1.0 - clamp(borderlineOffset, -1.0, 1.0)) * 0.5 * borderlineWidth + 1.0; -#elif IS_REQUIRED_ROUNDED_CORNER +#elif defined(IS_REQUIRED_ROUNDED_CORNER) vPosition = aPosition * visualSize; #else mediump vec2 vPosition = aPosition * visualSize; #endif vec4 finalPixelArea = pixelArea; -#if IS_REQUIRED_ALPHA_MASKING +#ifdef IS_REQUIRED_ALPHA_MASKING finalPixelArea = mix(pixelArea, vec4( vec2(0.5) + (pixelArea.xy - vec2(0.5)) * maskTextureRatio, diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 8dfc168..ba5e0c6 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -256,18 +256,18 @@ Shader ColorVisual::GenerateShader() const std::string fragmentShaderPrefixList; if(roundedCorner) { - vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; } if(blur) { - vertexShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; } if(borderline) { - vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; } shader = Shader::New(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data()); diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index cef1ef4..4bbae24 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -391,21 +391,21 @@ Shader GradientVisual::GenerateShader() const if(roundedCorner) { - vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; } if(borderline) { - vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; } if(radialGradient) { - fragmentShaderPrefixList += "#define RADIAL 1\n"; + fragmentShaderPrefixList += "#define RADIAL\n"; } if(userspaceUnit) { - vertexShaderPrefixList += "#define USER_SPACE 1\n"; + vertexShaderPrefixList += "#define USER_SPACE\n"; } shader = Shader::New(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_GRADIENT_VISUAL_SHADER_VERT.data(), diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp index 16ba9ca..ceb5848 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -52,18 +52,17 @@ enum class ImageVisualRequireFlag : uint32_t ALPHA_MASKING = 1 << 2, }; -static constexpr auto SHADER_TYPE_COUNT = 8u; +static constexpr auto SHADER_TYPE_COUNT = 8u; VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[SHADER_TYPE_COUNT] = -{ - VisualFactoryCache::IMAGE_SHADER, - VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, - VisualFactoryCache::IMAGE_SHADER_BORDERLINE, - VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE, - VisualFactoryCache::IMAGE_SHADER_MASKING, - VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING, - VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING, - VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING -}; + { + VisualFactoryCache::IMAGE_SHADER, + VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, + VisualFactoryCache::IMAGE_SHADER_BORDERLINE, + VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE, + VisualFactoryCache::IMAGE_SHADER_MASKING, + VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING, + VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING, + VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING}; } // unnamed namespace @@ -112,7 +111,7 @@ ImageVisualShaderFactory::~ImageVisualShaderFactory() Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder) { - Shader shader; + Shader shader; VisualFactoryCache::ShaderType shaderType = VisualFactoryCache::IMAGE_SHADER; const auto& atlasing = featureBuilder.mTextureAtlas; @@ -121,8 +120,8 @@ Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, con const auto& borderline = featureBuilder.mBorderline; const auto& alphaMaskingOnRendering = featureBuilder.mAlphaMaskingOnRendering; const auto& changeFragmentShader = (featureBuilder.mTexture && DevelTexture::IsNative(featureBuilder.mTexture)) - ? ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE - : ImageVisualShaderFeature::ChangeFragmentShader::DONT_CHANGE; + ? ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE + : ImageVisualShaderFeature::ChangeFragmentShader::DONT_CHANGE; if(atlasing == ImageVisualShaderFeature::TextureAtlas::ENABLED) { @@ -169,33 +168,33 @@ Shader ImageVisualShaderFactory::GetShader(VisualFactoryCache& factoryCache, con { if(defaultTextureWrapping == ImageVisualShaderFeature::DefaultTextureWrapMode::APPLY) { - fragmentShaderPrefixList += "#define ATLAS_DEFAULT_WARP 1\n"; + fragmentShaderPrefixList += "#define ATLAS_DEFAULT_WARP\n"; } else { - fragmentShaderPrefixList += "#define ATLAS_CUSTOM_WARP 1\n"; + fragmentShaderPrefixList += "#define ATLAS_CUSTOM_WARP\n"; } } else { if(roundedCorner == ImageVisualShaderFeature::RoundedCorner::ENABLED) { - vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; } if(borderline == ImageVisualShaderFeature::Borderline::ENABLED) { - vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; } if(alphaMaskingOnRendering == ImageVisualShaderFeature::AlphaMaskingOnRendering::ENABLED) { - vertexShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ALPHA_MASKING\n"; } } - std::string vertexShader = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_VERT.data()); + std::string vertexShader = std::string(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_VERT.data()); std::string fragmentShader = std::string(Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_IMAGE_VISUAL_SHADER_FRAG.data()); if(changeFragmentShader == ImageVisualShaderFeature::ChangeFragmentShader::NEED_CHANGE)