diff --git a/app/.externalNativeBuild/ndkBuild/debug/armeabi-v7a/android_gradle_build_lorie_armeabi-v7a.stdout.txt b/app/.externalNativeBuild/ndkBuild/debug/armeabi-v7a/android_gradle_build_lorie_armeabi-v7a.stdout.txt index 8128a5d..7a51857 100644 --- a/app/.externalNativeBuild/ndkBuild/debug/armeabi-v7a/android_gradle_build_lorie_armeabi-v7a.stdout.txt +++ b/app/.externalNativeBuild/ndkBuild/debug/armeabi-v7a/android_gradle_build_lorie_armeabi-v7a.stdout.txt @@ -2,4 +2,5 @@ Android NDK: WARNING:/home/twaik/TermuxX11/app/src/main/jni/lorie/Android.mk:lor Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the Android NDK: current module -make: `/home/twaik/TermuxX11/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/liblorie.so' is up to date. +[armeabi-v7a] Compile++ thumb: lorie <= egl-helper.cpp +[armeabi-v7a] SharedLibrary : liblorie.so diff --git a/app/app.iml b/app/app.iml index f7ab6c7..168247a 100644 --- a/app/app.iml +++ b/app/app.iml @@ -33,13 +33,6 @@ - - - - - - - @@ -58,7 +51,6 @@ - @@ -66,7 +58,6 @@ - @@ -74,7 +65,6 @@ - @@ -82,7 +72,6 @@ - @@ -90,7 +79,6 @@ - @@ -98,10 +86,9 @@ - - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 43c8a61..5c0e5c5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,14 +20,12 @@ + android:exported="false"/> + android:process="com.termux.x11.separated"/> MAGIC_NUMBER)?View.VISIBLE:View.INVISIBLE; + softKbdVisible = (visibility == View.VISIBLE); if (getVisibility() == visibility) return; - if (visibility == View.VISIBLE) + if (softKbdVisible) setY(r.bottom - r.top - getHeight()); setVisibility(visibility); } diff --git a/app/src/main/java/com/termux/x11/LoriePreferences.java b/app/src/main/java/com/termux/x11/LoriePreferences.java index 2b9c93a..12cf26d 100644 --- a/app/src/main/java/com/termux/x11/LoriePreferences.java +++ b/app/src/main/java/com/termux/x11/LoriePreferences.java @@ -74,6 +74,7 @@ public class LoriePreferences extends AppCompatActivity implements SharedPrefere addPreferencesFromResource(R.xml.preferences); String showImeEnabled = Settings.Secure.getString(getActivity().getContentResolver(), SHOW_IME_WITH_HARD_KEYBOARD); + if (showImeEnabled == null) showImeEnabled = "0"; SharedPreferences.Editor p = getPreferenceManager().getSharedPreferences().edit(); p.putBoolean("showIMEWhileExternalConnected", showImeEnabled.equals("1")); p.apply(); diff --git a/app/src/main/java/com/termux/x11/LorieService.java b/app/src/main/java/com/termux/x11/LorieService.java index 98854ec..4e4486f 100644 --- a/app/src/main/java/com/termux/x11/LorieService.java +++ b/app/src/main/java/com/termux/x11/LorieService.java @@ -315,6 +315,7 @@ public class LorieService extends Service { svc.pointerButton(TouchParser.BTN_RIGHT, (e.getAction() == KeyEvent.ACTION_DOWN) ? TouchParser.ACTION_DOWN : TouchParser.ACTION_UP); rightPressed = (e.getAction() == KeyEvent.ACTION_DOWN); } else if (e.getAction() == KeyEvent.ACTION_UP) { + if (act.kbd!=null) act.kbd.requestFocus(); KeyboardUtils.toggleKeyboardVisibility(act); } return true; diff --git a/app/src/main/jni/lorie/backend/android/android-app.cpp b/app/src/main/jni/lorie/backend/android/android-app.cpp index 37fc776..409fe3a 100644 --- a/app/src/main/jni/lorie/backend/android/android-app.cpp +++ b/app/src/main/jni/lorie/backend/android/android-app.cpp @@ -26,6 +26,8 @@ public: void get_keymap(int *fd, int *size) override; void window_change_callback(EGLNativeWindowType win, uint32_t width, uint32_t height, uint32_t physical_width, uint32_t physical_height); void layout_change_callback(char *layout); + + void egl_after_init(); LorieEGLHelper helper; @@ -39,11 +41,19 @@ public: LorieBackendAndroid::LorieBackendAndroid() : self(&LorieCompositor::start, this) {} + + +void LorieBackendAndroid::egl_after_init() { + renderer.init(); +} + void LorieBackendAndroid::backend_init() { if (!helper.init(EGL_DEFAULT_DISPLAY)) { LOGE("Failed to initialize EGL context"); } + helper.onInit = std::bind(std::mem_fn(&LorieBackendAndroid::egl_after_init), this); + if (xkb_context == nullptr) { xkb_context = xkb_context_new((enum xkb_context_flags) 0); if (xkb_context == nullptr) { @@ -185,13 +195,9 @@ JNI_DECLARE(LorieService, windowChanged)(JNIEnv *env, jobject __unused instance, LorieBackendAndroid *b = fromLong(jcompositor); EGLNativeWindowType win = ANativeWindow_fromSurface(env, jsurface); - if (win == nullptr) { - LOGE("Surface is invalid"); - return; - } - - LOGV("JNI: window is changed: %p(%p) %dx%d (%dmm x %dmm)", win, jsurface, width, height, mmWidth, mmHeight); b->queue.call(&LorieBackendAndroid::window_change_callback, b, win, width, height, mmWidth, mmHeight); + + LOGV("JNI: window is changed: %p(%p) %dx%d (%dmm x %dmm)", win, jsurface, width, height, mmWidth, mmHeight); } extern "C" JNIEXPORT void JNICALL diff --git a/app/src/main/jni/lorie/backend/x11/x11.cpp b/app/src/main/jni/lorie/backend/x11/x11.cpp index 9ddbeb2..0590dbd 100644 --- a/app/src/main/jni/lorie/backend/x11/x11.cpp +++ b/app/src/main/jni/lorie/backend/x11/x11.cpp @@ -37,6 +37,9 @@ public: private: LorieEGLHelper helper; X11Window win; + + void onInit(); + void onUninit(); }; void Backtrace(); @@ -127,9 +130,21 @@ static void proc(int fd, uint32_t mask, void *data) { that->processEvents(); } +void LorieBackendX11::onInit() { + renderer.init(); +} + +void LorieBackendX11::onUninit() { + renderer.uninit(); +} + void LorieBackendX11::backend_init() { win.createWindow (WINDOW_WIDTH, WINDOW_HEIGHT); helper.init(win.x_dpy); + + helper.onInit = std::bind(std::mem_fn(&LorieBackendX11::onInit), this); + helper.onUninit = std::bind(std::mem_fn(&LorieBackendX11::onUninit), this); + helper.setWindow(win.window); renderer.resize(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/DPI*25.4, WINDOW_HEIGHT/DPI*25.4); diff --git a/app/src/main/jni/lorie/compositor.cpp b/app/src/main/jni/lorie/compositor.cpp index edcb4cc..f6976ea 100644 --- a/app/src/main/jni/lorie/compositor.cpp +++ b/app/src/main/jni/lorie/compositor.cpp @@ -28,8 +28,8 @@ wrapper(keyboard_keymap_changed), #undef wrapper renderer(*this), -toplevel(toplevel_surface), -cursor(cursor_surface), +toplevel(renderer.toplevel_surface), +cursor(renderer.cursor_surface), client_created_listener(*this) {} int proc(int fd, uint32_t mask, void *data) { @@ -57,7 +57,6 @@ void LorieCompositor::start() { wl_resource_t::global_create(display, this); backend_init(); - renderer.init(); wl_display_run(display); } @@ -81,18 +80,11 @@ void LorieCompositor::real_terminate() { } void LorieCompositor::set_toplevel(LorieSurface *surface) { - LOGV("Setting surface %p as toplevel", surface); - toplevel_surface = surface; - output_redraw(); + renderer.set_toplevel(surface); } void LorieCompositor::set_cursor(LorieSurface *surface, uint32_t hotspot_x, uint32_t hotspot_y) { - LOGV("Setting surface %p as cursor", surface); - cursor_surface = surface; - renderer.hotspot_x = hotspot_x; - renderer.hotspot_y = hotspot_y; - - output_redraw(); + renderer.set_cursor(surface, hotspot_x, hotspot_y); } void LorieCompositor::real_output_redraw() { diff --git a/app/src/main/jni/lorie/egl-helper.cpp b/app/src/main/jni/lorie/egl-helper.cpp index 3feca9f..e581559 100644 --- a/app/src/main/jni/lorie/egl-helper.cpp +++ b/app/src/main/jni/lorie/egl-helper.cpp @@ -1,5 +1,6 @@ #include #include +#include static char* eglGetErrorText(int code) { switch(eglGetError()) { @@ -78,7 +79,7 @@ bool LorieEGLHelper::init(EGLNativeDisplayType display) { return false; } - if (eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx) != EGL_TRUE) { + if (eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONFIG_KHR) != EGL_TRUE) { LOGE("LorieEGLHelper::init : eglMakeCurrent failed: %s", eglGetErrorText(eglGetError())); return false; } @@ -87,9 +88,10 @@ bool LorieEGLHelper::init(EGLNativeDisplayType display) { } bool LorieEGLHelper::setWindow(EGLNativeWindowType window) { + LOGV("Trying to use window %p", window); if (sfc != EGL_NO_SURFACE) { - if (eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx) != EGL_TRUE) { - LOGE("LorieEGLHelper::setWindow : eglMakeCurrent failed: %s", eglGetErrorText(eglGetError())); + if (eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) { + LOGE("LorieEGLHelper::setWindow : eglMakeCurrent (EGL_NO_SURFACE) failed: %s", eglGetErrorText(eglGetError())); return false; } if (eglDestroySurface(dpy, sfc) != EGL_TRUE) { @@ -97,20 +99,35 @@ bool LorieEGLHelper::setWindow(EGLNativeWindowType window) { return false; } }; + + sfc = EGL_NO_SURFACE; win = window; - if (win == EGL_NO_WINDOW) return true; + if (win == EGL_NO_WINDOW) { + if (onUninit != nullptr) onUninit(); + return true; + } sfc = eglCreateWindowSurface(dpy, cfg, win, NULL); if (sfc == EGL_NO_SURFACE) { LOGE("LorieEGLHelper::setWindow : eglCreateWindowSurface failed: %s", eglGetErrorText(eglGetError())); + if (onUninit != nullptr) onUninit(); return false; } if (eglMakeCurrent(dpy, sfc, sfc, ctx) != EGL_TRUE) { LOGE("LorieEGLHelper::setWindow : eglMakeCurrent failed: %s", eglGetErrorText(eglGetError())); + if (onUninit != nullptr) onUninit(); return false; } + + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + + swap(); + + if (onInit != nullptr) + onInit(); return true; } diff --git a/app/src/main/jni/lorie/include/LorieImpls.hpp b/app/src/main/jni/lorie/include/LorieImpls.hpp index 619e729..d84326d 100644 --- a/app/src/main/jni/lorie/include/LorieImpls.hpp +++ b/app/src/main/jni/lorie/include/LorieImpls.hpp @@ -40,8 +40,7 @@ class LorieSurface: public wl_surface_t { public: void on_destroy() override {}; void on_create() override {}; - - uint32_t width = 0, height = 0; + uint32_t x = 0, y = 0; LorieTexture texture; struct wl_resource *buffer = NULL; diff --git a/app/src/main/jni/lorie/include/lorie-compositor.hpp b/app/src/main/jni/lorie/include/lorie-compositor.hpp index ba87a9d..7e9855b 100644 --- a/app/src/main/jni/lorie/include/lorie-compositor.hpp +++ b/app/src/main/jni/lorie/include/lorie-compositor.hpp @@ -77,9 +77,6 @@ private: struct LorieClient* get_toplevel_client(); uint32_t next_serial(); - - LorieSurface* toplevel_surface = nullptr; - LorieSurface* cursor_surface = nullptr; struct { uint32_t depressed = 0, latched = 0, locked = 0, group = 0; diff --git a/app/src/main/jni/lorie/include/lorie-egl-helper.hpp b/app/src/main/jni/lorie/include/lorie-egl-helper.hpp index b5c4fa7..d2e7bca 100644 --- a/app/src/main/jni/lorie/include/lorie-egl-helper.hpp +++ b/app/src/main/jni/lorie/include/lorie-egl-helper.hpp @@ -1,5 +1,6 @@ #include #include +#include #if defined(__ANDROID__) #define EGL_NO_WINDOW nullptr @@ -15,6 +16,9 @@ public: EGLSurface sfc = EGL_NO_SURFACE; EGLContext ctx = EGL_NO_CONTEXT; EGLNativeWindowType win = EGL_NO_WINDOW; + + std::function onInit = nullptr; + std::function onUninit = nullptr; bool init(EGLNativeDisplayType display); bool setWindow(EGLNativeWindowType window); diff --git a/app/src/main/jni/lorie/include/lorie-renderer.hpp b/app/src/main/jni/lorie/include/lorie-renderer.hpp index b4b277e..e8bcd64 100644 --- a/app/src/main/jni/lorie/include/lorie-renderer.hpp +++ b/app/src/main/jni/lorie/include/lorie-renderer.hpp @@ -1,13 +1,16 @@ #pragma once #include #include +#include "LorieImpls.hpp" class LorieCompositor; +class LorieSurface; class LorieRenderer { public: LorieRenderer(LorieCompositor& compositor); void requestRedraw(); void init(); + void uninit(); uint32_t width = 1024; uint32_t height = 600; @@ -25,6 +28,12 @@ public: private: static void idleDraw(void *data); LorieCompositor& compositor; + + void set_toplevel(LorieSurface *surface); + void set_cursor(LorieSurface *surface, uint32_t hotspot_x, uint32_t hotspot_y); + + LorieSurface* toplevel_surface = nullptr; + LorieSurface* cursor_surface = nullptr; struct wl_event_source *idle = NULL; void drawCursor(); @@ -33,20 +42,25 @@ private: GLuint gvPos = 0; GLuint gvCoords = 0; GLuint gvTextureSamplerHandle = 0; + bool ready = false; friend class LorieTexture; + friend class LorieCompositor; }; class LorieTexture { private: LorieRenderer* r = nullptr; + bool damaged = false; public: LorieTexture(); uint32_t width, height; + void *data = nullptr; + void set_data(LorieRenderer* renderer, uint32_t width, uint32_t height, void *data); + void damage(int32_t x, int32_t y, int32_t width, int32_t height); void uninit(); - void reinit(LorieRenderer* renderer, uint32_t _width, uint32_t _height); + void reinit(); bool valid(); - void upload(void *data); private: GLuint id = UINT_MAX; void draw(float x0, float y0, float x1, float y1); diff --git a/app/src/main/jni/lorie/renderer.cpp b/app/src/main/jni/lorie/renderer.cpp index 98c10de..884b267 100644 --- a/app/src/main/jni/lorie/renderer.cpp +++ b/app/src/main/jni/lorie/renderer.cpp @@ -128,7 +128,8 @@ void LorieRenderer::init() { } gvPos = (GLuint) glGetAttribLocation(gTextureProgram, "position"); checkGlError("glGetAttribLocation"); gvCoords = (GLuint) glGetAttribLocation(gTextureProgram, "texCoords"); checkGlError("glGetAttribLocation"); - gvTextureSamplerHandle = (GLuint) glGetUniformLocation(gTextureProgram, "texture"); checkGlError("glGetAttribLocation"); + gvTextureSamplerHandle = (GLuint) glGetUniformLocation(gTextureProgram, "texture"); checkGlError("glGetAttribLocation"); + ready = true; redraw(); } @@ -176,6 +177,23 @@ void LorieRenderer::setCursorVisibility(bool visibility) { cursorVisible = visibility; } +void LorieRenderer::set_toplevel(LorieSurface *surface) { + LOGV("Setting surface %p as toplevel", surface); + if (toplevel_surface) toplevel_surface->texture.uninit(); + toplevel_surface = surface; + requestRedraw(); +} + +void LorieRenderer::set_cursor(LorieSurface *surface, uint32_t hotspot_x, uint32_t hotspot_y) { + LOGV("Setting surface %p as cursor", surface); + if (cursor_surface) cursor_surface->texture.uninit(); + cursor_surface = surface; + this->hotspot_x = hotspot_x; + this->hotspot_y = hotspot_y; + + requestRedraw(); +} + void LorieRenderer::idleDraw(void *data) { LorieRenderer* r = static_cast (data); @@ -183,17 +201,21 @@ void LorieRenderer::idleDraw(void *data) { } void LorieRenderer::drawCursor() { - if (compositor.toplevel == NULL || compositor.cursor == NULL || !compositor.cursor->texture.valid()) return; + if (toplevel_surface == NULL || cursor_surface == NULL) return; LorieTexture& toplevel = compositor.toplevel->texture; LorieTexture& cursor = compositor.cursor->texture; + + if (!cursor.valid()) cursor.reinit(); + if (!cursor.valid()) return; + float x, y, width, height, hs_x, hs_y; hs_x = ((float)hotspot_x)/toplevel.width*2; hs_y = ((float)hotspot_y)/toplevel.height*2; x = (((float)compositor.cursor->x)/toplevel.width)*2 - 1.0 - hs_x; y = (((float)compositor.cursor->y)/toplevel.height)*2 - 1.0 - hs_y; - width = 2*((float)compositor.cursor->width)/toplevel.width; - height = 2*((float)compositor.cursor->height)/toplevel.height; + width = 2*((float)cursor.width)/toplevel.width; + height = 2*((float)cursor.height)/toplevel.height; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); cursor.draw(x, y, x + width, y + height); @@ -203,13 +225,16 @@ void LorieRenderer::drawCursor() { void LorieRenderer::redraw() { //LOGV("Redrawing screen"); idle = NULL; + if (!ready) return; //#define RAND ((float)(rand()%256)/256) //glClearColor(RAND, RAND, RAND, 1.0); checkGlError("glClearColor"); glClearColor(0.f, 0.f, 0.f, 0.f); checkGlError("glClearColor"); glClear(GL_COLOR_BUFFER_BIT); checkGlError("glClear"); - - if (compositor.toplevel && compositor.toplevel->texture.valid()) { - compositor.toplevel->texture.draw(-1.0, -1.0, 1.0, 1.0); + + if (toplevel_surface) { + if (!toplevel_surface->texture.valid()) + toplevel_surface->texture.reinit(); + toplevel_surface->texture.draw(-1.0, -1.0, 1.0, 1.0); } if (cursorVisible) @@ -218,9 +243,19 @@ void LorieRenderer::redraw() { compositor.swap_buffers(); } -LorieRenderer::~LorieRenderer() { +void LorieRenderer::uninit() { + ready = false; + LOGV("Destroying renderer (tid %d)", ::gettid()); glUseProgram(0); glDeleteProgram(gTextureProgram); + gTextureProgram = gvPos = gvCoords = gvTextureSamplerHandle = 0; + + if (toplevel_surface) toplevel_surface->texture.uninit(); + if (cursor_surface) cursor_surface->texture.uninit(); +} + +LorieRenderer::~LorieRenderer() { + uninit(); } LorieTexture::LorieTexture(){ @@ -237,12 +272,17 @@ void LorieTexture::uninit() { r = nullptr; } -void LorieTexture::reinit(LorieRenderer* renderer, uint32_t _width, uint32_t _height) { - LOGV("Reinitializing texture to %dx%d", _width, _height); +void LorieTexture::set_data(LorieRenderer* renderer, uint32_t width, uint32_t height, void *data) { uninit(); - r = renderer; - width = _width; - height = _height; + LOGV("Reinitializing texture to %dx%d", width, height); + this->r = renderer; + this->width = width; + this->height = height; + this->data = data; + reinit(); +} + +void LorieTexture::reinit() { glClearColor(0.f, 0.f, 0.f, 0.f); checkGlError("glClearColor"); glClear(GL_COLOR_BUFFER_BIT); checkGlError("glClear"); @@ -257,18 +297,13 @@ void LorieTexture::reinit(LorieRenderer* renderer, uint32_t _width, uint32_t _he glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); checkGlError("glTexImage2D"); } -void LorieTexture::upload(void *data) { - if (!valid()) return; - - glActiveTexture(GL_TEXTURE0); checkGlError("glActiveTexture"); - glBindTexture(GL_TEXTURE_2D, id); checkGlError("glBindTexture"); - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - checkGlError("glTexSubImage2D"); +void LorieTexture::damage(int32_t x, int32_t y, int32_t width, int32_t height) { + damaged = true; + r->requestRedraw(); } bool LorieTexture::valid() { - return (id != UINT_MAX && r != nullptr); + return (width != 0 && height != 0 && id != UINT_MAX && r != nullptr); } void LorieTexture::draw(float x0, float y0, float x1, float y1) { @@ -284,6 +319,12 @@ void LorieTexture::draw(float x0, float y0, float x1, float y1) { glUseProgram(r->gTextureProgram); checkGlError("glUseProgram"); glBindTexture(GL_TEXTURE_2D, id); checkGlError("glBindTexture"); + if (damaged) { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); + checkGlError("glTexSubImage2D"); + damaged = false; + } + glVertexAttribPointer(r->gvPos, 3, GL_FLOAT, GL_FALSE, 20, coords); checkGlError("glVertexAttribPointer"); glVertexAttribPointer(r->gvCoords, 2, GL_FLOAT, GL_FALSE, 20, &coords[3]); checkGlError("glVertexAttribPointer"); glEnableVertexAttribArray(r->gvPos); checkGlError("glEnableVertexAttribArray"); diff --git a/app/src/main/jni/lorie/seat.cpp b/app/src/main/jni/lorie/seat.cpp index c21b160..6fda1c9 100644 --- a/app/src/main/jni/lorie/seat.cpp +++ b/app/src/main/jni/lorie/seat.cpp @@ -44,8 +44,8 @@ void LoriePointer::request_set_cursor(uint32_t serial, void LoriePointer::send_enter() { if (client == nullptr || (*client)->compositor.toplevel == nullptr) return; - wl_fixed_t x = wl_fixed_from_double ((*client)->compositor.toplevel->width/2); - wl_fixed_t y = wl_fixed_from_double ((*client)->compositor.toplevel->height/2); + wl_fixed_t x = wl_fixed_from_double ((*client)->compositor.toplevel->texture.width/2); + wl_fixed_t y = wl_fixed_from_double ((*client)->compositor.toplevel->texture.height/2); wl_pointer_t::send_enter(next_serial(), *(*client)->compositor.toplevel, x, y); } diff --git a/app/src/main/jni/lorie/surface.cpp b/app/src/main/jni/lorie/surface.cpp index 7289732..3adf89a 100644 --- a/app/src/main/jni/lorie/surface.cpp +++ b/app/src/main/jni/lorie/surface.cpp @@ -2,34 +2,27 @@ #include #include -void LorieSurface::request_attach(struct wl_resource *wl_buffer, int32_t x, int32_t y) { +void LorieSurface::request_attach(struct wl_resource *buffer, int32_t x, int32_t y) { if (client == nullptr) return; - buffer = wl_buffer; + LorieRenderer* renderer = &(*client)->compositor.renderer; + this->buffer = buffer; struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (buffer); if (shm_buffer == NULL) { - width = height = 0; + texture.set_data(renderer, 0, 0, nullptr); return; } - width = (uint32_t) wl_shm_buffer_get_width (shm_buffer); - height = (uint32_t) wl_shm_buffer_get_height (shm_buffer); - - if (width == 0 || height == 0) { - texture.uninit(); - return; - } + uint32_t width = (uint32_t) wl_shm_buffer_get_width (shm_buffer); + uint32_t height = (uint32_t) wl_shm_buffer_get_height (shm_buffer); + void *data = wl_shm_buffer_get_data(shm_buffer); - if (!texture.valid() || - texture.width != width || - texture.height != height) { - texture.reinit(&(*client)->compositor.renderer, width, height); - } + texture.set_data(renderer, width, height, data); } void LorieSurface::request_damage(int32_t x, int32_t y, int32_t width, int32_t height) { if (client == nullptr) return; - - (*client)->compositor.renderer.requestRedraw(); + + texture.damage(x, y, width, height); } void LorieSurface::request_frame(uint32_t callback) { @@ -37,15 +30,8 @@ void LorieSurface::request_frame(uint32_t callback) { } void LorieSurface::request_commit() { - if (!buffer) return; - struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (buffer); - if (texture.valid() && shm_buffer) { - void *data = wl_shm_buffer_get_data (shm_buffer); - if (data) { - texture.upload(data); - } - } - wl_buffer_send_release (buffer); + //if (!buffer) return; + //wl_buffer_send_release (buffer); if (frame_callback) { wl_callback_send_done (frame_callback, LorieUtils::timestamp());