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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <mesh-builder.h>
25 // Internal headers are allowed here
26 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
27 #include <dali/internal/event/rendering/renderer-impl.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/rendering/scene-graph-renderer.h>
33 void utc_dali_internal_handles_startup()
35 test_return_value = TET_UNDEF;
38 void utc_dali_internal_handles_cleanup()
40 test_return_value = TET_PASS;
43 int UtcDaliCameraActorConstructorRefObject(void)
45 TestApplication application;
46 tet_infoline("Testing Dali::CameraActor::CameraActor(Internal::CameraActor*)");
48 CameraActor actor(NULL);
50 DALI_TEST_CHECK(!actor);
56 struct DerivedRenderer : public Dali::Internal::Renderer
58 static IntrusivePtr<DerivedRenderer> New()
60 auto sceneObjectKey = Dali::Internal::SceneGraph::Renderer::NewKey();
61 IntrusivePtr<DerivedRenderer> impl = new DerivedRenderer(sceneObjectKey.Get());
63 // transfer scene object ownership to update manager
64 Internal::EventThreadServices& eventThreadServices = impl->GetEventThreadServices();
65 Internal::SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
66 AddRendererMessage(updateManager, sceneObjectKey);
67 eventThreadServices.RegisterObject(impl.Get());
71 DerivedRenderer(const Dali::Internal::SceneGraph::Renderer* sceneObject)
72 : Internal::Renderer(sceneObject)
81 struct DerivedRenderer : public Renderer
83 static DerivedRenderer New(Geometry geometry, Shader shader)
85 IntrusivePtr<Impl::DerivedRenderer> impl = Impl::DerivedRenderer::New();
86 impl->SetGeometry(GetImplementation(geometry));
87 impl->SetShader(GetImplementation(shader));
88 DerivedRenderer custom(impl.Get());
91 DerivedRenderer() = default;
92 ~DerivedRenderer() = default;
93 DerivedRenderer(Impl::DerivedRenderer* impl)
99 int UtcDaliInternalHandleRendererPropertyComponents(void)
101 TestApplication application;
103 Dali::TypeRegistration typeRegistration(typeid(DerivedRenderer), typeid(Dali::Renderer), nullptr);
105 Shader shader = Shader::New("VertexSource", "FragmentSource");
106 Geometry geometry = CreateQuadGeometry();
107 auto derived = DerivedRenderer::New(geometry, shader);
108 Actor actor = Actor::New();
109 actor.AddRenderer(derived);
110 application.GetScene().Add(actor);
112 const Property::Index foobarIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX;
113 const Property::Index fooIndex = foobarIndex + 1;
114 const Property::Index barIndex = foobarIndex + 2;
116 const Property::Index rgbIndex = foobarIndex + 3;
117 const Property::Index redIndex = rgbIndex + 1;
118 const Property::Index greenIndex = rgbIndex + 2;
119 const Property::Index blueIndex = rgbIndex + 3;
121 const Property::Index rgbaIndex = rgbIndex + 4;
122 const Property::Index red2Index = rgbaIndex + 1;
123 const Property::Index green2Index = rgbaIndex + 2;
124 const Property::Index blue2Index = rgbaIndex + 3;
125 const Property::Index alphaIndex = rgbaIndex + 4;
127 // If we don't properly register a scene graph property for the "parent" type,
128 // then Object::GetSceneGraphProperty registers a float type for the child...
130 AnimatablePropertyRegistration(typeRegistration, "Foobar", foobarIndex, Vector2(10.0f, 20.0f));
131 AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.x", fooIndex, foobarIndex, 0);
132 AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.y", barIndex, foobarIndex, 1);
134 AnimatablePropertyRegistration(typeRegistration, "RGB", rgbIndex, Vector3(0.5f, 0.5, 1.0f));
135 AnimatablePropertyComponentRegistration(typeRegistration, "RGB.red", redIndex, rgbIndex, 0);
136 AnimatablePropertyComponentRegistration(typeRegistration, "RGB.green", greenIndex, rgbIndex, 1);
137 AnimatablePropertyComponentRegistration(typeRegistration, "RGB.blue", blueIndex, rgbIndex, 2);
139 AnimatablePropertyRegistration(typeRegistration, "RGBA", rgbaIndex, Vector4(0.5f, 0.5, 1.0f, 1.0f));
140 AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.red", red2Index, rgbaIndex, 0);
141 AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.green", green2Index, rgbaIndex, 1);
142 AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.blue", blue2Index, rgbaIndex, 2);
143 AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.alpha", alphaIndex, rgbaIndex, 3);
145 derived.SetProperty(foobarIndex, Vector2(9.0f, 10.0f));
146 derived.SetProperty(fooIndex, 100.0f);
147 derived.SetProperty(barIndex, 200.0f);
149 derived.SetProperty(rgbIndex, Vector3(0.9f, 0.9f, 0.1f));
150 derived.SetProperty(redIndex, 1.0f);
151 derived.SetProperty(greenIndex, 1.0f);
152 derived.SetProperty(blueIndex, 1.0f);
154 derived.SetProperty(rgbaIndex, Color::WHITE * 0.5f);
155 derived.SetProperty(red2Index, Color::SEA_GREEN.r);
156 derived.SetProperty(green2Index, Color::SEA_GREEN.g);
157 derived.SetProperty(blue2Index, Color::SEA_GREEN.b);
158 derived.SetProperty(alphaIndex, Color::SEA_GREEN.a);
160 application.SendNotification();
161 application.Render(16);
163 Vector2 foobar = derived.GetCurrentProperty<Vector2>(foobarIndex);
164 DALI_TEST_EQUALS(foobar, Vector2(100.0f, 200.0f), 0.0001f, TEST_LOCATION);
166 Vector3 colour = derived.GetCurrentProperty<Vector3>(rgbIndex);
167 DALI_TEST_EQUALS(colour, Vector3(1.0f, 1.0f, 1.0f), 0.0001f, TEST_LOCATION);
169 Vector4 col2 = derived.GetCurrentProperty<Vector4>(rgbaIndex);
170 DALI_TEST_EQUALS(col2, Color::SEA_GREEN, 0.0001f, TEST_LOCATION);