Skip to content

Commit cac653a

Browse files
committed
- solid wip hooking in surface create, starting user thread
1 parent b4b3c67 commit cac653a

File tree

3 files changed

+106
-5
lines changed

3 files changed

+106
-5
lines changed

core/pen/source/android/os.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@
99
#include <jni.h>
1010
#include <stdio.h>
1111

12+
#include <android/asset_manager.h>
13+
#include <android/asset_manager_jni.h>
14+
#include <android/native_window_jni.h>
15+
16+
#include <EGL/egl.h>
17+
#include <EGL/eglext.h>
18+
1219
// need to copy example/src/main/jniLibs (fmod)
1320
// inject strings for other samples res/values
1421

1522
// BLOG NOTES:
1623
// - gradle version, always changing
1724
// - depracated maven etc
1825
// - trying to link .so vs .a
26+
// - EGL_NONE, array terminator.
1927
// - No implementation found for void cc.pmtech.pen_activity.entry() (tried Java_cc_pmtech_pen_1activity_entry and Java_cc_pmtech_pen_1activity_entry__) - is the library loaded, e.g. System.loadLibrary?
2028

2129
// DONE:
@@ -43,6 +51,84 @@ PEN_JNIFUNC(void, pen_1activity, entry)(JNIEnv* env, jclass thiz)
4351
PEN_LOG("hello print %i\n", 69);
4452
}
4553

54+
PEN_JNIFUNC(void, SurfaceWrapper, render)(JNIEnv* env, jclass thiz, jobject caller)
55+
{
56+
PEN_LOG("render%i\n", 79);
57+
}
58+
59+
PEN_JNIFUNC(void, SurfaceWrapper, surface_1created)(JNIEnv* env, jclass thiz, jobject surface, int window_width, int window_height, int device_width, int device_height, int orientation, long app_ptr)
60+
{
61+
auto window = ANativeWindow_fromSurface(env, surface);
62+
63+
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
64+
PEN_ASSERT(display != EGL_NO_DISPLAY);
65+
EGLBoolean res = eglInitialize(display, nullptr, nullptr);
66+
PEN_ASSERT(res == EGL_TRUE);
67+
68+
EGLint attr[] = {
69+
EGL_BUFFER_SIZE, 32,
70+
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
71+
EGL_NONE
72+
};
73+
74+
EGLint num_configs;
75+
EGLConfig config;
76+
res = eglChooseConfig(display, &attr[0], &config, 1, &num_configs);
77+
PEN_ASSERT(res == EGL_TRUE);
78+
79+
EGLint ctx_attr[] = {
80+
EGL_CONTEXT_MAJOR_VERSION, 2,
81+
EGL_NONE
82+
};
83+
84+
eglBindAPI(EGL_OPENGL_ES_API);
85+
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attr);
86+
PEN_ASSERT(context != EGL_NO_CONTEXT);
87+
88+
EGLSurface egl_surface = eglCreateWindowSurface(display, config, window, nullptr);
89+
PEN_ASSERT(surface != EGL_NO_SURFACE);
90+
91+
res = eglMakeCurrent(
92+
display,
93+
egl_surface,
94+
egl_surface,
95+
context
96+
);
97+
PEN_ASSERT(res == EGL_TRUE);
98+
99+
eglSwapBuffers(display, egl_surface);
100+
101+
// TODO: call user_setup
102+
pen::pen_creation_params params = pen::pen_entry(0, nullptr);
103+
104+
pen::jobs_create_job(params.user_thread_function, 1024 * 1024, params.user_data, pen::e_thread_start_flags::detached);
105+
106+
/*
107+
// for get elapsed time
108+
s_startTime = getElapsedTimeMs();
109+
110+
s_context.m_windowWidth = windowWidth;
111+
s_context.m_windowHeight = windowHeight;
112+
113+
if(s_context.m_device.m_window)
114+
ANativeWindow_release(s_context.m_device.m_window);
115+
s_context.m_device.m_window = ANativeWindow_fromSurface(env, surface);
116+
s_context.m_device.m_surfaceWrapperClass = thiz;
117+
118+
fw::gfx::createMainContext((fw::gfx::Device)&s_context.m_device);
119+
120+
fw::AppConfig::get()->setupSystemInfo();
121+
122+
if (!s_context.m_app && appPtr != 0)
123+
{
124+
FW_LOG_CONSOLE("Surface created with width=%d, height=%d\n", s_context.m_windowWidth, s_context.m_windowHeight);
125+
126+
s_context.m_app = (App*)((intptr_t)appPtr);
127+
s_context.m_app->setup();
128+
}
129+
*/
130+
}
131+
46132
namespace pen
47133
{
48134
u32 window_init(void* params)

core/pen/source/posix/threads.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ namespace pen
108108
{
109109
pen::semaphore* new_semaphore = (pen::semaphore*)pen::memory_alloc(sizeof(pen::semaphore));
110110

111+
#ifndef PEN_PLATFORM_ANDROID
111112
c8 name_buf[32];
112113
pen::string_format(&name_buf[0], 32, "sem%i%i", semaphone_index++, window_get_id());
113114

114115
sem_unlink(name_buf);
115116
new_semaphore->handle = sem_open(name_buf, O_CREAT, 0, 0);
117+
#else
118+
new_semaphore->handle = (sem_t*)malloc(sizeof(sem_t));
119+
memset(new_semaphore->handle, 0x0, sizeof(sem_t));
120+
sem_init(new_semaphore->handle, 0, 0);
121+
#endif
116122

117123
assert(!(new_semaphore->handle == (void*)-1));
118124
return new_semaphore;

core/template/android/activity/pen_activity.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class VideoSurfaceTexture extends SurfaceTexture
4949
// new graphics api agnostic implementation of android surface to support native egl and vulkan
5050
class SurfaceWrapper extends SurfaceView implements SurfaceHolder.Callback, SurfaceTexture.OnFrameAvailableListener {
5151

52+
public static native void surface_created(Surface surface, int window_width, int window_height, int display_width, int display_height, int orientation, long app_ptr);
53+
public static native void render(SurfaceWrapper caller);
5254
/*
5355
public static native void render(SurfaceWrapper caller);
5456
public static native long fwEntry();
@@ -97,28 +99,31 @@ protected void onDraw(Canvas canvas)
9799
{
98100
Log.d("PMTECH", "onDraw");
99101

100-
// render(this);
102+
render(this);
101103
invalidate();
102104
}
103105

104106
@Override
105107
public void surfaceCreated(SurfaceHolder holder)
106108
{
107109
Log.d("PMTECH", "surfaceCreated");
110+
108111
/*
109-
setWillNotDraw(false);
110112
if(appPtr == 0) {
111-
113+
112114
}
113-
Surface surf = holder.getSurface();
114-
onSurfaceCreated(surf, m_windowWidth, m_windowHeight, m_displayWidth, m_displayHeight, orientation, appPtr); // creates entry point and stuff
115115
*/
116+
117+
setWillNotDraw(false);
118+
Surface surf = holder.getSurface();
119+
surface_created(surf, m_windowWidth, m_windowHeight, m_displayWidth, m_displayHeight, orientation, appPtr); // creates entry point and stuff
116120
}
117121

118122
@Override
119123
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
120124
{
121125
Log.d("PMTECH", "surfaceChanged");
126+
122127
// m_touchHeight = height;
123128
//onSurfaceChanged(width, height);
124129
}
@@ -289,6 +294,10 @@ protected void onCreate(Bundle arg0) {
289294

290295
android.view.SurfaceView view = new SurfaceWrapper(this);
291296

297+
// device dims
298+
299+
setContentView(view);
300+
292301
entry();
293302

294303
super.onCreate(arg0);

0 commit comments

Comments
 (0)