progress
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 19 Jun 2024 08:03:54 +0000 (10:03 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 19 Jun 2024 08:03:54 +0000 (10:03 +0200)
Change-Id: I1799be6c34df1d318bda0a4a9b7aa3b243b2dcd5

tizen/src/ui/Makefile.objs
tizen/src/ui/displayglwidget.cpp
tizen/src/ui/qt5.c
tizen/src/ui/qt5_supplement.cpp
ui/sdl2-gl.c

index 479b3f7a917ee49ec3faee3cc84ae83bc3461b1d..8c8feecc8c24cefc99961eb2b22645bb6084902c 100644 (file)
@@ -35,8 +35,6 @@ $(obj)/moc_displayglwidget.cpp: $(obj)/displayglwidget.h
        moc $< -o $@
 $(obj)/moc_displayswwidget.cpp: $(obj)/displayswwidget.h
        moc $< -o $@
-$(obj)/moc_displayqemuglwidget.cpp: $(obj)/displayqemuglwidget.h
-       moc $< -o $@
 $(obj)/moc_mainwindow.cpp: $(obj)/mainwindow.h
        moc $< -o $@
 $(obj)/moc_skinkeyitem.cpp: $(obj)/skinkeyitem.h
index 3cd6523462136780e83cfdec3c82c8152ba6d296..e6af18541f296f98138cc5f5d7fd044c15a13446 100644 (file)
@@ -522,7 +522,6 @@ void DisplayGLWidget::paintGL()
     textureListMutex.unlock();
 
     if (current) {
-        fprintf(stderr, "will show %d\n", current->tex);
         drawQuad(current->tex, false);
     }
 
index 90027843778addf7b42f52902d41f652fcf27dc8..931c5a6ce2e88169fc829f8c5bf3aada98e93b6d 100644 (file)
@@ -60,6 +60,10 @@ static struct qt5_state {
     bool updated;
     ConsoleGLState *gls;
     QEMUGLContext ctx;
+    bool is_scanout;
+    uint32_t scanout_fbs[2];
+    bool backing_y_0_top;
+    uint32_t backing_width, backing_height;
 #endif
 } *qt5_console;
 
@@ -121,11 +125,13 @@ static void qt5_gl_update(DisplayChangeListener *dcl,
                        int x, int y, int w, int h)
 {
     struct qt5_state *con = container_of(dcl, struct qt5_state, dcl);
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
+
+    if (con->is_scanout)
+        return;
+
     if (con->ctx)
         qt5_gl_make_context_current_internal(con->ctx);
     surface_gl_update_texture(con->gls, con->surface, x, y, w, h);
-    fprintf(stderr, "rendered %d\n", con->surface->texture);
     con->updated = true;
 }
 
@@ -133,7 +139,7 @@ static void qt5_gl_switch(DisplayChangeListener *dcl,
                        DisplaySurface *new_surface)
 {
     struct qt5_state *con = container_of(dcl, struct qt5_state, dcl);
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
+
     if (con->ctx)
         qt5_gl_make_context_current_internal(con->ctx);
 
@@ -155,24 +161,22 @@ static void qt5_gl_switch(DisplayChangeListener *dcl,
 
     con->surface = new_surface;
     con->gen += 1;
+    // TODO: con->is_scanout?
     surface_gl_create_texture(con->gls, con->surface);
-    fprintf(stderr, "created %d\n", con->surface->texture);
 }
 
 static void qt5_gl_refresh(DisplayChangeListener *dcl)
 {
     struct qt5_state *con = container_of(dcl, struct qt5_state, dcl);
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
+
     if (con->ctx)
         qt5_gl_make_context_current_internal(con->ctx);
 
     graphic_hw_update(dcl->con);
-    if (con->surface && con->updated) {
-        fprintf(stderr, "sending %d\n", con->surface->texture);
+    if (con->surface && !con->is_scanout && con->updated) {
         con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen);
         if (con->surface->texture == 0) {
             surface_gl_create_texture(con->gls, con->surface);
-            fprintf(stderr, "created %d\n", con->surface->texture);
         }
         con->updated = false;
     }
@@ -196,20 +200,17 @@ static QEMUGLContext qt5_gl_create_context(DisplayChangeListener *dcl,
 
 static void qt5_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
 {
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
     qt5_gl_destroy_context_internal(ctx);
 }
 
 static int qt5_gl_make_context_current(DisplayChangeListener *dcl,
                                  QEMUGLContext ctx)
 {
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
     qt5_gl_make_context_current_internal(ctx);
 }
 
 static QEMUGLContext qt5_gl_get_current_context(DisplayChangeListener *dcl)
 {
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
     return qt5_gl_get_current_context_internal();
 }
 
@@ -220,7 +221,29 @@ static void qt5_gl_scanout(DisplayChangeListener *dcl,
                      uint32_t w, uint32_t h)
 {
     struct qt5_state *con = container_of(dcl, struct qt5_state, dcl);
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
+
+    if (backing_id == 0) {
+        con->is_scanout = false;
+        return;
+    }
+    con->is_scanout = true;
+
+    if (con->ctx)
+        qt5_gl_make_context_current_internal(con->ctx);
+
+    con->backing_y_0_top = backing_y_0_top;
+    con->backing_width = backing_width;
+    con->backing_height = backing_height;
+
+    if (con->scanout_fbs[0] == 0) {
+        // TODO: these leak?
+        glGenFramebuffers(2, con->scanout_fbs);
+    }
+
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, con->scanout_fbs[0]);
+    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, con->scanout_fbs[1]);
+    glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,
+                              GL_TEXTURE_2D, backing_id, 0);
 
 }
 
@@ -228,8 +251,23 @@ static void qt5_gl_scanout_flush(DisplayChangeListener *dcl,
                            uint32_t x, uint32_t y, uint32_t w, uint32_t h)
 {
     struct qt5_state *con = container_of(dcl, struct qt5_state, dcl);
-    fprintf(stderr, "in %s %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);
 
+    if (con->ctx)
+        qt5_gl_make_context_current_internal(con->ctx);
+
+    glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,
+                              GL_TEXTURE_2D, con->surface->texture, 0);
+
+    uint32_t y1 = con->backing_y_0_top ? con->backing_height : 0;
+    uint32_t y2 = con->backing_y_0_top ? 0 : con->backing_height;
+    glBlitFramebuffer(0, y1, con->backing_width, y2,
+                      0, 0, surface_width(con->surface), surface_height(con->surface),
+                      GL_COLOR_BUFFER_BIT, GL_NEAREST);
+
+    con->surface->texture = qt5_gl_refresh_internal(con->surface->texture, surface_width(con->surface), surface_height(con->surface), con->gen);
+    if (con->surface->texture == 0) {
+        surface_gl_create_texture(con->gls, con->surface);
+    }
 }
 
 static const DisplayChangeListenerOps dcl_ops = {
@@ -341,15 +379,17 @@ void maru_qt5_display_init(DisplayState *ds, int full_screen)
     qt5_console = g_new0(struct qt5_state, qt5_num_outputs);
     for (i = 0; i < qt5_num_outputs; i++) {
         QemuConsole *con = qemu_console_lookup_by_index(i);
-        fprintf(stderr, "opengl is %d\n", display_opengl);
         qt5_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_ops;
         qt5_console[i].dcl.con = con;
         register_displaychangelistener(&qt5_console[i].dcl);
         qt5_console[i].idx = i;
+
         qt5_console[i].gen = 0;
         qt5_console[i].updated = false;
         qt5_console[i].gls = NULL;
         qt5_console[i].ctx = qt5_gl_create_context_internal(3, 3);
+        qt5_console[i].is_scanout = false;
+        qt5_console[i].scanout_fbs[0] = 0;
     }
 
     if (full_screen) {
index 375f7af086ba02d36585ef6e672514b086a7f150..fb450fd1c5318f9d5d23ea40349d66e97d0bb318 100644 (file)
@@ -626,7 +626,7 @@ uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height,
             qemu_mutex_lock(&item->mutex);
             bool ok = dpy_item_gen[item_id] == 0 || item->available;
             if (ok) {
-                if (dpy_item_gen[item_id] == gen) {
+                if (dpy_item_gen[item_id] == gen && /* HACK HACK HACK */ item->tex >= 25) {
                     ret = item->tex;
                 } else {
                     // TODO: we will leak a texture soon!
index 2e812ba0cac11c20c30a39bc2d12e249e7717132..039645df3e6e44dd2647f22dd0993f02944bf5e2 100644 (file)
@@ -191,59 +191,59 @@ void sdl2_gl_scanout(DisplayChangeListener *dcl,
                      uint32_t w, uint32_t h)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
-    //
-    // assert(scon->opengl);
-    // scon->x = x;
-    // scon->y = y;
-    // scon->w = w;
-    // scon->h = h;
-    // scon->tex_id = backing_id;
-    // scon->y0_top = backing_y_0_top;
-    //
-    // SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
-    //
-    // if (scon->tex_id == 0 || scon->w == 0 || scon->h == 0) {
-    //     sdl2_set_scanout_mode(scon, false);
-    //     return;
-    // }
-    //
-    // sdl2_set_scanout_mode(scon, true);
-    // if (!scon->fbo_id) {
-    //     glGenFramebuffers(1, &scon->fbo_id);
-    // }
-    //
-    // glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
-    // glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
-    //                           GL_TEXTURE_2D, scon->tex_id, 0);
+
+    assert(scon->opengl);
+    scon->x = x;
+    scon->y = y;
+    scon->w = w;
+    scon->h = h;
+    scon->tex_id = backing_id;
+    scon->y0_top = backing_y_0_top;
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+
+    if (scon->tex_id == 0 || scon->w == 0 || scon->h == 0) {
+        sdl2_set_scanout_mode(scon, false);
+        return;
+    }
+
+    sdl2_set_scanout_mode(scon, true);
+    if (!scon->fbo_id) {
+        glGenFramebuffers(1, &scon->fbo_id);
+    }
+
+    glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
+    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+                              GL_TEXTURE_2D, scon->tex_id, 0);
 }
 
 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
                            uint32_t x, uint32_t y, uint32_t w, uint32_t h)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
-    // int ww, wh, y1, y2;
-    //
-    // assert(scon->opengl);
-    // if (!scon->scanout_mode) {
-    //     return;
-    // }
-    // if (!scon->fbo_id) {
-    //     return;
-    // }
-    //
-    // SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
-    //
-    // glBindFramebuffer(GL_READ_FRAMEBUFFER, scon->fbo_id);
-    // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-    //
-    // SDL_GetWindowSize(scon->real_window, &ww, &wh);
-    // glViewport(0, 0, ww, wh);
-    // y1 = scon->y0_top ? 0 : scon->h;
-    // y2 = scon->y0_top ? scon->h : 0;
-    // glBlitFramebuffer(0, y1, scon->w, y2,
-    //                   0, 0, ww, wh,
-    //                   GL_COLOR_BUFFER_BIT, GL_NEAREST);
-    // glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
-    //
-    // SDL_GL_SwapWindow(scon->real_window);
+    int ww, wh, y1, y2;
+
+    assert(scon->opengl);
+    if (!scon->scanout_mode) {
+        return;
+    }
+    if (!scon->fbo_id) {
+        return;
+    }
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, scon->fbo_id);
+    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+
+    SDL_GetWindowSize(scon->real_window, &ww, &wh);
+    glViewport(0, 0, ww, wh);
+    y1 = scon->y0_top ? 0 : scon->h;
+    y2 = scon->y0_top ? scon->h : 0;
+    glBlitFramebuffer(0, y1, scon->w, y2,
+                      0, 0, ww, wh,
+                      GL_COLOR_BUFFER_BIT, GL_NEAREST);
+    glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
+
+    SDL_GL_SwapWindow(scon->real_window);
 }