diff --git a/entry/src/main/cpp/CMakeLists.txt b/entry/src/main/cpp/CMakeLists.txt index 98306087..e884a2e3 100644 --- a/entry/src/main/cpp/CMakeLists.txt +++ b/entry/src/main/cpp/CMakeLists.txt @@ -32,13 +32,11 @@ add_library(opencax SHARED NativeEGLOCCT/NativeRender.h NativeEGLOCCT/NativeRenderThread.h NativeEGLOCCT/NativeManager.h - NativeEGLOCCT/NativeWindow.h # Cpp Src NativeEGLOCCT/EGLCore.cpp NativeEGLOCCT/NativeRender.cpp NativeEGLOCCT/NativeRenderThread.cpp NativeEGLOCCT/NativeManager.cpp - NativeEGLOCCT/NativeWindow.cpp napi_init.cpp ) diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp index a867c002..4e381508 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp @@ -151,6 +151,11 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) { //NativeManager回调 void NativeManager::OnSurfaceCreated(OH_NativeXComponent *component, void *window) { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "XComponent_Native", "PluginManager::OnSurfaceCreated"); + if (!window) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "XComponent_Native", + "ERROR: window is NULL in OnSurfaceCreated!"); + return; + } OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); int64_t id = 0; std::lock_guard lock(mapMutex); diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp index c24ea604..270c7ffc 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp @@ -1,5 +1,6 @@ #include "NativeRender.h" + #include #include #include @@ -36,8 +37,7 @@ NativeRender::~NativeRender() { shapes_.clear(); } -bool NativeRender::init(OHNativeWindow* window,int width, int height) { - nativeWindow_=new NativeWindow(window); +bool NativeRender::init(int width, int height) { width_ = width; height_ = height; if (view_.IsNull()) { @@ -96,7 +96,6 @@ void NativeRender::setupView() { } bool NativeRender::loadModel(const std::string& filePath) { - //view_->SetWindow(nativeWindow_); // 清除现有模型 for (auto& shape : shapes_) { context_->Remove(shape, Standard_False); @@ -244,7 +243,6 @@ void NativeRender::resize(int width, int height) { width_ = width; height_ = height; if (!view_.IsNull()) { - view_->SetWindow(nativeWindow_); view_->MustBeResized(); } } diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h index f049d9a0..0de503d1 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h @@ -17,9 +17,9 @@ #include #include #include -#include "NativeWindow.h" +#include -class NativeWindow; +class Aspect_Window; class gp_Quaternion; class Graphic3d_Camera; @@ -29,7 +29,7 @@ public: NativeRender(); ~NativeRender(); - bool init(OHNativeWindow* window,int width, int height); + bool init(int width, int height); bool loadModel(const std::string& filePath); void render(); void resize(int width, int height); @@ -59,7 +59,6 @@ private: float translationX_; float translationY_; Quantity_Color clearColor_; - Handle(NativeWindow) nativeWindow_; }; } // namespace NativeRender #endif // NATIVE_RENDER_H diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp index c0fb3553..85543cf2 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp @@ -29,7 +29,7 @@ bool NativeRenderThread::start(OHNativeWindow* window) { } // 初始化OCCT渲染器 - if (!renderer_.init(nativeWindow_,windowWidth_, windowHeight_)) { + if (!renderer_.init(windowWidth_, windowHeight_)) { printf("Failed to initialize OCCT renderer\n"); eglCore_.destroy(); return false; diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.cpp deleted file mode 100644 index 22bc3a4f..00000000 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// -// Created on 2026/2/26. -// -// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, -// please include "napi/native_api.h". - -#include "NativeWindow.h" - -namespace NativeOpenCAX { - -NativeWindow::NativeWindow(OHNativeWindow *window) - :nativeWindow_(window), - width_(0), - height_(0) { - - if (!window) { - throw std::invalid_argument("OHNativeWindow cannot be null"); - } -} - -NativeWindow::~NativeWindow() {} - -void NativeWindow::Map() const { - -} -void NativeWindow::Unmap() const { - -}; -Standard_Real NativeWindow::Ratio() const { - if (height_ > 0) { - return static_cast(width_) / static_cast(height_); - } else { - // Return 1.0 if height is invalid (e.g., 0 or negative) - return 1.0; - } -} - -void NativeWindow::Position(int &theX1, int &theY1, int &theX2, int &theY2) const { - theX1 = 0; - theY1 = 0; - theX2 = width_; - theY2 = height_; -} - - -void NativeWindow::Size(int &theWidth, int &theHeight) const { - theWidth = width_; - theHeight = height_; -} -Standard_Boolean NativeWindow::IsMapped() const { - // 对于 NativeWindow,通常意味着它已经与原生窗口系统关联并准备就绪。 - // 可以根据 nativeWindow_ 是否有效来判断,或者根据实际状态。 - // 最简单的实现是返回 Standard_True。 - return Standard_True; -} - -Aspect_TypeOfResize NativeWindow::DoResize() { - return Aspect_TOR_UNKNOWN; -} - -Standard_Boolean NativeWindow::DoMapping() const { - // 通常对于嵌入式窗口,如果 NativeWindow 对象存在,我们就认为映射是有效的。 - // 这也可以根据 nativeWindow_ 的有效性来判断。 - return Standard_True; -} -Aspect_Drawable NativeWindow::NativeHandle() const { - // OHNativeWindow* 本身就可以被视为一个原生 Drawable 句柄 - // 或者你需要通过特定 API 获取更精确的句柄,例如 eglSurface_ - // 在这个场景下,直接返回 nativeWindow_ 的指针值通常是合适的。 - // 注意:Aspect_Drawable 通常是 void* 或一个整数类型。 - return reinterpret_cast(nativeWindow_); -} -Aspect_Drawable NativeWindow::NativeParentHandle() const { - // 对于 XComponent 等嵌入式窗口,通常没有明确的父窗口句柄, - // 或者其父窗口由框架管理,这里可以返回 0 或者调用特定 API 获取。 - // 暂时返回 0,表示没有或未知父窗口。 - return (Aspect_Drawable)0; - // 或者,如果你有方法获取父窗口句柄,则返回它: - // return (Aspect_Drawable)getParentNativeWindow(); -} -Aspect_FBConfig NativeWindow::NativeFBConfig() const { - // 对于大多数 Android/HarmonyOS 场景下的 OpenGL ES 应用, - // Framebuffer Config 由 EGL 管理,此函数可返回 0。 - return 0; -} -} // namespace NativeOpenCAX \ No newline at end of file diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.h b/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.h deleted file mode 100644 index b091ceef..00000000 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeWindow.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created on 2026/2/26. -// -// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, -// please include "napi/native_api.h". - -#ifndef NATIVE_WINDOW_H -#define NATIVE_WINDOW_H -#include "Aspect_Window.hxx" -#include -namespace NativeOpenCAX { - -class NativeWindow : public Aspect_Window { -public: - explicit NativeWindow(OHNativeWindow *window); - virtual ~NativeWindow(); - - virtual void Map() const override; - virtual void Unmap() const override; - // Remove '= 0' from the following declarations - virtual Standard_Boolean IsMapped() const override; - virtual Aspect_TypeOfResize DoResize() override; - virtual Standard_Boolean DoMapping() const override; - virtual Standard_Real Ratio() const override; - virtual void Position(int &theX1, int &theY1, int &theX2, int &theY2) const override; - virtual void Size(int &theWidth, int &theHeight) const override; - // Remove '= 0' from the following declarations - virtual Aspect_Drawable NativeHandle() const override; - virtual Aspect_Drawable NativeParentHandle() const override; - virtual Aspect_FBConfig NativeFBConfig() const override; - OHNativeWindow *GetNativeWindow() const { return nativeWindow_; } -private: - OHNativeWindow *nativeWindow_; - mutable int width_; - mutable int height_; -}; -} // namespace NativeOpenCAX -#endif // OPENCAX_NATIVEWINDOW_H