Commit 0dff23d6 authored by Zhigang Gong's avatar Zhigang Gong

glamor: Don't direct call to any gl functions.

Create a new structure glamor_gl_dispatch to hold all the
gl function's pointer and initialize them at run time ,
rather than use them directly. To do this is to avoid
symbol conflicts.
Signed-off-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent 7daf9af0
......@@ -43,4 +43,5 @@ libglamor_la_SOURCES = \
glamor_pixmap.c\
glamor_picture.c\
glamor_window.c\
glamor_gl_dispatch.c\
glamor.h
......@@ -59,7 +59,7 @@ glamor_get_drawable_pixmap(DrawablePtr drawable)
return (PixmapPtr)drawable;
}
static void
void
glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex)
{
ScreenPtr screen = pixmap->drawable.pScreen;
......@@ -111,6 +111,7 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
int type = GLAMOR_PIXMAP_TEXTURE;
glamor_pixmap_private *pixmap_priv;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (w > 32767 || h > 32767)
return NullPixmap;
......@@ -141,6 +142,7 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
pixmap_priv = glamor_get_pixmap_private(pixmap);
pixmap_priv->container = pixmap;
pixmap_priv->glamor_priv = glamor_priv;
if (w == 0 || h == 0 || type == GLAMOR_PIXMAP_MEMORY)
return pixmap;
......@@ -160,11 +162,11 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
}
/* Create the texture used to store the pixmap's data. */
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
dispatch->glGenTextures(1, &tex);
dispatch->glBindTexture(GL_TEXTURE_2D, tex);
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
dispatch->glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
format, GL_UNSIGNED_BYTE, NULL);
glamor_set_pixmap_texture(pixmap, w, h, tex);
......@@ -210,14 +212,16 @@ glamor_create_screen_pixmap(ScreenPtr screen, int w, int h, int depth,
static Bool
glamor_destroy_pixmap(PixmapPtr pixmap)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (pixmap->refcnt == 1) {
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
if (pixmap_priv->fb)
glDeleteFramebuffers(1, &pixmap_priv->fb);
dispatch->glDeleteFramebuffers(1, &pixmap_priv->fb);
if (pixmap_priv->tex)
glDeleteTextures(1, &pixmap_priv->tex);
dispatch->glDeleteTextures(1, &pixmap_priv->tex);
if (pixmap_priv->pbo)
glDeleteBuffers(1, &pixmap_priv->pbo);
dispatch->glDeleteBuffers(1, &pixmap_priv->pbo);
dixFreePrivates(pixmap->devPrivates, PRIVATE_PIXMAP);
}
......@@ -227,7 +231,8 @@ glamor_destroy_pixmap(PixmapPtr pixmap)
static void
glamor_block_handler(void *data, OSTimePtr timeout, void *last_select_mask)
{
glFlush();
glamor_gl_dispatch *dispatch = data;
dispatch->glFlush();
}
static void
......@@ -295,6 +300,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
goto fail;
}
glamor_gl_dispatch_init(screen, &glamor_priv->dispatch, gl_version);
#ifdef GLAMOR_GLES2
if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
......@@ -305,11 +311,11 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_priv->has_pack_invert = glamor_gl_has_extension("GL_MESA_pack_invert");
glamor_priv->has_fbo_blit = glamor_gl_has_extension("GL_EXT_framebuffer_blit");
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size);
glamor_priv->dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size);
if (!RegisterBlockAndWakeupHandlers(glamor_block_handler,
glamor_wakeup_handler,
NULL)) {
(void*)&glamor_priv->dispatch)) {
goto fail;
}
......
......@@ -52,10 +52,12 @@ extern _X_EXPORT Bool glamor_init(ScreenPtr screen, unsigned int flags);
extern _X_EXPORT void glamor_fini(ScreenPtr screen);
extern _X_EXPORT void glamor_set_screen_pixmap_texture(ScreenPtr screen, int w, int h, unsigned int tex);
extern _X_EXPORT Bool glamor_glyphs_init (ScreenPtr pScreen);
void glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex);
#ifdef GLAMOR_FOR_XORG
extern _X_EXPORT Bool glamor_egl_init(ScrnInfoPtr scrn, int fd);
extern _X_EXPORT Bool glamor_create_egl_screen_image(ScreenPtr screen, int handle, int stride);
extern _X_EXPORT Bool glamor_create_egl_pixmap_image(PixmapPtr pixmap, int handle, int stride);
extern _X_EXPORT Bool glamor_close_egl_screen(ScreenPtr screen);
extern _X_EXPORT void glamor_free_egl_screen(int scrnIndex, int flags);
#endif
......@@ -46,6 +46,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
glamor_pixmap_private *src_pixmap_priv;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
if (!glamor_priv->has_fbo_blit) {
......@@ -78,14 +79,14 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
}
glamor_validate_pixmap(dst_pixmap);
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->fb);
dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->fb);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
src_y_off += dy;
for (i = 0; i < nbox; i++) {
if(glamor_priv->yInverted) {
glBlitFramebuffer((box[i].x1 + dx + src_x_off),
dispatch->glBlitFramebuffer((box[i].x1 + dx + src_x_off),
(box[i].y1 + src_y_off),
(box[i].x2 + dx + src_x_off),
(box[i].y2 + src_y_off),
......@@ -101,7 +102,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
int flip_src_y1 = src_pixmap->drawable.height - (box[i].y2 + src_y_off);
int flip_src_y2 = src_pixmap->drawable.height - (box[i].y1 + src_y_off);
glBlitFramebuffer(box[i].x1 + dx + src_x_off,
dispatch->glBlitFramebuffer(box[i].x1 + dx + src_x_off,
flip_src_y1,
box[i].x2 + dx + src_x_off,
flip_src_y2,
......@@ -129,6 +130,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
{
glamor_screen_private *glamor_priv =
glamor_get_screen_private(dst->pScreen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
int i;
......@@ -162,7 +164,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
flush_needed = 1;
if (gc) {
glamor_set_alu(gc->alu);
glamor_set_alu(dispatch, gc->alu);
if (!glamor_set_planemask(dst_pixmap, gc->planemask))
goto fail;
if (gc->alu != GXcopy) {
......@@ -181,10 +183,10 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE,
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE,
2 * sizeof(float),
vertices);
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
if (GLAMOR_PIXMAP_PRIV_NO_PENDING(src_pixmap_priv)) {
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
......@@ -192,25 +194,25 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
dy += src_y_off;
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->tex);
dispatch->glActiveTexture(GL_TEXTURE0);
dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->tex);
#ifndef GLAMOR_GLES2
glEnable(GL_TEXTURE_2D);
dispatch->glEnable(GL_TEXTURE_2D);
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE,
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE,
2 * sizeof(float),
texcoords);
glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
glUseProgram(glamor_priv->finish_access_prog[0]);
glUniform1i(glamor_priv->finish_access_no_revert[0], 1);
glUniform1i(glamor_priv->finish_access_swap_rb[0], 0);
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
dispatch->glUseProgram(glamor_priv->finish_access_prog[0]);
dispatch->glUniform1i(glamor_priv->finish_access_no_revert[0], 1);
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0], 0);
}
else {
GLAMOR_CHECK_PENDING_FILL(glamor_priv, src_pixmap_priv);
GLAMOR_CHECK_PENDING_FILL(dispatch, glamor_priv, src_pixmap_priv);
}
for (i = 0; i < nbox; i++) {
......@@ -230,24 +232,24 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
glamor_priv->yInverted,
texcoords);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
if (GLAMOR_PIXMAP_PRIV_NO_PENDING(src_pixmap_priv)) {
glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
#ifndef GLAMOR_GLES2
glDisable(GL_TEXTURE_2D);
dispatch->glDisable(GL_TEXTURE_2D);
#endif
}
glUseProgram(0);
dispatch->glUseProgram(0);
/* The source texture is bound to a fbo, we have to flush it here. */
if (flush_needed)
glFlush();
dispatch->glFlush();
return TRUE;
fail:
glamor_set_alu(GXcopy);
glamor_set_alu(dispatch, GXcopy);
glamor_set_planemask(dst_pixmap, ~0);
return FALSE;
}
......
......@@ -54,49 +54,24 @@ glamor_get_drawable_location(const DrawablePtr drawable)
return 'f';
}
void
glamor_get_transform_uniform_locations(GLint prog,
glamor_transform_uniforms *uniform_locations)
{
uniform_locations->x_bias = glGetUniformLocation(prog, "x_bias");
uniform_locations->x_scale = glGetUniformLocation(prog, "x_scale");
uniform_locations->y_bias = glGetUniformLocation(prog, "y_bias");
uniform_locations->y_scale = glGetUniformLocation(prog, "y_scale");
}
/* We don't use a full matrix for our transformations because it's
* wasteful when all we want is to rescale to NDC and possibly do a flip
* if it's the front buffer.
*/
void
glamor_set_transform_for_pixmap(PixmapPtr pixmap,
glamor_transform_uniforms *uniform_locations)
{
glUniform1f(uniform_locations->x_bias, -pixmap->drawable.width / 2.0f);
glUniform1f(uniform_locations->x_scale, 2.0f / pixmap->drawable.width);
glUniform1f(uniform_locations->y_bias, -pixmap->drawable.height / 2.0f);
glUniform1f(uniform_locations->y_scale, -2.0f / pixmap->drawable.height);
}
GLint
glamor_compile_glsl_prog(GLenum type, const char *source)
glamor_compile_glsl_prog(glamor_gl_dispatch *dispatch, GLenum type, const char *source)
{
GLint ok;
GLint prog;
prog = glCreateShader(type);
glShaderSource(prog, 1, (const GLchar **)&source, NULL);
glCompileShader(prog);
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
prog = dispatch->glCreateShader(type);
dispatch->glShaderSource(prog, 1, (const GLchar **)&source, NULL);
dispatch->glCompileShader(prog);
dispatch->glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
dispatch->glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetShaderInfoLog(prog, size, NULL, info);
dispatch->glGetShaderInfoLog(prog, size, NULL, info);
ErrorF("Failed to compile %s: %s\n",
type == GL_FRAGMENT_SHADER ? "FS" : "VS",
info);
......@@ -108,20 +83,20 @@ glamor_compile_glsl_prog(GLenum type, const char *source)
}
void
glamor_link_glsl_prog(GLint prog)
glamor_link_glsl_prog(glamor_gl_dispatch *dispatch, GLint prog)
{
GLint ok;
glLinkProgram(prog);
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
dispatch->glLinkProgram(prog);
dispatch->glGetProgramiv(prog, GL_LINK_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
dispatch->glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetProgramInfoLog(prog, size, NULL, info);
dispatch->glGetProgramInfoLog(prog, size, NULL, info);
ErrorF("Failed to link: %s\n",
info);
FatalError("GLSL link failure\n");
......@@ -140,6 +115,7 @@ void
glamor_init_finish_access_shaders(ScreenPtr screen)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
const char *vs_source =
"attribute vec4 v_position;\n"
"attribute vec4 v_texcoord0;\n"
......@@ -200,51 +176,51 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
GLint fs_prog, vs_prog, avs_prog, set_alpha_prog;
GLint sampler_uniform_location;
glamor_priv->finish_access_prog[0] = glCreateProgram();
glamor_priv->finish_access_prog[1] = glCreateProgram();
glamor_priv->finish_access_prog[0] = dispatch->glCreateProgram();
glamor_priv->finish_access_prog[1] = dispatch->glCreateProgram();
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source);
glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
glAttachShader(glamor_priv->finish_access_prog[0], fs_prog);
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, vs_source);
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, fs_source);
dispatch->glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
dispatch->glAttachShader(glamor_priv->finish_access_prog[0], fs_prog);
avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
set_alpha_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, set_alpha_source);
glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
glAttachShader(glamor_priv->finish_access_prog[1], set_alpha_prog);
avs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, vs_source);
set_alpha_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, set_alpha_source);
dispatch->glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
dispatch->glAttachShader(glamor_priv->finish_access_prog[1], set_alpha_prog);
glBindAttribLocation(glamor_priv->finish_access_prog[0], GLAMOR_VERTEX_POS, "v_position");
glBindAttribLocation(glamor_priv->finish_access_prog[0], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(glamor_priv->finish_access_prog[0]);
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[0], GLAMOR_VERTEX_POS, "v_position");
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[0], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(dispatch, glamor_priv->finish_access_prog[0]);
glBindAttribLocation(glamor_priv->finish_access_prog[1], GLAMOR_VERTEX_POS, "v_position");
glBindAttribLocation(glamor_priv->finish_access_prog[1], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(glamor_priv->finish_access_prog[1]);
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[1], GLAMOR_VERTEX_POS, "v_position");
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[1], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(dispatch, glamor_priv->finish_access_prog[1]);
glamor_priv->finish_access_no_revert[0] =
glGetUniformLocation(glamor_priv->finish_access_prog[0], "no_revert");
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[0], "no_revert");
glamor_priv->finish_access_swap_rb[0] =
glGetUniformLocation(glamor_priv->finish_access_prog[0], "swap_rb");
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[0], "swap_rb");
sampler_uniform_location =
glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
glUseProgram(glamor_priv->finish_access_prog[0]);
glUniform1i(sampler_uniform_location, 0);
glUniform1i(glamor_priv->finish_access_no_revert[0],1);
glUniform1i(glamor_priv->finish_access_swap_rb[0],0);
glUseProgram(0);
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
dispatch->glUseProgram(glamor_priv->finish_access_prog[0]);
dispatch->glUniform1i(sampler_uniform_location, 0);
dispatch->glUniform1i(glamor_priv->finish_access_no_revert[0],1);
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0],0);
dispatch->glUseProgram(0);
glamor_priv->finish_access_no_revert[1] =
glGetUniformLocation(glamor_priv->finish_access_prog[1], "no_revert");
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], "no_revert");
glamor_priv->finish_access_swap_rb[1] =
glGetUniformLocation(glamor_priv->finish_access_prog[1], "swap_rb");
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], "swap_rb");
sampler_uniform_location =
glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler");
glUseProgram(glamor_priv->finish_access_prog[1]);
glUniform1i(glamor_priv->finish_access_no_revert[1],1);
glUniform1i(sampler_uniform_location, 0);
glUniform1i(glamor_priv->finish_access_swap_rb[1],0);
glUseProgram(0);
dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler");
dispatch->glUseProgram(glamor_priv->finish_access_prog[1]);
dispatch->glUniform1i(glamor_priv->finish_access_no_revert[1],1);
dispatch->glUniform1i(sampler_uniform_location, 0);
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[1],0);
dispatch->glUseProgram(0);
}
......@@ -254,6 +230,7 @@ glamor_finish_access(DrawablePtr drawable)
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv = glamor_get_screen_private(drawable->pScreen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
return;
......@@ -264,10 +241,10 @@ glamor_finish_access(DrawablePtr drawable)
if (pixmap_priv->pbo != 0 && pixmap_priv->pbo_valid) {
assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
glBindBuffer (GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
dispatch->glBindBuffer (GL_PIXEL_PACK_BUFFER, 0);
dispatch->glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
pixmap_priv->pbo_valid = FALSE;
glDeleteBuffers(1, &pixmap_priv->pbo);
dispatch->glDeleteBuffers(1, &pixmap_priv->pbo);
pixmap_priv->pbo = 0;
} else {
free(pixmap->devPrivate.ptr);
......
......@@ -54,6 +54,7 @@
#define GLAMOR_FOR_XORG
#include <glamor.h>
#include <glamor_gl_dispatch.h>
#define GLAMOR_VERSION_MAJOR 0
#define GLAMOR_VERSION_MINOR 1
......@@ -84,6 +85,7 @@ struct glamor_screen_private {
PFNEGLEXPORTDRMIMAGEMESA egl_export_drm_image_mesa;
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes;
struct glamor_gl_dispatch *dispatch;
};
int xf86GlamorEGLPrivateIndex = -1;
......@@ -127,10 +129,10 @@ _glamor_create_egl_screen_image(ScrnInfoPtr scrn, int width, int height, int str
if (image == EGL_NO_IMAGE_KHR)
return FALSE;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glamor->dispatch->glGenTextures(1, &texture);
glamor->dispatch->glBindTexture(GL_TEXTURE_2D, texture);
glamor->dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glamor->dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
(glamor->egl_image_target_texture2d_oes)(GL_TEXTURE_2D, image);
......@@ -296,3 +298,14 @@ glamor_free_egl_screen(int scrnIndex, int flags)
free(glamor);
}
}
Bool
glamor_gl_dispatch_init(ScreenPtr screen, struct glamor_gl_dispatch *dispatch, int gl_version)
{
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_screen_private *glamor_egl = glamor_get_egl_screen_private(scrn);
if (!glamor_gl_dispatch_init_impl(dispatch, gl_version, eglGetProcAddress))
return FALSE;
glamor_egl->dispatch = dispatch;
return TRUE;
}
......@@ -105,6 +105,7 @@ void
glamor_init_solid_shader(ScreenPtr screen)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
const char *solid_vs =
"attribute vec4 v_position;"
"void main()\n"
......@@ -120,17 +121,17 @@ glamor_init_solid_shader(ScreenPtr screen)
"}\n";
GLint fs_prog, vs_prog;
glamor_priv->solid_prog = glCreateProgram();
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, solid_vs);
fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, solid_fs);
glAttachShader(glamor_priv->solid_prog, vs_prog);
glAttachShader(glamor_priv->solid_prog, fs_prog);
glamor_priv->solid_prog = dispatch->glCreateProgram();
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, solid_vs);
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, solid_fs);
dispatch->glAttachShader(glamor_priv->solid_prog, vs_prog);
dispatch->glAttachShader(glamor_priv->solid_prog, fs_prog);
glBindAttribLocation(glamor_priv->solid_prog, GLAMOR_VERTEX_POS, "v_position");
glamor_link_glsl_prog(glamor_priv->solid_prog);
dispatch->glBindAttribLocation(glamor_priv->solid_prog, GLAMOR_VERTEX_POS, "v_position");
glamor_link_glsl_prog(dispatch, glamor_priv->solid_prog);
glamor_priv->solid_color_uniform_location =
glGetUniformLocation(glamor_priv->solid_prog, "color");
dispatch->glGetUniformLocation(glamor_priv->solid_prog, "color");
}
Bool
......@@ -140,6 +141,7 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
ScreenPtr screen = pixmap->drawable.pScreen;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
int x1 = x;
int x2 = x + width;
int y1 = y;
......@@ -151,7 +153,7 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
glamor_fallback("dest %p has no fbo.\n", pixmap);
goto fail;
}
glamor_set_alu(alu);
glamor_set_alu(dispatch, alu);
if (!glamor_set_planemask(pixmap, planemask)) {
glamor_fallback("Failedto set planemask in glamor_solid.\n");
goto fail;
......@@ -178,24 +180,24 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
glamor_set_destination_pixmap_priv_nc(pixmap_priv);
glamor_validate_pixmap(pixmap);
glUseProgram(glamor_priv->solid_prog);
dispatch->glUseProgram(glamor_priv->solid_prog);
glUniform4fv(glamor_priv->solid_color_uniform_location, 1, color);
dispatch->glUniform4fv(glamor_priv->solid_color_uniform_location, 1, color);
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE,
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE,
2 * sizeof(float), vertices);
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
pixmap_priv_get_scale(pixmap_priv, &xscale, &yscale);
glamor_set_normalize_vcoords(xscale, yscale, x1, y1, x2, y2,
glamor_priv->yInverted,
vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
glUseProgram(0);
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
dispatch->glUseProgram(0);
return TRUE;
fail:
glamor_set_alu(GXcopy);
glamor_set_alu(dispatch, GXcopy);
glamor_set_planemask(pixmap, ~0);
return FALSE;
}
......
......@@ -44,6 +44,7 @@ glamor_get_spans(DrawablePtr drawable,
int no_alpha, no_revert;
glamor_screen_private *glamor_priv = glamor_get_screen_private(drawable->pScreen);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
PixmapPtr temp_pixmap = NULL;
int i;
uint8_t *readpixels_dst = (uint8_t *)dst;
......@@ -79,14 +80,14 @@ glamor_get_spans(DrawablePtr drawable,
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
for (i = 0; i < count; i++) {
if (glamor_priv->yInverted) {
glReadPixels(points[i].x + x_off,
dispatch->glReadPixels(points[i].x + x_off,
(points[i].y + y_off),
widths[i],
1,
format, type,
readpixels_dst);
} else {
glReadPixels(points[i].x + x_off,
dispatch->glReadPixels(points[i].x + x_off,
pixmap->drawable.height - 1 - (points[i].y + y_off),
widths[i],
1,
......
#include "glamor_priv.h"
#define INIT_FUNC(dst,func_name,get) \
dst->func_name = get(#func_name); \
if (dst->func_name == NULL) \
{ ErrorF("Failed to get fun %s", #func_name); \
goto fail; }
Bool
glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch,
int gl_version,
void *(*get_proc_address)(const char*))
{
INIT_FUNC(dispatch, glMatrixMode, get_proc_address);
INIT_FUNC(dispatch, glLoadIdentity, get_proc_address);
INIT_FUNC(dispatch, glViewport, get_proc_address);
INIT_FUNC(dispatch, glRasterPos2i, get_proc_address);
INIT_FUNC(dispatch, glDrawArrays, get_proc_address);
INIT_FUNC(dispatch, glReadPixels, get_proc_address);
INIT_FUNC(dispatch, glDrawPixels, get_proc_address);
INIT_FUNC(dispatch, glPixelStorei, get_proc_address);
INIT_FUNC(dispatch, glTexParameteri, get_proc_address);
INIT_FUNC(dispatch, glTexImage2D, get_proc_address);
INIT_FUNC(dispatch, glGenTextures, get_proc_address);
INIT_FUNC(dispatch, glDeleteTextures, get_proc_address);
INIT_FUNC(dispatch, glBindTexture, get_proc_address);
INIT_FUNC(dispatch, glTexSubImage2D, get_proc_address);
INIT_FUNC(dispatch, glFlush, get_proc_address);
INIT_FUNC(dispatch, glGetIntegerv, get_proc_address);
INIT_FUNC(dispatch, glGetString, get_proc_address);
INIT_FUNC(dispatch, glScissor, get_proc_address);
INIT_FUNC(dispatch, glEnable, get_proc_address);
INIT_FUNC(dispatch, glDisable, get_proc_address);
INIT_FUNC(dispatch, glBlendFunc, get_proc_address);
INIT_FUNC(dispatch, glLogicOp, get_proc_address);
INIT_FUNC(dispatch, glActiveTexture, get_proc_address);
INIT_FUNC(dispatch, glGenBuffers, get_proc_address);
INIT_FUNC(dispatch, glBufferData, get_proc_address);