mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 23:20:32 +00:00
告警清理
Signed-off-by: limingkang <limingkang1@huawei.com> Change-Id: Idc52e88615322e6dfd3a98a90f3a51554821a565
This commit is contained in:
parent
5706af7723
commit
38d3bfa5f0
@ -2,6 +2,7 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(XComponent)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_definitions(-DOHOS_PLATFORM)
|
||||
|
||||
|
@ -23,25 +23,25 @@
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
PluginManager PluginManager::m_pluginManager;
|
||||
PluginManager PluginManager::pluginmanager_;
|
||||
|
||||
PluginManager::~PluginManager()
|
||||
{
|
||||
for (auto iter = m_nativeXComponentMap.begin(); iter != m_nativeXComponentMap.end(); ++iter) {
|
||||
for (auto iter = nativeXComponentMap_.begin(); iter != nativeXComponentMap_.end(); ++iter) {
|
||||
if (iter->second != nullptr) {
|
||||
delete iter->second;
|
||||
iter->second = nullptr;
|
||||
}
|
||||
}
|
||||
m_nativeXComponentMap.clear();
|
||||
nativeXComponentMap_.clear();
|
||||
|
||||
for (auto iter = m_pluginRenderMap.begin(); iter != m_pluginRenderMap.end(); ++iter) {
|
||||
for (auto iter = pluginrendermap_.begin(); iter != pluginrendermap_.end(); ++iter) {
|
||||
if (iter->second != nullptr) {
|
||||
delete iter->second;
|
||||
iter->second = nullptr;
|
||||
}
|
||||
}
|
||||
m_pluginRenderMap.clear();
|
||||
pluginrendermap_.clear();
|
||||
}
|
||||
|
||||
void PluginManager::Export(napi_env env, napi_value exports)
|
||||
@ -76,7 +76,7 @@ void PluginManager::Export(napi_env env, napi_value exports)
|
||||
if ((context != nullptr) && (nativeXComponent != nullptr)) {
|
||||
context->SetNativeXComponent(id, nativeXComponent);
|
||||
auto render = context->GetRender(id);
|
||||
OH_NativeXComponent_RegisterCallback(nativeXComponent, &PluginRender::m_callback);
|
||||
OH_NativeXComponent_RegisterCallback(nativeXComponent, &PluginRender::callback_);
|
||||
if (render != nullptr) {
|
||||
render->Export(env, exports);
|
||||
}
|
||||
@ -89,27 +89,21 @@ void PluginManager::SetNativeXComponent(std::string &id, OH_NativeXComponent *na
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_nativeXComponentMap.find(id) == m_nativeXComponentMap.end()) {
|
||||
m_nativeXComponentMap[id] = nativeXComponent;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_nativeXComponentMap[id] != nativeXComponent) {
|
||||
OH_NativeXComponent *tmp = m_nativeXComponentMap[id];
|
||||
delete tmp;
|
||||
tmp = nullptr;
|
||||
m_nativeXComponentMap[id] = nativeXComponent;
|
||||
auto [iter, inserted] = nativeXComponentMap_.try_emplace(id, nativeXComponent);
|
||||
if (!inserted && iter->second != nativeXComponent) {
|
||||
delete iter->second;
|
||||
iter->second = nativeXComponent;
|
||||
}
|
||||
}
|
||||
|
||||
PluginRender *PluginManager::GetRender(std::string &id)
|
||||
{
|
||||
if (m_pluginRenderMap.find(id) == m_pluginRenderMap.end()) {
|
||||
if (pluginrendermap_.find(id) == pluginrendermap_.end()) {
|
||||
PluginRender *instance = PluginRender::GetInstance(id);
|
||||
m_pluginRenderMap[id] = instance;
|
||||
pluginrendermap_[id] = instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
return m_pluginRenderMap[id];
|
||||
return pluginrendermap_[id];
|
||||
}
|
||||
} // namespace OHOS
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
static PluginManager *GetInstance()
|
||||
{
|
||||
return &PluginManager::m_pluginManager;
|
||||
return &PluginManager::pluginmanager_;
|
||||
}
|
||||
|
||||
void SetNativeXComponent(std::string &id, OH_NativeXComponent *nativeXComponent);
|
||||
@ -38,10 +38,10 @@ public:
|
||||
void Export(napi_env env, napi_value exports);
|
||||
|
||||
private:
|
||||
static PluginManager m_pluginManager;
|
||||
static PluginManager pluginmanager_;
|
||||
|
||||
std::unordered_map<std::string, OH_NativeXComponent *> m_nativeXComponentMap;
|
||||
std::unordered_map<std::string, PluginRender *> m_pluginRenderMap;
|
||||
std::unordered_map<std::string, OH_NativeXComponent *> nativeXComponentMap_;
|
||||
std::unordered_map<std::string, PluginRender *> pluginrendermap_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // PLUGIN_MANAGER_H
|
||||
|
@ -32,23 +32,21 @@ bool EGLCore::EglContextInit(void *window, int width, int height)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
if (m_width > 0) {
|
||||
m_widthPercent = FIFTY_PERCENT * m_height / m_width;
|
||||
}
|
||||
m_eglWindow = static_cast<EGLNativeWindowType>(window);
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
widthpercent_ = FIFTY_PERCENT * height_ / width_;
|
||||
eglwindow_ = static_cast<EGLNativeWindowType>(window);
|
||||
|
||||
// Init display.
|
||||
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (m_eglDisplay == EGL_NO_DISPLAY) {
|
||||
egldisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (egldisplay_ == EGL_NO_DISPLAY) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglGetDisplay: unable to get EGL display");
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLint majorVersion;
|
||||
EGLint minorVersion;
|
||||
if (!eglInitialize(m_eglDisplay, &majorVersion, &minorVersion)) {
|
||||
if (!eglInitialize(egldisplay_, &majorVersion, &minorVersion)) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore",
|
||||
"eglInitialize: unable to get initialize EGL display");
|
||||
return false;
|
||||
@ -57,7 +55,7 @@ bool EGLCore::EglContextInit(void *window, int width, int height)
|
||||
// Select configuration.
|
||||
const EGLint maxConfigSize = 1;
|
||||
EGLint numConfigs;
|
||||
if (!eglChooseConfig(m_eglDisplay, ATTRIB_LIST, &m_eglConfig, maxConfigSize, &numConfigs)) {
|
||||
if (!eglChooseConfig(egldisplay_, ATTRIB_LIST, &eglconfig_, maxConfigSize, &numConfigs)) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglChooseConfig: unable to choose configs");
|
||||
return false;
|
||||
}
|
||||
@ -67,27 +65,27 @@ bool EGLCore::EglContextInit(void *window, int width, int height)
|
||||
|
||||
bool EGLCore::CreateEnvironment()
|
||||
{
|
||||
if (m_eglWindow == nullptr) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "m_eglWindow is null");
|
||||
if (eglwindow_ == nullptr) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglwindow_ is null");
|
||||
return false;
|
||||
}
|
||||
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglWindow, nullptr);
|
||||
if (m_eglSurface == nullptr) {
|
||||
eglsurface_ = eglCreateWindowSurface(egldisplay_, eglconfig_, eglwindow_, nullptr);
|
||||
if (eglsurface_ == nullptr) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore",
|
||||
"eglCreateWindowSurface: unable to create WindowSurface");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create context.
|
||||
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, CONTEXT_ATTRIBS);
|
||||
if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext)) {
|
||||
eglcontext_ = eglCreateContext(egldisplay_, eglconfig_, EGL_NO_CONTEXT, CONTEXT_ATTRIBS);
|
||||
if (!eglMakeCurrent(egldisplay_, eglsurface_, eglsurface_, eglcontext_)) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglMakeCurrent failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create program.
|
||||
m_program = CreateProgram(VERTEX_SHADER, FRAGMENT_SHADER);
|
||||
if (m_program == PROGRAM_ERROR) {
|
||||
program_ = CreateProgram(VERTEX_SHADER, FRAGMENT_SHADER);
|
||||
if (program_ == PROGRAM_ERROR) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "CreateProgram: unable to create program");
|
||||
return false;
|
||||
}
|
||||
@ -138,7 +136,7 @@ GLuint EGLCore::CreateProgram(const char *vertexShader, const char *fragShader)
|
||||
GLint infoLen = 0;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
|
||||
if (infoLen > 1) {
|
||||
char *infoLog = (char *)malloc(sizeof(char) * (infoLen + 1));
|
||||
char *infoLog = static_cast<char*>(malloc(sizeof(char) * (infoLen + 1)));
|
||||
std::fill(infoLog, infoLog + infoLen, 0);
|
||||
glGetProgramInfoLog(program, infoLen, nullptr, infoLog);
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glLinkProgram error = %s", infoLog);
|
||||
@ -181,7 +179,7 @@ GLuint EGLCore::LoadShader(GLenum type, const char *shaderSrc)
|
||||
return PROGRAM_ERROR;
|
||||
}
|
||||
|
||||
char *infoLog = (char *)malloc(sizeof(char) * (infoLen + 1));
|
||||
char *infoLog = static_cast<char*>(malloc(sizeof(char) * (infoLen + 1)));
|
||||
if (infoLog != nullptr) {
|
||||
std::fill(infoLog, infoLog + infoLen, 0);
|
||||
glGetShaderInfoLog(shader, infoLen, nullptr, infoLog);
|
||||
@ -195,7 +193,7 @@ GLuint EGLCore::LoadShader(GLenum type, const char *shaderSrc)
|
||||
|
||||
void EGLCore::Draw()
|
||||
{
|
||||
m_flag = false;
|
||||
flag_ = false;
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "Draw");
|
||||
GLint position = PrepareDraw();
|
||||
if (position == POSITION_ERROR) {
|
||||
@ -210,10 +208,10 @@ void EGLCore::Draw()
|
||||
}
|
||||
|
||||
const GLfloat rectangleVertices[] = {
|
||||
-m_widthPercent, FIFTY_PERCENT,
|
||||
m_widthPercent, FIFTY_PERCENT,
|
||||
m_widthPercent, -FIFTY_PERCENT,
|
||||
-m_widthPercent, -FIFTY_PERCENT
|
||||
-widthpercent_, FIFTY_PERCENT,
|
||||
widthpercent_, FIFTY_PERCENT,
|
||||
widthpercent_, -FIFTY_PERCENT,
|
||||
-widthpercent_, -FIFTY_PERCENT
|
||||
};
|
||||
if (!ExecuteDraw(position, DRAW_COLOR, rectangleVertices, sizeof(rectangleVertices))) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw execute draw rectangle failed");
|
||||
@ -225,24 +223,24 @@ void EGLCore::Draw()
|
||||
return;
|
||||
}
|
||||
|
||||
m_flag = true;
|
||||
flag_ = true;
|
||||
}
|
||||
|
||||
GLint EGLCore::PrepareDraw()
|
||||
{
|
||||
if ((m_eglDisplay == nullptr) || (m_eglSurface == nullptr) || (m_eglContext == nullptr) ||
|
||||
(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))) {
|
||||
if ((egldisplay_ == nullptr) || (eglsurface_ == nullptr) || (eglcontext_ == nullptr) ||
|
||||
(!eglMakeCurrent(egldisplay_, eglsurface_, eglsurface_, eglcontext_))) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "PrepareDraw: param error");
|
||||
return POSITION_ERROR;
|
||||
}
|
||||
|
||||
// The gl function has no return value.
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glViewport(0, 0, width_, height_);
|
||||
glClearColor(0, 255, 0, 1); //255 is color value, 1 is transparency
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(m_program);
|
||||
glUseProgram(program_);
|
||||
|
||||
return glGetAttribLocation(m_program, "a_position");
|
||||
return glGetAttribLocation(program_, "a_position");
|
||||
}
|
||||
|
||||
bool EGLCore::ExecuteDraw(GLint position, const GLfloat *color, const GLfloat rectangleVertices[],
|
||||
@ -268,20 +266,20 @@ bool EGLCore::FinishDraw()
|
||||
// The gl function has no return value.
|
||||
glFlush();
|
||||
glFinish();
|
||||
return eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
||||
return eglSwapBuffers(egldisplay_, eglsurface_);
|
||||
}
|
||||
|
||||
void EGLCore::Release()
|
||||
{
|
||||
if ((m_eglDisplay == nullptr) || (m_eglSurface == nullptr) || (!eglDestroySurface(m_eglDisplay, m_eglSurface))) {
|
||||
if ((egldisplay_ == nullptr) || (eglsurface_ == nullptr) || (!eglDestroySurface(egldisplay_, eglsurface_))) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglDestroySurface failed");
|
||||
}
|
||||
|
||||
if ((m_eglDisplay == nullptr) || (m_eglContext == nullptr) || (!eglDestroyContext(m_eglDisplay, m_eglContext))) {
|
||||
if ((egldisplay_ == nullptr) || (eglcontext_ == nullptr) || (!eglDestroyContext(egldisplay_, eglcontext_))) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglDestroyContext failed");
|
||||
}
|
||||
|
||||
if ((m_eglDisplay == nullptr) || (!eglTerminate(m_eglDisplay))) {
|
||||
if ((egldisplay_ == nullptr) || (!eglTerminate(egldisplay_))) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglTerminate failed");
|
||||
}
|
||||
}
|
||||
|
@ -33,20 +33,21 @@ private:
|
||||
GLuint LoadShader(GLenum type, const char *shaderSrc);
|
||||
GLuint CreateProgram(const char *vertexShader, const char *fragShader);
|
||||
GLint PrepareDraw();
|
||||
bool ExecuteDraw(GLint position, const GLfloat *color, const GLfloat rectangleVertices[], unsigned long vertSize);
|
||||
static bool ExecuteDraw(GLint position, const GLfloat *color, const GLfloat rectangleVertices[],
|
||||
unsigned long vertSize);
|
||||
bool FinishDraw();
|
||||
|
||||
private:
|
||||
EGLNativeWindowType m_eglWindow;
|
||||
EGLDisplay m_eglDisplay = EGL_NO_DISPLAY;
|
||||
EGLConfig m_eglConfig = EGL_NO_CONFIG_KHR;
|
||||
EGLSurface m_eglSurface = EGL_NO_SURFACE;
|
||||
EGLContext m_eglContext = EGL_NO_CONTEXT;
|
||||
GLuint m_program;
|
||||
bool m_flag = false;
|
||||
int m_width;
|
||||
int m_height;
|
||||
GLfloat m_widthPercent;
|
||||
EGLNativeWindowType eglwindow_;
|
||||
EGLDisplay egldisplay_ = EGL_NO_DISPLAY;
|
||||
EGLConfig eglconfig_ = EGL_NO_CONFIG_KHR;
|
||||
EGLSurface eglsurface_ = EGL_NO_SURFACE;
|
||||
EGLContext eglcontext_ = EGL_NO_CONTEXT;
|
||||
GLuint program_ = 0;
|
||||
bool flag_ = false;
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
GLfloat widthpercent_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // EGL_CORE_H
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
std::unordered_map<std::string, PluginRender *> PluginRender::m_instance;
|
||||
OH_NativeXComponent_Callback PluginRender::m_callback;
|
||||
std::unordered_map<std::string, PluginRender *> PluginRender::instance_;
|
||||
OH_NativeXComponent_Callback PluginRender::callback_;
|
||||
|
||||
void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
|
||||
{
|
||||
@ -49,7 +49,7 @@ void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
|
||||
uint64_t height;
|
||||
int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height);
|
||||
if ((xSize == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) && (render != nullptr)) {
|
||||
render->m_eglCore->EglContextInit(window, width, height);
|
||||
render->eglcore_->EglContextInit(window, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,23 +74,23 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
|
||||
PluginRender::Release(id);
|
||||
}
|
||||
|
||||
PluginRender::PluginRender(std::string &id)
|
||||
PluginRender::PluginRender(const std::string &id)
|
||||
{
|
||||
this->m_id = id;
|
||||
this->m_eglCore = new EGLCore();
|
||||
OH_NativeXComponent_Callback *renderCallback = &PluginRender::m_callback;
|
||||
this->id_ = id;
|
||||
this->eglcore_ = new EGLCore();
|
||||
OH_NativeXComponent_Callback *renderCallback = &PluginRender::callback_;
|
||||
renderCallback->OnSurfaceCreated = OnSurfaceCreatedCB;
|
||||
renderCallback->OnSurfaceDestroyed = OnSurfaceDestroyedCB;
|
||||
}
|
||||
|
||||
PluginRender *PluginRender::GetInstance(std::string &id)
|
||||
{
|
||||
if (m_instance.find(id) == m_instance.end()) {
|
||||
if (instance_.find(id) == instance_.end()) {
|
||||
PluginRender *instance = new PluginRender(id);
|
||||
m_instance[id] = instance;
|
||||
instance_[id] = instance;
|
||||
return instance;
|
||||
} else {
|
||||
return m_instance[id];
|
||||
return instance_[id];
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,8 +133,8 @@ napi_value PluginRender::NapiDrawRectangle(napi_env env, napi_callback_info info
|
||||
std::string id(idStr);
|
||||
PluginRender *render = PluginRender::GetInstance(id);
|
||||
if (render) {
|
||||
render->m_eglCore->Draw();
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "PluginRender", "render->m_eglCore->Draw() executed");
|
||||
render->eglcore_->Draw();
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "PluginRender", "render->eglcore_->Draw() executed");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -158,12 +158,12 @@ void PluginRender::Release(std::string &id)
|
||||
{
|
||||
PluginRender *render = PluginRender::GetInstance(id);
|
||||
if (render != nullptr) {
|
||||
render->m_eglCore->Release();
|
||||
delete render->m_eglCore;
|
||||
render->m_eglCore = nullptr;
|
||||
render->eglcore_->Release();
|
||||
delete render->eglcore_;
|
||||
render->eglcore_ = nullptr;
|
||||
delete render;
|
||||
render = nullptr;
|
||||
m_instance.erase(m_instance.find(id));
|
||||
instance_.erase(instance_.find(id));
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
@ -26,26 +26,26 @@
|
||||
namespace OHOS {
|
||||
class PluginRender {
|
||||
public:
|
||||
explicit PluginRender(std::string &id);
|
||||
explicit PluginRender(const std::string &id);
|
||||
~PluginRender()
|
||||
{
|
||||
if (m_eglCore != nullptr) {
|
||||
m_eglCore->Release();
|
||||
delete m_eglCore;
|
||||
m_eglCore = nullptr;
|
||||
if (eglcore_ != nullptr) {
|
||||
eglcore_->Release();
|
||||
delete eglcore_;
|
||||
eglcore_ = nullptr;
|
||||
}
|
||||
}
|
||||
static PluginRender *GetInstance(std::string &id);
|
||||
static void Release(std::string &id);
|
||||
static napi_value NapiDrawRectangle(napi_env env, napi_callback_info info);
|
||||
void Export(napi_env env, napi_value exports);
|
||||
static void Export(napi_env env, napi_value exports);
|
||||
|
||||
public:
|
||||
static std::unordered_map<std::string, PluginRender *> m_instance;
|
||||
static OH_NativeXComponent_Callback m_callback;
|
||||
static std::unordered_map<std::string, PluginRender *> instance_;
|
||||
static OH_NativeXComponent_Callback callback_;
|
||||
|
||||
EGLCore *m_eglCore;
|
||||
std::string m_id;
|
||||
EGLCore *eglcore_ = nullptr;
|
||||
std::string id_ = "";
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // PLUGIN_RENDER_H
|
@ -2,6 +2,7 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(drawing_test)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
|
@ -46,16 +46,10 @@ void PluginManager::SetNativeXComponent(std::string &id, OH_NativeXComponent *na
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeXComponentMap_.find(id) == nativeXComponentMap_.end()) {
|
||||
nativeXComponentMap_[id] = nativeXComponent;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeXComponentMap_[id] != nativeXComponent) {
|
||||
OH_NativeXComponent *tmp = nativeXComponentMap_[id];
|
||||
delete tmp;
|
||||
tmp = nullptr;
|
||||
nativeXComponentMap_[id] = nativeXComponent;
|
||||
auto [iter, inserted] = nativeXComponentMap_.try_emplace(id, nativeXComponent);
|
||||
if (!inserted && iter->second != nativeXComponent) {
|
||||
delete iter->second;
|
||||
iter->second = nativeXComponent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,6 +301,9 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component,
|
||||
}
|
||||
std::string id(idStr);
|
||||
auto render = SampleBitMap::GetInstance(id);
|
||||
if (render == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHNativeWindow *nativeWindow = static_cast<OHNativeWindow *>(window);
|
||||
render->SetNativeWindow(nativeWindow);
|
||||
|
||||
|
@ -52,11 +52,11 @@ public:
|
||||
void DisPlay();
|
||||
void ConstructPath();
|
||||
void SetPenAndBrush();
|
||||
void Export(napi_env env, napi_value exports);
|
||||
static void Export(napi_env env, napi_value exports);
|
||||
void RegisterCallback(OH_NativeXComponent *nativeXComponent);
|
||||
void Destroy();
|
||||
static SampleBitMap *GetInstance(std::string &id);
|
||||
std::string id_;
|
||||
std::string id_ = "";
|
||||
private:
|
||||
OH_NativeXComponent_Callback renderCallback_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user