Skip to content

Commit

Permalink
init: skia dom基础功能和demo (#4)
Browse files Browse the repository at this point in the history
* refactor: init skia moudle

* refactor: XComponent使用TEXTURE模式,nativeId的获取和渲染时机调整

* init: skia dom基础功能和demo
  • Loading branch information
Mrliwang authored Aug 19, 2024
1 parent bb4c234 commit c5d4753
Show file tree
Hide file tree
Showing 31 changed files with 2,597 additions and 762 deletions.
Binary file added tester/assets/BigBuckBunny.mp4
Binary file not shown.
Binary file added tester/assets/expo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tester/assets/gifdemo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tester/assets/placeholder2000x2000.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
724 changes: 724 additions & 0 deletions tester/assets/tiger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions tester/harmony/skia/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ add_library(${PACKAGE_NAME} SHARED ${rnoh_skia_SRC})
target_include_directories(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/skia)
target_include_directories(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/rnskia)
target_include_directories(${PACKAGE_NAME} PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/include)



target_link_directories(${PACKAGE_NAME} PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/aarch64-linux-ohos)
target_link_libraries(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/libthird_party__harfbuzz.a)
target_link_libraries(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/libthird_party__expat.a)
target_link_libraries(${PACKAGE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/libthird_party__freetype2.a)
Expand Down Expand Up @@ -111,7 +111,6 @@ find_library(
uv
)


target_link_libraries(
${PACKAGE_NAME}
PUBLIC
Expand All @@ -126,8 +125,16 @@ target_link_libraries(
libnative_buffer.so
libace_napi.z.so

libnative_media_core.so

libavplayer.so
libnative_media_core.so
libnative_media_avsource.so
libnative_media_acodec.so
libnative_media_avdemuxer.so
libnative_media_codecbase.so
libnative_media_vdec.so
libohaudio.so
librcp_c.so

${EGL-lib} ${GLES-lib} ${hilog-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib}
# libEGL.so
Expand Down
2 changes: 1 addition & 1 deletion tester/harmony/skia/src/main/cpp/RNSkiaModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace rnoh {

bool RNSkiaModule::install(jsi::Runtime &rt) {
DLOG(INFO) << "RNSkiaModule::install";
auto pixelDensity = 300;
auto pixelDensity = 3.25;

platformContext = std::make_shared<RNSkia::HarmonyPlatformContext>(&rt, jsInvoker_, pixelDensity);
RNSkia::SkiaManager::getInstance().setContext(platformContext);
Expand Down
96 changes: 4 additions & 92 deletions tester/harmony/skia/src/main/cpp/rnskia/HarmonyOpenGLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
#pragma clang diagnostic pop

namespace RNSkia {
// using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
// constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
// constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
// constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
// constexpr char CHARACTER_WHITESPACE = ' ';
// constexpr const char *CHARACTER_STRING_WHITESPACE = " ";
// constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
// constexpr int32_t NATIVE_CACHE_BUFFER = 3;

/**
* Singleton holding the default display and shared eglContext that will be the
Expand All @@ -43,49 +35,7 @@ class OpenGLResourceHolder {
private:
OpenGLResourceHolder() {
DLOG(INFO) << "OpenGLResourceHolder Initialize OpenGL";
// glDisplay = GetPlatformEglDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, NULL);
// if (glDisplay == EGL_NO_DISPLAY) {
// return;
// }
// EGLint major, minor;
// // Initialize EGLDisplay
// if (eglInitialize(glDisplay, &major, &minor) == EGL_FALSE) {
// return;
// }
// // The API for binding graphic drawing is OpenGLES
// if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
// return;
// }
// unsigned int ret;
// EGLint count;
// EGLint config_attribs[] = {EGL_SURFACE_TYPE,
// EGL_WINDOW_BIT,
// EGL_RED_SIZE,
// 8,
// EGL_GREEN_SIZE,
// 8,
// EGL_BLUE_SIZE,
// 8,
// EGL_ALPHA_SIZE,
// 8,
// EGL_RENDERABLE_TYPE,
// EGL_OPENGL_ES3_BIT,
// EGL_NONE};
// // Obtain a valid system configuration information
// ret = eglChooseConfig(glDisplay, config_attribs, &glConfig, 1, &count);
// if (!(ret && static_cast<unsigned int>(count) >= 1)) {
// return;
// }
// static const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE};
// glContext = eglCreateContext(glContext, glConfig, EGL_NO_CONTEXT, context_attribs);
// if (glContext == EGL_NO_CONTEXT) {
// return;
// }
// // Associated Context
// eglMakeCurrent(glDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, glContext);


/*// Initialize OpenGL
// Initialize OpenGL
glDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (glDisplay == EGL_NO_DISPLAY) {
DLOG(INFO) << "eglGetDisplay failed : " << glGetError();
Expand All @@ -110,7 +60,7 @@ class OpenGLResourceHolder {
glContext = eglCreateContext(glDisplay, glConfig, glContext, contextAttribs);
if (glContext == EGL_NO_CONTEXT) {
DLOG(INFO) << "glCreateContext failed : " << glGetError();
}*/
}
}

~OpenGLResourceHolder() {
Expand Down Expand Up @@ -148,9 +98,7 @@ class OpenGLResourceHolder {
/**
* Shared eglConfig
*/
EGLConfig glConfig = 0;


std::atomic<EGLConfig> glConfig = 0;

private:
/**
Expand Down Expand Up @@ -189,43 +137,6 @@ class OpenGLResourceHolder {

return glConfig;
}

// EGLDisplay GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list) {
// static GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL;
// if (!eglGetPlatformDisplayExt) {
// const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
// if (extensions && (CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) ||
// CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) {
// eglGetPlatformDisplayExt = (GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT);
// }
// }
//
// if (eglGetPlatformDisplayExt) {
// return eglGetPlatformDisplayExt(platform, native_display, attrib_list);
// }
//
// return eglGetDisplay((EGLNativeDisplayType)native_display);
// }
//
// bool CheckEglExtension(const char *eglExtensions, const char *eglExtension) {
// // Check egl extension
// size_t extLenth = strlen(eglExtension);
// const char *endPos = eglExtensions + strlen(eglExtensions);
//
// while (eglExtensions < endPos) {
// size_t len = 0;
// if (*eglExtensions == CHARACTER_WHITESPACE) {
// eglExtensions++;
// continue;
// }
// len = strcspn(eglExtensions, CHARACTER_STRING_WHITESPACE);
// if (len == extLenth && strncmp(eglExtension, eglExtensions, len) == 0) {
// return true;
// }
// eglExtensions += len;
// }
// return false;
// }
};

struct SkiaOpenGLContext {
Expand Down Expand Up @@ -319,6 +230,7 @@ class SkiaOpenGLHelper {
DLOG(INFO) << "eglSwapBuffers failed:" << eglGetError();
return false;
}
DLOG(INFO) << "swapBuffers success";
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions tester/harmony/skia/src/main/cpp/rnskia/RNSkHarmonyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ template <typename T> class RNSkHarmonyView : public T, public RNSkBaseHarmonyVi

// Try to render directly when the surface has been set so that
// we don't have to wait until the draw loop returns.
DLOG(INFO) << "surfaceAvailable to renderImmediate";
RNSkView::renderImmediate();
DLOG(INFO) << "surfaceAvailable to renderImmediate finish";
}

void surfaceDestroyed() override {
Expand Down Expand Up @@ -89,12 +91,14 @@ template <typename T> class RNSkHarmonyView : public T, public RNSkBaseHarmonyVi
if (eGLCore.EglContextInit(window, width, height)) {
eGLCore.Background();
}
int32_t has = 0;
eGLCore.Draw(has);
}

void render() override {
// int32_t has = 0;
// eGLCore.Draw(has);
DLOG(INFO) << "render to renderImmediate";
RNSkView::renderImmediate();
DLOG(INFO) << "render to renderImmediate finish";
}
};
} // namespace RNSkia
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <native_window/external_window.h>
#include "native_drawing/drawing_surface.h"
#include "NativeImageAdaptor.h"
#endif // HARMONY_RNSKOPENGLCANVASPROVIDER_H
#pragma once

Expand All @@ -41,14 +40,14 @@ class WindowSurfaceHolder {
if (_width > 0) {
_widthPercent = 0.5 * _height / _width;
}
//_window = window;
_window = NativeImageAdaptor::GetInstance()->getNativeWindow();
_window = window;
DLOG(INFO) << "WindowSurfaceHolder init _width: " << _width << " _height: " << _height
<< " _widthPercent: " << _widthPercent;
}

// 析构函数,释放本地窗口
~WindowSurfaceHolder() {
DLOG(INFO) << "~WindowSurfaceHolder release _window: " << _window;
if (_window) {
OH_NativeWindow_DestroyNativeWindow(_window);
}
Expand Down Expand Up @@ -212,7 +211,7 @@ class WindowSurfaceHolder {
}

private:
OHNativeWindow *_window; // 本地窗口
OHNativeWindow* _window; // 本地窗口
sk_sp<SkSurface> _skSurface = nullptr; // Skia表面
EGLSurface _glSurface = EGL_NO_SURFACE; // OpenGL表面
GrGLuint _textureId;
Expand Down
32 changes: 9 additions & 23 deletions tester/harmony/skia/src/main/cpp/rnskia/napi_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
*/

#include <hilog/log.h>
#include "plugin_manager.h"
#include <glog/logging.h>
#include "common.h"
#include "plugin_manager.h"

#include <js_native_api.h>
#include <js_native_api_types.h>
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <napi/native_api.h>
#include "NativeRender.h"
#include "NativeImageAdaptor.h"

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports) {
Expand All @@ -32,31 +30,19 @@ static napi_value Init(napi_env env, napi_value exports) {
DLOG(INFO) << "env or exports is null";
return nullptr;
}

//surface
// napi_property_descriptor desc[] = {{"registerView", nullptr, RNSkia::PluginRender::RegisterView, nullptr, nullptr,
// nullptr, napi_default, nullptr}};
// auto napiResult = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
// if (napiResult != napi_ok) {
// DLOG(ERROR) << "Export: napi_define_properties failed";
// }
// RNSkia::PluginManager::GetInstance()->Export(env, exports);

//texture
napi_property_descriptor desc[] = {
{ "getNativeRender", nullptr, RNSkia::NativeRender::GetNativeRender, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "registerView", nullptr, RNSkia::NativeRender::RegisterView, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
bool ret = RNSkia::NativeRender::GetInstance()->Export(env, exports);
if (!ret) {
DLOG(ERROR) << "NativeRender Init failed";
{"registerView", nullptr, RNSkia::PluginRender::RegisterView, nullptr, nullptr, nullptr, napi_default, nullptr}};
auto napiResult = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
if (napiResult != napi_ok) {
DLOG(ERROR) << "Export: napi_define_properties failed";
}
RNSkia::PluginManager::GetInstance()->Export(env, exports);

return exports;
}

EXTERN_C_END
static napi_module nativerenderModule = {.nm_version = 1,
static napi_module rn_skiaModule = {.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
// 入口函数
Expand All @@ -67,4 +53,4 @@ static napi_module nativerenderModule = {.nm_version = 1,
.reserved = {0}};

// 使用NAPI接口napi_module_register()传入模块描述信息进行模块注册
extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&nativerenderModule); }
extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&rn_skiaModule); }
Loading

0 comments on commit c5d4753

Please sign in to comment.