update code,because of code check
Signed-off-by: tyBrave <tianyong13@huawei.com>
This commit is contained in:
parent
83014e5457
commit
d18694a96e
|
@ -24,34 +24,34 @@
|
|||
|
||||
#define NAPI_RETVAL_NOTHING
|
||||
|
||||
#define GET_AND_THROW_LAST_ERROR(env) \
|
||||
do { \
|
||||
const napi_extended_error_info* errorInfo = nullptr; \
|
||||
napi_get_last_error_info((env),&errorInfo); \
|
||||
bool isPending = false; \
|
||||
napi_is_exception_pending((env),&isPending); \
|
||||
if (!isPending && errorInfo != nullptr) { \
|
||||
const char* errorMessage = \
|
||||
errorInfo->error_message != nullptr ? errorInfo->error_message : "empty error message"; \
|
||||
napi_throw_error((env),nullptr,errorMessage); \
|
||||
} \
|
||||
} while (0)
|
||||
#define GET_AND_THROW_LAST_ERROR(env) \
|
||||
do { \
|
||||
const napi_extended_error_info* errorInfo = nullptr; \
|
||||
napi_get_last_error_info((env), &errorInfo); \
|
||||
bool isPending = false; \
|
||||
napi_is_exception_pending((env), &isPending); \
|
||||
if (!isPending && errorInfo != nullptr) { \
|
||||
const char* errorMessage = \
|
||||
errorInfo->error_message != nullptr ? errorInfo->error_message : "empty error message"; \
|
||||
napi_throw_error((env), nullptr, errorMessage); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DECLARE_NAPI_FUNCTION(name, func) \
|
||||
{ \
|
||||
(name),nullptr,(func),nullptr,nullptr,nullptr,napi_default,nullptr \
|
||||
}
|
||||
#define DECLARE_NAPI_FUNCTION(name, func) \
|
||||
{ \
|
||||
(name), nullptr, (func), nullptr, nullptr, nullptr, napi_default, nullptr \
|
||||
}
|
||||
|
||||
|
||||
#define NAPI_CALL_BASE(env, theCall, retVal) \
|
||||
do { \
|
||||
if((theCall) != napi_ok) { \
|
||||
GET_AND_THROW_LAST_ERROR((env)); \
|
||||
return retVal; \
|
||||
} \
|
||||
} while (0)
|
||||
#define NAPI_CALL_BASE(env, theCall, retVal) \
|
||||
do { \
|
||||
if ((theCall) != napi_ok) { \
|
||||
GET_AND_THROW_LAST_ERROR((env)); \
|
||||
return retVal; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define NAPI_CALL(env, theCall) NAPI_CALL_BASE(env, theCall, nullptr)
|
||||
|
||||
#endif //GPU_ImageETS_native_common_H
|
||||
#endif // GPU_ImageETS_native_common_H
|
||||
|
|
|
@ -57,7 +57,7 @@ const int SHADER_TYPE_GRAYSCALE = 10;
|
|||
const int SHADER_TYPE_BLUR = 12;
|
||||
|
||||
|
||||
const char vShaderStr[] =
|
||||
const char vShaderStr[] =
|
||||
"#version 300 es \n"
|
||||
"layout(location = 0) in vec4 a_position; \n"
|
||||
"layout(location = 1) in vec2 a_texCoord; \n"
|
||||
|
@ -79,7 +79,7 @@ const char fShaderStr0[] =
|
|||
"outColor = texture(s_TextureMap,v_texCoord); \n"
|
||||
"} \n";
|
||||
|
||||
const char v3x3ShaderStr[] =
|
||||
const char v3x3ShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"layout(location = 0) in vec4 a_position;\n"
|
||||
|
@ -116,7 +116,7 @@ const char v3x3ShaderStr[] =
|
|||
"}";
|
||||
|
||||
// kuwahara
|
||||
const char fShaderStr3[] =
|
||||
const char fShaderStr3[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"layout(location = 0) out vec4 outColor;\n"
|
||||
|
@ -201,7 +201,7 @@ const char fShaderStr3[] =
|
|||
"}\n";
|
||||
|
||||
// 旋转
|
||||
const char swirlFShaderStr[] =
|
||||
const char swirlFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"layout(location = 0) out vec4 outColor;\n"
|
||||
|
@ -227,7 +227,7 @@ const char swirlFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// 亮度
|
||||
const char brightFShaderStr[] =
|
||||
const char brightFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -244,7 +244,7 @@ const char brightFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// 反转
|
||||
const char contrastFShaderStr[] =
|
||||
const char contrastFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -261,7 +261,7 @@ const char contrastFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// invert
|
||||
const char invertFShaderStr[] =
|
||||
const char invertFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -277,7 +277,7 @@ const char invertFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// pixel
|
||||
const char pixelFShaderStr[] =
|
||||
const char pixelFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -298,7 +298,7 @@ const char pixelFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// vignette
|
||||
const char vignetteFShaderStr[] =
|
||||
const char vignetteFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"uniform lowp sampler2D s_TextureMap;\n"
|
||||
|
@ -324,7 +324,7 @@ const char vignetteFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// ColorMatrix
|
||||
const char colorMatrixFShaderStr[] =
|
||||
const char colorMatrixFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -341,7 +341,7 @@ const char colorMatrixFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// toon
|
||||
const char toonFShaderStr[] =
|
||||
const char toonFShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -382,7 +382,7 @@ const char toonFShaderStr[] =
|
|||
"}";
|
||||
|
||||
// grayScale
|
||||
const char grayScaleShaderStr[] =
|
||||
const char grayScaleShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"in vec2 v_texCoord;\n"
|
||||
|
@ -397,7 +397,7 @@ const char grayScaleShaderStr[] =
|
|||
"}";
|
||||
|
||||
// sketch
|
||||
const char sketchShaderStr[] =
|
||||
const char sketchShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"layout(location = 0) out vec4 outColor;\n"
|
||||
|
@ -432,7 +432,7 @@ const char sketchShaderStr[] =
|
|||
"}";
|
||||
|
||||
// blur
|
||||
const char blurShaderStr[] =
|
||||
const char blurShaderStr[] =
|
||||
"#version 300 es\n"
|
||||
"precision highp float;\n"
|
||||
"uniform lowp sampler2D s_TextureMap;\n"
|
||||
|
|
|
@ -54,28 +54,29 @@ static napi_value Add(napi_env env, napi_callback_info info)
|
|||
|
||||
}
|
||||
|
||||
static napi_value Init(napi_env env, napi_value exports) {
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("EglRenderInit",EGLRender:: RenderInit),
|
||||
DECLARE_NAPI_FUNCTION("EglRenderSetImageData",EGLRender:: RenderSetData),
|
||||
DECLARE_NAPI_FUNCTION("EglPixelMapSurface",EGLRender:: GetPixelMapOfSurface),
|
||||
DECLARE_NAPI_FUNCTION("EglRenderSetIntParams",EGLRender:: RenderSetIntParams),
|
||||
DECLARE_NAPI_FUNCTION("EglIsInit",EGLRender:: EGLIsInit),
|
||||
DECLARE_NAPI_FUNCTION("EglDestroy",EGLRender:: DestroyGlesEnv),
|
||||
DECLARE_NAPI_FUNCTION("EglRenderInit", EGLRender:: RenderInit),
|
||||
DECLARE_NAPI_FUNCTION("EglRenderSetImageData", EGLRender:: RenderSetData),
|
||||
DECLARE_NAPI_FUNCTION("EglPixelMapSurface", EGLRender:: GetPixelMapOfSurface),
|
||||
DECLARE_NAPI_FUNCTION("EglRenderSetIntParams", EGLRender:: RenderSetIntParams),
|
||||
DECLARE_NAPI_FUNCTION("EglIsInit", EGLRender:: EGLIsInit),
|
||||
DECLARE_NAPI_FUNCTION("EglDestroy", EGLRender:: DestroyGlesEnv),
|
||||
|
||||
DECLARE_NAPI_FUNCTION("EglUseProgram",EGLRender:: StartUseProgram),
|
||||
DECLARE_NAPI_FUNCTION("EglRendering",EGLRender:: Rendering),
|
||||
DECLARE_NAPI_FUNCTION("EglUseProgram", EGLRender:: StartUseProgram),
|
||||
DECLARE_NAPI_FUNCTION("EglRendering", EGLRender:: Rendering),
|
||||
|
||||
DECLARE_NAPI_FUNCTION("EglUniform1i",EGLRender:: RenderGlUniform1i),
|
||||
DECLARE_NAPI_FUNCTION("EglUniform1f",EGLRender:: RenderGlUniform1f),
|
||||
DECLARE_NAPI_FUNCTION("EglUniform2fv",EGLRender:: RenderGlUniform2fv),
|
||||
DECLARE_NAPI_FUNCTION("EglUniform1i", EGLRender:: RenderGlUniform1i),
|
||||
DECLARE_NAPI_FUNCTION("EglUniform1f", EGLRender:: RenderGlUniform1f),
|
||||
DECLARE_NAPI_FUNCTION("EglUniform2fv", EGLRender:: RenderGlUniform2fv),
|
||||
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfFloat",EGLRender:: setTypeArrayOfFloat),
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfFloat", EGLRender:: setTypeArrayOfFloat),
|
||||
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfMatrix3f",EGLRender:: setTypeArrayOfMatrix3f),
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfMatrix4f",EGLRender:: setTypeArrayOfMatrix4f),
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfMatrix3f", EGLRender:: setTypeArrayOfMatrix3f),
|
||||
DECLARE_NAPI_FUNCTION("EglSetTypeArrayOfMatrix4f", EGLRender:: setTypeArrayOfMatrix4f),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]),desc));
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ const int32_t STR_DEFAULT_SIZE = 1024;
|
|||
EGLRender *EGLRender::sInstance = nullptr;
|
||||
|
||||
// 顶点坐标
|
||||
const GLfloat vVertices[] = {
|
||||
const static GLfloat vVertices[] = {
|
||||
-1.0f, -1.0f, 0.0f, // bottom left
|
||||
1.0f, -1.0f, 0.0f, // bottom right
|
||||
-1.0f, 1.0f, 0.0f, // top left
|
||||
|
@ -53,7 +53,7 @@ const GLfloat vVertices[] = {
|
|||
};
|
||||
|
||||
// 正常纹理坐标
|
||||
const GLfloat vTexCoors[] = {
|
||||
const static GLfloat vTexCoors[] = {
|
||||
0.0f, 1.0f, // bottom left
|
||||
1.0f, 1.0f, // bottom right
|
||||
0.0f, 0.0f, // top left
|
||||
|
@ -61,28 +61,24 @@ const GLfloat vTexCoors[] = {
|
|||
};
|
||||
|
||||
// fbo 纹理坐标与正常纹理方向不同(上下镜像)
|
||||
const GLfloat vFboTexCoors[] = {
|
||||
const static GLfloat vFboTexCoors[] = {
|
||||
0.0f, 0.0f, // bottom left
|
||||
1.0f, 0.0f, // bottom right
|
||||
0.0f, 1.0f, // top left
|
||||
1.0f, 1.0f, // top right
|
||||
};
|
||||
|
||||
const GLushort indices[] = { 0, 1, 2, 1, 3, 2 };
|
||||
const static GLushort indices[] = { 0, 1, 2, 1, 3, 2 };
|
||||
|
||||
|
||||
napi_value EGLRender::RenderInit(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value exports;
|
||||
|
||||
NAPI_CALL(env, napi_create_object(env, &exports));
|
||||
napi_property_descriptor desc[] = {
|
||||
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]),desc));
|
||||
|
||||
napi_property_descriptor desc[] = {};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
EGLRender::GetInstance() ->Init();
|
||||
return exports;
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,26 +87,22 @@ napi_value EGLRender::RenderSetData(napi_env env, napi_callback_info info)
|
|||
size_t argc = 3;
|
||||
napi_value args[3] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
void* buffer;
|
||||
size_t bufferLength;
|
||||
napi_status buffStatus = napi_get_arraybuffer_info(env, args[0], &buffer, &bufferLength);
|
||||
if (buffStatus != napi_ok)
|
||||
{
|
||||
if (buffStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t* uint8_buf = reinterpret_cast<uint8_t *>(buffer);
|
||||
uint32_t width;
|
||||
napi_status wStatus = napi_get_value_uint32(env, args[1], &width);
|
||||
if (wStatus != napi_ok)
|
||||
{
|
||||
if (wStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t height;
|
||||
napi_status hStatus = napi_get_value_uint32(env, args[2], &height);
|
||||
if (hStatus != napi_ok)
|
||||
{
|
||||
if (hStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -123,20 +115,18 @@ napi_value EGLRender::RenderSetIntParams(napi_env env, napi_callback_info info)
|
|||
LOGI("gl--> RenderSetIntParams start");
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
uint32_t type;
|
||||
napi_status tStatus = napi_get_value_uint32(env, args[0], &type);
|
||||
if (tStatus != napi_ok)
|
||||
{
|
||||
if (tStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t param;
|
||||
napi_status pStatus = napi_get_value_uint32(env, args[1], ¶m);
|
||||
if (pStatus != napi_ok)
|
||||
{
|
||||
if (pStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
EGLRender::GetInstance() -> SetIntParams(type, param);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -145,35 +135,31 @@ napi_value EGLRender::GetPixelMapOfSurface(napi_env env, napi_callback_info info
|
|||
{
|
||||
size_t argc = 4;
|
||||
napi_value args[4] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
uint32_t x;
|
||||
napi_status xStatus = napi_get_value_uint32(env, args[0], &x);
|
||||
if (xStatus != napi_ok)
|
||||
{
|
||||
if (xStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t y;
|
||||
napi_status yStatus = napi_get_value_uint32(env, args[1], &y);
|
||||
if (yStatus != napi_ok)
|
||||
{
|
||||
if (yStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t surfaceWidth;
|
||||
napi_status swStatus = napi_get_value_uint32(env, args[2], &surfaceWidth);
|
||||
if (swStatus != napi_ok)
|
||||
{
|
||||
if (swStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t surfaceHeight;
|
||||
napi_status shStatus = napi_get_value_uint32(env, args[3], &surfaceHeight);
|
||||
if (shStatus != napi_ok)
|
||||
{
|
||||
if (shStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* pixels = (uint8_t*) malloc(surfaceWidth * surfaceHeight * DEFAULT_FOUR);
|
||||
|
||||
|
@ -183,8 +169,7 @@ napi_value EGLRender::GetPixelMapOfSurface(napi_env env, napi_callback_info info
|
|||
NativeImageUtil::flip(&pixels, surfaceWidth, surfaceHeight);
|
||||
napi_value array;
|
||||
int byte_length = surfaceWidth * surfaceHeight * DEFAULT_FOUR;
|
||||
if (!NativeImageUtil::CreateArrayBuffer(env, pixels, byte_length, &array))
|
||||
{
|
||||
if (!NativeImageUtil::CreateArrayBuffer(env, pixels, byte_length, &array)) {
|
||||
LOGI("gl--> GetPixelMapOfSurface error");
|
||||
}
|
||||
free(pixels);
|
||||
|
@ -195,15 +180,13 @@ napi_value EGLRender::EGLIsInit(napi_env env, napi_callback_info info)
|
|||
{
|
||||
napi_value isInit;
|
||||
int32_t value;
|
||||
if (EGLRender::GetInstance() -> m_IsGLContextReady)
|
||||
{
|
||||
if (EGLRender::GetInstance() -> m_IsGLContextReady) {
|
||||
value = 1;
|
||||
}else {
|
||||
value = 0;
|
||||
}
|
||||
napi_status status = napi_create_int32(env, value, &isInit);
|
||||
if (status != napi_ok)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInit;
|
||||
|
@ -232,10 +215,9 @@ napi_value EGLRender::Rendering(napi_env env, napi_callback_info info)
|
|||
|
||||
napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
||||
{
|
||||
|
||||
size_t argc = 3;
|
||||
napi_value args[3] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string locationContent;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, locationContent);
|
||||
|
@ -251,9 +233,9 @@ napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
|||
void* buffer;
|
||||
size_t bufferLength;
|
||||
size_t byte_offset;
|
||||
napi_status buffStatus = napi_get_typedarray_info(env, args[2], &dataType, &bufferLength, &buffer, &args[2], &byte_offset);
|
||||
if (buffStatus != napi_ok)
|
||||
{
|
||||
napi_status buffStatus = napi_get_typedarray_info(env,
|
||||
args[2], &dataType, &bufferLength, &buffer, &args[2], &byte_offset);
|
||||
if (buffStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -261,20 +243,15 @@ napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
|||
|
||||
int uniformType;
|
||||
|
||||
if (strcmp(key, "glUniform2fv") == 0)
|
||||
{
|
||||
if (strcmp(key, "glUniform2fv") == 0) {
|
||||
uniformType = UNIFORM_TYPE_2FV;
|
||||
}else if (strcmp(key, "glUniform3fv") == 0)
|
||||
{
|
||||
}else if (strcmp(key, "glUniform3fv") == 0) {
|
||||
uniformType = UNIFORM_TYPE_3FV;
|
||||
}else if (strcmp(key, "glUniform4fv") == 0)
|
||||
{
|
||||
}else if (strcmp(key, "glUniform4fv") == 0) {
|
||||
uniformType = UNIFORM_TYPE_4FV;
|
||||
}else if (strcmp(key, "glUniform1fv") == 0)
|
||||
{
|
||||
}else if (strcmp(key, "glUniform1fv") == 0) {
|
||||
uniformType = UNIFORM_TYPE_FV;
|
||||
}else if (strcmp(key, "glUniform2f") == 0)
|
||||
{
|
||||
}else if (strcmp(key, "glUniform2f") == 0) {
|
||||
uniformType = UNIFORM_TYPE_2F;
|
||||
}
|
||||
|
||||
|
@ -286,7 +263,7 @@ napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info in
|
|||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string locationContent;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, locationContent);
|
||||
|
@ -297,9 +274,9 @@ napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info in
|
|||
void* buffer;
|
||||
size_t bufferLength;
|
||||
size_t byte_offset;
|
||||
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||
if (buffStatus != napi_ok)
|
||||
{
|
||||
napi_status buffStatus = napi_get_typedarray_info(env,
|
||||
args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||
if (buffStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -314,7 +291,7 @@ napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info in
|
|||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string locationContent;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, locationContent);
|
||||
|
@ -325,9 +302,9 @@ napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info in
|
|||
void* buffer;
|
||||
size_t bufferLength;
|
||||
size_t byte_offset;
|
||||
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||
if (buffStatus != napi_ok)
|
||||
{
|
||||
napi_status buffStatus = napi_get_typedarray_info(env,
|
||||
args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||
if (buffStatus != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -342,14 +319,13 @@ napi_value EGLRender::RenderGlUniform1i(napi_env env, napi_callback_info info)
|
|||
// int
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string content;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
||||
uint32_t value;
|
||||
napi_status status = napi_get_value_uint32(env, args[1], &value);
|
||||
if (status != napi_ok)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ZERO);
|
||||
|
@ -361,14 +337,13 @@ napi_value EGLRender::RenderGlUniform1f(napi_env env, napi_callback_info info)
|
|||
// float
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string content;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
||||
double value;
|
||||
napi_status status = napi_get_value_double(env, args[1], &value);
|
||||
if (status != napi_ok)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ONE);
|
||||
|
@ -380,21 +355,19 @@ napi_value EGLRender::RenderGlUniform2fv(napi_env env, napi_callback_info info)
|
|||
// float 数组
|
||||
size_t argc = 3;
|
||||
napi_value args[3] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
std::string content;
|
||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
||||
|
||||
double value;
|
||||
napi_status status = napi_get_value_double(env, args[1], &value);
|
||||
if (status != napi_ok)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
double value2;
|
||||
napi_status status2 = napi_get_value_double(env, args[2], &value2);
|
||||
if (status2 != napi_ok)
|
||||
{
|
||||
if (status2 != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -419,19 +392,16 @@ EGLRender::EGLRender()
|
|||
m_eglDisplay = nullptr;
|
||||
m_IsGLContextReady = false;
|
||||
m_ShaderIndex = 0;
|
||||
|
||||
}
|
||||
EGLRender::~EGLRender()
|
||||
{
|
||||
}
|
||||
void EGLRender::Init()
|
||||
{
|
||||
if (CreateGlEnv() == 0)
|
||||
{
|
||||
if (CreateGlEnv() == 0) {
|
||||
m_IsGLContextReady = true;
|
||||
}
|
||||
if (!m_IsGLContextReady)
|
||||
{
|
||||
if (!m_IsGLContextReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -448,14 +418,12 @@ void EGLRender::Init()
|
|||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||
|
||||
|
||||
m_ProgramObj = GLUtils::CreateProgram(vShaderStr, fShaderStr0, m_VertexShader,
|
||||
m_FragmentShader);
|
||||
if (!m_ProgramObj)
|
||||
{
|
||||
m_FragmentShader);
|
||||
if (!m_ProgramObj) {
|
||||
GLUtils::CheckGLError("Create Program");
|
||||
return;
|
||||
}
|
||||
|
@ -469,7 +437,7 @@ void EGLRender::Init()
|
|||
glBufferData(GL_ARRAY_BUFFER, sizeof(vFboTexCoors), vTexCoors, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||
|
||||
// Generate VAO Ids
|
||||
glGenVertexArrays(DEFAULT_ONE, m_VaoIds);
|
||||
|
@ -479,13 +447,22 @@ void EGLRender::Init()
|
|||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]);
|
||||
glEnableVertexAttribArray(VERTEX_POS_LOC);
|
||||
glVertexAttribPointer(VERTEX_POS_LOC, DEFAULT_THREE, GL_FLOAT, GL_FALSE, DEFAULT_THREE * sizeof(GLfloat), (const void *)DEFAULT_ZERO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER,GL_NONE);
|
||||
glVertexAttribPointer(VERTEX_POS_LOC,
|
||||
DEFAULT_THREE,
|
||||
GL_FLOAT, GL_FALSE,
|
||||
DEFAULT_THREE * sizeof(GLfloat),
|
||||
(const void *)DEFAULT_ZERO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ONE]);
|
||||
glEnableVertexAttribArray(TEXTURE_POS_LOC);
|
||||
glVertexAttribPointer(TEXTURE_POS_LOC, DEFAULT_TWO, GL_FLOAT, GL_FALSE, DEFAULT_TWO * sizeof(GLfloat), (const void *)DEFAULT_ZERO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER,GL_NONE);
|
||||
glVertexAttribPointer(TEXTURE_POS_LOC,
|
||||
DEFAULT_TWO,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
DEFAULT_TWO * sizeof(GLfloat),
|
||||
(const void *)DEFAULT_ZERO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]);
|
||||
glBindVertexArray(GL_NONE);
|
||||
|
@ -493,7 +470,7 @@ void EGLRender::Init()
|
|||
|
||||
int EGLRender::CreateGlEnv()
|
||||
{
|
||||
const EGLint confAttr[] =
|
||||
const EGLint confAttr[] =
|
||||
{
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
||||
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||
|
@ -506,14 +483,14 @@ int EGLRender::CreateGlEnv()
|
|||
EGL_NONE
|
||||
};
|
||||
// EGL context attributes
|
||||
const EGLint ctxAttr[] = {
|
||||
const EGLint ctxAttr[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
// surface attributes
|
||||
// the surface size is set to the input frame size
|
||||
const EGLint surfaceAttr[] = {
|
||||
const EGLint surfaceAttr[] =
|
||||
{
|
||||
EGL_WIDTH, 1,
|
||||
EGL_HEIGHT, 1,
|
||||
EGL_NONE
|
||||
|
@ -521,35 +498,29 @@ int EGLRender::CreateGlEnv()
|
|||
EGLint eglMajVers, eglMinVers;
|
||||
EGLint numConfigs;
|
||||
int resultCode = 0;
|
||||
do
|
||||
{
|
||||
do {
|
||||
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (m_eglDisplay == EGL_NO_DISPLAY)
|
||||
{
|
||||
if (m_eglDisplay == EGL_NO_DISPLAY) {
|
||||
resultCode = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
// 初始化 egl 方法
|
||||
if (!eglInitialize(m_eglDisplay, &eglMajVers, &eglMinVers))
|
||||
{
|
||||
if (!eglInitialize(m_eglDisplay, &eglMajVers, &eglMinVers)) {
|
||||
resultCode = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
// 获取 EGLConfig 对象,确定渲染表面的配置信息
|
||||
if (!eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, 1, &numConfigs))
|
||||
{
|
||||
if (!eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, 1, &numConfigs)) {
|
||||
resultCode = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
// 创建渲染表面 EGLSurface 使用 eglCreateBufferSurface 创建屏幕外渲染区域
|
||||
m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
|
||||
if (m_eglSurface == EGL_NO_SURFACE)
|
||||
{
|
||||
switch(eglGetError())
|
||||
{
|
||||
if (m_eglSurface == EGL_NO_SURFACE) {
|
||||
switch(eglGetError()) {
|
||||
case EGL_BAD_ALLOC:
|
||||
LOGI("gl-->::CreateGlesEnv Not enough resources available");
|
||||
break;
|
||||
|
@ -570,28 +541,24 @@ int EGLRender::CreateGlEnv()
|
|||
|
||||
// 创建渲染上下文 EGLContext
|
||||
m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
|
||||
if (m_eglCtx == EGL_NO_CONTEXT)
|
||||
{
|
||||
if (m_eglCtx == EGL_NO_CONTEXT) {
|
||||
EGLint error = eglGetError();
|
||||
if (error == EGL_BAD_CONFIG)
|
||||
{
|
||||
if (error == EGL_BAD_CONFIG) {
|
||||
LOGI("gl-->::CreateGlesEnv EGL_BAD_CONFIG");
|
||||
resultCode = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定上下文
|
||||
if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx))
|
||||
{
|
||||
if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx)) {
|
||||
resultCode = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOGI("gl-->::CreateGlesEnv initialize success");
|
||||
} while (false);
|
||||
|
||||
if (resultCode != 0)
|
||||
{
|
||||
if (resultCode != 0) {
|
||||
LOGI("gl-->::CreateGlesEnv fail");
|
||||
}
|
||||
|
||||
|
@ -600,10 +567,8 @@ int EGLRender::CreateGlEnv()
|
|||
|
||||
void EGLRender::SetImageData(uint8_t *pData, int width, int height)
|
||||
{
|
||||
if (pData && m_IsGLContextReady)
|
||||
{
|
||||
if (m_RenderImage.ppPlane[0])
|
||||
{
|
||||
if (pData && m_IsGLContextReady) {
|
||||
if (m_RenderImage.ppPlane[0]) {
|
||||
NativeImageUtil::FreeNativeImage(&m_RenderImage);
|
||||
m_RenderImage.ppPlane[0] = nullptr;
|
||||
}
|
||||
|
@ -614,106 +579,103 @@ void EGLRender::SetImageData(uint8_t *pData, int width, int height)
|
|||
memcpy(m_RenderImage.ppPlane[0], pData, width * height * DEFAULT_FOUR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_RenderImage.width, m_RenderImage.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_RenderImage.ppPlane[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
m_RenderImage.width,
|
||||
m_RenderImage.height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
m_RenderImage.ppPlane[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||
|
||||
if (m_FboId == GL_NONE)
|
||||
{
|
||||
if (m_FboId == GL_NONE) {
|
||||
// Create FBO
|
||||
glGenFramebuffers(1, &m_FboId);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FboId);
|
||||
glBindTexture(GL_TEXTURE_2D, m_FboTextureId);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_FboTextureId, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_RenderImage.width, m_RenderImage.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
m_RenderImage.width,
|
||||
m_RenderImage.height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
nullptr);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOGI("gl--> EGLRender ::SetImageData glCheckFramebufferStatus status != GL_FRAMEBUFFER_COMPLETE");
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE);
|
||||
}
|
||||
}
|
||||
LOGI("gl--> :: SetImageData end");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EGLRender::SetIntParams(int paramType, int param)
|
||||
{
|
||||
LOGI("gl--> EGLRender::SetIntParams paramType = %{public}d,param = %{public}d", paramType, param);
|
||||
switch(paramType)
|
||||
{
|
||||
case PARAM_TYPE_SHADER_INDEX:
|
||||
{
|
||||
if (param >= 0)
|
||||
{
|
||||
if (m_ProgramObj)
|
||||
{
|
||||
switch (paramType) {
|
||||
case PARAM_TYPE_SHADER_INDEX: {
|
||||
if (param >= 0) {
|
||||
if (m_ProgramObj) {
|
||||
glDeleteProgram(m_ProgramObj);
|
||||
m_ProgramObj = GL_NONE;
|
||||
}
|
||||
}
|
||||
const char* vShader[1];
|
||||
vShader[0] = vShaderStr;
|
||||
const char* fShader[1];
|
||||
switch(param)
|
||||
{
|
||||
case SHADER_TYPE_KUWAHARA:
|
||||
{
|
||||
switch (param) {
|
||||
case SHADER_TYPE_KUWAHARA: {
|
||||
fShader[0] = fShaderStr3;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_SWIRL:
|
||||
{
|
||||
case SHADER_TYPE_SWIRL: {
|
||||
fShader[0] = swirlFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_BRIGHT:
|
||||
{
|
||||
case SHADER_TYPE_BRIGHT: {
|
||||
fShader[0] = brightFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_CONTRAST:
|
||||
{
|
||||
case SHADER_TYPE_CONTRAST: {
|
||||
fShader[0] = contrastFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_INVERT:
|
||||
{
|
||||
case SHADER_TYPE_INVERT: {
|
||||
fShader[0] = invertFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_PIXELATION:
|
||||
{
|
||||
case SHADER_TYPE_PIXELATION: {
|
||||
fShader[0] = pixelFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_SEPIA:
|
||||
{
|
||||
case SHADER_TYPE_SEPIA: {
|
||||
fShader[0] = colorMatrixFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_SKETCH:
|
||||
{
|
||||
case SHADER_TYPE_SKETCH: {
|
||||
fShader[0] = sketchShaderStr;
|
||||
vShader[0] = v3x3ShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_TOON:
|
||||
{
|
||||
case SHADER_TYPE_TOON: {
|
||||
fShader[0] = toonFShaderStr;
|
||||
vShader[0] = v3x3ShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_VIGNETTE:
|
||||
{
|
||||
case SHADER_TYPE_VIGNETTE: {
|
||||
fShader[0] = vignetteFShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_GRAYSCALE:
|
||||
{
|
||||
case SHADER_TYPE_GRAYSCALE: {
|
||||
fShader[0] = grayScaleShaderStr;
|
||||
break;
|
||||
}
|
||||
case SHADER_TYPE_BLUR:
|
||||
{
|
||||
case SHADER_TYPE_BLUR: {
|
||||
fShader[0] = blurShaderStr;
|
||||
break;
|
||||
}
|
||||
|
@ -723,13 +685,12 @@ void EGLRender::SetIntParams(int paramType, int param)
|
|||
}
|
||||
|
||||
m_ProgramObj = GLUtils::CreateProgram(vShader[0], fShader[0], m_VertexShader,
|
||||
m_FragmentShader);
|
||||
if (!m_ProgramObj)
|
||||
{
|
||||
m_FragmentShader);
|
||||
if (!m_ProgramObj) {
|
||||
GLUtils::CheckGLError("Create Program");
|
||||
LOGI("gl--> EGLRender::SetIntParams Could not create program.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_SamplerLoc = glGetUniformLocation(m_ProgramObj, "s_TextureMap");
|
||||
m_TexSizeLoc = glGetUniformLocation(m_ProgramObj, "u_texSize");
|
||||
|
@ -758,8 +719,7 @@ void EGLRender::UseProgram()
|
|||
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
|
||||
glUniform1i(m_SamplerLoc, 0);
|
||||
|
||||
if (m_TexSizeLoc > -1)
|
||||
{
|
||||
if (m_TexSizeLoc > -1) {
|
||||
GLfloat size[2];
|
||||
size[0] = m_RenderImage.width;
|
||||
size[1] = m_RenderImage.height;
|
||||
|
@ -770,8 +730,7 @@ void EGLRender::UseProgram()
|
|||
void EGLRender::GlUniform(char* location, float value, int unType)
|
||||
{
|
||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||
switch(unType)
|
||||
{
|
||||
switch (unType) {
|
||||
case UNIFORM_TYPE_ZERO:
|
||||
glUniform1i(ll, (int)value);
|
||||
break;
|
||||
|
@ -786,8 +745,7 @@ void EGLRender::GlUniform(char* location, float value, int unType)
|
|||
void EGLRender::GlUniformArray(char* location, float* value, int unType)
|
||||
{
|
||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||
switch(unType)
|
||||
{
|
||||
switch (unType) {
|
||||
case UNIFORM_TYPE_2FV_SIZE:
|
||||
GLfloat vec2[2];
|
||||
vec2[0] = value[0] * m_RenderImage.width;
|
||||
|
@ -817,10 +775,9 @@ void EGLRender::GlUniformArray(char* location, float* value, int unType)
|
|||
void EGLRender::GlUniformMatrix(char* location, float* value, int unType)
|
||||
{
|
||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||
switch(unType)
|
||||
{
|
||||
switch (unType) {
|
||||
case UNIFORM_TYPE_THREE:
|
||||
glUniformMatrix3fv(ll, 1, false,value);
|
||||
glUniformMatrix3fv(ll, 1, false, value);
|
||||
break;
|
||||
case UNIFORM_TYPE_FOUR:
|
||||
glUniformMatrix4fv(ll, 1, false, value);
|
||||
|
@ -832,54 +789,46 @@ void EGLRender::GlUniformMatrix(char* location, float* value, int unType)
|
|||
|
||||
void EGLRender::UnInit()
|
||||
{
|
||||
if (m_ProgramObj)
|
||||
{
|
||||
if (m_ProgramObj) {
|
||||
glDeleteProgram(m_ProgramObj);
|
||||
m_ProgramObj = GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ImageTextureId)
|
||||
{
|
||||
if (m_ImageTextureId) {
|
||||
glDeleteTextures(DEFAULT_ONE, &m_ImageTextureId);
|
||||
m_ImageTextureId = GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_FboTextureId)
|
||||
{
|
||||
if (m_FboTextureId) {
|
||||
glDeleteTextures(DEFAULT_ONE, &m_FboTextureId);
|
||||
m_FboTextureId = GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_VboIds[DEFAULT_ZERO])
|
||||
{
|
||||
if (m_VboIds[DEFAULT_ZERO]) {
|
||||
glDeleteBuffers(DEFAULT_THREE, m_VboIds);
|
||||
m_VboIds[DEFAULT_ZERO] = GL_NONE;
|
||||
m_VboIds[DEFAULT_ONE] = GL_NONE;
|
||||
m_VboIds[DEFAULT_TWO] = GL_NONE;
|
||||
}
|
||||
|
||||
if (m_VaoIds[DEFAULT_ZERO])
|
||||
{
|
||||
if (m_VaoIds[DEFAULT_ZERO]) {
|
||||
glDeleteVertexArrays(DEFAULT_ONE, m_VaoIds);
|
||||
m_VaoIds[DEFAULT_ZERO] = GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_FboId)
|
||||
{
|
||||
if (m_FboId) {
|
||||
glDeleteFramebuffers(1, &m_FboId);
|
||||
m_FboId = GL_NONE;
|
||||
}
|
||||
if (m_IsGLContextReady)
|
||||
{
|
||||
}
|
||||
if (m_IsGLContextReady) {
|
||||
DestroyGl();
|
||||
m_IsGLContextReady = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
void EGLRender::DestroyGl()
|
||||
{
|
||||
// 释放 EGL 环境
|
||||
if (m_eglDisplay != EGL_NO_DISPLAY)
|
||||
{
|
||||
if (m_eglDisplay != EGL_NO_DISPLAY) {
|
||||
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroyContext(m_eglDisplay, m_eglCtx);
|
||||
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
||||
|
|
|
@ -31,20 +31,23 @@
|
|||
const int EGL_FEATURE_NUM = 7;
|
||||
|
||||
class EGLRender {
|
||||
|
||||
public:
|
||||
public:
|
||||
EGLRender();
|
||||
~EGLRender();
|
||||
|
||||
static EGLRender* GetInstance() {
|
||||
if(sInstance == nullptr) {
|
||||
static EGLRender* GetInstance()
|
||||
{
|
||||
if(sInstance == nullptr)
|
||||
{
|
||||
sInstance = new EGLRender();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
static void DestroyRender() {
|
||||
if(sInstance) {
|
||||
static void DestroyRender()
|
||||
{
|
||||
if (sInstance)
|
||||
{
|
||||
delete sInstance;
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
@ -61,7 +64,6 @@ class EGLRender {
|
|||
|
||||
static napi_value Rendering(napi_env env, napi_callback_info info);
|
||||
|
||||
|
||||
static napi_value RenderGlUniform1i(napi_env env, napi_callback_info info);
|
||||
static napi_value RenderGlUniform1f(napi_env env, napi_callback_info info);
|
||||
static napi_value RenderGlUniform2fv(napi_env env, napi_callback_info info);
|
||||
|
@ -91,7 +93,7 @@ class EGLRender {
|
|||
|
||||
void UnInit();
|
||||
|
||||
private:
|
||||
private:
|
||||
static EGLRender* sInstance;
|
||||
GLuint m_ImageTextureId;
|
||||
GLuint m_FboTextureId;
|
||||
|
@ -113,8 +115,6 @@ class EGLRender {
|
|||
bool m_IsGLContextReady;
|
||||
const char* m_fShaderStrs[EGL_FEATURE_NUM];
|
||||
int m_ShaderIndex;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // GPU_ImageETS_EGLRender_H
|
||||
|
|
|
@ -28,24 +28,20 @@ GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource)
|
|||
{
|
||||
GLuint shader = 0;
|
||||
shader = glCreateShader(shaderType);
|
||||
if (shader)
|
||||
{
|
||||
if (shader) {
|
||||
glShaderSource(shader, 1, &pSource, NULL);
|
||||
glCompileShader(shader);
|
||||
GLint compiled = 0;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
if (!compiled) {
|
||||
GLint infoLen = 0;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
|
||||
if (infoLen)
|
||||
{
|
||||
if (infoLen) {
|
||||
char* buf = (char*) malloc((size_t)infoLen);
|
||||
if (buf)
|
||||
{
|
||||
if (buf) {
|
||||
glGetShaderInfoLog(shader, infoLen, NULL, buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
glDeleteShader(shader);
|
||||
shader = 0;
|
||||
}
|
||||
|
@ -54,17 +50,19 @@ GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource)
|
|||
return shader;
|
||||
}
|
||||
|
||||
GLuint GLUtils::CreateProgram(const char *pVertexShaderSource, const char *pFragShaderSource, GLuint &vertexShaderHandle, GLuint &fragShaderHandle)
|
||||
GLuint GLUtils::CreateProgram(const char *pVertexShaderSource,
|
||||
const char *pFragShaderSource,
|
||||
GLuint &vertexShaderHandle,
|
||||
GLuint &fragShaderHandle)
|
||||
{
|
||||
GLuint program = 0;
|
||||
vertexShaderHandle = LoadShader(GL_VERTEX_SHADER, pVertexShaderSource);
|
||||
if (!vertexShaderHandle) return program;
|
||||
fragShaderHandle = LoadShader(GL_FRAGMENT_SHADER, pFragShaderSource);
|
||||
if (!fragShaderHandle) return program;
|
||||
if (!fragShaderHandle) return program;
|
||||
|
||||
program = glCreateProgram();
|
||||
if (program)
|
||||
{
|
||||
if (program) {
|
||||
glAttachShader(program, vertexShaderHandle);
|
||||
CheckGLError("glAttachShader");
|
||||
glAttachShader(program, fragShaderHandle);
|
||||
|
@ -78,32 +76,28 @@ GLuint GLUtils::CreateProgram(const char *pVertexShaderSource, const char *pFrag
|
|||
vertexShaderHandle = 0;
|
||||
glDetachShader(program, fragShaderHandle);
|
||||
glDeleteShader(fragShaderHandle);
|
||||
fragShaderHandle = 0;
|
||||
fragShaderHandle = 0;
|
||||
|
||||
if (linkStatus != GL_TRUE)
|
||||
{
|
||||
if (linkStatus != GL_TRUE) {
|
||||
GLint bufLength = 0;
|
||||
glGetProgramiv(program,GL_INFO_LOG_LENGTH, &bufLength);
|
||||
if (bufLength)
|
||||
{
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
|
||||
if (bufLength) {
|
||||
char* buf = (char*) malloc((size_t)bufLength);
|
||||
if (buf)
|
||||
{
|
||||
if (buf) {
|
||||
glGetProgramInfoLog(program, bufLength, NULL, buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glDeleteProgram(program);
|
||||
program = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
void GLUtils::CheckGLError(const char *pGLOperation)
|
||||
{
|
||||
for (GLint error = glGetError(); error; error = glGetError())
|
||||
{
|
||||
for (GLint error = glGetError(); error; error = glGetError()) {
|
||||
LOGI("GLUtils::CheckGLError GL Operation %{public}s() glError (0x%x)\n", pGLOperation, error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <GLES3/gl3.h>
|
||||
|
||||
class GLUtils {
|
||||
public:
|
||||
public:
|
||||
static GLuint LoadShader(GLenum shaderType, const char *pSource);
|
||||
static GLuint CreateProgram(const char *pVertexShaderSource, const char *pFragShaderSource,
|
||||
GLuint &vertexShaderHandle,
|
||||
|
|
|
@ -32,18 +32,16 @@ const int32_t MAX_STR_LENGTH = 1024;
|
|||
|
||||
void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, const int32_t bufLen, std::string &target)
|
||||
{
|
||||
if (bufLen <= 0 || bufLen > MAX_STR_LENGTH)
|
||||
{
|
||||
LOGI("%s string too long malloc failed",__func__);
|
||||
if (bufLen <= 0 || bufLen > MAX_STR_LENGTH) {
|
||||
LOGI("%s string too long malloc failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr <char[]> buf = std::make_unique <char[]>(bufLen);
|
||||
if (buf.get() == nullptr)
|
||||
{
|
||||
LOGI("%s nullptr js object to string malloc failed",__func__);
|
||||
if (buf.get() == nullptr) {
|
||||
LOGI("%s nullptr js object to string malloc failed", __func__);
|
||||
return;
|
||||
}
|
||||
}
|
||||
(void) memset(buf.get(), 0, bufLen);
|
||||
size_t result = 0;
|
||||
napi_get_value_string_utf8(env, value, buf.get(), bufLen, &result);
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
#include "native_common.h"
|
||||
|
||||
class NapiUtil {
|
||||
public:
|
||||
public:
|
||||
static void JsValueToString(const napi_env &env, const napi_value &value, const int32_t bufLen,
|
||||
std::string &target);
|
||||
std::string &target);
|
||||
};
|
||||
|
||||
#endif // GPU_ImageETS_NapiUtil_H
|
||||
|
|
|
@ -51,8 +51,7 @@
|
|||
#define IMAGE_FORMAT_P010_EXT "P010" // 16bit NV21
|
||||
|
||||
|
||||
struct NativeImage
|
||||
{
|
||||
struct NativeImage {
|
||||
int width;
|
||||
int height;
|
||||
int format;
|
||||
|
@ -69,54 +68,56 @@ struct NativeImage
|
|||
}
|
||||
};
|
||||
|
||||
class NativeImageUtil
|
||||
{
|
||||
public:
|
||||
class NativeImageUtil {
|
||||
public:
|
||||
static void AllocNativeImage(NativeImage *pImage)
|
||||
{
|
||||
if (pImage ->height == DEFAULT_ZERO || pImage ->width == DEFAULT_ZERO) return;
|
||||
switch(pImage -> format)
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_FOUR));
|
||||
switch (pImage -> format) {
|
||||
case IMAGE_FORMAT_RGBA: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_FOUR));
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_YUYV:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_TWO));
|
||||
case IMAGE_FORMAT_YUYV: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_TWO));
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_NV12:
|
||||
case IMAGE_FORMAT_NV21:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_ONE_HALF));
|
||||
pImage->ppPlane[DEFAULT_ONE] = pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height;
|
||||
case IMAGE_FORMAT_NV21: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_ONE_HALF));
|
||||
pImage->ppPlane[DEFAULT_ONE] =
|
||||
pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height;
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_I420:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_ONE_HALF));
|
||||
pImage->ppPlane[DEFAULT_ONE] = pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height;
|
||||
pImage->ppPlane[DEFAULT_TWO] = pImage->ppPlane[DEFAULT_ONE] + pImage->width * (pImage->height >> DEFAULT_TWO);
|
||||
case IMAGE_FORMAT_I420: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_ONE_HALF));
|
||||
pImage->ppPlane[DEFAULT_ONE] =
|
||||
pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height;
|
||||
pImage->ppPlane[DEFAULT_TWO] =
|
||||
pImage->ppPlane[DEFAULT_ONE] + pImage->width * (pImage->height >> DEFAULT_TWO);
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_GRAY:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height));
|
||||
case IMAGE_FORMAT_GRAY: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height));
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_I444:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_THREE));
|
||||
case IMAGE_FORMAT_I444: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_THREE));
|
||||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_P010:
|
||||
{
|
||||
pImage->ppPlane[DEFAULT_ZERO] = static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_THREE));
|
||||
pImage->ppPlane[DEFAULT_ONE] = pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height * DEFAULT_TWO;
|
||||
break;
|
||||
case IMAGE_FORMAT_P010: {
|
||||
pImage->ppPlane[DEFAULT_ZERO] =
|
||||
static_cast<uint8_t *>(malloc(pImage->width * pImage ->height * DEFAULT_THREE));
|
||||
pImage->ppPlane[DEFAULT_ONE] =
|
||||
pImage->ppPlane[DEFAULT_ZERO] + pImage->width * pImage->height * DEFAULT_TWO;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -133,13 +134,11 @@ class NativeImageUtil
|
|||
|
||||
static bool CreateArrayBuffer(napi_env env, void* src, size_t srcLen, napi_value *res)
|
||||
{
|
||||
if (src == nullptr || srcLen == DEFAULT_ZERO)
|
||||
{
|
||||
if (src == nullptr || srcLen == DEFAULT_ZERO) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void *nativePtr = nullptr;
|
||||
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr)
|
||||
{
|
||||
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
memcpy(nativePtr, src, srcLen);
|
||||
|
@ -153,8 +152,7 @@ class NativeImageUtil
|
|||
uint8_t* tmp = (uint8_t*)malloc(totalLength);
|
||||
memcpy(tmp, *buf, totalLength);
|
||||
memset(*buf, DEFAULT_ZERO, sizeof(uint8_t)*totalLength);
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int i = 0; i < height; i++) {
|
||||
memcpy(*buf + oneLineLength * i, tmp + totalLength - oneLineLength * (i+1), oneLineLength);
|
||||
}
|
||||
free(tmp);
|
||||
|
|
Loading…
Reference in New Issue