diff --git a/shell/platform/tizen/channels/platform_channel.cc b/shell/platform/tizen/channels/platform_channel.cc index b79f780af3a52..f2f97a6872923 100644 --- a/shell/platform/tizen/channels/platform_channel.cc +++ b/shell/platform/tizen/channels/platform_channel.cc @@ -6,12 +6,15 @@ #include +#include + #include "flutter/shell/platform/common/cpp/json_method_codec.h" #include "flutter/shell/platform/tizen/tizen_log.h" static constexpr char kChannelName[] = "flutter/platform"; -PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger) +PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger, + TizenRenderer* renderer) : channel_(std::make_unique>( messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) { channel_->SetMethodCallHandler( @@ -20,6 +23,9 @@ PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger) std::unique_ptr> result) { HandleMethodCall(call, std::move(result)); }); + // renderer pointer is managed by TizenEmbedderEngine + // !! can be nullptr in case of service application !! + tizen_renderer_ = renderer; } PlatformChannel::~PlatformChannel() {} @@ -43,7 +49,41 @@ void PlatformChannel::HandleMethodCall( } else if (method == "Clipboard.hasStrings") { result->NotImplemented(); } else if (method == "SystemChrome.setPreferredOrientations") { - result->NotImplemented(); + if (tizen_renderer_) { + static const std::string kPortraitUp = "DeviceOrientation.portraitUp"; + static const std::string kPortraitDown = "DeviceOrientation.portraitDown"; + static const std::string kLandscapeLeft = + "DeviceOrientation.landscapeLeft"; + static const std::string kLandscapeRight = + "DeviceOrientation.landscapeRight"; + static const std::map orientation_mapping = { + {kPortraitUp, 0}, + {kLandscapeLeft, 90}, + {kPortraitDown, 180}, + {kLandscapeRight, 270}, + }; + + const auto& list = call.arguments()[0]; + std::vector rotations; + for (rapidjson::Value::ConstValueIterator itr = list.Begin(); + itr != list.End(); ++itr) { + const std::string& rot = itr->GetString(); + FT_LOGD("Passed rotation: %s", rot.c_str()); + rotations.push_back(orientation_mapping.at(rot)); + } + if (rotations.size() == 0) { + // According do docs + // https://api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html + // "The empty list causes the application to defer to the operating + // system default." + FT_LOGD("No rotations passed, using default values"); + rotations = {0, 90, 180, 270}; + } + tizen_renderer_->SetPreferredOrientations(rotations); + result->Success(); + } else { + result->Error("Not supported for service applications"); + } } else if (method == "SystemChrome.setApplicationSwitcherDescription") { result->NotImplemented(); } else if (method == "SystemChrome.setEnabledSystemUIOverlays") { diff --git a/shell/platform/tizen/channels/platform_channel.h b/shell/platform/tizen/channels/platform_channel.h index 078c05f5a2b28..87d2127058954 100644 --- a/shell/platform/tizen/channels/platform_channel.h +++ b/shell/platform/tizen/channels/platform_channel.h @@ -7,15 +7,18 @@ #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" +#include "flutter/shell/platform/tizen/tizen_renderer.h" #include "rapidjson/document.h" class PlatformChannel { public: - explicit PlatformChannel(flutter::BinaryMessenger* messenger); + explicit PlatformChannel(flutter::BinaryMessenger* messenger, + TizenRenderer* renderer); virtual ~PlatformChannel(); private: std::unique_ptr> channel_; + TizenRenderer* tizen_renderer_; void HandleMethodCall( const flutter::MethodCall& call, diff --git a/shell/platform/tizen/tizen_embedder_engine.cc b/shell/platform/tizen/tizen_embedder_engine.cc index ca04bf11d6f4b..5d9655db0d06d 100644 --- a/shell/platform/tizen/tizen_embedder_engine.cc +++ b/shell/platform/tizen/tizen_embedder_engine.cc @@ -218,7 +218,7 @@ bool TizenEmbedderEngine::RunEngine( navigation_channel = std::make_unique( internal_plugin_registrar_->messenger()); platform_channel = std::make_unique( - internal_plugin_registrar_->messenger()); + internal_plugin_registrar_->messenger(), tizen_renderer.get()); settings_channel = std::make_unique( internal_plugin_registrar_->messenger()); text_input_channel = std::make_unique( diff --git a/shell/platform/tizen/tizen_renderer.h b/shell/platform/tizen/tizen_renderer.h index 51864583a8c5a..9627531cedd5e 100644 --- a/shell/platform/tizen/tizen_renderer.h +++ b/shell/platform/tizen/tizen_renderer.h @@ -6,6 +6,7 @@ #define EMBEDDER_TIZEN_RENDERER_H #include +#include class TizenRenderer { public: @@ -36,6 +37,7 @@ class TizenRenderer { virtual void SetRotate(int angle) = 0; virtual void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height, int32_t degree) = 0; + virtual void SetPreferredOrientations(const std::vector& rotations) = 0; protected: explicit TizenRenderer(TizenRenderer::Delegate& delegate); diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc index 38f70de016f09..269a37646b852 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc @@ -585,3 +585,9 @@ void TizenRendererEcoreWl2::SendRotationChangeDone() { ecore_wl2_window_, ecore_wl2_window_rotation_get(ecore_wl2_window_), w, h); } + +void TizenRendererEcoreWl2::SetPreferredOrientations( + const std::vector &rotations) { + ecore_wl2_window_available_rotations_set(ecore_wl2_window_, rotations.data(), + rotations.size()); +} diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.h b/shell/platform/tizen/tizen_renderer_ecore_wl2.h index bb09751d4bef9..8f0e3027d4d7e 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl2.h +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.h @@ -30,6 +30,7 @@ class TizenRendererEcoreWl2 : public TizenRenderer { void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height, int32_t angle) override; void SetRotate(int angle) override; + void SetPreferredOrientations(const std::vector &rotations) override; private: bool InitializeRenderer(); diff --git a/shell/platform/tizen/tizen_renderer_evas_gl.cc b/shell/platform/tizen/tizen_renderer_evas_gl.cc index d7f36b209027f..3da6ab3c139a8 100644 --- a/shell/platform/tizen/tizen_renderer_evas_gl.cc +++ b/shell/platform/tizen/tizen_renderer_evas_gl.cc @@ -709,3 +709,10 @@ void TizenRendererEvasGL::ResizeWithRotation(int32_t x, int32_t y, void TizenRendererEvasGL::SendRotationChangeDone() { elm_win_wm_rotation_manual_rotation_done(evas_window_); } + +void TizenRendererEvasGL::SetPreferredOrientations( + const std::vector& rotations) { + elm_win_wm_rotation_available_rotations_set( + evas_window_, static_cast(rotations.data()), + rotations.size()); +} diff --git a/shell/platform/tizen/tizen_renderer_evas_gl.h b/shell/platform/tizen/tizen_renderer_evas_gl.h index 371b3aaeb8cc0..62fb964b36765 100644 --- a/shell/platform/tizen/tizen_renderer_evas_gl.h +++ b/shell/platform/tizen/tizen_renderer_evas_gl.h @@ -31,6 +31,7 @@ class TizenRendererEvasGL : public TizenRenderer { void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height, int32_t angle) override; void SetRotate(int angle) override; + void SetPreferredOrientations(const std::vector& rotations) override; void* GetImageHandle();