diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeImageAdaptor.cpp b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeImageAdaptor.cpp index f8a4f7b414a6aa2c0b30fac451832cdd79535e3e..1323233ac68d18cfe34e5c33637581400e8d1e2f 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeImageAdaptor.cpp +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeImageAdaptor.cpp @@ -199,7 +199,13 @@ bool NativeImageAdaptor::InitNativeWindow() LOGE("OH_NativeWindow_GetSurfaceId fail"); } OH_NativeWindow_DestroyNativeWindow(nativeWindow); - + OH_NativeBuffer* testbuffer; + OH_NativeBuffer_Config config111 { + .width = 100, + .height = 100, + .format = OH_NativeBuffer_Format::NATIVEBUFFER_PIXEL_FMT_BGRA_8888 + }; + testbuffer = OH_NativeBuffer_Alloc(&config111); return true; } diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.cpp b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.cpp index f69d9178a515ff867469d2b9179322596880556b..01bb75b47b0f64742169b8383249cc7a7a6b9173 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.cpp +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.cpp @@ -18,6 +18,7 @@ #include #include "logger_common.h" #include "IPCKit/ipc_cparcel.h" +#include "native_window/graphic_error_code.h" namespace NativeWindowSample { void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) @@ -91,6 +92,7 @@ bool NativeRender::Export(napi_env env, napi_value exports) napi_property_descriptor desc[] = { { "DrawColor", nullptr, NativeRender::NapiOnDraw, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "CleanCache", nullptr, NativeRender::NapiOnCleanCache, nullptr, nullptr, nullptr, napi_default, nullptr }, { "ChangeScalingMode", nullptr, NativeRender::NapiOnChangeScalingMode, nullptr, nullptr, nullptr, napi_default, nullptr }, }; @@ -140,6 +142,12 @@ napi_value NativeRender::NapiOnDraw(napi_env env, napi_callback_info info) return nullptr; } +napi_value NativeRender::NapiOnCleanCache(napi_env env, napi_callback_info info) +{ + NativeRender::GetInstance()->CleanCache(); + return nullptr; +} + napi_value NativeRender::NapiOnChangeScalingMode(napi_env env, napi_callback_info info) { NativeRender::GetInstance()->ChangeScalingMode(); @@ -260,6 +268,11 @@ void NativeRender::ChangeColor() DrawBaseColor(); } +void NativeRender::CleanCache() +{ + OH_NativeWindow_CleanCache(nativeWindow_); +} + void NativeRender::ChangeScalingMode() { flagFit_ = !flagFit_; @@ -268,7 +281,6 @@ void NativeRender::ChangeScalingMode() } else { OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow_, OH_SCALING_MODE_SCALE_CROP_V2); } - DrawBaseColor(); } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.h b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.h index 25ddd46640d22a94e02b2fa04d93214c5171bccb..7f6b454e12e1f70c139f722d2f0539bdf8d36452 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.h +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/NativeRender.h @@ -28,12 +28,14 @@ public: static napi_value GetNativeRender(napi_env env, napi_callback_info info); static napi_value NapiOnDraw(napi_env env, napi_callback_info info); static napi_value NapiOnChangeScalingMode(napi_env env, napi_callback_info info); + static napi_value NapiOnCleanCache(napi_env env, napi_callback_info info); static void Release(); bool Export(napi_env env, napi_value exports); void DrawBaseColor(); void ChangeColor(); void ChangeScalingMode(); void SetNativeWindow(OHNativeWindow* nativeWindow, uint64_t width, uint64_t height); + void CleanCache(); private: void NativeBufferApi(); diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/interface/NativeWindowContext.ts b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/interface/NativeWindowContext.ts index 7a1dfe24b8f3d8a1f6acf8cf7c804973ef13a2ef..59b96cd5da035c7a4597a89be260421f27dc5d12 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/interface/NativeWindowContext.ts +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/interface/NativeWindowContext.ts @@ -39,4 +39,5 @@ export default interface NativeWindowContext { GetBufferQueueSize(): number; GetAttachBufferCount(): number; GetCacheBufferCount(): number; + CleanCache(): number; }; diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets index ff69360f918b713f0d3a3ea141aa2f19c6572881..ebf3ad2e935e0fc3df0965d954737fcc7d06d4fc 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets @@ -158,16 +158,28 @@ struct Index { } }) .height(60) - Button(`attach buffer`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.nativeWindowContext.AttachBuffer(); - } - }) - .height(40) + Row() { + Button(`attach buffer`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.AttachBuffer(); + } + }) + .height(40) + Button(`clean cache`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.CleanCache(); + } + }) + .height(40) + } Button(`dettach buffer`) .fontSize('14fp') .fontWeight(500)