[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-ImageVisualShaderFeatureBuilder.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <toolkit-event-thread-callback.h>
24 #include <toolkit-text-utils.h>
25
26 #include <dali-toolkit/internal/visuals/image-visual-shader-feature-builder.h>
27
28 #include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
29 #include <dummy-visual.h>
30
31 using namespace Dali;
32 using namespace Toolkit;
33
34 int UtcImageVisualShaderFeatureBuilderSetGetProperty01(void)
35 {
36   ToolkitTestApplication application;
37   tet_infoline("Register an ImageVisual and and perform an Action on Visual directly");
38   auto featureBuilder = Dali::Toolkit::Internal::ImageVisualShaderFeatureBuilder()
39                           .EnableTextureAtlas(Dali::Toolkit::Internal::ImageVisualShaderFeature::TextureAtlas::ENABLED)
40                           .ApplyDefaultTextureWrapMode(true);
41
42   std::string vertexPrefixList;
43   std::string fragmentPrefixList;
44   featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
45   featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
46
47   DALI_TEST_EQUALS(vertexPrefixList, std::string(""), TEST_LOCATION);
48   DALI_TEST_EQUALS(fragmentPrefixList, std::string("#define ATLAS_DEFAULT_WARP\n"), TEST_LOCATION);
49
50   featureBuilder = featureBuilder.ApplyDefaultTextureWrapMode(false);
51
52   vertexPrefixList.clear();
53   fragmentPrefixList.clear();
54   featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
55   featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
56
57   DALI_TEST_EQUALS(vertexPrefixList, std::string(""), TEST_LOCATION);
58   DALI_TEST_EQUALS(fragmentPrefixList, std::string("#define ATLAS_CUSTOM_WARP\n"), TEST_LOCATION);
59   END_TEST;
60 }
61
62 int UtcImageVisualShaderFeatureBuilderSetGetProperty02(void)
63 {
64   ToolkitTestApplication application;
65   tet_infoline("Register an ImageVisual and and perform an Action on Visual directly");
66   auto featureBuilder = Dali::Toolkit::Internal::ImageVisualShaderFeatureBuilder()
67                           .EnableRoundedCorner(true)
68                           .EnableBorderline(true)
69                           .EnableAlphaMaskingOnRendering(true)
70                           .EnableYuvToRgb(true, false);
71
72   std::string vertexPrefixList;
73   std::string fragmentPrefixList;
74   featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
75   featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
76
77   std::string vertexPrefixListResult;
78   vertexPrefixListResult += "#define IS_REQUIRED_ROUNDED_CORNER\n";
79   vertexPrefixListResult += "#define IS_REQUIRED_BORDERLINE\n";
80   vertexPrefixListResult += "#define IS_REQUIRED_ALPHA_MASKING\n";
81
82   std::string fragmentPrefixListResult;
83   fragmentPrefixListResult += "#define IS_REQUIRED_ROUNDED_CORNER\n";
84   fragmentPrefixListResult += "#define IS_REQUIRED_BORDERLINE\n";
85   fragmentPrefixListResult += "#define IS_REQUIRED_ALPHA_MASKING\n";
86
87   DALI_TEST_EQUALS(vertexPrefixList, vertexPrefixListResult, TEST_LOCATION);
88   DALI_TEST_EQUALS(fragmentPrefixList, fragmentPrefixListResult, TEST_LOCATION);
89
90   featureBuilder = featureBuilder.EnableAlphaMaskingOnRendering(false);
91
92   vertexPrefixList.clear();
93   fragmentPrefixList.clear();
94   featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
95   featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
96
97   vertexPrefixListResult.clear();
98   vertexPrefixListResult += "#define IS_REQUIRED_ROUNDED_CORNER\n";
99   vertexPrefixListResult += "#define IS_REQUIRED_BORDERLINE\n";
100
101   fragmentPrefixListResult.clear();
102   fragmentPrefixListResult += "#define IS_REQUIRED_ROUNDED_CORNER\n";
103   fragmentPrefixListResult += "#define IS_REQUIRED_BORDERLINE\n";
104   fragmentPrefixListResult += "#define IS_REQUIRED_YUV_TO_RGB\n";
105
106   DALI_TEST_EQUALS(vertexPrefixList, vertexPrefixListResult, TEST_LOCATION);
107   DALI_TEST_EQUALS(fragmentPrefixList, fragmentPrefixListResult, TEST_LOCATION);
108
109   featureBuilder = featureBuilder.EnableYuvToRgb(true, true);
110
111   vertexPrefixList.clear();
112   fragmentPrefixList.clear();
113   featureBuilder.GetVertexShaderPrefixList(vertexPrefixList);
114   featureBuilder.GetFragmentShaderPrefixList(fragmentPrefixList);
115
116   fragmentPrefixListResult.clear();
117   fragmentPrefixListResult += "#define IS_REQUIRED_ROUNDED_CORNER\n";
118   fragmentPrefixListResult += "#define IS_REQUIRED_BORDERLINE\n";
119   fragmentPrefixListResult += "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n";
120
121   DALI_TEST_EQUALS(vertexPrefixList, vertexPrefixListResult, TEST_LOCATION);
122   DALI_TEST_EQUALS(fragmentPrefixList, fragmentPrefixListResult, TEST_LOCATION);
123   END_TEST;
124 }