提交 371c4ef6 编写于 作者: G Gerd Hoffmann

sdl2: use framebuffer helper functions.

Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
Message-id: 20170614084149.31314-4-kraxel@redhat.com
上级 d8dc67e1
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include <SDL.h> #include <SDL.h>
#include <SDL_syswm.h> #include <SDL_syswm.h>
#ifdef CONFIG_OPENGL
# include "ui/egl-helpers.h"
#endif
struct sdl2_console { struct sdl2_console {
DisplayChangeListener dcl; DisplayChangeListener dcl;
DisplaySurface *surface; DisplaySurface *surface;
...@@ -23,8 +27,8 @@ struct sdl2_console { ...@@ -23,8 +27,8 @@ struct sdl2_console {
SDL_GLContext winctx; SDL_GLContext winctx;
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
ConsoleGLState *gls; ConsoleGLState *gls;
GLuint tex_id; egl_fb guest_fb;
GLuint fbo_id; egl_fb win_fb;
bool y0_top; bool y0_top;
bool scanout_mode; bool scanout_mode;
#endif #endif
......
...@@ -42,14 +42,7 @@ static void sdl2_set_scanout_mode(struct sdl2_console *scon, bool scanout) ...@@ -42,14 +42,7 @@ static void sdl2_set_scanout_mode(struct sdl2_console *scon, bool scanout)
scon->scanout_mode = scanout; scon->scanout_mode = scanout;
if (!scon->scanout_mode) { if (!scon->scanout_mode) {
if (scon->fbo_id) { egl_fb_destroy(&scon->guest_fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, 0, 0);
glDeleteFramebuffers(1, &scon->fbo_id);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
scon->fbo_id = 0;
}
if (scon->surface) { if (scon->surface) {
surface_gl_destroy_texture(scon->gls, scon->surface); surface_gl_destroy_texture(scon->gls, scon->surface);
surface_gl_create_texture(scon->gls, scon->surface); surface_gl_create_texture(scon->gls, scon->surface);
...@@ -191,7 +184,6 @@ void sdl2_gl_scanout_disable(DisplayChangeListener *dcl) ...@@ -191,7 +184,6 @@ void sdl2_gl_scanout_disable(DisplayChangeListener *dcl)
assert(scon->opengl); assert(scon->opengl);
scon->w = 0; scon->w = 0;
scon->h = 0; scon->h = 0;
scon->tex_id = 0;
sdl2_set_scanout_mode(scon, false); sdl2_set_scanout_mode(scon, false);
} }
...@@ -210,48 +202,34 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl, ...@@ -210,48 +202,34 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
scon->y = y; scon->y = y;
scon->w = w; scon->w = w;
scon->h = h; scon->h = h;
scon->tex_id = backing_id;
scon->y0_top = backing_y_0_top; scon->y0_top = backing_y_0_top;
SDL_GL_MakeCurrent(scon->real_window, scon->winctx); SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
sdl2_set_scanout_mode(scon, true); sdl2_set_scanout_mode(scon, true);
if (!scon->fbo_id) { egl_fb_create_for_tex(&scon->guest_fb, backing_width, backing_height,
glGenFramebuffers(1, &scon->fbo_id); backing_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, void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
uint32_t x, uint32_t y, uint32_t w, uint32_t h) uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{ {
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
int ww, wh, y1, y2; int ww, wh;
assert(scon->opengl); assert(scon->opengl);
if (!scon->scanout_mode) { if (!scon->scanout_mode) {
return; return;
} }
if (!scon->fbo_id) { if (!scon->guest_fb.framebuffer) {
return; return;
} }
SDL_GL_MakeCurrent(scon->real_window, scon->winctx); 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); SDL_GetWindowSize(scon->real_window, &ww, &wh);
glViewport(0, 0, ww, wh); egl_fb_setup_default(&scon->win_fb, ww, wh);
y1 = scon->y0_top ? 0 : scon->h; egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top);
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); SDL_GL_SwapWindow(scon->real_window);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册