Skip to content

Commit

Permalink
make LorieBuffer handle regular pixmaps not backed but fd or ahardwar…
Browse files Browse the repository at this point in the history
…ebuffer

some preparations to support transferring non-root-window pixmaps to renderer process
  • Loading branch information
twaik committed Feb 10, 2025
1 parent 8964da1 commit 500779a
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 91 deletions.
30 changes: 12 additions & 18 deletions app/src/main/cpp/lorie/InitOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ Bool drawSquares() {
LoriePixmapPriv* priv = lorieRootWindowPixmapPriv();
uint32_t* pixels = !priv ? NULL : priv->locked;
if (pixels) {
LorieBuffer_Desc d = {0};
LorieBuffer_describe(priv->buffer, &d);
int l = min(d.width, d.height) / 4, x = (d.width - l)/2, y = (d.height - l)/2;
const LorieBuffer_Desc *d = LorieBuffer_description(priv->buffer);
int l = min(d->width, d->height) / 4, x = (d->width - l)/2, y = (d->height - l)/2;

drawSquare(x - l/3, y - l/3, l, 0x00FF0000, d.stride, pixels);
drawSquare(x, y, l, 0x0000FF00, d.stride, pixels);
drawSquare(x + l/3, y + l/3, l, 0x000000FF, d.stride, pixels);
drawSquare(x - l/3, y - l/3, l, 0x00FF0000, d->stride, pixels);
drawSquare(x, y, l, 0x0000FF00, d->stride, pixels);
drawSquare(x + l/3, y + l/3, l, 0x000000FF, d->stride, pixels);
}

return FALSE;
Expand Down Expand Up @@ -443,7 +442,7 @@ static Bool lorieRedraw(__unused ClientPtr pClient, __unused void *closure) {
// Also according to AHardwareBuffer docs simultaneous reading in rendering thread and
// locking for writing in other thread is fine.
LorieBuffer_unlock(priv->buffer);
status = LorieBuffer_lock(priv->buffer, NULL, &priv->locked);
status = LorieBuffer_lock(priv->buffer, &priv->locked);
if (status)
FatalError("Failed to lock the surface: %d\n", status);

Expand Down Expand Up @@ -778,29 +777,24 @@ void lorieSetVM(JavaVM* vm) {

void exaDDXDriverInit(__unused ScreenPtr pScreen) {}

void *lorieCreatePixmap(__unused ScreenPtr pScreen, int width, int height, __unused int depth, int usage_hint, int bpp, int *new_fb_pitch) {
void *lorieCreatePixmap(__unused ScreenPtr pScreen, int width, int height, __unused int depth, int usage_hint, __unused int bpp, int *new_fb_pitch) {
LoriePixmapPriv *priv;
size_t size = sizeof(LoriePixmapPriv);
*new_fb_pitch = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits);

if (usage_hint != CREATE_PIXMAP_USAGE_LORIEBUFFER_BACKED)
size += *new_fb_pitch * height;
*new_fb_pitch = 0;

priv = calloc(1, size);
if (!priv)
return NULL;

if (usage_hint != CREATE_PIXMAP_USAGE_LORIEBUFFER_BACKED)
if (width == 0 || height == 0)
return priv;

uint8_t type = pvfb->root.legacyDrawing ? LORIEBUFFER_REGULAR : LORIEBUFFER_AHARDWAREBUFFER;
uint8_t type = usage_hint != CREATE_PIXMAP_USAGE_LORIEBUFFER_BACKED ? LORIEBUFFER_REGULAR : pvfb->root.legacyDrawing ? LORIEBUFFER_FD : LORIEBUFFER_AHARDWAREBUFFER;
uint8_t format = pvfb->root.flip ? AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM : AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM;
priv->buffer = LorieBuffer_allocate(width, height, format, type);
LorieBuffer_Desc d = {0};
LorieBuffer_describe(priv->buffer, &d);
*new_fb_pitch = d.stride * 4;
*new_fb_pitch = LorieBuffer_description(priv->buffer)->stride * 4;

LorieBuffer_lock(priv->buffer, NULL, &priv->locked);
LorieBuffer_lock(priv->buffer, &priv->locked);
if (!priv->buffer) {
free(priv);
return NULL;
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/cpp/lorie/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ static int xcallback(int fd, int events, __unused void* data) {
}
case EVENT_SHARED_ROOT_WINDOW_BUFFER: {
static LorieBuffer* buffer = NULL;
LorieBuffer_Desc desc = {0};
const LorieBuffer_Desc* desc;
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);
desc = LorieBuffer_description(buffer);
log(INFO, "Received shared buffer width %d height %d format %d", desc->width, desc->height, desc->format);
rendererSetBuffer(buffer);
LorieBuffer_release(buffer);
break;
Expand Down Expand Up @@ -223,7 +223,7 @@ static void connect_(__unused JNIEnv* env, __unused jobject cls, jint fd) {
}
}

static jboolean connected(JNIEnv* env, jclass clazz) {
static jboolean connected(__unused JNIEnv* env,__unused jclass clazz) {
return conn_fd != -1;
}

Expand Down Expand Up @@ -360,15 +360,15 @@ static void sendTextEvent(JNIEnv *env, __unused jobject thiz, jbyteArray text) {
}
}

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

rendererSetWindow(win);
}

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, __unused void *reserved) {
JNIEnv* env;
static JNINativeMethod methods[] = {
{"nativeInit", "()V", (void *)&nativeInit},
Expand Down
Loading

0 comments on commit 500779a

Please sign in to comment.