Skip to content

Commit

Permalink
Implement FlutterDesktopViewGetResourceId (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan authored Dec 6, 2023
1 parent 8bdfbfc commit f6da9cc
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flutter/shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ void* FlutterDesktopViewGetNativeHandle(FlutterDesktopViewRef view_ref) {
return view->tizen_view()->GetNativeHandle();
}

uint32_t FlutterDesktopViewGetResourceId(FlutterDesktopViewRef view_ref) {
flutter::FlutterTizenView* view = ViewFromHandle(view_ref);
return view->tizen_view()->GetResourceId();
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view,
int32_t width,
int32_t height) {
Expand Down
4 changes: 4 additions & 0 deletions flutter/shell/platform/tizen/public/flutter_tizen.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ FLUTTER_EXPORT void FlutterDesktopViewDestroy(FlutterDesktopViewRef view);
FLUTTER_EXPORT void* FlutterDesktopViewGetNativeHandle(
FlutterDesktopViewRef view);

// Returns the resource id of current window.
FLUTTER_EXPORT uint32_t
FlutterDesktopViewGetResourceId(FlutterDesktopViewRef view);

// Resizes the view.
// @warning This API is a work-in-progress and may change.
FLUTTER_EXPORT void FlutterDesktopViewResize(FlutterDesktopViewRef view,
Expand Down
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/tizen_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class TizenViewBase {
// Returns the dpi of the screen.
virtual int32_t GetDpi() = 0;

virtual uint32_t GetResourceId() = 0;

virtual void UpdateFlutterCursor(const std::string& kind) = 0;

// Sets the delegate used to communicate state changes from render target to
Expand Down
4 changes: 4 additions & 0 deletions flutter/shell/platform/tizen/tizen_view_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ uintptr_t TizenViewElementary::GetWindowId() {
ecore_evas_ecore_evas_get(evas_object_evas_get(container_)));
}

uint32_t TizenViewElementary::GetResourceId() {
return 0;
}

void TizenViewElementary::Show() {
evas_object_show(container_);
evas_object_show(image_);
Expand Down
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/tizen_view_elementary.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class TizenViewElementary : public TizenView {

uintptr_t GetWindowId() override;

uint32_t GetResourceId() override;

void Show() override;

void UpdateFlutterCursor(const std::string& kind) override;
Expand Down
4 changes: 4 additions & 0 deletions flutter/shell/platform/tizen/tizen_view_nui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ uintptr_t TizenViewNui::GetWindowId() {
return default_window_id_;
}

uint32_t TizenViewNui::GetResourceId() {
return 0;
}

void TizenViewNui::Show() {
// Do nothing.
}
Expand Down
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/tizen_view_nui.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TizenViewNui : public TizenView {

uintptr_t GetWindowId() override;

uint32_t GetResourceId() override;

void Show() override;

void RequestRendering();
Expand Down
60 changes: 60 additions & 0 deletions flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,66 @@ uintptr_t TizenWindowEcoreWl2::GetWindowId() {
return ecore_wl2_window_id_get(ecore_wl2_window_);
}

void HandleResourceId(void* data, tizen_resource* tizen_resource, uint32_t id) {
if (data) {
*reinterpret_cast<uint32_t*>(data) = id;
}
}

uint32_t TizenWindowEcoreWl2::GetResourceId() {
if (resource_id_ > 0) {
return resource_id_;
}
struct wl_registry* registry =
ecore_wl2_display_registry_get(ecore_wl2_display_);
if (!registry) {
FT_LOG(Error) << "Could not retreive wl_registry from the display.";
return 0;
}

static const struct tizen_resource_listener tz_resource_listener = {
HandleResourceId};
Eina_Iterator* iter = ecore_wl2_display_globals_get(ecore_wl2_display_);
Ecore_Wl2_Global* global = nullptr;
struct tizen_surface* surface = nullptr;
EINA_ITERATOR_FOREACH(iter, global) {
if (strcmp(global->interface, "tizen_surface") == 0) {
surface = static_cast<tizen_surface*>(wl_registry_bind(
registry, global->id, &tizen_surface_interface, global->version));
break;
}
}
eina_iterator_free(iter);
if (!surface) {
FT_LOG(Error) << "Failed to initialize the tizen surface.";
return 0;
}

struct tizen_resource* resource = tizen_surface_get_tizen_resource(
surface, ecore_wl2_window_surface_get(ecore_wl2_window_));

if (!resource) {
FT_LOG(Error) << "Failed to get tizen resource.";
tizen_surface_destroy(surface);
return 0;
}

struct wl_event_queue* event_queue = wl_display_create_queue(wl2_display_);
if (!event_queue) {
FT_LOG(Error) << "Failed to create wl_event_queue.";
tizen_resource_destroy(resource);
tizen_surface_destroy(surface);
return 0;
}
wl_proxy_set_queue(reinterpret_cast<struct wl_proxy*>(resource), event_queue);
tizen_resource_add_listener(resource, &tz_resource_listener, &resource_id_);
wl_display_roundtrip_queue(wl2_display_, event_queue);
tizen_resource_destroy(resource);
tizen_surface_destroy(surface);
wl_event_queue_destroy(event_queue);
return resource_id_;
}

void TizenWindowEcoreWl2::SetPreferredOrientations(
const std::vector<int>& rotations) {
ecore_wl2_window_available_rotations_set(ecore_wl2_window_, rotations.data(),
Expand Down
3 changes: 3 additions & 0 deletions flutter/shell/platform/tizen/tizen_window_ecore_wl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TizenWindowEcoreWl2 : public TizenWindow {

uintptr_t GetWindowId() override;

uint32_t GetResourceId() override;

void SetPreferredOrientations(const std::vector<int>& rotations) override;

void BindKeys(const std::vector<std::string>& keys) override;
Expand Down Expand Up @@ -77,6 +79,7 @@ class TizenWindowEcoreWl2 : public TizenWindow {
std::vector<Ecore_Event_Handler*> ecore_event_handlers_;

tizen_policy* tizen_policy_ = nullptr;
uint32_t resource_id_ = 0;
};

} // namespace flutter
Expand Down
4 changes: 4 additions & 0 deletions flutter/shell/platform/tizen/tizen_window_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ uintptr_t TizenWindowElementary::GetWindowId() {
ecore_evas_ecore_evas_get(evas_object_evas_get(elm_win_)));
}

uint32_t TizenWindowElementary::GetResourceId() {
return 0;
}

void TizenWindowElementary::SetPreferredOrientations(
const std::vector<int>& rotations) {
elm_win_wm_rotation_available_rotations_set(elm_win_, rotations.data(),
Expand Down
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/tizen_window_elementary.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class TizenWindowElementary : public TizenWindow {

uintptr_t GetWindowId() override;

uint32_t GetResourceId() override;

void SetPreferredOrientations(const std::vector<int>& rotations) override;

void BindKeys(const std::vector<std::string>& keys) override;
Expand Down

0 comments on commit f6da9cc

Please sign in to comment.