Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/egl.c | 29 +++++++++++++++++++++++++++++ server/egl.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/server/egl.c b/server/egl.c index 9bfa413..b791c95 100644 --- a/server/egl.c +++ b/server/egl.c @@ -64,6 +64,35 @@ void *egl_own_context(void *egl_display, void *egl_context) return ectx; } +static EGLContext egl_context = EGL_NO_CONTEXT; + +void *get_texture_raw_data(RedGlTexture *texture, size_t *data_size) +{ + if (egl_context == EGL_NO_CONTEXT) { + EGLBoolean b; + b = eglMakeCurrent(texture->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, texture->egl_context); + spice_assert(b != EGL_FALSE); + } + + glBindTexture(GL_TEXTURE_2D, texture->tex_id); + GLint w = 0, h = 0; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); + if (w == 0 || h == 0) + return NULL; + size_t tex_size = w * h * 4; + uint8_t *data = spice_malloc(tex_size); + glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, data); + if (w > texture->width) { + int y; + for (y = 1; y < texture->height; ++y) + memmove(data + texture->width * 4 * y, data + w * 4 * y, texture->width * 4); + tex_size = texture->width * texture->height * 4; + } + *data_size = tex_size; + return data; +} + int egl_get_fd_for_texture(void *egl_display, void *egl_context, uint32_t tex_id, uint32_t *stride, uint32_t *fourcc) diff --git a/server/egl.h b/server/egl.h index 6360a8a..cb3f92c 100644 --- a/server/egl.h +++ b/server/egl.h @@ -18,6 +18,9 @@ #ifndef EGL_H_ #define EGL_H_ +#include "red-qxl.h" + +void *get_texture_raw_data(RedGlTexture *texture, size_t *data_size); int egl_get_fd_for_texture(void *egl_display, void *egl_context, uint32_t tex_id, uint32_t *stride, uint32_t *fourcc); -- 2.7.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel