Commit 22a9e1fd authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/kraxel/tags/queue/ui-pull-request' into staging



# gpg: Signature made Wed 21 Jun 2017 14:23:31 BST
# gpg:                using RSA key 0x4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/queue/ui-pull-request:
  ui: Remove inclusion of "hw/qdev.h"
  console: remove do_safe_dpy_refresh
  gtk: use framebuffer helper functions.
  sdl2: use framebuffer helper functions.
  egl-headless: use framebuffer helper functions.
  egl-helpers: add helpers to handle opengl framebuffers

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 84e3d072 95e92000
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -8,6 +8,21 @@
extern EGLDisplay *qemu_egl_display;
extern EGLConfig qemu_egl_config;

typedef struct egl_fb {
    int width;
    int height;
    GLuint texture;
    GLuint framebuffer;
    bool delete_texture;
} egl_fb;

void egl_fb_destroy(egl_fb *fb);
void egl_fb_setup_default(egl_fb *fb, int width, int height);
void egl_fb_create_for_tex(egl_fb *fb, int width, int height, GLuint texture);
void egl_fb_create_new_tex(egl_fb *fb, int width, int height);
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
void egl_fb_read(void *dst, egl_fb *src);

#ifdef CONFIG_OPENGL_DMABUF

extern int qemu_egl_rn_fd;
+2 −2
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ typedef struct VirtualGfxConsole {
    EGLSurface esurface;
    int glupdates;
    int x, y, w, h;
    GLuint tex_id;
    GLuint fbo_id;
    egl_fb guest_fb;
    egl_fb win_fb;
    bool y0_top;
    bool scanout_mode;
#endif
+6 −2
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@
#include <SDL.h>
#include <SDL_syswm.h>

#ifdef CONFIG_OPENGL
# include "ui/egl-helpers.h"
#endif

struct sdl2_console {
    DisplayChangeListener dcl;
    DisplaySurface *surface;
@@ -23,8 +27,8 @@ struct sdl2_console {
    SDL_GLContext winctx;
#ifdef CONFIG_OPENGL
    ConsoleGLState *gls;
    GLuint tex_id;
    GLuint fbo_id;
    egl_fb guest_fb;
    egl_fb win_fb;
    bool y0_top;
    bool scanout_mode;
#endif
+1 −24
Original line number Diff line number Diff line
@@ -1579,39 +1579,16 @@ bool dpy_gfx_check_format(QemuConsole *con,
    return true;
}

/*
 * Safe DPY refresh for TCG guests. We use the exclusive mechanism to
 * ensure the TCG vCPUs are quiescent so we can avoid races between
 * dirty page tracking for direct frame-buffer access by the guest.
 *
 * This is a temporary stopgap until we've fixed the dirty tracking
 * races in display adapters.
 */
static void do_safe_dpy_refresh(DisplayChangeListener *dcl)
{
    qemu_mutex_unlock_iothread();
    start_exclusive();
    qemu_mutex_lock_iothread();
    dcl->ops->dpy_refresh(dcl);
    qemu_mutex_unlock_iothread();
    end_exclusive();
    qemu_mutex_lock_iothread();
}

static void dpy_refresh(DisplayState *s)
{
    DisplayChangeListener *dcl;

    QLIST_FOREACH(dcl, &s->listeners, next) {
        if (dcl->ops->dpy_refresh) {
            if (tcg_enabled()) {
                do_safe_dpy_refresh(dcl);
            } else {
            dcl->ops->dpy_refresh(dcl);
        }
    }
}
}

void dpy_text_cursor(QemuConsole *con, int x, int y)
{
+18 −51
Original line number Diff line number Diff line
@@ -8,14 +8,13 @@
typedef struct egl_dpy {
    DisplayChangeListener dcl;
    DisplaySurface *ds;
    int width, height;
    GLuint texture;
    GLuint framebuffer;
    GLuint blit_texture;
    GLuint blit_framebuffer;
    egl_fb guest_fb;
    egl_fb blit_fb;
    bool y_0_top;
} egl_dpy;

/* ------------------------------------------------------------------ */

static void egl_refresh(DisplayChangeListener *dcl)
{
    graphic_hw_update(dcl->con);
@@ -38,8 +37,8 @@ static void egl_scanout_disable(DisplayChangeListener *dcl)
{
    egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);

    edpy->texture = 0;
    /* XXX: delete framebuffers here ??? */
    egl_fb_destroy(&edpy->guest_fb);
    egl_fb_destroy(&edpy->blit_fb);
}

static void egl_scanout_texture(DisplayChangeListener *dcl,
@@ -52,34 +51,17 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,
{
    egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);

    edpy->texture = backing_id;
    edpy->y_0_top = backing_y_0_top;

    /* source framebuffer */
    if (!edpy->framebuffer) {
        glGenFramebuffers(1, &edpy->framebuffer);
    }
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, edpy->framebuffer);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                              GL_TEXTURE_2D, edpy->texture, 0);
    egl_fb_create_for_tex(&edpy->guest_fb,
                          backing_width, backing_height, backing_id);

    /* dest framebuffer */
    if (!edpy->blit_framebuffer) {
        glGenFramebuffers(1, &edpy->blit_framebuffer);
        glGenTextures(1, &edpy->blit_texture);
        edpy->width = 0;
        edpy->height = 0;
    }
    if (edpy->width != backing_width || edpy->height != backing_height) {
        edpy->width   = backing_width;
        edpy->height  = backing_height;
        glBindTexture(GL_TEXTURE_2D, edpy->blit_texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                     edpy->width, edpy->height,
                     0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
        glBindFramebuffer(GL_FRAMEBUFFER_EXT, edpy->blit_framebuffer);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                  GL_TEXTURE_2D, edpy->blit_texture, 0);
    if (edpy->blit_fb.width  != backing_width ||
        edpy->blit_fb.height != backing_height) {
        egl_fb_destroy(&edpy->blit_fb);
        egl_fb_create_new_tex(&edpy->blit_fb, backing_width, backing_height);
    }
}

@@ -88,32 +70,17 @@ static void egl_scanout_flush(DisplayChangeListener *dcl,
                              uint32_t w, uint32_t h)
{
    egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
    GLuint y1, y2;

    if (!edpy->texture || !edpy->ds) {
    if (!edpy->guest_fb.texture || !edpy->ds) {
        return;
    }
    assert(surface_width(edpy->ds)  == edpy->width);
    assert(surface_height(edpy->ds) == edpy->height);
    assert(surface_width(edpy->ds)  == edpy->guest_fb.width);
    assert(surface_height(edpy->ds) == edpy->guest_fb.height);
    assert(surface_format(edpy->ds) == PIXMAN_x8r8g8b8);

    /* blit framebuffer, flip if needed */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, edpy->framebuffer);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, edpy->blit_framebuffer);
    glViewport(0, 0, edpy->width, edpy->height);
    y1 = edpy->y_0_top ? edpy->height : 0;
    y2 = edpy->y_0_top ? 0 : edpy->height;
    glBlitFramebuffer(0, y1, edpy->width, y2,
                      0, 0, edpy->width, edpy->height,
                      GL_COLOR_BUFFER_BIT, GL_NEAREST);

    /* read pixels to surface */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, edpy->blit_framebuffer);
    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
    glReadPixels(0, 0, edpy->width, edpy->height,
                 GL_BGRA, GL_UNSIGNED_BYTE, surface_data(edpy->ds));

    /* notify about updates */
    egl_fb_blit(&edpy->blit_fb, &edpy->guest_fb, edpy->y_0_top);
    egl_fb_read(surface_data(edpy->ds), &edpy->blit_fb);

    dpy_gfx_update(edpy->dcl.con, x, y, w, h);
}

Loading