From 87d3d8ce8c138df07285e4364a22d857c925cf68 Mon Sep 17 00:00:00 2001 From: lushi Date: Fri, 10 Dec 2021 11:37:19 +0800 Subject: [PATCH 1/3] adapt new window manager Signed-off-by: sunfei Change-Id: I826b7b609991c063177991fee8da80cb71f7d166 --- .../flutter/shell/platform/ohos/ohos_surface.h | 4 ++-- .../shell/platform/ohos/ohos_surface_gl.cc | 16 +++++++++++++--- .../shell/platform/ohos/ohos_surface_gl.h | 4 ++-- .../shell/platform/ohos/ohos_surface_software.cc | 8 ++++++-- .../shell/platform/ohos/ohos_surface_software.h | 4 ++-- .../shell/platform/ohos/platform_view_ohos.cc | 2 +- .../shell/platform/ohos/platform_view_ohos.h | 2 +- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface.h b/engine/flutter/shell/platform/ohos/ohos_surface.h index e18496f1..f413f8de 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface.h @@ -11,7 +11,7 @@ #include "flutter/fml/macros.h" #include "flutter/shell/common/surface.h" -#include "window_manager.h" +#include "window.h" namespace flutter { @@ -27,7 +27,7 @@ public: virtual bool OnScreenSurfaceResize(const SkISize& size) = 0; - virtual void SetPlatformWindow(const ::OHOS::sptr<::OHOS::Window> &window) = 0; + virtual void SetPlatformWindow(const ::OHOS::sptr<::OHOS::Rosen::Window> &window) = 0; virtual bool ResourceContextMakeCurrent() = 0; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index 3d941fae..fb0b8a35 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -32,7 +32,7 @@ std::unique_ptr OhosSurfaceGL::CreateGPUSurface() return surface->IsValid() ? std::move(surface) : nullptr; } -void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) +void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) { if (window == nullptr) { FML_LOG(ERROR) << "Ohos window is nullptr"; @@ -128,7 +128,7 @@ SkMatrix OhosSurfaceGL::GLContextSurfaceTransformation() const SkMatrix matrix; matrix.setIdentity(); // Mirror flip - double y = window_->GetHeight() / 2.0; + double y = window_->GetRect().height_ / 2.0; // get middle of height for flip mirror matrix.postTranslate(0, -y); matrix.postScale(1, -1); matrix.postTranslate(0, y); @@ -188,7 +188,17 @@ bool OhosSurfaceGL::InitRenderSurface() return false; } - OHOS::sptr bufferProducer = window_->GetProducer(); + auto surfaceNode = window_->GetSurfaceNode(); + if (!surfaceNode) { + FML_LOG(ERROR) << "surface node is null"; + return; + } + auto surface = surfaceNode->GetSurface(); + if (!surface) { + FML_LOG(ERROR) << "surface is null"; + return; + } + OHOS::sptr bufferProducer = surface->GetProducer(); if (bufferProducer == nullptr) { FML_LOG(ERROR) << "bufferProducer is nullptr"; return false; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index f3591a54..8bca6696 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -29,7 +29,7 @@ public: std::unique_ptr CreateGPUSurface() override; // |OhosSurface| - void SetPlatformWindow(const ::OHOS::sptr& window) override; + void SetPlatformWindow(const ::OHOS::sptr& window) override; // |OhosSurface| bool OnScreenSurfaceResize(const SkISize& size) override; @@ -68,7 +68,7 @@ public: ExternalViewEmbedder* GetExternalViewEmbedder() override; private: - OHOS::sptr window_; + OHOS::sptr window_; OHOS::sptr eglRenderSurface_; EGLDisplay eglDisplay_; EGLContext eglContext_; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 694eb0ea..b8c60916 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -73,14 +73,18 @@ bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) return true; } -void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &window) +void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &window) { if (window == nullptr) { FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, window is nullptr"; return; } window_ = window; - surface_ = window->GetSurface(); + auto surfaceNode = window->GetSurfaceNode(); + if (!surfaceNode) { + FML_LOG(ERROR) << "surface node is null"; + } + surface_ = surfaceNode->GetSurface(); if (surface_ == nullptr) { FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, surface_ is nullptr"; return; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index 059c4c0e..679bebf5 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -25,7 +25,7 @@ public: bool OnScreenSurfaceResize(const SkISize& size) override; - void SetPlatformWindow(const OHOS::sptr &window) override; + void SetPlatformWindow(const OHOS::sptr &window) override; sk_sp AcquireBackingStore(const SkISize& size) override; @@ -52,7 +52,7 @@ private: SkColorType target_color_type_; SkAlphaType target_alpha_type_; - OHOS::sptr window_ = nullptr; + OHOS::sptr window_ = nullptr; OHOS::BufferRequestConfig requestConfig_; OHOS::sptr surface_ = nullptr; diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index 58b4ad56..24579a58 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -28,7 +28,7 @@ PlatformViewOhos::PlatformViewOhos( #endif } -void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) +void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Rosen::Window> &window) { if (surface_) { #ifndef GPU_DISABLED diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.h b/engine/flutter/shell/platform/ohos/platform_view_ohos.h index 65983ae6..70781353 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.h +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.h @@ -16,7 +16,7 @@ class PlatformViewOhos final : public PlatformView { public: PlatformViewOhos(PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, bool use_software_rendering); - void NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window); + void NotifyCreated(const ::OHOS::sptr<::OHOS::Rosen::Window> &window); void NotifyChanged(const SkISize& size); std::unique_ptr CreateRenderingSurface(); std::unique_ptr CreateVSyncWaiter(int32_t platform); -- Gitee From 0c4e3cfca8f99b453b603c7445bb0263569477d4 Mon Sep 17 00:00:00 2001 From: lushi Date: Wed, 22 Dec 2021 16:46:27 +0800 Subject: [PATCH 2/3] fix bug when using flutter surface Signed-off-by: sunfei Change-Id: Ib8c58ee9df1a890eba13045e8b6edce8af3facde --- engine/flutter/shell/platform/ohos/ohos_surface_gl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index fb0b8a35..aab1dfed 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -191,12 +191,12 @@ bool OhosSurfaceGL::InitRenderSurface() auto surfaceNode = window_->GetSurfaceNode(); if (!surfaceNode) { FML_LOG(ERROR) << "surface node is null"; - return; + return false; } auto surface = surfaceNode->GetSurface(); if (!surface) { FML_LOG(ERROR) << "surface is null"; - return; + return false; } OHOS::sptr bufferProducer = surface->GetProducer(); if (bufferProducer == nullptr) { -- Gitee From f2d3da0375c1f6305b0ca9e2b4f181eb8b3b4c5b Mon Sep 17 00:00:00 2001 From: sunfei Date: Fri, 24 Dec 2021 01:01:13 +0800 Subject: [PATCH 3/3] uicontent adapt for new rosen renderer Signed-off-by: sunfei Change-Id: I8365b48272ba18a24113d3296cec412860e7c221 --- engine/flutter/common/settings.h | 1 + engine/flutter/shell/platform/ohos/ohos_shell_holder.cc | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/flutter/common/settings.h b/engine/flutter/common/settings.h index a148d264..034e486b 100644 --- a/engine/flutter/common/settings.h +++ b/engine/flutter/common/settings.h @@ -104,6 +104,7 @@ struct Settings { // soon as a frame is rasterized. FrameRasterizedCallback frame_rasterized_callback; int32_t instanceId = 0; + bool platform_as_ui_thread = false; AcePlatform platform = AcePlatform::ACE_PLATFORM_INVALID; diff --git a/engine/flutter/shell/platform/ohos/ohos_shell_holder.cc b/engine/flutter/shell/platform/ohos/ohos_shell_holder.cc index 4c2a93b7..faeb9048 100644 --- a/engine/flutter/shell/platform/ohos/ohos_shell_holder.cc +++ b/engine/flutter/shell/platform/ohos/ohos_shell_holder.cc @@ -69,7 +69,11 @@ OhosShellHolder::OhosShellHolder( io_runner = single_task_runner; } else { gpu_runner = thread_host_.gpu_thread->GetTaskRunner(); - ui_runner = thread_host_.ui_thread->GetTaskRunner(); + if (settings_.platform_as_ui_thread) { + ui_runner = platform_runner; + } else { + ui_runner = thread_host_.ui_thread->GetTaskRunner(); + } io_runner = thread_host_.io_thread->GetTaskRunner(); } flutter::TaskRunners task_runners(thread_label, // label -- Gitee