修正无效代码和实现逻辑
This commit is contained in:
parent
1314f9f551
commit
d748961030
@ -32,13 +32,11 @@ add_library(opencax SHARED
|
|||||||
NativeEGLOCCT/NativeRender.h
|
NativeEGLOCCT/NativeRender.h
|
||||||
NativeEGLOCCT/NativeRenderThread.h
|
NativeEGLOCCT/NativeRenderThread.h
|
||||||
NativeEGLOCCT/NativeManager.h
|
NativeEGLOCCT/NativeManager.h
|
||||||
NativeEGLOCCT/NativeWindow.h
|
|
||||||
# Cpp Src
|
# Cpp Src
|
||||||
NativeEGLOCCT/EGLCore.cpp
|
NativeEGLOCCT/EGLCore.cpp
|
||||||
NativeEGLOCCT/NativeRender.cpp
|
NativeEGLOCCT/NativeRender.cpp
|
||||||
NativeEGLOCCT/NativeRenderThread.cpp
|
NativeEGLOCCT/NativeRenderThread.cpp
|
||||||
NativeEGLOCCT/NativeManager.cpp
|
NativeEGLOCCT/NativeManager.cpp
|
||||||
NativeEGLOCCT/NativeWindow.cpp
|
|
||||||
napi_init.cpp
|
napi_init.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -151,6 +151,11 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {
|
|||||||
//NativeManager回调
|
//NativeManager回调
|
||||||
void NativeManager::OnSurfaceCreated(OH_NativeXComponent *component, void *window) {
|
void NativeManager::OnSurfaceCreated(OH_NativeXComponent *component, void *window) {
|
||||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "XComponent_Native", "PluginManager::OnSurfaceCreated");
|
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_);
|
OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
|
||||||
int64_t id = 0;
|
int64_t id = 0;
|
||||||
std::lock_guard<std::mutex> lock(mapMutex);
|
std::lock_guard<std::mutex> lock(mapMutex);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "NativeRender.h"
|
#include "NativeRender.h"
|
||||||
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <OSD_Environment.hxx>
|
#include <OSD_Environment.hxx>
|
||||||
@ -36,8 +37,7 @@ NativeRender::~NativeRender() {
|
|||||||
shapes_.clear();
|
shapes_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeRender::init(OHNativeWindow* window,int width, int height) {
|
bool NativeRender::init(int width, int height) {
|
||||||
nativeWindow_=new NativeWindow(window);
|
|
||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
if (view_.IsNull()) {
|
if (view_.IsNull()) {
|
||||||
@ -96,7 +96,6 @@ void NativeRender::setupView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NativeRender::loadModel(const std::string& filePath) {
|
bool NativeRender::loadModel(const std::string& filePath) {
|
||||||
//view_->SetWindow(nativeWindow_);
|
|
||||||
// 清除现有模型
|
// 清除现有模型
|
||||||
for (auto& shape : shapes_) {
|
for (auto& shape : shapes_) {
|
||||||
context_->Remove(shape, Standard_False);
|
context_->Remove(shape, Standard_False);
|
||||||
@ -244,7 +243,6 @@ void NativeRender::resize(int width, int height) {
|
|||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
if (!view_.IsNull()) {
|
if (!view_.IsNull()) {
|
||||||
view_->SetWindow(nativeWindow_);
|
|
||||||
view_->MustBeResized();
|
view_->MustBeResized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
#include <Quantity_Color.hxx>
|
#include <Quantity_Color.hxx>
|
||||||
#include <gp_Quaternion.hxx>
|
#include <gp_Quaternion.hxx>
|
||||||
#include <gp_EulerSequence.hxx>
|
#include <gp_EulerSequence.hxx>
|
||||||
#include "NativeWindow.h"
|
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||||
|
|
||||||
class NativeWindow;
|
class Aspect_Window;
|
||||||
class gp_Quaternion;
|
class gp_Quaternion;
|
||||||
class Graphic3d_Camera;
|
class Graphic3d_Camera;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public:
|
|||||||
NativeRender();
|
NativeRender();
|
||||||
~NativeRender();
|
~NativeRender();
|
||||||
|
|
||||||
bool init(OHNativeWindow* window,int width, int height);
|
bool init(int width, int height);
|
||||||
bool loadModel(const std::string& filePath);
|
bool loadModel(const std::string& filePath);
|
||||||
void render();
|
void render();
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
@ -59,7 +59,6 @@ private:
|
|||||||
float translationX_;
|
float translationX_;
|
||||||
float translationY_;
|
float translationY_;
|
||||||
Quantity_Color clearColor_;
|
Quantity_Color clearColor_;
|
||||||
Handle(NativeWindow) nativeWindow_;
|
|
||||||
};
|
};
|
||||||
} // namespace NativeRender
|
} // namespace NativeRender
|
||||||
#endif // NATIVE_RENDER_H
|
#endif // NATIVE_RENDER_H
|
||||||
|
|||||||
@ -29,7 +29,7 @@ bool NativeRenderThread::start(OHNativeWindow* window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化OCCT渲染器
|
// 初始化OCCT渲染器
|
||||||
if (!renderer_.init(nativeWindow_,windowWidth_, windowHeight_)) {
|
if (!renderer_.init(windowWidth_, windowHeight_)) {
|
||||||
printf("Failed to initialize OCCT renderer\n");
|
printf("Failed to initialize OCCT renderer\n");
|
||||||
eglCore_.destroy();
|
eglCore_.destroy();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -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<Standard_Real>(width_) / static_cast<Standard_Real>(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<Aspect_Drawable>(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
|
|
||||||
@ -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 <ace/xcomponent/native_interface_xcomponent.h>
|
|
||||||
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
|
|
||||||
Loading…
Reference in New Issue
Block a user