Skip to content

Commit

Permalink
removing X server side root window rendering leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
twaik committed Jan 26, 2025
1 parent 4f0b355 commit 13f9902
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 145 deletions.
1 change: 0 additions & 1 deletion app/src/main/aidl/com/termux/x11/ICmdEntryInterface.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.termux.x11;

// This interface is used by utility on termux side.
interface ICmdEntryInterface {
void windowChanged(in Surface surface);
ParcelFileDescriptor getXConnection();
ParcelFileDescriptor getLogcatOutput();
}
14 changes: 0 additions & 14 deletions app/src/main/cpp/lorie/InitOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ void OsVendorInit(void) {
pthread_condattr_init(&cond_attr);
pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
pthread_cond_init(&lorieScreen.state->cond, &cond_attr);
#if !RENDERER_IN_ACTIVITY
renderer_set_shared_state(lorieScreen.state);
#endif
}

void lorieActivityConnected(void) {
Expand Down Expand Up @@ -484,11 +481,7 @@ static Bool lorieCreateScreenResources(ScreenPtr pScreen) {
DamageRegister(&(*pScreen->GetScreenPixmap)(pScreen)->drawable, pvfb->damage);
pvfb->fpsTimer = TimerSet(NULL, 0, 5000, lorieFramecounter, pScreen);

#if RENDERER_IN_ACTIVITY
lorieSendRootWindowBuffer(((LoriePixmapPriv*) exaGetPixmapDriverPrivate(pScreen->devPrivate))->buffer);
#else
renderer_set_buffer(((LoriePixmapPriv*) exaGetPixmapDriverPrivate(pScreen->devPrivate))->buffer);
#endif

return TRUE;
}
Expand Down Expand Up @@ -542,11 +535,7 @@ static Bool lorieRRScreenSetSize(ScreenPtr pScreen, CARD16 width, CARD16 height,
pScreen->DestroyPixmap(oldPixmap);
}

#if RENDERER_IN_ACTIVITY
lorieSendRootWindowBuffer(((LoriePixmapPriv*) exaGetPixmapDriverPrivate(pScreen->devPrivate))->buffer);
#else
renderer_set_buffer(((LoriePixmapPriv*) exaGetPixmapDriverPrivate(pScreen->devPrivate))->buffer);
#endif

pScreen->ResizeWindow(pScreen->root, 0, 0, width, height, NULL);
RegionReset(&pScreen->root->winSize, &box);
Expand Down Expand Up @@ -708,9 +697,6 @@ void InitOutput(ScreenInfo * screen_info, int argc, char **argv) {
screen_info->bitmapBitOrder = BITMAP_BIT_ORDER;
screen_info->numPixmapFormats = ARRAY_SIZE(depths);

#if !RENDERER_IN_ACTIVITY
renderer_init(pvfb->env);
#endif
renderer_test_capabilities(&pvfb->root.legacyDrawing, &pvfb->root.flip);
xorgGlxCreateVendor();
lorieInitClipboard();
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/cpp/lorie/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ static int xcallback(int fd, int events, __unused void* data) {
ALooper_removeFd(ALooper_forThread(), fd);
close(conn_fd);
conn_fd = -1;
#if RENDERER_IN_ACTIVITY
renderer_set_shared_state(NULL);
renderer_set_buffer(NULL);
#endif
log(DEBUG, "disconnected");
return 1;
}
Expand Down Expand Up @@ -184,12 +182,7 @@ static int xcallback(int fd, int events, __unused void* data) {
state = NULL;
}

#if RENDERER_IN_ACTIVITY
renderer_set_shared_state(state);
#else
// Should pass it to renderer thread here, but currently it is not implemented...
munmap(state, sizeof(*state));
#endif

close(stateFd); // Closing file descriptor does not unmmap shared memory fragment.
break;
Expand All @@ -200,9 +193,7 @@ static int xcallback(int fd, int events, __unused void* data) {
LorieBuffer_recvHandleFromUnixSocket(conn_fd, &buffer);
LorieBuffer_describe(buffer, &desc);
log(INFO, "Received shared buffer width %d height %d format %d", desc.width, desc.height, desc.format);
#if RENDERER_IN_ACTIVITY
renderer_set_buffer(buffer);
#endif
LorieBuffer_release(buffer);
}
}
Expand Down Expand Up @@ -366,18 +357,11 @@ static void sendTextEvent(JNIEnv *env, __unused jobject thiz, jbyteArray text) {
}

static void surfaceChanged(JNIEnv *env, jobject thiz, jobject sfc) {
#if RENDERER_IN_ACTIVITY
ANativeWindow* win = sfc ? ANativeWindow_fromSurface(env, sfc) : NULL;
if (win)
ANativeWindow_acquire(win);

renderer_set_window(win);
#endif
}

JNIEXPORT jboolean JNICALL
Java_com_termux_x11_LorieView_renderingInActivity(JNIEnv *env, jobject thiz) {
return RENDERER_IN_ACTIVITY;
}

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
Expand All @@ -404,9 +388,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
jclass cls = (*env)->FindClass(env, "com/termux/x11/LorieView");
(*env)->RegisterNatives(env, cls, methods, sizeof(methods)/sizeof(methods[0]));

#if RENDERER_IN_ACTIVITY
renderer_init(env);
#endif

return JNI_VERSION_1_6;
}
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/cpp/lorie/cmdentrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ Java_com_termux_x11_CmdEntryPoint_start(JNIEnv *env, __unused jclass cls, jobjec
return JNI_TRUE;
}

JNIEXPORT void JNICALL
Java_com_termux_x11_CmdEntryPoint_windowChanged(JNIEnv *env, __unused jobject cls, jobject surface) {
#if !RENDERER_IN_ACTIVITY
renderer_set_window(env, surface ? (*env)->NewGlobalRef(env, surface) : NULL);
#endif
}

static Bool sendConfigureNotify(__unused ClientPtr pClient, void *closure) {
// This must be done only on X server thread.
lorieEvent* e = closure;
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/cpp/lorie/lorie.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#define RENDERER_IN_ACTIVITY 1

#include <android/hardware_buffer.h>
#include <android/native_window_jni.h>
Expand Down Expand Up @@ -40,11 +39,7 @@ bool lorieConnectionAlive(void);
__unused int renderer_init(JNIEnv* env);
__unused void renderer_test_capabilities(int* legacy_drawing, uint8_t* flip);
__unused void renderer_set_buffer(LorieBuffer* buffer);
#if RENDERER_IN_ACTIVITY
__unused void renderer_set_window(ANativeWindow* win);
#else
__unused void renderer_set_window(JNIEnv* env, jobject surface);
#endif
__unused void renderer_set_shared_state(struct lorie_shared_server_state* state);

static inline __always_inline void lorie_mutex_lock(pthread_mutex_t* mutex, pid_t* lockingPid) {
Expand Down
90 changes: 0 additions & 90 deletions app/src/main/cpp/lorie/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,14 @@ static EGLContext ctx = EGL_NO_CONTEXT;
static EGLSurface sfc = EGL_NO_SURFACE;
static EGLConfig cfg = 0;
static ANativeWindow* win = 0;
#if !RENDERER_IN_ACTIVITY
static jobject surface = NULL;
#endif
static LorieBuffer *buffer = NULL;
static EGLImageKHR image = NULL;

#if !RENDERER_IN_ACTIVITY
static jmethodID Surface_release = NULL;
static jmethodID Surface_destroy = NULL;
#endif

static JNIEnv* renderEnv = NULL;
static volatile bool stateChanged = false, bufferChanged = false, windowChanged = false;
static volatile struct lorie_shared_server_state* pendingState = NULL;
static volatile LorieBuffer* pendingBuffer = NULL;
#if RENDERER_IN_ACTIVITY
static volatile ANativeWindow* pendingWin = NULL;
#else
static volatile jobject pendingSurface = NULL;
#endif

static pthread_mutex_t stateLock;
static pthread_cond_t stateCond;
Expand Down Expand Up @@ -188,20 +176,6 @@ int renderer_init(JNIEnv* env) {
pthread_mutex_init(&stateLock, NULL);
pthread_cond_init(&stateCond, NULL);

#if !RENDERER_IN_ACTIVITY
jclass Surface = (*env)->FindClass(env, "android/view/Surface");
Surface_release = (*env)->GetMethodID(env, Surface, "release", "()V");
Surface_destroy = (*env)->GetMethodID(env, Surface, "destroy", "()V");
if (!Surface_release) {
loge("Failed to find required Surface.release method. Aborting.\n");
abort();
}
if (!Surface_destroy) {
loge("Failed to find required Surface.destroy method. Aborting.\n");
abort();
}
#endif

egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (egl_display == EGL_NO_DISPLAY)
return printEglError("Got no EGL display", __LINE__);
Expand Down Expand Up @@ -379,13 +353,8 @@ void renderer_set_buffer(LorieBuffer* buf) {
end: pthread_mutex_unlock(&stateLock);
}

#if RENDERER_IN_ACTIVITY
void renderer_set_window(ANativeWindow* newWin) {
#else
void renderer_set_window(JNIEnv* env, jobject new_surface) {
#endif
pthread_mutex_lock(&stateLock);
#if RENDERER_IN_ACTIVITY
if (newWin && pendingWin == newWin) {
ANativeWindow_release(newWin);
pthread_mutex_unlock(&stateLock);
Expand All @@ -396,23 +365,6 @@ void renderer_set_window(JNIEnv* env, jobject new_surface) {
ANativeWindow_release(pendingWin);

pendingWin = newWin;
#else
if (pendingSurface && new_surface && pendingSurface != new_surface && (*env)->IsSameObject(env, pendingSurface, new_surface)) {
(*env)->DeleteGlobalRef(env, new_surface);
pthread_mutex_unlock(&stateLock);
return;
}

if (pendingSurface && pendingSurface == new_surface) {
pthread_mutex_unlock(&stateLock);
return;
}

if (pendingSurface)
(*env)->DeleteGlobalRef(env, pendingSurface);

pendingSurface = new_surface;
#endif
windowChanged = TRUE;

// We are not sure which conditional variable is used at current moment so let's signal both
Expand All @@ -423,11 +375,7 @@ void renderer_set_window(JNIEnv* env, jobject new_surface) {
pthread_mutex_unlock(&stateLock);
}

#if RENDERER_IN_ACTIVITY
static inline __always_inline void release_win_and_surface(JNIEnv *env, ANativeWindow** anw, EGLSurface *esfc) {
#else
static inline __always_inline void release_win_and_surface(JNIEnv *env, jobject* jsfc, ANativeWindow** anw, EGLSurface *esfc) {
#endif
if (esfc && *esfc) {
if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE)
return vprintEglError("eglMakeCurrent failed (EGL_NO_SURFACE)", __LINE__);
Expand All @@ -440,57 +388,23 @@ static inline __always_inline void release_win_and_surface(JNIEnv *env, jobject*
ANativeWindow_release(*anw);
*anw = NULL;
}

#if !RENDERER_IN_ACTIVITY
if (jsfc && *jsfc) {
(*env)->CallVoidMethod(env, *jsfc, Surface_release);
(*env)->CallVoidMethod(env, *jsfc, Surface_destroy);
(*env)->DeleteGlobalRef(env, *jsfc);
*jsfc = NULL;
}
#endif
}

void renderer_refresh_context(JNIEnv* env) {
uint32_t emptyData = {0};
#if !RENDERER_IN_ACTIVITY
ANativeWindow* pendingWin = pendingSurface ? ANativeWindow_fromSurface(env, pendingSurface) : NULL;
if ((pendingSurface && surface && pendingSurface != surface && (*env)->IsSameObject(env, pendingSurface, surface)) || (pendingWin && win == pendingWin)) {
(*env)->DeleteGlobalRef(env, pendingSurface);
pendingSurface = NULL;
windowChanged = FALSE;
return;
}
#endif
int width = pendingWin ? ANativeWindow_getWidth(pendingWin) : 0;
int height = pendingWin ? ANativeWindow_getHeight(pendingWin) : 0;
log("renderer_set_window %p %d %d", pendingWin, width, height);

#if RENDERER_IN_ACTIVITY
release_win_and_surface(env, &win, &sfc);
#else
if (pendingWin)
ANativeWindow_acquire(pendingWin);

release_win_and_surface(env, &surface, &win, &sfc);
#endif

if (pendingWin && (width <= 0 || height <= 0)) {
log("Xlorie: We've got invalid surface. Probably it became invalid before we started working with it.\n");
#if RENDERER_IN_ACTIVITY
release_win_and_surface(env, &pendingWin, NULL);
#else
release_win_and_surface(env, &pendingSurface, &pendingWin, NULL);
#endif
}

win = pendingWin;
#if RENDERER_IN_ACTIVITY
pendingWin = NULL;
#else
surface = pendingSurface;
pendingSurface = NULL;
#endif
windowChanged = FALSE;

if (!win) {
Expand Down Expand Up @@ -649,11 +563,7 @@ void renderer_redraw_locked(JNIEnv* env) {
err = eglGetError();
if (err == EGL_BAD_NATIVE_WINDOW || err == EGL_BAD_SURFACE) {
log("The window is to be destroyed. Native window disconnected/abandoned, probably activity is destroyed or in background");
#if RENDERER_IN_ACTIVITY
renderer_set_window(NULL);
#else
renderer_set_window(env, NULL);
#endif
lorie_mutex_unlock(&state->lock, &state->lockingPid);
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/termux/x11/CmdEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public static Context createContext() {
}

public static native boolean start(String[] args);
public native void windowChanged(Surface surface);
public native ParcelFileDescriptor getXConnection();
public native ParcelFileDescriptor getLogcatOutput();
private static native boolean connected();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/termux/x11/LorieView.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ public boolean commitText(CharSequence text, int newCursorPosition) {
}
}

static native boolean renderingInActivity();
@FastNative private native void nativeInit();
@FastNative private native void surfaceChanged(Surface surface);
@FastNative static native void connect(int fd);
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ else if (SamsungDexUtils.checkDeXEnabled(this))
else
name = "External Display";
LorieView.sendWindowChange(screenWidth, screenHeight, framerate, name);

if (service != null && !LorieView.renderingInActivity()) {
try {
service.windowChanged(sfc);
} catch (RemoteException e) {
Log.e("MainActivity", "failed to send windowChanged request", e);
}
}
});

registerReceiver(receiver, new IntentFilter(ACTION_START) {{
Expand Down

0 comments on commit 13f9902

Please sign in to comment.