From 7e8d8e68742901caa0549a61f79ef43a9466e24e Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Thu, 23 Sep 2021 18:58:49 +0800 Subject: [PATCH 01/10] fix compile error Change-Id: I8436375281ae8cc6719bb260ed0a1b3d6b7b2b4e --- BUILD.gn | 15 +- .../shell/platform/ohos/ohos_surface.h | 6 + .../shell/platform/ohos/ohos_surface_gl.cc | 198 +++++++++++ .../shell/platform/ohos/ohos_surface_gl.h | 74 ++++ .../platform/ohos/ohos_surface_software.cc | 315 +++++++++--------- .../platform/ohos/ohos_surface_software.h | 13 +- .../shell/platform/ohos/platform_view_ohos.cc | 3 + 7 files changed, 466 insertions(+), 158 deletions(-) create mode 100644 engine/flutter/shell/platform/ohos/ohos_surface_gl.cc create mode 100644 engine/flutter/shell/platform/ohos/ohos_surface_gl.h diff --git a/BUILD.gn b/BUILD.gn index 8d5da39c..e8f69259 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -59,8 +59,7 @@ template("make_skia_deps") { deps = [ ":ace_fontmgr_$platform", ":ace_gif", - - #":ace_gpu", + ":ace_gpu", ":ace_heif", ":ace_jpeg", ":ace_libexpat", @@ -177,6 +176,7 @@ config("flutter_config") { ] } if (is_standard_system) { + cflags += [ "-DEGL_NO_X11" ] cflags_cc += [ "-Wno-thread-safety-attributes", "-Wno-thread-safety-analysis", @@ -455,6 +455,7 @@ template("flutter_engine_shell") { deps += [ "//foundation/graphic/standard:libwmclient" ] sources += [ "engine/flutter/shell/platform/ohos/ohos_shell_holder.cc", + "engine/flutter/shell/platform/ohos/ohos_surface_gl.cc", "engine/flutter/shell/platform/ohos/ohos_surface_software.cc", "engine/flutter/shell/platform/ohos/platform_task_runner_adapter.cc", "engine/flutter/shell/platform/ohos/platform_view_ohos.cc", @@ -2047,7 +2048,7 @@ ohos_source_set("ace_skia_core") { if (is_standard_system) { defines += [ "SK_SUPPORT_ATLAS_TEXT=0", - "SK_SUPPORT_GPU=0", + #"SK_SUPPORT_GPU=0", ] } else { defines += [ @@ -2553,7 +2554,8 @@ ace_pdf("ace_pdf_mac") { config("ace_gpu_config") { visibility = [ ":*" ] - include_dirs = [ "skia" ] + include_dirs = [ "skia", + "//third_party/weston/include" ] if (use_mingw_win) { include_dirs += [ "skia/third_party/externals/angle2/include" ] @@ -2636,6 +2638,7 @@ config("ace_gpu_config") { "-Wno-unused-parameter", "-fvisibility=hidden", "-Wno-extra-semi", + "-DEGL_NO_X11" ] if (use_mingw_win) { cflags_cc += [ @@ -2949,6 +2952,10 @@ ohos_source_set("ace_gpu") { sources -= [ "skia/src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp" ] sources += [ "skia/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp" ] } + + if (is_standard_system) { + deps = [ "//device/rockchip/hardware/gpu:mali-bifrost-g52-g2p0-wayland" ] + } } config("ace_typeface_freetype_config") { diff --git a/engine/flutter/shell/platform/ohos/ohos_surface.h b/engine/flutter/shell/platform/ohos/ohos_surface.h index 158f6d21..86d16137 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface.h @@ -28,6 +28,12 @@ class OhosSurface { virtual bool OnScreenSurfaceResize(const SkISize& size) = 0; virtual void SetPlatformWindow(const ::OHOS::sptr<::OHOS::Window> &window) = 0; + + virtual bool ResourceContextMakeCurrent() = 0; + + virtual bool ResourceContextClearCurrent() = 0; + + virtual void TeardownOnScreenContext() = 0; }; } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc new file mode 100644 index 00000000..41de19cf --- /dev/null +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -0,0 +1,198 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/ohos/ohos_surface_gl.h" + +#include + +#include "flutter/fml/logging.h" +#include "flutter/fml/memory/ref_ptr.h" + +namespace flutter { + +OhosSurfaceGL::OhosSurfaceGL() + : window_(nullptr), + eglRenderSurface_(nullptr), + eglDisplay_(nullptr), + eglContext_(nullptr), + eglSurface_(nullptr), + width_(0), + height_(0), + valid_(false) { + FML_LOG(ERROR) << "OhosSurfaceGL::OhosSurfaceGL xxx constructor"; +} + +bool OhosSurfaceGL::IsValid() const { + return valid_; +} + +std::unique_ptr OhosSurfaceGL::CreateGPUSurface() { + auto surface = std::make_unique(this, true); + return surface->IsValid() ? std::move(surface) : nullptr; +} + +void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) { + if (window == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; + return; + } + window_ = window; + OHOS::sptr bufferProducer = window_->GetProducer(); + if (bufferProducer == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, bufferProducer is nullptr"; + return; + } + + eglRenderSurface_ = + OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); + if (eglRenderSurface_ == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceGL::SetPlatformWindow, eglRenderSurface_ is nullptr"; + return; + } + + eglDisplay_ = eglRenderSurface_->GetEglDisplay(); + if (eglDisplay_ == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceGL::SetPlatformWindow, eglDisplay_ is nullptr"; + return; + } + + eglContext_ = eglRenderSurface_->GetEglContext(); + if (eglContext_ == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceGL::SetPlatformWindow, eglContext_ is nullptr"; + return; + } + + OHOS::SurfaceError errorCode; + errorCode = eglRenderSurface_->InitContext(eglContext_); + if (errorCode != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, InitContext error " + << errorCode; + return; + } + + eglSurface_ = eglRenderSurface_->GetEglSurface(); + if (eglSurface_ == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceGL::SetPlatformWindow, eglSurface_ is nullptr"; + return; + } + + width_ = eglRenderSurface_->GetDefaultWidth(); + height_ = eglRenderSurface_->GetDefaultHeight(); + FML_LOG(INFO) << "eglRenderSurface width " << width_ << " height " << height_; + + valid_ = true; +} + +bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize& size) { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::OnScreenSurfaceResize, surface invalid"; + return false; + } + + width_ = eglRenderSurface_->GetDefaultWidth(); + height_ = eglRenderSurface_->GetDefaultHeight(); + + return true; +} + +void OhosSurfaceGL::TeardownOnScreenContext() { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; + return; + } + + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; + return; + } + + if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT) != EGL_TRUE) { + FML_LOG(ERROR) << "Could not clear the current context"; + return; + } +} + +bool OhosSurfaceGL::ResourceContextMakeCurrent() { + return true; +} + +bool OhosSurfaceGL::ResourceContextClearCurrent() { + return true; +} + +bool OhosSurfaceGL::GLContextPresent() { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, surface invalid"; + return false; + } + + OHOS::Rect rect = {0, 0, width_, height_}; + OHOS::SurfaceError errorCode = eglRenderSurface_->SwapBuffers(rect); + if (errorCode != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, SwapBuffers error " + << errorCode; + return false; + } + + return true; +} + +intptr_t OhosSurfaceGL::GLContextFBO() const { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextFBO, surface invalid"; + return 0; + } + return static_cast(eglRenderSurface_->GetEglFbo()); +} + +bool OhosSurfaceGL::GLContextMakeCurrent() { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent, surface invalid"; + return false; + } + + // Avoid unused egl called. + if (eglGetCurrentContext() == eglContext_) { + return true; + } + + if (eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != + EGL_TRUE) { + FML_LOG(ERROR) << "Could not make the context current"; + return false; + } + + return true; +} + +bool OhosSurfaceGL::GLContextClearCurrent() { + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; + return false; + } + + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; + return true; + } + + if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT) != EGL_TRUE) { + FML_LOG(ERROR) << "Could not clear the current context"; + return false; + } + + return true; +} + +ExternalViewEmbedder* OhosSurfaceGL::GetExternalViewEmbedder() { + return nullptr; +} + +} // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h new file mode 100644 index 00000000..3efbb6cd --- /dev/null +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -0,0 +1,74 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ +#define FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ + +#include + +#include "flutter/fml/macros.h" +#include "flutter/shell/gpu/gpu_surface_gl.h" +#include "flutter/shell/platform/ohos/ohos_surface.h" +#include "egl_surface.h" + +namespace flutter { + +class OhosSurfaceGL final : public GPUSurfaceGLDelegate, public OhosSurface { + public: + OhosSurfaceGL(); + + ~OhosSurfaceGL() override = default; + + // |OhosSurface| + bool IsValid() const override; + + // |OhosSurface| + std::unique_ptr CreateGPUSurface() override; + + // |OhosSurface| + void SetPlatformWindow(const ::OHOS::sptr& window) override; + + // |OhosSurface| + bool OnScreenSurfaceResize(const SkISize& size) override; + + // |OhosSurface| + void TeardownOnScreenContext() override; + + // |OhosSurface| + bool ResourceContextMakeCurrent() override; + + // |OhosSurface| + bool ResourceContextClearCurrent() override; + + // |GPUSurfaceGLDelegate| + bool GLContextPresent() override; + + // |GPUSurfaceGLDelegate| + intptr_t GLContextFBO() const override; + + // |GPUSurfaceGLDelegate| + bool GLContextMakeCurrent() override; + + // |GPUSurfaceGLDelegate| + bool GLContextClearCurrent() override; + + // |GPUSurfaceGLDelegate| + ExternalViewEmbedder* GetExternalViewEmbedder() override; + + private: + OHOS::sptr window_; + OHOS::sptr eglRenderSurface_; + EGLDisplay eglDisplay_; + EGLContext eglContext_; + EGLSurface eglSurface_; + int32_t width_; + int32_t height_; + bool valid_; + + FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 2cb0db2f..63df0ff4 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -17,194 +17,205 @@ namespace flutter { namespace { - bool GetSkColorType(int32_t buffer_format, SkColorType* color_type, - SkAlphaType* alpha_type) -{ - switch (buffer_format) { - case PIXEL_FMT_RGB_565: - *color_type = kRGB_565_SkColorType; - *alpha_type = kOpaque_SkAlphaType; - return true; - case PIXEL_FMT_RGBA_8888: - *color_type = kRGBA_8888_SkColorType; - *alpha_type = kPremul_SkAlphaType; - return true; - default: - return false; - } - return false; + SkAlphaType* alpha_type) { + switch (buffer_format) { + case PIXEL_FMT_RGB_565: + *color_type = kRGB_565_SkColorType; + *alpha_type = kOpaque_SkAlphaType; + return true; + case PIXEL_FMT_RGBA_8888: + *color_type = kRGBA_8888_SkColorType; + *alpha_type = kPremul_SkAlphaType; + return true; + default: + return false; + } + return false; } } // anonymous namespace -OhosSurfaceSoftware::OhosSurfaceSoftware() -{ - GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); +OhosSurfaceSoftware::OhosSurfaceSoftware() { + FML_LOG(ERROR) << "OhosSurfaceSoftware::OhosSurfaceSoftware xxx constructor"; + GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } -bool OhosSurfaceSoftware::IsValid() const -{ - return true; +bool OhosSurfaceSoftware::IsValid() const { + return true; } -std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() -{ - if (!IsValid()) { - return nullptr; - } +std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() { + if (!IsValid()) { + return nullptr; + } - auto surface = std::make_unique(this); + auto surface = std::make_unique(this); - if (!surface->IsValid()) { - return nullptr; - } + if (!surface->IsValid()) { + return nullptr; + } - return surface; + return surface; } -bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) -{ - FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software surface do noting"; - requestConfig_.width = size.fWidth; - requestConfig_.height = size.fHeight; - return true; +bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) { + FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software " + "surface do noting"; + requestConfig_.width = size.fWidth; + requestConfig_.height = size.fHeight; + return true; } -void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &window) -{ - if (window == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, window is nullptr"; - return; - } - window_ = window; - surface_ = window->GetSurface(); - if (surface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, surface_ is nullptr"; - return; - } - requestConfig_ = { - .width = surface_->GetDefaultWidth(), - .height = surface_->GetDefaultHeight(), - .strideAlignment = 0x8, - .format = PIXEL_FMT_RGBA_8888, - .usage = surface_->GetDefaultUsage(), - }; - // Set buffer size to 5 for enough buffer - surface_->SetQueueSize(5); +void OhosSurfaceSoftware::SetPlatformWindow( + const OHOS::sptr& window) { + if (window == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceSoftware::SetPlatformWindow, window is nullptr"; + return; + } + window_ = window; + surface_ = window->GetSurface(); + if (surface_ == nullptr) { + FML_LOG(ERROR) + << "OhosSurfaceSoftware::SetPlatformWindow, surface_ is nullptr"; + return; + } + requestConfig_ = { + .width = surface_->GetDefaultWidth(), + .height = surface_->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = PIXEL_FMT_RGBA_8888, + .usage = surface_->GetDefaultUsage(), + }; + // Set buffer size to 5 for enough buffer + surface_->SetQueueSize(5); } -sk_sp OhosSurfaceSoftware::AcquireBackingStore( - const SkISize& size) -{ - TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); - if (!IsValid()) { - return nullptr; - } +sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize& size) { + TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); + if (!IsValid()) { + return nullptr; + } - if (sk_surface_ != nullptr && SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) { - // The old and new surface sizes are the same. Nothing to do here. - return sk_surface_; - } + if (sk_surface_ != nullptr && + SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) { + // The old and new surface sizes are the same. Nothing to do here. + return sk_surface_; + } - SkImageInfo image_info = SkImageInfo::Make( - size.fWidth, size.fHeight, target_color_type_, target_alpha_type_, SkColorSpace::MakeSRGB()); + SkImageInfo image_info = + SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_, + target_alpha_type_, SkColorSpace::MakeSRGB()); - sk_surface_ = SkSurface::MakeRaster(image_info); + sk_surface_ = SkSurface::MakeRaster(image_info); - return sk_surface_; + return sk_surface_; } -bool OhosSurfaceSoftware::PresentBackingStore( - sk_sp backing_store) -{ - TRACE_EVENT0("flutter", "OhosSurfaceSoftware::PresentBackingStore"); - if (!IsValid() || backing_store == nullptr) { - return false; - } - - FML_LOG(INFO) << "OhosSurfaceSoftware peek pixels"; - SkPixmap pixmap; - if (!backing_store->peekPixels(&pixmap)) { - return false; - } +bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) { + TRACE_EVENT0("flutter", "OhosSurfaceSoftware::PresentBackingStore"); + if (!IsValid() || backing_store == nullptr) { + return false; + } - if (surface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surface is nullptr"; - return false; - } + FML_LOG(INFO) << "OhosSurfaceSoftware peek pixels"; + SkPixmap pixmap; + if (!backing_store->peekPixels(&pixmap)) { + return false; + } - OHOS::BufferRequestConfig requestConfig = { - .width = requestConfig_.width, - .height = requestConfig_.height, - .strideAlignment = 8, - .format = PIXEL_FMT_RGBA_8888, - .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, - .timeout = 0, - }; - OHOS::sptr surfaceBuffer; - int32_t releaseFence; - - OHOS::SurfaceError ret = surface_->RequestBuffer(surfaceBuffer, releaseFence, requestConfig); - if (ret != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceSoftware RequestBuffer failed"; - return false; - } + if (surface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surface is nullptr"; + return false; + } + + OHOS::BufferRequestConfig requestConfig = { + .width = requestConfig_.width, + .height = requestConfig_.height, + .strideAlignment = 8, + .format = PIXEL_FMT_RGBA_8888, + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, + .timeout = 0, + }; + OHOS::sptr surfaceBuffer; + int32_t releaseFence; + + OHOS::SurfaceError ret = + surface_->RequestBuffer(surfaceBuffer, releaseFence, requestConfig); + if (ret != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceSoftware RequestBuffer failed"; + return false; + } - if (surfaceBuffer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer is nullptr"; - return false; - } + if (surfaceBuffer == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer is nullptr"; + return false; + } - if (surfaceBuffer->GetVirAddr() == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer addr is nullptr"; - return false; - } + if (surfaceBuffer->GetVirAddr() == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer addr is nullptr"; + return false; + } - if (surfaceBuffer->GetSize() == 0) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer size error"; - return false; + if (surfaceBuffer->GetSize() == 0) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer size error"; + return false; + } + + memset(surfaceBuffer->GetVirAddr(), 0, surfaceBuffer->GetSize()); + + SkColorType color_type; + SkAlphaType alpha_type; + if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { + SkImageInfo native_image_info = SkImageInfo::Make( + requestConfig.width, requestConfig.height, color_type, alpha_type); + + std::unique_ptr canvas = SkCanvas::MakeRasterDirect( + native_image_info, surfaceBuffer->GetVirAddr(), + surfaceBuffer->GetSize() / requestConfig.height); + + if (canvas) { + SkBitmap bitmap; + if (bitmap.installPixels(pixmap)) { + canvas->drawBitmapRect( + bitmap, SkRect::MakeIWH(requestConfig.width, requestConfig.height), + nullptr); + } } + } + + FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; + OHOS::BufferFlushConfig flushConfig = {.damage = + { + .x = 0, + .y = 0, + .w = requestConfig_.width, + .h = requestConfig_.height, + }, + .timestamp = 0}; + surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); + + return true; +} - memset(surfaceBuffer->GetVirAddr(), 0, surfaceBuffer->GetSize()); - - SkColorType color_type; - SkAlphaType alpha_type; - if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { - SkImageInfo native_image_info = SkImageInfo::Make( - requestConfig.width, requestConfig.height, color_type, alpha_type); - - std::unique_ptr canvas = SkCanvas::MakeRasterDirect( - native_image_info, surfaceBuffer->GetVirAddr(), - surfaceBuffer->GetSize() / requestConfig.height); +ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() { + return nullptr; +} - if (canvas) { - SkBitmap bitmap; - if (bitmap.installPixels(pixmap)) { - canvas->drawBitmapRect(bitmap, SkRect::MakeIWH(requestConfig.width, requestConfig.height), nullptr); - } - } - } +bool OhosSurfaceSoftware::ResourceContextMakeCurrent() { + // implement in ohos surface gl + return false; +} - FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; - OHOS::BufferFlushConfig flushConfig = { - .damage = { - .x = 0, - .y = 0, - .w = requestConfig_.width, - .h = requestConfig_.height, - }, - .timestamp = 0 - }; - surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); - - return true; +bool OhosSurfaceSoftware::ResourceContextClearCurrent() { + // implement in ohos surface gl + return false; } -ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() -{ - return nullptr; +void OhosSurfaceSoftware::TeardownOnScreenContext() { + // implement in ohos surface gl } } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index 831ee420..941b28e7 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -14,7 +14,7 @@ namespace flutter { class OhosSurfaceSoftware final : public OhosSurface, - public GPUSurfaceSoftwareDelegate { + public GPUSurfaceSoftwareDelegate { public: OhosSurfaceSoftware(); @@ -26,7 +26,7 @@ class OhosSurfaceSoftware final : public OhosSurface, 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; @@ -34,6 +34,15 @@ class OhosSurfaceSoftware final : public OhosSurface, ExternalViewEmbedder* GetExternalViewEmbedder() override; + // |OhosSurface| + virtual bool ResourceContextMakeCurrent() override; + + // |OhosSurface| + virtual bool ResourceContextClearCurrent() override; + + // |OhosSurface| + virtual void TeardownOnScreenContext() override; + private: sk_sp sk_surface_; SkColorType target_color_type_; diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index 862e1a25..2ac0710d 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -11,6 +11,7 @@ #include "flutter/common/settings.h" #include "flutter/shell/platform/ohos/ohos_surface_software.h" +#include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/vsync_waiter_embedder.h" namespace flutter { @@ -23,6 +24,8 @@ PlatformViewOhos::PlatformViewOhos( { if (use_software_rendering) { surface_ = std::make_unique(); + } else { + surface_ = std::make_unique(); } } -- Gitee From a5edd2bcba2b09d67f913b4984fced3f6009e05c Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Thu, 23 Sep 2021 18:58:49 +0800 Subject: [PATCH 02/10] fix compile error Change-Id: I8436375281ae8cc6719bb260ed0a1b3d6b7b2b4e --- .../shell/platform/ohos/ohos_surface_gl.cc | 287 ++++++++-------- .../shell/platform/ohos/ohos_surface_gl.h | 75 ++-- .../platform/ohos/ohos_surface_software.cc | 325 +++++++++--------- .../platform/ohos/ohos_surface_software.h | 51 ++- .../shell/platform/ohos/platform_view_ohos.cc | 7 +- 5 files changed, 374 insertions(+), 371 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index 41de19cf..df523c83 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -19,180 +19,183 @@ OhosSurfaceGL::OhosSurfaceGL() eglSurface_(nullptr), width_(0), height_(0), - valid_(false) { - FML_LOG(ERROR) << "OhosSurfaceGL::OhosSurfaceGL xxx constructor"; + valid_(false) +{ + FML_LOG(INFO) << "OhosSurfaceGL::OhosSurfaceGL constructor"; } -bool OhosSurfaceGL::IsValid() const { - return valid_; +bool OhosSurfaceGL::IsValid() const +{ + return valid_; } -std::unique_ptr OhosSurfaceGL::CreateGPUSurface() { - auto surface = std::make_unique(this, true); - return surface->IsValid() ? std::move(surface) : nullptr; +std::unique_ptr OhosSurfaceGL::CreateGPUSurface() +{ + auto surface = std::make_unique(this, true); + return surface->IsValid() ? std::move(surface) : nullptr; } -void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) { - if (window == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; - return; - } - window_ = window; - OHOS::sptr bufferProducer = window_->GetProducer(); - if (bufferProducer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, bufferProducer is nullptr"; - return; - } - - eglRenderSurface_ = - OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); - if (eglRenderSurface_ == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceGL::SetPlatformWindow, eglRenderSurface_ is nullptr"; - return; - } - - eglDisplay_ = eglRenderSurface_->GetEglDisplay(); - if (eglDisplay_ == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceGL::SetPlatformWindow, eglDisplay_ is nullptr"; - return; - } - - eglContext_ = eglRenderSurface_->GetEglContext(); - if (eglContext_ == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceGL::SetPlatformWindow, eglContext_ is nullptr"; - return; - } - - OHOS::SurfaceError errorCode; - errorCode = eglRenderSurface_->InitContext(eglContext_); - if (errorCode != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, InitContext error " - << errorCode; - return; - } - - eglSurface_ = eglRenderSurface_->GetEglSurface(); - if (eglSurface_ == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceGL::SetPlatformWindow, eglSurface_ is nullptr"; - return; - } - - width_ = eglRenderSurface_->GetDefaultWidth(); - height_ = eglRenderSurface_->GetDefaultHeight(); - FML_LOG(INFO) << "eglRenderSurface width " << width_ << " height " << height_; - - valid_ = true; +void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr &window) +{ + if (window == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; + return; + } + window_ = window; + OHOS::sptr bufferProducer = window_->GetProducer(); + if (bufferProducer == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, bufferProducer is nullptr"; + return; + } + + eglRenderSurface_ = OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); + if (eglRenderSurface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglRenderSurface_ is nullptr"; + return; + } + + eglDisplay_ = eglRenderSurface_->GetEglDisplay(); + if (eglDisplay_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglDisplay_ is nullptr"; + return; + } + + eglContext_ = eglRenderSurface_->GetEglContext(); + if (eglContext_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglContext_ is nullptr"; + return; + } + + OHOS::SurfaceError errorCode; + errorCode = eglRenderSurface_->InitContext(eglContext_); + if (errorCode != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, InitContext error " << errorCode; + return; + } + + eglSurface_ = eglRenderSurface_->GetEglSurface(); + if (eglSurface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglSurface_ is nullptr"; + return; + } + + width_ = eglRenderSurface_->GetDefaultWidth(); + height_ = eglRenderSurface_->GetDefaultHeight(); + FML_LOG(INFO) << "eglRenderSurface width " << width_ << " height " << height_; + + valid_ = true; } -bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize& size) { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::OnScreenSurfaceResize, surface invalid"; - return false; - } +bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize &size) +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::OnScreenSurfaceResize, surface invalid"; + return false; + } - width_ = eglRenderSurface_->GetDefaultWidth(); - height_ = eglRenderSurface_->GetDefaultHeight(); + width_ = eglRenderSurface_->GetDefaultWidth(); + height_ = eglRenderSurface_->GetDefaultHeight(); - return true; + return true; } -void OhosSurfaceGL::TeardownOnScreenContext() { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; - return; - } - - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; - return; - } - - if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not clear the current context"; - return; - } +void OhosSurfaceGL::TeardownOnScreenContext() +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; + return; + } + + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; + return; + } + + if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { + FML_LOG(ERROR) << "Could not clear the current context"; + return; + } } -bool OhosSurfaceGL::ResourceContextMakeCurrent() { - return true; +bool OhosSurfaceGL::ResourceContextMakeCurrent() +{ + return true; } -bool OhosSurfaceGL::ResourceContextClearCurrent() { - return true; +bool OhosSurfaceGL::ResourceContextClearCurrent() +{ + return true; } -bool OhosSurfaceGL::GLContextPresent() { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, surface invalid"; - return false; - } - - OHOS::Rect rect = {0, 0, width_, height_}; - OHOS::SurfaceError errorCode = eglRenderSurface_->SwapBuffers(rect); - if (errorCode != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, SwapBuffers error " - << errorCode; - return false; - } - - return true; +bool OhosSurfaceGL::GLContextPresent() +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, surface invalid"; + return false; + } + + OHOS::Rect rect = {0, 0, width_, height_}; + OHOS::SurfaceError errorCode = eglRenderSurface_->SwapBuffers(rect); + if (errorCode != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, SwapBuffers error " << errorCode; + return false; + } + + return true; } -intptr_t OhosSurfaceGL::GLContextFBO() const { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextFBO, surface invalid"; - return 0; - } - return static_cast(eglRenderSurface_->GetEglFbo()); +intptr_t OhosSurfaceGL::GLContextFBO() const +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextFBO, surface invalid"; + return 0; + } + return static_cast(eglRenderSurface_->GetEglFbo()); } -bool OhosSurfaceGL::GLContextMakeCurrent() { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent, surface invalid"; - return false; - } +bool OhosSurfaceGL::GLContextMakeCurrent() +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent, surface invalid"; + return false; + } - // Avoid unused egl called. - if (eglGetCurrentContext() == eglContext_) { - return true; - } + // Avoid unused egl called. + if (eglGetCurrentContext() == eglContext_) { + return true; + } - if (eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != - EGL_TRUE) { - FML_LOG(ERROR) << "Could not make the context current"; - return false; - } + if (eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != EGL_TRUE) { + FML_LOG(ERROR) << "Could not make the context current"; + return false; + } - return true; + return true; } -bool OhosSurfaceGL::GLContextClearCurrent() { - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; - return false; - } +bool OhosSurfaceGL::GLContextClearCurrent() +{ + if (!IsValid()) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; + return false; + } - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; - return true; - } + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; + return true; + } - if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not clear the current context"; - return false; - } + if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { + FML_LOG(ERROR) << "Could not clear the current context"; + return false; + } - return true; + return true; } -ExternalViewEmbedder* OhosSurfaceGL::GetExternalViewEmbedder() { - return nullptr; +ExternalViewEmbedder *OhosSurfaceGL::GetExternalViewEmbedder() +{ + return nullptr; } } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index 3efbb6cd..717e1a57 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -10,63 +10,64 @@ #include "flutter/fml/macros.h" #include "flutter/shell/gpu/gpu_surface_gl.h" #include "flutter/shell/platform/ohos/ohos_surface.h" + #include "egl_surface.h" namespace flutter { class OhosSurfaceGL final : public GPUSurfaceGLDelegate, public OhosSurface { - public: - OhosSurfaceGL(); +public: + OhosSurfaceGL(); - ~OhosSurfaceGL() override = default; + ~OhosSurfaceGL() override = default; - // |OhosSurface| - bool IsValid() const override; + // |OhosSurface| + bool IsValid() const override; - // |OhosSurface| - std::unique_ptr CreateGPUSurface() override; + // |OhosSurface| + std::unique_ptr CreateGPUSurface() override; - // |OhosSurface| - void SetPlatformWindow(const ::OHOS::sptr& window) override; + // |OhosSurface| + void SetPlatformWindow(const ::OHOS::sptr &window) override; - // |OhosSurface| - bool OnScreenSurfaceResize(const SkISize& size) override; + // |OhosSurface| + bool OnScreenSurfaceResize(const SkISize &size) override; - // |OhosSurface| - void TeardownOnScreenContext() override; + // |OhosSurface| + void TeardownOnScreenContext() override; - // |OhosSurface| - bool ResourceContextMakeCurrent() override; + // |OhosSurface| + bool ResourceContextMakeCurrent() override; - // |OhosSurface| - bool ResourceContextClearCurrent() override; + // |OhosSurface| + bool ResourceContextClearCurrent() override; - // |GPUSurfaceGLDelegate| - bool GLContextPresent() override; + // |GPUSurfaceGLDelegate| + bool GLContextPresent() override; - // |GPUSurfaceGLDelegate| - intptr_t GLContextFBO() const override; + // |GPUSurfaceGLDelegate| + intptr_t GLContextFBO() const override; - // |GPUSurfaceGLDelegate| - bool GLContextMakeCurrent() override; + // |GPUSurfaceGLDelegate| + bool GLContextMakeCurrent() override; - // |GPUSurfaceGLDelegate| - bool GLContextClearCurrent() override; + // |GPUSurfaceGLDelegate| + bool GLContextClearCurrent() override; - // |GPUSurfaceGLDelegate| - ExternalViewEmbedder* GetExternalViewEmbedder() override; + // |GPUSurfaceGLDelegate| + ExternalViewEmbedder *GetExternalViewEmbedder() override; - private: - OHOS::sptr window_; - OHOS::sptr eglRenderSurface_; - EGLDisplay eglDisplay_; - EGLContext eglContext_; - EGLSurface eglSurface_; - int32_t width_; - int32_t height_; - bool valid_; +private: + OHOS::sptr window_; + OHOS::sptr eglRenderSurface_; + EGLDisplay eglDisplay_; + EGLContext eglContext_; + EGLSurface eglSurface_; + int32_t width_ = 0; + int32_t height_ = 0; + bool valid_ = 0; - FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); + FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); }; } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 63df0ff4..2f31d90a 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -17,205 +17,206 @@ namespace flutter { namespace { -bool GetSkColorType(int32_t buffer_format, - SkColorType* color_type, - SkAlphaType* alpha_type) { - switch (buffer_format) { - case PIXEL_FMT_RGB_565: - *color_type = kRGB_565_SkColorType; - *alpha_type = kOpaque_SkAlphaType; - return true; - case PIXEL_FMT_RGBA_8888: - *color_type = kRGBA_8888_SkColorType; - *alpha_type = kPremul_SkAlphaType; - return true; - default: - return false; - } - return false; +bool GetSkColorType(int32_t buffer_format, SkColorType *color_type, SkAlphaType *alpha_type) +{ + switch (buffer_format) { + case PIXEL_FMT_RGB_565: + *color_type = kRGB_565_SkColorType; + *alpha_type = kOpaque_SkAlphaType; + return true; + case PIXEL_FMT_RGBA_8888: + *color_type = kRGBA_8888_SkColorType; + *alpha_type = kPremul_SkAlphaType; + return true; + default: + return false; + } + return false; } } // anonymous namespace -OhosSurfaceSoftware::OhosSurfaceSoftware() { - FML_LOG(ERROR) << "OhosSurfaceSoftware::OhosSurfaceSoftware xxx constructor"; - GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); +OhosSurfaceSoftware::OhosSurfaceSoftware() +{ + FML_LOG(INFO) << "OhosSurfaceSoftware::OhosSurfaceSoftware constructor"; + GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } -bool OhosSurfaceSoftware::IsValid() const { - return true; +bool OhosSurfaceSoftware::IsValid() const +{ + return true; } -std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() { - if (!IsValid()) { - return nullptr; - } +std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() +{ + if (!IsValid()) { + return nullptr; + } - auto surface = std::make_unique(this); + auto surface = std::make_unique(this); - if (!surface->IsValid()) { - return nullptr; - } + if (!surface->IsValid()) { + return nullptr; + } - return surface; + return surface; } -bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) { - FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software " - "surface do noting"; - requestConfig_.width = size.fWidth; - requestConfig_.height = size.fHeight; - return true; +bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize &size) +{ + FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software " + "surface do noting"; + requestConfig_.width = size.fWidth; + requestConfig_.height = size.fHeight; + return true; } -void OhosSurfaceSoftware::SetPlatformWindow( - const OHOS::sptr& window) { - if (window == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceSoftware::SetPlatformWindow, window is nullptr"; - return; - } - window_ = window; - surface_ = window->GetSurface(); - if (surface_ == nullptr) { - FML_LOG(ERROR) - << "OhosSurfaceSoftware::SetPlatformWindow, surface_ is nullptr"; - return; - } - requestConfig_ = { - .width = surface_->GetDefaultWidth(), - .height = surface_->GetDefaultHeight(), - .strideAlignment = 0x8, - .format = PIXEL_FMT_RGBA_8888, - .usage = surface_->GetDefaultUsage(), - }; - // Set buffer size to 5 for enough buffer - surface_->SetQueueSize(5); +void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &window) +{ + if (window == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, window is nullptr"; + return; + } + window_ = window; + surface_ = window->GetSurface(); + if (surface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware::SetPlatformWindow, surface_ is nullptr"; + return; + } + requestConfig_ = { + .width = surface_->GetDefaultWidth(), + .height = surface_->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = PIXEL_FMT_RGBA_8888, + .usage = surface_->GetDefaultUsage(), + }; + // Set buffer size to 5 for enough buffer + surface_->SetQueueSize(5); } -sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize& size) { - TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); - if (!IsValid()) { - return nullptr; - } +sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize &size) +{ + TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); + if (!IsValid()) { + return nullptr; + } - if (sk_surface_ != nullptr && - SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) { - // The old and new surface sizes are the same. Nothing to do here. - return sk_surface_; - } + if (sk_surface_ != nullptr && SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) { + // The old and new surface sizes are the same. Nothing to do here. + return sk_surface_; + } - SkImageInfo image_info = - SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_, - target_alpha_type_, SkColorSpace::MakeSRGB()); + SkImageInfo image_info = + SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_, target_alpha_type_, SkColorSpace::MakeSRGB()); - sk_surface_ = SkSurface::MakeRaster(image_info); + sk_surface_ = SkSurface::MakeRaster(image_info); - return sk_surface_; + return sk_surface_; } -bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) { - TRACE_EVENT0("flutter", "OhosSurfaceSoftware::PresentBackingStore"); - if (!IsValid() || backing_store == nullptr) { - return false; - } +bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) +{ + TRACE_EVENT0("flutter", "OhosSurfaceSoftware::PresentBackingStore"); + if (!IsValid() || backing_store == nullptr) { + return false; + } - FML_LOG(INFO) << "OhosSurfaceSoftware peek pixels"; - SkPixmap pixmap; - if (!backing_store->peekPixels(&pixmap)) { - return false; - } + FML_LOG(INFO) << "OhosSurfaceSoftware peek pixels"; + SkPixmap pixmap; + if (!backing_store->peekPixels(&pixmap)) { + return false; + } - if (surface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surface is nullptr"; - return false; - } - - OHOS::BufferRequestConfig requestConfig = { - .width = requestConfig_.width, - .height = requestConfig_.height, - .strideAlignment = 8, - .format = PIXEL_FMT_RGBA_8888, - .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, - .timeout = 0, - }; - OHOS::sptr surfaceBuffer; - int32_t releaseFence; - - OHOS::SurfaceError ret = - surface_->RequestBuffer(surfaceBuffer, releaseFence, requestConfig); - if (ret != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceSoftware RequestBuffer failed"; - return false; - } + if (surface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surface is nullptr"; + return false; + } - if (surfaceBuffer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer is nullptr"; - return false; - } + OHOS::BufferRequestConfig requestConfig = { + .width = requestConfig_.width, + .height = requestConfig_.height, + .strideAlignment = 8, + .format = PIXEL_FMT_RGBA_8888, + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, + .timeout = 0, + }; + OHOS::sptr surfaceBuffer; + int32_t releaseFence; + + OHOS::SurfaceError ret = surface_->RequestBuffer(surfaceBuffer, releaseFence, requestConfig); + if (ret != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceSoftware RequestBuffer failed"; + return false; + } - if (surfaceBuffer->GetVirAddr() == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer addr is nullptr"; - return false; - } + if (surfaceBuffer == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer is nullptr"; + return false; + } - if (surfaceBuffer->GetSize() == 0) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer size error"; - return false; - } - - memset(surfaceBuffer->GetVirAddr(), 0, surfaceBuffer->GetSize()); - - SkColorType color_type; - SkAlphaType alpha_type; - if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { - SkImageInfo native_image_info = SkImageInfo::Make( - requestConfig.width, requestConfig.height, color_type, alpha_type); - - std::unique_ptr canvas = SkCanvas::MakeRasterDirect( - native_image_info, surfaceBuffer->GetVirAddr(), - surfaceBuffer->GetSize() / requestConfig.height); - - if (canvas) { - SkBitmap bitmap; - if (bitmap.installPixels(pixmap)) { - canvas->drawBitmapRect( - bitmap, SkRect::MakeIWH(requestConfig.width, requestConfig.height), - nullptr); - } + if (surfaceBuffer->GetVirAddr() == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer addr is nullptr"; + return false; + } + + if (surfaceBuffer->GetSize() == 0) { + FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer size error"; + return false; } - } - - FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; - OHOS::BufferFlushConfig flushConfig = {.damage = - { - .x = 0, - .y = 0, - .w = requestConfig_.width, - .h = requestConfig_.height, - }, - .timestamp = 0}; - surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); - - return true; + + memset(surfaceBuffer->GetVirAddr(), 0, surfaceBuffer->GetSize()); + + SkColorType color_type; + SkAlphaType alpha_type; + if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { + SkImageInfo native_image_info = + SkImageInfo::Make(requestConfig.width, requestConfig.height, color_type, alpha_type); + + std::unique_ptr canvas = SkCanvas::MakeRasterDirect( + native_image_info, surfaceBuffer->GetVirAddr(), surfaceBuffer->GetSize() / requestConfig.height); + + if (canvas) { + SkBitmap bitmap; + if (bitmap.installPixels(pixmap)) { + canvas->drawBitmapRect(bitmap, SkRect::MakeIWH(requestConfig.width, requestConfig.height), nullptr); + } + } + } + + FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; + OHOS::BufferFlushConfig flushConfig = {.damage = + { + .x = 0, + .y = 0, + .w = requestConfig_.width, + .h = requestConfig_.height, + }, + .timestamp = 0}; + surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); + + return true; } -ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() { - return nullptr; +ExternalViewEmbedder *OhosSurfaceSoftware::GetExternalViewEmbedder() +{ + return nullptr; } -bool OhosSurfaceSoftware::ResourceContextMakeCurrent() { - // implement in ohos surface gl - return false; +bool OhosSurfaceSoftware::ResourceContextMakeCurrent() +{ + // implement in ohos surface gl + return false; } -bool OhosSurfaceSoftware::ResourceContextClearCurrent() { - // implement in ohos surface gl - return false; +bool OhosSurfaceSoftware::ResourceContextClearCurrent() +{ + // implement in ohos surface gl + return false; } -void OhosSurfaceSoftware::TeardownOnScreenContext() { - // implement in ohos surface gl +void OhosSurfaceSoftware::TeardownOnScreenContext() +{ + // implement in ohos surface gl } } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index 941b28e7..880c7fc9 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -13,46 +13,45 @@ namespace flutter { -class OhosSurfaceSoftware final : public OhosSurface, - public GPUSurfaceSoftwareDelegate { - public: - OhosSurfaceSoftware(); +class OhosSurfaceSoftware final : public OhosSurface, public GPUSurfaceSoftwareDelegate { +public: + OhosSurfaceSoftware(); - ~OhosSurfaceSoftware() override = default; + ~OhosSurfaceSoftware() override = default; - bool IsValid() const override; + bool IsValid() const override; - std::unique_ptr CreateGPUSurface() override; + std::unique_ptr CreateGPUSurface() override; - bool OnScreenSurfaceResize(const SkISize& size) override; + 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; + sk_sp AcquireBackingStore(const SkISize &size) override; - bool PresentBackingStore(sk_sp backing_store) override; + bool PresentBackingStore(sk_sp backing_store) override; - ExternalViewEmbedder* GetExternalViewEmbedder() override; + ExternalViewEmbedder *GetExternalViewEmbedder() override; - // |OhosSurface| - virtual bool ResourceContextMakeCurrent() override; + // |OhosSurface| + virtual bool ResourceContextMakeCurrent() override; - // |OhosSurface| - virtual bool ResourceContextClearCurrent() override; + // |OhosSurface| + virtual bool ResourceContextClearCurrent() override; - // |OhosSurface| - virtual void TeardownOnScreenContext() override; + // |OhosSurface| + virtual void TeardownOnScreenContext() override; - private: - sk_sp sk_surface_; - SkColorType target_color_type_; - SkAlphaType target_alpha_type_; +private: + sk_sp sk_surface_; + SkColorType target_color_type_; + SkAlphaType target_alpha_type_; - OHOS::sptr window_ = nullptr; - OHOS::BufferRequestConfig requestConfig_; - OHOS::sptr surface_ = nullptr; + OHOS::sptr window_ = nullptr; + OHOS::BufferRequestConfig requestConfig_; + OHOS::sptr surface_ = nullptr; - FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceSoftware); + FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceSoftware); }; } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index 2ac0710d..939f3d87 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -10,6 +10,7 @@ #include #include "flutter/common/settings.h" +#include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/ohos_surface_software.h" #include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/vsync_waiter_embedder.h" @@ -17,9 +18,7 @@ namespace flutter { PlatformViewOhos::PlatformViewOhos( - PlatformView::Delegate& delegate, - flutter::TaskRunners task_runners, - bool use_software_rendering) + PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, bool use_software_rendering) : PlatformView(delegate, std::move(task_runners)) { if (use_software_rendering) { @@ -38,7 +37,7 @@ void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) PlatformView::NotifyCreated(); } -void PlatformViewOhos::NotifyChanged(const SkISize& size) +void PlatformViewOhos::NotifyChanged(const SkISize &size) { if (surface_) { surface_->OnScreenSurfaceResize(size); -- Gitee From 3e6048324f125825785fa86e6edd96f48eef7d6f Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Thu, 23 Sep 2021 18:58:49 +0800 Subject: [PATCH 03/10] fix compile error Change-Id: I8436375281ae8cc6719bb260ed0a1b3d6b7b2b4e --- .../platform/ohos/ohos_surface_software.cc | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 2f31d90a..5267d3eb 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -64,8 +64,7 @@ std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize &size) { - FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software " - "surface do noting"; + FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software surface do noting"; requestConfig_.width = size.fWidth; requestConfig_.height = size.fHeight; return true; @@ -184,14 +183,15 @@ bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) } FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; - OHOS::BufferFlushConfig flushConfig = {.damage = - { - .x = 0, - .y = 0, - .w = requestConfig_.width, - .h = requestConfig_.height, - }, - .timestamp = 0}; + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .x = 0, + .y = 0, + .w = requestConfig_.width, + .h = requestConfig_.height, + }, + .timestamp = 0 + }; surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); return true; -- Gitee From 5be44ae007792c32d4a88663bffc4af087c6e8d4 Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Thu, 23 Sep 2021 18:58:49 +0800 Subject: [PATCH 04/10] fix compile error Change-Id: I8436375281ae8cc6719bb260ed0a1b3d6b7b2b4e --- engine/flutter/shell/platform/ohos/ohos_surface_gl.cc | 6 +++--- engine/flutter/shell/platform/ohos/ohos_surface_gl.h | 8 ++++---- .../shell/platform/ohos/ohos_surface_software.cc | 10 +++++----- .../shell/platform/ohos/ohos_surface_software.h | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index df523c83..855ad5c3 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -35,7 +35,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) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; @@ -86,7 +86,7 @@ void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr &window) valid_ = true; } -bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize &size) +bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize& size) { if (!IsValid()) { FML_LOG(ERROR) << "OhosSurfaceGL::OnScreenSurfaceResize, surface invalid"; @@ -193,7 +193,7 @@ bool OhosSurfaceGL::GLContextClearCurrent() return true; } -ExternalViewEmbedder *OhosSurfaceGL::GetExternalViewEmbedder() +ExternalViewEmbedder* OhosSurfaceGL::GetExternalViewEmbedder() { return nullptr; } diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index 717e1a57..fb6169a9 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -28,10 +28,10 @@ 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; + bool OnScreenSurfaceResize(const SkISize& size) override; // |OhosSurface| void TeardownOnScreenContext() override; @@ -55,7 +55,7 @@ public: bool GLContextClearCurrent() override; // |GPUSurfaceGLDelegate| - ExternalViewEmbedder *GetExternalViewEmbedder() override; + ExternalViewEmbedder* GetExternalViewEmbedder() override; private: OHOS::sptr window_; @@ -65,7 +65,7 @@ private: EGLSurface eglSurface_; int32_t width_ = 0; int32_t height_ = 0; - bool valid_ = 0; + bool valid_ = false; FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); }; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 5267d3eb..e9af38cd 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -17,7 +17,7 @@ namespace flutter { namespace { -bool GetSkColorType(int32_t buffer_format, SkColorType *color_type, SkAlphaType *alpha_type) +bool GetSkColorType(int32_t buffer_format, SkColorType* color_type, SkAlphaType* alpha_type) { switch (buffer_format) { case PIXEL_FMT_RGB_565: @@ -62,7 +62,7 @@ std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() return surface; } -bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize &size) +bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) { FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software surface do noting"; requestConfig_.width = size.fWidth; @@ -70,7 +70,7 @@ 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"; @@ -93,7 +93,7 @@ void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &wind surface_->SetQueueSize(5); } -sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize &size) +sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize& size) { TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); if (!IsValid()) { @@ -197,7 +197,7 @@ bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) return true; } -ExternalViewEmbedder *OhosSurfaceSoftware::GetExternalViewEmbedder() +ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() { return nullptr; } diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index 880c7fc9..ce069479 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -23,15 +23,15 @@ public: std::unique_ptr CreateGPUSurface() override; - bool OnScreenSurfaceResize(const SkISize &size) override; + 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; + sk_sp AcquireBackingStore(const SkISize& size) override; bool PresentBackingStore(sk_sp backing_store) override; - ExternalViewEmbedder *GetExternalViewEmbedder() override; + ExternalViewEmbedder* GetExternalViewEmbedder() override; // |OhosSurface| virtual bool ResourceContextMakeCurrent() override; -- Gitee From 1de3412bab1a081d2d7dd7837c1879e31808ce4b Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Fri, 24 Sep 2021 10:35:59 +0800 Subject: [PATCH 05/10] enable gpu Change-Id: I2f76ea256656bef172e7c46e1d6586f12c35a634 --- BUILD.gn | 4 +- engine/flutter/lib/ui/window/window.h | 1 + engine/flutter/shell/common/rasterizer.cc | 15 +++ .../shell/platform/ohos/ohos_surface_gl.cc | 126 +++++++++++------- .../shell/platform/ohos/ohos_surface_gl.h | 3 + .../shell/platform/ohos/platform_view_ohos.cc | 12 +- 6 files changed, 102 insertions(+), 59 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index e8f69259..3cdb1f5c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2047,8 +2047,8 @@ ohos_source_set("ace_skia_core") { if (is_standard_system) { defines += [ - "SK_SUPPORT_ATLAS_TEXT=0", - #"SK_SUPPORT_GPU=0", + "SK_SUPPORT_ATLAS_TEXT=1", + "SK_GL", ] } else { defines += [ diff --git a/engine/flutter/lib/ui/window/window.h b/engine/flutter/lib/ui/window/window.h index 721c075b..e067c46b 100644 --- a/engine/flutter/lib/ui/window/window.h +++ b/engine/flutter/lib/ui/window/window.h @@ -12,6 +12,7 @@ #include "flutter/fml/time/time_point.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/viewport_metrics.h" +#include "third_party/flutter/skia/include/gpu/GrContext.h" #include "flutter/lib/ui/window/platform_message.h" namespace flutter { diff --git a/engine/flutter/shell/common/rasterizer.cc b/engine/flutter/shell/common/rasterizer.cc index fa8dcfd4..d5356cc0 100644 --- a/engine/flutter/shell/common/rasterizer.cc +++ b/engine/flutter/shell/common/rasterizer.cc @@ -18,6 +18,10 @@ namespace flutter { +// The rasterizer will tell Skia to purge cached resources that have not been +// used within this interval. +static constexpr std::chrono::milliseconds kSkiaCleanupExpiration(15000); + // TODO(dnfield): Remove this once internal embedders have caught up. static Rasterizer::DummyDelegate dummy_delegate_; Rasterizer::Rasterizer( @@ -259,6 +263,10 @@ RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { } FireNextFrameCallbackIfPresent(); + if (surface_->GetContext()) { + surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); + } + return raster_status; } @@ -440,6 +448,13 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { if (!surface_) { return; } + + GrContext* context = surface_->GetContext(); + if (context) { + int max_resources; + context->getResourceCacheLimits(&max_resources, nullptr); + context->setResourceCacheLimits(max_resources, max_bytes); + } } std::optional Rasterizer::GetResourceCacheMaxBytes() const { diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index 855ad5c3..7d9fd1aa 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -5,6 +5,7 @@ #include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include +#include #include "flutter/fml/logging.h" #include "flutter/fml/memory/ref_ptr.h" @@ -17,11 +18,11 @@ OhosSurfaceGL::OhosSurfaceGL() eglDisplay_(nullptr), eglContext_(nullptr), eglSurface_(nullptr), + eglShareContext_(nullptr), width_(0), height_(0), valid_(false) { - FML_LOG(INFO) << "OhosSurfaceGL::OhosSurfaceGL constructor"; } bool OhosSurfaceGL::IsValid() const @@ -41,49 +42,13 @@ void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; return; } - window_ = window; - OHOS::sptr bufferProducer = window_->GetProducer(); - if (bufferProducer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, bufferProducer is nullptr"; - return; - } - - eglRenderSurface_ = OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); - if (eglRenderSurface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglRenderSurface_ is nullptr"; - return; - } - eglDisplay_ = eglRenderSurface_->GetEglDisplay(); - if (eglDisplay_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglDisplay_ is nullptr"; - return; - } - - eglContext_ = eglRenderSurface_->GetEglContext(); - if (eglContext_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglContext_ is nullptr"; - return; - } - - OHOS::SurfaceError errorCode; - errorCode = eglRenderSurface_->InitContext(eglContext_); - if (errorCode != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, InitContext error " << errorCode; - return; - } + window_ = window; - eglSurface_ = eglRenderSurface_->GetEglSurface(); - if (eglSurface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, eglSurface_ is nullptr"; - return; + // init render surface + if (!this->InitRenderSurface()) { + FML_LOG(ERROR) << "OhosSurfaceGL::CreateGPUSurface InitRenderSurface error"; } - - width_ = eglRenderSurface_->GetDefaultWidth(); - height_ = eglRenderSurface_->GetDefaultHeight(); - FML_LOG(INFO) << "eglRenderSurface width " << width_ << " height " << height_; - - valid_ = true; } bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize& size) @@ -106,8 +71,8 @@ void OhosSurfaceGL::TeardownOnScreenContext() return; } - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; + if (eglGetCurrentContext() != eglShareContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, share context diff"; return; } @@ -119,12 +84,12 @@ void OhosSurfaceGL::TeardownOnScreenContext() bool OhosSurfaceGL::ResourceContextMakeCurrent() { - return true; + return false; } bool OhosSurfaceGL::ResourceContextClearCurrent() { - return true; + return false; } bool OhosSurfaceGL::GLContextPresent() @@ -150,6 +115,7 @@ intptr_t OhosSurfaceGL::GLContextFBO() const FML_LOG(ERROR) << "OhosSurfaceGL::GLContextFBO, surface invalid"; return 0; } + return static_cast(eglRenderSurface_->GetEglFbo()); } @@ -161,12 +127,13 @@ bool OhosSurfaceGL::GLContextMakeCurrent() } // Avoid unused egl called. - if (eglGetCurrentContext() == eglContext_) { + if (eglGetCurrentContext() == eglShareContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent share context same"; return true; } - if (eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not make the context current"; + if ((eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglShareContext_) != EGL_TRUE)) { + FML_LOG(ERROR) << "Could not make the context current code" << eglGetError(); return false; } @@ -180,13 +147,13 @@ bool OhosSurfaceGL::GLContextClearCurrent() return false; } - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; + if (eglGetCurrentContext() != eglShareContext_) { + FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent share context diff"; return true; } if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not clear the current context"; + FML_LOG(ERROR) << "Could not clear the current context" << eglGetError(); return false; } @@ -198,4 +165,61 @@ ExternalViewEmbedder* OhosSurfaceGL::GetExternalViewEmbedder() return nullptr; } +bool OhosSurfaceGL::InitRenderSurface() +{ + if (!window_) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, window_ is nullptr"; + return false; + } + + OHOS::sptr bufferProducer = window_->GetProducer(); + if (bufferProducer == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, bufferProducer is nullptr"; + return false; + } + + eglRenderSurface_ = OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); + if (eglRenderSurface_ == nullptr) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglRenderSurface_ is nullptr"; + return false; + } + + OHOS::SurfaceError errorCode; + errorCode = eglRenderSurface_->InitContext(); + if (errorCode != OHOS::SURFACE_ERROR_OK) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, InitContext error " << errorCode; + return false; + } + + eglDisplay_ = eglRenderSurface_->GetEglDisplay(); + if (eglDisplay_ == EGL_NO_DISPLAY) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglDisplay_ is nullptr"; + return false; + } + + eglContext_ = eglRenderSurface_->GetEglContext(); + if (eglContext_ == EGL_NO_CONTEXT) { + FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglContext_ is nullptr"; + return false; + } + + // surface default EGL_NO_SURFACE + eglSurface_ = eglRenderSurface_->GetEglSurface(); + + // create offscreen context. + eglShareContext_ = eglRenderSurface_->GetSharedContext(); + if (eglShareContext_ == EGL_NO_CONTEXT) { + FML_LOG(ERROR) << "OhosContextGL::InitRenderSurface Could not get share context " << eglGetError(); + return false; + } + + width_ = eglRenderSurface_->GetDefaultWidth(); + height_ = eglRenderSurface_->GetDefaultHeight(); + valid_ = true; + + FML_LOG(INFO) << "OhosSurfaceGL::InitRenderSurface eglRenderSurface width " << width_ << " height " << height_; + + return true; +} + } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index fb6169a9..59c6ea11 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -63,10 +63,13 @@ private: EGLDisplay eglDisplay_; EGLContext eglContext_; EGLSurface eglSurface_; + EGLContext eglShareContext_; int32_t width_ = 0; int32_t height_ = 0; bool valid_ = false; + bool InitRenderSurface(); + FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); }; diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index 939f3d87..bff054ce 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -12,7 +12,6 @@ #include "flutter/common/settings.h" #include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/ohos_surface_software.h" -#include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/vsync_waiter_embedder.h" namespace flutter { @@ -21,11 +20,12 @@ PlatformViewOhos::PlatformViewOhos( PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, bool use_software_rendering) : PlatformView(delegate, std::move(task_runners)) { - if (use_software_rendering) { - surface_ = std::make_unique(); - } else { - surface_ = std::make_unique(); - } + surface_ = std::make_unique(); + // if (use_software_rendering) { + // surface_ = std::make_unique(); + // } else { + // surface_ = std::make_unique(); + // } } void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) -- Gitee From c3cd4195324b162c5087471af91dcfda7749ac49 Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Fri, 24 Sep 2021 10:35:59 +0800 Subject: [PATCH 06/10] enable gpu Change-Id: I2f76ea256656bef172e7c46e1d6586f12c35a634 --- BUILD.gn | 39 +++++++++++---- engine/flutter/lib/ui/window/window.h | 2 + engine/flutter/shell/common/rasterizer.cc | 41 +++++++++------- .../shell/platform/ohos/ohos_surface_gl.cc | 48 +++++++++++-------- .../shell/platform/ohos/ohos_surface_gl.h | 3 -- .../platform/ohos/ohos_surface_software.cc | 21 ++++---- .../shell/platform/ohos/platform_view_ohos.cc | 39 ++++++++++++--- .../shell/platform/ohos/platform_view_ohos.h | 2 +- 8 files changed, 128 insertions(+), 67 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 3cdb1f5c..744eb6f6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -59,7 +59,6 @@ template("make_skia_deps") { deps = [ ":ace_fontmgr_$platform", ":ace_gif", - ":ace_gpu", ":ace_heif", ":ace_jpeg", ":ace_libexpat", @@ -85,6 +84,9 @@ template("make_skia_deps") { if (is_standard_system) { deps += [ ":make_third_party_skia_include_dir" ] + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { + deps += [ ":ace_gpu" ] + } } } } @@ -164,6 +166,9 @@ config("flutter_config") { "-Os", ] defines = [] + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { + defines += [ "ENABLE_GPU" ] + } if (use_mingw_win || use_mac) { defines += ace_common_defines @@ -176,6 +181,7 @@ config("flutter_config") { ] } if (is_standard_system) { + cflags += [ "-DEGL_NO_X11" ] cflags_cc += [ "-Wno-thread-safety-attributes", @@ -2046,10 +2052,17 @@ ohos_source_set("ace_skia_core") { ] if (is_standard_system) { - defines += [ - "SK_SUPPORT_ATLAS_TEXT=1", - "SK_GL", - ] + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { + defines += [ + "SK_SUPPORT_ATLAS_TEXT=1", + "SK_GL" + ] + } else { + defines += [ + "SK_SUPPORT_ATLAS_TEXT=0", + "SK_SUPPORT_GPU=0", + ] + } } else { defines += [ "SK_SUPPORT_ATLAS_TEXT=1", @@ -2554,8 +2567,12 @@ ace_pdf("ace_pdf_mac") { config("ace_gpu_config") { visibility = [ ":*" ] - include_dirs = [ "skia", - "//third_party/weston/include" ] + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { + include_dirs = [ "skia", + "//third_party/weston/include" ] + } else { + include_dirs = [ "skia" ] + } if (use_mingw_win) { include_dirs += [ "skia/third_party/externals/angle2/include" ] @@ -2638,8 +2655,12 @@ config("ace_gpu_config") { "-Wno-unused-parameter", "-fvisibility=hidden", "-Wno-extra-semi", - "-DEGL_NO_X11" ] + + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { + cflags += [ "-DEGL_NO_X11" ] + } + if (use_mingw_win) { cflags_cc += [ "-Wno-unknown-pragmas", @@ -2953,7 +2974,7 @@ ohos_source_set("ace_gpu") { sources += [ "skia/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp" ] } - if (is_standard_system) { + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { deps = [ "//device/rockchip/hardware/gpu:mali-bifrost-g52-g2p0-wayland" ] } } diff --git a/engine/flutter/lib/ui/window/window.h b/engine/flutter/lib/ui/window/window.h index e067c46b..93798850 100644 --- a/engine/flutter/lib/ui/window/window.h +++ b/engine/flutter/lib/ui/window/window.h @@ -12,7 +12,9 @@ #include "flutter/fml/time/time_point.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/viewport_metrics.h" +#ifdef ENABLE_GPU #include "third_party/flutter/skia/include/gpu/GrContext.h" +#endif #include "flutter/lib/ui/window/platform_message.h" namespace flutter { diff --git a/engine/flutter/shell/common/rasterizer.cc b/engine/flutter/shell/common/rasterizer.cc index d5356cc0..2898efa9 100644 --- a/engine/flutter/shell/common/rasterizer.cc +++ b/engine/flutter/shell/common/rasterizer.cc @@ -18,9 +18,11 @@ namespace flutter { +#ifdef ENABLE_GPU // The rasterizer will tell Skia to purge cached resources that have not been // used within this interval. static constexpr std::chrono::milliseconds kSkiaCleanupExpiration(15000); +#endif // TODO(dnfield): Remove this once internal embedders have caught up. static Rasterizer::DummyDelegate dummy_delegate_; @@ -263,9 +265,11 @@ RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { } FireNextFrameCallbackIfPresent(); +#ifdef ENABLE_GPU if (surface_->GetContext()) { - surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); + surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); } +#endif return raster_status; } @@ -448,26 +452,29 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { if (!surface_) { return; } - - GrContext* context = surface_->GetContext(); - if (context) { - int max_resources; - context->getResourceCacheLimits(&max_resources, nullptr); - context->setResourceCacheLimits(max_resources, max_bytes); - } +#ifdef ENABLE_GPU + GrContext* context = surface_->GetContext(); + if (context) { + int max_resources; + context->getResourceCacheLimits(&max_resources, nullptr); + context->setResourceCacheLimits(max_resources, max_bytes); + } +#endif } std::optional Rasterizer::GetResourceCacheMaxBytes() const { - if (!surface_) { + if (!surface_) { + return std::nullopt; + } +#ifdef ENABLE_GPU + GrContext* context = surface_->GetContext(); + if (context) { + size_t max_bytes; + context->getResourceCacheLimits(nullptr, &max_bytes); + return max_bytes; + } +#endif return std::nullopt; - } - GrContext* context = surface_->GetContext(); - if (context) { - size_t max_bytes; - context->getResourceCacheLimits(nullptr, &max_bytes); - return max_bytes; - } - return std::nullopt; } Rasterizer::Screenshot::Screenshot() {} diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index 7d9fd1aa..09c789d8 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -1,11 +1,21 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include -#include #include "flutter/fml/logging.h" #include "flutter/fml/memory/ref_ptr.h" @@ -71,8 +81,8 @@ void OhosSurfaceGL::TeardownOnScreenContext() return; } - if (eglGetCurrentContext() != eglShareContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, share context diff"; + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(INFO) << "OhosSurfaceGL::TeardownOnScreenContext, context diff"; return; } @@ -127,12 +137,12 @@ bool OhosSurfaceGL::GLContextMakeCurrent() } // Avoid unused egl called. - if (eglGetCurrentContext() == eglShareContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent share context same"; + if (eglGetCurrentContext() == eglContext_) { + FML_LOG(INFO) << "OhosSurfaceGL::GLContextMakeCurrent context same"; return true; } - if ((eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglShareContext_) != EGL_TRUE)) { + if ((eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != EGL_TRUE)) { FML_LOG(ERROR) << "Could not make the context current code" << eglGetError(); return false; } @@ -147,8 +157,8 @@ bool OhosSurfaceGL::GLContextClearCurrent() return false; } - if (eglGetCurrentContext() != eglShareContext_) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent share context diff"; + if (eglGetCurrentContext() != eglContext_) { + FML_LOG(INFO) << "OhosSurfaceGL::GLContextMakeCurrent context diff"; return true; } @@ -184,13 +194,17 @@ bool OhosSurfaceGL::InitRenderSurface() return false; } - OHOS::SurfaceError errorCode; - errorCode = eglRenderSurface_->InitContext(); + OHOS::SurfaceError errorCode = eglRenderSurface_->InitContext(); if (errorCode != OHOS::SURFACE_ERROR_OK) { FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, InitContext error " << errorCode; return false; } + if ((eglGetCurrentContext() == eglContext_) && + (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE)) { + FML_LOG(ERROR) << "Could not clear the current context" << eglGetError(); + } + eglDisplay_ = eglRenderSurface_->GetEglDisplay(); if (eglDisplay_ == EGL_NO_DISPLAY) { FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglDisplay_ is nullptr"; @@ -205,14 +219,6 @@ bool OhosSurfaceGL::InitRenderSurface() // surface default EGL_NO_SURFACE eglSurface_ = eglRenderSurface_->GetEglSurface(); - - // create offscreen context. - eglShareContext_ = eglRenderSurface_->GetSharedContext(); - if (eglShareContext_ == EGL_NO_CONTEXT) { - FML_LOG(ERROR) << "OhosContextGL::InitRenderSurface Could not get share context " << eglGetError(); - return false; - } - width_ = eglRenderSurface_->GetDefaultWidth(); height_ = eglRenderSurface_->GetDefaultHeight(); valid_ = true; diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index 59c6ea11..34150d56 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -14,7 +14,6 @@ #include "egl_surface.h" namespace flutter { - class OhosSurfaceGL final : public GPUSurfaceGLDelegate, public OhosSurface { public: OhosSurfaceGL(); @@ -72,7 +71,5 @@ private: FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); }; - } // namespace flutter - #endif // FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index e9af38cd..302102b7 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -17,7 +17,9 @@ namespace flutter { namespace { -bool GetSkColorType(int32_t buffer_format, SkColorType* color_type, SkAlphaType* alpha_type) +bool GetSkColorType(int32_t buffer_format, + SkColorType* color_type, + SkAlphaType* alpha_type) { switch (buffer_format) { case PIXEL_FMT_RGB_565: @@ -38,7 +40,6 @@ bool GetSkColorType(int32_t buffer_format, SkColorType* color_type, SkAlphaType* OhosSurfaceSoftware::OhosSurfaceSoftware() { - FML_LOG(INFO) << "OhosSurfaceSoftware::OhosSurfaceSoftware constructor"; GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } @@ -62,7 +63,7 @@ std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() return surface; } -bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) +bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize &size) { FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software surface do noting"; requestConfig_.width = size.fWidth; @@ -70,7 +71,7 @@ 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"; @@ -93,7 +94,7 @@ void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr& wind surface_->SetQueueSize(5); } -sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize& size) +sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize &size) { TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); if (!IsValid()) { @@ -113,7 +114,8 @@ sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize& size) return sk_surface_; } -bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) +bool OhosSurfaceSoftware::PresentBackingStore( + sk_sp backing_store) { TRACE_EVENT0("flutter", "OhosSurfaceSoftware::PresentBackingStore"); if (!IsValid() || backing_store == nullptr) { @@ -168,11 +170,12 @@ bool OhosSurfaceSoftware::PresentBackingStore(sk_sp backing_store) SkColorType color_type; SkAlphaType alpha_type; if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { - SkImageInfo native_image_info = - SkImageInfo::Make(requestConfig.width, requestConfig.height, color_type, alpha_type); + SkImageInfo native_image_info = SkImageInfo::Make( + requestConfig.width, requestConfig.height, color_type, alpha_type); std::unique_ptr canvas = SkCanvas::MakeRasterDirect( - native_image_info, surfaceBuffer->GetVirAddr(), surfaceBuffer->GetSize() / requestConfig.height); + native_image_info, surfaceBuffer->GetVirAddr(), + surfaceBuffer->GetSize() / requestConfig.height); if (canvas) { SkBitmap bitmap; diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index bff054ce..78628beb 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -17,21 +17,35 @@ namespace flutter { PlatformViewOhos::PlatformViewOhos( - PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, bool use_software_rendering) + PlatformView::Delegate& delegate, + flutter::TaskRunners task_runners, + bool use_software_rendering) : PlatformView(delegate, std::move(task_runners)) { - surface_ = std::make_unique(); - // if (use_software_rendering) { - // surface_ = std::make_unique(); - // } else { - // surface_ = std::make_unique(); - // } +#ifdef ENABLE_GPU + surface_ = std::make_shared(); +#else + if (use_software_rendering) { + surface_ = std::make_shared(); + } +#endif } void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) { if (surface_) { +#ifdef ENABLE_GPU + fml::AutoResetWaitableEvent latch; + fml::TaskRunner::RunNowOrPostTask( + task_runners_.GetGPUTaskRunner(), + [&latch, surface = surface_.get(), &window]() mutable { + surface->SetPlatformWindow(window); + latch.Signal(); + }); + latch.Wait(); +#else surface_->SetPlatformWindow(window); +#endif } PlatformView::NotifyCreated(); @@ -40,7 +54,18 @@ void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) void PlatformViewOhos::NotifyChanged(const SkISize &size) { if (surface_) { +#ifdef ENABLE_GPU + fml::AutoResetWaitableEvent latch; + fml::TaskRunner::RunNowOrPostTask( + task_runners_.GetGPUTaskRunner(), + [&latch, surface = surface_.get(), &size]() mutable { + surface->OnScreenSurfaceResize(size); + latch.Signal(); + }); + latch.Wait(); +#else surface_->OnScreenSurfaceResize(size); +#endif } } diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.h b/engine/flutter/shell/platform/ohos/platform_view_ohos.h index 1db43053..65983ae6 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.h +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.h @@ -22,7 +22,7 @@ public: std::unique_ptr CreateVSyncWaiter(int32_t platform); private: - std::unique_ptr surface_; + std::shared_ptr surface_; FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOhos); }; -- Gitee From bb4000fb5d4e9a7968ebed1b61bf70150a7d893f Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Tue, 28 Sep 2021 22:53:59 +0800 Subject: [PATCH 07/10] enable gpu Change-Id: Id5a98abbebc3858b6507c9fdcba3b17aadfab71a --- BUILD.gn | 1 - .../shell/platform/ohos/ohos_surface_gl.cc | 26 +++++-------------- .../shell/platform/ohos/ohos_surface_gl.h | 2 ++ .../platform/ohos/ohos_surface_software.cc | 1 + 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 744eb6f6..103359d1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -181,7 +181,6 @@ config("flutter_config") { ] } if (is_standard_system) { - cflags += [ "-DEGL_NO_X11" ] cflags_cc += [ "-Wno-thread-safety-attributes", diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index 09c789d8..e0077cd4 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -1,17 +1,8 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// 2021.4.30 platform view adapt ohos. +// Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. #include "flutter/shell/platform/ohos/ohos_surface_gl.h" @@ -21,18 +12,16 @@ #include "flutter/fml/memory/ref_ptr.h" namespace flutter { - OhosSurfaceGL::OhosSurfaceGL() : window_(nullptr), eglRenderSurface_(nullptr), eglDisplay_(nullptr), eglContext_(nullptr), - eglSurface_(nullptr), - eglShareContext_(nullptr), width_(0), height_(0), valid_(false) { + FML_LOG(WARNING) << "OhosSurfaceGL Constructor"; } bool OhosSurfaceGL::IsValid() const @@ -227,5 +216,4 @@ bool OhosSurfaceGL::InitRenderSurface() return true; } - -} // namespace flutter +} // namespace flutter \ No newline at end of file diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index 34150d56..9e4f31fd 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -1,6 +1,8 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// 2021.4.30 platform view adapt ohos. +// Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. #ifndef FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ #define FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 302102b7..ab978b25 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -40,6 +40,7 @@ bool GetSkColorType(int32_t buffer_format, OhosSurfaceSoftware::OhosSurfaceSoftware() { + FML_LOG(WARNING) << "OhosSurfaceSoftware Constructor"; GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } -- Gitee From 7abe0407311bb08e76073b60cf173484bd5167b6 Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Tue, 28 Sep 2021 22:53:59 +0800 Subject: [PATCH 08/10] enable gpu Change-Id: Id5a98abbebc3858b6507c9fdcba3b17aadfab71a --- engine/flutter/shell/platform/ohos/ohos_surface_gl.cc | 1 + engine/flutter/shell/platform/ohos/ohos_surface_gl.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc index e0077cd4..143f3ff9 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -17,6 +17,7 @@ OhosSurfaceGL::OhosSurfaceGL() eglRenderSurface_(nullptr), eglDisplay_(nullptr), eglContext_(nullptr), + eglSurface_(nullptr), width_(0), height_(0), valid_(false) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h index 9e4f31fd..f3ba6cda 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h @@ -64,7 +64,6 @@ private: EGLDisplay eglDisplay_; EGLContext eglContext_; EGLSurface eglSurface_; - EGLContext eglShareContext_; int32_t width_ = 0; int32_t height_ = 0; bool valid_ = false; -- Gitee From 0c64ba2551d82835d59e64f739b4e2ae1a01ee01 Mon Sep 17 00:00:00 2001 From: "zhang_xilong@neusoft.com" Date: Tue, 28 Sep 2021 22:53:59 +0800 Subject: [PATCH 09/10] enable gpu Change-Id: Id5a98abbebc3858b6507c9fdcba3b17aadfab71a --- engine/flutter/shell/platform/ohos/ohos_surface_gl.cc | 2 +- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 2 +- 2 files 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 143f3ff9..ea89aab0 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc @@ -22,7 +22,7 @@ OhosSurfaceGL::OhosSurfaceGL() height_(0), valid_(false) { - FML_LOG(WARNING) << "OhosSurfaceGL Constructor"; + FML_LOG(ERROR) << "OhosSurfaceGL Constructor"; } bool OhosSurfaceGL::IsValid() const diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index ab978b25..c996acaf 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -40,7 +40,7 @@ bool GetSkColorType(int32_t buffer_format, OhosSurfaceSoftware::OhosSurfaceSoftware() { - FML_LOG(WARNING) << "OhosSurfaceSoftware Constructor"; + FML_LOG(ERROR) << "OhosSurfaceSoftware Constructor"; GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } -- Gitee From ac4e25f0a283296f4dbb054aadd2be7ed0bccf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9B=A6=E9=BE=99?= Date: Wed, 29 Sep 2021 14:18:23 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!3?= =?UTF-8?q?=20:=20=E4=BD=BF=E8=83=BDGPU02'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BUILD.gn | 41 +--- engine/flutter/lib/ui/window/window.h | 3 - engine/flutter/shell/common/rasterizer.cc | 40 +--- .../shell/platform/ohos/ohos_surface.h | 6 - .../shell/platform/ohos/ohos_surface_gl.cc | 220 ------------------ .../shell/platform/ohos/ohos_surface_gl.h | 76 ------ .../platform/ohos/ohos_surface_software.cc | 28 +-- .../platform/ohos/ohos_surface_software.h | 48 ++-- .../shell/platform/ohos/platform_view_ohos.cc | 31 +-- .../shell/platform/ohos/platform_view_ohos.h | 2 +- 10 files changed, 45 insertions(+), 450 deletions(-) delete mode 100644 engine/flutter/shell/platform/ohos/ohos_surface_gl.cc delete mode 100644 engine/flutter/shell/platform/ohos/ohos_surface_gl.h diff --git a/BUILD.gn b/BUILD.gn index 103359d1..8d5da39c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -59,6 +59,8 @@ template("make_skia_deps") { deps = [ ":ace_fontmgr_$platform", ":ace_gif", + + #":ace_gpu", ":ace_heif", ":ace_jpeg", ":ace_libexpat", @@ -84,9 +86,6 @@ template("make_skia_deps") { if (is_standard_system) { deps += [ ":make_third_party_skia_include_dir" ] - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - deps += [ ":ace_gpu" ] - } } } } @@ -166,9 +165,6 @@ config("flutter_config") { "-Os", ] defines = [] - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - defines += [ "ENABLE_GPU" ] - } if (use_mingw_win || use_mac) { defines += ace_common_defines @@ -181,7 +177,6 @@ config("flutter_config") { ] } if (is_standard_system) { - cflags += [ "-DEGL_NO_X11" ] cflags_cc += [ "-Wno-thread-safety-attributes", "-Wno-thread-safety-analysis", @@ -460,7 +455,6 @@ template("flutter_engine_shell") { deps += [ "//foundation/graphic/standard:libwmclient" ] sources += [ "engine/flutter/shell/platform/ohos/ohos_shell_holder.cc", - "engine/flutter/shell/platform/ohos/ohos_surface_gl.cc", "engine/flutter/shell/platform/ohos/ohos_surface_software.cc", "engine/flutter/shell/platform/ohos/platform_task_runner_adapter.cc", "engine/flutter/shell/platform/ohos/platform_view_ohos.cc", @@ -2051,17 +2045,10 @@ ohos_source_set("ace_skia_core") { ] if (is_standard_system) { - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - defines += [ - "SK_SUPPORT_ATLAS_TEXT=1", - "SK_GL" - ] - } else { - defines += [ - "SK_SUPPORT_ATLAS_TEXT=0", - "SK_SUPPORT_GPU=0", - ] - } + defines += [ + "SK_SUPPORT_ATLAS_TEXT=0", + "SK_SUPPORT_GPU=0", + ] } else { defines += [ "SK_SUPPORT_ATLAS_TEXT=1", @@ -2566,12 +2553,7 @@ ace_pdf("ace_pdf_mac") { config("ace_gpu_config") { visibility = [ ":*" ] - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - include_dirs = [ "skia", - "//third_party/weston/include" ] - } else { - include_dirs = [ "skia" ] - } + include_dirs = [ "skia" ] if (use_mingw_win) { include_dirs += [ "skia/third_party/externals/angle2/include" ] @@ -2655,11 +2637,6 @@ config("ace_gpu_config") { "-fvisibility=hidden", "-Wno-extra-semi", ] - - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - cflags += [ "-DEGL_NO_X11" ] - } - if (use_mingw_win) { cflags_cc += [ "-Wno-unknown-pragmas", @@ -2972,10 +2949,6 @@ ohos_source_set("ace_gpu") { sources -= [ "skia/src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp" ] sources += [ "skia/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp" ] } - - if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") { - deps = [ "//device/rockchip/hardware/gpu:mali-bifrost-g52-g2p0-wayland" ] - } } config("ace_typeface_freetype_config") { diff --git a/engine/flutter/lib/ui/window/window.h b/engine/flutter/lib/ui/window/window.h index 93798850..721c075b 100644 --- a/engine/flutter/lib/ui/window/window.h +++ b/engine/flutter/lib/ui/window/window.h @@ -12,9 +12,6 @@ #include "flutter/fml/time/time_point.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/viewport_metrics.h" -#ifdef ENABLE_GPU -#include "third_party/flutter/skia/include/gpu/GrContext.h" -#endif #include "flutter/lib/ui/window/platform_message.h" namespace flutter { diff --git a/engine/flutter/shell/common/rasterizer.cc b/engine/flutter/shell/common/rasterizer.cc index 2898efa9..fa8dcfd4 100644 --- a/engine/flutter/shell/common/rasterizer.cc +++ b/engine/flutter/shell/common/rasterizer.cc @@ -18,12 +18,6 @@ namespace flutter { -#ifdef ENABLE_GPU -// The rasterizer will tell Skia to purge cached resources that have not been -// used within this interval. -static constexpr std::chrono::milliseconds kSkiaCleanupExpiration(15000); -#endif - // TODO(dnfield): Remove this once internal embedders have caught up. static Rasterizer::DummyDelegate dummy_delegate_; Rasterizer::Rasterizer( @@ -265,12 +259,6 @@ RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { } FireNextFrameCallbackIfPresent(); -#ifdef ENABLE_GPU - if (surface_->GetContext()) { - surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); - } -#endif - return raster_status; } @@ -452,29 +440,19 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { if (!surface_) { return; } -#ifdef ENABLE_GPU - GrContext* context = surface_->GetContext(); - if (context) { - int max_resources; - context->getResourceCacheLimits(&max_resources, nullptr); - context->setResourceCacheLimits(max_resources, max_bytes); - } -#endif } std::optional Rasterizer::GetResourceCacheMaxBytes() const { - if (!surface_) { - return std::nullopt; - } -#ifdef ENABLE_GPU - GrContext* context = surface_->GetContext(); - if (context) { - size_t max_bytes; - context->getResourceCacheLimits(nullptr, &max_bytes); - return max_bytes; - } -#endif + if (!surface_) { return std::nullopt; + } + GrContext* context = surface_->GetContext(); + if (context) { + size_t max_bytes; + context->getResourceCacheLimits(nullptr, &max_bytes); + return max_bytes; + } + return std::nullopt; } Rasterizer::Screenshot::Screenshot() {} diff --git a/engine/flutter/shell/platform/ohos/ohos_surface.h b/engine/flutter/shell/platform/ohos/ohos_surface.h index 86d16137..158f6d21 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface.h @@ -28,12 +28,6 @@ class OhosSurface { virtual bool OnScreenSurfaceResize(const SkISize& size) = 0; virtual void SetPlatformWindow(const ::OHOS::sptr<::OHOS::Window> &window) = 0; - - virtual bool ResourceContextMakeCurrent() = 0; - - virtual bool ResourceContextClearCurrent() = 0; - - virtual void TeardownOnScreenContext() = 0; }; } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc b/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc deleted file mode 100644 index ea89aab0..00000000 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// 2021.4.30 platform view adapt ohos. -// Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. - -#include "flutter/shell/platform/ohos/ohos_surface_gl.h" - -#include - -#include "flutter/fml/logging.h" -#include "flutter/fml/memory/ref_ptr.h" - -namespace flutter { -OhosSurfaceGL::OhosSurfaceGL() - : window_(nullptr), - eglRenderSurface_(nullptr), - eglDisplay_(nullptr), - eglContext_(nullptr), - eglSurface_(nullptr), - width_(0), - height_(0), - valid_(false) -{ - FML_LOG(ERROR) << "OhosSurfaceGL Constructor"; -} - -bool OhosSurfaceGL::IsValid() const -{ - return valid_; -} - -std::unique_ptr OhosSurfaceGL::CreateGPUSurface() -{ - auto surface = std::make_unique(this, true); - return surface->IsValid() ? std::move(surface) : nullptr; -} - -void OhosSurfaceGL::SetPlatformWindow(const OHOS::sptr& window) -{ - if (window == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::SetPlatformWindow, window is nullptr"; - return; - } - - window_ = window; - - // init render surface - if (!this->InitRenderSurface()) { - FML_LOG(ERROR) << "OhosSurfaceGL::CreateGPUSurface InitRenderSurface error"; - } -} - -bool OhosSurfaceGL::OnScreenSurfaceResize(const SkISize& size) -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::OnScreenSurfaceResize, surface invalid"; - return false; - } - - width_ = eglRenderSurface_->GetDefaultWidth(); - height_ = eglRenderSurface_->GetDefaultHeight(); - - return true; -} - -void OhosSurfaceGL::TeardownOnScreenContext() -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::TeardownOnScreenContext, surface invalid"; - return; - } - - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(INFO) << "OhosSurfaceGL::TeardownOnScreenContext, context diff"; - return; - } - - if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not clear the current context"; - return; - } -} - -bool OhosSurfaceGL::ResourceContextMakeCurrent() -{ - return false; -} - -bool OhosSurfaceGL::ResourceContextClearCurrent() -{ - return false; -} - -bool OhosSurfaceGL::GLContextPresent() -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, surface invalid"; - return false; - } - - OHOS::Rect rect = {0, 0, width_, height_}; - OHOS::SurfaceError errorCode = eglRenderSurface_->SwapBuffers(rect); - if (errorCode != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextPresent, SwapBuffers error " << errorCode; - return false; - } - - return true; -} - -intptr_t OhosSurfaceGL::GLContextFBO() const -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextFBO, surface invalid"; - return 0; - } - - return static_cast(eglRenderSurface_->GetEglFbo()); -} - -bool OhosSurfaceGL::GLContextMakeCurrent() -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextMakeCurrent, surface invalid"; - return false; - } - - // Avoid unused egl called. - if (eglGetCurrentContext() == eglContext_) { - FML_LOG(INFO) << "OhosSurfaceGL::GLContextMakeCurrent context same"; - return true; - } - - if ((eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_) != EGL_TRUE)) { - FML_LOG(ERROR) << "Could not make the context current code" << eglGetError(); - return false; - } - - return true; -} - -bool OhosSurfaceGL::GLContextClearCurrent() -{ - if (!IsValid()) { - FML_LOG(ERROR) << "OhosSurfaceGL::GLContextClearCurrent, surface invalid"; - return false; - } - - if (eglGetCurrentContext() != eglContext_) { - FML_LOG(INFO) << "OhosSurfaceGL::GLContextMakeCurrent context diff"; - return true; - } - - if (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { - FML_LOG(ERROR) << "Could not clear the current context" << eglGetError(); - return false; - } - - return true; -} - -ExternalViewEmbedder* OhosSurfaceGL::GetExternalViewEmbedder() -{ - return nullptr; -} - -bool OhosSurfaceGL::InitRenderSurface() -{ - if (!window_) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, window_ is nullptr"; - return false; - } - - OHOS::sptr bufferProducer = window_->GetProducer(); - if (bufferProducer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, bufferProducer is nullptr"; - return false; - } - - eglRenderSurface_ = OHOS::EglRenderSurface::CreateEglRenderSurfaceAsProducer(bufferProducer); - if (eglRenderSurface_ == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglRenderSurface_ is nullptr"; - return false; - } - - OHOS::SurfaceError errorCode = eglRenderSurface_->InitContext(); - if (errorCode != OHOS::SURFACE_ERROR_OK) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, InitContext error " << errorCode; - return false; - } - - if ((eglGetCurrentContext() == eglContext_) && - (eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE)) { - FML_LOG(ERROR) << "Could not clear the current context" << eglGetError(); - } - - eglDisplay_ = eglRenderSurface_->GetEglDisplay(); - if (eglDisplay_ == EGL_NO_DISPLAY) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglDisplay_ is nullptr"; - return false; - } - - eglContext_ = eglRenderSurface_->GetEglContext(); - if (eglContext_ == EGL_NO_CONTEXT) { - FML_LOG(ERROR) << "OhosSurfaceGL::InitRenderSurface, eglContext_ is nullptr"; - return false; - } - - // surface default EGL_NO_SURFACE - eglSurface_ = eglRenderSurface_->GetEglSurface(); - width_ = eglRenderSurface_->GetDefaultWidth(); - height_ = eglRenderSurface_->GetDefaultHeight(); - valid_ = true; - - FML_LOG(INFO) << "OhosSurfaceGL::InitRenderSurface eglRenderSurface width " << width_ << " height " << height_; - - return true; -} -} // namespace flutter \ No newline at end of file diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h b/engine/flutter/shell/platform/ohos/ohos_surface_gl.h deleted file mode 100644 index f3ba6cda..00000000 --- a/engine/flutter/shell/platform/ohos/ohos_surface_gl.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// 2021.4.30 platform view adapt ohos. -// Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. - -#ifndef FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ -#define FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ - -#include - -#include "flutter/fml/macros.h" -#include "flutter/shell/gpu/gpu_surface_gl.h" -#include "flutter/shell/platform/ohos/ohos_surface.h" - -#include "egl_surface.h" - -namespace flutter { -class OhosSurfaceGL final : public GPUSurfaceGLDelegate, public OhosSurface { -public: - OhosSurfaceGL(); - - ~OhosSurfaceGL() override = default; - - // |OhosSurface| - bool IsValid() const override; - - // |OhosSurface| - std::unique_ptr CreateGPUSurface() override; - - // |OhosSurface| - void SetPlatformWindow(const ::OHOS::sptr& window) override; - - // |OhosSurface| - bool OnScreenSurfaceResize(const SkISize& size) override; - - // |OhosSurface| - void TeardownOnScreenContext() override; - - // |OhosSurface| - bool ResourceContextMakeCurrent() override; - - // |OhosSurface| - bool ResourceContextClearCurrent() override; - - // |GPUSurfaceGLDelegate| - bool GLContextPresent() override; - - // |GPUSurfaceGLDelegate| - intptr_t GLContextFBO() const override; - - // |GPUSurfaceGLDelegate| - bool GLContextMakeCurrent() override; - - // |GPUSurfaceGLDelegate| - bool GLContextClearCurrent() override; - - // |GPUSurfaceGLDelegate| - ExternalViewEmbedder* GetExternalViewEmbedder() override; - -private: - OHOS::sptr window_; - OHOS::sptr eglRenderSurface_; - EGLDisplay eglDisplay_; - EGLContext eglContext_; - EGLSurface eglSurface_; - int32_t width_ = 0; - int32_t height_ = 0; - bool valid_ = false; - - bool InitRenderSurface(); - - FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceGL); -}; -} // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_GL_H_ diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index c996acaf..2cb0db2f 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -17,6 +17,7 @@ namespace flutter { namespace { + bool GetSkColorType(int32_t buffer_format, SkColorType* color_type, SkAlphaType* alpha_type) @@ -40,7 +41,6 @@ bool GetSkColorType(int32_t buffer_format, OhosSurfaceSoftware::OhosSurfaceSoftware() { - FML_LOG(ERROR) << "OhosSurfaceSoftware Constructor"; GetSkColorType(PIXEL_FMT_RGBA_8888, &target_color_type_, &target_alpha_type_); } @@ -64,7 +64,7 @@ std::unique_ptr OhosSurfaceSoftware::CreateGPUSurface() return surface; } -bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize &size) +bool OhosSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) { FML_LOG(INFO) << "OhosSurfaceSoftware::OnScreenSurfaceResize, software surface do noting"; requestConfig_.width = size.fWidth; @@ -95,7 +95,8 @@ void OhosSurfaceSoftware::SetPlatformWindow(const OHOS::sptr &wind surface_->SetQueueSize(5); } -sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize &size) +sk_sp OhosSurfaceSoftware::AcquireBackingStore( + const SkISize& size) { TRACE_EVENT0("flutter", "OhosSurfaceSoftware::AcquireBackingStore"); if (!IsValid()) { @@ -107,8 +108,8 @@ sk_sp OhosSurfaceSoftware::AcquireBackingStore(const SkISize &size) return sk_surface_; } - SkImageInfo image_info = - SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_, target_alpha_type_, SkColorSpace::MakeSRGB()); + SkImageInfo image_info = SkImageInfo::Make( + size.fWidth, size.fHeight, target_color_type_, target_alpha_type_, SkColorSpace::MakeSRGB()); sk_surface_ = SkSurface::MakeRaster(image_info); @@ -206,21 +207,4 @@ ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() return nullptr; } -bool OhosSurfaceSoftware::ResourceContextMakeCurrent() -{ - // implement in ohos surface gl - return false; -} - -bool OhosSurfaceSoftware::ResourceContextClearCurrent() -{ - // implement in ohos surface gl - return false; -} - -void OhosSurfaceSoftware::TeardownOnScreenContext() -{ - // implement in ohos surface gl -} - } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index ce069479..831ee420 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -13,45 +13,37 @@ namespace flutter { -class OhosSurfaceSoftware final : public OhosSurface, public GPUSurfaceSoftwareDelegate { -public: - OhosSurfaceSoftware(); +class OhosSurfaceSoftware final : public OhosSurface, + public GPUSurfaceSoftwareDelegate { + public: + OhosSurfaceSoftware(); - ~OhosSurfaceSoftware() override = default; + ~OhosSurfaceSoftware() override = default; - bool IsValid() const override; + bool IsValid() const override; - std::unique_ptr CreateGPUSurface() override; + std::unique_ptr CreateGPUSurface() override; - bool OnScreenSurfaceResize(const SkISize& size) override; + 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; + sk_sp AcquireBackingStore(const SkISize& size) override; - bool PresentBackingStore(sk_sp backing_store) override; + bool PresentBackingStore(sk_sp backing_store) override; - ExternalViewEmbedder* GetExternalViewEmbedder() override; + ExternalViewEmbedder* GetExternalViewEmbedder() override; - // |OhosSurface| - virtual bool ResourceContextMakeCurrent() override; + private: + sk_sp sk_surface_; + SkColorType target_color_type_; + SkAlphaType target_alpha_type_; - // |OhosSurface| - virtual bool ResourceContextClearCurrent() override; + OHOS::sptr window_ = nullptr; + OHOS::BufferRequestConfig requestConfig_; + OHOS::sptr surface_ = nullptr; - // |OhosSurface| - virtual void TeardownOnScreenContext() override; - -private: - sk_sp sk_surface_; - SkColorType target_color_type_; - SkAlphaType target_alpha_type_; - - OHOS::sptr window_ = nullptr; - OHOS::BufferRequestConfig requestConfig_; - OHOS::sptr surface_ = nullptr; - - FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceSoftware); + FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceSoftware); }; } // namespace flutter diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc index 78628beb..862e1a25 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.cc +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.cc @@ -10,7 +10,6 @@ #include #include "flutter/common/settings.h" -#include "flutter/shell/platform/ohos/ohos_surface_gl.h" #include "flutter/shell/platform/ohos/ohos_surface_software.h" #include "flutter/shell/platform/ohos/vsync_waiter_embedder.h" @@ -22,50 +21,24 @@ PlatformViewOhos::PlatformViewOhos( bool use_software_rendering) : PlatformView(delegate, std::move(task_runners)) { -#ifdef ENABLE_GPU - surface_ = std::make_shared(); -#else if (use_software_rendering) { - surface_ = std::make_shared(); + surface_ = std::make_unique(); } -#endif } void PlatformViewOhos::NotifyCreated(const ::OHOS::sptr<::OHOS::Window> &window) { if (surface_) { -#ifdef ENABLE_GPU - fml::AutoResetWaitableEvent latch; - fml::TaskRunner::RunNowOrPostTask( - task_runners_.GetGPUTaskRunner(), - [&latch, surface = surface_.get(), &window]() mutable { - surface->SetPlatformWindow(window); - latch.Signal(); - }); - latch.Wait(); -#else surface_->SetPlatformWindow(window); -#endif } PlatformView::NotifyCreated(); } -void PlatformViewOhos::NotifyChanged(const SkISize &size) +void PlatformViewOhos::NotifyChanged(const SkISize& size) { if (surface_) { -#ifdef ENABLE_GPU - fml::AutoResetWaitableEvent latch; - fml::TaskRunner::RunNowOrPostTask( - task_runners_.GetGPUTaskRunner(), - [&latch, surface = surface_.get(), &size]() mutable { - surface->OnScreenSurfaceResize(size); - latch.Signal(); - }); - latch.Wait(); -#else surface_->OnScreenSurfaceResize(size); -#endif } } diff --git a/engine/flutter/shell/platform/ohos/platform_view_ohos.h b/engine/flutter/shell/platform/ohos/platform_view_ohos.h index 65983ae6..1db43053 100644 --- a/engine/flutter/shell/platform/ohos/platform_view_ohos.h +++ b/engine/flutter/shell/platform/ohos/platform_view_ohos.h @@ -22,7 +22,7 @@ public: std::unique_ptr CreateVSyncWaiter(int32_t platform); private: - std::shared_ptr surface_; + std::unique_ptr surface_; FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOhos); }; -- Gitee