From 4729a77dbc66e7fda062b617b09db8353998015a Mon Sep 17 00:00:00 2001 From: songcongyi Date: Thu, 2 Sep 2021 20:22:40 +0800 Subject: [PATCH 1/9] fix pixel demonstrate Change-Id: I0788421ca3faebf31a985dd7692c9fb640dda639 --- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 3395043e..1bdd254f 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -122,8 +122,12 @@ bool OhosSurfaceSoftware::PresentBackingStore( return false; } + + int32_t PIXEL_BASE = 16; + int32_t convertWidth = requestConfig_.width % PIXEL_BASE == 0 ? requestConfig_.width + : (requestConfig_.width / PIXEL_BASE + 1) * PIXEL_BASE; OHOS::BufferRequestConfig requestConfig = { - .width = requestConfig_.width, + .width = convertWidth, .height = requestConfig_.height, .strideAlignment = 8, .format = PIXEL_FMT_RGBA_8888, -- Gitee From 312d6a10146d1833b6edd3fb98908f9510c10c81 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Thu, 2 Sep 2021 21:12:53 +0800 Subject: [PATCH 2/9] fix codex problem Change-Id: I293a9dae237795b49201052fdb706f6a61fd5663 --- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 1bdd254f..9e0428f0 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -126,10 +126,11 @@ bool OhosSurfaceSoftware::PresentBackingStore( int32_t PIXEL_BASE = 16; int32_t convertWidth = requestConfig_.width % PIXEL_BASE == 0 ? requestConfig_.width : (requestConfig_.width / PIXEL_BASE + 1) * PIXEL_BASE; + int32_t alignment = 8; OHOS::BufferRequestConfig requestConfig = { .width = convertWidth, .height = requestConfig_.height, - .strideAlignment = 8, + .strideAlignment = alignment, .format = PIXEL_FMT_RGBA_8888, .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, .timeout = 0, -- Gitee From 8365e9211e59f544d4b485bd3cb967a27afd7815 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 09:30:11 +0800 Subject: [PATCH 3/9] fix codex problem Change-Id: Ic093f7ac0b6dde5d567883fb93c86e83e3195b67 --- .../flutter/shell/platform/ohos/ohos_surface_software.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 9e0428f0..3b9cd403 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -123,9 +123,10 @@ bool OhosSurfaceSoftware::PresentBackingStore( } - int32_t PIXEL_BASE = 16; - int32_t convertWidth = requestConfig_.width % PIXEL_BASE == 0 ? requestConfig_.width - : (requestConfig_.width / PIXEL_BASE + 1) * PIXEL_BASE; + int32_t pixelBase = 16; + int32_t upperBase = 1; + int32_t convertWidth = requestConfig_.width % pixelBase == 0 ? requestConfig_.width + : (requestConfig_.width / pixelBase + upperBase) * pixelBase; int32_t alignment = 8; OHOS::BufferRequestConfig requestConfig = { .width = convertWidth, -- Gitee From eaf05d25df0dc9aa00642ba4f542ed67134fc139 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 10:29:18 +0800 Subject: [PATCH 4/9] fix codex Change-Id: Ibfbae8ab84a70b65853dcd2378387e96041e6db4 --- .../platform/ohos/ohos_surface_software.cc | 39 +++++++------------ .../platform/ohos/ohos_surface_software.h | 4 ++ 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 3b9cd403..9fdd0572 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -109,62 +109,51 @@ bool OhosSurfaceSoftware::PresentBackingStore( if (!IsValid() || backing_store == nullptr) { 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; } - - int32_t pixelBase = 16; - int32_t upperBase = 1; int32_t convertWidth = requestConfig_.width % pixelBase == 0 ? requestConfig_.width - : (requestConfig_.width / pixelBase + upperBase) * pixelBase; + : (requestConfig_.width / pixelBase + 1) * pixelBase; int32_t alignment = 8; OHOS::BufferRequestConfig requestConfig = { .width = convertWidth, .height = requestConfig_.height, - .strideAlignment = alignment, + .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"; + if (ret != OHOS::SURFACE_ERROR_OK || surfaceBuffer == nullptr || surfaceBuffer->GetSize() == 0) { + FML_LOG(ERROR) << "OhosSurfaceSoftware request surfaceBuffer fail"; return false; } + SurfaceDrawBuffer(requestConfig, surfaceBuffer); + SurfaceFlushBuffer(surfaceBuffer); - 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; - } + return true; +} +bool OhosSurfaceSoftware::SurfaceDrawBuffer( + OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer) +{ 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)) { @@ -172,7 +161,10 @@ bool OhosSurfaceSoftware::PresentBackingStore( } } } +} +void OhosSurfaceSoftware::SurfaceFlushBuffer(OHOS::sptr surfaceBuffer) +{ FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; OHOS::BufferFlushConfig flushConfig = { .damage = { @@ -184,13 +176,10 @@ bool OhosSurfaceSoftware::PresentBackingStore( .timestamp = 0 }; surface_->FlushBuffer(surfaceBuffer, -1, flushConfig); - - return true; } ExternalViewEmbedder* OhosSurfaceSoftware::GetExternalViewEmbedder() { return nullptr; } - } // 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 cab0ee9a..ecfa921b 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -30,6 +30,10 @@ class OhosSurfaceSoftware final : public OhosSurface, bool PresentBackingStore(sk_sp backing_store) override; + void SurfaceDrawBuffer(OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer); + + void SurfaceFlushBuffer(OHOS::sptr); + ExternalViewEmbedder* GetExternalViewEmbedder() override; private: -- Gitee From 810d4b08a6de26de09a5329fd0f849be986dbdc2 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 11:03:25 +0800 Subject: [PATCH 5/9] fix codex problem Change-Id: I15626e1a457b2f33d89c3fc30b4fb935a32eec38 --- .../flutter/shell/platform/ohos/ohos_surface_software.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 9fdd0572..49158108 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -109,11 +109,13 @@ bool OhosSurfaceSoftware::PresentBackingStore( if (!IsValid() || backing_store == nullptr) { 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; @@ -121,7 +123,6 @@ bool OhosSurfaceSoftware::PresentBackingStore( int32_t pixelBase = 16; int32_t convertWidth = requestConfig_.width % pixelBase == 0 ? requestConfig_.width : (requestConfig_.width / pixelBase + 1) * pixelBase; - int32_t alignment = 8; OHOS::BufferRequestConfig requestConfig = { .width = convertWidth, .height = requestConfig_.height, @@ -132,11 +133,13 @@ bool OhosSurfaceSoftware::PresentBackingStore( }; OHOS::sptr surfaceBuffer; int32_t releaseFence; + OHOS::SurfaceError ret = surface_->RequestBuffer(surfaceBuffer, releaseFence, requestConfig); if (ret != OHOS::SURFACE_ERROR_OK || surfaceBuffer == nullptr || surfaceBuffer->GetSize() == 0) { FML_LOG(ERROR) << "OhosSurfaceSoftware request surfaceBuffer fail"; return false; } + SurfaceDrawBuffer(requestConfig, surfaceBuffer); SurfaceFlushBuffer(surfaceBuffer); @@ -151,9 +154,11 @@ bool OhosSurfaceSoftware::SurfaceDrawBuffer( 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)) { -- Gitee From 48e64eb011256b4029f74ae0e542b0b4ebbf0155 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 11:04:39 +0800 Subject: [PATCH 6/9] fix codex problem Change-Id: I0fa68ed0919ed64e73db8a009c246fab25c3f0ac --- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 49158108..2727b1a9 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -146,7 +146,7 @@ bool OhosSurfaceSoftware::PresentBackingStore( return true; } -bool OhosSurfaceSoftware::SurfaceDrawBuffer( +void OhosSurfaceSoftware::SurfaceDrawBuffer( OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer) { SkColorType color_type; -- Gitee From 8c18075a26c3c58444aae673926f326feaa67b94 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 11:06:33 +0800 Subject: [PATCH 7/9] fix codex Change-Id: If4bd29fccbea5002841970b73853f29a24497974 --- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 2727b1a9..62ab0b68 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -140,14 +140,14 @@ bool OhosSurfaceSoftware::PresentBackingStore( return false; } - SurfaceDrawBuffer(requestConfig, surfaceBuffer); + SurfaceDrawBuffer(requestConfig, surfaceBuffer, pixmap); SurfaceFlushBuffer(surfaceBuffer); return true; } void OhosSurfaceSoftware::SurfaceDrawBuffer( - OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer) + OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer, SkPixmap& pixmap) { SkColorType color_type; SkAlphaType alpha_type; -- Gitee From d920330076ef04ef300642e8e8fe5b4dc22f68ab Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 11:17:37 +0800 Subject: [PATCH 8/9] fix pixel problem Change-Id: I59eb465d9dd93555c7ec895ec72d98baf8e7a2e3 --- engine/flutter/shell/platform/ohos/ohos_surface_software.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index ecfa921b..311563fd 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -30,7 +30,8 @@ class OhosSurfaceSoftware final : public OhosSurface, bool PresentBackingStore(sk_sp backing_store) override; - void SurfaceDrawBuffer(OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer); + void SurfaceDrawBuffer( + OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer, SkPixmap& pixmap); void SurfaceFlushBuffer(OHOS::sptr); -- Gitee From 0ee500d1f0caf8e9f6bd3730ed5409578ba1e880 Mon Sep 17 00:00:00 2001 From: songcongyi Date: Fri, 3 Sep 2021 11:33:48 +0800 Subject: [PATCH 9/9] fix codex problem Change-Id: I34f312bce557af316639304b5b6291c7e344ed41 --- engine/flutter/shell/platform/ohos/ohos_surface_software.cc | 3 ++- engine/flutter/shell/platform/ohos/ohos_surface_software.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 62ab0b68..02fd2927 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -123,10 +123,11 @@ bool OhosSurfaceSoftware::PresentBackingStore( int32_t pixelBase = 16; int32_t convertWidth = requestConfig_.width % pixelBase == 0 ? requestConfig_.width : (requestConfig_.width / pixelBase + 1) * pixelBase; + int32_t alignment = 8; OHOS::BufferRequestConfig requestConfig = { .width = convertWidth, .height = requestConfig_.height, - .strideAlignment = 8, + .strideAlignment = alignment, .format = PIXEL_FMT_RGBA_8888, .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, .timeout = 0, diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.h b/engine/flutter/shell/platform/ohos/ohos_surface_software.h index 311563fd..4c7b0d91 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -48,7 +48,6 @@ class OhosSurfaceSoftware final : public OhosSurface, FML_DISALLOW_COPY_AND_ASSIGN(OhosSurfaceSoftware); }; - } // namespace flutter #endif // FLUTTER_SHELL_PLATFORM_OHOS_OHOS_SURFACE_SOFTWARE_H_ -- Gitee