diff --git a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc index 3395043eae77635d11adecf1b630124c9e00b4cc..02fd292780b8a39284c2641ed4ccd345e82cc0f4 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.cc +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.cc @@ -116,16 +116,18 @@ bool OhosSurfaceSoftware::PresentBackingStore( return false; } - if (surface_ == nullptr) { FML_LOG(ERROR) << "OhosSurfaceSoftware surface is nullptr"; return false; } - + 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 = requestConfig_.width, + .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, @@ -134,21 +136,20 @@ bool OhosSurfaceSoftware::PresentBackingStore( 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; } - if (surfaceBuffer == nullptr) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer is nullptr"; - return false; - } + SurfaceDrawBuffer(requestConfig, surfaceBuffer, pixmap); + SurfaceFlushBuffer(surfaceBuffer); - if (surfaceBuffer->GetSize() == 0) { - FML_LOG(ERROR) << "OhosSurfaceSoftware surfaceBuffer size error"; - return false; - } + return true; +} +void OhosSurfaceSoftware::SurfaceDrawBuffer( + OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer, SkPixmap& pixmap) +{ SkColorType color_type; SkAlphaType alpha_type; if (GetSkColorType(requestConfig.format, &color_type, &alpha_type)) { @@ -166,7 +167,10 @@ bool OhosSurfaceSoftware::PresentBackingStore( } } } +} +void OhosSurfaceSoftware::SurfaceFlushBuffer(OHOS::sptr surfaceBuffer) +{ FML_LOG(INFO) << "OhosSurfaceSoftware flush buffer"; OHOS::BufferFlushConfig flushConfig = { .damage = { @@ -178,13 +182,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 cab0ee9a2e425cb2d69f59af95cc314faeb6599f..4c7b0d91b53ab8a2b66e3b4c486d2d34a0ecb042 100644 --- a/engine/flutter/shell/platform/ohos/ohos_surface_software.h +++ b/engine/flutter/shell/platform/ohos/ohos_surface_software.h @@ -30,6 +30,11 @@ class OhosSurfaceSoftware final : public OhosSurface, bool PresentBackingStore(sk_sp backing_store) override; + void SurfaceDrawBuffer( + OHOS::BufferRequestConfig& requestConfig, OHOS::sptr surfaceBuffer, SkPixmap& pixmap); + + void SurfaceFlushBuffer(OHOS::sptr); + ExternalViewEmbedder* GetExternalViewEmbedder() override; private: @@ -43,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_