Commit 172e8cfc authored by Zhigang Gong's avatar Zhigang Gong Committed by Zhigang Gong

glamor: Remove GLEW dependency.

Glamor doesn't need to use GLEW. We can parse the extension by
ourself. This patch also fix the fbo size checking from a hard
coded style to a dynamic checking style.
Signed-off-by: Zhigang Gong's avatarZhigang Gong <zhigang.gong@gmail.com>
parent 2146a25b
......@@ -2,48 +2,6 @@
1. Prerequirement.
Please install makedepend and libudev-devel firstly.
Glamor need patch glew-1.5.8, here is the patch:
diff -ur ../Downloads/glew-1.5.8/Makefile glew-1.5.8/Makefile
--- ../Downloads/glew-1.5.8/Makefile 2011-01-31 22:17:27.000000000 +0800
+++ glew-1.5.8/Makefile 2011-06-28 10:13:54.147700479 +0800
@@ -63,8 +63,12 @@
else
OPT = $(POPT)
endif
-INCLUDE = -Iinclude
+
+INCLUDE = -Iinclude
CFLAGS = $(OPT) $(WARN) $(INCLUDE) $(CFLAGS.EXTRA)
+ifeq ($(NO_GLX), 1)
+CFLAGS += -D_NO_GLX_
+endif
LIB.SRCS = src/glew.c
LIB.OBJS = $(LIB.SRCS:.c=.o)
diff -ur ../Downloads/glew-1.5.8/src/glew.c glew-1.5.8/src/glew.c
--- ../Downloads/glew-1.5.8/src/glew.c 2011-01-31 22:17:27.000000000 +0800
+++ glew-1.5.8/src/glew.c 2011-06-28 10:06:45.952700777 +0800
@@ -11379,6 +11379,10 @@
{
GLenum r;
if ( (r = glewContextInit()) ) return r;
+#if defined(_NO_GLX_)
+ return r;
+#endif
+
#if defined(_WIN32)
return wglewContextInit();
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) /* _UNIX */
As xserver's glx extension code has conflicts with glew's glx related
initialization, we have to disable it in glew currently. Please apply the
above patch to glew and then build the glew as follow which will
workaround the problem.
glew-1.5.8# NO_GLX=1 make
2. Build xserver-glamor.
......
......@@ -2036,15 +2036,6 @@ if test "$KDRIVE" = yes; then
AC_MSG_ERROR([Xephyr dependencies missing])
fi
AC_CHECK_LIB(GLEW, glewInit, [
AC_CHECK_HEADER(GL/glew.h, [], [
AC_MSG_ERROR([requires glew http://glew.sourceforge.net/])
])
], [
AC_MSG_ERROR([requires glew http://glew.sourceforge.net/])
])
XEPHYR_LIBS="$XEPHYR_LIBS -lGLEW"
# Xephyr needs nanosleep() which is in librt on Solaris
AC_CHECK_FUNC([nanosleep], [],
AC_CHECK_LIB([rt], [nanosleep], XEPHYR_LIBS="$XEPHYR_LIBS -lrt"))
......
......@@ -110,10 +110,11 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
GLuint tex;
int type = GLAMOR_PIXMAP_TEXTURE;
glamor_pixmap_private *pixmap_priv;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
if (w > 32767 || h > 32767)
return NullPixmap;
if (!glamor_check_fbo_width_height(w,h)
if (!glamor_check_fbo_size(glamor_priv, w,h)
|| !glamor_check_fbo_depth(depth)
|| usage == GLAMOR_CREATE_PIXMAP_CPU) {
/* MESA can only support upto MAX_WIDTH*MAX_HEIGHT fbo.
......@@ -249,6 +250,7 @@ Bool
glamor_init(ScreenPtr screen, unsigned int flags)
{
glamor_screen_private *glamor_priv;
int gl_version;
#ifdef RENDER
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
......@@ -271,7 +273,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
LogMessage(X_WARNING,
"glamor%d: Failed to allocate screen private\n",
screen->myNum);
return FALSE;
goto fail;
}
dixSetPrivate(&screen->devPrivates, glamor_screen_private_key, glamor_priv);
......@@ -281,36 +283,27 @@ glamor_init(ScreenPtr screen, unsigned int flags)
LogMessage(X_WARNING,
"glamor%d: Failed to allocate pixmap private\n",
screen->myNum);
return FALSE;
goto fail;;
}
gl_version = glamor_gl_get_version();
#ifndef GLAMOR_GLES2
glewInit();
if (!GLEW_EXT_framebuffer_object) {
ErrorF("GL_EXT_framebuffer_object required\n");
goto fail;
}
if (!GLEW_ARB_shader_objects) {
ErrorF("GL_ARB_shader_objects required\n");
goto fail;
}
if (!GLEW_ARB_vertex_shader) {
ErrorF("GL_ARB_vertex_shader required\n");
if (gl_version < GLAMOR_GL_VERSION_ENCODE(1,3)) {
ErrorF("Require Opengl 1.3 or latter.\n");
goto fail;
}
if (!GLEW_ARB_pixel_buffer_object) {
ErrorF("GL_ARB_pixel_buffer_object required\n");
goto fail;
}
if (!GLEW_EXT_bgra) {
ErrorF("GL_EXT_bgra required\n");
#ifdef GLAMOR_GLES2
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");
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size);
if (!RegisterBlockAndWakeupHandlers(glamor_block_handler,
glamor_wakeup_handler,
......
......@@ -48,7 +48,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
if (!GLEW_EXT_framebuffer_blit) {
if (!glamor_priv->has_fbo_blit) {
glamor_delayed_fallback(screen,"no EXT_framebuffer_blit\n");
return FALSE;
}
......@@ -85,7 +85,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
for (i = 0; i < nbox; i++) {
if(glamor_priv->yInverted) {
glBlitFramebufferEXT((box[i].x1 + dx + src_x_off),
glBlitFramebuffer((box[i].x1 + dx + src_x_off),
(box[i].y1 + src_y_off),
(box[i].x2 + dx + src_x_off),
(box[i].y2 + src_y_off),
......@@ -101,7 +101,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
int flip_src_y1 = src_pixmap->drawable.height - (box[i].y2 + src_y_off);
int flip_src_y2 = src_pixmap->drawable.height - (box[i].y1 + src_y_off);
glBlitFramebufferEXT(box[i].x1 + dx + src_x_off,
glBlitFramebuffer(box[i].x1 + dx + src_x_off,
flip_src_y1,
box[i].x2 + dx + src_x_off,
flip_src_y2,
......
......@@ -201,7 +201,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glamor_priv->finish_access_prog[2] = glCreateProgram();
glamor_priv->finish_access_prog[3] = glCreateProgram();
if (GLEW_ARB_fragment_shader) {
#ifndef GLAMOR_GLES2
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source);
......@@ -223,13 +222,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glAttachShader(glamor_priv->finish_access_prog[3], es_avs_prog);
glAttachShader(glamor_priv->finish_access_prog[3], es_aswizzle_prog);
} else {
#ifndef GLAMOR_GLES2
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
ErrorF("Lack of framgment shader support.\n");
#endif
}
#ifndef GLAMOR_GLES2
......@@ -244,7 +236,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glBindAttribLocation(glamor_priv->finish_access_prog[3], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(glamor_priv->finish_access_prog[3]);
if (GLEW_ARB_fragment_shader) {
GLint sampler_uniform_location;
#ifndef GLAMOR_GLES2
sampler_uniform_location =
......@@ -271,7 +262,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glUniform1i(sampler_uniform_location, 0);
glUseProgram(0);
}
}
void
......@@ -494,3 +484,50 @@ glamor_bitmap_to_region(PixmapPtr pixmap)
glamor_finish_access(&pixmap->drawable);
return ret;
}
/* Borrow from cairo. */
Bool
glamor_gl_has_extension(char *extension)
{
const char *gl_extensions;
char *pext;
int ext_len;
ext_len = strlen(extension);
gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
pext = (char*)gl_extensions;
if (pext == NULL || extension == NULL)
return FALSE;
while((pext = strstr(pext, extension)) != NULL) {
if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
return TRUE;
pext += ext_len;
}
return FALSE;
}
int
glamor_gl_get_version (void)
{
int major, minor;
const char *version = (const char *) glGetString (GL_VERSION);
const char *dot = version == NULL ? NULL : strchr (version, '.');
const char *major_start = dot;
/* Sanity check */
if (dot == NULL || dot == version || *(dot + 1) == '\0') {
major = 0;
minor = 0;
} else {
/* Find the start of the major version in the string */
while (major_start > version && *major_start != ' ')
--major_start;
major = strtol (major_start, NULL, 10);
minor = strtol (dot + 1, NULL, 10);
}
return GLAMOR_GL_VERSION_ENCODE (major, minor);
}
......@@ -139,15 +139,10 @@ glamor_init_solid_shader(ScreenPtr screen)
GLint fs_prog, vs_prog;
glamor_priv->solid_prog = glCreateProgram();
if (GLEW_ARB_fragment_shader) {
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);
} else {
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, solid_vs_only);
glAttachShader(glamor_priv->solid_prog, vs_prog);
}
glBindAttribLocation(glamor_priv->solid_prog, GLAMOR_VERTEX_POS, "v_position");
glamor_link_glsl_prog(glamor_priv->solid_prog);
......
......@@ -407,7 +407,7 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, int ax)
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
if (!glamor_check_fbo_width_height(pixmap->drawable.width , pixmap->drawable.height)
if (!glamor_check_fbo_size(glamor_priv, pixmap->drawable.width , pixmap->drawable.height)
|| !glamor_check_fbo_depth(pixmap->drawable.depth)) {
glamor_fallback("upload failed reason: bad size or depth %d x %d @depth %d \n",
pixmap->drawable.width, pixmap->drawable.height, pixmap->drawable.depth);
......@@ -571,7 +571,7 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
// glPixelStorei(GL_PACK_ROW_LENGTH, 0);
}
if (GLEW_MESA_pack_invert || glamor_priv->yInverted) {
if (glamor_priv->has_pack_invert || glamor_priv->yInverted) {
if (!glamor_priv->yInverted) {
assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
......
......@@ -37,8 +37,6 @@
#ifdef GLAMOR_GLES2
#define GLEW_ES_ONLY 1
#define GL_BGRA GL_BGRA_EXT
#define GL_COLOR_INDEX 0x1900
#define GL_BITMAP 0x1A00
......@@ -49,7 +47,6 @@
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
#define GLEW_ARB_fragment_shader 1
#define GL_PIXEL_PACK_BUFFER 0x88EB
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
#define GL_CLAMP_TO_BORDER 0x812D
......@@ -66,7 +63,6 @@
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56
#define GLEW_MESA_pack_invert 0
#define GL_PACK_INVERT_MESA 0x8758
#define glMapBuffer(x, y) NULL
......@@ -76,12 +72,13 @@
#endif
#ifdef GLAMOR_GLES2
#define GL_GLEXT_PROTOTYPES
#ifdef GLAMOR_GLES2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#endif
......@@ -90,19 +87,11 @@
#endif
#ifndef MAX_WIDTH
#define MAX_WIDTH 4096
#endif
#ifndef MAX_HEIGHT
#define MAX_HEIGHT 4096
#endif
#include "glamor_debug.h"
#define glamor_check_fbo_width_height(_w_, _h_) ((_w_) > 0 && (_h_) > 0 \
&& (_w_) < MAX_WIDTH \
&& (_h_) < MAX_HEIGHT)
#define glamor_check_fbo_size(_glamor_,_w_, _h_) ((_w_) > 0 && (_h_) > 0 \
&& (_w_) < _glamor_->max_fbo_size \
&& (_h_) < _glamor_->max_fbo_size)
#define glamor_check_fbo_depth(_depth_) ( \
_depth_ == 8 \
......@@ -241,6 +230,9 @@ typedef struct glamor_screen_private {
char *vb;
int vb_stride;
enum glamor_gl_flavor gl_flavor;
int has_pack_invert;
int has_fbo_blit;
int max_fbo_size;
/* glamor_finishaccess */
GLint finish_access_prog[4];
......@@ -674,6 +666,15 @@ void glamor_set_transform_for_pixmap(PixmapPtr pixmap,
glamor_transform_uniforms *uniform_locations);
Bool glamor_change_window_attributes(WindowPtr pWin, unsigned long mask);
RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap);
Bool glamor_gl_has_extension(char *extension);
int glamor_gl_get_version(void);
#define GLAMOR_GL_VERSION_ENCODE(major, minor) ( \
((major) * 256) \
+ ((minor) * 1))
/* glamor_fill.c */
void glamor_fill(DrawablePtr drawable,
......
......@@ -1154,6 +1154,7 @@ glamor_composite(CARD8 op,
PicturePtr temp_src = source, temp_mask = mask;
int x_temp_src, y_temp_src, x_temp_mask, y_temp_mask;
glamor_composite_rect_t rect;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
x_temp_src = x_source;
y_temp_src = y_source;
......@@ -1181,7 +1182,7 @@ glamor_composite(CARD8 op,
&& !GLAMOR_PIXMAP_PRIV_HAS_FBO(source_pixmap_priv)
&& ((width * height * 4
< (source_pixmap->drawable.width * source_pixmap->drawable.height))
|| !(glamor_check_fbo_width_height(source_pixmap->drawable.width,
|| !(glamor_check_fbo_size(glamor_priv, source_pixmap->drawable.width,
source_pixmap->drawable.height))))) {
temp_src = glamor_convert_gradient_picture(screen, source, x_source, y_source, width, height);
if (!temp_src) {
......@@ -1197,7 +1198,7 @@ glamor_composite(CARD8 op,
&& (!GLAMOR_PIXMAP_PRIV_HAS_FBO(mask_pixmap_priv))
&& ((width * height * 4
< (mask_pixmap->drawable.width * mask_pixmap->drawable.height))
|| !(glamor_check_fbo_width_height(mask_pixmap->drawable.width,
|| !(glamor_check_fbo_size(glamor_priv, mask_pixmap->drawable.width,
mask_pixmap->drawable.height)))))) {
/* XXX if mask->pDrawable is the same as source->pDrawable, we have an opportunity
* to do reduce one convertion. */
......
......@@ -74,9 +74,6 @@ glamor_init_tile_shader(ScreenPtr screen)
GLint fs_prog, vs_prog;
GLint sampler_uniform_location;
if (!GLEW_ARB_fragment_shader)
return;
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);
......
......@@ -66,6 +66,12 @@ libxephyr_la_SOURCES = $(XEPHYR_SRCS)
Xephyr_SOURCES = \
ephyrinit.c
if GLAMOR_GLES2
GLAMOR_GL_LIB = -lGLESv2
else
GLAMOR_GL_LIB = -lGL
endif
Xephyr_LDADD = \
libxephyr.la \
libxephyr-hostx.la \
......@@ -74,7 +80,8 @@ Xephyr_LDADD = \
$(top_builddir)/exa/libexa.la \
$(top_builddir)/glamor/libglamor.la \
@KDRIVE_LIBS@ \
@XEPHYR_LIBS@
@XEPHYR_LIBS@ \
$(GLAMOR_GL_LIB)
Xephyr_DEPENDENCIES = \
libxephyr.la \
......
......@@ -15,7 +15,7 @@ if GLAMOR_GLES2
glamor_la_CFLAGS+=-DGLAMOR_GLES2
GLAMOR_GL_LIB = -lGLESv2
else
GLAMOR_GL_LIB = -L$(libdir)/../lib64 -lGLEW
GLAMOR_GL_LIB = -lGL
endif
glamor_la_LDFLAGS = \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment