Skip to content

Commit 70d310b

Browse files
committed
Adapt tcore window/clipboard to tizen-core-wl 0.1.34 and harden init
tizen_core_wl_get_connected_display() was removed in tizen-core-wl 0.1.34. The clipboard view-mode path now opens its own display connection via display_create()/display_connect() (display cache shares the same core, so it is equivalent), tracks ownership, and disconnects/destroys/shuts down the connection it owns. This also fixes a pre-existing leak on that path. Fix several robustness issues surfaced in review: - TizenClipboard::SendData(): loop write() to handle partial writes and EINTR instead of dropping clipboard data on short writes. - CreateWindow(): check tizen_core_wl_display_sync()/get_event() return values and bail out instead of proceeding with an invalid event handle. - UpdateFlutterCursor(): drop the TV_PROFILE branch that called the seat cursor setters with a null seat handle. - Route all event-listener registration through an AddEventListener() helper that checks the return value and stores the handle, removing the reused-listener variable that could double-push a stale handle on failure. Verified: builds for arm/arm64 Tizen 11 (--use-tcore) and runs on a Tizen 11 arm64 device (window creation, input, and listeners confirmed via dlog).
1 parent 02d7fa6 commit 70d310b

4 files changed

Lines changed: 86 additions & 49 deletions

File tree

flutter/shell/platform/tizen/tizen_clipboard.cc

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#include <unistd.h>
88

9+
#include <cerrno>
10+
#include <cstring>
11+
912
#include "flutter/shell/platform/tizen/logger.h"
1013
#include "flutter/shell/platform/tizen/tizen_window.h"
1114

@@ -31,11 +34,22 @@ TizenClipboard::TizenClipboard(TizenViewBase* view) {
3134
static_cast<tizen_core_wl_window_h>(window->GetNativeHandle());
3235
tizen_core_wl_window_get_display(tcore_window, &display_);
3336
} else {
34-
// TODO(jsuya): tizen_core_wl_get_connected_display() will be deprecated.
35-
tizen_core_wl_get_connected_display(nullptr, &display_);
37+
if (tizen_core_wl_init() != TIZEN_CORE_WL_ERROR_NONE ||
38+
tizen_core_wl_display_create(&display_) != TIZEN_CORE_WL_ERROR_NONE ||
39+
tizen_core_wl_display_connect(display_, nullptr) !=
40+
TIZEN_CORE_WL_ERROR_NONE) {
41+
FT_LOG(Error) << "Failed to connect display for clipboard.";
42+
display_ = nullptr;
43+
return;
44+
}
45+
owns_display_ = true;
3646
}
3747

38-
tizen_core_wl_display_get_event(display_, &tcore_wl_event_);
48+
if (tizen_core_wl_display_get_event(display_, &tcore_wl_event_) !=
49+
TIZEN_CORE_WL_ERROR_NONE) {
50+
FT_LOG(Error) << "Failed to get event handle for clipboard.";
51+
return;
52+
}
3953

4054
tizen_core_wl_event_add_listener(
4155
tcore_wl_event_, TIZEN_CORE_WL_EVENT_DATA_SOURCE_SEND,
@@ -63,6 +77,12 @@ TizenClipboard::~TizenClipboard() {
6377
if (receive_listener_) {
6478
tizen_core_wl_event_remove_listener(tcore_wl_event_, receive_listener_);
6579
}
80+
81+
if (owns_display_ && display_) {
82+
tizen_core_wl_display_disconnect(display_);
83+
tizen_core_wl_display_destroy(display_);
84+
tizen_core_wl_shutdown();
85+
}
6686
}
6787

6888
void TizenClipboard::SendData(void* event) {
@@ -101,7 +121,20 @@ void TizenClipboard::SendData(void* event) {
101121
return;
102122
}
103123

104-
write(fd, data_.c_str(), data_.length());
124+
const char* buffer = data_.c_str();
125+
size_t remaining = data_.length();
126+
while (remaining > 0) {
127+
ssize_t written = write(fd, buffer, remaining);
128+
if (written < 0) {
129+
if (errno == EINTR) {
130+
continue;
131+
}
132+
FT_LOG(Error) << "Failed to write clipboard data: " << strerror(errno);
133+
break;
134+
}
135+
buffer += written;
136+
remaining -= written;
137+
}
105138
close(fd);
106139
}
107140

flutter/shell/platform/tizen/tizen_clipboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TizenClipboard {
4242
#ifdef USE_TCORE_WL
4343
tizen_core_wl_data_offer_h selection_offer_ = nullptr;
4444
tizen_core_wl_display_h display_ = nullptr;
45+
bool owns_display_ = false;
4546
tizen_core_event_h tcore_wl_event_ = nullptr;
4647
tizen_core_wl_event_listener_h send_listener_ = nullptr;
4748
tizen_core_wl_event_listener_h receive_listener_ = nullptr;

flutter/shell/platform/tizen/tizen_window_tcore_wl.cc

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,17 @@ bool TizenWindowTcoreWl::CreateWindow(void* window_handle) {
211211
tizen_core_wl_display_private_get_wl_display(tcore_wl_display_,
212212
&wl2_display_);
213213

214-
tizen_core_wl_display_sync(tcore_wl_display_);
214+
if (tizen_core_wl_display_sync(tcore_wl_display_) !=
215+
TIZEN_CORE_WL_ERROR_NONE) {
216+
FT_LOG(Error) << "Failed to sync tizen core wl display.";
217+
return false;
218+
}
215219

216-
tizen_core_wl_display_get_event(tcore_wl_display_, &tcore_wl_event_);
220+
if (tizen_core_wl_display_get_event(tcore_wl_display_, &tcore_wl_event_) !=
221+
TIZEN_CORE_WL_ERROR_NONE) {
222+
FT_LOG(Error) << "Could not get tizen core wl event handle.";
223+
return false;
224+
}
217225

218226
int32_t width = 0, height = 0;
219227
GList* output_list = nullptr;
@@ -439,12 +447,21 @@ void TizenWindowTcoreWl::ShowUnsupportedToast() {
439447
}
440448
#endif
441449

442-
void TizenWindowTcoreWl::RegisterEventHandlers() {
450+
void TizenWindowTcoreWl::AddEventListener(tizen_core_wl_event_type_e type,
451+
tizen_core_wl_event_cb callback) {
443452
tizen_core_wl_event_listener_h listener = nullptr;
453+
if (tizen_core_wl_event_add_listener(tcore_wl_event_, type, callback, this,
454+
&listener) != TIZEN_CORE_WL_ERROR_NONE) {
455+
FT_LOG(Error) << "Failed to add tizen core wl event listener.";
456+
return;
457+
}
458+
tcore_event_listeners_.push_back(listener);
459+
}
444460

461+
void TizenWindowTcoreWl::RegisterEventHandlers() {
445462
// Window rotation event.
446-
tizen_core_wl_event_add_listener(
447-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_WINDOW_ROTATION,
463+
AddEventListener(
464+
TIZEN_CORE_WL_EVENT_WINDOW_ROTATION,
448465
[](void* event, tizen_core_wl_event_type_e type, void* data) {
449466
auto* self = static_cast<TizenWindowTcoreWl*>(data);
450467
if (self->view_delegate_) {
@@ -467,14 +484,12 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
467484
self->tcore_wl_window_, degree);
468485
}
469486
}
470-
},
471-
this, &listener);
472-
tcore_event_listeners_.push_back(listener);
487+
});
473488

474489
// Window configure event.
475490
if (!is_vulkan_) {
476-
tizen_core_wl_event_add_listener(
477-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_WINDOW_CONFIGURE_COMPLETE,
491+
AddEventListener(
492+
TIZEN_CORE_WL_EVENT_WINDOW_CONFIGURE_COMPLETE,
478493
[](void* event, tizen_core_wl_event_type_e type, void* data) {
479494
auto* self = static_cast<TizenWindowTcoreWl*>(data);
480495
if (self->view_delegate_) {
@@ -494,14 +509,12 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
494509
self->view_delegate_->OnResize(x, y, w, h);
495510
}
496511
}
497-
},
498-
this, &listener);
499-
tcore_event_listeners_.push_back(listener);
512+
});
500513
}
501514

502515
// Mouse button down.
503-
tizen_core_wl_event_add_listener(
504-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_MOUSE_BUTTON_DOWN,
516+
AddEventListener(
517+
TIZEN_CORE_WL_EVENT_MOUSE_BUTTON_DOWN,
505518
[](void* event, tizen_core_wl_event_type_e type, void* data) {
506519
auto* self = static_cast<TizenWindowTcoreWl*>(data);
507520
#ifdef TV_PROFILE
@@ -543,13 +556,11 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
543556
touch_id);
544557
}
545558
}
546-
},
547-
this, &listener);
548-
tcore_event_listeners_.push_back(listener);
559+
});
549560

550561
// Mouse button up.
551-
tizen_core_wl_event_add_listener(
552-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_MOUSE_BUTTON_UP,
562+
AddEventListener(
563+
TIZEN_CORE_WL_EVENT_MOUSE_BUTTON_UP,
553564
[](void* event, tizen_core_wl_event_type_e type, void* data) {
554565
auto* self = static_cast<TizenWindowTcoreWl*>(data);
555566
if (self->view_delegate_) {
@@ -572,13 +583,11 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
572583
touch_id);
573584
}
574585
}
575-
},
576-
this, &listener);
577-
tcore_event_listeners_.push_back(listener);
586+
});
578587

579588
// Mouse move.
580-
tizen_core_wl_event_add_listener(
581-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_MOUSE_MOVE,
589+
AddEventListener(
590+
TIZEN_CORE_WL_EVENT_MOUSE_MOVE,
582591
[](void* event, tizen_core_wl_event_type_e type, void* data) {
583592
auto* self = static_cast<TizenWindowTcoreWl*>(data);
584593
if (self->view_delegate_) {
@@ -599,13 +608,11 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
599608
touch_id);
600609
}
601610
}
602-
},
603-
this, &listener);
604-
tcore_event_listeners_.push_back(listener);
611+
});
605612

606613
// Mouse wheel.
607-
tizen_core_wl_event_add_listener(
608-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_MOUSE_WHEEL,
614+
AddEventListener(
615+
TIZEN_CORE_WL_EVENT_MOUSE_WHEEL,
609616
[](void* event, tizen_core_wl_event_type_e type, void* data) {
610617
auto* self = static_cast<TizenWindowTcoreWl*>(data);
611618
if (self->view_delegate_) {
@@ -634,13 +641,11 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
634641
kFlutterPointerDeviceKindMouse, 0);
635642
}
636643
}
637-
},
638-
this, &listener);
639-
tcore_event_listeners_.push_back(listener);
644+
});
640645

641646
// Key down.
642-
tizen_core_wl_event_add_listener(
643-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_KEY_DOWN,
647+
AddEventListener(
648+
TIZEN_CORE_WL_EVENT_KEY_DOWN,
644649
[](void* event, tizen_core_wl_event_type_e type, void* data) {
645650
auto* self = static_cast<TizenWindowTcoreWl*>(data);
646651
if (!self->view_delegate_) {
@@ -689,13 +694,11 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
689694
free(keysymbol);
690695
free(compose);
691696
free(dev_identifier);
692-
},
693-
this, &listener);
694-
tcore_event_listeners_.push_back(listener);
697+
});
695698

696699
// Key up.
697-
tizen_core_wl_event_add_listener(
698-
tcore_wl_event_, TIZEN_CORE_WL_EVENT_KEY_UP,
700+
AddEventListener(
701+
TIZEN_CORE_WL_EVENT_KEY_UP,
699702
[](void* event, tizen_core_wl_event_type_e type, void* data) {
700703
auto* self = static_cast<TizenWindowTcoreWl*>(data);
701704
if (!self->view_delegate_) {
@@ -733,9 +736,7 @@ void TizenWindowTcoreWl::RegisterEventHandlers() {
733736
free(keyname);
734737
free(keysymbol);
735738
free(compose);
736-
},
737-
this, &listener);
738-
tcore_event_listeners_.push_back(listener);
739+
});
739740
}
740741

741742
void TizenWindowTcoreWl::UnregisterEventHandlers() {
@@ -910,8 +911,7 @@ void TizenWindowTcoreWl::UpdateFlutterCursor(const std::string& kind) {
910911
kTcoreWlInputCursorThemeName);
911912
tizen_core_wl_seat_set_cursor_name(default_seat, cursor_name.c_str());
912913
} else {
913-
tizen_core_wl_seat_set_cursor_theme(default_seat, "default");
914-
tizen_core_wl_seat_set_cursor_name(default_seat, "left_ptr");
914+
FT_LOG(Error) << "Failed to get default seat; cannot update cursor.";
915915
}
916916
#else
917917
tizen_core_wl_seat_h default_seat = nullptr;

flutter/shell/platform/tizen/tizen_window_tcore_wl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class TizenWindowTcoreWl : public TizenWindow {
8383

8484
void RegisterEventHandlers();
8585

86+
void AddEventListener(tizen_core_wl_event_type_e type,
87+
tizen_core_wl_event_cb callback);
88+
8689
void UnregisterEventHandlers();
8790

8891
void SetNotificationLevel(int level);

0 commit comments

Comments
 (0)