From: Max Reitz <mreitz@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Subject: Re: [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl.
Date: Thu, 15 Jan 2015 17:14:48 -0500 [thread overview]
Message-ID: <54B83BD8.9020600@redhat.com> (raw)
In-Reply-To: <1421066126-25737-4-git-send-email-kraxel@redhat.com>
On 2015-01-12 at 07:35, Gerd Hoffmann wrote:
> Add new sdl2-gl.c file, with display
> rendering functions using opengl.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> include/ui/console.h | 1 +
> include/ui/sdl2.h | 10 +++++
> ui/Makefile.objs | 4 ++
> ui/sdl.c | 11 +++++
> ui/sdl2-2d.c | 7 ++++
> ui/sdl2-gl.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++
> ui/sdl2.c | 67 ++++++++++++++++++++++++++----
> vl.c | 11 +++++
> 8 files changed, 218 insertions(+), 7 deletions(-)
> create mode 100644 ui/sdl2-gl.c
>
> diff --git a/include/ui/console.h b/include/ui/console.h
> index 5cb169c..7496dee 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -344,6 +344,7 @@ void surface_gl_setup_viewport(DisplaySurface *surface,
> #endif
>
> /* sdl.c */
> +void sdl_display_early_init(int opengl);
> void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
>
> /* cocoa.m */
> diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
> index f56c596..5c962da 100644
> --- a/include/ui/sdl2.h
> +++ b/include/ui/sdl2.h
> @@ -11,6 +11,9 @@ struct sdl2_console {
> int last_vm_running; /* per console for caption reasons */
> int x, y;
> int hidden;
> + int opengl;
> + int updates;
> + SDL_GLContext winctx;
> };
>
> void sdl2_window_create(struct sdl2_console *scon);
> @@ -29,4 +32,11 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
> void sdl2_2d_refresh(DisplayChangeListener *dcl);
> void sdl2_2d_redraw(struct sdl2_console *scon);
>
> +void sdl2_gl_update(DisplayChangeListener *dcl,
> + int x, int y, int w, int h);
> +void sdl2_gl_switch(DisplayChangeListener *dcl,
> + DisplaySurface *new_surface);
> +void sdl2_gl_refresh(DisplayChangeListener *dcl);
> +void sdl2_gl_redraw(struct sdl2_console *scon);
> +
> #endif /* SDL2_H */
> diff --git a/ui/Makefile.objs b/ui/Makefile.objs
> index 3173778..c1f4299 100644
> --- a/ui/Makefile.objs
> +++ b/ui/Makefile.objs
> @@ -21,6 +21,10 @@ sdl.mo-objs := sdl.o sdl_zoom.o
> endif
> ifeq ($(CONFIG_SDLABI),2.0)
> sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
> +ifeq ($(CONFIG_OPENGL),y)
> +sdl.mo-objs += sdl2-gl.o
> +libs_softmmu += $(OPENGL_LIBS)
> +endif
> endif
> sdl.mo-cflags := $(SDL_CFLAGS)
>
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 3e9d810..1fe002d 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -873,6 +873,17 @@ static const DisplayChangeListenerOps dcl_ops = {
> .dpy_cursor_define = sdl_mouse_define,
> };
>
> +void sdl_display_early_init(int opengl)
> +{
> + if (opengl == 1 /* on */) {
> + fprintf(stderr,
> + "SDL1 display code has no opengl support.\n"
> + "Please recompile qemu with SDL2, using\n"
> + "./configure --enable-sdl --with-sdlabi=2.0\n");
> + exit(1);
> + }
> +}
> +
> void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
> {
> int flags;
> diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
> index 9264817..85f1be4 100644
> --- a/ui/sdl2-2d.c
> +++ b/ui/sdl2-2d.c
> @@ -42,6 +42,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
> DisplaySurface *surf = qemu_console_surface(dcl->con);
> SDL_Rect rect;
>
> + assert(!scon->opengl);
> +
> if (!surf) {
> return;
> }
> @@ -67,6 +69,8 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
> DisplaySurface *old_surface = scon->surface;
> int format = 0;
>
> + assert(!scon->opengl);
> +
> scon->surface = new_surface;
>
> if (scon->texture) {
> @@ -107,12 +111,15 @@ void sdl2_2d_refresh(DisplayChangeListener *dcl)
> {
> struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
>
> + assert(!scon->opengl);
> graphic_hw_update(dcl->con);
> sdl2_poll_events(scon);
> }
>
> void sdl2_2d_redraw(struct sdl2_console *scon)
> {
> + assert(!scon->opengl);
> +
> if (!scon->surface) {
> return;
> }
> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
> new file mode 100644
> index 0000000..b8620ca
> --- /dev/null
> +++ b/ui/sdl2-gl.c
> @@ -0,0 +1,114 @@
> +/*
> + * QEMU SDL display driver
> + *
> + * Copyright (c) 2003 Fabrice Bellard
Just as mentioned by Paolo on patch 2, this may be supposed to mention
you instead.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
And this line seems wrong.
> +
> +/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
> +#undef WIN32_LEAN_AND_MEAN
> +
> +#include <SDL.h>
> +#include <SDL_syswm.h>
> +#include <SDL_opengl.h>
> +
> +#include "qemu-common.h"
> +#include "ui/console.h"
> +#include "ui/input.h"
> +#include "ui/sdl2.h"
> +#include "sysemu/sysemu.h"
> +
> +static void sdl2_gl_render_surface(struct sdl2_console *scon)
> +{
> + int ww, wh;
> +
> + SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> +
> + SDL_GetWindowSize(scon->real_window, &ww, &wh);
> + surface_gl_setup_viewport(scon->surface, ww, wh);
> +
> + surface_gl_render_texture(scon->surface);
> + SDL_GL_SwapWindow(scon->real_window);
> +}
> +
> +void sdl2_gl_update(DisplayChangeListener *dcl,
> + int x, int y, int w, int h)
> +{
> + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
> +
> + assert(scon->opengl);
> +
> + SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> + surface_gl_update_texture(scon->surface, x, y, w, h);
> + scon->updates++;
> +}
> +
> +void sdl2_gl_switch(DisplayChangeListener *dcl,
> + DisplaySurface *new_surface)
> +{
> + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
> + DisplaySurface *old_surface = scon->surface;
> +
> + assert(scon->opengl);
> +
> + SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> + surface_gl_destroy_texture(scon->surface);
Can a surface be in use by multiple DCLs? If so, this would probably
need reference counting.
> +
> + scon->surface = new_surface;
> +
> + if (!new_surface) {
> + sdl2_window_destroy(scon);
> + return;
> + }
> +
> + if (!scon->real_window) {
> + sdl2_window_create(scon);
> + } else if (old_surface &&
> + ((surface_width(old_surface) != surface_width(new_surface)) ||
> + (surface_height(old_surface) != surface_height(new_surface)))) {
> + sdl2_window_resize(scon);
Hm, now that I think about it... If the window is scaled, this will
reset the scaling to 100 %. Fine, why not. However, if the new surface
has the same dimensions as the old surface, the window will not be
scaled. That would seem strange to me.
Apart from this and the question about surfaces used by multiple DCLs at
the same time, the patch looks good to me (the option parsing in
select_display() in vl.c looks like nightmare fuel, but it's just in
line with its environment).
Max
next prev parent reply other threads:[~2015-01-15 22:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
2015-01-12 12:55 ` Paolo Bonzini
2015-01-12 13:11 ` Gerd Hoffmann
2015-01-15 19:55 ` Max Reitz
2015-01-16 9:11 ` Gerd Hoffmann
2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
2015-01-12 13:04 ` Paolo Bonzini
2015-01-12 13:13 ` Gerd Hoffmann
2015-01-15 20:46 ` Max Reitz
2015-01-16 9:21 ` Gerd Hoffmann
2015-01-16 15:05 ` Max Reitz
2015-01-12 12:35 ` [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl Gerd Hoffmann
2015-01-15 22:14 ` Max Reitz [this message]
2015-01-12 12:35 ` [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h Gerd Hoffmann
2015-01-15 22:21 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54B83BD8.9020600@redhat.com \
--to=mreitz@redhat.com \
--cc=aliguori@amazon.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).