diff options
author | marha <marha@users.sourceforge.net> | 2014-03-04 12:18:13 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2014-03-04 12:23:48 +0100 |
commit | 45392e4a0642880b569ea5d4a350cdc395a2c7db (patch) | |
tree | c3c2a49de903a18c3f8e1bf79684c29337ebcf7c /xorg-server/glamor | |
parent | 5ec0616d4e3c4c6095f4975abbe9c21e5b6af967 (diff) | |
parent | 321c01267ae1c446f1bd22b642567fcafa016c02 (diff) | |
download | vcxsrv-45392e4a0642880b569ea5d4a350cdc395a2c7db.tar.gz vcxsrv-45392e4a0642880b569ea5d4a350cdc395a2c7db.tar.bz2 vcxsrv-45392e4a0642880b569ea5d4a350cdc395a2c7db.zip |
Merge remote-tracking branch 'origin/released'
* origin/released:
libX11 libxcb mesa xserver xcb-proto xkeyboard-config git update 4 Mar 2014
Conflicts:
mesalib/src/mapi/glapi/glapi.h
mesalib/src/mapi/glapi/glthread.c
mesalib/src/mesa/drivers/dri/common/dri_util.c
mesalib/src/mesa/main/bufferobj.c
xorg-server/dix/dispatch.c
xorg-server/hw/xwin/glx/gen_gl_wrappers.py
xorg-server/hw/xwin/winmultiwindowwm.c
Diffstat (limited to 'xorg-server/glamor')
25 files changed, 1524 insertions, 2072 deletions
diff --git a/xorg-server/glamor/Makefile.am b/xorg-server/glamor/Makefile.am index 3fe25304d..12a57c441 100644 --- a/xorg-server/glamor/Makefile.am +++ b/xorg-server/glamor/Makefile.am @@ -6,15 +6,15 @@ AM_CFLAGS = $(CWARNFLAGS) $(DIX_CFLAGS) $(GLAMOR_CFLAGS) libglamor_la_SOURCES = \ glamor.c \ + glamor_context.h \ glamor_copyarea.c \ glamor_copywindow.c \ glamor_core.c \ glamor_debug.h \ - glamor_gl_dispatch.h \ glamor_fill.c \ glamor_fillspans.c \ glamor_getspans.c \ - glamor_glext.h \ + glamor_glx.c \ glamor_glyphs.c \ glamor_polyfillrect.c \ glamor_polylines.c \ @@ -35,7 +35,6 @@ libglamor_la_SOURCES = \ glamor_largepixmap.c\ glamor_picture.c\ glamor_window.c\ - glamor_gl_dispatch.c\ glamor_fbo.c\ glamor_compositerects.c\ glamor_xv.c\ diff --git a/xorg-server/glamor/glamor.c b/xorg-server/glamor/glamor.c index feb110a66..7d8228cdd 100644 --- a/xorg-server/glamor/glamor.c +++ b/xorg-server/glamor/glamor.c @@ -95,7 +95,7 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex) glamor_destroy_fbo(fbo); } - gl_iformat_for_depth(pixmap->drawable.depth, &format); + format = gl_iformat_for_pixmap(pixmap); fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap->drawable.width, pixmap->drawable.height, format, tex, 0); @@ -162,7 +162,7 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, pixmap_priv->base.pixmap = pixmap; pixmap_priv->base.glamor_priv = glamor_priv; - gl_iformat_for_depth(depth, &format); + format = gl_iformat_for_pixmap(pixmap); pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3; screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL); @@ -218,13 +218,12 @@ void glamor_block_handler(ScreenPtr screen) { glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); glamor_priv->tick++; - dispatch->glFlush(); + glFlush(); glamor_fbo_expire(glamor_priv); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); if (glamor_priv->state == RENDER_STATE && glamor_priv->render_idle_cnt++ > RENDER_IDEL_MAX) { glamor_priv->state = IDLE_STATE; @@ -236,10 +235,10 @@ static void _glamor_block_handler(void *data, OSTimePtr timeout, void *last_select_mask) { glamor_screen_private *glamor_priv = data; - glamor_gl_dispatch *dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glFlush(); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glFlush(); + glamor_put_context(glamor_priv); } static void @@ -281,10 +280,10 @@ glamor_init(ScreenPtr screen, unsigned int flags) return FALSE; if (flags & GLAMOR_INVERTED_Y_AXIS) { - glamor_priv->yInverted = 1; + glamor_priv->yInverted = TRUE; } else - glamor_priv->yInverted = 0; + glamor_priv->yInverted = FALSE; if (!dixRegisterPrivateKey(glamor_screen_private_key, PRIVATE_SCREEN, 0)) { LogMessage(X_WARNING, @@ -302,50 +301,49 @@ glamor_init(ScreenPtr screen, unsigned int flags) goto fail;; } - gl_version = glamor_gl_get_version(); + if (epoxy_is_desktop_gl()) + glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP; + else + glamor_priv->gl_flavor = GLAMOR_GL_ES2; -#ifndef GLAMOR_GLES2 - if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) { - ErrorF("Require OpenGL version 1.3 or latter.\n"); - goto fail; - } -#else - if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) { - ErrorF("Require Open GLES2.0 or latter.\n"); - goto fail; - } -#endif + gl_version = glamor_gl_get_version(); - glamor_gl_dispatch_init(screen, &glamor_priv->_dispatch, gl_version); + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) { + ErrorF("Require OpenGL version 1.3 or later.\n"); + goto fail; + } + } else { + if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) { + ErrorF("Require Open GLES2.0 or later.\n"); + goto fail; + } -#ifdef GLAMOR_GLES2 - if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) { - ErrorF("GL_EXT_texture_format_BGRA8888 required\n"); - goto fail; + if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) { + ErrorF("GL_EXT_texture_format_BGRA8888 required\n"); + goto fail; + } } -#endif 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"); - glamor_priv->_dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, - &glamor_priv->max_fbo_size); + glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size); #ifdef MAX_FBO_SIZE glamor_priv->max_fbo_size = MAX_FBO_SIZE; #endif glamor_set_debug_level(&glamor_debug_level); -#ifdef GLAMOR_GLES2 - glamor_priv->gl_flavor = GLAMOR_GL_ES2; -#else - glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP; -#endif /* If we are using egl screen, call egl screen init to * register correct close screen function. */ - if (flags & GLAMOR_USE_EGL_SCREEN) - glamor_egl_screen_init(screen); + if (flags & GLAMOR_USE_EGL_SCREEN) { + glamor_egl_screen_init(screen, &glamor_priv->ctx); + } else { + if (!glamor_glx_screen_init(&glamor_priv->ctx)) + goto fail; + } glamor_priv->saved_procs.close_screen = screen->CloseScreen; screen->CloseScreen = glamor_close_screen; diff --git a/xorg-server/glamor/glamor.h b/xorg-server/glamor/glamor.h index 05f565b12..eec687256 100644 --- a/xorg-server/glamor/glamor.h +++ b/xorg-server/glamor/glamor.h @@ -36,6 +36,8 @@ #include <fb.h> #include <fbpict.h> +struct glamor_context; + /* * glamor_pixmap_type : glamor pixmap's type. * @MEMORY: pixmap is in memory. @@ -142,11 +144,6 @@ extern _X_EXPORT void glamor_block_handler(ScreenPtr screen); extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, unsigned int usage); -extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen); - -extern _X_EXPORT void glamor_egl_make_current(ScreenPtr screen); -extern _X_EXPORT void glamor_egl_restore_context(ScreenPtr screen); - /* @glamor_egl_exchange_buffers: Exchange the underlying buffers(KHR image,fbo). * * @front: front pixmap. diff --git a/xorg-server/glamor/glamor_context.h b/xorg-server/glamor/glamor_context.h new file mode 100644 index 000000000..8781afc48 --- /dev/null +++ b/xorg-server/glamor/glamor_context.h @@ -0,0 +1,56 @@ +/* + * Copyright © 2013 Intel Corporation + * + * 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 (including the next + * paragraph) 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. + */ + +/** + * @file glamor_context.h + * + * This is the struct of state required for context switching in + * glamor. It has to use types that don't require including either + * server headers or Xlib headers, since it will be included by both + * the server and the GLX (xlib) code. + */ + +struct glamor_context { + /** Either an EGLDisplay or an Xlib Display */ + void *display; + + /** Either a GLXContext or an EGLContext. */ + void *ctx; + + /** The EGLSurface we should MakeCurrent to */ + void *drawable; + + /** The GLXDrawable we should MakeCurrent to */ + uint32_t drawable_xid; + + /** + * Count of how deep in glamor_get_context() we are, to reduce + * MakeCurrent calls. + */ + int get_count; + + void (*get_context)(struct glamor_context *glamor_ctx); + void (*put_context)(struct glamor_context *glamor_ctx); +}; + +Bool glamor_glx_screen_init(struct glamor_context *glamor_ctx); diff --git a/xorg-server/glamor/glamor_copyarea.c b/xorg-server/glamor/glamor_copyarea.c index 2735ba0bc..d6bcacd36 100644 --- a/xorg-server/glamor/glamor_copyarea.c +++ b/xorg-server/glamor/glamor_copyarea.c @@ -31,7 +31,6 @@ * * GC CopyArea implementation */ -#ifndef GLAMOR_GLES2 static Bool glamor_copy_n_to_n_fbo_blit(DrawablePtr src, DrawablePtr dst, @@ -42,7 +41,6 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src); glamor_pixmap_private *src_pixmap_priv, *dst_pixmap_priv; glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; int dst_x_off, dst_y_off, src_x_off, src_y_off, i; int fbo_x_off, fbo_y_off; int src_fbo_x_off, src_fbo_y_off; @@ -72,9 +70,8 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, pixmap_priv_get_fbo_off(dst_pixmap_priv, &fbo_x_off, &fbo_y_off); pixmap_priv_get_fbo_off(src_pixmap_priv, &src_fbo_x_off, &src_fbo_y_off); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, - src_pixmap_priv->base.fbo->fb); + glamor_get_context(glamor_priv); + glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->base.fbo->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); dst_x_off += fbo_x_off; @@ -84,23 +81,15 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, for (i = 0; i < nbox; i++) { if (glamor_priv->yInverted) { - 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), - (box[i].x1 + - dst_x_off), - (box[i].y1 + - dst_y_off), - (box[i].x2 + - dst_x_off), - (box[i].y2 + - dst_y_off), - GL_COLOR_BUFFER_BIT, GL_NEAREST); + 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, + box[i].x1 + dst_x_off, + box[i].y1 + dst_y_off, + box[i].x2 + dst_x_off, + box[i].y2 + dst_y_off, + GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { int flip_dst_y1 = @@ -112,26 +101,21 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, int flip_src_y2 = src_pixmap->drawable.height - (box[i].y1 + src_y_off); - dispatch->glBlitFramebuffer(box[i].x1 + dx + - src_x_off, - flip_src_y1, - box[i].x2 + dx + - src_x_off, - flip_src_y2, - box[i].x1 + - dst_x_off, - flip_dst_y1, - box[i].x2 + - dst_x_off, - flip_dst_y2, - GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBlitFramebuffer(box[i].x1 + dx + src_x_off, + flip_src_y1, + box[i].x2 + dx + src_x_off, + flip_src_y2, + box[i].x1 + dst_x_off, + flip_dst_y1, + box[i].x2 + dst_x_off, + flip_dst_y2, + GL_COLOR_BUFFER_BIT, GL_NEAREST); } } - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); glamor_priv->state = BLIT_STATE; return TRUE; } -#endif static Bool glamor_copy_n_to_n_textured(DrawablePtr src, @@ -140,7 +124,6 @@ glamor_copy_n_to_n_textured(DrawablePtr src, { glamor_screen_private *glamor_priv = glamor_get_screen_private(dst->pScreen); - glamor_gl_dispatch *dispatch; PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src); PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst); int i; @@ -172,37 +155,32 @@ glamor_copy_n_to_n_textured(DrawablePtr src, glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), vertices); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off); dx += src_x_off; dy += src_y_off; - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex); -#ifndef GLAMOR_GLES2 - dispatch->glEnable(GL_TEXTURE_2D); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); -#endif - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, - GL_FLOAT, GL_FALSE, - 2 * sizeof(float), texcoords); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(glamor_priv->finish_access_prog[0]); - dispatch->glUniform1i(glamor_priv->finish_access_revert[0], REVERT_NONE); - dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0], - SWAP_NONE_UPLOADING); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex); + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + 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_revert[0], REVERT_NONE); + glUniform1i(glamor_priv->finish_access_swap_rb[0], SWAP_NONE_UPLOADING); for (i = 0; i < nbox; i++) { @@ -222,17 +200,14 @@ glamor_copy_n_to_n_textured(DrawablePtr src, box[i].x2 + dx, box[i].y2 + dy, glamor_priv->yInverted, texcoords); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); -#ifndef GLAMOR_GLES2 - dispatch->glDisable(GL_TEXTURE_2D); -#endif - dispatch->glUseProgram(0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); /* The source texture is bound to a fbo, we have to flush it here. */ - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; return TRUE; @@ -289,15 +264,14 @@ __glamor_copy_n_to_n(DrawablePtr src, box[0].x1, box[0].y1, box[0].x2 - box[0].x1, box[0].y2 - box[0].y1, dx, dy, src_pixmap, dst_pixmap); -#ifndef GLAMOR_GLES2 - if (!overlaped && + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP && + !overlaped && (glamor_priv->state != RENDER_STATE || !src_pixmap_priv->base.gl_tex || !dst_pixmap_priv->base.gl_tex) && glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) { ret = TRUE; goto done; } -#endif glamor_calculate_boxes_bound(&bound, box, nbox); /* Overlaped indicate the src and dst are the same pixmap. */ @@ -364,10 +338,10 @@ _glamor_copy_n_to_n(DrawablePtr src, Bool upsidedown, Pixel bitplane, void *closure, Bool fallback) { + ScreenPtr screen = dst->pScreen; PixmapPtr dst_pixmap, src_pixmap; glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv; glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; BoxPtr extent; RegionRec region; int src_x_off, src_y_off, dst_x_off, dst_y_off; @@ -381,7 +355,7 @@ _glamor_copy_n_to_n(DrawablePtr src, src_pixmap = glamor_get_drawable_pixmap(src); src_pixmap_priv = glamor_get_pixmap_private(src_pixmap); - glamor_priv = glamor_get_screen_private(dst->pScreen); + glamor_priv = glamor_get_screen_private(screen); DEBUGF("Copy %d %d %dx%d dx %d dy %d from %p to %p \n", box[0].x1, box[0].y1, @@ -394,12 +368,12 @@ _glamor_copy_n_to_n(DrawablePtr src, if (gc) { if (!glamor_set_planemask(dst_pixmap, gc->planemask)) goto fall_back; - dispatch = glamor_get_dispatch(glamor_priv); - if (!glamor_set_alu(dispatch, gc->alu)) { - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + if (!glamor_set_alu(screen, gc->alu)) { + glamor_put_context(glamor_priv); goto fail; } - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } if (!src_pixmap_priv) { @@ -572,9 +546,9 @@ _glamor_copy_n_to_n(DrawablePtr src, } fail: - dispatch = glamor_get_dispatch(glamor_priv); - glamor_set_alu(dispatch, GXcopy); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glamor_set_alu(screen, GXcopy); + glamor_put_context(glamor_priv); if (ok) return TRUE; diff --git a/xorg-server/glamor/glamor_core.c b/xorg-server/glamor/glamor_core.c index 4eac85603..58838095b 100644 --- a/xorg-server/glamor/glamor_core.c +++ b/xorg-server/glamor/glamor_core.c @@ -51,24 +51,23 @@ glamor_get_drawable_location(const DrawablePtr drawable) } GLint -glamor_compile_glsl_prog(glamor_gl_dispatch * dispatch, GLenum type, - const char *source) +glamor_compile_glsl_prog(GLenum type, const char *source) { GLint ok; GLint prog; - prog = dispatch->glCreateShader(type); - dispatch->glShaderSource(prog, 1, (const GLchar **) &source, NULL); - dispatch->glCompileShader(prog); - dispatch->glGetShaderiv(prog, GL_COMPILE_STATUS, &ok); + prog = glCreateShader(type); + glShaderSource(prog, 1, (const GLchar **) &source, NULL); + glCompileShader(prog); + glGetShaderiv(prog, GL_COMPILE_STATUS, &ok); if (!ok) { GLchar *info; GLint size; - dispatch->glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size); + glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size); info = malloc(size); if (info) { - dispatch->glGetShaderInfoLog(prog, size, NULL, info); + glGetShaderInfoLog(prog, size, NULL, info); ErrorF("Failed to compile %s: %s\n", type == GL_FRAGMENT_SHADER ? "FS" : "VS", info); ErrorF("Program source:\n%s", source); @@ -83,20 +82,20 @@ glamor_compile_glsl_prog(glamor_gl_dispatch * dispatch, GLenum type, } void -glamor_link_glsl_prog(glamor_gl_dispatch * dispatch, GLint prog) +glamor_link_glsl_prog(GLint prog) { GLint ok; - dispatch->glLinkProgram(prog); - dispatch->glGetProgramiv(prog, GL_LINK_STATUS, &ok); + glLinkProgram(prog); + glGetProgramiv(prog, GL_LINK_STATUS, &ok); if (!ok) { GLchar *info; GLint size; - dispatch->glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); info = malloc(size); - dispatch->glGetProgramInfoLog(prog, size, NULL, info); + glGetProgramInfoLog(prog, size, NULL, info); ErrorF("Failed to link: %s\n", info); FatalError("GLSL link failure\n"); } @@ -143,7 +142,6 @@ void glamor_init_finish_access_shaders(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; const char *vs_source = "attribute vec4 v_position;\n" "attribute vec4 v_texcoord0;\n" @@ -217,86 +215,78 @@ glamor_init_finish_access_shaders(ScreenPtr screen) char *source; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - glamor_priv->finish_access_prog[0] = dispatch->glCreateProgram(); - glamor_priv->finish_access_prog[1] = dispatch->glCreateProgram(); + glamor_get_context(glamor_priv); + glamor_priv->finish_access_prog[0] = glCreateProgram(); + glamor_priv->finish_access_prog[1] = glCreateProgram(); - vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, vs_source); + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source); XNFasprintf(&source, "%s%s", common_source, fs_source); - fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, source); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, source); free(source); - dispatch->glAttachShader(glamor_priv->finish_access_prog[0], vs_prog); - dispatch->glAttachShader(glamor_priv->finish_access_prog[0], fs_prog); + glAttachShader(glamor_priv->finish_access_prog[0], vs_prog); + glAttachShader(glamor_priv->finish_access_prog[0], fs_prog); - avs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, vs_source); + avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source); XNFasprintf(&source, "%s%s", common_source, set_alpha_source); - set_alpha_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, + set_alpha_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, source); free(source); - dispatch->glAttachShader(glamor_priv->finish_access_prog[1], avs_prog); - dispatch->glAttachShader(glamor_priv->finish_access_prog[1], - set_alpha_prog); + glAttachShader(glamor_priv->finish_access_prog[1], avs_prog); + glAttachShader(glamor_priv->finish_access_prog[1], set_alpha_prog); - 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[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[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]); + 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]); glamor_priv->finish_access_revert[0] = - dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[0], - "revert"); + glGetUniformLocation(glamor_priv->finish_access_prog[0], "revert"); glamor_priv->finish_access_swap_rb[0] = - dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[0], - "swap_rb"); + glGetUniformLocation(glamor_priv->finish_access_prog[0], "swap_rb"); sampler_uniform_location = - 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_revert[0], 0); - dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0], 0); - dispatch->glUseProgram(0); + 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_revert[0], 0); + glUniform1i(glamor_priv->finish_access_swap_rb[0], 0); + glUseProgram(0); glamor_priv->finish_access_revert[1] = - dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], - "revert"); + glGetUniformLocation(glamor_priv->finish_access_prog[1], "revert"); glamor_priv->finish_access_swap_rb[1] = - dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], - "swap_rb"); + glGetUniformLocation(glamor_priv->finish_access_prog[1], "swap_rb"); sampler_uniform_location = - dispatch->glGetUniformLocation(glamor_priv->finish_access_prog[1], - "sampler"); - dispatch->glUseProgram(glamor_priv->finish_access_prog[1]); - dispatch->glUniform1i(glamor_priv->finish_access_revert[1], 0); - dispatch->glUniform1i(sampler_uniform_location, 0); - dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[1], 0); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler"); + glUseProgram(glamor_priv->finish_access_prog[1]); + glUniform1i(glamor_priv->finish_access_revert[1], 0); + glUniform1i(sampler_uniform_location, 0); + glUniform1i(glamor_priv->finish_access_swap_rb[1], 0); + glUseProgram(0); + glamor_put_context(glamor_priv); } void glamor_fini_finish_access_shaders(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glDeleteProgram(glamor_priv->finish_access_prog[0]); - dispatch->glDeleteProgram(glamor_priv->finish_access_prog[1]); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glDeleteProgram(glamor_priv->finish_access_prog[0]); + glDeleteProgram(glamor_priv->finish_access_prog[1]); + glamor_put_context(glamor_priv); } void @@ -315,15 +305,13 @@ glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode) } if (pixmap_priv->base.fbo->pbo != 0 && pixmap_priv->base.fbo->pbo_valid) { - glamor_gl_dispatch *dispatch; - assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - dispatch->glDeleteBuffers(1, &pixmap_priv->base.fbo->pbo); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glDeleteBuffers(1, &pixmap_priv->base.fbo->pbo); + glamor_put_context(glamor_priv); pixmap_priv->base.fbo->pbo_valid = FALSE; pixmap_priv->base.fbo->pbo = 0; diff --git a/xorg-server/glamor/glamor_egl.c b/xorg-server/glamor/glamor_egl.c index 2f97a839b..9dcba71ce 100644 --- a/xorg-server/glamor/glamor_egl.c +++ b/xorg-server/glamor/glamor_egl.c @@ -37,8 +37,6 @@ #include <errno.h> #include <xf86.h> #include <xf86drm.h> -#define GL_GLEXT_PROTOTYPES -#define EGL_EGLEXT_PROTOTYPES #define EGL_DISPLAY_NO_X_MESA #ifdef GLAMOR_HAS_GBM @@ -46,19 +44,12 @@ #include <drm_fourcc.h> #endif -#if GLAMOR_GLES2 -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> -#else -#include <GL/gl.h> -#endif - #define MESA_EGL_NO_X11_HEADERS -#include <EGL/egl.h> -#include <EGL/eglext.h> +#include <epoxy/gl.h> +#include <epoxy/egl.h> #include "glamor.h" -#include "glamor_gl_dispatch.h" +#include "glamor_priv.h" static const char glamor_name[] = "glamor"; @@ -91,16 +82,13 @@ struct glamor_egl_screen_private { int gl_context_depth; int dri3_capable; - PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr; - PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr; - PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes; - struct glamor_gl_dispatch *dispatch; CloseScreenProcPtr saved_close_screen; xf86FreeScreenProc *saved_free_screen; }; int xf86GlamorEGLPrivateIndex = -1; + static struct glamor_egl_screen_private * glamor_egl_get_screen_private(ScrnInfoPtr scrn) { @@ -108,38 +96,30 @@ glamor_egl_get_screen_private(ScrnInfoPtr scrn) scrn->privates[xf86GlamorEGLPrivateIndex].ptr; } -_X_EXPORT void -glamor_egl_make_current(ScreenPtr screen) +static void +glamor_egl_get_context(struct glamor_context *glamor_ctx) { - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct glamor_egl_screen_private *glamor_egl = - glamor_egl_get_screen_private(scrn); - - if (glamor_egl->gl_context_depth++) + if (glamor_ctx->get_count++) return; - if (glamor_egl->context != eglGetCurrentContext()) { - eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE, + if (glamor_ctx->ctx != eglGetCurrentContext()) { + eglMakeCurrent(glamor_ctx->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (!eglMakeCurrent(glamor_egl->display, + if (!eglMakeCurrent(glamor_ctx->display, EGL_NO_SURFACE, EGL_NO_SURFACE, - glamor_egl->context)) { + glamor_ctx->ctx)) { FatalError("Failed to make EGL context current\n"); } } } -_X_EXPORT void -glamor_egl_restore_context(ScreenPtr screen) +static void +glamor_egl_put_context(struct glamor_context *glamor_ctx) { - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct glamor_egl_screen_private *glamor_egl = - glamor_egl_get_screen_private(scrn); - - if (--glamor_egl->gl_context_depth) + if (--glamor_ctx->get_count) return; - eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE, + eglMakeCurrent(glamor_ctx->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } @@ -164,11 +144,11 @@ _glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl, attribs[5] = stride; if (depth != 32 && depth != 24) return EGL_NO_IMAGE_KHR; - image = glamor_egl->egl_create_image_khr(glamor_egl->display, - glamor_egl->context, - EGL_DRM_BUFFER_MESA, - (void *) (uintptr_t) name, - attribs); + image = eglCreateImageKHR(glamor_egl->display, + glamor_egl->context, + EGL_DRM_BUFFER_MESA, + (void *) (uintptr_t) name, + attribs); if (image == EGL_NO_IMAGE_KHR) return EGL_NO_IMAGE_KHR; @@ -192,15 +172,13 @@ glamor_create_texture_from_image(struct glamor_egl_screen_private *glamor_egl, EGLImageKHR image, GLuint * texture) { - glamor_egl->dispatch->glGenTextures(1, texture); - glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, *texture); - glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - (glamor_egl->egl_image_target_texture2d_oes) (GL_TEXTURE_2D, image); - glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, 0); + 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); + + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); + glBindTexture(GL_TEXTURE_2D, 0); return TRUE; } @@ -212,7 +190,7 @@ glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h) EGLImageKHR image; GLuint texture; -#ifdef GLAMOR_HAS_DRI3_SUPPORT +#ifdef GLAMOR_HAS_GBM struct gbm_bo *bo; EGLNativePixmapType native_pixmap; @@ -228,15 +206,15 @@ glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h) * compile with dri3 support enabled */ native_pixmap = bo; - image = glamor_egl->egl_create_image_khr(glamor_egl->display, - EGL_NO_CONTEXT, - EGL_NATIVE_PIXMAP_KHR, - native_pixmap, NULL); + image = eglCreateImageKHR(glamor_egl->display, + EGL_NO_CONTEXT, + EGL_NATIVE_PIXMAP_KHR, + native_pixmap, NULL); gbm_bo_destroy(bo); if (image == EGL_NO_IMAGE_KHR) return 0; glamor_create_texture_from_image(glamor_egl, image, &texture); - glamor_egl->egl_destroy_image_khr(glamor_egl->display, image); + eglDestroyImageKHR(glamor_egl->display, image); return texture; #else @@ -300,6 +278,8 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) { ScreenPtr screen = pixmap->drawable.pScreen; ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + struct glamor_screen_private *glamor_priv = + glamor_get_screen_private(screen); struct glamor_egl_screen_private *glamor_egl; EGLImageKHR image; GLuint texture; @@ -308,7 +288,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) glamor_egl = glamor_egl_get_screen_private(scrn); - glamor_egl_make_current(screen); + glamor_get_context(glamor_priv); if (glamor_egl->has_gem) { if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) { xf86DrvMsg(scrn->scrnIndex, X_ERROR, @@ -338,7 +318,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) ret = TRUE; done: - glamor_egl_restore_context(screen); + glamor_put_context(glamor_priv); return ret; } @@ -347,6 +327,8 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo) { ScreenPtr screen = pixmap->drawable.pScreen; ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + struct glamor_screen_private *glamor_priv = + glamor_get_screen_private(screen); struct glamor_egl_screen_private *glamor_egl; EGLImageKHR image; GLuint texture; @@ -354,11 +336,11 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo) glamor_egl = glamor_egl_get_screen_private(scrn); - glamor_egl_make_current(screen); + glamor_get_context(glamor_priv); - image = glamor_egl->egl_create_image_khr(glamor_egl->display, - glamor_egl->context, - EGL_NATIVE_PIXMAP_KHR, bo, NULL); + image = eglCreateImageKHR(glamor_egl->display, + glamor_egl->context, + EGL_NATIVE_PIXMAP_KHR, bo, NULL); if (image == EGL_NO_IMAGE_KHR) { glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY); goto done; @@ -370,11 +352,11 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo) ret = TRUE; done: - glamor_egl_restore_context(screen); + glamor_put_context(glamor_priv); return ret; } -#ifdef GLAMOR_HAS_DRI3_SUPPORT +#ifdef GLAMOR_HAS_GBM int glamor_get_fd_from_bo(int gbm_fd, struct gbm_bo *bo, int *fd); void glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name); int @@ -409,8 +391,10 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen, unsigned int tex, Bool want_name, CARD16 *stride, CARD32 *size) { -#ifdef GLAMOR_HAS_DRI3_SUPPORT +#ifdef GLAMOR_HAS_GBM ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + struct glamor_screen_private *glamor_priv = + glamor_get_screen_private(screen); struct glamor_egl_screen_private *glamor_egl; EGLImageKHR image; struct gbm_bo *bo; @@ -424,17 +408,17 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen, glamor_egl = glamor_egl_get_screen_private(scrn); - glamor_egl_make_current(screen); + glamor_get_context(glamor_priv); image = dixLookupPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key); if (image == EGL_NO_IMAGE_KHR || image == NULL) { - image = glamor_egl->egl_create_image_khr(glamor_egl->display, - glamor_egl->context, - EGL_GL_TEXTURE_2D_KHR, - (EGLClientBuffer) (uintptr_t) - tex, attribs); + image = eglCreateImageKHR(glamor_egl->display, + glamor_egl->context, + EGL_GL_TEXTURE_2D_KHR, + (EGLClientBuffer) (uintptr_t) + tex, attribs); if (image == EGL_NO_IMAGE_KHR) goto failure; @@ -462,7 +446,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen, gbm_bo_destroy(bo); failure: - glamor_egl_restore_context(screen); + glamor_put_context(glamor_priv); return fd; #else return -1; @@ -476,7 +460,7 @@ glamor_egl_dri3_pixmap_from_fd(ScreenPtr screen, CARD16 height, CARD16 stride, CARD8 depth, CARD8 bpp) { -#ifdef GLAMOR_HAS_DRI3_SUPPORT +#ifdef GLAMOR_HAS_GBM ScrnInfoPtr scrn = xf86ScreenToScrn(screen); struct glamor_egl_screen_private *glamor_egl; struct gbm_bo *bo; @@ -506,10 +490,10 @@ glamor_egl_dri3_pixmap_from_fd(ScreenPtr screen, attribs[3] = height; attribs[7] = fd; attribs[11] = stride; - image = glamor_egl->egl_create_image_khr(glamor_egl->display, - EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, - NULL, attribs); + image = eglCreateImageKHR(glamor_egl->display, + EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + NULL, attribs); if (image == EGL_NO_IMAGE_KHR) return NULL; @@ -518,7 +502,7 @@ glamor_egl_dri3_pixmap_from_fd(ScreenPtr screen, * usage of the image. Use gbm_bo to bypass the limitations. */ bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0); - glamor_egl->egl_destroy_image_khr(glamor_egl->display, image); + eglDestroyImageKHR(glamor_egl->display, image); if (!bo) return NULL; @@ -555,7 +539,7 @@ _glamor_egl_destroy_pixmap_image(PixmapPtr pixmap) * a texture. we must call glFlush to make sure the * operation on that texture has been done.*/ glamor_block_handler(pixmap->drawable.pScreen); - glamor_egl->egl_destroy_image_khr(glamor_egl->display, image); + eglDestroyImageKHR(glamor_egl->display, image); dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key, NULL); } @@ -605,8 +589,7 @@ glamor_egl_close_screen(ScreenPtr screen) glamor_egl = glamor_egl_get_screen_private(scrn); screen_pixmap = screen->GetScreenPixmap(screen); - glamor_egl->egl_destroy_image_khr(glamor_egl->display, - glamor_egl->front_image); + eglDestroyImageKHR(glamor_egl->display,glamor_egl->front_image); dixSetPrivate(&screen_pixmap->devPrivates, glamor_egl_pixmap_private_key, NULL); glamor_egl->front_image = NULL; @@ -614,7 +597,7 @@ glamor_egl_close_screen(ScreenPtr screen) back_image = dixLookupPrivate(&(*glamor_egl->back_pixmap)->devPrivates, glamor_egl_pixmap_private_key); if (back_image != NULL && back_image != EGL_NO_IMAGE_KHR) { - glamor_egl->egl_destroy_image_khr(glamor_egl->display, back_image); + eglDestroyImageKHR(glamor_egl->display, back_image); dixSetPrivate(&(*glamor_egl->back_pixmap)->devPrivates, glamor_egl_pixmap_private_key, NULL); } @@ -645,7 +628,7 @@ glamor_egl_has_extension(struct glamor_egl_screen_private *glamor_egl, } void -glamor_egl_screen_init(ScreenPtr screen) +glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx) { ScrnInfoPtr scrn = xf86ScreenToScrn(screen); struct glamor_egl_screen_private *glamor_egl = @@ -653,6 +636,12 @@ glamor_egl_screen_init(ScreenPtr screen) glamor_egl->saved_close_screen = screen->CloseScreen; screen->CloseScreen = glamor_egl_close_screen; + + glamor_ctx->ctx = glamor_egl->context; + glamor_ctx->display = glamor_egl->display; + + glamor_ctx->get_context = glamor_egl_get_context; + glamor_ctx->put_context = glamor_egl_put_context; } static void @@ -746,26 +735,11 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) KHR_surfaceless_opengl); #endif -#ifdef GLAMOR_HAS_DRI3_SUPPORT +#ifdef GLAMOR_HAS_GBM if (glamor_egl_has_extension(glamor_egl, "EGL_KHR_gl_texture_2D_image") && glamor_egl_has_extension(glamor_egl, "EGL_EXT_image_dma_buf_import")) glamor_egl->dri3_capable = TRUE; #endif - glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC) - eglGetProcAddress("eglCreateImageKHR"); - - glamor_egl->egl_destroy_image_khr = (PFNEGLDESTROYIMAGEKHRPROC) - eglGetProcAddress("eglDestroyImageKHR"); - - glamor_egl->egl_image_target_texture2d_oes = - (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) - eglGetProcAddress("glEGLImageTargetTexture2DOES"); - - if (!glamor_egl->egl_create_image_khr - || !glamor_egl->egl_image_target_texture2d_oes) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, "eglGetProcAddress() failed\n"); - return FALSE; - } glamor_egl->context = eglCreateContext(glamor_egl->display, NULL, EGL_NO_CONTEXT, @@ -809,17 +783,3 @@ glamor_egl_init_textured_pixmap(ScreenPtr screen) glamor_enable_dri3(screen); return TRUE; } - -Bool -glamor_gl_dispatch_init(ScreenPtr screen, - struct glamor_gl_dispatch *dispatch, int gl_version) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct glamor_egl_screen_private *glamor_egl = - glamor_egl_get_screen_private(scrn); - if (!glamor_gl_dispatch_init_impl - (dispatch, gl_version, (get_proc_address_t) eglGetProcAddress)) - return FALSE; - glamor_egl->dispatch = dispatch; - return TRUE; -} diff --git a/xorg-server/glamor/glamor_egl_stubs.c b/xorg-server/glamor/glamor_egl_stubs.c index 1449d0874..4fd9e8016 100644 --- a/xorg-server/glamor/glamor_egl_stubs.c +++ b/xorg-server/glamor/glamor_egl_stubs.c @@ -29,7 +29,7 @@ #include "glamor_priv.h" void -glamor_egl_screen_init(ScreenPtr screen) +glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx) { } @@ -38,16 +38,6 @@ glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap) { } -void -glamor_egl_make_current(ScreenPtr screen) -{ -} - -void -glamor_egl_restore_context(ScreenPtr screen) -{ -} - int glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen, PixmapPtr pixmap, diff --git a/xorg-server/glamor/glamor_fbo.c b/xorg-server/glamor/glamor_fbo.c index d94e53071..281cf830e 100644 --- a/xorg-server/glamor/glamor_fbo.c +++ b/xorg-server/glamor/glamor_fbo.c @@ -129,15 +129,15 @@ glamor_pixmap_fbo_cache_get(glamor_screen_private *glamor_priv, void glamor_purge_fbo(glamor_pixmap_fbo *fbo) { - glamor_gl_dispatch *dispatch = glamor_get_dispatch(fbo->glamor_priv); + glamor_get_context(fbo->glamor_priv); if (fbo->fb) - dispatch->glDeleteFramebuffers(1, &fbo->fb); + glDeleteFramebuffers(1, &fbo->fb); if (fbo->tex) - dispatch->glDeleteTextures(1, &fbo->tex); + glDeleteTextures(1, &fbo->tex); if (fbo->pbo) - dispatch->glDeleteBuffers(1, &fbo->pbo); - glamor_put_dispatch(fbo->glamor_priv); + glDeleteBuffers(1, &fbo->pbo); + glamor_put_context(fbo->glamor_priv); free(fbo); } @@ -178,19 +178,17 @@ glamor_pixmap_fbo_cache_put(glamor_pixmap_fbo *fbo) static void glamor_pixmap_ensure_fb(glamor_pixmap_fbo *fbo) { - glamor_gl_dispatch *dispatch; int status; - dispatch = glamor_get_dispatch(fbo->glamor_priv); + glamor_get_context(fbo->glamor_priv); if (fbo->fb == 0) - dispatch->glGenFramebuffers(1, &fbo->fb); + glGenFramebuffers(1, &fbo->fb); assert(fbo->tex != 0); - dispatch->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb); - dispatch->glFramebufferTexture2D(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, fbo->tex, 0); - status = dispatch->glCheckFramebufferStatus(GL_FRAMEBUFFER); + glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, fbo->tex, 0); + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { const char *str; @@ -221,7 +219,7 @@ glamor_pixmap_ensure_fb(glamor_pixmap_fbo *fbo) FatalError("destination is framebuffer incomplete: %s [%x]\n", str, status); } - glamor_put_dispatch(fbo->glamor_priv); + glamor_put_context(fbo->glamor_priv); } glamor_pixmap_fbo * @@ -243,11 +241,9 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv, fbo->glamor_priv = glamor_priv; if (flag == GLAMOR_CREATE_PIXMAP_MAP) { - glamor_gl_dispatch *dispatch; - - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glGenBuffers(1, &fbo->pbo); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glGenBuffers(1, &fbo->pbo); + glamor_put_context(glamor_priv); goto done; } @@ -334,7 +330,6 @@ static int _glamor_create_tex(glamor_screen_private *glamor_priv, int w, int h, GLenum format) { - glamor_gl_dispatch *dispatch; unsigned int tex = 0; /* With dri3, we want to allocate ARGB8888 pixmaps only. @@ -346,16 +341,14 @@ _glamor_create_tex(glamor_screen_private *glamor_priv, w, h); } if (!tex) { - dispatch = glamor_get_dispatch(glamor_priv); - 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_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + 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, + format, GL_UNSIGNED_BYTE, NULL); + glamor_put_context(glamor_priv); } return tex; } diff --git a/xorg-server/glamor/glamor_fill.c b/xorg-server/glamor/glamor_fill.c index d59e6204f..dda55eace 100644 --- a/xorg-server/glamor/glamor_fill.c +++ b/xorg-server/glamor/glamor_fill.c @@ -137,7 +137,6 @@ void glamor_init_solid_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; const char *solid_vs = "attribute vec4 v_position;" "void main()\n" @@ -154,32 +153,31 @@ glamor_init_solid_shader(ScreenPtr screen) GLint fs_prog, vs_prog; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - 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); + glamor_get_context(glamor_priv); + 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); - dispatch->glBindAttribLocation(glamor_priv->solid_prog, - GLAMOR_VERTEX_POS, "v_position"); - glamor_link_glsl_prog(dispatch, glamor_priv->solid_prog); + glBindAttribLocation(glamor_priv->solid_prog, + GLAMOR_VERTEX_POS, "v_position"); + glamor_link_glsl_prog(glamor_priv->solid_prog); glamor_priv->solid_color_uniform_location = - dispatch->glGetUniformLocation(glamor_priv->solid_prog, "color"); - glamor_put_dispatch(glamor_priv); + glGetUniformLocation(glamor_priv->solid_prog, "color"); + glamor_put_context(glamor_priv); } void glamor_fini_solid_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glDeleteProgram(glamor_priv->solid_prog); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glDeleteProgram(glamor_priv->solid_prog); + glamor_put_context(glamor_priv); } static void @@ -188,7 +186,6 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) 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; GLfloat xscale, yscale; float vertices[32]; float *pvertices = vertices; @@ -196,10 +193,10 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) glamor_set_destination_pixmap_priv_nc(pixmap_priv); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glUseProgram(glamor_priv->solid_prog); + glamor_get_context(glamor_priv); + glUseProgram(glamor_priv->solid_prog); - dispatch->glUniform4fv(glamor_priv->solid_color_uniform_location, 1, color); + glUniform4fv(glamor_priv->solid_color_uniform_location, 1, color); pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); @@ -221,11 +218,11 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) } if (_X_UNLIKELY(nbox > 1)) - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), pvertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), pvertices); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); while (nbox) { int box_cnt, i; @@ -242,17 +239,16 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) valid_vertices += 4 * 2; } if (box_cnt == 1) - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4); - else -#ifndef GLAMOR_GLES2 - dispatch->glDrawRangeElements(GL_TRIANGLES, - 0, - box_cnt * 4, - box_cnt * 6, GL_UNSIGNED_SHORT, NULL); -#else - dispatch->glDrawElements(GL_TRIANGLES, - box_cnt * 6, GL_UNSIGNED_SHORT, NULL); -#endif + glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4); + else { + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + glDrawRangeElements(GL_TRIANGLES, 0, box_cnt * 4, box_cnt * 6, + GL_UNSIGNED_SHORT, NULL); + } else { + glDrawElements(GL_TRIANGLES, box_cnt * 6, GL_UNSIGNED_SHORT, + NULL); + } + } nbox -= box_cnt; box += box_cnt; } @@ -260,9 +256,9 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) if (pvertices != vertices) free(pvertices); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glUseProgram(0); + glamor_put_context(glamor_priv); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; } @@ -321,7 +317,6 @@ 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_gl_dispatch *dispatch; BoxRec box; pixmap_priv = glamor_get_pixmap_private(pixmap); @@ -334,13 +329,13 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height, return FALSE; } - dispatch = glamor_get_dispatch(glamor_priv); - if (!glamor_set_alu(dispatch, alu)) { + glamor_get_context(glamor_priv); + if (!glamor_set_alu(screen, alu)) { if (alu == GXclear) fg_pixel = 0; else { glamor_fallback("unsupported alu %x\n", alu); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); return FALSE; } } @@ -350,8 +345,8 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height, box.y2 = y + height; glamor_solid_boxes(pixmap, &box, 1, fg_pixel); - glamor_set_alu(dispatch, GXcopy); - glamor_put_dispatch(glamor_priv); + glamor_set_alu(screen, GXcopy); + glamor_put_context(glamor_priv); return TRUE; } diff --git a/xorg-server/glamor/glamor_gl_dispatch.c b/xorg-server/glamor/glamor_gl_dispatch.c deleted file mode 100644 index 0bdda9c34..000000000 --- a/xorg-server/glamor/glamor_gl_dispatch.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2009 Intel Corporation - * Copyright © 1998 Keith Packard - * - * 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 (including the next - * paragraph) 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. - * - * Authors: - * Zhigang Gong <zhigang.gong@gmail.com> - * - */ - -#include "glamor_priv.h" -#include <dlfcn.h> - -#define INIT_FUNC(dst,func_name,get) \ - dst->func_name = get(#func_name); \ - if (dst->func_name == NULL) { \ - dst->func_name = (void *)dlsym(NULL, #func_name); \ - if (dst->func_name == NULL) { \ - ErrorF("Failed to get function %s\n", #func_name);\ - goto fail; \ - } \ - } \ - -_X_EXPORT Bool -glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch, - int gl_version, - void *(*get_proc_address) (const char *)) -{ -#ifndef GLAMOR_GLES2 - INIT_FUNC(dispatch, glMatrixMode, get_proc_address); - INIT_FUNC(dispatch, glLoadIdentity, get_proc_address); - INIT_FUNC(dispatch, glRasterPos2i, get_proc_address); - INIT_FUNC(dispatch, glDrawPixels, get_proc_address); - INIT_FUNC(dispatch, glLogicOp, get_proc_address); - INIT_FUNC(dispatch, glMapBuffer, get_proc_address); - INIT_FUNC(dispatch, glMapBufferRange, get_proc_address); - INIT_FUNC(dispatch, glUnmapBuffer, get_proc_address); - INIT_FUNC(dispatch, glBlitFramebuffer, get_proc_address); - INIT_FUNC(dispatch, glDrawRangeElements, get_proc_address); -#endif - INIT_FUNC(dispatch, glViewport, get_proc_address); - INIT_FUNC(dispatch, glDrawArrays, get_proc_address); - INIT_FUNC(dispatch, glDrawElements, get_proc_address); - INIT_FUNC(dispatch, glReadPixels, 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, glFinish, 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, glActiveTexture, get_proc_address); - INIT_FUNC(dispatch, glGenBuffers, get_proc_address); - INIT_FUNC(dispatch, glBufferData, get_proc_address); - INIT_FUNC(dispatch, glBindBuffer, get_proc_address); - INIT_FUNC(dispatch, glDeleteBuffers, get_proc_address); - INIT_FUNC(dispatch, glFramebufferTexture2D, get_proc_address); - INIT_FUNC(dispatch, glBindFramebuffer, get_proc_address); - INIT_FUNC(dispatch, glDeleteFramebuffers, get_proc_address); - INIT_FUNC(dispatch, glGenFramebuffers, get_proc_address); - INIT_FUNC(dispatch, glCheckFramebufferStatus, get_proc_address); - INIT_FUNC(dispatch, glVertexAttribPointer, get_proc_address); - INIT_FUNC(dispatch, glDisableVertexAttribArray, get_proc_address); - INIT_FUNC(dispatch, glEnableVertexAttribArray, get_proc_address); - INIT_FUNC(dispatch, glBindAttribLocation, get_proc_address); - INIT_FUNC(dispatch, glLinkProgram, get_proc_address); - INIT_FUNC(dispatch, glShaderSource, get_proc_address); - - INIT_FUNC(dispatch, glUseProgram, get_proc_address); - INIT_FUNC(dispatch, glUniform1i, get_proc_address); - INIT_FUNC(dispatch, glUniform1f, get_proc_address); - INIT_FUNC(dispatch, glUniform4f, get_proc_address); - INIT_FUNC(dispatch, glUniform4fv, get_proc_address); - INIT_FUNC(dispatch, glUniform1fv, get_proc_address); - INIT_FUNC(dispatch, glUniform2fv, get_proc_address); - INIT_FUNC(dispatch, glUniformMatrix3fv, get_proc_address); - INIT_FUNC(dispatch, glCreateProgram, get_proc_address); - INIT_FUNC(dispatch, glDeleteProgram, get_proc_address); - INIT_FUNC(dispatch, glCreateShader, get_proc_address); - INIT_FUNC(dispatch, glCompileShader, get_proc_address); - INIT_FUNC(dispatch, glAttachShader, get_proc_address); - INIT_FUNC(dispatch, glDeleteShader, get_proc_address); - INIT_FUNC(dispatch, glGetShaderiv, get_proc_address); - INIT_FUNC(dispatch, glGetShaderInfoLog, get_proc_address); - INIT_FUNC(dispatch, glGetProgramiv, get_proc_address); - INIT_FUNC(dispatch, glGetProgramInfoLog, get_proc_address); - INIT_FUNC(dispatch, glGetUniformLocation, get_proc_address); - - return TRUE; - fail: - return FALSE; -} diff --git a/xorg-server/glamor/glamor_gl_dispatch.h b/xorg-server/glamor/glamor_gl_dispatch.h deleted file mode 100644 index 63790b41f..000000000 --- a/xorg-server/glamor/glamor_gl_dispatch.h +++ /dev/null @@ -1,128 +0,0 @@ -typedef struct glamor_gl_dispatch { - /* Transformation functions */ - void (*glMatrixMode) (GLenum mode); - void (*glLoadIdentity) (void); - void (*glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); - /* Drawing functions */ - void (*glRasterPos2i) (GLint x, GLint y); - - /* Vertex Array */ - void (*glDrawArrays) (GLenum mode, GLint first, GLsizei count); - - /* Elements Array */ - void (*glDrawElements) (GLenum mode, GLsizei count, GLenum type, - const GLvoid * indices); - void (*glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, - GLsizei count, GLenum type, - const GLvoid * indices); - - /* Raster functions */ - void (*glReadPixels) (GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, GLenum type, GLvoid * pixels); - - void (*glDrawPixels) (GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid * pixels); - void (*glPixelStorei) (GLenum pname, GLint param); - /* Texture Mapping */ - - void (*glTexParameteri) (GLenum target, GLenum pname, GLint param); - void (*glTexImage2D) (GLenum target, GLint level, - GLint internalFormat, - GLsizei width, GLsizei height, - GLint border, GLenum format, GLenum type, - const GLvoid * pixels); - /* 1.1 */ - void (*glGenTextures) (GLsizei n, GLuint * textures); - void (*glDeleteTextures) (GLsizei n, const GLuint * textures); - void (*glBindTexture) (GLenum target, GLuint texture); - void (*glTexSubImage2D) (GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid * pixels); - /* MISC */ - void (*glFlush) (void); - void (*glFinish) (void); - void (*glGetIntegerv) (GLenum pname, GLint * params); - const GLubyte *(*glGetString) (GLenum name); - void (*glScissor) (GLint x, GLint y, GLsizei width, GLsizei height); - void (*glEnable) (GLenum cap); - void (*glDisable) (GLenum cap); - void (*glBlendFunc) (GLenum sfactor, GLenum dfactor); - void (*glLogicOp) (GLenum opcode); - - /* 1.3 */ - void (*glActiveTexture) (GLenum texture); - - /* GL Extentions */ - void (*glGenBuffers) (GLsizei n, GLuint * buffers); - void (*glBufferData) (GLenum target, GLsizeiptr size, - const GLvoid * data, GLenum usage); - GLvoid *(*glMapBuffer) (GLenum target, GLenum access); - GLvoid *(*glMapBufferRange) (GLenum target, GLintptr offset, - GLsizeiptr length, GLbitfield access); - GLboolean(*glUnmapBuffer) (GLenum target); - void (*glBindBuffer) (GLenum target, GLuint buffer); - void (*glDeleteBuffers) (GLsizei n, const GLuint * buffers); - - void (*glFramebufferTexture2D) (GLenum target, GLenum attachment, - GLenum textarget, GLuint texture, - GLint level); - void (*glBindFramebuffer) (GLenum target, GLuint framebuffer); - void (*glDeleteFramebuffers) (GLsizei n, const GLuint * framebuffers); - void (*glGenFramebuffers) (GLsizei n, GLuint * framebuffers); - GLenum(*glCheckFramebufferStatus) (GLenum target); - void (*glBlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, - GLint srcY1, GLint dstX0, GLint dstY0, - GLint dstX1, GLint dstY1, - GLbitfield mask, GLenum filter); - - void (*glVertexAttribPointer) (GLuint index, GLint size, - GLenum type, GLboolean normalized, - GLsizei stride, const GLvoid * pointer); - void (*glDisableVertexAttribArray) (GLuint index); - void (*glEnableVertexAttribArray) (GLuint index); - void (*glBindAttribLocation) (GLuint program, GLuint index, - const GLchar * name); - - void (*glLinkProgram) (GLuint program); - void (*glShaderSource) (GLuint shader, GLsizei count, - const GLchar * *string, const GLint * length); - void (*glUseProgram) (GLuint program); - void (*glUniform1i) (GLint location, GLint v0); - void (*glUniform1f) (GLint location, GLfloat v0); - void (*glUniform4f) (GLint location, GLfloat v0, GLfloat v1, - GLfloat v2, GLfloat v3); - void (*glUniform1fv) (GLint location, GLsizei count, const GLfloat * value); - void (*glUniform2fv) (GLint location, GLsizei count, const GLfloat * value); - void (*glUniform4fv) (GLint location, GLsizei count, const GLfloat * value); - void (*glUniformMatrix3fv) (GLint location, GLsizei count, - GLboolean transpose, const GLfloat * value); - GLuint(*glCreateProgram) (void); - GLuint(*glDeleteProgram) (GLuint); - GLuint(*glCreateShader) (GLenum type); - void (*glCompileShader) (GLuint shader); - void (*glAttachShader) (GLuint program, GLuint shader); - void (*glDeleteShader) (GLuint shader); - void (*glGetShaderiv) (GLuint shader, GLenum pname, GLint * params); - void (*glGetShaderInfoLog) (GLuint shader, GLsizei bufSize, - GLsizei * length, GLchar * infoLog); - void (*glGetProgramiv) (GLuint program, GLenum pname, GLint * params); - void (*glGetProgramInfoLog) (GLuint program, GLsizei bufSize, - GLsizei * length, GLchar * infoLog); - GLint(*glGetUniformLocation) (GLuint program, const GLchar * name); - -} glamor_gl_dispatch; - -typedef void *(*get_proc_address_t) (const char *); - -_X_EXPORT Bool - -glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch, - int gl_version, - get_proc_address_t get_proc_address); - -_X_EXPORT Bool - -glamor_gl_dispatch_init(ScreenPtr screen, - struct glamor_gl_dispatch *dispatch, int gl_version); diff --git a/xorg-server/glamor/glamor_glext.h b/xorg-server/glamor/glamor_glext.h deleted file mode 100644 index 2a220c32f..000000000 --- a/xorg-server/glamor/glamor_glext.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright © 2001 Keith Packard - * Copyright © 2008 Intel Corporation - * - * 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 (including the next - * paragraph) 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. - * - * Authors: - * Zhigang Gong <zhigang.gong@linux.intel.com> - * - */ - -#ifdef GLAMOR_GLES2 - -#define GL_BGRA GL_BGRA_EXT -#define GL_COLOR_INDEX 0x1900 -#define GL_BITMAP 0x1A00 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 - -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_CLAMP_TO_BORDER 0x812D - -#define GL_READ_WRITE 0x88BA -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_PACK_ROW_LENGTH 0x0D02 -#define GL_UNPACK_ROW_LENGTH 0x0CF2 - -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 - -#define GL_PACK_INVERT_MESA 0x8758 -#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 -#define GL_MAP_READ_BIT 0x0001 -#define GL_MAP_WRITE_BIT 0x0002 - -#endif diff --git a/xorg-server/glamor/glamor_glx.c b/xorg-server/glamor/glamor_glx.c new file mode 100644 index 000000000..311bf758d --- /dev/null +++ b/xorg-server/glamor/glamor_glx.c @@ -0,0 +1,82 @@ +/* + * Copyright © 2013 Intel Corporation + * + * 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 (including the next + * paragraph) 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. + */ + +#include <epoxy/glx.h> +#include "glamor_context.h" + +/** + * @file glamor_glx.c + * + * GLX context management for glamor. + * + * This has to be kept separate from the server sources because of + * Xlib's conflicting definition of CARD32 and similar typedefs. + */ + +static void +glamor_glx_get_context(struct glamor_context *glamor_ctx) +{ + GLXContext old_ctx; + + if (glamor_ctx->get_count++) + return; + + old_ctx = glXGetCurrentContext(); + if (old_ctx == glamor_ctx->ctx) + return; + + glXMakeCurrent(glamor_ctx->display, glamor_ctx->drawable_xid, + glamor_ctx->ctx); +} + + +static void +glamor_glx_put_context(struct glamor_context *glamor_ctx) +{ + if (--glamor_ctx->get_count) + return; + + /* We actually reset the context, so that indirect GLX's EGL usage + * won't get confused by ours. + */ + glXMakeCurrent(glamor_ctx->display, None, NULL); +} + +Bool +glamor_glx_screen_init(struct glamor_context *glamor_ctx) +{ + glamor_ctx->ctx = glXGetCurrentContext(); + if (!glamor_ctx->ctx) + return False; + + glamor_ctx->display = glXGetCurrentDisplay(); + if (!glamor_ctx->display) + return False; + + glamor_ctx->drawable_xid = glXGetCurrentDrawable(); + + glamor_ctx->get_context = glamor_glx_get_context; + glamor_ctx->put_context = glamor_glx_put_context; + + return True; +} diff --git a/xorg-server/glamor/glamor_glyphs.c b/xorg-server/glamor/glamor_glyphs.c index 3586b33da..caafa4348 100644 --- a/xorg-server/glamor/glamor_glyphs.c +++ b/xorg-server/glamor/glamor_glyphs.c @@ -1274,15 +1274,13 @@ glamor_buffer_glyph(glamor_screen_private *glamor_priv, if (buffer->source == NULL) buffer->source = source; if (glyphs_dst_mode == GLYPHS_DST_MODE_VIA_MASK_CACHE) { - glamor_gl_dispatch *dispatch; - /* mode 1 means we are using global mask cache, * thus we have to composite from the cache picture * to the cache picture, we need a flush here to make * sure latter we get the corret glyphs data.*/ - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glFlush(); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glFlush(); + glamor_put_context(glamor_priv); } } else { diff --git a/xorg-server/glamor/glamor_gradient.c b/xorg-server/glamor/glamor_gradient.c index df2ccb8a0..9f6f1b1cf 100644 --- a/xorg-server/glamor/glamor_gradient.c +++ b/xorg-server/glamor/glamor_gradient.c @@ -42,15 +42,13 @@ #ifdef GLAMOR_GRADIENT_SHADER -static GLint -_glamor_create_getcolor_fs_program(ScreenPtr screen, int stops_count, - int use_array) +static const char * +_glamor_create_getcolor_fs_source(ScreenPtr screen, int stops_count, + int use_array) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; char *gradient_fs = NULL; - GLint fs_getcolor_prog; #define gradient_fs_getcolor\ GLAMOR_DEFAULT_PRECISION\ @@ -177,22 +175,16 @@ _glamor_create_getcolor_fs_program(ScreenPtr screen, int stops_count, "}\n"; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (use_array) { XNFasprintf(&gradient_fs, gradient_fs_getcolor, stops_count, stops_count); - fs_getcolor_prog = - glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, gradient_fs); - free(gradient_fs); + return gradient_fs; } else { - fs_getcolor_prog = - glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, - gradient_fs_getcolor_no_array); + return XNFstrdup(gradient_fs_getcolor_no_array); } - - return fs_getcolor_prog; } static void @@ -200,12 +192,11 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, int dyn_gen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; int index; GLint gradient_prog = 0; char *gradient_fs = NULL; - GLint fs_main_prog, fs_getcolor_prog, vs_prog; + GLint fs_prog, vs_prog; const char *gradient_vs = GLAMOR_DEFAULT_PRECISION @@ -346,7 +337,10 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, " } else {\n"\ " gl_FragColor = get_color(stop_len);\n"\ " }\n"\ - "}\n" + "}\n"\ + "\n"\ + "%s\n" /* fs_getcolor_source */ + const char *fs_getcolor_source; glamor_priv = glamor_get_screen_private(screen); @@ -355,61 +349,42 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, return; } - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (dyn_gen && glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][2]) { - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_VS_PROG][2]); - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_VS_PROG][2] = 0; - - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_FS_MAIN_PROG][2]); - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][2] = - 0; - - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_FS_GETCOLOR_PROG][2]); - glamor_priv-> - radial_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][2] = 0; - - dispatch->glDeleteProgram(glamor_priv-> - gradient_prog[SHADER_GRADIENT_RADIAL][2]); + glDeleteProgram(glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][2]); glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][2] = 0; } - gradient_prog = dispatch->glCreateProgram(); + gradient_prog = glCreateProgram(); + + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, gradient_vs); - vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, gradient_vs); + fs_getcolor_source = + _glamor_create_getcolor_fs_source(screen, stops_count, + (stops_count > 0)); XNFasprintf(&gradient_fs, gradient_radial_fs_template, PIXMAN_REPEAT_NONE, PIXMAN_REPEAT_NORMAL, - PIXMAN_REPEAT_REFLECT); + PIXMAN_REPEAT_REFLECT, + fs_getcolor_source); - fs_main_prog = glamor_compile_glsl_prog(dispatch, - GL_FRAGMENT_SHADER, gradient_fs); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, gradient_fs); free(gradient_fs); - fs_getcolor_prog = - _glamor_create_getcolor_fs_program(screen, stops_count, - (stops_count > 0)); + glAttachShader(gradient_prog, vs_prog); + glAttachShader(gradient_prog, fs_prog); + glDeleteShader(vs_prog); + glDeleteShader(fs_prog); - dispatch->glAttachShader(gradient_prog, vs_prog); - dispatch->glAttachShader(gradient_prog, fs_getcolor_prog); - dispatch->glAttachShader(gradient_prog, fs_main_prog); + glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, "v_position"); + glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, "v_texcoord"); - dispatch->glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, - "v_positionsition"); - dispatch->glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, - "v_texcoord"); + glamor_link_glsl_prog(gradient_prog); - glamor_link_glsl_prog(dispatch, gradient_prog); - - dispatch->glUseProgram(0); + glUseProgram(0); if (dyn_gen) { index = 2; @@ -423,15 +398,8 @@ _glamor_create_radial_gradient_program(ScreenPtr screen, int stops_count, } glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][index] = gradient_prog; - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_VS_PROG][index] = - vs_prog; - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][index] = - fs_main_prog; - glamor_priv-> - radial_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][index] = - fs_getcolor_prog; - - glamor_put_dispatch(glamor_priv); + + glamor_put_context(glamor_priv); } static void @@ -439,12 +407,11 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, int dyn_gen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; int index = 0; GLint gradient_prog = 0; char *gradient_fs = NULL; - GLint fs_main_prog, fs_getcolor_prog, vs_prog; + GLint fs_prog, vs_prog; const char *gradient_vs = GLAMOR_DEFAULT_PRECISION @@ -587,7 +554,10 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, "{\n"\ " float stop_len = get_stop_len();\n"\ " gl_FragColor = get_color(stop_len);\n"\ - "}\n" + "}\n"\ + "\n"\ + "%s" /* fs_getcolor_source */ + const char *fs_getcolor_source; glamor_priv = glamor_get_screen_private(screen); @@ -596,58 +566,38 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, return; } - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (dyn_gen && glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][2]) { - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_VS_PROG][2]); - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_VS_PROG][2] = 0; - - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_FS_MAIN_PROG][2]); - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][2] = - 0; - - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_FS_GETCOLOR_PROG][2]); - glamor_priv-> - linear_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][2] = 0; - - dispatch->glDeleteProgram(glamor_priv-> - gradient_prog[SHADER_GRADIENT_LINEAR][2]); + glDeleteProgram(glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][2]); glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][2] = 0; } - gradient_prog = dispatch->glCreateProgram(); + gradient_prog = glCreateProgram(); - vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, gradient_vs); + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, gradient_vs); + + fs_getcolor_source = + _glamor_create_getcolor_fs_source(screen, stops_count, stops_count > 0); XNFasprintf(&gradient_fs, gradient_fs_template, - PIXMAN_REPEAT_NORMAL, PIXMAN_REPEAT_REFLECT); + PIXMAN_REPEAT_NORMAL, PIXMAN_REPEAT_REFLECT, + fs_getcolor_source); - fs_main_prog = glamor_compile_glsl_prog(dispatch, - GL_FRAGMENT_SHADER, gradient_fs); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, gradient_fs); free(gradient_fs); - fs_getcolor_prog = - _glamor_create_getcolor_fs_program(screen, stops_count, - (stops_count > 0)); - - dispatch->glAttachShader(gradient_prog, vs_prog); - dispatch->glAttachShader(gradient_prog, fs_getcolor_prog); - dispatch->glAttachShader(gradient_prog, fs_main_prog); + glAttachShader(gradient_prog, vs_prog); + glAttachShader(gradient_prog, fs_prog); + glDeleteShader(vs_prog); + glDeleteShader(fs_prog); - dispatch->glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, - "v_position"); - dispatch->glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, - "v_texcoord"); + glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_POS, "v_position"); + glBindAttribLocation(gradient_prog, GLAMOR_VERTEX_SOURCE, "v_texcoord"); - glamor_link_glsl_prog(dispatch, gradient_prog); + glamor_link_glsl_prog(gradient_prog); - dispatch->glUseProgram(0); + glUseProgram(0); if (dyn_gen) { index = 2; @@ -661,15 +611,8 @@ _glamor_create_linear_gradient_program(ScreenPtr screen, int stops_count, } glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][index] = gradient_prog; - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_VS_PROG][index] = - vs_prog; - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][index] = - fs_main_prog; - glamor_priv-> - linear_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][index] = - fs_getcolor_prog; - - glamor_put_dispatch(glamor_priv); + + glamor_put_context(glamor_priv); } void @@ -682,18 +625,7 @@ glamor_init_gradient_shader(ScreenPtr screen) for (i = 0; i < 3; i++) { glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][i] = 0; - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_VS_PROG][i] = 0; - glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][i] = - 0; - glamor_priv-> - linear_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][i] = 0; - glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][i] = 0; - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_VS_PROG][i] = 0; - glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][i] = - 0; - glamor_priv-> - radial_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][i] = 0; } glamor_priv->linear_max_nstops = 0; glamor_priv->radial_max_nstops = 0; @@ -709,59 +641,23 @@ void glamor_fini_gradient_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; int i = 0; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); for (i = 0; i < 3; i++) { /* Linear Gradient */ - if (glamor_priv->linear_gradient_shaders[SHADER_GRADIENT_VS_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_VS_PROG][i]); - - if (glamor_priv-> - linear_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_FS_MAIN_PROG][i]); - - if (glamor_priv-> - linear_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - linear_gradient_shaders - [SHADER_GRADIENT_FS_GETCOLOR_PROG][i]); - if (glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][i]) - dispatch->glDeleteProgram(glamor_priv-> - gradient_prog[SHADER_GRADIENT_LINEAR][i]); - - /* Radial Gradient */ - if (glamor_priv->radial_gradient_shaders[SHADER_GRADIENT_VS_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_VS_PROG][i]); - - if (glamor_priv-> - radial_gradient_shaders[SHADER_GRADIENT_FS_MAIN_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_FS_MAIN_PROG][i]); - - if (glamor_priv-> - radial_gradient_shaders[SHADER_GRADIENT_FS_GETCOLOR_PROG][i]) - dispatch->glDeleteShader(glamor_priv-> - radial_gradient_shaders - [SHADER_GRADIENT_FS_GETCOLOR_PROG][i]); + glDeleteProgram(glamor_priv->gradient_prog + [SHADER_GRADIENT_LINEAR][i]); if (glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][i]) - dispatch->glDeleteProgram(glamor_priv-> - gradient_prog[SHADER_GRADIENT_RADIAL][i]); + glDeleteProgram(glamor_priv->gradient_prog + [SHADER_GRADIENT_RADIAL][i]); } - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } static void @@ -835,7 +731,6 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen, { glamor_pixmap_private *pixmap_priv; PixmapPtr pixmap = NULL; - glamor_gl_dispatch *dispatch = NULL; pixmap = glamor_get_drawable_pixmap(dst_picture->pDrawable); pixmap_priv = glamor_get_pixmap_private(pixmap); @@ -893,17 +788,17 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen, tex_vertices[0], tex_vertices[1], tex_vertices[2], tex_vertices[3], tex_vertices[4], tex_vertices[5], tex_vertices[6], tex_vertices[7]); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 0, vertices); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, - GL_FALSE, 0, tex_vertices); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 0, vertices); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, + GL_FALSE, 0, tex_vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); return 1; } @@ -996,7 +891,6 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, PictFormatShort format) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; PicturePtr dst_picture = NULL; PixmapPtr pixmap = NULL; GLint gradient_prog = 0; @@ -1047,7 +941,7 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, GLint r2_uniform_location = 0; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); /* Create a pixmap with VBO. */ pixmap = glamor_create_pixmap(screen, @@ -1088,77 +982,74 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, } /* Bind all the uniform vars . */ - transform_mat_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "transform_mat"); - repeat_type_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "repeat_type"); - n_stop_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "n_stop"); - A_value_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "A_value"); - repeat_type_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "repeat_type"); - c1_uniform_location = dispatch->glGetUniformLocation(gradient_prog, "c1"); - r1_uniform_location = dispatch->glGetUniformLocation(gradient_prog, "r1"); - c2_uniform_location = dispatch->glGetUniformLocation(gradient_prog, "c2"); - r2_uniform_location = dispatch->glGetUniformLocation(gradient_prog, "r2"); + transform_mat_uniform_location = glGetUniformLocation(gradient_prog, + "transform_mat"); + repeat_type_uniform_location = glGetUniformLocation(gradient_prog, + "repeat_type"); + n_stop_uniform_location = glGetUniformLocation(gradient_prog, "n_stop"); + A_value_uniform_location = glGetUniformLocation(gradient_prog, "A_value"); + repeat_type_uniform_location =glGetUniformLocation(gradient_prog, + "repeat_type"); + c1_uniform_location = glGetUniformLocation(gradient_prog, "c1"); + r1_uniform_location = glGetUniformLocation(gradient_prog, "r1"); + c2_uniform_location = glGetUniformLocation(gradient_prog, "c2"); + r2_uniform_location = glGetUniformLocation(gradient_prog, "r2"); if (src_picture->pSourcePict->radial.nstops + 2 <= RADIAL_SMALL_STOPS) { stop0_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop0"); + glGetUniformLocation(gradient_prog, "stop0"); stop1_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop1"); + glGetUniformLocation(gradient_prog, "stop1"); stop2_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop2"); + glGetUniformLocation(gradient_prog, "stop2"); stop3_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop3"); + glGetUniformLocation(gradient_prog, "stop3"); stop4_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop4"); + glGetUniformLocation(gradient_prog, "stop4"); stop5_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop5"); + glGetUniformLocation(gradient_prog, "stop5"); stop6_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop6"); + glGetUniformLocation(gradient_prog, "stop6"); stop7_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop7"); + glGetUniformLocation(gradient_prog, "stop7"); stop_color0_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color0"); + glGetUniformLocation(gradient_prog, "stop_color0"); stop_color1_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color1"); + glGetUniformLocation(gradient_prog, "stop_color1"); stop_color2_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color2"); + glGetUniformLocation(gradient_prog, "stop_color2"); stop_color3_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color3"); + glGetUniformLocation(gradient_prog, "stop_color3"); stop_color4_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color4"); + glGetUniformLocation(gradient_prog, "stop_color4"); stop_color5_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color5"); + glGetUniformLocation(gradient_prog, "stop_color5"); stop_color6_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color6"); + glGetUniformLocation(gradient_prog, "stop_color6"); stop_color7_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color7"); + glGetUniformLocation(gradient_prog, "stop_color7"); } else { stops_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stops"); + glGetUniformLocation(gradient_prog, "stops"); stop_colors_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_colors"); + glGetUniformLocation(gradient_prog, "stop_colors"); } - dispatch->glUseProgram(gradient_prog); + glUseProgram(gradient_prog); - dispatch->glUniform1i(repeat_type_uniform_location, - src_picture->repeatType); + glUniform1i(repeat_type_uniform_location, src_picture->repeatType); if (src_picture->transform) { _glamor_gradient_convert_trans_matrix(src_picture->transform, transform_mat, width, height, 0); - dispatch->glUniformMatrix3fv(transform_mat_uniform_location, - 1, 1, &transform_mat[0][0]); + glUniformMatrix3fv(transform_mat_uniform_location, + 1, 1, &transform_mat[0][0]); } else { - dispatch->glUniformMatrix3fv(transform_mat_uniform_location, - 1, 1, &identity_mat[0][0]); + glUniformMatrix3fv(transform_mat_uniform_location, + 1, 1, &identity_mat[0][0]); } if (!_glamor_gradient_set_pixmap_destination @@ -1193,54 +1084,53 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, if (src_picture->pSourcePict->linear.nstops + 2 <= RADIAL_SMALL_STOPS) { int j = 0; - dispatch->glUniform4f(stop_color0_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color0_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color1_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color1_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color2_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color2_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color3_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color3_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color4_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color4_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color5_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color5_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color6_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color6_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color7_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color7_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j = 0; - dispatch->glUniform1f(stop0_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop1_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop2_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop3_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop4_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop5_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop6_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop7_uniform_location, n_stops[j++]); - dispatch->glUniform1i(n_stop_uniform_location, count); + glUniform1f(stop0_uniform_location, n_stops[j++]); + glUniform1f(stop1_uniform_location, n_stops[j++]); + glUniform1f(stop2_uniform_location, n_stops[j++]); + glUniform1f(stop3_uniform_location, n_stops[j++]); + glUniform1f(stop4_uniform_location, n_stops[j++]); + glUniform1f(stop5_uniform_location, n_stops[j++]); + glUniform1f(stop6_uniform_location, n_stops[j++]); + glUniform1f(stop7_uniform_location, n_stops[j++]); + glUniform1i(n_stop_uniform_location, count); } else { - dispatch->glUniform4fv(stop_colors_uniform_location, count, - stop_colors); - dispatch->glUniform1fv(stops_uniform_location, count, n_stops); - dispatch->glUniform1i(n_stop_uniform_location, count); + glUniform4fv(stop_colors_uniform_location, count, stop_colors); + glUniform1fv(stops_uniform_location, count, n_stops); + glUniform1i(n_stop_uniform_location, count); } c1x = (float) pixman_fixed_to_double(src_picture->pSourcePict->radial.c1.x); @@ -1255,25 +1145,25 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, glamor_set_circle_centre(width, height, c1x, c1y, glamor_priv->yInverted, cxy); - dispatch->glUniform2fv(c1_uniform_location, 1, cxy); - dispatch->glUniform1f(r1_uniform_location, r1); + glUniform2fv(c1_uniform_location, 1, cxy); + glUniform1f(r1_uniform_location, r1); glamor_set_circle_centre(width, height, c2x, c2y, glamor_priv->yInverted, cxy); - dispatch->glUniform2fv(c2_uniform_location, 1, cxy); - dispatch->glUniform1f(r2_uniform_location, r2); + glUniform2fv(c2_uniform_location, 1, cxy); + glUniform1f(r2_uniform_location, r2); A_value = (c2x - c1x) * (c2x - c1x) + (c2y - c1y) * (c2y - c1y) - (r2 - r1) * (r2 - r1); - dispatch->glUniform1f(A_value_uniform_location, A_value); + glUniform1f(A_value_uniform_location, A_value); DEBUGF("C1:(%f, %f) R1:%f\nC2:(%f, %f) R2:%f\nA = %f\n", c1x, c1y, r1, c2x, c2y, r2, A_value); /* Now rendering. */ - dispatch->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); /* Do the clear logic. */ if (stops_count > RADIAL_SMALL_STOPS) { @@ -1281,14 +1171,14 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, free(stop_colors); } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); return dst_picture; GRADIENT_FAIL: @@ -1303,13 +1193,13 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, free(stop_colors); } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); + glamor_put_context(glamor_priv); return NULL; } @@ -1321,7 +1211,6 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, PictFormatShort format) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; PicturePtr dst_picture = NULL; PixmapPtr pixmap = NULL; GLint gradient_prog = 0; @@ -1374,7 +1263,7 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, GLint pt_distance_uniform_location = 0; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); /* Create a pixmap with VBO. */ pixmap = glamor_create_pixmap(screen, @@ -1417,79 +1306,78 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, /* Bind all the uniform vars . */ n_stop_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "n_stop"); + glGetUniformLocation(gradient_prog, "n_stop"); pt_slope_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "pt_slope"); + glGetUniformLocation(gradient_prog, "pt_slope"); repeat_type_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "repeat_type"); + glGetUniformLocation(gradient_prog, "repeat_type"); hor_ver_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "hor_ver"); + glGetUniformLocation(gradient_prog, "hor_ver"); transform_mat_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "transform_mat"); + glGetUniformLocation(gradient_prog, "transform_mat"); cos_val_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "cos_val"); + glGetUniformLocation(gradient_prog, "cos_val"); p1_distance_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "p1_distance"); + glGetUniformLocation(gradient_prog, "p1_distance"); pt_distance_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "pt_distance"); + glGetUniformLocation(gradient_prog, "pt_distance"); if (src_picture->pSourcePict->linear.nstops + 2 <= LINEAR_SMALL_STOPS) { stop0_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop0"); + glGetUniformLocation(gradient_prog, "stop0"); stop1_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop1"); + glGetUniformLocation(gradient_prog, "stop1"); stop2_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop2"); + glGetUniformLocation(gradient_prog, "stop2"); stop3_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop3"); + glGetUniformLocation(gradient_prog, "stop3"); stop4_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop4"); + glGetUniformLocation(gradient_prog, "stop4"); stop5_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop5"); + glGetUniformLocation(gradient_prog, "stop5"); stop6_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop6"); + glGetUniformLocation(gradient_prog, "stop6"); stop7_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop7"); + glGetUniformLocation(gradient_prog, "stop7"); stop_color0_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color0"); + glGetUniformLocation(gradient_prog, "stop_color0"); stop_color1_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color1"); + glGetUniformLocation(gradient_prog, "stop_color1"); stop_color2_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color2"); + glGetUniformLocation(gradient_prog, "stop_color2"); stop_color3_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color3"); + glGetUniformLocation(gradient_prog, "stop_color3"); stop_color4_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color4"); + glGetUniformLocation(gradient_prog, "stop_color4"); stop_color5_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color5"); + glGetUniformLocation(gradient_prog, "stop_color5"); stop_color6_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color6"); + glGetUniformLocation(gradient_prog, "stop_color6"); stop_color7_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_color7"); + glGetUniformLocation(gradient_prog, "stop_color7"); } else { stops_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stops"); + glGetUniformLocation(gradient_prog, "stops"); stop_colors_uniform_location = - dispatch->glGetUniformLocation(gradient_prog, "stop_colors"); + glGetUniformLocation(gradient_prog, "stop_colors"); } - dispatch->glUseProgram(gradient_prog); + glUseProgram(gradient_prog); - dispatch->glUniform1i(repeat_type_uniform_location, - src_picture->repeatType); + glUniform1i(repeat_type_uniform_location, src_picture->repeatType); /* set the transform matrix. */ if (src_picture->transform) { _glamor_gradient_convert_trans_matrix(src_picture->transform, transform_mat, width, height, 1); - dispatch->glUniformMatrix3fv(transform_mat_uniform_location, - 1, 1, &transform_mat[0][0]); + glUniformMatrix3fv(transform_mat_uniform_location, + 1, 1, &transform_mat[0][0]); } else { - dispatch->glUniformMatrix3fv(transform_mat_uniform_location, - 1, 1, &identity_mat[0][0]); + glUniformMatrix3fv(transform_mat_uniform_location, + 1, 1, &identity_mat[0][0]); } if (!_glamor_gradient_set_pixmap_destination @@ -1547,66 +1435,65 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, if (src_picture->pSourcePict->linear.nstops + 2 <= LINEAR_SMALL_STOPS) { int j = 0; - dispatch->glUniform4f(stop_color0_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color0_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color1_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color1_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color2_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color2_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color3_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color3_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color4_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color4_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color5_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color5_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color6_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color6_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j++; - dispatch->glUniform4f(stop_color7_uniform_location, - stop_colors[4 * j + 0], stop_colors[4 * j + 1], - stop_colors[4 * j + 2], stop_colors[4 * j + 3]); + glUniform4f(stop_color7_uniform_location, + stop_colors[4 * j + 0], stop_colors[4 * j + 1], + stop_colors[4 * j + 2], stop_colors[4 * j + 3]); j = 0; - dispatch->glUniform1f(stop0_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop1_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop2_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop3_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop4_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop5_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop6_uniform_location, n_stops[j++]); - dispatch->glUniform1f(stop7_uniform_location, n_stops[j++]); - - dispatch->glUniform1i(n_stop_uniform_location, count); + glUniform1f(stop0_uniform_location, n_stops[j++]); + glUniform1f(stop1_uniform_location, n_stops[j++]); + glUniform1f(stop2_uniform_location, n_stops[j++]); + glUniform1f(stop3_uniform_location, n_stops[j++]); + glUniform1f(stop4_uniform_location, n_stops[j++]); + glUniform1f(stop5_uniform_location, n_stops[j++]); + glUniform1f(stop6_uniform_location, n_stops[j++]); + glUniform1f(stop7_uniform_location, n_stops[j++]); + + glUniform1i(n_stop_uniform_location, count); } else { - dispatch->glUniform4fv(stop_colors_uniform_location, count, - stop_colors); - dispatch->glUniform1fv(stops_uniform_location, count, n_stops); - dispatch->glUniform1i(n_stop_uniform_location, count); + glUniform4fv(stop_colors_uniform_location, count, stop_colors); + glUniform1fv(stops_uniform_location, count, n_stops); + glUniform1i(n_stop_uniform_location, count); } if (src_picture->pSourcePict->linear.p2.y == src_picture->pSourcePict->linear.p1.y) { // The horizontal case. - dispatch->glUniform1i(hor_ver_uniform_location, 1); + glUniform1i(hor_ver_uniform_location, 1); DEBUGF("p1.y: %f, p2.y: %f, enter the horizontal case\n", pt1[1], pt2[1]); p1_distance = pt1[0]; pt_distance = (pt2[0] - p1_distance); - dispatch->glUniform1f(p1_distance_uniform_location, p1_distance); - dispatch->glUniform1f(pt_distance_uniform_location, pt_distance); + glUniform1f(p1_distance_uniform_location, p1_distance); + glUniform1f(pt_distance_uniform_location, pt_distance); } else { /* The slope need to compute here. In shader, the viewport set will change @@ -1616,20 +1503,20 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, (float) (src_picture->pSourcePict->linear.p2.y - src_picture->pSourcePict->linear.p1.y); slope = slope * yscale / xscale; - dispatch->glUniform1f(pt_slope_uniform_location, slope); - dispatch->glUniform1i(hor_ver_uniform_location, 0); + glUniform1f(pt_slope_uniform_location, slope); + glUniform1i(hor_ver_uniform_location, 0); cos_val = sqrt(1.0 / (slope * slope + 1.0)); - dispatch->glUniform1f(cos_val_uniform_location, cos_val); + glUniform1f(cos_val_uniform_location, cos_val); p1_distance = (pt1[1] - pt1[0] * slope) * cos_val; pt_distance = (pt2[1] - pt2[0] * slope) * cos_val - p1_distance; - dispatch->glUniform1f(p1_distance_uniform_location, p1_distance); - dispatch->glUniform1f(pt_distance_uniform_location, pt_distance); + glUniform1f(p1_distance_uniform_location, p1_distance); + glUniform1f(pt_distance_uniform_location, pt_distance); } /* Now rendering. */ - dispatch->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); /* Do the clear logic. */ if (stops_count > LINEAR_SMALL_STOPS) { @@ -1637,14 +1524,14 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, free(stop_colors); } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); return dst_picture; GRADIENT_FAIL: @@ -1659,13 +1546,13 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, free(stop_colors); } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); + glamor_put_context(glamor_priv); return NULL; } diff --git a/xorg-server/glamor/glamor_picture.c b/xorg-server/glamor/glamor_picture.c index f51a7e459..8bbe2e98b 100644 --- a/xorg-server/glamor/glamor_picture.c +++ b/xorg-server/glamor/glamor_picture.c @@ -93,8 +93,7 @@ glamor_create_picture(PicturePtr picture) * we have to mark this pixmap as a separated texture, and don't * fallback to DDX layer. */ if (pixmap_priv->type == GLAMOR_TEXTURE_DRM - && !glamor_pict_format_is_compatible(picture->format, - pixmap->drawable.depth)) + && !glamor_pict_format_is_compatible(picture)) glamor_set_pixmap_type(pixmap, GLAMOR_SEPARATE_TEXTURE); } } diff --git a/xorg-server/glamor/glamor_pixmap.c b/xorg-server/glamor/glamor_pixmap.c index f7de59c39..77197b5d1 100644 --- a/xorg-server/glamor/glamor_pixmap.c +++ b/xorg-server/glamor/glamor_pixmap.c @@ -66,18 +66,12 @@ void glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo *fbo, int x0, int y0, int width, int height) { - glamor_gl_dispatch *dispatch = glamor_get_dispatch(fbo->glamor_priv); - - dispatch->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb); -#ifndef GLAMOR_GLES2 - dispatch->glMatrixMode(GL_PROJECTION); - dispatch->glLoadIdentity(); - dispatch->glMatrixMode(GL_MODELVIEW); - dispatch->glLoadIdentity(); -#endif - dispatch->glViewport(x0, y0, width, height); + glamor_get_context(fbo->glamor_priv); + + glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb); + glViewport(x0, y0, width, height); - glamor_put_dispatch(fbo->glamor_priv); + glamor_put_context(fbo->glamor_priv); } void @@ -121,71 +115,387 @@ glamor_set_planemask(PixmapPtr pixmap, unsigned long planemask) } Bool -glamor_set_alu(struct glamor_gl_dispatch *dispatch, unsigned char alu) +glamor_set_alu(ScreenPtr screen, unsigned char alu) { -#ifndef GLAMOR_GLES2 + glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); + + if (glamor_priv->gl_flavor == GLAMOR_GL_ES2) { + if (alu != GXcopy) + return FALSE; + else + return TRUE; + } + if (alu == GXcopy) { - dispatch->glDisable(GL_COLOR_LOGIC_OP); + glDisable(GL_COLOR_LOGIC_OP); return TRUE; } - dispatch->glEnable(GL_COLOR_LOGIC_OP); + glEnable(GL_COLOR_LOGIC_OP); switch (alu) { case GXclear: - dispatch->glLogicOp(GL_CLEAR); + glLogicOp(GL_CLEAR); break; case GXand: - dispatch->glLogicOp(GL_AND); + glLogicOp(GL_AND); break; case GXandReverse: - dispatch->glLogicOp(GL_AND_REVERSE); + glLogicOp(GL_AND_REVERSE); break; case GXandInverted: - dispatch->glLogicOp(GL_AND_INVERTED); + glLogicOp(GL_AND_INVERTED); break; case GXnoop: - dispatch->glLogicOp(GL_NOOP); + glLogicOp(GL_NOOP); break; case GXxor: - dispatch->glLogicOp(GL_XOR); + glLogicOp(GL_XOR); break; case GXor: - dispatch->glLogicOp(GL_OR); + glLogicOp(GL_OR); break; case GXnor: - dispatch->glLogicOp(GL_NOR); + glLogicOp(GL_NOR); break; case GXequiv: - dispatch->glLogicOp(GL_EQUIV); + glLogicOp(GL_EQUIV); break; case GXinvert: - dispatch->glLogicOp(GL_INVERT); + glLogicOp(GL_INVERT); break; case GXorReverse: - dispatch->glLogicOp(GL_OR_REVERSE); + glLogicOp(GL_OR_REVERSE); break; case GXcopyInverted: - dispatch->glLogicOp(GL_COPY_INVERTED); + glLogicOp(GL_COPY_INVERTED); break; case GXorInverted: - dispatch->glLogicOp(GL_OR_INVERTED); + glLogicOp(GL_OR_INVERTED); break; case GXnand: - dispatch->glLogicOp(GL_NAND); + glLogicOp(GL_NAND); break; case GXset: - dispatch->glLogicOp(GL_SET); + glLogicOp(GL_SET); break; default: glamor_fallback("unsupported alu %x\n", alu); return FALSE; } -#else - if (alu != GXcopy) - return FALSE; -#endif + return TRUE; } +/* + * Map picture's format to the correct gl texture format and type. + * no_alpha is used to indicate whehter we need to wire alpha to 1. + * + * Although opengl support A1/GL_BITMAP, we still don't use it + * here, it seems that mesa has bugs when uploading a A1 bitmap. + * + * Return 0 if find a matched texture type. Otherwise return -1. + **/ +static int +glamor_get_tex_format_type_from_pictformat_gl(PictFormatShort format, + GLenum *tex_format, + GLenum *tex_type, + int *no_alpha, + int *revert, + int *swap_rb, int is_upload) +{ + *no_alpha = 0; + *revert = REVERT_NONE; + *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING; + switch (format) { + case PICT_a1: + *tex_format = GL_ALPHA; + *tex_type = GL_UNSIGNED_BYTE; + *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1; + break; + case PICT_b8g8r8x8: + *no_alpha = 1; + case PICT_b8g8r8a8: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_INT_8_8_8_8; + break; + + case PICT_x8r8g8b8: + *no_alpha = 1; + case PICT_a8r8g8b8: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + case PICT_x8b8g8r8: + *no_alpha = 1; + case PICT_a8b8g8r8: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + case PICT_x2r10g10b10: + *no_alpha = 1; + case PICT_a2r10g10b10: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV; + break; + case PICT_x2b10g10r10: + *no_alpha = 1; + case PICT_a2b10g10r10: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV; + break; + + case PICT_r5g6b5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5; + break; + case PICT_b5g6r5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV; + break; + case PICT_x1b5g5r5: + *no_alpha = 1; + case PICT_a1b5g5r5: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + break; + + case PICT_x1r5g5b5: + *no_alpha = 1; + case PICT_a1r5g5b5: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + break; + case PICT_a8: + *tex_format = GL_ALPHA; + *tex_type = GL_UNSIGNED_BYTE; + break; + case PICT_x4r4g4b4: + *no_alpha = 1; + case PICT_a4r4g4b4: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; + break; + + case PICT_x4b4g4r4: + *no_alpha = 1; + case PICT_a4b4g4r4: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; + break; + + default: + LogMessageVerb(X_INFO, 0, + "fail to get matched format for %x \n", format); + return -1; + } + return 0; +} + +#define IS_LITTLE_ENDIAN (IMAGE_BYTE_ORDER == LSBFirst) + +static int +glamor_get_tex_format_type_from_pictformat_gles2(PictFormatShort format, + GLenum *tex_format, + GLenum *tex_type, + int *no_alpha, + int *revert, + int *swap_rb, int is_upload) +{ + int need_swap_rb = 0; + + *no_alpha = 0; + *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL; + + switch (format) { + case PICT_b8g8r8x8: + *no_alpha = 1; + case PICT_b8g8r8a8: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_BYTE; + need_swap_rb = 1; + *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; + break; + + case PICT_x8r8g8b8: + *no_alpha = 1; + case PICT_a8r8g8b8: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_BYTE; + need_swap_rb = 1; + break; + + case PICT_x8b8g8r8: + *no_alpha = 1; + case PICT_a8b8g8r8: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_BYTE; + break; + + case PICT_x2r10g10b10: + *no_alpha = 1; + case PICT_a2r10g10b10: + *tex_format = GL_RGBA; + /* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2. + * we have to use GL_UNSIGNED_BYTE and do the conversion in + * shader latter.*/ + *tex_type = GL_UNSIGNED_BYTE; + if (is_upload == 1) { + if (!IS_LITTLE_ENDIAN) + *revert = REVERT_UPLOADING_10_10_10_2; + else + *revert = REVERT_UPLOADING_2_10_10_10; + } + else { + if (!IS_LITTLE_ENDIAN) { + *revert = REVERT_DOWNLOADING_10_10_10_2; + } + else { + *revert = REVERT_DOWNLOADING_2_10_10_10; + } + } + need_swap_rb = 1; + + break; + + case PICT_x2b10g10r10: + *no_alpha = 1; + case PICT_a2b10g10r10: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_BYTE; + if (is_upload == 1) { + if (!IS_LITTLE_ENDIAN) + *revert = REVERT_UPLOADING_10_10_10_2; + else + *revert = REVERT_UPLOADING_2_10_10_10; + } + else { + if (!IS_LITTLE_ENDIAN) { + *revert = REVERT_DOWNLOADING_10_10_10_2; + } + else { + *revert = REVERT_DOWNLOADING_2_10_10_10; + } + } + break; + + case PICT_r5g6b5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5; + *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL; + + break; + + case PICT_b5g6r5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5; + need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;; + break; + + case PICT_x1b5g5r5: + *no_alpha = 1; + case PICT_a1b5g5r5: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_5_5_5_1; + if (IS_LITTLE_ENDIAN) { + *revert = + is_upload ? REVERT_UPLOADING_1_5_5_5 : + REVERT_DOWNLOADING_1_5_5_5; + } + else + *revert = REVERT_NONE; + break; + + case PICT_x1r5g5b5: + *no_alpha = 1; + case PICT_a1r5g5b5: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_5_5_5_1; + if (IS_LITTLE_ENDIAN) { + *revert = + is_upload ? REVERT_UPLOADING_1_5_5_5 : + REVERT_DOWNLOADING_1_5_5_5; + } + else + *revert = REVERT_NONE; + need_swap_rb = 1; + break; + + case PICT_a1: + *tex_format = GL_ALPHA; + *tex_type = GL_UNSIGNED_BYTE; + *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1; + break; + + case PICT_a8: + *tex_format = GL_ALPHA; + *tex_type = GL_UNSIGNED_BYTE; + *revert = REVERT_NONE; + break; + + case PICT_x4r4g4b4: + *no_alpha = 1; + case PICT_a4r4g4b4: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4; + *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; + need_swap_rb = 1; + break; + + case PICT_x4b4g4r4: + *no_alpha = 1; + case PICT_a4b4g4r4: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4; + *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; + break; + + default: + LogMessageVerb(X_INFO, 0, + "fail to get matched format for %x \n", format); + return -1; + } + + if (need_swap_rb) + *swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING; + else + *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING; + return 0; +} + +static int +glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap, + GLenum *format, + GLenum *type, + int *no_alpha, + int *revert, int *swap_rb, int is_upload) +{ + glamor_pixmap_private *pixmap_priv; + PictFormatShort pict_format; + glamor_screen_private *glamor_priv = + glamor_get_screen_private(pixmap->drawable.pScreen); + + pixmap_priv = glamor_get_pixmap_private(pixmap); + if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv)) + pict_format = pixmap_priv->base.picture->format; + else + pict_format = format_for_depth(pixmap->drawable.depth); + + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + return glamor_get_tex_format_type_from_pictformat_gl(pict_format, + format, type, + no_alpha, + revert, + swap_rb, + is_upload); + } else { + return glamor_get_tex_format_type_from_pictformat_gles2(pict_format, + format, type, + no_alpha, + revert, + swap_rb, + is_upload); + } +} + static void * _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h, int stride, int revert) @@ -397,38 +707,35 @@ __glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex, { glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen); - glamor_gl_dispatch *dispatch; int non_sub = 0; unsigned int iformat = 0; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (*tex == 0) { - dispatch->glGenTextures(1, tex); + glGenTextures(1, tex); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - gl_iformat_for_depth(pixmap->drawable.depth, &iformat); + iformat = gl_iformat_for_pixmap(pixmap); else iformat = format; non_sub = 1; assert(x == 0 && y == 0); } - 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->glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + 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); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); if (bits == NULL) - dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); if (non_sub) - dispatch->glTexImage2D(GL_TEXTURE_2D, - 0, iformat, w, h, 0, format, type, bits); + glTexImage2D(GL_TEXTURE_2D, 0, iformat, w, h, 0, format, type, bits); else - dispatch->glTexSubImage2D(GL_TEXTURE_2D, - 0, x, y, w, h, format, type, bits); + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, type, bits); if (bits == NULL) - dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glamor_put_dispatch(glamor_priv); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glamor_put_context(glamor_priv); } static Bool @@ -440,7 +747,6 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format, glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap); glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen); - glamor_gl_dispatch *dispatch; static float vertices[8]; static float texcoords[8] = { 0, 1, @@ -526,42 +832,35 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format, x + w, y + h, glamor_priv->yInverted, vertices); /* Slow path, we need to flip y or wire alpha to 1. */ - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), ptexcoords); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glamor_get_context(glamor_priv); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), vertices); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), ptexcoords); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); glamor_set_destination_pixmap_priv_nc(pixmap_priv); __glamor_upload_pixmap_to_texture(pixmap, &tex, format, type, 0, 0, w, h, bits, pbo); - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glBindTexture(GL_TEXTURE_2D, tex); + glActiveTexture(GL_TEXTURE0); + 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); -#ifndef GLAMOR_GLES2 - dispatch->glEnable(GL_TEXTURE_2D); -#endif - dispatch->glUseProgram(glamor_priv->finish_access_prog[no_alpha]); - dispatch->glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert); - dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], - swap_rb); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glUseProgram(glamor_priv->finish_access_prog[no_alpha]); + glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert); + glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); -#ifndef GLAMOR_GLES2 - dispatch->glDisable(GL_TEXTURE_2D); -#endif - dispatch->glUseProgram(0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glDeleteTextures(1, &tex); - dispatch->glBindFramebuffer(GL_FRAMEBUFFER, 0); + glUseProgram(0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDeleteTextures(1, &tex); + glBindFramebuffer(GL_FRAMEBUFFER, 0); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); if (need_free_bits) free(bits); @@ -615,7 +914,7 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha, return 0; if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - gl_iformat_for_depth(pixmap->drawable.depth, &iformat); + iformat = gl_iformat_for_pixmap(pixmap); else iformat = format; @@ -831,7 +1130,6 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, glamor_screen_private *glamor_priv; ScreenPtr screen; glamor_pixmap_fbo *temp_fbo; - glamor_gl_dispatch *dispatch; float temp_xscale, temp_yscale, source_xscale, source_yscale; static float vertices[8]; static float texcoords[8]; @@ -844,7 +1142,7 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, if (temp_fbo == NULL) return NULL; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); temp_xscale = 1.0 / w; temp_yscale = 1.0 / h; @@ -852,9 +1150,9 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, temp_xscale, temp_yscale, 0, 0, w, h, glamor_priv->yInverted, vertices); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(float), vertices); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); pixmap_priv_get_scale(source_priv, &source_xscale, &source_yscale); glamor_set_normalize_tcoords(source_priv, source_xscale, @@ -863,27 +1161,26 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, x + w, y + h, glamor_priv->yInverted, texcoords); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), texcoords); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(float), texcoords); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glBindTexture(GL_TEXTURE_2D, source_priv->base.fbo->tex); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, source_priv->base.fbo->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glamor_set_destination_pixmap_fbo(temp_fbo, 0, 0, w, h); - dispatch->glUseProgram(glamor_priv->finish_access_prog[no_alpha]); - dispatch->glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert); - dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], - swap_rb); + glUseProgram(glamor_priv->finish_access_prog[no_alpha]); + glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert); + glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glUseProgram(0); + glamor_put_context(glamor_priv); return temp_fbo; } @@ -905,7 +1202,6 @@ _glamor_download_sub_pixmap_to_cpu(PixmapPtr pixmap, GLenum format, void *data, *read; glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen); - glamor_gl_dispatch *dispatch; glamor_pixmap_fbo *temp_fbo = NULL; int need_post_conversion = 0; int need_free_data = 0; @@ -964,57 +1260,53 @@ _glamor_download_sub_pixmap_to_cpu(PixmapPtr pixmap, GLenum format, fbo_y_off = 0; } - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glPixelStorei(GL_PACK_ALIGNMENT, 4); + glamor_get_context(glamor_priv); + glPixelStorei(GL_PACK_ALIGNMENT, 4); if (glamor_priv->has_pack_invert || glamor_priv->yInverted) { if (!glamor_priv->yInverted) { assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP); - dispatch->glPixelStorei(GL_PACK_INVERT_MESA, 1); + glPixelStorei(GL_PACK_INVERT_MESA, 1); } if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP && data == NULL) { assert(pbo > 0); - dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); - dispatch->glBufferData(GL_PIXEL_PACK_BUFFER, - stride * h, NULL, gl_usage); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + glBufferData(GL_PIXEL_PACK_BUFFER, stride * h, NULL, gl_usage); } - dispatch->glReadPixels(x + fbo_x_off, y + fbo_y_off, w, h, format, type, - data); + glReadPixels(x + fbo_x_off, y + fbo_y_off, w, h, format, type, data); if (!glamor_priv->yInverted) { assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP); - dispatch->glPixelStorei(GL_PACK_INVERT_MESA, 0); + glPixelStorei(GL_PACK_INVERT_MESA, 0); } if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP && bits == NULL) { - bits = dispatch->glMapBuffer(GL_PIXEL_PACK_BUFFER, gl_access); - dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + bits = glMapBuffer(GL_PIXEL_PACK_BUFFER, gl_access); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); } } else { unsigned int temp_pbo; int yy; - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glGenBuffers(1, &temp_pbo); - dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, temp_pbo); - dispatch->glBufferData(GL_PIXEL_PACK_BUFFER, - stride * h, NULL, GL_STREAM_READ); - dispatch->glReadPixels(x + fbo_x_off, y + fbo_y_off, w, h, - format, type, 0); - read = dispatch->glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); + glamor_get_context(glamor_priv); + glGenBuffers(1, &temp_pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER, temp_pbo); + glBufferData(GL_PIXEL_PACK_BUFFER, stride * h, NULL, GL_STREAM_READ); + glReadPixels(x + fbo_x_off, y + fbo_y_off, w, h, format, type, 0); + read = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); for (yy = 0; yy < pixmap->drawable.height; yy++) memcpy((char *) data + yy * stride, (char *) read + (h - yy - 1) * stride, stride); - dispatch->glUnmapBuffer(GL_PIXEL_PACK_BUFFER); - dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - dispatch->glDeleteBuffers(1, &temp_pbo); + glUnmapBuffer(GL_PIXEL_PACK_BUFFER); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glDeleteBuffers(1, &temp_pbo); } - dispatch->glBindFramebuffer(GL_FRAMEBUFFER, 0); - glamor_put_dispatch(glamor_priv); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glamor_put_context(glamor_priv); if (need_post_conversion) { /* As OpenGL desktop version never enters here. @@ -1168,7 +1460,6 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access) void *data = NULL, *dst; glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen); - glamor_gl_dispatch *dispatch; int pbo = 0; if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) @@ -1189,10 +1480,10 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access) data = malloc(stride * pixmap->drawable.height); } else { - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (pixmap_priv->base.fbo->pbo == 0) - dispatch->glGenBuffers(1, &pixmap_priv->base.fbo->pbo); - glamor_put_dispatch(glamor_priv); + glGenBuffers(1, &pixmap_priv->base.fbo->pbo); + glamor_put_context(glamor_priv); pbo = pixmap_priv->base.fbo->pbo; } diff --git a/xorg-server/glamor/glamor_priv.h b/xorg-server/glamor/glamor_priv.h index dc3873013..fe4b42332 100644 --- a/xorg-server/glamor/glamor_priv.h +++ b/xorg-server/glamor/glamor_priv.h @@ -35,23 +35,19 @@ #endif #include "glamor.h" -#ifdef GLAMOR_GLES2 -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> - -#define GLAMOR_DEFAULT_PRECISION "precision mediump float;\n" -#include "glamor_glext.h" -#else -#include <GL/gl.h> -#include <GL/glext.h> -#define GLAMOR_DEFAULT_PRECISION -#endif +#include <epoxy/gl.h> + +#define GLAMOR_DEFAULT_PRECISION \ + "#ifdef GL_ES\n" \ + "precision mediump float;\n" \ + "#endif\n" #ifdef RENDER #include "glyphstr.h" #endif #include "glamor_debug.h" +#include "glamor_context.h" #include <list.h> @@ -145,13 +141,6 @@ enum gradient_shader { SHADER_GRADIENT_COUNT, }; -enum gradient_shader_prog { - SHADER_GRADIENT_VS_PROG, - SHADER_GRADIENT_FS_MAIN_PROG, - SHADER_GRADIENT_FS_GETCOLOR_PROG, - SHADER_GRADIENT_PROG_COUNT, -}; - struct glamor_screen_private; struct glamor_pixmap_private; @@ -178,8 +167,6 @@ typedef struct { uint16_t evict; } glamor_glyph_cache_t; -#include "glamor_gl_dispatch.h" - struct glamor_saved_procs { CloseScreenProcPtr close_screen; CreateGCProcPtr create_gc; @@ -202,11 +189,7 @@ struct glamor_saved_procs { SetWindowPixmapProcPtr set_window_pixmap; }; -#ifdef GLAMOR_GLES2 #define CACHE_FORMAT_COUNT 3 -#else -#define CACHE_FORMAT_COUNT 2 -#endif #define CACHE_BUCKET_WCOUNT 4 #define CACHE_BUCKET_HCOUNT 4 @@ -220,8 +203,7 @@ struct glamor_saved_procs { #define RENDER_IDEL_MAX 32 typedef struct glamor_screen_private { - struct glamor_gl_dispatch _dispatch; - int yInverted; + Bool yInverted; unsigned int tick; enum glamor_gl_flavor gl_flavor; int has_pack_invert; @@ -262,9 +244,7 @@ typedef struct glamor_screen_private { /* glamor gradient, 0 for small nstops, 1 for large nstops and 2 for dynamic generate. */ GLint gradient_prog[SHADER_GRADIENT_COUNT][3]; - GLint linear_gradient_shaders[SHADER_GRADIENT_PROG_COUNT][3]; int linear_max_nstops; - GLint radial_gradient_shaders[SHADER_GRADIENT_PROG_COUNT][3]; int radial_max_nstops; /* glamor trapezoid shader. */ @@ -288,6 +268,8 @@ typedef struct glamor_screen_private { /* xv */ GLint xv_prog; + + struct glamor_context ctx; } glamor_screen_private; typedef enum glamor_access { @@ -583,9 +565,8 @@ Bool glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple, unsigned char alu, unsigned long planemask, unsigned long fg_pixel, unsigned long bg_pixel, int stipple_x, int stipple_y); -GLint glamor_compile_glsl_prog(glamor_gl_dispatch *dispatch, GLenum type, - const char *source); -void glamor_link_glsl_prog(glamor_gl_dispatch *dispatch, GLint prog); +GLint glamor_compile_glsl_prog(GLenum type, const char *source); +void glamor_link_glsl_prog(GLint prog); void glamor_get_color_4f_from_pixel(PixmapPtr pixmap, unsigned long fg_pixel, GLfloat *color); @@ -604,7 +585,7 @@ glamor_pixmap_fbo *glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int no_alpha, int revert, int swap_rb); -Bool glamor_set_alu(struct glamor_gl_dispatch *dispatch, unsigned char alu); +Bool glamor_set_alu(ScreenPtr screen, unsigned char alu); Bool glamor_set_planemask(PixmapPtr pixmap, unsigned long planemask); Bool glamor_change_window_attributes(WindowPtr pWin, unsigned long mask); RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap); @@ -935,6 +916,9 @@ void glamor_composite_rectangles(CARD8 op, xRenderColor *color, int num_rects, xRectangle *rects); +extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen, + struct glamor_context *glamor_ctx); + /* glamor_xv */ typedef struct { uint32_t transform_index; diff --git a/xorg-server/glamor/glamor_putimage.c b/xorg-server/glamor/glamor_putimage.c index 6b25bec84..702e89f14 100644 --- a/xorg-server/glamor/glamor_putimage.c +++ b/xorg-server/glamor/glamor_putimage.c @@ -67,27 +67,26 @@ glamor_init_putimage_shaders(ScreenPtr screen) if (!GLEW_ARB_fragment_shader) return; - prog = dispatch->glCreateProgram(); + prog = glCreateProgram(); vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, xybitmap_vs); fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, xybitmap_fs); - dispatch->glAttachShader(prog, vs_prog); - dispatch->glAttachShader(prog, fs_prog); + glAttachShader(prog, vs_prog); + glAttachShader(prog, fs_prog); glamor_link_glsl_prog(prog); - dispatch->glUseProgram(prog); - sampler_uniform_location = - dispatch->glGetUniformLocation(prog, "bitmap_sampler"); - dispatch->glUniform1i(sampler_uniform_location, 0); + glUseProgram(prog); + sampler_uniform_location = glGetUniformLocation(prog, "bitmap_sampler"); + glUniform1i(sampler_uniform_location, 0); glamor_priv->put_image_xybitmap_fg_uniform_location = - dispatch->glGetUniformLocation(prog, "fg"); + glGetUniformLocation(prog, "fg"); glamor_priv->put_image_xybitmap_bg_uniform_location = - dispatch->glGetUniformLocation(prog, "bg"); + glGetUniformLocation(prog, "bg"); glamor_get_transform_uniform_locations(prog, &glamor_priv-> put_image_xybitmap_transform); glamor_priv->put_image_xybitmap_prog = prog; - dispatch->glUseProgram(0); + glUseProgram(0); #endif } @@ -162,40 +161,37 @@ glamor_put_image_xybitmap(DrawablePtr drawable, GCPtr gc, if (!glamor_set_planemask(pixmap, gc->planemask)) goto fail; - dispatch->glUseProgram(glamor_priv->put_image_xybitmap_prog); + glUseProgram(glamor_priv->put_image_xybitmap_prog); glamor_get_color_4f_from_pixel(pixmap, gc->fgPixel, fg); - dispatch->glUniform4fv - (glamor_priv->put_image_xybitmap_fg_uniform_location, 1, fg); + glUniform4fv(glamor_priv->put_image_xybitmap_fg_uniform_location, 1, fg); glamor_get_color_4f_from_pixel(pixmap, gc->bgPixel, bg); - dispatch->glUniform4fv - (glamor_priv->put_image_xybitmap_bg_uniform_location, 1, bg); - - dispatch->glGenTextures(1, &tex); - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glEnable(GL_TEXTURE_2D); - 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->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, stride * 8); - dispatch->glPixelStorei(GL_UNPACK_SKIP_PIXELS, left_pad); - dispatch->glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, - w, h, 0, GL_COLOR_INDEX, GL_BITMAP, bits); - dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - dispatch->glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glUniform4fv(glamor_priv->put_image_xybitmap_bg_uniform_location, 1, bg); + + glGenTextures(1, &tex); + glActiveTexture(GL_TEXTURE0); + 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); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, stride * 8); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, left_pad); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, + w, h, 0, GL_COLOR_INDEX, GL_BITMAP, bits); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); /* Now that we've set up our bitmap texture and the shader, shove * the destination rectangle through the cliprects and run the * shader on the resulting fragments. */ - dispatch->glVertexPointer(2, GL_FLOAT, 0, dest_coords); - dispatch->glEnableClientState(GL_VERTEX_ARRAY); - dispatch->glClientActiveTexture(GL_TEXTURE0); - dispatch->glTexCoordPointer(2, GL_FLOAT, 0, bitmap_coords); - dispatch->glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, dest_coords); + glEnableClientState(GL_VERTEX_ARRAY); + glClientActiveTexture(GL_TEXTURE0); + glTexCoordPointer(2, GL_FLOAT, 0, bitmap_coords); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); - dispatch->glEnable(GL_SCISSOR_TEST); + glEnable(GL_SCISSOR_TEST); clip = fbGetCompositeClip(gc); for (nbox = REGION_NUM_RECTS(clip), box = REGION_RECTS(clip); nbox--; box++) { int x1 = x; @@ -214,19 +210,17 @@ glamor_put_image_xybitmap(DrawablePtr drawable, GCPtr gc, if (x1 >= x2 || y1 >= y2) continue; - dispatch->glScissor(box->x1, - y_flip(pixmap, box->y1), - box->x2 - box->x1, box->y2 - box->y1); - dispatch->glDrawArrays(GL_QUADS, 0, 4); + glScissor(box->x1, y_flip(pixmap, box->y1), + box->x2 - box->x1, box->y2 - box->y1); + glDrawArrays(GL_QUADS, 0, 4); } - dispatch->glDisable(GL_SCISSOR_TEST); + glDisable(GL_SCISSOR_TEST); glamor_set_alu(GXcopy); glamor_set_planemask(pixmap, ~0); - dispatch->glDeleteTextures(1, &tex); - dispatch->glDisable(GL_TEXTURE_2D); - dispatch->glDisableClientState(GL_VERTEX_ARRAY); - dispatch->glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDeleteTextures(1, &tex); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); return; glamor_set_alu(GXcopy); glamor_set_planemask(pixmap, ~0); diff --git a/xorg-server/glamor/glamor_render.c b/xorg-server/glamor/glamor_render.c index 4a3a97ccd..093a2151d 100644 --- a/xorg-server/glamor/glamor_render.c +++ b/xorg-server/glamor/glamor_render.c @@ -62,8 +62,7 @@ static struct blendinfo composite_op_info[] = { #define RepeatFix 10 static GLuint -glamor_create_composite_fs(glamor_gl_dispatch *dispatch, - struct shader_key *key) +glamor_create_composite_fs(struct shader_key *key) { const char *repeat_define = "#define RepeatNone 0\n" @@ -266,15 +265,14 @@ glamor_create_composite_fs(glamor_gl_dispatch *dispatch, XNFasprintf(&source, "%s%s%s%s%s%s", repeat_define, relocate_texture, rel_sampler, source_fetch, mask_fetch, in); - prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, source); + prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, source); free(source); return prog; } static GLuint -glamor_create_composite_vs(glamor_gl_dispatch *dispatch, - struct shader_key *key) +glamor_create_composite_vs(struct shader_key *key) { const char *main_opening = "attribute vec4 v_position;\n" @@ -304,7 +302,7 @@ glamor_create_composite_vs(glamor_gl_dispatch *dispatch, main_opening, source_coords_setup, mask_coords_setup, main_closing); - prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, source); + prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, source); free(source); return prog; @@ -317,60 +315,57 @@ glamor_create_composite_shader(ScreenPtr screen, struct shader_key *key, GLuint vs, fs, prog; GLint source_sampler_uniform_location, mask_sampler_uniform_location; glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; - dispatch = glamor_get_dispatch(glamor_priv); - vs = glamor_create_composite_vs(dispatch, key); + glamor_get_context(glamor_priv); + vs = glamor_create_composite_vs(key); if (vs == 0) goto out; - fs = glamor_create_composite_fs(dispatch, key); + fs = glamor_create_composite_fs(key); if (fs == 0) goto out; - prog = dispatch->glCreateProgram(); - dispatch->glAttachShader(prog, vs); - dispatch->glAttachShader(prog, fs); + prog = glCreateProgram(); + glAttachShader(prog, vs); + glAttachShader(prog, fs); - dispatch->glBindAttribLocation(prog, GLAMOR_VERTEX_POS, "v_position"); - dispatch->glBindAttribLocation(prog, GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - dispatch->glBindAttribLocation(prog, GLAMOR_VERTEX_MASK, "v_texcoord1"); + glBindAttribLocation(prog, GLAMOR_VERTEX_POS, "v_position"); + glBindAttribLocation(prog, GLAMOR_VERTEX_SOURCE, "v_texcoord0"); + glBindAttribLocation(prog, GLAMOR_VERTEX_MASK, "v_texcoord1"); - glamor_link_glsl_prog(dispatch, prog); + glamor_link_glsl_prog(prog); shader->prog = prog; - dispatch->glUseProgram(prog); + glUseProgram(prog); if (key->source == SHADER_SOURCE_SOLID) { - shader->source_uniform_location = - dispatch->glGetUniformLocation(prog, "source"); + shader->source_uniform_location = glGetUniformLocation(prog, "source"); } else { source_sampler_uniform_location = - dispatch->glGetUniformLocation(prog, "source_sampler"); - dispatch->glUniform1i(source_sampler_uniform_location, 0); - shader->source_wh = dispatch->glGetUniformLocation(prog, "source_wh"); + glGetUniformLocation(prog, "source_sampler"); + glUniform1i(source_sampler_uniform_location, 0); + shader->source_wh = glGetUniformLocation(prog, "source_wh"); shader->source_repeat_mode = - dispatch->glGetUniformLocation(prog, "source_repeat_mode"); + glGetUniformLocation(prog, "source_repeat_mode"); } if (key->mask != SHADER_MASK_NONE) { if (key->mask == SHADER_MASK_SOLID) { - shader->mask_uniform_location = - dispatch->glGetUniformLocation(prog, "mask"); + shader->mask_uniform_location = glGetUniformLocation(prog, "mask"); } else { mask_sampler_uniform_location = - dispatch->glGetUniformLocation(prog, "mask_sampler"); - dispatch->glUniform1i(mask_sampler_uniform_location, 1); - shader->mask_wh = dispatch->glGetUniformLocation(prog, "mask_wh"); + glGetUniformLocation(prog, "mask_sampler"); + glUniform1i(mask_sampler_uniform_location, 1); + shader->mask_wh = glGetUniformLocation(prog, "mask_wh"); shader->mask_repeat_mode = - dispatch->glGetUniformLocation(prog, "mask_repeat_mode"); + glGetUniformLocation(prog, "mask_repeat_mode"); } } out: - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } static glamor_composite_shader * @@ -407,23 +402,21 @@ void glamor_init_composite_shaders(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; unsigned short *eb; float *vb = NULL; int eb_size; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glGenBuffers(1, &glamor_priv->vbo); - dispatch->glGenBuffers(1, &glamor_priv->ebo); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); + glamor_get_context(glamor_priv); + glGenBuffers(1, &glamor_priv->vbo); + glGenBuffers(1, &glamor_priv->ebo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); eb_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(short) * 2; if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { - dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER, - eb_size, NULL, GL_STATIC_DRAW); - eb = dispatch->glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, eb_size, NULL, GL_STATIC_DRAW); + eb = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); } else { vb = malloc(GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * 2); @@ -438,51 +431,49 @@ glamor_init_composite_shaders(ScreenPtr screen) glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { - dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } else { - dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER, - eb_size, eb, GL_STATIC_DRAW); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, eb_size, eb, GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); - dispatch->glBufferData(GL_ARRAY_BUFFER, - GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * - 2, NULL, GL_DYNAMIC_DRAW); - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glBufferData(GL_ARRAY_BUFFER, + GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * + 2, NULL, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); free(eb); glamor_priv->vb = (char *) vb; } - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } void glamor_fini_composite_shaders(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_composite_shader *shader; int i, j, k; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glDeleteBuffers(1, &glamor_priv->vbo); - dispatch->glDeleteBuffers(1, &glamor_priv->ebo); + glamor_get_context(glamor_priv); + glDeleteBuffers(1, &glamor_priv->vbo); + glDeleteBuffers(1, &glamor_priv->ebo); for (i = 0; i < SHADER_SOURCE_COUNT; i++) for (j = 0; j < SHADER_MASK_COUNT; j++) for (k = 0; k < SHADER_IN_COUNT; k++) { shader = &glamor_priv->composite_shader[i][j][k]; if (shader->prog) - dispatch->glDeleteProgram(shader->prog); + glDeleteProgram(shader->prog); } if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP && glamor_priv->vb) free(glamor_priv->vb); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } static Bool @@ -535,44 +526,37 @@ glamor_set_composite_texture(glamor_screen_private *glamor_priv, int unit, glamor_pixmap_private *pixmap_priv, GLuint wh_location, GLuint repeat_location) { - glamor_gl_dispatch *dispatch; float wh[4]; int repeat_type; - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glActiveTexture(GL_TEXTURE0 + unit); - dispatch->glBindTexture(GL_TEXTURE_2D, pixmap_priv->base.fbo->tex); + glamor_get_context(glamor_priv); + glActiveTexture(GL_TEXTURE0 + unit); + glBindTexture(GL_TEXTURE_2D, pixmap_priv->base.fbo->tex); repeat_type = picture->repeatType; switch (picture->repeatType) { case RepeatNone: -#ifndef GLAMOR_GLES2 - /* XXX GLES2 doesn't support GL_CLAMP_TO_BORDER. */ - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_BORDER); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_BORDER); -#else - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); -#endif + if (glamor_priv->gl_flavor != GLAMOR_GL_ES2) { + /* XXX GLES2 doesn't support GL_CLAMP_TO_BORDER. */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, + GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, + GL_CLAMP_TO_BORDER); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } break; case RepeatNormal: - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); break; case RepeatPad: - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); break; case RepeatReflect: - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_MIRRORED_REPEAT); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); break; } @@ -580,23 +564,16 @@ glamor_set_composite_texture(glamor_screen_private *glamor_priv, int unit, default: case PictFilterFast: case PictFilterNearest: - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MIN_FILTER, GL_NEAREST); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); break; case PictFilterGood: case PictFilterBest: case PictFilterBilinear: - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MIN_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break; } -#ifndef GLAMOR_GLES2 - dispatch->glEnable(GL_TEXTURE_2D); -#endif /* * GLES2 doesn't support RepeatNone. We need to fix it anyway. @@ -615,19 +592,18 @@ glamor_set_composite_texture(glamor_screen_private *glamor_priv, int unit, if ((wh[0] != 1.0 || wh[1] != 1.0) || (glamor_priv->gl_flavor == GLAMOR_GL_ES2 && repeat_type == RepeatFix)) - dispatch->glUniform4fv(wh_location, 1, wh); + glUniform4fv(wh_location, 1, wh); else repeat_type -= RepeatFix; } - dispatch->glUniform1i(repeat_location, repeat_type); - glamor_put_dispatch(glamor_priv); + glUniform1i(repeat_location, repeat_type); + glamor_put_context(glamor_priv); } static void -glamor_set_composite_solid(glamor_gl_dispatch *dispatch, float *color, - GLint uniform_location) +glamor_set_composite_solid(float *color, GLint uniform_location) { - dispatch->glUniform4fv(uniform_location, 1, color); + glUniform4fv(uniform_location, 1, color); } static int @@ -729,7 +705,6 @@ void glamor_setup_composite_vbo(ScreenPtr screen, int n_verts) { glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; int vert_size; glamor_priv->render_nr_verts = 0; @@ -741,65 +716,54 @@ glamor_setup_composite_vbo(ScreenPtr screen, int n_verts) vert_size = n_verts * glamor_priv->vb_stride; - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glamor_get_context(glamor_priv); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { if (glamor_priv->vbo_size < (glamor_priv->vbo_offset + vert_size)) { glamor_priv->vbo_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * glamor_priv->vb_stride; glamor_priv->vbo_offset = 0; - dispatch->glBufferData(GL_ARRAY_BUFFER, - glamor_priv->vbo_size, NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, + glamor_priv->vbo_size, NULL, GL_STREAM_DRAW); } - glamor_priv->vb = dispatch->glMapBufferRange(GL_ARRAY_BUFFER, - glamor_priv->vbo_offset, - vert_size, - GL_MAP_WRITE_BIT | - GL_MAP_UNSYNCHRONIZED_BIT); + glamor_priv->vb = glMapBufferRange(GL_ARRAY_BUFFER, + glamor_priv->vbo_offset, + vert_size, + GL_MAP_WRITE_BIT | + GL_MAP_UNSYNCHRONIZED_BIT); assert(glamor_priv->vb != NULL); glamor_priv->vb -= glamor_priv->vbo_offset; } else glamor_priv->vbo_offset = 0; - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, glamor_priv->vb_stride, - (void *) ((long) - glamor_priv->vbo_offset)); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, + glamor_priv->vb_stride, + (void *) ((long) + glamor_priv->vbo_offset)); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); if (glamor_priv->has_source_coords) { - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, - GL_FLOAT, GL_FALSE, - glamor_priv->vb_stride, (void *) ((long) - glamor_priv-> - vbo_offset - + - 2 * - sizeof - (float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, + GL_FLOAT, GL_FALSE, + glamor_priv->vb_stride, + (void *) ((long) glamor_priv->vbo_offset + + 2 * sizeof(float))); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); } if (glamor_priv->has_mask_coords) { - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_MASK, 2, - GL_FLOAT, GL_FALSE, - glamor_priv->vb_stride, (void *) ((long) - glamor_priv-> - vbo_offset - + - (glamor_priv-> - has_source_coords - ? 4 : - 2) * - sizeof - (float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_MASK); - } - glamor_put_dispatch(glamor_priv); + glVertexAttribPointer(GLAMOR_VERTEX_MASK, 2, GL_FLOAT, GL_FALSE, + glamor_priv->vb_stride, + (void *) ((long) glamor_priv->vbo_offset + + (glamor_priv->has_source_coords ? + 4 : 2) * sizeof(float))); + glEnableVertexAttribArray(GLAMOR_VERTEX_MASK); + } + glamor_put_context(glamor_priv); } void @@ -831,32 +795,29 @@ static void glamor_flush_composite_rects(ScreenPtr screen) { glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - dispatch->glUnmapBuffer(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ARRAY_BUFFER); else { - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); - dispatch->glBufferData(GL_ARRAY_BUFFER, - glamor_priv->vbo_offset, - glamor_priv->vb, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glBufferData(GL_ARRAY_BUFFER, glamor_priv->vbo_offset, + glamor_priv->vb, GL_DYNAMIC_DRAW); } if (!glamor_priv->render_nr_verts) return; -#ifndef GLAMOR_GLES2 - dispatch->glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts, - (glamor_priv->render_nr_verts * 3) / 2, - GL_UNSIGNED_SHORT, NULL); -#else - dispatch->glDrawElements(GL_TRIANGLES, - (glamor_priv->render_nr_verts * 3) / 2, - GL_UNSIGNED_SHORT, NULL); -#endif - glamor_put_dispatch(glamor_priv); + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts, + (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); + } else { + glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); + } + glamor_put_context(glamor_priv); } int pict_format_combine_tab[][3] = { @@ -1228,17 +1189,15 @@ glamor_composite_set_shader_blend(glamor_pixmap_private *dest_priv, glamor_composite_shader *shader, struct blendinfo *op_info) { - glamor_gl_dispatch *dispatch; glamor_screen_private *glamor_priv; glamor_priv = dest_priv->base.glamor_priv; - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glUseProgram(shader->prog); + glamor_get_context(glamor_priv); + glUseProgram(shader->prog); if (key->source == SHADER_SOURCE_SOLID) { - glamor_set_composite_solid(dispatch, - shader->source_solid_color, + glamor_set_composite_solid(shader->source_solid_color, shader->source_uniform_location); } else { @@ -1250,8 +1209,7 @@ glamor_composite_set_shader_blend(glamor_pixmap_private *dest_priv, if (key->mask != SHADER_MASK_NONE) { if (key->mask == SHADER_MASK_SOLID) { - glamor_set_composite_solid(dispatch, - shader->mask_solid_color, + glamor_set_composite_solid(shader->mask_solid_color, shader->mask_uniform_location); } else { @@ -1263,14 +1221,14 @@ glamor_composite_set_shader_blend(glamor_pixmap_private *dest_priv, } if (op_info->source_blend == GL_ONE && op_info->dest_blend == GL_ZERO) { - dispatch->glDisable(GL_BLEND); + glDisable(GL_BLEND); } else { - dispatch->glEnable(GL_BLEND); - dispatch->glBlendFunc(op_info->source_blend, op_info->dest_blend); + glEnable(GL_BLEND); + glBlendFunc(op_info->source_blend, op_info->dest_blend); } - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } static Bool @@ -1289,7 +1247,6 @@ glamor_composite_with_shader(CARD8 op, PixmapPtr dest_pixmap = dest_pixmap_priv->base.pixmap; PixmapPtr source_pixmap = NULL; PixmapPtr mask_pixmap = NULL; - glamor_gl_dispatch *dispatch = NULL; GLfloat dst_xscale, dst_yscale; GLfloat mask_xscale = 1, mask_yscale = 1, src_xscale = 1, src_yscale = 1; struct shader_key key, key_ca; @@ -1328,7 +1285,7 @@ glamor_composite_with_shader(CARD8 op, glamor_set_destination_pixmap_priv_nc(dest_pixmap_priv); glamor_composite_set_shader_blend(dest_pixmap_priv, &key, shader, &op_info); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); glamor_priv->has_source_coords = key.source != SHADER_SOURCE_SOLID; glamor_priv->has_mask_coords = (key.mask != SHADER_MASK_NONE && @@ -1445,25 +1402,19 @@ glamor_composite_with_shader(CARD8 op, } } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_MASK); - dispatch->glDisable(GL_BLEND); -#ifndef GLAMOR_GLES2 - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glDisable(GL_TEXTURE_2D); - dispatch->glActiveTexture(GL_TEXTURE1); - dispatch->glDisable(GL_TEXTURE_2D); -#endif + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_MASK); + glDisable(GL_BLEND); DEBUGF("finish rendering.\n"); - dispatch->glUseProgram(0); + glUseProgram(0); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; if (saved_source_format) source->format = saved_source_format; - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); ret = TRUE; return ret; diff --git a/xorg-server/glamor/glamor_tile.c b/xorg-server/glamor/glamor_tile.c index 9c8e521b9..7288af30e 100644 --- a/xorg-server/glamor/glamor_tile.c +++ b/xorg-server/glamor/glamor_tile.c @@ -37,7 +37,6 @@ void glamor_init_tile_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; const char *tile_vs = "attribute vec4 v_position;\n" "attribute vec4 v_texcoord0;\n" @@ -63,40 +62,39 @@ glamor_init_tile_shader(ScreenPtr screen) GLint sampler_uniform_location; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - glamor_priv->tile_prog = dispatch->glCreateProgram(); - vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, tile_vs); - fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, tile_fs); - dispatch->glAttachShader(glamor_priv->tile_prog, vs_prog); - dispatch->glAttachShader(glamor_priv->tile_prog, fs_prog); - - dispatch->glBindAttribLocation(glamor_priv->tile_prog, - GLAMOR_VERTEX_POS, "v_position"); - dispatch->glBindAttribLocation(glamor_priv->tile_prog, - GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - glamor_link_glsl_prog(dispatch, glamor_priv->tile_prog); + glamor_get_context(glamor_priv); + glamor_priv->tile_prog = glCreateProgram(); + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, tile_vs); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, tile_fs); + glAttachShader(glamor_priv->tile_prog, vs_prog); + glAttachShader(glamor_priv->tile_prog, fs_prog); + + glBindAttribLocation(glamor_priv->tile_prog, + GLAMOR_VERTEX_POS, "v_position"); + glBindAttribLocation(glamor_priv->tile_prog, + GLAMOR_VERTEX_SOURCE, "v_texcoord0"); + glamor_link_glsl_prog(glamor_priv->tile_prog); sampler_uniform_location = - dispatch->glGetUniformLocation(glamor_priv->tile_prog, "sampler"); - dispatch->glUseProgram(glamor_priv->tile_prog); - dispatch->glUniform1i(sampler_uniform_location, 0); + glGetUniformLocation(glamor_priv->tile_prog, "sampler"); + glUseProgram(glamor_priv->tile_prog); + glUniform1i(sampler_uniform_location, 0); glamor_priv->tile_wh = - dispatch->glGetUniformLocation(glamor_priv->tile_prog, "wh"); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glGetUniformLocation(glamor_priv->tile_prog, "wh"); + glUseProgram(0); + glamor_put_context(glamor_priv); } void glamor_fini_tile_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glDeleteProgram(glamor_priv->tile_prog); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glDeleteProgram(glamor_priv->tile_prog); + glamor_put_context(glamor_priv); } static void @@ -105,7 +103,6 @@ _glamor_tile(PixmapPtr pixmap, PixmapPtr tile, { ScreenPtr screen = pixmap->drawable.pScreen; glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; int x1 = x; int x2 = x + width; int y1 = y; @@ -127,47 +124,40 @@ _glamor_tile(PixmapPtr pixmap, PixmapPtr tile, glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv); pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glUseProgram(glamor_priv->tile_prog); + glamor_get_context(glamor_priv); + glUseProgram(glamor_priv->tile_prog); glamor_pixmap_fbo_fix_wh_ratio(wh, src_pixmap_priv); - dispatch->glUniform2fv(glamor_priv->tile_wh, 1, wh); - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); -#ifndef GLAMOR_GLES2 - dispatch->glEnable(GL_TEXTURE_2D); -#endif + glUniform2fv(glamor_priv->tile_wh, 1, wh); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glamor_set_repeat_normalize_tcoords (src_pixmap_priv, RepeatNormal, src_xscale, src_yscale, tile_x1, tile_y1, tile_x2, tile_y2, glamor_priv->yInverted, source_texcoords); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, - GL_FLOAT, GL_FALSE, - 2 * sizeof(float), source_texcoords); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(float), source_texcoords); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); glamor_set_normalize_vcoords(dst_pixmap_priv, dst_xscale, dst_yscale, x1, y1, x2, y2, glamor_priv->yInverted, vertices); - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(float), vertices); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); -#ifndef GLAMOR_GLES2 - dispatch->glDisable(GL_TEXTURE_2D); -#endif - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glUseProgram(0); + glamor_put_context(glamor_priv); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; @@ -182,7 +172,6 @@ glamor_tile(PixmapPtr pixmap, PixmapPtr tile, glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); glamor_pixmap_private *dst_pixmap_priv; glamor_pixmap_private *src_pixmap_priv; - glamor_gl_dispatch *dispatch; dst_pixmap_priv = glamor_get_pixmap_private(pixmap); src_pixmap_priv = glamor_get_pixmap_private(tile); @@ -206,10 +195,10 @@ glamor_tile(PixmapPtr pixmap, PixmapPtr tile, goto fail; } - dispatch = glamor_get_dispatch(glamor_priv); - if (!glamor_set_alu(dispatch, alu)) { + glamor_get_context(glamor_priv); + if (!glamor_set_alu(screen, alu)) { glamor_fallback("unsupported alu %x\n", alu); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); goto fail; } @@ -302,8 +291,8 @@ glamor_tile(PixmapPtr pixmap, PixmapPtr tile, else _glamor_tile(pixmap, tile, x, y, width, height, tile_x, tile_y); - glamor_set_alu(dispatch, GXcopy); - glamor_put_dispatch(glamor_priv); + glamor_set_alu(screen, GXcopy); + glamor_put_context(glamor_priv); return TRUE; fail: return FALSE; diff --git a/xorg-server/glamor/glamor_trapezoid.c b/xorg-server/glamor/glamor_trapezoid.c index cd99a4782..7bc925a25 100644 --- a/xorg-server/glamor/glamor_trapezoid.c +++ b/xorg-server/glamor/glamor_trapezoid.c @@ -204,24 +204,22 @@ static void glamor_flush_composite_triangles(ScreenPtr screen) { glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - dispatch->glUnmapBuffer(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ARRAY_BUFFER); else { - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); - dispatch->glBufferData(GL_ARRAY_BUFFER, - glamor_priv->vbo_offset, - glamor_priv->vb, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glBufferData(GL_ARRAY_BUFFER, glamor_priv->vbo_offset, + glamor_priv->vb, GL_DYNAMIC_DRAW); } if (!glamor_priv->render_nr_verts) return; - dispatch->glDrawArrays(GL_TRIANGLES, 0, glamor_priv->render_nr_verts); - glamor_put_dispatch(glamor_priv); + glDrawArrays(GL_TRIANGLES, 0, glamor_priv->render_nr_verts); + glamor_put_context(glamor_priv); } static Bool @@ -582,7 +580,6 @@ static void glamor_setup_composite_vbo_for_trapezoid(ScreenPtr screen, int n_verts) { glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - glamor_gl_dispatch *dispatch; int stride; int vert_size; @@ -605,25 +602,25 @@ glamor_setup_composite_vbo_for_trapezoid(ScreenPtr screen, int n_verts) vert_size = n_verts * glamor_priv->vb_stride; - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); + glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); + glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { if (glamor_priv->vbo_size < (glamor_priv->vbo_offset + vert_size)) { glamor_priv->vbo_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * glamor_priv->vb_stride; glamor_priv->vbo_offset = 0; - dispatch->glBufferData(GL_ARRAY_BUFFER, - glamor_priv->vbo_size, NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, + glamor_priv->vbo_size, NULL, GL_STREAM_DRAW); } - glamor_priv->vb = dispatch->glMapBufferRange(GL_ARRAY_BUFFER, + glamor_priv->vb = glMapBufferRange(GL_ARRAY_BUFFER, glamor_priv->vbo_offset, vert_size, GL_MAP_WRITE_BIT | @@ -636,43 +633,43 @@ glamor_setup_composite_vbo_for_trapezoid(ScreenPtr screen, int n_verts) glamor_priv->vbo_offset = 0; } - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); /* Set the vertex pointer. */ - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, glamor_priv->vb_stride, - (void *) ((long) glamor_priv->vbo_offset)); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, glamor_priv->vb_stride, + (void *) ((long) glamor_priv->vbo_offset)); + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); stride = 2; - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, - GL_FALSE, glamor_priv->vb_stride, - (void *) ((long) glamor_priv->vbo_offset + - stride * sizeof(float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, + GL_FALSE, glamor_priv->vb_stride, + (void *) ((long) glamor_priv->vbo_offset + + stride * sizeof(float))); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); stride += 2; - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_TOP_BOTTOM, 2, GL_FLOAT, + glVertexAttribPointer(GLAMOR_VERTEX_TOP_BOTTOM, 2, GL_FLOAT, GL_FALSE, glamor_priv->vb_stride, (void *) ((long) glamor_priv->vbo_offset + stride * sizeof(float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); + glEnableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); stride += 2; - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_LEFT_PARAM, 4, GL_FLOAT, + glVertexAttribPointer(GLAMOR_VERTEX_LEFT_PARAM, 4, GL_FLOAT, GL_FALSE, glamor_priv->vb_stride, (void *) ((long) glamor_priv->vbo_offset + stride * sizeof(float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); + glEnableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); stride += 4; - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_RIGHT_PARAM, 4, GL_FLOAT, + glVertexAttribPointer(GLAMOR_VERTEX_RIGHT_PARAM, 4, GL_FLOAT, GL_FALSE, glamor_priv->vb_stride, (void *) ((long) glamor_priv->vbo_offset + stride * sizeof(float))); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); + glEnableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } static Bool @@ -701,7 +698,6 @@ _glamor_trapezoids_with_shader(CARD8 op, GLfloat dst_xscale, dst_yscale; BoxRec bounds; PicturePtr temp_src = src; - glamor_gl_dispatch *dispatch = NULL; int vert_stride = 3; int ntriangle_per_loop; int nclip_rect; @@ -815,6 +811,8 @@ _glamor_trapezoids_with_shader(CARD8 op, goto TRAPEZOID_OUT; } + glamor_get_context(glamor_priv); + box = REGION_RECTS(®ion); nbox = REGION_NUM_RECTS(®ion); pbox = box; @@ -833,8 +831,6 @@ _glamor_trapezoids_with_shader(CARD8 op, glamor_priv->has_mask_coords = (key.mask != SHADER_MASK_NONE && key.mask != SHADER_MASK_SOLID); - dispatch = glamor_get_dispatch(glamor_priv); - glamor_get_drawable_deltas(dst->pDrawable, dest_pixmap, &dest_x_off, &dest_y_off); @@ -974,19 +970,14 @@ _glamor_trapezoids_with_shader(CARD8 op, ret = TRUE; TRAPEZOID_RESET_GL: - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_MASK); - dispatch->glDisable(GL_BLEND); -#ifndef GLAMOR_GLES2 - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glDisable(GL_TEXTURE_2D); - dispatch->glActiveTexture(GL_TEXTURE1); - dispatch->glDisable(GL_TEXTURE_2D); -#endif - dispatch->glUseProgram(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_MASK); + glDisable(GL_BLEND); + glUseProgram(0); + glamor_put_context(glamor_priv); TRAPEZOID_OUT: if (box) { @@ -1002,10 +993,6 @@ _glamor_trapezoids_with_shader(CARD8 op, } } - if (dispatch) { - glamor_put_dispatch(glamor_priv); - } - return ret; } @@ -1013,7 +1000,6 @@ void glamor_init_trapezoid_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; GLint fs_prog, vs_prog; const char *trapezoid_vs = @@ -1344,46 +1330,43 @@ glamor_init_trapezoid_shader(ScreenPtr screen) "}\n"; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); - glamor_priv->trapezoid_prog = dispatch->glCreateProgram(); + glamor_priv->trapezoid_prog = glCreateProgram(); - vs_prog = glamor_compile_glsl_prog(dispatch, - GL_VERTEX_SHADER, trapezoid_vs); - fs_prog = glamor_compile_glsl_prog(dispatch, - GL_FRAGMENT_SHADER, trapezoid_fs); + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, trapezoid_vs); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, trapezoid_fs); - dispatch->glAttachShader(glamor_priv->trapezoid_prog, vs_prog); - dispatch->glAttachShader(glamor_priv->trapezoid_prog, fs_prog); + glAttachShader(glamor_priv->trapezoid_prog, vs_prog); + glAttachShader(glamor_priv->trapezoid_prog, fs_prog); - dispatch->glBindAttribLocation(glamor_priv->trapezoid_prog, - GLAMOR_VERTEX_POS, "v_positionsition"); - dispatch->glBindAttribLocation(glamor_priv->trapezoid_prog, - GLAMOR_VERTEX_SOURCE, "v_texcoord"); - dispatch->glBindAttribLocation(glamor_priv->trapezoid_prog, - GLAMOR_VERTEX_TOP_BOTTOM, "v_top_bottom"); - dispatch->glBindAttribLocation(glamor_priv->trapezoid_prog, - GLAMOR_VERTEX_LEFT_PARAM, "v_left_param"); - dispatch->glBindAttribLocation(glamor_priv->trapezoid_prog, - GLAMOR_VERTEX_RIGHT_PARAM, "v_right_param"); + glBindAttribLocation(glamor_priv->trapezoid_prog, + GLAMOR_VERTEX_POS, "v_positionsition"); + glBindAttribLocation(glamor_priv->trapezoid_prog, + GLAMOR_VERTEX_SOURCE, "v_texcoord"); + glBindAttribLocation(glamor_priv->trapezoid_prog, + GLAMOR_VERTEX_TOP_BOTTOM, "v_top_bottom"); + glBindAttribLocation(glamor_priv->trapezoid_prog, + GLAMOR_VERTEX_LEFT_PARAM, "v_left_param"); + glBindAttribLocation(glamor_priv->trapezoid_prog, + GLAMOR_VERTEX_RIGHT_PARAM, "v_right_param"); - glamor_link_glsl_prog(dispatch, glamor_priv->trapezoid_prog); + glamor_link_glsl_prog(glamor_priv->trapezoid_prog); - dispatch->glUseProgram(0); + glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } void glamor_fini_trapezoid_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glDeleteProgram(glamor_priv->trapezoid_prog); - glamor_put_dispatch(glamor_priv); + glamor_get_context(glamor_priv); + glDeleteProgram(glamor_priv->trapezoid_prog); + glamor_put_context(glamor_priv); } static Bool @@ -1392,7 +1375,6 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture, BoxRec *bounds) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_pixmap_private *pixmap_priv; PixmapPtr pixmap = NULL; GLint trapezoid_prog; @@ -1425,20 +1407,20 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture, return FALSE; } - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); glamor_set_destination_pixmap_priv_nc(pixmap_priv); pixmap_priv_get_dest_scale(pixmap_priv, (&xscale), (&yscale)); - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); /* Now draw the Trapezoid mask. */ - dispatch->glUseProgram(trapezoid_prog); + glUseProgram(trapezoid_prog); - dispatch->glEnable(GL_BLEND); - dispatch->glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); nrect_max = GLAMOR_COMPOSITE_VBO_VERT_CNT / (4 * GLAMOR_VERTEX_RIGHT_PARAM); @@ -1565,37 +1547,36 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture, continue; if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - dispatch->glUnmapBuffer(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ARRAY_BUFFER); else { - dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); - dispatch->glBufferData(GL_ARRAY_BUFFER, - glamor_priv->vbo_offset, - glamor_priv->vb, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); + glBufferData(GL_ARRAY_BUFFER, glamor_priv->vbo_offset, + glamor_priv->vb, GL_DYNAMIC_DRAW); } -#ifndef GLAMOR_GLES2 - dispatch->glDrawRangeElements(GL_TRIANGLES, 0, - glamor_priv->render_nr_verts, - (glamor_priv->render_nr_verts * 3) / 2, - GL_UNSIGNED_SHORT, NULL); -#else - dispatch->glDrawElements(GL_TRIANGLES, - (glamor_priv->render_nr_verts * 3) / 2, - GL_UNSIGNED_SHORT, NULL); -#endif + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + glDrawRangeElements(GL_TRIANGLES, 0, + glamor_priv->render_nr_verts, + (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); + } else { + glDrawElements(GL_TRIANGLES, + (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); + } } - dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - dispatch->glBlendFunc(GL_ONE, GL_ZERO); - dispatch->glDisable(GL_BLEND); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBlendFunc(GL_ONE, GL_ZERO); + glDisable(GL_BLEND); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM); + glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM); + glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM); + glUseProgram(0); + glamor_put_context(glamor_priv); return TRUE; } diff --git a/xorg-server/glamor/glamor_utils.h b/xorg-server/glamor/glamor_utils.h index ea827df3b..9374c9d4d 100644 --- a/xorg-server/glamor/glamor_utils.h +++ b/xorg-server/glamor/glamor_utils.h @@ -869,19 +869,17 @@ format_for_depth(int depth) } } -static inline void -gl_iformat_for_depth(int depth, GLenum * format) +static inline GLenum +gl_iformat_for_pixmap(PixmapPtr pixmap) { - switch (depth) { -#ifndef GLAMOR_GLES2 - case 1: - case 8: - *format = GL_ALPHA; - break; -#endif - default: - *format = GL_RGBA; - break; + glamor_screen_private *glamor_priv = + glamor_get_screen_private(pixmap->drawable.pScreen); + + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP && + (pixmap->drawable.depth == 1 || pixmap->drawable.depth == 8)) { + return GL_ALPHA; + } else { + return GL_RGBA; } } @@ -916,298 +914,6 @@ format_for_pixmap(PixmapPtr pixmap) #define SWAP_UPLOADING 2 #define SWAP_NONE_UPLOADING 3 -/* - * Map picture's format to the correct gl texture format and type. - * no_alpha is used to indicate whehter we need to wire alpha to 1. - * - * Although opengl support A1/GL_BITMAP, we still don't use it - * here, it seems that mesa has bugs when uploading a A1 bitmap. - * - * Return 0 if find a matched texture type. Otherwise return -1. - **/ -#ifndef GLAMOR_GLES2 -static inline int -glamor_get_tex_format_type_from_pictformat(PictFormatShort format, - GLenum * tex_format, - GLenum * tex_type, - int *no_alpha, - int *revert, - int *swap_rb, int is_upload) -{ - *no_alpha = 0; - *revert = REVERT_NONE; - *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING; - switch (format) { - case PICT_a1: - *tex_format = GL_ALPHA; - *tex_type = GL_UNSIGNED_BYTE; - *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1; - break; - case PICT_b8g8r8x8: - *no_alpha = 1; - case PICT_b8g8r8a8: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_INT_8_8_8_8; - break; - - case PICT_x8r8g8b8: - *no_alpha = 1; - case PICT_a8r8g8b8: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case PICT_x8b8g8r8: - *no_alpha = 1; - case PICT_a8b8g8r8: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case PICT_x2r10g10b10: - *no_alpha = 1; - case PICT_a2r10g10b10: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV; - break; - case PICT_x2b10g10r10: - *no_alpha = 1; - case PICT_a2b10g10r10: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV; - break; - - case PICT_r5g6b5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5; - break; - case PICT_b5g6r5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV; - break; - case PICT_x1b5g5r5: - *no_alpha = 1; - case PICT_a1b5g5r5: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - break; - - case PICT_x1r5g5b5: - *no_alpha = 1; - case PICT_a1r5g5b5: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - break; - case PICT_a8: - *tex_format = GL_ALPHA; - *tex_type = GL_UNSIGNED_BYTE; - break; - case PICT_x4r4g4b4: - *no_alpha = 1; - case PICT_a4r4g4b4: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; - break; - - case PICT_x4b4g4r4: - *no_alpha = 1; - case PICT_a4b4g4r4: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; - break; - - default: - LogMessageVerb(X_INFO, 0, - "fail to get matched format for %x \n", format); - return -1; - } - return 0; -} - -/* Currently, we use RGBA to represent all formats. */ -inline static int -cache_format(GLenum format) -{ - switch (format) { - case GL_ALPHA: - return 1; - case GL_RGBA: - return 0; - default: - return -1; - } -} - -#else -#define IS_LITTLE_ENDIAN (IMAGE_BYTE_ORDER == LSBFirst) - -static inline int -glamor_get_tex_format_type_from_pictformat(PictFormatShort format, - GLenum * tex_format, - GLenum * tex_type, - int *no_alpha, - int *revert, - int *swap_rb, int is_upload) -{ - int need_swap_rb = 0; - - *no_alpha = 0; - *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL; - - switch (format) { - case PICT_b8g8r8x8: - *no_alpha = 1; - case PICT_b8g8r8a8: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_BYTE; - need_swap_rb = 1; - *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; - break; - - case PICT_x8r8g8b8: - *no_alpha = 1; - case PICT_a8r8g8b8: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_BYTE; - need_swap_rb = 1; - break; - - case PICT_x8b8g8r8: - *no_alpha = 1; - case PICT_a8b8g8r8: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_BYTE; - break; - - case PICT_x2r10g10b10: - *no_alpha = 1; - case PICT_a2r10g10b10: - *tex_format = GL_RGBA; - /* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2. - * we have to use GL_UNSIGNED_BYTE and do the conversion in - * shader latter.*/ - *tex_type = GL_UNSIGNED_BYTE; - if (is_upload == 1) { - if (!IS_LITTLE_ENDIAN) - *revert = REVERT_UPLOADING_10_10_10_2; - else - *revert = REVERT_UPLOADING_2_10_10_10; - } - else { - if (!IS_LITTLE_ENDIAN) { - *revert = REVERT_DOWNLOADING_10_10_10_2; - } - else { - *revert = REVERT_DOWNLOADING_2_10_10_10; - } - } - need_swap_rb = 1; - - break; - - case PICT_x2b10g10r10: - *no_alpha = 1; - case PICT_a2b10g10r10: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_BYTE; - if (is_upload == 1) { - if (!IS_LITTLE_ENDIAN) - *revert = REVERT_UPLOADING_10_10_10_2; - else - *revert = REVERT_UPLOADING_2_10_10_10; - } - else { - if (!IS_LITTLE_ENDIAN) { - *revert = REVERT_DOWNLOADING_10_10_10_2; - } - else { - *revert = REVERT_DOWNLOADING_2_10_10_10; - } - } - break; - - case PICT_r5g6b5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5; - *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL; - - break; - - case PICT_b5g6r5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5; - need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;; - break; - - case PICT_x1b5g5r5: - *no_alpha = 1; - case PICT_a1b5g5r5: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_5_5_5_1; - if (IS_LITTLE_ENDIAN) { - *revert = - is_upload ? REVERT_UPLOADING_1_5_5_5 : - REVERT_DOWNLOADING_1_5_5_5; - } - else - *revert = REVERT_NONE; - break; - - case PICT_x1r5g5b5: - *no_alpha = 1; - case PICT_a1r5g5b5: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_5_5_5_1; - if (IS_LITTLE_ENDIAN) { - *revert = - is_upload ? REVERT_UPLOADING_1_5_5_5 : - REVERT_DOWNLOADING_1_5_5_5; - } - else - *revert = REVERT_NONE; - need_swap_rb = 1; - break; - - case PICT_a1: - *tex_format = GL_ALPHA; - *tex_type = GL_UNSIGNED_BYTE; - *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1; - break; - - case PICT_a8: - *tex_format = GL_ALPHA; - *tex_type = GL_UNSIGNED_BYTE; - *revert = REVERT_NONE; - break; - - case PICT_x4r4g4b4: - *no_alpha = 1; - case PICT_a4r4g4b4: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4; - *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; - need_swap_rb = 1; - break; - - case PICT_x4b4g4r4: - *no_alpha = 1; - case PICT_a4b4g4r4: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4; - *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE; - break; - - default: - LogMessageVerb(X_INFO, 0, - "fail to get matched format for %x \n", format); - return -1; - } - - if (need_swap_rb) - *swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING; - else - *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING; - return 0; -} - inline static int cache_format(GLenum format) { @@ -1223,31 +929,6 @@ cache_format(GLenum format) } } -#endif - -static inline int -glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap, - GLenum * format, - GLenum * type, - int *no_alpha, - int *revert, int *swap_rb, int is_upload) -{ - glamor_pixmap_private *pixmap_priv; - PictFormatShort pict_format; - - pixmap_priv = glamor_get_pixmap_private(pixmap); - if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv)) - pict_format = pixmap_priv->base.picture->format; - else - pict_format = format_for_depth(pixmap->drawable.depth); - - return glamor_get_tex_format_type_from_pictformat(pict_format, - format, type, - no_alpha, - revert, - swap_rb, is_upload); -} - /* borrowed from uxa */ static inline Bool glamor_get_rgba_from_pixel(CARD32 pixel, @@ -1319,16 +1000,18 @@ glamor_get_rgba_from_pixel(CARD32 pixel, } inline static Bool -glamor_pict_format_is_compatible(PictFormatShort pict_format, int depth) +glamor_pict_format_is_compatible(PicturePtr picture) { GLenum iformat; + PixmapPtr pixmap = glamor_get_drawable_pixmap(picture->pDrawable); - gl_iformat_for_depth(depth, &iformat); + iformat = gl_iformat_for_pixmap(pixmap); switch (iformat) { case GL_RGBA: - return (pict_format == PICT_a8r8g8b8 || pict_format == PICT_x8r8g8b8); + return (picture->format == PICT_a8r8g8b8 || + picture->format == PICT_x8r8g8b8); case GL_ALPHA: - return (pict_format == PICT_a8); + return (picture->format == PICT_a8); default: return FALSE; } @@ -1817,31 +1500,15 @@ __fls(unsigned long x) #endif static inline void -glamor_make_current(ScreenPtr screen) +glamor_get_context(glamor_screen_private * glamor_priv) { - glamor_egl_make_current(screen); -} - -static inline void -glamor_restore_current(ScreenPtr screen) -{ - glamor_egl_restore_context(screen); -} - -static inline glamor_gl_dispatch * -glamor_get_dispatch(glamor_screen_private * glamor_priv) -{ - if (glamor_priv->flags & GLAMOR_USE_EGL_SCREEN) - glamor_make_current(glamor_priv->screen); - - return &glamor_priv->_dispatch; + glamor_priv->ctx.get_context(&glamor_priv->ctx); } static inline void -glamor_put_dispatch(glamor_screen_private * glamor_priv) +glamor_put_context(glamor_screen_private * glamor_priv) { - if (glamor_priv->flags & GLAMOR_USE_EGL_SCREEN) - glamor_restore_current(glamor_priv->screen); + glamor_priv->ctx.put_context(&glamor_priv->ctx); } #endif diff --git a/xorg-server/glamor/glamor_xv.c b/xorg-server/glamor/glamor_xv.c index cbe07c8b1..dc39476b5 100644 --- a/xorg-server/glamor/glamor_xv.c +++ b/xorg-server/glamor/glamor_xv.c @@ -90,38 +90,36 @@ void glamor_init_xv_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; GLint fs_prog, vs_prog; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); - glamor_priv->xv_prog = dispatch->glCreateProgram(); + glamor_get_context(glamor_priv); + glamor_priv->xv_prog = glCreateProgram(); - vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, xv_vs); - fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, xv_ps); - dispatch->glAttachShader(glamor_priv->xv_prog, vs_prog); - dispatch->glAttachShader(glamor_priv->xv_prog, fs_prog); + vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, xv_vs); + fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, xv_ps); + glAttachShader(glamor_priv->xv_prog, vs_prog); + glAttachShader(glamor_priv->xv_prog, fs_prog); - dispatch->glBindAttribLocation(glamor_priv->xv_prog, - GLAMOR_VERTEX_POS, "v_position"); - dispatch->glBindAttribLocation(glamor_priv->xv_prog, - GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - glamor_link_glsl_prog(dispatch, glamor_priv->xv_prog); + glBindAttribLocation(glamor_priv->xv_prog, + GLAMOR_VERTEX_POS, "v_position"); + glBindAttribLocation(glamor_priv->xv_prog, + GLAMOR_VERTEX_SOURCE, "v_texcoord0"); + glamor_link_glsl_prog(glamor_priv->xv_prog); - glamor_put_dispatch(glamor_priv); + glamor_put_context(glamor_priv); } void glamor_fini_xv_shader(ScreenPtr screen) { glamor_screen_private *glamor_priv; - glamor_gl_dispatch *dispatch; glamor_priv = glamor_get_screen_private(screen); - dispatch = glamor_get_dispatch(glamor_priv); + glamor_get_context(glamor_priv); - dispatch->glDeleteProgram(glamor_priv->xv_prog); - glamor_put_dispatch(glamor_priv); + glDeleteProgram(glamor_priv->xv_prog); + glamor_put_context(glamor_priv); } #define ClipValue(v,min,max) ((v) < (min) ? (min) : (v) > (max) ? (max) : (v)) @@ -278,7 +276,6 @@ glamor_display_textured_video(glamor_port_private *port_priv) glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(port_priv->pPixmap); glamor_pixmap_private *src_pixmap_priv[3]; - glamor_gl_dispatch *dispatch; float vertices[32], texcoords[8]; BoxPtr box = REGION_RECTS(&port_priv->clip); int nBox = REGION_NUM_RECTS(&port_priv->clip); @@ -327,62 +324,53 @@ glamor_display_textured_video(glamor_port_private *port_priv) &src_yscale[i]); } } - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glUseProgram(glamor_priv->xv_prog); - - uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "offsetyco"); - dispatch->glUniform4f(uloc, off[0], off[1], off[2], yco); - uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "ucogamma"); - dispatch->glUniform4f(uloc, uco[0], uco[1], uco[2], gamma); - uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "vco"); - dispatch->glUniform4f(uloc, vco[0], vco[1], vco[2], 0); - - dispatch->glActiveTexture(GL_TEXTURE0); - dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[0]->base.fbo->tex); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - dispatch->glActiveTexture(GL_TEXTURE1); - dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[1]->base.fbo->tex); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - dispatch->glActiveTexture(GL_TEXTURE2); - dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[2]->base.fbo->tex); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - dispatch->glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - sampler_loc = - dispatch->glGetUniformLocation(glamor_priv->xv_prog, "y_sampler"); - dispatch->glUniform1i(sampler_loc, 0); - sampler_loc = - dispatch->glGetUniformLocation(glamor_priv->xv_prog, "u_sampler"); - dispatch->glUniform1i(sampler_loc, 1); - sampler_loc = - dispatch->glGetUniformLocation(glamor_priv->xv_prog, "v_sampler"); - dispatch->glUniform1i(sampler_loc, 2); - - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, - GL_FLOAT, GL_FALSE, - 2 * sizeof(float), texcoords); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), vertices); - - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glamor_get_context(glamor_priv); + glUseProgram(glamor_priv->xv_prog); + + uloc = glGetUniformLocation(glamor_priv->xv_prog, "offsetyco"); + glUniform4f(uloc, off[0], off[1], off[2], yco); + uloc = glGetUniformLocation(glamor_priv->xv_prog, "ucogamma"); + glUniform4f(uloc, uco[0], uco[1], uco[2], gamma); + uloc = glGetUniformLocation(glamor_priv->xv_prog, "vco"); + glUniform4f(uloc, vco[0], vco[1], vco[2], 0); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[0]->base.fbo->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[1]->base.fbo->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[2]->base.fbo->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "y_sampler"); + glUniform1i(sampler_loc, 0); + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "u_sampler"); + glUniform1i(sampler_loc, 1); + sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "v_sampler"); + glUniform1i(sampler_loc, 2); + + glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, + GL_FLOAT, GL_FALSE, + 2 * sizeof(float), texcoords); + glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), vertices); + + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); for (i = 0; i < nBox; i++) { float off_x = box[i].x1 - port_priv->drw_x; float off_y = box[i].y1 - port_priv->drw_y; @@ -418,14 +406,14 @@ glamor_display_textured_video(glamor_port_private *port_priv) srcy + srch, glamor_priv->yInverted, texcoords); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glUseProgram(0); + glamor_put_context(glamor_priv); DamageDamageRegion(port_priv->pDraw, &port_priv->clip); } |