2 * Copyright (c) 2022 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/actors/drawable-actor.h>
23 bool Render(const RenderCallbackInput& inputData)
25 // Store the size of rendered area
26 size = inputData.size;
31 bool RenderWithTextures(const RenderCallbackInput& inputData)
33 // Store the size of rendered area
34 size = inputData.size;
36 auto count = inputData.textureBindings.size();
38 // test whether number of textures matches 1
39 DALI_TEST_EQUALS(count, 1, TEST_LOCATION);
47 int UtcDaliRendererSetRenderCallbackP(void)
49 tet_infoline("Testing Renderer:LSetRenderCallback()");
50 TestApplication application;
52 DrawableObject drawable{};
54 auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
56 Actor actor = Actor::New();
57 application.GetScene().Add(actor);
59 actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
61 auto renderer = Renderer::New(*callback);
62 actor.AddRenderer(renderer);
64 // flush the queue and render once
65 application.SendNotification();
68 // Check the size (whether callback has been called)
69 auto size(drawable.size);
70 DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
75 int UtcDaliDrawableActor1P(void)
77 tet_infoline("Testing DrawableActor");
78 TestApplication application;
80 DrawableObject drawable{};
82 auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
84 DrawableActor drawableActor = DrawableActor::New(*callback);
85 application.GetScene().Add(drawableActor);
87 drawableActor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
89 // flush the queue and render once
90 application.SendNotification();
93 // Check the size (whether callback has been called)
94 DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
99 int UtcRenderCallbackTextureBindingP(void)
101 tet_infoline("Testing RenderCallback texture bindings");
102 TestApplication application;
104 DrawableObject drawable{};
106 auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::RenderWithTextures);
109 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
110 auto* data = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
111 PixelData pixelData = PixelData::New(data, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
112 texture.Upload(pixelData);
114 std::vector<Texture> texturesToBind;
115 texturesToBind.push_back(texture);
116 callback->BindTextureResources(texturesToBind);
118 DrawableActor drawableActor = DrawableActor::New(*callback);
119 application.GetScene().Add(drawableActor);
121 drawableActor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
123 // flush the queue and render once
124 application.SendNotification();
125 application.Render();
127 // Check the size (whether callback has been called)
128 DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);