From 279fa220d0a5de534a093af9303c9c23f689e1f1 Mon Sep 17 00:00:00 2001 From: domrjchen Date: Mon, 11 Nov 2024 12:54:30 +0800 Subject: [PATCH] Improve performance when repeatedly writing to the hardware buffer on the OHOS platform. (#327) --- src/platform/ohos/HardwareBuffer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform/ohos/HardwareBuffer.cpp b/src/platform/ohos/HardwareBuffer.cpp index f713dac1..9a79d7ad 100644 --- a/src/platform/ohos/HardwareBuffer.cpp +++ b/src/platform/ohos/HardwareBuffer.cpp @@ -22,6 +22,8 @@ #include "utils/PixelFormatUtil.h" namespace tgfx { +#define BUFFER_USAGE_MEM_MMZ_CACHE (1ULL << 5) + std::shared_ptr ImageBuffer::MakeFrom(HardwareBufferRef hardwareBuffer, YUVColorSpace colorSpace) { auto pixelBuffer = PixelBuffer::MakeFrom(hardwareBuffer); @@ -43,8 +45,9 @@ HardwareBufferRef HardwareBufferAllocate(int width, int height, bool alphaOnly) return nullptr; } OH_NativeBuffer_Config config = {width, height, NATIVEBUFFER_PIXEL_FMT_RGBA_8888, - NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | - NATIVEBUFFER_USAGE_HW_RENDER | NATIVEBUFFER_USAGE_HW_TEXTURE, + NATIVEBUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_MMZ_CACHE | + NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_HW_RENDER | + NATIVEBUFFER_USAGE_HW_TEXTURE, 0}; return OH_NativeBuffer_Alloc(&config); }