diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 1ea9bcf30bb00..d0321482c6751 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -94,9 +94,9 @@ template("embedder_for_profile") { "channels/settings_channel.cc", "channels/text_input_channel.cc", "external_texture_gl.cc", + "flutter_tizen_engine.cc", "flutter_tizen.cc", "key_event_handler.cc", - "tizen_embedder_engine.cc", "tizen_event_loop.cc", "tizen_log.cc", "tizen_renderer.cc", diff --git a/shell/platform/tizen/channels/lifecycle_channel.h b/shell/platform/tizen/channels/lifecycle_channel.h index ac1bb84057528..a8a722affc943 100644 --- a/shell/platform/tizen/channels/lifecycle_channel.h +++ b/shell/platform/tizen/channels/lifecycle_channel.h @@ -11,6 +11,7 @@ class LifecycleChannel { public: explicit LifecycleChannel(FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine); virtual ~LifecycleChannel(); + void AppIsInactive(); void AppIsResumed(); void AppIsPaused(); diff --git a/shell/platform/tizen/channels/localization_channel.cc b/shell/platform/tizen/channels/localization_channel.cc index fcd2d146dfba8..ad44541a880c4 100644 --- a/shell/platform/tizen/channels/localization_channel.cc +++ b/shell/platform/tizen/channels/localization_channel.cc @@ -73,8 +73,8 @@ void LocalizationChannel::SendPlatformResolvedLocale() { return; } - FlutterLocale* flutterLocale = GetFlutterLocale(locale); - if (!flutterLocale) { + FlutterLocale* flutter_locale = GetFlutterLocale(locale); + if (!flutter_locale) { FT_LOGE("Language code is required but not present."); return; } @@ -86,14 +86,15 @@ void LocalizationChannel::SendPlatformResolvedLocale() { document.AddMember("method", "setPlatformResolvedLocale", allocator); rapidjson::Value language_code, country_code, script_code, variant_code; - language_code.SetString(flutterLocale->language_code, allocator); + language_code.SetString(flutter_locale->language_code, allocator); country_code.SetString( - flutterLocale->country_code ? flutterLocale->country_code : "", + flutter_locale->country_code ? flutter_locale->country_code : "", allocator); script_code.SetString( - flutterLocale->script_code ? flutterLocale->script_code : "", allocator); + flutter_locale->script_code ? flutter_locale->script_code : "", + allocator); variant_code.SetString( - flutterLocale->variant_code ? flutterLocale->variant_code : "", + flutter_locale->variant_code ? flutter_locale->variant_code : "", allocator); rapidjson::Value args(rapidjson::kArrayType); @@ -118,7 +119,7 @@ void LocalizationChannel::SendPlatformResolvedLocale() { message.response_handle = nullptr; FlutterEngineSendPlatformMessage(flutter_engine_, &message); - DestroyFlutterLocale(flutterLocale); + DestroyFlutterLocale(flutter_locale); } FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { @@ -166,39 +167,39 @@ FlutterLocale* LocalizationChannel::GetFlutterLocale(const char* locale) { variant[bufSize] = '\0'; } - FlutterLocale* flutterLocale = new FlutterLocale; - flutterLocale->struct_size = sizeof(FlutterLocale); - flutterLocale->language_code = language; - flutterLocale->country_code = country; - flutterLocale->script_code = script; - flutterLocale->variant_code = variant; + FlutterLocale* flutter_locale = new FlutterLocale; + flutter_locale->struct_size = sizeof(FlutterLocale); + flutter_locale->language_code = language; + flutter_locale->country_code = country; + flutter_locale->script_code = script; + flutter_locale->variant_code = variant; - return flutterLocale; + return flutter_locale; } -void LocalizationChannel::DestroyFlutterLocale(FlutterLocale* flutterLocale) { - if (flutterLocale) { - if (flutterLocale->language_code) { - delete[] flutterLocale->language_code; - flutterLocale->language_code = nullptr; +void LocalizationChannel::DestroyFlutterLocale(FlutterLocale* flutter_locale) { + if (flutter_locale) { + if (flutter_locale->language_code) { + delete[] flutter_locale->language_code; + flutter_locale->language_code = nullptr; } - if (flutterLocale->country_code) { - delete[] flutterLocale->country_code; - flutterLocale->country_code = nullptr; + if (flutter_locale->country_code) { + delete[] flutter_locale->country_code; + flutter_locale->country_code = nullptr; } - if (flutterLocale->script_code) { - delete[] flutterLocale->script_code; - flutterLocale->script_code = nullptr; + if (flutter_locale->script_code) { + delete[] flutter_locale->script_code; + flutter_locale->script_code = nullptr; } - if (flutterLocale->variant_code) { - delete[] flutterLocale->variant_code; - flutterLocale->variant_code = nullptr; + if (flutter_locale->variant_code) { + delete[] flutter_locale->variant_code; + flutter_locale->variant_code = nullptr; } - delete flutterLocale; - flutterLocale = nullptr; + delete flutter_locale; + flutter_locale = nullptr; } } diff --git a/shell/platform/tizen/channels/localization_channel.h b/shell/platform/tizen/channels/localization_channel.h index ce65ca670c286..af184540fcd94 100644 --- a/shell/platform/tizen/channels/localization_channel.h +++ b/shell/platform/tizen/channels/localization_channel.h @@ -12,13 +12,15 @@ class LocalizationChannel { explicit LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine); virtual ~LocalizationChannel(); + void SendLocales(); private: void SendPlatformResolvedLocale(); FlutterLocale* GetFlutterLocale(const char* locale); - void DestroyFlutterLocale(FlutterLocale* flutterLocale); + void DestroyFlutterLocale(FlutterLocale* flutter_locale); FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_; }; + #endif // EMBEDDER_LOCALIZATION_CHANNEL_H_ diff --git a/shell/platform/tizen/channels/platform_channel.cc b/shell/platform/tizen/channels/platform_channel.cc index f2f97a6872923..ccc330d6a09f9 100644 --- a/shell/platform/tizen/channels/platform_channel.cc +++ b/shell/platform/tizen/channels/platform_channel.cc @@ -16,16 +16,14 @@ static constexpr char kChannelName[] = "flutter/platform"; PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger, TizenRenderer* renderer) : channel_(std::make_unique>( - messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) { + messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())), + renderer_(renderer) { channel_->SetMethodCallHandler( [this]( const flutter::MethodCall& call, 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() {} @@ -49,7 +47,7 @@ void PlatformChannel::HandleMethodCall( } else if (method == "Clipboard.hasStrings") { result->NotImplemented(); } else if (method == "SystemChrome.setPreferredOrientations") { - if (tizen_renderer_) { + if (renderer_) { static const std::string kPortraitUp = "DeviceOrientation.portraitUp"; static const std::string kPortraitDown = "DeviceOrientation.portraitDown"; static const std::string kLandscapeLeft = @@ -79,7 +77,7 @@ void PlatformChannel::HandleMethodCall( FT_LOGD("No rotations passed, using default values"); rotations = {0, 90, 180, 270}; } - tizen_renderer_->SetPreferredOrientations(rotations); + renderer_->SetPreferredOrientations(rotations); result->Success(); } else { result->Error("Not supported for service applications"); diff --git a/shell/platform/tizen/channels/platform_channel.h b/shell/platform/tizen/channels/platform_channel.h index 87d2127058954..50b73756b4863 100644 --- a/shell/platform/tizen/channels/platform_channel.h +++ b/shell/platform/tizen/channels/platform_channel.h @@ -17,12 +17,15 @@ class PlatformChannel { virtual ~PlatformChannel(); private: - std::unique_ptr> channel_; - TizenRenderer* tizen_renderer_; - void HandleMethodCall( const flutter::MethodCall& call, std::unique_ptr> result); + + std::unique_ptr> channel_; + + // A reference to the renderer object managed by FlutterTizenEngine. + // This can be nullptr if the engine is running in headless mode. + TizenRenderer* renderer_; }; #endif // EMBEDDER_PLATFORM_CHANNEL_H_ diff --git a/shell/platform/tizen/channels/platform_view_channel.cc b/shell/platform/tizen/channels/platform_view_channel.cc index 0cd0825ca0b07..2dd83e0703c00 100644 --- a/shell/platform/tizen/channels/platform_view_channel.cc +++ b/shell/platform/tizen/channels/platform_view_channel.cc @@ -8,8 +8,8 @@ #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h" #include "flutter/shell/platform/common/cpp/json_method_codec.h" #include "flutter/shell/platform/tizen/channels/text_input_channel.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/public/flutter_platform_view.h" -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" static constexpr char kChannelName[] = "flutter/platform_views"; @@ -68,7 +68,7 @@ flutter::EncodableList ExtractListFromMap( } PlatformViewChannel::PlatformViewChannel(flutter::BinaryMessenger* messenger, - TizenEmbedderEngine* engine) + FlutterTizenEngine* engine) : engine_(engine), channel_( std::make_unique>( diff --git a/shell/platform/tizen/channels/platform_view_channel.h b/shell/platform/tizen/channels/platform_view_channel.h index 84e3c5ce91fbd..4b172b16db4a7 100644 --- a/shell/platform/tizen/channels/platform_view_channel.h +++ b/shell/platform/tizen/channels/platform_view_channel.h @@ -13,15 +13,17 @@ #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h" #include "rapidjson/document.h" -class TizenEmbedderEngine; +class FlutterTizenEngine; class PlatformView; class PlatformViewFactory; class PlatformViewChannel { public: explicit PlatformViewChannel(flutter::BinaryMessenger* messenger, - TizenEmbedderEngine* engine); + FlutterTizenEngine* engine); virtual ~PlatformViewChannel(); + void Dispose(); + std::map>& ViewFactories() { return view_factories_; } @@ -34,14 +36,14 @@ class PlatformViewChannel { void DispatchCompositionEndEvent(const std::string& key); private: - TizenEmbedderEngine* engine_; - std::unique_ptr> channel_; - std::map> view_factories_; - std::map view_instances_; - void HandleMethodCall( const flutter::MethodCall& call, std::unique_ptr> result); + + FlutterTizenEngine* engine_; + std::unique_ptr> channel_; + std::map> view_factories_; + std::map view_instances_; }; #endif // EMBEDDER_PLATFORM_VIEW_CHANNEL_H_ diff --git a/shell/platform/tizen/channels/settings_channel.cc b/shell/platform/tizen/channels/settings_channel.cc index 4a6e49c1f6357..dc87446e47280 100644 --- a/shell/platform/tizen/channels/settings_channel.cc +++ b/shell/platform/tizen/channels/settings_channel.cc @@ -4,15 +4,15 @@ #include "settings_channel.h" -static constexpr char CHANNEL_NAME[] = "flutter/settings"; -static constexpr char TEXT_SCALE_FACTOR[] = "textScaleFactor"; -static constexpr char ALWAYS_USE_24_HOUR_FORMAT[] = "alwaysUse24HourFormat"; -static constexpr char PLATFORM_BRIGHTNESS[] = "platformBrightness"; +static constexpr char kChannelName[] = "flutter/settings"; +static constexpr char kTextScaleFactorKey[] = "textScaleFactor"; +static constexpr char kAlwaysUse24HourFormatKey[] = "alwaysUse24HourFormat"; +static constexpr char kPlatformBrightnessKey[] = "platformBrightness"; SettingsChannel::SettingsChannel(flutter::BinaryMessenger* messenger) : channel_( std::make_unique>( - messenger, CHANNEL_NAME, + messenger, kChannelName, &flutter::JsonMessageCodec::GetInstance())) { system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, OnSettingsChangedCallback, this); @@ -31,16 +31,15 @@ void SettingsChannel::SendSettingsEvent() { int ret = system_settings_get_value_bool( SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &value); if (ret == SYSTEM_SETTINGS_ERROR_NONE) { - event.AddMember(TEXT_SCALE_FACTOR, 1.0, allocator); - event.AddMember(PLATFORM_BRIGHTNESS, "light", allocator); - event.AddMember(ALWAYS_USE_24_HOUR_FORMAT, value, allocator); + event.AddMember(kTextScaleFactorKey, 1.0, allocator); + event.AddMember(kPlatformBrightnessKey, "light", allocator); + event.AddMember(kAlwaysUse24HourFormatKey, value, allocator); channel_->Send(event); } } void SettingsChannel::OnSettingsChangedCallback(system_settings_key_e key, void* user_data) { - SettingsChannel* settingsChannel = - reinterpret_cast(user_data); - settingsChannel->SendSettingsEvent(); + auto settings_channel = reinterpret_cast(user_data); + settings_channel->SendSettingsEvent(); } diff --git a/shell/platform/tizen/channels/settings_channel.h b/shell/platform/tizen/channels/settings_channel.h index 9495db445d3b1..6d050b2c7df4b 100644 --- a/shell/platform/tizen/channels/settings_channel.h +++ b/shell/platform/tizen/channels/settings_channel.h @@ -18,10 +18,11 @@ class SettingsChannel { virtual ~SettingsChannel(); private: - std::unique_ptr> channel_; static void OnSettingsChangedCallback(system_settings_key_e key, void* user_data); void SendSettingsEvent(); + + std::unique_ptr> channel_; }; #endif // EMBEDDER_SETTINGS_CHANNEL_H_ diff --git a/shell/platform/tizen/channels/text_input_channel.cc b/shell/platform/tizen/channels/text_input_channel.cc index 663722b184a4e..26049f77ad7fc 100644 --- a/shell/platform/tizen/channels/text_input_channel.cc +++ b/shell/platform/tizen/channels/text_input_channel.cc @@ -7,7 +7,7 @@ #include #include -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" static constexpr char kSetEditingStateMethod[] = "TextInput.setEditingState"; @@ -203,7 +203,7 @@ Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( } TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger, - TizenEmbedderEngine* engine) + FlutterTizenEngine* engine) : channel_(std::make_unique>( messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())), engine_(engine) { @@ -223,7 +223,7 @@ TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger, } if (imf_context_) { ecore_imf_context_client_window_set( - imf_context_, (void*)engine_->tizen_renderer->GetWindowId()); + imf_context_, (void*)engine_->renderer->GetWindowId()); RegisterIMFCallback(); } else { FT_LOGE("Failed to create imfContext"); diff --git a/shell/platform/tizen/channels/text_input_channel.h b/shell/platform/tizen/channels/text_input_channel.h index 74b6629975a0b..9a460e0e35c51 100644 --- a/shell/platform/tizen/channels/text_input_channel.h +++ b/shell/platform/tizen/channels/text_input_channel.h @@ -16,16 +16,19 @@ #include "flutter/shell/platform/common/cpp/json_method_codec.h" #include "flutter/shell/platform/common/cpp/text_input_model.h" -class TizenEmbedderEngine; +class FlutterTizenEngine; class TextInputChannel { public: struct SoftwareKeyboardGeometry { int32_t x = 0, y = 0, w = 0, h = 0; }; + enum EditStatus { kNone, kPreeditStart, kPreeditEnd, kCommit }; + explicit TextInputChannel(flutter::BinaryMessenger* messenger, - TizenEmbedderEngine* engine); + FlutterTizenEngine* engine); virtual ~TextInputChannel(); + void OnKeyDown(Ecore_Event_Key* key); void OnCommit(std::string str); void OnPreedit(std::string str, int cursor_pos); @@ -91,7 +94,7 @@ class TextInputChannel { int preedit_end_pos_{0}; int preedit_start_pos_{0}; std::string last_handled_ecore_event_keyname_; - TizenEmbedderEngine* engine_{nullptr}; + FlutterTizenEngine* engine_{nullptr}; Ecore_IMF_Context* imf_context_{nullptr}; }; diff --git a/shell/platform/tizen/flutter_tizen.cc b/shell/platform/tizen/flutter_tizen.cc index d8a92a531ab82..0b0f3a574d22f 100644 --- a/shell/platform/tizen/flutter_tizen.cc +++ b/shell/platform/tizen/flutter_tizen.cc @@ -10,53 +10,37 @@ #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h" #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/public/flutter_platform_view.h" #include "flutter/shell/platform/tizen/public/flutter_tizen_texture_registrar.h" -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" -// Opaque reference to a Tizen embedder engine. -struct FlutterWindowControllerState { - std::unique_ptr engine; -}; - -FlutterWindowControllerRef FlutterCreateWindow( - const FlutterEngineProperties& engine_properties) { - StartLogging(); - - auto state = std::make_unique(); - state->engine = std::make_unique(); - - if (!state->engine->RunEngine(engine_properties)) { - FT_LOGE("Failed to run the Flutter engine."); - return nullptr; - } +// Returns the engine corresponding to the given opaque API handle. +static FlutterTizenEngine* EngineFromHandle(FlutterDesktopEngineRef ref) { + return reinterpret_cast(ref); +} - return state.release(); +// Returns the opaque API handle for the given engine instance. +static FlutterDesktopEngineRef HandleForEngine(FlutterTizenEngine* engine) { + return reinterpret_cast(engine); } -FlutterWindowControllerRef FlutterRunEngine( - const FlutterEngineProperties& engine_properties) { +FlutterDesktopEngineRef FlutterDesktopRunEngine( + const FlutterDesktopEngineProperties& engine_properties, bool headed) { StartLogging(); - auto state = std::make_unique(); - state->engine = std::make_unique(false); - if (!state->engine->RunEngine(engine_properties)) { + auto engine = std::make_unique(headed); + if (!engine->RunEngine(engine_properties)) { FT_LOGE("Failed to run the Flutter engine."); return nullptr; } - return state.release(); + return HandleForEngine(engine.release()); } -void FlutterDestroyWindow(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->StopEngine(); - } - delete controller; -} - -bool FlutterRunsPrecompiledCode() { - return FlutterEngineRunsAOTCompiledDartCode(); +void FlutterDesktopShutdownEngine(FlutterDesktopEngineRef engine_ref) { + auto engine = EngineFromHandle(engine_ref); + engine->StopEngine(); + delete engine; } void FlutterDesktopPluginRegistrarEnableInputBlocking( @@ -65,11 +49,16 @@ void FlutterDesktopPluginRegistrarEnableInputBlocking( } FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar( - FlutterWindowControllerRef controller, const char* plugin_name) { + FlutterDesktopEngineRef engine, const char* plugin_name) { // Currently, one registrar acts as the registrar for all plugins, so the // name is ignored. It is part of the API to reduce churn in the future when // aligning more closely with the Flutter registrar system. - return controller->engine->GetPluginRegistrar(); + return EngineFromHandle(engine)->GetPluginRegistrar(); +} + +FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger( + FlutterDesktopEngineRef engine) { + return EngineFromHandle(engine)->messenger.get(); } FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger( @@ -142,40 +131,29 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, user_data); } -void FlutterNotifyLocaleChange(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->SendLocales(); - } +void FlutterDesktopNotifyLocaleChange(FlutterDesktopEngineRef engine) { + EngineFromHandle(engine)->localization_channel->SendLocales(); } -void FlutterNotifyAppIsInactive(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->AppIsInactive(); - } +void FlutterDesktopNotifyAppIsInactive(FlutterDesktopEngineRef engine) { + EngineFromHandle(engine)->lifecycle_channel->AppIsInactive(); } -void FlutterNotifyAppIsResumed(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->AppIsResumed(); - } +void FlutterDesktopNotifyAppIsResumed(FlutterDesktopEngineRef engine) { + EngineFromHandle(engine)->lifecycle_channel->AppIsResumed(); } -void FlutterNotifyAppIsPaused(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->AppIsPaused(); - } +void FlutterDesktopNotifyAppIsPaused(FlutterDesktopEngineRef engine) { + EngineFromHandle(engine)->lifecycle_channel->AppIsPaused(); } -void FlutterNotifyAppIsDetached(FlutterWindowControllerRef controller) { - if (controller->engine) { - controller->engine->AppIsDetached(); - } +void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) { + EngineFromHandle(engine)->lifecycle_channel->AppIsDetached(); } -void FlutterNotifyLowMemoryWarning(FlutterWindowControllerRef controller) { - if (controller->engine->flutter_engine) { - FlutterEngineNotifyLowMemoryWarning(controller->engine->flutter_engine); - } +void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) { + auto flutter_engine = EngineFromHandle(engine)->flutter_engine; + FlutterEngineNotifyLowMemoryWarning(flutter_engine); } int64_t FlutterRegisterExternalTexture( diff --git a/shell/platform/tizen/tizen_embedder_engine.cc b/shell/platform/tizen/flutter_tizen_engine.cc similarity index 65% rename from shell/platform/tizen/tizen_embedder_engine.cc rename to shell/platform/tizen/flutter_tizen_engine.cc index b5d37ee656b18..f4fbb192cbb00 100644 --- a/shell/platform/tizen/tizen_embedder_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "tizen_embedder_engine.h" +#include "flutter_tizen_engine.h" #include @@ -35,11 +35,10 @@ static DeviceProfile GetDeviceProfile() { } else if (profile == "common") { return DeviceProfile::kCommon; } - FT_LOGW("Flutter-tizen is running on an unknown device profile!"); return DeviceProfile::kUnknown; } -TizenEmbedderEngine::TizenEmbedderEngine(bool initialize_tizen_renderer) +FlutterTizenEngine::FlutterTizenEngine(bool headed) : device_profile(GetDeviceProfile()) { // Run flutter task on Tizen main loop. // Tizen engine has four threads (GPU thread, UI thread, IO thread, platform @@ -57,14 +56,19 @@ TizenEmbedderEngine::TizenEmbedderEngine(bool initialize_tizen_renderer) message_dispatcher = std::make_unique(messenger.get()); - if (initialize_tizen_renderer) { - InitializeTizenRenderer(); + plugin_registrar_ = std::make_unique(); + plugin_registrar_->engine = this; + + if (headed) { + InitializeRenderer(); } } -void TizenEmbedderEngine::InitializeTizenRenderer() { +FlutterTizenEngine::~FlutterTizenEngine() { renderer = nullptr; } + +void FlutterTizenEngine::InitializeRenderer() { #ifdef TIZEN_RENDERER_EVAS_GL - tizen_renderer = std::make_unique(*this); + renderer = std::make_unique(*this); render_loop_ = std::make_unique( std::this_thread::get_id(), // main thread @@ -73,18 +77,14 @@ void TizenEmbedderEngine::InitializeTizenRenderer() { FT_LOGE("Could not post an engine task."); } }, - tizen_renderer.get()); + renderer.get()); #else - tizen_renderer = std::make_unique(*this); + renderer = std::make_unique(*this); + tizen_vsync_waiter_ = std::make_unique(this); #endif } -TizenEmbedderEngine::~TizenEmbedderEngine() { - FT_LOGD("Destroy"); - tizen_renderer = nullptr; -} - // Attempts to load AOT data from the given path, which must be absolute and // non-empty. Logs and returns nullptr on failure. UniqueAotDataPtr LoadAotData(std::string aot_data_path) { @@ -110,9 +110,9 @@ UniqueAotDataPtr LoadAotData(std::string aot_data_path) { return UniqueAotDataPtr(data); } -bool TizenEmbedderEngine::RunEngine( - const FlutterEngineProperties& engine_properties) { - if (HasTizenRenderer() && !tizen_renderer->IsValid()) { +bool FlutterTizenEngine::RunEngine( + const FlutterDesktopEngineProperties& engine_properties) { + if (IsHeaded() && !renderer->IsValid()) { FT_LOGE("The display was not valid."); return false; } @@ -126,7 +126,7 @@ bool TizenEmbedderEngine::RunEngine( &engine_properties.switches[engine_properties.switches_count]); } - // Configure task runner interop. + // Configure task runners. FlutterTaskRunnerDescription platform_task_runner = {}; platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription); platform_task_runner.user_data = event_loop_.get(); @@ -145,7 +145,7 @@ bool TizenEmbedderEngine::RunEngine( #ifdef TIZEN_RENDERER_EVAS_GL FlutterTaskRunnerDescription render_task_runner = {}; - if (HasTizenRenderer()) { + if (IsHeaded()) { render_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription); render_task_runner.user_data = render_loop_.get(); render_task_runner.runs_task_on_current_thread_callback = @@ -161,27 +161,6 @@ bool TizenEmbedderEngine::RunEngine( } #endif - FlutterRendererConfig config = {}; - if (HasTizenRenderer()) { - config.type = kOpenGL; - config.open_gl.struct_size = sizeof(config.open_gl); - config.open_gl.make_current = MakeContextCurrent; - config.open_gl.make_resource_current = MakeResourceCurrent; - config.open_gl.clear_current = ClearContext; - config.open_gl.present = Present; - config.open_gl.fbo_callback = GetActiveFbo; - config.open_gl.surface_transformation = Transformation; - config.open_gl.gl_proc_resolver = GlProcResolver; - config.open_gl.gl_external_texture_frame_callback = - OnAcquireExternalTexture; - } else { - config.type = kSoftware; - config.software.struct_size = sizeof(config.software); - config.software.surface_present_callback = - [](void* user_data, const void* allocation, size_t row_bytes, - size_t height) -> bool { return true; }; - } - FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); args.assets_path = engine_properties.assets_path; @@ -190,10 +169,12 @@ bool TizenEmbedderEngine::RunEngine( args.command_line_argv = &argv[0]; args.platform_message_callback = OnFlutterPlatformMessage; args.custom_task_runners = &custom_task_runners; - #ifndef TIZEN_RENDERER_EVAS_GL - if (HasTizenRenderer()) { - args.vsync_callback = OnVsyncCallback; + if (IsHeaded()) { + args.vsync_callback = [](void* user_data, intptr_t baton) -> void { + reinterpret_cast(user_data) + ->tizen_vsync_waiter_->AsyncWaitForVsync(baton); + }; } #endif @@ -206,8 +187,10 @@ bool TizenEmbedderEngine::RunEngine( args.aot_data = aot_data_.get(); } - auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, this, - &flutter_engine); + FlutterRendererConfig renderer_config = GetRendererConfig(); + + auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &renderer_config, + &args, this, &flutter_engine); if (result == kSuccess && flutter_engine != nullptr) { FT_LOGD("FlutterEngineRun Success!"); } else { @@ -215,25 +198,21 @@ bool TizenEmbedderEngine::RunEngine( return false; } - plugin_registrar_ = std::make_unique(); - plugin_registrar_->engine = this; - internal_plugin_registrar_ = std::make_unique(plugin_registrar_.get()); platform_channel = std::make_unique( - internal_plugin_registrar_->messenger(), tizen_renderer.get()); + internal_plugin_registrar_->messenger(), renderer.get()); settings_channel = std::make_unique( internal_plugin_registrar_->messenger()); localization_channel = std::make_unique(flutter_engine); localization_channel->SendLocales(); lifecycle_channel = std::make_unique(flutter_engine); - if (HasTizenRenderer()) { - std::unique_ptr textures = - std::make_unique(); - textures->flutter_engine = flutter_engine; - plugin_registrar_->texture_registrar = std::move(textures); + if (IsHeaded()) { + auto texture_registrar = std::make_unique(); + texture_registrar->flutter_engine = flutter_engine; + plugin_registrar_->texture_registrar = std::move(texture_registrar); key_event_channel = std::make_unique( internal_plugin_registrar_->messenger()); @@ -252,11 +231,7 @@ bool TizenEmbedderEngine::RunEngine( return true; } -void TizenEmbedderEngine::OnRotationChange(int angle) { - SetWindowOrientation(angle); -} - -bool TizenEmbedderEngine::StopEngine() { +bool FlutterTizenEngine::StopEngine() { if (flutter_engine) { if (platform_view_channel) { platform_view_channel->Dispose(); @@ -271,34 +246,17 @@ bool TizenEmbedderEngine::StopEngine() { return false; } -FlutterDesktopPluginRegistrarRef TizenEmbedderEngine::GetPluginRegistrar() { +FlutterDesktopPluginRegistrarRef FlutterTizenEngine::GetPluginRegistrar() { return plugin_registrar_.get(); } -void TizenEmbedderEngine::SetPluginRegistrarDestructionCallback( +void FlutterTizenEngine::SetPluginRegistrarDestructionCallback( FlutterDesktopOnPluginRegistrarDestroyed callback) { plugin_registrar_destruction_callback_ = callback; } -bool TizenEmbedderEngine::OnAcquireExternalTexture( - void* user_data, int64_t texture_id, size_t width, size_t height, - FlutterOpenGLTexture* texture) { - TizenEmbedderEngine* tizen_embedder_engine = - reinterpret_cast(user_data); - std::lock_guard lock( - tizen_embedder_engine->plugin_registrar_->texture_registrar->mutex); - auto it = tizen_embedder_engine->plugin_registrar_->texture_registrar - ->textures.find(texture_id); - int ret = false; - if (it != tizen_embedder_engine->plugin_registrar_->texture_registrar - ->textures.end()) { - ret = it->second->PopulateTextureWithIdentifier(width, height, texture); - } - return ret; -} - -void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height, - double pixel_ratio) { +void FlutterTizenEngine::SendWindowMetrics(int32_t width, int32_t height, + double pixel_ratio) { FlutterWindowMetricsEvent event; event.struct_size = sizeof(FlutterWindowMetricsEvent); event.width = width; @@ -308,8 +266,8 @@ void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height, // profile. A fixed DPI value (72) is used on TVs. See: // https://docs.tizen.org/application/native/guides/ui/efl/multiple-screens double dpi = 72.0; - if (tizen_renderer && device_profile != DeviceProfile::kTV) { - dpi = (double)tizen_renderer->GetDpi(); + if (renderer && device_profile != DeviceProfile::kTV) { + dpi = (double)renderer->GetDpi(); } double profile_factor = 1.0; if (device_profile == DeviceProfile::kWearable) { @@ -329,15 +287,15 @@ void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height, // This must be called at least once in order to initialize the value of // transformation_. -void TizenEmbedderEngine::SetWindowOrientation(int32_t degree) { - if (!tizen_renderer) { +void FlutterTizenEngine::SetWindowOrientation(int32_t degree) { + if (!renderer) { return; } - tizen_renderer->SetRotate(degree); + renderer->SetRotate(degree); // Compute renderer transformation based on the angle of rotation. double rad = (360 - degree) * M_PI / 180; - auto geometry = tizen_renderer->GetGeometry(); + auto geometry = renderer->GetGeometry(); double width = geometry.w; double height = geometry.h; @@ -358,55 +316,34 @@ void TizenEmbedderEngine::SetWindowOrientation(int32_t degree) { touch_event_handler_->rotation = degree; text_input_channel->rotation = degree; if (degree == 90 || degree == 270) { - tizen_renderer->ResizeWithRotation(geometry.x, geometry.y, height, width, - degree); + renderer->ResizeWithRotation(geometry.x, geometry.y, height, width, degree); SendWindowMetrics(height, width, 0.0); } else { - tizen_renderer->ResizeWithRotation(geometry.x, geometry.y, width, height, - degree); + renderer->ResizeWithRotation(geometry.x, geometry.y, width, height, degree); SendWindowMetrics(width, height, 0.0); } } -void TizenEmbedderEngine::SendLocales() { localization_channel->SendLocales(); } - -void TizenEmbedderEngine::AppIsInactive() { - lifecycle_channel->AppIsInactive(); +void FlutterTizenEngine::OnOrientationChange(int32_t degree) { + SetWindowOrientation(degree); } -void TizenEmbedderEngine::AppIsResumed() { lifecycle_channel->AppIsResumed(); } - -void TizenEmbedderEngine::AppIsPaused() { lifecycle_channel->AppIsPaused(); } - -void TizenEmbedderEngine::AppIsDetached() { - lifecycle_channel->AppIsDetached(); -} - -void TizenEmbedderEngine::OnFlutterPlatformMessage( +// The Flutter Engine calls out to this function when new platform messages are +// available. +void FlutterTizenEngine::OnFlutterPlatformMessage( const FlutterPlatformMessage* engine_message, void* user_data) { if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) { - FT_LOGE("Invalid message size received. Expected: %zu, received %zu", + FT_LOGE("Invalid message size received. Expected: %zu, but received %zu", sizeof(FlutterPlatformMessage), engine_message->struct_size); return; } - FT_LOGD("%s", engine_message->channel); - TizenEmbedderEngine* tizen_embedder_engine = - reinterpret_cast(user_data); - auto message = - tizen_embedder_engine->ConvertToDesktopMessage(*engine_message); - tizen_embedder_engine->message_dispatcher->HandleMessage(message); -} - -#ifndef TIZEN_RENDERER_EVAS_GL -void TizenEmbedderEngine::OnVsyncCallback(void* user_data, intptr_t baton) { - TizenEmbedderEngine* tizen_embedder_engine = - reinterpret_cast(user_data); - tizen_embedder_engine->tizen_vsync_waiter_->AsyncWaitForVsync(baton); + auto engine = reinterpret_cast(user_data); + auto message = engine->ConvertToDesktopMessage(*engine_message); + engine->message_dispatcher->HandleMessage(message); } -#endif // Converts a FlutterPlatformMessage to an equivalent FlutterDesktopMessage. -FlutterDesktopMessage TizenEmbedderEngine::ConvertToDesktopMessage( +FlutterDesktopMessage FlutterTizenEngine::ConvertToDesktopMessage( const FlutterPlatformMessage& engine_message) { FlutterDesktopMessage message = {}; message.struct_size = sizeof(message); @@ -417,40 +354,60 @@ FlutterDesktopMessage TizenEmbedderEngine::ConvertToDesktopMessage( return message; } -bool TizenEmbedderEngine::MakeContextCurrent(void* user_data) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnMakeCurrent(); -} - -bool TizenEmbedderEngine::ClearContext(void* user_data) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnClearCurrent(); -} - -bool TizenEmbedderEngine::Present(void* user_data) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnPresent(); -} - -bool TizenEmbedderEngine::MakeResourceCurrent(void* user_data) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnMakeResourceCurrent(); -} - -uint32_t TizenEmbedderEngine::GetActiveFbo(void* user_data) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnGetFBO(); -} - -FlutterTransformation TizenEmbedderEngine::Transformation(void* user_data) { - return reinterpret_cast(user_data)->transformation_; -} - -void* TizenEmbedderEngine::GlProcResolver(void* user_data, const char* name) { - return reinterpret_cast(user_data) - ->tizen_renderer->OnProcResolver(name); -} - -bool TizenEmbedderEngine::HasTizenRenderer() { - return tizen_renderer != nullptr; +FlutterRendererConfig FlutterTizenEngine::GetRendererConfig() { + FlutterRendererConfig config = {}; + if (IsHeaded()) { + config.type = kOpenGL; + config.open_gl.struct_size = sizeof(config.open_gl); + config.open_gl.make_current = [](void* user_data) -> bool { + return reinterpret_cast(user_data) + ->renderer->OnMakeCurrent(); + }; + config.open_gl.make_resource_current = [](void* user_data) -> bool { + return reinterpret_cast(user_data) + ->renderer->OnMakeResourceCurrent(); + }; + config.open_gl.clear_current = [](void* user_data) -> bool { + return reinterpret_cast(user_data) + ->renderer->OnClearCurrent(); + }; + config.open_gl.present = [](void* user_data) -> bool { + return reinterpret_cast(user_data) + ->renderer->OnPresent(); + }; + config.open_gl.fbo_callback = [](void* user_data) -> uint32_t { + return reinterpret_cast(user_data) + ->renderer->OnGetFBO(); + }; + config.open_gl.surface_transformation = + [](void* user_data) -> FlutterTransformation { + return reinterpret_cast(user_data)->transformation_; + }; + config.open_gl.gl_proc_resolver = [](void* user_data, + const char* name) -> void* { + return reinterpret_cast(user_data) + ->renderer->OnProcResolver(name); + }; + config.open_gl.gl_external_texture_frame_callback = + [](void* user_data, int64_t texture_id, size_t width, size_t height, + FlutterOpenGLTexture* texture) -> bool { + auto engine = reinterpret_cast(user_data); + auto texture_registrar = + engine->plugin_registrar_->texture_registrar.get(); + std::lock_guard lock(texture_registrar->mutex); + auto it = texture_registrar->textures.find(texture_id); + int ret = false; + if (it != texture_registrar->textures.end()) { + ret = it->second->PopulateTextureWithIdentifier(width, height, texture); + } + return ret; + }; + } else { + config.type = kSoftware; + config.software.struct_size = sizeof(config.software); + config.software.surface_present_callback = + [](void* user_data, const void* allocation, size_t row_bytes, + size_t height) -> bool { return true; }; + } + return config; } diff --git a/shell/platform/tizen/tizen_embedder_engine.h b/shell/platform/tizen/flutter_tizen_engine.h similarity index 81% rename from shell/platform/tizen/tizen_embedder_engine.h rename to shell/platform/tizen/flutter_tizen_engine.h index 4ea9619052477..dfb54b7096150 100644 --- a/shell/platform/tizen/tizen_embedder_engine.h +++ b/shell/platform/tizen/flutter_tizen_engine.h @@ -6,6 +6,7 @@ #ifndef EMBEDDER_TIZEN_EMBEDDER_ENGINE_H_ #define EMBEDDER_TIZEN_EMBEDDER_ENGINE_H_ +#include #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" @@ -35,7 +36,7 @@ // State associated with the plugin registrar. struct FlutterDesktopPluginRegistrar { // The engine that owns this state object. - TizenEmbedderEngine* engine; + FlutterTizenEngine* engine; // The plugin texture registrar handle given to API clients. std::unique_ptr texture_registrar; @@ -44,7 +45,7 @@ struct FlutterDesktopPluginRegistrar { // State associated with the messenger used to communicate with the engine. struct FlutterDesktopMessenger { // The engine that owns this state object. - TizenEmbedderEngine* engine = nullptr; + FlutterTizenEngine* engine = nullptr; }; // Custom deleter for FlutterEngineAOTData. @@ -68,12 +69,18 @@ using UniqueAotDataPtr = std::unique_ptr<_FlutterEngineAOTData, AOTDataDeleter>; enum DeviceProfile { kUnknown, kMobile, kWearable, kTV, kCommon }; // Manages state associated with the underlying FlutterEngine. -class TizenEmbedderEngine : public TizenRenderer::Delegate { +class FlutterTizenEngine : public TizenRenderer::Delegate { public: - explicit TizenEmbedderEngine(bool initialize_tizen_renderer = true); - virtual ~TizenEmbedderEngine(); - void InitializeTizenRenderer(); - bool RunEngine(const FlutterEngineProperties& engine_properties); + explicit FlutterTizenEngine(bool headed); + virtual ~FlutterTizenEngine(); + + // Prevent copying. + FlutterTizenEngine(FlutterTizenEngine const&) = delete; + FlutterTizenEngine& operator=(FlutterTizenEngine const&) = delete; + + void InitializeRenderer(); + + bool RunEngine(const FlutterDesktopEngineProperties& engine_properties); bool StopEngine(); // Returns the currently configured Plugin Registrar. @@ -85,12 +92,7 @@ class TizenEmbedderEngine : public TizenRenderer::Delegate { void SendWindowMetrics(int32_t width, int32_t height, double pixel_ratio); void SetWindowOrientation(int32_t degree); - void SendLocales(); - void AppIsInactive(); - void AppIsResumed(); - void AppIsPaused(); - void AppIsDetached(); - void OnRotationChange(int degree) override; + void OnOrientationChange(int32_t degree) override; // The Flutter engine instance. FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine; @@ -102,7 +104,7 @@ class TizenEmbedderEngine : public TizenRenderer::Delegate { std::unique_ptr message_dispatcher; // The interface between the Flutter rasterizer and the platform. - std::unique_ptr tizen_renderer; + std::unique_ptr renderer; // The system channels for communicating between Flutter and the platform. std::unique_ptr key_event_channel; @@ -117,26 +119,13 @@ class TizenEmbedderEngine : public TizenRenderer::Delegate { const DeviceProfile device_profile; private: - static bool MakeContextCurrent(void* user_data); - static bool ClearContext(void* user_data); - static bool Present(void* user_data); - static bool MakeResourceCurrent(void* user_data); - static uint32_t GetActiveFbo(void* user_data); - static FlutterTransformation Transformation(void* user_data); - static void* GlProcResolver(void* user_data, const char* name); + bool IsHeaded() { return renderer != nullptr; } + static void OnFlutterPlatformMessage( const FlutterPlatformMessage* engine_message, void* user_data); -#ifndef TIZEN_RENDERER_EVAS_GL - static void OnVsyncCallback(void* user_data, intptr_t baton); -#endif - FlutterDesktopMessage ConvertToDesktopMessage( const FlutterPlatformMessage& engine_message); - static bool OnAcquireExternalTexture(void* user_data, int64_t texture_id, - size_t width, size_t height, - FlutterOpenGLTexture* texture); - - bool HasTizenRenderer(); + FlutterRendererConfig GetRendererConfig(); // The handlers listening to platform events. std::unique_ptr key_event_handler_; diff --git a/shell/platform/tizen/key_event_handler.cc b/shell/platform/tizen/key_event_handler.cc index 28f7d8d687200..4bf2ff59d3efa 100644 --- a/shell/platform/tizen/key_event_handler.cc +++ b/shell/platform/tizen/key_event_handler.cc @@ -4,12 +4,11 @@ #include "key_event_handler.h" -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" static constexpr char kPlatformBackButtonName[] = "XF86Back"; -KeyEventHandler::KeyEventHandler(TizenEmbedderEngine *engine) - : engine_(engine) { +KeyEventHandler::KeyEventHandler(FlutterTizenEngine *engine) : engine_(engine) { key_event_handlers_.push_back( ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, OnKey, this)); key_event_handlers_.push_back( diff --git a/shell/platform/tizen/key_event_handler.h b/shell/platform/tizen/key_event_handler.h index 6253a6ca37056..15f7a11bc7b78 100644 --- a/shell/platform/tizen/key_event_handler.h +++ b/shell/platform/tizen/key_event_handler.h @@ -9,15 +9,15 @@ #include -class TizenEmbedderEngine; +class FlutterTizenEngine; class KeyEventHandler { public: - explicit KeyEventHandler(TizenEmbedderEngine* engine); + explicit KeyEventHandler(FlutterTizenEngine* engine); virtual ~KeyEventHandler(); private: - TizenEmbedderEngine* engine_; + FlutterTizenEngine* engine_; std::vector key_event_handlers_; static Eina_Bool OnKey(void* data, int type, void* event); diff --git a/shell/platform/tizen/public/flutter_tizen.h b/shell/platform/tizen/public/flutter_tizen.h index 17e0c5fc91ebe..9cac0f3371dce 100644 --- a/shell/platform/tizen/public/flutter_tizen.h +++ b/shell/platform/tizen/public/flutter_tizen.h @@ -17,8 +17,9 @@ extern "C" { #endif -// Opaque reference to a Flutter window controller. -typedef struct FlutterWindowControllerState* FlutterWindowControllerRef; +// Opaque reference to a Flutter engine instance. +struct FlutterDesktopEngine; +typedef struct FlutterDesktopEngine* FlutterDesktopEngineRef; // Properties for configuring a Flutter engine instance. typedef struct { @@ -26,7 +27,7 @@ typedef struct { const char* assets_path; // The path to the icudtl.dat file for the version of Flutter you are using. const char* icu_data_path; - // The path to the libapp.so file for the application to be run. + // The path to the AOT libary file for your application, if any. const char* aot_library_path; // The switches to pass to the Flutter engine. // @@ -35,42 +36,48 @@ typedef struct { const char** switches; // The number of elements in |switches|. size_t switches_count; -} FlutterEngineProperties; +} FlutterDesktopEngineProperties; -FLUTTER_EXPORT FlutterWindowControllerRef -FlutterCreateWindow(const FlutterEngineProperties& engine_properties); +// Runs an instance of a Flutter engine with the given properties. +// +// If |headed| is false, the engine is run in headless mode. +FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopRunEngine( + const FlutterDesktopEngineProperties& engine_properties, bool headed); -FLUTTER_EXPORT FlutterWindowControllerRef -FlutterRunEngine(const FlutterEngineProperties& engine_properties); +// Shuts down the given engine instance. +// +// |engine| is no longer valid after this call. +FLUTTER_EXPORT void FlutterDesktopShutdownEngine( + FlutterDesktopEngineRef engine); // Returns the plugin registrar handle for the plugin with the given name. // // The name must be unique across the application. FLUTTER_EXPORT FlutterDesktopPluginRegistrarRef -FlutterDesktopGetPluginRegistrar(FlutterWindowControllerRef controller, +FlutterDesktopGetPluginRegistrar(FlutterDesktopEngineRef engine, const char* plugin_name); -FLUTTER_EXPORT void FlutterDestroyWindow(FlutterWindowControllerRef controller); - -FLUTTER_EXPORT bool FlutterRunsPrecompiledCode(); +// Returns the messenger associated with the engine. +FLUTTER_EXPORT FlutterDesktopMessengerRef +FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyLocaleChange( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyLocaleChange( + FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyLowMemoryWarning( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyLowMemoryWarning( + FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyAppIsInactive( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyAppIsInactive( + FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyAppIsResumed( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyAppIsResumed( + FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyAppIsPaused( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyAppIsPaused( + FlutterDesktopEngineRef engine); -FLUTTER_EXPORT void FlutterNotifyAppIsDetached( - FlutterWindowControllerRef controller); +FLUTTER_EXPORT void FlutterDesktopNotifyAppIsDetached( + FlutterDesktopEngineRef engine); #if defined(__cplusplus) } // extern "C" diff --git a/shell/platform/tizen/tizen_event_loop.cc b/shell/platform/tizen/tizen_event_loop.cc index ec69bb61c1580..7215f11dbb43f 100644 --- a/shell/platform/tizen/tizen_event_loop.cc +++ b/shell/platform/tizen/tizen_event_loop.cc @@ -113,11 +113,11 @@ void TizenPlatformEventLoop::OnTaskExpired() { #ifdef TIZEN_RENDERER_EVAS_GL TizenRenderEventLoop::TizenRenderEventLoop(std::thread::id main_thread_id, TaskExpiredCallback on_task_expired, - TizenRenderer* tizen_renderer) + TizenRenderer* renderer) : TizenEventLoop(main_thread_id, on_task_expired), - tizen_renderer_(tizen_renderer) { + renderer_(renderer) { evas_object_image_pixels_get_callback_set( - (Evas_Object*)static_cast(tizen_renderer_) + (Evas_Object*)static_cast(renderer_) ->GetImageHandle(), [](void* data, Evas_Object* o) { // Render callback TizenRenderEventLoop* self = (TizenRenderEventLoop*)data; @@ -141,7 +141,7 @@ void TizenRenderEventLoop::OnTaskExpired() { expired_tasks_count = expired_tasks_.size(); if (!has_pending_renderer_callback_ && expired_tasks_count) { evas_object_image_pixels_dirty_set( - (Evas_Object*)static_cast(tizen_renderer_) + (Evas_Object*)static_cast(renderer_) ->GetImageHandle(), EINA_TRUE); has_pending_renderer_callback_ = true; diff --git a/shell/platform/tizen/tizen_event_loop.h b/shell/platform/tizen/tizen_event_loop.h index 9aaf58ff12a61..1cd2743617042 100644 --- a/shell/platform/tizen/tizen_event_loop.h +++ b/shell/platform/tizen/tizen_event_loop.h @@ -89,12 +89,12 @@ class TizenRenderEventLoop : public TizenEventLoop { public: TizenRenderEventLoop(std::thread::id main_thread_id, TaskExpiredCallback on_task_expired, - TizenRenderer* tizen_renderer); + TizenRenderer* renderer); virtual ~TizenRenderEventLoop(); virtual void OnTaskExpired() override; private: - TizenRenderer* tizen_renderer_{nullptr}; + TizenRenderer* renderer_{nullptr}; std::atomic_bool has_pending_renderer_callback_{false}; }; #endif diff --git a/shell/platform/tizen/tizen_renderer.h b/shell/platform/tizen/tizen_renderer.h index 9627531cedd5e..95f5d149e5dbf 100644 --- a/shell/platform/tizen/tizen_renderer.h +++ b/shell/platform/tizen/tizen_renderer.h @@ -16,7 +16,7 @@ class TizenRenderer { class Delegate { public: - virtual void OnRotationChange(int angle) = 0; + virtual void OnOrientationChange(int32_t degree) = 0; }; virtual ~TizenRenderer(); diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc index 269a37646b852..26d24115f521f 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc @@ -560,9 +560,8 @@ void TizenRendererEcoreWl2::DestroyEglSurface() { Eina_Bool TizenRendererEcoreWl2::RotationEventCb(void *data, int type, void *event) { auto *self = reinterpret_cast(data); - Ecore_Wl2_Event_Window_Rotation *ev = - reinterpret_cast(event); - self->delegate_.OnRotationChange(ev->angle); + auto *ev = reinterpret_cast(event); + self->delegate_.OnOrientationChange(ev->angle); return ECORE_CALLBACK_PASS_ON; } diff --git a/shell/platform/tizen/tizen_renderer_evas_gl.cc b/shell/platform/tizen/tizen_renderer_evas_gl.cc index 3da6ab3c139a8..1472bd9e242e3 100644 --- a/shell/platform/tizen/tizen_renderer_evas_gl.cc +++ b/shell/platform/tizen/tizen_renderer_evas_gl.cc @@ -690,7 +690,7 @@ void TizenRendererEvasGL::RotationEventCb(void* data, Evas_Object* obj, auto* self = reinterpret_cast(data); // TODO : Use current window rotation degree FT_UNIMPLEMENTED(); - self->delegate_.OnRotationChange(0); + self->delegate_.OnOrientationChange(0); } void TizenRendererEvasGL::SetRotate(int angle) { diff --git a/shell/platform/tizen/tizen_vsync_waiter.cc b/shell/platform/tizen/tizen_vsync_waiter.cc index 5dc73529262c2..4b7f7349bc331 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.cc +++ b/shell/platform/tizen/tizen_vsync_waiter.cc @@ -6,7 +6,7 @@ #include -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" static const int QUEUE_QUIT = -1; @@ -19,7 +19,7 @@ typedef struct { static Eina_Thread_Queue* vblank_thread_queue{nullptr}; -TizenVsyncWaiter::TizenVsyncWaiter(TizenEmbedderEngine* engine) +TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine) : engine_(engine) { if (!CreateTDMVblank()) { FT_LOGE("Failed to create TDM vblank"); diff --git a/shell/platform/tizen/tizen_vsync_waiter.h b/shell/platform/tizen/tizen_vsync_waiter.h index ae1a8e6b94f65..f5c34b6cebebc 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.h +++ b/shell/platform/tizen/tizen_vsync_waiter.h @@ -10,11 +10,11 @@ #include "flutter/shell/platform/embedder/embedder.h" -class TizenEmbedderEngine; +class FlutterTizenEngine; class TizenVsyncWaiter { public: - TizenVsyncWaiter(TizenEmbedderEngine* engine); + TizenVsyncWaiter(FlutterTizenEngine* engine); virtual ~TizenVsyncWaiter(); void AsyncWaitForVsync(intptr_t baton); @@ -32,7 +32,7 @@ class TizenVsyncWaiter { tdm_client* client_{nullptr}; tdm_client_output* output_{nullptr}; tdm_client_vblank* vblank_{nullptr}; - TizenEmbedderEngine* engine_{nullptr}; + FlutterTizenEngine* engine_{nullptr}; intptr_t baton_{0}; Ecore_Thread* vblank_thread_{nullptr}; }; diff --git a/shell/platform/tizen/touch_event_handler.cc b/shell/platform/tizen/touch_event_handler.cc index 0e3f0d283397b..5b799a868fc43 100644 --- a/shell/platform/tizen/touch_event_handler.cc +++ b/shell/platform/tizen/touch_event_handler.cc @@ -4,13 +4,13 @@ #include "touch_event_handler.h" -#include "flutter/shell/platform/tizen/tizen_embedder_engine.h" +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" static const int DIRECTION_VERTICAL = 0; static const int DIRECTION_HORIZONTAL = 1; -TouchEventHandler::TouchEventHandler(TizenEmbedderEngine *engine) +TouchEventHandler::TouchEventHandler(FlutterTizenEngine *engine) : engine_(engine) { touch_event_handlers_.push_back( ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, OnTouch, this)); @@ -40,7 +40,7 @@ void TouchEventHandler::SendFlutterPointerEvent(FlutterPointerPhase phase, } // Correct errors caused by window rotation. - auto window_geometry = engine_->tizen_renderer->GetGeometry(); + auto window_geometry = engine_->renderer->GetGeometry(); double width = window_geometry.w; double height = window_geometry.h; double new_x = x, new_y = y; diff --git a/shell/platform/tizen/touch_event_handler.h b/shell/platform/tizen/touch_event_handler.h index 688ad80bb5a27..e22aa989a44d8 100644 --- a/shell/platform/tizen/touch_event_handler.h +++ b/shell/platform/tizen/touch_event_handler.h @@ -11,17 +11,17 @@ #include "flutter/shell/platform/embedder/embedder.h" -class TizenEmbedderEngine; +class FlutterTizenEngine; class TouchEventHandler { public: - explicit TouchEventHandler(TizenEmbedderEngine* engine); + explicit TouchEventHandler(FlutterTizenEngine* engine); virtual ~TouchEventHandler(); int32_t rotation = 0; private: - TizenEmbedderEngine* engine_; + FlutterTizenEngine* engine_; std::vector touch_event_handlers_; bool pointer_state_ = false;