2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/public-api/shader-effects/distance-field-effect.h>
25 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit-test-suite-utils.h>
31 static void Startup();
32 static void Cleanup();
35 void (*tet_startup)() = Startup;
36 void (*tet_cleanup)() = Cleanup;
39 static void UtcDaliDistanceFieldEffectUninitialized();
40 static void UtcDaliDistanceFieldEffectPropertyNames();
41 static void UtcDaliDistanceFieldEffectDefaultValues();
42 static void UtcDaliDistanceFieldEffectCustomValues();
45 POSITIVE_TC_IDX = 0x01,
49 // Add test functionality for all APIs in the class (Positive and Negative)
51 struct tet_testlist tet_testlist[] = {
52 { UtcDaliDistanceFieldEffectUninitialized, NEGATIVE_TC_IDX },
53 { UtcDaliDistanceFieldEffectPropertyNames, POSITIVE_TC_IDX },
54 { UtcDaliDistanceFieldEffectDefaultValues, POSITIVE_TC_IDX },
55 { UtcDaliDistanceFieldEffectCustomValues, POSITIVE_TC_IDX },
60 // Called only once before first test is run.
65 // Called only once after last test is run
70 // Create bitmap image
71 BitmapImage CreateDistanceField()
73 BitmapImage image = BitmapImage::New(256, 256, Pixel::RGBA8888);
74 BitmapImage distanceFieldImage = BitmapImage::New(256, 256, Pixel::L8);
76 PixelBuffer* pixbuf = image.GetBuffer();
78 for(size_t i=0; i<16; i++)
86 // GenerateDistanceFieldMap(distanceFieldImage.GetBuffer(), Size(256, 256), pixbuf, Size(256, 256), 8, 4);
88 return distanceFieldImage;
91 static void UtcDaliDistanceFieldEffectUninitialized()
93 ToolkitTestApplication application;
95 Toolkit::DistanceFieldEffect effect;
99 // New() must be called to create a DistanceField effect or it wont be valid.
100 effect.SetShadow( true );
101 DALI_TEST_CHECK( false );
103 catch (Dali::DaliException& e)
105 // Tests that a negative test of an assertion succeeds
106 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
107 DALI_TEST_CHECK(!effect);
111 static void UtcDaliDistanceFieldEffectPropertyNames()
113 ToolkitTestApplication application;
115 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
117 // Check the names, this names are used in the shaders code,
118 // if they change the shader code has to be updated
119 DALI_TEST_EQUALS( effect.GetColorPropertyName(), "uColor", TEST_LOCATION );
120 DALI_TEST_EQUALS( effect.GetSmoothingPropertyName(), "uSmoothing", TEST_LOCATION );
123 DALI_TEST_EQUALS( effect.GetOutlineEnablePropertyName(), "uDoOutline", TEST_LOCATION );
124 DALI_TEST_EQUALS( effect.GetGlowEnablePropertyName(), "uDoGlow", TEST_LOCATION );
125 DALI_TEST_EQUALS( effect.GetShadowEnablePropertyName(), "uDoShadow", TEST_LOCATION );
127 DALI_TEST_EQUALS( effect.GetGlowBoundaryPropertyName(), "uGlowBoundary", TEST_LOCATION );
128 DALI_TEST_EQUALS( effect.GetGlowColorPropertyName(), "uGlowColor", TEST_LOCATION );
130 DALI_TEST_EQUALS( effect.GetOutlineColorPropertyName(), "uOutlineColor", TEST_LOCATION );
131 DALI_TEST_EQUALS( effect.GetOutlineSizePropertyName(), "uOutlineParams", TEST_LOCATION );
133 DALI_TEST_EQUALS( effect.GetShadowColorPropertyName(), "uShadowColor", TEST_LOCATION );
134 DALI_TEST_EQUALS( effect.GetShadowOffsetPropertyName(), "uShadowOffset", TEST_LOCATION );
138 static void UtcDaliDistanceFieldEffectDefaultValues()
140 ToolkitTestApplication application;
142 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
143 DALI_TEST_CHECK( effect );
145 BitmapImage image = CreateDistanceField();
147 ImageActor actor = ImageActor::New( image );
148 actor.SetSize( 100.0f, 100.0f );
149 actor.SetShaderEffect( effect );
150 Stage::GetCurrent().Add( actor );
152 application.SendNotification();
153 application.Render();
156 application.GetGlAbstraction().CheckUniformValue(
157 effect.GetOutlineEnablePropertyName().c_str(),
161 application.GetGlAbstraction().CheckUniformValue(
162 effect.GetGlowEnablePropertyName().c_str(),
166 application.GetGlAbstraction().CheckUniformValue(
167 effect.GetShadowEnablePropertyName().c_str(),
171 static void UtcDaliDistanceFieldEffectCustomValues()
173 ToolkitTestApplication application;
175 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
176 DALI_TEST_CHECK( effect );
178 BitmapImage image = CreateDistanceField();
180 ImageActor actor = ImageActor::New( image );
181 actor.SetSize( 100.0f, 100.0f );
183 effect.SetShadowColor(Color::YELLOW);
184 effect.SetGlowColor(Color::BLUE);
186 actor.SetShaderEffect( effect );
187 Stage::GetCurrent().Add( actor );
189 application.SendNotification();
190 application.Render();
192 // Gets converted to opengl viewport coordinates
194 application.GetGlAbstraction().CheckUniformValue(
195 effect.GetShadowColorPropertyName().c_str(),
199 application.GetGlAbstraction().CheckUniformValue(
200 effect.GetGlowColorPropertyName().c_str(),