2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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
8 // http://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/shader-effects/distance-field-effect.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
30 static void Startup();
31 static void Cleanup();
34 void (*tet_startup)() = Startup;
35 void (*tet_cleanup)() = Cleanup;
38 static void UtcDaliDistanceFieldEffectUninitialized();
39 static void UtcDaliDistanceFieldEffectPropertyNames();
40 static void UtcDaliDistanceFieldEffectDefaultValues();
41 static void UtcDaliDistanceFieldEffectCustomValues();
44 POSITIVE_TC_IDX = 0x01,
48 // Add test functionality for all APIs in the class (Positive and Negative)
50 struct tet_testlist tet_testlist[] = {
51 { UtcDaliDistanceFieldEffectUninitialized, NEGATIVE_TC_IDX },
52 { UtcDaliDistanceFieldEffectPropertyNames, POSITIVE_TC_IDX },
53 { UtcDaliDistanceFieldEffectDefaultValues, POSITIVE_TC_IDX },
54 { UtcDaliDistanceFieldEffectCustomValues, POSITIVE_TC_IDX },
59 // Called only once before first test is run.
64 // Called only once after last test is run
69 // Create bitmap image
70 BitmapImage CreateDistanceField()
72 BitmapImage image = BitmapImage::New(256, 256, Pixel::RGBA8888);
73 BitmapImage distanceFieldImage = BitmapImage::New(256, 256, Pixel::L8);
75 PixelBuffer* pixbuf = image.GetBuffer();
77 for(size_t i=0; i<16; i++)
85 // GenerateDistanceFieldMap(distanceFieldImage.GetBuffer(), Size(256, 256), pixbuf, Size(256, 256), 8, 4);
87 return distanceFieldImage;
90 static void UtcDaliDistanceFieldEffectUninitialized()
92 ToolkitTestApplication application;
94 Toolkit::DistanceFieldEffect effect;
98 // New() must be called to create a DistanceField effect or it wont be valid.
99 effect.SetShadow( true );
100 DALI_TEST_CHECK( false );
102 catch (Dali::DaliException& e)
104 // Tests that a negative test of an assertion succeeds
105 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
106 DALI_TEST_CHECK(!effect);
110 static void UtcDaliDistanceFieldEffectPropertyNames()
112 ToolkitTestApplication application;
114 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
116 // Check the names, this names are used in the shaders code,
117 // if they change the shader code has to be updated
118 DALI_TEST_EQUALS( effect.GetColorPropertyName(), "uColor", TEST_LOCATION );
119 DALI_TEST_EQUALS( effect.GetSmoothingPropertyName(), "uSmoothing", TEST_LOCATION );
122 DALI_TEST_EQUALS( effect.GetOutlineEnablePropertyName(), "uDoOutline", TEST_LOCATION );
123 DALI_TEST_EQUALS( effect.GetGlowEnablePropertyName(), "uDoGlow", TEST_LOCATION );
124 DALI_TEST_EQUALS( effect.GetShadowEnablePropertyName(), "uDoShadow", TEST_LOCATION );
126 DALI_TEST_EQUALS( effect.GetGlowBoundaryPropertyName(), "uGlowBoundary", TEST_LOCATION );
127 DALI_TEST_EQUALS( effect.GetGlowColorPropertyName(), "uGlowColor", TEST_LOCATION );
129 DALI_TEST_EQUALS( effect.GetOutlineColorPropertyName(), "uOutlineColor", TEST_LOCATION );
130 DALI_TEST_EQUALS( effect.GetOutlineSizePropertyName(), "uOutlineParams", TEST_LOCATION );
132 DALI_TEST_EQUALS( effect.GetShadowColorPropertyName(), "uShadowColor", TEST_LOCATION );
133 DALI_TEST_EQUALS( effect.GetShadowOffsetPropertyName(), "uShadowOffset", TEST_LOCATION );
137 static void UtcDaliDistanceFieldEffectDefaultValues()
139 ToolkitTestApplication application;
141 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
142 DALI_TEST_CHECK( effect );
144 BitmapImage image = CreateDistanceField();
146 ImageActor actor = ImageActor::New( image );
147 actor.SetSize( 100.0f, 100.0f );
148 actor.SetShaderEffect( effect );
149 Stage::GetCurrent().Add( actor );
151 application.SendNotification();
152 application.Render();
155 application.GetGlAbstraction().CheckUniformValue(
156 effect.GetOutlineEnablePropertyName().c_str(),
160 application.GetGlAbstraction().CheckUniformValue(
161 effect.GetGlowEnablePropertyName().c_str(),
165 application.GetGlAbstraction().CheckUniformValue(
166 effect.GetShadowEnablePropertyName().c_str(),
170 static void UtcDaliDistanceFieldEffectCustomValues()
172 ToolkitTestApplication application;
174 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
175 DALI_TEST_CHECK( effect );
177 BitmapImage image = CreateDistanceField();
179 ImageActor actor = ImageActor::New( image );
180 actor.SetSize( 100.0f, 100.0f );
182 effect.SetShadowColor(Color::YELLOW);
183 effect.SetGlowColor(Color::BLUE);
185 actor.SetShaderEffect( effect );
186 Stage::GetCurrent().Add( actor );
188 application.SendNotification();
189 application.Render();
191 // Gets converted to opengl viewport coordinates
193 application.GetGlAbstraction().CheckUniformValue(
194 effect.GetShadowColorPropertyName().c_str(),
198 application.GetGlAbstraction().CheckUniformValue(
199 effect.GetGlowColorPropertyName().c_str(),