2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/hwc.h>
5 #include <tizen-hwc-client-protocol.h>
7 #define TIZEN_HWC_VERSION 1
9 class MockHwcCompositor : public MockCompositor
13 : MockCompositor(&MockHwcCompositor::TestSetup, this)
15 ds_inf("%s : this(%p)", __func__, this);
17 bHwcDestroyed = false;
18 bSurfaceDestroyed = false;
23 ds_inf("%s : this(%p)", __func__, this);
26 static void TestSetup(void *data)
28 MockHwcCompositor *mockComp =
29 static_cast<MockHwcCompositor *>(data);
30 Compositor *comp = mockComp->compositor;
32 ds_inf("%s: mockComp(%p)", __func__, mockComp);
34 // new surface listener
35 mockComp->mNewSurfaceListener.notify =
36 MockHwcCompositor::NewSurfaceCallback;
37 mockComp->mNewSurfaceListener.parent = mockComp;
38 ds_compositor_add_new_surface_listener(comp->compositor,
39 &mockComp->mNewSurfaceListener);
42 ds_tizen_hwc_create(comp->display);
45 mockComp->mHwcDestroyListener.notify =
46 MockHwcCompositor::HwcDestroyCallback;
47 mockComp->mHwcDestroyListener.parent = mockComp;
48 ds_tizen_hwc_add_destroy_listener(mockComp->mHwc,
49 &mockComp->mHwcDestroyListener);
51 // add_ignore_output_transform listener
52 mockComp->mHwcNewCommitFeedbackListener.notify =
53 MockHwcCompositor::HwcNewCommitFeedbackCallback;
54 mockComp->mHwcNewCommitFeedbackListener.parent = mockComp;
55 ds_tizen_hwc_add_new_commit_feedback_listener(
57 &mockComp->mHwcNewCommitFeedbackListener);
60 static void NewSurfaceCallback(struct wl_listener *listener, void *data)
62 MockHwcCompositor *mockComp =
63 reinterpret_cast<NewSurfaceListener *>(listener)->parent;
64 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
66 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
68 mockComp->mSurface = surface;
70 // del surface listener
71 mockComp->mDelSurfaceListener.notify =
72 MockHwcCompositor::DelSurfaceCallback;
73 mockComp->mDelSurfaceListener.parent = mockComp;
74 ds_surface_add_destroy_listener(surface,
75 &mockComp->mDelSurfaceListener);
78 static void DelSurfaceCallback(struct wl_listener *listener, void *data)
80 MockHwcCompositor *mockComp =
81 reinterpret_cast<DelSurfaceListener *>(listener)->parent;
82 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
84 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
86 if (ds_surface_get_wl_resource(mockComp->mSurface) ==
87 ds_surface_get_wl_resource(surface)) {
88 ds_inf("%s: surface is deleted.", __func__);
89 mockComp->bSurfaceDestroyed = true;
93 static void HwcDestroyCallback(struct wl_listener *listener, void *data)
95 ds_inf("%s", __func__);
97 MockHwcCompositor *mockComp =
98 reinterpret_cast<HwcDestroyListener *>(listener)->parent;
100 mockComp->bHwcDestroyed = true;
103 static void HwcNewCommitFeedbackCallback(struct wl_listener *listener,
106 ds_inf("%s", __func__);
108 MockHwcCompositor *mockComp =
109 reinterpret_cast<HwcNewCommitFeedbackListener *>(listener)->parent;
110 struct ds_tizen_hwc_commit_feedback *commitFeedback =
111 static_cast<struct ds_tizen_hwc_commit_feedback *>(data);
113 ds_inf("%s: mockComp(%p), commitFeedback(%p)", __func__, mockComp, commitFeedback);
115 mockComp->mCommitFeedback = commitFeedback;
117 ds_tizen_hwc_commit_feedback_get_surface(mockComp->mCommitFeedback);
119 mockComp->mHwcCommitFeedbackDestroyListener.notify =
120 MockHwcCompositor::HwcCommitFeedbackDestroyCallback;
121 mockComp->mHwcCommitFeedbackDestroyListener.parent = mockComp;
122 ds_tizen_hwc_commit_feedback_add_destroy_listener(mockComp->mCommitFeedback,
123 &mockComp->mHwcCommitFeedbackDestroyListener);
126 static void HwcCommitFeedbackDestroyCallback(struct wl_listener *listener,
129 ds_inf("%s", __func__);
131 MockHwcCompositor *mockComp =
132 reinterpret_cast<HwcCommitFeedbackDestroyListener *>(listener)->parent;
133 struct ds_tizen_hwc_commit_feedback *commitFeedback =
134 static_cast<struct ds_tizen_hwc_commit_feedback *>(data);
136 ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, commitFeedback);
138 if (mockComp->mCommitFeedback == commitFeedback) {
139 ds_inf("%s: commitFeedback is deleted.", __func__);
143 void SendHwcCommitFeedbackCommitted(void)
145 ds_inf("%s", __func__);
147 ds_tizen_hwc_commit_feedback_send_committed(mCommitFeedback);
150 void SendHwcCommitFeedbackDiscarded(void)
152 ds_inf("%s", __func__);
154 ds_tizen_hwc_commit_feedback_send_discarded(mCommitFeedback);
159 bool bSurfaceDestroyed;
162 struct ds_tizen_hwc *mHwc;
164 struct HwcDestroyListener : ::wl_listener {
165 MockHwcCompositor *parent;
167 HwcDestroyListener mHwcDestroyListener;
169 struct ds_surface *mSurface;
171 struct NewSurfaceListener : ::wl_listener {
172 MockHwcCompositor *parent;
174 NewSurfaceListener mNewSurfaceListener;
176 struct DelSurfaceListener : ::wl_listener {
177 MockHwcCompositor *parent;
179 DelSurfaceListener mDelSurfaceListener;
181 struct ds_tizen_hwc_commit_feedback *mCommitFeedback;
183 struct HwcNewCommitFeedbackListener : ::wl_listener {
184 MockHwcCompositor *parent;
186 HwcNewCommitFeedbackListener mHwcNewCommitFeedbackListener;
188 struct HwcCommitFeedbackDestroyListener : ::wl_listener {
189 MockHwcCompositor *parent;
191 HwcCommitFeedbackDestroyListener mHwcCommitFeedbackDestroyListener;
194 class MockHwcClient : public MockClient
198 : bCommittedEvent(false),
199 bDiscardedEvent(false),
200 compositorRes(nullptr),
203 MockHwcClient(const struct wl_registry_listener *listener)
204 : MockClient(listener, this)
206 ds_inf("%s", __func__);
210 ds_inf("%s", __func__);
213 void SetWlCompositor(struct wl_compositor *globalRes)
215 ds_inf("%s", __func__);
217 compositorRes = globalRes;
220 struct wl_compositor *GetWlCompositor()
222 ds_inf("%s", __func__);
224 return compositorRes;
227 void SetTizenHwc(struct tizen_hwc *resource)
229 ds_inf("%s", __func__);
231 tizenHwcRes = resource;
234 struct tizen_hwc *GetTizenHwc()
236 ds_inf("%s", __func__);
242 bool bCommittedEvent;
243 bool bDiscardedEvent;
245 struct wl_compositor *compositorRes;
246 struct tizen_hwc *tizenHwcRes;
250 client_registry_cb_global(void *data, struct wl_registry *registry,
251 uint32_t name, const char *interface, uint32_t version)
253 ds_inf("%s", __func__);
255 MockHwcClient *client = static_cast<MockHwcClient *>(data);
256 struct wl_compositor *compositor_res;
257 struct tizen_hwc *tizen_hwc_res;
259 if (!strcmp(interface, "wl_compositor")) {
260 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
261 name, &wl_compositor_interface, 1);
262 if (compositor_res == nullptr) {
263 ds_err("wl_registry_bind() failed. wl_compositor resource.");
266 client->SetWlCompositor(compositor_res);
267 } else if (!strcmp(interface, "tizen_hwc")) {
268 tizen_hwc_res = (struct tizen_hwc *)wl_registry_bind(registry,
269 name, &tizen_hwc_interface, TIZEN_HWC_VERSION);
270 if (tizen_hwc_res == nullptr) {
271 ds_err("wl_registry_bind() failed. tizen_hwc resource.");
274 client->SetTizenHwc(tizen_hwc_res);
279 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
282 ds_inf("%s", __func__);
284 MockHwcClient *client = static_cast<MockHwcClient *>(data);
285 struct wl_compositor *compositor_res = client->GetWlCompositor();
286 struct tizen_hwc *tizen_hwc_res = client->GetTizenHwc();
288 tizen_hwc_destroy(tizen_hwc_res);
289 wl_compositor_destroy(compositor_res);
292 static const struct wl_registry_listener registry_listener = {
293 .global = client_registry_cb_global,
294 .global_remove = client_registry_cb_global_remove
297 class HwcTest : public ::testing::Test
300 void SetUp(void) override;
301 void TearDown(void) override;
303 MockHwcCompositor *comp;
304 MockHwcClient *client;
305 struct wl_compositor *compositorRes;
306 struct tizen_hwc *tizenHwcRes;
307 struct wl_surface *surfaceRes;
308 struct tizen_hwc_commit_feedback *tizenHwcCommitFeedbackRes;
312 tizen_hwc_commit_feedback_cb_committed(void *data,
313 struct tizen_hwc_commit_feedback *hwc_commit_feedback,
316 ds_inf("%s", __func__);
318 MockHwcClient *client = static_cast<MockHwcClient *>(data);
320 client->bCommittedEvent = true;
322 tizen_hwc_commit_feedback_destroy(hwc_commit_feedback);
326 tizen_hwc_commit_feedback_cb_discarded(void *data,
327 struct tizen_hwc_commit_feedback *hwc_commit_feedback,
330 ds_inf("%s", __func__);
332 MockHwcClient *client = static_cast<MockHwcClient *>(data);
334 client->bDiscardedEvent = true;
336 tizen_hwc_commit_feedback_destroy(hwc_commit_feedback);
339 static const struct tizen_hwc_commit_feedback_listener tizen_hwc_commit_feedback_cb_listener = {
340 .committed = tizen_hwc_commit_feedback_cb_committed,
341 .discarded = tizen_hwc_commit_feedback_cb_discarded,
347 ds_inf("%s", __func__);
349 comp = new MockHwcCompositor();
350 client = new MockHwcClient(®istry_listener);
351 compositorRes = client->GetWlCompositor();
352 tizenHwcRes = client->GetTizenHwc();
353 surfaceRes = wl_compositor_create_surface(compositorRes);
355 tizenHwcCommitFeedbackRes =
356 tizen_hwc_create_commit_feedback(tizenHwcRes, surfaceRes, 1);
358 tizen_hwc_commit_feedback_add_listener(tizenHwcCommitFeedbackRes,
359 &tizen_hwc_commit_feedback_cb_listener, client);
365 HwcTest::TearDown(void)
367 ds_inf("%s", __func__);
369 wl_surface_destroy(surfaceRes);
371 EXPECT_TRUE(comp->bSurfaceDestroyed);
377 TEST_F(HwcTest, Create_P)
382 TEST_F(HwcTest, Ev_TizenHwcCommitFeedbackCommitted)
384 comp->SendHwcCommitFeedbackCommitted();
388 EXPECT_TRUE(client->bCommittedEvent);
391 TEST_F(HwcTest, Ev_TizenHwcCommitFeedbackDiscared)
393 comp->SendHwcCommitFeedbackDiscarded();
397 EXPECT_TRUE(client->bDiscardedEvent);