修复主窗口最大化,view没有同步问题

This commit is contained in:
JackLee 2026-03-07 21:55:39 +08:00
parent 406cd03b02
commit 19347be837
4 changed files with 17 additions and 7 deletions

View File

@ -81,6 +81,10 @@ std::string uuid_v4() {
void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) {
// [StartExclude plugin_on_surface_created]
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "XComponent_Native", "OnSurfaceCreatedCB");
//主动关闭CPU访问窗口缓冲区数据降低功耗
uint64_t usage = 0;
int32_t ret2 = OH_NativeWindow_NativeWindowHandleOpt((OHNativeWindow*)window, SET_USAGE, usage);
int32_t ret;
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
@ -163,12 +167,7 @@ void NativeManager::OnSurfaceChanged(OH_NativeXComponent *component, void *windo
{
std::lock_guard<std::mutex> lock(mapMutex);
if (renderThreadMap.find(id) != renderThreadMap.end()) {
HILOG_ERROR(NATIVE_TAG,"uint64_t Size:%{public}dX%{public}d",width_,height_);
uint32_t _width=static_cast<uint32_t>(width_);
uint32_t _height=static_cast<uint32_t>(height_);
HILOG_ERROR(NATIVE_TAG,"uint32_t Size:%{public}dX%{public}d",_width,_height);
ArkUI_NumberValue comSizeData[] = {{.u32=_width}, {.u32=_height}};
ArkUI_AttributeItem comSizeItem = {comSizeData, 2};
HILOG_ERROR(NATIVE_TAG,"uint32_t Size:%{public}dX%{public}d",width_,height_);
renderThreadMap[id]->resizeWindow(width_, height_);
}
}

View File

@ -3,6 +3,8 @@
#ifndef NATIVE_TAG
#define NATIVE_TAG "NativeRender"
#endif
static std::mutex renderMutex;
namespace NativeOpenCAX {
NativeRender::NativeRender()
@ -141,10 +143,18 @@ void NativeRender::render() {
}
void NativeRender::resize(int width, int height) {
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",width,height);
rendOption.width = width;
rendOption.height = height;
if (!rendOption.view.IsNull()) {
rendOption.window->SetSize(rendOption.width, rendOption.height);
rendOption.window->DoResize();
rendOption.view->MustBeResized();
rendOption.view->Redraw();
Standard_Integer theWidth;
Standard_Integer theHeight;
rendOption.window->Size(theWidth,theHeight);
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",theWidth,theHeight);
}
}

View File

@ -63,8 +63,8 @@ void NativeRenderThread::renderLoop() {
while (isRunning_) {
RenderCommand command;
bool hasCommand = false;
std::unique_lock<std::mutex> lock(commandMutex_);
{
std::unique_lock<std::mutex> lock(commandMutex_);
commandCondition_.wait_for(lock, std::chrono::milliseconds(16), [this] {
return !commandQueue_.empty();
});

View File

@ -48,5 +48,6 @@ bool InitView(RenderOption& opt) {
}
return false;
}
void ChangeView() {}
}