Merge branch 'arb_half_float_vertex'
authorDave Airlie <airlied@redhat.com>
Sat, 23 Jan 2010 02:29:33 +0000 (12:29 +1000)
committerDave Airlie <airlied@redhat.com>
Sat, 23 Jan 2010 02:29:33 +0000 (12:29 +1000)
342 files changed:
configs/autoconf.in
configs/default
configs/linux-dri
configs/linux-dri-xcb
configs/linux-egl
configs/linux-opengl-es
configure.ac
docs/egl.html
docs/lists.html
docs/opengles.html
docs/openvg.html
docs/sourcetree.html
progs/trivial/tri-fbo-tex-mip.c
progs/xdemos/glxgears.c
progs/xdemos/offset.c
src/egl/drivers/Makefile.template [new file with mode: 0644]
src/egl/drivers/demo/Makefile [deleted file]
src/egl/drivers/demo/demo.c [deleted file]
src/egl/drivers/glx/Makefile
src/egl/drivers/glx/egl_glx.c
src/egl/drivers/xdri/Makefile
src/egl/drivers/xdri/driinit.c
src/egl/drivers/xdri/egl_xdri.c
src/egl/drivers/xdri/glxinit.c
src/egl/drivers/xdri/glxinit.h
src/egl/main/egldriver.c
src/gallium/auxiliary/Makefile
src/gallium/auxiliary/SConscript
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_pipe.c
src/gallium/auxiliary/draw/draw_pipe_cull.c
src/gallium/auxiliary/draw/draw_pipe_validate.c
src/gallium/auxiliary/draw/draw_pt.c
src/gallium/auxiliary/draw/draw_pt_fetch.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
src/gallium/auxiliary/draw/draw_pt_post_vs.c
src/gallium/auxiliary/draw/draw_vs_varient.c
src/gallium/auxiliary/pipebuffer/Makefile [new file with mode: 0644]
src/gallium/auxiliary/pipebuffer/SConscript [new file with mode: 0644]
src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c [deleted file]
src/gallium/auxiliary/pipebuffer/pb_validate.c
src/gallium/auxiliary/tgsi/tgsi_scan.c
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_gen_mipmap.c
src/gallium/auxiliary/util/u_upload_mgr.c
src/gallium/drivers/i915/i915_clear.c
src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/i915/i915_debug.c
src/gallium/drivers/i915/i915_debug_fp.c
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/i915/i915_state_derived.c
src/gallium/drivers/i915/i915_state_sampler.c
src/gallium/drivers/i915/i915_surface.c
src/gallium/drivers/i915/i915_texture.c
src/gallium/drivers/llvmpipe/lp_bld_alpha.c
src/gallium/drivers/llvmpipe/lp_bld_arit.c
src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c
src/gallium/drivers/llvmpipe/lp_bld_conv.c
src/gallium/drivers/llvmpipe/lp_bld_format_aos.c
src/gallium/drivers/llvmpipe/lp_bld_tgsi_soa.c
src/gallium/drivers/llvmpipe/lp_draw_arrays.c
src/gallium/drivers/llvmpipe/lp_flush.c
src/gallium/drivers/llvmpipe/lp_jit.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_state_surface.c
src/gallium/drivers/llvmpipe/lp_state_vertex.c
src/gallium/drivers/llvmpipe/lp_test_blend.c
src/gallium/drivers/llvmpipe/lp_tex_cache.c
src/gallium/drivers/llvmpipe/lp_tex_sample_c.c [new file with mode: 0644]
src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c
src/gallium/drivers/llvmpipe/lp_texture.c
src/gallium/drivers/llvmpipe/lp_tile_cache.c
src/gallium/drivers/softpipe/sp_context.c
src/gallium/drivers/softpipe/sp_flush.c
src/gallium/drivers/softpipe/sp_prim_vbuf.c
src/gallium/drivers/softpipe/sp_quad_blend.c
src/gallium/drivers/softpipe/sp_quad_depth_test.c
src/gallium/drivers/softpipe/sp_quad_fs.c
src/gallium/drivers/softpipe/sp_setup.c
src/gallium/drivers/softpipe/sp_state_surface.c
src/gallium/drivers/softpipe/sp_state_vertex.c
src/gallium/drivers/softpipe/sp_tex_tile_cache.c
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/svga/svga_draw_arrays.c
src/gallium/drivers/svga/svga_draw_elements.c
src/gallium/drivers/svga/svga_pipe_blend.c
src/gallium/drivers/svga/svga_pipe_constants.c
src/gallium/drivers/svga/svga_pipe_depthstencil.c
src/gallium/drivers/svga/svga_pipe_draw.c
src/gallium/drivers/svga/svga_pipe_flush.c
src/gallium/drivers/svga/svga_pipe_fs.c
src/gallium/drivers/svga/svga_pipe_misc.c
src/gallium/drivers/svga/svga_pipe_query.c
src/gallium/drivers/svga/svga_pipe_rasterizer.c
src/gallium/drivers/svga/svga_pipe_sampler.c
src/gallium/drivers/svga/svga_pipe_vertex.c
src/gallium/drivers/svga/svga_pipe_vs.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/svga/svga_screen.h
src/gallium/drivers/svga/svga_screen_buffer.c
src/gallium/drivers/svga/svga_screen_buffer.h
src/gallium/drivers/svga/svga_screen_texture.c
src/gallium/drivers/svga/svga_state_framebuffer.c
src/gallium/drivers/svga/svga_state_rss.c
src/gallium/drivers/svga/svga_state_tss.c
src/gallium/drivers/svga/svga_swtnl_backend.c
src/gallium/drivers/svga/svga_swtnl_draw.c
src/gallium/drivers/svga/svga_swtnl_state.c
src/gallium/drivers/svga/svga_tgsi_decl_sm20.c
src/gallium/drivers/svga/svga_tgsi_decl_sm30.c
src/gallium/drivers/svga/svga_winsys.h
src/gallium/drivers/trace/tr_drm.c
src/gallium/include/pipe/p_inlines.h
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/dri/dri_context.c
src/gallium/state_trackers/dri/dri_drawable.c
src/gallium/state_trackers/dri/dri_screen.c
src/gallium/state_trackers/dri/dri_screen.h
src/gallium/state_trackers/egl/Makefile
src/gallium/state_trackers/egl/common/egl_g3d.c [new file with mode: 0644]
src/gallium/state_trackers/egl/common/egl_g3d.h [new file with mode: 0644]
src/gallium/state_trackers/egl/common/egl_st.c [new file with mode: 0644]
src/gallium/state_trackers/egl/common/egl_st.h [new file with mode: 0644]
src/gallium/state_trackers/egl/common/native.h [new file with mode: 0644]
src/gallium/state_trackers/egl/common/st_public_tmp.h [new file with mode: 0644]
src/gallium/state_trackers/egl/egl_context.c [deleted file]
src/gallium/state_trackers/egl/egl_surface.c [deleted file]
src/gallium/state_trackers/egl/egl_tracker.c [deleted file]
src/gallium/state_trackers/egl/egl_tracker.h [deleted file]
src/gallium/state_trackers/egl/egl_visual.c [deleted file]
src/gallium/state_trackers/egl/kms/native_kms.c [new file with mode: 0644]
src/gallium/state_trackers/egl/kms/native_kms.h [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/native_dri2.c [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/native_x11.c [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/native_x11.h [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/native_ximage.c [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/sw_winsys.c [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/sw_winsys.h [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/x11_screen.c [new file with mode: 0644]
src/gallium/state_trackers/egl/x11/x11_screen.h [new file with mode: 0644]
src/gallium/state_trackers/egl_g3d/Makefile [deleted file]
src/gallium/state_trackers/egl_g3d/common/egl_g3d.c [deleted file]
src/gallium/state_trackers/egl_g3d/common/egl_g3d.h [deleted file]
src/gallium/state_trackers/egl_g3d/common/egl_st.c [deleted file]
src/gallium/state_trackers/egl_g3d/common/egl_st.h [deleted file]
src/gallium/state_trackers/egl_g3d/common/native.h [deleted file]
src/gallium/state_trackers/egl_g3d/common/st_public_tmp.h [deleted file]
src/gallium/state_trackers/egl_g3d/kms/native_kms.c [deleted file]
src/gallium/state_trackers/egl_g3d/kms/native_kms.h [deleted file]
src/gallium/state_trackers/egl_g3d/x11/glxinit.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/glxinit.h [deleted file]
src/gallium/state_trackers/egl_g3d/x11/native_dri2.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/native_x11.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/native_x11.h [deleted file]
src/gallium/state_trackers/egl_g3d/x11/native_ximage.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/sw_winsys.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/sw_winsys.h [deleted file]
src/gallium/state_trackers/egl_g3d/x11/x11_screen.c [deleted file]
src/gallium/state_trackers/egl_g3d/x11/x11_screen.h [deleted file]
src/gallium/state_trackers/wgl/stw_pixelformat.c
src/gallium/state_trackers/xorg/xorg_composite.c
src/gallium/state_trackers/xorg/xorg_dri2.c
src/gallium/state_trackers/xorg/xorg_driver.c
src/gallium/state_trackers/xorg/xorg_exa.c
src/gallium/state_trackers/xorg/xorg_exa_tgsi.c
src/gallium/state_trackers/xorg/xorg_output.c
src/gallium/state_trackers/xorg/xorg_xv.c
src/gallium/winsys/drm/Makefile.egl [new file with mode: 0644]
src/gallium/winsys/drm/Makefile.egl_g3d [deleted file]
src/gallium/winsys/drm/i965/egl/Makefile
src/gallium/winsys/drm/i965/egl/dummy.c [new file with mode: 0644]
src/gallium/winsys/drm/i965/egl_g3d/Makefile [deleted file]
src/gallium/winsys/drm/i965/egl_g3d/dummy.c [deleted file]
src/gallium/winsys/drm/intel/egl/Makefile
src/gallium/winsys/drm/intel/egl/dummy.c
src/gallium/winsys/drm/intel/egl_g3d/Makefile [deleted file]
src/gallium/winsys/drm/intel/egl_g3d/dummy.c [deleted file]
src/gallium/winsys/drm/intel/gem/intel_drm_api.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
src/gallium/winsys/drm/nouveau/egl/Makefile [new file with mode: 0644]
src/gallium/winsys/drm/nouveau/egl/dummy.c [new file with mode: 0644]
src/gallium/winsys/drm/nouveau/egl_g3d/Makefile [deleted file]
src/gallium/winsys/drm/nouveau/egl_g3d/dummy.c [deleted file]
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/drm/radeon/egl/Makefile
src/gallium/winsys/drm/radeon/egl/dummy.c
src/gallium/winsys/drm/radeon/egl_g3d/Makefile [deleted file]
src/gallium/winsys/drm/radeon/egl_g3d/dummy.c [deleted file]
src/gallium/winsys/drm/swrast/Makefile [new file with mode: 0644]
src/gallium/winsys/drm/swrast/core/Makefile [new file with mode: 0644]
src/gallium/winsys/drm/swrast/core/swrast_drm_api.c [new file with mode: 0644]
src/gallium/winsys/drm/swrast/egl/Makefile [new file with mode: 0644]
src/gallium/winsys/drm/swrast/egl/dummy.c [new file with mode: 0644]
src/gallium/winsys/drm/vmware/core/vmw_context.c
src/gallium/winsys/drm/vmware/core/vmw_screen.h
src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c
src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c
src/gallium/winsys/drm/vmware/egl/Makefile
src/gallium/winsys/drm/vmware/egl/dummy.c [new file with mode: 0644]
src/gallium/winsys/drm/vmware/egl_g3d/Makefile [deleted file]
src/gallium/winsys/drm/vmware/egl_g3d/dummy.c [deleted file]
src/gallium/winsys/egl_xlib/Makefile [deleted file]
src/gallium/winsys/egl_xlib/egl_xlib.c [deleted file]
src/gallium/winsys/egl_xlib/sw_winsys.c [deleted file]
src/gallium/winsys/egl_xlib/sw_winsys.h [deleted file]
src/gallium/winsys/xlib/xlib_softpipe.c
src/glx/x11/glxcurrent.c
src/mesa/SConscript
src/mesa/drivers/dri/common/spantmp2.h
src/mesa/drivers/dri/fb/Makefile
src/mesa/drivers/dri/fb/fb_egl.c [deleted file]
src/mesa/drivers/dri/ffb/ffb_bitmap.c
src/mesa/drivers/dri/ffb/ffb_clear.c
src/mesa/drivers/dri/ffb/ffb_dd.c
src/mesa/drivers/dri/ffb/ffb_depth.c
src/mesa/drivers/dri/ffb/ffb_lines.c
src/mesa/drivers/dri/ffb/ffb_points.c
src/mesa/drivers/dri/ffb/ffb_span.c
src/mesa/drivers/dri/ffb/ffb_state.c
src/mesa/drivers/dri/ffb/ffb_stencil.c
src/mesa/drivers/dri/ffb/ffb_vb.c
src/mesa/drivers/dri/ffb/ffb_xmesa.c
src/mesa/drivers/dri/i810/i810context.c
src/mesa/drivers/dri/i810/i810render.c
src/mesa/drivers/dri/i810/i810screen.c
src/mesa/drivers/dri/i810/i810state.c
src/mesa/drivers/dri/i810/i810tex.c
src/mesa/drivers/dri/i810/i810texmem.c
src/mesa/drivers/dri/i810/i810vb.c
src/mesa/drivers/dri/mach64/mach64_context.c
src/mesa/drivers/dri/mach64/mach64_dd.c
src/mesa/drivers/dri/mach64/mach64_lock.c
src/mesa/drivers/dri/mach64/mach64_screen.c
src/mesa/drivers/dri/mach64/mach64_span.c
src/mesa/drivers/dri/mach64/mach64_state.c
src/mesa/drivers/dri/mach64/mach64_tex.c
src/mesa/drivers/dri/mach64/mach64_texmem.c
src/mesa/drivers/dri/mach64/mach64_texstate.c
src/mesa/drivers/dri/mach64/mach64_vb.c
src/mesa/drivers/dri/r200/Makefile
src/mesa/drivers/dri/r200/r200_state_init.c
src/mesa/drivers/dri/r200/server/radeon_egl.c [deleted symlink]
src/mesa/drivers/dri/r300/Makefile
src/mesa/drivers/dri/r300/server/radeon_egl.c [deleted symlink]
src/mesa/drivers/dri/r600/Makefile
src/mesa/drivers/dri/r600/r600_texstate.c
src/mesa/drivers/dri/r600/r700_chip.c
src/mesa/drivers/dri/r600/r700_state.c
src/mesa/drivers/dri/r600/server/radeon_egl.c [deleted symlink]
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.h
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/radeon/server/radeon_egl.c [deleted file]
src/mesa/drivers/dri/unichrome/via_context.c
src/mesa/drivers/dri/unichrome/via_ioctl.c
src/mesa/drivers/dri/unichrome/via_render.c
src/mesa/drivers/dri/unichrome/via_screen.c
src/mesa/drivers/dri/unichrome/via_state.c
src/mesa/drivers/dri/unichrome/via_tex.c
src/mesa/drivers/dri/unichrome/via_texcombine.c
src/mesa/glapi/Makefile
src/mesa/glapi/gl_apitemp.py
src/mesa/glapi/glapi.c
src/mesa/glapi/glapi.h
src/mesa/glapi/glapi_nop.c [new file with mode: 0644]
src/mesa/glapi/glapitemp.h
src/mesa/main/attrib.c
src/mesa/main/blend.c
src/mesa/main/buffers.c
src/mesa/main/context.c
src/mesa/main/convolve.c
src/mesa/main/debug.c
src/mesa/main/depthstencil.c
src/mesa/main/dlist.c
src/mesa/main/drawpix.c
src/mesa/main/enable.c
src/mesa/main/fbobject.c
src/mesa/main/formats.c
src/mesa/main/image.c
src/mesa/main/lines.c
src/mesa/main/mipmap.c
src/mesa/main/pixel.c
src/mesa/main/pixelstore.c
src/mesa/main/points.c
src/mesa/main/polygon.c
src/mesa/main/state.c
src/mesa/main/texcompress.c
src/mesa/main/texformat.c
src/mesa/main/texgetimage.c
src/mesa/main/teximage.c
src/mesa/main/texobj.c
src/mesa/main/texparam.c
src/mesa/main/texstate.c
src/mesa/main/texstore.c
src/mesa/main/vtxfmt.c
src/mesa/shader/arbprogparse.c
src/mesa/shader/arbprogram.c
src/mesa/shader/lex.yy.c
src/mesa/shader/nvvertparse.c
src/mesa/shader/prog_execute.c
src/mesa/shader/prog_statevars.c
src/mesa/shader/program_lexer.l
src/mesa/shader/program_parse.tab.c
src/mesa/shader/program_parse.y
src/mesa/shader/shader_api.c
src/mesa/shader/slang/slang_builtin.c
src/mesa/shader/slang/slang_compile.c
src/mesa/shader/slang/slang_emit.c
src/mesa/shader/slang/slang_link.c
src/mesa/shader/slang/slang_log.c
src/mesa/sources.mak
src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_atom_pixeltransfer.c
src/mesa/state_tracker/st_atom_sampler.c
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_cb_accum.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_blit.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_feedback.c
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_cb_queryobj.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_cb_readpixels.c
src/mesa/state_tracker/st_cb_strings.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_cb_viewport.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_draw_feedback.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_framebuffer.c
src/mesa/state_tracker/st_gen_mipmap.c
src/mesa/state_tracker/st_inlines.h
src/mesa/swrast/s_depth.c
src/mesa/swrast/s_span.c

index c6d315e4d2e325e68aa7e113ae5ee5d5739c23fd..d9fa2dafe93cba7d41f6b514a0931933621a7231 100644 (file)
@@ -85,7 +85,6 @@ PROGRAM_DIRS = @PROGRAM_DIRS@
 DRI_DIRS = @DRI_DIRS@ 
 WINDOW_SYSTEM = @WINDOW_SYSTEM@
 EGL_DISPLAYS = @EGL_DISPLAYS@
-USING_EGL = @USING_EGL@
 
 # Dependencies
 X11_INCLUDES = @X11_INCLUDES@
index ec9670dd6344715a9d9c640844bb1351d5cf1892..3aa136b9c5867cd56dcdc9a84c6ed944c39c0df5 100644 (file)
@@ -93,15 +93,15 @@ DRIVER_DIRS = x11 osmesa
 PROGRAM_DIRS = demos redbook samples glsl objviewer xdemos
 
 # EGL drivers to build
-EGL_DRIVERS_DIRS = demo
+EGL_DRIVERS_DIRS = glx
 
 # Gallium directories and 
 GALLIUM_DIRS = auxiliary drivers state_trackers
 GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
 GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity
 GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
-GALLIUM_WINSYS_DIRS = xlib egl_xlib
-GALLIUM_WINSYS_DRM_DIRS =
+GALLIUM_WINSYS_DIRS = drm xlib
+GALLIUM_WINSYS_DRM_DIRS = swrast
 GALLIUM_STATE_TRACKERS_DIRS = glx
 
 # native displays EGL should support
index ff9bcc9396a03ac8696613d3f5af5b25e3307354..95f77ade1dd2301e60618dd19a910d3ec246fc2f 100644 (file)
@@ -55,7 +55,7 @@ SRC_DIRS := glx/x11 egl $(SRC_DIRS)
 PROGRAM_DIRS := egl $(PROGRAM_DIRS)
 
 # EGL directories
-EGL_DRIVERS_DIRS = demo glx
+EGL_DRIVERS_DIRS = glx
 
 DRIVER_DIRS = dri
 WINDOW_SYSTEM = dri
index 827fb97330801deafcbbd651fd290c077baa4985..7b99dccdb88fa1fc6adfa29e0cb9dc02dcecdf54 100644 (file)
@@ -47,21 +47,8 @@ DRI_LIB_DEPS  = $(EXTRA_LIB_PATH) -lm -lpthread -lexpat -ldl $(LIBDRM_LIB)
 GL_LIB_DEPS   = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lm -lpthread -ldl \
                 $(LIBDRM_LIB) $(shell pkg-config --libs xcb) $(shell pkg-config --libs x11-xcb) $(shell pkg-config --libs xcb-glx)
 
-
-# This is now 0 by default since it seems to confuse the hell out of people
-# and generate a lot of extra noise on bugzilla.  If you need to build with
-# EGL, do 'make linux-dri USING_EGL=1'
-
-USING_EGL=0
-
-# Directories
-ifeq ($(USING_EGL), 1)
-SRC_DIRS = egl glx/x11 gallium mesa glu glut/glx glew glw
-PROGRAM_DIRS = egl
-else
 SRC_DIRS = glx/x11 gallium mesa glu glut/glx glew glw
 PROGRAM_DIRS = xdemos
-endif
 
 DRIVER_DIRS = dri
 WINDOW_SYSTEM=dri
index e906806f4b887c4aefc2b0d053cfb04115eb2686..6494a68aeb1a349422ff38ff67cd090f9058a3ca 100644 (file)
@@ -46,12 +46,6 @@ GL_LIB_DEPS   = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \
                 $(LIBDRM_LIB)
 
 
-# This is now 0 by default since it seems to confuse the hell out of people
-# and generate a lot of extra noise on bugzilla.  If you need to build with
-# EGL, do 'make linux-dri USING_EGL=1'
-
-USING_EGL=0
-
 # Directories
 SRC_DIRS = gallium mesa gallium/winsys glu egl
 PROGRAM_DIRS = egl
index 566cd758e3ec1a89e981e2f594293cf8bf5a1366..259c26a931bd525c1806a1c0f0198547d5b933c8 100644 (file)
@@ -9,19 +9,20 @@ LIB_DIR = lib
 SRC_DIRS = egl glsl mesa/es gallium gallium/winsys
 PROGRAM_DIRS = es1/screen es1/xegl es2/xegl
 
+# egl st needs this
+DEFINES += -DGLX_DIRECT_RENDERING
+
 # no mesa or egl drivers
 DRIVER_DIRS =
 EGL_DRIVERS_DIRS =
 
 GALLIUM_DRIVERS_DIRS = softpipe
 
-# build egl_softpipe.so
-GALLIUM_WINSYS_DIRS = egl_xlib
-# and libGLES*.so
+# build libGLES*.so
 GALLIUM_STATE_TRACKERS_DIRS = es
 
-# build egl_i915.so
+# build egl_x11_{swrast,i915}.so
 GALLIUM_DRIVERS_DIRS += trace i915
 GALLIUM_STATE_TRACKERS_DIRS += egl
 GALLIUM_WINSYS_DIRS += drm
-GALLIUM_WINSYS_DRM_DIRS = intel
+GALLIUM_WINSYS_DRM_DIRS += intel swrast
index 619ed47bcbd62f5ff45b644e8726f404506a8c17..370bd1b9b7fa29f4209b8f68288aff4a92d2438f 100644 (file)
@@ -699,10 +699,6 @@ yes)
     ;;
 esac
 
-dnl Just default to no EGL for now
-USING_EGL=0
-AC_SUBST([USING_EGL])
-
 dnl Set DRI_DIRS, DEFINES and LIB_DEPS
 if test "$mesa_driver" = dri; then
     # Use TLS in GLX?
@@ -710,10 +706,6 @@ if test "$mesa_driver" = dri; then
         DEFINES="$DEFINES -DGLX_USE_TLS -DPTHREADS"
     fi
 
-    if test "x$USING_EGL" = x1; then
-        PROGRAM_DIRS="egl"
-    fi
-
     # Platform specific settings and drivers to build
     case "$host_os" in
     linux*)
@@ -1173,7 +1165,7 @@ yes)
     dri)
         GALLIUM_STATE_TRACKERS_DIRS="dri"
         if test "x$enable_egl" = xyes; then
-            GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl egl_g3d"
+            GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
         fi
         # Have only tested st/xorg on 1.6.0 servers
         PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0],
@@ -1231,7 +1223,7 @@ yes)
     # verify the requested driver directories exist
     egl_displays=`IFS=', '; echo $with_egl_displays`
     for dpy in $egl_displays; do
-        test -d "$srcdir/src/gallium/state_trackers/egl_g3d/$dpy" || \
+        test -d "$srcdir/src/gallium/state_trackers/egl/$dpy" || \
             AC_MSG_ERROR([EGL display '$dpy' does't exist])
     done
     EGL_DISPLAYS="$egl_displays"
@@ -1319,6 +1311,18 @@ if test "x$enable_gallium_nouveau" = xyes; then
     GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv04 nv10 nv20 nv30 nv40 nv50"
 fi
 
+dnl
+dnl Gallium swrast configuration
+dnl
+AC_ARG_ENABLE([gallium-swrast],
+    [AS_HELP_STRING([--enable-gallium-swrast],
+        [build gallium swrast @<:@default=disabled@:>@])],
+    [enable_gallium_swrast="$enableval"],
+    [enable_gallium_swrast=auto])
+if test "x$enable_gallium_swrast" = xyes; then
+    GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast"
+fi
+
 dnl prepend CORE_DIRS to SRC_DIRS
 SRC_DIRS="$CORE_DIRS $SRC_DIRS"
 
index 9bbce83d4b081aad164c8672f3581ce4b230846e..088259896694373448772445ee874cefc31b93aa 100644 (file)
@@ -32,10 +32,10 @@ cards.</p>
 the Gallium driver for your hardware.  For example</p>
 
 <pre>
-  $ ./configure --with-state-trackers=egl_g3d,es,vega --enable-gallium-intel
+  $ ./configure --with-state-trackers=egl,es,vega --enable-gallium-intel
 </pre>
 
-<p>The main library will be enabled by default.  The <code>egl_g3d</code> state
+<p>The main library will be enabled by default.  The <code>egl</code> state
 tracker is needed by a number of EGL drivers.  EGL drivers will be covered
 later.  The <a href="opengles.html">es state tracker</a> provides OpenGL ES 1.x
 and 2.x and the <a href="openvg.html">vega state tracker</a> provides OpenVG
@@ -77,9 +77,17 @@ bare KMS (kernel modesetting).</p>
 
 <p>The argument is a comma separated string.  It is usually used to specify the
 rendering APIs, like OpenGL ES or OpenVG, to build.  But it should be noted
-that a number of EGL drivers depend on the <code>egl_g3d</code> state tracker.
-They will <em>not</em> be built without the <code>egl_g3d</code> state
-tracker.</p>
+that a number of EGL drivers depend on the <code>egl</code> state tracker.
+They will <em>not</em> be built without the <code>egl</code> state tracker.</p>
+
+</li>
+
+<li><code>--enable-gallium-swrast</code>
+
+<p>This option is not specific to EGL.  But if there is no driver for your
+hardware, or you are experiencing problems with the hardware driver, you can
+enable the swrast DRM driver.  It is a dummy driver and EGL will fallback to
+software rendering automatically.</p>
 
 </li>
 </ul>
@@ -151,7 +159,7 @@ variable to true forces the use of software rendering.</p>
 
 <p>Gallium EGL drivers supports all rendering APIs specified in EGL 1.4.  The
 support for optional EGL functions and EGL extensions is usually more complete
-than the classic ones.  These drivers depend on the <code>egl_g3d</code> state
+than the classic ones.  These drivers depend on the <code>egl</code> state
 tracker to build.  The available drivers are</p>
 
 <ul>
@@ -159,6 +167,7 @@ tracker to build.  The available drivers are</p>
 <li><code>egl_&lt;dpy&gt;_i965</code></li>
 <li><code>egl_&lt;dpy&gt;_radeon</code></li>
 <li><code>egl_&lt;dpy&gt;_nouveau</code></li>
+<li><code>egl_&lt;dpy&gt;_swrast</code></li>
 <li><code>egl_&lt;dpy&gt;_vmwgfx</code></li>
 </ul>
 
@@ -182,12 +191,12 @@ is not available in GLX or GLX extensions.</p>
 <li><code>egl_xdri</code>
 
 <p>This driver supports the X Window System as its window system.  It functions
-as a DRI driver loader.  Unlike <code>egl_glx</code>, it has no dependency on
-<code>libGL</code>.  It talks to the X server directly using DRI or DRI2
-protocols.  It also talks minimal GLX protocol for things like available
-visuals or fbconfigs.  With direct access to the DRI drivers, it has the
-potential to support more EGL functions that are not possible with
-<code>egl_glx</code></p>
+as a DRI driver loader and can load DRI/DRI2/DRISW drivers.  Unlike
+<code>egl_glx</code>, it has no dependency on <code>libGL</code>.  It talks to
+the X server directly using DRI or DRI2 protocols.  It also talks minimal GLX
+protocol for things like available visuals or fbconfigs.  With direct access to
+the DRI drivers, it has the potential to support more EGL functions that are
+not possible with <code>egl_glx</code>.</p>
 
 </li>
 <li><code>egl_dri</code>
@@ -208,8 +217,8 @@ runtime.</p>
 <h2>Developers</h2>
 
 The sources of the main library and the classic drivers can be found at
-<code>src/egl/</code>.  The sources of the <code>egl_g3d</code> state tracker
-can be found at <code>src/gallium/state_trackers/egl_g3d/</code>.
+<code>src/egl/</code>.  The sources of the <code>egl</code> state tracker can
+be found at <code>src/gallium/state_trackers/egl/</code>.
 
 <h3>TODOs</h3>
 
index 5227fbd055b2d9392eeeac2e83525245aa0d2f20..9c17a9f3540444bae23da800e9489a7750b1c0e4 100644 (file)
 </p>
 
 <ul>
-<li><a href="https://lists.sourceforge.net/lists/listinfo/mesa3d-announce"
-target="_parent">mesa3d-announce</a> - announcements of new Mesa
-versions are sent to this list.
-</li>
-<br>
 <li><a href="https://lists.sourceforge.net/lists/listinfo/mesa3d-users"
-target="_parent">mesa3d-users</a> - intended for users of the Mesa and DRI.
-Newbie questions are appropriate, but please try the general OpenGL
+target="_parent">mesa3d-users</a> - intended for end-users of Mesa and DRI
+drivers.  Newbie questions are OK, but please try the general OpenGL
 resources and Mesa/DRI documentation first.
 </li>
 <br>
 <li><a href="https://lists.sourceforge.net/lists/listinfo/mesa3d-dev"
-target="_parent">mesa3d-dev</a> - for discussion of Mesa and Direct Rendering 
-Infrastructure development. Not for beginners.
+target="_parent">mesa3d-dev</a> - for Mesa, Gallium and DRI development
+discussion.  Not for beginners.
 </li>
 <br>
 <li><a href="http://lists.freedesktop.org/mailman/listinfo/mesa-commit"
 target="_parent">mesa-commit</a> - relays git check-in messages
 (for developers).
+In general, people should not post to this list.
+</li>
 <br>
-Note: the old mesa3d-cvs list is no longer in use.
+<li><a href="https://lists.sourceforge.net/lists/listinfo/mesa3d-announce"
+target="_parent">mesa3d-announce</a> - announcements of new Mesa
+versions are sent to this list.  Very low traffic.
 </li>
 </ul>
 
+<p>
+Follow the links above for list archives.
+</p>
+
 <p>For mailing lists about Direct Rendering Modules (drm) in Linux/BSD 
-kernels, see <a href="http://dri.freedesktop.org/wiki/MailingLists">wiki</a>.
+kernels, see the
+<a href="http://dri.freedesktop.org/wiki/MailingLists" target="_parent">
+DRI wiki</a>.
+</p>
 
 <p>
-<b>Notice</b>: non-member posts to any of these lists will be automatically
-rejected.
+<b>Notice</b>: You must subscribe to these lists in order to post to them.
 </p>
 
 
index a871e85d0b70611c4ef4685f735456c5ed712197..fc41e6771c132c14835f92774d5246f88f5cc6af 100644 (file)
@@ -20,7 +20,7 @@ for more information about EGL.</p>
 
 <h2>Build the Libraries</h2>
 <ol>
-<li>Run <code>configure</code> with <code>--with-state-trackers=egl_g3d,es</code> and enable the Gallium driver for your hardware.</li>
+<li>Run <code>configure</code> with <code>--with-state-trackers=egl,es</code> and enable the Gallium driver for your hardware.</li>
 <li>Build and install Mesa as usual.</li>
 </ol>
 
index cd39b133c437333003573eda625adeaf5a8eb462..cdf6b57e0f432b22136e2f00b5c0d31f13d1e678 100644 (file)
@@ -34,7 +34,7 @@ Please refer to <a href="egl.html">Mesa EGL</a> for more information about EGL.
 <h3>Sample build</h3>
 A sample build looks as follows:
 <pre>
-  $ ./configure --with-state-trackers=egl_g3d,vega --enable-gallium-intel
+  $ ./configure --with-state-trackers=egl,vega --enable-gallium-intel
   $ make
   $ make install
 </pre>
index bc4ce71bee5033c52f952f5ba3e265928012a7ce..00dc4e7c9f4665a4f08f5327f6e7a28973f263a3 100644 (file)
@@ -48,6 +48,7 @@ each directory.
        <li><b>glslcompiler</b> - a stand-alone GLSL compiler driver
         <li>XXX more
         </ul>
+    <li><b>es</b> - OpenGL ES overlay, parallelly buildable with the core Mesa
     <li><b>math</b> - vertex array translation and transformation code
         (not used with Gallium)
     <li><b>ppc</b> - Assembly code/optimizations for PPC systems
@@ -123,20 +124,19 @@ each directory.
       </ul>
     <li><b>state_trackers</b> -
        <ul>
-       <li><b>dri</b> -
-       <li><b>egl</b> -
-       <li><b>es</b> -
+       <li><b>dri</b> - Meta state tracker for DRI drivers
+       <li><b>egl</b> - Meta state tracker for EGL drivers
+       <li><b>es</b> - OpenGL ES 1.x and 2.x state trackers
        <li><b>g3dvl</b> -
-       <li><b>glx</b> -
+       <li><b>glx</b> - Meta state tracker for GLX
        <li><b>python</b> -
-       <li><b>vega</b> -
+       <li><b>vega</b> - OpenVG 1.x state tracker
        <li><b>wgl</b> -
-       <li><b>xorg</b> -
+       <li><b>xorg</b> - Meta state tracker for Xorg video drivers
        </ul>
     <li><b>winsys</b> -
        <ul>
        <li><b>drm</b> -
-       <li><b>egl_xlib</b> -
        <li><b>g3dvl</b> -
        <li><b>gdi</b> -
        <li><b>xlib</b> -
index df4725c7b4e42825d758037733625e5a4bec9099..2e8fb74a00bb575319a2abf00af404c189d1f73d 100644 (file)
@@ -6,7 +6,6 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <math.h>
 
 /* For debug */
 
index 088f25a357ab08753bb6faa976db672734f3a3e4..2993c82416169169ef0ee27a19a3c00259651a69 100644 (file)
@@ -771,6 +771,7 @@ main(int argc, char *argv[])
    glDeleteLists(gear1, 1);
    glDeleteLists(gear2, 1);
    glDeleteLists(gear3, 1);
+   glXMakeCurrent(dpy, None, NULL);
    glXDestroyContext(dpy, ctx);
    XDestroyWindow(dpy, win);
    XCloseDisplay(dpy);
index 314a4fcdd179d7cb6b113dac8ec94692ccbe1171..3858a5b8020e8fd93e0814c4dff166df17c72e63 100644 (file)
@@ -94,6 +94,9 @@ static int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
 
 static int dimension = 3;
 
+static float Scale = 1.0;
+
+
 int main(int argc, char** argv) {
     Display *dpy;
     XVisualInfo *vi;
@@ -182,6 +185,7 @@ draw_scene(int mx, int my) {
 #else
     glEnable(GL_POLYGON_OFFSET_FILL);
 #endif
+    glScalef(Scale, Scale, Scale);
     cubes(mx, my, HIDDEN_LINE);
 #ifdef GL_EXT_polygon_offset
     glDisable(GL_POLYGON_OFFSET_EXT);
@@ -289,6 +293,12 @@ process_input(Display *dpy, Window win) {
        case KeyPress:
            (void) XLookupString(&event.xkey, buf, sizeof(buf), &keysym, NULL);
            switch (keysym) {
+            case 'Z':
+               Scale *= 1.1;
+               break;
+            case 'z':
+               Scale *= 0.9;
+               break;
            case XK_Escape:
                exit(EXIT_SUCCESS);
            default:
diff --git a/src/egl/drivers/Makefile.template b/src/egl/drivers/Makefile.template
new file mode 100644 (file)
index 0000000..02a65b0
--- /dev/null
@@ -0,0 +1,51 @@
+# src/egl/drivers/Makefile.template
+#
+# Drivers should define
+#
+# EGL_DRIVER, the driver name
+# EGL_SOURCES, the driver sources
+# EGL_INCLUDES, the include pathes
+# EGL_CFLAGS, additional CFLAGS
+# EGL_LIBS, additional LIBS
+#
+# before including this template.
+#
+
+
+EGL_DRIVER_PATH = $(TOP)/$(LIB_DIR)/$(EGL_DRIVER)
+EGL_OBJECTS = $(EGL_SOURCES:.c=.o)
+
+
+default: depend $(EGL_DRIVER_PATH)
+
+$(EGL_DRIVER_PATH): $(EGL_DRIVER)
+       $(INSTALL) $< $(TOP)/$(LIB_DIR)
+
+$(EGL_DRIVER): $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template
+       @$(MKLIB) -o $(EGL_DRIVER) -noprefix \
+               -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+               -L$(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
+               $(EGL_OBJECTS) $(EGL_LIBS)
+
+.c.o:
+       $(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@
+
+
+install: $(EGL_DRIVER_PATH)
+       $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
+       $(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(INSTALL_LIB_DIR)
+
+clean:
+       rm -f $(EGL_DRIVER)
+       rm -f $(EGL_OBJECTS)
+       rm -f depend depend.bak
+
+depend: $(EGL_SOURCES)
+       @ echo "running $(MKDEP)"
+       @ rm -f depend
+       @ touch depend
+       $(MKDEP) $(MKDEP_OPTIONS) $(EGL_INCLUDES) $(EGL_SOURCES) \
+               >/dev/null 2>/dev/null
+
+sinclude depend
+# DO NOT DELETE
diff --git a/src/egl/drivers/demo/Makefile b/src/egl/drivers/demo/Makefile
deleted file mode 100644 (file)
index 444dfb3..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-# src/egl/drivers/demo/Makefile
-
-TOP = ../../../..
-include $(TOP)/configs/current
-
-
-INCLUDE_DIRS = -I$(TOP)/include -I$(TOP)/src/egl/main $(X11_INCLUDES)
-
-
-SOURCES = demo.c
-
-OBJECTS = $(SOURCES:.c=.o)
-
-
-.c.o:
-       $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(TOP)/$(LIB_DIR)/demodriver.so
-
-
-$(TOP)/$(LIB_DIR)/demodriver.so: $(OBJECTS)
-       $(MKLIB) -o demodriver.so -noprefix -linker '$(CC)' \
-               -ldflags '$(LDFLAGS)' -install $(TOP)/$(LIB_DIR) \
-               $(OBJECTS)
-
-install:
-
-clean:
-       -rm -f *.o
-       -rm -f *.so
diff --git a/src/egl/drivers/demo/demo.c b/src/egl/drivers/demo/demo.c
deleted file mode 100644 (file)
index 0933c0b..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Sample driver: Demo
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "eglconfig.h"
-#include "eglcontext.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglglobals.h"
-#include "eglmode.h"
-#include "eglscreen.h"
-#include "eglsurface.h"
-
-
-/**
- * Demo driver-specific driver class derived from _EGLDriver
- */
-typedef struct demo_driver
-{
-   _EGLDriver Base;  /* base class/object */
-   unsigned DemoStuff;
-} DemoDriver;
-
-#define DEMO_DRIVER(D) ((DemoDriver *) (D))
-
-
-/**
- * Demo driver-specific surface class derived from _EGLSurface
- */
-typedef struct demo_surface
-{
-   _EGLSurface Base;  /* base class/object */
-   unsigned DemoStuff;
-} DemoSurface;
-
-
-/**
- * Demo driver-specific context class derived from _EGLContext
- */
-typedef struct demo_context
-{
-   _EGLContext Base;  /* base class/object */
-   unsigned DemoStuff;
-} DemoContext;
-
-
-
-static EGLBoolean
-demoInitialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
-{
-   _EGLScreen *scrn;
-   EGLint i;
-
-   /* Create a screen */
-   scrn = calloc(1, sizeof(*scrn));
-   _eglAddScreen(disp, scrn);
-
-   /* Create the screen's modes - silly example */
-   _eglAddNewMode(scrn, 1600, 1200, 72 * 1000, "1600x1200-72");
-   _eglAddNewMode(scrn, 1280, 1024, 72 * 1000, "1280x1024-70");
-   _eglAddNewMode(scrn, 1280, 1024, 70 * 1000, "1280x1024-70");
-   _eglAddNewMode(scrn, 1024,  768, 72 * 1000, "1024x768-72");
-
-   /* Create the display's visual configs - silly example */
-   for (i = 0; i < 4; i++) {
-      _EGLConfig *config = calloc(1, sizeof(_EGLConfig));
-      _eglInitConfig(config, i + 1);
-      _eglSetConfigAttrib(config, EGL_RED_SIZE, 8);
-      _eglSetConfigAttrib(config, EGL_GREEN_SIZE, 8);
-      _eglSetConfigAttrib(config, EGL_BLUE_SIZE, 8);
-      _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, 8);
-      _eglSetConfigAttrib(config, EGL_BUFFER_SIZE, 32);
-      if (i & 1) {
-         _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, 32);
-      }
-      if (i & 2) {
-         _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, 8);
-      }
-      _eglSetConfigAttrib(config, EGL_SURFACE_TYPE,
-                          (EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT));
-      _eglAddConfig(disp, config);
-   }
-
-   /* enable supported extensions */
-   disp->Extensions.MESA_screen_surface = EGL_TRUE;
-   disp->Extensions.MESA_copy_context = EGL_TRUE;
-
-   *major = 1;
-   *minor = 0;
-
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-demoTerminate(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
-   return EGL_TRUE;
-}
-
-
-static DemoContext *
-LookupDemoContext(_EGLContext *c)
-{
-   return (DemoContext *) c;
-}
-
-
-static DemoSurface *
-LookupDemoSurface(_EGLSurface *s)
-{
-   return (DemoSurface *) s;
-}
-
-
-static _EGLContext *
-demoCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list)
-{
-   DemoContext *c;
-   int i;
-
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs defined for now */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext");
-         return NULL;
-      }
-   }
-
-   c = (DemoContext *) calloc(1, sizeof(DemoContext));
-   if (!c)
-      return NULL;
-
-   _eglInitContext(drv, &c->Base, conf, attrib_list);
-   c->DemoStuff = 1;
-   printf("demoCreateContext\n");
-
-   return &c->Base;
-}
-
-
-static _EGLSurface *
-demoCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list)
-{
-   int i;
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs at this time */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreateWindowSurface");
-         return NULL;
-      }
-   }
-   printf("eglCreateWindowSurface()\n");
-   /* XXX unfinished */
-
-   return NULL;
-}
-
-
-static _EGLSurface *
-demoCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list)
-{
-   EGLint i;
-
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs at this time */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface");
-         return NULL;
-      }
-   }
-
-   if (GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE) == 0) {
-      _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface");
-      return NULL;
-   }
-
-   printf("eglCreatePixmapSurface()\n");
-   return NULL;
-}
-
-
-static _EGLSurface *
-demoCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
-                         const EGLint *attrib_list)
-{
-   DemoSurface *surf = (DemoSurface *) calloc(1, sizeof(DemoSurface));
-
-   if (!surf)
-      return NULL;
-
-   if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT,
-                        conf, attrib_list)) {
-      free(surf);
-      return NULL;
-   }
-
-   /* a real driver would allocate the pbuffer memory here */
-
-   return &surf->Base;
-}
-
-
-static EGLBoolean
-demoDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
-{
-   DemoSurface *fs = LookupDemoSurface(surface);
-   if (!_eglIsSurfaceBound(&fs->Base))
-      free(fs);
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-demoDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context)
-{
-   DemoContext *fc = LookupDemoContext(context);
-   if (!_eglIsContextBound(&fc->Base))
-      free(fc);
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-demoMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *drawSurf, _EGLSurface *readSurf, _EGLContext *ctx)
-{
-   /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
-   EGLBoolean b;
-
-   b = _eglMakeCurrent(drv, dpy, drawSurf, readSurf, ctx);
-   if (!b)
-      return EGL_FALSE;
-
-   /* XXX this is where we'd do the hardware context switch */
-   (void) drawSurf;
-   (void) readSurf;
-   (void) ctx;
-
-   printf("eglMakeCurrent()\n");
-   return EGL_TRUE;
-}
-
-
-static void
-demoUnload(_EGLDriver *drv)
-{
-   free(drv);
-}
-
-
-/**
- * The bootstrap function.  Return a new DemoDriver object and
- * plug in API functions.
- */
-_EGLDriver *
-_eglMain(const char *args)
-{
-   DemoDriver *demo;
-
-   demo = (DemoDriver *) calloc(1, sizeof(DemoDriver));
-   if (!demo) {
-      return NULL;
-   }
-
-   /* First fill in the dispatch table with defaults */
-   _eglInitDriverFallbacks(&demo->Base);
-   /* then plug in our Demo-specific functions */
-   demo->Base.API.Initialize = demoInitialize;
-   demo->Base.API.Terminate = demoTerminate;
-   demo->Base.API.CreateContext = demoCreateContext;
-   demo->Base.API.MakeCurrent = demoMakeCurrent;
-   demo->Base.API.CreateWindowSurface = demoCreateWindowSurface;
-   demo->Base.API.CreatePixmapSurface = demoCreatePixmapSurface;
-   demo->Base.API.CreatePbufferSurface = demoCreatePbufferSurface;
-   demo->Base.API.DestroySurface = demoDestroySurface;
-   demo->Base.API.DestroyContext = demoDestroyContext;
-
-   demo->Base.Name = "egl/demo";
-   demo->Base.Unload = demoUnload;
-
-   return &demo->Base;
-}
index 20ef0352ad9cb407a0d44e2f0c122e2c752a090f..634638f5387a11cdea55f2a0443a186325c5da5a 100644 (file)
@@ -1,77 +1,16 @@
 # src/egl/drivers/glx/Makefile
 
-# Build XEGL DRI driver loader library:  egl_glx.so
-
-
 TOP = ../../../..
 include $(TOP)/configs/current
 
+EGL_DRIVER = egl_glx.so
+EGL_SOURCES = egl_glx.c
 
-EXTRA_DEFINES = -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\"
-
-DRIVER_NAME = egl_glx.so
-
-
-INCLUDE_DIRS = \
-       -I. \
-       -I/usr/include \
-       $(shell pkg-config --cflags-only-I libdrm) \
+EGL_INCLUDES = \
        -I$(TOP)/include \
-       -I$(TOP)/include/GL/internal \
-       -I$(TOP)/src/mesa/glapi \
-       -I$(TOP)/src/mesa/drivers/dri/common \
-       -I$(TOP)/src/mesa/main \
-       -I$(TOP)/src/mesa \
-       -I$(TOP)/src/egl/main \
-       -I$(TOP)/src/glx/x11
-
-SOURCES = egl_glx.c
-
-OBJECTS = $(SOURCES:.c=.o)
-
-DRM_LIB = `pkg-config --libs libdrm`
-
-MISC_LIBS = -ldl -lXext -lGL
-
-
-.c.o:
-       $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(EXTRA_DEFINES) $< -o $@
-
-
-.PHONY: library
-
-
-default: depend library Makefile
-
-
-library: $(TOP)/$(LIB_DIR)/$(DRIVER_NAME)
-
-
-# Make the egl_glx.so library
-$(TOP)/$(LIB_DIR)/$(DRIVER_NAME): $(OBJECTS)
-       $(TOP)/bin/mklib -o $(DRIVER_NAME) \
-               -noprefix \
-               -major 1 -minor 0 \
-               -L$(TOP)/$(LIB_DIR) \
-               -install $(TOP)/$(LIB_DIR) \
-               $(OBJECTS) $(DRM_LIB) $(MISC_LIBS)
-
-install:
-       $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
-       $(MINSTALL) $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)
-
-clean:
-       rm -f *.o
-       rm -f *.so
-       rm -f depend depend.bak
-
+       -I$(TOP)/src/egl/main
 
-depend: $(SOURCES) $(HEADERS)
-       @ echo "running $(MKDEP)"
-       @ rm -f depend
-       @ touch depend
-       $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \
-               $(SOURCES) $(HEADERS) >/dev/null 2>/dev/null
+EGL_CFLAGS =
+EGL_LIBS = -lX11 -lGL
 
-include depend
-# DO NOT DELETE
+include ../Makefile.template
index 7c6e8637a1ca8c4cc964583c78679f0cdae47d52..6d2815888b111d5526bec646103465dbeda23664 100644 (file)
 #error "GL/glx.h must be equal to or greater than GLX 1.4"
 #endif
 
-/*
- * report OpenGL ES bits because apps usually forget to specify
- * EGL_RENDERABLE_TYPE when choosing configs
- */
-#define GLX_EGL_APIS (EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT)
-
-
 /** subclass of _EGLDriver */
 struct GLX_egl_driver
 {
@@ -244,7 +237,7 @@ convert_fbconfig(Display *dpy, GLXFBConfig fbconfig,
 
    GLX_conf->double_buffered = (mode.doubleBufferMode != 0);
    return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode,
-                                        GLX_EGL_APIS, GLX_EGL_APIS);
+                                        EGL_OPENGL_BIT, EGL_OPENGL_BIT);
 }
 
 
@@ -364,7 +357,7 @@ convert_visual(Display *dpy, XVisualInfo *vinfo,
 
    GLX_conf->double_buffered = (mode.doubleBufferMode != 0);
    return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode,
-                                        GLX_EGL_APIS, GLX_EGL_APIS);
+                                        EGL_OPENGL_BIT, EGL_OPENGL_BIT);
 }
 
 
@@ -559,7 +552,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
    }
 
    disp->DriverData = (void *) GLX_dpy;
-   disp->ClientAPIsMask = GLX_EGL_APIS;
+   disp->ClientAPIsMask = EGL_OPENGL_BIT;
 
    /* we're supporting EGL 1.4 */
    *major = 1;
index 4c1fc9071c5457b4bd0df8f284a3bc1f46421cfd..9120620dc521e7b9dfb8b4bf86218973b0767fb8 100644 (file)
@@ -1,78 +1,28 @@
 # src/egl/drivers/xdri/Makefile
 
-# Build XEGL DRI driver loader library:  egl_xdri.so
-
-
 TOP = ../../../..
 include $(TOP)/configs/current
 
+EGL_DRIVER = egl_xdri.so
 
-DRIVER_NAME = egl_xdri.so
-
-
-INCLUDE_DIRS = \
-       -I. \
-       -I/usr/include \
+# steal sources from GLX
+GLX_SOURCES = dri_common.c XF86dri.c dri2.c dri2_glx.c dri_glx.c drisw_glx.c
+GLX_SOURCES := $(addprefix ../../../glx/x11/,$(GLX_SOURCES))
+GLX_INCLUDES = \
        $(shell pkg-config --cflags-only-I libdrm) \
-       -I$(TOP)/include \
        -I$(TOP)/include/GL/internal \
-       -I$(TOP)/src/mesa \
+       -I$(TOP)/src/glx/x11 \
        -I$(TOP)/src/mesa/glapi \
-       -I$(TOP)/src/egl/main \
-       -I$(TOP)/src/glx/x11
-
-HEADERS = glxinit.h driinit.h
-SOURCES = egl_xdri.c glxinit.c driinit.c
-
-DRI_SOURCES = dri_common.c XF86dri.c dri2.c dri2_glx.c dri_glx.c
-DRI_SOURCES := $(addprefix ../../../glx/x11/,$(DRI_SOURCES))
-
-SOURCES += $(DRI_SOURCES)
-
-OBJECTS = $(SOURCES:.c=.o)
-
-DRM_LIB = `pkg-config --libs libdrm`
-
-CFLAGS += -DGLX_DIRECT_RENDERING
-
-.c.o:
-       $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-.PHONY: library
-
-
-default: depend library Makefile
-
-
-library: $(TOP)/$(LIB_DIR)/$(DRIVER_NAME)
-
-
-# Make the egl_xdri.so library
-$(TOP)/$(LIB_DIR)/$(DRIVER_NAME): $(OBJECTS)
-       $(TOP)/bin/mklib -o $(DRIVER_NAME) \
-               -noprefix \
-               -major 1 -minor 0 \
-               -L$(TOP)/$(LIB_DIR) \
-               -install $(TOP)/$(LIB_DIR) \
-               $(OBJECTS) $(DRM_LIB) $(GL_LIB_DEPS)
-
-install:
-       $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
-       $(MINSTALL) $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)
-
-clean:
-       rm -f *.o
-       rm -f *.so
-       rm -f depend depend.bak
+       -I$(TOP)/src/mesa
+GLX_CFLAGS = -DGLX_DIRECT_RENDERING
 
+EGL_SOURCES = egl_xdri.c glxinit.c driinit.c $(GLX_SOURCES)
+EGL_INCLUDES = \
+       -I$(TOP)/include \
+       -I$(TOP)/src/egl/main \
+       $(GLX_INCLUDES)
 
-depend: $(SOURCES) $(HEADERS)
-       @ echo "running $(MKDEP)"
-       @ rm -f depend
-       @ touch depend
-       $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \
-               $(SOURCES) $(HEADERS) >/dev/null 2>/dev/null
+EGL_CFLAGS = $(GLX_CFLAGS)
+EGL_LIBS = -lX11 -lGL
 
-include depend
-# DO NOT DELETE
+include ../Makefile.template
index 12da1bcd248bd954dbe4c960ee0a9b6400991d3f..3e54f0bd4d8be3e9550835bab68c0f3ee1cbae23 100644 (file)
@@ -2,6 +2,7 @@
  * DRI initialization.  The DRI loaders are defined in src/glx/x11/.
  */
 
+#include <stdlib.h>
 #include <sys/time.h>
 
 #include "glxclient.h"
@@ -42,18 +43,26 @@ __glXEnableDirectExtension(__GLXscreenConfigs * psc, const char *name)
 _X_HIDDEN __GLXDRIdisplay *
 __driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version)
 {
-   __GLXDRIdisplay *driDisplay;
+   __GLXDRIdisplay *driDisplay = NULL;
    int ver = 0;
+   char *env;
+   int force_sw;
+
+   env = getenv("EGL_SOFTWARE");
+   force_sw = (env && *env != '0');
 
    /* try DRI2 first */
-   driDisplay = dri2CreateDisplay(dpyPriv->dpy);
-   if (driDisplay) {
-      /* fill in the required field */
-      dpyPriv->dri2Display = driDisplay;
-      ver = 2;
+   if (!force_sw) {
+      driDisplay = dri2CreateDisplay(dpyPriv->dpy);
+      if (driDisplay) {
+         /* fill in the required field */
+         dpyPriv->dri2Display = driDisplay;
+         ver = 2;
+      }
    }
-   else {
-      /* try DRI */
+
+   /* and then DRI */
+   if (!force_sw && !driDisplay) {
       driDisplay = driCreateDisplay(dpyPriv->dpy);
       if (driDisplay) {
          dpyPriv->driDisplay = driDisplay;
@@ -61,6 +70,15 @@ __driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version)
       }
    }
 
+   /* and then DRISW */
+   if (!driDisplay) {
+      driDisplay = driswCreateDisplay(dpyPriv->dpy);
+      if (driDisplay) {
+         dpyPriv->driDisplay = driDisplay;
+         ver = 0;
+      }
+   }
+
    if (version)
       *version = ver;
    return driDisplay;
index 8425b3d11efab7e6d48d271eaf440a20d77dbae2..b133939155db1c3c40aef656eb0ddf4fc031b637 100644 (file)
@@ -62,6 +62,7 @@
 struct xdri_egl_driver
 {
    _EGLDriver Base;   /**< base class */
+   void (*FlushCurrentContext)(void);
 };
 
 
@@ -71,6 +72,7 @@ struct xdri_egl_display
    Display *dpy;
    __GLXdisplayPrivate *dpyPriv;
    __GLXDRIdisplay *driDisplay;
+   int driVersion;
 
    __GLXscreenConfigs *psc;
    EGLint scr;
@@ -167,14 +169,10 @@ get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height)
 static EGLBoolean
 convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m)
 {
-   static const EGLint all_apis = (EGL_OPENGL_ES_BIT |
-                                   EGL_OPENGL_ES2_BIT |
-                                   EGL_OPENVG_BIT |
-                                   EGL_OPENGL_BIT);
    EGLint val;
 
    _eglInitConfig(conf, id);
-   if (!_eglConfigFromContextModesRec(conf, m, all_apis, all_apis))
+   if (!_eglConfigFromContextModesRec(conf, m, EGL_OPENGL_BIT, EGL_OPENGL_BIT))
       return EGL_FALSE;
 
    if (m->doubleBufferMode) {
@@ -215,6 +213,7 @@ convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m)
 static EGLint
 create_configs(_EGLDisplay *disp, const __GLcontextModes *m, EGLint first_id)
 {
+   struct xdri_egl_display *xdri_dpy = lookup_display(disp);
    int id = first_id;
 
    for (; m; m = m->next) {
@@ -224,8 +223,15 @@ create_configs(_EGLDisplay *disp, const __GLcontextModes *m, EGLint first_id)
 
       if (!convert_config(&conf, id, m))
          continue;
-
-      rb = (m->doubleBufferMode) ? EGL_BACK_BUFFER : EGL_SINGLE_BUFFER;
+      if (m->doubleBufferMode) {
+         rb = EGL_BACK_BUFFER;
+      }
+      else {
+         /* ignore single-buffered mode for DRISW */
+         if (xdri_dpy->driVersion == 0)
+            continue;
+         rb = EGL_SINGLE_BUFFER;
+      }
 
       xdri_conf = CALLOC_STRUCT(xdri_egl_config);
       if (xdri_conf) {
@@ -275,7 +281,7 @@ xdri_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
       return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
    }
 
-   driDisplay = __driCreateDisplay(dpyPriv, NULL);
+   driDisplay = __driCreateDisplay(dpyPriv, &xdri_dpy->driVersion);
    if (!driDisplay) {
       _eglLog(_EGL_WARNING, "failed to create DRI display");
       free(xdri_dpy);
@@ -297,16 +303,13 @@ xdri_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
       return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
    }
 
+   dpy->DriverData = xdri_dpy;
+   dpy->ClientAPIsMask = EGL_OPENGL_BIT;
+
    /* add visuals and fbconfigs */
    first_id = create_configs(dpy, psc->visuals, first_id);
    create_configs(dpy, psc->configs, first_id);
 
-   dpy->DriverData = xdri_dpy;
-   dpy->ClientAPIsMask = (EGL_OPENGL_BIT |
-                          EGL_OPENGL_ES_BIT |
-                          EGL_OPENGL_ES2_BIT |
-                          EGL_OPENVG_BIT);
-
    /* we're supporting EGL 1.4 */
    *minor = 1;
    *major = 4;
@@ -342,7 +345,6 @@ xdri_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy)
    }
 
    xdri_dpy->driDisplay->destroyDisplay(xdri_dpy->driDisplay);
-   __glXRelease(xdri_dpy->dpyPriv);
 
    free(xdri_dpy);
    dpy->DriverData = NULL;
@@ -441,13 +443,23 @@ static EGLBoolean
 xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
                     _EGLSurface *r, _EGLContext *context)
 {
+   struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
    struct xdri_egl_context *xdri_ctx = lookup_context(context);
    struct xdri_egl_surface *draw = lookup_surface(d);
    struct xdri_egl_surface *read = lookup_surface(r);
+   _EGLContext *old = _eglGetCurrentContext();
+
+   /* an unlinked context will be invalid after context switch */
+   if (!_eglIsContextLinked(old))
+      old = NULL;
 
    if (!_eglMakeCurrent(drv, dpy, d, r, context))
       return EGL_FALSE;
 
+   /* flush before context switch */
+   if (old && old != context && xdri_driver->FlushCurrentContext)
+      xdri_driver->FlushCurrentContext();
+
    /* the symbol is defined in libGL.so */
    _glapi_check_multithread();
 
@@ -458,12 +470,9 @@ xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
          return EGL_FALSE;
       }
    }
-   else {
-      _EGLContext *old = _eglGetCurrentContext();
-      if (old) {
-         xdri_ctx = lookup_context(old);
-         xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
-      }
+   else if (old) {
+      xdri_ctx = lookup_context(old);
+      xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
    }
 
    return EGL_TRUE;
@@ -559,9 +568,15 @@ xdri_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
 static EGLBoolean
 xdri_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
 {
+   struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
    struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
    struct xdri_egl_surface *xdri_surf = lookup_surface(draw);
 
+   /* swapBuffers does not flush commands */
+   if (draw == _eglGetCurrentSurface(EGL_DRAW) &&
+       xdri_driver->FlushCurrentContext)
+      xdri_driver->FlushCurrentContext();
    xdri_dpy->psc->driScreen->swapBuffers(xdri_surf->driDrawable, 0, 0, 0);
 
    return EGL_TRUE;
@@ -606,5 +621,9 @@ _eglMain(const char *args)
    xdri_drv->Base.Name = "X/DRI";
    xdri_drv->Base.Unload = xdri_Unload;
 
+   /* we need a way to flush commands */
+   xdri_drv->FlushCurrentContext =
+      (void (*)(void)) xdri_eglGetProcAddress(&xdri_drv->Base, "glFlush");
+
    return &xdri_drv->Base;
 }
index 77750093944d51e1db1ae4f66555a6519d4a5a02..5c0fbc6b3c365cb9bfa8cee1d97368c5b4278786 100644 (file)
@@ -1,8 +1,10 @@
 /**
  * GLX initialization.  Code based on glxext.c, glx_query.c, and
- * glcontextmodes.c under src/glx/x11/.  The major difference is that no DRI
- * related code here.
+ * glcontextmodes.c under src/glx/x11/.  The major difference is that DRI
+ * related code is stripped out.
  *
+ * If the maintenance of this file takes too much time, we should consider
+ * refactoring glxext.c.
  */
 
 #include <assert.h>
@@ -31,7 +33,26 @@ typedef struct GLXGenericGetString
 static char *__glXExtensionName = GLX_EXTENSION_NAME;
 static XExtensionInfo *__glXExtensionInfo = NULL;
 
-static /* const */ XExtensionHooks __glXExtensionHooks = { NULL };
+static int
+__glXCloseDisplay(Display * dpy, XExtCodes * codes)
+{
+   return XextRemoveDisplay(__glXExtensionInfo, dpy);
+}
+
+static /* const */ XExtensionHooks __glXExtensionHooks = {
+  NULL,                   /* create_gc */
+  NULL,                   /* copy_gc */
+  NULL,                   /* flush_gc */
+  NULL,                   /* free_gc */
+  NULL,                   /* create_font */
+  NULL,                   /* free_font */
+  __glXCloseDisplay,      /* close_display */
+  NULL,                   /* wire_to_event */
+  NULL,                   /* event_to_wire */
+  NULL,                   /* error */
+  NULL,                   /* error_string */
+};
+
 static
 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo,
                            __glXExtensionName, &__glXExtensionHooks,
@@ -180,6 +201,30 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv)
    priv->screenConfigs = NULL;
 }
 
+/*
+** Release the private memory referred to in a display private
+** structure.  The caller will free the extension structure.
+*/
+static int
+__glXFreeDisplayPrivate(XExtData * extension)
+{
+   __GLXdisplayPrivate *priv;
+
+   priv = (__GLXdisplayPrivate *) extension->private_data;
+   FreeScreenConfigs(priv);
+   if (priv->serverGLXvendor) {
+      Xfree((char *) priv->serverGLXvendor);
+      priv->serverGLXvendor = 0x0;      /* to protect against double free's */
+   }
+   if (priv->serverGLXversion) {
+      Xfree((char *) priv->serverGLXversion);
+      priv->serverGLXversion = 0x0;     /* to protect against double free's */
+   }
+
+   Xfree((char *) priv);
+   return 0;
+}
+
 /************************************************************************/
 
 /*
@@ -570,40 +615,40 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
    return GL_TRUE;
 }
 
-_X_HIDDEN void
-__glXRelease(__GLXdisplayPrivate *dpyPriv)
-{
-   FreeScreenConfigs(dpyPriv);
-
-   if (dpyPriv->serverGLXvendor) {
-      Xfree((char *) dpyPriv->serverGLXvendor);
-      dpyPriv->serverGLXvendor = NULL;
-   }
-   if (dpyPriv->serverGLXversion) {
-      Xfree((char *) dpyPriv->serverGLXversion);
-      dpyPriv->serverGLXversion = NULL;
-   }
-
-   Xfree(dpyPriv);
-}
-
 _X_HIDDEN __GLXdisplayPrivate *
 __glXInitialize(Display * dpy)
 {
    XExtDisplayInfo *info = __glXFindDisplay(dpy);
+   XExtData **privList, *private, *found;
    __GLXdisplayPrivate *dpyPriv;
+   XEDataObject dataObj;
    int major, minor;
 
    if (!XextHasExtension(info))
       return NULL;
 
+   /* See if a display private already exists.  If so, return it */
+   dataObj.display = dpy;
+   privList = XEHeadOfExtensionList(dataObj);
+   found = XFindOnExtensionList(privList, info->codes->extension);
+   if (found)
+      return (__GLXdisplayPrivate *) found->private_data;
+
    /* See if the versions are compatible */
    if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor))
       return NULL;
 
+   /*
+    ** Allocate memory for all the pieces needed for this buffer.
+    */
+   private = (XExtData *) Xmalloc(sizeof(XExtData));
+   if (!private)
+      return NULL;
    dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate));
-   if (!dpyPriv)
+   if (!dpyPriv) {
+      Xfree(private);
       return NULL;
+   }
 
    /*
     ** Init the display private and then read in the screen config
@@ -619,8 +664,20 @@ __glXInitialize(Display * dpy)
 
    if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
       Xfree(dpyPriv);
+      Xfree(private);
       return NULL;
    }
 
+   /*
+    ** Fill in the private structure.  This is the actual structure that
+    ** hangs off of the Display structure.  Our private structure is
+    ** referred to by this structure.  Got that?
+    */
+   private->number = info->codes->extension;
+   private->next = 0;
+   private->free_private = __glXFreeDisplayPrivate;
+   private->private_data = (char *) dpyPriv;
+   XAddToExtensionList(privList, private);
+
    return dpyPriv;
 }
index 57206e627b2e8519ff85cfda8c349675cd29f520..1cc7c460fe27da20f076176cb4f767cbb997fea1 100644 (file)
@@ -8,7 +8,4 @@
 extern void
 _gl_context_modes_destroy(__GLcontextModes * modes);
 
-extern void
-__glXRelease(__GLXdisplayPrivate *dpyPriv);
-
 #endif /* GLXINIT_INCLUDED */
index 0574f83f45037e4867ca020946065e90df2078a8..f890df1bb1b3660fe5ccc7b0a505390948549cce 100644 (file)
@@ -61,7 +61,7 @@ library_suffix(void)
 #elif defined(_EGL_PLATFORM_POSIX)
 
 
-static const char DefaultDriverName[] = "egl_softpipe";
+static const char DefaultDriverName[] = "egl_glx";
 
 typedef void * lib_handle;
 
index 8f937e3b4e9dbdab946b93394dbaa624fbf95d30..da1fb6b299f17332613dbf68c06e1aa99d27fff6 100644 (file)
@@ -48,12 +48,10 @@ C_SOURCES = \
        draw/draw_vs_sse.c \
        indices/u_indices_gen.c \
        indices/u_unfilled_gen.c \
-       pipebuffer/pb_buffer_fenced.c \
        pipebuffer/pb_buffer_malloc.c \
        pipebuffer/pb_bufmgr_alt.c \
        pipebuffer/pb_bufmgr_cache.c \
        pipebuffer/pb_bufmgr_debug.c \
-       pipebuffer/pb_bufmgr_fenced.c \
        pipebuffer/pb_bufmgr_mm.c \
        pipebuffer/pb_bufmgr_ondemand.c \
        pipebuffer/pb_bufmgr_pool.c \
@@ -92,6 +90,7 @@ C_SOURCES = \
        util/u_debug_dump.c \
        util/u_debug_symbol.c \
        util/u_debug_stack.c \
+       util/u_bitmask.c \
        util/u_blit.c \
        util/u_blitter.c \
        util/u_cache.c \
index f957090b5fb1ebf6a5da4e9b0c12ddaa4b3ccfd2..3aa782f81e6ebcfa89fd29013c5c7bc26d380930 100644 (file)
@@ -87,7 +87,6 @@ source = [
     'pipebuffer/pb_bufmgr_alt.c',
     'pipebuffer/pb_bufmgr_cache.c',
     'pipebuffer/pb_bufmgr_debug.c',
-    'pipebuffer/pb_bufmgr_fenced.c',
     'pipebuffer/pb_bufmgr_mm.c',
     'pipebuffer/pb_bufmgr_ondemand.c',
     'pipebuffer/pb_bufmgr_pool.c',
index e90dfc5aec4b53557898520e8d4cb9308b8e564e..fb1bc05af4ae0aa8622e5d59f1dd46a255efec8b 100644 (file)
@@ -34,7 +34,6 @@
 #include "util/u_memory.h"
 #include "util/u_math.h"
 #include "draw_context.h"
-#include "draw_vbuf.h"
 #include "draw_vs.h"
 #include "draw_gs.h"
 #include "draw_pt.h"
index 1c6d657297c7e161268ad223937f1148de151033..11d6485dcf074021eb5b67292b54a20871387dc5 100644 (file)
@@ -106,10 +106,9 @@ void draw_pipeline_destroy( struct draw_context *draw )
 
 
 
-
-
-
-
+/**
+ * Build primitive to render a point with vertex at v0.
+ */
 static void do_point( struct draw_context *draw,
                      const char *v0 )
 {
@@ -123,6 +122,10 @@ static void do_point( struct draw_context *draw,
 }
 
 
+/**
+ * Build primitive to render a line with vertices at v0, v1.
+ * \param flags  bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE
+ */
 static void do_line( struct draw_context *draw,
                      ushort flags,
                     const char *v0,
@@ -139,6 +142,10 @@ static void do_line( struct draw_context *draw,
 }
 
 
+/**
+ * Build primitive to render a triangle with vertices at v0, v1, v2.
+ * \param flags  bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE
+ */
 static void do_triangle( struct draw_context *draw,
                          ushort flags,
                         char *v0,
@@ -157,7 +164,10 @@ static void do_triangle( struct draw_context *draw,
 }
 
 
-
+/*
+ * Set up macros for draw_pt_decompose.h template code.
+ * This code uses vertex indexes / elements.
+ */
 #define QUAD(i0,i1,i2,i3)                       \
    do_triangle( draw,                           \
                 ( DRAW_PIPE_RESET_STIPPLE |     \
@@ -175,16 +185,16 @@ static void do_triangle( struct draw_context *draw,
 
 #define TRIANGLE(flags,i0,i1,i2)                                        \
    do_triangle( draw,                                                   \
-                elts[i0],  /* flags */                          \
+                elts[i0],  /* flags */                                  \
                 verts + stride * (elts[i0] & ~DRAW_PIPE_FLAG_MASK),     \
-                verts + stride * elts[i1],                              \
-                verts + stride * elts[i2])
+                verts + stride * (elts[i1] & ~DRAW_PIPE_FLAG_MASK),     \
+                verts + stride * (elts[i2] & ~DRAW_PIPE_FLAG_MASK) );
 
 #define LINE(flags,i0,i1)                                       \
    do_line( draw,                                               \
-            elts[i0],                                   \
+            elts[i0],                                           \
             verts + stride * (elts[i0] & ~DRAW_PIPE_FLAG_MASK), \
-            verts + stride * elts[i1])
+            verts + stride * (elts[i1] & ~DRAW_PIPE_FLAG_MASK) );
 
 #define POINT(i0)                               \
    do_point( draw,                              \
@@ -213,7 +223,9 @@ static void do_triangle( struct draw_context *draw,
 
 
 
-/* Code to run the pipeline on a fairly arbitary collection of vertices.
+/**
+ * Code to run the pipeline on a fairly arbitary collection of vertices.
+ * For drawing indexed primitives.
  *
  * Vertex headers must be pre-initialized with the
  * UNDEFINED_VERTEX_ID, this code will cause that id to become
@@ -243,6 +255,12 @@ void draw_pipeline_run( struct draw_context *draw,
    draw->pipeline.vertex_count = 0;
 }
 
+
+
+/*
+ * Set up macros for draw_pt_decompose.h template code.
+ * This code is for non-indexed rendering (no elts).
+ */
 #define QUAD(i0,i1,i2,i3)                                        \
    do_triangle( draw,                                            \
                 ( DRAW_PIPE_RESET_STIPPLE |                      \
@@ -293,6 +311,10 @@ void draw_pipeline_run( struct draw_context *draw,
 
 #include "draw_pt_decompose.h"
 
+
+/*
+ * For drawing non-indexed primitives.
+ */
 void draw_pipeline_run_linear( struct draw_context *draw,
                                unsigned prim,
                                struct vertex_header *vertices,
index 11b39db5990b2541ca71fe0b7e41450322cb2127..dc66c65a56c2ab78bb65005df1492bf761b79637 100644 (file)
@@ -50,8 +50,6 @@ static INLINE struct cull_stage *cull_stage( struct draw_stage *stage )
 }
 
 
-
-
 static void cull_tri( struct draw_stage *stage,
                      struct prim_header *header )
 {
@@ -62,7 +60,7 @@ static void cull_tri( struct draw_stage *stage,
    const float *v1 = header->v[1]->data[pos];
    const float *v2 = header->v[2]->data[pos];
 
-   /* edge vectors e = v0 - v2, f = v1 - v2 */
+   /* edge vectors: e = v0 - v2, f = v1 - v2 */
    const float ex = v0[0] - v2[0];
    const float ey = v0[1] - v2[1];
    const float fx = v1[0] - v2[0];
@@ -72,7 +70,7 @@ static void cull_tri( struct draw_stage *stage,
    header->det = ex * fy - ey * fx;
 
    if (header->det != 0) {
-      /* if (det < 0 then Z points toward camera and triangle is 
+      /* if det < 0 then Z points toward the camera and the triangle is 
        * counter-clockwise winding.
        */
       unsigned winding = (header->det < 0) ? PIPE_WINDING_CCW : PIPE_WINDING_CW;
@@ -84,6 +82,7 @@ static void cull_tri( struct draw_stage *stage,
    }
 }
 
+
 static void cull_first_tri( struct draw_stage *stage, 
                            struct prim_header *header )
 {
@@ -96,13 +95,13 @@ static void cull_first_tri( struct draw_stage *stage,
 }
 
 
-
 static void cull_flush( struct draw_stage *stage, unsigned flags )
 {
    stage->tri = cull_first_tri;
    stage->next->flush( stage->next, flags );
 }
 
+
 static void cull_reset_stipple_counter( struct draw_stage *stage )
 {
    stage->next->reset_stipple_counter( stage->next );
@@ -140,7 +139,7 @@ struct draw_stage *draw_cull_stage( struct draw_context *draw )
 
    return &cull->stage;
 
- fail:
+fail:
    if (cull)
       cull->stage.destroy( &cull->stage );
 
index bea90e50d30cd91eee9e00ff292e9806a908f182..a69e2633becf80877fd8ca5330208ae16db740c4 100644 (file)
@@ -151,8 +151,8 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
 {
    struct draw_context *draw = stage->draw;
    struct draw_stage *next = draw->pipeline.rasterize;
-   int need_det = 0;
-   int precalc_flat = 0;
+   boolean need_det = FALSE;
+   boolean precalc_flat = FALSE;
    boolean wide_lines, wide_points;
 
    /* Set the validate's next stage to the rasterize stage, so that it
@@ -194,7 +194,7 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
    if (wide_lines) {
       draw->pipeline.wide_line->next = next;
       next = draw->pipeline.wide_line;
-      precalc_flat = 1;
+      precalc_flat = TRUE;
    }
 
    if (wide_points || draw->rasterizer->point_sprite) {
@@ -205,7 +205,7 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
    if (draw->rasterizer->line_stipple_enable && draw->pipeline.line_stipple) {
       draw->pipeline.stipple->next = next;
       next = draw->pipeline.stipple;
-      precalc_flat = 1;                /* only needed for lines really */
+      precalc_flat = TRUE;             /* only needed for lines really */
    }
 
    if (draw->rasterizer->poly_stipple_enable
@@ -218,8 +218,8 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
        draw->rasterizer->fill_ccw != PIPE_POLYGON_MODE_FILL) {
       draw->pipeline.unfilled->next = next;
       next = draw->pipeline.unfilled;
-      precalc_flat = 1;                /* only needed for triangles really */
-      need_det = 1;
+      precalc_flat = TRUE;             /* only needed for triangles really */
+      need_det = TRUE;
    }
 
    if (draw->rasterizer->flatshade && precalc_flat) {
@@ -231,13 +231,13 @@ static struct draw_stage *validate_pipeline( struct draw_stage *stage )
        draw->rasterizer->offset_ccw) {
       draw->pipeline.offset->next = next;
       next = draw->pipeline.offset;
-      need_det = 1;
+      need_det = TRUE;
    }
 
    if (draw->rasterizer->light_twoside) {
       draw->pipeline.twoside->next = next;
       next = draw->pipeline.twoside;
-      need_det = 1;
+      need_det = TRUE;
    }
 
    /* Always run the cull stage as we calculate determinant there
index a5ddec52863fb21654fb52c4e8cf3d61240fe0e6..f5ed32d0b0574ff63e0f41bad7bd94cd1938cd60 100644 (file)
@@ -33,7 +33,6 @@
 #include "draw/draw_context.h"
 #include "draw/draw_private.h"
 #include "draw/draw_pt.h"
-#include "draw/draw_vs.h"
 #include "tgsi/tgsi_dump.h"
 #include "util/u_math.h"
 #include "util/u_prim.h"
index 55e7a7b81adfdcfd49b422ea7d4ac41238c7e571..252be5053e4c75bdb260ad43d128326761f00d7b 100644 (file)
@@ -30,7 +30,6 @@
 #include "draw/draw_context.h"
 #include "draw/draw_private.h"
 #include "draw/draw_vbuf.h"
-#include "draw/draw_vertex.h"
 #include "draw/draw_pt.h"
 #include "translate/translate.h"
 #include "translate/translate_cache.h"
index 734c05f0688ab19a1706bdb6047cfbed4497c0d3..c5dfbcfa3cb70802f2869a21db5ffc3e7a71642e 100644 (file)
@@ -40,7 +40,6 @@
 #include "draw/draw_pt.h"
 #include "draw/draw_vs.h"
 
-#include "translate/translate.h"
 
 struct fetch_shade_emit;
 
index 55151823a14e4071bd539ccd208506ddc6feb6ff..9728d5c2bdf134ded1eda2e4155d964c0ed0ed1e 100644 (file)
@@ -30,7 +30,6 @@
 #include "draw/draw_context.h"
 #include "draw/draw_private.h"
 #include "draw/draw_vbuf.h"
-#include "draw/draw_vertex.h"
 #include "draw/draw_pt.h"
 
 struct pt_post_vs {
index 9f40030f39fe6d83285e7330d45e63c2376632c3..b87a465f6bed5ced6cca731eb4d07862f782c307 100644 (file)
@@ -38,7 +38,6 @@
 #include "draw/draw_vertex.h"
 #include "draw/draw_vs.h"
 #include "translate/translate.h"
-#include "translate/translate_cache.h"
 
 /* A first pass at incorporating vertex fetch/emit functionality into 
  */
diff --git a/src/gallium/auxiliary/pipebuffer/Makefile b/src/gallium/auxiliary/pipebuffer/Makefile
new file mode 100644 (file)
index 0000000..21d25d2
--- /dev/null
@@ -0,0 +1,18 @@
+TOP = ../../../..
+include $(TOP)/configs/current
+
+LIBNAME = pipebuffer
+
+C_SOURCES = \
+       pb_buffer_fenced.c \
+       pb_buffer_malloc.c \
+       pb_bufmgr_alt.c \
+       pb_bufmgr_cache.c \
+       pb_bufmgr_debug.c \
+       pb_bufmgr_mm.c \
+       pb_bufmgr_ondemand.c \
+       pb_bufmgr_pool.c \
+       pb_bufmgr_slab.c \
+       pb_validate.c
+
+include ../../Makefile.template
diff --git a/src/gallium/auxiliary/pipebuffer/SConscript b/src/gallium/auxiliary/pipebuffer/SConscript
new file mode 100644 (file)
index 0000000..a074a55
--- /dev/null
@@ -0,0 +1,18 @@
+Import('*')
+
+pipebuffer = env.ConvenienceLibrary(
+       target = 'pipebuffer',
+       source = [
+               'pb_buffer_fenced.c',
+               'pb_buffer_malloc.c',
+               'pb_bufmgr_alt.c',
+               'pb_bufmgr_cache.c',
+               'pb_bufmgr_debug.c',
+               'pb_bufmgr_mm.c',
+               'pb_bufmgr_ondemand.c',
+               'pb_bufmgr_pool.c',
+               'pb_bufmgr_slab.c',
+               'pb_validate.c',
+       ])
+
+auxiliaries.insert(0, pipebuffer)
index 8c8d7130781d81bcf34b2ab15c96e7a5fc62d46e..06669917ff6a4c7fbb177b9a2b06e88fc120b9c4 100644 (file)
@@ -175,7 +175,9 @@ struct pb_fence_ops;
  */
 struct pb_manager *
 fenced_bufmgr_create(struct pb_manager *provider,
-                     struct pb_fence_ops *ops);
+                     struct pb_fence_ops *ops,
+                     pb_size max_buffer_size,
+                     pb_size max_cpu_total_size);
 
 
 struct pb_manager *
index 6e3214ca9c9b4de60c596792f49c056e03b24d52..8f74180a111b90016c66ad31662e10d870e730f7 100644 (file)
@@ -371,6 +371,9 @@ pb_debug_manager_create_buffer(struct pb_manager *_mgr,
    struct pb_desc real_desc;
    pb_size real_size;
    
+   assert(size);
+   assert(desc->alignment);
+
    buf = CALLOC_STRUCT(pb_debug_buffer);
    if(!buf)
       return NULL;
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c
deleted file mode 100644 (file)
index 97dd142..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
- * All Rights Reserved.
- * 
- * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- * 
- * 
- **************************************************************************/
-
-/**
- * \file
- * A buffer manager that wraps buffers in fenced buffers.
- * 
- * \author Jose Fonseca <jrfonseca@tungstengraphics.dot.com>
- */
-
-
-#include "util/u_debug.h"
-#include "util/u_memory.h"
-
-#include "pb_buffer.h"
-#include "pb_buffer_fenced.h"
-#include "pb_bufmgr.h"
-
-
-struct fenced_pb_manager
-{
-   struct pb_manager base;
-
-   struct pb_manager *provider;
-   
-   struct fenced_buffer_list *fenced_list;
-};
-
-
-static INLINE struct fenced_pb_manager *
-fenced_pb_manager(struct pb_manager *mgr)
-{
-   assert(mgr);
-   return (struct fenced_pb_manager *)mgr;
-}
-
-
-static struct pb_buffer *
-fenced_bufmgr_create_buffer(struct pb_manager *mgr, 
-                            pb_size size,
-                            const struct pb_desc *desc)
-{
-   struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
-   struct pb_buffer *buf;
-   struct pb_buffer *fenced_buf;
-
-   /* check for free buffers before allocating new ones */
-   fenced_buffer_list_check_free(fenced_mgr->fenced_list, 0);
-   
-   buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
-   if(!buf) {
-      /* try harder to get a buffer */
-      fenced_buffer_list_check_free(fenced_mgr->fenced_list, 1);
-      
-      buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
-      if(!buf) {
-#if 0
-         fenced_buffer_list_dump(fenced_mgr->fenced_list);
-#endif
-         
-         /* give up */
-         return NULL;
-      }
-   }
-   
-   fenced_buf = fenced_buffer_create(fenced_mgr->fenced_list, buf);
-   if(!fenced_buf) {
-      pb_reference(&buf, NULL);
-   }
-   
-   return fenced_buf;
-}
-
-
-static void
-fenced_bufmgr_flush(struct pb_manager *mgr)
-{
-   struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
-
-   fenced_buffer_list_check_free(fenced_mgr->fenced_list, TRUE);
-
-   assert(fenced_mgr->provider->flush);
-   if(fenced_mgr->provider->flush)
-      fenced_mgr->provider->flush(fenced_mgr->provider);
-}
-
-
-static void
-fenced_bufmgr_destroy(struct pb_manager *mgr)
-{
-   struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
-
-   fenced_buffer_list_destroy(fenced_mgr->fenced_list);
-
-   if(fenced_mgr->provider)
-      fenced_mgr->provider->destroy(fenced_mgr->provider);
-   
-   FREE(fenced_mgr);
-}
-
-
-struct pb_manager *
-fenced_bufmgr_create(struct pb_manager *provider, 
-                     struct pb_fence_ops *ops) 
-{
-   struct fenced_pb_manager *fenced_mgr;
-
-   if(!provider)
-      return NULL;
-   
-   fenced_mgr = CALLOC_STRUCT(fenced_pb_manager);
-   if (!fenced_mgr)
-      return NULL;
-
-   fenced_mgr->base.destroy = fenced_bufmgr_destroy;
-   fenced_mgr->base.create_buffer = fenced_bufmgr_create_buffer;
-   fenced_mgr->base.flush = fenced_bufmgr_flush;
-
-   fenced_mgr->provider = provider;
-   fenced_mgr->fenced_list = fenced_buffer_list_create(ops);
-   if(!fenced_mgr->fenced_list) {
-      FREE(fenced_mgr);
-      return NULL;
-   }
-      
-   return &fenced_mgr->base;
-}
index ce40c0cf0e693fad1106b4594380aade082fa8ab..903afc749d3854bd8d973bbb8ce2545fabe07235 100644 (file)
@@ -39,7 +39,6 @@
 #include "util/u_debug.h"
 
 #include "pb_buffer.h"
-#include "pb_buffer_fenced.h"
 #include "pb_validate.h"
 
 
index a6cc773003ace80c6b7d904f89ef7cb3381c5e76..b9be8dc0a316a22ca00ded7dffafcc7cf4edbf30 100644 (file)
@@ -101,12 +101,10 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
                       src->Register.File == TGSI_FILE_SYSTEM_VALUE) {
                      const int ind = src->Register.Index;
                      if (info->input_semantic_name[ind] == TGSI_SEMANTIC_FOG) {
-                        if (src->Register.SwizzleX == TGSI_SWIZZLE_X) {
-                           info->uses_fogcoord = TRUE;
-                        }
-                        else if (src->Register.SwizzleX == TGSI_SWIZZLE_Y) {
-                           info->uses_frontfacing = TRUE;
-                        }
+                        info->uses_fogcoord = TRUE;
+                     }
+                     else if (info->input_semantic_name[ind] == TGSI_SEMANTIC_FACE) {
+                        info->uses_frontfacing = TRUE;
                      }
                   }
                }
index 9725890bd4ada4c16a3f21b4a2d3d4a4c51ac31d..236f1e4feee0d7cd5563de3d373d4c0231e9ca05 100644 (file)
@@ -226,8 +226,8 @@ setup_vertex_data_tex(struct blit_state *ctx,
 
    offset = get_next_slot( ctx );
 
-   pipe_buffer_write(ctx->pipe->screen, ctx->vbuf,
-                     offset, sizeof(ctx->vertices), ctx->vertices);
+   pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
+                               offset, sizeof(ctx->vertices), ctx->vertices);
 
    return offset;
 }
index 76023794dcdaecdacb0cea2a509c17bf0b037105..5426c91152da3187de33d0c4ea05d5305178b323 100644 (file)
@@ -1411,8 +1411,8 @@ set_vertex_data(struct gen_mipmap_state *ctx,
 
    offset = get_next_slot( ctx );
 
-   pipe_buffer_write(ctx->pipe->screen, ctx->vbuf,
-                     offset, sizeof(ctx->vertices), ctx->vertices);
+   pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
+                               offset, sizeof(ctx->vertices), ctx->vertices);
 
    return offset;
 }
index 975ee89c4551df262de09cc2b3ad613c4816edeb..55a65375c81d1f9b619874ed3b5d94e1d295e802 100644 (file)
@@ -85,7 +85,9 @@ my_buffer_write(struct pipe_screen *screen,
 
    map = pipe_buffer_map_range(screen, buf, offset, size, 
                                PIPE_BUFFER_USAGE_CPU_WRITE |
-                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT);
+                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
+                               PIPE_BUFFER_USAGE_DISCARD |
+                               PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
    if (map == NULL) 
       return PIPE_ERROR_OUT_OF_MEMORY;
 
index 90530f2826f10e4237d8d3e22aee3b091639116d..0d0859f8f335478f0111f994a12f77b336e60ed1 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "util/u_clear.h"
 #include "i915_context.h"
-#include "i915_state.h"
 
 
 /**
index 89feeade7566ec84fd39a03ea7e31a82d828dcfb..4c5ff37ca8472cf6c63dadeb8073089802085929 100644 (file)
 #include "i915_state.h"
 #include "i915_screen.h"
 #include "i915_batch.h"
-#include "i915_texture.h"
-#include "i915_reg.h"
 
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
 #include "pipe/p_inlines.h"
 #include "util/u_memory.h"
 #include "pipe/p_screen.h"
index c6e6d6fd3137446b124b5006c1977368237efe3f..237654d26b2ec9e67656cbcc1306dd07356b8d15 100644 (file)
@@ -29,7 +29,6 @@
 #include "i915_context.h"
 #include "i915_debug.h"
 #include "i915_batch.h"
-#include "pipe/internal/p_winsys_screen.h"
 #include "util/u_debug.h"
 
 
index 9c5b117b6dd47ae12157edc26f6db8c56bcbb42c..f9c40d8a110cdcbb7e1de3e611d4af27ac9d0f58 100644 (file)
@@ -29,7 +29,6 @@
 #include "i915_reg.h"
 #include "i915_debug.h"
 #include "pipe/internal/p_winsys_screen.h"
-#include "util/u_memory.h"
 
 
 static void
index 0fab6e1bc363797e29c460e4f275bc60bf23167a..06949c15f88178205567ccd99dfa18a928cbf74a 100644 (file)
@@ -30,7 +30,6 @@
 
 
 #include "draw/draw_context.h"
-#include "pipe/internal/p_winsys_screen.h"
 #include "pipe/p_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
@@ -38,7 +37,6 @@
 
 #include "i915_context.h"
 #include "i915_reg.h"
-#include "i915_state.h"
 #include "i915_state_inlines.h"
 #include "i915_fpc.h"
 
index 03dd5091a611ba63de9eed9779ffabfff85e6e86..f5b0e9f011eb79d9dd8896ace3e38c5a0df2a8f1 100644 (file)
@@ -33,7 +33,6 @@
 #include "i915_context.h"
 #include "i915_state.h"
 #include "i915_reg.h"
-#include "i915_fpc.h"
 
 
 
index cbac4175c8f78fb5652718cc3a630771aa9b3eb3..e5c6d87215bb57723434fd05c3389fc71a00e81c 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
-#include "util/u_memory.h"
 
 #include "i915_state_inlines.h"
 #include "i915_context.h"
index c693eb30e87e3a1e9dcde7b1a4b06a1aa815204a..13684aa59c539515fbbf5a7d9dea3cf3167c9860 100644 (file)
 
 #include "i915_context.h"
 #include "i915_blit.h"
-#include "i915_state.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
-#include "pipe/p_inlines.h"
 #include "pipe/internal/p_winsys_screen.h"
 #include "util/u_format.h"
-#include "util/u_tile.h"
-#include "util/u_rect.h"
 
 
 /* Assumes all values are within bounds -- no checking at this level -
index 50a9e19094b8906ca1fe96f2d2f208368f1e1f9b..441bc4f193024ed4215c5e34ae5659dd890c0751 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "i915_context.h"
 #include "i915_texture.h"
-#include "i915_debug.h"
 #include "i915_screen.h"
 #include "intel_winsys.h"
 
index 2b4bc5c819d7c85e3c137f142889a2318e61739e..7245730350cf85d2d42618bff814a087e73a1662 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
-#include "lp_bld_arit.h"
 #include "lp_bld_logic.h"
 #include "lp_bld_flow.h"
 #include "lp_bld_debug.h"
index eea6b5d6a5c9d2d1002fa9ff5b6edac8dba0c07c..1aee9b35f31cd5737457f05f812fa5e574817a97 100644 (file)
@@ -56,7 +56,6 @@
 #include "lp_bld_intr.h"
 #include "lp_bld_logic.h"
 #include "lp_bld_pack.h"
-#include "lp_bld_debug.h"
 #include "lp_bld_arit.h"
 
 
index 9511299d558daea791b6c04e130fe5bd8bd8505e..5d5ca7a5d43015effa64f11cefd711459a83423a 100644 (file)
@@ -71,7 +71,6 @@
 #include "pipe/p_state.h"
 
 #include "lp_bld_type.h"
-#include "lp_bld_const.h"
 #include "lp_bld_arit.h"
 #include "lp_bld_blend.h"
 
index 99352094379f81e0aca4ab03555082803264907f..ebf554cd045bafd08fb5a1d85c8b606d8e4ea7c2 100644 (file)
 
 #include "util/u_debug.h"
 #include "util/u_math.h"
-#include "util/u_cpu_detect.h"
 
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
-#include "lp_bld_intr.h"
 #include "lp_bld_arit.h"
 #include "lp_bld_pack.h"
 #include "lp_bld_conv.h"
index 10e82f120bb7ef8f5042714a6b8e2474254e49f9..dfa080b85338d056c7c580882de6eb3bc1421c64 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
-#include "lp_bld_logic.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_format.h"
 
index fb1eda4423ba4db3047ae131839be2135619e5c4..85e3b1bdd421fde789da440eb5b777ac8c527e8b 100644 (file)
 #include "tgsi/tgsi_exec.h"
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
-#include "lp_bld_intr.h"
 #include "lp_bld_arit.h"
 #include "lp_bld_logic.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_flow.h"
 #include "lp_bld_tgsi.h"
-#include "lp_bld_debug.h"
 
 
 #define LP_MAX_TEMPS 256
index c152b4413fcf00fc31d06ef7cbbe57744d60c3c9..a0316194c6a5c04f16bcef0fab5d6f3233b3fc53 100644 (file)
@@ -33,8 +33,6 @@
 
 #include "pipe/p_defines.h"
 #include "pipe/p_context.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
 #include "util/u_prim.h"
 
 #include "lp_buffer.h"
index cd8381fe3086c1c6702286c488a04ee05cf0bfcd..6c81012e84b0c8e2e4dd2b3f72ebe96edd6a514d 100644 (file)
@@ -37,8 +37,6 @@
 #include "lp_surface.h"
 #include "lp_state.h"
 #include "lp_tile_cache.h"
-#include "lp_tex_cache.h"
-#include "lp_winsys.h"
 
 
 void
index 4ef0783f3e2962078d51a2477ba968e72f8a779b..9e0118c55b6cb34a4309b15a06afb94379c34a22 100644 (file)
@@ -39,7 +39,6 @@
 #include "util/u_cpu_detect.h"
 #include "lp_screen.h"
 #include "lp_bld_intr.h"
-#include "lp_bld_misc.h"
 #include "lp_jit.h"
 
 
index 9f4bbef73fb7aba647bd696c30aa51448885ed84..70e2a082cc02835fd29f23df50b476b2549af23f 100644 (file)
@@ -62,7 +62,6 @@
 #include "util/u_memory.h"
 #include "util/u_format.h"
 #include "util/u_debug_dump.h"
-#include "pipe/internal/p_winsys_screen.h"
 #include "pipe/p_shader_tokens.h"
 #include "draw/draw_context.h"
 #include "tgsi/tgsi_dump.h"
@@ -85,7 +84,6 @@
 #include "lp_context.h"
 #include "lp_buffer.h"
 #include "lp_state.h"
-#include "lp_quad.h"
 #include "lp_tex_sample.h"
 #include "lp_debug.h"
 
index e37ff04f3df172aab3e3c764a645f2124c5f715f..3b08b0d1d700db00a35b36938f5e080c2d4d2603 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "lp_context.h"
 #include "lp_state.h"
-#include "lp_surface.h"
 #include "lp_tile_cache.h"
 
 #include "draw/draw_context.h"
index 1a17631a4c62627f88255cbf0d87d7d27253da9c..57ac25ea0cba07d27deaaa1920b088096ece5bbf 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "lp_context.h"
 #include "lp_state.h"
-#include "lp_surface.h"
 
 #include "draw/draw_context.h"
 
index 6c29e8d8ace250ca16b7c490d188e17fd541f559..7b65bab43a472de9e60113f2ec1afc4b0569bf5a 100644 (file)
@@ -38,7 +38,6 @@
 
 
 #include "lp_bld_type.h"
-#include "lp_bld_arit.h"
 #include "lp_bld_blend.h"
 #include "lp_bld_debug.h"
 #include "lp_test.h"
index a6d9a2c1acfc724056542bcca14df24cb63c5641..8094625d74d9a1d324e3508790e0cde1b7675c81 100644 (file)
@@ -38,7 +38,6 @@
 #include "util/u_format.h"
 #include "util/u_math.h"
 #include "lp_context.h"
-#include "lp_surface.h"
 #include "lp_texture.h"
 #include "lp_tex_cache.h"
 
diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample_c.c b/src/gallium/drivers/llvmpipe/lp_tex_sample_c.c
new file mode 100644 (file)
index 0000000..d1f5d95
--- /dev/null
@@ -0,0 +1,1712 @@
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * Copyright 2008 VMware, Inc.  All rights reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
+ **************************************************************************/
+
+/**
+ * Texture sampling
+ *
+ * Authors:
+ *   Brian Paul
+ */
+
+#include "lp_context.h"
+#include "lp_quad.h"
+#include "lp_texture.h"
+#include "lp_tex_sample.h"
+#include "lp_tex_cache.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+
+
+/*
+ * Note, the FRAC macro has to work perfectly.  Otherwise you'll sometimes
+ * see 1-pixel bands of improperly weighted linear-filtered textures.
+ * The tests/texwrap.c demo is a good test.
+ * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
+ * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
+ */
+#define FRAC(f)  ((f) - util_ifloor(f))
+
+
+/**
+ * Linear interpolation macro
+ */
+static INLINE float
+lerp(float a, float v0, float v1)
+{
+   return v0 + a * (v1 - v0);
+}
+
+
+/**
+ * Do 2D/biliner interpolation of float values.
+ * v00, v10, v01 and v11 are typically four texture samples in a square/box.
+ * a and b are the horizontal and vertical interpolants.
+ * It's important that this function is inlined when compiled with
+ * optimization!  If we find that's not true on some systems, convert
+ * to a macro.
+ */
+static INLINE float
+lerp_2d(float a, float b,
+        float v00, float v10, float v01, float v11)
+{
+   const float temp0 = lerp(a, v00, v10);
+   const float temp1 = lerp(a, v01, v11);
+   return lerp(b, temp0, temp1);
+}
+
+
+/**
+ * As above, but 3D interpolation of 8 values.
+ */
+static INLINE float
+lerp_3d(float a, float b, float c,
+        float v000, float v100, float v010, float v110,
+        float v001, float v101, float v011, float v111)
+{
+   const float temp0 = lerp_2d(a, b, v000, v100, v010, v110);
+   const float temp1 = lerp_2d(a, b, v001, v101, v011, v111);
+   return lerp(c, temp0, temp1);
+}
+
+
+
+/**
+ * If A is a signed integer, A % B doesn't give the right value for A < 0
+ * (in terms of texture repeat).  Just casting to unsigned fixes that.
+ */
+#define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B))
+
+
+/**
+ * Apply texture coord wrapping mode and return integer texture indexes
+ * for a vector of four texcoords (S or T or P).
+ * \param wrapMode  PIPE_TEX_WRAP_x
+ * \param s  the incoming texcoords
+ * \param size  the texture image size
+ * \param icoord  returns the integer texcoords
+ * \return  integer texture index
+ */
+static INLINE void
+nearest_texcoord_4(unsigned wrapMode, const float s[4], unsigned size,
+                   int icoord[4])
+{
+   uint ch;
+   switch (wrapMode) {
+   case PIPE_TEX_WRAP_REPEAT:
+      /* s limited to [0,1) */
+      /* i limited to [0,size-1] */
+      for (ch = 0; ch < 4; ch++) {
+         int i = util_ifloor(s[ch] * size);
+         icoord[ch] = REMAINDER(i, size);
+      }
+      return;
+   case PIPE_TEX_WRAP_CLAMP:
+      /* s limited to [0,1] */
+      /* i limited to [0,size-1] */
+      for (ch = 0; ch < 4; ch++) {
+         if (s[ch] <= 0.0F)
+            icoord[ch] = 0;
+         else if (s[ch] >= 1.0F)
+            icoord[ch] = size - 1;
+         else
+            icoord[ch] = util_ifloor(s[ch] * size);
+      }
+      return;
+   case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
+      {
+         /* s limited to [min,max] */
+         /* i limited to [0, size-1] */
+         const float min = 1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            if (s[ch] < min)
+               icoord[ch] = 0;
+            else if (s[ch] > max)
+               icoord[ch] = size - 1;
+            else
+               icoord[ch] = util_ifloor(s[ch] * size);
+         }
+      }
+      return;
+   case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+      {
+         /* s limited to [min,max] */
+         /* i limited to [-1, size] */
+         const float min = -1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            if (s[ch] <= min)
+               icoord[ch] = -1;
+            else if (s[ch] >= max)
+               icoord[ch] = size;
+            else
+               icoord[ch] = util_ifloor(s[ch] * size);
+         }
+      }
+      return;
+   case PIPE_TEX_WRAP_MIRROR_REPEAT:
+      {
+         const float min = 1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            const int flr = util_ifloor(s[ch]);
+            float u;
+            if (flr & 1)
+               u = 1.0F - (s[ch] - (float) flr);
+            else
+               u = s[ch] - (float) flr;
+            if (u < min)
+               icoord[ch] = 0;
+            else if (u > max)
+               icoord[ch] = size - 1;
+            else
+               icoord[ch] = util_ifloor(u * size);
+         }
+      }
+      return;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP:
+      for (ch = 0; ch < 4; ch++) {
+         /* s limited to [0,1] */
+         /* i limited to [0,size-1] */
+         const float u = fabsf(s[ch]);
+         if (u <= 0.0F)
+            icoord[ch] = 0;
+         else if (u >= 1.0F)
+            icoord[ch] = size - 1;
+         else
+            icoord[ch] = util_ifloor(u * size);
+      }
+      return;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
+      {
+         /* s limited to [min,max] */
+         /* i limited to [0, size-1] */
+         const float min = 1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            const float u = fabsf(s[ch]);
+            if (u < min)
+               icoord[ch] = 0;
+            else if (u > max)
+               icoord[ch] = size - 1;
+            else
+               icoord[ch] = util_ifloor(u * size);
+         }
+      }
+      return;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
+      {
+         /* s limited to [min,max] */
+         /* i limited to [0, size-1] */
+         const float min = -1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            const float u = fabsf(s[ch]);
+            if (u < min)
+               icoord[ch] = -1;
+            else if (u > max)
+               icoord[ch] = size;
+            else
+               icoord[ch] = util_ifloor(u * size);
+         }
+      }
+      return;
+   default:
+      assert(0);
+   }
+}
+
+
+/**
+ * Used to compute texel locations for linear sampling for four texcoords.
+ * \param wrapMode  PIPE_TEX_WRAP_x
+ * \param s  the texcoords
+ * \param size  the texture image size
+ * \param icoord0  returns first texture indexes
+ * \param icoord1  returns second texture indexes (usually icoord0 + 1)
+ * \param w  returns blend factor/weight between texture indexes
+ * \param icoord  returns the computed integer texture coords
+ */
+static INLINE void
+linear_texcoord_4(unsigned wrapMode, const float s[4], unsigned size,
+                  int icoord0[4], int icoord1[4], float w[4])
+{
+   uint ch;
+
+   switch (wrapMode) {
+   case PIPE_TEX_WRAP_REPEAT:
+      for (ch = 0; ch < 4; ch++) {
+         float u = s[ch] * size - 0.5F;
+         icoord0[ch] = REMAINDER(util_ifloor(u), size);
+         icoord1[ch] = REMAINDER(icoord0[ch] + 1, size);
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_CLAMP:
+      for (ch = 0; ch < 4; ch++) {
+         float u = CLAMP(s[ch], 0.0F, 1.0F);
+         u = u * size - 0.5f;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
+      for (ch = 0; ch < 4; ch++) {
+         float u = CLAMP(s[ch], 0.0F, 1.0F);
+         u = u * size - 0.5f;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         if (icoord0[ch] < 0)
+            icoord0[ch] = 0;
+         if (icoord1[ch] >= (int) size)
+            icoord1[ch] = size - 1;
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+      {
+         const float min = -1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            float u = CLAMP(s[ch], min, max);
+            u = u * size - 0.5f;
+            icoord0[ch] = util_ifloor(u);
+            icoord1[ch] = icoord0[ch] + 1;
+            w[ch] = FRAC(u);
+         }
+      }
+      break;;
+   case PIPE_TEX_WRAP_MIRROR_REPEAT:
+      for (ch = 0; ch < 4; ch++) {
+         const int flr = util_ifloor(s[ch]);
+         float u;
+         if (flr & 1)
+            u = 1.0F - (s[ch] - (float) flr);
+         else
+            u = s[ch] - (float) flr;
+         u = u * size - 0.5F;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         if (icoord0[ch] < 0)
+            icoord0[ch] = 0;
+         if (icoord1[ch] >= (int) size)
+            icoord1[ch] = size - 1;
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP:
+      for (ch = 0; ch < 4; ch++) {
+         float u = fabsf(s[ch]);
+         if (u >= 1.0F)
+            u = (float) size;
+         else
+            u *= size;
+         u -= 0.5F;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
+      for (ch = 0; ch < 4; ch++) {
+         float u = fabsf(s[ch]);
+         if (u >= 1.0F)
+            u = (float) size;
+         else
+            u *= size;
+         u -= 0.5F;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         if (icoord0[ch] < 0)
+            icoord0[ch] = 0;
+         if (icoord1[ch] >= (int) size)
+            icoord1[ch] = size - 1;
+         w[ch] = FRAC(u);
+      }
+      break;;
+   case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
+      {
+         const float min = -1.0F / (2.0F * size);
+         const float max = 1.0F - min;
+         for (ch = 0; ch < 4; ch++) {
+            float u = fabsf(s[ch]);
+            if (u <= min)
+               u = min * size;
+            else if (u >= max)
+               u = max * size;
+            else
+               u *= size;
+            u -= 0.5F;
+            icoord0[ch] = util_ifloor(u);
+            icoord1[ch] = icoord0[ch] + 1;
+            w[ch] = FRAC(u);
+         }
+      }
+      break;;
+   default:
+      assert(0);
+   }
+}
+
+
+/**
+ * For RECT textures / unnormalized texcoords
+ * Only a subset of wrap modes supported.
+ */
+static INLINE void
+nearest_texcoord_unnorm_4(unsigned wrapMode, const float s[4], unsigned size,
+                          int icoord[4])
+{
+   uint ch;
+   switch (wrapMode) {
+   case PIPE_TEX_WRAP_CLAMP:
+      for (ch = 0; ch < 4; ch++) {
+         int i = util_ifloor(s[ch]);
+         icoord[ch]= CLAMP(i, 0, (int) size-1);
+      }
+      return;
+   case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
+      /* fall-through */
+   case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+      for (ch = 0; ch < 4; ch++) {
+         icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) );
+      }
+      return;
+   default:
+      assert(0);
+   }
+}
+
+
+/**
+ * For RECT textures / unnormalized texcoords.
+ * Only a subset of wrap modes supported.
+ */
+static INLINE void
+linear_texcoord_unnorm_4(unsigned wrapMode, const float s[4], unsigned size,
+                         int icoord0[4], int icoord1[4], float w[4])
+{
+   uint ch;
+   switch (wrapMode) {
+   case PIPE_TEX_WRAP_CLAMP:
+      for (ch = 0; ch < 4; ch++) {
+         /* Not exactly what the spec says, but it matches NVIDIA output */
+         float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f);
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         w[ch] = FRAC(u);
+      }
+      return;
+   case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
+      /* fall-through */
+   case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+      for (ch = 0; ch < 4; ch++) {
+         float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F);
+         u -= 0.5F;
+         icoord0[ch] = util_ifloor(u);
+         icoord1[ch] = icoord0[ch] + 1;
+         if (icoord1[ch] > (int) size - 1)
+            icoord1[ch] = size - 1;
+         w[ch] = FRAC(u);
+      }
+      break;
+   default:
+      assert(0);
+   }
+}
+
+
+static unsigned
+choose_cube_face(float rx, float ry, float rz, float *newS, float *newT)
+{
+   /*
+      major axis
+      direction     target                             sc     tc    ma
+      ----------    -------------------------------    ---    ---   ---
+       +rx          TEXTURE_CUBE_MAP_POSITIVE_X_EXT    -rz    -ry   rx
+       -rx          TEXTURE_CUBE_MAP_NEGATIVE_X_EXT    +rz    -ry   rx
+       +ry          TEXTURE_CUBE_MAP_POSITIVE_Y_EXT    +rx    +rz   ry
+       -ry          TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT    +rx    -rz   ry
+       +rz          TEXTURE_CUBE_MAP_POSITIVE_Z_EXT    +rx    -ry   rz
+       -rz          TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT    -rx    -ry   rz
+   */
+   const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz);
+   unsigned face;
+   float sc, tc, ma;
+
+   if (arx > ary && arx > arz) {
+      if (rx >= 0.0F) {
+         face = PIPE_TEX_FACE_POS_X;
+         sc = -rz;
+         tc = -ry;
+         ma = arx;
+      }
+      else {
+         face = PIPE_TEX_FACE_NEG_X;
+         sc = rz;
+         tc = -ry;
+         ma = arx;
+      }
+   }
+   else if (ary > arx && ary > arz) {
+      if (ry >= 0.0F) {
+         face = PIPE_TEX_FACE_POS_Y;
+         sc = rx;
+         tc = rz;
+         ma = ary;
+      }
+      else {
+         face = PIPE_TEX_FACE_NEG_Y;
+         sc = rx;
+         tc = -rz;
+         ma = ary;
+      }
+   }
+   else {
+      if (rz > 0.0F) {
+         face = PIPE_TEX_FACE_POS_Z;
+         sc = rx;
+         tc = -ry;
+         ma = arz;
+      }
+      else {
+         face = PIPE_TEX_FACE_NEG_Z;
+         sc = -rx;
+         tc = -ry;
+         ma = arz;
+      }
+   }
+
+   *newS = ( sc / ma + 1.0F ) * 0.5F;
+   *newT = ( tc / ma + 1.0F ) * 0.5F;
+
+   return face;
+}
+
+
+/**
+ * Examine the quad's texture coordinates to compute the partial
+ * derivatives w.r.t X and Y, then compute lambda (level of detail).
+ *
+ * This is only done for fragment shaders, not vertex shaders.
+ */
+static float
+compute_lambda(struct tgsi_sampler *tgsi_sampler,
+               const float s[QUAD_SIZE],
+               const float t[QUAD_SIZE],
+               const float p[QUAD_SIZE],
+               float lodbias)
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+   float rho, lambda;
+
+   if (samp->processor == TGSI_PROCESSOR_VERTEX)
+      return lodbias;
+
+   assert(sampler->normalized_coords);
+
+   assert(s);
+   {
+      float dsdx = s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT];
+      float dsdy = s[QUAD_TOP_LEFT]     - s[QUAD_BOTTOM_LEFT];
+      dsdx = fabsf(dsdx);
+      dsdy = fabsf(dsdy);
+      rho = MAX2(dsdx, dsdy) * texture->width[0];
+   }
+   if (t) {
+      float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT];
+      float dtdy = t[QUAD_TOP_LEFT]     - t[QUAD_BOTTOM_LEFT];
+      float max;
+      dtdx = fabsf(dtdx);
+      dtdy = fabsf(dtdy);
+      max = MAX2(dtdx, dtdy) * texture->height[0];
+      rho = MAX2(rho, max);
+   }
+   if (p) {
+      float dpdx = p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT];
+      float dpdy = p[QUAD_TOP_LEFT]     - p[QUAD_BOTTOM_LEFT];
+      float max;
+      dpdx = fabsf(dpdx);
+      dpdy = fabsf(dpdy);
+      max = MAX2(dpdx, dpdy) * texture->depth[0];
+      rho = MAX2(rho, max);
+   }
+
+   lambda = util_fast_log2(rho);
+   lambda += lodbias + sampler->lod_bias;
+   lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod);
+
+   return lambda;
+}
+
+
+/**
+ * Do several things here:
+ * 1. Compute lambda from the texcoords, if needed
+ * 2. Determine if we're minifying or magnifying
+ * 3. If minifying, choose mipmap levels
+ * 4. Return image filter to use within mipmap images
+ * \param level0  Returns first mipmap level to sample from
+ * \param level1  Returns second mipmap level to sample from
+ * \param levelBlend  Returns blend factor between levels, in [0,1]
+ * \param imgFilter  Returns either the min or mag filter, depending on lambda
+ */
+static void
+choose_mipmap_levels(struct tgsi_sampler *tgsi_sampler,
+                     const float s[QUAD_SIZE],
+                     const float t[QUAD_SIZE],
+                     const float p[QUAD_SIZE],
+                     float lodbias,
+                     unsigned *level0, unsigned *level1, float *levelBlend,
+                     unsigned *imgFilter)
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+
+   if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
+      /* no mipmap selection needed */
+      *level0 = *level1 = CLAMP((int) sampler->min_lod,
+                                0, (int) texture->last_level);
+
+      if (sampler->min_img_filter != sampler->mag_img_filter) {
+         /* non-mipmapped texture, but still need to determine if doing
+          * minification or magnification.
+          */
+         float lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
+         if (lambda <= 0.0) {
+            *imgFilter = sampler->mag_img_filter;
+         }
+         else {
+            *imgFilter = sampler->min_img_filter;
+         }
+      }
+      else {
+         *imgFilter = sampler->mag_img_filter;
+      }
+   }
+   else {
+      float lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
+
+      if (lambda <= 0.0) { /* XXX threshold depends on the filter */
+         /* magnifying */
+         *imgFilter = sampler->mag_img_filter;
+         *level0 = *level1 = 0;
+      }
+      else {
+         /* minifying */
+         *imgFilter = sampler->min_img_filter;
+
+         /* choose mipmap level(s) and compute the blend factor between them */
+         if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NEAREST) {
+            /* Nearest mipmap level */
+            const int lvl = (int) (lambda + 0.5);
+            *level0 =
+            *level1 = CLAMP(lvl, 0, (int) texture->last_level);
+         }
+         else {
+            /* Linear interpolation between mipmap levels */
+            const int lvl = (int) lambda;
+            *level0 = CLAMP(lvl,     0, (int) texture->last_level);
+            *level1 = CLAMP(lvl + 1, 0, (int) texture->last_level);
+            *levelBlend = FRAC(lambda);  /* blending weight between levels */
+         }
+      }
+   }
+}
+
+
+/**
+ * Get a texel from a texture, using the texture tile cache.
+ *
+ * \param face  the cube face in 0..5
+ * \param level  the mipmap level
+ * \param x  the x coord of texel within 2D image
+ * \param y  the y coord of texel within 2D image
+ * \param z  which slice of a 3D texture
+ * \param rgba  the quad to put the texel/color into
+ * \param j  which element of the rgba quad to write to
+ *
+ * XXX maybe move this into lp_tile_cache.c and merge with the
+ * lp_get_cached_tile_tex() function.  Also, get 4 texels instead of 1...
+ */
+static void
+get_texel_quad_2d(const struct tgsi_sampler *tgsi_sampler,
+                  unsigned face, unsigned level, int x, int y, 
+                  const uint8_t *out[4])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+
+   const struct llvmpipe_cached_tex_tile *tile
+      = lp_get_cached_tex_tile(samp->cache,
+                               tex_tile_address(x, y, 0, face, level));
+
+   y %= TEX_TILE_SIZE;
+   x %= TEX_TILE_SIZE;
+      
+   out[0] = &tile->color[y  ][x  ][0];
+   out[1] = &tile->color[y  ][x+1][0];
+   out[2] = &tile->color[y+1][x  ][0];
+   out[3] = &tile->color[y+1][x+1][0];
+}
+
+static INLINE const uint8_t *
+get_texel_2d_ptr(const struct tgsi_sampler *tgsi_sampler,
+                 unsigned face, unsigned level, int x, int y)
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+
+   const struct llvmpipe_cached_tex_tile *tile
+      = lp_get_cached_tex_tile(samp->cache,
+                               tex_tile_address(x, y, 0, face, level));
+
+   y %= TEX_TILE_SIZE;
+   x %= TEX_TILE_SIZE;
+
+   return &tile->color[y][x][0];
+}
+
+
+static void
+get_texel_quad_2d_mt(const struct tgsi_sampler *tgsi_sampler,
+                     unsigned face, unsigned level, 
+                     int x0, int y0, 
+                     int x1, int y1,
+                     const uint8_t *out[4])
+{
+   unsigned i;
+
+   for (i = 0; i < 4; i++) {
+      unsigned tx = (i & 1) ? x1 : x0;
+      unsigned ty = (i >> 1) ? y1 : y0;
+
+      out[i] = get_texel_2d_ptr( tgsi_sampler, face, level, tx, ty );
+   }
+}
+
+static void
+get_texel(const struct tgsi_sampler *tgsi_sampler,
+                 unsigned face, unsigned level, int x, int y, int z,
+                 float rgba[NUM_CHANNELS][QUAD_SIZE], unsigned j)
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+
+   if (x < 0 || x >= (int) texture->width[level] ||
+       y < 0 || y >= (int) texture->height[level] ||
+       z < 0 || z >= (int) texture->depth[level]) {
+      rgba[0][j] = sampler->border_color[0];
+      rgba[1][j] = sampler->border_color[1];
+      rgba[2][j] = sampler->border_color[2];
+      rgba[3][j] = sampler->border_color[3];
+   }
+   else {
+      const unsigned tx = x % TEX_TILE_SIZE;
+      const unsigned ty = y % TEX_TILE_SIZE;
+      const struct llvmpipe_cached_tex_tile *tile;
+
+      tile = lp_get_cached_tex_tile(samp->cache,
+                                    tex_tile_address(x, y, z, face, level));
+
+      rgba[0][j] = ubyte_to_float(tile->color[ty][tx][0]);
+      rgba[1][j] = ubyte_to_float(tile->color[ty][tx][1]);
+      rgba[2][j] = ubyte_to_float(tile->color[ty][tx][2]);
+      rgba[3][j] = ubyte_to_float(tile->color[ty][tx][3]);
+      if (0)
+      {
+         debug_printf("Get texel %f %f %f %f from %s\n",
+                      rgba[0][j], rgba[1][j], rgba[2][j], rgba[3][j],
+                      pf_name(texture->format));
+      }
+   }
+}
+
+
+/**
+ * Compare texcoord 'p' (aka R) against texture value 'rgba[0]'
+ * When we sampled the depth texture, the depth value was put into all
+ * RGBA channels.  We look at the red channel here.
+ * \param rgba  quad of (depth) texel values
+ * \param p  texture 'P' components for four pixels in quad
+ * \param j  which pixel in the quad to test [0..3]
+ */
+static INLINE void
+shadow_compare(const struct pipe_sampler_state *sampler,
+               float rgba[NUM_CHANNELS][QUAD_SIZE],
+               const float p[QUAD_SIZE],
+               uint j)
+{
+   int k;
+   switch (sampler->compare_func) {
+   case PIPE_FUNC_LESS:
+      k = p[j] < rgba[0][j];
+      break;
+   case PIPE_FUNC_LEQUAL:
+      k = p[j] <= rgba[0][j];
+      break;
+   case PIPE_FUNC_GREATER:
+      k = p[j] > rgba[0][j];
+      break;
+   case PIPE_FUNC_GEQUAL:
+      k = p[j] >= rgba[0][j];
+      break;
+   case PIPE_FUNC_EQUAL:
+      k = p[j] == rgba[0][j];
+      break;
+   case PIPE_FUNC_NOTEQUAL:
+      k = p[j] != rgba[0][j];
+      break;
+   case PIPE_FUNC_ALWAYS:
+      k = 1;
+      break;
+   case PIPE_FUNC_NEVER:
+      k = 0;
+      break;
+   default:
+      k = 0;
+      assert(0);
+      break;
+   }
+
+   /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
+   rgba[0][j] = rgba[1][j] = rgba[2][j] = (float) k;
+   rgba[3][j] = 1.0F;
+}
+
+
+/**
+ * As above, but do four z/texture comparisons.
+ */
+static INLINE void
+shadow_compare4(const struct pipe_sampler_state *sampler,
+                float rgba[NUM_CHANNELS][QUAD_SIZE],
+                const float p[QUAD_SIZE])
+{
+   int j, k0, k1, k2, k3;
+   float val;
+
+   /* compare four texcoords vs. four texture samples */
+   switch (sampler->compare_func) {
+   case PIPE_FUNC_LESS:
+      k0 = p[0] < rgba[0][0];
+      k1 = p[1] < rgba[0][1];
+      k2 = p[2] < rgba[0][2];
+      k3 = p[3] < rgba[0][3];
+      break;
+   case PIPE_FUNC_LEQUAL:
+      k0 = p[0] <= rgba[0][0];
+      k1 = p[1] <= rgba[0][1];
+      k2 = p[2] <= rgba[0][2];
+      k3 = p[3] <= rgba[0][3];
+      break;
+   case PIPE_FUNC_GREATER:
+      k0 = p[0] > rgba[0][0];
+      k1 = p[1] > rgba[0][1];
+      k2 = p[2] > rgba[0][2];
+      k3 = p[3] > rgba[0][3];
+      break;
+   case PIPE_FUNC_GEQUAL:
+      k0 = p[0] >= rgba[0][0];
+      k1 = p[1] >= rgba[0][1];
+      k2 = p[2] >= rgba[0][2];
+      k3 = p[3] >= rgba[0][3];
+      break;
+   case PIPE_FUNC_EQUAL:
+      k0 = p[0] == rgba[0][0];
+      k1 = p[1] == rgba[0][1];
+      k2 = p[2] == rgba[0][2];
+      k3 = p[3] == rgba[0][3];
+      break;
+   case PIPE_FUNC_NOTEQUAL:
+      k0 = p[0] != rgba[0][0];
+      k1 = p[1] != rgba[0][1];
+      k2 = p[2] != rgba[0][2];
+      k3 = p[3] != rgba[0][3];
+      break;
+   case PIPE_FUNC_ALWAYS:
+      k0 = k1 = k2 = k3 = 1;
+      break;
+   case PIPE_FUNC_NEVER:
+      k0 = k1 = k2 = k3 = 0;
+      break;
+   default:
+      k0 = k1 = k2 = k3 = 0;
+      assert(0);
+      break;
+   }
+
+   /* convert four pass/fail values to an intensity in [0,1] */
+   val = 0.25F * (k0 + k1 + k2 + k3);
+
+   /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
+   for (j = 0; j < 4; j++) {
+      rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
+      rgba[3][j] = 1.0F;
+   }
+}
+
+
+
+static void
+lp_get_samples_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler,
+                                    const float s[QUAD_SIZE],
+                                    const float t[QUAD_SIZE],
+                                    const float p[QUAD_SIZE],
+                                    float lodbias,
+                                    float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   unsigned  j;
+   unsigned level = samp->level;
+   unsigned xpot = 1 << (samp->xpot - level);
+   unsigned ypot = 1 << (samp->ypot - level);
+   unsigned xmax = (xpot - 1) & (TEX_TILE_SIZE - 1); /* MIN2(TEX_TILE_SIZE, xpot) - 1; */
+   unsigned ymax = (ypot - 1) & (TEX_TILE_SIZE - 1); /* MIN2(TEX_TILE_SIZE, ypot) - 1; */
+      
+   for (j = 0; j < QUAD_SIZE; j++) {
+      int c;
+
+      float u = s[j] * xpot - 0.5F;
+      float v = t[j] * ypot - 0.5F;
+
+      int uflr = util_ifloor(u);
+      int vflr = util_ifloor(v);
+
+      float xw = u - (float)uflr;
+      float yw = v - (float)vflr;
+
+      int x0 = uflr & (xpot - 1);
+      int y0 = vflr & (ypot - 1);
+
+      const uint8_t *tx[4];
+      
+
+      /* Can we fetch all four at once:
+       */
+      if (x0 < xmax && y0 < ymax)
+      {
+         get_texel_quad_2d(tgsi_sampler, 0, level, x0, y0, tx);
+      }
+      else 
+      {
+         unsigned x1 = (x0 + 1) & (xpot - 1);
+         unsigned y1 = (y0 + 1) & (ypot - 1);
+         get_texel_quad_2d_mt(tgsi_sampler, 0, level, 
+                              x0, y0, x1, y1, tx);
+      }
+
+
+      /* interpolate R, G, B, A */
+      for (c = 0; c < 4; c++) {
+         rgba[c][j] = lerp_2d(xw, yw, 
+                              ubyte_to_float(tx[0][c]), ubyte_to_float(tx[1][c]),
+                              ubyte_to_float(tx[2][c]), ubyte_to_float(tx[3][c]));
+      }
+   }
+}
+
+
+static void
+lp_get_samples_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler,
+                                     const float s[QUAD_SIZE],
+                                     const float t[QUAD_SIZE],
+                                     const float p[QUAD_SIZE],
+                                     float lodbias,
+                                     float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   unsigned  j;
+   unsigned level = samp->level;
+   unsigned xpot = 1 << (samp->xpot - level);
+   unsigned ypot = 1 << (samp->ypot - level);
+
+   for (j = 0; j < QUAD_SIZE; j++) {
+      int c;
+
+      float u = s[j] * xpot;
+      float v = t[j] * ypot;
+
+      int uflr = util_ifloor(u);
+      int vflr = util_ifloor(v);
+
+      int x0 = uflr & (xpot - 1);
+      int y0 = vflr & (ypot - 1);
+
+      const uint8_t *out = get_texel_2d_ptr(tgsi_sampler, 0, level, x0, y0);
+
+      for (c = 0; c < 4; c++) {
+         rgba[c][j] = ubyte_to_float(out[c]);
+      }
+   }
+}
+
+
+static void
+lp_get_samples_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler,
+                                     const float s[QUAD_SIZE],
+                                     const float t[QUAD_SIZE],
+                                     const float p[QUAD_SIZE],
+                                     float lodbias,
+                                     float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   unsigned  j;
+   unsigned level = samp->level;
+   unsigned xpot = 1 << (samp->xpot - level);
+   unsigned ypot = 1 << (samp->ypot - level);
+
+   for (j = 0; j < QUAD_SIZE; j++) {
+      int c;
+
+      float u = s[j] * xpot;
+      float v = t[j] * ypot;
+
+      int x0, y0;
+      const uint8_t *out;
+
+      x0 = util_ifloor(u);
+      if (x0 < 0) 
+         x0 = 0;
+      else if (x0 > xpot - 1)
+         x0 = xpot - 1;
+
+      y0 = util_ifloor(v);
+      if (y0 < 0) 
+         y0 = 0;
+      else if (y0 > ypot - 1)
+         y0 = ypot - 1;
+      
+      out = get_texel_2d_ptr(tgsi_sampler, 0, level, x0, y0);
+
+      for (c = 0; c < 4; c++) {
+         rgba[c][j] = ubyte_to_float(out[c]);
+      }
+   }
+}
+
+
+static void
+lp_get_samples_2d_linear_mip_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler,
+                                               const float s[QUAD_SIZE],
+                                               const float t[QUAD_SIZE],
+                                               const float p[QUAD_SIZE],
+                                               float lodbias,
+                                               float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   int level0;
+   float lambda;
+
+   lambda = compute_lambda(tgsi_sampler, s, t, p, lodbias);
+   level0 = (int)lambda;
+
+   if (lambda < 0.0) { 
+      samp->level = 0;
+      lp_get_samples_2d_linear_repeat_POT( tgsi_sampler,
+                                           s, t, p, 0, rgba );
+   }
+   else if (level0 >= texture->last_level) {
+      samp->level = texture->last_level;
+      lp_get_samples_2d_linear_repeat_POT( tgsi_sampler,
+                                           s, t, p, 0, rgba );
+   }
+   else {
+      float levelBlend = lambda - level0;
+      float rgba0[4][4];
+      float rgba1[4][4];
+      int c,j;
+
+      samp->level = level0;
+      lp_get_samples_2d_linear_repeat_POT( tgsi_sampler,
+                                           s, t, p, 0, rgba0 );
+
+      samp->level = level0+1;
+      lp_get_samples_2d_linear_repeat_POT( tgsi_sampler,
+                                           s, t, p, 0, rgba1 );
+
+      for (j = 0; j < QUAD_SIZE; j++) {
+         for (c = 0; c < 4; c++) {
+            rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]);
+         }
+      }
+   }
+}
+
+/**
+ * Common code for sampling 1D/2D/cube textures.
+ * Could probably extend for 3D...
+ */
+static void
+lp_get_samples_2d_common(struct tgsi_sampler *tgsi_sampler,
+                         const float s[QUAD_SIZE],
+                         const float t[QUAD_SIZE],
+                         const float p[QUAD_SIZE],
+                         float lodbias,
+                         float rgba[NUM_CHANNELS][QUAD_SIZE],
+                         const unsigned faces[4])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+   unsigned level0, level1, j, imgFilter;
+   int width, height;
+   float levelBlend = 0.0F;
+
+   choose_mipmap_levels(tgsi_sampler, s, t, p, 
+                        lodbias,
+                        &level0, &level1, &levelBlend, &imgFilter);
+
+   assert(sampler->normalized_coords);
+
+   width = texture->width[level0];
+   height = texture->height[level0];
+
+   assert(width > 0);
+
+   switch (imgFilter) {
+   case PIPE_TEX_FILTER_NEAREST:
+      {
+         int x[4], y[4];
+         nearest_texcoord_4(sampler->wrap_s, s, width, x);
+         nearest_texcoord_4(sampler->wrap_t, t, height, y);
+
+         for (j = 0; j < QUAD_SIZE; j++) {
+            get_texel(tgsi_sampler, faces[j], level0, x[j], y[j], 0, rgba, j);
+            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
+               shadow_compare(sampler, rgba, p, j);
+            }
+
+            if (level0 != level1) {
+               /* get texels from second mipmap level and blend */
+               float rgba2[4][4];
+               unsigned c;
+               x[j] /= 2;
+               y[j] /= 2;
+               get_texel(tgsi_sampler, faces[j], level1, x[j], y[j], 0,
+                         rgba2, j);
+               if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE){
+                  shadow_compare(sampler, rgba2, p, j);
+               }
+
+               for (c = 0; c < NUM_CHANNELS; c++) {
+                  rgba[c][j] = lerp(levelBlend, rgba[c][j], rgba2[c][j]);
+               }
+            }
+         }
+      }
+      break;
+   case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
+      {
+         int x0[4], y0[4], x1[4], y1[4];
+         float xw[4], yw[4]; /* weights */
+
+         linear_texcoord_4(sampler->wrap_s, s, width, x0, x1, xw);
+         linear_texcoord_4(sampler->wrap_t, t, height, y0, y1, yw);
+
+         for (j = 0; j < QUAD_SIZE; j++) {
+            float tx[4][4]; /* texels */
+            int c;
+            get_texel(tgsi_sampler, faces[j], level0, x0[j], y0[j], 0, tx, 0);
+            get_texel(tgsi_sampler, faces[j], level0, x1[j], y0[j], 0, tx, 1);
+            get_texel(tgsi_sampler, faces[j], level0, x0[j], y1[j], 0, tx, 2);
+            get_texel(tgsi_sampler, faces[j], level0, x1[j], y1[j], 0, tx, 3);
+            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
+               shadow_compare4(sampler, tx, p);
+            }
+
+            /* interpolate R, G, B, A */
+            for (c = 0; c < 4; c++) {
+               rgba[c][j] = lerp_2d(xw[j], yw[j],
+                                    tx[c][0], tx[c][1],
+                                    tx[c][2], tx[c][3]);
+            }
+
+            if (level0 != level1) {
+               /* get texels from second mipmap level and blend */
+               float rgba2[4][4];
+
+               /* XXX: This is incorrect -- will often end up with (x0
+                *  == x1 && y0 == y1), meaning that we fetch the same
+                *  texel four times and linearly interpolate between
+                *  identical values.  The correct approach would be to
+                *  call linear_texcoord again for the second level.
+                */
+               x0[j] /= 2;
+               y0[j] /= 2;
+               x1[j] /= 2;
+               y1[j] /= 2;
+               get_texel(tgsi_sampler, faces[j], level1, x0[j], y0[j], 0, tx, 0);
+               get_texel(tgsi_sampler, faces[j], level1, x1[j], y0[j], 0, tx, 1);
+               get_texel(tgsi_sampler, faces[j], level1, x0[j], y1[j], 0, tx, 2);
+               get_texel(tgsi_sampler, faces[j], level1, x1[j], y1[j], 0, tx, 3);
+               if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE){
+                  shadow_compare4(sampler, tx, p);
+               }
+
+               /* interpolate R, G, B, A */
+               for (c = 0; c < 4; c++) {
+                  rgba2[c][j] = lerp_2d(xw[j], yw[j],
+                                        tx[c][0], tx[c][1], tx[c][2], tx[c][3]);
+               }
+
+               for (c = 0; c < NUM_CHANNELS; c++) {
+                  rgba[c][j] = lerp(levelBlend, rgba[c][j], rgba2[c][j]);
+               }
+            }
+         }
+      }
+      break;
+   default:
+      assert(0);
+   }
+}
+
+
+static INLINE void
+lp_get_samples_1d(struct tgsi_sampler *sampler,
+                  const float s[QUAD_SIZE],
+                  const float t[QUAD_SIZE],
+                  const float p[QUAD_SIZE],
+                  float lodbias,
+                  float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   static const unsigned faces[4] = {0, 0, 0, 0};
+   static const float tzero[4] = {0, 0, 0, 0};
+   lp_get_samples_2d_common(sampler, s, tzero, NULL,
+                            lodbias, rgba, faces);
+}
+
+
+static INLINE void
+lp_get_samples_2d(struct tgsi_sampler *sampler,
+                  const float s[QUAD_SIZE],
+                  const float t[QUAD_SIZE],
+                  const float p[QUAD_SIZE],
+                  float lodbias,
+                  float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   static const unsigned faces[4] = {0, 0, 0, 0};
+   lp_get_samples_2d_common(sampler, s, t, p,
+                            lodbias, rgba, faces);
+}
+
+
+static INLINE void
+lp_get_samples_3d(struct tgsi_sampler *tgsi_sampler,
+                  const float s[QUAD_SIZE],
+                  const float t[QUAD_SIZE],
+                  const float p[QUAD_SIZE],
+                  float lodbias,
+                  float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+   /* get/map pipe_surfaces corresponding to 3D tex slices */
+   unsigned level0, level1, j, imgFilter;
+   int width, height, depth;
+   float levelBlend;
+   const uint face = 0;
+
+   choose_mipmap_levels(tgsi_sampler, s, t, p, 
+                        lodbias,
+                        &level0, &level1, &levelBlend, &imgFilter);
+
+   assert(sampler->normalized_coords);
+
+   width = texture->width[level0];
+   height = texture->height[level0];
+   depth = texture->depth[level0];
+
+   assert(width > 0);
+   assert(height > 0);
+   assert(depth > 0);
+
+   switch (imgFilter) {
+   case PIPE_TEX_FILTER_NEAREST:
+      {
+         int x[4], y[4], z[4];
+         nearest_texcoord_4(sampler->wrap_s, s, width, x);
+         nearest_texcoord_4(sampler->wrap_t, t, height, y);
+         nearest_texcoord_4(sampler->wrap_r, p, depth, z);
+         for (j = 0; j < QUAD_SIZE; j++) {
+            get_texel(tgsi_sampler, face, level0, x[j], y[j], z[j], rgba, j);
+            if (level0 != level1) {
+               /* get texels from second mipmap level and blend */
+               float rgba2[4][4];
+               unsigned c;
+               x[j] /= 2;
+               y[j] /= 2;
+               z[j] /= 2;
+               get_texel(tgsi_sampler, face, level1, x[j], y[j], z[j], rgba2, j);
+               for (c = 0; c < NUM_CHANNELS; c++) {
+                  rgba[c][j] = lerp(levelBlend, rgba2[c][j], rgba[c][j]);
+               }
+            }
+         }
+      }
+      break;
+   case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
+      {
+         int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4];
+         float xw[4], yw[4], zw[4]; /* interpolation weights */
+         linear_texcoord_4(sampler->wrap_s, s, width,  x0, x1, xw);
+         linear_texcoord_4(sampler->wrap_t, t, height, y0, y1, yw);
+         linear_texcoord_4(sampler->wrap_r, p, depth,  z0, z1, zw);
+
+         for (j = 0; j < QUAD_SIZE; j++) {
+            int c;
+            float tx0[4][4], tx1[4][4];
+            get_texel(tgsi_sampler, face, level0, x0[j], y0[j], z0[j], tx0, 0);
+            get_texel(tgsi_sampler, face, level0, x1[j], y0[j], z0[j], tx0, 1);
+            get_texel(tgsi_sampler, face, level0, x0[j], y1[j], z0[j], tx0, 2);
+            get_texel(tgsi_sampler, face, level0, x1[j], y1[j], z0[j], tx0, 3);
+            get_texel(tgsi_sampler, face, level0, x0[j], y0[j], z1[j], tx1, 0);
+            get_texel(tgsi_sampler, face, level0, x1[j], y0[j], z1[j], tx1, 1);
+            get_texel(tgsi_sampler, face, level0, x0[j], y1[j], z1[j], tx1, 2);
+            get_texel(tgsi_sampler, face, level0, x1[j], y1[j], z1[j], tx1, 3);
+
+            /* interpolate R, G, B, A */
+            for (c = 0; c < 4; c++) {
+               rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j],
+                                    tx0[c][0], tx0[c][1],
+                                    tx0[c][2], tx0[c][3],
+                                    tx1[c][0], tx1[c][1],
+                                    tx1[c][2], tx1[c][3]);
+            }
+
+            if (level0 != level1) {
+               /* get texels from second mipmap level and blend */
+               float rgba2[4][4];
+               x0[j] /= 2;
+               y0[j] /= 2;
+               z0[j] /= 2;
+               x1[j] /= 2;
+               y1[j] /= 2;
+               z1[j] /= 2;
+               get_texel(tgsi_sampler, face, level1, x0[j], y0[j], z0[j], tx0, 0);
+               get_texel(tgsi_sampler, face, level1, x1[j], y0[j], z0[j], tx0, 1);
+               get_texel(tgsi_sampler, face, level1, x0[j], y1[j], z0[j], tx0, 2);
+               get_texel(tgsi_sampler, face, level1, x1[j], y1[j], z0[j], tx0, 3);
+               get_texel(tgsi_sampler, face, level1, x0[j], y0[j], z1[j], tx1, 0);
+               get_texel(tgsi_sampler, face, level1, x1[j], y0[j], z1[j], tx1, 1);
+               get_texel(tgsi_sampler, face, level1, x0[j], y1[j], z1[j], tx1, 2);
+               get_texel(tgsi_sampler, face, level1, x1[j], y1[j], z1[j], tx1, 3);
+
+               /* interpolate R, G, B, A */
+               for (c = 0; c < 4; c++) {
+                  rgba2[c][j] = lerp_3d(xw[j], yw[j], zw[j],
+                                        tx0[c][0], tx0[c][1],
+                                        tx0[c][2], tx0[c][3],
+                                        tx1[c][0], tx1[c][1],
+                                        tx1[c][2], tx1[c][3]);
+               }
+
+               /* blend mipmap levels */
+               for (c = 0; c < NUM_CHANNELS; c++) {
+                  rgba[c][j] = lerp(levelBlend, rgba[c][j], rgba2[c][j]);
+               }
+            }
+         }
+      }
+      break;
+   default:
+      assert(0);
+   }
+}
+
+
+static void
+lp_get_samples_cube(struct tgsi_sampler *sampler,
+                    const float s[QUAD_SIZE],
+                    const float t[QUAD_SIZE],
+                    const float p[QUAD_SIZE],
+                    float lodbias,
+                    float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   unsigned faces[QUAD_SIZE], j;
+   float ssss[4], tttt[4];
+   for (j = 0; j < QUAD_SIZE; j++) {
+      faces[j] = choose_cube_face(s[j], t[j], p[j], ssss + j, tttt + j);
+   }
+   lp_get_samples_2d_common(sampler, ssss, tttt, NULL,
+                            lodbias, rgba, faces);
+}
+
+
+static void
+lp_get_samples_rect(struct tgsi_sampler *tgsi_sampler,
+                    const float s[QUAD_SIZE],
+                    const float t[QUAD_SIZE],
+                    const float p[QUAD_SIZE],
+                    float lodbias,
+                    float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   const struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+   const uint face = 0;
+   unsigned level0, level1, j, imgFilter;
+   int width, height;
+   float levelBlend;
+
+   choose_mipmap_levels(tgsi_sampler, s, t, p, 
+                        lodbias,
+                        &level0, &level1, &levelBlend, &imgFilter);
+
+   /* texture RECTS cannot be mipmapped */
+   assert(level0 == level1);
+
+   width = texture->width[level0];
+   height = texture->height[level0];
+
+   assert(width > 0);
+
+   switch (imgFilter) {
+   case PIPE_TEX_FILTER_NEAREST:
+      {
+         int x[4], y[4];
+         nearest_texcoord_unnorm_4(sampler->wrap_s, s, width, x);
+         nearest_texcoord_unnorm_4(sampler->wrap_t, t, height, y);
+         for (j = 0; j < QUAD_SIZE; j++) {
+            get_texel(tgsi_sampler, face, level0, x[j], y[j], 0, rgba, j);
+            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
+               shadow_compare(sampler, rgba, p, j);
+            }
+         }
+      }
+      break;
+   case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
+      {
+         int x0[4], y0[4], x1[4], y1[4];
+         float xw[4], yw[4]; /* weights */
+         linear_texcoord_unnorm_4(sampler->wrap_s, s, width,  x0, x1, xw);
+         linear_texcoord_unnorm_4(sampler->wrap_t, t, height, y0, y1, yw);
+         for (j = 0; j < QUAD_SIZE; j++) {
+            float tx[4][4]; /* texels */
+            int c;
+            get_texel(tgsi_sampler, face, level0, x0[j], y0[j], 0, tx, 0);
+            get_texel(tgsi_sampler, face, level0, x1[j], y0[j], 0, tx, 1);
+            get_texel(tgsi_sampler, face, level0, x0[j], y1[j], 0, tx, 2);
+            get_texel(tgsi_sampler, face, level0, x1[j], y1[j], 0, tx, 3);
+            if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
+               shadow_compare4(sampler, tx, p);
+            }
+            for (c = 0; c < 4; c++) {
+               rgba[c][j] = lerp_2d(xw[j], yw[j],
+                                    tx[c][0], tx[c][1], tx[c][2], tx[c][3]);
+            }
+         }
+      }
+      break;
+   default:
+      assert(0);
+   }
+}
+
+
+/**
+ * Error condition handler
+ */
+static INLINE void
+lp_get_samples_null(struct tgsi_sampler *tgsi_sampler,
+                    const float s[QUAD_SIZE],
+                    const float t[QUAD_SIZE],
+                    const float p[QUAD_SIZE],
+                    float lodbias,
+                    float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   int i,j;
+
+   for (i = 0; i < 4; i++)
+      for (j = 0; j < 4; j++)
+         rgba[i][j] = 1.0;
+}
+
+/**
+ * Called via tgsi_sampler::get_samples() when using a sampler for the
+ * first time.  Determine the actual sampler function, link it in and
+ * call it.
+ */
+void
+lp_get_samples(struct tgsi_sampler *tgsi_sampler,
+               const float s[QUAD_SIZE],
+               const float t[QUAD_SIZE],
+               const float p[QUAD_SIZE],
+               float lodbias,
+               float rgba[NUM_CHANNELS][QUAD_SIZE])
+{
+   struct lp_shader_sampler *samp = lp_shader_sampler(tgsi_sampler);
+   const struct pipe_texture *texture = samp->texture;
+   const struct pipe_sampler_state *sampler = samp->sampler;
+
+   /* Default to the 'undefined' case:
+    */
+   tgsi_sampler->get_samples = lp_get_samples_null;
+
+   if (!texture) {
+      assert(0);                /* is this legal?? */
+      goto out;
+   }
+
+   if (!sampler->normalized_coords) {
+      assert (texture->target == PIPE_TEXTURE_2D);
+      tgsi_sampler->get_samples = lp_get_samples_rect;
+      goto out;
+   }
+
+   switch (texture->target) {
+   case PIPE_TEXTURE_1D:
+      tgsi_sampler->get_samples = lp_get_samples_1d;
+      break;
+   case PIPE_TEXTURE_2D:
+      tgsi_sampler->get_samples = lp_get_samples_2d;
+      break;
+   case PIPE_TEXTURE_3D:
+      tgsi_sampler->get_samples = lp_get_samples_3d;
+      break;
+   case PIPE_TEXTURE_CUBE:
+      tgsi_sampler->get_samples = lp_get_samples_cube;
+      break;
+   default:
+      assert(0);
+      break;
+   }
+
+   /* Do this elsewhere: 
+    */
+   samp->xpot = util_unsigned_logbase2( samp->texture->width[0] );
+   samp->ypot = util_unsigned_logbase2( samp->texture->height[0] );
+
+   /* Try to hook in a faster sampler.  Ultimately we'll have to
+    * code-generate these.  Luckily most of this looks like it is
+    * orthogonal state within the sampler.
+    */
+   if (texture->target == PIPE_TEXTURE_2D &&
+       sampler->min_img_filter == sampler->mag_img_filter &&
+       sampler->wrap_s == sampler->wrap_t &&
+       sampler->compare_mode == FALSE &&
+       sampler->normalized_coords) 
+   {
+      if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
+         samp->level = CLAMP((int) sampler->min_lod,
+                             0, (int) texture->last_level);
+
+         if (sampler->wrap_s == PIPE_TEX_WRAP_REPEAT) {
+            switch (sampler->min_img_filter) {
+            case PIPE_TEX_FILTER_NEAREST:
+               tgsi_sampler->get_samples = lp_get_samples_2d_nearest_repeat_POT;
+               break;
+            case PIPE_TEX_FILTER_LINEAR:
+               tgsi_sampler->get_samples = lp_get_samples_2d_linear_repeat_POT;
+               break;
+            default:
+               break;
+            }
+         } 
+         else if (sampler->wrap_s == PIPE_TEX_WRAP_CLAMP) {
+            switch (sampler->min_img_filter) {
+            case PIPE_TEX_FILTER_NEAREST:
+               tgsi_sampler->get_samples = lp_get_samples_2d_nearest_clamp_POT;
+               break;
+            default:
+               break;
+            }
+         }
+      }
+      else if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
+         if (sampler->wrap_s == PIPE_TEX_WRAP_REPEAT) {
+            switch (sampler->min_img_filter) {
+            case PIPE_TEX_FILTER_LINEAR:
+               tgsi_sampler->get_samples = lp_get_samples_2d_linear_mip_linear_repeat_POT;
+               break;
+            default:
+               break;
+            }
+         } 
+      }
+   }
+   else if (0) {
+      _debug_printf("target %d/%d min_mip %d/%d min_img %d/%d wrap %d/%d compare %d/%d norm %d/%d\n",
+                    texture->target, PIPE_TEXTURE_2D,
+                    sampler->min_mip_filter, PIPE_TEX_MIPFILTER_NONE,
+                    sampler->min_img_filter, sampler->mag_img_filter,
+                    sampler->wrap_s, sampler->wrap_t,
+                    sampler->compare_mode, FALSE,
+                    sampler->normalized_coords, TRUE);
+   }
+
+out:
+   tgsi_sampler->get_samples( tgsi_sampler, s, t, p, lodbias, rgba );
+}
+
+
+void PIPE_CDECL
+lp_fetch_texel_soa( struct tgsi_sampler **samplers,
+                    uint32_t unit,
+                    float *store )
+{
+   struct tgsi_sampler *sampler = samplers[unit];
+
+#if 0
+   uint j;
+
+   debug_printf("%s sampler: %p (%p) store: %p\n",
+                __FUNCTION__,
+                sampler, *sampler,
+                store );
+
+   debug_printf("lodbias %f\n", store[12]);
+
+   for (j = 0; j < 4; j++)
+      debug_printf("sample %d texcoord %f %f\n",
+                   j,
+                   store[0+j],
+                   store[4+j]);
+#endif
+
+   {
+      float rgba[NUM_CHANNELS][QUAD_SIZE];
+      sampler->get_samples(sampler,
+                           &store[0],
+                           &store[4],
+                           &store[8],
+                           0.0f, /*store[12],  lodbias */
+                           rgba);
+      memcpy(store, rgba, sizeof rgba);
+   }
+
+#if 0
+   for (j = 0; j < 4; j++)
+      debug_printf("sample %d result %f %f %f %f\n",
+                   j,
+                   store[0+j],
+                   store[4+j],
+                   store[8+j],
+                   store[12+j]);
+#endif
+}
+
+
+#include "lp_bld_type.h"
+#include "lp_bld_intr.h"
+#include "lp_bld_tgsi.h"
+
+
+struct lp_c_sampler_soa
+{
+   struct lp_build_sampler_soa base;
+
+   LLVMValueRef context_ptr;
+
+   LLVMValueRef samplers_ptr;
+
+   /** Coords/texels store */
+   LLVMValueRef store_ptr;
+};
+
+
+static void
+lp_c_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
+{
+   FREE(sampler);
+}
+
+
+static void
+lp_c_sampler_soa_emit_fetch_texel(struct lp_build_sampler_soa *_sampler,
+                                  LLVMBuilderRef builder,
+                                  struct lp_type type,
+                                  unsigned unit,
+                                  unsigned num_coords,
+                                  const LLVMValueRef *coords,
+                                  LLVMValueRef lodbias,
+                                  LLVMValueRef *texel)
+{
+   struct lp_c_sampler_soa *sampler = (struct lp_c_sampler_soa *)_sampler;
+   LLVMTypeRef vec_type = LLVMTypeOf(coords[0]);
+   LLVMValueRef args[3];
+   unsigned i;
+
+   if(!sampler->samplers_ptr)
+      sampler->samplers_ptr = lp_jit_context_samplers(builder, sampler->context_ptr);
+
+   if(!sampler->store_ptr)
+      sampler->store_ptr = LLVMBuildArrayAlloca(builder,
+                                            vec_type,
+                                            LLVMConstInt(LLVMInt32Type(), 4, 0),
+                                            "texel_store");
+
+   for (i = 0; i < num_coords; i++) {
+      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+      LLVMValueRef coord_ptr = LLVMBuildGEP(builder, sampler->store_ptr, &index, 1, "");
+      LLVMBuildStore(builder, coords[i], coord_ptr);
+   }
+
+   args[0] = sampler->samplers_ptr;
+   args[1] = LLVMConstInt(LLVMInt32Type(), unit, 0);
+   args[2] = sampler->store_ptr;
+
+   lp_build_intrinsic(builder, "fetch_texel", LLVMVoidType(), args, 3);
+
+   for (i = 0; i < NUM_CHANNELS; ++i) {
+      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+      LLVMValueRef texel_ptr = LLVMBuildGEP(builder, sampler->store_ptr, &index, 1, "");
+      texel[i] = LLVMBuildLoad(builder, texel_ptr, "");
+   }
+}
+
+
+struct lp_build_sampler_soa *
+lp_c_sampler_soa_create(LLVMValueRef context_ptr)
+{
+   struct lp_c_sampler_soa *sampler;
+
+   sampler = CALLOC_STRUCT(lp_c_sampler_soa);
+   if(!sampler)
+      return NULL;
+
+   sampler->base.destroy = lp_c_sampler_soa_destroy;
+   sampler->base.emit_fetch_texel = lp_c_sampler_soa_emit_fetch_texel;
+   sampler->context_ptr = context_ptr;
+
+   return &sampler->base;
+}
+
index d2a6ae21f57ab5670aabe66785a2d42b3915196c..5138ccf7c93aaf4d7aaa79aec815f354f91f1198 100644 (file)
@@ -44,7 +44,6 @@
 #include "pipe/p_shader_tokens.h"
 #include "lp_bld_debug.h"
 #include "lp_bld_type.h"
-#include "lp_bld_intr.h"
 #include "lp_bld_sample.h"
 #include "lp_bld_tgsi.h"
 #include "lp_state.h"
index 2c135029ea2d1b5bd817c6f6d8ca5485bfe19fe3..039539d682d3dd637a0c55cce218769d0239dc82 100644 (file)
@@ -42,7 +42,6 @@
 #include "lp_context.h"
 #include "lp_state.h"
 #include "lp_texture.h"
-#include "lp_tex_cache.h"
 #include "lp_screen.h"
 #include "lp_winsys.h"
 
index 7a1ecf5107b218e8844876ef3a9c85fa961c55bc..971d933333153eb507b85632086fd3846b0d1c93 100644 (file)
@@ -38,8 +38,6 @@
 #include "util/u_tile.h"
 #include "util/u_rect.h"
 #include "lp_context.h"
-#include "lp_surface.h"
-#include "lp_texture.h"
 #include "lp_tile_soa.h"
 #include "lp_tile_cache.h"
 
index 8e01793940226eb8b33d781533bf009ec3621460..73e075f0d88671e2f1fcbbc2104e9b5849023725 100644 (file)
@@ -43,7 +43,6 @@
 #include "sp_surface.h"
 #include "sp_tile_cache.h"
 #include "sp_tex_tile_cache.h"
-#include "sp_texture.h"
 #include "sp_winsys.h"
 #include "sp_query.h"
 
index 75dac810a12afe00d5b33abaed4974abe6cf5680..e8952bf4fb863bdc7a9dc36ff7b2577aba16971d 100644 (file)
 #include "draw/draw_context.h"
 #include "sp_flush.h"
 #include "sp_context.h"
-#include "sp_surface.h"
 #include "sp_state.h"
 #include "sp_tile_cache.h"
 #include "sp_tex_tile_cache.h"
-#include "sp_winsys.h"
 
 
 void
index 5812d1eefeb1ed278299cb0c98c09086618f27ad..98c08eaffaf628d388ff5805e929f5c5495acb8d 100644 (file)
@@ -526,7 +526,8 @@ static void
 sp_vbuf_destroy(struct vbuf_render *vbr)
 {
    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
-   align_free(cvbr->vertex_buffer);
+   if(cvbr->vertex_buffer)
+      align_free(cvbr->vertex_buffer);
    sp_setup_destroy_context(cvbr->setup);
    FREE(cvbr);
 }
index d9babe81dad5d165e10a19fafabd412ad654ae86..3b8c2d5789c8eb87d30e28c0dd2362d0f9e366ef 100644 (file)
@@ -35,7 +35,6 @@
 #include "util/u_memory.h"
 #include "sp_context.h"
 #include "sp_quad.h"
-#include "sp_surface.h"
 #include "sp_tile_cache.h"
 #include "sp_quad_pipe.h"
 
index 0ca86c4e1cbb1a2e93e82c70132df62443a565d5..a981775cbd3c91f7c7d7147e51c6699ccbfbf109 100644 (file)
  */
 
 #include "pipe/p_defines.h"
+#include "util/u_format.h"
 #include "util/u_memory.h"
 #include "tgsi/tgsi_scan.h"
 #include "sp_context.h"
 #include "sp_quad.h"
-#include "sp_surface.h"
 #include "sp_quad_pipe.h"
 #include "sp_tile_cache.h"
 #include "sp_state.h"           /* for sp_fragment_shader */
@@ -651,6 +651,20 @@ static unsigned mask_count[16] =
 
 
 
+/** helper to get number of Z buffer bits */
+static unsigned
+get_depth_bits(struct quad_stage *qs)
+{
+   struct pipe_surface *zsurf = qs->softpipe->framebuffer.zsbuf;
+   if (zsurf)
+      return util_format_get_component_bits(zsurf->format,
+                                            UTIL_FORMAT_COLORSPACE_ZS, 0);
+   else
+      return 0;
+}
+
+
+
 static void
 depth_test_quads_fallback(struct quad_stage *qs, 
                           struct quad_header *quads[],
@@ -666,7 +680,7 @@ depth_test_quads_fallback(struct quad_stage *qs,
       nr = alpha_test_quads(qs, quads, nr);
    }
 
-   if (qs->softpipe->framebuffer.zsbuf && 
+   if (get_depth_bits(qs) > 0 &&
        (qs->softpipe->depth_stencil->depth.enabled ||
         qs->softpipe->depth_stencil->stencil[0].enabled)) {
 
@@ -884,7 +898,7 @@ choose_depth_test(struct quad_stage *qs,
 
    boolean alpha = qs->softpipe->depth_stencil->alpha.enabled;
 
-   boolean depth = (qs->softpipe->framebuffer.zsbuf && 
+   boolean depth = (get_depth_bits(qs) > 0 &&
                     qs->softpipe->depth_stencil->depth.enabled);
 
    unsigned depthfunc = qs->softpipe->depth_stencil->depth.func;
@@ -895,7 +909,6 @@ choose_depth_test(struct quad_stage *qs,
 
    boolean occlusion = qs->softpipe->active_query_count;
 
-
    if (!alpha &&
        !depth &&
        !stencil) {
index 1e7533d0f9ec8cafd0d007fe38ceb2f95e19a165..e799df136edd9a1de96ef88b9dcfa6f709bd05db 100644 (file)
@@ -45,8 +45,6 @@
 #include "sp_state.h"
 #include "sp_quad.h"
 #include "sp_quad_pipe.h"
-#include "sp_texture.h"
-#include "sp_tex_sample.h"
 
 
 struct quad_shade_stage
index 3da75364c5d7090c274244e47768408ce5d96dd7..f6c3a2b38b9e5be1c9aa8582d5f7d5e2541f8e03 100644 (file)
@@ -41,7 +41,6 @@
 #include "draw/draw_private.h"
 #include "draw/draw_vertex.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_thread.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
index f6154109ea831dae4d555249261bd46de91f96f9..39466782195adaf5176866e67c4952251288366e 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "sp_context.h"
 #include "sp_state.h"
-#include "sp_surface.h"
 #include "sp_tile_cache.h"
 
 #include "draw/draw_context.h"
index 46b6991195d80d64a9e6640557e62c407598935e..b491d92ed154612dfe8f4d182d3226e45c1dc46f 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "sp_context.h"
 #include "sp_state.h"
-#include "sp_surface.h"
 
 #include "draw/draw_context.h"
 
index e50a76a73bc9b9809d525a50d66dfb374a4c0ea6..50242d5bd69d9bd41356a2ea5ee51fad4e3053cf 100644 (file)
@@ -37,7 +37,6 @@
 #include "util/u_tile.h"
 #include "util/u_math.h"
 #include "sp_context.h"
-#include "sp_surface.h"
 #include "sp_texture.h"
 #include "sp_tex_tile_cache.h"
 
index 45e80c544775b237b0d84ea7a225fff140d91090..a5fff915077ad2d999a74e5ff0701a9f3a446957 100644 (file)
@@ -38,7 +38,6 @@
 #include "util/u_memory.h"
 
 #include "sp_context.h"
-#include "sp_state.h"
 #include "sp_texture.h"
 #include "sp_screen.h"
 #include "sp_winsys.h"
index 75492dffca2882765b2028a4c98c06136f7a4046..6b6ebc9b585b0a092ddf59d65a3adbd7d9c503f6 100644 (file)
@@ -26,7 +26,6 @@
 #include "svga_cmd.h"
 
 #include "pipe/p_inlines.h"
-#include "util/u_prim.h"
 #include "indices/u_indices.h"
 
 #include "svga_hw_reg.h"
index 167d8178315657418adf70a960ea39061c022332..022b444eb9162992abc590a97d35cb8759430958 100644 (file)
@@ -24,7 +24,6 @@
  **********************************************************/
 
 #include "pipe/p_inlines.h"
-#include "util/u_prim.h"
 #include "util/u_upload_mgr.h"
 #include "indices/u_indices.h"
 
index 855d228755f1839a0227747d1d81c1c8bdd1f8f1..3ad3f97816c1f0aa7b0e6d5b0493bdd6490619ee 100644 (file)
@@ -29,7 +29,6 @@
 #include "util/u_memory.h"
 
 #include "svga_context.h"
-#include "svga_state.h"
 
 #include "svga_hw_reg.h"
 
index ca2c7c49d72946d22a80668df7a8f62174f3c81d..93022f3cc51e2d91b1f939165b7c193cdbb7ac4b 100644 (file)
@@ -30,9 +30,6 @@
 #include "tgsi/tgsi_parse.h"
 
 #include "svga_context.h"
-#include "svga_state.h"
-#include "svga_hw_reg.h"
-#include "svga_cmd.h"
 
 /***********************************************************************
  * Constant buffers 
index df636c08a0592fc7c13b7f0d9757752b3f712d8d..34e60cb341abf25280db6c4f17cc574742cd6fb6 100644 (file)
@@ -29,7 +29,6 @@
 #include "util/u_memory.h"
 
 #include "svga_context.h"
-#include "svga_state.h"
 #include "svga_hw_reg.h"
 
 
index 0f24ef4ee8d46a8fd2cd4b83544639e8d5210ee7..4e0c499dc3ec91fcec0fe5a847b9da2fd1e64b57 100644 (file)
@@ -33,7 +33,6 @@
 #include "svga_hw_reg.h"
 #include "svga_context.h"
 #include "svga_screen.h"
-#include "svga_winsys.h"
 #include "svga_draw.h"
 #include "svga_state.h"
 #include "svga_swtnl.h"
index 0becb0765acc20387f3f70eb2b6d7fb999967d0d..3eb10336c4e3562a7c6b6d15b52d134e2acface5 100644 (file)
 #include "svga_screen_texture.h"
 #include "svga_context.h"
 #include "svga_winsys.h"
-#include "svga_draw.h"
 #include "svga_debug.h"
 
-#include "svga_hw_reg.h"
-
-
-
 
 static void svga_flush( struct pipe_context *pipe,
                         unsigned flags,
index 5f1213e46a3e530c592fd541c62f12c657297dbc..32f07fb2616c744fc4e74b525c5c823ebd35effd 100644 (file)
 
 #include "svga_screen.h"
 #include "svga_context.h"
-#include "svga_state.h"
 #include "svga_tgsi.h"
 #include "svga_hw_reg.h"
 #include "svga_cmd.h"
-#include "svga_draw.h"
 #include "svga_debug.h"
 
 
index 58cb1e6e23055800fdb3419183d628d8da463fc6..8cf1f2e083ad0acfb80784a75a5516a9a1f54997 100644 (file)
 
 #include "svga_context.h"
 #include "svga_screen_texture.h"
-#include "svga_state.h"
-#include "svga_winsys.h"
-
-#include "svga_hw_reg.h"
-
-
 
 
 static void svga_set_scissor_state( struct pipe_context *pipe,
index 01336b0a2c3ac5fdf9be0302241fbf28583df7bf..08283e37317d083959b9d77a3537f08b4fdddf17 100644 (file)
@@ -32,7 +32,6 @@
 #include "svga_screen.h"
 #include "svga_screen_buffer.h"
 #include "svga_winsys.h"
-#include "svga_draw.h"
 #include "svga_debug.h"
 
 
index b03f8eb9cf36a8b9ef887b41065ef4f850edfcb9..9ea11aad9a9f52c281779e5aa17f416f14ee979c 100644 (file)
@@ -30,7 +30,6 @@
 #include "util/u_memory.h"
 
 #include "svga_context.h"
-#include "svga_state.h"
 
 #include "svga_hw_reg.h"
 
index 460a101f8c0f5c8c2cb3d0a3abae99f898857fe5..161c66dd4ffd001b303a295251657f9cdb7883f6 100644 (file)
@@ -32,9 +32,6 @@
 
 #include "svga_context.h"
 #include "svga_screen_texture.h"
-#include "svga_state.h"
-
-#include "svga_hw_reg.h"
 
 #include "svga_debug.h"
 
index 42f290d162af4def6327f2fbcb1badcd887cb59b..0bf43fa9008fa679c292ed944380d7abe9699053 100644 (file)
 #include "svga_screen.h"
 #include "svga_screen_buffer.h"
 #include "svga_context.h"
-#include "svga_state.h"
-#include "svga_winsys.h"
-
-#include "svga_hw_reg.h"
 
 
 static void svga_set_vertex_buffers(struct pipe_context *pipe,
index 7e6ab576add36e84de79cda456fb3fa9ebeaa4cf..c4ac5304ac6ae758f33133090cb2726067e0471c 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "svga_screen.h"
 #include "svga_context.h"
-#include "svga_state.h"
 #include "svga_tgsi.h"
 #include "svga_hw_reg.h"
 #include "svga_cmd.h"
index fc1b3c980efe2a9ea3225caf1182c7b75d9b597b..cd1ed7bac8b352c2bd27d72f8a4ea6b0bde2166e 100644 (file)
 #include "svga_screen.h"
 #include "svga_screen_texture.h"
 #include "svga_screen_buffer.h"
-#include "svga_cmd.h"
 #include "svga_debug.h"
 
-#include "svga_hw_reg.h"
 #include "svga3d_shaderdefs.h"
 
 
@@ -393,8 +391,6 @@ svga_screen_create(struct svga_winsys_screen *sws)
    pipe_mutex_init(svgascreen->tex_mutex);
    pipe_mutex_init(svgascreen->swc_mutex);
 
-   LIST_INITHEAD(&svgascreen->cached_buffers);
-   
    svga_screen_cache_init(svgascreen);
 
    return screen;
index b94ca7fc1cad2f66c775a35b3068751e2f00df39..a009b607200c35f381d4c8e9f05604541e4258aa 100644 (file)
@@ -68,12 +68,6 @@ struct svga_screen
    pipe_mutex tex_mutex; 
    pipe_mutex swc_mutex; /* Protects the use of swc and dirty_buffers */
    
-   /** 
-    * List of buffers with cached GMR. Ordered from the most recently used to
-    * the least recently used 
-    */
-   struct list_head cached_buffers;
-   
    struct svga_host_surface_cache cache;
 };
 
index 58a1aba464b8fb4be3e29a0294414eb272082f9c..430a6970fde490622aade880b9d37c9ca6f643c6 100644 (file)
@@ -113,68 +113,9 @@ svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf)
    if(sbuf->hw.buf) {
       sws->buffer_destroy(sws, sbuf->hw.buf);
       sbuf->hw.buf = NULL;
-      assert(sbuf->head.prev && sbuf->head.next);
-      LIST_DEL(&sbuf->head);
-#ifdef DEBUG
-      sbuf->head.next = sbuf->head.prev = NULL; 
-#endif
    }
 }
 
-static INLINE enum pipe_error
-svga_buffer_backup(struct svga_screen *ss, struct svga_buffer *sbuf)
-{
-   if (sbuf->hw.buf && sbuf->hw.num_ranges) {
-      void *src;
-
-      if (!sbuf->swbuf)
-        sbuf->swbuf = align_malloc(sbuf->base.size, sbuf->base.alignment);
-      if (!sbuf->swbuf)
-        return PIPE_ERROR_OUT_OF_MEMORY;
-
-      src = ss->sws->buffer_map(ss->sws, sbuf->hw.buf,
-                               PIPE_BUFFER_USAGE_CPU_READ);
-      if (!src)
-        return PIPE_ERROR;
-
-      memcpy(sbuf->swbuf, src, sbuf->base.size);
-      ss->sws->buffer_unmap(ss->sws, sbuf->hw.buf);
-   }
-
-   return PIPE_OK;
-}
-
-/**
- * Try to make GMR space available by freeing the hardware storage of 
- * unmapped
- */
-boolean
-svga_buffer_free_cached_hw_storage(struct svga_screen *ss)
-{
-   struct list_head *curr;
-   struct svga_buffer *sbuf;
-   enum pipe_error ret = PIPE_OK;
-
-   curr = ss->cached_buffers.prev;
-   
-   /* free the least recently used buffer's hw storage which is not mapped */
-   do {
-      if(curr == &ss->cached_buffers)
-         return FALSE;
-
-      sbuf = LIST_ENTRY(struct svga_buffer, curr, head);
-      
-      curr = curr->prev;
-      if (sbuf->map.count == 0)
-        ret = svga_buffer_backup(ss, sbuf);
-
-   } while(sbuf->map.count != 0 || ret != PIPE_OK);
-   
-   svga_buffer_destroy_hw_storage(ss, sbuf);
-   
-   return TRUE;
-}
-
 struct svga_winsys_buffer *
 svga_winsys_buffer_create( struct svga_screen *ss,
                            unsigned alignment, 
@@ -195,12 +136,6 @@ svga_winsys_buffer_create( struct svga_screen *ss,
       svga_screen_flush(ss, NULL);
       buf = sws->buffer_create(sws, alignment, usage, size);
 
-      SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "evicting buffers to find %d bytes GMR\n", 
-               size);
-
-      /* Try evicing all buffer storage */
-      while(!buf && svga_buffer_free_cached_hw_storage(ss))
-         buf = sws->buffer_create(sws, alignment, usage, size);
    }
    
    return buf;
@@ -226,8 +161,6 @@ svga_buffer_create_hw_storage(struct svga_screen *ss,
          return PIPE_ERROR_OUT_OF_MEMORY;
       
       assert(!sbuf->needs_flush);
-      assert(!sbuf->head.prev && !sbuf->head.next);
-      LIST_ADD(&sbuf->head, &ss->cached_buffers);
    }
    
    return PIPE_OK;
@@ -311,7 +244,6 @@ static void
 svga_buffer_upload_flush(struct svga_context *svga,
                          struct svga_buffer *sbuf)
 {
-   struct svga_screen *ss = svga_screen(svga->pipe.screen);
    SVGA3dCopyBox *boxes;
    unsigned i;
 
@@ -348,13 +280,16 @@ svga_buffer_upload_flush(struct svga_context *svga,
 
    assert(sbuf->head.prev && sbuf->head.next);
    LIST_DEL(&sbuf->head);
+#ifdef DEBUG
+   sbuf->head.next = sbuf->head.prev = NULL; 
+#endif
    sbuf->needs_flush = FALSE;
-   /* XXX: do we care about cached_buffers any more ?*/
-   LIST_ADD(&sbuf->head, &ss->cached_buffers);
 
    sbuf->hw.svga = NULL;
    sbuf->hw.boxes = NULL;
 
+   sbuf->host_written = TRUE;
+
    /* Decrement reference count */
    pipe_reference(&(sbuf->base.reference), NULL);
    sbuf = NULL;
@@ -437,17 +372,17 @@ svga_buffer_map_range( struct pipe_screen *screen,
    }
    else {
       if(!sbuf->hw.buf) {
-         struct svga_winsys_surface *handle = sbuf->handle;
-
          if(svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK)
             return NULL;
          
          /* Populate the hardware storage if the host surface pre-existed */
-         if((usage & PIPE_BUFFER_USAGE_CPU_READ) && handle) {
+         if(sbuf->host_written) {
             SVGA3dSurfaceDMAFlags flags;
             enum pipe_error ret;
             struct pipe_fence_handle *fence = NULL;
             
+            assert(sbuf->handle);
+
             SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "dma from sid %p (buffer), bytes %u - %u\n", 
                      sbuf->handle, 0, sbuf->base.size);
 
@@ -478,17 +413,6 @@ svga_buffer_map_range( struct pipe_screen *screen,
             sws->fence_reference(sws, &fence, NULL);
          }
       }
-      else {
-         if((usage & PIPE_BUFFER_USAGE_CPU_READ) && !sbuf->needs_flush) {
-            /* We already had the hardware storage but we would have to issue
-             * a download if we hadn't, so move the buffer to the begginning
-             * of the LRU list.
-             */
-            assert(sbuf->head.prev && sbuf->head.next);
-            LIST_DEL(&sbuf->head);
-            LIST_ADD(&sbuf->head, &ss->cached_buffers);
-         }
-      }
          
       map = sws->buffer_map(sws, sbuf->hw.buf, usage);
    }
@@ -572,10 +496,8 @@ svga_buffer_destroy( struct pipe_buffer *buf )
    
    assert(!sbuf->needs_flush);
 
-   if(sbuf->handle) {
-      SVGA_DBG(DEBUG_DMA, "release sid %p sz %d\n", sbuf->handle, sbuf->base.size);
-      svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle);
-   }
+   if(sbuf->handle)
+      svga_buffer_destroy_host_surface(ss, sbuf);
    
    if(sbuf->hw.buf)
       svga_buffer_destroy_hw_storage(ss, sbuf);
@@ -595,6 +517,9 @@ svga_buffer_create(struct pipe_screen *screen,
    struct svga_screen *ss = svga_screen(screen);
    struct svga_buffer *sbuf;
    
+   assert(size);
+   assert(alignment);
+
    sbuf = CALLOC_STRUCT(svga_buffer);
    if(!sbuf)
       goto error1;
@@ -755,8 +680,7 @@ svga_buffer_handle(struct svga_context *svga,
       assert(sbuf->hw.svga == svga);
 
       sbuf->needs_flush = TRUE;
-      assert(sbuf->head.prev && sbuf->head.next);
-      LIST_DEL(&sbuf->head);
+      assert(!sbuf->head.prev && !sbuf->head.next);
       LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers);
    }
 
index 5d7af5a7c5049ef0cba2a16f14f49c5d8251948b..448ac107c7f309b4e8282dfbb2e7b89403501dd7 100644 (file)
@@ -135,6 +135,11 @@ struct svga_buffer
     */
    struct svga_winsys_surface *handle;
    
+   /**
+    * Whether the host has been ever written.
+    */
+   boolean host_written;
+
    struct {
       unsigned count;
       boolean writing;
@@ -178,9 +183,6 @@ svga_buffer_handle(struct svga_context *svga,
 void
 svga_context_flush_buffers(struct svga_context *svga);
 
-boolean
-svga_buffer_free_cached_hw_storage(struct svga_screen *ss);
-
 struct svga_winsys_buffer *
 svga_winsys_buffer_create(struct svga_screen *ss,
                           unsigned alignment, 
index 2224c2d3945d96d102dea8a032a9be3f311be2bb..0d69007fd87316ae6eeed7c879b23f1839b16647 100644 (file)
@@ -306,11 +306,19 @@ svga_texture_create(struct pipe_screen *screen,
       tex->key.numFaces = 1;
    }
 
+   tex->key.cachable = 1;
+
    if(templat->tex_usage & PIPE_TEXTURE_USAGE_SAMPLER)
       tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE;
 
-   if(templat->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY)
+   if(templat->tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) {
+      tex->key.cachable = 0;
+   }
+
+   if(templat->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) {
       tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT;
+      tex->key.cachable = 0;
+   }
    
    /* 
     * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
@@ -333,8 +341,6 @@ svga_texture_create(struct pipe_screen *screen,
    if(tex->key.format == SVGA3D_FORMAT_INVALID)
       goto error2;
 
-   tex->key.cachable = 1;
-   
    SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle);
    tex->handle = svga_screen_surface_create(svgascreen, &tex->key);
    if (tex->handle)
@@ -416,6 +422,62 @@ svga_texture_blanket(struct pipe_screen * screen,
 }
 
 
+struct pipe_texture *
+svga_screen_texture_wrap_surface(struct pipe_screen *screen,
+                                struct pipe_texture *base,
+                                enum SVGA3dSurfaceFormat format,
+                                struct svga_winsys_surface *srf)
+{
+   struct svga_texture *tex;
+   assert(screen);
+
+   /* Only supports one type */
+   if (base->target != PIPE_TEXTURE_2D ||
+       base->last_level != 0 ||
+       base->depth0 != 1) {
+      return NULL;
+   }
+
+   if (!srf)
+      return NULL;
+
+   if (svga_translate_format(base->format) != format) {
+      unsigned f1 = svga_translate_format(base->format);
+      unsigned f2 = format;
+
+      /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */
+      if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) ||
+              (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) ||
+              (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) {
+         debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2);
+         return NULL;
+      }
+   }
+
+   tex = CALLOC_STRUCT(svga_texture);
+   if (!tex)
+      return NULL;
+
+   tex->base = *base;
+   
+
+   if (format == 1)
+      tex->base.format = PIPE_FORMAT_X8R8G8B8_UNORM;
+   else if (format == 2)
+      tex->base.format = PIPE_FORMAT_A8R8G8B8_UNORM;
+
+   pipe_reference_init(&tex->base.reference, 1);
+   tex->base.screen = screen;
+
+   SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf);
+
+   tex->key.cachable = 0;
+   tex->handle = srf;
+
+   return &tex->base;
+}
+
+
 static void
 svga_texture_destroy(struct pipe_texture *pt)
 {
index cfdcae4ee4a0d37ead162a15a975239740eaec9a..eda1aefd67afe2000b5fcf210db524b30ba0e2fe 100644 (file)
@@ -32,8 +32,6 @@
 #include "svga_cmd.h"
 #include "svga_debug.h"
 
-#include "svga_hw_reg.h"
-
 
 /***********************************************************************
  * Hardware state update
index 8b6803a285af09756d659bd4db76914844341c3f..2f9adaeb56149c8a825a17223b39c163d18a2064 100644 (file)
@@ -31,9 +31,6 @@
 #include "svga_state.h"
 #include "svga_cmd.h"
 
-#include "svga_hw_reg.h"
-
-
 
 struct rs_queue {
    unsigned rs_count;
index b3137945202add4bccbae2270365d8675ba4d8ff..b3c9687b1a4445623541b77411b6e60a2015b913 100644 (file)
@@ -33,8 +33,6 @@
 #include "svga_state.h"
 #include "svga_cmd.h"
 
-#include "svga_hw_reg.h"
-
 
 void svga_cleanup_tss_binding(struct svga_context *svga)
 {
index b4f757a47a9264cc365807cd3147e0e02b947350..aafb3e26b0b9b7f134191f13fd774173294acece 100644 (file)
@@ -31,7 +31,6 @@
 #include "pipe/p_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
-#include "util/u_simple_shaders.h"
 
 #include "svga_context.h"
 #include "svga_state.h"
@@ -87,13 +86,13 @@ svga_vbuf_render_allocate_vertices( struct vbuf_render *render,
    if (!svga_render->vbuf) {
       svga_render->vbuf_size = MAX2(size, svga_render->vbuf_alloc_size);
       svga_render->vbuf = pipe_buffer_create(screen,
-                                             0,
+                                             16,
                                              PIPE_BUFFER_USAGE_VERTEX,
                                              svga_render->vbuf_size);
       if(!svga_render->vbuf) {
          svga_context_flush(svga, NULL);
          svga_render->vbuf = pipe_buffer_create(screen,
-                                                0,
+                                                16,
                                                 PIPE_BUFFER_USAGE_VERTEX,
                                                 svga_render->vbuf_size);
          assert(svga_render->vbuf);
@@ -123,7 +122,9 @@ svga_vbuf_render_map_vertices( struct vbuf_render *render )
    char *ptr = (char*)pipe_buffer_map(screen,
                                       svga_render->vbuf,
                                       PIPE_BUFFER_USAGE_CPU_WRITE | 
-                                      PIPE_BUFFER_USAGE_FLUSH_EXPLICIT);
+                                      PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
+                                      PIPE_BUFFER_USAGE_DISCARD |
+                                      PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
    return ptr + svga_render->vbuf_offset;
 }
 
@@ -259,14 +260,14 @@ svga_vbuf_render_draw( struct vbuf_render *render,
    if (!svga_render->ibuf) {
       svga_render->ibuf_size = MAX2(size, svga_render->ibuf_alloc_size);
       svga_render->ibuf = pipe_buffer_create(screen,
-                                             0,
+                                             2,
                                              PIPE_BUFFER_USAGE_VERTEX,
                                              svga_render->ibuf_size);
       svga_render->ibuf_offset = 0;
    }
 
-   pipe_buffer_write(screen, svga_render->ibuf,
-                     svga_render->ibuf_offset, 2 * nr_indices, indices);
+   pipe_buffer_write_nooverlap(screen, svga_render->ibuf,
+                                 svga_render->ibuf_offset, 2 * nr_indices, indices);
 
 
    /* off to hardware */
index 7655121bec17fb6ea448cc93f8e4ae88896a4c4c..0ae58c7d9deb4497e8afbf2052731e47ff11ac00 100644 (file)
@@ -27,7 +27,6 @@
 #include "draw/draw_vbuf.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_state.h"
-#include "util/u_memory.h"
 
 #include "svga_context.h"
 #include "svga_swtnl.h"
index 94b6ccc62dd7fef172858c44b86152aed5dc10e4..fe03e207fffb375a317796b887fa47b5f725b36d 100644 (file)
@@ -27,7 +27,6 @@
 #include "draw/draw_vbuf.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_state.h"
-#include "util/u_memory.h"
 
 #include "svga_context.h"
 #include "svga_swtnl.h"
index 23b3ace7f30dd2ff571e83f0d96be1ae224fb8fe..1ae990676103844479a11852fa5b523d09e4b0ad 100644 (file)
@@ -29,9 +29,6 @@
 #include "util/u_memory.h"
 
 #include "svga_tgsi_emit.h"
-#include "svga_context.h"
-
-
 
 
 static boolean ps20_input( struct svga_shader_emitter *emit,
index d1c7336dec497b0861b32cc74fb31d27cfc864fc..43fc0d3235969bb24a3e3403f2c0c92843679b58 100644 (file)
@@ -29,7 +29,6 @@
 #include "util/u_memory.h"
 
 #include "svga_tgsi_emit.h"
-#include "svga_context.h"
 
 static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semantic,
                                          unsigned *usage,
index 59f299c185865fc21fd25e3a8d8ca5aaf6ecaa95..27b99fe4c102f715e0f88e8bf03dbcd9d7d2b229 100644 (file)
@@ -296,4 +296,10 @@ svga_screen_buffer_from_texture(struct pipe_texture *texture,
                                struct pipe_buffer **buffer,
                                unsigned *stride);
 
+struct pipe_texture *
+svga_screen_texture_wrap_surface(struct pipe_screen *screen,
+                                struct pipe_texture *base,
+                                enum SVGA3dSurfaceFormat format,
+                                struct svga_winsys_surface *srf);
+
 #endif /* SVGA_WINSYS_H_ */
index 48d1c4051cc274a258b96be292da2b1ba13a0a55..e7ca3a86eadf081f3538769aeab753fa8f0d85b6 100644 (file)
@@ -173,6 +173,7 @@ trace_drm_create(struct drm_api *api)
    if (!tr_api)
       goto error;
 
+   tr_api->base.driver_name = api->driver_name;
    tr_api->base.create_screen = trace_drm_create_screen;
    tr_api->base.create_context = trace_drm_create_context;
    tr_api->base.texture_from_shared_handle = trace_drm_texture_from_shared_handle;
index 5fbd62a03d2bba16e3f9bda3d8cbb6ede5edb222..72f5c1dc2a261d7ba26a4cf2c19d32d915d84357 100644 (file)
@@ -63,13 +63,6 @@ pipe_buffer_map(struct pipe_screen *screen,
    if(screen->buffer_map_range) {
       unsigned offset = 0;
       unsigned length = buf->size;
-
-      /* XXX: Actually we should be using/detecting DISCARD
-       * instead of assuming that WRITE implies discard */
-      if((usage & PIPE_BUFFER_USAGE_CPU_WRITE) &&
-         !(usage & PIPE_BUFFER_USAGE_DISCARD))
-         usage |= PIPE_BUFFER_USAGE_CPU_READ;
-
       return screen->buffer_map_range(screen, buf, offset, length, usage);
    }
    else
@@ -126,7 +119,39 @@ pipe_buffer_write(struct pipe_screen *screen,
 
    map = pipe_buffer_map_range(screen, buf, offset, size, 
                                PIPE_BUFFER_USAGE_CPU_WRITE | 
-                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT);
+                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
+                               PIPE_BUFFER_USAGE_DISCARD);
+   assert(map);
+   if(map) {
+      memcpy((uint8_t *)map + offset, data, size);
+      pipe_buffer_flush_mapped_range(screen, buf, offset, size);
+      pipe_buffer_unmap(screen, buf);
+   }
+}
+
+/**
+ * Special case for writing non-overlapping ranges.
+ *
+ * We can avoid GPU/CPU synchronization when writing range that has never
+ * been written before.
+ */
+static INLINE void
+pipe_buffer_write_nooverlap(struct pipe_screen *screen,
+                            struct pipe_buffer *buf,
+                            unsigned offset, unsigned size,
+                            const void *data)
+{
+   void *map;
+
+   assert(offset < buf->size);
+   assert(offset + size <= buf->size);
+   assert(size);
+
+   map = pipe_buffer_map_range(screen, buf, offset, size,
+                               PIPE_BUFFER_USAGE_CPU_WRITE |
+                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
+                               PIPE_BUFFER_USAGE_DISCARD |
+                               PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
    assert(map);
    if(map) {
       memcpy((uint8_t *)map + offset, data, size);
index bb928928c9076e63d130d240a7803a116e8f03c8..b248a81880866e4e25e6e31713383c06ab5d8a89 100644 (file)
@@ -30,6 +30,11 @@ struct drm_api
 {
         const char *name;
 
+       /**
+        * Kernel driver name, as accepted by drmOpenByName.
+        */
+       const char *driver_name;
+
        /**
         * Special buffer functions
         */
index f2e5f3fb23c7be29cfdb5cd63069a6b87160ffc0..07f0554cc0d84966fa8595ce83f8221bbef9a363 100644 (file)
@@ -101,6 +101,12 @@ dri_destroy_context(__DRIcontext * cPriv)
 {
    struct dri_context *ctx = dri_context(cPriv);
 
+   /* note: we are freeing values and nothing more because
+    * driParseConfigFiles allocated values only - the rest
+    * is owned by screen optionCache.
+    */
+   FREE(ctx->optionCache.values);
+
    /* No particular reason to wait for command completion before
     * destroying a context, but it is probably worthwhile flushing it
     * to avoid having to add code elsewhere to cope with flushing a
index 0fdfa96b35ab7da3c823159c1591dea0cd2bc6a2..28fd8decf10b2815a4ba9a14aa09de643dea84d5 100644 (file)
@@ -123,11 +123,12 @@ dri_get_buffers(__DRIdrawable * dPriv)
 
    struct dri_drawable *drawable = dri_drawable(dPriv);
    struct pipe_surface *surface = NULL;
-   struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
+   struct dri_screen *st_screen = dri_screen(drawable->sPriv);
+   struct pipe_screen *screen = st_screen->pipe_screen;
    __DRIbuffer *buffers = NULL;
    __DRIscreen *dri_screen = drawable->sPriv;
    __DRIdrawable *dri_drawable = drawable->dPriv;
-   struct drm_api *api = ((struct dri_screen*)(dri_screen->private))->api;
+   struct drm_api *api = st_screen->api;
    boolean have_depth = FALSE;
    int i, count;
 
@@ -180,7 +181,9 @@ dri_get_buffers(__DRIdrawable * dPriv)
 
       switch (buffers[i].attachment) {
       case __DRI_BUFFER_FRONT_LEFT:
-        continue;
+        if (!st_screen->auto_fake_front)
+           continue;
+        /* fallthrough */
       case __DRI_BUFFER_FAKE_FRONT_LEFT:
         index = ST_SURFACE_FRONT_LEFT;
         format = drawable->color_format;
@@ -373,8 +376,8 @@ dri_create_buffer(__DRIscreen * sPriv,
    /* TODO incase of double buffer visual, delay fake creation */
    i = 0;
    drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
-   drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT;
-
+   if (!screen->auto_fake_front)
+      drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT;
    if (visual->doubleBufferMode)
       drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT;
    if (visual->depthBits && visual->stencilBits)
index d8c054313b3552f7f928a691d52235e6e6d84a05..cdc8eb1b1220d6a479dfc12970aa07f739511f02 100644 (file)
@@ -292,6 +292,8 @@ dri_init_screen2(__DRIscreen * sPriv)
 {
    struct dri_screen *screen;
    struct drm_create_screen_arg arg;
+   const __DRIdri2LoaderExtension *dri2_ext =
+     sPriv->dri2.loader;
 
    screen = CALLOC_STRUCT(dri_screen);
    if (!screen)
@@ -317,6 +319,9 @@ dri_init_screen2(__DRIscreen * sPriv)
    driParseOptionInfo(&screen->optionCache,
                      __driConfigOptions, __driNConfigOptions);
 
+   screen->auto_fake_front = dri2_ext->base.version >= 3 &&
+      dri2_ext->getBuffersWithFormat != NULL;
+
    return dri_fill_in_modes(screen, 32);
  fail:
    return NULL;
@@ -326,8 +331,18 @@ static void
 dri_destroy_screen(__DRIscreen * sPriv)
 {
    struct dri_screen *screen = dri_screen(sPriv);
+   int i;
 
    screen->pipe_screen->destroy(screen->pipe_screen);
+   
+   for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) {
+      FREE(screen->optionCache.info[i].name);
+      FREE(screen->optionCache.info[i].ranges);
+   }
+
+   FREE(screen->optionCache.info);
+   FREE(screen->optionCache.values);
+
    FREE(screen);
    sPriv->private = NULL;
 }
index 03387a0e81361eb1729ed85aed73caa91a40a3f4..75a0ee4250e89a7f6df1768272b8df4fb07d42f9 100644 (file)
@@ -59,6 +59,7 @@ struct dri_screen
    struct pipe_screen *pipe_screen;
    boolean d_depth_bits_last;
    boolean sd_depth_bits_last;
+   boolean auto_fake_front;
 };
 
 /** cast wrapper */
index e825aa718b6773bdb46a877d6076e2ce737dbe8c..b696f2fae93cce7af0233f5418f352abddd521c6 100644 (file)
@@ -1,19 +1,75 @@
 TOP = ../../../..
 include $(TOP)/configs/current
 
-LIBNAME = egldrm
-
-LIBRARY_INCLUDES = \
+common_INCLUDES = \
+       -I. \
        -I$(TOP)/src/gallium/include \
        -I$(TOP)/src/gallium/auxiliary \
-       -I$(TOP)/src/mesa/drivers/dri/common \
-       -I$(TOP)/src/mesa \
-       -I$(TOP)/include \
        -I$(TOP)/src/egl/main \
+       -I$(TOP)/include
+
+common_SOURCES = $(wildcard common/*.c)
+common_OBJECTS = $(common_SOURCES:.c=.o)
+
+
+x11_INCLUDES = \
+       -I$(TOP)/src/gallium/drivers \
+       -I$(TOP)/src/glx/x11 \
+       -I$(TOP)/src/egl/drivers/xdri \
+       -I$(TOP)/src/mesa \
        $(shell pkg-config --cflags-only-I libdrm)
 
+x11_SOURCES = $(wildcard x11/*.c) \
+             $(TOP)/src/glx/x11/dri2.c \
+             $(TOP)/src/egl/drivers/xdri/glxinit.c
+x11_OBJECTS = $(x11_SOURCES:.c=.o)
+
+
+kms_INCLUDES = $(shell pkg-config --cflags-only-I libdrm)
+kms_SOURCES = $(wildcard kms/*.c)
+kms_OBJECTS = $(kms_SOURCES:.c=.o)
+
+
+ALL_INCLUDES = $(common_INCLUDES) $(x11_INCLUDES) $(kms_INCLUDES)
+ALL_SOURCES = $(common_SOURCES) $(x11_SOURCES) $(kms_SOURCES)
+ALL_OBJECTS = $(common_OBJECTS) $(x11_OBJECTS) $(kms_OBJECTS)
+
+##### TARGETS #####
+
+EGL_DISPLAYS_MODS = $(foreach dpy, $(EGL_DISPLAYS), libegl$(dpy).a)
+
+default: depend $(EGL_DISPLAYS_MODS)
+
+
+libeglx11.a: $(x11_OBJECTS) $(common_OBJECTS) Makefile
+       $(MKLIB) -o eglx11 -static $(x11_OBJECTS) $(common_OBJECTS)
+
+libeglkms.a: $(kms_OBJECTS) $(common_OBJECTS) Makefile
+       $(MKLIB) -o eglkms -static $(kms_OBJECTS) $(common_OBJECTS)
+
+depend: 
+       rm -f depend
+       touch depend
+       $(MKDEP) $(MKDEP_OPTIONS) $(ALL_INCLUDES) $(ALL_SOURCES) 2> /dev/null
+
+clean:
+       rm -f $(ALL_OBJECTS)
+       rm -f $(EGL_DISPLAYS_MODS)
+       rm -f depend depend.bak
+
+# Dummy target
+install:
+       @echo -n ""
+
+##### RULES #####
+
+$(common_OBJECTS): %.o: %.c
+       $(CC) -c $(common_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
 
-C_SOURCES = $(wildcard ./*.c)
+$(x11_OBJECTS): %.o: %.c
+       $(CC) -c $(common_INCLUDES) $(x11_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
 
+$(kms_OBJECTS): %.o: %.c
+       $(CC) -c $(common_INCLUDES) $(kms_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
 
-include ../../Makefile.template
+sinclude depend
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
new file mode 100644 (file)
index 0000000..2ac6215
--- /dev/null
@@ -0,0 +1,1336 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <assert.h>
+#include <string.h>
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+#include "util/u_rect.h"
+#include "egldriver.h"
+#include "eglcurrent.h"
+#include "eglconfigutil.h"
+#include "egllog.h"
+
+#include "native.h"
+#include "egl_g3d.h"
+#include "egl_st.h"
+
+/**
+ * Validate the draw/read surfaces of the context.
+ */
+static void
+egl_g3d_validate_context(_EGLDisplay *dpy, _EGLContext *ctx)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct pipe_screen *screen = gdpy->native->screen;
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   const uint st_att_map[NUM_NATIVE_ATTACHMENTS] = {
+      ST_SURFACE_FRONT_LEFT,
+      ST_SURFACE_BACK_LEFT,
+      ST_SURFACE_FRONT_RIGHT,
+      ST_SURFACE_BACK_RIGHT,
+   };
+   EGLint num_surfaces, s;
+
+   /* validate draw and/or read buffers */
+   num_surfaces = (gctx->base.ReadSurface == gctx->base.DrawSurface) ? 1 : 2;
+   for (s = 0; s < num_surfaces; s++) {
+      struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+      struct egl_g3d_surface *gsurf;
+      struct egl_g3d_buffer *gbuf;
+      EGLint att;
+
+      if (s == 0) {
+         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
+         gbuf = &gctx->draw;
+      }
+      else {
+         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
+         gbuf = &gctx->read;
+      }
+
+      if (!gctx->force_validate) {
+         unsigned int seq_num;
+
+         gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
+               &seq_num, NULL, NULL, NULL);
+         /* skip validation */
+         if (gsurf->sequence_number == seq_num)
+            continue;
+      }
+
+      pipe_surface_reference(&gsurf->render_surface, NULL);
+      memset(textures, 0, sizeof(textures));
+
+      gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
+            &gsurf->sequence_number, textures,
+            &gsurf->base.Width, &gsurf->base.Height);
+      for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+         struct pipe_texture *pt = textures[att];
+         struct pipe_surface *ps;
+
+         if (native_attachment_mask_test(gbuf->attachment_mask, att) && pt) {
+            ps = screen->get_tex_surface(screen, pt, 0, 0, 0,
+                  PIPE_BUFFER_USAGE_GPU_READ |
+                  PIPE_BUFFER_USAGE_GPU_WRITE);
+            gctx->stapi->st_set_framebuffer_surface(gbuf->st_fb,
+                  st_att_map[att], ps);
+
+            if (gsurf->render_att == att)
+               pipe_surface_reference(&gsurf->render_surface, ps);
+
+            pipe_surface_reference(&ps, NULL);
+            pipe_texture_reference(&pt, NULL);
+         }
+      }
+
+      gctx->stapi->st_resize_framebuffer(gbuf->st_fb,
+            gsurf->base.Width, gsurf->base.Height);
+   }
+
+   gctx->force_validate = EGL_FALSE;
+
+}
+
+/**
+ * Create a st_framebuffer.
+ */
+static struct st_framebuffer *
+create_framebuffer(_EGLContext *ctx, _EGLSurface *surf)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
+
+   return gctx->stapi->st_create_framebuffer(&gconf->native->mode,
+         gconf->native->color_format, gconf->native->depth_format,
+         gconf->native->stencil_format,
+         gsurf->base.Width, gsurf->base.Height, &gsurf->base);
+}
+
+/**
+ * Update the attachments of draw/read surfaces.
+ */
+static void
+egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   EGLint s;
+
+   /* route draw and read buffers' attachments */
+   for (s = 0; s < 2; s++) {
+      struct egl_g3d_surface *gsurf;
+      struct egl_g3d_buffer *gbuf;
+
+      if (s == 0) {
+         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
+         gbuf = &gctx->draw;
+      }
+      else {
+         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
+         gbuf = &gctx->read;
+      }
+
+      gbuf->attachment_mask = (1 << gsurf->render_att);
+
+      /* FIXME OpenGL defaults to draw the front or back buffer when the
+       * context is single-buffered or double-buffered respectively.  In EGL,
+       * however, the buffer to be drawn is determined by the surface, instead
+       * of the context.  As a result, rendering to a pixmap surface with a
+       * double-buffered context does not work as expected.
+       *
+       * gctx->stapi->st_draw_front_buffer(gctx->st_ctx, natt ==
+       *    NATIVE_ATTACHMENT_FRONT_LEFT);
+       */
+
+      /*
+       * FIXME If the back buffer is asked for here, and the front buffer is
+       * later needed by the client API (e.g. glDrawBuffer is called to draw
+       * the front buffer), it will create a new pipe texture and draw there.
+       * One fix is to ask for both buffers here, but it would be a waste if
+       * the front buffer is never used.  A better fix is to add a callback to
+       * the pipe screen with context private (just like flush_frontbuffer).
+       */
+   }
+}
+
+/**
+ * Reallocate the context's framebuffers after draw/read surfaces change.
+ */
+static EGLBoolean
+egl_g3d_realloc_context(_EGLDisplay *dpy, _EGLContext *ctx)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   struct egl_g3d_surface *gdraw = egl_g3d_surface(gctx->base.DrawSurface);
+   struct egl_g3d_surface *gread = egl_g3d_surface(gctx->base.ReadSurface);
+
+   /* unreference the old framebuffers */
+   if (gctx->draw.st_fb) {
+      EGLBoolean is_equal = (gctx->draw.st_fb == gctx->read.st_fb);
+      void *priv;
+
+      priv = gctx->stapi->st_framebuffer_private(gctx->draw.st_fb);
+      if (!gdraw || priv != (void *) &gdraw->base) {
+         gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
+         gctx->draw.st_fb = NULL;
+         gctx->draw.attachment_mask = 0x0;
+      }
+
+      if (is_equal) {
+         gctx->read.st_fb = NULL;
+         gctx->draw.attachment_mask = 0x0;
+      }
+      else {
+         priv = gctx->stapi->st_framebuffer_private(gctx->read.st_fb);
+         if (!gread || priv != (void *) &gread->base) {
+            gctx->stapi->st_unreference_framebuffer(gctx->read.st_fb);
+            gctx->read.st_fb = NULL;
+            gctx->draw.attachment_mask = 0x0;
+         }
+      }
+   }
+
+   if (!gdraw)
+      return EGL_TRUE;
+
+   /* create the draw fb */
+   if (!gctx->draw.st_fb) {
+      gctx->draw.st_fb = create_framebuffer(&gctx->base, &gdraw->base);
+      if (!gctx->draw.st_fb)
+         return EGL_FALSE;
+   }
+
+   /* create the read fb */
+   if (!gctx->read.st_fb) {
+      if (gread != gdraw) {
+         gctx->read.st_fb = create_framebuffer(&gctx->base, &gread->base);
+         if (!gctx->read.st_fb) {
+            gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
+            gctx->draw.st_fb = NULL;
+            return EGL_FALSE;
+         }
+      }
+      else {
+         /* there is no st_reference_framebuffer... */
+         gctx->read.st_fb = gctx->draw.st_fb;
+      }
+   }
+
+   egl_g3d_route_context(dpy, &gctx->base);
+   gctx->force_validate = EGL_TRUE;
+
+   return EGL_TRUE;
+}
+
+/**
+ * Return the current context of the given API.
+ */
+static struct egl_g3d_context *
+egl_g3d_get_current_context(EGLint api)
+{
+   _EGLThreadInfo *t = _eglGetCurrentThread();
+   EGLint api_index = _eglConvertApiToIndex(api);
+   return egl_g3d_context(t->CurrentContexts[api_index]);
+}
+
+/**
+ * Return the state tracker for the given context.
+ */
+static const struct egl_g3d_st *
+egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   const struct egl_g3d_st *stapi;
+   EGLint idx = -1;
+
+   switch (ctx->ClientAPI) {
+   case EGL_OPENGL_ES_API:
+      switch (ctx->ClientVersion) {
+      case 1:
+         idx = EGL_G3D_ST_OPENGL_ES;
+         break;
+      case 2:
+         idx = EGL_G3D_ST_OPENGL_ES2;
+         break;
+      default:
+         _eglLog(_EGL_WARNING, "unknown client version %d",
+               ctx->ClientVersion);
+         break;
+      }
+      break;
+   case EGL_OPENVG_API:
+      idx = EGL_G3D_ST_OPENVG;
+      break;
+   case EGL_OPENGL_API:
+      idx = EGL_G3D_ST_OPENGL;
+      break;
+   default:
+      _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI);
+      break;
+   }
+
+   stapi = (idx >= 0) ? gdrv->stapis[idx] : NULL;
+   return stapi;
+}
+
+/**
+ * Initialize the state trackers.
+ */
+static void
+egl_g3d_init_st(_EGLDriver *drv)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   EGLint i;
+
+   /* already initialized */
+   if (gdrv->api_mask)
+      return;
+
+   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
+      gdrv->stapis[i] = egl_g3d_get_st(i);
+      if (gdrv->stapis[i])
+         gdrv->api_mask |= gdrv->stapis[i]->api_bit;
+   }
+
+   if (gdrv->api_mask)
+      _eglLog(_EGL_DEBUG, "Driver API mask: 0x%x", gdrv->api_mask);
+   else
+      _eglLog(_EGL_WARNING, "No supported client API");
+}
+
+/**
+ * Get the probe object of the display.
+ *
+ * Note that this function may be called before the display is initialized.
+ */
+static struct native_probe *
+egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   struct native_probe *nprobe;
+
+   nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
+   if (!nprobe || nprobe->display != dpy->NativeDisplay) {
+      if (nprobe)
+         nprobe->destroy(nprobe);
+      nprobe = native_create_probe(dpy->NativeDisplay);
+      _eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
+   }
+
+   return nprobe;
+}
+
+/**
+ * Destroy the probe object of the display.  The display may be NULL.
+ *
+ * Note that this function may be called before the display is initialized.
+ */
+static void
+egl_g3d_destroy_probe(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   struct native_probe *nprobe;
+
+   nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
+   if (nprobe && (!dpy || nprobe->display == dpy->NativeDisplay)) {
+      nprobe->destroy(nprobe);
+      _eglSetProbeCache(gdrv->probe_key, NULL);
+   }
+}
+
+/**
+ * Return an API mask that consists of the state trackers that supports the
+ * given mode.
+ *
+ * FIXME add st_is_mode_supported()?
+ */
+static EGLint
+get_mode_api_mask(const __GLcontextModes *mode, EGLint api_mask)
+{
+   EGLint check;
+
+   /* OpenGL ES 1.x and 2.x are checked together */
+   check = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT;
+   if (api_mask & check) {
+      /* this is required by EGL, not by OpenGL ES */
+      if (mode->drawableType & GLX_WINDOW_BIT && !mode->doubleBufferMode)
+         api_mask &= ~check;
+   }
+
+   check = EGL_OPENVG_BIT;
+   if (api_mask & check) {
+      /* vega st needs the depth/stencil rb */
+      if (!mode->depthBits && !mode->stencilBits)
+         api_mask &= ~check;
+   }
+
+   return api_mask;
+}
+
+#ifdef EGL_MESA_screen_surface
+
+static void
+egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   const struct native_connector **native_connectors;
+   EGLint num_connectors, i;
+
+   native_connectors =
+      gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL);
+   if (!num_connectors) {
+      if (native_connectors)
+         free(native_connectors);
+      return;
+   }
+
+   for (i = 0; i < num_connectors; i++) {
+      const struct native_connector *nconn = native_connectors[i];
+      struct egl_g3d_screen *gscr;
+      const struct native_mode **native_modes;
+      EGLint num_modes, j;
+
+      /* TODO support for hotplug */
+      native_modes =
+         gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes);
+      if (!num_modes) {
+         if (native_modes)
+            free(native_modes);
+         continue;
+      }
+
+      gscr = CALLOC_STRUCT(egl_g3d_screen);
+      if (!gscr) {
+         free(native_modes);
+         continue;
+      }
+
+      _eglInitScreen(&gscr->base);
+
+      for (j = 0; j < num_modes; j++) {
+         const struct native_mode *nmode = native_modes[j];
+         _EGLMode *mode;
+
+         mode = _eglAddNewMode(&gscr->base, nmode->width, nmode->height,
+               nmode->refresh_rate, nmode->desc);
+         if (!mode)
+            break;
+         /* gscr->native_modes and gscr->base.Modes should be consistent */
+         assert(mode == &gscr->base.Modes[j]);
+      }
+
+      gscr->native = nconn;
+      gscr->native_modes = native_modes;
+
+      _eglAddScreen(dpy, &gscr->base);
+   }
+
+   free(native_connectors);
+}
+
+#endif /* EGL_MESA_screen_surface */
+
+/**
+ * Add configs to display and return the next config ID.
+ */
+static EGLint
+egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   const struct native_config **native_configs;
+   int num_configs, i;
+
+   native_configs = gdpy->native->get_configs(gdpy->native,
+         &num_configs);
+   if (!num_configs) {
+      if (native_configs)
+         free(native_configs);
+      return id;
+   }
+
+   for (i = 0; i < num_configs; i++) {
+      EGLint api_mask;
+      struct egl_g3d_config *gconf;
+      EGLBoolean valid;
+
+      api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
+      if (!api_mask) {
+         _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x",
+               native_configs[i]->mode.visualID);
+         continue;
+      }
+
+      gconf = CALLOC_STRUCT(egl_g3d_config);
+      if (!gconf)
+         continue;
+
+      _eglInitConfig(&gconf->base, id);
+      valid = _eglConfigFromContextModesRec(&gconf->base,
+            &native_configs[i]->mode, api_mask, api_mask);
+      if (valid) {
+#ifdef EGL_MESA_screen_surface
+         /* check if scanout surface bit is set */
+         if (native_configs[i]->scanout_bit) {
+            EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE);
+            val |= EGL_SCREEN_BIT_MESA;
+            SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val);
+         }
+#endif
+         valid = _eglValidateConfig(&gconf->base, EGL_FALSE);
+      }
+      if (!valid) {
+         _eglLog(_EGL_DEBUG, "skip invalid config 0x%x",
+               native_configs[i]->mode.visualID);
+         free(gconf);
+         continue;
+      }
+
+      gconf->native = native_configs[i];
+      _eglAddConfig(dpy, &gconf->base);
+      id++;
+   }
+
+   free(native_configs);
+   return id;
+}
+
+/**
+ * Flush the front buffer of the context's draw surface.
+ */
+static void
+egl_g3d_flush_frontbuffer(struct pipe_screen *screen,
+                          struct pipe_surface *surf, void *context_private)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(gctx->base.DrawSurface);
+
+   if (gsurf)
+      gsurf->native->flush_frontbuffer(gsurf->native);
+}
+
+/**
+ * Re-validate the context.
+ */
+static void
+egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
+
+   /**
+    * It is likely that the surface has changed when this function is called.
+    * Set force_validate to skip an unnecessary check.
+    */
+   gctx->force_validate = EGL_TRUE;
+   egl_g3d_validate_context(gctx->base.Display, &gctx->base);
+}
+
+static EGLBoolean
+egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   EGLint i;
+
+   _eglReleaseDisplayResources(drv, dpy);
+   _eglCleanupDisplay(dpy);
+
+   if (dpy->Screens) {
+      for (i = 0; i < dpy->NumScreens; i++) {
+         struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]);
+         free(gscr->native_modes);
+         free(gscr);
+      }
+      free(dpy->Screens);
+   }
+
+   if (gdpy->native)
+      gdpy->native->destroy(gdpy->native);
+
+   free(gdpy);
+   dpy->DriverData = NULL;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
+                   EGLint *major, EGLint *minor)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   struct egl_g3d_display *gdpy;
+
+   /* the probe object is unlikely to be needed again */
+   egl_g3d_destroy_probe(drv, dpy);
+
+   gdpy = CALLOC_STRUCT(egl_g3d_display);
+   if (!gdpy) {
+      _eglError(EGL_BAD_ALLOC, "eglInitialize");
+      goto fail;
+   }
+   dpy->DriverData = gdpy;
+
+   gdpy->native = native_create_display(dpy->NativeDisplay);
+   if (!gdpy->native) {
+      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
+      goto fail;
+   }
+
+   gdpy->native->screen->flush_frontbuffer = egl_g3d_flush_frontbuffer;
+   gdpy->native->screen->update_buffer = egl_g3d_update_buffer;
+
+   egl_g3d_init_st(&gdrv->base);
+   dpy->ClientAPIsMask = gdrv->api_mask;
+
+   if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
+      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
+      goto fail;
+   }
+
+#ifdef EGL_MESA_screen_surface
+   /* enable MESA_screen_surface */
+   if (gdpy->native->modeset) {
+      dpy->Extensions.MESA_screen_surface = EGL_TRUE;
+      egl_g3d_add_screens(drv, dpy);
+   }
+#endif
+
+   *major = 1;
+   *minor = 4;
+
+   return EGL_TRUE;
+
+fail:
+   if (gdpy)
+      egl_g3d_terminate(drv, dpy);
+   return EGL_FALSE;
+}
+
+static _EGLContext *
+egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
+                       _EGLContext *share, const EGLint *attribs)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_context *gshare = egl_g3d_context(share);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_context *gctx;
+   const __GLcontextModes *mode;
+
+   gctx = CALLOC_STRUCT(egl_g3d_context);
+   if (!gctx) {
+      _eglError(EGL_BAD_ALLOC, "eglCreateContext");
+      return NULL;
+   }
+
+   if (!_eglInitContext(drv, &gctx->base, conf, attribs)) {
+      free(gctx);
+      return NULL;
+   }
+
+   gctx->stapi = egl_g3d_choose_st(drv, &gctx->base);
+   if (!gctx->stapi) {
+      free(gctx);
+      return NULL;
+   }
+
+   mode = &gconf->native->mode;
+   gctx->pipe =
+      gdpy->native->create_context(gdpy->native, (void *) &gctx->base);
+   if (!gctx->pipe) {
+      free(gctx);
+      return NULL;
+   }
+
+   gctx->st_ctx = gctx->stapi->st_create_context(gctx->pipe, mode,
+                        (gshare) ? gshare->st_ctx : NULL);
+   if (!gctx->st_ctx) {
+      gctx->pipe->destroy(gctx->pipe);
+      free(gctx);
+      return NULL;
+   }
+
+   return &gctx->base;
+}
+
+static EGLBoolean
+egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+
+   if (_eglIsContextBound(&gctx->base))
+      return EGL_TRUE;
+
+   egl_g3d_realloc_context(dpy, &gctx->base);
+
+   /* it will destroy pipe context */
+   gctx->stapi->st_destroy_context(gctx->st_ctx);
+
+   free(gctx);
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+init_surface_geometry(_EGLSurface *surf)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+
+   return gsurf->native->validate(gsurf->native, 0x0,
+         &gsurf->sequence_number, NULL,
+         &gsurf->base.Width, &gsurf->base.Height);
+}
+
+static _EGLSurface *
+egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+                              _EGLConfig *conf, EGLNativeWindowType win,
+                              const EGLint *attribs)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_surface *gsurf;
+
+   gsurf = CALLOC_STRUCT(egl_g3d_surface);
+   if (!gsurf) {
+      _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
+      return NULL;
+   }
+
+   if (!_eglInitSurface(drv, &gsurf->base, EGL_WINDOW_BIT, conf, attribs)) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->native =
+      gdpy->native->create_window_surface(gdpy->native, win, gconf->native);
+   if (!gsurf->native) {
+      free(gsurf);
+      return NULL;
+   }
+
+   if (!init_surface_geometry(&gsurf->base)) {
+      gsurf->native->destroy(gsurf->native);
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER ||
+                        !gconf->native->mode.doubleBufferMode) ?
+      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
+
+   return &gsurf->base;
+}
+
+static _EGLSurface *
+egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+                              _EGLConfig *conf, EGLNativePixmapType pix,
+                              const EGLint *attribs)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_surface *gsurf;
+
+   gsurf = CALLOC_STRUCT(egl_g3d_surface);
+   if (!gsurf) {
+      _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
+      return NULL;
+   }
+
+   if (!_eglInitSurface(drv, &gsurf->base, EGL_PIXMAP_BIT, conf, attribs)) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->native =
+      gdpy->native->create_pixmap_surface(gdpy->native, pix, gconf->native);
+   if (!gsurf->native) {
+      free(gsurf);
+      return NULL;
+   }
+
+   if (!init_surface_geometry(&gsurf->base)) {
+      gsurf->native->destroy(gsurf->native);
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+   return &gsurf->base;
+}
+
+static _EGLSurface *
+egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+                               _EGLConfig *conf, const EGLint *attribs)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_surface *gsurf;
+
+   gsurf = CALLOC_STRUCT(egl_g3d_surface);
+   if (!gsurf) {
+      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
+      return NULL;
+   }
+
+   if (!_eglInitSurface(drv, &gsurf->base, EGL_PBUFFER_BIT, conf, attribs)) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->native =
+      gdpy->native->create_pbuffer_surface(gdpy->native, gconf->native,
+            gsurf->base.Width, gsurf->base.Height);
+   if (!gsurf->native) {
+      free(gsurf);
+      return NULL;
+   }
+
+   if (!init_surface_geometry(&gsurf->base)) {
+      gsurf->native->destroy(gsurf->native);
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
+      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
+
+   return &gsurf->base;
+}
+
+static EGLBoolean
+egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+
+   if (_eglIsSurfaceBound(&gsurf->base))
+         return EGL_TRUE;
+
+   pipe_surface_reference(&gsurf->render_surface, NULL);
+   gsurf->native->destroy(gsurf->native);
+   free(gsurf);
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
+                     _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   struct egl_g3d_context *old_gctx;
+   EGLint api;
+   EGLBoolean ok = EGL_TRUE;
+
+   /* find the old context */
+   api = (gctx) ? gctx->base.ClientAPI : eglQueryAPI();
+   old_gctx = egl_g3d_get_current_context(api);
+   if (old_gctx && !_eglIsContextLinked(&old_gctx->base))
+         old_gctx = NULL;
+
+   if (!_eglMakeCurrent(drv, dpy, draw, read, ctx))
+      return EGL_FALSE;
+
+   if (old_gctx) {
+      /* flush old context */
+      old_gctx->stapi->st_flush(old_gctx->st_ctx,
+            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
+
+      /*
+       * The old context is no longer current, and egl_g3d_realloc_context()
+       * should be called to destroy the framebuffers.  However, it is possible
+       * that it will be made current again with the same draw/read surfaces.
+       * It might be better to keep it around.
+       */
+   }
+
+   if (gctx) {
+      struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
+
+      ok = egl_g3d_realloc_context(dpy, &gctx->base);
+      if (ok) {
+         ok = gctx->stapi->st_make_current(gctx->st_ctx,
+               gctx->draw.st_fb, gctx->read.st_fb);
+         if (ok) {
+            egl_g3d_validate_context(dpy, &gctx->base);
+            if (gdraw->base.Type == EGL_WINDOW_BIT) {
+               gctx->base.WindowRenderBuffer =
+                  (gdraw->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) ?
+                  EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
+            }
+         }
+      }
+   }
+   else if (old_gctx) {
+      ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL);
+      old_gctx->base.WindowRenderBuffer = EGL_NONE;
+   }
+
+   return ok;
+}
+
+static EGLBoolean
+egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct egl_g3d_context *gctx = NULL;
+
+   /* no-op for pixmap or pbuffer surface */
+   if (gsurf->base.Type == EGL_PIXMAP_BIT ||
+       gsurf->base.Type == EGL_PBUFFER_BIT)
+      return EGL_TRUE;
+
+   /* or when the surface is single-buffered */
+   if (gsurf->render_att == NATIVE_ATTACHMENT_FRONT_LEFT)
+      return EGL_TRUE;
+
+   if (ctx && ctx->DrawSurface == surf)
+      gctx = egl_g3d_context(ctx);
+
+   /* flush if the surface is current */
+   if (gctx)
+      gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb);
+
+   /*
+    * We drew on the back buffer, unless there was no back buffer.
+    * In that case, we drew on the front buffer.  Either case, we call
+    * swap_buffers.
+    */
+   if (!gsurf->native->swap_buffers(gsurf->native))
+      return EGL_FALSE;
+
+   if (gctx) {
+      struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
+
+      /* force validation if the swap method is not copy */
+      if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML) {
+         gctx->force_validate = EGL_TRUE;
+         egl_g3d_validate_context(dpy, &gctx->base);
+      }
+   }
+
+   return EGL_TRUE;
+}
+
+/**
+ * Find a config that supports the pixmap.
+ */
+static _EGLConfig *
+find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_config *gconf;
+   EGLint i;
+
+   for (i = 0; i < dpy->NumConfigs; i++) {
+      gconf = egl_g3d_config(dpy->Configs[i]);
+      if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native))
+         break;
+   }
+
+   return (i < dpy->NumConfigs) ? &gconf->base : NULL;
+}
+
+/**
+ * Get the pipe surface of the given attachment of the native surface.
+ */
+static struct pipe_surface *
+get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
+                 enum native_attachment natt)
+{
+   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+   struct pipe_surface *psurf;
+
+   textures[natt] = NULL;
+   nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL);
+   if (!textures[natt])
+      return NULL;
+
+   psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt],
+         0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE);
+   pipe_texture_reference(&textures[natt], NULL);
+
+   return psurf;
+}
+
+static EGLBoolean
+egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
+                     NativePixmapType target)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct egl_g3d_config *gconf;
+   struct native_surface *nsurf;
+   struct pipe_screen *screen = gdpy->native->screen;
+   struct pipe_surface *psurf;
+
+   if (!gsurf->render_surface)
+      return EGL_TRUE;
+
+   gconf = egl_g3d_config(find_pixmap_config(dpy, target));
+   if (!gconf)
+      return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
+
+   nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
+         target, gconf->native);
+   if (!nsurf)
+      return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
+
+   /* flush if the surface is current */
+   if (ctx && ctx->DrawSurface == &gsurf->base) {
+      struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+      gctx->stapi->st_flush(gctx->st_ctx,
+            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
+   }
+
+   psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+   if (psurf) {
+      struct pipe_context pipe;
+
+      /**
+       * XXX This is hacky.  If we might allow the EGLDisplay to create a pipe
+       * context of its own and use the blitter context for this.
+       */
+      memset(&pipe, 0, sizeof(pipe));
+      pipe.screen = screen;
+
+      util_surface_copy(&pipe, FALSE, psurf, 0, 0,
+            gsurf->render_surface, 0, 0, psurf->width, psurf->height);
+
+      pipe_surface_reference(&psurf, NULL);
+      nsurf->flush_frontbuffer(nsurf);
+   }
+
+   nsurf->destroy(nsurf);
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
+{
+   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   gctx->stapi->st_finish(gctx->st_ctx);
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
+{
+   _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW);
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+
+   if (engine != EGL_CORE_NATIVE_ENGINE)
+      return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
+
+   if (gsurf)
+      gsurf->native->wait(gsurf->native);
+
+   return EGL_TRUE;
+}
+
+static _EGLProc
+egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   _EGLProc proc;
+   EGLint i;
+
+   /* in case this is called before a display is initialized */
+   egl_g3d_init_st(&gdrv->base);
+
+   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
+      const struct egl_g3d_st *stapi = gdrv->stapis[i];
+      if (stapi) {
+         proc = (_EGLProc) stapi->st_get_proc_address(procname);
+         if (proc)
+            return proc;
+      }
+   }
+
+   return (_EGLProc) NULL;
+}
+
+static EGLBoolean
+egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
+                       _EGLSurface *surf, EGLint buffer)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct egl_g3d_context *gctx;
+   enum pipe_format target_format;
+   int target;
+
+   if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT)
+      return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
+   if (buffer != EGL_BACK_BUFFER)
+      return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage");
+   if (gsurf->base.BoundToTexture)
+      return _eglError(EGL_BAD_ACCESS, "eglBindTexImage");
+
+   switch (gsurf->base.TextureFormat) {
+   case EGL_TEXTURE_RGB:
+      target_format = PIPE_FORMAT_R8G8B8_UNORM;
+      break;
+   case EGL_TEXTURE_RGBA:
+      target_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+      break;
+   default:
+      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
+   }
+
+   switch (gsurf->base.TextureTarget) {
+   case EGL_TEXTURE_2D:
+      target = ST_TEXTURE_2D;
+      break;
+   default:
+      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
+   }
+
+   /* flush properly if the surface is bound */
+   if (gsurf->base.Binding) {
+      gctx = egl_g3d_context(gsurf->base.Binding);
+      gctx->stapi->st_flush(gctx->st_ctx,
+            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
+   }
+
+   /* XXX change to EGL_OPENGL_ES_API once OpenGL ES is merged */
+   gctx = egl_g3d_get_current_context(EGL_OPENGL_API);
+   if (gctx) {
+      if (!gsurf->render_surface)
+         return EGL_FALSE;
+
+      gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
+            target, gsurf->base.MipmapLevel, target_format);
+      gsurf->base.BoundToTexture = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
+                          _EGLSurface *surf, EGLint buffer)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+
+   if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT ||
+       !gsurf->base.BoundToTexture)
+      return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
+   if (buffer != EGL_BACK_BUFFER)
+      return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage");
+
+   if (gsurf->render_surface) {
+      _EGLThreadInfo *t = _eglGetCurrentThread();
+      /* XXX change to EGL_OPENGL_ES_API once OpenGL ES is merged */
+      struct egl_g3d_context *gctx = egl_g3d_context(
+            t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_API)]);
+
+      /* what if the context the surface binds to is no longer current? */
+      if (gctx)
+         gctx->stapi->st_unbind_texture_surface(gsurf->render_surface,
+               ST_TEXTURE_2D, gsurf->base.MipmapLevel);
+   }
+
+   gsurf->base.BoundToTexture = EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+#ifdef EGL_MESA_screen_surface
+
+static _EGLSurface *
+egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+                              _EGLConfig *conf, const EGLint *attribs)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_surface *gsurf;
+
+   gsurf = CALLOC_STRUCT(egl_g3d_surface);
+   if (!gsurf) {
+      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
+      return NULL;
+   }
+
+   if (!_eglInitSurface(drv, &gsurf->base,
+            EGL_SCREEN_BIT_MESA, conf, attribs)) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->native =
+      gdpy->native->modeset->create_scanout_surface(gdpy->native,
+            gconf->native, gsurf->base.Width, gsurf->base.Height);
+   if (!gsurf->native) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
+      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
+
+   return &gsurf->base;
+}
+
+static EGLBoolean
+egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+                            _EGLScreen *scr, _EGLSurface *surf,
+                            _EGLMode *mode)
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct egl_g3d_screen *gscr = egl_g3d_screen(scr);
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct native_surface *nsurf;
+   const struct native_mode *nmode;
+   EGLBoolean changed;
+
+   if (gsurf) {
+      EGLint idx;
+
+      if (!mode)
+         return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
+      if (gsurf->base.Type != EGL_SCREEN_BIT_MESA)
+         return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA");
+      if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height)
+         return _eglError(EGL_BAD_MATCH,
+               "eglShowSurfaceMESA(surface smaller than mode size)");
+
+      /* find the index of the mode */
+      for (idx = 0; idx < gscr->base.NumModes; idx++)
+         if (mode == &gscr->base.Modes[idx])
+            break;
+      if (idx >= gscr->base.NumModes) {
+         return _eglError(EGL_BAD_MODE_MESA,
+               "eglShowSurfaceMESA(unknown mode)");
+      }
+
+      nsurf = gsurf->native;
+      nmode = gscr->native_modes[idx];
+   }
+   else {
+      if (mode)
+         return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
+
+      /* disable the screen */
+      nsurf = NULL;
+      nmode = NULL;
+   }
+
+   /* TODO surface panning by CRTC choosing */
+   changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf,
+         gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode);
+   if (changed) {
+      gscr->base.CurrentSurface = &gsurf->base;
+      gscr->base.CurrentMode = mode;
+   }
+
+   return changed;
+}
+
+#endif /* EGL_MESA_screen_surface */
+
+static EGLint
+egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+   struct native_probe *nprobe;
+   enum native_probe_result res;
+   EGLint score;
+
+   nprobe = egl_g3d_get_probe(drv, dpy);
+   res = native_get_probe_result(nprobe);
+
+   switch (res) {
+   case NATIVE_PROBE_UNKNOWN:
+   default:
+      score = 0;
+      break;
+   case NATIVE_PROBE_FALLBACK:
+      score = 40;
+      break;
+   case NATIVE_PROBE_SUPPORTED:
+      score = 50;
+      break;
+   case NATIVE_PROBE_EXACT:
+      score = 100;
+      break;
+   }
+
+   return score;
+}
+
+static void
+egl_g3d_unload(_EGLDriver *drv)
+{
+   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+
+   egl_g3d_destroy_probe(drv, NULL);
+   free(gdrv);
+}
+
+_EGLDriver *
+_eglMain(const char *args)
+{
+   static char driver_name[64];
+   struct egl_g3d_driver *gdrv;
+
+   snprintf(driver_name, sizeof(driver_name),
+         "Gallium/%s", native_get_name());
+
+   gdrv = CALLOC_STRUCT(egl_g3d_driver);
+   if (!gdrv)
+      return NULL;
+
+   _eglInitDriverFallbacks(&gdrv->base);
+
+   gdrv->base.API.Initialize = egl_g3d_initialize;
+   gdrv->base.API.Terminate = egl_g3d_terminate;
+   gdrv->base.API.CreateContext = egl_g3d_create_context;
+   gdrv->base.API.DestroyContext = egl_g3d_destroy_context;
+   gdrv->base.API.CreateWindowSurface = egl_g3d_create_window_surface;
+   gdrv->base.API.CreatePixmapSurface = egl_g3d_create_pixmap_surface;
+   gdrv->base.API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface;
+   gdrv->base.API.DestroySurface = egl_g3d_destroy_surface;
+   gdrv->base.API.MakeCurrent = egl_g3d_make_current;
+   gdrv->base.API.SwapBuffers = egl_g3d_swap_buffers;
+   gdrv->base.API.CopyBuffers = egl_g3d_copy_buffers;
+   gdrv->base.API.WaitClient = egl_g3d_wait_client;
+   gdrv->base.API.WaitNative = egl_g3d_wait_native;
+   gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
+
+   gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image;
+   gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image;
+
+#ifdef EGL_MESA_screen_surface
+   gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface;
+   gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface;
+#endif
+
+   gdrv->base.Name = driver_name;
+   gdrv->base.Probe = egl_g3d_probe;
+   gdrv->base.Unload = egl_g3d_unload;
+
+   /* the key is " EGL G3D" */
+   gdrv->probe_key = 0x0E61063D;
+
+   return &gdrv->base;
+}
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h
new file mode 100644 (file)
index 0000000..3dae8c4
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _EGL_G3D_H_
+#define _EGL_G3D_H_
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
+#include "pipe/p_format.h"
+#include "egldriver.h"
+#include "egldisplay.h"
+#include "eglcontext.h"
+#include "eglsurface.h"
+#include "eglconfig.h"
+#include "eglscreen.h"
+#include "eglmode.h"
+
+#include "native.h"
+#include "egl_st.h"
+
+struct egl_g3d_driver {
+   _EGLDriver base;
+   const struct egl_g3d_st *stapis[NUM_EGL_G3D_STS];
+   EGLint api_mask;
+
+   EGLint probe_key;
+};
+
+struct egl_g3d_display {
+   struct native_display *native;
+};
+
+struct egl_g3d_buffer {
+   struct st_framebuffer *st_fb;
+   uint attachment_mask;
+};
+
+struct egl_g3d_context {
+   _EGLContext base;
+
+   const struct egl_g3d_st *stapi;
+   struct pipe_context *pipe;
+
+   struct st_context *st_ctx;
+   EGLBoolean force_validate;
+   struct egl_g3d_buffer draw, read;
+};
+
+struct egl_g3d_surface {
+   _EGLSurface base;
+   struct native_surface *native;
+   enum native_attachment render_att;
+   struct pipe_surface *render_surface;
+   unsigned int sequence_number;
+};
+
+struct egl_g3d_config {
+   _EGLConfig base;
+   const struct native_config *native;
+};
+
+struct egl_g3d_screen {
+   _EGLScreen base;
+   const struct native_connector *native;
+   const struct native_mode **native_modes;
+};
+
+static INLINE struct egl_g3d_driver *
+egl_g3d_driver(_EGLDriver *drv)
+{
+   return (struct egl_g3d_driver *) drv;
+}
+
+static INLINE struct egl_g3d_display *
+egl_g3d_display(_EGLDisplay *dpy)
+{
+   /* note that it is not direct casting */
+   return (struct egl_g3d_display *) dpy->DriverData;
+}
+
+static INLINE struct egl_g3d_context *
+egl_g3d_context(_EGLContext *ctx)
+{
+   return (struct egl_g3d_context *) ctx;
+}
+
+static INLINE struct egl_g3d_surface *
+egl_g3d_surface(_EGLSurface *surf)
+{
+   return (struct egl_g3d_surface *) surf;
+}
+
+static INLINE struct egl_g3d_config *
+egl_g3d_config(_EGLConfig *conf)
+{
+   return (struct egl_g3d_config *) conf;
+}
+
+static INLINE struct egl_g3d_screen *
+egl_g3d_screen(_EGLScreen *scr)
+{
+   return (struct egl_g3d_screen *) scr;
+}
+
+#endif /* _EGL_G3D_H_ */
diff --git a/src/gallium/state_trackers/egl/common/egl_st.c b/src/gallium/state_trackers/egl/common/egl_st.c
new file mode 100644 (file)
index 0000000..a88ff91
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <dlfcn.h>
+#include "pipe/p_compiler.h"
+#include "util/u_memory.h"
+#include "egllog.h"
+#include "EGL/egl.h" /* for EGL_api_BIT */
+
+#include "egl_st.h"
+
+#ifndef HAVE_DLADDR
+#define HAVE_DLADDR 1
+#endif
+
+#if HAVE_DLADDR
+
+static const char *
+egl_g3d_st_names[] = {
+#define ST_PUBLIC(name, ...) #name,
+#include "st_public_tmp.h"
+   NULL
+};
+
+static boolean
+egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
+{
+   st_proc *procs = (st_proc *) stapi;
+   void *handle;
+   Dl_info info;
+   const char **name;
+
+   if (!dladdr(sym, &info))
+      return FALSE;
+   handle = dlopen(info.dli_fname, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
+   if (!handle)
+      return FALSE;
+
+   for (name = egl_g3d_st_names; *name; name++) {
+      st_proc proc = (st_proc) dlsym(handle, *name);
+      if (!proc) {
+         _eglLog(_EGL_WARNING, "%s is missing in %s", *name, info.dli_fname);
+         memset(stapi, 0, sizeof(*stapi));
+         dlclose(handle);
+         return FALSE;
+      }
+      *procs++ = proc;
+   }
+
+   dlclose(handle);
+   return TRUE;
+}
+
+#else /* HAVE_DLADDR */
+
+static boolean
+egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
+{
+#define ST_PUBLIC(name, ...) stapi->name = name;
+#include "st_public_tmp.h"
+   return TRUE;
+}
+
+#endif /* HAVE_DLADDR */
+
+static boolean
+egl_g3d_init_st(struct egl_g3d_st *stapi, const char *api)
+{
+   void *handle, *sym;
+   boolean res = FALSE;
+
+   /* already initialized */
+   if (stapi->st_notify_swapbuffers != NULL)
+      return TRUE;
+
+   handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
+   if (!handle)
+      return FALSE;
+
+   sym = dlsym(handle, api);
+   if (sym && egl_g3d_fill_st(stapi, sym))
+      res = TRUE;
+
+   dlclose(handle);
+   return res;
+}
+
+static struct {
+   const char *symbol;
+   EGLint api_bit;
+} egl_g3d_st_info[NUM_EGL_G3D_STS] = {
+   { "st_api_OpenGL_ES1",  EGL_OPENGL_ES_BIT },
+   { "st_api_OpenVG",      EGL_OPENVG_BIT },
+   { "st_api_OpenGL_ES2",  EGL_OPENGL_ES2_BIT },
+   { "st_api_OpenGL",      EGL_OPENGL_BIT },
+};
+
+const struct egl_g3d_st *
+egl_g3d_get_st(enum egl_g3d_st_api api)
+{
+   static struct egl_g3d_st all_trackers[NUM_EGL_G3D_STS];
+
+   if (egl_g3d_init_st(&all_trackers[api], egl_g3d_st_info[api].symbol)) {
+      all_trackers[api].api_bit = egl_g3d_st_info[api].api_bit;
+      return &all_trackers[api];
+   }
+   else {
+      return NULL;
+   }
+}
diff --git a/src/gallium/state_trackers/egl/common/egl_st.h b/src/gallium/state_trackers/egl/common/egl_st.h
new file mode 100644 (file)
index 0000000..8fb464b
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _EGL_ST_H_
+#define _EGL_ST_H_
+
+#include "GL/gl.h" /* for GL types */
+#include "GL/internal/glcore.h"  /* for __GLcontextModes */
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_format.h"
+#include "pipe/p_context.h"
+
+/* avoid calling st functions directly */
+#if 1
+
+#define ST_SURFACE_FRONT_LEFT   0
+#define ST_SURFACE_BACK_LEFT    1
+#define ST_SURFACE_FRONT_RIGHT  2
+#define ST_SURFACE_BACK_RIGHT   3
+
+#define ST_TEXTURE_2D    0x2
+
+struct st_context;
+struct st_framebuffer;
+typedef void (*st_proc)();
+
+#else
+#include "state_tracker/st_public.h"
+#endif
+
+/* remember to update egl_g3d_get_st() when update the enums */
+enum egl_g3d_st_api {
+   EGL_G3D_ST_OPENGL_ES = 0,
+   EGL_G3D_ST_OPENVG,
+   EGL_G3D_ST_OPENGL_ES2,
+   EGL_G3D_ST_OPENGL,
+
+   NUM_EGL_G3D_STS
+};
+
+struct egl_g3d_st {
+#define ST_PUBLIC(name, ret, ...) ret (*name)(__VA_ARGS__);
+#include "st_public_tmp.h"
+   /* fields must be added here */
+   EGLint api_bit;
+};
+
+const struct egl_g3d_st *
+egl_g3d_get_st(enum egl_g3d_st_api api);
+
+#endif /* _EGL_ST_H_ */
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
new file mode 100644 (file)
index 0000000..72a9cec
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _NATIVE_H_
+#define _NATIVE_H_
+
+#include "EGL/egl.h"  /* for EGL native types */
+#include "GL/gl.h" /* for GL types needed by __GLcontextModes */
+#include "GL/internal/glcore.h"  /* for __GLcontextModes */
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+
+/**
+ * Only color buffers are listed.  The others are allocated privately through,
+ * for example, st_renderbuffer_alloc_storage().
+ */
+enum native_attachment {
+   NATIVE_ATTACHMENT_FRONT_LEFT,
+   NATIVE_ATTACHMENT_BACK_LEFT,
+   NATIVE_ATTACHMENT_FRONT_RIGHT,
+   NATIVE_ATTACHMENT_BACK_RIGHT,
+
+   NUM_NATIVE_ATTACHMENTS
+};
+
+/**
+ * Enumerations for probe results.
+ */
+enum native_probe_result {
+   NATIVE_PROBE_UNKNOWN,
+   NATIVE_PROBE_FALLBACK,
+   NATIVE_PROBE_SUPPORTED,
+   NATIVE_PROBE_EXACT,
+};
+
+/**
+ * A probe object for display probe.
+ */
+struct native_probe {
+   int magic;
+   EGLNativeDisplayType display;
+   void *data;
+
+   void (*destroy)(struct native_probe *nprobe);
+};
+
+struct native_surface {
+   void (*destroy)(struct native_surface *nsurf);
+
+   /**
+    * Swap the front and back buffers so that the back buffer is visible.  It
+    * is no-op if the surface is single-buffered.  The contents of the back
+    * buffer after swapping may or may not be preserved.
+    */
+   boolean (*swap_buffers)(struct native_surface *nsurf);
+
+   /**
+    * Make the front buffer visible.  In some native displays, changes to the
+    * front buffer might not be visible immediately and require manual flush.
+    */
+   boolean (*flush_frontbuffer)(struct native_surface *nsurf);
+
+   /**
+    * Validate the buffers of the surface.  textures, if not NULL, points to an
+    * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
+    * by the caller.  A sequence number is also returned.  The caller can use
+    * it to check if anything has changed since the last call. Any of the
+    * pointers may be NULL and it indicates the caller has no interest in those
+    * values.
+    *
+    * If this function is called multiple times with different attachment
+    * masks, those not listed in the latest call might be destroyed.  This
+    * behavior might change in the future.
+    */
+   boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
+                       unsigned int *seq_num, struct pipe_texture **textures,
+                       int *width, int *height);
+
+   /**
+    * Wait until all native commands affecting the surface has been executed.
+    */
+   void (*wait)(struct native_surface *nsurf);
+};
+
+struct native_config {
+   /* __GLcontextModes should go away some day */
+   __GLcontextModes mode;
+   enum pipe_format color_format;
+   enum pipe_format depth_format;
+   enum pipe_format stencil_format;
+
+   /* treat it as an additional flag to mode.drawableType */
+   boolean scanout_bit;
+};
+
+struct native_connector {
+   int dummy;
+};
+
+struct native_mode {
+   const char *desc;
+   int width, height;
+   int refresh_rate;
+};
+
+struct native_display_modeset;
+
+/**
+ * A pipe winsys abstracts the OS.  A pipe screen abstracts the graphcis
+ * hardware.  A native display consists of a pipe winsys, a pipe screen, and
+ * the native display server.
+ */
+struct native_display {
+   /**
+    * The pipe screen of the native display.
+    *
+    * Note that the "flush_frontbuffer" and "update_buffer" callbacks will be
+    * overridden.
+    */
+   struct pipe_screen *screen;
+
+   void (*destroy)(struct native_display *ndpy);
+
+   /**
+    * Get the supported configs.  The configs are owned by the display, but
+    * the returned array should be free()ed.
+    *
+    * The configs will be converted to EGL config by
+    * _eglConfigFromContextModesRec and validated by _eglValidateConfig.
+    * Those failing to pass the test will be skipped.
+    */
+   const struct native_config **(*get_configs)(struct native_display *ndpy,
+                                               int *num_configs);
+
+   /**
+    * Test if a pixmap is supported by the given config.  Required unless no
+    * config has GLX_PIXMAP_BIT set.
+    *
+    * This function is usually called to find a config that supports a given
+    * pixmap.  Thus, it is usually called with the same pixmap in a row.
+    */
+   boolean (*is_pixmap_supported)(struct native_display *ndpy,
+                                  EGLNativePixmapType pix,
+                                  const struct native_config *nconf);
+
+   /**
+    * Create a pipe context.
+    */
+   struct pipe_context *(*create_context)(struct native_display *ndpy,
+                                          void *context_private);
+
+   /**
+    * Create a window surface.  Required unless no config has GLX_WINDOW_BIT
+    * set.
+    */
+   struct native_surface *(*create_window_surface)(struct native_display *ndpy,
+                                                   EGLNativeWindowType win,
+                                                   const struct native_config *nconf);
+
+   /**
+    * Create a pixmap surface.  Required unless no config has GLX_PIXMAP_BIT
+    * set.
+    */
+   struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
+                                                   EGLNativePixmapType pix,
+                                                   const struct native_config *nconf);
+
+   /**
+    * Create a pbuffer surface.  Required unless no config has GLX_PBUFFER_BIT
+    * set.
+    */
+   struct native_surface *(*create_pbuffer_surface)(struct native_display *ndpy,
+                                                    const struct native_config *nconf,
+                                                    uint width, uint height);
+
+   const struct native_display_modeset *modeset;
+};
+
+/**
+ * Mode setting interface of the native display.  It exposes the mode setting
+ * capabilities of the underlying graphics hardware.
+ */
+struct native_display_modeset {
+   /**
+    * Get the available physical connectors and the number of CRTCs.
+    */
+   const struct native_connector **(*get_connectors)(struct native_display *ndpy,
+                                                     int *num_connectors,
+                                                     int *num_crtcs);
+
+   /**
+    * Get the current supported modes of a connector.  The returned modes may
+    * change every time this function is called and those from previous calls
+    * might become invalid.
+    */
+   const struct native_mode **(*get_modes)(struct native_display *ndpy,
+                                           const struct native_connector *nconn,
+                                           int *num_modes);
+
+   /**
+    * Create a scan-out surface.  Required unless no config has
+    * GLX_SCREEN_BIT_MESA set.
+    */
+   struct native_surface *(*create_scanout_surface)(struct native_display *ndpy,
+                                                    const struct native_config *nconf,
+                                                    uint width, uint height);
+
+   /**
+    * Program the CRTC to output the surface to the given connectors with the
+    * given mode.  When surface is not given, the CRTC is disabled.
+    *
+    * This interface does not export a way to query capabilities of the CRTCs.
+    * The native display usually needs to dynamically map the index to a CRTC
+    * that supports the given connectors.
+    */
+   boolean (*program)(struct native_display *ndpy, int crtc_idx,
+                      struct native_surface *nsurf, uint x, uint y,
+                      const struct native_connector **nconns, int num_nconns,
+                      const struct native_mode *nmode);
+};
+
+/**
+ * Test whether an attachment is set in the mask.
+ */
+static INLINE boolean
+native_attachment_mask_test(uint mask, enum native_attachment att)
+{
+   return !!(mask & (1 << att));
+}
+
+/**
+ * Return a probe object for the given display.
+ *
+ * Note that the returned object may be cached and used by different native
+ * display modules.  It allows fast probing when multiple modules probe the
+ * same display.
+ */
+struct native_probe *
+native_create_probe(EGLNativeDisplayType dpy);
+
+/**
+ * Probe the probe object.
+ */
+enum native_probe_result
+native_get_probe_result(struct native_probe *nprobe);
+
+const char *
+native_get_name(void);
+
+struct native_display *
+native_create_display(EGLNativeDisplayType dpy);
+
+#endif /* _NATIVE_H_ */
diff --git a/src/gallium/state_trackers/egl/common/st_public_tmp.h b/src/gallium/state_trackers/egl/common/st_public_tmp.h
new file mode 100644 (file)
index 0000000..507a0ec
--- /dev/null
@@ -0,0 +1,20 @@
+ST_PUBLIC(st_create_context,              struct st_context *,       struct pipe_context *pipe, const __GLcontextModes *visual, struct st_context *share)
+ST_PUBLIC(st_destroy_context,             void,                      struct st_context *st)
+ST_PUBLIC(st_copy_context_state,          void,                      struct st_context *dst, struct st_context *src, uint mask)
+ST_PUBLIC(st_create_framebuffer,          struct st_framebuffer *,   const __GLcontextModes *visual, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, uint width, uint height, void *privateData)
+ST_PUBLIC(st_resize_framebuffer,          void,                      struct st_framebuffer *stfb, uint width, uint height)
+ST_PUBLIC(st_set_framebuffer_surface,     void,                      struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface *surf)
+ST_PUBLIC(st_get_framebuffer_dimensions,  void,                      struct st_framebuffer *stfb, uint *width, uint *height)
+ST_PUBLIC(st_get_framebuffer_surface,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface **surface)
+ST_PUBLIC(st_get_framebuffer_texture,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture)
+ST_PUBLIC(st_framebuffer_private,         void *,                    struct st_framebuffer *stfb)
+ST_PUBLIC(st_unreference_framebuffer,     void,                      struct st_framebuffer *stfb)
+ST_PUBLIC(st_make_current,                GLboolean,                 struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read)
+ST_PUBLIC(st_get_current,                 struct st_context *,       void)
+ST_PUBLIC(st_flush,                       void,                      struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence)
+ST_PUBLIC(st_finish,                      void,                      struct st_context *st)
+ST_PUBLIC(st_notify_swapbuffers,          void,                      struct st_framebuffer *stfb)
+ST_PUBLIC(st_bind_texture_surface,        int,                       struct pipe_surface *ps, int target, int level, enum pipe_format format)
+ST_PUBLIC(st_unbind_texture_surface,      int,                       struct pipe_surface *ps, int target, int level)
+ST_PUBLIC(st_get_proc_address,            st_proc,                   const char *procname)
+#undef ST_PUBLIC
diff --git a/src/gallium/state_trackers/egl/egl_context.c b/src/gallium/state_trackers/egl/egl_context.c
deleted file mode 100644 (file)
index fee186c..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-
-#include "utils.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "egl_tracker.h"
-
-#include "egllog.h"
-
-
-#include "pipe/p_context.h"
-#include "pipe/p_screen.h"
-
-#include "state_tracker/st_public.h"
-#include "state_tracker/drm_api.h"
-
-#include "GL/internal/glcore.h"
-
-_EGLContext *
-drm_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       struct drm_context *ctx;
-       struct drm_context *share = NULL;
-       struct st_context *st_share = NULL;
-       int i;
-       __GLcontextModes *visual;
-
-       for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-               switch (attrib_list[i]) {
-                       /* no attribs defined for now */
-                       default:
-                               _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext");
-                               return EGL_NO_CONTEXT;
-               }
-       }
-
-       ctx = (struct drm_context *) calloc(1, sizeof(struct drm_context));
-       if (!ctx)
-               goto err_c;
-
-       _eglInitContext(drv, &ctx->base, conf, attrib_list);
-
-       ctx->pipe = dev->api->create_context(dev->api, dev->screen);
-       if (!ctx->pipe)
-               goto err_pipe;
-
-       if (share)
-               st_share = share->st;
-
-       visual = drm_visual_from_config(conf);
-       ctx->st = st_create_context(ctx->pipe, visual, st_share);
-       drm_visual_modes_destroy(visual);
-
-       if (!ctx->st)
-               goto err_gl;
-
-       return &ctx->base;
-
-err_gl:
-       ctx->pipe->destroy(ctx->pipe);
-err_pipe:
-       free(ctx);
-err_c:
-       return NULL;
-}
-
-EGLBoolean
-drm_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context)
-{
-       struct drm_context *c = lookup_drm_context(context);
-       if (!_eglIsContextBound(&c->base)) {
-               st_destroy_context(c->st);
-               free(c);
-       }
-       return EGL_TRUE;
-}
-
-EGLBoolean
-drm_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *context)
-{
-       struct drm_surface *readSurf = lookup_drm_surface(read);
-       struct drm_surface *drawSurf = lookup_drm_surface(draw);
-       struct drm_context *ctx = lookup_drm_context(context);
-       EGLBoolean b;
-
-       b = _eglMakeCurrent(drv, dpy, draw, read, context);
-       if (!b)
-               return EGL_FALSE;
-
-       if (ctx) {
-               if (!drawSurf || !readSurf)
-                       return EGL_FALSE;
-
-               st_make_current(ctx->st, drawSurf->stfb, readSurf->stfb);
-
-               /* st_resize_framebuffer needs a bound context to work */
-               st_resize_framebuffer(drawSurf->stfb, drawSurf->w, drawSurf->h);
-               st_resize_framebuffer(readSurf->stfb, readSurf->w, readSurf->h);
-       } else {
-               st_make_current(NULL, NULL, NULL);
-       }
-
-       return EGL_TRUE;
-}
diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c
deleted file mode 100644 (file)
index d55aa51..0000000
+++ /dev/null
@@ -1,443 +0,0 @@
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "egl_tracker.h"
-
-#include "egllog.h"
-
-#include "pipe/p_inlines.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_context.h"
-
-#include "state_tracker/drm_api.h"
-
-#include "util/u_format.h"
-#include "util/u_rect.h"
-
-/*
- * Util functions
- */
-
-static drmModeModeInfoPtr
-drm_find_mode(drmModeConnectorPtr connector, _EGLMode *mode)
-{
-       int i;
-       drmModeModeInfoPtr m = NULL;
-
-       for (i = 0; i < connector->count_modes; i++) {
-               m = &connector->modes[i];
-               if (m->hdisplay == mode->Width && m->vdisplay == mode->Height && m->vrefresh == mode->RefreshRate)
-                       break;
-               m = &connector->modes[0]; /* if we can't find one, return first */
-       }
-
-       return m;
-}
-
-static struct st_framebuffer *
-drm_create_framebuffer(struct pipe_screen *screen,
-                       const __GLcontextModes *visual,
-                       unsigned width,
-                       unsigned height,
-                       void *priv)
-{
-       enum pipe_format color_format, depth_stencil_format;
-       boolean d_depth_bits_last;
-       boolean ds_depth_bits_last;
-
-       d_depth_bits_last =
-               screen->is_format_supported(screen, PIPE_FORMAT_X8Z24_UNORM,
-                                           PIPE_TEXTURE_2D,
-                                           PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-       ds_depth_bits_last =
-               screen->is_format_supported(screen, PIPE_FORMAT_S8Z24_UNORM,
-                                           PIPE_TEXTURE_2D,
-                                           PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-
-       if (visual->redBits == 8) {
-               if (visual->alphaBits == 8)
-                       color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-               else
-                       color_format = PIPE_FORMAT_X8R8G8B8_UNORM;
-       } else {
-               color_format = PIPE_FORMAT_R5G6B5_UNORM;
-       }
-
-       switch(visual->depthBits) {
-               default:
-               case 0:
-                       depth_stencil_format = PIPE_FORMAT_NONE;
-                       break;
-               case 16:
-                       depth_stencil_format = PIPE_FORMAT_Z16_UNORM;
-                       break;
-               case 24:
-                       if (visual->stencilBits == 0) {
-                               depth_stencil_format = (d_depth_bits_last) ?
-                                       PIPE_FORMAT_X8Z24_UNORM:
-                                       PIPE_FORMAT_Z24X8_UNORM;
-                       } else {
-                               depth_stencil_format = (ds_depth_bits_last) ?
-                                       PIPE_FORMAT_S8Z24_UNORM:
-                                       PIPE_FORMAT_Z24S8_UNORM;
-                       }
-                       break;
-               case 32:
-                       depth_stencil_format = PIPE_FORMAT_Z32_UNORM;
-                       break;
-       }
-
-       return st_create_framebuffer(visual,
-                                    color_format,
-                                    depth_stencil_format,
-                                    depth_stencil_format,
-                                    width,
-                                    height,
-                                    priv);
-}
-
-static void
-drm_create_texture(_EGLDisplay *dpy,
-                   struct drm_screen *scrn,
-                   unsigned w, unsigned h)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       struct pipe_screen *screen = dev->screen;
-       struct pipe_surface *surface;
-       struct pipe_texture *texture;
-       struct pipe_texture templat;
-       struct pipe_buffer *buf = NULL;
-       unsigned pitch = 0;
-
-       memset(&templat, 0, sizeof(templat));
-       templat.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-       templat.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY;
-       templat.target = PIPE_TEXTURE_2D;
-       templat.last_level = 0;
-       templat.depth0 = 1;
-       templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
-       templat.width0 = w;
-       templat.height0 = h;
-
-       texture = screen->texture_create(dev->screen,
-                                        &templat);
-
-       if (!texture)
-               goto err_tex;
-
-       surface = screen->get_tex_surface(screen,
-                                         texture,
-                                         0,
-                                         0,
-                                         0,
-                                         PIPE_BUFFER_USAGE_GPU_WRITE);
-
-       if (!surface)
-               goto err_surf;
-
-       scrn->tex = texture;
-       scrn->surface = surface;
-       scrn->front.width = w;
-       scrn->front.height = h;
-       scrn->front.pitch = pitch;
-       dev->api->local_handle_from_texture(dev->api, screen, texture,
-                                           &scrn->front.pitch, &scrn->front.handle);
-       if (0)
-               goto err_handle;
-
-       return;
-
-err_handle:
-       pipe_surface_reference(&surface, NULL);
-err_surf:
-       pipe_texture_reference(&texture, NULL);
-err_tex:
-       pipe_buffer_reference(&buf, NULL);
-       return;
-}
-
-/*
- * Exported functions
- */
-
-void
-drm_takedown_shown_screen(_EGLDisplay *dpy, struct drm_screen *screen)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-
-       screen->surf = NULL;
-
-       drmModeSetCrtc(
-               dev->drmFD,
-               screen->crtcID,
-               0, /* FD */
-               0, 0,
-               NULL, 0, /* List of output ids */
-               NULL);
-
-       drmModeRmFB(dev->drmFD, screen->fbID);
-       drmModeFreeFB(screen->fb);
-       screen->fb = NULL;
-
-       pipe_surface_reference(&screen->surface, NULL);
-       pipe_texture_reference(&screen->tex, NULL);
-
-       screen->shown = 0;
-}
-
-/**
- * Called by libEGL's eglCreateWindowSurface().
- */
-_EGLSurface *
-drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list)
-{
-       return NULL;
-}
-
-
-/**
- * Called by libEGL's eglCreatePixmapSurface().
- */
-_EGLSurface *
-drm_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list)
-{
-       return NULL;
-}
-
-
-/**
- * Called by libEGL's eglCreatePbufferSurface().
- */
-_EGLSurface *
-drm_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
-                           const EGLint *attrib_list)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       int i;
-       int width = -1;
-       int height = -1;
-       struct drm_surface *surf = NULL;
-       __GLcontextModes *visual;
-
-       for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-               switch (attrib_list[i]) {
-                       case EGL_WIDTH:
-                               width = attrib_list[++i];
-                               break;
-                       case EGL_HEIGHT:
-                               height = attrib_list[++i];
-                               break;
-                       default:
-                               _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePbufferSurface");
-                               return EGL_NO_SURFACE;
-               }
-       }
-
-       if (width < 1 || height < 1) {
-               _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePbufferSurface");
-               return NULL;
-       }
-
-       surf = (struct drm_surface *) calloc(1, sizeof(struct drm_surface));
-       if (!surf)
-               goto err;
-
-       if (!_eglInitSurface(drv, &surf->base, EGL_PBUFFER_BIT, conf, attrib_list))
-               goto err_surf;
-
-       surf->w = width;
-       surf->h = height;
-
-       visual = drm_visual_from_config(conf);
-       surf->stfb = drm_create_framebuffer(dev->screen, visual,
-                                           width, height,
-                                           (void*)surf);
-       drm_visual_modes_destroy(visual);
-
-       return &surf->base;
-
-err_surf:
-       free(surf);
-err:
-       return NULL;
-}
-
-/**
- * Called by libEGL's eglCreateScreenSurfaceMESA().
- */
-_EGLSurface *
-drm_create_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *cfg,
-                               const EGLint *attrib_list)
-{
-       EGLSurface surf = drm_create_pbuffer_surface(drv, dpy, cfg, attrib_list);
-
-       return surf;
-}
-
-/**
- * Called by libEGL's eglShowScreenSurfaceMESA().
- */
-EGLBoolean
-drm_show_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy,
-                             _EGLScreen *screen,
-                             _EGLSurface *surface, _EGLMode *mode)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       struct drm_surface *surf = lookup_drm_surface(surface);
-       struct drm_screen *scrn = lookup_drm_screen(screen);
-       int ret;
-       unsigned int i, k;
-
-       if (scrn->shown)
-               drm_takedown_shown_screen(dpy, scrn);
-
-
-       drm_create_texture(dpy, scrn, mode->Width, mode->Height);
-       if (!scrn->tex)
-               goto err_tex;
-
-       ret = drmModeAddFB(dev->drmFD,
-                          scrn->front.width, scrn->front.height,
-                          32, 32, scrn->front.pitch,
-                          scrn->front.handle,
-                          &scrn->fbID);
-
-       if (ret)
-               goto err_bo;
-
-       scrn->fb = drmModeGetFB(dev->drmFD, scrn->fbID);
-       if (!scrn->fb)
-               goto err_bo;
-
-       /* find a fitting crtc */
-       {
-               drmModeConnector *con = scrn->connector;
-
-               scrn->mode = drm_find_mode(con, mode);
-               if (!scrn->mode)
-                       goto err_fb;
-
-               for (k = 0; k < con->count_encoders; k++) {
-                       drmModeEncoder *enc = drmModeGetEncoder(dev->drmFD, con->encoders[k]);
-                       for (i = 0; i < dev->res->count_crtcs; i++) {
-                               if (enc->possible_crtcs & (1<<i)) {
-                                       /* save the ID */
-                                       scrn->crtcID = dev->res->crtcs[i];
-
-                                       /* skip the rest */
-                                       i = dev->res->count_crtcs;
-                                       k = dev->res->count_encoders;
-                               }
-                       }
-                       drmModeFreeEncoder(enc);
-               }
-       }
-
-       ret = drmModeSetCrtc(dev->drmFD,
-                            scrn->crtcID,
-                            scrn->fbID,
-                            0, 0,
-                            &scrn->connectorID, 1,
-                            scrn->mode);
-
-       if (ret)
-               goto err_crtc;
-
-
-       if (scrn->dpms)
-               drmModeConnectorSetProperty(dev->drmFD,
-                                           scrn->connectorID,
-                                           scrn->dpms->prop_id,
-                                           DRM_MODE_DPMS_ON);
-
-       surf->screen = scrn;
-
-       scrn->surf = surf;
-       scrn->shown = 1;
-
-       return EGL_TRUE;
-
-err_crtc:
-       scrn->crtcID = 0;
-
-err_fb:
-       drmModeRmFB(dev->drmFD, scrn->fbID);
-       drmModeFreeFB(scrn->fb);
-       scrn->fb = NULL;
-
-err_bo:
-       pipe_surface_reference(&scrn->surface, NULL);
-       pipe_texture_reference(&scrn->tex, NULL);
-
-err_tex:
-       return EGL_FALSE;
-}
-
-/**
- * Called by libEGL's eglDestroySurface().
- */
-EGLBoolean
-drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
-{
-       struct drm_surface *surf = lookup_drm_surface(surface);
-       if (!_eglIsSurfaceBound(&surf->base)) {
-               if (surf->screen)
-                       drm_takedown_shown_screen(dpy, surf->screen);
-               st_unreference_framebuffer(surf->stfb);
-               free(surf);
-       }
-       return EGL_TRUE;
-}
-
-/**
- * Called by libEGL's eglSwapBuffers().
- */
-EGLBoolean
-drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       struct drm_surface *surf = lookup_drm_surface(draw);
-       struct pipe_surface *back_surf;
-
-       if (!surf)
-               return EGL_FALSE;
-
-       st_get_framebuffer_surface(surf->stfb, ST_SURFACE_BACK_LEFT, &back_surf);
-
-       if (back_surf) {
-               struct drm_context *ctx = lookup_drm_context(draw->Binding);
-
-               st_notify_swapbuffers(surf->stfb);
-
-               if (ctx && surf->screen) {
-            if (ctx->pipe->surface_copy) {
-                ctx->pipe->surface_copy(ctx->pipe,
-                    surf->screen->surface,
-                    0, 0,
-                    back_surf,
-                    0, 0,
-                    surf->w, surf->h);
-            } else {
-                util_surface_copy(ctx->pipe, FALSE,
-                    surf->screen->surface,
-                    0, 0,
-                    back_surf,
-                    0, 0,
-                    surf->w, surf->h);
-            }
-                       ctx->pipe->flush(ctx->pipe, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_TEXTURE_CACHE, NULL);
-
-#ifdef DRM_MODE_FEATURE_DIRTYFB
-                       /* TODO query connector property to see if this is needed */
-                       drmModeDirtyFB(dev->drmFD, surf->screen->fbID, NULL, 0);
-#else
-                       (void)dev;
-#endif
-
-                       /* TODO more stuff here */
-               }
-       }
-
-       return EGL_TRUE;
-}
diff --git a/src/gallium/state_trackers/egl/egl_tracker.c b/src/gallium/state_trackers/egl/egl_tracker.c
deleted file mode 100644 (file)
index 11583ec..0000000
+++ /dev/null
@@ -1,272 +0,0 @@
-
-#include "utils.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "egl_tracker.h"
-
-#include <fcntl.h>
-
-#include "egllog.h"
-#include "state_tracker/drm_api.h"
-
-#include "pipe/p_screen.h"
-#include "pipe/internal/p_winsys_screen.h"
-
-/** HACK */
-void* driDriverAPI;
-
-
-/*
- * Exported functions
- */
-
-/** Called by libEGL just prior to unloading/closing the driver.
- */
-static void
-drm_unload(_EGLDriver *drv)
-{
-       free(drv);
-}
-
-/**
- * The bootstrap function.  Return a new drm_driver object and
- * plug in API functions.
- * libEGL finds this function with dlopen()/dlsym() and calls it from
- * "load driver" function.
- */
-_EGLDriver *
-_eglMain(const char *args)
-{
-       _EGLDriver *drv;
-
-       drv = (_EGLDriver *) calloc(1, sizeof(_EGLDriver));
-       if (!drv) {
-               return NULL;
-       }
-
-       /* First fill in the dispatch table with defaults */
-       _eglInitDriverFallbacks(drv);
-       /* then plug in our Drm-specific functions */
-       drv->API.Initialize = drm_initialize;
-       drv->API.Terminate = drm_terminate;
-       drv->API.CreateContext = drm_create_context;
-       drv->API.MakeCurrent = drm_make_current;
-       drv->API.CreateWindowSurface = drm_create_window_surface;
-       drv->API.CreatePixmapSurface = drm_create_pixmap_surface;
-       drv->API.CreatePbufferSurface = drm_create_pbuffer_surface;
-       drv->API.DestroySurface = drm_destroy_surface;
-       drv->API.DestroyContext = drm_destroy_context;
-       drv->API.CreateScreenSurfaceMESA = drm_create_screen_surface_mesa;
-       drv->API.ShowScreenSurfaceMESA = drm_show_screen_surface_mesa;
-       drv->API.SwapBuffers = drm_swap_buffers;
-
-       drv->Name = "DRM/Gallium/Win";
-       drv->Unload = drm_unload;
-
-       return drv;
-}
-
-static void
-drm_get_device_id(struct drm_device *device)
-{
-       char path[512];
-       FILE *file;
-       char *ret;
-
-       /* TODO get the real minor */
-       int minor = 0;
-
-       device->deviceID = 0;
-
-       snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", minor);
-       file = fopen(path, "r");
-       if (!file) {
-               _eglLog(_EGL_WARNING, "Could not retrive device ID\n");
-               return;
-       }
-
-       ret = fgets(path, sizeof( path ), file);
-       fclose(file);
-       if (!ret)
-               return;
-
-       sscanf(path, "%x", &device->deviceID);
-}
-
-static void
-drm_update_res(struct drm_device *dev)
-{
-       drmModeFreeResources(dev->res);
-       dev->res = drmModeGetResources(dev->drmFD);
-}
-
-static void
-drm_add_modes_from_connector(_EGLScreen *screen, drmModeConnectorPtr connector)
-{
-       drmModeModeInfoPtr m = NULL;
-       int i;
-
-       for (i = 0; i < connector->count_modes; i++) {
-               m = &connector->modes[i];
-               _eglAddNewMode(screen, m->hdisplay, m->vdisplay, m->vrefresh, m->name);
-       }
-}
-
-static void
-drm_find_dpms(struct drm_device *dev, struct drm_screen *screen)
-{
-       drmModeConnectorPtr c = screen->connector;
-       drmModePropertyPtr p;
-       int i;
-
-       for (i = 0; i < c->count_props; i++) {
-               p = drmModeGetProperty(dev->drmFD, c->props[i]);
-               if (!strcmp(p->name, "DPMS"))
-                       break;
-
-               drmModeFreeProperty(p);
-               p = NULL;
-       }
-
-       screen->dpms = p;
-}
-
-static int drm_open_minor(int minor)
-{
-       char buf[64];
-
-       sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
-       return open(buf, O_RDWR, 0);
-}
-
-EGLBoolean
-drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
-{
-       struct drm_device *dev;
-       struct drm_screen *screen = NULL;
-       drmModeConnectorPtr connector = NULL;
-       drmModeResPtr res = NULL;
-       unsigned count_connectors = 0;
-       int num_screens = 0;
-       EGLint i;
-       int fd;
-       _EGLConfig *config;
-
-       dev = (struct drm_device *) calloc(1, sizeof(struct drm_device));
-       if (!dev)
-               return EGL_FALSE;
-       dev->api = drm_api_create();
-
-       /* try the first node */
-       fd = drm_open_minor(0);
-       if (fd < 0)
-               goto err_fd;
-
-       dev->drmFD = fd;
-       drm_get_device_id(dev);
-
-       dev->screen = dev->api->create_screen(dev->api, dev->drmFD, NULL);
-       if (!dev->screen)
-               goto err_screen;
-       dev->winsys = dev->screen->winsys;
-
-       drm_update_res(dev);
-       res = dev->res;
-       if (res)
-               count_connectors = res->count_connectors;
-       else
-               _eglLog(_EGL_WARNING, "Could not retrive kms information\n");
-
-       for(i = 0; i < count_connectors && i < MAX_SCREENS; i++) {
-               connector = drmModeGetConnector(fd, res->connectors[i]);
-
-               if (!connector)
-                       continue;
-
-               if (connector->connection != DRM_MODE_CONNECTED) {
-                       drmModeFreeConnector(connector);
-                       continue;
-               }
-
-               screen = malloc(sizeof(struct drm_screen));
-               memset(screen, 0, sizeof(*screen));
-               screen->connector = connector;
-               screen->connectorID = connector->connector_id;
-               _eglInitScreen(&screen->base);
-               _eglAddScreen(disp, &screen->base);
-               drm_add_modes_from_connector(&screen->base, connector);
-               drm_find_dpms(dev, screen);
-               dev->screens[num_screens++] = screen;
-       }
-       dev->count_screens = num_screens;
-
-       disp->DriverData = dev;
-
-       /* for now we only have one config */
-       config = calloc(1, sizeof(*config));
-       memset(config, 1, sizeof(*config));
-       _eglInitConfig(config, 1);
-       _eglSetConfigAttrib(config, EGL_RED_SIZE, 8);
-       _eglSetConfigAttrib(config, EGL_GREEN_SIZE, 8);
-       _eglSetConfigAttrib(config, EGL_BLUE_SIZE, 8);
-       _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, 8);
-       _eglSetConfigAttrib(config, EGL_BUFFER_SIZE, 32);
-       _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, 24);
-       _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, 8);
-       _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT);
-       _eglAddConfig(disp, config);
-
-       disp->ClientAPIsMask = EGL_OPENGL_BIT /*| EGL_OPENGL_ES_BIT*/;
-       /* enable supported extensions */
-       disp->Extensions.MESA_screen_surface = EGL_TRUE;
-       disp->Extensions.MESA_copy_context = EGL_TRUE;
-
-       *major = 1;
-       *minor = 4;
-
-       return EGL_TRUE;
-
-err_screen:
-       drmClose(fd);
-err_fd:
-       free(dev);
-       return EGL_FALSE;
-}
-
-EGLBoolean
-drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-       struct drm_device *dev = lookup_drm_device(dpy);
-       struct drm_screen *screen;
-       int i = 0;
-
-       _eglReleaseDisplayResources(drv, dpy);
-       _eglCleanupDisplay(dpy);
-
-       drmFreeVersion(dev->version);
-
-       for (i = 0; i < dev->count_screens; i++) {
-               screen = dev->screens[i];
-
-               if (screen->shown)
-                       drm_takedown_shown_screen(dpy, screen);
-
-               drmModeFreeProperty(screen->dpms);
-               drmModeFreeConnector(screen->connector);
-               _eglDestroyScreen(&screen->base);
-               dev->screens[i] = NULL;
-       }
-
-       dev->screen->destroy(dev->screen);
-       dev->winsys = NULL;
-
-       drmClose(dev->drmFD);
-
-       dev->api->destroy(dev->api);
-       free(dev);
-       dpy->DriverData = NULL;
-
-       return EGL_TRUE;
-}
diff --git a/src/gallium/state_trackers/egl/egl_tracker.h b/src/gallium/state_trackers/egl/egl_tracker.h
deleted file mode 100644 (file)
index 73eb1a1..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-
-#ifndef _EGL_TRACKER_H_
-#define _EGL_TRACKER_H_
-
-#include <stdint.h>
-
-#include "eglconfig.h"
-#include "eglcontext.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglglobals.h"
-#include "eglmode.h"
-#include "eglscreen.h"
-#include "eglsurface.h"
-
-#include "xf86drm.h"
-#include "xf86drmMode.h"
-
-#include "pipe/p_compiler.h"
-
-#include "state_tracker/st_public.h"
-
-#define MAX_SCREENS 16
-
-struct pipe_winsys;
-struct pipe_screen;
-struct pipe_context;
-struct state_tracker;
-
-struct drm_screen;
-struct drm_context;
-
-struct drm_device
-{
-       /*
-        * pipe
-        */
-
-       struct drm_api *api;
-       struct pipe_winsys *winsys;
-       struct pipe_screen *screen;
-
-       /*
-        * drm
-        */
-
-       int drmFD;
-       drmVersionPtr version;
-       int deviceID;
-
-       drmModeResPtr res;
-
-       struct drm_screen *screens[MAX_SCREENS];
-       size_t count_screens;
-};
-
-struct drm_surface
-{
-       _EGLSurface base; /* base class/object */
-
-       /*
-        * pipe
-        */
-
-
-       struct st_framebuffer *stfb;
-
-       /*
-        * drm
-        */
-
-       struct drm_screen *screen;
-
-       int w;
-       int h;
-};
-
-struct drm_context
-{
-       _EGLContext base; /* base class/object */
-
-       /* pipe */
-
-       struct pipe_context *pipe;
-       struct st_context *st;
-};
-
-struct drm_screen
-{
-       _EGLScreen base;
-
-       /*
-        * pipe
-        */
-
-       struct pipe_texture *tex;
-       struct pipe_surface *surface;
-
-       /*
-        * drm
-        */
-
-       struct {
-               unsigned height;
-               unsigned width;
-               unsigned pitch;
-               unsigned handle;
-       } front;
-
-       /* currently only support one connector */
-       drmModeConnectorPtr connector;
-       uint32_t connectorID;
-
-       /* dpms property */
-       drmModePropertyPtr dpms;
-
-       /* Has this screen been shown */
-       int shown;
-
-       /* Surface that is currently attached to this screen */
-       struct drm_surface *surf;
-
-       /* framebuffer */
-       drmModeFBPtr fb;
-       uint32_t fbID;
-
-       /* crtc and mode used */
-       /*drmModeCrtcPtr crtc;*/
-       uint32_t crtcID;
-
-       drmModeModeInfoPtr mode;
-};
-
-
-static INLINE struct drm_device *
-lookup_drm_device(_EGLDisplay *d)
-{
-       return (struct drm_device *) d->DriverData;
-}
-
-
-static INLINE struct drm_context *
-lookup_drm_context(_EGLContext *c)
-{
-       return (struct drm_context *) c;
-}
-
-
-static INLINE struct drm_surface *
-lookup_drm_surface(_EGLSurface *s)
-{
-       return (struct drm_surface *) s;
-}
-
-static INLINE struct drm_screen *
-lookup_drm_screen(_EGLScreen *s)
-{
-       return (struct drm_screen *) s;
-}
-
-/**
- * egl_visual.h
- */
-/*@{*/
-void drm_visual_modes_destroy(__GLcontextModes *modes);
-__GLcontextModes* drm_visual_modes_create(unsigned count, size_t minimum_size);
-__GLcontextModes* drm_visual_from_config(_EGLConfig *conf);
-/*@}*/
-
-/**
- * egl_surface.h
- */
-/*@{*/
-void drm_takedown_shown_screen(_EGLDisplay *dpy, struct drm_screen *screen);
-/*@}*/
-
-/**
- * All function exported to the egl side.
- */
-/*@{*/
-EGLBoolean drm_initialize(_EGLDriver *drv, _EGLDisplay *dpy, EGLint *major, EGLint *minor);
-EGLBoolean drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy);
-_EGLContext *drm_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list);
-EGLBoolean drm_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context);
-_EGLSurface *drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list);
-_EGLSurface *drm_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list);
-_EGLSurface *drm_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list);
-_EGLSurface *drm_create_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list);
-EGLBoolean drm_show_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface *surface, _EGLMode *mode);
-EGLBoolean drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface);
-EGLBoolean drm_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *context);
-EGLBoolean drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw);
-/*@}*/
-
-#endif
diff --git a/src/gallium/state_trackers/egl/egl_visual.c b/src/gallium/state_trackers/egl/egl_visual.c
deleted file mode 100644 (file)
index e59f893..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-
-#include "egl_tracker.h"
-
-#include "egllog.h"
-
-void
-drm_visual_modes_destroy(__GLcontextModes *modes)
-{
-   _eglLog(_EGL_DEBUG, "%s", __FUNCTION__);
-
-   while (modes) {
-      __GLcontextModes * const next = modes->next;
-      free(modes);
-      modes = next;
-   }
-}
-
-__GLcontextModes *
-drm_visual_modes_create(unsigned count, size_t minimum_size)
-{
-       /* This code copied from libGLX, and modified */
-       const size_t size = (minimum_size > sizeof(__GLcontextModes))
-               ? minimum_size : sizeof(__GLcontextModes);
-       __GLcontextModes * head = NULL;
-       __GLcontextModes ** next;
-       unsigned   i;
-
-       _eglLog(_EGL_DEBUG, "%s %d %d", __FUNCTION__, count, minimum_size);
-
-       next = & head;
-       for (i = 0 ; i < count ; i++) {
-               *next = (__GLcontextModes *) calloc(1, size);
-               if (*next == NULL) {
-                       drm_visual_modes_destroy(head);
-                       head = NULL;
-                       break;
-               }
-
-               (*next)->doubleBufferMode = 1;
-               (*next)->visualID = GLX_DONT_CARE;
-               (*next)->visualType = GLX_DONT_CARE;
-               (*next)->visualRating = GLX_NONE;
-               (*next)->transparentPixel = GLX_NONE;
-               (*next)->transparentRed = GLX_DONT_CARE;
-               (*next)->transparentGreen = GLX_DONT_CARE;
-               (*next)->transparentBlue = GLX_DONT_CARE;
-               (*next)->transparentAlpha = GLX_DONT_CARE;
-               (*next)->transparentIndex = GLX_DONT_CARE;
-               (*next)->xRenderable = GLX_DONT_CARE;
-               (*next)->fbconfigID = GLX_DONT_CARE;
-               (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
-               (*next)->bindToTextureRgb = GLX_DONT_CARE;
-               (*next)->bindToTextureRgba = GLX_DONT_CARE;
-               (*next)->bindToMipmapTexture = GLX_DONT_CARE;
-               (*next)->bindToTextureTargets = 0;
-               (*next)->yInverted = GLX_DONT_CARE;
-
-               next = & ((*next)->next);
-       }
-
-       return head;
-}
-
-__GLcontextModes *
-drm_visual_from_config(_EGLConfig *conf)
-{
-       __GLcontextModes *visual;
-       (void)conf;
-
-       visual = drm_visual_modes_create(1, sizeof(*visual));
-       visual->redBits = 8;
-       visual->greenBits = 8;
-       visual->blueBits = 8;
-       visual->alphaBits = 8;
-
-       visual->rgbBits = 32;
-       visual->doubleBufferMode = 1;
-
-       visual->depthBits = 24;
-       visual->haveDepthBuffer = visual->depthBits > 0;
-       visual->stencilBits = 8;
-       visual->haveStencilBuffer = visual->stencilBits > 0;
-
-       return visual;
-}
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c
new file mode 100644 (file)
index 0000000..d5baf2c
--- /dev/null
@@ -0,0 +1,866 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <string.h>
+
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
+#include "util/u_debug.h"
+#include "util/u_memory.h"
+#include "egllog.h"
+
+#include "native_kms.h"
+
+static boolean
+kms_surface_validate(struct native_surface *nsurf, uint attachment_mask,
+                     unsigned int *seq_num, struct pipe_texture **textures,
+                     int *width, int *height)
+{
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   struct kms_display *kdpy = ksurf->kdpy;
+   struct pipe_screen *screen = kdpy->base.screen;
+   struct pipe_texture templ, *ptex;
+   int att;
+
+   if (attachment_mask) {
+      memset(&templ, 0, sizeof(templ));
+      templ.target = PIPE_TEXTURE_2D;
+      templ.last_level = 0;
+      templ.width0 = ksurf->width;
+      templ.height0 = ksurf->height;
+      templ.depth0 = 1;
+      templ.format = ksurf->color_format;
+      templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+      if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT)
+         templ.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY;
+   }
+
+   /* create textures */
+   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+      /* delay the allocation */
+      if (!native_attachment_mask_test(attachment_mask, att))
+         continue;
+
+      ptex = ksurf->textures[att];
+      if (!ptex) {
+         ptex = screen->texture_create(screen, &templ);
+         ksurf->textures[att] = ptex;
+      }
+
+      if (textures) {
+         textures[att] = NULL;
+         pipe_texture_reference(&textures[att], ptex);
+      }
+   }
+
+   if (seq_num)
+      *seq_num = ksurf->sequence_number;
+   if (width)
+      *width = ksurf->width;
+   if (height)
+      *height = ksurf->height;
+
+   return TRUE;
+}
+
+/**
+ * Add textures as DRM framebuffers.
+ */
+static boolean
+kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back)
+{
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   struct kms_display *kdpy = ksurf->kdpy;
+   int num_framebuffers = (need_back) ? 2 : 1;
+   int i, err;
+
+   for (i = 0; i < num_framebuffers; i++) {
+      struct kms_framebuffer *fb;
+      enum native_attachment natt;
+      unsigned int handle, stride;
+      uint block_bits;
+
+      if (i == 0) {
+         fb = &ksurf->front_fb;
+         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+      }
+      else {
+         fb = &ksurf->back_fb;
+         natt = NATIVE_ATTACHMENT_BACK_LEFT;
+      }
+
+      if (!fb->texture) {
+         /* make sure the texture has been allocated */
+         kms_surface_validate(&ksurf->base, 1 << natt, NULL, NULL, NULL, NULL);
+         if (!ksurf->textures[natt])
+            return FALSE;
+
+         pipe_texture_reference(&fb->texture, ksurf->textures[natt]);
+      }
+
+      /* already initialized */
+      if (fb->buffer_id)
+         continue;
+
+      /* TODO detect the real value */
+      fb->is_passive = TRUE;
+
+      if (!kdpy->api->local_handle_from_texture(kdpy->api,
+               kdpy->base.screen, fb->texture, &stride, &handle))
+         return FALSE;
+
+      block_bits = util_format_get_blocksizebits(ksurf->color_format);
+      err = drmModeAddFB(kdpy->fd, ksurf->width, ksurf->height,
+            block_bits, block_bits, stride, handle, &fb->buffer_id);
+      if (err) {
+         fb->buffer_id = 0;
+         return FALSE;
+      }
+   }
+
+   return TRUE;
+}
+
+static boolean
+kms_surface_flush_frontbuffer(struct native_surface *nsurf)
+{
+#ifdef DRM_MODE_FEATURE_DIRTYFB
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   struct kms_display *kdpy = ksurf->kdpy;
+
+   /* pbuffer is private */
+   if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER)
+      return TRUE;
+
+   if (ksurf->front_fb.is_passive)
+      drmModeDirtyFB(kdpy->fd, ksurf->front_fb.buffer_id, NULL, 0);
+#endif
+
+   return TRUE;
+}
+
+static boolean
+kms_surface_swap_buffers(struct native_surface *nsurf)
+{
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   struct kms_crtc *kcrtc = &ksurf->current_crtc;
+   struct kms_display *kdpy = ksurf->kdpy;
+   struct kms_framebuffer tmp_fb;
+   struct pipe_texture *tmp_texture;
+   int err;
+
+   /* pbuffer is private */
+   if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER)
+      return TRUE;
+
+   if (!ksurf->back_fb.buffer_id) {
+      if (!kms_surface_init_framebuffers(&ksurf->base, TRUE))
+         return FALSE;
+   }
+
+   if (ksurf->is_shown && kcrtc->crtc) {
+      err = drmModeSetCrtc(kdpy->fd, kcrtc->crtc->crtc_id,
+            ksurf->back_fb.buffer_id, kcrtc->crtc->x, kcrtc->crtc->y,
+            kcrtc->connectors, kcrtc->num_connectors, &kcrtc->crtc->mode);
+      if (err)
+         return FALSE;
+   }
+
+   /* swap the buffers */
+   tmp_fb = ksurf->front_fb;
+   ksurf->front_fb = ksurf->back_fb;
+   ksurf->back_fb = tmp_fb;
+
+   tmp_texture = ksurf->textures[NATIVE_ATTACHMENT_FRONT_LEFT];
+   ksurf->textures[NATIVE_ATTACHMENT_FRONT_LEFT] =
+      ksurf->textures[NATIVE_ATTACHMENT_BACK_LEFT];
+   ksurf->textures[NATIVE_ATTACHMENT_BACK_LEFT] = tmp_texture;
+
+   /* the front/back textures are swapped */
+   ksurf->sequence_number++;
+
+   return TRUE;
+}
+
+static void
+kms_surface_wait(struct native_surface *nsurf)
+{
+   /* no-op */
+}
+
+static void
+kms_surface_destroy(struct native_surface *nsurf)
+{
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   int i;
+
+   if (ksurf->current_crtc.crtc)
+         drmModeFreeCrtc(ksurf->current_crtc.crtc);
+
+   if (ksurf->front_fb.buffer_id)
+      drmModeRmFB(ksurf->kdpy->fd, ksurf->front_fb.buffer_id);
+   pipe_texture_reference(&ksurf->front_fb.texture, NULL);
+
+   if (ksurf->back_fb.buffer_id)
+      drmModeRmFB(ksurf->kdpy->fd, ksurf->back_fb.buffer_id);
+   pipe_texture_reference(&ksurf->back_fb.texture, NULL);
+
+   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
+      struct pipe_texture *ptex = ksurf->textures[i];
+      pipe_texture_reference(&ptex, NULL);
+   }
+
+   free(ksurf);
+}
+
+static struct kms_surface *
+kms_display_create_surface(struct native_display *ndpy,
+                           enum kms_surface_type type,
+                           const struct native_config *nconf,
+                           uint width, uint height)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct kms_config *kconf = kms_config(nconf);
+   struct kms_surface *ksurf;
+
+   ksurf = CALLOC_STRUCT(kms_surface);
+   if (!ksurf)
+      return NULL;
+
+   ksurf->kdpy = kdpy;
+   ksurf->type = type;
+   ksurf->color_format = kconf->base.color_format;
+   ksurf->width = width;
+   ksurf->height = height;
+
+   ksurf->base.destroy = kms_surface_destroy;
+   ksurf->base.swap_buffers = kms_surface_swap_buffers;
+   ksurf->base.flush_frontbuffer = kms_surface_flush_frontbuffer;
+   ksurf->base.validate = kms_surface_validate;
+   ksurf->base.wait = kms_surface_wait;
+
+   return ksurf;
+}
+
+/**
+ * Choose a CRTC that supports all given connectors.
+ */
+static uint32_t
+kms_display_choose_crtc(struct native_display *ndpy,
+                        uint32_t *connectors, int num_connectors)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   int idx;
+
+   for (idx = 0; idx < kdpy->resources->count_crtcs; idx++) {
+      boolean found_crtc = TRUE;
+      int i, j;
+
+      for (i = 0; i < num_connectors; i++) {
+         drmModeConnectorPtr connector;
+         int encoder_idx = -1;
+
+         connector = drmModeGetConnector(kdpy->fd, connectors[i]);
+         if (!connector) {
+            found_crtc = FALSE;
+            break;
+         }
+
+         /* find an encoder the CRTC supports */
+         for (j = 0; j < connector->count_encoders; j++) {
+            drmModeEncoderPtr encoder =
+               drmModeGetEncoder(kdpy->fd, connector->encoders[j]);
+            if (encoder->possible_crtcs & (1 << idx)) {
+               encoder_idx = j;
+               break;
+            }
+            drmModeFreeEncoder(encoder);
+         }
+
+         drmModeFreeConnector(connector);
+         if (encoder_idx < 0) {
+            found_crtc = FALSE;
+            break;
+         }
+      }
+
+      if (found_crtc)
+         break;
+   }
+
+   if (idx >= kdpy->resources->count_crtcs) {
+      _eglLog(_EGL_WARNING,
+            "failed to find a CRTC that supports the given %d connectors",
+            num_connectors);
+      return 0;
+   }
+
+   return kdpy->resources->crtcs[idx];
+}
+
+/**
+ * Remember the original CRTC status and set the CRTC
+ */
+static boolean
+kms_display_set_crtc(struct native_display *ndpy, int crtc_idx,
+                     uint32_t buffer_id, uint32_t x, uint32_t y,
+                     uint32_t *connectors, int num_connectors,
+                     drmModeModeInfoPtr mode)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct kms_crtc *kcrtc = &kdpy->saved_crtcs[crtc_idx];
+   uint32_t crtc_id;
+   int err;
+
+   if (kcrtc->crtc) {
+      crtc_id = kcrtc->crtc->crtc_id;
+   }
+   else {
+      int count = 0, i;
+
+      /*
+       * Choose the CRTC once.  It could be more dynamic, but let's keep it
+       * simple for now.
+       */
+      crtc_id = kms_display_choose_crtc(&kdpy->base,
+            connectors, num_connectors);
+
+      /* save the original CRTC status */
+      kcrtc->crtc = drmModeGetCrtc(kdpy->fd, crtc_id);
+      if (!kcrtc->crtc)
+         return FALSE;
+
+      for (i = 0; i < kdpy->num_connectors; i++) {
+         struct kms_connector *kconn = &kdpy->connectors[i];
+         drmModeConnectorPtr connector = kconn->connector;
+         drmModeEncoderPtr encoder;
+
+         encoder = drmModeGetEncoder(kdpy->fd, connector->encoder_id);
+         if (encoder) {
+            if (encoder->crtc_id == crtc_id) {
+               kcrtc->connectors[count++] = connector->connector_id;
+               if (count >= Elements(kcrtc->connectors))
+                  break;
+            }
+            drmModeFreeEncoder(encoder);
+         }
+      }
+
+      kcrtc->num_connectors = count;
+   }
+
+   err = drmModeSetCrtc(kdpy->fd, crtc_id, buffer_id, x, y,
+         connectors, num_connectors, mode);
+   if (err) {
+      drmModeFreeCrtc(kcrtc->crtc);
+      kcrtc->crtc = NULL;
+      kcrtc->num_connectors = 0;
+
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+static boolean
+kms_display_program(struct native_display *ndpy, int crtc_idx,
+                    struct native_surface *nsurf, uint x, uint y,
+                    const struct native_connector **nconns, int num_nconns,
+                    const struct native_mode *nmode)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct kms_surface *ksurf = kms_surface(nsurf);
+   const struct kms_mode *kmode = kms_mode(nmode);
+   uint32_t connector_ids[32];
+   uint32_t buffer_id;
+   drmModeModeInfo mode_tmp, *mode;
+   int i;
+
+   if (num_nconns > Elements(connector_ids)) {
+      _eglLog(_EGL_WARNING, "too many connectors (%d)", num_nconns);
+      num_nconns = Elements(connector_ids);
+   }
+
+   if (ksurf) {
+      if (!kms_surface_init_framebuffers(&ksurf->base, FALSE))
+         return FALSE;
+
+      buffer_id = ksurf->front_fb.buffer_id;
+      /* the mode argument of drmModeSetCrtc is not constified */
+      mode_tmp = kmode->mode;
+      mode = &mode_tmp;
+   }
+   else {
+      /* disable the CRTC */
+      buffer_id = 0;
+      mode = NULL;
+      num_nconns = 0;
+   }
+
+   for (i = 0; i < num_nconns; i++) {
+      struct kms_connector *kconn = kms_connector(nconns[i]);
+      connector_ids[i] = kconn->connector->connector_id;
+   }
+
+   if (!kms_display_set_crtc(&kdpy->base, crtc_idx, buffer_id, x, y,
+            connector_ids, num_nconns, mode)) {
+      _eglLog(_EGL_WARNING, "failed to set CRTC %d", crtc_idx);
+
+      return FALSE;
+   }
+
+   if (kdpy->shown_surfaces[crtc_idx])
+      kdpy->shown_surfaces[crtc_idx]->is_shown = FALSE;
+   kdpy->shown_surfaces[crtc_idx] = ksurf;
+
+   /* remember the settings for buffer swapping */
+   if (ksurf) {
+      uint32_t crtc_id = kdpy->saved_crtcs[crtc_idx].crtc->crtc_id;
+      struct kms_crtc *kcrtc = &ksurf->current_crtc;
+
+      if (kcrtc->crtc)
+         drmModeFreeCrtc(kcrtc->crtc);
+      kcrtc->crtc = drmModeGetCrtc(kdpy->fd, crtc_id);
+
+      assert(num_nconns < Elements(kcrtc->connectors));
+      memcpy(kcrtc->connectors, connector_ids,
+            sizeof(*connector_ids) * num_nconns);
+      kcrtc->num_connectors = num_nconns;
+
+      ksurf->is_shown = TRUE;
+   }
+
+   return TRUE;
+}
+
+static const struct native_mode **
+kms_display_get_modes(struct native_display *ndpy,
+                      const struct native_connector *nconn,
+                      int *num_modes)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct kms_connector *kconn = kms_connector(nconn);
+   const struct native_mode **nmodes_return;
+   int count, i;
+
+   /* delete old data */
+   if (kconn->connector) {
+      drmModeFreeConnector(kconn->connector);
+      free(kconn->kms_modes);
+
+      kconn->connector = NULL;
+      kconn->kms_modes = NULL;
+      kconn->num_modes = 0;
+   }
+
+   /* detect again */
+   kconn->connector = drmModeGetConnector(kdpy->fd, kconn->connector_id);
+   if (!kconn->connector)
+      return NULL;
+
+   count = kconn->connector->count_modes;
+   kconn->kms_modes = calloc(count, sizeof(*kconn->kms_modes));
+   if (!kconn->kms_modes) {
+      drmModeFreeConnector(kconn->connector);
+      kconn->connector = NULL;
+
+      return NULL;
+   }
+
+   for (i = 0; i < count; i++) {
+      struct kms_mode *kmode = &kconn->kms_modes[i];
+      drmModeModeInfoPtr mode = &kconn->connector->modes[i];
+
+      kmode->mode = *mode;
+
+      kmode->base.desc = kmode->mode.name;
+      kmode->base.width = kmode->mode.hdisplay;
+      kmode->base.height = kmode->mode.vdisplay;
+      kmode->base.refresh_rate = kmode->mode.vrefresh / 1000;
+   }
+
+   nmodes_return = malloc(count * sizeof(*nmodes_return));
+   if (nmodes_return) {
+      for (i = 0; i < count; i++)
+         nmodes_return[i] = &kconn->kms_modes[i].base;
+      if (num_modes)
+         *num_modes = count;
+   }
+
+   return nmodes_return;
+}
+
+static const struct native_connector **
+kms_display_get_connectors(struct native_display *ndpy, int *num_connectors,
+                           int *num_crtc)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   const struct native_connector **connectors;
+   int i;
+
+   if (!kdpy->connectors) {
+      kdpy->connectors =
+         calloc(kdpy->resources->count_connectors, sizeof(*kdpy->connectors));
+      if (!kdpy->connectors)
+         return NULL;
+
+      for (i = 0; i < kdpy->resources->count_connectors; i++) {
+         struct kms_connector *kconn = &kdpy->connectors[i];
+
+         kconn->connector_id = kdpy->resources->connectors[i];
+         /* kconn->connector is allocated when the modes are asked */
+      }
+
+      kdpy->num_connectors = kdpy->resources->count_connectors;
+   }
+
+   connectors = malloc(kdpy->num_connectors * sizeof(*connectors));
+   if (connectors) {
+      for (i = 0; i < kdpy->num_connectors; i++)
+         connectors[i] = &kdpy->connectors[i].base;
+      if (num_connectors)
+         *num_connectors = kdpy->num_connectors;
+   }
+
+   if (num_crtc)
+      *num_crtc = kdpy->resources->count_crtcs;
+
+   return connectors;
+}
+
+static struct native_surface *
+kms_display_create_scanout_surface(struct native_display *ndpy,
+                                   const struct native_config *nconf,
+                                   uint width, uint height)
+{
+   struct kms_surface *ksurf;
+
+   ksurf = kms_display_create_surface(ndpy,
+         KMS_SURFACE_TYPE_SCANOUT, nconf, width, height);
+   return &ksurf->base;
+}
+
+static struct native_surface *
+kms_display_create_pbuffer_surface(struct native_display *ndpy,
+                                   const struct native_config *nconf,
+                                   uint width, uint height)
+{
+   struct kms_surface *ksurf;
+
+   ksurf = kms_display_create_surface(ndpy,
+         KMS_SURFACE_TYPE_PBUFFER, nconf, width, height);
+   return &ksurf->base;
+}
+
+static struct pipe_context *
+kms_display_create_context(struct native_display *ndpy, void *context_private)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct pipe_context *pctx;
+
+   pctx = kdpy->api->create_context(kdpy->api, kdpy->base.screen);
+   if (pctx)
+      pctx->priv = context_private;
+   return pctx;
+}
+
+static boolean
+kms_display_is_format_supported(struct native_display *ndpy,
+                                enum pipe_format fmt, boolean is_color)
+{
+   return ndpy->screen->is_format_supported(ndpy->screen,
+         fmt, PIPE_TEXTURE_2D,
+         (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
+         PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+}
+
+static const struct native_config **
+kms_display_get_configs(struct native_display *ndpy, int *num_configs)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   const struct native_config **configs;
+
+   /* first time */
+   if (!kdpy->config) {
+      struct native_config *nconf;
+      enum pipe_format format;
+
+      kdpy->config = calloc(1, sizeof(*kdpy->config));
+      if (!kdpy->config)
+         return NULL;
+
+      nconf = &kdpy->config->base;
+
+      /* always double-buffered */
+      nconf->mode.doubleBufferMode = TRUE;
+
+      format = PIPE_FORMAT_A8R8G8B8_UNORM;
+      if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) {
+         format = PIPE_FORMAT_B8G8R8A8_UNORM;
+         if (!kms_display_is_format_supported(&kdpy->base, format, TRUE))
+            format = PIPE_FORMAT_NONE;
+      }
+      if (format == PIPE_FORMAT_NONE)
+         return NULL;
+
+      nconf->color_format = format;
+      nconf->mode.redBits = 8;
+      nconf->mode.greenBits = 8;
+      nconf->mode.blueBits = 8;
+      nconf->mode.alphaBits = 8;
+      nconf->mode.rgbBits = 32;
+
+      format = PIPE_FORMAT_S8Z24_UNORM;
+      if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) {
+         format = PIPE_FORMAT_Z24S8_UNORM;
+         if (!kms_display_is_format_supported(&kdpy->base, format, FALSE))
+            format = PIPE_FORMAT_NONE;
+      }
+      if (format != PIPE_FORMAT_NONE) {
+         nconf->depth_format = format;
+         nconf->stencil_format = format;
+
+         nconf->mode.depthBits = 24;
+         nconf->mode.stencilBits = 8;
+         nconf->mode.haveDepthBuffer = TRUE;
+         nconf->mode.haveStencilBuffer = TRUE;
+      }
+
+      nconf->scanout_bit = TRUE;
+      nconf->mode.drawableType = GLX_PBUFFER_BIT;
+      nconf->mode.swapMethod = GLX_SWAP_EXCHANGE_OML;
+
+      nconf->mode.visualID = 0;
+      nconf->mode.visualType = EGL_NONE;
+
+      nconf->mode.renderType = GLX_RGBA_BIT;
+      nconf->mode.rgbMode = TRUE;
+      nconf->mode.xRenderable = FALSE;
+   }
+
+   configs = malloc(sizeof(*configs));
+   if (configs) {
+      configs[0] = &kdpy->config->base;
+      if (num_configs)
+         *num_configs = 1;
+   }
+
+   return configs;
+}
+
+static void
+kms_display_destroy(struct native_display *ndpy)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   int i;
+
+   if (kdpy->config)
+      free(kdpy->config);
+
+   if (kdpy->connectors) {
+      for (i = 0; i < kdpy->num_connectors; i++) {
+         struct kms_connector *kconn = &kdpy->connectors[i];
+         if (kconn->connector) {
+            drmModeFreeConnector(kconn->connector);
+            free(kconn->kms_modes);
+         }
+      }
+      free(kdpy->connectors);
+   }
+
+   if (kdpy->shown_surfaces)
+      free(kdpy->shown_surfaces);
+
+   if (kdpy->saved_crtcs) {
+      for (i = 0; i < kdpy->resources->count_crtcs; i++) {
+         struct kms_crtc *kcrtc = &kdpy->saved_crtcs[i];
+
+         if (kcrtc->crtc) {
+            /* restore crtc */
+            drmModeSetCrtc(kdpy->fd, kcrtc->crtc->crtc_id,
+                  kcrtc->crtc->buffer_id, kcrtc->crtc->x, kcrtc->crtc->y,
+                  kcrtc->connectors, kcrtc->num_connectors,
+                  &kcrtc->crtc->mode);
+
+            drmModeFreeCrtc(kcrtc->crtc);
+         }
+      }
+      free(kdpy->saved_crtcs);
+   }
+
+   if (kdpy->resources)
+      drmModeFreeResources(kdpy->resources);
+
+   if (kdpy->base.screen)
+      kdpy->base.screen->destroy(kdpy->base.screen);
+
+   if (kdpy->fd >= 0)
+      drmClose(kdpy->fd);
+
+   if (kdpy->api)
+      kdpy->api->destroy(kdpy->api);
+   free(kdpy);
+}
+
+/**
+ * Initialize KMS and pipe screen.
+ */
+static boolean
+kms_display_init_screen(struct native_display *ndpy)
+{
+   struct kms_display *kdpy = kms_display(ndpy);
+   struct drm_create_screen_arg arg;
+   int fd;
+
+   fd = drmOpen(kdpy->api->name, NULL);
+   if (fd < 0) {
+      _eglLog(_EGL_WARNING, "failed to open DRM device");
+      return FALSE;
+   }
+
+#if 0
+   if (drmSetMaster(fd)) {
+      _eglLog(_EGL_WARNING, "failed to become DRM master");
+      return FALSE;
+   }
+#endif
+
+   memset(&arg, 0, sizeof(arg));
+   arg.mode = DRM_CREATE_NORMAL;
+   kdpy->base.screen = kdpy->api->create_screen(kdpy->api, fd, &arg);
+   if (!kdpy->base.screen) {
+      _eglLog(_EGL_WARNING, "failed to create DRM screen");
+      drmClose(fd);
+      return FALSE;
+   }
+
+   kdpy->fd = fd;
+
+   return TRUE;
+}
+
+static struct native_display_modeset kms_display_modeset = {
+   .get_connectors = kms_display_get_connectors,
+   .get_modes = kms_display_get_modes,
+   .create_scanout_surface = kms_display_create_scanout_surface,
+   .program = kms_display_program
+};
+
+static struct native_display *
+kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api)
+{
+   struct kms_display *kdpy;
+
+   kdpy = CALLOC_STRUCT(kms_display);
+   if (!kdpy)
+      return NULL;
+
+   kdpy->api = api;
+   if (!kdpy->api) {
+      _eglLog(_EGL_WARNING, "failed to create DRM API");
+      free(kdpy);
+      return NULL;
+   }
+
+   kdpy->fd = -1;
+   if (!kms_display_init_screen(&kdpy->base)) {
+      kms_display_destroy(&kdpy->base);
+      return NULL;
+   }
+
+   /* resources are fixed, unlike crtc, connector, or encoder */
+   kdpy->resources = drmModeGetResources(kdpy->fd);
+   if (!kdpy->resources) {
+      kms_display_destroy(&kdpy->base);
+      return NULL;
+   }
+
+   kdpy->saved_crtcs =
+      calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->saved_crtcs));
+   if (!kdpy->saved_crtcs) {
+      kms_display_destroy(&kdpy->base);
+      return NULL;
+   }
+
+   kdpy->shown_surfaces =
+      calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->shown_surfaces));
+   if (!kdpy->shown_surfaces) {
+      kms_display_destroy(&kdpy->base);
+      return NULL;
+   }
+
+   kdpy->base.destroy = kms_display_destroy;
+   kdpy->base.get_configs = kms_display_get_configs;
+   kdpy->base.create_context = kms_display_create_context;
+   kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface;
+
+   kdpy->base.modeset = &kms_display_modeset;
+
+   return &kdpy->base;
+}
+
+struct native_probe *
+native_create_probe(EGLNativeDisplayType dpy)
+{
+   return NULL;
+}
+
+enum native_probe_result
+native_get_probe_result(struct native_probe *nprobe)
+{
+   return NATIVE_PROBE_UNKNOWN;
+}
+
+/* the api is destroyed with the native display */
+static struct drm_api *drm_api;
+
+const char *
+native_get_name(void)
+{
+   static char kms_name[32];
+
+   if (!drm_api)
+      drm_api = drm_api_create();
+
+   if (drm_api)
+      snprintf(kms_name, sizeof(kms_name), "KMS/%s", drm_api->name);
+   else
+      snprintf(kms_name, sizeof(kms_name), "KMS");
+
+   return kms_name;
+}
+
+struct native_display *
+native_create_display(EGLNativeDisplayType dpy)
+{
+   struct native_display *ndpy = NULL;
+
+   if (!drm_api)
+      drm_api = drm_api_create();
+
+   if (drm_api)
+      ndpy = kms_create_display(dpy, drm_api);
+
+   return ndpy;
+}
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.h b/src/gallium/state_trackers/egl/kms/native_kms.h
new file mode 100644 (file)
index 0000000..095186e
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _NATIVE_KMS_H_
+#define _NATIVE_KMS_H_
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "pipe/p_compiler.h"
+#include "util/u_format.h"
+#include "pipe/p_state.h"
+#include "state_tracker/drm_api.h"
+
+#include "common/native.h"
+
+enum kms_surface_type {
+   KMS_SURFACE_TYPE_PBUFFER,
+   KMS_SURFACE_TYPE_SCANOUT
+};
+
+struct kms_config;
+struct kms_connector;
+struct kms_mode;
+
+struct kms_crtc {
+   drmModeCrtcPtr crtc;
+   uint32_t connectors[32];
+   int num_connectors;
+};
+
+struct kms_display {
+   struct native_display base;
+
+   int fd;
+   struct drm_api *api;
+   drmModeResPtr resources;
+   struct kms_config *config;
+
+   struct kms_connector *connectors;
+   int num_connectors;
+
+   struct kms_surface **shown_surfaces;
+   /* save the original settings of the CRTCs */
+   struct kms_crtc *saved_crtcs;
+};
+
+struct kms_framebuffer {
+   struct pipe_texture *texture;
+   boolean is_passive;
+
+   uint32_t buffer_id;
+};
+
+struct kms_surface {
+   struct native_surface base;
+   enum kms_surface_type type;
+   enum pipe_format color_format;
+   struct kms_display *kdpy;
+   int width, height;
+
+   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+   unsigned int sequence_number;
+   struct kms_framebuffer front_fb, back_fb;
+
+   boolean is_shown;
+   struct kms_crtc current_crtc;
+};
+
+struct kms_config {
+   struct native_config base;
+};
+
+struct kms_connector {
+   struct native_connector base;
+
+   uint32_t connector_id;
+   drmModeConnectorPtr connector;
+   struct kms_mode *kms_modes;
+   int num_modes;
+};
+
+struct kms_mode {
+   struct native_mode base;
+   drmModeModeInfo mode;
+};
+
+static INLINE struct kms_display *
+kms_display(const struct native_display *ndpy)
+{
+   return (struct kms_display *) ndpy;
+}
+
+static INLINE struct kms_surface *
+kms_surface(const struct native_surface *nsurf)
+{
+   return (struct kms_surface *) nsurf;
+}
+
+static INLINE struct kms_config *
+kms_config(const struct native_config *nconf)
+{
+   return (struct kms_config *) nconf;
+}
+
+static INLINE struct kms_connector *
+kms_connector(const struct native_connector *nconn)
+{
+   return (struct kms_connector *) nconn;
+}
+
+static INLINE struct kms_mode *
+kms_mode(const struct native_mode *nmode)
+{
+   return (struct kms_mode *) nmode;
+}
+
+#endif /* _NATIVE_KMS_H_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
new file mode 100644 (file)
index 0000000..07f82d8
--- /dev/null
@@ -0,0 +1,705 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 "util/u_memory.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "pipe/p_compiler.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+#include "state_tracker/drm_api.h"
+#include "egllog.h"
+
+#include "native_x11.h"
+#include "x11_screen.h"
+
+enum dri2_surface_type {
+   DRI2_SURFACE_TYPE_WINDOW,
+   DRI2_SURFACE_TYPE_PIXMAP,
+   DRI2_SURFACE_TYPE_PBUFFER
+};
+
+struct dri2_display {
+   struct native_display base;
+   Display *dpy;
+   boolean own_dpy;
+
+   struct drm_api *api;
+   struct x11_screen *xscr;
+   int xscr_number;
+
+   struct dri2_config *configs;
+   int num_configs;
+};
+
+struct dri2_surface {
+   struct native_surface base;
+   Drawable drawable;
+   enum dri2_surface_type type;
+   enum pipe_format color_format;
+   struct dri2_display *dri2dpy;
+
+   struct pipe_texture *pbuffer_textures[NUM_NATIVE_ATTACHMENTS];
+   boolean have_back, have_fake;
+   int width, height;
+   unsigned int sequence_number;
+};
+
+struct dri2_config {
+   struct native_config base;
+};
+
+static INLINE struct dri2_display *
+dri2_display(const struct native_display *ndpy)
+{
+   return (struct dri2_display *) ndpy;
+}
+
+static INLINE struct dri2_surface *
+dri2_surface(const struct native_surface *nsurf)
+{
+   return (struct dri2_surface *) nsurf;
+}
+
+static INLINE struct dri2_config *
+dri2_config(const struct native_config *nconf)
+{
+   return (struct dri2_config *) nconf;
+}
+
+static boolean
+dri2_surface_flush_frontbuffer(struct native_surface *nsurf)
+{
+   struct dri2_surface *dri2surf = dri2_surface(nsurf);
+   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
+
+   /* pbuffer is private */
+   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
+      return TRUE;
+
+   /* copy to real front buffer */
+   if (dri2surf->have_fake)
+      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
+            0, 0, dri2surf->width, dri2surf->height,
+            DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
+
+   return TRUE;
+}
+
+static boolean
+dri2_surface_swap_buffers(struct native_surface *nsurf)
+{
+   struct dri2_surface *dri2surf = dri2_surface(nsurf);
+   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
+
+   /* pbuffer is private */
+   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
+      return TRUE;
+
+   /* copy to front buffer */
+   if (dri2surf->have_back)
+      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
+            0, 0, dri2surf->width, dri2surf->height,
+            DRI2BufferBackLeft, DRI2BufferFrontLeft);
+
+   /* and update fake front buffer */
+   if (dri2surf->have_fake)
+      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
+            0, 0, dri2surf->width, dri2surf->height,
+            DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+
+   return TRUE;
+}
+
+static boolean
+dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
+                      unsigned int *seq_num, struct pipe_texture **textures,
+                      int *width, int *height)
+{
+   struct dri2_surface *dri2surf = dri2_surface(nsurf);
+   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
+   unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS];
+   struct pipe_texture templ;
+   struct x11_drawable_buffer *xbufs;
+   int num_ins, num_outs, att, i;
+
+   if (attachment_mask) {
+      memset(&templ, 0, sizeof(templ));
+      templ.target = PIPE_TEXTURE_2D;
+      templ.last_level = 0;
+      templ.width0 = dri2surf->width;
+      templ.height0 = dri2surf->height;
+      templ.depth0 = 1;
+      templ.format = dri2surf->color_format;
+      templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+      if (textures)
+         memset(textures, 0, sizeof(*textures) * NUM_NATIVE_ATTACHMENTS);
+   }
+
+   /* create textures for pbuffer */
+   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) {
+      struct pipe_screen *screen = dri2dpy->base.screen;
+
+      for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+         struct pipe_texture *ptex = dri2surf->pbuffer_textures[att];
+
+         /* delay the allocation */
+         if (!native_attachment_mask_test(attachment_mask, att))
+            continue;
+
+         if (!ptex) {
+            ptex = screen->texture_create(screen, &templ);
+            dri2surf->pbuffer_textures[att] = ptex;
+         }
+
+         if (textures)
+            pipe_texture_reference(&textures[att], ptex);
+      }
+
+      if (seq_num)
+         *seq_num = dri2surf->sequence_number;
+      if (width)
+         *width = dri2surf->width;
+      if (height)
+         *height = dri2surf->height;
+
+      return TRUE;
+   }
+
+   /* prepare the attachments */
+   num_ins = 0;
+   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+      if (native_attachment_mask_test(attachment_mask, att)) {
+         unsigned int dri2att;
+
+         switch (att) {
+         case NATIVE_ATTACHMENT_FRONT_LEFT:
+            dri2att = DRI2BufferFrontLeft;
+            break;
+         case NATIVE_ATTACHMENT_BACK_LEFT:
+            dri2att = DRI2BufferBackLeft;
+            break;
+         case NATIVE_ATTACHMENT_FRONT_RIGHT:
+            dri2att = DRI2BufferFrontRight;
+            break;
+         case NATIVE_ATTACHMENT_BACK_RIGHT:
+            dri2att = DRI2BufferBackRight;
+            break;
+         default:
+            assert(0);
+            dri2att = 0;
+            break;
+         }
+
+         dri2atts[num_ins] = dri2att;
+         num_ins++;
+      }
+   }
+
+   dri2surf->have_back = FALSE;
+   dri2surf->have_fake = FALSE;
+
+   /* remember old geometry */
+   templ.width0 = dri2surf->width;
+   templ.height0 = dri2surf->height;
+
+   xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable,
+                                    &dri2surf->width, &dri2surf->height,
+                                    dri2atts, FALSE, num_ins, &num_outs);
+   if (!xbufs)
+      return FALSE;
+
+   if (templ.width0 != dri2surf->width || templ.height0 != dri2surf->height) {
+      /* are there cases where the buffers change and the geometry doesn't? */
+      dri2surf->sequence_number++;
+
+      templ.width0 = dri2surf->width;
+      templ.height0 = dri2surf->height;
+   }
+
+   for (i = 0; i < num_outs; i++) {
+      struct x11_drawable_buffer *xbuf = &xbufs[i];
+      const char *desc;
+      enum native_attachment natt;
+
+      switch (xbuf->attachment) {
+      case DRI2BufferFrontLeft:
+         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+         desc = "DRI2 Front Buffer";
+         break;
+      case DRI2BufferFakeFrontLeft:
+         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+         desc = "DRI2 Fake Front Buffer";
+         dri2surf->have_fake = TRUE;
+         break;
+      case DRI2BufferBackLeft:
+         natt = NATIVE_ATTACHMENT_BACK_LEFT;
+         desc = "DRI2 Back Buffer";
+         dri2surf->have_back = TRUE;
+         break;
+      default:
+         desc = NULL;
+         break;
+      }
+
+      if (!desc || !native_attachment_mask_test(attachment_mask, natt) ||
+          (textures && textures[natt])) {
+         if (!desc)
+            _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment);
+         else if (!native_attachment_mask_test(attachment_mask, natt))
+            _eglLog(_EGL_WARNING, "unexpected buffer %d", xbuf->attachment);
+         else
+            _eglLog(_EGL_WARNING, "both real and fake front buffers are listed");
+         continue;
+      }
+
+      if (textures) {
+         struct pipe_texture *ptex =
+            dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
+                  dri2dpy->base.screen, &templ,
+                  desc, xbuf->pitch, xbuf->name);
+         if (ptex) {
+            /* the caller owns the textures */
+            textures[natt] = ptex;
+         }
+      }
+   }
+
+   free(xbufs);
+
+   if (seq_num)
+      *seq_num = dri2surf->sequence_number;
+   if (width)
+      *width = dri2surf->width;
+   if (height)
+      *height = dri2surf->height;
+
+   return TRUE;
+}
+
+static void
+dri2_surface_wait(struct native_surface *nsurf)
+{
+   struct dri2_surface *dri2surf = dri2_surface(nsurf);
+   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
+
+   if (dri2surf->have_fake) {
+      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
+            0, 0, dri2surf->width, dri2surf->height,
+            DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+   }
+}
+
+static void
+dri2_surface_destroy(struct native_surface *nsurf)
+{
+   struct dri2_surface *dri2surf = dri2_surface(nsurf);
+   int i;
+
+   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
+      struct pipe_texture *ptex = dri2surf->pbuffer_textures[i];
+      pipe_texture_reference(&ptex, NULL);
+   }
+
+   if (dri2surf->drawable)
+      x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr,
+            dri2surf->drawable, FALSE);
+   free(dri2surf);
+}
+
+static struct dri2_surface *
+dri2_display_create_surface(struct native_display *ndpy,
+                            enum dri2_surface_type type,
+                            Drawable drawable,
+                            const struct native_config *nconf)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+   struct dri2_config *dri2conf = dri2_config(nconf);
+   struct dri2_surface *dri2surf;
+
+   dri2surf = CALLOC_STRUCT(dri2_surface);
+   if (!dri2surf)
+      return NULL;
+
+   if (drawable)
+      x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE);
+
+   dri2surf->dri2dpy = dri2dpy;
+   dri2surf->type = type;
+   dri2surf->drawable = drawable;
+   dri2surf->color_format = dri2conf->base.color_format;
+
+   dri2surf->base.destroy = dri2_surface_destroy;
+   dri2surf->base.swap_buffers = dri2_surface_swap_buffers;
+   dri2surf->base.flush_frontbuffer = dri2_surface_flush_frontbuffer;
+   dri2surf->base.validate = dri2_surface_validate;
+   dri2surf->base.wait = dri2_surface_wait;
+
+   return dri2surf;
+}
+
+static struct native_surface *
+dri2_display_create_window_surface(struct native_display *ndpy,
+                                   EGLNativeWindowType win,
+                                   const struct native_config *nconf)
+{
+   struct dri2_surface *dri2surf;
+
+   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_WINDOW,
+         (Drawable) win, nconf);
+   return (dri2surf) ? &dri2surf->base : NULL;
+}
+
+static struct native_surface *
+dri2_display_create_pixmap_surface(struct native_display *ndpy,
+                                   EGLNativePixmapType pix,
+                                   const struct native_config *nconf)
+{
+   struct dri2_surface *dri2surf;
+
+   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PIXMAP,
+         (Drawable) pix, nconf);
+   return (dri2surf) ? &dri2surf->base : NULL;
+}
+
+static struct native_surface *
+dri2_display_create_pbuffer_surface(struct native_display *ndpy,
+                                    const struct native_config *nconf,
+                                    uint width, uint height)
+{
+   struct dri2_surface *dri2surf;
+
+   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PBUFFER,
+         (Drawable) None, nconf);
+   if (dri2surf) {
+      dri2surf->width = width;
+      dri2surf->height = height;
+   }
+   return (dri2surf) ? &dri2surf->base : NULL;
+}
+
+static struct pipe_context *
+dri2_display_create_context(struct native_display *ndpy, void *context_private)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+   struct pipe_context *pctx;
+
+   pctx = dri2dpy->api->create_context(dri2dpy->api, dri2dpy->base.screen);
+   if (pctx)
+      pctx->priv = context_private;
+   return pctx;
+}
+
+static int
+choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32])
+{
+   int count = 0;
+
+   switch (mode->rgbBits) {
+   case 32:
+      formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
+      formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
+      break;
+   case 24:
+      formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM;
+      formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM;
+      formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
+      formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
+      break;
+   case 16:
+      formats[count++] = PIPE_FORMAT_R5G6B5_UNORM;
+      break;
+   default:
+      break;
+   }
+
+   return count;
+}
+
+static int
+choose_depth_stencil_format(const __GLcontextModes *mode,
+                            enum pipe_format formats[32])
+{
+   int count = 0;
+
+   switch (mode->depthBits) {
+   case 32:
+      formats[count++] = PIPE_FORMAT_Z32_UNORM;
+      break;
+   case 24:
+      if (mode->stencilBits) {
+         formats[count++] = PIPE_FORMAT_S8Z24_UNORM;
+         formats[count++] = PIPE_FORMAT_Z24S8_UNORM;
+      }
+      else {
+         formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
+         formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
+      }
+      break;
+   case 16:
+      formats[count++] = PIPE_FORMAT_Z16_UNORM;
+      break;
+   default:
+      break;
+   }
+
+   return count;
+}
+
+static boolean
+is_format_supported(struct pipe_screen *screen,
+                    enum pipe_format fmt, boolean is_color)
+{
+   return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D,
+         (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
+         PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+}
+
+static boolean
+dri2_display_convert_config(struct native_display *ndpy,
+                            const __GLcontextModes *mode,
+                            struct native_config *nconf)
+{
+   enum pipe_format formats[32];
+   int num_formats, i;
+
+   if (!(mode->renderType & GLX_RGBA_BIT) || !mode->rgbMode)
+      return FALSE;
+
+   /* skip single-buffered configs */
+   if (!mode->doubleBufferMode)
+      return FALSE;
+
+   nconf->mode = *mode;
+   nconf->mode.renderType = GLX_RGBA_BIT;
+   nconf->mode.rgbMode = TRUE;
+   /* pbuffer is allocated locally and is always supported */
+   nconf->mode.drawableType |= GLX_PBUFFER_BIT;
+   /* the swap method is always copy */
+   nconf->mode.swapMethod = GLX_SWAP_COPY_OML;
+
+   /* fix up */
+   nconf->mode.rgbBits =
+      nconf->mode.redBits + nconf->mode.greenBits +
+      nconf->mode.blueBits + nconf->mode.alphaBits;
+   if (!(nconf->mode.drawableType & GLX_WINDOW_BIT)) {
+      nconf->mode.visualID = 0;
+      nconf->mode.visualType = GLX_NONE;
+   }
+   if (!(nconf->mode.drawableType & GLX_PBUFFER_BIT)) {
+      nconf->mode.bindToTextureRgb = FALSE;
+      nconf->mode.bindToTextureRgba = FALSE;
+   }
+
+   nconf->color_format = PIPE_FORMAT_NONE;
+   nconf->depth_format = PIPE_FORMAT_NONE;
+   nconf->stencil_format = PIPE_FORMAT_NONE;
+
+   /* choose color format */
+   num_formats = choose_color_format(mode, formats);
+   for (i = 0; i < num_formats; i++) {
+      if (is_format_supported(ndpy->screen, formats[i], TRUE)) {
+         nconf->color_format = formats[i];
+         break;
+      }
+   }
+   if (nconf->color_format == PIPE_FORMAT_NONE)
+      return FALSE;
+
+   /* choose depth/stencil format */
+   num_formats = choose_depth_stencil_format(mode, formats);
+   for (i = 0; i < num_formats; i++) {
+      if (is_format_supported(ndpy->screen, formats[i], FALSE)) {
+         nconf->depth_format = formats[i];
+         nconf->stencil_format = formats[i];
+         break;
+      }
+   }
+   if ((nconf->mode.depthBits && nconf->depth_format == PIPE_FORMAT_NONE) ||
+       (nconf->mode.stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE))
+      return FALSE;
+
+   return TRUE;
+}
+
+static const struct native_config **
+dri2_display_get_configs(struct native_display *ndpy, int *num_configs)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+   const struct native_config **configs;
+   int i;
+
+   /* first time */
+   if (!dri2dpy->configs) {
+      const __GLcontextModes *modes;
+      int num_modes, count;
+
+      modes = x11_screen_get_glx_configs(dri2dpy->xscr);
+      if (!modes)
+         return NULL;
+      num_modes = x11_context_modes_count(modes);
+
+      dri2dpy->configs = calloc(num_modes, sizeof(*dri2dpy->configs));
+      if (!dri2dpy->configs)
+         return NULL;
+
+      count = 0;
+      for (i = 0; i < num_modes; i++) {
+         struct native_config *nconf = &dri2dpy->configs[count].base;
+         if (dri2_display_convert_config(&dri2dpy->base, modes, nconf))
+            count++;
+         modes = modes->next;
+      }
+
+      dri2dpy->num_configs = count;
+   }
+
+   configs = malloc(dri2dpy->num_configs * sizeof(*configs));
+   if (configs) {
+      for (i = 0; i < dri2dpy->num_configs; i++)
+         configs[i] = (const struct native_config *) &dri2dpy->configs[i];
+      if (num_configs)
+         *num_configs = dri2dpy->num_configs;
+   }
+
+   return configs;
+}
+
+static boolean
+dri2_display_is_pixmap_supported(struct native_display *ndpy,
+                                 EGLNativePixmapType pix,
+                                 const struct native_config *nconf)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+   uint depth, nconf_depth;
+
+   depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix);
+   nconf_depth = util_format_get_blocksizebits(nconf->color_format);
+
+   /* simple depth match for now */
+   return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth));
+}
+
+static void
+dri2_display_destroy(struct native_display *ndpy)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+
+   if (dri2dpy->configs)
+      free(dri2dpy->configs);
+
+   if (dri2dpy->base.screen)
+      dri2dpy->base.screen->destroy(dri2dpy->base.screen);
+
+   if (dri2dpy->xscr)
+      x11_screen_destroy(dri2dpy->xscr);
+   if (dri2dpy->own_dpy)
+      XCloseDisplay(dri2dpy->dpy);
+   if (dri2dpy->api && dri2dpy->api->destroy)
+      dri2dpy->api->destroy(dri2dpy->api);
+   free(dri2dpy);
+}
+
+/**
+ * Initialize DRI2 and pipe screen.
+ */
+static boolean
+dri2_display_init_screen(struct native_display *ndpy)
+{
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+   const char *driver = dri2dpy->api->name;
+   struct drm_create_screen_arg arg;
+   int fd;
+
+   if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) ||
+       !x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_GLX)) {
+      _eglLog(_EGL_WARNING, "GLX/DRI2 is not supported");
+      return FALSE;
+   }
+
+   fd = x11_screen_enable_dri2(dri2dpy->xscr, driver);
+   if (fd < 0)
+      return FALSE;
+
+   memset(&arg, 0, sizeof(arg));
+   arg.mode = DRM_CREATE_NORMAL;
+   dri2dpy->base.screen = dri2dpy->api->create_screen(dri2dpy->api, fd, &arg);
+   if (!dri2dpy->base.screen) {
+      _eglLog(_EGL_WARNING, "failed to create DRM screen");
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+struct native_display *
+x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
+{
+   struct dri2_display *dri2dpy;
+
+   dri2dpy = CALLOC_STRUCT(dri2_display);
+   if (!dri2dpy)
+      return NULL;
+
+   dri2dpy->api = api;
+   if (!dri2dpy->api) {
+      _eglLog(_EGL_WARNING, "failed to create DRM API");
+      free(dri2dpy);
+      return NULL;
+   }
+
+   dri2dpy->dpy = dpy;
+   if (!dri2dpy->dpy) {
+      dri2dpy->dpy = XOpenDisplay(NULL);
+      if (!dri2dpy->dpy) {
+         dri2_display_destroy(&dri2dpy->base);
+         return NULL;
+      }
+      dri2dpy->own_dpy = TRUE;
+   }
+
+   dri2dpy->xscr_number = DefaultScreen(dri2dpy->dpy);
+   dri2dpy->xscr = x11_screen_create(dri2dpy->dpy, dri2dpy->xscr_number);
+   if (!dri2dpy->xscr) {
+      dri2_display_destroy(&dri2dpy->base);
+      return NULL;
+   }
+
+   if (!dri2_display_init_screen(&dri2dpy->base)) {
+      dri2_display_destroy(&dri2dpy->base);
+      return NULL;
+   }
+
+   dri2dpy->base.destroy = dri2_display_destroy;
+   dri2dpy->base.get_configs = dri2_display_get_configs;
+   dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
+   dri2dpy->base.create_context = dri2_display_create_context;
+   dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
+   dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
+   dri2dpy->base.create_pbuffer_surface = dri2_display_create_pbuffer_surface;
+
+   return &dri2dpy->base;
+}
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c
new file mode 100644 (file)
index 0000000..695ab88
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <string.h>
+#include "util/u_debug.h"
+#include "util/u_memory.h"
+#include "state_tracker/drm_api.h"
+#include "egllog.h"
+
+#include "native_x11.h"
+#include "x11_screen.h"
+
+#define X11_PROBE_MAGIC 0x11980BE /* "X11PROBE" */
+
+static struct drm_api *api;
+
+static void
+x11_probe_destroy(struct native_probe *nprobe)
+{
+   if (nprobe->data)
+      free(nprobe->data);
+   free(nprobe);
+}
+
+struct native_probe *
+native_create_probe(EGLNativeDisplayType dpy)
+{
+   struct native_probe *nprobe;
+   struct x11_screen *xscr;
+   int scr;
+   const char *driver_name = NULL;
+   Display *xdpy;
+
+   nprobe = CALLOC_STRUCT(native_probe);
+   if (!nprobe)
+      return NULL;
+
+   xdpy = dpy;
+   if (!xdpy) {
+      xdpy = XOpenDisplay(NULL);
+      if (!xdpy) {
+         free(nprobe);
+         return NULL;
+      }
+   }
+
+   scr = DefaultScreen(xdpy);
+   xscr = x11_screen_create(xdpy, scr);
+   if (xscr) {
+      if (x11_screen_support(xscr, X11_SCREEN_EXTENSION_DRI2)) {
+         driver_name = x11_screen_probe_dri2(xscr);
+         nprobe->data = strdup(driver_name);
+      }
+
+      x11_screen_destroy(xscr);
+   }
+
+   if (xdpy != dpy)
+      XCloseDisplay(xdpy);
+
+   nprobe->magic = X11_PROBE_MAGIC;
+   nprobe->display = dpy;
+
+   nprobe->destroy = x11_probe_destroy;
+
+   return nprobe;
+}
+
+enum native_probe_result
+native_get_probe_result(struct native_probe *nprobe)
+{
+   if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
+      return NATIVE_PROBE_UNKNOWN;
+
+   if (!api)
+      api = drm_api_create();
+
+   /* this is a software driver */
+   if (!api)
+      return NATIVE_PROBE_SUPPORTED;
+
+   /* the display does not support DRI2 or the driver mismatches */
+   if (!nprobe->data || strcmp(api->name, (const char *) nprobe->data) != 0)
+      return NATIVE_PROBE_FALLBACK;
+
+   return NATIVE_PROBE_EXACT;
+}
+
+const char *
+native_get_name(void)
+{
+   static char x11_name[32];
+
+   if (!api)
+      api = drm_api_create();
+
+   if (api)
+      snprintf(x11_name, sizeof(x11_name), "X11/%s", api->name);
+   else
+      snprintf(x11_name, sizeof(x11_name), "X11");
+
+   return x11_name;
+}
+
+struct native_display *
+native_create_display(EGLNativeDisplayType dpy)
+{
+   struct native_display *ndpy = NULL;
+   boolean force_sw;
+
+   if (!api)
+      api = drm_api_create();
+
+   force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
+   if (api && !force_sw) {
+      ndpy = x11_create_dri2_display(dpy, api);
+   }
+
+   if (!ndpy) {
+      EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING;
+
+      _eglLog(level, "use software fallback");
+      ndpy = x11_create_ximage_display(dpy, TRUE);
+   }
+
+   return ndpy;
+}
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h
new file mode 100644 (file)
index 0000000..622ddac
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _NATIVE_X11_H_
+#define _NATIVE_X11_H_
+
+#include "state_tracker/drm_api.h"
+#include "common/native.h"
+
+struct native_display *
+x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm);
+
+struct native_display *
+x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api);
+
+#endif /* _NATIVE_X11_H_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
new file mode 100644 (file)
index 0000000..dfa8df2
--- /dev/null
@@ -0,0 +1,694 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <assert.h>
+#include <sys/ipc.h>
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XShm.h>
+#include "util/u_memory.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "pipe/p_compiler.h"
+#include "pipe/internal/p_winsys_screen.h"
+#include "softpipe/sp_winsys.h"
+#include "egllog.h"
+
+#include "sw_winsys.h"
+#include "native_x11.h"
+#include "x11_screen.h"
+
+enum ximage_surface_type {
+   XIMAGE_SURFACE_TYPE_WINDOW,
+   XIMAGE_SURFACE_TYPE_PIXMAP,
+   XIMAGE_SURFACE_TYPE_PBUFFER
+};
+
+struct ximage_display {
+   struct native_display base;
+   Display *dpy;
+   boolean own_dpy;
+
+   struct x11_screen *xscr;
+   int xscr_number;
+
+   boolean use_xshm;
+
+   struct pipe_winsys *winsys;
+   struct ximage_config *configs;
+   int num_configs;
+};
+
+struct ximage_buffer {
+   XImage *ximage;
+
+   struct pipe_texture *texture;
+   XShmSegmentInfo *shm_info;
+   boolean xshm_attached;
+};
+
+struct ximage_surface {
+   struct native_surface base;
+   Drawable drawable;
+   enum ximage_surface_type type;
+   enum pipe_format color_format;
+   XVisualInfo visual;
+   struct ximage_display *xdpy;
+
+   int width, height;
+   GC gc;
+
+   struct ximage_buffer buffers[NUM_NATIVE_ATTACHMENTS];
+   unsigned int sequence_number;
+};
+
+struct ximage_config {
+   struct native_config base;
+   const XVisualInfo *visual;
+};
+
+static INLINE struct ximage_display *
+ximage_display(const struct native_display *ndpy)
+{
+   return (struct ximage_display *) ndpy;
+}
+
+static INLINE struct ximage_surface *
+ximage_surface(const struct native_surface *nsurf)
+{
+   return (struct ximage_surface *) nsurf;
+}
+
+static INLINE struct ximage_config *
+ximage_config(const struct native_config *nconf)
+{
+   return (struct ximage_config *) nconf;
+}
+
+static void
+ximage_surface_free_buffer(struct native_surface *nsurf,
+                           enum native_attachment which)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   struct ximage_buffer *xbuf = &xsurf->buffers[which];
+
+   pipe_texture_reference(&xbuf->texture, NULL);
+
+   if (xbuf->shm_info) {
+      if (xbuf->xshm_attached)
+         XShmDetach(xsurf->xdpy->dpy, xbuf->shm_info);
+      if (xbuf->shm_info->shmaddr != (void *) -1)
+         shmdt(xbuf->shm_info->shmaddr);
+      if (xbuf->shm_info->shmid != -1)
+         shmctl(xbuf->shm_info->shmid, IPC_RMID, 0);
+
+      xbuf->shm_info->shmaddr = (void *) -1;
+      xbuf->shm_info->shmid = -1;
+   }
+}
+
+static boolean
+ximage_surface_alloc_buffer(struct native_surface *nsurf,
+                            enum native_attachment which)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   struct ximage_buffer *xbuf = &xsurf->buffers[which];
+   struct pipe_screen *screen = xsurf->xdpy->base.screen;
+   struct pipe_texture templ;
+
+   /* free old data */
+   if (xbuf->texture)
+      ximage_surface_free_buffer(&xsurf->base, which);
+
+   memset(&templ, 0, sizeof(templ));
+   templ.target = PIPE_TEXTURE_2D;
+   templ.format = xsurf->color_format;
+   templ.width0 = xsurf->width;
+   templ.height0 = xsurf->height;
+   templ.depth0 = 1;
+   templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+   if (xbuf->shm_info) {
+      struct pipe_buffer *pbuf;
+      unsigned stride, size;
+      void *addr = NULL;
+
+      stride = util_format_get_stride(xsurf->color_format, xsurf->width);
+      /* alignment should depend on visual? */
+      stride = align(stride, 4);
+      size = stride * xsurf->height;
+
+      /* create and attach shm object */
+      xbuf->shm_info->shmid = shmget(IPC_PRIVATE, size, 0755);
+      if (xbuf->shm_info->shmid != -1) {
+         xbuf->shm_info->shmaddr =
+            shmat(xbuf->shm_info->shmid, NULL, 0);
+         if (xbuf->shm_info->shmaddr != (void *) -1) {
+            if (XShmAttach(xsurf->xdpy->dpy, xbuf->shm_info)) {
+               addr = xbuf->shm_info->shmaddr;
+               xbuf->xshm_attached = TRUE;
+            }
+         }
+      }
+
+      if (addr) {
+         pbuf = screen->user_buffer_create(screen, addr, size);
+         if (pbuf) {
+            xbuf->texture =
+               screen->texture_blanket(screen, &templ, &stride, pbuf);
+            pipe_buffer_reference(&pbuf, NULL);
+         }
+      }
+   }
+   else {
+      xbuf->texture = screen->texture_create(screen, &templ);
+   }
+
+   /* clean up the buffer if allocation failed */
+   if (!xbuf->texture)
+      ximage_surface_free_buffer(&xsurf->base, which);
+
+   return (xbuf->texture != NULL);
+}
+
+static boolean
+ximage_surface_draw_buffer(struct native_surface *nsurf,
+                           enum native_attachment which)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   struct ximage_buffer *xbuf = &xsurf->buffers[which];
+   struct pipe_screen *screen = xsurf->xdpy->base.screen;
+   struct pipe_transfer *transfer;
+
+   if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER)
+      return TRUE;
+
+   assert(xsurf->drawable && xbuf->ximage && xbuf->texture);
+
+   transfer = screen->get_tex_transfer(screen, xbuf->texture,
+         0, 0, 0, PIPE_TRANSFER_READ, 0, 0, xsurf->width, xsurf->height);
+   if (!transfer)
+      return FALSE;
+
+   xbuf->ximage->bytes_per_line = transfer->stride;
+   xbuf->ximage->data = screen->transfer_map(screen, transfer);
+   if (!xbuf->ximage->data) {
+      screen->tex_transfer_destroy(transfer);
+      return FALSE;
+   }
+
+
+   if (xbuf->shm_info)
+      XShmPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
+            xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height, False);
+   else
+      XPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
+            xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height);
+
+   xbuf->ximage->data = NULL;
+   screen->transfer_unmap(screen, transfer);
+
+   /*
+    * softpipe allows the pipe transfer to be re-used, but we don't want to
+    * rely on that behavior.
+    */
+   screen->tex_transfer_destroy(transfer);
+
+   XSync(xsurf->xdpy->dpy, FALSE);
+
+   return TRUE;
+}
+
+static boolean
+ximage_surface_flush_frontbuffer(struct native_surface *nsurf)
+{
+   return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+}
+
+static boolean
+ximage_surface_swap_buffers(struct native_surface *nsurf)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   struct ximage_buffer *xfront, *xback, xtmp;
+
+   xfront = &xsurf->buffers[NATIVE_ATTACHMENT_FRONT_LEFT];
+   xback = &xsurf->buffers[NATIVE_ATTACHMENT_BACK_LEFT];
+
+   /* draw the back buffer directly if there is no front buffer */
+   if (!xfront->texture)
+      return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_BACK_LEFT);
+
+   /* swap the buffers */
+   xtmp = *xfront;
+   *xfront = *xback;
+   *xback = xtmp;
+
+   /* the front/back textures are swapped */
+   xsurf->sequence_number++;
+
+   return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+}
+
+static void
+ximage_surface_update_geometry(struct native_surface *nsurf)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   Status ok;
+   Window root;
+   int x, y;
+   unsigned int w, h, border, depth;
+
+   /* pbuffer has fixed geometry */
+   if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER)
+      return;
+
+   ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable,
+         &root, &x, &y, &w, &h, &border, &depth);
+   if (ok) {
+      xsurf->width = w;
+      xsurf->height = h;
+   }
+}
+
+static boolean
+ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask,
+                        unsigned int *seq_num, struct pipe_texture **textures,
+                        int *width, int *height)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   boolean new_buffers = FALSE;
+   int att;
+
+   ximage_surface_update_geometry(&xsurf->base);
+
+   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+      struct ximage_buffer *xbuf = &xsurf->buffers[att];
+
+      /* delay the allocation */
+      if (!native_attachment_mask_test(attachment_mask, att))
+         continue;
+
+      /* reallocate the texture */
+      if (!xbuf->texture ||
+          xsurf->width != xbuf->texture->width0 ||
+          xsurf->height != xbuf->texture->height0) {
+         new_buffers = TRUE;
+         if (ximage_surface_alloc_buffer(&xsurf->base, att)) {
+            /* update ximage */
+            if (xbuf->ximage) {
+               xbuf->ximage->width = xsurf->width;
+               xbuf->ximage->height = xsurf->height;
+            }
+         }
+      }
+
+      if (textures) {
+         textures[att] = NULL;
+         pipe_texture_reference(&textures[att], xbuf->texture);
+      }
+   }
+
+   /* increase the sequence number so that caller knows */
+   if (new_buffers)
+      xsurf->sequence_number++;
+
+   if (seq_num)
+      *seq_num = xsurf->sequence_number;
+   if (width)
+      *width = xsurf->width;
+   if (height)
+      *height = xsurf->height;
+
+   return TRUE;
+}
+
+static void
+ximage_surface_wait(struct native_surface *nsurf)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   XSync(xsurf->xdpy->dpy, FALSE);
+   /* TODO XGetImage and update the front texture */
+}
+
+static void
+ximage_surface_destroy(struct native_surface *nsurf)
+{
+   struct ximage_surface *xsurf = ximage_surface(nsurf);
+   int i;
+
+   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
+      struct ximage_buffer *xbuf = &xsurf->buffers[i];
+      ximage_surface_free_buffer(&xsurf->base, i);
+      /* xbuf->shm_info is owned by xbuf->ximage? */
+      if (xbuf->ximage) {
+         XDestroyImage(xbuf->ximage);
+         xbuf->ximage = NULL;
+      }
+   }
+
+   if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER)
+      XFreeGC(xsurf->xdpy->dpy, xsurf->gc);
+   free(xsurf);
+}
+
+static struct ximage_surface *
+ximage_display_create_surface(struct native_display *ndpy,
+                              enum ximage_surface_type type,
+                              Drawable drawable,
+                              const struct native_config *nconf)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+   struct ximage_config *xconf = ximage_config(nconf);
+   struct ximage_surface *xsurf;
+   int i;
+
+   xsurf = CALLOC_STRUCT(ximage_surface);
+   if (!xsurf)
+      return NULL;
+
+   xsurf->xdpy = xdpy;
+   xsurf->type = type;
+   xsurf->color_format = xconf->base.color_format;
+   xsurf->drawable = drawable;
+
+   if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) {
+      xsurf->drawable = drawable;
+      xsurf->visual = *xconf->visual;
+
+      xsurf->gc = XCreateGC(xdpy->dpy, xsurf->drawable, 0, NULL);
+      if (!xsurf->gc) {
+         free(xsurf);
+         return NULL;
+      }
+
+      for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
+         struct ximage_buffer *xbuf = &xsurf->buffers[i];
+
+         if (xdpy->use_xshm) {
+            xbuf->shm_info = calloc(1, sizeof(*xbuf->shm_info));
+            if (xbuf->shm_info) {
+               /* initialize shm info */
+               xbuf->shm_info->shmid = -1;
+               xbuf->shm_info->shmaddr = (void *) -1;
+               xbuf->shm_info->readOnly = TRUE;
+
+               xbuf->ximage = XShmCreateImage(xsurf->xdpy->dpy,
+                     xsurf->visual.visual,
+                     xsurf->visual.depth,
+                     ZPixmap, NULL,
+                     xbuf->shm_info,
+                     0, 0);
+            }
+         }
+         else {
+            xbuf->ximage = XCreateImage(xsurf->xdpy->dpy,
+                  xsurf->visual.visual,
+                  xsurf->visual.depth,
+                  ZPixmap, 0,   /* format, offset */
+                  NULL,         /* data */
+                  0, 0,         /* size */
+                  8,            /* bitmap_pad */
+                  0);           /* bytes_per_line */
+         }
+
+         if (!xbuf->ximage) {
+            XFreeGC(xdpy->dpy, xsurf->gc);
+            free(xsurf);
+            return NULL;
+         }
+      }
+   }
+
+   xsurf->base.destroy = ximage_surface_destroy;
+   xsurf->base.swap_buffers = ximage_surface_swap_buffers;
+   xsurf->base.flush_frontbuffer = ximage_surface_flush_frontbuffer;
+   xsurf->base.validate = ximage_surface_validate;
+   xsurf->base.wait = ximage_surface_wait;
+
+   return xsurf;
+}
+
+static struct native_surface *
+ximage_display_create_window_surface(struct native_display *ndpy,
+                                     EGLNativeWindowType win,
+                                     const struct native_config *nconf)
+{
+   struct ximage_surface *xsurf;
+
+   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_WINDOW,
+         (Drawable) win, nconf);
+   return (xsurf) ? &xsurf->base : NULL;
+}
+
+static struct native_surface *
+ximage_display_create_pixmap_surface(struct native_display *ndpy,
+                                     EGLNativePixmapType pix,
+                                     const struct native_config *nconf)
+{
+   struct ximage_surface *xsurf;
+
+   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PIXMAP,
+         (Drawable) pix, nconf);
+   return (xsurf) ? &xsurf->base : NULL;
+}
+
+static struct native_surface *
+ximage_display_create_pbuffer_surface(struct native_display *ndpy,
+                                      const struct native_config *nconf,
+                                      uint width, uint height)
+{
+   struct ximage_surface *xsurf;
+
+   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PBUFFER,
+         (Drawable) None, nconf);
+   if (xsurf) {
+      xsurf->width = width;
+      xsurf->height = height;
+   }
+   return (xsurf) ? &xsurf->base : NULL;
+}
+
+static struct pipe_context *
+ximage_display_create_context(struct native_display *ndpy,
+                              void *context_private)
+{
+   struct pipe_context *pctx = softpipe_create(ndpy->screen);
+   if (pctx)
+      pctx->priv = context_private;
+   return pctx;
+}
+
+static enum pipe_format
+choose_format(const XVisualInfo *vinfo)
+{
+   enum pipe_format fmt;
+   /* TODO elaborate the formats */
+   switch (vinfo->depth) {
+   case 32:
+      fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
+      break;
+   case 24:
+      fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
+      break;
+   case 16:
+      fmt = PIPE_FORMAT_R5G6B5_UNORM;
+      break;
+   default:
+      fmt = PIPE_FORMAT_NONE;
+      break;
+   }
+
+   return fmt;
+}
+
+static const struct native_config **
+ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+   const struct native_config **configs;
+   int i;
+
+   /* first time */
+   if (!xdpy->configs) {
+      const XVisualInfo *visuals;
+      int num_visuals, count, j;
+
+      visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals);
+      if (!visuals)
+         return NULL;
+
+      /*
+       * Create two configs for each visual.
+       * One with depth/stencil buffer; one without
+       */
+      xdpy->configs = calloc(num_visuals * 2, sizeof(*xdpy->configs));
+      if (!xdpy->configs)
+         return NULL;
+
+      count = 0;
+      for (i = 0; i < num_visuals; i++) {
+         for (j = 0; j < 2; j++) {
+            struct ximage_config *xconf = &xdpy->configs[count];
+            __GLcontextModes *mode = &xconf->base.mode;
+
+            xconf->visual = &visuals[i];
+            xconf->base.color_format = choose_format(xconf->visual);
+            if (xconf->base.color_format == PIPE_FORMAT_NONE)
+               continue;
+
+            x11_screen_convert_visual(xdpy->xscr, xconf->visual, mode);
+            /* support double buffer mode */
+            mode->doubleBufferMode = TRUE;
+
+            xconf->base.depth_format = PIPE_FORMAT_NONE;
+            xconf->base.stencil_format = PIPE_FORMAT_NONE;
+            /* create the second config with depth/stencil buffer */
+            if (j == 1) {
+               xconf->base.depth_format = PIPE_FORMAT_S8Z24_UNORM;
+               xconf->base.stencil_format = PIPE_FORMAT_S8Z24_UNORM;
+               mode->depthBits = 24;
+               mode->stencilBits = 8;
+               mode->haveDepthBuffer = TRUE;
+               mode->haveStencilBuffer = TRUE;
+            }
+
+            mode->maxPbufferWidth = 4096;
+            mode->maxPbufferHeight = 4096;
+            mode->maxPbufferPixels = 4096 * 4096;
+            mode->drawableType =
+               GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
+            mode->swapMethod = GLX_SWAP_EXCHANGE_OML;
+
+            if (mode->alphaBits)
+               mode->bindToTextureRgba = TRUE;
+            else
+               mode->bindToTextureRgb = TRUE;
+
+            count++;
+         }
+      }
+
+      xdpy->num_configs = count;
+   }
+
+   configs = malloc(xdpy->num_configs * sizeof(*configs));
+   if (configs) {
+      for (i = 0; i < xdpy->num_configs; i++)
+         configs[i] = (const struct native_config *) &xdpy->configs[i];
+      if (num_configs)
+         *num_configs = xdpy->num_configs;
+   }
+   return configs;
+}
+
+static boolean
+ximage_display_is_pixmap_supported(struct native_display *ndpy,
+                                   EGLNativePixmapType pix,
+                                   const struct native_config *nconf)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+   enum pipe_format fmt;
+   uint depth;
+
+   depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix);
+   switch (depth) {
+   case 32:
+      fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
+      break;
+   case 24:
+      fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
+      break;
+   case 16:
+      fmt = PIPE_FORMAT_R5G6B5_UNORM;
+      break;
+   default:
+      fmt = PIPE_FORMAT_NONE;
+      break;
+   }
+
+   return (fmt == nconf->color_format);
+}
+
+static void
+ximage_display_destroy(struct native_display *ndpy)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+
+   if (xdpy->configs)
+      free(xdpy->configs);
+
+   xdpy->base.screen->destroy(xdpy->base.screen);
+   free(xdpy->winsys);
+
+   x11_screen_destroy(xdpy->xscr);
+   if (xdpy->own_dpy)
+      XCloseDisplay(xdpy->dpy);
+   free(xdpy);
+}
+
+struct native_display *
+x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm)
+{
+   struct ximage_display *xdpy;
+
+   xdpy = CALLOC_STRUCT(ximage_display);
+   if (!xdpy)
+      return NULL;
+
+   xdpy->dpy = dpy;
+   if (!xdpy->dpy) {
+      xdpy->dpy = XOpenDisplay(NULL);
+      if (!xdpy->dpy) {
+         free(xdpy);
+         return NULL;
+      }
+      xdpy->own_dpy = TRUE;
+   }
+
+   xdpy->xscr_number = DefaultScreen(xdpy->dpy);
+   xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
+   if (!xdpy->xscr) {
+      free(xdpy);
+      return NULL;
+   }
+
+   xdpy->use_xshm =
+      (use_xshm && x11_screen_support(xdpy->xscr, X11_SCREEN_EXTENSION_XSHM));
+
+   xdpy->winsys = create_sw_winsys();
+   xdpy->base.screen = softpipe_create_screen(xdpy->winsys);
+
+   xdpy->base.destroy = ximage_display_destroy;
+
+   xdpy->base.get_configs = ximage_display_get_configs;
+   xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported;
+   xdpy->base.create_context = ximage_display_create_context;
+   xdpy->base.create_window_surface = ximage_display_create_window_surface;
+   xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface;
+   xdpy->base.create_pbuffer_surface = ximage_display_create_pbuffer_surface;
+
+   return &xdpy->base;
+}
diff --git a/src/gallium/state_trackers/egl/x11/sw_winsys.c b/src/gallium/state_trackers/egl/x11/sw_winsys.c
new file mode 100644 (file)
index 0000000..6ee3ede
--- /dev/null
@@ -0,0 +1,231 @@
+/**************************************************************************
+ * 
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
+ **************************************************************************/
+
+/**
+ * Totally software-based winsys layer.
+ * Note that the one winsys function that we can't implement here
+ * is flush_frontbuffer().
+ * Whoever uses this code will have to provide that.
+ *
+ * Authors: Brian Paul
+ */
+
+
+#include "pipe/internal/p_winsys_screen.h"
+#include "pipe/p_state.h"
+#include "pipe/p_inlines.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "sw_winsys.h"
+
+
+
+/** Subclass of pipe_winsys */
+struct sw_pipe_winsys
+{
+   struct pipe_winsys Base;
+   /* no extra fields for now */
+};
+
+
+/** subclass of pipe_buffer */
+struct sw_pipe_buffer
+{
+   struct pipe_buffer Base;
+   boolean UserBuffer;  /** Is this a user-space buffer? */
+   void *Data;
+   void *Mapped;
+};
+
+
+/** cast wrapper */
+static INLINE struct sw_pipe_buffer *
+sw_pipe_buffer(struct pipe_buffer *b)
+{
+   return (struct sw_pipe_buffer *) b;
+}
+
+
+static const char *
+get_name(struct pipe_winsys *pws)
+{
+   return "software";
+}
+
+
+/** Create new pipe_buffer and allocate storage of given size */
+static struct pipe_buffer *
+buffer_create(struct pipe_winsys *pws, 
+              unsigned alignment, 
+              unsigned usage,
+              unsigned size)
+{
+   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
+   if (!buffer)
+      return NULL;
+
+   pipe_reference_init(&buffer->Base.reference, 1);
+   buffer->Base.alignment = alignment;
+   buffer->Base.usage = usage;
+   buffer->Base.size = size;
+
+   /* align to 16-byte multiple for Cell */
+   buffer->Data = align_malloc(size, MAX2(alignment, 16));
+
+   return &buffer->Base;
+}
+
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_buffer *
+user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
+{
+   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
+   if (!buffer)
+      return NULL;
+
+   pipe_reference_init(&buffer->Base.reference, 1);
+   buffer->Base.size = bytes;
+   buffer->UserBuffer = TRUE;
+   buffer->Data = ptr;
+
+   return &buffer->Base;
+}
+
+
+static void *
+buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
+{
+   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
+   buffer->Mapped = buffer->Data;
+   return buffer->Mapped;
+}
+
+
+static void
+buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
+{
+   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
+   buffer->Mapped = NULL;
+}
+
+
+static void
+buffer_destroy(struct pipe_buffer *buf)
+{
+   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
+
+   if (buffer->Data && !buffer->UserBuffer) {
+      align_free(buffer->Data);
+      buffer->Data = NULL;
+   }
+
+   free(buffer);
+}
+
+
+static struct pipe_buffer *
+surface_buffer_create(struct pipe_winsys *winsys,
+                      unsigned width, unsigned height,
+                      enum pipe_format format, 
+                      unsigned usage,
+                      unsigned tex_usage,
+                      unsigned *stride)
+{
+   const unsigned alignment = 64;
+   unsigned nblocksy;
+
+   nblocksy = util_format_get_nblocksy(format, height);
+   *stride = align(util_format_get_stride(format, width), alignment);
+
+   return winsys->buffer_create(winsys, alignment,
+                                usage,
+                                *stride * nblocksy);
+}
+
+
+static void
+fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
+                struct pipe_fence_handle *fence)
+{
+   /* no-op */
+}
+
+
+static int
+fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+                unsigned flag)
+{
+   /* no-op */
+   return 0;
+}
+
+
+static int
+fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+             unsigned flag)
+{
+   /* no-op */
+   return 0;
+}
+
+
+/**
+ * Create/return a new pipe_winsys object.
+ */
+struct pipe_winsys *
+create_sw_winsys(void)
+{
+   struct sw_pipe_winsys *ws = CALLOC_STRUCT(sw_pipe_winsys);
+   if (!ws)
+      return NULL;
+
+   /* Fill in this struct with callbacks that pipe will need to
+    * communicate with the window system, buffer manager, etc. 
+    */
+   ws->Base.buffer_create = buffer_create;
+   ws->Base.user_buffer_create = user_buffer_create;
+   ws->Base.buffer_map = buffer_map;
+   ws->Base.buffer_unmap = buffer_unmap;
+   ws->Base.buffer_destroy = buffer_destroy;
+
+   ws->Base.surface_buffer_create = surface_buffer_create;
+
+   ws->Base.fence_reference = fence_reference;
+   ws->Base.fence_signalled = fence_signalled;
+   ws->Base.fence_finish = fence_finish;
+
+   ws->Base.flush_frontbuffer = NULL; /* not implemented here! */
+
+   ws->Base.get_name = get_name;
+
+   return &ws->Base;
+}
diff --git a/src/gallium/state_trackers/egl/x11/sw_winsys.h b/src/gallium/state_trackers/egl/x11/sw_winsys.h
new file mode 100644 (file)
index 0000000..f96c5a1
--- /dev/null
@@ -0,0 +1,40 @@
+/**************************************************************************
+ * 
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
+ **************************************************************************/
+
+
+#ifndef SW_WINSYS_H
+#define SW_WINSYS_H
+
+
+struct pipe_winsys;
+
+
+extern struct pipe_winsys *
+create_sw_winsys(void);
+
+
+#endif /* SW_WINSYS_H */
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c
new file mode 100644 (file)
index 0000000..76ce45e
--- /dev/null
@@ -0,0 +1,453 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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 <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/XShm.h>
+#include "util/u_memory.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "xf86drm.h"
+#include "egllog.h"
+
+#include "x11_screen.h"
+#include "dri2.h"
+#include "glxinit.h"
+
+struct x11_screen {
+   Display *dpy;
+   int number;
+
+   /*
+    * This is used to fetch GLX visuals/fbconfigs.  It uses code from egl_xdri.
+    * It might be better to rewrite the part in Xlib or XCB.
+    */
+   __GLXdisplayPrivate *glx_dpy;
+
+   int dri_major, dri_minor;
+   char *dri_driver;
+   char *dri_device;
+   int dri_fd;
+
+   XVisualInfo *visuals;
+   int num_visuals;
+
+   /* cached values for x11_drawable_get_depth */
+   Drawable last_drawable;
+   unsigned int last_depth;
+};
+
+
+/**
+ * Create a X11 screen.
+ */
+struct x11_screen *
+x11_screen_create(Display *dpy, int screen)
+{
+   struct x11_screen *xscr;
+
+   if (screen >= ScreenCount(dpy))
+      return NULL;
+
+   xscr = CALLOC_STRUCT(x11_screen);
+   if (xscr) {
+      xscr->dpy = dpy;
+      xscr->number = screen;
+
+      xscr->dri_major = -1;
+      xscr->dri_fd = -1;
+   }
+   return xscr;
+}
+
+/**
+ * Destroy a X11 screen.
+ */
+void
+x11_screen_destroy(struct x11_screen *xscr)
+{
+   if (xscr->dri_fd >= 0)
+      close(xscr->dri_fd);
+   if (xscr->dri_driver)
+      Xfree(xscr->dri_driver);
+   if (xscr->dri_device)
+      Xfree(xscr->dri_device);
+
+   /* xscr->glx_dpy will be destroyed with the X display */
+
+   if (xscr->visuals)
+      XFree(xscr->visuals);
+   free(xscr);
+}
+
+static boolean
+x11_screen_init_dri2(struct x11_screen *xscr)
+{
+   if (xscr->dri_major < 0) {
+      int eventBase, errorBase;
+
+      if (!DRI2QueryExtension(xscr->dpy, &eventBase, &errorBase) ||
+          !DRI2QueryVersion(xscr->dpy, &xscr->dri_major, &xscr->dri_minor))
+         xscr->dri_major = -1;
+   }
+   return (xscr->dri_major >= 0);
+}
+
+static boolean
+x11_screen_init_glx(struct x11_screen *xscr)
+{
+   if (!xscr->glx_dpy)
+      xscr->glx_dpy = __glXInitialize(xscr->dpy);
+   return (xscr->glx_dpy != NULL);
+}
+
+/**
+ * Return true if the screen supports the extension.
+ */
+boolean
+x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext)
+{
+   boolean supported = FALSE;
+
+   switch (ext) {
+   case X11_SCREEN_EXTENSION_XSHM:
+      supported = XShmQueryExtension(xscr->dpy);
+      break;
+   case X11_SCREEN_EXTENSION_GLX:
+      supported = x11_screen_init_glx(xscr);
+      break;
+   case X11_SCREEN_EXTENSION_DRI2:
+      supported = x11_screen_init_dri2(xscr);
+      break;
+   default:
+      break;
+   }
+
+   return supported;
+}
+
+/**
+ * Return the X visuals.
+ */
+const XVisualInfo *
+x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals)
+{
+   if (!xscr->visuals) {
+      XVisualInfo vinfo_template;
+      vinfo_template.screen = xscr->number;
+      xscr->visuals = XGetVisualInfo(xscr->dpy, VisualScreenMask,
+            &vinfo_template, &xscr->num_visuals);
+   }
+
+   if (num_visuals)
+      *num_visuals = xscr->num_visuals;
+   return xscr->visuals;
+}
+
+void
+x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual,
+                          __GLcontextModes *mode)
+{
+   int r, g, b, a;
+   int visual_type;
+
+   r = util_bitcount(visual->red_mask);
+   g = util_bitcount(visual->green_mask);
+   b = util_bitcount(visual->blue_mask);
+   a = visual->depth - (r + g + b);
+#if defined(__cplusplus) || defined(c_plusplus)
+   visual_type = visual->c_class;
+#else
+   visual_type = visual->class;
+#endif
+
+   /* convert to GLX visual type */
+   switch (visual_type) {
+   case TrueColor:
+      visual_type = GLX_TRUE_COLOR;
+      break;
+   case DirectColor:
+      visual_type = GLX_DIRECT_COLOR;
+      break;
+   case PseudoColor:
+      visual_type = GLX_PSEUDO_COLOR;
+      break;
+   case StaticColor:
+      visual_type = GLX_STATIC_COLOR;
+      break;
+   case GrayScale:
+      visual_type = GLX_GRAY_SCALE;
+      break;
+   case StaticGray:
+      visual_type = GLX_STATIC_GRAY;
+      break;
+   default:
+      visual_type = GLX_NONE;
+      break;
+   }
+
+   mode->rgbBits = r + g + b + a;
+   mode->redBits = r;
+   mode->greenBits = g;
+   mode->blueBits = b;
+   mode->alphaBits = a;
+   mode->visualID = visual->visualid;
+   mode->visualType = visual_type;
+
+   /* sane defaults */
+   mode->renderType = GLX_RGBA_BIT;
+   mode->rgbMode = TRUE;
+   mode->visualRating = GLX_SLOW_CONFIG;
+   mode->xRenderable = TRUE;
+}
+
+/**
+ * Return the GLX fbconfigs.
+ */
+const __GLcontextModes *
+x11_screen_get_glx_configs(struct x11_screen *xscr)
+{
+   return (x11_screen_init_glx(xscr))
+      ? xscr->glx_dpy->screenConfigs[xscr->number].configs
+      : NULL;
+}
+
+/**
+ * Return the GLX visuals.
+ */
+const __GLcontextModes *
+x11_screen_get_glx_visuals(struct x11_screen *xscr)
+{
+   return (x11_screen_init_glx(xscr))
+      ? xscr->glx_dpy->screenConfigs[xscr->number].visuals
+      : NULL;
+}
+
+static boolean
+x11_screen_is_driver_equal(struct x11_screen *xscr, const char *driver)
+{
+   return (strcmp(xscr->dri_driver, driver) == 0);
+}
+
+/**
+ * Probe the screen for the DRI2 driver name.
+ */
+const char *
+x11_screen_probe_dri2(struct x11_screen *xscr)
+{
+   /* get the driver name and the device name */
+   if (!xscr->dri_driver) {
+      if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number),
+               &xscr->dri_driver, &xscr->dri_device))
+         xscr->dri_driver = xscr->dri_device = NULL;
+   }
+
+   return xscr->dri_driver;
+}
+
+/**
+ * Enable DRI2 and returns the file descriptor of the DRM device.  The file
+ * descriptor will be closed automatically when the screen is destoryed.
+ */
+int
+x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver)
+{
+   if (xscr->dri_fd < 0) {
+      int fd;
+      drm_magic_t magic;
+
+      /* get the driver name and the device name first */
+      if (!x11_screen_probe_dri2(xscr))
+         return -1;
+
+      if (!x11_screen_is_driver_equal(xscr, driver)) {
+         _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s",
+               xscr->dri_driver, driver);
+         return -1;
+      }
+
+      fd = open(xscr->dri_device, O_RDWR);
+      if (fd < 0) {
+         _eglLog(_EGL_WARNING, "failed to open %s", xscr->dri_device);
+         return -1;
+      }
+
+      memset(&magic, 0, sizeof(magic));
+      if (drmGetMagic(fd, &magic)) {
+         _eglLog(_EGL_WARNING, "failed to get magic");
+         close(fd);
+         return -1;
+      }
+
+      if (!DRI2Authenticate(xscr->dpy,
+               RootWindow(xscr->dpy, xscr->number), magic)) {
+         _eglLog(_EGL_WARNING, "failed to authenticate magic");
+         close(fd);
+         return -1;
+      }
+
+      xscr->dri_fd = fd;
+   }
+
+   return xscr->dri_fd;
+}
+
+/**
+ * Create/Destroy the DRI drawable.
+ */
+void
+x11_drawable_enable_dri2(struct x11_screen *xscr,
+                         Drawable drawable, boolean on)
+{
+   if (on)
+      DRI2CreateDrawable(xscr->dpy, drawable);
+   else
+      DRI2DestroyDrawable(xscr->dpy, drawable);
+}
+
+/**
+ * Copy between buffers of the DRI2 drawable.
+ */
+void
+x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
+                          int x, int y, int width, int height,
+                          int src_buf, int dst_buf)
+{
+   XRectangle rect;
+   XserverRegion region;
+
+   rect.x = x;
+   rect.y = y;
+   rect.width = width;
+   rect.height = height;
+
+   region = XFixesCreateRegion(xscr->dpy, &rect, 1);
+   DRI2CopyRegion(xscr->dpy, drawable, region, dst_buf, src_buf);
+   XFixesDestroyRegion(xscr->dpy, region);
+}
+
+/**
+ * Get the buffers of the DRI2 drawable.  The returned array should be freed.
+ */
+struct x11_drawable_buffer *
+x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
+                         int *width, int *height, unsigned int *attachments,
+                         boolean with_format, int num_ins, int *num_outs)
+{
+   DRI2Buffer *dri2bufs;
+
+   if (with_format)
+      dri2bufs = DRI2GetBuffersWithFormat(xscr->dpy, drawable, width, height,
+            attachments, num_ins, num_outs);
+   else
+      dri2bufs = DRI2GetBuffers(xscr->dpy, drawable, width, height,
+            attachments, num_ins, num_outs);
+
+   return (struct x11_drawable_buffer *) dri2bufs;
+}
+
+/**
+ * Return the depth of a drawable.
+ *
+ * Unlike other drawable functions, the drawable needs not be a DRI2 drawable.
+ */
+uint
+x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable)
+{
+   unsigned int depth;
+
+   if (drawable != xscr->last_drawable) {
+      Window root;
+      int x, y;
+      unsigned int w, h, border;
+      Status ok;
+
+      ok = XGetGeometry(xscr->dpy, drawable, &root,
+            &x, &y, &w, &h, &border, &depth);
+      if (!ok)
+         depth = 0;
+
+      xscr->last_drawable = drawable;
+      xscr->last_depth = depth;
+   }
+   else {
+      depth = xscr->last_depth;
+   }
+
+   return depth;
+}
+
+/**
+ * Create a mode list of the given size.
+ */
+__GLcontextModes *
+x11_context_modes_create(unsigned count)
+{
+   const size_t size = sizeof(__GLcontextModes);
+   __GLcontextModes *base = NULL;
+   __GLcontextModes **next;
+   unsigned i;
+
+   next = &base;
+   for (i = 0; i < count; i++) {
+      *next = (__GLcontextModes *) calloc(1, size);
+      if (*next == NULL) {
+         x11_context_modes_destroy(base);
+         base = NULL;
+         break;
+      }
+      next = &((*next)->next);
+   }
+
+   return base;
+}
+
+/**
+ * Destroy a mode list.
+ */
+void
+x11_context_modes_destroy(__GLcontextModes *modes)
+{
+   while (modes != NULL) {
+      __GLcontextModes *next = modes->next;
+      free(modes);
+      modes = next;
+   }
+}
+
+/**
+ * Return the number of the modes in the mode list.
+ */
+unsigned
+x11_context_modes_count(const __GLcontextModes *modes)
+{
+   const __GLcontextModes *mode;
+   int count = 0;
+   for (mode = modes; mode; mode = mode->next)
+      count++;
+   return count;
+}
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h b/src/gallium/state_trackers/egl/x11/x11_screen.h
new file mode 100644 (file)
index 0000000..5432858
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef _X11_SCREEN_H_
+#define _X11_SCREEN_H_
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/dri2tokens.h>
+#include "pipe/p_compiler.h"
+#include "common/native.h"
+
+enum x11_screen_extension {
+   X11_SCREEN_EXTENSION_XSHM,
+   X11_SCREEN_EXTENSION_GLX,
+   X11_SCREEN_EXTENSION_DRI2,
+};
+
+/* the same as DRI2Buffer */
+struct x11_drawable_buffer {
+   unsigned int attachment;
+   unsigned int name;
+   unsigned int pitch;
+   unsigned int cpp;
+   unsigned int flags;
+};
+
+struct x11_screen;
+
+struct x11_screen *
+x11_screen_create(Display *dpy, int screen);
+
+void
+x11_screen_destroy(struct x11_screen *xscr);
+
+boolean
+x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext);
+
+const XVisualInfo *
+x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals);
+
+void
+x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual,
+                          __GLcontextModes *mode);
+
+const __GLcontextModes *
+x11_screen_get_glx_configs(struct x11_screen *xscr);
+
+const __GLcontextModes *
+x11_screen_get_glx_visuals(struct x11_screen *xscr);
+
+const char *
+x11_screen_probe_dri2(struct x11_screen *xscr);
+
+int
+x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver);
+
+__GLcontextModes *
+x11_context_modes_create(unsigned count);
+
+void
+x11_context_modes_destroy(__GLcontextModes *modes);
+
+unsigned
+x11_context_modes_count(const __GLcontextModes *modes);
+
+void
+x11_drawable_enable_dri2(struct x11_screen *xscr,
+                         Drawable drawable, boolean on);
+
+void
+x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
+                          int x, int y, int width, int height,
+                          int src_buf, int dst_buf);
+
+struct x11_drawable_buffer *
+x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
+                         int *width, int *height, unsigned int *attachments,
+                         boolean with_format, int num_ins, int *num_outs);
+
+uint
+x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable);
+
+#endif /* _X11_SCREEN_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/Makefile b/src/gallium/state_trackers/egl_g3d/Makefile
deleted file mode 100644 (file)
index 213eb3e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-TOP = ../../../..
-include $(TOP)/configs/current
-
-common_INCLUDES = \
-       -I. \
-       -I$(TOP)/src/gallium/include \
-       -I$(TOP)/src/gallium/auxiliary \
-       -I$(TOP)/src/egl/main \
-       -I$(TOP)/include
-
-common_SOURCES = $(wildcard common/*.c)
-common_OBJECTS = $(common_SOURCES:.c=.o)
-
-
-x11_INCLUDES = \
-       -I$(TOP)/src/gallium/drivers \
-       -I$(TOP)/src/glx/x11 \
-       -I$(TOP)/src/mesa \
-       $(shell pkg-config --cflags-only-I libdrm)
-
-x11_SOURCES = $(wildcard x11/*.c) $(TOP)/src/glx/x11/dri2.c
-x11_OBJECTS = $(x11_SOURCES:.c=.o)
-
-
-kms_INCLUDES = $(shell pkg-config --cflags-only-I libdrm)
-kms_SOURCES = $(wildcard kms/*.c)
-kms_OBJECTS = $(kms_SOURCES:.c=.o)
-
-
-ALL_INCLUDES = $(common_INCLUDES) $(x11_INCLUDES) $(kms_INCLUDES)
-ALL_SOURCES = $(common_SOURCES) $(x11_SOURCES) $(kms_SOURCES)
-ALL_OBJECTS = $(common_OBJECTS) $(x11_OBJECTS) $(kms_OBJECTS)
-
-##### TARGETS #####
-
-EGL_DISPLAYS_MODS = $(foreach dpy, $(EGL_DISPLAYS), libegl$(dpy).a)
-
-default: depend $(EGL_DISPLAYS_MODS)
-
-
-libeglx11.a: $(x11_OBJECTS) $(common_OBJECTS) Makefile
-       $(MKLIB) -o eglx11 -static $(x11_OBJECTS) $(common_OBJECTS)
-
-libeglkms.a: $(kms_OBJECTS) $(common_OBJECTS) Makefile
-       $(MKLIB) -o eglkms -static $(kms_OBJECTS) $(common_OBJECTS)
-
-depend: 
-       rm -f depend
-       touch depend
-       $(MKDEP) $(MKDEP_OPTIONS) $(ALL_INCLUDES) $(ALL_SOURCES) 2> /dev/null
-
-clean:
-       rm -f $(ALL_OBJECTS)
-       rm -f $(EGL_DISPLAYS_MODS)
-       rm -f depend depend.bak
-
-# Dummy target
-install:
-       @echo -n ""
-
-##### RULES #####
-
-$(common_OBJECTS): %.o: %.c
-       $(CC) -c $(common_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
-
-$(x11_OBJECTS): %.o: %.c
-       $(CC) -c $(common_INCLUDES) $(x11_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
-
-$(kms_OBJECTS): %.o: %.c
-       $(CC) -c $(common_INCLUDES) $(kms_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
-
-sinclude depend
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
deleted file mode 100644 (file)
index 2ac6215..0000000
+++ /dev/null
@@ -1,1336 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <assert.h>
-#include <string.h>
-#include "pipe/p_screen.h"
-#include "util/u_memory.h"
-#include "util/u_rect.h"
-#include "egldriver.h"
-#include "eglcurrent.h"
-#include "eglconfigutil.h"
-#include "egllog.h"
-
-#include "native.h"
-#include "egl_g3d.h"
-#include "egl_st.h"
-
-/**
- * Validate the draw/read surfaces of the context.
- */
-static void
-egl_g3d_validate_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct pipe_screen *screen = gdpy->native->screen;
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   const uint st_att_map[NUM_NATIVE_ATTACHMENTS] = {
-      ST_SURFACE_FRONT_LEFT,
-      ST_SURFACE_BACK_LEFT,
-      ST_SURFACE_FRONT_RIGHT,
-      ST_SURFACE_BACK_RIGHT,
-   };
-   EGLint num_surfaces, s;
-
-   /* validate draw and/or read buffers */
-   num_surfaces = (gctx->base.ReadSurface == gctx->base.DrawSurface) ? 1 : 2;
-   for (s = 0; s < num_surfaces; s++) {
-      struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
-      struct egl_g3d_surface *gsurf;
-      struct egl_g3d_buffer *gbuf;
-      EGLint att;
-
-      if (s == 0) {
-         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-         gbuf = &gctx->draw;
-      }
-      else {
-         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
-         gbuf = &gctx->read;
-      }
-
-      if (!gctx->force_validate) {
-         unsigned int seq_num;
-
-         gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
-               &seq_num, NULL, NULL, NULL);
-         /* skip validation */
-         if (gsurf->sequence_number == seq_num)
-            continue;
-      }
-
-      pipe_surface_reference(&gsurf->render_surface, NULL);
-      memset(textures, 0, sizeof(textures));
-
-      gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
-            &gsurf->sequence_number, textures,
-            &gsurf->base.Width, &gsurf->base.Height);
-      for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-         struct pipe_texture *pt = textures[att];
-         struct pipe_surface *ps;
-
-         if (native_attachment_mask_test(gbuf->attachment_mask, att) && pt) {
-            ps = screen->get_tex_surface(screen, pt, 0, 0, 0,
-                  PIPE_BUFFER_USAGE_GPU_READ |
-                  PIPE_BUFFER_USAGE_GPU_WRITE);
-            gctx->stapi->st_set_framebuffer_surface(gbuf->st_fb,
-                  st_att_map[att], ps);
-
-            if (gsurf->render_att == att)
-               pipe_surface_reference(&gsurf->render_surface, ps);
-
-            pipe_surface_reference(&ps, NULL);
-            pipe_texture_reference(&pt, NULL);
-         }
-      }
-
-      gctx->stapi->st_resize_framebuffer(gbuf->st_fb,
-            gsurf->base.Width, gsurf->base.Height);
-   }
-
-   gctx->force_validate = EGL_FALSE;
-
-}
-
-/**
- * Create a st_framebuffer.
- */
-static struct st_framebuffer *
-create_framebuffer(_EGLContext *ctx, _EGLSurface *surf)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
-
-   return gctx->stapi->st_create_framebuffer(&gconf->native->mode,
-         gconf->native->color_format, gconf->native->depth_format,
-         gconf->native->stencil_format,
-         gsurf->base.Width, gsurf->base.Height, &gsurf->base);
-}
-
-/**
- * Update the attachments of draw/read surfaces.
- */
-static void
-egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   EGLint s;
-
-   /* route draw and read buffers' attachments */
-   for (s = 0; s < 2; s++) {
-      struct egl_g3d_surface *gsurf;
-      struct egl_g3d_buffer *gbuf;
-
-      if (s == 0) {
-         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-         gbuf = &gctx->draw;
-      }
-      else {
-         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
-         gbuf = &gctx->read;
-      }
-
-      gbuf->attachment_mask = (1 << gsurf->render_att);
-
-      /* FIXME OpenGL defaults to draw the front or back buffer when the
-       * context is single-buffered or double-buffered respectively.  In EGL,
-       * however, the buffer to be drawn is determined by the surface, instead
-       * of the context.  As a result, rendering to a pixmap surface with a
-       * double-buffered context does not work as expected.
-       *
-       * gctx->stapi->st_draw_front_buffer(gctx->st_ctx, natt ==
-       *    NATIVE_ATTACHMENT_FRONT_LEFT);
-       */
-
-      /*
-       * FIXME If the back buffer is asked for here, and the front buffer is
-       * later needed by the client API (e.g. glDrawBuffer is called to draw
-       * the front buffer), it will create a new pipe texture and draw there.
-       * One fix is to ask for both buffers here, but it would be a waste if
-       * the front buffer is never used.  A better fix is to add a callback to
-       * the pipe screen with context private (just like flush_frontbuffer).
-       */
-   }
-}
-
-/**
- * Reallocate the context's framebuffers after draw/read surfaces change.
- */
-static EGLBoolean
-egl_g3d_realloc_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   struct egl_g3d_surface *gdraw = egl_g3d_surface(gctx->base.DrawSurface);
-   struct egl_g3d_surface *gread = egl_g3d_surface(gctx->base.ReadSurface);
-
-   /* unreference the old framebuffers */
-   if (gctx->draw.st_fb) {
-      EGLBoolean is_equal = (gctx->draw.st_fb == gctx->read.st_fb);
-      void *priv;
-
-      priv = gctx->stapi->st_framebuffer_private(gctx->draw.st_fb);
-      if (!gdraw || priv != (void *) &gdraw->base) {
-         gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
-         gctx->draw.st_fb = NULL;
-         gctx->draw.attachment_mask = 0x0;
-      }
-
-      if (is_equal) {
-         gctx->read.st_fb = NULL;
-         gctx->draw.attachment_mask = 0x0;
-      }
-      else {
-         priv = gctx->stapi->st_framebuffer_private(gctx->read.st_fb);
-         if (!gread || priv != (void *) &gread->base) {
-            gctx->stapi->st_unreference_framebuffer(gctx->read.st_fb);
-            gctx->read.st_fb = NULL;
-            gctx->draw.attachment_mask = 0x0;
-         }
-      }
-   }
-
-   if (!gdraw)
-      return EGL_TRUE;
-
-   /* create the draw fb */
-   if (!gctx->draw.st_fb) {
-      gctx->draw.st_fb = create_framebuffer(&gctx->base, &gdraw->base);
-      if (!gctx->draw.st_fb)
-         return EGL_FALSE;
-   }
-
-   /* create the read fb */
-   if (!gctx->read.st_fb) {
-      if (gread != gdraw) {
-         gctx->read.st_fb = create_framebuffer(&gctx->base, &gread->base);
-         if (!gctx->read.st_fb) {
-            gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
-            gctx->draw.st_fb = NULL;
-            return EGL_FALSE;
-         }
-      }
-      else {
-         /* there is no st_reference_framebuffer... */
-         gctx->read.st_fb = gctx->draw.st_fb;
-      }
-   }
-
-   egl_g3d_route_context(dpy, &gctx->base);
-   gctx->force_validate = EGL_TRUE;
-
-   return EGL_TRUE;
-}
-
-/**
- * Return the current context of the given API.
- */
-static struct egl_g3d_context *
-egl_g3d_get_current_context(EGLint api)
-{
-   _EGLThreadInfo *t = _eglGetCurrentThread();
-   EGLint api_index = _eglConvertApiToIndex(api);
-   return egl_g3d_context(t->CurrentContexts[api_index]);
-}
-
-/**
- * Return the state tracker for the given context.
- */
-static const struct egl_g3d_st *
-egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   const struct egl_g3d_st *stapi;
-   EGLint idx = -1;
-
-   switch (ctx->ClientAPI) {
-   case EGL_OPENGL_ES_API:
-      switch (ctx->ClientVersion) {
-      case 1:
-         idx = EGL_G3D_ST_OPENGL_ES;
-         break;
-      case 2:
-         idx = EGL_G3D_ST_OPENGL_ES2;
-         break;
-      default:
-         _eglLog(_EGL_WARNING, "unknown client version %d",
-               ctx->ClientVersion);
-         break;
-      }
-      break;
-   case EGL_OPENVG_API:
-      idx = EGL_G3D_ST_OPENVG;
-      break;
-   case EGL_OPENGL_API:
-      idx = EGL_G3D_ST_OPENGL;
-      break;
-   default:
-      _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI);
-      break;
-   }
-
-   stapi = (idx >= 0) ? gdrv->stapis[idx] : NULL;
-   return stapi;
-}
-
-/**
- * Initialize the state trackers.
- */
-static void
-egl_g3d_init_st(_EGLDriver *drv)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   EGLint i;
-
-   /* already initialized */
-   if (gdrv->api_mask)
-      return;
-
-   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
-      gdrv->stapis[i] = egl_g3d_get_st(i);
-      if (gdrv->stapis[i])
-         gdrv->api_mask |= gdrv->stapis[i]->api_bit;
-   }
-
-   if (gdrv->api_mask)
-      _eglLog(_EGL_DEBUG, "Driver API mask: 0x%x", gdrv->api_mask);
-   else
-      _eglLog(_EGL_WARNING, "No supported client API");
-}
-
-/**
- * Get the probe object of the display.
- *
- * Note that this function may be called before the display is initialized.
- */
-static struct native_probe *
-egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   struct native_probe *nprobe;
-
-   nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
-   if (!nprobe || nprobe->display != dpy->NativeDisplay) {
-      if (nprobe)
-         nprobe->destroy(nprobe);
-      nprobe = native_create_probe(dpy->NativeDisplay);
-      _eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
-   }
-
-   return nprobe;
-}
-
-/**
- * Destroy the probe object of the display.  The display may be NULL.
- *
- * Note that this function may be called before the display is initialized.
- */
-static void
-egl_g3d_destroy_probe(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   struct native_probe *nprobe;
-
-   nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
-   if (nprobe && (!dpy || nprobe->display == dpy->NativeDisplay)) {
-      nprobe->destroy(nprobe);
-      _eglSetProbeCache(gdrv->probe_key, NULL);
-   }
-}
-
-/**
- * Return an API mask that consists of the state trackers that supports the
- * given mode.
- *
- * FIXME add st_is_mode_supported()?
- */
-static EGLint
-get_mode_api_mask(const __GLcontextModes *mode, EGLint api_mask)
-{
-   EGLint check;
-
-   /* OpenGL ES 1.x and 2.x are checked together */
-   check = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT;
-   if (api_mask & check) {
-      /* this is required by EGL, not by OpenGL ES */
-      if (mode->drawableType & GLX_WINDOW_BIT && !mode->doubleBufferMode)
-         api_mask &= ~check;
-   }
-
-   check = EGL_OPENVG_BIT;
-   if (api_mask & check) {
-      /* vega st needs the depth/stencil rb */
-      if (!mode->depthBits && !mode->stencilBits)
-         api_mask &= ~check;
-   }
-
-   return api_mask;
-}
-
-#ifdef EGL_MESA_screen_surface
-
-static void
-egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   const struct native_connector **native_connectors;
-   EGLint num_connectors, i;
-
-   native_connectors =
-      gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL);
-   if (!num_connectors) {
-      if (native_connectors)
-         free(native_connectors);
-      return;
-   }
-
-   for (i = 0; i < num_connectors; i++) {
-      const struct native_connector *nconn = native_connectors[i];
-      struct egl_g3d_screen *gscr;
-      const struct native_mode **native_modes;
-      EGLint num_modes, j;
-
-      /* TODO support for hotplug */
-      native_modes =
-         gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes);
-      if (!num_modes) {
-         if (native_modes)
-            free(native_modes);
-         continue;
-      }
-
-      gscr = CALLOC_STRUCT(egl_g3d_screen);
-      if (!gscr) {
-         free(native_modes);
-         continue;
-      }
-
-      _eglInitScreen(&gscr->base);
-
-      for (j = 0; j < num_modes; j++) {
-         const struct native_mode *nmode = native_modes[j];
-         _EGLMode *mode;
-
-         mode = _eglAddNewMode(&gscr->base, nmode->width, nmode->height,
-               nmode->refresh_rate, nmode->desc);
-         if (!mode)
-            break;
-         /* gscr->native_modes and gscr->base.Modes should be consistent */
-         assert(mode == &gscr->base.Modes[j]);
-      }
-
-      gscr->native = nconn;
-      gscr->native_modes = native_modes;
-
-      _eglAddScreen(dpy, &gscr->base);
-   }
-
-   free(native_connectors);
-}
-
-#endif /* EGL_MESA_screen_surface */
-
-/**
- * Add configs to display and return the next config ID.
- */
-static EGLint
-egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   const struct native_config **native_configs;
-   int num_configs, i;
-
-   native_configs = gdpy->native->get_configs(gdpy->native,
-         &num_configs);
-   if (!num_configs) {
-      if (native_configs)
-         free(native_configs);
-      return id;
-   }
-
-   for (i = 0; i < num_configs; i++) {
-      EGLint api_mask;
-      struct egl_g3d_config *gconf;
-      EGLBoolean valid;
-
-      api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
-      if (!api_mask) {
-         _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x",
-               native_configs[i]->mode.visualID);
-         continue;
-      }
-
-      gconf = CALLOC_STRUCT(egl_g3d_config);
-      if (!gconf)
-         continue;
-
-      _eglInitConfig(&gconf->base, id);
-      valid = _eglConfigFromContextModesRec(&gconf->base,
-            &native_configs[i]->mode, api_mask, api_mask);
-      if (valid) {
-#ifdef EGL_MESA_screen_surface
-         /* check if scanout surface bit is set */
-         if (native_configs[i]->scanout_bit) {
-            EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE);
-            val |= EGL_SCREEN_BIT_MESA;
-            SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val);
-         }
-#endif
-         valid = _eglValidateConfig(&gconf->base, EGL_FALSE);
-      }
-      if (!valid) {
-         _eglLog(_EGL_DEBUG, "skip invalid config 0x%x",
-               native_configs[i]->mode.visualID);
-         free(gconf);
-         continue;
-      }
-
-      gconf->native = native_configs[i];
-      _eglAddConfig(dpy, &gconf->base);
-      id++;
-   }
-
-   free(native_configs);
-   return id;
-}
-
-/**
- * Flush the front buffer of the context's draw surface.
- */
-static void
-egl_g3d_flush_frontbuffer(struct pipe_screen *screen,
-                          struct pipe_surface *surf, void *context_private)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-
-   if (gsurf)
-      gsurf->native->flush_frontbuffer(gsurf->native);
-}
-
-/**
- * Re-validate the context.
- */
-static void
-egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
-
-   /**
-    * It is likely that the surface has changed when this function is called.
-    * Set force_validate to skip an unnecessary check.
-    */
-   gctx->force_validate = EGL_TRUE;
-   egl_g3d_validate_context(gctx->base.Display, &gctx->base);
-}
-
-static EGLBoolean
-egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   EGLint i;
-
-   _eglReleaseDisplayResources(drv, dpy);
-   _eglCleanupDisplay(dpy);
-
-   if (dpy->Screens) {
-      for (i = 0; i < dpy->NumScreens; i++) {
-         struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]);
-         free(gscr->native_modes);
-         free(gscr);
-      }
-      free(dpy->Screens);
-   }
-
-   if (gdpy->native)
-      gdpy->native->destroy(gdpy->native);
-
-   free(gdpy);
-   dpy->DriverData = NULL;
-
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
-                   EGLint *major, EGLint *minor)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   struct egl_g3d_display *gdpy;
-
-   /* the probe object is unlikely to be needed again */
-   egl_g3d_destroy_probe(drv, dpy);
-
-   gdpy = CALLOC_STRUCT(egl_g3d_display);
-   if (!gdpy) {
-      _eglError(EGL_BAD_ALLOC, "eglInitialize");
-      goto fail;
-   }
-   dpy->DriverData = gdpy;
-
-   gdpy->native = native_create_display(dpy->NativeDisplay);
-   if (!gdpy->native) {
-      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
-      goto fail;
-   }
-
-   gdpy->native->screen->flush_frontbuffer = egl_g3d_flush_frontbuffer;
-   gdpy->native->screen->update_buffer = egl_g3d_update_buffer;
-
-   egl_g3d_init_st(&gdrv->base);
-   dpy->ClientAPIsMask = gdrv->api_mask;
-
-   if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
-      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
-      goto fail;
-   }
-
-#ifdef EGL_MESA_screen_surface
-   /* enable MESA_screen_surface */
-   if (gdpy->native->modeset) {
-      dpy->Extensions.MESA_screen_surface = EGL_TRUE;
-      egl_g3d_add_screens(drv, dpy);
-   }
-#endif
-
-   *major = 1;
-   *minor = 4;
-
-   return EGL_TRUE;
-
-fail:
-   if (gdpy)
-      egl_g3d_terminate(drv, dpy);
-   return EGL_FALSE;
-}
-
-static _EGLContext *
-egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
-                       _EGLContext *share, const EGLint *attribs)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_context *gshare = egl_g3d_context(share);
-   struct egl_g3d_config *gconf = egl_g3d_config(conf);
-   struct egl_g3d_context *gctx;
-   const __GLcontextModes *mode;
-
-   gctx = CALLOC_STRUCT(egl_g3d_context);
-   if (!gctx) {
-      _eglError(EGL_BAD_ALLOC, "eglCreateContext");
-      return NULL;
-   }
-
-   if (!_eglInitContext(drv, &gctx->base, conf, attribs)) {
-      free(gctx);
-      return NULL;
-   }
-
-   gctx->stapi = egl_g3d_choose_st(drv, &gctx->base);
-   if (!gctx->stapi) {
-      free(gctx);
-      return NULL;
-   }
-
-   mode = &gconf->native->mode;
-   gctx->pipe =
-      gdpy->native->create_context(gdpy->native, (void *) &gctx->base);
-   if (!gctx->pipe) {
-      free(gctx);
-      return NULL;
-   }
-
-   gctx->st_ctx = gctx->stapi->st_create_context(gctx->pipe, mode,
-                        (gshare) ? gshare->st_ctx : NULL);
-   if (!gctx->st_ctx) {
-      gctx->pipe->destroy(gctx->pipe);
-      free(gctx);
-      return NULL;
-   }
-
-   return &gctx->base;
-}
-
-static EGLBoolean
-egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-
-   if (_eglIsContextBound(&gctx->base))
-      return EGL_TRUE;
-
-   egl_g3d_realloc_context(dpy, &gctx->base);
-
-   /* it will destroy pipe context */
-   gctx->stapi->st_destroy_context(gctx->st_ctx);
-
-   free(gctx);
-
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-init_surface_geometry(_EGLSurface *surf)
-{
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-
-   return gsurf->native->validate(gsurf->native, 0x0,
-         &gsurf->sequence_number, NULL,
-         &gsurf->base.Width, &gsurf->base.Height);
-}
-
-static _EGLSurface *
-egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
-                              _EGLConfig *conf, EGLNativeWindowType win,
-                              const EGLint *attribs)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf = egl_g3d_config(conf);
-   struct egl_g3d_surface *gsurf;
-
-   gsurf = CALLOC_STRUCT(egl_g3d_surface);
-   if (!gsurf) {
-      _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
-      return NULL;
-   }
-
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_WINDOW_BIT, conf, attribs)) {
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->native =
-      gdpy->native->create_window_surface(gdpy->native, win, gconf->native);
-   if (!gsurf->native) {
-      free(gsurf);
-      return NULL;
-   }
-
-   if (!init_surface_geometry(&gsurf->base)) {
-      gsurf->native->destroy(gsurf->native);
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER ||
-                        !gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
-   return &gsurf->base;
-}
-
-static _EGLSurface *
-egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
-                              _EGLConfig *conf, EGLNativePixmapType pix,
-                              const EGLint *attribs)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf = egl_g3d_config(conf);
-   struct egl_g3d_surface *gsurf;
-
-   gsurf = CALLOC_STRUCT(egl_g3d_surface);
-   if (!gsurf) {
-      _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
-      return NULL;
-   }
-
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_PIXMAP_BIT, conf, attribs)) {
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->native =
-      gdpy->native->create_pixmap_surface(gdpy->native, pix, gconf->native);
-   if (!gsurf->native) {
-      free(gsurf);
-      return NULL;
-   }
-
-   if (!init_surface_geometry(&gsurf->base)) {
-      gsurf->native->destroy(gsurf->native);
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
-
-   return &gsurf->base;
-}
-
-static _EGLSurface *
-egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
-                               _EGLConfig *conf, const EGLint *attribs)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf = egl_g3d_config(conf);
-   struct egl_g3d_surface *gsurf;
-
-   gsurf = CALLOC_STRUCT(egl_g3d_surface);
-   if (!gsurf) {
-      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
-      return NULL;
-   }
-
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_PBUFFER_BIT, conf, attribs)) {
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->native =
-      gdpy->native->create_pbuffer_surface(gdpy->native, gconf->native,
-            gsurf->base.Width, gsurf->base.Height);
-   if (!gsurf->native) {
-      free(gsurf);
-      return NULL;
-   }
-
-   if (!init_surface_geometry(&gsurf->base)) {
-      gsurf->native->destroy(gsurf->native);
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
-   return &gsurf->base;
-}
-
-static EGLBoolean
-egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
-{
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-
-   if (_eglIsSurfaceBound(&gsurf->base))
-         return EGL_TRUE;
-
-   pipe_surface_reference(&gsurf->render_surface, NULL);
-   gsurf->native->destroy(gsurf->native);
-   free(gsurf);
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
-                     _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   struct egl_g3d_context *old_gctx;
-   EGLint api;
-   EGLBoolean ok = EGL_TRUE;
-
-   /* find the old context */
-   api = (gctx) ? gctx->base.ClientAPI : eglQueryAPI();
-   old_gctx = egl_g3d_get_current_context(api);
-   if (old_gctx && !_eglIsContextLinked(&old_gctx->base))
-         old_gctx = NULL;
-
-   if (!_eglMakeCurrent(drv, dpy, draw, read, ctx))
-      return EGL_FALSE;
-
-   if (old_gctx) {
-      /* flush old context */
-      old_gctx->stapi->st_flush(old_gctx->st_ctx,
-            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
-
-      /*
-       * The old context is no longer current, and egl_g3d_realloc_context()
-       * should be called to destroy the framebuffers.  However, it is possible
-       * that it will be made current again with the same draw/read surfaces.
-       * It might be better to keep it around.
-       */
-   }
-
-   if (gctx) {
-      struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
-
-      ok = egl_g3d_realloc_context(dpy, &gctx->base);
-      if (ok) {
-         ok = gctx->stapi->st_make_current(gctx->st_ctx,
-               gctx->draw.st_fb, gctx->read.st_fb);
-         if (ok) {
-            egl_g3d_validate_context(dpy, &gctx->base);
-            if (gdraw->base.Type == EGL_WINDOW_BIT) {
-               gctx->base.WindowRenderBuffer =
-                  (gdraw->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) ?
-                  EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
-            }
-         }
-      }
-   }
-   else if (old_gctx) {
-      ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL);
-      old_gctx->base.WindowRenderBuffer = EGL_NONE;
-   }
-
-   return ok;
-}
-
-static EGLBoolean
-egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
-{
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   _EGLContext *ctx = _eglGetCurrentContext();
-   struct egl_g3d_context *gctx = NULL;
-
-   /* no-op for pixmap or pbuffer surface */
-   if (gsurf->base.Type == EGL_PIXMAP_BIT ||
-       gsurf->base.Type == EGL_PBUFFER_BIT)
-      return EGL_TRUE;
-
-   /* or when the surface is single-buffered */
-   if (gsurf->render_att == NATIVE_ATTACHMENT_FRONT_LEFT)
-      return EGL_TRUE;
-
-   if (ctx && ctx->DrawSurface == surf)
-      gctx = egl_g3d_context(ctx);
-
-   /* flush if the surface is current */
-   if (gctx)
-      gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb);
-
-   /*
-    * We drew on the back buffer, unless there was no back buffer.
-    * In that case, we drew on the front buffer.  Either case, we call
-    * swap_buffers.
-    */
-   if (!gsurf->native->swap_buffers(gsurf->native))
-      return EGL_FALSE;
-
-   if (gctx) {
-      struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
-
-      /* force validation if the swap method is not copy */
-      if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML) {
-         gctx->force_validate = EGL_TRUE;
-         egl_g3d_validate_context(dpy, &gctx->base);
-      }
-   }
-
-   return EGL_TRUE;
-}
-
-/**
- * Find a config that supports the pixmap.
- */
-static _EGLConfig *
-find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf;
-   EGLint i;
-
-   for (i = 0; i < dpy->NumConfigs; i++) {
-      gconf = egl_g3d_config(dpy->Configs[i]);
-      if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native))
-         break;
-   }
-
-   return (i < dpy->NumConfigs) ? &gconf->base : NULL;
-}
-
-/**
- * Get the pipe surface of the given attachment of the native surface.
- */
-static struct pipe_surface *
-get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
-                 enum native_attachment natt)
-{
-   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
-   struct pipe_surface *psurf;
-
-   textures[natt] = NULL;
-   nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL);
-   if (!textures[natt])
-      return NULL;
-
-   psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt],
-         0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE);
-   pipe_texture_reference(&textures[natt], NULL);
-
-   return psurf;
-}
-
-static EGLBoolean
-egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
-                     NativePixmapType target)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   _EGLContext *ctx = _eglGetCurrentContext();
-   struct egl_g3d_config *gconf;
-   struct native_surface *nsurf;
-   struct pipe_screen *screen = gdpy->native->screen;
-   struct pipe_surface *psurf;
-
-   if (!gsurf->render_surface)
-      return EGL_TRUE;
-
-   gconf = egl_g3d_config(find_pixmap_config(dpy, target));
-   if (!gconf)
-      return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
-
-   nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
-         target, gconf->native);
-   if (!nsurf)
-      return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
-
-   /* flush if the surface is current */
-   if (ctx && ctx->DrawSurface == &gsurf->base) {
-      struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-      gctx->stapi->st_flush(gctx->st_ctx,
-            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
-   }
-
-   psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
-   if (psurf) {
-      struct pipe_context pipe;
-
-      /**
-       * XXX This is hacky.  If we might allow the EGLDisplay to create a pipe
-       * context of its own and use the blitter context for this.
-       */
-      memset(&pipe, 0, sizeof(pipe));
-      pipe.screen = screen;
-
-      util_surface_copy(&pipe, FALSE, psurf, 0, 0,
-            gsurf->render_surface, 0, 0, psurf->width, psurf->height);
-
-      pipe_surface_reference(&psurf, NULL);
-      nsurf->flush_frontbuffer(nsurf);
-   }
-
-   nsurf->destroy(nsurf);
-
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   gctx->stapi->st_finish(gctx->st_ctx);
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
-{
-   _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-
-   if (engine != EGL_CORE_NATIVE_ENGINE)
-      return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
-
-   if (gsurf)
-      gsurf->native->wait(gsurf->native);
-
-   return EGL_TRUE;
-}
-
-static _EGLProc
-egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   _EGLProc proc;
-   EGLint i;
-
-   /* in case this is called before a display is initialized */
-   egl_g3d_init_st(&gdrv->base);
-
-   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
-      const struct egl_g3d_st *stapi = gdrv->stapis[i];
-      if (stapi) {
-         proc = (_EGLProc) stapi->st_get_proc_address(procname);
-         if (proc)
-            return proc;
-      }
-   }
-
-   return (_EGLProc) NULL;
-}
-
-static EGLBoolean
-egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
-                       _EGLSurface *surf, EGLint buffer)
-{
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct egl_g3d_context *gctx;
-   enum pipe_format target_format;
-   int target;
-
-   if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT)
-      return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
-   if (buffer != EGL_BACK_BUFFER)
-      return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage");
-   if (gsurf->base.BoundToTexture)
-      return _eglError(EGL_BAD_ACCESS, "eglBindTexImage");
-
-   switch (gsurf->base.TextureFormat) {
-   case EGL_TEXTURE_RGB:
-      target_format = PIPE_FORMAT_R8G8B8_UNORM;
-      break;
-   case EGL_TEXTURE_RGBA:
-      target_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-      break;
-   default:
-      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
-   }
-
-   switch (gsurf->base.TextureTarget) {
-   case EGL_TEXTURE_2D:
-      target = ST_TEXTURE_2D;
-      break;
-   default:
-      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
-   }
-
-   /* flush properly if the surface is bound */
-   if (gsurf->base.Binding) {
-      gctx = egl_g3d_context(gsurf->base.Binding);
-      gctx->stapi->st_flush(gctx->st_ctx,
-            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
-   }
-
-   /* XXX change to EGL_OPENGL_ES_API once OpenGL ES is merged */
-   gctx = egl_g3d_get_current_context(EGL_OPENGL_API);
-   if (gctx) {
-      if (!gsurf->render_surface)
-         return EGL_FALSE;
-
-      gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
-            target, gsurf->base.MipmapLevel, target_format);
-      gsurf->base.BoundToTexture = EGL_TRUE;
-   }
-
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
-                          _EGLSurface *surf, EGLint buffer)
-{
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-
-   if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT ||
-       !gsurf->base.BoundToTexture)
-      return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
-   if (buffer != EGL_BACK_BUFFER)
-      return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage");
-
-   if (gsurf->render_surface) {
-      _EGLThreadInfo *t = _eglGetCurrentThread();
-      /* XXX change to EGL_OPENGL_ES_API once OpenGL ES is merged */
-      struct egl_g3d_context *gctx = egl_g3d_context(
-            t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_API)]);
-
-      /* what if the context the surface binds to is no longer current? */
-      if (gctx)
-         gctx->stapi->st_unbind_texture_surface(gsurf->render_surface,
-               ST_TEXTURE_2D, gsurf->base.MipmapLevel);
-   }
-
-   gsurf->base.BoundToTexture = EGL_FALSE;
-
-   return EGL_TRUE;
-}
-
-#ifdef EGL_MESA_screen_surface
-
-static _EGLSurface *
-egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
-                              _EGLConfig *conf, const EGLint *attribs)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_config *gconf = egl_g3d_config(conf);
-   struct egl_g3d_surface *gsurf;
-
-   gsurf = CALLOC_STRUCT(egl_g3d_surface);
-   if (!gsurf) {
-      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
-      return NULL;
-   }
-
-   if (!_eglInitSurface(drv, &gsurf->base,
-            EGL_SCREEN_BIT_MESA, conf, attribs)) {
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->native =
-      gdpy->native->modeset->create_scanout_surface(gdpy->native,
-            gconf->native, gsurf->base.Width, gsurf->base.Height);
-   if (!gsurf->native) {
-      free(gsurf);
-      return NULL;
-   }
-
-   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
-   return &gsurf->base;
-}
-
-static EGLBoolean
-egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
-                            _EGLScreen *scr, _EGLSurface *surf,
-                            _EGLMode *mode)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct egl_g3d_screen *gscr = egl_g3d_screen(scr);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct native_surface *nsurf;
-   const struct native_mode *nmode;
-   EGLBoolean changed;
-
-   if (gsurf) {
-      EGLint idx;
-
-      if (!mode)
-         return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
-      if (gsurf->base.Type != EGL_SCREEN_BIT_MESA)
-         return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA");
-      if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height)
-         return _eglError(EGL_BAD_MATCH,
-               "eglShowSurfaceMESA(surface smaller than mode size)");
-
-      /* find the index of the mode */
-      for (idx = 0; idx < gscr->base.NumModes; idx++)
-         if (mode == &gscr->base.Modes[idx])
-            break;
-      if (idx >= gscr->base.NumModes) {
-         return _eglError(EGL_BAD_MODE_MESA,
-               "eglShowSurfaceMESA(unknown mode)");
-      }
-
-      nsurf = gsurf->native;
-      nmode = gscr->native_modes[idx];
-   }
-   else {
-      if (mode)
-         return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
-
-      /* disable the screen */
-      nsurf = NULL;
-      nmode = NULL;
-   }
-
-   /* TODO surface panning by CRTC choosing */
-   changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf,
-         gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode);
-   if (changed) {
-      gscr->base.CurrentSurface = &gsurf->base;
-      gscr->base.CurrentMode = mode;
-   }
-
-   return changed;
-}
-
-#endif /* EGL_MESA_screen_surface */
-
-static EGLint
-egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct native_probe *nprobe;
-   enum native_probe_result res;
-   EGLint score;
-
-   nprobe = egl_g3d_get_probe(drv, dpy);
-   res = native_get_probe_result(nprobe);
-
-   switch (res) {
-   case NATIVE_PROBE_UNKNOWN:
-   default:
-      score = 0;
-      break;
-   case NATIVE_PROBE_FALLBACK:
-      score = 40;
-      break;
-   case NATIVE_PROBE_SUPPORTED:
-      score = 50;
-      break;
-   case NATIVE_PROBE_EXACT:
-      score = 100;
-      break;
-   }
-
-   return score;
-}
-
-static void
-egl_g3d_unload(_EGLDriver *drv)
-{
-   struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-
-   egl_g3d_destroy_probe(drv, NULL);
-   free(gdrv);
-}
-
-_EGLDriver *
-_eglMain(const char *args)
-{
-   static char driver_name[64];
-   struct egl_g3d_driver *gdrv;
-
-   snprintf(driver_name, sizeof(driver_name),
-         "Gallium/%s", native_get_name());
-
-   gdrv = CALLOC_STRUCT(egl_g3d_driver);
-   if (!gdrv)
-      return NULL;
-
-   _eglInitDriverFallbacks(&gdrv->base);
-
-   gdrv->base.API.Initialize = egl_g3d_initialize;
-   gdrv->base.API.Terminate = egl_g3d_terminate;
-   gdrv->base.API.CreateContext = egl_g3d_create_context;
-   gdrv->base.API.DestroyContext = egl_g3d_destroy_context;
-   gdrv->base.API.CreateWindowSurface = egl_g3d_create_window_surface;
-   gdrv->base.API.CreatePixmapSurface = egl_g3d_create_pixmap_surface;
-   gdrv->base.API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface;
-   gdrv->base.API.DestroySurface = egl_g3d_destroy_surface;
-   gdrv->base.API.MakeCurrent = egl_g3d_make_current;
-   gdrv->base.API.SwapBuffers = egl_g3d_swap_buffers;
-   gdrv->base.API.CopyBuffers = egl_g3d_copy_buffers;
-   gdrv->base.API.WaitClient = egl_g3d_wait_client;
-   gdrv->base.API.WaitNative = egl_g3d_wait_native;
-   gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
-
-   gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image;
-   gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image;
-
-#ifdef EGL_MESA_screen_surface
-   gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface;
-   gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface;
-#endif
-
-   gdrv->base.Name = driver_name;
-   gdrv->base.Probe = egl_g3d_probe;
-   gdrv->base.Unload = egl_g3d_unload;
-
-   /* the key is " EGL G3D" */
-   gdrv->probe_key = 0x0E61063D;
-
-   return &gdrv->base;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.h b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.h
deleted file mode 100644 (file)
index 3dae8c4..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _EGL_G3D_H_
-#define _EGL_G3D_H_
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_context.h"
-#include "pipe/p_format.h"
-#include "egldriver.h"
-#include "egldisplay.h"
-#include "eglcontext.h"
-#include "eglsurface.h"
-#include "eglconfig.h"
-#include "eglscreen.h"
-#include "eglmode.h"
-
-#include "native.h"
-#include "egl_st.h"
-
-struct egl_g3d_driver {
-   _EGLDriver base;
-   const struct egl_g3d_st *stapis[NUM_EGL_G3D_STS];
-   EGLint api_mask;
-
-   EGLint probe_key;
-};
-
-struct egl_g3d_display {
-   struct native_display *native;
-};
-
-struct egl_g3d_buffer {
-   struct st_framebuffer *st_fb;
-   uint attachment_mask;
-};
-
-struct egl_g3d_context {
-   _EGLContext base;
-
-   const struct egl_g3d_st *stapi;
-   struct pipe_context *pipe;
-
-   struct st_context *st_ctx;
-   EGLBoolean force_validate;
-   struct egl_g3d_buffer draw, read;
-};
-
-struct egl_g3d_surface {
-   _EGLSurface base;
-   struct native_surface *native;
-   enum native_attachment render_att;
-   struct pipe_surface *render_surface;
-   unsigned int sequence_number;
-};
-
-struct egl_g3d_config {
-   _EGLConfig base;
-   const struct native_config *native;
-};
-
-struct egl_g3d_screen {
-   _EGLScreen base;
-   const struct native_connector *native;
-   const struct native_mode **native_modes;
-};
-
-static INLINE struct egl_g3d_driver *
-egl_g3d_driver(_EGLDriver *drv)
-{
-   return (struct egl_g3d_driver *) drv;
-}
-
-static INLINE struct egl_g3d_display *
-egl_g3d_display(_EGLDisplay *dpy)
-{
-   /* note that it is not direct casting */
-   return (struct egl_g3d_display *) dpy->DriverData;
-}
-
-static INLINE struct egl_g3d_context *
-egl_g3d_context(_EGLContext *ctx)
-{
-   return (struct egl_g3d_context *) ctx;
-}
-
-static INLINE struct egl_g3d_surface *
-egl_g3d_surface(_EGLSurface *surf)
-{
-   return (struct egl_g3d_surface *) surf;
-}
-
-static INLINE struct egl_g3d_config *
-egl_g3d_config(_EGLConfig *conf)
-{
-   return (struct egl_g3d_config *) conf;
-}
-
-static INLINE struct egl_g3d_screen *
-egl_g3d_screen(_EGLScreen *scr)
-{
-   return (struct egl_g3d_screen *) scr;
-}
-
-#endif /* _EGL_G3D_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_st.c b/src/gallium/state_trackers/egl_g3d/common/egl_st.c
deleted file mode 100644 (file)
index a88ff91..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <dlfcn.h>
-#include "pipe/p_compiler.h"
-#include "util/u_memory.h"
-#include "egllog.h"
-#include "EGL/egl.h" /* for EGL_api_BIT */
-
-#include "egl_st.h"
-
-#ifndef HAVE_DLADDR
-#define HAVE_DLADDR 1
-#endif
-
-#if HAVE_DLADDR
-
-static const char *
-egl_g3d_st_names[] = {
-#define ST_PUBLIC(name, ...) #name,
-#include "st_public_tmp.h"
-   NULL
-};
-
-static boolean
-egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
-{
-   st_proc *procs = (st_proc *) stapi;
-   void *handle;
-   Dl_info info;
-   const char **name;
-
-   if (!dladdr(sym, &info))
-      return FALSE;
-   handle = dlopen(info.dli_fname, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
-   if (!handle)
-      return FALSE;
-
-   for (name = egl_g3d_st_names; *name; name++) {
-      st_proc proc = (st_proc) dlsym(handle, *name);
-      if (!proc) {
-         _eglLog(_EGL_WARNING, "%s is missing in %s", *name, info.dli_fname);
-         memset(stapi, 0, sizeof(*stapi));
-         dlclose(handle);
-         return FALSE;
-      }
-      *procs++ = proc;
-   }
-
-   dlclose(handle);
-   return TRUE;
-}
-
-#else /* HAVE_DLADDR */
-
-static boolean
-egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
-{
-#define ST_PUBLIC(name, ...) stapi->name = name;
-#include "st_public_tmp.h"
-   return TRUE;
-}
-
-#endif /* HAVE_DLADDR */
-
-static boolean
-egl_g3d_init_st(struct egl_g3d_st *stapi, const char *api)
-{
-   void *handle, *sym;
-   boolean res = FALSE;
-
-   /* already initialized */
-   if (stapi->st_notify_swapbuffers != NULL)
-      return TRUE;
-
-   handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
-   if (!handle)
-      return FALSE;
-
-   sym = dlsym(handle, api);
-   if (sym && egl_g3d_fill_st(stapi, sym))
-      res = TRUE;
-
-   dlclose(handle);
-   return res;
-}
-
-static struct {
-   const char *symbol;
-   EGLint api_bit;
-} egl_g3d_st_info[NUM_EGL_G3D_STS] = {
-   { "st_api_OpenGL_ES1",  EGL_OPENGL_ES_BIT },
-   { "st_api_OpenVG",      EGL_OPENVG_BIT },
-   { "st_api_OpenGL_ES2",  EGL_OPENGL_ES2_BIT },
-   { "st_api_OpenGL",      EGL_OPENGL_BIT },
-};
-
-const struct egl_g3d_st *
-egl_g3d_get_st(enum egl_g3d_st_api api)
-{
-   static struct egl_g3d_st all_trackers[NUM_EGL_G3D_STS];
-
-   if (egl_g3d_init_st(&all_trackers[api], egl_g3d_st_info[api].symbol)) {
-      all_trackers[api].api_bit = egl_g3d_st_info[api].api_bit;
-      return &all_trackers[api];
-   }
-   else {
-      return NULL;
-   }
-}
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_st.h b/src/gallium/state_trackers/egl_g3d/common/egl_st.h
deleted file mode 100644 (file)
index 8fb464b..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _EGL_ST_H_
-#define _EGL_ST_H_
-
-#include "GL/gl.h" /* for GL types */
-#include "GL/internal/glcore.h"  /* for __GLcontextModes */
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-#include "pipe/p_context.h"
-
-/* avoid calling st functions directly */
-#if 1
-
-#define ST_SURFACE_FRONT_LEFT   0
-#define ST_SURFACE_BACK_LEFT    1
-#define ST_SURFACE_FRONT_RIGHT  2
-#define ST_SURFACE_BACK_RIGHT   3
-
-#define ST_TEXTURE_2D    0x2
-
-struct st_context;
-struct st_framebuffer;
-typedef void (*st_proc)();
-
-#else
-#include "state_tracker/st_public.h"
-#endif
-
-/* remember to update egl_g3d_get_st() when update the enums */
-enum egl_g3d_st_api {
-   EGL_G3D_ST_OPENGL_ES = 0,
-   EGL_G3D_ST_OPENVG,
-   EGL_G3D_ST_OPENGL_ES2,
-   EGL_G3D_ST_OPENGL,
-
-   NUM_EGL_G3D_STS
-};
-
-struct egl_g3d_st {
-#define ST_PUBLIC(name, ret, ...) ret (*name)(__VA_ARGS__);
-#include "st_public_tmp.h"
-   /* fields must be added here */
-   EGLint api_bit;
-};
-
-const struct egl_g3d_st *
-egl_g3d_get_st(enum egl_g3d_st_api api);
-
-#endif /* _EGL_ST_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/common/native.h b/src/gallium/state_trackers/egl_g3d/common/native.h
deleted file mode 100644 (file)
index 72a9cec..0000000
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _NATIVE_H_
-#define _NATIVE_H_
-
-#include "EGL/egl.h"  /* for EGL native types */
-#include "GL/gl.h" /* for GL types needed by __GLcontextModes */
-#include "GL/internal/glcore.h"  /* for __GLcontextModes */
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-
-/**
- * Only color buffers are listed.  The others are allocated privately through,
- * for example, st_renderbuffer_alloc_storage().
- */
-enum native_attachment {
-   NATIVE_ATTACHMENT_FRONT_LEFT,
-   NATIVE_ATTACHMENT_BACK_LEFT,
-   NATIVE_ATTACHMENT_FRONT_RIGHT,
-   NATIVE_ATTACHMENT_BACK_RIGHT,
-
-   NUM_NATIVE_ATTACHMENTS
-};
-
-/**
- * Enumerations for probe results.
- */
-enum native_probe_result {
-   NATIVE_PROBE_UNKNOWN,
-   NATIVE_PROBE_FALLBACK,
-   NATIVE_PROBE_SUPPORTED,
-   NATIVE_PROBE_EXACT,
-};
-
-/**
- * A probe object for display probe.
- */
-struct native_probe {
-   int magic;
-   EGLNativeDisplayType display;
-   void *data;
-
-   void (*destroy)(struct native_probe *nprobe);
-};
-
-struct native_surface {
-   void (*destroy)(struct native_surface *nsurf);
-
-   /**
-    * Swap the front and back buffers so that the back buffer is visible.  It
-    * is no-op if the surface is single-buffered.  The contents of the back
-    * buffer after swapping may or may not be preserved.
-    */
-   boolean (*swap_buffers)(struct native_surface *nsurf);
-
-   /**
-    * Make the front buffer visible.  In some native displays, changes to the
-    * front buffer might not be visible immediately and require manual flush.
-    */
-   boolean (*flush_frontbuffer)(struct native_surface *nsurf);
-
-   /**
-    * Validate the buffers of the surface.  textures, if not NULL, points to an
-    * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
-    * by the caller.  A sequence number is also returned.  The caller can use
-    * it to check if anything has changed since the last call. Any of the
-    * pointers may be NULL and it indicates the caller has no interest in those
-    * values.
-    *
-    * If this function is called multiple times with different attachment
-    * masks, those not listed in the latest call might be destroyed.  This
-    * behavior might change in the future.
-    */
-   boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
-                       unsigned int *seq_num, struct pipe_texture **textures,
-                       int *width, int *height);
-
-   /**
-    * Wait until all native commands affecting the surface has been executed.
-    */
-   void (*wait)(struct native_surface *nsurf);
-};
-
-struct native_config {
-   /* __GLcontextModes should go away some day */
-   __GLcontextModes mode;
-   enum pipe_format color_format;
-   enum pipe_format depth_format;
-   enum pipe_format stencil_format;
-
-   /* treat it as an additional flag to mode.drawableType */
-   boolean scanout_bit;
-};
-
-struct native_connector {
-   int dummy;
-};
-
-struct native_mode {
-   const char *desc;
-   int width, height;
-   int refresh_rate;
-};
-
-struct native_display_modeset;
-
-/**
- * A pipe winsys abstracts the OS.  A pipe screen abstracts the graphcis
- * hardware.  A native display consists of a pipe winsys, a pipe screen, and
- * the native display server.
- */
-struct native_display {
-   /**
-    * The pipe screen of the native display.
-    *
-    * Note that the "flush_frontbuffer" and "update_buffer" callbacks will be
-    * overridden.
-    */
-   struct pipe_screen *screen;
-
-   void (*destroy)(struct native_display *ndpy);
-
-   /**
-    * Get the supported configs.  The configs are owned by the display, but
-    * the returned array should be free()ed.
-    *
-    * The configs will be converted to EGL config by
-    * _eglConfigFromContextModesRec and validated by _eglValidateConfig.
-    * Those failing to pass the test will be skipped.
-    */
-   const struct native_config **(*get_configs)(struct native_display *ndpy,
-                                               int *num_configs);
-
-   /**
-    * Test if a pixmap is supported by the given config.  Required unless no
-    * config has GLX_PIXMAP_BIT set.
-    *
-    * This function is usually called to find a config that supports a given
-    * pixmap.  Thus, it is usually called with the same pixmap in a row.
-    */
-   boolean (*is_pixmap_supported)(struct native_display *ndpy,
-                                  EGLNativePixmapType pix,
-                                  const struct native_config *nconf);
-
-   /**
-    * Create a pipe context.
-    */
-   struct pipe_context *(*create_context)(struct native_display *ndpy,
-                                          void *context_private);
-
-   /**
-    * Create a window surface.  Required unless no config has GLX_WINDOW_BIT
-    * set.
-    */
-   struct native_surface *(*create_window_surface)(struct native_display *ndpy,
-                                                   EGLNativeWindowType win,
-                                                   const struct native_config *nconf);
-
-   /**
-    * Create a pixmap surface.  Required unless no config has GLX_PIXMAP_BIT
-    * set.
-    */
-   struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
-                                                   EGLNativePixmapType pix,
-                                                   const struct native_config *nconf);
-
-   /**
-    * Create a pbuffer surface.  Required unless no config has GLX_PBUFFER_BIT
-    * set.
-    */
-   struct native_surface *(*create_pbuffer_surface)(struct native_display *ndpy,
-                                                    const struct native_config *nconf,
-                                                    uint width, uint height);
-
-   const struct native_display_modeset *modeset;
-};
-
-/**
- * Mode setting interface of the native display.  It exposes the mode setting
- * capabilities of the underlying graphics hardware.
- */
-struct native_display_modeset {
-   /**
-    * Get the available physical connectors and the number of CRTCs.
-    */
-   const struct native_connector **(*get_connectors)(struct native_display *ndpy,
-                                                     int *num_connectors,
-                                                     int *num_crtcs);
-
-   /**
-    * Get the current supported modes of a connector.  The returned modes may
-    * change every time this function is called and those from previous calls
-    * might become invalid.
-    */
-   const struct native_mode **(*get_modes)(struct native_display *ndpy,
-                                           const struct native_connector *nconn,
-                                           int *num_modes);
-
-   /**
-    * Create a scan-out surface.  Required unless no config has
-    * GLX_SCREEN_BIT_MESA set.
-    */
-   struct native_surface *(*create_scanout_surface)(struct native_display *ndpy,
-                                                    const struct native_config *nconf,
-                                                    uint width, uint height);
-
-   /**
-    * Program the CRTC to output the surface to the given connectors with the
-    * given mode.  When surface is not given, the CRTC is disabled.
-    *
-    * This interface does not export a way to query capabilities of the CRTCs.
-    * The native display usually needs to dynamically map the index to a CRTC
-    * that supports the given connectors.
-    */
-   boolean (*program)(struct native_display *ndpy, int crtc_idx,
-                      struct native_surface *nsurf, uint x, uint y,
-                      const struct native_connector **nconns, int num_nconns,
-                      const struct native_mode *nmode);
-};
-
-/**
- * Test whether an attachment is set in the mask.
- */
-static INLINE boolean
-native_attachment_mask_test(uint mask, enum native_attachment att)
-{
-   return !!(mask & (1 << att));
-}
-
-/**
- * Return a probe object for the given display.
- *
- * Note that the returned object may be cached and used by different native
- * display modules.  It allows fast probing when multiple modules probe the
- * same display.
- */
-struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy);
-
-/**
- * Probe the probe object.
- */
-enum native_probe_result
-native_get_probe_result(struct native_probe *nprobe);
-
-const char *
-native_get_name(void);
-
-struct native_display *
-native_create_display(EGLNativeDisplayType dpy);
-
-#endif /* _NATIVE_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/common/st_public_tmp.h b/src/gallium/state_trackers/egl_g3d/common/st_public_tmp.h
deleted file mode 100644 (file)
index 507a0ec..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-ST_PUBLIC(st_create_context,              struct st_context *,       struct pipe_context *pipe, const __GLcontextModes *visual, struct st_context *share)
-ST_PUBLIC(st_destroy_context,             void,                      struct st_context *st)
-ST_PUBLIC(st_copy_context_state,          void,                      struct st_context *dst, struct st_context *src, uint mask)
-ST_PUBLIC(st_create_framebuffer,          struct st_framebuffer *,   const __GLcontextModes *visual, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, uint width, uint height, void *privateData)
-ST_PUBLIC(st_resize_framebuffer,          void,                      struct st_framebuffer *stfb, uint width, uint height)
-ST_PUBLIC(st_set_framebuffer_surface,     void,                      struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface *surf)
-ST_PUBLIC(st_get_framebuffer_dimensions,  void,                      struct st_framebuffer *stfb, uint *width, uint *height)
-ST_PUBLIC(st_get_framebuffer_surface,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface **surface)
-ST_PUBLIC(st_get_framebuffer_texture,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture)
-ST_PUBLIC(st_framebuffer_private,         void *,                    struct st_framebuffer *stfb)
-ST_PUBLIC(st_unreference_framebuffer,     void,                      struct st_framebuffer *stfb)
-ST_PUBLIC(st_make_current,                GLboolean,                 struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read)
-ST_PUBLIC(st_get_current,                 struct st_context *,       void)
-ST_PUBLIC(st_flush,                       void,                      struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence)
-ST_PUBLIC(st_finish,                      void,                      struct st_context *st)
-ST_PUBLIC(st_notify_swapbuffers,          void,                      struct st_framebuffer *stfb)
-ST_PUBLIC(st_bind_texture_surface,        int,                       struct pipe_surface *ps, int target, int level, enum pipe_format format)
-ST_PUBLIC(st_unbind_texture_surface,      int,                       struct pipe_surface *ps, int target, int level)
-ST_PUBLIC(st_get_proc_address,            st_proc,                   const char *procname)
-#undef ST_PUBLIC
diff --git a/src/gallium/state_trackers/egl_g3d/kms/native_kms.c b/src/gallium/state_trackers/egl_g3d/kms/native_kms.c
deleted file mode 100644 (file)
index d5baf2c..0000000
+++ /dev/null
@@ -1,866 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <string.h>
-
-#include "pipe/p_screen.h"
-#include "pipe/p_context.h"
-#include "util/u_debug.h"
-#include "util/u_memory.h"
-#include "egllog.h"
-
-#include "native_kms.h"
-
-static boolean
-kms_surface_validate(struct native_surface *nsurf, uint attachment_mask,
-                     unsigned int *seq_num, struct pipe_texture **textures,
-                     int *width, int *height)
-{
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   struct kms_display *kdpy = ksurf->kdpy;
-   struct pipe_screen *screen = kdpy->base.screen;
-   struct pipe_texture templ, *ptex;
-   int att;
-
-   if (attachment_mask) {
-      memset(&templ, 0, sizeof(templ));
-      templ.target = PIPE_TEXTURE_2D;
-      templ.last_level = 0;
-      templ.width0 = ksurf->width;
-      templ.height0 = ksurf->height;
-      templ.depth0 = 1;
-      templ.format = ksurf->color_format;
-      templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-      if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT)
-         templ.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY;
-   }
-
-   /* create textures */
-   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-      /* delay the allocation */
-      if (!native_attachment_mask_test(attachment_mask, att))
-         continue;
-
-      ptex = ksurf->textures[att];
-      if (!ptex) {
-         ptex = screen->texture_create(screen, &templ);
-         ksurf->textures[att] = ptex;
-      }
-
-      if (textures) {
-         textures[att] = NULL;
-         pipe_texture_reference(&textures[att], ptex);
-      }
-   }
-
-   if (seq_num)
-      *seq_num = ksurf->sequence_number;
-   if (width)
-      *width = ksurf->width;
-   if (height)
-      *height = ksurf->height;
-
-   return TRUE;
-}
-
-/**
- * Add textures as DRM framebuffers.
- */
-static boolean
-kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back)
-{
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   struct kms_display *kdpy = ksurf->kdpy;
-   int num_framebuffers = (need_back) ? 2 : 1;
-   int i, err;
-
-   for (i = 0; i < num_framebuffers; i++) {
-      struct kms_framebuffer *fb;
-      enum native_attachment natt;
-      unsigned int handle, stride;
-      uint block_bits;
-
-      if (i == 0) {
-         fb = &ksurf->front_fb;
-         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
-      }
-      else {
-         fb = &ksurf->back_fb;
-         natt = NATIVE_ATTACHMENT_BACK_LEFT;
-      }
-
-      if (!fb->texture) {
-         /* make sure the texture has been allocated */
-         kms_surface_validate(&ksurf->base, 1 << natt, NULL, NULL, NULL, NULL);
-         if (!ksurf->textures[natt])
-            return FALSE;
-
-         pipe_texture_reference(&fb->texture, ksurf->textures[natt]);
-      }
-
-      /* already initialized */
-      if (fb->buffer_id)
-         continue;
-
-      /* TODO detect the real value */
-      fb->is_passive = TRUE;
-
-      if (!kdpy->api->local_handle_from_texture(kdpy->api,
-               kdpy->base.screen, fb->texture, &stride, &handle))
-         return FALSE;
-
-      block_bits = util_format_get_blocksizebits(ksurf->color_format);
-      err = drmModeAddFB(kdpy->fd, ksurf->width, ksurf->height,
-            block_bits, block_bits, stride, handle, &fb->buffer_id);
-      if (err) {
-         fb->buffer_id = 0;
-         return FALSE;
-      }
-   }
-
-   return TRUE;
-}
-
-static boolean
-kms_surface_flush_frontbuffer(struct native_surface *nsurf)
-{
-#ifdef DRM_MODE_FEATURE_DIRTYFB
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   struct kms_display *kdpy = ksurf->kdpy;
-
-   /* pbuffer is private */
-   if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER)
-      return TRUE;
-
-   if (ksurf->front_fb.is_passive)
-      drmModeDirtyFB(kdpy->fd, ksurf->front_fb.buffer_id, NULL, 0);
-#endif
-
-   return TRUE;
-}
-
-static boolean
-kms_surface_swap_buffers(struct native_surface *nsurf)
-{
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   struct kms_crtc *kcrtc = &ksurf->current_crtc;
-   struct kms_display *kdpy = ksurf->kdpy;
-   struct kms_framebuffer tmp_fb;
-   struct pipe_texture *tmp_texture;
-   int err;
-
-   /* pbuffer is private */
-   if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER)
-      return TRUE;
-
-   if (!ksurf->back_fb.buffer_id) {
-      if (!kms_surface_init_framebuffers(&ksurf->base, TRUE))
-         return FALSE;
-   }
-
-   if (ksurf->is_shown && kcrtc->crtc) {
-      err = drmModeSetCrtc(kdpy->fd, kcrtc->crtc->crtc_id,
-            ksurf->back_fb.buffer_id, kcrtc->crtc->x, kcrtc->crtc->y,
-            kcrtc->connectors, kcrtc->num_connectors, &kcrtc->crtc->mode);
-      if (err)
-         return FALSE;
-   }
-
-   /* swap the buffers */
-   tmp_fb = ksurf->front_fb;
-   ksurf->front_fb = ksurf->back_fb;
-   ksurf->back_fb = tmp_fb;
-
-   tmp_texture = ksurf->textures[NATIVE_ATTACHMENT_FRONT_LEFT];
-   ksurf->textures[NATIVE_ATTACHMENT_FRONT_LEFT] =
-      ksurf->textures[NATIVE_ATTACHMENT_BACK_LEFT];
-   ksurf->textures[NATIVE_ATTACHMENT_BACK_LEFT] = tmp_texture;
-
-   /* the front/back textures are swapped */
-   ksurf->sequence_number++;
-
-   return TRUE;
-}
-
-static void
-kms_surface_wait(struct native_surface *nsurf)
-{
-   /* no-op */
-}
-
-static void
-kms_surface_destroy(struct native_surface *nsurf)
-{
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   int i;
-
-   if (ksurf->current_crtc.crtc)
-         drmModeFreeCrtc(ksurf->current_crtc.crtc);
-
-   if (ksurf->front_fb.buffer_id)
-      drmModeRmFB(ksurf->kdpy->fd, ksurf->front_fb.buffer_id);
-   pipe_texture_reference(&ksurf->front_fb.texture, NULL);
-
-   if (ksurf->back_fb.buffer_id)
-      drmModeRmFB(ksurf->kdpy->fd, ksurf->back_fb.buffer_id);
-   pipe_texture_reference(&ksurf->back_fb.texture, NULL);
-
-   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
-      struct pipe_texture *ptex = ksurf->textures[i];
-      pipe_texture_reference(&ptex, NULL);
-   }
-
-   free(ksurf);
-}
-
-static struct kms_surface *
-kms_display_create_surface(struct native_display *ndpy,
-                           enum kms_surface_type type,
-                           const struct native_config *nconf,
-                           uint width, uint height)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct kms_config *kconf = kms_config(nconf);
-   struct kms_surface *ksurf;
-
-   ksurf = CALLOC_STRUCT(kms_surface);
-   if (!ksurf)
-      return NULL;
-
-   ksurf->kdpy = kdpy;
-   ksurf->type = type;
-   ksurf->color_format = kconf->base.color_format;
-   ksurf->width = width;
-   ksurf->height = height;
-
-   ksurf->base.destroy = kms_surface_destroy;
-   ksurf->base.swap_buffers = kms_surface_swap_buffers;
-   ksurf->base.flush_frontbuffer = kms_surface_flush_frontbuffer;
-   ksurf->base.validate = kms_surface_validate;
-   ksurf->base.wait = kms_surface_wait;
-
-   return ksurf;
-}
-
-/**
- * Choose a CRTC that supports all given connectors.
- */
-static uint32_t
-kms_display_choose_crtc(struct native_display *ndpy,
-                        uint32_t *connectors, int num_connectors)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   int idx;
-
-   for (idx = 0; idx < kdpy->resources->count_crtcs; idx++) {
-      boolean found_crtc = TRUE;
-      int i, j;
-
-      for (i = 0; i < num_connectors; i++) {
-         drmModeConnectorPtr connector;
-         int encoder_idx = -1;
-
-         connector = drmModeGetConnector(kdpy->fd, connectors[i]);
-         if (!connector) {
-            found_crtc = FALSE;
-            break;
-         }
-
-         /* find an encoder the CRTC supports */
-         for (j = 0; j < connector->count_encoders; j++) {
-            drmModeEncoderPtr encoder =
-               drmModeGetEncoder(kdpy->fd, connector->encoders[j]);
-            if (encoder->possible_crtcs & (1 << idx)) {
-               encoder_idx = j;
-               break;
-            }
-            drmModeFreeEncoder(encoder);
-         }
-
-         drmModeFreeConnector(connector);
-         if (encoder_idx < 0) {
-            found_crtc = FALSE;
-            break;
-         }
-      }
-
-      if (found_crtc)
-         break;
-   }
-
-   if (idx >= kdpy->resources->count_crtcs) {
-      _eglLog(_EGL_WARNING,
-            "failed to find a CRTC that supports the given %d connectors",
-            num_connectors);
-      return 0;
-   }
-
-   return kdpy->resources->crtcs[idx];
-}
-
-/**
- * Remember the original CRTC status and set the CRTC
- */
-static boolean
-kms_display_set_crtc(struct native_display *ndpy, int crtc_idx,
-                     uint32_t buffer_id, uint32_t x, uint32_t y,
-                     uint32_t *connectors, int num_connectors,
-                     drmModeModeInfoPtr mode)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct kms_crtc *kcrtc = &kdpy->saved_crtcs[crtc_idx];
-   uint32_t crtc_id;
-   int err;
-
-   if (kcrtc->crtc) {
-      crtc_id = kcrtc->crtc->crtc_id;
-   }
-   else {
-      int count = 0, i;
-
-      /*
-       * Choose the CRTC once.  It could be more dynamic, but let's keep it
-       * simple for now.
-       */
-      crtc_id = kms_display_choose_crtc(&kdpy->base,
-            connectors, num_connectors);
-
-      /* save the original CRTC status */
-      kcrtc->crtc = drmModeGetCrtc(kdpy->fd, crtc_id);
-      if (!kcrtc->crtc)
-         return FALSE;
-
-      for (i = 0; i < kdpy->num_connectors; i++) {
-         struct kms_connector *kconn = &kdpy->connectors[i];
-         drmModeConnectorPtr connector = kconn->connector;
-         drmModeEncoderPtr encoder;
-
-         encoder = drmModeGetEncoder(kdpy->fd, connector->encoder_id);
-         if (encoder) {
-            if (encoder->crtc_id == crtc_id) {
-               kcrtc->connectors[count++] = connector->connector_id;
-               if (count >= Elements(kcrtc->connectors))
-                  break;
-            }
-            drmModeFreeEncoder(encoder);
-         }
-      }
-
-      kcrtc->num_connectors = count;
-   }
-
-   err = drmModeSetCrtc(kdpy->fd, crtc_id, buffer_id, x, y,
-         connectors, num_connectors, mode);
-   if (err) {
-      drmModeFreeCrtc(kcrtc->crtc);
-      kcrtc->crtc = NULL;
-      kcrtc->num_connectors = 0;
-
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-static boolean
-kms_display_program(struct native_display *ndpy, int crtc_idx,
-                    struct native_surface *nsurf, uint x, uint y,
-                    const struct native_connector **nconns, int num_nconns,
-                    const struct native_mode *nmode)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct kms_surface *ksurf = kms_surface(nsurf);
-   const struct kms_mode *kmode = kms_mode(nmode);
-   uint32_t connector_ids[32];
-   uint32_t buffer_id;
-   drmModeModeInfo mode_tmp, *mode;
-   int i;
-
-   if (num_nconns > Elements(connector_ids)) {
-      _eglLog(_EGL_WARNING, "too many connectors (%d)", num_nconns);
-      num_nconns = Elements(connector_ids);
-   }
-
-   if (ksurf) {
-      if (!kms_surface_init_framebuffers(&ksurf->base, FALSE))
-         return FALSE;
-
-      buffer_id = ksurf->front_fb.buffer_id;
-      /* the mode argument of drmModeSetCrtc is not constified */
-      mode_tmp = kmode->mode;
-      mode = &mode_tmp;
-   }
-   else {
-      /* disable the CRTC */
-      buffer_id = 0;
-      mode = NULL;
-      num_nconns = 0;
-   }
-
-   for (i = 0; i < num_nconns; i++) {
-      struct kms_connector *kconn = kms_connector(nconns[i]);
-      connector_ids[i] = kconn->connector->connector_id;
-   }
-
-   if (!kms_display_set_crtc(&kdpy->base, crtc_idx, buffer_id, x, y,
-            connector_ids, num_nconns, mode)) {
-      _eglLog(_EGL_WARNING, "failed to set CRTC %d", crtc_idx);
-
-      return FALSE;
-   }
-
-   if (kdpy->shown_surfaces[crtc_idx])
-      kdpy->shown_surfaces[crtc_idx]->is_shown = FALSE;
-   kdpy->shown_surfaces[crtc_idx] = ksurf;
-
-   /* remember the settings for buffer swapping */
-   if (ksurf) {
-      uint32_t crtc_id = kdpy->saved_crtcs[crtc_idx].crtc->crtc_id;
-      struct kms_crtc *kcrtc = &ksurf->current_crtc;
-
-      if (kcrtc->crtc)
-         drmModeFreeCrtc(kcrtc->crtc);
-      kcrtc->crtc = drmModeGetCrtc(kdpy->fd, crtc_id);
-
-      assert(num_nconns < Elements(kcrtc->connectors));
-      memcpy(kcrtc->connectors, connector_ids,
-            sizeof(*connector_ids) * num_nconns);
-      kcrtc->num_connectors = num_nconns;
-
-      ksurf->is_shown = TRUE;
-   }
-
-   return TRUE;
-}
-
-static const struct native_mode **
-kms_display_get_modes(struct native_display *ndpy,
-                      const struct native_connector *nconn,
-                      int *num_modes)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct kms_connector *kconn = kms_connector(nconn);
-   const struct native_mode **nmodes_return;
-   int count, i;
-
-   /* delete old data */
-   if (kconn->connector) {
-      drmModeFreeConnector(kconn->connector);
-      free(kconn->kms_modes);
-
-      kconn->connector = NULL;
-      kconn->kms_modes = NULL;
-      kconn->num_modes = 0;
-   }
-
-   /* detect again */
-   kconn->connector = drmModeGetConnector(kdpy->fd, kconn->connector_id);
-   if (!kconn->connector)
-      return NULL;
-
-   count = kconn->connector->count_modes;
-   kconn->kms_modes = calloc(count, sizeof(*kconn->kms_modes));
-   if (!kconn->kms_modes) {
-      drmModeFreeConnector(kconn->connector);
-      kconn->connector = NULL;
-
-      return NULL;
-   }
-
-   for (i = 0; i < count; i++) {
-      struct kms_mode *kmode = &kconn->kms_modes[i];
-      drmModeModeInfoPtr mode = &kconn->connector->modes[i];
-
-      kmode->mode = *mode;
-
-      kmode->base.desc = kmode->mode.name;
-      kmode->base.width = kmode->mode.hdisplay;
-      kmode->base.height = kmode->mode.vdisplay;
-      kmode->base.refresh_rate = kmode->mode.vrefresh / 1000;
-   }
-
-   nmodes_return = malloc(count * sizeof(*nmodes_return));
-   if (nmodes_return) {
-      for (i = 0; i < count; i++)
-         nmodes_return[i] = &kconn->kms_modes[i].base;
-      if (num_modes)
-         *num_modes = count;
-   }
-
-   return nmodes_return;
-}
-
-static const struct native_connector **
-kms_display_get_connectors(struct native_display *ndpy, int *num_connectors,
-                           int *num_crtc)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   const struct native_connector **connectors;
-   int i;
-
-   if (!kdpy->connectors) {
-      kdpy->connectors =
-         calloc(kdpy->resources->count_connectors, sizeof(*kdpy->connectors));
-      if (!kdpy->connectors)
-         return NULL;
-
-      for (i = 0; i < kdpy->resources->count_connectors; i++) {
-         struct kms_connector *kconn = &kdpy->connectors[i];
-
-         kconn->connector_id = kdpy->resources->connectors[i];
-         /* kconn->connector is allocated when the modes are asked */
-      }
-
-      kdpy->num_connectors = kdpy->resources->count_connectors;
-   }
-
-   connectors = malloc(kdpy->num_connectors * sizeof(*connectors));
-   if (connectors) {
-      for (i = 0; i < kdpy->num_connectors; i++)
-         connectors[i] = &kdpy->connectors[i].base;
-      if (num_connectors)
-         *num_connectors = kdpy->num_connectors;
-   }
-
-   if (num_crtc)
-      *num_crtc = kdpy->resources->count_crtcs;
-
-   return connectors;
-}
-
-static struct native_surface *
-kms_display_create_scanout_surface(struct native_display *ndpy,
-                                   const struct native_config *nconf,
-                                   uint width, uint height)
-{
-   struct kms_surface *ksurf;
-
-   ksurf = kms_display_create_surface(ndpy,
-         KMS_SURFACE_TYPE_SCANOUT, nconf, width, height);
-   return &ksurf->base;
-}
-
-static struct native_surface *
-kms_display_create_pbuffer_surface(struct native_display *ndpy,
-                                   const struct native_config *nconf,
-                                   uint width, uint height)
-{
-   struct kms_surface *ksurf;
-
-   ksurf = kms_display_create_surface(ndpy,
-         KMS_SURFACE_TYPE_PBUFFER, nconf, width, height);
-   return &ksurf->base;
-}
-
-static struct pipe_context *
-kms_display_create_context(struct native_display *ndpy, void *context_private)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct pipe_context *pctx;
-
-   pctx = kdpy->api->create_context(kdpy->api, kdpy->base.screen);
-   if (pctx)
-      pctx->priv = context_private;
-   return pctx;
-}
-
-static boolean
-kms_display_is_format_supported(struct native_display *ndpy,
-                                enum pipe_format fmt, boolean is_color)
-{
-   return ndpy->screen->is_format_supported(ndpy->screen,
-         fmt, PIPE_TEXTURE_2D,
-         (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
-         PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-}
-
-static const struct native_config **
-kms_display_get_configs(struct native_display *ndpy, int *num_configs)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   const struct native_config **configs;
-
-   /* first time */
-   if (!kdpy->config) {
-      struct native_config *nconf;
-      enum pipe_format format;
-
-      kdpy->config = calloc(1, sizeof(*kdpy->config));
-      if (!kdpy->config)
-         return NULL;
-
-      nconf = &kdpy->config->base;
-
-      /* always double-buffered */
-      nconf->mode.doubleBufferMode = TRUE;
-
-      format = PIPE_FORMAT_A8R8G8B8_UNORM;
-      if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) {
-         format = PIPE_FORMAT_B8G8R8A8_UNORM;
-         if (!kms_display_is_format_supported(&kdpy->base, format, TRUE))
-            format = PIPE_FORMAT_NONE;
-      }
-      if (format == PIPE_FORMAT_NONE)
-         return NULL;
-
-      nconf->color_format = format;
-      nconf->mode.redBits = 8;
-      nconf->mode.greenBits = 8;
-      nconf->mode.blueBits = 8;
-      nconf->mode.alphaBits = 8;
-      nconf->mode.rgbBits = 32;
-
-      format = PIPE_FORMAT_S8Z24_UNORM;
-      if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) {
-         format = PIPE_FORMAT_Z24S8_UNORM;
-         if (!kms_display_is_format_supported(&kdpy->base, format, FALSE))
-            format = PIPE_FORMAT_NONE;
-      }
-      if (format != PIPE_FORMAT_NONE) {
-         nconf->depth_format = format;
-         nconf->stencil_format = format;
-
-         nconf->mode.depthBits = 24;
-         nconf->mode.stencilBits = 8;
-         nconf->mode.haveDepthBuffer = TRUE;
-         nconf->mode.haveStencilBuffer = TRUE;
-      }
-
-      nconf->scanout_bit = TRUE;
-      nconf->mode.drawableType = GLX_PBUFFER_BIT;
-      nconf->mode.swapMethod = GLX_SWAP_EXCHANGE_OML;
-
-      nconf->mode.visualID = 0;
-      nconf->mode.visualType = EGL_NONE;
-
-      nconf->mode.renderType = GLX_RGBA_BIT;
-      nconf->mode.rgbMode = TRUE;
-      nconf->mode.xRenderable = FALSE;
-   }
-
-   configs = malloc(sizeof(*configs));
-   if (configs) {
-      configs[0] = &kdpy->config->base;
-      if (num_configs)
-         *num_configs = 1;
-   }
-
-   return configs;
-}
-
-static void
-kms_display_destroy(struct native_display *ndpy)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   int i;
-
-   if (kdpy->config)
-      free(kdpy->config);
-
-   if (kdpy->connectors) {
-      for (i = 0; i < kdpy->num_connectors; i++) {
-         struct kms_connector *kconn = &kdpy->connectors[i];
-         if (kconn->connector) {
-            drmModeFreeConnector(kconn->connector);
-            free(kconn->kms_modes);
-         }
-      }
-      free(kdpy->connectors);
-   }
-
-   if (kdpy->shown_surfaces)
-      free(kdpy->shown_surfaces);
-
-   if (kdpy->saved_crtcs) {
-      for (i = 0; i < kdpy->resources->count_crtcs; i++) {
-         struct kms_crtc *kcrtc = &kdpy->saved_crtcs[i];
-
-         if (kcrtc->crtc) {
-            /* restore crtc */
-            drmModeSetCrtc(kdpy->fd, kcrtc->crtc->crtc_id,
-                  kcrtc->crtc->buffer_id, kcrtc->crtc->x, kcrtc->crtc->y,
-                  kcrtc->connectors, kcrtc->num_connectors,
-                  &kcrtc->crtc->mode);
-
-            drmModeFreeCrtc(kcrtc->crtc);
-         }
-      }
-      free(kdpy->saved_crtcs);
-   }
-
-   if (kdpy->resources)
-      drmModeFreeResources(kdpy->resources);
-
-   if (kdpy->base.screen)
-      kdpy->base.screen->destroy(kdpy->base.screen);
-
-   if (kdpy->fd >= 0)
-      drmClose(kdpy->fd);
-
-   if (kdpy->api)
-      kdpy->api->destroy(kdpy->api);
-   free(kdpy);
-}
-
-/**
- * Initialize KMS and pipe screen.
- */
-static boolean
-kms_display_init_screen(struct native_display *ndpy)
-{
-   struct kms_display *kdpy = kms_display(ndpy);
-   struct drm_create_screen_arg arg;
-   int fd;
-
-   fd = drmOpen(kdpy->api->name, NULL);
-   if (fd < 0) {
-      _eglLog(_EGL_WARNING, "failed to open DRM device");
-      return FALSE;
-   }
-
-#if 0
-   if (drmSetMaster(fd)) {
-      _eglLog(_EGL_WARNING, "failed to become DRM master");
-      return FALSE;
-   }
-#endif
-
-   memset(&arg, 0, sizeof(arg));
-   arg.mode = DRM_CREATE_NORMAL;
-   kdpy->base.screen = kdpy->api->create_screen(kdpy->api, fd, &arg);
-   if (!kdpy->base.screen) {
-      _eglLog(_EGL_WARNING, "failed to create DRM screen");
-      drmClose(fd);
-      return FALSE;
-   }
-
-   kdpy->fd = fd;
-
-   return TRUE;
-}
-
-static struct native_display_modeset kms_display_modeset = {
-   .get_connectors = kms_display_get_connectors,
-   .get_modes = kms_display_get_modes,
-   .create_scanout_surface = kms_display_create_scanout_surface,
-   .program = kms_display_program
-};
-
-static struct native_display *
-kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api)
-{
-   struct kms_display *kdpy;
-
-   kdpy = CALLOC_STRUCT(kms_display);
-   if (!kdpy)
-      return NULL;
-
-   kdpy->api = api;
-   if (!kdpy->api) {
-      _eglLog(_EGL_WARNING, "failed to create DRM API");
-      free(kdpy);
-      return NULL;
-   }
-
-   kdpy->fd = -1;
-   if (!kms_display_init_screen(&kdpy->base)) {
-      kms_display_destroy(&kdpy->base);
-      return NULL;
-   }
-
-   /* resources are fixed, unlike crtc, connector, or encoder */
-   kdpy->resources = drmModeGetResources(kdpy->fd);
-   if (!kdpy->resources) {
-      kms_display_destroy(&kdpy->base);
-      return NULL;
-   }
-
-   kdpy->saved_crtcs =
-      calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->saved_crtcs));
-   if (!kdpy->saved_crtcs) {
-      kms_display_destroy(&kdpy->base);
-      return NULL;
-   }
-
-   kdpy->shown_surfaces =
-      calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->shown_surfaces));
-   if (!kdpy->shown_surfaces) {
-      kms_display_destroy(&kdpy->base);
-      return NULL;
-   }
-
-   kdpy->base.destroy = kms_display_destroy;
-   kdpy->base.get_configs = kms_display_get_configs;
-   kdpy->base.create_context = kms_display_create_context;
-   kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface;
-
-   kdpy->base.modeset = &kms_display_modeset;
-
-   return &kdpy->base;
-}
-
-struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
-{
-   return NULL;
-}
-
-enum native_probe_result
-native_get_probe_result(struct native_probe *nprobe)
-{
-   return NATIVE_PROBE_UNKNOWN;
-}
-
-/* the api is destroyed with the native display */
-static struct drm_api *drm_api;
-
-const char *
-native_get_name(void)
-{
-   static char kms_name[32];
-
-   if (!drm_api)
-      drm_api = drm_api_create();
-
-   if (drm_api)
-      snprintf(kms_name, sizeof(kms_name), "KMS/%s", drm_api->name);
-   else
-      snprintf(kms_name, sizeof(kms_name), "KMS");
-
-   return kms_name;
-}
-
-struct native_display *
-native_create_display(EGLNativeDisplayType dpy)
-{
-   struct native_display *ndpy = NULL;
-
-   if (!drm_api)
-      drm_api = drm_api_create();
-
-   if (drm_api)
-      ndpy = kms_create_display(dpy, drm_api);
-
-   return ndpy;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/kms/native_kms.h b/src/gallium/state_trackers/egl_g3d/kms/native_kms.h
deleted file mode 100644 (file)
index 095186e..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _NATIVE_KMS_H_
-#define _NATIVE_KMS_H_
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "pipe/p_compiler.h"
-#include "util/u_format.h"
-#include "pipe/p_state.h"
-#include "state_tracker/drm_api.h"
-
-#include "common/native.h"
-
-enum kms_surface_type {
-   KMS_SURFACE_TYPE_PBUFFER,
-   KMS_SURFACE_TYPE_SCANOUT
-};
-
-struct kms_config;
-struct kms_connector;
-struct kms_mode;
-
-struct kms_crtc {
-   drmModeCrtcPtr crtc;
-   uint32_t connectors[32];
-   int num_connectors;
-};
-
-struct kms_display {
-   struct native_display base;
-
-   int fd;
-   struct drm_api *api;
-   drmModeResPtr resources;
-   struct kms_config *config;
-
-   struct kms_connector *connectors;
-   int num_connectors;
-
-   struct kms_surface **shown_surfaces;
-   /* save the original settings of the CRTCs */
-   struct kms_crtc *saved_crtcs;
-};
-
-struct kms_framebuffer {
-   struct pipe_texture *texture;
-   boolean is_passive;
-
-   uint32_t buffer_id;
-};
-
-struct kms_surface {
-   struct native_surface base;
-   enum kms_surface_type type;
-   enum pipe_format color_format;
-   struct kms_display *kdpy;
-   int width, height;
-
-   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
-   unsigned int sequence_number;
-   struct kms_framebuffer front_fb, back_fb;
-
-   boolean is_shown;
-   struct kms_crtc current_crtc;
-};
-
-struct kms_config {
-   struct native_config base;
-};
-
-struct kms_connector {
-   struct native_connector base;
-
-   uint32_t connector_id;
-   drmModeConnectorPtr connector;
-   struct kms_mode *kms_modes;
-   int num_modes;
-};
-
-struct kms_mode {
-   struct native_mode base;
-   drmModeModeInfo mode;
-};
-
-static INLINE struct kms_display *
-kms_display(const struct native_display *ndpy)
-{
-   return (struct kms_display *) ndpy;
-}
-
-static INLINE struct kms_surface *
-kms_surface(const struct native_surface *nsurf)
-{
-   return (struct kms_surface *) nsurf;
-}
-
-static INLINE struct kms_config *
-kms_config(const struct native_config *nconf)
-{
-   return (struct kms_config *) nconf;
-}
-
-static INLINE struct kms_connector *
-kms_connector(const struct native_connector *nconn)
-{
-   return (struct kms_connector *) nconn;
-}
-
-static INLINE struct kms_mode *
-kms_mode(const struct native_mode *nmode)
-{
-   return (struct kms_mode *) nmode;
-}
-
-#endif /* _NATIVE_KMS_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/x11/glxinit.c b/src/gallium/state_trackers/egl_g3d/x11/glxinit.c
deleted file mode 100644 (file)
index c955a90..0000000
+++ /dev/null
@@ -1,573 +0,0 @@
-/**
- * GLX initialization.  Code based on glxext.c, glx_query.c, and
- * glcontextmodes.c under src/glx/x11/.  The major difference is that no DRI
- * related code here.
- *
- */
-
-#include <assert.h>
-#include <X11/Xlib.h>
-#include <X11/Xproto.h>
-#include <X11/extensions/Xext.h>
-#include <X11/extensions/extutil.h>
-#include <sys/time.h>
-
-#include "x11_screen.h"
-#include "glxinit.h"
-
-typedef struct GLXGenericGetString
-{
-   CARD8 reqType;
-   CARD8 glxCode;
-   CARD16 length B16;
-   CARD32 for_whom B32;
-   CARD32 name B32;
-} xGLXGenericGetStringReq;
-
-#define sz_xGLXGenericGetStringReq 12
-#define X_GLXGenericGetString 0
-
-/* Extension required boiler plate */
-
-static char *__glXExtensionName = GLX_EXTENSION_NAME;
-static XExtensionInfo *__glXExtensionInfo = NULL;
-
-static /* const */ XExtensionHooks __glXExtensionHooks = { NULL };
-static
-XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo,
-                           __glXExtensionName, &__glXExtensionHooks,
-                           __GLX_NUMBER_EVENTS, NULL)
-
-static GLint
-_gl_convert_from_x_visual_type(int visualType)
-{
-#define NUM_VISUAL_TYPES   6
-   static const int glx_visual_types[NUM_VISUAL_TYPES] = {
-      GLX_STATIC_GRAY, GLX_GRAY_SCALE,
-      GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
-      GLX_TRUE_COLOR, GLX_DIRECT_COLOR
-   };
-
-   return ((unsigned) visualType < NUM_VISUAL_TYPES)
-      ? glx_visual_types[visualType] : GLX_NONE;
-}
-
-_X_HIDDEN char *
-__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name)
-{
-   xGLXGenericGetStringReq *req;
-   xGLXSingleReply reply;
-   int length;
-   int numbytes;
-   char *buf;
-   CARD32 for_whom = screen;
-   CARD32 glxCode = X_GLXQueryServerString;
-
-
-   LockDisplay(dpy);
-
-
-   /* All of the GLX protocol requests for getting a string from the server
-    * look the same.  The exact meaning of the for_whom field is usually
-    * either the screen number (for glXQueryServerString) or the context tag
-    * (for GLXSingle).
-    */
-
-   GetReq(GLXGenericGetString, req);
-   req->reqType = opcode;
-   req->glxCode = glxCode;
-   req->for_whom = for_whom;
-   req->name = name;
-
-   _XReply(dpy, (xReply *) & reply, 0, False);
-
-   length = reply.length * 4;
-   numbytes = reply.size;
-
-   buf = (char *) Xmalloc(numbytes);
-   if (buf != NULL) {
-      _XRead(dpy, buf, numbytes);
-      length -= numbytes;
-   }
-
-   _XEatData(dpy, length);
-
-   UnlockDisplay(dpy);
-   SyncHandle();
-
-   return buf;
-}
-
-/************************************************************************/
-/*
-** Free the per screen configs data as well as the array of
-** __glXScreenConfigs.
-*/
-static void
-FreeScreenConfigs(__GLXdisplayPrivate * priv)
-{
-   __GLXscreenConfigs *psc;
-   GLint i, screens;
-
-   /* Free screen configuration information */
-   psc = priv->screenConfigs;
-   screens = ScreenCount(priv->dpy);
-   for (i = 0; i < screens; i++, psc++) {
-      if (psc->configs) {
-         x11_context_modes_destroy(psc->configs);
-         psc->configs = NULL;   /* NOTE: just for paranoia */
-      }
-      if (psc->visuals) {
-         x11_context_modes_destroy(psc->visuals);
-         psc->visuals = NULL;   /* NOTE: just for paranoia */
-      }
-      Xfree((char *) psc->serverGLXexts);
-   }
-   XFree((char *) priv->screenConfigs);
-   priv->screenConfigs = NULL;
-}
-
-/************************************************************************/
-
-/*
-** Query the version of the GLX extension.  This procedure works even if
-** the client extension is not completely set up.
-*/
-static Bool
-QueryVersion(Display * dpy, int opcode, int *major, int *minor)
-{
-   xGLXQueryVersionReq *req;
-   xGLXQueryVersionReply reply;
-
-   /* Send the glXQueryVersion request */
-   LockDisplay(dpy);
-   GetReq(GLXQueryVersion, req);
-   req->reqType = opcode;
-   req->glxCode = X_GLXQueryVersion;
-   req->majorVersion = GLX_MAJOR_VERSION;
-   req->minorVersion = GLX_MINOR_VERSION;
-   _XReply(dpy, (xReply *) & reply, 0, False);
-   UnlockDisplay(dpy);
-   SyncHandle();
-
-   if (reply.majorVersion != GLX_MAJOR_VERSION) {
-      /*
-       ** The server does not support the same major release as this
-       ** client.
-       */
-      return GL_FALSE;
-   }
-   *major = reply.majorVersion;
-   *minor = min(reply.minorVersion, GLX_MINOR_VERSION);
-   return GL_TRUE;
-}
-
-_X_HIDDEN void
-__glXInitializeVisualConfigFromTags(__GLcontextModes * config, int count,
-                                    const INT32 * bp, Bool tagged_only,
-                                    Bool fbconfig_style_tags)
-{
-   int i;
-
-   if (!tagged_only) {
-      /* Copy in the first set of properties */
-      config->visualID = *bp++;
-
-      config->visualType = _gl_convert_from_x_visual_type(*bp++);
-
-      config->rgbMode = *bp++;
-
-      config->redBits = *bp++;
-      config->greenBits = *bp++;
-      config->blueBits = *bp++;
-      config->alphaBits = *bp++;
-      config->accumRedBits = *bp++;
-      config->accumGreenBits = *bp++;
-      config->accumBlueBits = *bp++;
-      config->accumAlphaBits = *bp++;
-
-      config->doubleBufferMode = *bp++;
-      config->stereoMode = *bp++;
-
-      config->rgbBits = *bp++;
-      config->depthBits = *bp++;
-      config->stencilBits = *bp++;
-      config->numAuxBuffers = *bp++;
-      config->level = *bp++;
-
-      count -= __GLX_MIN_CONFIG_PROPS;
-   }
-
-   /*
-    ** Additional properties may be in a list at the end
-    ** of the reply.  They are in pairs of property type
-    ** and property value.
-    */
-
-#define FETCH_OR_SET(tag) \
-    config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
-
-   for (i = 0; i < count; i += 2) {
-      switch (*bp++) {
-      case GLX_RGBA:
-         FETCH_OR_SET(rgbMode);
-         break;
-      case GLX_BUFFER_SIZE:
-         config->rgbBits = *bp++;
-         break;
-      case GLX_LEVEL:
-         config->level = *bp++;
-         break;
-      case GLX_DOUBLEBUFFER:
-         FETCH_OR_SET(doubleBufferMode);
-         break;
-      case GLX_STEREO:
-         FETCH_OR_SET(stereoMode);
-         break;
-      case GLX_AUX_BUFFERS:
-         config->numAuxBuffers = *bp++;
-         break;
-      case GLX_RED_SIZE:
-         config->redBits = *bp++;
-         break;
-      case GLX_GREEN_SIZE:
-         config->greenBits = *bp++;
-         break;
-      case GLX_BLUE_SIZE:
-         config->blueBits = *bp++;
-         break;
-      case GLX_ALPHA_SIZE:
-         config->alphaBits = *bp++;
-         break;
-      case GLX_DEPTH_SIZE:
-         config->depthBits = *bp++;
-         break;
-      case GLX_STENCIL_SIZE:
-         config->stencilBits = *bp++;
-         break;
-      case GLX_ACCUM_RED_SIZE:
-         config->accumRedBits = *bp++;
-         break;
-      case GLX_ACCUM_GREEN_SIZE:
-         config->accumGreenBits = *bp++;
-         break;
-      case GLX_ACCUM_BLUE_SIZE:
-         config->accumBlueBits = *bp++;
-         break;
-      case GLX_ACCUM_ALPHA_SIZE:
-         config->accumAlphaBits = *bp++;
-         break;
-      case GLX_VISUAL_CAVEAT_EXT:
-         config->visualRating = *bp++;
-         break;
-      case GLX_X_VISUAL_TYPE:
-         config->visualType = *bp++;
-         break;
-      case GLX_TRANSPARENT_TYPE:
-         config->transparentPixel = *bp++;
-         break;
-      case GLX_TRANSPARENT_INDEX_VALUE:
-         config->transparentIndex = *bp++;
-         break;
-      case GLX_TRANSPARENT_RED_VALUE:
-         config->transparentRed = *bp++;
-         break;
-      case GLX_TRANSPARENT_GREEN_VALUE:
-         config->transparentGreen = *bp++;
-         break;
-      case GLX_TRANSPARENT_BLUE_VALUE:
-         config->transparentBlue = *bp++;
-         break;
-      case GLX_TRANSPARENT_ALPHA_VALUE:
-         config->transparentAlpha = *bp++;
-         break;
-      case GLX_VISUAL_ID:
-         config->visualID = *bp++;
-         break;
-      case GLX_DRAWABLE_TYPE:
-         config->drawableType = *bp++;
-         break;
-      case GLX_RENDER_TYPE:
-         config->renderType = *bp++;
-         break;
-      case GLX_X_RENDERABLE:
-         config->xRenderable = *bp++;
-         break;
-      case GLX_FBCONFIG_ID:
-         config->fbconfigID = *bp++;
-         break;
-      case GLX_MAX_PBUFFER_WIDTH:
-         config->maxPbufferWidth = *bp++;
-         break;
-      case GLX_MAX_PBUFFER_HEIGHT:
-         config->maxPbufferHeight = *bp++;
-         break;
-      case GLX_MAX_PBUFFER_PIXELS:
-         config->maxPbufferPixels = *bp++;
-         break;
-      case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
-         config->optimalPbufferWidth = *bp++;
-         break;
-      case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
-         config->optimalPbufferHeight = *bp++;
-         break;
-      case GLX_VISUAL_SELECT_GROUP_SGIX:
-         config->visualSelectGroup = *bp++;
-         break;
-      case GLX_SWAP_METHOD_OML:
-         config->swapMethod = *bp++;
-         break;
-      case GLX_SAMPLE_BUFFERS_SGIS:
-         config->sampleBuffers = *bp++;
-         break;
-      case GLX_SAMPLES_SGIS:
-         config->samples = *bp++;
-         break;
-      case GLX_BIND_TO_TEXTURE_RGB_EXT:
-         config->bindToTextureRgb = *bp++;
-         break;
-      case GLX_BIND_TO_TEXTURE_RGBA_EXT:
-         config->bindToTextureRgba = *bp++;
-         break;
-      case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
-         config->bindToMipmapTexture = *bp++;
-         break;
-      case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
-         config->bindToTextureTargets = *bp++;
-         break;
-      case GLX_Y_INVERTED_EXT:
-         config->yInverted = *bp++;
-         break;
-      case None:
-         i = count;
-         break;
-      default:
-         break;
-      }
-   }
-
-   config->renderType =
-      (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
-
-   config->haveAccumBuffer = ((config->accumRedBits +
-                               config->accumGreenBits +
-                               config->accumBlueBits +
-                               config->accumAlphaBits) > 0);
-   config->haveDepthBuffer = (config->depthBits > 0);
-   config->haveStencilBuffer = (config->stencilBits > 0);
-}
-
-static __GLcontextModes *
-createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
-                            int screen, GLboolean tagged_only)
-{
-   INT32 buf[__GLX_TOTAL_CONFIG], *props;
-   unsigned prop_size;
-   __GLcontextModes *modes, *m;
-   int i;
-
-   if (nprops == 0)
-      return NULL;
-
-   /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
-
-   /* Check number of properties */
-   if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
-      return NULL;
-
-   /* Allocate memory for our config structure */
-   modes = x11_context_modes_create(nvisuals);
-   if (!modes)
-      return NULL;
-
-   prop_size = nprops * __GLX_SIZE_INT32;
-   if (prop_size <= sizeof(buf))
-      props = buf;
-   else
-      props = Xmalloc(prop_size);
-
-   /* Read each config structure and convert it into our format */
-   m = modes;
-   for (i = 0; i < nvisuals; i++) {
-      _XRead(dpy, (char *) props, prop_size);
-      /* Older X servers don't send this so we default it here. */
-      m->drawableType = GLX_WINDOW_BIT;
-      __glXInitializeVisualConfigFromTags(m, nprops, props,
-                                     tagged_only, GL_TRUE);
-      m->screen = screen;
-      m = m->next;
-   }
-
-   if (props != buf)
-      Xfree(props);
-
-   return modes;
-}
-
-static GLboolean
-getVisualConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen)
-{
-   xGLXGetVisualConfigsReq *req;
-   __GLXscreenConfigs *psc;
-   xGLXGetVisualConfigsReply reply;
-
-   LockDisplay(dpy);
-
-   psc = priv->screenConfigs + screen;
-   psc->visuals = NULL;
-   GetReq(GLXGetVisualConfigs, req);
-   req->reqType = priv->majorOpcode;
-   req->glxCode = X_GLXGetVisualConfigs;
-   req->screen = screen;
-
-   if (!_XReply(dpy, (xReply *) & reply, 0, False))
-      goto out;
-
-   psc->visuals = createConfigsFromProperties(dpy,
-                                              reply.numVisuals,
-                                              reply.numProps,
-                                              screen, GL_FALSE);
-
- out:
-   UnlockDisplay(dpy);
-   return psc->visuals != NULL;
-}
-
-static GLboolean
-getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen)
-{
-   xGLXGetFBConfigsReq *fb_req;
-   xGLXGetFBConfigsSGIXReq *sgi_req;
-   xGLXVendorPrivateWithReplyReq *vpreq;
-   xGLXGetFBConfigsReply reply;
-   __GLXscreenConfigs *psc;
-
-   psc = priv->screenConfigs + screen;
-   psc->serverGLXexts =
-      __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
-
-   LockDisplay(dpy);
-
-   psc->configs = NULL;
-   if (atof(priv->serverGLXversion) >= 1.3) {
-      GetReq(GLXGetFBConfigs, fb_req);
-      fb_req->reqType = priv->majorOpcode;
-      fb_req->glxCode = X_GLXGetFBConfigs;
-      fb_req->screen = screen;
-   }
-   else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
-      GetReqExtra(GLXVendorPrivateWithReply,
-                  sz_xGLXGetFBConfigsSGIXReq +
-                  sz_xGLXVendorPrivateWithReplyReq, vpreq);
-      sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
-      sgi_req->reqType = priv->majorOpcode;
-      sgi_req->glxCode = X_GLXVendorPrivateWithReply;
-      sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
-      sgi_req->screen = screen;
-   }
-   else
-      goto out;
-
-   if (!_XReply(dpy, (xReply *) & reply, 0, False))
-      goto out;
-
-   psc->configs = createConfigsFromProperties(dpy,
-                                              reply.numFBConfigs,
-                                              reply.numAttribs * 2,
-                                              screen, GL_TRUE);
-
- out:
-   UnlockDisplay(dpy);
-   return psc->configs != NULL;
-}
-
-static GLboolean
-AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
-{
-   __GLXscreenConfigs *psc;
-   GLint i, screens;
-
-   /*
-    ** First allocate memory for the array of per screen configs.
-    */
-   screens = ScreenCount(dpy);
-   psc = (__GLXscreenConfigs *) Xmalloc(screens * sizeof(__GLXscreenConfigs));
-   if (!psc) {
-      return GL_FALSE;
-   }
-   memset(psc, 0, screens * sizeof(__GLXscreenConfigs));
-   priv->screenConfigs = psc;
-
-   priv->serverGLXversion =
-      __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
-   if (priv->serverGLXversion == NULL) {
-      FreeScreenConfigs(priv);
-      return GL_FALSE;
-   }
-
-   for (i = 0; i < screens; i++, psc++) {
-      getFBConfigs(dpy, priv, i);
-      getVisualConfigs(dpy, priv, i);
-      psc->scr = i;
-      psc->dpy = dpy;
-   }
-
-   SyncHandle();
-
-   return GL_TRUE;
-}
-
-_X_HIDDEN void
-__glXRelease(__GLXdisplayPrivate *dpyPriv)
-{
-   FreeScreenConfigs(dpyPriv);
-
-   if (dpyPriv->serverGLXvendor) {
-      Xfree((char *) dpyPriv->serverGLXvendor);
-      dpyPriv->serverGLXvendor = NULL;
-   }
-   if (dpyPriv->serverGLXversion) {
-      Xfree((char *) dpyPriv->serverGLXversion);
-      dpyPriv->serverGLXversion = NULL;
-   }
-
-   Xfree(dpyPriv);
-}
-
-_X_HIDDEN __GLXdisplayPrivate *
-__glXInitialize(Display * dpy)
-{
-   XExtDisplayInfo *info = __glXFindDisplay(dpy);
-   __GLXdisplayPrivate *dpyPriv;
-   int major, minor;
-
-   if (!XextHasExtension(info))
-      return NULL;
-
-   /* See if the versions are compatible */
-   if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor))
-      return NULL;
-
-   dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate));
-   if (!dpyPriv)
-      return NULL;
-
-   /*
-    ** Init the display private and then read in the screen config
-    ** structures from the server.
-    */
-   dpyPriv->majorOpcode = info->codes->major_opcode;
-   dpyPriv->majorVersion = major;
-   dpyPriv->minorVersion = minor;
-   dpyPriv->dpy = dpy;
-
-   dpyPriv->serverGLXvendor = NULL;
-   dpyPriv->serverGLXversion = NULL;
-
-   if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
-      Xfree(dpyPriv);
-      return NULL;
-   }
-
-   return dpyPriv;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/glxinit.h b/src/gallium/state_trackers/egl_g3d/x11/glxinit.h
deleted file mode 100644 (file)
index 515a825..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef GLXINIT_INCLUDED
-#define GLXINIT_INCLUDED
-
-#include <X11/Xlib.h>
-
-#ifndef GLX_DIRECT_RENDERING
-#define GLX_DIRECT_RENDERING
-#endif
-#include "glxclient.h"
-
-extern void
-__glXRelease(__GLXdisplayPrivate *dpyPriv);
-
-#endif /* GLXINIT_INCLUDED */
diff --git a/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c b/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c
deleted file mode 100644 (file)
index 07f82d8..0000000
+++ /dev/null
@@ -1,705 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 "util/u_memory.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "pipe/p_compiler.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "state_tracker/drm_api.h"
-#include "egllog.h"
-
-#include "native_x11.h"
-#include "x11_screen.h"
-
-enum dri2_surface_type {
-   DRI2_SURFACE_TYPE_WINDOW,
-   DRI2_SURFACE_TYPE_PIXMAP,
-   DRI2_SURFACE_TYPE_PBUFFER
-};
-
-struct dri2_display {
-   struct native_display base;
-   Display *dpy;
-   boolean own_dpy;
-
-   struct drm_api *api;
-   struct x11_screen *xscr;
-   int xscr_number;
-
-   struct dri2_config *configs;
-   int num_configs;
-};
-
-struct dri2_surface {
-   struct native_surface base;
-   Drawable drawable;
-   enum dri2_surface_type type;
-   enum pipe_format color_format;
-   struct dri2_display *dri2dpy;
-
-   struct pipe_texture *pbuffer_textures[NUM_NATIVE_ATTACHMENTS];
-   boolean have_back, have_fake;
-   int width, height;
-   unsigned int sequence_number;
-};
-
-struct dri2_config {
-   struct native_config base;
-};
-
-static INLINE struct dri2_display *
-dri2_display(const struct native_display *ndpy)
-{
-   return (struct dri2_display *) ndpy;
-}
-
-static INLINE struct dri2_surface *
-dri2_surface(const struct native_surface *nsurf)
-{
-   return (struct dri2_surface *) nsurf;
-}
-
-static INLINE struct dri2_config *
-dri2_config(const struct native_config *nconf)
-{
-   return (struct dri2_config *) nconf;
-}
-
-static boolean
-dri2_surface_flush_frontbuffer(struct native_surface *nsurf)
-{
-   struct dri2_surface *dri2surf = dri2_surface(nsurf);
-   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
-
-   /* pbuffer is private */
-   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
-      return TRUE;
-
-   /* copy to real front buffer */
-   if (dri2surf->have_fake)
-      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
-            0, 0, dri2surf->width, dri2surf->height,
-            DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
-
-   return TRUE;
-}
-
-static boolean
-dri2_surface_swap_buffers(struct native_surface *nsurf)
-{
-   struct dri2_surface *dri2surf = dri2_surface(nsurf);
-   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
-
-   /* pbuffer is private */
-   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER)
-      return TRUE;
-
-   /* copy to front buffer */
-   if (dri2surf->have_back)
-      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
-            0, 0, dri2surf->width, dri2surf->height,
-            DRI2BufferBackLeft, DRI2BufferFrontLeft);
-
-   /* and update fake front buffer */
-   if (dri2surf->have_fake)
-      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
-            0, 0, dri2surf->width, dri2surf->height,
-            DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
-
-   return TRUE;
-}
-
-static boolean
-dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
-                      unsigned int *seq_num, struct pipe_texture **textures,
-                      int *width, int *height)
-{
-   struct dri2_surface *dri2surf = dri2_surface(nsurf);
-   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
-   unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS];
-   struct pipe_texture templ;
-   struct x11_drawable_buffer *xbufs;
-   int num_ins, num_outs, att, i;
-
-   if (attachment_mask) {
-      memset(&templ, 0, sizeof(templ));
-      templ.target = PIPE_TEXTURE_2D;
-      templ.last_level = 0;
-      templ.width0 = dri2surf->width;
-      templ.height0 = dri2surf->height;
-      templ.depth0 = 1;
-      templ.format = dri2surf->color_format;
-      templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-
-      if (textures)
-         memset(textures, 0, sizeof(*textures) * NUM_NATIVE_ATTACHMENTS);
-   }
-
-   /* create textures for pbuffer */
-   if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) {
-      struct pipe_screen *screen = dri2dpy->base.screen;
-
-      for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-         struct pipe_texture *ptex = dri2surf->pbuffer_textures[att];
-
-         /* delay the allocation */
-         if (!native_attachment_mask_test(attachment_mask, att))
-            continue;
-
-         if (!ptex) {
-            ptex = screen->texture_create(screen, &templ);
-            dri2surf->pbuffer_textures[att] = ptex;
-         }
-
-         if (textures)
-            pipe_texture_reference(&textures[att], ptex);
-      }
-
-      if (seq_num)
-         *seq_num = dri2surf->sequence_number;
-      if (width)
-         *width = dri2surf->width;
-      if (height)
-         *height = dri2surf->height;
-
-      return TRUE;
-   }
-
-   /* prepare the attachments */
-   num_ins = 0;
-   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-      if (native_attachment_mask_test(attachment_mask, att)) {
-         unsigned int dri2att;
-
-         switch (att) {
-         case NATIVE_ATTACHMENT_FRONT_LEFT:
-            dri2att = DRI2BufferFrontLeft;
-            break;
-         case NATIVE_ATTACHMENT_BACK_LEFT:
-            dri2att = DRI2BufferBackLeft;
-            break;
-         case NATIVE_ATTACHMENT_FRONT_RIGHT:
-            dri2att = DRI2BufferFrontRight;
-            break;
-         case NATIVE_ATTACHMENT_BACK_RIGHT:
-            dri2att = DRI2BufferBackRight;
-            break;
-         default:
-            assert(0);
-            dri2att = 0;
-            break;
-         }
-
-         dri2atts[num_ins] = dri2att;
-         num_ins++;
-      }
-   }
-
-   dri2surf->have_back = FALSE;
-   dri2surf->have_fake = FALSE;
-
-   /* remember old geometry */
-   templ.width0 = dri2surf->width;
-   templ.height0 = dri2surf->height;
-
-   xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable,
-                                    &dri2surf->width, &dri2surf->height,
-                                    dri2atts, FALSE, num_ins, &num_outs);
-   if (!xbufs)
-      return FALSE;
-
-   if (templ.width0 != dri2surf->width || templ.height0 != dri2surf->height) {
-      /* are there cases where the buffers change and the geometry doesn't? */
-      dri2surf->sequence_number++;
-
-      templ.width0 = dri2surf->width;
-      templ.height0 = dri2surf->height;
-   }
-
-   for (i = 0; i < num_outs; i++) {
-      struct x11_drawable_buffer *xbuf = &xbufs[i];
-      const char *desc;
-      enum native_attachment natt;
-
-      switch (xbuf->attachment) {
-      case DRI2BufferFrontLeft:
-         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
-         desc = "DRI2 Front Buffer";
-         break;
-      case DRI2BufferFakeFrontLeft:
-         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
-         desc = "DRI2 Fake Front Buffer";
-         dri2surf->have_fake = TRUE;
-         break;
-      case DRI2BufferBackLeft:
-         natt = NATIVE_ATTACHMENT_BACK_LEFT;
-         desc = "DRI2 Back Buffer";
-         dri2surf->have_back = TRUE;
-         break;
-      default:
-         desc = NULL;
-         break;
-      }
-
-      if (!desc || !native_attachment_mask_test(attachment_mask, natt) ||
-          (textures && textures[natt])) {
-         if (!desc)
-            _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment);
-         else if (!native_attachment_mask_test(attachment_mask, natt))
-            _eglLog(_EGL_WARNING, "unexpected buffer %d", xbuf->attachment);
-         else
-            _eglLog(_EGL_WARNING, "both real and fake front buffers are listed");
-         continue;
-      }
-
-      if (textures) {
-         struct pipe_texture *ptex =
-            dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
-                  dri2dpy->base.screen, &templ,
-                  desc, xbuf->pitch, xbuf->name);
-         if (ptex) {
-            /* the caller owns the textures */
-            textures[natt] = ptex;
-         }
-      }
-   }
-
-   free(xbufs);
-
-   if (seq_num)
-      *seq_num = dri2surf->sequence_number;
-   if (width)
-      *width = dri2surf->width;
-   if (height)
-      *height = dri2surf->height;
-
-   return TRUE;
-}
-
-static void
-dri2_surface_wait(struct native_surface *nsurf)
-{
-   struct dri2_surface *dri2surf = dri2_surface(nsurf);
-   struct dri2_display *dri2dpy = dri2surf->dri2dpy;
-
-   if (dri2surf->have_fake) {
-      x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable,
-            0, 0, dri2surf->width, dri2surf->height,
-            DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
-   }
-}
-
-static void
-dri2_surface_destroy(struct native_surface *nsurf)
-{
-   struct dri2_surface *dri2surf = dri2_surface(nsurf);
-   int i;
-
-   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
-      struct pipe_texture *ptex = dri2surf->pbuffer_textures[i];
-      pipe_texture_reference(&ptex, NULL);
-   }
-
-   if (dri2surf->drawable)
-      x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr,
-            dri2surf->drawable, FALSE);
-   free(dri2surf);
-}
-
-static struct dri2_surface *
-dri2_display_create_surface(struct native_display *ndpy,
-                            enum dri2_surface_type type,
-                            Drawable drawable,
-                            const struct native_config *nconf)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-   struct dri2_config *dri2conf = dri2_config(nconf);
-   struct dri2_surface *dri2surf;
-
-   dri2surf = CALLOC_STRUCT(dri2_surface);
-   if (!dri2surf)
-      return NULL;
-
-   if (drawable)
-      x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE);
-
-   dri2surf->dri2dpy = dri2dpy;
-   dri2surf->type = type;
-   dri2surf->drawable = drawable;
-   dri2surf->color_format = dri2conf->base.color_format;
-
-   dri2surf->base.destroy = dri2_surface_destroy;
-   dri2surf->base.swap_buffers = dri2_surface_swap_buffers;
-   dri2surf->base.flush_frontbuffer = dri2_surface_flush_frontbuffer;
-   dri2surf->base.validate = dri2_surface_validate;
-   dri2surf->base.wait = dri2_surface_wait;
-
-   return dri2surf;
-}
-
-static struct native_surface *
-dri2_display_create_window_surface(struct native_display *ndpy,
-                                   EGLNativeWindowType win,
-                                   const struct native_config *nconf)
-{
-   struct dri2_surface *dri2surf;
-
-   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_WINDOW,
-         (Drawable) win, nconf);
-   return (dri2surf) ? &dri2surf->base : NULL;
-}
-
-static struct native_surface *
-dri2_display_create_pixmap_surface(struct native_display *ndpy,
-                                   EGLNativePixmapType pix,
-                                   const struct native_config *nconf)
-{
-   struct dri2_surface *dri2surf;
-
-   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PIXMAP,
-         (Drawable) pix, nconf);
-   return (dri2surf) ? &dri2surf->base : NULL;
-}
-
-static struct native_surface *
-dri2_display_create_pbuffer_surface(struct native_display *ndpy,
-                                    const struct native_config *nconf,
-                                    uint width, uint height)
-{
-   struct dri2_surface *dri2surf;
-
-   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PBUFFER,
-         (Drawable) None, nconf);
-   if (dri2surf) {
-      dri2surf->width = width;
-      dri2surf->height = height;
-   }
-   return (dri2surf) ? &dri2surf->base : NULL;
-}
-
-static struct pipe_context *
-dri2_display_create_context(struct native_display *ndpy, void *context_private)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-   struct pipe_context *pctx;
-
-   pctx = dri2dpy->api->create_context(dri2dpy->api, dri2dpy->base.screen);
-   if (pctx)
-      pctx->priv = context_private;
-   return pctx;
-}
-
-static int
-choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32])
-{
-   int count = 0;
-
-   switch (mode->rgbBits) {
-   case 32:
-      formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
-      formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
-      break;
-   case 24:
-      formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM;
-      formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM;
-      formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
-      formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
-      break;
-   case 16:
-      formats[count++] = PIPE_FORMAT_R5G6B5_UNORM;
-      break;
-   default:
-      break;
-   }
-
-   return count;
-}
-
-static int
-choose_depth_stencil_format(const __GLcontextModes *mode,
-                            enum pipe_format formats[32])
-{
-   int count = 0;
-
-   switch (mode->depthBits) {
-   case 32:
-      formats[count++] = PIPE_FORMAT_Z32_UNORM;
-      break;
-   case 24:
-      if (mode->stencilBits) {
-         formats[count++] = PIPE_FORMAT_S8Z24_UNORM;
-         formats[count++] = PIPE_FORMAT_Z24S8_UNORM;
-      }
-      else {
-         formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
-         formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
-      }
-      break;
-   case 16:
-      formats[count++] = PIPE_FORMAT_Z16_UNORM;
-      break;
-   default:
-      break;
-   }
-
-   return count;
-}
-
-static boolean
-is_format_supported(struct pipe_screen *screen,
-                    enum pipe_format fmt, boolean is_color)
-{
-   return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D,
-         (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
-         PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-}
-
-static boolean
-dri2_display_convert_config(struct native_display *ndpy,
-                            const __GLcontextModes *mode,
-                            struct native_config *nconf)
-{
-   enum pipe_format formats[32];
-   int num_formats, i;
-
-   if (!(mode->renderType & GLX_RGBA_BIT) || !mode->rgbMode)
-      return FALSE;
-
-   /* skip single-buffered configs */
-   if (!mode->doubleBufferMode)
-      return FALSE;
-
-   nconf->mode = *mode;
-   nconf->mode.renderType = GLX_RGBA_BIT;
-   nconf->mode.rgbMode = TRUE;
-   /* pbuffer is allocated locally and is always supported */
-   nconf->mode.drawableType |= GLX_PBUFFER_BIT;
-   /* the swap method is always copy */
-   nconf->mode.swapMethod = GLX_SWAP_COPY_OML;
-
-   /* fix up */
-   nconf->mode.rgbBits =
-      nconf->mode.redBits + nconf->mode.greenBits +
-      nconf->mode.blueBits + nconf->mode.alphaBits;
-   if (!(nconf->mode.drawableType & GLX_WINDOW_BIT)) {
-      nconf->mode.visualID = 0;
-      nconf->mode.visualType = GLX_NONE;
-   }
-   if (!(nconf->mode.drawableType & GLX_PBUFFER_BIT)) {
-      nconf->mode.bindToTextureRgb = FALSE;
-      nconf->mode.bindToTextureRgba = FALSE;
-   }
-
-   nconf->color_format = PIPE_FORMAT_NONE;
-   nconf->depth_format = PIPE_FORMAT_NONE;
-   nconf->stencil_format = PIPE_FORMAT_NONE;
-
-   /* choose color format */
-   num_formats = choose_color_format(mode, formats);
-   for (i = 0; i < num_formats; i++) {
-      if (is_format_supported(ndpy->screen, formats[i], TRUE)) {
-         nconf->color_format = formats[i];
-         break;
-      }
-   }
-   if (nconf->color_format == PIPE_FORMAT_NONE)
-      return FALSE;
-
-   /* choose depth/stencil format */
-   num_formats = choose_depth_stencil_format(mode, formats);
-   for (i = 0; i < num_formats; i++) {
-      if (is_format_supported(ndpy->screen, formats[i], FALSE)) {
-         nconf->depth_format = formats[i];
-         nconf->stencil_format = formats[i];
-         break;
-      }
-   }
-   if ((nconf->mode.depthBits && nconf->depth_format == PIPE_FORMAT_NONE) ||
-       (nconf->mode.stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE))
-      return FALSE;
-
-   return TRUE;
-}
-
-static const struct native_config **
-dri2_display_get_configs(struct native_display *ndpy, int *num_configs)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-   const struct native_config **configs;
-   int i;
-
-   /* first time */
-   if (!dri2dpy->configs) {
-      const __GLcontextModes *modes;
-      int num_modes, count;
-
-      modes = x11_screen_get_glx_configs(dri2dpy->xscr);
-      if (!modes)
-         return NULL;
-      num_modes = x11_context_modes_count(modes);
-
-      dri2dpy->configs = calloc(num_modes, sizeof(*dri2dpy->configs));
-      if (!dri2dpy->configs)
-         return NULL;
-
-      count = 0;
-      for (i = 0; i < num_modes; i++) {
-         struct native_config *nconf = &dri2dpy->configs[count].base;
-         if (dri2_display_convert_config(&dri2dpy->base, modes, nconf))
-            count++;
-         modes = modes->next;
-      }
-
-      dri2dpy->num_configs = count;
-   }
-
-   configs = malloc(dri2dpy->num_configs * sizeof(*configs));
-   if (configs) {
-      for (i = 0; i < dri2dpy->num_configs; i++)
-         configs[i] = (const struct native_config *) &dri2dpy->configs[i];
-      if (num_configs)
-         *num_configs = dri2dpy->num_configs;
-   }
-
-   return configs;
-}
-
-static boolean
-dri2_display_is_pixmap_supported(struct native_display *ndpy,
-                                 EGLNativePixmapType pix,
-                                 const struct native_config *nconf)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-   uint depth, nconf_depth;
-
-   depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix);
-   nconf_depth = util_format_get_blocksizebits(nconf->color_format);
-
-   /* simple depth match for now */
-   return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth));
-}
-
-static void
-dri2_display_destroy(struct native_display *ndpy)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-
-   if (dri2dpy->configs)
-      free(dri2dpy->configs);
-
-   if (dri2dpy->base.screen)
-      dri2dpy->base.screen->destroy(dri2dpy->base.screen);
-
-   if (dri2dpy->xscr)
-      x11_screen_destroy(dri2dpy->xscr);
-   if (dri2dpy->own_dpy)
-      XCloseDisplay(dri2dpy->dpy);
-   if (dri2dpy->api && dri2dpy->api->destroy)
-      dri2dpy->api->destroy(dri2dpy->api);
-   free(dri2dpy);
-}
-
-/**
- * Initialize DRI2 and pipe screen.
- */
-static boolean
-dri2_display_init_screen(struct native_display *ndpy)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-   const char *driver = dri2dpy->api->name;
-   struct drm_create_screen_arg arg;
-   int fd;
-
-   if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) ||
-       !x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_GLX)) {
-      _eglLog(_EGL_WARNING, "GLX/DRI2 is not supported");
-      return FALSE;
-   }
-
-   fd = x11_screen_enable_dri2(dri2dpy->xscr, driver);
-   if (fd < 0)
-      return FALSE;
-
-   memset(&arg, 0, sizeof(arg));
-   arg.mode = DRM_CREATE_NORMAL;
-   dri2dpy->base.screen = dri2dpy->api->create_screen(dri2dpy->api, fd, &arg);
-   if (!dri2dpy->base.screen) {
-      _eglLog(_EGL_WARNING, "failed to create DRM screen");
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
-{
-   struct dri2_display *dri2dpy;
-
-   dri2dpy = CALLOC_STRUCT(dri2_display);
-   if (!dri2dpy)
-      return NULL;
-
-   dri2dpy->api = api;
-   if (!dri2dpy->api) {
-      _eglLog(_EGL_WARNING, "failed to create DRM API");
-      free(dri2dpy);
-      return NULL;
-   }
-
-   dri2dpy->dpy = dpy;
-   if (!dri2dpy->dpy) {
-      dri2dpy->dpy = XOpenDisplay(NULL);
-      if (!dri2dpy->dpy) {
-         dri2_display_destroy(&dri2dpy->base);
-         return NULL;
-      }
-      dri2dpy->own_dpy = TRUE;
-   }
-
-   dri2dpy->xscr_number = DefaultScreen(dri2dpy->dpy);
-   dri2dpy->xscr = x11_screen_create(dri2dpy->dpy, dri2dpy->xscr_number);
-   if (!dri2dpy->xscr) {
-      dri2_display_destroy(&dri2dpy->base);
-      return NULL;
-   }
-
-   if (!dri2_display_init_screen(&dri2dpy->base)) {
-      dri2_display_destroy(&dri2dpy->base);
-      return NULL;
-   }
-
-   dri2dpy->base.destroy = dri2_display_destroy;
-   dri2dpy->base.get_configs = dri2_display_get_configs;
-   dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
-   dri2dpy->base.create_context = dri2_display_create_context;
-   dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
-   dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
-   dri2dpy->base.create_pbuffer_surface = dri2_display_create_pbuffer_surface;
-
-   return &dri2dpy->base;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/native_x11.c b/src/gallium/state_trackers/egl_g3d/x11/native_x11.c
deleted file mode 100644 (file)
index 695ab88..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <string.h>
-#include "util/u_debug.h"
-#include "util/u_memory.h"
-#include "state_tracker/drm_api.h"
-#include "egllog.h"
-
-#include "native_x11.h"
-#include "x11_screen.h"
-
-#define X11_PROBE_MAGIC 0x11980BE /* "X11PROBE" */
-
-static struct drm_api *api;
-
-static void
-x11_probe_destroy(struct native_probe *nprobe)
-{
-   if (nprobe->data)
-      free(nprobe->data);
-   free(nprobe);
-}
-
-struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
-{
-   struct native_probe *nprobe;
-   struct x11_screen *xscr;
-   int scr;
-   const char *driver_name = NULL;
-   Display *xdpy;
-
-   nprobe = CALLOC_STRUCT(native_probe);
-   if (!nprobe)
-      return NULL;
-
-   xdpy = dpy;
-   if (!xdpy) {
-      xdpy = XOpenDisplay(NULL);
-      if (!xdpy) {
-         free(nprobe);
-         return NULL;
-      }
-   }
-
-   scr = DefaultScreen(xdpy);
-   xscr = x11_screen_create(xdpy, scr);
-   if (xscr) {
-      if (x11_screen_support(xscr, X11_SCREEN_EXTENSION_DRI2)) {
-         driver_name = x11_screen_probe_dri2(xscr);
-         nprobe->data = strdup(driver_name);
-      }
-
-      x11_screen_destroy(xscr);
-   }
-
-   if (xdpy != dpy)
-      XCloseDisplay(xdpy);
-
-   nprobe->magic = X11_PROBE_MAGIC;
-   nprobe->display = dpy;
-
-   nprobe->destroy = x11_probe_destroy;
-
-   return nprobe;
-}
-
-enum native_probe_result
-native_get_probe_result(struct native_probe *nprobe)
-{
-   if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
-      return NATIVE_PROBE_UNKNOWN;
-
-   if (!api)
-      api = drm_api_create();
-
-   /* this is a software driver */
-   if (!api)
-      return NATIVE_PROBE_SUPPORTED;
-
-   /* the display does not support DRI2 or the driver mismatches */
-   if (!nprobe->data || strcmp(api->name, (const char *) nprobe->data) != 0)
-      return NATIVE_PROBE_FALLBACK;
-
-   return NATIVE_PROBE_EXACT;
-}
-
-const char *
-native_get_name(void)
-{
-   static char x11_name[32];
-
-   if (!api)
-      api = drm_api_create();
-
-   if (api)
-      snprintf(x11_name, sizeof(x11_name), "X11/%s", api->name);
-   else
-      snprintf(x11_name, sizeof(x11_name), "X11");
-
-   return x11_name;
-}
-
-struct native_display *
-native_create_display(EGLNativeDisplayType dpy)
-{
-   struct native_display *ndpy = NULL;
-   boolean force_sw;
-
-   if (!api)
-      api = drm_api_create();
-
-   force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
-   if (api && !force_sw) {
-      ndpy = x11_create_dri2_display(dpy, api);
-   }
-
-   if (!ndpy) {
-      EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING;
-
-      _eglLog(level, "use software fallback");
-      ndpy = x11_create_ximage_display(dpy, TRUE);
-   }
-
-   return ndpy;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/native_x11.h b/src/gallium/state_trackers/egl_g3d/x11/native_x11.h
deleted file mode 100644 (file)
index 622ddac..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _NATIVE_X11_H_
-#define _NATIVE_X11_H_
-
-#include "state_tracker/drm_api.h"
-#include "common/native.h"
-
-struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm);
-
-struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api);
-
-#endif /* _NATIVE_X11_H_ */
diff --git a/src/gallium/state_trackers/egl_g3d/x11/native_ximage.c b/src/gallium/state_trackers/egl_g3d/x11/native_ximage.c
deleted file mode 100644 (file)
index dfa8df2..0000000
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <assert.h>
-#include <sys/ipc.h>
-#include <sys/types.h>
-#include <sys/shm.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/XShm.h>
-#include "util/u_memory.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "pipe/p_compiler.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "softpipe/sp_winsys.h"
-#include "egllog.h"
-
-#include "sw_winsys.h"
-#include "native_x11.h"
-#include "x11_screen.h"
-
-enum ximage_surface_type {
-   XIMAGE_SURFACE_TYPE_WINDOW,
-   XIMAGE_SURFACE_TYPE_PIXMAP,
-   XIMAGE_SURFACE_TYPE_PBUFFER
-};
-
-struct ximage_display {
-   struct native_display base;
-   Display *dpy;
-   boolean own_dpy;
-
-   struct x11_screen *xscr;
-   int xscr_number;
-
-   boolean use_xshm;
-
-   struct pipe_winsys *winsys;
-   struct ximage_config *configs;
-   int num_configs;
-};
-
-struct ximage_buffer {
-   XImage *ximage;
-
-   struct pipe_texture *texture;
-   XShmSegmentInfo *shm_info;
-   boolean xshm_attached;
-};
-
-struct ximage_surface {
-   struct native_surface base;
-   Drawable drawable;
-   enum ximage_surface_type type;
-   enum pipe_format color_format;
-   XVisualInfo visual;
-   struct ximage_display *xdpy;
-
-   int width, height;
-   GC gc;
-
-   struct ximage_buffer buffers[NUM_NATIVE_ATTACHMENTS];
-   unsigned int sequence_number;
-};
-
-struct ximage_config {
-   struct native_config base;
-   const XVisualInfo *visual;
-};
-
-static INLINE struct ximage_display *
-ximage_display(const struct native_display *ndpy)
-{
-   return (struct ximage_display *) ndpy;
-}
-
-static INLINE struct ximage_surface *
-ximage_surface(const struct native_surface *nsurf)
-{
-   return (struct ximage_surface *) nsurf;
-}
-
-static INLINE struct ximage_config *
-ximage_config(const struct native_config *nconf)
-{
-   return (struct ximage_config *) nconf;
-}
-
-static void
-ximage_surface_free_buffer(struct native_surface *nsurf,
-                           enum native_attachment which)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   struct ximage_buffer *xbuf = &xsurf->buffers[which];
-
-   pipe_texture_reference(&xbuf->texture, NULL);
-
-   if (xbuf->shm_info) {
-      if (xbuf->xshm_attached)
-         XShmDetach(xsurf->xdpy->dpy, xbuf->shm_info);
-      if (xbuf->shm_info->shmaddr != (void *) -1)
-         shmdt(xbuf->shm_info->shmaddr);
-      if (xbuf->shm_info->shmid != -1)
-         shmctl(xbuf->shm_info->shmid, IPC_RMID, 0);
-
-      xbuf->shm_info->shmaddr = (void *) -1;
-      xbuf->shm_info->shmid = -1;
-   }
-}
-
-static boolean
-ximage_surface_alloc_buffer(struct native_surface *nsurf,
-                            enum native_attachment which)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   struct ximage_buffer *xbuf = &xsurf->buffers[which];
-   struct pipe_screen *screen = xsurf->xdpy->base.screen;
-   struct pipe_texture templ;
-
-   /* free old data */
-   if (xbuf->texture)
-      ximage_surface_free_buffer(&xsurf->base, which);
-
-   memset(&templ, 0, sizeof(templ));
-   templ.target = PIPE_TEXTURE_2D;
-   templ.format = xsurf->color_format;
-   templ.width0 = xsurf->width;
-   templ.height0 = xsurf->height;
-   templ.depth0 = 1;
-   templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-
-   if (xbuf->shm_info) {
-      struct pipe_buffer *pbuf;
-      unsigned stride, size;
-      void *addr = NULL;
-
-      stride = util_format_get_stride(xsurf->color_format, xsurf->width);
-      /* alignment should depend on visual? */
-      stride = align(stride, 4);
-      size = stride * xsurf->height;
-
-      /* create and attach shm object */
-      xbuf->shm_info->shmid = shmget(IPC_PRIVATE, size, 0755);
-      if (xbuf->shm_info->shmid != -1) {
-         xbuf->shm_info->shmaddr =
-            shmat(xbuf->shm_info->shmid, NULL, 0);
-         if (xbuf->shm_info->shmaddr != (void *) -1) {
-            if (XShmAttach(xsurf->xdpy->dpy, xbuf->shm_info)) {
-               addr = xbuf->shm_info->shmaddr;
-               xbuf->xshm_attached = TRUE;
-            }
-         }
-      }
-
-      if (addr) {
-         pbuf = screen->user_buffer_create(screen, addr, size);
-         if (pbuf) {
-            xbuf->texture =
-               screen->texture_blanket(screen, &templ, &stride, pbuf);
-            pipe_buffer_reference(&pbuf, NULL);
-         }
-      }
-   }
-   else {
-      xbuf->texture = screen->texture_create(screen, &templ);
-   }
-
-   /* clean up the buffer if allocation failed */
-   if (!xbuf->texture)
-      ximage_surface_free_buffer(&xsurf->base, which);
-
-   return (xbuf->texture != NULL);
-}
-
-static boolean
-ximage_surface_draw_buffer(struct native_surface *nsurf,
-                           enum native_attachment which)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   struct ximage_buffer *xbuf = &xsurf->buffers[which];
-   struct pipe_screen *screen = xsurf->xdpy->base.screen;
-   struct pipe_transfer *transfer;
-
-   if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER)
-      return TRUE;
-
-   assert(xsurf->drawable && xbuf->ximage && xbuf->texture);
-
-   transfer = screen->get_tex_transfer(screen, xbuf->texture,
-         0, 0, 0, PIPE_TRANSFER_READ, 0, 0, xsurf->width, xsurf->height);
-   if (!transfer)
-      return FALSE;
-
-   xbuf->ximage->bytes_per_line = transfer->stride;
-   xbuf->ximage->data = screen->transfer_map(screen, transfer);
-   if (!xbuf->ximage->data) {
-      screen->tex_transfer_destroy(transfer);
-      return FALSE;
-   }
-
-
-   if (xbuf->shm_info)
-      XShmPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
-            xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height, False);
-   else
-      XPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
-            xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height);
-
-   xbuf->ximage->data = NULL;
-   screen->transfer_unmap(screen, transfer);
-
-   /*
-    * softpipe allows the pipe transfer to be re-used, but we don't want to
-    * rely on that behavior.
-    */
-   screen->tex_transfer_destroy(transfer);
-
-   XSync(xsurf->xdpy->dpy, FALSE);
-
-   return TRUE;
-}
-
-static boolean
-ximage_surface_flush_frontbuffer(struct native_surface *nsurf)
-{
-   return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
-}
-
-static boolean
-ximage_surface_swap_buffers(struct native_surface *nsurf)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   struct ximage_buffer *xfront, *xback, xtmp;
-
-   xfront = &xsurf->buffers[NATIVE_ATTACHMENT_FRONT_LEFT];
-   xback = &xsurf->buffers[NATIVE_ATTACHMENT_BACK_LEFT];
-
-   /* draw the back buffer directly if there is no front buffer */
-   if (!xfront->texture)
-      return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_BACK_LEFT);
-
-   /* swap the buffers */
-   xtmp = *xfront;
-   *xfront = *xback;
-   *xback = xtmp;
-
-   /* the front/back textures are swapped */
-   xsurf->sequence_number++;
-
-   return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
-}
-
-static void
-ximage_surface_update_geometry(struct native_surface *nsurf)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   Status ok;
-   Window root;
-   int x, y;
-   unsigned int w, h, border, depth;
-
-   /* pbuffer has fixed geometry */
-   if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER)
-      return;
-
-   ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable,
-         &root, &x, &y, &w, &h, &border, &depth);
-   if (ok) {
-      xsurf->width = w;
-      xsurf->height = h;
-   }
-}
-
-static boolean
-ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask,
-                        unsigned int *seq_num, struct pipe_texture **textures,
-                        int *width, int *height)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   boolean new_buffers = FALSE;
-   int att;
-
-   ximage_surface_update_geometry(&xsurf->base);
-
-   for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-      struct ximage_buffer *xbuf = &xsurf->buffers[att];
-
-      /* delay the allocation */
-      if (!native_attachment_mask_test(attachment_mask, att))
-         continue;
-
-      /* reallocate the texture */
-      if (!xbuf->texture ||
-          xsurf->width != xbuf->texture->width0 ||
-          xsurf->height != xbuf->texture->height0) {
-         new_buffers = TRUE;
-         if (ximage_surface_alloc_buffer(&xsurf->base, att)) {
-            /* update ximage */
-            if (xbuf->ximage) {
-               xbuf->ximage->width = xsurf->width;
-               xbuf->ximage->height = xsurf->height;
-            }
-         }
-      }
-
-      if (textures) {
-         textures[att] = NULL;
-         pipe_texture_reference(&textures[att], xbuf->texture);
-      }
-   }
-
-   /* increase the sequence number so that caller knows */
-   if (new_buffers)
-      xsurf->sequence_number++;
-
-   if (seq_num)
-      *seq_num = xsurf->sequence_number;
-   if (width)
-      *width = xsurf->width;
-   if (height)
-      *height = xsurf->height;
-
-   return TRUE;
-}
-
-static void
-ximage_surface_wait(struct native_surface *nsurf)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   XSync(xsurf->xdpy->dpy, FALSE);
-   /* TODO XGetImage and update the front texture */
-}
-
-static void
-ximage_surface_destroy(struct native_surface *nsurf)
-{
-   struct ximage_surface *xsurf = ximage_surface(nsurf);
-   int i;
-
-   for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
-      struct ximage_buffer *xbuf = &xsurf->buffers[i];
-      ximage_surface_free_buffer(&xsurf->base, i);
-      /* xbuf->shm_info is owned by xbuf->ximage? */
-      if (xbuf->ximage) {
-         XDestroyImage(xbuf->ximage);
-         xbuf->ximage = NULL;
-      }
-   }
-
-   if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER)
-      XFreeGC(xsurf->xdpy->dpy, xsurf->gc);
-   free(xsurf);
-}
-
-static struct ximage_surface *
-ximage_display_create_surface(struct native_display *ndpy,
-                              enum ximage_surface_type type,
-                              Drawable drawable,
-                              const struct native_config *nconf)
-{
-   struct ximage_display *xdpy = ximage_display(ndpy);
-   struct ximage_config *xconf = ximage_config(nconf);
-   struct ximage_surface *xsurf;
-   int i;
-
-   xsurf = CALLOC_STRUCT(ximage_surface);
-   if (!xsurf)
-      return NULL;
-
-   xsurf->xdpy = xdpy;
-   xsurf->type = type;
-   xsurf->color_format = xconf->base.color_format;
-   xsurf->drawable = drawable;
-
-   if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) {
-      xsurf->drawable = drawable;
-      xsurf->visual = *xconf->visual;
-
-      xsurf->gc = XCreateGC(xdpy->dpy, xsurf->drawable, 0, NULL);
-      if (!xsurf->gc) {
-         free(xsurf);
-         return NULL;
-      }
-
-      for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
-         struct ximage_buffer *xbuf = &xsurf->buffers[i];
-
-         if (xdpy->use_xshm) {
-            xbuf->shm_info = calloc(1, sizeof(*xbuf->shm_info));
-            if (xbuf->shm_info) {
-               /* initialize shm info */
-               xbuf->shm_info->shmid = -1;
-               xbuf->shm_info->shmaddr = (void *) -1;
-               xbuf->shm_info->readOnly = TRUE;
-
-               xbuf->ximage = XShmCreateImage(xsurf->xdpy->dpy,
-                     xsurf->visual.visual,
-                     xsurf->visual.depth,
-                     ZPixmap, NULL,
-                     xbuf->shm_info,
-                     0, 0);
-            }
-         }
-         else {
-            xbuf->ximage = XCreateImage(xsurf->xdpy->dpy,
-                  xsurf->visual.visual,
-                  xsurf->visual.depth,
-                  ZPixmap, 0,   /* format, offset */
-                  NULL,         /* data */
-                  0, 0,         /* size */
-                  8,            /* bitmap_pad */
-                  0);           /* bytes_per_line */
-         }
-
-         if (!xbuf->ximage) {
-            XFreeGC(xdpy->dpy, xsurf->gc);
-            free(xsurf);
-            return NULL;
-         }
-      }
-   }
-
-   xsurf->base.destroy = ximage_surface_destroy;
-   xsurf->base.swap_buffers = ximage_surface_swap_buffers;
-   xsurf->base.flush_frontbuffer = ximage_surface_flush_frontbuffer;
-   xsurf->base.validate = ximage_surface_validate;
-   xsurf->base.wait = ximage_surface_wait;
-
-   return xsurf;
-}
-
-static struct native_surface *
-ximage_display_create_window_surface(struct native_display *ndpy,
-                                     EGLNativeWindowType win,
-                                     const struct native_config *nconf)
-{
-   struct ximage_surface *xsurf;
-
-   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_WINDOW,
-         (Drawable) win, nconf);
-   return (xsurf) ? &xsurf->base : NULL;
-}
-
-static struct native_surface *
-ximage_display_create_pixmap_surface(struct native_display *ndpy,
-                                     EGLNativePixmapType pix,
-                                     const struct native_config *nconf)
-{
-   struct ximage_surface *xsurf;
-
-   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PIXMAP,
-         (Drawable) pix, nconf);
-   return (xsurf) ? &xsurf->base : NULL;
-}
-
-static struct native_surface *
-ximage_display_create_pbuffer_surface(struct native_display *ndpy,
-                                      const struct native_config *nconf,
-                                      uint width, uint height)
-{
-   struct ximage_surface *xsurf;
-
-   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PBUFFER,
-         (Drawable) None, nconf);
-   if (xsurf) {
-      xsurf->width = width;
-      xsurf->height = height;
-   }
-   return (xsurf) ? &xsurf->base : NULL;
-}
-
-static struct pipe_context *
-ximage_display_create_context(struct native_display *ndpy,
-                              void *context_private)
-{
-   struct pipe_context *pctx = softpipe_create(ndpy->screen);
-   if (pctx)
-      pctx->priv = context_private;
-   return pctx;
-}
-
-static enum pipe_format
-choose_format(const XVisualInfo *vinfo)
-{
-   enum pipe_format fmt;
-   /* TODO elaborate the formats */
-   switch (vinfo->depth) {
-   case 32:
-      fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
-      break;
-   case 24:
-      fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
-      break;
-   case 16:
-      fmt = PIPE_FORMAT_R5G6B5_UNORM;
-      break;
-   default:
-      fmt = PIPE_FORMAT_NONE;
-      break;
-   }
-
-   return fmt;
-}
-
-static const struct native_config **
-ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
-{
-   struct ximage_display *xdpy = ximage_display(ndpy);
-   const struct native_config **configs;
-   int i;
-
-   /* first time */
-   if (!xdpy->configs) {
-      const XVisualInfo *visuals;
-      int num_visuals, count, j;
-
-      visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals);
-      if (!visuals)
-         return NULL;
-
-      /*
-       * Create two configs for each visual.
-       * One with depth/stencil buffer; one without
-       */
-      xdpy->configs = calloc(num_visuals * 2, sizeof(*xdpy->configs));
-      if (!xdpy->configs)
-         return NULL;
-
-      count = 0;
-      for (i = 0; i < num_visuals; i++) {
-         for (j = 0; j < 2; j++) {
-            struct ximage_config *xconf = &xdpy->configs[count];
-            __GLcontextModes *mode = &xconf->base.mode;
-
-            xconf->visual = &visuals[i];
-            xconf->base.color_format = choose_format(xconf->visual);
-            if (xconf->base.color_format == PIPE_FORMAT_NONE)
-               continue;
-
-            x11_screen_convert_visual(xdpy->xscr, xconf->visual, mode);
-            /* support double buffer mode */
-            mode->doubleBufferMode = TRUE;
-
-            xconf->base.depth_format = PIPE_FORMAT_NONE;
-            xconf->base.stencil_format = PIPE_FORMAT_NONE;
-            /* create the second config with depth/stencil buffer */
-            if (j == 1) {
-               xconf->base.depth_format = PIPE_FORMAT_S8Z24_UNORM;
-               xconf->base.stencil_format = PIPE_FORMAT_S8Z24_UNORM;
-               mode->depthBits = 24;
-               mode->stencilBits = 8;
-               mode->haveDepthBuffer = TRUE;
-               mode->haveStencilBuffer = TRUE;
-            }
-
-            mode->maxPbufferWidth = 4096;
-            mode->maxPbufferHeight = 4096;
-            mode->maxPbufferPixels = 4096 * 4096;
-            mode->drawableType =
-               GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
-            mode->swapMethod = GLX_SWAP_EXCHANGE_OML;
-
-            if (mode->alphaBits)
-               mode->bindToTextureRgba = TRUE;
-            else
-               mode->bindToTextureRgb = TRUE;
-
-            count++;
-         }
-      }
-
-      xdpy->num_configs = count;
-   }
-
-   configs = malloc(xdpy->num_configs * sizeof(*configs));
-   if (configs) {
-      for (i = 0; i < xdpy->num_configs; i++)
-         configs[i] = (const struct native_config *) &xdpy->configs[i];
-      if (num_configs)
-         *num_configs = xdpy->num_configs;
-   }
-   return configs;
-}
-
-static boolean
-ximage_display_is_pixmap_supported(struct native_display *ndpy,
-                                   EGLNativePixmapType pix,
-                                   const struct native_config *nconf)
-{
-   struct ximage_display *xdpy = ximage_display(ndpy);
-   enum pipe_format fmt;
-   uint depth;
-
-   depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix);
-   switch (depth) {
-   case 32:
-      fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
-      break;
-   case 24:
-      fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
-      break;
-   case 16:
-      fmt = PIPE_FORMAT_R5G6B5_UNORM;
-      break;
-   default:
-      fmt = PIPE_FORMAT_NONE;
-      break;
-   }
-
-   return (fmt == nconf->color_format);
-}
-
-static void
-ximage_display_destroy(struct native_display *ndpy)
-{
-   struct ximage_display *xdpy = ximage_display(ndpy);
-
-   if (xdpy->configs)
-      free(xdpy->configs);
-
-   xdpy->base.screen->destroy(xdpy->base.screen);
-   free(xdpy->winsys);
-
-   x11_screen_destroy(xdpy->xscr);
-   if (xdpy->own_dpy)
-      XCloseDisplay(xdpy->dpy);
-   free(xdpy);
-}
-
-struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm)
-{
-   struct ximage_display *xdpy;
-
-   xdpy = CALLOC_STRUCT(ximage_display);
-   if (!xdpy)
-      return NULL;
-
-   xdpy->dpy = dpy;
-   if (!xdpy->dpy) {
-      xdpy->dpy = XOpenDisplay(NULL);
-      if (!xdpy->dpy) {
-         free(xdpy);
-         return NULL;
-      }
-      xdpy->own_dpy = TRUE;
-   }
-
-   xdpy->xscr_number = DefaultScreen(xdpy->dpy);
-   xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
-   if (!xdpy->xscr) {
-      free(xdpy);
-      return NULL;
-   }
-
-   xdpy->use_xshm =
-      (use_xshm && x11_screen_support(xdpy->xscr, X11_SCREEN_EXTENSION_XSHM));
-
-   xdpy->winsys = create_sw_winsys();
-   xdpy->base.screen = softpipe_create_screen(xdpy->winsys);
-
-   xdpy->base.destroy = ximage_display_destroy;
-
-   xdpy->base.get_configs = ximage_display_get_configs;
-   xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported;
-   xdpy->base.create_context = ximage_display_create_context;
-   xdpy->base.create_window_surface = ximage_display_create_window_surface;
-   xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface;
-   xdpy->base.create_pbuffer_surface = ximage_display_create_pbuffer_surface;
-
-   return &xdpy->base;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/sw_winsys.c b/src/gallium/state_trackers/egl_g3d/x11/sw_winsys.c
deleted file mode 100644 (file)
index 6ee3ede..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-/**
- * Totally software-based winsys layer.
- * Note that the one winsys function that we can't implement here
- * is flush_frontbuffer().
- * Whoever uses this code will have to provide that.
- *
- * Authors: Brian Paul
- */
-
-
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "sw_winsys.h"
-
-
-
-/** Subclass of pipe_winsys */
-struct sw_pipe_winsys
-{
-   struct pipe_winsys Base;
-   /* no extra fields for now */
-};
-
-
-/** subclass of pipe_buffer */
-struct sw_pipe_buffer
-{
-   struct pipe_buffer Base;
-   boolean UserBuffer;  /** Is this a user-space buffer? */
-   void *Data;
-   void *Mapped;
-};
-
-
-/** cast wrapper */
-static INLINE struct sw_pipe_buffer *
-sw_pipe_buffer(struct pipe_buffer *b)
-{
-   return (struct sw_pipe_buffer *) b;
-}
-
-
-static const char *
-get_name(struct pipe_winsys *pws)
-{
-   return "software";
-}
-
-
-/** Create new pipe_buffer and allocate storage of given size */
-static struct pipe_buffer *
-buffer_create(struct pipe_winsys *pws, 
-              unsigned alignment, 
-              unsigned usage,
-              unsigned size)
-{
-   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
-   if (!buffer)
-      return NULL;
-
-   pipe_reference_init(&buffer->Base.reference, 1);
-   buffer->Base.alignment = alignment;
-   buffer->Base.usage = usage;
-   buffer->Base.size = size;
-
-   /* align to 16-byte multiple for Cell */
-   buffer->Data = align_malloc(size, MAX2(alignment, 16));
-
-   return &buffer->Base;
-}
-
-
-/**
- * Create buffer which wraps user-space data.
- */
-static struct pipe_buffer *
-user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
-{
-   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
-   if (!buffer)
-      return NULL;
-
-   pipe_reference_init(&buffer->Base.reference, 1);
-   buffer->Base.size = bytes;
-   buffer->UserBuffer = TRUE;
-   buffer->Data = ptr;
-
-   return &buffer->Base;
-}
-
-
-static void *
-buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-   buffer->Mapped = buffer->Data;
-   return buffer->Mapped;
-}
-
-
-static void
-buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-   buffer->Mapped = NULL;
-}
-
-
-static void
-buffer_destroy(struct pipe_buffer *buf)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-
-   if (buffer->Data && !buffer->UserBuffer) {
-      align_free(buffer->Data);
-      buffer->Data = NULL;
-   }
-
-   free(buffer);
-}
-
-
-static struct pipe_buffer *
-surface_buffer_create(struct pipe_winsys *winsys,
-                      unsigned width, unsigned height,
-                      enum pipe_format format, 
-                      unsigned usage,
-                      unsigned tex_usage,
-                      unsigned *stride)
-{
-   const unsigned alignment = 64;
-   unsigned nblocksy;
-
-   nblocksy = util_format_get_nblocksy(format, height);
-   *stride = align(util_format_get_stride(format, width), alignment);
-
-   return winsys->buffer_create(winsys, alignment,
-                                usage,
-                                *stride * nblocksy);
-}
-
-
-static void
-fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
-                struct pipe_fence_handle *fence)
-{
-   /* no-op */
-}
-
-
-static int
-fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-                unsigned flag)
-{
-   /* no-op */
-   return 0;
-}
-
-
-static int
-fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-             unsigned flag)
-{
-   /* no-op */
-   return 0;
-}
-
-
-/**
- * Create/return a new pipe_winsys object.
- */
-struct pipe_winsys *
-create_sw_winsys(void)
-{
-   struct sw_pipe_winsys *ws = CALLOC_STRUCT(sw_pipe_winsys);
-   if (!ws)
-      return NULL;
-
-   /* Fill in this struct with callbacks that pipe will need to
-    * communicate with the window system, buffer manager, etc. 
-    */
-   ws->Base.buffer_create = buffer_create;
-   ws->Base.user_buffer_create = user_buffer_create;
-   ws->Base.buffer_map = buffer_map;
-   ws->Base.buffer_unmap = buffer_unmap;
-   ws->Base.buffer_destroy = buffer_destroy;
-
-   ws->Base.surface_buffer_create = surface_buffer_create;
-
-   ws->Base.fence_reference = fence_reference;
-   ws->Base.fence_signalled = fence_signalled;
-   ws->Base.fence_finish = fence_finish;
-
-   ws->Base.flush_frontbuffer = NULL; /* not implemented here! */
-
-   ws->Base.get_name = get_name;
-
-   return &ws->Base;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/sw_winsys.h b/src/gallium/state_trackers/egl_g3d/x11/sw_winsys.h
deleted file mode 100644 (file)
index f96c5a1..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-
-#ifndef SW_WINSYS_H
-#define SW_WINSYS_H
-
-
-struct pipe_winsys;
-
-
-extern struct pipe_winsys *
-create_sw_winsys(void);
-
-
-#endif /* SW_WINSYS_H */
diff --git a/src/gallium/state_trackers/egl_g3d/x11/x11_screen.c b/src/gallium/state_trackers/egl_g3d/x11/x11_screen.c
deleted file mode 100644 (file)
index fef7878..0000000
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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 <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/XShm.h>
-#include "util/u_memory.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "xf86drm.h"
-#include "egllog.h"
-
-#include "x11_screen.h"
-#include "dri2.h"
-#include "glxinit.h"
-
-struct x11_screen {
-   Display *dpy;
-   int number;
-
-   __GLXdisplayPrivate *glx_dpy;
-
-   int dri_major, dri_minor;
-   char *dri_driver;
-   char *dri_device;
-   int dri_fd;
-
-   XVisualInfo *visuals;
-   int num_visuals;
-
-   /* cached values for x11_drawable_get_depth */
-   Drawable last_drawable;
-   unsigned int last_depth;
-};
-
-
-/**
- * Create a X11 screen.
- */
-struct x11_screen *
-x11_screen_create(Display *dpy, int screen)
-{
-   struct x11_screen *xscr;
-
-   if (screen >= ScreenCount(dpy))
-      return NULL;
-
-   xscr = CALLOC_STRUCT(x11_screen);
-   if (xscr) {
-      xscr->dpy = dpy;
-      xscr->number = screen;
-
-      xscr->dri_major = -1;
-      xscr->dri_fd = -1;
-   }
-   return xscr;
-}
-
-/**
- * Destroy a X11 screen.
- */
-void
-x11_screen_destroy(struct x11_screen *xscr)
-{
-   if (xscr->dri_fd >= 0)
-      close(xscr->dri_fd);
-   if (xscr->dri_driver)
-      Xfree(xscr->dri_driver);
-   if (xscr->dri_device)
-      Xfree(xscr->dri_device);
-
-   if (xscr->glx_dpy)
-      __glXRelease(xscr->glx_dpy);
-   if (xscr->visuals)
-      XFree(xscr->visuals);
-   free(xscr);
-}
-
-static boolean
-x11_screen_init_dri2(struct x11_screen *xscr)
-{
-   if (xscr->dri_major < 0) {
-      int eventBase, errorBase;
-
-      if (!DRI2QueryExtension(xscr->dpy, &eventBase, &errorBase) ||
-          !DRI2QueryVersion(xscr->dpy, &xscr->dri_major, &xscr->dri_minor))
-         xscr->dri_major = -1;
-   }
-   return (xscr->dri_major >= 0);
-}
-
-static boolean
-x11_screen_init_glx(struct x11_screen *xscr)
-{
-   if (!xscr->glx_dpy)
-      xscr->glx_dpy = __glXInitialize(xscr->dpy);
-   return (xscr->glx_dpy != NULL);
-}
-
-/**
- * Return true if the screen supports the extension.
- */
-boolean
-x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext)
-{
-   boolean supported = FALSE;
-
-   switch (ext) {
-   case X11_SCREEN_EXTENSION_XSHM:
-      supported = XShmQueryExtension(xscr->dpy);
-      break;
-   case X11_SCREEN_EXTENSION_GLX:
-      supported = x11_screen_init_glx(xscr);
-      break;
-   case X11_SCREEN_EXTENSION_DRI2:
-      supported = x11_screen_init_dri2(xscr);
-      break;
-   default:
-      break;
-   }
-
-   return supported;
-}
-
-/**
- * Return the X visuals.
- */
-const XVisualInfo *
-x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals)
-{
-   if (!xscr->visuals) {
-      XVisualInfo vinfo_template;
-      vinfo_template.screen = xscr->number;
-      xscr->visuals = XGetVisualInfo(xscr->dpy, VisualScreenMask,
-            &vinfo_template, &xscr->num_visuals);
-   }
-
-   if (num_visuals)
-      *num_visuals = xscr->num_visuals;
-   return xscr->visuals;
-}
-
-void
-x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual,
-                          __GLcontextModes *mode)
-{
-   int r, g, b, a;
-   int visual_type;
-
-   r = util_bitcount(visual->red_mask);
-   g = util_bitcount(visual->green_mask);
-   b = util_bitcount(visual->blue_mask);
-   a = visual->depth - (r + g + b);
-#if defined(__cplusplus) || defined(c_plusplus)
-   visual_type = visual->c_class;
-#else
-   visual_type = visual->class;
-#endif
-
-   /* convert to GLX visual type */
-   switch (visual_type) {
-   case TrueColor:
-      visual_type = GLX_TRUE_COLOR;
-      break;
-   case DirectColor:
-      visual_type = GLX_DIRECT_COLOR;
-      break;
-   case PseudoColor:
-      visual_type = GLX_PSEUDO_COLOR;
-      break;
-   case StaticColor:
-      visual_type = GLX_STATIC_COLOR;
-      break;
-   case GrayScale:
-      visual_type = GLX_GRAY_SCALE;
-      break;
-   case StaticGray:
-      visual_type = GLX_STATIC_GRAY;
-      break;
-   default:
-      visual_type = GLX_NONE;
-      break;
-   }
-
-   mode->rgbBits = r + g + b + a;
-   mode->redBits = r;
-   mode->greenBits = g;
-   mode->blueBits = b;
-   mode->alphaBits = a;
-   mode->visualID = visual->visualid;
-   mode->visualType = visual_type;
-
-   /* sane defaults */
-   mode->renderType = GLX_RGBA_BIT;
-   mode->rgbMode = TRUE;
-   mode->visualRating = GLX_SLOW_CONFIG;
-   mode->xRenderable = TRUE;
-}
-
-/**
- * Return the GLX fbconfigs.
- */
-const __GLcontextModes *
-x11_screen_get_glx_configs(struct x11_screen *xscr)
-{
-   return (x11_screen_init_glx(xscr))
-      ? xscr->glx_dpy->screenConfigs[xscr->number].configs
-      : NULL;
-}
-
-/**
- * Return the GLX visuals.
- */
-const __GLcontextModes *
-x11_screen_get_glx_visuals(struct x11_screen *xscr)
-{
-   return (x11_screen_init_glx(xscr))
-      ? xscr->glx_dpy->screenConfigs[xscr->number].visuals
-      : NULL;
-}
-
-static boolean
-x11_screen_is_driver_equal(struct x11_screen *xscr, const char *driver)
-{
-   return (strcmp(xscr->dri_driver, driver) == 0);
-}
-
-/**
- * Probe the screen for the DRI2 driver name.
- */
-const char *
-x11_screen_probe_dri2(struct x11_screen *xscr)
-{
-   /* get the driver name and the device name */
-   if (!xscr->dri_driver) {
-      if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number),
-               &xscr->dri_driver, &xscr->dri_device))
-         xscr->dri_driver = xscr->dri_device = NULL;
-   }
-
-   return xscr->dri_driver;
-}
-
-/**
- * Enable DRI2 and returns the file descriptor of the DRM device.  The file
- * descriptor will be closed automatically when the screen is destoryed.
- */
-int
-x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver)
-{
-   if (xscr->dri_fd < 0) {
-      int fd;
-      drm_magic_t magic;
-
-      /* get the driver name and the device name first */
-      if (!x11_screen_probe_dri2(xscr))
-         return -1;
-
-      if (!x11_screen_is_driver_equal(xscr, driver)) {
-         _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s",
-               xscr->dri_driver, driver);
-         return -1;
-      }
-
-      fd = open(xscr->dri_device, O_RDWR);
-      if (fd < 0) {
-         _eglLog(_EGL_WARNING, "failed to open %s", xscr->dri_device);
-         return -1;
-      }
-
-      memset(&magic, 0, sizeof(magic));
-      if (drmGetMagic(fd, &magic)) {
-         _eglLog(_EGL_WARNING, "failed to get magic");
-         close(fd);
-         return -1;
-      }
-
-      if (!DRI2Authenticate(xscr->dpy,
-               RootWindow(xscr->dpy, xscr->number), magic)) {
-         _eglLog(_EGL_WARNING, "failed to authenticate magic");
-         close(fd);
-         return -1;
-      }
-
-      xscr->dri_fd = fd;
-   }
-
-   return xscr->dri_fd;
-}
-
-/**
- * Create/Destroy the DRI drawable.
- */
-void
-x11_drawable_enable_dri2(struct x11_screen *xscr,
-                         Drawable drawable, boolean on)
-{
-   if (on)
-      DRI2CreateDrawable(xscr->dpy, drawable);
-   else
-      DRI2DestroyDrawable(xscr->dpy, drawable);
-}
-
-/**
- * Copy between buffers of the DRI2 drawable.
- */
-void
-x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
-                          int x, int y, int width, int height,
-                          int src_buf, int dst_buf)
-{
-   XRectangle rect;
-   XserverRegion region;
-
-   rect.x = x;
-   rect.y = y;
-   rect.width = width;
-   rect.height = height;
-
-   region = XFixesCreateRegion(xscr->dpy, &rect, 1);
-   DRI2CopyRegion(xscr->dpy, drawable, region, dst_buf, src_buf);
-   XFixesDestroyRegion(xscr->dpy, region);
-}
-
-/**
- * Get the buffers of the DRI2 drawable.  The returned array should be freed.
- */
-struct x11_drawable_buffer *
-x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
-                         int *width, int *height, unsigned int *attachments,
-                         boolean with_format, int num_ins, int *num_outs)
-{
-   DRI2Buffer *dri2bufs;
-
-   if (with_format)
-      dri2bufs = DRI2GetBuffersWithFormat(xscr->dpy, drawable, width, height,
-            attachments, num_ins, num_outs);
-   else
-      dri2bufs = DRI2GetBuffers(xscr->dpy, drawable, width, height,
-            attachments, num_ins, num_outs);
-
-   return (struct x11_drawable_buffer *) dri2bufs;
-}
-
-/**
- * Return the depth of a drawable.
- *
- * Unlike other drawable functions, the drawable needs not be a DRI2 drawable.
- */
-uint
-x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable)
-{
-   unsigned int depth;
-
-   if (drawable != xscr->last_drawable) {
-      Window root;
-      int x, y;
-      unsigned int w, h, border;
-      Status ok;
-
-      ok = XGetGeometry(xscr->dpy, drawable, &root,
-            &x, &y, &w, &h, &border, &depth);
-      if (!ok)
-         depth = 0;
-
-      xscr->last_drawable = drawable;
-      xscr->last_depth = depth;
-   }
-   else {
-      depth = xscr->last_depth;
-   }
-
-   return depth;
-}
-
-/**
- * Create a mode list of the given size.
- */
-__GLcontextModes *
-x11_context_modes_create(unsigned count)
-{
-   const size_t size = sizeof(__GLcontextModes);
-   __GLcontextModes *base = NULL;
-   __GLcontextModes **next;
-   unsigned i;
-
-   next = &base;
-   for (i = 0; i < count; i++) {
-      *next = (__GLcontextModes *) calloc(1, size);
-      if (*next == NULL) {
-         x11_context_modes_destroy(base);
-         base = NULL;
-         break;
-      }
-      next = &((*next)->next);
-   }
-
-   return base;
-}
-
-/**
- * Destroy a mode list.
- */
-void
-x11_context_modes_destroy(__GLcontextModes *modes)
-{
-   while (modes != NULL) {
-      __GLcontextModes *next = modes->next;
-      free(modes);
-      modes = next;
-   }
-}
-
-/**
- * Return the number of the modes in the mode list.
- */
-unsigned
-x11_context_modes_count(const __GLcontextModes *modes)
-{
-   const __GLcontextModes *mode;
-   int count = 0;
-   for (mode = modes; mode; mode = mode->next)
-      count++;
-   return count;
-}
diff --git a/src/gallium/state_trackers/egl_g3d/x11/x11_screen.h b/src/gallium/state_trackers/egl_g3d/x11/x11_screen.h
deleted file mode 100644 (file)
index 5432858..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * 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 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _X11_SCREEN_H_
-#define _X11_SCREEN_H_
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/dri2tokens.h>
-#include "pipe/p_compiler.h"
-#include "common/native.h"
-
-enum x11_screen_extension {
-   X11_SCREEN_EXTENSION_XSHM,
-   X11_SCREEN_EXTENSION_GLX,
-   X11_SCREEN_EXTENSION_DRI2,
-};
-
-/* the same as DRI2Buffer */
-struct x11_drawable_buffer {
-   unsigned int attachment;
-   unsigned int name;
-   unsigned int pitch;
-   unsigned int cpp;
-   unsigned int flags;
-};
-
-struct x11_screen;
-
-struct x11_screen *
-x11_screen_create(Display *dpy, int screen);
-
-void
-x11_screen_destroy(struct x11_screen *xscr);
-
-boolean
-x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext);
-
-const XVisualInfo *
-x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals);
-
-void
-x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual,
-                          __GLcontextModes *mode);
-
-const __GLcontextModes *
-x11_screen_get_glx_configs(struct x11_screen *xscr);
-
-const __GLcontextModes *
-x11_screen_get_glx_visuals(struct x11_screen *xscr);
-
-const char *
-x11_screen_probe_dri2(struct x11_screen *xscr);
-
-int
-x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver);
-
-__GLcontextModes *
-x11_context_modes_create(unsigned count);
-
-void
-x11_context_modes_destroy(__GLcontextModes *modes);
-
-unsigned
-x11_context_modes_count(const __GLcontextModes *modes);
-
-void
-x11_drawable_enable_dri2(struct x11_screen *xscr,
-                         Drawable drawable, boolean on);
-
-void
-x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable,
-                          int x, int y, int width, int height,
-                          int src_buf, int dst_buf);
-
-struct x11_drawable_buffer *
-x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
-                         int *width, int *height, unsigned int *attachments,
-                         boolean with_format, int num_ins, int *num_outs);
-
-uint
-x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable);
-
-#endif /* _X11_SCREEN_H_ */
index 54cc36141290385106d9d9d52e9b90ef641d6d57..7d4c2430b0cf617a64fe8c5e0bec6b7f4a67b5b4 100644 (file)
@@ -95,8 +95,6 @@ stw_pf_depth_stencil[] = {
    { PIPE_FORMAT_Z24X8_UNORM, {24, 0} },
    { PIPE_FORMAT_X8Z24_UNORM, {24, 0} },
    { PIPE_FORMAT_Z16_UNORM,   {16, 0} },
-   /* pure stencil */
-   { PIPE_FORMAT_S8_UNORM,    { 0, 8} },
    /* combined depth-stencil */
    { PIPE_FORMAT_S8Z24_UNORM, {24, 8} },
    { PIPE_FORMAT_Z24S8_UNORM, {24, 8} }
@@ -220,7 +218,8 @@ stw_pixelformat_init( void )
          const struct stw_pf_color_info *color = &stw_pf_color[j];
          
          if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, 
-                                         PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
+                                         PIPE_TEXTURE_USAGE_RENDER_TARGET |
+                                         PIPE_TEXTURE_USAGE_DISPLAY_TARGET, 0))
             continue;
          
          for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) {
index 1c248a629e681e24625a98125bb6d0323492d761..0324441c067a873b593ceec3a22fff7fc3aa926f 100644 (file)
@@ -4,10 +4,7 @@
 #include "xorg_exa_tgsi.h"
 
 #include "cso_cache/cso_context.h"
-#include "util/u_draw_quad.h"
-#include "util/u_math.h"
 
-#include "pipe/p_inlines.h"
 
 /*XXX also in Xrender.h but the including it here breaks compilition */
 #define XFixedToDouble(f)    (((double) (f)) / 65536.)
index fd82f4fa1d1db4d31aca8003aac5db16446f6c82..e6a89c764510ef029a0a6f6c5ac4da229f74d017 100644 (file)
 #include "util/u_rect.h"
 
 /* Make all the #if cases in the code esier to read */
-/* XXX can it be set to 1? */
 #ifndef DRI2INFOREC_VERSION
-#define DRI2INFOREC_VERSION 0
+#define DRI2INFOREC_VERSION 1
+#endif
+
+#if DRI2INFOREC_VERSION == 2
+static Bool set_format_in_do_create_buffer;
 #endif
 
 typedef struct {
@@ -147,7 +150,9 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form
     buffer->driverPrivate = private;
     buffer->flags = 0; /* not tiled */
 #if DRI2INFOREC_VERSION == 2
-    ((DRI2Buffer2Ptr)buffer)->format = 0;
+    /* ABI forwards/backwards compatibility */
+    if (set_format_in_do_create_buffer)
+       ((DRI2Buffer2Ptr)buffer)->format = 0;
 #elif DRI2INFOREC_VERSION >= 3
     buffer->format = 0;
 #endif
@@ -211,7 +216,9 @@ dri2_destroy_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer)
     xfree(buffer);
 }
 
-#else /* DRI2INFOREC_VERSION < 2 */
+#endif /* DRI2INFOREC_VERSION >= 2 */
+
+#if DRI2INFOREC_VERSION <= 2
 
 static DRI2BufferPtr
 dri2_create_buffers(DrawablePtr pDraw, unsigned int *attachments, int count)
@@ -261,7 +268,7 @@ dri2_destroy_buffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
     }
 }
 
-#endif /* DRI2INFOREC_VERSION >= 2 */
+#endif /* DRI2INFOREC_VERSION <= 2 */
 
 static void
 dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion,
@@ -369,12 +376,17 @@ xorg_dri2_init(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
     DRI2InfoRec dri2info;
+    int major, minor;
+
+    if (xf86LoaderCheckSymbol("DRI2Version")) {
+       DRI2Version(&major, &minor);
+    } else {
+       /* Assume version 1.0 */
+       major = 1;
+       minor = 0;
+    }
 
-#if DRI2INFOREC_VERSION >= 2
     dri2info.version = DRI2INFOREC_VERSION;
-#else
-    dri2info.version = 1;
-#endif
     dri2info.fd = ms->fd;
 
     dri2info.driverName = pScrn->driverName;
@@ -383,7 +395,22 @@ xorg_dri2_init(ScreenPtr pScreen)
 #if DRI2INFOREC_VERSION >= 2
     dri2info.CreateBuffer = dri2_create_buffer;
     dri2info.DestroyBuffer = dri2_destroy_buffer;
-#else
+#endif
+
+    /* For X servers in the 1.6.x series there where two DRI2 version.
+     * This allows us to build one binary that works on both servers.
+     */
+#if DRI2INFOREC_VERSION == 2
+    if (minor == 0) {
+       set_format_in_do_create_buffer = FALSE;
+       dri2info.CreateBuffers = dri2_create_buffers;
+       dri2info.DestroyBuffers = dri2_destroy_buffers;
+    } else
+       set_format_in_do_create_buffer = FALSE;
+#endif
+
+    /* For version 1 set these unconditionaly. */
+#if DRI2INFOREC_VERSION == 1
     dri2info.CreateBuffers = dri2_create_buffers;
     dri2info.DestroyBuffers = dri2_destroy_buffers;
 #endif
index b02fe68f313aee83aab0bf1488db8a5892ee4a65..41bfcd0f5e74a2a538cd0936b765db34077f0205 100644 (file)
@@ -45,7 +45,6 @@
 #include "miscstruct.h"
 #include "dixstruct.h"
 #include "xf86xv.h"
-#include <X11/extensions/Xv.h>
 #ifndef XSERVER_LIBPCIACCESS
 #error "libpciaccess needed"
 #endif
@@ -206,15 +205,40 @@ drv_init_drm(ScrnInfoPtr pScrn)
                ms->PciInfo->dev, ms->PciInfo->func
            );
 
-       ms->fd = drmOpen(NULL, BusID);
 
-       if (ms->fd < 0)
-           return FALSE;
+       ms->api = drm_api_create();
+       ms->fd = drmOpen(ms->api ? ms->api->driver_name : NULL, BusID);
+       xfree(BusID);
+
+       if (ms->fd >= 0)
+           return TRUE;
+
+       if (ms->api && ms->api->destroy)
+           ms->api->destroy(ms->api);
+
+       ms->api = NULL;
+
+       return FALSE;
     }
 
     return TRUE;
 }
 
+static Bool
+drv_close_drm(ScrnInfoPtr pScrn)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (ms->api && ms->api->destroy)
+       ms->api->destroy(ms->api);
+    ms->api = NULL;
+
+    drmClose(ms->fd);
+    ms->fd = -1;
+
+    return TRUE;
+}
+
 static Bool
 drv_init_resource_management(ScrnInfoPtr pScrn)
 {
@@ -229,7 +253,6 @@ drv_init_resource_management(ScrnInfoPtr pScrn)
     if (ms->screen || ms->kms)
        return TRUE;
 
-    ms->api = drm_api_create();
     if (ms->api) {
        ms->screen = ms->api->create_screen(ms->api, ms->fd, NULL);
 
@@ -269,10 +292,6 @@ drv_close_resource_management(ScrnInfoPtr pScrn)
     }
     ms->screen = NULL;
 
-    if (ms->api && ms->api->destroy)
-       ms->api->destroy(ms->api);
-    ms->api = NULL;
-
 #ifdef HAVE_LIBKMS
     if (ms->kms)
        kms_destroy(&ms->kms);
@@ -823,8 +842,7 @@ drv_close_screen(int scrnIndex, ScreenPtr pScreen)
 
     drv_close_resource_management(pScrn);
 
-    drmClose(ms->fd);
-    ms->fd = -1;
+    drv_close_drm(pScrn);
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
index d9432babf185080afced01fe76db5b105e8d5c3f..c91dee73463c819d37ad6c93ee58f7183df04f1a 100644 (file)
@@ -41,7 +41,6 @@
 #include "pipe/p_format.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
 
 #include "util/u_format.h"
 #include "util/u_rect.h"
index bed17caab77da7a2bb8afd616d8999767cd0ef71..3e5e6bd6a6e29a4d02a23dc9d69583869af63088 100644 (file)
@@ -6,11 +6,9 @@
 #include "pipe/p_format.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
 #include "pipe/p_shader_tokens.h"
 
 #include "util/u_memory.h"
-#include "util/u_simple_shaders.h"
 
 #include "tgsi/tgsi_ureg.h"
 
index 251f331ea7ad5aa4b7983bc099f650218fad0e90..13c3fb97e3bd8b1581b5ce290cbd15e781f5e6f3 100644 (file)
@@ -49,8 +49,6 @@
 #include <X11/extensions/dpms.h>
 #endif
 
-#include "X11/Xatom.h"
-
 #include "xorg_tracker.h"
 
 static char *output_enum_list[] = {
index 5bf0e94b62797a6440bebb987e06e4575e4b5235..7bcf77e1d318b54471b2dda448b110aacf5cd235 100644 (file)
@@ -11,7 +11,6 @@
 #include "cso_cache/cso_context.h"
 
 #include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
 
 #include "util/u_format.h"
 
diff --git a/src/gallium/winsys/drm/Makefile.egl b/src/gallium/winsys/drm/Makefile.egl
new file mode 100644 (file)
index 0000000..1b10f11
--- /dev/null
@@ -0,0 +1,65 @@
+# src/gallium/winsys/drm/Makefile.egl
+
+# The driver Makefile should define
+#
+#   EGL_DRIVER_NAME, the name of the driver
+#   EGL_DRIVER_SOURCES, the sources of the driver
+#   EGL_DRIVER_LIBS, extra libraries needed by the driver
+#   EGL_DRIVER_PIPES, the pipe drivers of the driver
+#
+# before including this file.
+
+EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o)
+
+common_LIBS = -ldrm -lm -ldl
+
+x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a
+x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes
+
+kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a
+kms_LIBS = $(common_LIBS)
+
+##### RULES #####
+
+.c.o:
+       $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+
+
+##### TARGETS #####
+
+EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so)
+
+LIB_GALLIUM_DIR = $(TOP)/$(LIB_DIR)/gallium
+EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(LIB_GALLIUM_DIR)/$(drv))
+
+default: $(EGL_DISPLAY_LIBS)
+
+$(EGL_DISPLAY_LIBS): $(LIB_GALLIUM_DIR)/%.so: %.so
+       @mkdir -p $(LIB_GALLIUM_DIR)
+       $(INSTALL) $^ $(LIB_GALLIUM_DIR)
+
+define mklib-egl
+$(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+       $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \
+       -Wl,--whole-archive $($(1)_ST) -Wl,--no-whole-archive \
+       $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $($(1)_LIBS) $(EGL_DRIVER_LIBS)
+endef
+
+egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile
+       $(call mklib-egl,x11)
+
+egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile
+       $(call mklib-egl,kms)
+
+clean:
+       -rm -f $(EGL_DRIVER_OBJECTS)
+       -rm -f $(EGL_DISPLAY_DRIVERS)
+
+install: $(EGL_DISPLAY_LIBS)
+       @$(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+       @echo "Install $(EGL_DISPLAY_DRIVERS)"
+       @for lib in "$(EGL_DISPLAY_LIBS)"; do \
+               $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR); \
+       done
+
+depend:
diff --git a/src/gallium/winsys/drm/Makefile.egl_g3d b/src/gallium/winsys/drm/Makefile.egl_g3d
deleted file mode 100644 (file)
index 3ce2725..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-# src/gallium/winsys/drm/Makefile.egl_g3d
-
-# The driver Makefile should define
-#
-#   EGL_DRIVER_NAME, the name of the driver
-#   EGL_DRIVER_SOURCES, the sources of the driver
-#   EGL_DRIVER_LIBS, extra libraries needed by the driver
-#   EGL_DRIVER_PIPES, the pipe drivers of the driver
-#
-# before including this file.
-
-EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o)
-
-common_LIBS = -ldrm -lm -ldl
-
-x11_ST = $(TOP)/src/gallium/state_trackers/egl_g3d/libeglx11.a
-x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes
-
-kms_ST = $(TOP)/src/gallium/state_trackers/egl_g3d/libeglkms.a
-kms_LIBS = $(common_LIBS)
-
-##### RULES #####
-
-.c.o:
-       $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
-
-
-##### TARGETS #####
-
-EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so)
-
-LIB_GALLIUM_DIR = $(TOP)/$(LIB_DIR)/gallium
-EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(LIB_GALLIUM_DIR)/$(drv))
-
-default: $(EGL_DISPLAY_LIBS)
-
-$(EGL_DISPLAY_LIBS): $(LIB_GALLIUM_DIR)/%.so: %.so
-       @mkdir -p $(LIB_GALLIUM_DIR)
-       $(INSTALL) $^ $(LIB_GALLIUM_DIR)
-
-define mklib-egl
-$(MKLIB) -noprefix -o $@ $(EGL_DRIVER_OBJECTS) \
-       -Wl,--whole-archive $($(1)_ST) -Wl,--no-whole-archive \
-       $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $($(1)_LIBS) $(EGL_DRIVER_LIBS)
-endef
-
-egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile
-       $(call mklib-egl,x11)
-
-egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile
-       $(call mklib-egl,kms)
-
-clean:
-       -rm -f $(EGL_DRIVER_OBJECTS)
-       -rm -f $(EGL_DISPLAY_DRIVERS)
-
-install: $(EGL_DISPLAY_LIBS)
-       @$(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
-       @echo "Install $(EGL_DISPLAY_DRIVERS)"
-       @for lib in "$(EGL_DISPLAY_LIBS)"; do \
-               $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR); \
-       done
-
-depend:
index a1b32eb2a79305039648bef39ab5eff8f0735b96..1c132582005631ef8f843f2c45e56b97544ce676 100644 (file)
@@ -1,29 +1,14 @@
 TOP = ../../../../../..
-GALLIUMDIR = ../../../..
 include $(TOP)/configs/current
 
-LIBNAME = EGL_i965.so
+EGL_DRIVER_NAME = i965
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS = -ldrm_intel
 
-PIPE_DRIVERS = \
-       $(TOP)/src/gallium/state_trackers/egl/libegldrm.a \
-       $(GALLIUMDIR)/winsys/drm/i965/gem/libi965drm.a \
+EGL_DRIVER_PIPES = \
+       $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/i965/libi965.a
 
-DRIVER_SOURCES =
-
-C_SOURCES = \
-       $(COMMON_GALLIUM_SOURCES) \
-       $(DRIVER_SOURCES)
-
-DRIVER_EXTRAS = -ldrm_intel
-
-ASM_SOURCES = 
-
-DRIVER_DEFINES = -I../gem $(shell pkg-config libdrm --atleast-version=2.3.1 \
-                               && echo "-DDRM_VBLANK_FLIP=DRM_VBLANK_FLIP")
-
-include ../../Makefile.template
-
-symlinks:
+include ../../Makefile.egl
diff --git a/src/gallium/winsys/drm/i965/egl/dummy.c b/src/gallium/winsys/drm/i965/egl/dummy.c
new file mode 100644 (file)
index 0000000..4a1bc28
--- /dev/null
@@ -0,0 +1 @@
+/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/i965/egl_g3d/Makefile b/src/gallium/winsys/drm/i965/egl_g3d/Makefile
deleted file mode 100644 (file)
index dd2efe2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER_NAME = i965
-EGL_DRIVER_SOURCES = dummy.c
-EGL_DRIVER_LIBS = -ldrm_intel
-
-EGL_DRIVER_PIPES = \
-       $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
-       $(TOP)/src/gallium/drivers/trace/libtrace.a \
-       $(TOP)/src/gallium/drivers/i965/libi965.a
-
-include ../../Makefile.egl_g3d
diff --git a/src/gallium/winsys/drm/i965/egl_g3d/dummy.c b/src/gallium/winsys/drm/i965/egl_g3d/dummy.c
deleted file mode 100644 (file)
index 4a1bc28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* mklib expects at least one object file */
index c9c92b69b65b81756f48c03ee0abc0f1b00a7a2a..60d675ca73d4011ee2e0ff950bbbf141c047eb2b 100644 (file)
@@ -1,38 +1,14 @@
 TOP = ../../../../../..
-GALLIUMDIR = ../../../..
 include $(TOP)/configs/current
 
-LIBNAME = egl_i915.so
+EGL_DRIVER_NAME = i915
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS = -ldrm_intel
 
-PIPE_DRIVERS = \
-       $(TOP)/src/gallium/state_trackers/egl/libegldrm.a \
-       $(GALLIUMDIR)/winsys/drm/intel/gem/libinteldrm.a \
+EGL_DRIVER_PIPES = \
+       $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/i915/libi915.a
 
-DRIVER_EXTRAS = -lm -lpthread -ldrm_intel
-
-OBJECTS = dummy.o
-
-default: $(TOP)/$(LIB_DIR)/$(LIBNAME)
-
-$(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME)
-       @mkdir -p $(TOP)/$(LIB_DIR)
-       $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)
-
-$(LIBNAME): $(OBJECTS) $(GALLIUM_AUXILIARIES) $(PIPE_DRIVERS) Makefile
-       $(MKLIB) -noprefix -o $@ $(OBJECTS) \
-               -Wl,--whole-archive $(PIPE_DRIVERS) -Wl,--no-whole-archive \
-               -Wl,--start-group $(GALLIUM_AUXILIARIES) -Wl,--end-group \
-                 $(DRI_LIB_DEPS) $(DRIVER_EXTRAS)
-
-clean:
-       -rm -f *.o *.so *~
-
-depend:
-
-symlinks:
-
-install: $(LIBNAME)
-       $(MINSTALL) -m 755 $(LIBNAME) $(INSTALL_DIR)/$(LIB_DIR)
+include ../../Makefile.egl
index 58c7af84e0ab52722684078fa921aea7c5342201..4a1bc28b0b60a60603cda147503dc3227021e1f6 100644 (file)
@@ -1 +1 @@
-/* mklib expects at least one .o is given */
+/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/intel/egl_g3d/Makefile b/src/gallium/winsys/drm/intel/egl_g3d/Makefile
deleted file mode 100644 (file)
index cdbb680..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER_NAME = i915
-EGL_DRIVER_SOURCES = dummy.c
-EGL_DRIVER_LIBS = -ldrm_intel
-
-EGL_DRIVER_PIPES = \
-       $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
-       $(TOP)/src/gallium/drivers/trace/libtrace.a \
-       $(TOP)/src/gallium/drivers/i915/libi915.a
-
-include ../../Makefile.egl_g3d
diff --git a/src/gallium/winsys/drm/intel/egl_g3d/dummy.c b/src/gallium/winsys/drm/intel/egl_g3d/dummy.c
deleted file mode 100644 (file)
index 4a1bc28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* mklib expects at least one object file */
index 450ae09b345225fd48afa84ec82d34453db751dc..8c8176e44ac84dd63b21c8262e636daa4d332e9f 100644 (file)
@@ -196,6 +196,7 @@ destroy(struct drm_api *api)
 struct drm_api intel_drm_api =
 {
    .name = "i915",
+   .driver_name = "i915",
    .create_context = intel_drm_create_context,
    .create_screen = intel_drm_create_screen,
    .texture_from_shared_handle = intel_drm_texture_from_shared_handle,
index 4b2c6a1025edda4df54f7249657827888bd19f40..c9f39d815d8a9e05c13a15f0238dcc429139818a 100644 (file)
@@ -255,6 +255,7 @@ nouveau_drm_handle_from_pt(struct drm_api *api, struct pipe_screen *pscreen,
 
 struct drm_api drm_api_hooks = {
        .name = "nouveau",
+       .driver_name = "nouveau",
        .create_screen = nouveau_drm_create_screen,
        .create_context = nouveau_drm_create_context,
        .texture_from_shared_handle = nouveau_drm_pt_from_name,
diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile
new file mode 100644 (file)
index 0000000..8e812ac
--- /dev/null
@@ -0,0 +1,19 @@
+TOP = ../../../../../..
+include $(TOP)/configs/current
+
+EGL_DRIVER_NAME = nouveau
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS = -ldrm_nouveau
+
+EGL_DRIVER_PIPES = \
+       $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \
+       $(TOP)/src/gallium/drivers/nv04/libnv04.a \
+       $(TOP)/src/gallium/drivers/nv10/libnv10.a \
+       $(TOP)/src/gallium/drivers/nv20/libnv20.a \
+       $(TOP)/src/gallium/drivers/nv30/libnv30.a \
+       $(TOP)/src/gallium/drivers/nv40/libnv40.a \
+       $(TOP)/src/gallium/drivers/nv50/libnv50.a \
+       $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \
+       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a
+
+include ../../Makefile.egl
diff --git a/src/gallium/winsys/drm/nouveau/egl/dummy.c b/src/gallium/winsys/drm/nouveau/egl/dummy.c
new file mode 100644 (file)
index 0000000..4a1bc28
--- /dev/null
@@ -0,0 +1 @@
+/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/nouveau/egl_g3d/Makefile b/src/gallium/winsys/drm/nouveau/egl_g3d/Makefile
deleted file mode 100644 (file)
index 865a5d5..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER_NAME = nouveau
-EGL_DRIVER_SOURCES = dummy.c
-EGL_DRIVER_LIBS = -ldrm_nouveau
-
-EGL_DRIVER_PIPES = \
-       $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \
-       $(TOP)/src/gallium/drivers/nv04/libnv04.a \
-       $(TOP)/src/gallium/drivers/nv10/libnv10.a \
-       $(TOP)/src/gallium/drivers/nv20/libnv20.a \
-       $(TOP)/src/gallium/drivers/nv30/libnv30.a \
-       $(TOP)/src/gallium/drivers/nv40/libnv40.a \
-       $(TOP)/src/gallium/drivers/nv50/libnv50.a \
-       $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a
-
-include ../../Makefile.egl_g3d
diff --git a/src/gallium/winsys/drm/nouveau/egl_g3d/dummy.c b/src/gallium/winsys/drm/nouveau/egl_g3d/dummy.c
deleted file mode 100644 (file)
index 4a1bc28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* mklib expects at least one object file */
index 9552f0ad6a9cafd9d27be4ab323563a7f0f611ca..bff6fdc1ad060e00cd53df3f2fafd158a48c7574 100644 (file)
@@ -270,6 +270,7 @@ static boolean radeon_local_handle_from_texture(struct drm_api *api,
 
 struct drm_api drm_api_hooks = {
     .name = "radeon",
+    .driver_name = "radeon",
     .create_screen = radeon_create_screen,
     .create_context = radeon_create_context,
     .texture_from_shared_handle = radeon_texture_from_shared_handle,
index fcbfd09786562c851db067bab675c2ce54475eee..cd4f9b20f062aa7c20022e1728d8577b0dcd89e0 100644 (file)
@@ -1,38 +1,14 @@
 TOP = ../../../../../..
-GALLIUMDIR = ../../../..
 include $(TOP)/configs/current
 
-LIBNAME = egl_radeon.so
+EGL_DRIVER_NAME = radeon
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS = -ldrm_radeon
 
-PIPE_DRIVERS = \
-       $(TOP)/src/gallium/state_trackers/egl/libegldrm.a \
-       $(GALLIUMDIR)/winsys/drm/radeon/core/libradeonwinsys.a \
+EGL_DRIVER_PIPES = \
+       $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
 
-DRIVER_EXTRAS = -lm -lpthread -ldrm_radeon
-
-OBJECTS = dummy.o
-
-default: $(TOP)/$(LIB_DIR)/$(LIBNAME)
-
-$(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME)
-       @mkdir -p $(TOP)/$(LIB_DIR)
-       $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)
-
-$(LIBNAME): $(OBJECTS) $(GALLIUM_AUXILIARIES) $(PIPE_DRIVERS) Makefile
-       $(MKLIB) -noprefix -o $@ $(OBJECTS) \
-               -Wl,--whole-archive $(PIPE_DRIVERS) -Wl,--no-whole-archive \
-               -Wl,--start-group $(GALLIUM_AUXILIARIES) -Wl,--end-group \
-                 $(DRI_LIB_DEPS) $(DRIVER_EXTRAS)
-
-clean:
-       -rm -f *.o *.so *~
-
-depend:
-
-symlinks:
-
-install: $(LIBNAME)
-       $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(INSTALL_DIR)/$(LIB_DIR)
+include ../../Makefile.egl
index 58c7af84e0ab52722684078fa921aea7c5342201..4a1bc28b0b60a60603cda147503dc3227021e1f6 100644 (file)
@@ -1 +1 @@
-/* mklib expects at least one .o is given */
+/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/radeon/egl_g3d/Makefile b/src/gallium/winsys/drm/radeon/egl_g3d/Makefile
deleted file mode 100644 (file)
index e0de68c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER_NAME = radeon
-EGL_DRIVER_SOURCES = dummy.c
-EGL_DRIVER_LIBS = -ldrm_radeon
-
-EGL_DRIVER_PIPES = \
-       $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
-       $(TOP)/src/gallium/drivers/trace/libtrace.a \
-       $(TOP)/src/gallium/drivers/r300/libr300.a
-
-include ../../Makefile.egl_g3d
diff --git a/src/gallium/winsys/drm/radeon/egl_g3d/dummy.c b/src/gallium/winsys/drm/radeon/egl_g3d/dummy.c
deleted file mode 100644 (file)
index 4a1bc28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/swrast/Makefile b/src/gallium/winsys/drm/swrast/Makefile
new file mode 100644 (file)
index 0000000..363b895
--- /dev/null
@@ -0,0 +1,12 @@
+# src/gallium/winsys/drm/swrast/Makefile
+TOP = ../../../../..
+include $(TOP)/configs/current
+
+SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS)
+
+default install clean:
+       @for dir in $(SUBDIRS) ; do \
+               if [ -d $$dir ] ; then \
+                       (cd $$dir && $(MAKE) $@) || exit 1; \
+               fi \
+       done
diff --git a/src/gallium/winsys/drm/swrast/core/Makefile b/src/gallium/winsys/drm/swrast/core/Makefile
new file mode 100644 (file)
index 0000000..93931ae
--- /dev/null
@@ -0,0 +1,10 @@
+# src/gallium/winsys/drm/swrast/core/Makefile
+
+TOP = ../../../../../..
+include $(TOP)/configs/current
+
+LIBNAME = swrastdrm
+
+C_SOURCES = swrast_drm_api.c
+
+include ../../../../Makefile.template
diff --git a/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c b/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c
new file mode 100644 (file)
index 0000000..8c9f80e
--- /dev/null
@@ -0,0 +1,13 @@
+#include "state_tracker/drm_api.h"
+
+static struct drm_api swrast_drm_api =
+{
+   .name = "swrast",
+};
+
+struct drm_api *
+drm_api_create()
+{
+   (void) swrast_drm_api;
+   return NULL;
+}
diff --git a/src/gallium/winsys/drm/swrast/egl/Makefile b/src/gallium/winsys/drm/swrast/egl/Makefile
new file mode 100644 (file)
index 0000000..26fe2d2
--- /dev/null
@@ -0,0 +1,12 @@
+TOP = ../../../../../..
+include $(TOP)/configs/current
+
+EGL_DRIVER_NAME = swrast
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS =
+
+EGL_DRIVER_PIPES = \
+       $(TOP)/src/gallium/winsys/drm/swrast/core/libswrastdrm.a \
+       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a
+
+include ../../Makefile.egl
diff --git a/src/gallium/winsys/drm/swrast/egl/dummy.c b/src/gallium/winsys/drm/swrast/egl/dummy.c
new file mode 100644 (file)
index 0000000..4a1bc28
--- /dev/null
@@ -0,0 +1 @@
+/* mklib expects at least one object file */
index b6997588de49c1c4d49dbc2a81498eb9098a5a24..b5fd4f5a6a17aa251e304b231fa8774eb128bb33 100644 (file)
 
 #define VMW_COMMAND_SIZE (64*1024)
 #define VMW_SURFACE_RELOCS (1024)
+#define VMW_REGION_RELOCS (512)
 
 #define VMW_MUST_FLUSH_STACK 8
 
+struct vmw_region_relocation
+{
+   struct SVGAGuestPtr *where;
+   struct pb_buffer *buffer;
+   /* TODO: put offset info inside where */
+   uint32 offset;
+};
+
 struct vmw_svga_winsys_context
 {
    struct svga_winsys_context base;
@@ -69,10 +78,31 @@ struct vmw_svga_winsys_context
       uint32_t staged;
       uint32_t reserved;
    } surface;
+   
+   struct {
+      struct vmw_region_relocation relocs[VMW_REGION_RELOCS];
+      uint32_t size;
+      uint32_t used;
+      uint32_t staged;
+      uint32_t reserved;
+   } region;
 
    struct pb_validate *validate;
 
    uint32_t last_fence;
+
+   /**
+    * The amount of GMR that is referred by the commands currently batched
+    * in the context.
+    */
+   uint32_t seen_regions;
+
+   /**
+    * Whether this context should fail to reserve more commands, not because it
+    * ran out of command space, but because a substantial ammount of GMR was
+    * referred.
+    */
+   boolean preemptive_flush;
 };
 
 
@@ -96,6 +126,19 @@ vmw_swc_flush(struct svga_winsys_context *swc,
    ret = pb_validate_validate(vswc->validate);
    assert(ret == PIPE_OK);
    if(ret == PIPE_OK) {
+   
+      /* Apply relocations */
+      for(i = 0; i < vswc->region.used; ++i) {
+         struct vmw_region_relocation *reloc = &vswc->region.relocs[i];
+         struct SVGAGuestPtr ptr;
+
+         if(!vmw_gmr_bufmgr_region_ptr(reloc->buffer, &ptr))
+            assert(0);
+
+         ptr.offset += reloc->offset;
+
+         *reloc->where = ptr;
+      }
 
       if (vswc->command.used)
          vmw_ioctl_command(vswc->vws,
@@ -121,9 +164,18 @@ vmw_swc_flush(struct svga_winsys_context *swc,
    vswc->surface.used = 0;
    vswc->surface.reserved = 0;
 
+   for(i = 0; i < vswc->region.used + vswc->region.staged; ++i) {
+      pb_reference(&vswc->region.relocs[i].buffer, NULL);
+   }
+
+   vswc->region.used = 0;
+   vswc->region.reserved = 0;
+
 #ifdef DEBUG
    vswc->must_flush = FALSE;
 #endif
+   vswc->preemptive_flush = FALSE;
+   vswc->seen_regions = 0;
 
    if(pfence)
       *pfence = fence;
@@ -151,8 +203,10 @@ vmw_swc_reserve(struct svga_winsys_context *swc,
    if(nr_bytes > vswc->command.size)
       return NULL;
 
-   if(vswc->command.used + nr_bytes > vswc->command.size ||
-      vswc->surface.used + nr_relocs > vswc->surface.size) {
+   if(vswc->preemptive_flush ||
+      vswc->command.used + nr_bytes > vswc->command.size ||
+      vswc->surface.used + nr_relocs > vswc->surface.size ||
+      vswc->region.used + nr_relocs > vswc->region.size) {
 #ifdef DEBUG
       vswc->must_flush = TRUE;
       debug_backtrace_capture(vswc->must_flush_stack, 1,
@@ -163,11 +217,14 @@ vmw_swc_reserve(struct svga_winsys_context *swc,
 
    assert(vswc->command.used + nr_bytes <= vswc->command.size);
    assert(vswc->surface.used + nr_relocs <= vswc->surface.size);
-
+   assert(vswc->region.used + nr_relocs <= vswc->region.size);
+   
    vswc->command.reserved = nr_bytes;
    vswc->surface.reserved = nr_relocs;
    vswc->surface.staged = 0;
-
+   vswc->region.reserved = nr_relocs;
+   vswc->region.staged = 0;
+   
    return vswc->command.buffer + vswc->command.used;
 }
 
@@ -206,20 +263,41 @@ vmw_swc_region_relocation(struct svga_winsys_context *swc,
                           unsigned flags)
 {
    struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
-   struct SVGAGuestPtr ptr;
-   struct pb_buffer *buf = vmw_pb_buffer(buffer);
+   struct vmw_region_relocation *reloc;
    enum pipe_error ret;
+   
+   assert(vswc->region.staged < vswc->region.reserved);
 
-   if(!vmw_gmr_bufmgr_region_ptr(buf, &ptr))
-      assert(0);
-
-   ptr.offset += offset;
+   reloc = &vswc->region.relocs[vswc->region.used + vswc->region.staged];
+   reloc->where = where;
+   pb_reference(&reloc->buffer, vmw_pb_buffer(buffer));
+   reloc->offset = offset;
 
-   *where = ptr;
+   ++vswc->region.staged;
 
-   ret = pb_validate_add_buffer(vswc->validate, buf, flags);
+   ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags);
    /* TODO: Update pipebuffer to reserve buffers and not fail here */
    assert(ret == PIPE_OK);
+
+   /*
+    * Flush preemptively the FIFO commands to keep the GMR working set within
+    * the GMR pool size.
+    *
+    * This is necessary for applications like SPECviewperf that generate huge
+    * amounts of immediate vertex data, so that we don't pile up too much of
+    * that vertex data neither in the guest nor in the host.
+    *
+    * Note that in the current implementation if a region is referred twice in
+    * a command stream, it will be accounted twice. We could detect repeated
+    * regions and count only once, but there is no incentive to do that, since
+    * regions are typically short-lived; always referred in a single command;
+    * and at the worst we just flush the commands a bit sooner, which for the
+    * SVGA virtual device it's not a performance issue since flushing commands
+    * to the FIFO won't cause flushing in the host.
+    */
+   vswc->seen_regions += reloc->buffer->base.size;
+   if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2)
+      vswc->preemptive_flush = TRUE;
 }
 
 
@@ -238,6 +316,12 @@ vmw_swc_commit(struct svga_winsys_context *swc)
    vswc->surface.used += vswc->surface.staged;
    vswc->surface.staged = 0;
    vswc->surface.reserved = 0;
+
+   assert(vswc->region.staged <= vswc->region.reserved);
+   assert(vswc->region.used + vswc->region.staged <= vswc->region.size);
+   vswc->region.used += vswc->region.staged;
+   vswc->region.staged = 0;
+   vswc->region.reserved = 0;
 }
 
 
@@ -246,6 +330,11 @@ vmw_swc_destroy(struct svga_winsys_context *swc)
 {
    struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
    unsigned i;
+
+   for(i = 0; i < vswc->region.used; ++i) {
+      pb_reference(&vswc->region.relocs[i].buffer, NULL);
+   }
+
    for(i = 0; i < vswc->surface.used; ++i) {
       p_atomic_dec(&vswc->surface.handles[i]->validated);
       vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL);
@@ -279,6 +368,7 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
 
    vswc->command.size = VMW_COMMAND_SIZE;
    vswc->surface.size = VMW_SURFACE_RELOCS;
+   vswc->region.size = VMW_REGION_RELOCS;
 
    vswc->validate = pb_validate_create();
    if(!vswc->validate) {
index a875107370cb56269c48e268b9c9180d4342ca3e..f1d69865e774f35b3f8e6eb29c6ffc2a1c255c64 100644 (file)
 
 #include "svga_winsys.h"
 
+
+#define VMW_GMR_POOL_SIZE (16*1024*1024)
+
+
 struct pb_manager;
 struct vmw_region;
 
index 4f5ccea4677124fb08b348b5ce1fcd05601c6fca..d9abde307939bf650478672fb767fc22bd806ac4 100644 (file)
@@ -85,6 +85,23 @@ vmw_drm_create_screen(struct drm_api *drm_api,
    struct pipe_screen *screen;
    struct dri1_create_screen_arg *dri1;
 
+   if (!arg || arg->mode == DRM_CREATE_NORMAL) {
+      struct dri1_api_version drm_ver;
+      drmVersionPtr ver;
+
+      ver = drmGetVersion(fd);
+      if (ver == NULL)
+        return NULL;
+
+      drm_ver.major = ver->version_major;
+      drm_ver.minor = ver->version_minor;
+
+      drmFreeVersion(ver);
+      if (!vmw_dri1_check_version(&drm_ver, &drm_required,
+                                 &drm_compat, "vmwgfx drm driver"))
+        return NULL;
+   }
+
    if (arg != NULL) {
       switch (arg->mode) {
       case DRM_CREATE_NORMAL:
@@ -220,22 +237,19 @@ vmw_dri1_present_locked(struct pipe_context *locked_pipe,
    vmw_svga_winsys_surface_reference(&vsrf, NULL);
 }
 
-/**
- * FIXME: We'd probably want to cache these buffers in the
- * screen, based on handle.
- */
-
-static struct pipe_buffer *
-vmw_drm_buffer_from_handle(struct drm_api *drm_api,
-                           struct pipe_screen *screen,
-                          const char *name,
-                          unsigned handle)
+static struct pipe_texture *
+vmw_drm_texture_from_handle(struct drm_api *drm_api,
+                           struct pipe_screen *screen,
+                           struct pipe_texture *templat,
+                           const char *name,
+                           unsigned stride,
+                           unsigned handle)
 {
     struct vmw_svga_winsys_surface *vsrf;
     struct svga_winsys_surface *ssrf;
     struct vmw_winsys_screen *vws =
        vmw_winsys_screen(svga_winsys_screen(screen));
-    struct pipe_buffer *buf;
+    struct pipe_texture *tex;
     union drm_vmw_surface_reference_arg arg;
     struct drm_vmw_surface_arg *req = &arg.req;
     struct drm_vmw_surface_create_req *rep = &arg.rep;
@@ -282,43 +296,28 @@ vmw_drm_buffer_from_handle(struct drm_api *drm_api,
 
     pipe_reference_init(&vsrf->refcnt, 1);
     p_atomic_set(&vsrf->validated, 0);
+    vsrf->screen = vws;
     vsrf->sid = handle;
     ssrf = svga_winsys_surface(vsrf);
-    buf = svga_screen_buffer_wrap_surface(screen, rep->format, ssrf);
-    if (!buf)
+    tex = svga_screen_texture_wrap_surface(screen, templat, rep->format, ssrf);
+    if (!tex)
        vmw_svga_winsys_surface_reference(&vsrf, NULL);
 
-    return buf;
+    return tex;
   out_mip:
     vmw_ioctl_surface_destroy(vws, handle);
     return NULL;
 }
 
-static struct pipe_texture *
-vmw_drm_texture_from_handle(struct drm_api *drm_api,
-                           struct pipe_screen *screen,
-                           struct pipe_texture *templat,
-                           const char *name,
-                           unsigned stride,
-                           unsigned handle)
-{
-    struct pipe_buffer *buffer;
-    buffer = vmw_drm_buffer_from_handle(drm_api, screen, name, handle);
-
-    if (!buffer)
-       return NULL;
-
-    return screen->texture_blanket(screen, templat, &stride, buffer);
-}
-
 static boolean
-vmw_drm_handle_from_buffer(struct drm_api *drm_api,
+vmw_drm_handle_from_texture(struct drm_api *drm_api,
                            struct pipe_screen *screen,
-                          struct pipe_buffer *buffer,
+                          struct pipe_texture *texture,
+                          unsigned *stride,
                           unsigned *handle)
 {
     struct svga_winsys_surface *surface =
-       svga_screen_buffer_get_winsys_surface(buffer);
+       svga_screen_texture_get_winsys_surface(texture);
     struct vmw_svga_winsys_surface *vsrf;
 
     if (!surface)
@@ -326,25 +325,13 @@ vmw_drm_handle_from_buffer(struct drm_api *drm_api,
 
     vsrf = vmw_svga_winsys_surface(surface);
     *handle = vsrf->sid;
+    *stride = util_format_get_nblocksx(texture->format, texture->width0) *
+       util_format_get_blocksize(texture->format);
+
     vmw_svga_winsys_surface_reference(&vsrf, NULL);
     return TRUE;
 }
 
-static boolean
-vmw_drm_handle_from_texture(struct drm_api *drm_api,
-                           struct pipe_screen *screen,
-                           struct pipe_texture *texture,
-                           unsigned *stride,
-                           unsigned *handle)
-{
-    struct pipe_buffer *buffer;
-
-    if (!svga_screen_buffer_from_texture(texture, &buffer, stride))
-       return FALSE;
-
-    return vmw_drm_handle_from_buffer(drm_api, screen, buffer, handle);
-}
-
 static struct pipe_context*
 vmw_drm_create_context(struct drm_api *drm_api,
                        struct pipe_screen *screen)
@@ -359,6 +346,7 @@ static struct dri1_api dri1_api_hooks = {
 
 static struct drm_api vmw_drm_api_hooks = {
    .name = "vmwgfx",
+   .driver_name = "vmwgfx",
    .create_screen = vmw_drm_create_screen,
    .create_context = vmw_drm_create_context,
    .texture_from_shared_handle = vmw_drm_texture_from_handle,
index b1c24b0cb6a1bd139a92e73b768e67f65e5c8d3b..b9823d7857502fb50a3e47093877549955920672 100644 (file)
@@ -53,14 +53,32 @@ vmw_pools_init(struct vmw_winsys_screen *vws)
       goto error;
 
    vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr,
-                                        16*1024*1024,
+                                        VMW_GMR_POOL_SIZE,
                                         12 /* 4096 alignment */);
    if(!vws->pools.gmr_mm)
       goto error;
 
+   /*
+    * GMR buffers are typically shortlived, but it's possible that at a given
+    * instance a buffer is mapped. So to avoid stalling we tell pipebuffer to
+    * forbid creation of buffers beyond half the GMR pool size,
+    *
+    * XXX: It is unclear weather we want to limit the total amount of temporary
+    * malloc memory used to backup unvalidated GMR buffers. On one hand it is
+    * preferrable to fail an allocation than exhausting the guest memory with
+    * temporary data, but on the other hand it is possible that a stupid
+    * application creates large vertex buffers and does not use them for a long
+    * time -- since the svga pipe driver only emits the DMA uploads when a
+    * buffer is used for drawing this would effectively disabling swapping GMR
+    * buffers to memory. So far, the preemptively flush already seems to keep
+    * total allocated memory within relatively small numbers, so we don't
+    * limit.
+    */
    vws->pools.gmr_fenced = fenced_bufmgr_create(
       vws->pools.gmr_mm,
-      vmw_fence_ops_create(vws));
+      vmw_fence_ops_create(vws),
+      VMW_GMR_POOL_SIZE/2,
+      ~0);
 
 #ifdef DEBUG
    vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced,
index 8e2980c318c8b5075c82706c9d27e2262defaff3..a3e73131c35aa2397afeff421c7ffc6a96cfe234 100644 (file)
@@ -1,18 +1,14 @@
-
 TOP = ../../../../../..
 include $(TOP)/configs/current
 
-LIBNAME = EGL_svga.so
+EGL_DRIVER_NAME = vmwgfx
+EGL_DRIVER_SOURCES = dummy.c
+EGL_DRIVER_LIBS =
 
-PIPE_DRIVERS = \
-       $(TOP)/src/gallium/state_trackers/egl/libegldrm.a \
+EGL_DRIVER_PIPES = \
        $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \
+       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/svga/libsvga.a
 
-C_SOURCES = \
-       $(COMMON_GALLIUM_SOURCES)
-
-include ../../Makefile.template
-
-symlinks:
+include ../../Makefile.egl
diff --git a/src/gallium/winsys/drm/vmware/egl/dummy.c b/src/gallium/winsys/drm/vmware/egl/dummy.c
new file mode 100644 (file)
index 0000000..4a1bc28
--- /dev/null
@@ -0,0 +1 @@
+/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/drm/vmware/egl_g3d/Makefile b/src/gallium/winsys/drm/vmware/egl_g3d/Makefile
deleted file mode 100644 (file)
index 3cf7992..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-EGL_DRIVER_NAME = vmwgfx
-EGL_DRIVER_SOURCES = dummy.c
-EGL_DRIVER_LIBS =
-
-EGL_DRIVER_PIPES = \
-       $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
-       $(TOP)/src/gallium/drivers/trace/libtrace.a \
-       $(TOP)/src/gallium/drivers/svga/libsvga.a
-
-include ../../Makefile.egl_g3d
diff --git a/src/gallium/winsys/drm/vmware/egl_g3d/dummy.c b/src/gallium/winsys/drm/vmware/egl_g3d/dummy.c
deleted file mode 100644 (file)
index 4a1bc28..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* mklib expects at least one object file */
diff --git a/src/gallium/winsys/egl_xlib/Makefile b/src/gallium/winsys/egl_xlib/Makefile
deleted file mode 100644 (file)
index 06c1fb0..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-# src/gallium/winsys/egl_xlib/Makefile
-
-# Build softpipe/xlib/EGL driver library/object: "egl_softpipe.so"
-
-
-TOP = ../../../..
-include $(TOP)/configs/current
-
-
-DRIVER_NAME = egl_softpipe.so
-
-
-INCLUDE_DIRS = \
-       -I$(TOP)/include \
-       -I$(TOP)/src/egl/main \
-       -I$(TOP)/src/mesa \
-       -I$(TOP)/src/mesa/main \
-       -I$(TOP)/src/gallium/include \
-       -I$(TOP)/src/gallium/drivers \
-       -I$(TOP)/src/gallium/auxiliary
-
-WINSYS_SOURCES = \
-       egl_xlib.c \
-       sw_winsys.c
-
-WINSYS_OBJECTS = $(WINSYS_SOURCES:.c=.o)
-
-
-LIBS = \
-       $(GALLIUM_DRIVERS) \
-       $(GALLIUM_AUXILIARIES)
-LIB_DEPS = $(EGL_LIB_DEPS) -lm -lX11
-
-LOCAL_CFLAGS =
-
-
-.c.o:
-       $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@
-
-
-.PHONY: library
-
-
-default: depend library Makefile
-
-
-library: $(TOP)/$(LIB_DIR)/$(DRIVER_NAME)
-
-
-# Make the egl_softpipe.so library
-$(TOP)/$(LIB_DIR)/$(DRIVER_NAME): $(WINSYS_OBJECTS) $(LIBS)
-       $(TOP)/bin/mklib -o $(DRIVER_NAME) \
-               -linker "$(CC)" \
-               -noprefix \
-               -install $(TOP)/$(LIB_DIR) \
-               $(MKLIB_OPTIONS) $(WINSYS_OBJECTS) \
-               -Wl,--whole-archive $(LIBS) -Wl,--no-whole-archive \
-               $(LIB_DEPS)
-
-
-depend: $(WINSYS_SOURCES)
-       @ echo "running $(MKDEP)"
-       @ rm -f depend  # workaround oops on gutsy?!?
-       @ touch depend
-       @ $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(WINSYS_SOURCES) \
-               > /dev/null 2>/dev/null
-
-
-install: default
-       $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR)
-       @if [ -e $(TOP)/$(LIB_DIR) ]; then \
-               $(MINSTALL) $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) $(INSTALL_DIR)/$(LIB_DIR); \
-       fi
-
-
-# Emacs tags
-tags:
-       etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h
-
-clean:
-       -rm -f *.o *~ *.bak
-
-
-include depend
diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c
deleted file mode 100644 (file)
index 1d9bac3..0000000
+++ /dev/null
@@ -1,853 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-/**
- * EGL / softpipe / xlib winsys module
- *
- * Authors: Brian Paul
- */
-
-
-#include <dlfcn.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-#include "pipe/p_state.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "util/u_memory.h"
-#include "util/u_math.h"
-#include "softpipe/sp_winsys.h"
-#include "softpipe/sp_texture.h"
-
-#include "eglconfig.h"
-#include "eglconfigutil.h"
-#include "eglcontext.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglglobals.h"
-#include "egllog.h"
-#include "eglsurface.h"
-
-#include "state_tracker/st_public.h"
-
-#include "sw_winsys.h"
-
-
-/** subclass of _EGLDriver */
-struct xlib_egl_driver
-{
-   _EGLDriver Base;   /**< base class */
-   EGLint apis;
-};
-
-
-/** driver data of _EGLDisplay */
-struct xlib_egl_display
-{
-   Display *Dpy;
-
-   struct pipe_winsys *winsys;
-   struct pipe_screen *screen;
-};
-
-
-/** subclass of _EGLContext */
-struct xlib_egl_context
-{
-   _EGLContext Base;   /**< base class */
-
-   struct pipe_context *pipe;   /**< Gallium driver context */
-   struct st_context *Context;  /**< Mesa/gallium state tracker context */
-};
-
-
-/** subclass of _EGLSurface */
-struct xlib_egl_surface
-{
-   _EGLSurface Base;   /**< base class */
-
-   /* These are set for window surface */
-   Display *Dpy;  /**< The X Display of the window */
-   Window Win;    /**< The user-created window ID */
-   GC Gc;
-   XVisualInfo VisInfo;
-
-   struct pipe_winsys *winsys;
-
-   struct st_framebuffer *Framebuffer;
-};
-
-
-static void
-flush_frontbuffer(struct pipe_winsys *pws,
-                  struct pipe_surface *psurf,
-                  void *context_private);
-
-
-/** cast wrapper */
-static INLINE struct xlib_egl_driver *
-xlib_egl_driver(_EGLDriver *drv)
-{
-   return (struct xlib_egl_driver *) drv;
-}
-
-
-static INLINE struct xlib_egl_display *
-xlib_egl_display(_EGLDisplay *dpy)
-{
-   return (struct xlib_egl_display *) dpy->DriverData;
-}
-
-
-static INLINE struct xlib_egl_surface *
-lookup_surface(_EGLSurface *surf)
-{
-   return (struct xlib_egl_surface *) surf;
-}
-
-
-static INLINE struct xlib_egl_context *
-lookup_context(_EGLContext *ctx)
-{
-   return (struct xlib_egl_context *) ctx;
-}
-
-
-/**
- * Create the EGLConfigs.  (one per X visual)
- */
-static void
-create_configs(struct xlib_egl_display *xdpy, _EGLDisplay *disp)
-{
-   static const EGLint all_apis = (EGL_OPENGL_ES_BIT |
-                                   EGL_OPENGL_ES2_BIT |
-                                   EGL_OPENVG_BIT |
-                                   EGL_OPENGL_BIT);
-   XVisualInfo *visInfo, visTemplate;
-   int num_visuals, i;
-
-   /* get list of all X visuals, create an EGL config for each */
-   visTemplate.screen = DefaultScreen(xdpy->Dpy);
-   visInfo = XGetVisualInfo(xdpy->Dpy, VisualScreenMask,
-                            &visTemplate, &num_visuals);
-   if (!visInfo) {
-      printf("egl_xlib.c: couldn't get any X visuals\n");
-      abort();
-   }
-
-   for (i = 0; i < num_visuals; i++) {
-      _EGLConfig *config = calloc(1, sizeof(_EGLConfig));
-      int id = i + 1;
-      int rbits = util_bitcount(visInfo[i].red_mask);
-      int gbits = util_bitcount(visInfo[i].green_mask);
-      int bbits = util_bitcount(visInfo[i].blue_mask);
-      int abits = bbits == 8 ? 8 : 0;
-      int zbits = 24;
-      int sbits = 8;
-      int visid = visInfo[i].visualid;
-#if defined(__cplusplus) || defined(c_plusplus)
-      int vistype = visInfo[i].c_class;
-#else
-      int vistype = visInfo[i].class;
-#endif
-
-      _eglInitConfig(config, id);
-      SET_CONFIG_ATTRIB(config, EGL_BUFFER_SIZE, rbits + gbits + bbits + abits);
-      SET_CONFIG_ATTRIB(config, EGL_RED_SIZE, rbits);
-      SET_CONFIG_ATTRIB(config, EGL_GREEN_SIZE, gbits);
-      SET_CONFIG_ATTRIB(config, EGL_BLUE_SIZE, bbits);
-      SET_CONFIG_ATTRIB(config, EGL_ALPHA_SIZE, abits);
-      SET_CONFIG_ATTRIB(config, EGL_DEPTH_SIZE, zbits);
-      SET_CONFIG_ATTRIB(config, EGL_STENCIL_SIZE, sbits);
-      SET_CONFIG_ATTRIB(config, EGL_NATIVE_VISUAL_ID, visid);
-      SET_CONFIG_ATTRIB(config, EGL_NATIVE_VISUAL_TYPE, vistype);
-      SET_CONFIG_ATTRIB(config, EGL_NATIVE_RENDERABLE, EGL_FALSE);
-      SET_CONFIG_ATTRIB(config, EGL_CONFORMANT, all_apis);
-      SET_CONFIG_ATTRIB(config, EGL_RENDERABLE_TYPE, all_apis);
-      SET_CONFIG_ATTRIB(config, EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT);
-      SET_CONFIG_ATTRIB(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
-      SET_CONFIG_ATTRIB(config, EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
-
-      _eglAddConfig(disp, config);
-   }
-
-   XFree(visInfo);
-}
-
-
-/**
- * Called via eglInitialize(), drv->API.Initialize().
- */
-static EGLBoolean
-xlib_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
-                   EGLint *major, EGLint *minor)
-{
-   struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
-   struct xlib_egl_display *xdpy;
-
-   xdpy = CALLOC_STRUCT(xlib_egl_display);
-   if (!xdpy)
-      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
-
-   xdpy->Dpy = (Display *) dpy->NativeDisplay;
-   if (!xdpy->Dpy) {
-      xdpy->Dpy = XOpenDisplay(NULL);
-      if (!xdpy->Dpy) {
-         free(xdpy);
-         return EGL_FALSE;
-      }
-   }
-
-   /* create winsys and pipe screen */
-   xdpy->winsys = create_sw_winsys();
-   if (!xdpy->winsys) {
-      free(xdpy);
-      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
-   }
-   xdpy->winsys->flush_frontbuffer = flush_frontbuffer;
-   xdpy->screen = softpipe_create_screen(xdpy->winsys);
-   if (!xdpy->screen) {
-      free(xdpy->winsys);
-      free(xdpy);
-      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
-   }
-
-   dpy->DriverData = (void *) xdpy;
-   dpy->ClientAPIsMask = xdrv->apis;
-
-   create_configs(xdpy, dpy);
-
-   /* we're supporting EGL 1.4 */
-   *major = 1;
-   *minor = 4;
-
-   return EGL_TRUE;
-}
-
-
-/**
- * Called via eglTerminate(), drv->API.Terminate().
- */
-static EGLBoolean
-xlib_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-   struct xlib_egl_display *xdpy = xlib_egl_display(dpy);
-
-   _eglReleaseDisplayResources(drv, dpy);
-   _eglCleanupDisplay(dpy);
-
-   xdpy->screen->destroy(xdpy->screen);
-   free(xdpy->winsys);
-
-   if (!dpy->NativeDisplay)
-      XCloseDisplay(xdpy->Dpy);
-   free(xdpy);
-
-   return EGL_TRUE;
-}
-
-
-static _EGLProc
-xlib_eglGetProcAddress(_EGLDriver *drv, const char *procname)
-{
-   return (_EGLProc) st_get_proc_address(procname);
-}
-
-
-static void
-get_drawable_visual_info(Display *dpy, Drawable d, XVisualInfo *visInfo)
-{
-   XWindowAttributes attr;
-   XVisualInfo visTemp, *vis;
-   int num_visuals;
-
-   XGetWindowAttributes(dpy, d, &attr);
-
-   visTemp.screen = DefaultScreen(dpy);
-   visTemp.visualid = attr.visual->visualid;
-   vis = XGetVisualInfo(dpy,
-                        (VisualScreenMask | VisualIDMask),
-                        &visTemp, &num_visuals);
-   if (vis)
-      *visInfo = *vis;
-
-   XFree(vis);
-}
-
-
-
-/** Get size of given window */
-static Status
-get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height)
-{
-   Window root;
-   Status stat;
-   int xpos, ypos;
-   unsigned int w, h, bw, depth;
-   stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth);
-   *width = w;
-   *height = h;
-   return stat;
-}
-
-
-static void
-check_and_update_buffer_size(struct xlib_egl_surface *surface)
-{
-   uint width, height;
-   if (surface->Base.Type == EGL_PBUFFER_BIT) {
-      width = surface->Base.Width;
-      height = surface->Base.Height;
-   }
-   else {
-      get_drawable_size(surface->Dpy, surface->Win, &width, &height);
-   }
-   st_resize_framebuffer(surface->Framebuffer, width, height);
-   surface->Base.Width = width;
-   surface->Base.Height = height;
-}
-
-
-
-static void
-display_surface(struct pipe_winsys *pws,
-                struct pipe_surface *psurf,
-                struct xlib_egl_surface *xsurf)
-{
-   struct softpipe_texture *spt = softpipe_texture(psurf->texture);
-   XImage *ximage;
-   void *data;
-
-   if (xsurf->Base.Type == EGL_PBUFFER_BIT)
-      return;
-
-   ximage = XCreateImage(xsurf->Dpy,
-                         xsurf->VisInfo.visual,
-                         xsurf->VisInfo.depth,
-                         ZPixmap, 0,   /* format, offset */
-                         NULL,         /* data */
-                         0, 0,         /* size */
-                         32,           /* bitmap_pad */
-                         0);           /* bytes_per_line */
-
-
-   assert(ximage->format);
-   assert(ximage->bitmap_unit);
-
-   data = pws->buffer_map(pws, spt->buffer, 0);
-
-   /* update XImage's fields */
-   ximage->data = data;
-   ximage->width = psurf->width;
-   ximage->height = psurf->height;
-   ximage->bytes_per_line = spt->stride[psurf->level];
-   
-   XPutImage(xsurf->Dpy, xsurf->Win, xsurf->Gc,
-             ximage, 0, 0, 0, 0, psurf->width, psurf->height);
-
-   XSync(xsurf->Dpy, 0);
-
-   ximage->data = NULL;
-   XDestroyImage(ximage);
-
-   pws->buffer_unmap(pws, spt->buffer);
-}
-
-
-
-/** Display gallium surface in X window */
-static void
-flush_frontbuffer(struct pipe_winsys *pws,
-                  struct pipe_surface *psurf,
-                  void *context_private)
-{
-   struct xlib_egl_surface *xsurf = (struct xlib_egl_surface *) context_private;
-   display_surface(pws, psurf, xsurf);
-}
-
-
-
-/**
- * Called via eglCreateContext(), drv->API.CreateContext().
- */
-static _EGLContext *
-xlib_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
-                      _EGLContext *share_list, const EGLint *attrib_list)
-{
-   struct xlib_egl_display *xdpy = xlib_egl_display(dpy);
-   struct xlib_egl_context *ctx;
-   struct st_context *share_ctx = NULL; /* XXX fix */
-   __GLcontextModes visual;
-
-   ctx = CALLOC_STRUCT(xlib_egl_context);
-   if (!ctx)
-      return NULL;
-
-   /* let EGL lib init the common stuff */
-   if (!_eglInitContext(drv, &ctx->Base, conf, attrib_list)) {
-      free(ctx);
-      return NULL;
-   }
-
-   /* API-dependent context creation */
-   switch (ctx->Base.ClientAPI) {
-   case EGL_OPENVG_API:
-   case EGL_OPENGL_ES_API:
-      _eglLog(_EGL_DEBUG, "Create Context for ES version %d\n",
-              ctx->Base.ClientVersion);
-      /* fall-through */
-   case EGL_OPENGL_API:
-      /* create a softpipe context */
-      ctx->pipe = softpipe_create(xdpy->screen);
-      /* Now do xlib / state tracker inits here */
-      _eglConfigToContextModesRec(conf, &visual);
-      ctx->Context = st_create_context(ctx->pipe, &visual, share_ctx);
-      break;
-   default:
-      _eglError(EGL_BAD_MATCH, "eglCreateContext(unsupported API)");
-      free(ctx);
-      return NULL;
-   }
-
-   return &ctx->Base;
-}
-
-
-static EGLBoolean
-xlib_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct xlib_egl_context *context = lookup_context(ctx);
-
-   if (!_eglIsContextBound(&context->Base)) {
-      /* API-dependent clean-up */
-      switch (context->Base.ClientAPI) {
-      case EGL_OPENGL_ES_API:
-      case EGL_OPENVG_API:
-         /* fall-through */
-      case EGL_OPENGL_API:
-         st_destroy_context(context->Context);
-         break;
-      default:
-         assert(0);
-      }
-      free(context);
-   }
-   return EGL_TRUE;
-}
-
-
-/**
- * Called via eglMakeCurrent(), drv->API.MakeCurrent().
- */
-static EGLBoolean
-xlib_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy,
-                    _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
-{
-   struct xlib_egl_context *context = lookup_context(ctx);
-   struct xlib_egl_surface *draw_surf = lookup_surface(draw);
-   struct xlib_egl_surface *read_surf = lookup_surface(read);
-   struct st_context *oldcontext = NULL;
-   _EGLContext *oldctx;
-
-   oldctx = _eglGetCurrentContext();
-   if (oldctx && _eglIsContextLinked(oldctx))
-      oldcontext = st_get_current();
-
-   if (!_eglMakeCurrent(drv, dpy, draw, read, ctx))
-      return EGL_FALSE;
-
-   /* Flush before switching context.  Check client API? */
-   if (oldcontext)
-      st_flush(oldcontext, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
-   st_make_current((context ? context->Context : NULL),
-                   (draw_surf ? draw_surf->Framebuffer : NULL),
-                   (read_surf ? read_surf->Framebuffer : NULL));
-
-   if (draw_surf)
-      check_and_update_buffer_size(draw_surf);
-   if (read_surf && read_surf != draw_surf)
-      check_and_update_buffer_size(draw_surf);
-
-   return EGL_TRUE;
-}
-
-
-static enum pipe_format
-choose_color_format(const __GLcontextModes *visual)
-{
-   if (visual->redBits == 8 &&
-       visual->greenBits == 8 &&
-       visual->blueBits == 8 &&
-       visual->alphaBits == 8) {
-      /* XXX this really also depends on the ordering of R,G,B,A */
-      return PIPE_FORMAT_A8R8G8B8_UNORM;
-   }
-   else {
-      assert(0);
-      return PIPE_FORMAT_NONE;
-   }
-}
-
-
-static enum pipe_format
-choose_depth_format(const __GLcontextModes *visual)
-{
-   if (visual->depthBits > 0)
-      return PIPE_FORMAT_S8Z24_UNORM;
-   else
-      return PIPE_FORMAT_NONE;
-}
-
-
-static enum pipe_format
-choose_stencil_format(const __GLcontextModes *visual)
-{
-   if (visual->stencilBits > 0)
-      return PIPE_FORMAT_S8Z24_UNORM;
-   else
-      return PIPE_FORMAT_NONE;
-}
-
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-xlib_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
-                            NativeWindowType window, const EGLint *attrib_list)
-{
-   struct xlib_egl_display *xdpy = xlib_egl_display(disp);
-   struct xlib_egl_surface *surf;
-   __GLcontextModes visual;
-   uint width, height;
-
-   surf = CALLOC_STRUCT(xlib_egl_surface);
-   if (!surf)
-      return NULL;
-
-   /* Let EGL lib init the common stuff */
-   if (!_eglInitSurface(drv, &surf->Base, EGL_WINDOW_BIT,
-                        conf, attrib_list)) {
-      free(surf);
-      return NULL;
-   }
-
-   /*
-    * Now init the Xlib and gallium stuff
-    */
-   surf->Win = (Window) window;  /* The X window ID */
-   surf->Dpy = xdpy->Dpy;  /* The X display */
-   surf->Gc = XCreateGC(surf->Dpy, surf->Win, 0, NULL);
-
-   surf->winsys = xdpy->winsys;
-
-   _eglConfigToContextModesRec(conf, &visual);
-   get_drawable_size(surf->Dpy, surf->Win, &width, &height);
-   get_drawable_visual_info(surf->Dpy, surf->Win, &surf->VisInfo);
-
-   surf->Base.Width = width;
-   surf->Base.Height = height;
-
-   /* Create GL statetracker framebuffer */
-   surf->Framebuffer = st_create_framebuffer(&visual,
-                                             choose_color_format(&visual),
-                                             choose_depth_format(&visual),
-                                             choose_stencil_format(&visual),
-                                             width, height,
-                                             (void *) surf);
-
-   st_resize_framebuffer(surf->Framebuffer, width, height);
-
-   return &surf->Base;
-}
-
-
-static _EGLSurface *
-xlib_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
-                             const EGLint *attrib_list)
-{
-   struct xlib_egl_display *xdpy = xlib_egl_display(disp);
-   struct xlib_egl_surface *surf;
-   __GLcontextModes visual;
-   uint width, height;
-   EGLBoolean bind_texture;
-
-   surf = CALLOC_STRUCT(xlib_egl_surface);
-   if (!surf) {
-      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
-      return NULL;
-   }
-
-   if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT,
-                        conf, attrib_list)) {
-      free(surf);
-      return NULL;
-   }
-   if (surf->Base.Width < 0 || surf->Base.Height < 0) {
-      _eglError(EGL_BAD_PARAMETER, "eglCreatePbufferSurface");
-      free(surf);
-      return NULL;
-   }
-
-   bind_texture = (surf->Base.TextureFormat != EGL_NO_TEXTURE);
-   width = (uint) surf->Base.Width;
-   height = (uint) surf->Base.Height;
-   if ((surf->Base.TextureTarget == EGL_NO_TEXTURE && bind_texture) ||
-       (surf->Base.TextureTarget != EGL_NO_TEXTURE && !bind_texture)) {
-      _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface");
-      free(surf);
-      return NULL;
-   }
-   /* a framebuffer of zero width or height confuses st */
-   if (width == 0 || height == 0) {
-      _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface");
-      free(surf);
-      return NULL;
-   }
-   /* no mipmap generation */
-   if (surf->Base.MipmapTexture) {
-      _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface");
-      free(surf);
-      return NULL;
-   }
-
-   surf->winsys = xdpy->winsys;
-
-   _eglConfigToContextModesRec(conf, &visual);
-
-   /* Create GL statetracker framebuffer */
-   surf->Framebuffer = st_create_framebuffer(&visual,
-                                             choose_color_format(&visual),
-                                             choose_depth_format(&visual),
-                                             choose_stencil_format(&visual),
-                                             width, height,
-                                             (void *) surf);
-   st_resize_framebuffer(surf->Framebuffer, width, height);
-
-   return &surf->Base;
-}
-
-
-static EGLBoolean
-xlib_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
-{
-   struct xlib_egl_surface *surf = lookup_surface(surface);
-   if (!_eglIsSurfaceBound(&surf->Base)) {
-      if (surf->Base.Type != EGL_PBUFFER_BIT)
-         XFreeGC(surf->Dpy, surf->Gc);
-      st_unreference_framebuffer(surf->Framebuffer);
-      free(surf);
-   }
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-xlib_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy,
-                     _EGLSurface *surface, EGLint buffer)
-{
-   struct xlib_egl_surface *xsurf = lookup_surface(surface);
-   struct xlib_egl_context *xctx;
-   struct pipe_surface *psurf;
-   enum pipe_format format;
-   int target;
-
-   if (!xsurf || xsurf->Base.Type != EGL_PBUFFER_BIT)
-      return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
-   if (buffer != EGL_BACK_BUFFER)
-      return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage");
-   if (xsurf->Base.BoundToTexture)
-      return _eglError(EGL_BAD_ACCESS, "eglBindTexImage");
-
-   /* this should be updated when choose_color_format is */
-   switch (xsurf->Base.TextureFormat) {
-   case EGL_TEXTURE_RGB:
-      format = PIPE_FORMAT_R8G8B8_UNORM;
-      break;
-   case EGL_TEXTURE_RGBA:
-      format = PIPE_FORMAT_A8R8G8B8_UNORM;
-      break;
-   default:
-      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
-   }
-
-   switch (xsurf->Base.TextureTarget) {
-   case EGL_TEXTURE_2D:
-      target = ST_TEXTURE_2D;
-      break;
-   default:
-      return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
-   }
-
-   /* flush properly */
-   if (eglGetCurrentSurface(EGL_DRAW) == surface) {
-      xctx = lookup_context(_eglGetCurrentContext());
-      st_flush(xctx->Context, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME,
-               NULL);
-   }
-   else if (_eglIsSurfaceBound(&xsurf->Base)) {
-      xctx = lookup_context(xsurf->Base.Binding);
-      if (xctx)
-         st_finish(xctx->Context);
-   }
-
-   st_get_framebuffer_surface(xsurf->Framebuffer, ST_SURFACE_BACK_LEFT,
-                              &psurf);
-   st_bind_texture_surface(psurf, target, xsurf->Base.MipmapLevel, format);
-   xsurf->Base.BoundToTexture = EGL_TRUE;
-
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-xlib_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface,
-                        EGLint buffer)
-{
-   struct xlib_egl_surface *xsurf = lookup_surface(surface);
-   struct pipe_surface *psurf;
-
-   if (!xsurf || xsurf->Base.Type != EGL_PBUFFER_BIT ||
-       !xsurf->Base.BoundToTexture)
-      return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
-   if (buffer != EGL_BACK_BUFFER)
-      return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage");
-
-   st_get_framebuffer_surface(xsurf->Framebuffer, ST_SURFACE_BACK_LEFT,
-                              &psurf);
-   st_unbind_texture_surface(psurf, ST_TEXTURE_2D, xsurf->Base.MipmapLevel);
-   xsurf->Base.BoundToTexture = EGL_FALSE;
-
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-xlib_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
-{
-   struct xlib_egl_surface *xsurf = lookup_surface(draw);
-   struct pipe_winsys *pws = xsurf->winsys;
-   struct pipe_surface *psurf;
-
-   st_get_framebuffer_surface(xsurf->Framebuffer, ST_SURFACE_BACK_LEFT,
-         &psurf);
-
-   st_notify_swapbuffers(xsurf->Framebuffer);
-
-   display_surface(pws, psurf, xsurf);
-
-   check_and_update_buffer_size(xsurf);
-
-   return EGL_TRUE;
-}
-
-
-/**
- * Determine which API(s) is(are) present by looking for some specific
- * global symbols.
- */
-static EGLint
-find_supported_apis(void)
-{
-   EGLint mask = 0;
-   void *handle;
-
-   handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
-   if(!handle)
-      return mask;
-
-   if (dlsym(handle, "st_api_OpenGL_ES1"))
-      mask |= EGL_OPENGL_ES_BIT;
-
-   if (dlsym(handle, "st_api_OpenGL_ES2"))
-      mask |= EGL_OPENGL_ES2_BIT;
-
-   if (dlsym(handle, "st_api_OpenGL"))
-      mask |= EGL_OPENGL_BIT;
-
-   if (dlsym(handle, "st_api_OpenVG"))
-      mask |= EGL_OPENVG_BIT;
-
-   dlclose(handle);
-
-   return mask;
-}
-
-
-static void
-xlib_Unload(_EGLDriver *drv)
-{
-   struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
-   free(xdrv);
-}
-
-
-/**
- * This is the main entrypoint into the driver.
- * Called by libEGL to instantiate an _EGLDriver object.
- */
-_EGLDriver *
-_eglMain(const char *args)
-{
-   struct xlib_egl_driver *xdrv;
-
-   _eglLog(_EGL_INFO, "Entering EGL/Xlib _eglMain(%s)", args);
-
-   xdrv = CALLOC_STRUCT(xlib_egl_driver);
-   if (!xdrv)
-      return NULL;
-
-   _eglInitDriverFallbacks(&xdrv->Base);
-   xdrv->Base.API.Initialize = xlib_eglInitialize;
-   xdrv->Base.API.Terminate = xlib_eglTerminate;
-   xdrv->Base.API.GetProcAddress = xlib_eglGetProcAddress;
-   xdrv->Base.API.CreateContext = xlib_eglCreateContext;
-   xdrv->Base.API.DestroyContext = xlib_eglDestroyContext;
-   xdrv->Base.API.CreateWindowSurface = xlib_eglCreateWindowSurface;
-   xdrv->Base.API.CreatePbufferSurface = xlib_eglCreatePbufferSurface;
-   xdrv->Base.API.DestroySurface = xlib_eglDestroySurface;
-   xdrv->Base.API.BindTexImage = xlib_eglBindTexImage;
-   xdrv->Base.API.ReleaseTexImage = xlib_eglReleaseTexImage;
-   xdrv->Base.API.MakeCurrent = xlib_eglMakeCurrent;
-   xdrv->Base.API.SwapBuffers = xlib_eglSwapBuffers;
-
-   xdrv->apis = find_supported_apis();
-   if (xdrv->apis == 0x0) {
-      /* the app isn't directly linked with any EGL-supprted APIs
-       * (such as libGLESv2.so) so use an EGL utility to see what
-       * APIs might be loaded dynamically on this system.
-       */
-      xdrv->apis = _eglFindAPIs();
-   }
-
-   xdrv->Base.Name = "Xlib/softpipe";
-   xdrv->Base.Unload = xlib_Unload;
-
-   return &xdrv->Base;
-}
diff --git a/src/gallium/winsys/egl_xlib/sw_winsys.c b/src/gallium/winsys/egl_xlib/sw_winsys.c
deleted file mode 100644 (file)
index 6ee3ede..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-/**
- * Totally software-based winsys layer.
- * Note that the one winsys function that we can't implement here
- * is flush_frontbuffer().
- * Whoever uses this code will have to provide that.
- *
- * Authors: Brian Paul
- */
-
-
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "sw_winsys.h"
-
-
-
-/** Subclass of pipe_winsys */
-struct sw_pipe_winsys
-{
-   struct pipe_winsys Base;
-   /* no extra fields for now */
-};
-
-
-/** subclass of pipe_buffer */
-struct sw_pipe_buffer
-{
-   struct pipe_buffer Base;
-   boolean UserBuffer;  /** Is this a user-space buffer? */
-   void *Data;
-   void *Mapped;
-};
-
-
-/** cast wrapper */
-static INLINE struct sw_pipe_buffer *
-sw_pipe_buffer(struct pipe_buffer *b)
-{
-   return (struct sw_pipe_buffer *) b;
-}
-
-
-static const char *
-get_name(struct pipe_winsys *pws)
-{
-   return "software";
-}
-
-
-/** Create new pipe_buffer and allocate storage of given size */
-static struct pipe_buffer *
-buffer_create(struct pipe_winsys *pws, 
-              unsigned alignment, 
-              unsigned usage,
-              unsigned size)
-{
-   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
-   if (!buffer)
-      return NULL;
-
-   pipe_reference_init(&buffer->Base.reference, 1);
-   buffer->Base.alignment = alignment;
-   buffer->Base.usage = usage;
-   buffer->Base.size = size;
-
-   /* align to 16-byte multiple for Cell */
-   buffer->Data = align_malloc(size, MAX2(alignment, 16));
-
-   return &buffer->Base;
-}
-
-
-/**
- * Create buffer which wraps user-space data.
- */
-static struct pipe_buffer *
-user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
-{
-   struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
-   if (!buffer)
-      return NULL;
-
-   pipe_reference_init(&buffer->Base.reference, 1);
-   buffer->Base.size = bytes;
-   buffer->UserBuffer = TRUE;
-   buffer->Data = ptr;
-
-   return &buffer->Base;
-}
-
-
-static void *
-buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-   buffer->Mapped = buffer->Data;
-   return buffer->Mapped;
-}
-
-
-static void
-buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-   buffer->Mapped = NULL;
-}
-
-
-static void
-buffer_destroy(struct pipe_buffer *buf)
-{
-   struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-
-   if (buffer->Data && !buffer->UserBuffer) {
-      align_free(buffer->Data);
-      buffer->Data = NULL;
-   }
-
-   free(buffer);
-}
-
-
-static struct pipe_buffer *
-surface_buffer_create(struct pipe_winsys *winsys,
-                      unsigned width, unsigned height,
-                      enum pipe_format format, 
-                      unsigned usage,
-                      unsigned tex_usage,
-                      unsigned *stride)
-{
-   const unsigned alignment = 64;
-   unsigned nblocksy;
-
-   nblocksy = util_format_get_nblocksy(format, height);
-   *stride = align(util_format_get_stride(format, width), alignment);
-
-   return winsys->buffer_create(winsys, alignment,
-                                usage,
-                                *stride * nblocksy);
-}
-
-
-static void
-fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
-                struct pipe_fence_handle *fence)
-{
-   /* no-op */
-}
-
-
-static int
-fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-                unsigned flag)
-{
-   /* no-op */
-   return 0;
-}
-
-
-static int
-fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-             unsigned flag)
-{
-   /* no-op */
-   return 0;
-}
-
-
-/**
- * Create/return a new pipe_winsys object.
- */
-struct pipe_winsys *
-create_sw_winsys(void)
-{
-   struct sw_pipe_winsys *ws = CALLOC_STRUCT(sw_pipe_winsys);
-   if (!ws)
-      return NULL;
-
-   /* Fill in this struct with callbacks that pipe will need to
-    * communicate with the window system, buffer manager, etc. 
-    */
-   ws->Base.buffer_create = buffer_create;
-   ws->Base.user_buffer_create = user_buffer_create;
-   ws->Base.buffer_map = buffer_map;
-   ws->Base.buffer_unmap = buffer_unmap;
-   ws->Base.buffer_destroy = buffer_destroy;
-
-   ws->Base.surface_buffer_create = surface_buffer_create;
-
-   ws->Base.fence_reference = fence_reference;
-   ws->Base.fence_signalled = fence_signalled;
-   ws->Base.fence_finish = fence_finish;
-
-   ws->Base.flush_frontbuffer = NULL; /* not implemented here! */
-
-   ws->Base.get_name = get_name;
-
-   return &ws->Base;
-}
diff --git a/src/gallium/winsys/egl_xlib/sw_winsys.h b/src/gallium/winsys/egl_xlib/sw_winsys.h
deleted file mode 100644 (file)
index f96c5a1..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-
-#ifndef SW_WINSYS_H
-#define SW_WINSYS_H
-
-
-struct pipe_winsys;
-
-
-extern struct pipe_winsys *
-create_sw_winsys(void);
-
-
-#endif /* SW_WINSYS_H */
index f7c0099584e8f77cead739623b443007b81609c5..bf78aca6869fc9860fec4c5ed25c34792d9d468f 100644 (file)
@@ -63,7 +63,7 @@ struct xm_buffer
 
    XImage *tempImage;
 #ifdef USE_XSHM
-   int shm;
+   boolean shm;         /** Is this a shared memory buffer? */
    XShmSegmentInfo shminfo;
 #endif
 };
@@ -152,7 +152,7 @@ alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
                                   &b->shminfo,
                                   width, height);
    if (b->tempImage == NULL) {
-      b->shm = 0;
+      b->shm = FALSE;
       return;
    }
 
@@ -169,12 +169,12 @@ alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
       mesaXErrorFlag = 0;
       XDestroyImage(b->tempImage);
       b->tempImage = NULL;
-      b->shm = 0;
+      b->shm = FALSE;
       (void) XSetErrorHandler(old_handler);
       return;
    }
 
-   b->shm = 1;
+   b->shm = TRUE;
 }
 
 #endif /* USE_XSHM */
@@ -204,6 +204,14 @@ xm_buffer_destroy(struct pipe_buffer *buf)
 {
    struct xm_buffer *oldBuf = xm_buffer(buf);
 
+   /*
+    * Note oldBuf->data may point to one of three things:
+    * 1. XShm shared memory image data
+    * 2. User-provided (wrapped) memory, see xm_user_buffer_create()
+    * 3. Regular, malloc'd memory
+    * We need to be careful with freeing that data now.
+    */
+
    if (oldBuf->data) {
 #ifdef USE_XSHM
       if (oldBuf->shminfo.shmid >= 0) {
@@ -213,12 +221,20 @@ xm_buffer_destroy(struct pipe_buffer *buf)
          oldBuf->shminfo.shmid = -1;
          oldBuf->shminfo.shmaddr = (char *) -1;
       }
-      else
+
+      if (oldBuf->shm) {
+         oldBuf->data = NULL;
+      }
+
+      if (oldBuf->tempImage) {
+         XDestroyImage(oldBuf->tempImage);
+         oldBuf->tempImage = NULL;
+      }
 #endif
-      {
-         if (!oldBuf->userBuffer) {
-            align_free(oldBuf->data);
-         }
+
+      if (oldBuf->data && !oldBuf->userBuffer) {
+         /* this was regular malloc'd memory */
+         align_free(oldBuf->data);
       }
 
       oldBuf->data = NULL;
@@ -327,10 +343,8 @@ xm_buffer_create(struct pipe_winsys *pws,
    buffer->base.usage = usage;
    buffer->base.size = size;
 
-   if (buffer->data == NULL) {
-      /* align to 16-byte multiple for Cell */
-      buffer->data = align_malloc(size, max(alignment, 16));
-   }
+   /* align to 16-byte multiple for Cell */
+   buffer->data = align_malloc(size, max(alignment, 16));
 
    return &buffer->base;
 }
index fae1bd9fa629434e69f15266f3279af3f7731a9d..50de7d612b8b6aaaafbe61eefc15e6f50531bae5 100644 (file)
@@ -162,6 +162,7 @@ __glXSetCurrentContextNull(void)
    __glXSetCurrentContext(&dummyContext);
 #ifdef GLX_DIRECT_RENDERING
    _glapi_set_dispatch(NULL);   /* no-op functions */
+   _glapi_set_context(NULL);
 #endif
 }
 
index bdcfffed4baf49e18c566e8af4e10f5f0c90babf..ea5bad2825a040d7ae720bc4737c50dff92a47a4 100644 (file)
@@ -251,6 +251,7 @@ if env['platform'] != 'winddk':
                'main/dispatch.c',
                'glapi/glapi.c',
                'glapi/glapi_getproc.c',
+               'glapi/glapi_nop.c',
                'glapi/glthread.c',
        ]
        
index 447f3d15b9516c2c7aca30f47beb68caaf6bde76..c15222690222946417698078139aa611d1535081 100644 (file)
 #  define READ_RGBA( rgba, _x, _y )                                    \
      do {                                                              \
         GLuint p = GET_VALUE(_x, _y);                                  \
-        *((uint32_t *) rgba) = (t << 8) | 0xff;                                \
+        *((uint32_t *) rgba) = (p << 8) | 0xff;                                \
      } while (0)
 # else
 #  define READ_RGBA( rgba, _x, _y )                                    \
index cf9b3a85563548f2cb621b8053cb82b22e2c0cff..848e2041e27dc9e1bbadb5e1262641f9e24690a4 100644 (file)
@@ -5,9 +5,6 @@ include $(TOP)/configs/current
 
 LIBNAME = fb_dri.so
 
-ifeq ($(USING_EGL), 1)
-EGL_SOURCES = server/radeon_egl.c
-endif
 
 DRIVER_SOURCES = \
        fb_dri.c \
diff --git a/src/mesa/drivers/dri/fb/fb_egl.c b/src/mesa/drivers/dri/fb/fb_egl.c
deleted file mode 100644 (file)
index 02e44bb..0000000
+++ /dev/null
@@ -1,881 +0,0 @@
-/*
- * Test egl driver for fb_dri.so
- */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h> 
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <linux/fb.h>
-
-#include "utils.h"
-#include "buffers.h"
-#include "main/extensions.h"
-#include "main/framebuffer.h"
-#include "main/renderbuffer.h"
-#include "vbo/vbo.h"
-#include "swrast/swrast.h"
-#include "swrast_setup/swrast_setup.h"
-#include "tnl/tnl.h"
-#include "tnl/tcontext.h"
-#include "tnl/t_pipeline.h"
-#include "drivers/common/driverfuncs.h"
-#include "drirenderbuffer.h"
-
-#include "eglconfig.h"
-#include "eglmain/context.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglglobals.h"
-#include "eglmode.h"
-#include "eglscreen.h"
-#include "eglsurface.h"
-
-extern void
-fbSetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis);
-
-/**
- * fb driver-specific driver class derived from _EGLDriver
- */
-typedef struct fb_driver
-{
-   _EGLDriver Base;  /* base class/object */
-   GLuint fbStuff;
-} fbDriver;
-
-/**
- * fb display-specific driver class derived from _EGLDisplay
- */
-typedef struct fb_display
-{
-   _EGLDisplay Base;  /* base class/object */
-   void *pFB;
-} fbDisplay;
-
-/**
- * fb driver-specific screen class derived from _EGLScreen
- */
-typedef struct fb_screen
-{
-   _EGLScreen Base;
-   char fb[NAME_MAX];
-} fbScreen;
-
-
-/**
- * fb driver-specific surface class derived from _EGLSurface
- */
-typedef struct fb_surface
-{
-   _EGLSurface Base;  /* base class/object */
-   struct gl_framebuffer *mesa_framebuffer;
-} fbSurface;
-
-
-/**
- * fb driver-specific context class derived from _EGLContext
- */
-typedef struct fb_context
-{
-   _EGLContext Base;  /* base class/object */
-   GLcontext *glCtx;
-   struct {
-      __DRIcontext *context;   
-      __DRIscreen *screen;     
-      __DRIdrawable *drawable; /* drawable bound to this ctx */
-   } dri;
-} fbContext, *fbContextPtr;
-
-#define FB_CONTEXT(ctx)                ((fbContextPtr)(ctx->DriverCtx))
-
-
-static EGLBoolean
-fbFillInConfigs(_EGLDisplay *disp, unsigned pixel_bits, unsigned depth_bits,
-               unsigned stencil_bits, GLboolean have_back_buffer) {
-   _EGLConfig *configs;
-   _EGLConfig *c;
-   unsigned int i, num_configs;
-   unsigned int depth_buffer_factor;
-   unsigned int back_buffer_factor;
-   GLenum fb_format;
-   GLenum fb_type;
-
-   /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
-   * enough to add support.  Basically, if a context is created with an
-   * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
-   * will never be used.
-   */
-   static const GLenum back_buffer_modes[] = {
-            GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
-         };
-
-   uint8_t depth_bits_array[2];
-   uint8_t stencil_bits_array[2];
-
-   depth_bits_array[0] = 0;
-   depth_bits_array[1] = depth_bits;
-
-   /* Just like with the accumulation buffer, always provide some modes
-   * with a stencil buffer.  It will be a sw fallback, but some apps won't
-   * care about that.
-   */
-   stencil_bits_array[0] = 0;
-   stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
-
-   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
-   back_buffer_factor = (have_back_buffer) ? 2 : 1;
-
-   num_configs = depth_buffer_factor * back_buffer_factor * 2;
-
-   if (pixel_bits == 16) {
-      fb_format = GL_RGB;
-      fb_type = GL_UNSIGNED_SHORT_5_6_5;
-   } else {
-      fb_format = GL_RGBA;
-      fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-   }
-
-   configs = calloc(sizeof(*configs), num_configs);
-   c = configs;
-   if (!_eglFillInConfigs(c, fb_format, fb_type,
-                          depth_bits_array, stencil_bits_array, depth_buffer_factor,
-                          back_buffer_modes, back_buffer_factor,
-                          GLX_TRUE_COLOR)) {
-      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n",
-               __func__, __LINE__);
-      return EGL_FALSE;
-   }
-
-   /* Mark the visual as slow if there are "fake" stencil bits.
-   */
-   for (i = 0, c = configs; i < num_configs; i++, c++) {
-      int stencil = GET_CONFIG_ATTRIB(c, EGL_STENCIL_SIZE);
-      if ((stencil != 0)  && (stencil != stencil_bits)) {
-         SET_CONFIG_ATTRIB(c, EGL_CONFIG_CAVEAT, EGL_SLOW_CONFIG);
-      }
-   }
-
-   for (i = 0, c = configs; i < num_configs; i++, c++)
-      _eglAddConfig(disp, c);
-      
-   free(configs);
-   
-   return EGL_TRUE;
-}
-
-static EGLBoolean
-fbSetupFramebuffer(fbDisplay *disp, char *fbdev) 
-{
-   int fd;
-   char dev[20];
-   struct fb_var_screeninfo varInfo;
-   struct fb_fix_screeninfo fixedInfo;
-   
-   snprintf(dev, sizeof(dev), "/dev/%s", fbdev);
-
-   /* open the framebuffer device */
-   fd = open(dev, O_RDWR);
-   if (fd < 0) {
-      fprintf(stderr, "Error opening %s: %s\n", fbdev, strerror(errno));
-      return EGL_FALSE;
-   }
-
-   /* get the original variable screen info */
-   if (ioctl(fd, FBIOGET_VSCREENINFO, &varInfo)) {
-      fprintf(stderr, "error: ioctl(FBIOGET_VSCREENINFO) failed: %s\n",
-               strerror(errno));
-      return EGL_FALSE;
-   }
-
-   /* Turn off hw accels (otherwise mmap of mmio region will be
-    * refused)
-    */
-   if (varInfo.accel_flags) {
-      varInfo.accel_flags = 0;
-      if (ioctl(fd, FBIOPUT_VSCREENINFO, &varInfo)) {
-         fprintf(stderr, "error: ioctl(FBIOPUT_VSCREENINFO) failed: %s\n",
-                  strerror(errno));
-         return EGL_FALSE;
-      }
-   }
-
-   /* Get the fixed screen info */
-   if (ioctl(fd, FBIOGET_FSCREENINFO, &fixedInfo)) {
-      fprintf(stderr, "error: ioctl(FBIOGET_FSCREENINFO) failed: %s\n",
-               strerror(errno));
-      return EGL_FALSE;
-   }
-   
-   if (fixedInfo.visual == FB_VISUAL_DIRECTCOLOR) {
-      struct fb_cmap cmap;
-      unsigned short red[256], green[256], blue[256];
-      int rcols = 1 << varInfo.red.length;
-      int gcols = 1 << varInfo.green.length;
-      int bcols = 1 << varInfo.blue.length;
-      int i;
-
-      cmap.start = 0;      
-      cmap.len = gcols;
-      cmap.red   = red;
-      cmap.green = green;
-      cmap.blue  = blue;
-      cmap.transp = NULL;
-
-      for (i = 0; i < rcols ; i++) 
-         red[i] = (65536/(rcols-1)) * i;
-
-      for (i = 0; i < gcols ; i++) 
-         green[i] = (65536/(gcols-1)) * i;
-
-      for (i = 0; i < bcols ; i++) 
-         blue[i] = (65536/(bcols-1)) * i;
-      
-      if (ioctl(fd, FBIOPUTCMAP, (void *) &cmap) < 0) {
-         fprintf(stderr, "ioctl(FBIOPUTCMAP) failed [%d]\n", i);
-         exit(1);
-      }
-   }
-
-   /* mmap the framebuffer into our address space */
-   if (!disp->pFB)
-      disp->pFB = (caddr_t)mmap(0,  /* start */
-                      fixedInfo.smem_len,  /* bytes */
-                      PROT_READ | PROT_WRITE,  /* prot */
-                      MAP_SHARED,  /* flags */
-                      fd,  /* fd */
-                      0); /* offset */ 
-   if (disp->pFB == (caddr_t)-1) {
-      fprintf(stderr, "error: unable to mmap framebuffer: %s\n",
-               strerror(errno));
-      return EGL_FALSE;
-   }
-   
-   return EGL_TRUE;
-}
-   
-const char *sysfs = "/sys/class/graphics";
-
-static EGLBoolean
-fbInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor)
-{
-   _EGLDisplay *disp = _eglLookupDisplay(dpy);
-   fbDisplay *display;
-   fbScreen *s;
-   _EGLScreen *scrn;
-   char c;
-   unsigned int x, y, r;
-   DIR *dir;
-   FILE *file;
-   struct dirent *dirent;
-   char path[NAME_MAX];
-   
-   /* Switch display structure to one with our private fields */
-   display = calloc(1, sizeof(*display));
-   display->Base = *disp;
-   _eglHashInsert(_eglGlobal.Displays, disp->Handle, display);
-   free(disp);
-   
-   *major = 1;
-   *minor = 0;
-   
-   dir = opendir(sysfs);
-   if (!dir) {
-      printf("EGL - %s framebuffer device not found.", sysfs);
-      return EGL_FALSE;
-   }
-   
-   while ((dirent = readdir(dir))) {  /* assignment! */
-      
-      if (dirent->d_name[0] != 'f')
-         continue;
-      if (dirent->d_name[1] != 'b')
-         continue;
-   
-      if (fbSetupFramebuffer(display, dirent->d_name) == EGL_FALSE)
-         continue;
-         
-      /* Create a screen */
-      s = (fbScreen *) calloc(1, sizeof(fbScreen));
-      if (!s)
-         return EGL_FALSE;
-
-      strncpy(s->fb, dirent->d_name, NAME_MAX);
-      scrn = &s->Base;
-      _eglInitScreen(scrn);
-      _eglAddScreen(&display->Base, scrn);
-      
-      snprintf(path, sizeof(path), "%s/%s/modes", sysfs, s->fb);
-      file = fopen(path, "r");
-      while (fgets(path, sizeof(path), file)) {
-         sscanf(path, "%c:%ux%u-%u", &c, &x, &y, &r);
-         _eglAddMode(scrn, x, y, r * 1000, path);
-      }
-      fclose(file);
-
-      fbFillInConfigs(&display->Base, 32, 24, 8, 1);
-      
-   }
-   closedir(dir);
-
-   drv->Initialized = EGL_TRUE;
-   return EGL_TRUE;
-}
-
-
-static fbDisplay *
-Lookup_fbDisplay(EGLDisplay dpy)
-{
-   _EGLDisplay *d = _eglLookupDisplay(dpy);
-   return (fbDisplay *) d;
-}
-
-
-static fbScreen *
-Lookup_fbScreen(EGLDisplay dpy, EGLScreenMESA screen)
-{
-   _EGLScreen *s = _eglLookupScreen(dpy, screen);
-   return (fbScreen *) s;
-}
-
-
-static fbContext *
-Lookup_fbContext(EGLContext ctx)
-{
-   _EGLContext *c = _eglLookupContext(ctx);
-   return (fbContext *) c;
-}
-
-
-static fbSurface *
-Lookup_fbSurface(EGLSurface surf)
-{
-   _EGLSurface *s = _eglLookupSurface(surf);
-   return (fbSurface *) s;
-}
-
-
-static EGLBoolean
-fbTerminate(_EGLDriver *drv, EGLDisplay dpy)
-{
-   fbDisplay *display = Lookup_fbDisplay(dpy);
-   _eglCleanupDisplay(&display->Base);
-   free(display);
-   free(drv);
-   return EGL_TRUE;
-}
-
-
-static const GLubyte *
-get_string(GLcontext *ctx, GLenum pname)
-{
-   (void) ctx;
-   switch (pname) {
-      case GL_RENDERER:
-         return (const GLubyte *) "Mesa dumb framebuffer";
-      default:
-         return NULL;
-   }
-}
-
-
-static void
-update_state( GLcontext *ctx, GLuint new_state )
-{
-   /* not much to do here - pass it on */
-   _swrast_InvalidateState( ctx, new_state );
-   _swsetup_InvalidateState( ctx, new_state );
-   _vbo_InvalidateState( ctx, new_state );
-   _tnl_InvalidateState( ctx, new_state );
-}
-
-
-/**
- * Called by ctx->Driver.GetBufferSize from in core Mesa to query the
- * current framebuffer size.
- */
-static void
-get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
-{
-   *width  = buffer->Width;
-   *height = buffer->Height;
-}
-
-
-static void
-updateFramebufferSize(GLcontext *ctx)
-{
-   fbContextPtr fbmesa = FB_CONTEXT(ctx);
-   struct gl_framebuffer *fb = ctx->WinSysDrawBuffer;
-   if (fbmesa->dri.drawable->w != fb->Width ||
-       fbmesa->dri.drawable->h != fb->Height) {
-      driUpdateFramebufferSize(ctx, fbmesa->dri.drawable);
-   }
-}
-
-static void
-viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
-{
-   /* XXX this should be called after we acquire the DRI lock, not here */
-   updateFramebufferSize(ctx);
-}
-
-
-static void
-init_core_functions( struct dd_function_table *functions )
-{
-   functions->GetString = get_string;
-   functions->UpdateState = update_state;
-   functions->GetBufferSize = get_buffer_size;
-   functions->Viewport = viewport;
-
-   functions->Clear = _swrast_Clear;  /* could accelerate with blits */
-}
-
-
-static EGLContext
-fbCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list)
-{
-   GLcontext *ctx;
-   _EGLConfig *conf;
-   fbContext *c;
-   _EGLDisplay *disp = _eglLookupDisplay(dpy);
-   struct dd_function_table functions;
-   GLvisual vis;
-   int i;
-
-   conf = _eglLookupConfig(drv, dpy, config);
-   if (!conf) {
-      _eglError(EGL_BAD_CONFIG, "eglCreateContext");
-      return EGL_NO_CONTEXT;
-   }
-
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs defined for now */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext");
-         return EGL_NO_CONTEXT;
-      }
-   }
-
-   c = (fbContext *) calloc(1, sizeof(fbContext));
-   if (!c)
-      return EGL_NO_CONTEXT;
-
-   _eglInitContext(&c->Base);
-   c->Base.Display = disp;
-   c->Base.Config = conf;
-   c->Base.DrawSurface = EGL_NO_SURFACE;
-   c->Base.ReadSurface = EGL_NO_SURFACE;
-
-   /* link to display */
-   _eglLinkContext(&c->Base, disp);
-   assert(c->Base.Handle);
-
-   /* Init default driver functions then plug in our FBdev-specific functions
-    */
-   _mesa_init_driver_functions(&functions);
-   init_core_functions(&functions);
-
-   _eglConfigToContextModesRec(conf, &vis);
-
-   ctx = c->glCtx = _mesa_create_context(&vis, NULL, &functions, (void *)c);
-   if (!c->glCtx) {
-      _mesa_free(c);
-      return GL_FALSE;
-   }
-
-   /* Create module contexts */
-   _swrast_CreateContext( ctx );
-   _vbo_CreateContext( ctx );
-   _tnl_CreateContext( ctx );
-   _swsetup_CreateContext( ctx );
-   _swsetup_Wakeup( ctx );
-
-
-   /* use default TCL pipeline */
-   {
-      TNLcontext *tnl = TNL_CONTEXT(ctx);
-      tnl->Driver.RunPipeline = _tnl_run_pipeline;
-   }
-
-   _mesa_enable_sw_extensions(ctx);
-
-   return c->Base.Handle;
-}
-
-
-static EGLSurface
-fbCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list)
-{
-   int i;
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs at this time */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreateWindowSurface");
-         return EGL_NO_SURFACE;
-      }
-   }
-   printf("eglCreateWindowSurface()\n");
-   /* XXX unfinished */
-
-   return EGL_NO_SURFACE;
-}
-
-
-static EGLSurface
-fbCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list)
-{
-   _EGLConfig *conf;
-   EGLint i;
-
-   conf = _eglLookupConfig(drv, dpy, config);
-   if (!conf) {
-      _eglError(EGL_BAD_CONFIG, "eglCreatePixmapSurface");
-      return EGL_NO_SURFACE;
-   }
-
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-         /* no attribs at this time */
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface");
-         return EGL_NO_SURFACE;
-      }
-   }
-
-   if (conf->Attrib[EGL_SURFACE_TYPE - FIRST_ATTRIB] == 0) {
-      _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface");
-      return EGL_NO_SURFACE;
-   }
-
-   printf("eglCreatePixmapSurface()\n");
-   return EGL_NO_SURFACE;
-}
-
-
-static EGLSurface
-fbCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
-{
-   fbSurface *surf;
-
-   surf = (fbSurface *) calloc(1, sizeof(fbSurface));
-   if (!surf) {
-      return EGL_NO_SURFACE;
-   }
-
-   if (_eglInitPbufferSurface(&surf->Base, drv, dpy, config, attrib_list) == EGL_NO_SURFACE) {
-      free(surf);
-      return EGL_NO_SURFACE;
-   }
-
-   /* create software-based pbuffer */
-   {
-      GLcontext *ctx = NULL; /* this _should_ be OK */
-      GLvisual vis;
-      _EGLConfig *conf = _eglLookupConfig(drv, dpy, config);
-      assert(conf); /* bad config should be caught earlier */
-      _eglConfigToContextModesRec(conf, &vis);
-
-      surf->mesa_framebuffer = _mesa_create_framebuffer(&vis);
-      _mesa_add_soft_renderbuffers(surf->mesa_framebuffer,
-                                   GL_TRUE, /* color bufs */
-                                   vis.haveDepthBuffer,
-                                   vis.haveStencilBuffer,
-                                   vis.haveAccumBuffer,
-                                   GL_FALSE, /* alpha */
-                                   GL_FALSE /* aux */ );
-
-      /* set pbuffer/framebuffer size */
-      _mesa_resize_framebuffer(ctx, surf->mesa_framebuffer,
-                               surf->Base.Width, surf->Base.Height);
-   }
-
-   return surf->Base.Handle;
-}
-
-
-static EGLBoolean
-fbDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface)
-{
-   fbSurface *fs = Lookup_fbSurface(surface);
-   _eglUnlinkSurface(&fs->Base);
-   if (!_eglIsSurfaceBound(&fs->Base))
-      free(fs);
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-fbDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context)
-{
-   fbContext *fc = Lookup_fbContext(context);
-   _eglUnlinkContext(&fc->Base);
-   if (!_eglIsContextBound(&fc->Base))
-      free(fc);
-   return EGL_TRUE;
-}
-
-
-static EGLBoolean
-fbMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context)
-{
-   fbSurface *readSurf = Lookup_fbSurface(read);
-   fbSurface *drawSurf = Lookup_fbSurface(draw);
-   fbContext *ctx = Lookup_fbContext(context);
-   EGLBoolean b;
-
-   b = _eglMakeCurrent(drv, dpy, draw, read, context);
-   if (!b)
-      return EGL_FALSE;
-
-   if (ctx) {
-      _mesa_make_current( ctx->glCtx, 
-                           drawSurf->mesa_framebuffer,
-                           readSurf->mesa_framebuffer);
-   } else
-      _mesa_make_current( NULL, NULL, NULL );
-
-   return EGL_TRUE;
-}
-
-
-/**
- * Create a drawing surface which can be directly displayed on a screen.
- */
-static EGLSurface
-fbCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg,
-                          const EGLint *attrib_list)
-{
-   _EGLConfig *config = _eglLookupConfig(drv, dpy, cfg);
-   fbDisplay *display = Lookup_fbDisplay(dpy);
-   fbSurface *surface;
-   EGLSurface surf;
-   GLvisual vis;
-   GLcontext *ctx = NULL; /* this should be OK */
-   int origin, bytesPerPixel;
-   int width, height, stride;
-   
-   surface = (fbSurface *) malloc(sizeof(*surface));
-   if (!surface) {
-      return EGL_NO_SURFACE;
-   }
-
-   /* init base class, error check, etc. */
-   surf = _eglInitScreenSurface(&surface->Base, drv, dpy, cfg, attrib_list);
-   if (surf == EGL_NO_SURFACE) {
-      free(surface);
-      return EGL_NO_SURFACE;
-   }
-
-   /* convert EGLConfig to GLvisual */
-   _eglConfigToContextModesRec(config, &vis);
-
-   /* create Mesa framebuffer */
-   surface->mesa_framebuffer = _mesa_create_framebuffer(&vis);
-   if (!surface->mesa_framebuffer) {
-      free(surface);
-      _eglUnlinkSurface(&surface->Base);
-      return EGL_NO_SURFACE;
-   }
-
-   width = surface->Base.Width;
-   height = surface->Base.Height;
-   bytesPerPixel = vis.rgbBits / 8;
-   stride = width * bytesPerPixel;
-   origin = 0;
-
-   /* front color renderbuffer */
-   {
-      driRenderbuffer *drb = driNewRenderbuffer(MESA_FORMAT_ARGB8888, display->pFB,
-                                                bytesPerPixel,
-                                                origin, stride, NULL);
-      fbSetSpanFunctions(drb, &vis);
-      _mesa_add_renderbuffer(surface->mesa_framebuffer,
-                             BUFFER_FRONT_LEFT, &drb->Base);
-   }
-
-   /* back color renderbuffer */
-   if (vis.doubleBufferMode) {
-      GLubyte *backBuf = _mesa_malloc(stride * height);
-      driRenderbuffer *drb = driNewRenderbuffer(MESA_FORMAT_ARGB8888, backBuf,
-                                                bytesPerPixel,
-                                                origin, stride, NULL);
-      fbSetSpanFunctions(drb, &vis);
-      _mesa_add_renderbuffer(surface->mesa_framebuffer,
-                             BUFFER_BACK_LEFT, &drb->Base);
-   }
-
-   /* other renderbuffers- software based */
-   _mesa_add_soft_renderbuffers(surface->mesa_framebuffer,
-                                GL_FALSE, /* color */
-                                vis.haveDepthBuffer,
-                                vis.haveStencilBuffer,
-                                vis.haveAccumBuffer,
-                                GL_FALSE, /* alpha */
-                                GL_FALSE /* aux */);
-   
-   _mesa_resize_framebuffer(ctx, surface->mesa_framebuffer, width, height);
-
-   return surf;
-}
-
-
-/**
- * Show the given surface on the named screen.
- * If surface is EGL_NO_SURFACE, disable the screen's output.
- */
-static EGLBoolean
-fbShowSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
-                    EGLSurface surface, EGLModeMESA m)
-{
-   fbDisplay *display = Lookup_fbDisplay(dpy);
-   fbScreen *scrn = Lookup_fbScreen(dpy, screen);
-   fbSurface *surf = Lookup_fbSurface(surface);
-   FILE *file;
-   char buffer[NAME_MAX];
-   _EGLMode *mode = _eglLookupMode(dpy, m);
-   int bits;
-   
-   if (!_eglShowSurfaceMESA(drv, dpy, screen, surface, m))
-      return EGL_FALSE;
-      
-   snprintf(buffer, sizeof(buffer), "%s/%s/blank", sysfs, scrn->fb);
-   
-   file = fopen(buffer, "r+");
-   if (!file) {
-err:
-      printf("chown all fb sysfs attrib to allow write - %s\n", buffer);
-      return EGL_FALSE;
-   }
-   snprintf(buffer, sizeof(buffer), "%d", (m == EGL_NO_MODE_MESA ? VESA_POWERDOWN : VESA_VSYNC_SUSPEND));
-   fputs(buffer, file);
-   fclose(file);
-   
-   if (m == EGL_NO_MODE_MESA)
-      return EGL_TRUE;
-   
-   snprintf(buffer, sizeof(buffer), "%s/%s/mode", sysfs, scrn->fb);
-   
-   file = fopen(buffer, "r+");
-   if (!file)
-      goto err;
-   fputs(mode->Name, file);
-   fclose(file);
-   
-   snprintf(buffer, sizeof(buffer), "%s/%s/bits_per_pixel", sysfs, scrn->fb);
-   
-   file = fopen(buffer, "r+");
-   if (!file)
-      goto err;
-   bits = GET_CONFIG_ATTRIB(surf->Base.Config, EGL_BUFFER_SIZE);
-   snprintf(buffer, sizeof(buffer), "%d", bits);
-   fputs(buffer, file);
-   fclose(file);
-
-   fbSetupFramebuffer(display, scrn->fb);
-   
-   snprintf(buffer, sizeof(buffer), "%s/%s/blank", sysfs, scrn->fb);
-   
-   file = fopen(buffer, "r+");
-   if (!file)
-      goto err;
-      
-   snprintf(buffer, sizeof(buffer), "%d", VESA_NO_BLANKING);
-   fputs(buffer, file);
-   fclose(file);
-   
-   return EGL_TRUE;
-}
-
-
-/* If the backbuffer is on a videocard, this is extraordinarily slow!
- */
-static EGLBoolean
-fbSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw)
-{
-   fbContext *context = (fbContext *)_eglGetCurrentContext();
-   fbSurface *fs =  Lookup_fbSurface(draw);
-   struct gl_renderbuffer * front_renderbuffer = fs->mesa_framebuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
-   void *frontBuffer = front_renderbuffer->Data;
-   int currentPitch = ((driRenderbuffer *)front_renderbuffer)->pitch;
-   void *backBuffer = fs->mesa_framebuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer->Data;
-
-   if (!_eglSwapBuffers(drv, dpy, draw))
-      return EGL_FALSE;
-
-   if (context) {
-      GLcontext *ctx = context->glCtx;
-      
-      if (ctx->Visual.doubleBufferMode) {
-        int i;
-        int offset = 0;
-         char *tmp = _mesa_malloc(currentPitch);
-
-         _mesa_notifySwapBuffers( ctx );  /* flush pending rendering comands */
-
-         ASSERT(frontBuffer);
-         ASSERT(backBuffer);
-
-        for (i = 0; i < fs->Base.Height; i++) {
-            _mesa_memcpy(tmp, (char *) backBuffer + offset,
-                         currentPitch);
-            _mesa_memcpy((char *) frontBuffer + offset, tmp,
-                          currentPitch);
-            offset += currentPitch;
-        }
-           
-        _mesa_free(tmp);
-      }
-   }
-   else {
-      /* XXX this shouldn't be an error but we can't handle it for now */
-      _mesa_problem(NULL, "fbSwapBuffers: drawable has no context!\n");
-      return EGL_FALSE;
-   }
-   return EGL_TRUE;
-}
-
-
-/**
- * The bootstrap function.  Return a new fbDriver object and
- * plug in API functions.
- */
-_EGLDriver *
-_eglMain(_EGLDisplay *dpy)
-{
-   fbDriver *fb;
-
-   fb = (fbDriver *) calloc(1, sizeof(fbDriver));
-   if (!fb) {
-      return NULL;
-   }
-
-   /* First fill in the dispatch table with defaults */
-   _eglInitDriverFallbacks(&fb->Base);
-   
-   /* then plug in our fb-specific functions */
-   fb->Base.Initialize = fbInitialize;
-   fb->Base.Terminate = fbTerminate;
-   fb->Base.CreateContext = fbCreateContext;
-   fb->Base.MakeCurrent = fbMakeCurrent;
-   fb->Base.CreateWindowSurface = fbCreateWindowSurface;
-   fb->Base.CreatePixmapSurface = fbCreatePixmapSurface;
-   fb->Base.CreatePbufferSurface = fbCreatePbufferSurface;
-   fb->Base.DestroySurface = fbDestroySurface;
-   fb->Base.DestroyContext = fbDestroyContext;
-   fb->Base.CreateScreenSurfaceMESA = fbCreateScreenSurfaceMESA;
-   fb->Base.ShowSurfaceMESA = fbShowSurfaceMESA;
-   fb->Base.SwapBuffers = fbSwapBuffers;
-   
-   /* enable supported extensions */
-   fb->Base.MESA_screen_surface = EGL_TRUE;
-   fb->Base.MESA_copy_context = EGL_TRUE;
-
-   return &fb->Base;
-}
index 611afddfaf5c229d147b76800973964a09d49c54..b71a552c9dc6a0f6eafb23e385976dca0fec96c0 100644 (file)
@@ -30,7 +30,6 @@
 #include "ffb_lock.h"
 #include "ffb_bitmap.h"
 #include "swrast/swrast.h"
-#include "main/image.h"
 #include "main/macros.h"
 
 /* Compute ceiling of integer quotient of A divided by B: */
index dfe60f36f2b760f3ec1ba01d3557ea405190bacf..aa3fa0a86c5961d894b81e858a117c1965a1e1e8 100644 (file)
  */
 
 #include "main/mtypes.h"
-#include "main/extensions.h"
 
 #include "main/mm.h"
 #include "ffb_dd.h"
 #include "ffb_span.h"
-#include "ffb_depth.h"
 #include "ffb_context.h"
 #include "ffb_vb.h"
-#include "ffb_tris.h"
 #include "ffb_clear.h"
 #include "ffb_lock.h"
 
index cf83b91f0d472b288e12f95e597374f093b55413..91b6d3153af86a9bb8932fffe3a14f37b482ee52 100644 (file)
 
 #include "main/mtypes.h"
 #include "main/mm.h"
-#include "main/extensions.h"
 #include "ffb_dd.h"
 #include "ffb_span.h"
-#include "ffb_depth.h"
 #include "ffb_context.h"
-#include "ffb_vb.h"
-#include "ffb_tris.h"
 #include "ffb_clear.h"
 #include "ffb_lock.h"
 
index 5d509ff69630bd4df3164570e78a313ef25d196c..d19385b776bc03bc46e1ae9c9e1f0cfa2b50ef2d 100644 (file)
@@ -26,7 +26,6 @@
  */
 
 #include "main/mtypes.h"
-#include "swrast/swrast.h"
 #include "ffb_dd.h"
 #include "ffb_span.h"
 #include "ffb_context.h"
index 19dff50935464b67f8c6d793bf0471d02a8b66d0..6dca4edd29bc3754ddb8285ef8e8c46c9e1cf589 100644 (file)
 
 #include "main/mtypes.h"
 #include "main/mm.h"
-#include "main/extensions.h"
 #include "ffb_dd.h"
 #include "ffb_span.h"
-#include "ffb_depth.h"
 #include "ffb_context.h"
 #include "ffb_vb.h"
 #include "ffb_lines.h"
-#include "ffb_tris.h"
-#include "ffb_lock.h"
 
 #undef FFB_LINE_TRACE
 
index 9c37a47aeb97b3fb0fa54a2800a87eb0e730c146..5bf4f8f070777a1e7c76f0f350b7a8ee755f4615 100644 (file)
@@ -30,8 +30,6 @@
 #include "ffb_context.h"
 #include "ffb_vb.h"
 #include "ffb_points.h"
-#include "ffb_tris.h"
-#include "ffb_lock.h"
 
 
 #undef FFB_POINT_TRACE
index 8ec33a11bc607adfb92c79f8374ed334ca68b06f..61901cccadd55e5c86fd944d98c830097f7632fa 100644 (file)
@@ -31,8 +31,6 @@
 #include "ffb_context.h"
 #include "ffb_lock.h"
 
-#include "swrast/swrast.h"
-
 #define DBG 0
 
 #define HW_LOCK()                                              \
index 6f8a46d1fc798bad16cd2d596bed09f90f5d6244..c09d2fef838df252fd5168f2663c006534776667 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "main/mtypes.h"
 #include "main/colormac.h"
-#include "main/mm.h"
-#include "main/extensions.h"
 #include "main/enums.h"
 
 #include "vbo/vbo.h"
 
 #include "ffb_dd.h"
 #include "ffb_span.h"
-#include "ffb_depth.h"
 #include "ffb_context.h"
-#include "ffb_vb.h"
 #include "ffb_tris.h"
 #include "ffb_state.h"
-#include "ffb_lock.h"
 
 #undef STATE_TRACE
 
index ce8ef43c91e159195e57d84808809224c6bb7a9d..10cdfbc616ecdc279f0ae720a97820b8c8d61d0f 100644 (file)
@@ -32,8 +32,6 @@
 #include "ffb_stencil.h"
 #include "ffb_lock.h"
 
-#include "swrast/swrast.h"
-
 #undef STENCIL_TRACE
 
 static void FFBWriteStencilSpan( GLcontext *ctx,
index f9c6fd1f310b5f49464aa17247668e9be5954e40..ca8ffb27219881f2d6f7db6fed69e4bb6536e345 100644 (file)
@@ -30,8 +30,6 @@
 #include "ffb_vb.h"
 #include "main/imports.h"
 #include "tnl/t_context.h"
-#include "swrast_setup/swrast_setup.h"
-#include "math/m_translate.h"
 
 #undef VB_DEBUG
 
index 88285f454e9f726ba7c01c87c1e5f6f139df0470..6a84651479519751b96e0f019ea82a51932e98cb 100644 (file)
@@ -28,7 +28,6 @@
 #include "ffb_xmesa.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
-#include "main/matrix.h"
 #include "main/renderbuffer.h"
 #include "main/simple_list.h"
 #include "main/imports.h"
@@ -52,7 +51,6 @@
 #include "ffb_lines.h"
 #include "ffb_points.h"
 #include "ffb_state.h"
-#include "ffb_tex.h"
 #include "ffb_lock.h"
 #include "ffb_vtxfmt.h"
 #include "ffb_bitmap.h"
index bd9cfe5c0f75127637f35e5ba4f2583918868d4d..34e34606b4b34e4d15d2cdc9c3a9066349e67726 100644 (file)
@@ -34,10 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "main/glheader.h"
 #include "main/context.h"
-#include "main/matrix.h"
 #include "main/simple_list.h"
-#include "main/extensions.h"
-#include "main/framebuffer.h"
 #include "main/imports.h"
 #include "main/points.h"
 
index 1d98e006885869fafde788a3563115ab0b9c75ee..b543d4f012cca782389de4e914ed42a06b298619 100644 (file)
@@ -44,7 +44,6 @@
 
 #include "i810context.h"
 #include "i810tris.h"
-#include "i810state.h"
 #include "i810vb.h"
 #include "i810ioctl.h"
 
index 2a30782afd465da73c150e68b965f3c3be0f248e..476c8013580b451e3f8969a942f8aaf64c4446ee 100644 (file)
@@ -36,8 +36,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/imports.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
-#include "main/fbobject.h"
-#include "main/matrix.h"
 #include "main/renderbuffer.h"
 #include "main/simple_list.h"
 #include "utils.h"
@@ -48,8 +46,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "i810state.h"
 #include "i810tex.h"
 #include "i810span.h"
-#include "i810tris.h"
-#include "i810ioctl.h"
 
 #include "GL/internal/dri_interface.h"
 
index 642245c61c8b58569909e156908bf34d30a95360..0c68e120b021d555a3deea93af751d9fa1bf687b 100644 (file)
@@ -20,8 +20,6 @@
 #include "i810context.h"
 #include "i810state.h"
 #include "i810tex.h"
-#include "i810vb.h"
-#include "i810tris.h"
 #include "i810ioctl.h"
 
 
index e764644a6c1b8b7e651d88cc12baf43b0bff67fa..2ccb9562e90fda2d9630c3dd2c12d47ab5b515bb 100644 (file)
@@ -33,7 +33,6 @@
 #include "main/colormac.h"
 #include "main/texobj.h"
 #include "main/mm.h"
-#include "swrast/swrast.h"
 
 #include "texmem.h"
 
@@ -42,7 +41,6 @@
 
 #include "i810context.h"
 #include "i810tex.h"
-#include "i810state.h"
 #include "i810ioctl.h"
 
 
index d93afbf9ef6b5b9e3164b2f246b55b312f878e1d..bb426a41122d6213709a333ddc843e1a19f3e82c 100644 (file)
@@ -35,7 +35,6 @@
 #include "i810_dri.h"
 #include "i810context.h"
 #include "i810tex.h"
-#include "i810state.h"
 #include "i810ioctl.h"
 
 
index 30890dc9b70437cd8e0b68912384a437ffc45bce..09a772258c52debe1ff84d77778fde69fec4e8a5 100644 (file)
@@ -38,7 +38,6 @@
 #include "i810context.h"
 #include "i810vb.h"
 #include "i810ioctl.h"
-#include "i810tris.h"
 #include "i810state.h"
 
 
index 3b4ef7ffd82a9dc3b2c44f83932652cd3985e226..11bce31b12cb33e1acf9677d7ae46d1b7e5df388 100644 (file)
@@ -33,8 +33,6 @@
 #include "main/context.h"
 #include "main/simple_list.h"
 #include "main/imports.h"
-#include "main/matrix.h"
-#include "main/extensions.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
index e400e9a918d32bc53c036ef017531be518bda414..ca713e2de5eef75fac458e9333af0afdd21fe38c 100644 (file)
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
-#include "mach64_state.h"
-#include "mach64_vb.h"
 #include "mach64_dd.h"
 
 #include "main/context.h"
-#include "main/framebuffer.h"
 
 #include "utils.h"
 
index 8653c77da573ba4b78999570998090fe83455d84..1a95a8f619d02b14fd18c89b0d9347a86fe2120d 100644 (file)
@@ -32,7 +32,6 @@
 #include "mach64_context.h"
 #include "mach64_state.h"
 #include "mach64_lock.h"
-#include "mach64_tex.h"
 #include "drirenderbuffer.h"
 
 #if DEBUG_LOCKING
index 1ed3b0b70ef4d4fd442cb6f5de4d311ef2603dba..5cbfb85627afbd8f4d7c431113636b0e5d61da25 100644 (file)
@@ -31,8 +31,6 @@
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
-#include "mach64_tris.h"
-#include "mach64_vb.h"
 #include "mach64_span.h"
 
 #include "main/context.h"
index b4ba2a41c98cc250e1f7f28ecd3c39d211096f36..0c52c0c88cb4b5814595cd01d6a3ad8de37c84c1 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
-#include "mach64_state.h"
 #include "mach64_span.h"
 
 #include "swrast/swrast.h"
index df7cbc8670e50c4ea7e6f8543d9b89fcd06691e2..b9093b5a139d874f08a10b90abeeb72a2284c423 100644 (file)
@@ -36,7 +36,6 @@
 #include "mach64_vb.h"
 #include "mach64_tex.h"
 
-#include "main/context.h"
 #include "main/enums.h"
 #include "main/colormac.h"
 #include "swrast/swrast.h"
@@ -44,8 +43,6 @@
 #include "tnl/tnl.h"
 #include "swrast_setup/swrast_setup.h"
 
-#include "tnl/t_pipeline.h"
-
 
 /* =============================================================
  * Alpha blending
index 6627d3c38a05b82e1261186428a5dbe061c54811..1bce967d58f4c9f274982fc185e46f648d8fe1cc 100644 (file)
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
-#include "mach64_state.h"
-#include "mach64_vb.h"
-#include "mach64_tris.h"
 #include "mach64_tex.h"
 
-#include "main/context.h"
-#include "main/macros.h"
 #include "main/simple_list.h"
 #include "main/enums.h"
 #include "main/texstore.h"
index b97e9eec25b3da5437dad8bf754b32cae8ead4b2..46cee4320d00cbd0d07313ea0a73b0af4698adc6 100644 (file)
 #include "main/imports.h"
 
 #include "mach64_context.h"
-#include "mach64_state.h"
 #include "mach64_ioctl.h"
-#include "mach64_vb.h"
-#include "mach64_tris.h"
 #include "mach64_tex.h"
 
 
index df0a09a5c12d743ae61c55e44f86f5b34f1e8687..adf774ec194e768a2315ac4e416d00191a575fa8 100644 (file)
@@ -36,8 +36,6 @@
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
-#include "mach64_state.h"
-#include "mach64_vb.h"
 #include "mach64_tris.h"
 #include "mach64_tex.h"
 
index e58812e9028530bf2d6b1b1f95725773678c113e..00da83537698cdb844a71e109faabfd8cbf537f4 100644 (file)
@@ -42,7 +42,6 @@
 #include "mach64_vb.h"
 #include "mach64_ioctl.h"
 #include "mach64_tris.h"
-#include "mach64_state.h"
 
 
 #define MACH64_TEX1_BIT       0x1
index a93dbaee910fbdde962f3d2c494ed5e3ace8224f..14eb96c1bab18d3fb384dea391504511408824f3 100644 (file)
@@ -9,10 +9,6 @@ LIBNAME = r200_dri.so
 
 MINIGLX_SOURCES = server/radeon_dri.c 
 
-ifeq ($(USING_EGL), 1)
-EGL_SOURCES = server/radeon_egl.c
-endif
-
 ifeq ($(RADEON_LDFLAGS),)
 CS_SOURCES = radeon_cs_space_drm.c radeon_bo.c radeon_cs.c
 endif
index 6c5a0b79eed737ff71725a19d8c4b3b1d4739b18..80b08dcc99207fba856a02add9f73478531e8368 100644 (file)
@@ -698,7 +698,8 @@ static void tex_emit_mm(GLcontext *ctx, struct radeon_state_atom *atom)
    uint32_t dwords = atom->check(ctx, atom);
    int i = atom->idx;
    radeonTexObj *t = r200->state.texture.unit[i].texobj;
-   if (!r200->state.texture.unit[i].unitneeded)
+
+   if (!r200->state.texture.unit[i].unitneeded && !(dwords <= atom->cmd_size))
         dwords -= 4;
    BEGIN_BATCH_NO_AUTOSTATE(dwords);
 
diff --git a/src/mesa/drivers/dri/r200/server/radeon_egl.c b/src/mesa/drivers/dri/r200/server/radeon_egl.c
deleted file mode 120000 (symlink)
index d7735a7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../radeon/server/radeon_egl.c
\ No newline at end of file
index acc4d4d8b188521c88a6f7ff0fb9d46ca88d550d..04459c2ddfa104a545189f9bdd704622f2ac3f52 100644 (file)
@@ -9,10 +9,6 @@ LIBNAME = r300_dri.so
 
 MINIGLX_SOURCES = server/radeon_dri.c
 
-ifeq ($(USING_EGL), 1)
-EGL_SOURCES = server/radeon_egl.c
-endif
-
 ifeq ($(RADEON_LDFLAGS),)
 CS_SOURCES = radeon_cs_space_drm.c radeon_bo.c radeon_cs.c
 endif
diff --git a/src/mesa/drivers/dri/r300/server/radeon_egl.c b/src/mesa/drivers/dri/r300/server/radeon_egl.c
deleted file mode 120000 (symlink)
index d7735a7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../radeon/server/radeon_egl.c
\ No newline at end of file
index 8a45fc51b38ba01c703fd8523142782d7b4c3acb..5d509415393967c21f0abb14136bd78db3d346ca 100644 (file)
@@ -9,10 +9,6 @@ LIBNAME = r600_dri.so
 
 MINIGLX_SOURCES = server/radeon_dri.c
 
-ifeq ($(USING_EGL), 1)
-EGL_SOURCES = server/radeon_egl.c
-endif
-
 ifeq ($(RADEON_LDFLAGS),)
 CS_SOURCES = radeon_cs_space_drm.c radeon_bo.c radeon_cs.c
 endif
index b8466bdd75efec1c50f13ae7dbcb41fee50b4af9..3289d89c926962989d4ab512b1fd3d8906081c17 100644 (file)
@@ -85,6 +85,7 @@ static GLboolean r600GetTexFormat(struct gl_texture_object *tObj, gl_format mesa
        CLEARfield(t->SQ_TEX_RESOURCE4, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Y_mask);
        CLEARfield(t->SQ_TEX_RESOURCE4, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Z_mask);
        CLEARfield(t->SQ_TEX_RESOURCE4, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
+       CLEARbit(t->SQ_TEX_RESOURCE4, SQ_TEX_RESOURCE_WORD4_0__FORCE_DEGAMMA_bit);
 
        SETfield(t->SQ_TEX_RESOURCE4, SQ_FORMAT_COMP_UNSIGNED,
                 FORMAT_COMP_X_shift, FORMAT_COMP_X_mask);
@@ -95,6 +96,11 @@ static GLboolean r600GetTexFormat(struct gl_texture_object *tObj, gl_format mesa
        SETfield(t->SQ_TEX_RESOURCE4, SQ_FORMAT_COMP_UNSIGNED,
                 FORMAT_COMP_W_shift, FORMAT_COMP_W_mask);
 
+       CLEARbit(t->SQ_TEX_RESOURCE0, TILE_TYPE_bit);
+       SETfield(t->SQ_TEX_RESOURCE0, ARRAY_LINEAR_GENERAL,
+                SQ_TEX_RESOURCE_WORD0_0__TILE_MODE_shift,
+                SQ_TEX_RESOURCE_WORD0_0__TILE_MODE_mask);
+
        switch (mesa_format) /* This is mesa format. */
        {
        case MESA_FORMAT_RGBA8888:
@@ -158,6 +164,32 @@ static GLboolean r600GetTexFormat(struct gl_texture_object *tObj, gl_format mesa
                SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_W,
                         SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
                break;
+       case MESA_FORMAT_XRGB8888:
+               SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
+                        SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
+
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_Z,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_X_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_X_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_Y,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Y_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Y_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_X,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Z_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Z_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_1,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
+               break;
+       case MESA_FORMAT_XRGB8888_REV:
+               SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
+                        SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
+
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_1,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_X_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_X_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_Z,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Y_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Y_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_W,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Z_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_Z_mask);
+               SETfield(t->SQ_TEX_RESOURCE4, SQ_SEL_X,
+                        SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_shift, SQ_TEX_RESOURCE_WORD4_0__DST_SEL_W_mask);
+               break;
        case MESA_FORMAT_ARGB8888_REV:
                SETfield(t->SQ_TEX_RESOURCE1, FMT_8_8_8_8,
                         SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_shift, SQ_TEX_RESOURCE_WORD1_0__DATA_FORMAT_mask);
@@ -515,6 +547,10 @@ static GLboolean r600GetTexFormat(struct gl_texture_object *tObj, gl_format mesa
        case MESA_FORMAT_Z24_S8:
        case MESA_FORMAT_Z32:
        case MESA_FORMAT_S8:
+               SETbit(t->SQ_TEX_RESOURCE0, TILE_TYPE_bit);
+               SETfield(t->SQ_TEX_RESOURCE0, ARRAY_1D_TILED_THIN1,
+                        SQ_TEX_RESOURCE_WORD0_0__TILE_MODE_shift,
+                        SQ_TEX_RESOURCE_WORD0_0__TILE_MODE_mask);
                switch (mesa_format) {
                case MESA_FORMAT_Z16:
                        SETfield(t->SQ_TEX_RESOURCE1, FMT_16,
@@ -651,6 +687,12 @@ static GLuint r600_translate_shadow_func(GLenum func)
    }
 }
 
+static INLINE uint32_t
+S_FIXED(float value, uint32_t frac_bits)
+{
+   return value * (1 << frac_bits);
+}
+
 void r600SetDepthTexMode(struct gl_texture_object *tObj)
 {
        radeonTexObjPtr t;
@@ -670,8 +712,9 @@ void r600SetDepthTexMode(struct gl_texture_object *tObj)
  * \param rmesa Context pointer
  * \param t the r300 texture object
  */
-static void setup_hardware_state(context_t *rmesa, struct gl_texture_object *texObj)
+static void setup_hardware_state(GLcontext * ctx, struct gl_texture_object *texObj, int unit)
 {
+       context_t *rmesa = R700_CONTEXT(ctx);
        radeonTexObj *t = radeon_tex_obj(texObj);
        const struct gl_texture_image *firstImage;
        GLuint uTexelPitch, row_align;
@@ -733,11 +776,21 @@ static void setup_hardware_state(context_t *rmesa, struct gl_texture_object *tex
 
        t->SQ_TEX_RESOURCE2 = get_base_teximage_offset(t) / 256;
 
-       if ((t->maxLod - t->minLod) > 0) {
-               t->SQ_TEX_RESOURCE3 = radeon_miptree_image_offset(t->mt, 0, t->minLod + 1) / 256;
-               SETfield(t->SQ_TEX_RESOURCE4, 0, BASE_LEVEL_shift, BASE_LEVEL_mask);
-               SETfield(t->SQ_TEX_RESOURCE5, t->maxLod - t->minLod, LAST_LEVEL_shift, LAST_LEVEL_mask);
-       }
+       t->SQ_TEX_RESOURCE3 = radeon_miptree_image_offset(t->mt, 0, t->minLod + 1) / 256;
+
+       SETfield(t->SQ_TEX_RESOURCE4, 0, BASE_LEVEL_shift, BASE_LEVEL_mask);
+       SETfield(t->SQ_TEX_RESOURCE5, t->maxLod - t->minLod, LAST_LEVEL_shift, LAST_LEVEL_mask);
+
+       SETfield(t->SQ_TEX_SAMPLER1,
+               S_FIXED(CLAMP(t->base.MinLod - t->minLod, 0, 15), 6),
+               MIN_LOD_shift, MIN_LOD_mask);
+       SETfield(t->SQ_TEX_SAMPLER1,
+               S_FIXED(CLAMP(t->base.MaxLod - t->minLod, 0, 15), 6),
+               MAX_LOD_shift, MAX_LOD_mask);
+       SETfield(t->SQ_TEX_SAMPLER1,
+               S_FIXED(CLAMP(ctx->Texture.Unit[unit].LodBias + t->base.LodBias, -16, 16), 6),
+               SQ_TEX_SAMPLER_WORD1_0__LOD_BIAS_shift, SQ_TEX_SAMPLER_WORD1_0__LOD_BIAS_mask);
+
        if(texObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB)
        {
                SETfield(t->SQ_TEX_SAMPLER0, r600_translate_shadow_func(texObj->CompareFunc), DEPTH_COMPARE_FUNCTION_shift, DEPTH_COMPARE_FUNCTION_mask);
@@ -754,9 +807,8 @@ static void setup_hardware_state(context_t *rmesa, struct gl_texture_object *tex
  *
  * Mostly this means populating the texture object's mipmap tree.
  */
-static GLboolean r600_validate_texture(GLcontext * ctx, struct gl_texture_object *texObj)
+static GLboolean r600_validate_texture(GLcontext * ctx, struct gl_texture_object *texObj, int unit)
 {
-       context_t *rmesa = R700_CONTEXT(ctx);
        radeonTexObj *t = radeon_tex_obj(texObj);
 
        if (!radeon_validate_texture_miptree(ctx, texObj))
@@ -764,7 +816,7 @@ static GLboolean r600_validate_texture(GLcontext * ctx, struct gl_texture_object
 
        /* Configure the hardware registers (more precisely, the cached version
         * of the hardware registers). */
-       setup_hardware_state(rmesa, texObj);
+       setup_hardware_state(ctx, texObj, unit);
 
        t->validated = GL_TRUE;
        return GL_TRUE;
@@ -805,7 +857,7 @@ GLboolean r600ValidateBuffers(GLcontext * ctx)
                if (!ctx->Texture.Unit[i]._ReallyEnabled)
                        continue;
 
-               if (!r600_validate_texture(ctx, ctx->Texture.Unit[i]._Current)) {
+               if (!r600_validate_texture(ctx, ctx->Texture.Unit[i]._Current, i)) {
                        radeon_warning("failed to validate texture for unit %d.\n", i);
                }
                t = radeon_tex_obj(ctx->Texture.Unit[i]._Current);
index 1a1a87c3cf919e54781100393952d950699df47a..ef25cd93fe48af1276f89283c9ad9939f6e91d7d 100644 (file)
@@ -303,14 +303,13 @@ static void r700SetRenderTarget(context_t *context, int id)
     R600_STATECHANGE(context, cb_target);
 
     /* color buffer */
-    r700->render_target[id].CB_COLOR0_BASE.u32All = context->radeon.state.color.draw_offset;
+    r700->render_target[id].CB_COLOR0_BASE.u32All = context->radeon.state.color.draw_offset / 256;
 
     nPitchInPixel = rrb->pitch/rrb->cpp;
     SETfield(r700->render_target[id].CB_COLOR0_SIZE.u32All, (nPitchInPixel/8)-1,
              PITCH_TILE_MAX_shift, PITCH_TILE_MAX_mask);
     SETfield(r700->render_target[id].CB_COLOR0_SIZE.u32All, ( (nPitchInPixel * context->radeon.radeonScreen->driScreen->fbHeight)/64 )-1,
              SLICE_TILE_MAX_shift, SLICE_TILE_MAX_mask);
-    r700->render_target[id].CB_COLOR0_BASE.u32All = 0;
     SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ENDIAN_NONE, ENDIAN_shift, ENDIAN_mask);
     SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_LINEAR_GENERAL,
              CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
index 3c8cb579f9bcae6e5d0ebbc3e267d3fcf3861dd2..20e8afefbaa4a44ea17f0f301a3d0eac3f575e8e 100644 (file)
@@ -59,6 +59,7 @@ static void r700SetClipPlaneState(GLcontext * ctx, GLenum cap, GLboolean state);
 static void r700UpdatePolygonMode(GLcontext * ctx);
 static void r700SetPolygonOffsetState(GLcontext * ctx, GLboolean state);
 static void r700SetStencilState(GLcontext * ctx, GLboolean state);
+static void r700UpdateWindow(GLcontext * ctx, int id);
 
 void r700UpdateShaders(GLcontext * ctx)
 {
@@ -780,6 +781,9 @@ static void r700Enable(GLcontext * ctx, GLenum cap, GLboolean state) //---------
        case GL_LINE_STIPPLE:
                r700UpdateLineStipple(ctx);
                break;
+       case GL_DEPTH_CLAMP:
+               r700UpdateWindow(ctx, 0);
+               break;
        default:
                break;
        }
@@ -1576,9 +1580,9 @@ static void r700InitSQConfig(GLcontext * ctx)
     SETbit(r700->sq_config.SQ_CONFIG.u32All, DX9_CONSTS_bit);
     SETbit(r700->sq_config.SQ_CONFIG.u32All, ALU_INST_PREFER_VECTOR_bit);
     SETfield(r700->sq_config.SQ_CONFIG.u32All, ps_prio, PS_PRIO_shift, PS_PRIO_mask);
-    SETfield(r700->sq_config.SQ_CONFIG.u32All, ps_prio, VS_PRIO_shift, VS_PRIO_mask);
-    SETfield(r700->sq_config.SQ_CONFIG.u32All, ps_prio, GS_PRIO_shift, GS_PRIO_mask);
-    SETfield(r700->sq_config.SQ_CONFIG.u32All, ps_prio, ES_PRIO_shift, ES_PRIO_mask);
+    SETfield(r700->sq_config.SQ_CONFIG.u32All, vs_prio, VS_PRIO_shift, VS_PRIO_mask);
+    SETfield(r700->sq_config.SQ_CONFIG.u32All, gs_prio, GS_PRIO_shift, GS_PRIO_mask);
+    SETfield(r700->sq_config.SQ_CONFIG.u32All, es_prio, ES_PRIO_shift, ES_PRIO_mask);
 
     r700->sq_config.SQ_GPR_RESOURCE_MGMT_1.u32All = 0;
     SETfield(r700->sq_config.SQ_GPR_RESOURCE_MGMT_1.u32All, num_ps_gprs, NUM_PS_GPRS_shift, NUM_PS_GPRS_mask);
diff --git a/src/mesa/drivers/dri/r600/server/radeon_egl.c b/src/mesa/drivers/dri/r600/server/radeon_egl.c
deleted file mode 120000 (symlink)
index d7735a7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../radeon/server/radeon_egl.c
\ No newline at end of file
index 7b1f84a71548277f24413fd59d3d0df791d1e115..e780b9eef1b4fee917312c85d6e0c71e11b61cf9 100644 (file)
@@ -531,10 +531,9 @@ radeon_render_texture(GLcontext * ctx,
                                             att->TextureLevel);
 
    if (att->Texture->Target == GL_TEXTURE_3D) {
-      GLuint offsets[6];
-      radeon_miptree_depth_offsets(radeon_image->mt, att->TextureLevel,
-                                  offsets);
-      imageOffset += offsets[att->Zoffset];
+      imageOffset += radeon_image->mt->levels[att->TextureLevel].rowstride *
+                     radeon_image->mt->levels[att->TextureLevel].height *
+                     att->Zoffset;
    }
 
    /* store that offset in the region, along with the correct pitch for
index 033f26db2a1b69a7ca92c044380cdbe019aa5cd1..a1a523931fb1136e844668961141b17bb904a2ed 100644 (file)
@@ -177,6 +177,12 @@ static void calculate_miptree_layout_r300(radeonContextPtr rmesa, radeon_mipmap_
 
                for(face = 0; face < mt->faces; face++)
                        compute_tex_image_offset(rmesa, mt, face, level, &curOffset);
+               /* r600 cube levels seems to be aligned to 8 faces but
+                * we have separate register for 1'st level offset so add
+                * 2 image alignment after 1'st mip level */
+               if(rmesa->radeonScreen->chip_family >= CHIP_FAMILY_R600 &&
+                  mt->target == GL_TEXTURE_CUBE_MAP && level >= 1)
+                       curOffset += 2 * mt->levels[level].size;
        }
 
        /* Note the required size in memory */
@@ -380,25 +386,6 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t)
                texImg->Depth, t->tile_bits);
 }
 
-/* Although we use the image_offset[] array to store relative offsets
- * to cube faces, Mesa doesn't know anything about this and expects
- * each cube face to be treated as a separate image.
- *
- * These functions present that view to mesa:
- */
-void
-radeon_miptree_depth_offsets(radeon_mipmap_tree *mt, GLuint level, GLuint *offsets)
-{
-       if (mt->target != GL_TEXTURE_3D || mt->faces == 1) {
-               offsets[0] = 0;
-       } else {
-               int i;
-               for (i = 0; i < 6; i++) {
-                       offsets[i] = mt->levels[level].faces[i].offset;
-               }
-       }
-}
-
 GLuint
 radeon_miptree_image_offset(radeon_mipmap_tree *mt,
                            GLuint face, GLuint level)
@@ -619,4 +606,4 @@ uint32_t get_base_teximage_offset(radeonTexObj *texObj)
        } else {
                return radeon_miptree_image_offset(texObj->mt, 0, texObj->minLod);
        }
-}
\ No newline at end of file
+}
index a10649b5aeac8ee961d48b04c39f84bb62a44417..c911688c1a5d2d81f29b0d43b9b1f418b75d1898 100644 (file)
@@ -88,7 +88,5 @@ GLboolean radeon_miptree_matches_image(radeon_mipmap_tree *mt,
 void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t);
 GLuint radeon_miptree_image_offset(radeon_mipmap_tree *mt,
                                   GLuint face, GLuint level);
-void radeon_miptree_depth_offsets(radeon_mipmap_tree *mt, GLuint level, GLuint *offsets);
-
 uint32_t get_base_teximage_offset(radeonTexObj *texObj);
 #endif /* __RADEON_MIPMAP_TREE_H_ */
index 20a27ad9a70e8994c1b9bdb10e0d12c123a8a5be..4538e74eea1d4b2459168a6068158cc2a58693f4 100644 (file)
@@ -233,8 +233,15 @@ static void radeon_generate_mipmap(GLcontext *ctx, GLenum target,
 
 void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj)
 {
+       radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
+       struct radeon_bo *bo;
        GLuint face = _mesa_tex_target_to_face(target);
        radeon_texture_image *baseimage = get_radeon_texture_image(texObj->Image[face][texObj->BaseLevel]);
+       bo = !baseimage->mt ? baseimage->bo : baseimage->mt->bo;
+
+       if (bo && radeon_bo_is_referenced_by_cs(bo, rmesa->cmdbuf.cs)) {
+               radeon_firevertices(rmesa);
+       }
 
        radeon_teximage_map(baseimage, GL_FALSE);
        radeon_generate_mipmap(ctx, target, texObj);
diff --git a/src/mesa/drivers/dri/radeon/server/radeon_egl.c b/src/mesa/drivers/dri/radeon/server/radeon_egl.c
deleted file mode 100644 (file)
index c16d66e..0000000
+++ /dev/null
@@ -1,1088 +0,0 @@
-/*
- * EGL driver for radeon_dri.so
- */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-
-#include "eglconfig.h"
-#include "eglcontext.h"
-#include "egldisplay.h"
-#include "egldriver.h"
-#include "eglglobals.h"
-#include "egllog.h"
-#include "eglmode.h"
-#include "eglscreen.h"
-#include "eglsurface.h"
-#include "egldri.h"
-
-#include "mtypes.h"
-#include "memops.h"
-#include "drm.h"
-#include "drm_sarea.h"
-#include "radeon_drm.h"
-#include "radeon_dri.h"
-#include "radeon.h"
-
-static size_t radeon_drm_page_size;
-
-/**
- * radeon driver-specific driver class derived from _EGLDriver
- */
-typedef struct radeon_driver
-{
-   _EGLDriver Base;  /* base class/object */
-   GLuint radeonStuff;
-} radeonDriver;
-
-static int
-RADEONSetParam(driDisplay  *disp, int param, int value)
-{
-   drm_radeon_setparam_t sp;
-   int ret;
-
-   memset(&sp, 0, sizeof(sp));
-   sp.param = param;
-   sp.value = value;
-
-   if ((ret=drmCommandWrite(disp->drmFD, DRM_RADEON_SETPARAM, &sp, sizeof(sp)))) {
-     fprintf(stderr,"Set param failed\n", ret);
-      return -1;
-   }
-
-   return 0;
-}
-
-static int
-RADEONCheckDRMVersion(driDisplay *disp, RADEONInfoPtr info)
-{
-   drmVersionPtr  version;
-
-   version = drmGetVersion(disp->drmFD);
-   if (version) {
-      int req_minor, req_patch;
-
-      /* Need 1.21.x for card type detection getparam
-       */
-      req_minor = 21;
-      req_patch = 0;
-
-      if (version->version_major != 1 ||
-          version->version_minor < req_minor ||
-          (version->version_minor == req_minor &&
-           version->version_patchlevel < req_patch)) {
-         /* Incompatible drm version */
-         fprintf(stderr,
-                 "[dri] RADEONDRIScreenInit failed because of a version "
-                 "mismatch.\n"
-                 "[dri] radeon.o kernel module version is %d.%d.%d "
-                 "but version 1.%d.%d or newer is needed.\n"
-                 "[dri] Disabling DRI.\n",
-                 version->version_major,
-                 version->version_minor,
-                 version->version_patchlevel,
-                 req_minor,
-                 req_patch);
-         drmFreeVersion(version);
-         return 0;
-      }
-
-      info->drmMinor = version->version_minor;
-      drmFreeVersion(version);
-   }
-
-   return 1;
-}
-
-
-/**
- * \brief Compute base 2 logarithm.
- *
- * \param val value.
- *
- * \return base 2 logarithm of \p val.
- */
-static int RADEONMinBits(int val)
-{
-   int  bits;
-
-   if (!val) return 1;
-   for (bits = 0; val; val >>= 1, ++bits);
-   return bits;
-}
-
-
-/* Initialize the PCI GART state.  Request memory for use in PCI space,
- * and initialize the Radeon registers to point to that memory.
- */
-static int RADEONDRIPciInit(driDisplay *disp, RADEONInfoPtr info)
-{
-    int  ret;
-    int  flags = DRM_READ_ONLY | DRM_LOCKED | DRM_KERNEL;
-    int            s, l;
-
-    ret = drmScatterGatherAlloc(disp->drmFD, info->gartSize*1024*1024,
-                                &info->gartMemHandle);
-    if (ret < 0) {
-        fprintf(stderr, "[pci] Out of memory (%d)\n", ret);
-        return 0;
-    }
-    fprintf(stderr,
-               "[pci] %d kB allocated with handle 0x%04lx\n",
-            info->gartSize*1024, (long) info->gartMemHandle);
-
-   info->gartOffset = 0;
-
-   /* Initialize the CP ring buffer data */
-   info->ringStart       = info->gartOffset;
-   info->ringMapSize     = info->ringSize*1024*1024 + radeon_drm_page_size;
-
-   info->ringReadOffset  = info->ringStart + info->ringMapSize;
-   info->ringReadMapSize = radeon_drm_page_size;
-
-   /* Reserve space for vertex/indirect buffers */
-   info->bufStart        = info->ringReadOffset + info->ringReadMapSize;
-   info->bufMapSize      = info->bufSize*1024*1024;
-
-   /* Reserve the rest for AGP textures */
-   info->gartTexStart     = info->bufStart + info->bufMapSize;
-   s = (info->gartSize*1024*1024 - info->gartTexStart);
-   l = RADEONMinBits((s-1) / RADEON_NR_TEX_REGIONS);
-   if (l < RADEON_LOG_TEX_GRANULARITY) l = RADEON_LOG_TEX_GRANULARITY;
-   info->gartTexMapSize   = (s >> l) << l;
-   info->log2GARTTexGran  = l;
-
-    if (drmAddMap(disp->drmFD, info->ringStart, info->ringMapSize,
-                  DRM_SCATTER_GATHER, flags, &info->ringHandle) < 0) {
-        fprintf(stderr,
-                   "[pci] Could not add ring mapping\n");
-        return 0;
-    }
-    fprintf(stderr,
-               "[pci] ring handle = 0x%08lx\n", info->ringHandle);
-
-    if (drmAddMap(disp->drmFD, info->ringReadOffset, info->ringReadMapSize,
-                  DRM_SCATTER_GATHER, flags, &info->ringReadPtrHandle) < 0) {
-        fprintf(stderr,
-                   "[pci] Could not add ring read ptr mapping\n");
-        return 0;
-    }
-    fprintf(stderr,
-               "[pci] ring read ptr handle = 0x%08lx\n",
-               info->ringReadPtrHandle);
-
-    if (drmAddMap(disp->drmFD, info->bufStart, info->bufMapSize,
-                  DRM_SCATTER_GATHER, 0, &info->bufHandle) < 0) {
-        fprintf(stderr,
-                   "[pci] Could not add vertex/indirect buffers mapping\n");
-        return 0;
-    }
-    fprintf(stderr,
-               "[pci] vertex/indirect buffers handle = 0x%08lx\n",
-               info->bufHandle);
-
-    if (drmAddMap(disp->drmFD, info->gartTexStart, info->gartTexMapSize,
-                  DRM_SCATTER_GATHER, 0, &info->gartTexHandle) < 0) {
-        fprintf(stderr,
-                   "[pci] Could not add GART texture map mapping\n");
-        return 0;
-    }
-    fprintf(stderr,
-               "[pci] GART texture map handle = 0x%08lx\n",
-               info->gartTexHandle);
-
-    return 1;
-}
-
-
-/**
- * \brief Initialize the AGP state
- *
- * \param ctx display handle.
- * \param info driver private data.
- *
- * \return one on success, or zero on failure.
- *
- * Acquires and enables the AGP device. Reserves memory in the AGP space for
- * the ring buffer, vertex buffers and textures. Initialize the Radeon
- * registers to point to that memory and add client mappings.
- */
-static int RADEONDRIAgpInit( driDisplay *disp, RADEONInfoPtr info)
-{
-   int            mode, ret;
-   int            s, l;
-   int agpmode = 1;
-
-   if (drmAgpAcquire(disp->drmFD) < 0) {
-      fprintf(stderr, "[gart] AGP not available\n");
-      return 0;
-   }
-
-   mode = drmAgpGetMode(disp->drmFD);  /* Default mode */
-   /* Disable fast write entirely - too many lockups.
-    */
-   mode &= ~RADEON_AGP_MODE_MASK;
-   switch (agpmode) {
-   case 4:          mode |= RADEON_AGP_4X_MODE;
-   case 2:          mode |= RADEON_AGP_2X_MODE;
-   case 1: default: mode |= RADEON_AGP_1X_MODE;
-   }
-
-   if (drmAgpEnable(disp->drmFD, mode) < 0) {
-      fprintf(stderr, "[gart] AGP not enabled\n");
-      drmAgpRelease(disp->drmFD);
-      return 0;
-   }
-
-#if 0
-   /* Workaround for some hardware bugs */
-   if (info->ChipFamily < CHIP_FAMILY_R200)
-      OUTREG(RADEON_AGP_CNTL, INREG(RADEON_AGP_CNTL) | 0x000e0000);
-#endif
-   info->gartOffset = 0;
-
-   if ((ret = drmAgpAlloc(disp->drmFD, info->gartSize*1024*1024, 0, NULL,
-                          &info->gartMemHandle)) < 0) {
-      fprintf(stderr, "[gart] Out of memory (%d)\n", ret);
-      drmAgpRelease(disp->drmFD);
-      return 0;
-   }
-   fprintf(stderr,
-           "[gart] %d kB allocated with handle 0x%08x\n",
-           info->gartSize*1024, (unsigned)info->gartMemHandle);
-
-   if (drmAgpBind(disp->drmFD,
-                  info->gartMemHandle, info->gartOffset) < 0) {
-      fprintf(stderr, "[gart] Could not bind\n");
-      drmAgpFree(disp->drmFD, info->gartMemHandle);
-      drmAgpRelease(disp->drmFD);
-      return 0;
-   }
-
-   /* Initialize the CP ring buffer data */
-   info->ringStart       = info->gartOffset;
-   info->ringMapSize     = info->ringSize*1024*1024 + radeon_drm_page_size;
-
-   info->ringReadOffset  = info->ringStart + info->ringMapSize;
-   info->ringReadMapSize = radeon_drm_page_size;
-
-   /* Reserve space for vertex/indirect buffers */
-   info->bufStart        = info->ringReadOffset + info->ringReadMapSize;
-   info->bufMapSize      = info->bufSize*1024*1024;
-
-   /* Reserve the rest for AGP textures */
-   info->gartTexStart     = info->bufStart + info->bufMapSize;
-   s = (info->gartSize*1024*1024 - info->gartTexStart);
-   l = RADEONMinBits((s-1) / RADEON_NR_TEX_REGIONS);
-   if (l < RADEON_LOG_TEX_GRANULARITY) l = RADEON_LOG_TEX_GRANULARITY;
-   info->gartTexMapSize   = (s >> l) << l;
-   info->log2GARTTexGran  = l;
-
-   if (drmAddMap(disp->drmFD, info->ringStart, info->ringMapSize,
-                 DRM_AGP, DRM_READ_ONLY, &info->ringHandle) < 0) {
-      fprintf(stderr, "[gart] Could not add ring mapping\n");
-      return 0;
-   }
-   fprintf(stderr, "[gart] ring handle = 0x%08lx\n", info->ringHandle);
-
-
-   if (drmAddMap(disp->drmFD, info->ringReadOffset, info->ringReadMapSize,
-                 DRM_AGP, DRM_READ_ONLY, &info->ringReadPtrHandle) < 0) {
-      fprintf(stderr,
-              "[gart] Could not add ring read ptr mapping\n");
-      return 0;
-   }
-
-   fprintf(stderr,
-           "[gart] ring read ptr handle = 0x%08lx\n",
-           info->ringReadPtrHandle);
-
-   if (drmAddMap(disp->drmFD, info->bufStart, info->bufMapSize,
-                 DRM_AGP, 0, &info->bufHandle) < 0) {
-      fprintf(stderr,
-              "[gart] Could not add vertex/indirect buffers mapping\n");
-      return 0;
-   }
-   fprintf(stderr,
-           "[gart] vertex/indirect buffers handle = 0x%08lx\n",
-           info->bufHandle);
-
-   if (drmAddMap(disp->drmFD, info->gartTexStart, info->gartTexMapSize,
-                 DRM_AGP, 0, &info->gartTexHandle) < 0) {
-      fprintf(stderr,
-              "[gart] Could not add AGP texture map mapping\n");
-      return 0;
-   }
-   fprintf(stderr,
-           "[gart] AGP texture map handle = 0x%08lx\n",
-           info->gartTexHandle);
-
-   return 1;
-}
-
-
-/**
- * Initialize all the memory-related fields of the RADEONInfo object.
- * This includes the various 'offset' and 'size' fields.
- */
-static int
-RADEONMemoryInit(driDisplay *disp, RADEONInfoPtr info)
-{
-   int        width_bytes = disp->virtualWidth * disp->cpp;
-   int        cpp         = disp->cpp;
-   int        bufferSize  = ((disp->virtualHeight * width_bytes
-                              + RADEON_BUFFER_ALIGN)
-                             & ~RADEON_BUFFER_ALIGN);
-   int        depthSize   = ((((disp->virtualHeight+15) & ~15) * width_bytes
-                              + RADEON_BUFFER_ALIGN)
-                             & ~RADEON_BUFFER_ALIGN);
-   int        l;
-   int        pcie_gart_table_size = 0;
-
-   info->frontOffset = 0;
-   info->frontPitch = disp->virtualWidth;
-
-   if (disp->card_type==RADEON_CARD_PCIE)
-     pcie_gart_table_size  = RADEON_PCIGART_TABLE_SIZE;
-
-   /* Front, back and depth buffers - everything else texture??
-    */
-   info->textureSize = disp->fbSize - pcie_gart_table_size - 2 * bufferSize - depthSize;
-
-   if (info->textureSize < 0)
-      return 0;
-
-   l = RADEONMinBits((info->textureSize-1) / RADEON_NR_TEX_REGIONS);
-   if (l < RADEON_LOG_TEX_GRANULARITY) l = RADEON_LOG_TEX_GRANULARITY;
-
-   /* Round the texture size up to the nearest whole number of
-    * texture regions.  Again, be greedy about this, don't
-    * round down.
-    */
-   info->log2TexGran = l;
-   info->textureSize = (info->textureSize >> l) << l;
-
-   /* Set a minimum usable local texture heap size.  This will fit
-    * two 256x256x32bpp textures.
-    */
-   if (info->textureSize < 512 * 1024) {
-      info->textureOffset = 0;
-      info->textureSize = 0;
-   }
-
-   /* Reserve space for textures */
-   info->textureOffset = ((disp->fbSize - pcie_gart_table_size - info->textureSize +
-                           RADEON_BUFFER_ALIGN) &
-                          ~RADEON_BUFFER_ALIGN);
-
-   /* Reserve space for the shared depth
-    * buffer.
-    */
-   info->depthOffset = ((info->textureOffset - depthSize +
-                         RADEON_BUFFER_ALIGN) &
-                        ~RADEON_BUFFER_ALIGN);
-   info->depthPitch = disp->virtualWidth;
-
-   info->backOffset = ((info->depthOffset - bufferSize +
-                        RADEON_BUFFER_ALIGN) &
-                       ~RADEON_BUFFER_ALIGN);
-   info->backPitch = disp->virtualWidth;
-
-   if (pcie_gart_table_size)
-     info->pcieGartTableOffset = disp->fbSize - pcie_gart_table_size;
-
-   fprintf(stderr,
-           "Will use back buffer at offset 0x%x, pitch %d\n",
-           info->backOffset, info->backPitch);
-   fprintf(stderr,
-           "Will use depth buffer at offset 0x%x, pitch %d\n",
-           info->depthOffset, info->depthPitch);
-   fprintf(stderr,
-           "Will use %d kb for textures at offset 0x%x\n",
-           info->textureSize/1024, info->textureOffset);
-   if (pcie_gart_table_size)
-   { 
-     fprintf(stderr,
-            "Will use %d kb for PCIE GART Table at offset 0x%x\n",
-            pcie_gart_table_size/1024, info->pcieGartTableOffset);
-   }
-
-   /* XXX I don't think these are needed. */
-#if 0
-   info->frontPitchOffset = (((info->frontPitch * cpp / 64) << 22) |
-                             (info->frontOffset >> 10));
-
-   info->backPitchOffset = (((info->backPitch * cpp / 64) << 22) |
-                            (info->backOffset >> 10));
-
-   info->depthPitchOffset = (((info->depthPitch * cpp / 64) << 22) |
-                             (info->depthOffset >> 10));
-#endif
-
-   if (pcie_gart_table_size)
-     RADEONSetParam(disp, RADEON_SETPARAM_PCIGART_LOCATION, info->pcieGartTableOffset);
-
-   return 1;
-}
-
-
-/**
- * \brief Initialize the kernel data structures and enable the CP engine.
- *
- * \param ctx display handle.
- * \param info driver private data.
- *
- * \return non-zero on success, or zero on failure.
- *
- * This function is a wrapper around the DRM_RADEON_CP_INIT command, passing
- * all the parameters in a drm_radeon_init_t structure.
- */
-static int RADEONDRIKernelInit( driDisplay *disp,
-                               RADEONInfoPtr info)
-{
-   int cpp = disp->bpp / 8;
-   drm_radeon_init_t  drmInfo;
-   int ret;
-
-   memset(&drmInfo, 0, sizeof(drmInfo));
-
-   if ( (info->ChipFamily >= CHIP_FAMILY_R300) )
-      drmInfo.func            = RADEON_INIT_R300_CP;
-   else if ( (info->ChipFamily == CHIP_FAMILY_R200) ||
-        (info->ChipFamily == CHIP_FAMILY_RV250) ||
-        (info->ChipFamily == CHIP_FAMILY_M9) ||
-        (info->ChipFamily == CHIP_FAMILY_RV280) )
-      drmInfo.func             = RADEON_INIT_R200_CP;
-   else
-      drmInfo.func             = RADEON_INIT_CP;
-
-   /* This is the struct passed to the kernel module for its initialization */
-   /* XXX problem here:
-    * The front/back/depth_offset/pitch fields may change depending upon
-    * which drawing surface we're using!!!  They can't be set just once
-    * during initialization.
-    * Looks like we'll need a new ioctl to update these fields for drawing
-    * to other surfaces...
-    */
-   drmInfo.sarea_priv_offset   = sizeof(drm_sarea_t);
-   drmInfo.cp_mode             = RADEON_DEFAULT_CP_BM_MODE;
-   drmInfo.gart_size            = info->gartSize*1024*1024;
-   drmInfo.ring_size           = info->ringSize*1024*1024;
-   drmInfo.usec_timeout        = 1000;
-   drmInfo.fb_bpp              = disp->bpp;
-   drmInfo.depth_bpp           = disp->bpp;
-   drmInfo.front_offset        = info->frontOffset;
-   drmInfo.front_pitch         = info->frontPitch * cpp;
-   drmInfo.back_offset         = info->backOffset;
-   drmInfo.back_pitch          = info->backPitch * cpp;
-   drmInfo.depth_offset        = info->depthOffset;
-   drmInfo.depth_pitch         = info->depthPitch * cpp;
-   drmInfo.ring_offset         = info->ringHandle;
-   drmInfo.ring_rptr_offset    = info->ringReadPtrHandle;
-   drmInfo.buffers_offset      = info->bufHandle;
-   drmInfo.gart_textures_offset = info->gartTexHandle;
-
-   ret = drmCommandWrite(disp->drmFD, DRM_RADEON_CP_INIT, &drmInfo,
-                         sizeof(drm_radeon_init_t));
-
-   return ret >= 0;
-}
-
-
-/**
- * \brief Add a map for the vertex buffers that will be accessed by any
- * DRI-based clients.
- *
- * \param ctx display handle.
- * \param info driver private data.
- *
- * \return one on success, or zero on failure.
- *
- * Calls drmAddBufs() with the previously allocated vertex buffers.
- */
-static int RADEONDRIBufInit( driDisplay *disp, RADEONInfoPtr info )
-{
-   /* Initialize vertex buffers */
-   info->bufNumBufs = drmAddBufs(disp->drmFD,
-                                 info->bufMapSize / RADEON_BUFFER_SIZE,
-                                 RADEON_BUFFER_SIZE,
-                                (disp->card_type!=RADEON_CARD_AGP) ? DRM_SG_BUFFER : DRM_AGP_BUFFER,
-                                 info->bufStart);
-
-   if (info->bufNumBufs <= 0) {
-      fprintf(stderr,
-              "[drm] Could not create vertex/indirect buffers list\n");
-      return 0;
-   }
-   fprintf(stderr,
-           "[drm] Added %d %d byte vertex/indirect buffers\n",
-           info->bufNumBufs, RADEON_BUFFER_SIZE);
-
-   return 1;
-}
-
-
-/**
- * \brief Install an IRQ handler.
- *
- * \param disp display handle.
- * \param info driver private data.
- *
- * Attempts to install an IRQ handler via drmCtlInstHandler(), falling back to
- * IRQ-free operation on failure.
- */
-static void RADEONDRIIrqInit(driDisplay *disp, RADEONInfoPtr info)
-{
-   if ((drmCtlInstHandler(disp->drmFD, 0)) != 0)
-      fprintf(stderr, "[drm] failure adding irq handler, "
-                 "there is a device already using that irq\n"
-                 "[drm] falling back to irq-free operation\n");
-}
-
-
-/**
- * \brief Initialize the AGP heap.
- *
- * \param disp display handle.
- * \param info driver private data.
- *
- * This function is a wrapper around the DRM_RADEON_INIT_HEAP command, passing
- * all the parameters in a drm_radeon_mem_init_heap structure.
- */
-static void RADEONDRIAgpHeapInit(driDisplay *disp,
-                                 RADEONInfoPtr info)
-{
-   drm_radeon_mem_init_heap_t drmHeap;
-
-   /* Start up the simple memory manager for gart space */
-   drmHeap.region = RADEON_MEM_REGION_GART;
-   drmHeap.start  = 0;
-   drmHeap.size   = info->gartTexMapSize;
-
-   if (drmCommandWrite(disp->drmFD, DRM_RADEON_INIT_HEAP,
-                       &drmHeap, sizeof(drmHeap))) {
-      fprintf(stderr,
-              "[drm] Failed to initialized gart heap manager\n");
-   } else {
-      fprintf(stderr,
-              "[drm] Initialized kernel gart heap manager, %d\n",
-              info->gartTexMapSize);
-   }
-}
-
-static int RADEONGetCardType(driDisplay *disp, RADEONInfoPtr info)
-{
-   drm_radeon_getparam_t gp;  
-   int ret;
-   gp.param = RADEON_PARAM_CARD_TYPE;
-   gp.value = &disp->card_type;
-
-   ret=drmCommandWriteRead(disp->drmFD, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
-   if (ret) {
-     fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_CARD_TYPE) : %d\n", ret);
-     return -1;
-   }
-
-   return disp->card_type;
-}
-
-/**
- * Called at the start of each server generation.
- *
- * \param disp display handle.
- * \param info driver private data.
- *
- * \return non-zero on success, or zero on failure.
- *
- * Performs static frame buffer allocation. Opens the DRM device and add maps
- * to the SAREA, framebuffer and MMIO regions. Fills in \p info with more
- * information. Creates a \e server context to grab the lock for the
- * initialization ioctls and calls the other initilization functions in this
- * file. Starts the CP engine via the DRM_RADEON_CP_START command.
- *
- * Setups a RADEONDRIRec structure to be passed to radeon_dri.so for its
- * initialization.
- */
-static int
-RADEONScreenInit( driDisplay *disp, RADEONInfoPtr info,
-                  RADEONDRIPtr pRADEONDRI)
-{
-   int i, err;
-
-   /* XXX this probably isn't needed here */
-   {
-      int  width_bytes = (disp->virtualWidth * disp->cpp);
-      int  maxy        = disp->fbSize / width_bytes;
-
-      if (maxy <= disp->virtualHeight * 3) {
-         _eglLog(_EGL_WARNING,
-                 "Static buffer allocation failed -- "
-                 "need at least %d kB video memory (have %d kB)\n",
-                 (disp->virtualWidth * disp->virtualHeight *
-                  disp->cpp * 3 + 1023) / 1024,
-                 disp->fbSize / 1024);
-         return 0;
-      }
-   }
-
-   /* Memory manager setup */
-   if (!RADEONMemoryInit(disp, info)) {
-      return 0;
-   }
-
-   /* Create a 'server' context so we can grab the lock for
-    * initialization ioctls.
-    */
-   if ((err = drmCreateContext(disp->drmFD, &disp->serverContext)) != 0) {
-      _eglLog(_EGL_WARNING, "%s: drmCreateContext failed %d\n",
-              __FUNCTION__, err);
-      return 0;
-   }
-
-   DRM_LOCK(disp->drmFD, disp->pSAREA, disp->serverContext, 0);
-
-   /* Initialize the kernel data structures */
-   if (!RADEONDRIKernelInit(disp, info)) {
-      _eglLog(_EGL_WARNING, "RADEONDRIKernelInit failed\n");
-      DRM_UNLOCK(disp->drmFD, disp->pSAREA, disp->serverContext);
-      return 0;
-   }
-
-   /* Initialize the vertex buffers list */
-   if (!RADEONDRIBufInit(disp, info)) {
-      fprintf(stderr, "RADEONDRIBufInit failed\n");
-      DRM_UNLOCK(disp->drmFD, disp->pSAREA, disp->serverContext);
-      return 0;
-   }
-
-   /* Initialize IRQ */
-   RADEONDRIIrqInit(disp, info);
-
-   /* Initialize kernel gart memory manager */
-   RADEONDRIAgpHeapInit(disp, info);
-
-   /* Initialize the SAREA private data structure */
-   {
-      drm_radeon_sarea_t *pSAREAPriv;
-      pSAREAPriv = (drm_radeon_sarea_t *)(((char*)disp->pSAREA) +
-                                        sizeof(drm_sarea_t));
-      memset(pSAREAPriv, 0, sizeof(*pSAREAPriv));
-      pSAREAPriv->pfState = info->page_flip_enable;
-   }
-
-   for ( i = 0;; i++ ) {
-      drmMapType type;
-      drmMapFlags flags;
-      drm_handle_t handle, offset;
-      drmSize size;
-      int rc, mtrr;
-
-      if ( ( rc = drmGetMap( disp->drmFD, i, &offset, &size, &type, &flags, &handle, &mtrr ) ) != 0 )
-         break;
-      if ( type == DRM_REGISTERS ) {
-         pRADEONDRI->registerHandle = offset;
-         pRADEONDRI->registerSize = size;
-         break;
-      }
-   }
-   /* Quick hack to clear the front & back buffers.  Could also use
-    * the clear ioctl to do this, but would need to setup hw state
-    * first.
-    */
-   drimemsetio((char *)disp->pFB + info->frontOffset,
-          0xEE,
-          info->frontPitch * disp->cpp * disp->virtualHeight );
-
-   drimemsetio((char *)disp->pFB + info->backOffset,
-          0x30,
-          info->backPitch * disp->cpp * disp->virtualHeight );
-
-
-   /* This is the struct passed to radeon_dri.so for its initialization */
-   pRADEONDRI->deviceID          = info->Chipset;
-   pRADEONDRI->width             = disp->virtualWidth;
-   pRADEONDRI->height            = disp->virtualHeight;
-   pRADEONDRI->depth             = disp->bpp; /* XXX: depth */
-   pRADEONDRI->bpp               = disp->bpp;
-   pRADEONDRI->IsPCI             = (disp->card_type != RADEON_CARD_AGP);;
-   pRADEONDRI->frontOffset       = info->frontOffset;
-   pRADEONDRI->frontPitch        = info->frontPitch;
-   pRADEONDRI->backOffset        = info->backOffset;
-   pRADEONDRI->backPitch         = info->backPitch;
-   pRADEONDRI->depthOffset       = info->depthOffset;
-   pRADEONDRI->depthPitch        = info->depthPitch;
-   pRADEONDRI->textureOffset     = info->textureOffset;
-   pRADEONDRI->textureSize       = info->textureSize;
-   pRADEONDRI->log2TexGran       = info->log2TexGran;
-   pRADEONDRI->statusHandle      = info->ringReadPtrHandle;
-   pRADEONDRI->statusSize        = info->ringReadMapSize;
-   pRADEONDRI->gartTexHandle      = info->gartTexHandle;
-   pRADEONDRI->gartTexMapSize     = info->gartTexMapSize;
-   pRADEONDRI->log2GARTTexGran    = info->log2GARTTexGran;
-   pRADEONDRI->gartTexOffset      = info->gartTexStart;
-   pRADEONDRI->sarea_priv_offset = sizeof(drm_sarea_t);
-
-   /* Don't release the lock now - let the VT switch handler do it. */
-
-   return 1;
-}
-
-
-/**
- * \brief Get Radeon chip family from chipset number.
- *
- * \param info driver private data.
- *
- * \return non-zero on success, or zero on failure.
- *
- * Called by radeonInitFBDev() to set RADEONInfoRec::ChipFamily
- * according to the value of RADEONInfoRec::Chipset.  Fails if the
- * chipset is unrecognized or not appropriate for this driver (i.e., not
- * an r100 style radeon)
- */
-static int get_chipfamily_from_chipset( RADEONInfoPtr info )
-{
-    switch (info->Chipset) {
-    case PCI_CHIP_RADEON_LY:
-    case PCI_CHIP_RADEON_LZ:
-        info->ChipFamily = CHIP_FAMILY_M6;
-        break;
-
-    case PCI_CHIP_RADEON_QY:
-    case PCI_CHIP_RADEON_QZ:
-        info->ChipFamily = CHIP_FAMILY_VE;
-        break;
-
-    case PCI_CHIP_R200_QL:
-    case PCI_CHIP_R200_QN:
-    case PCI_CHIP_R200_QO:
-    case PCI_CHIP_R200_Ql:
-    case PCI_CHIP_R200_BB:
-        info->ChipFamily = CHIP_FAMILY_R200;
-        break;
-
-    case PCI_CHIP_RV200_QW: /* RV200 desktop */
-    case PCI_CHIP_RV200_QX:
-        info->ChipFamily = CHIP_FAMILY_RV200;
-        break;
-
-    case PCI_CHIP_RADEON_LW:
-    case PCI_CHIP_RADEON_LX:
-        info->ChipFamily = CHIP_FAMILY_M7;
-        break;
-
-    case PCI_CHIP_RV250_Id:
-    case PCI_CHIP_RV250_Ie:
-    case PCI_CHIP_RV250_If:
-    case PCI_CHIP_RV250_Ig:
-        info->ChipFamily = CHIP_FAMILY_RV250;
-        break;
-
-    case PCI_CHIP_RV250_Ld:
-    case PCI_CHIP_RV250_Le:
-    case PCI_CHIP_RV250_Lf:
-    case PCI_CHIP_RV250_Lg:
-        info->ChipFamily = CHIP_FAMILY_M9;
-        break;
-
-    case PCI_CHIP_RV280_Y_:
-    case PCI_CHIP_RV280_Ya:
-    case PCI_CHIP_RV280_Yb:
-    case PCI_CHIP_RV280_Yc:
-        info->ChipFamily = CHIP_FAMILY_RV280;
-        break;
-
-    case PCI_CHIP_R300_ND:
-    case PCI_CHIP_R300_NE:
-    case PCI_CHIP_R300_NF:
-    case PCI_CHIP_R300_NG:
-        info->ChipFamily = CHIP_FAMILY_R300;
-        break;
-
-    case PCI_CHIP_RV370_5460:
-        info->ChipFamily = CHIP_FAMILY_RV380;
-       break;
-
-    default:
-        /* Original Radeon/7200 */
-        info->ChipFamily = CHIP_FAMILY_RADEON;
-    }
-
-    return 1;
-}
-
-
-/**
- * \brief Initialize the framebuffer device mode
- *
- * \param disp display handle.
- *
- * \return one on success, or zero on failure.
- *
- * Fills in \p info with some default values and some information from \p disp
- * and then calls RADEONScreenInit() for the screen initialization.
- *
- * Before exiting clears the framebuffer memory accessing it directly.
- */
-static int radeonInitFBDev( driDisplay *disp, RADEONDRIPtr pRADEONDRI )
-{
-   int err;
-   RADEONInfoPtr info = calloc(1, sizeof(*info));
-
-   disp->driverPrivate = (void *)info;
-
-   info->gartFastWrite  = RADEON_DEFAULT_AGP_FAST_WRITE;
-   info->gartSize       = RADEON_DEFAULT_AGP_SIZE;
-   info->gartTexSize    = RADEON_DEFAULT_AGP_TEX_SIZE;
-   info->bufSize       = RADEON_DEFAULT_BUFFER_SIZE;
-   info->ringSize      = RADEON_DEFAULT_RING_SIZE;
-   info->page_flip_enable = RADEON_DEFAULT_PAGE_FLIP;
-
-   fprintf(stderr,
-           "Using %d MB AGP aperture\n", info->gartSize);
-   fprintf(stderr,
-           "Using %d MB for the ring buffer\n", info->ringSize);
-   fprintf(stderr,
-           "Using %d MB for vertex/indirect buffers\n", info->bufSize);
-   fprintf(stderr,
-           "Using %d MB for AGP textures\n", info->gartTexSize);
-   fprintf(stderr,
-           "page flipping %sabled\n", info->page_flip_enable?"en":"dis");
-
-   info->Chipset = disp->chipset;
-
-   if (!get_chipfamily_from_chipset( info )) {
-      fprintf(stderr, "Unknown or non-radeon chipset -- cannot continue\n");
-      fprintf(stderr, "==> Verify PCI BusID is correct in miniglx.conf\n");
-      return 0;
-   }
-#if 0
-   if (info->ChipFamily >= CHIP_FAMILY_R300) {
-      fprintf(stderr,
-              "Direct rendering not yet supported on "
-              "Radeon 9700 and newer cards\n");
-      return 0;
-   }
-#endif
-
-#if 00
-   /* don't seem to need this here */
-   info->frontPitch = disp->virtualWidth;
-#endif
-
-   /* Check the radeon DRM version */
-   if (!RADEONCheckDRMVersion(disp, info)) {
-      return 0;
-   }
-
-   if (RADEONGetCardType(disp, info)<0)
-      return 0;
-
-   if (disp->card_type!=RADEON_CARD_AGP) {
-      /* Initialize PCI */
-      if (!RADEONDRIPciInit(disp, info))
-         return 0;
-   }
-   else {
-      /* Initialize AGP */
-      if (!RADEONDRIAgpInit(disp, info))
-         return 0;
-   }
-
-   if (!RADEONScreenInit( disp, info, pRADEONDRI))
-      return 0;
-
-   /* Initialize and start the CP if required */
-   if ((err = drmCommandNone(disp->drmFD, DRM_RADEON_CP_START)) != 0) {
-      fprintf(stderr, "%s: CP start %d\n", __FUNCTION__, err);
-      return 0;
-   }
-
-   return 1;
-}
-
-
-/**
- * Create list of all supported surface configs, attach list to the display.
- */
-static EGLBoolean
-radeonFillInConfigs(_EGLDisplay *disp, unsigned pixel_bits,
-                    unsigned depth_bits,
-                    unsigned stencil_bits, GLboolean have_back_buffer)
-{
-   _EGLConfig *configs;
-   _EGLConfig *c;
-   unsigned int i, num_configs;
-   unsigned int depth_buffer_factor;
-   unsigned int back_buffer_factor;
-   GLenum fb_format;
-   GLenum fb_type;
-
-   /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
-   * enough to add support.  Basically, if a context is created with an
-   * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
-   * will never be used.
-   */
-   static const GLenum back_buffer_modes[] = {
-            GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
-         };
-
-   uint8_t depth_bits_array[2];
-   uint8_t stencil_bits_array[2];
-
-   depth_bits_array[0] = depth_bits;
-   depth_bits_array[1] = depth_bits;
-
-   /* Just like with the accumulation buffer, always provide some modes
-   * with a stencil buffer.  It will be a sw fallback, but some apps won't
-   * care about that.
-   */
-   stencil_bits_array[0] = 0;
-   stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
-
-   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
-   back_buffer_factor = (have_back_buffer) ? 2 : 1;
-
-   num_configs = depth_buffer_factor * back_buffer_factor * 2;
-
-   if (pixel_bits == 16) {
-      fb_format = GL_RGB;
-      fb_type = GL_UNSIGNED_SHORT_5_6_5;
-   } else {
-      fb_format = GL_RGBA;
-      fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-   }
-
-   configs = calloc(sizeof(*configs), num_configs);
-   c = configs;
-   if (!_eglFillInConfigs(c, fb_format, fb_type,
-                          depth_bits_array, stencil_bits_array,
-                          depth_buffer_factor,
-                          back_buffer_modes, back_buffer_factor,
-                          GLX_TRUE_COLOR)) {
-      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n",
-               __func__, __LINE__);
-      return EGL_FALSE;
-   }
-
-   /* Mark the visual as slow if there are "fake" stencil bits.
-   */
-   for (i = 0, c = configs; i < num_configs; i++, c++) {
-      int stencil = GET_CONFIG_ATTRIB(c, EGL_STENCIL_SIZE);
-      if ((stencil != 0)  && (stencil != stencil_bits)) {
-         SET_CONFIG_ATTRIB(c, EGL_CONFIG_CAVEAT, EGL_SLOW_CONFIG);
-      }
-   }
-
-   for (i = 0, c = configs; i < num_configs; i++, c++)
-      _eglAddConfig(disp, c);
-
-   free(configs);
-
-   return EGL_TRUE;
-}
-
-
-/**
- * Show the given surface on the named screen.
- * If surface is EGL_NO_SURFACE, disable the screen's output.
- */
-static EGLBoolean
-radeonShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
-                      EGLSurface surface, EGLModeMESA m)
-{
-   EGLBoolean b = _eglDRIShowScreenSurfaceMESA(drv, dpy, screen, surface, m);
-   return b;
-}
-
-
-/**
- * Called via eglInitialize() by user.
- */
-static EGLBoolean
-radeonInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor)
-{
-   __DRIframebuffer framebuffer;
-   driDisplay *display;
-
-   /* one-time init */
-   radeon_drm_page_size = getpagesize();
-
-   if (!_eglDRIInitialize(drv, dpy, major, minor))
-      return EGL_FALSE;
-
-   display = Lookup_driDisplay(dpy);
-
-   framebuffer.dev_priv_size = sizeof(RADEONDRIRec);
-   framebuffer.dev_priv = malloc(sizeof(RADEONDRIRec));
-
-   /* XXX we shouldn't hard-code values here! */
-   /* we won't know the screen surface size until the user calls
-    * eglCreateScreenSurfaceMESA().
-    */
-#if 0
-   display->virtualWidth = 1024;
-   display->virtualHeight = 768;
-#else
-   display->virtualWidth = 1280;
-   display->virtualHeight = 1024;
-#endif
-   display->bpp = 32;
-   display->cpp = 4;
-
-   if (!_eglDRIGetDisplayInfo(display))
-      return EGL_FALSE;
-
-   framebuffer.base = display->pFB;
-   framebuffer.width = display->virtualWidth;
-   framebuffer.height = display->virtualHeight;
-   framebuffer.stride = display->virtualWidth;
-   framebuffer.size = display->fbSize;
-   radeonInitFBDev( display, framebuffer.dev_priv );
-
-   if (!_eglDRICreateDisplay(display, &framebuffer))
-      return EGL_FALSE;
-
-   if (!_eglDRICreateScreens(display))
-      return EGL_FALSE;
-
-   /* create a variety of both 32 and 16-bit configurations */
-   radeonFillInConfigs(&display->Base, 32, 24, 8, GL_TRUE);
-   radeonFillInConfigs(&display->Base, 16, 16, 0, GL_TRUE);
-
-   drv->Initialized = EGL_TRUE;
-   return EGL_TRUE;
-}
-
-
-/**
- * The bootstrap function.  Return a new radeonDriver object and
- * plug in API functions.
- */
-_EGLDriver *
-_eglMain(_EGLDisplay *dpy)
-{
-   radeonDriver *radeon;
-
-   radeon = (radeonDriver *) calloc(1, sizeof(*radeon));
-   if (!radeon) {
-      return NULL;
-   }
-
-   /* First fill in the dispatch table with defaults */
-   _eglDRIInitDriverFallbacks(&radeon->Base);
-
-   /* then plug in our radeon-specific functions */
-   radeon->Base.API.Initialize = radeonInitialize;
-   radeon->Base.API.ShowScreenSurfaceMESA = radeonShowScreenSurfaceMESA;
-
-   return &radeon->Base;
-}
index d17a160271dbbf24ed6cf6888660f3d6e76b1753..9da96bdd45a836bf1d80210a13d49f14635527c7 100644 (file)
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/formats.h"
-#include "main/matrix.h"
-#include "main/state.h"
 #include "main/simple_list.h"
-#include "main/extensions.h"
 #include "main/framebuffer.h"
 #include "main/renderbuffer.h"
 
index 8d4edfa30587c378c67800e18b86e7065e5045ef..c9a31f3383c8a270ec3487c8d6133e6fee9c9ced 100644 (file)
@@ -34,7 +34,6 @@
 #include "via_context.h"
 #include "via_tris.h"
 #include "via_ioctl.h"
-#include "via_state.h"
 #include "via_fb.h"
 #include "via_3d_reg.h"
 
index f676cc13c815bce19679246fd6ce955394862e4f..896c43db1b03870e7ab06622c461601fb88b462f 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "via_context.h"
 #include "via_tris.h"
-#include "via_state.h"
 #include "via_ioctl.h"
 
 /*
index 2cfb98317da1ee576466830cb0261c0af1b4ccf8..8c91c937c686dd2cc0456bae8617f4d765f5b05f 100644 (file)
 #include "main/context.h"
 #include "main/framebuffer.h"
 #include "main/renderbuffer.h"
-#include "main/matrix.h"
 #include "main/simple_list.h"
 #include "vblank.h"
 
 #include "via_state.h"
 #include "via_tex.h"
 #include "via_span.h"
-#include "via_tris.h"
-#include "via_ioctl.h"
 #include "via_screen.h"
-#include "via_fb.h"
 #include "via_dri.h"
 
 #include "GL/internal/dri_interface.h"
index e6e5526d344f4218342b18286bd4c948939ad9bc..f7029b9492809dddda69232238347a1fe6238f02 100644 (file)
@@ -35,7 +35,6 @@
 #include "via_context.h"
 #include "via_state.h"
 #include "via_tex.h"
-#include "via_tris.h"
 #include "via_ioctl.h"
 #include "via_3d_reg.h"
 
@@ -44,8 +43,6 @@
 #include "tnl/tnl.h"
 #include "swrast_setup/swrast_setup.h"
 
-#include "tnl/t_pipeline.h"
-
 
 static GLuint ROP[16] = {
     HC_HROP_BLACK,    /* GL_CLEAR           0                          */
index 24924d261382f2652627fbe50be739c20dde71c8..917f975466942dea5a32361af9551cefdb19483e 100644 (file)
 #include "main/mipmap.h"
 #include "main/mm.h"
 #include "main/simple_list.h"
-#include "main/texcompress.h"
 #include "main/texobj.h"
 #include "main/texstore.h"
 
 #include "via_context.h"
 #include "via_fb.h"
 #include "via_tex.h"
-#include "via_state.h"
 #include "via_ioctl.h"
 #include "via_3d_reg.h"
 
index b64689784866323f142adff95f106468f299ceb0..f87ba071f3b83363deb130e270d54fc990b0013c 100644 (file)
@@ -38,7 +38,6 @@
 #include "main/enums.h"
 
 #include "via_context.h"
-#include "via_state.h"
 #include "via_tex.h"
 #include "via_3d_reg.h"
 
index 846c041cde1798cad9b8d183cffd93136b1356d4..bfc3db4313c2b115dff055d07b405323772c060c 100644 (file)
@@ -25,6 +25,7 @@ GLX_DIR = $(XORG_BASE)/glx
 SERVER_GLAPI_FILES = \
        $(GLX_DIR)/glapi.h \
        $(GLX_DIR)/glapi.c \
+       $(GLX_DIR)/glapi_nop.c \
        $(GLX_DIR)/glthread.c \
        $(GLX_DIR)/glthread.h
 
index 09b0d364ce3032fe87465ffe6217c8cdd9e3144c..41a40fbeb681d28c33a7de5b948ae0671fc263ca 100644 (file)
@@ -180,7 +180,7 @@ class PrintGlOffsets(gl_XML.gl_print_base):
 #error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined
 #endif
 
-static _glapi_proc DISPATCH_TABLE_NAME[] = {"""
+_glapi_proc DISPATCH_TABLE_NAME[] = {"""
                for f in api.functionIterateByOffset():
                        print '   TABLE_ENTRY(%s),' % (f.dispatch_name())
 
@@ -204,7 +204,7 @@ static _glapi_proc DISPATCH_TABLE_NAME[] = {"""
  * We list the functions which are not otherwise used.
  */
 #ifdef UNUSED_TABLE_NAME
-static _glapi_proc UNUSED_TABLE_NAME[] = {"""
+_glapi_proc UNUSED_TABLE_NAME[] = {"""
 
                normal_entries = []
                proto_entries = []
index adb47f9fecb0047a97b05eeaf56fbebfe97f0596..469523d57cffd5ca08a72a5778a983685db6933e 100644 (file)
 #include "glapi/glapioffsets.h"
 #include "glapi/glapitable.h"
 
-/***** BEGIN NO-OP DISPATCH *****/
-
-static GLboolean WarnFlag = GL_FALSE;
-static _glapi_warning_func warning_func;
-
-/*
- * Enable/disable printing of warning messages.
- */
-PUBLIC void
-_glapi_noop_enable_warnings(GLboolean enable)
-{
-   WarnFlag = enable;
-}
-
-/*
- * Register a callback function for reporting errors.
- */
-PUBLIC void
-_glapi_set_warning_func( _glapi_warning_func func )
-{
-   warning_func = func;
-}
-
-static int
-warn(const char *func)
-{
-#if !defined(_WIN32_WCE)
-   if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
-       && warning_func) {
-      warning_func(NULL, "GL User Error: called without context: %s", func);
-   }
-#endif
-   return 0;
-}
-
-#ifdef DEBUG
-
-#define KEYWORD1 static
-#define KEYWORD1_ALT static
-#define KEYWORD2 GLAPIENTRY
-#define NAME(func)  NoOp##func
-
-#define F NULL
-
-#define DISPATCH(func, args, msg)                                            \
-   warn(#func);
-
-#define RETURN_DISPATCH(func, args, msg)                                     \
-   return warn(#func);
-
-#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
-
-#else
-
-static void
-NoOpGeneric(void)
-{
-   if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
-       && warning_func) {
-      warning_func(NULL, "GL User Error: calling GL function");
-   }
-}
-
-#define TABLE_ENTRY(name) (_glapi_proc) NoOpGeneric
-
-#endif
-
-#define DISPATCH_TABLE_NAME __glapi_noop_table
-#define UNUSED_TABLE_NAME __unused_noop_functions
-
-static GLint NoOpUnused(void)
-{
-   return warn("extension function");
-}
-
-#include "glapi/glapitemp.h"
-
-/***** END NO-OP DISPATCH *****/
-
+extern _glapi_proc __glapi_noop_table[];
 
 
 /**
@@ -278,7 +200,6 @@ _glapi_check_multithread(void)
 PUBLIC void
 _glapi_set_context(void *context)
 {
-   (void) __unused_noop_functions; /* silence a warning */
 #if defined(GLX_USE_TLS)
    _glapi_tls_Context = context;
 #elif defined(THREADS)
index 5fb5401229aeb124982be07a8c46af8f39caf7a5..47ea23e92b50cd6c9fb0b2ff7ebf0bf19d6246ff 100644 (file)
@@ -55,8 +55,6 @@ struct _glapi_table;
 
 typedef void (*_glapi_proc)(void); /* generic function pointer */
 
-typedef void (*_glapi_warning_func)(void *ctx, const char *str, ...);
-
 
 #if defined(USE_MGL_NAMESPACE)
 #define _glapi_set_dispatch _mglapi_set_dispatch
@@ -106,12 +104,6 @@ extern struct _glapi_table *_glapi_Dispatch;
  ** GL API public functions
  **/
 
-extern void
-_glapi_noop_enable_warnings(GLboolean enable);
-
-extern void
-_glapi_set_warning_func(_glapi_warning_func func);
-
 extern void
 _glapi_check_multithread(void);
 
diff --git a/src/mesa/glapi/glapi_nop.c b/src/mesa/glapi/glapi_nop.c
new file mode 100644 (file)
index 0000000..5d2769c
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.8
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2010  VMWare, Inc.  All Rights Reserved.
+ *
+ * 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 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 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.
+ */
+
+
+/**
+ * No-op dispatch table.
+ *
+ * This file defines a special dispatch table which is loaded with no-op
+ * functions.
+ *
+ * When there's no current rendering context, calling a GL function like
+ * glBegin() is a no-op.  Apps should never normally do this.  So as a
+ * debugging aid, each of the no-op functions will emit a warning to
+ * stderr if the MESA_DEBUG or LIBGL_DEBUG env var is set.
+ */
+
+
+
+#include "main/compiler.h"
+#include "main/glheader.h"
+#include "glapi/glapi.h"
+
+
+/**
+ * Called by each of the no-op GL entrypoints.
+ */
+static int
+Warn(const char *func)
+{
+#if !defined(_WIN32_WCE)
+   if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) {
+      fprintf(stderr, "GL User Error: gl%s called without a rendering context\n",
+              func);
+   }
+#endif
+   return 0;
+}
+
+
+/**
+ * This is called if the user somehow calls an unassigned GL dispatch function.
+ */
+static GLint
+NoOpUnused(void)
+{
+   return Warn(" function");
+}
+
+
+/*
+ * Defines for the glapitemp.h functions.
+ */
+#define KEYWORD1 static
+#define KEYWORD1_ALT static
+#define KEYWORD2 GLAPIENTRY
+#define NAME(func)  NoOp##func
+#define DISPATCH(func, args, msg)  Warn(#func);
+#define RETURN_DISPATCH(func, args, msg)  Warn(#func); return 0
+
+
+/*
+ * Defines for the table of no-op entry points.
+ */
+#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
+#define DISPATCH_TABLE_NAME __glapi_noop_table
+#define UNUSED_TABLE_NAME __unused_noop_functions
+
+
+#include "glapi/glapitemp.h"
index b8bfcc1a160e225c4b10f598366a34c079bc12ee..2540ef6465777cf95d4b8eba77b978676dabadf4 100644 (file)
@@ -5764,7 +5764,7 @@ KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_366)(GLenum target, GLenum pname,
 #error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined
 #endif
 
-static _glapi_proc DISPATCH_TABLE_NAME[] = {
+_glapi_proc DISPATCH_TABLE_NAME[] = {
    TABLE_ENTRY(NewList),
    TABLE_ENTRY(EndList),
    TABLE_ENTRY(CallList),
@@ -6680,7 +6680,7 @@ static _glapi_proc DISPATCH_TABLE_NAME[] = {
  * We list the functions which are not otherwise used.
  */
 #ifdef UNUSED_TABLE_NAME
-static _glapi_proc UNUSED_TABLE_NAME[] = {
+_glapi_proc UNUSED_TABLE_NAME[] = {
 #ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS
    TABLE_ENTRY(ArrayElementEXT),
    TABLE_ENTRY(BindTextureEXT),
index 0641b98b3b78a88056751d406f962e4ff39d6b6a..3fbdba2b3fe66e8637045b57c5f187d295f29a2e 100644 (file)
@@ -33,7 +33,6 @@
 #include "bufferobj.h"
 #include "clear.h"
 #include "colormac.h"
-#include "colortab.h"
 #include "context.h"
 #include "depth.h"
 #include "enable.h"
index b8170dd46860eaecfc7c4fba38c28527c366ce9d..de60031cc80d802992096de7ed04964ee812f642 100644 (file)
@@ -35,7 +35,6 @@
 #include "enums.h"
 #include "macros.h"
 #include "mtypes.h"
-#include "glapi/glapitable.h"
 
 
 /**
index 97f065975819e7710b6080adbfcba5b7a8aef2ba..fb30b5996093542fd9903db8d95c15f381ad923a 100644 (file)
@@ -35,8 +35,6 @@
 #include "colormac.h"
 #include "context.h"
 #include "enums.h"
-#include "fbobject.h"
-#include "state.h"
 
 
 #define BAD_MASK ~0u
index 320c59068cc55562bb56490c87ebb57bc9df2c04..a570506d57b34ef2783f26ca6919439697bbcc34 100644 (file)
@@ -415,14 +415,6 @@ one_time_init( GLcontext *ctx )
          _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
       }
 
-      if (_mesa_getenv("MESA_DEBUG")) {
-         _glapi_noop_enable_warnings(GL_TRUE);
-         _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
-      }
-      else {
-         _glapi_noop_enable_warnings(GL_FALSE);
-      }
-
 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
       _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
                   MESA_VERSION_STRING, __DATE__, __TIME__);
index 8db3e79d384c6ff10d97cfdcc2feb2fad9e4c3d5..5ed93e0c600459623014a192b797d5ad4d69aa5e 100644 (file)
@@ -38,7 +38,6 @@
 #include "context.h"
 #include "image.h"
 #include "mtypes.h"
-#include "pixel.h"
 #include "state.h"
 #include "glapi/dispatch.h"
 
index a42113edcacac962204ad3317705dfbccc1cd7cf..9bad83487fbb7042b55af07806d9d3e03b7a751a 100644 (file)
@@ -26,7 +26,6 @@
 #include "mtypes.h"
 #include "attrib.h"
 #include "colormac.h"
-#include "context.h"
 #include "enums.h"
 #include "formats.h"
 #include "hash.h"
@@ -35,7 +34,6 @@
 #include "get.h"
 #include "pixelstore.h"
 #include "readpix.h"
-#include "texgetimage.h"
 #include "texobj.h"
 
 
@@ -54,7 +52,7 @@ const char *_mesa_prim_name[GL_POLYGON+4] = {
    "GL_QUAD_STRIP",
    "GL_POLYGON",
    "outside begin/end",
-   "inside unkown primitive",
+   "inside unknown primitive",
    "unknown state"
 };
 
index 193c7f8255fe9e4d246a7105b98b12ec8d8f26f4..49946a65062674b1ea66e9a32228d1da75caa433 100644 (file)
@@ -25,7 +25,6 @@
 #include "glheader.h"
 #include "imports.h"
 #include "context.h"
-#include "fbobject.h"
 #include "formats.h"
 #include "mtypes.h"
 #include "depthstencil.h"
index 21a8216254bebc11e128fddaf6f934aa4c7aa3d1..7db686c0aef2ee2e5b497b93f31248abe93ec879 100644 (file)
 #include "api_loopback.h"
 #include "config.h"
 #include "mfeatures.h"
-#include "attrib.h"
-#include "blend.h"
-#include "buffers.h"
 #if FEATURE_ARB_vertex_buffer_object
 #include "bufferobj.h"
 #endif
 #include "arrayobj.h"
-#include "clip.h"
-#include "colortab.h"
 #include "context.h"
-#include "convolve.h"
-#include "depth.h"
 #include "dlist.h"
-#include "enable.h"
 #include "enums.h"
 #include "eval.h"
-#include "extensions.h"
-#include "feedback.h"
 #include "framebuffer.h"
-#include "get.h"
 #include "glapi/glapi.h"
 #include "hash.h"
-#include "histogram.h"
 #include "image.h"
 #include "light.h"
-#include "lines.h"
 #include "dlist.h"
 #include "macros.h"
-#include "matrix.h"
-#include "pixel.h"
-#include "points.h"
-#include "polygon.h"
 #include "queryobj.h"
-#include "state.h"
-#include "texobj.h"
 #include "teximage.h"
-#include "texstate.h"
 #include "mtypes.h"
 #include "varray.h"
-#include "vtxfmt.h"
 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
 #include "shader/arbprogram.h"
 #include "shader/program.h"
index 5d4b53af4cbec89a8b0fa0def63e1444b0ada3a6..0afd47b797fa1e3ae5acf583b72958fc98a89e68 100644 (file)
@@ -30,7 +30,6 @@
 #include "enums.h"
 #include "feedback.h"
 #include "framebuffer.h"
-#include "image.h"
 #include "readpix.h"
 #include "state.h"
 #include "glapi/dispatch.h"
index cd6e881ad2d93f082c4061100ded10155cda9d5c..f5c88a63e6e7e95c2318e7095b93cf1f5c8ca355 100644 (file)
@@ -32,7 +32,6 @@
 #include "context.h"
 #include "enable.h"
 #include "light.h"
-#include "macros.h"
 #include "simple_list.h"
 #include "mtypes.h"
 #include "enums.h"
index 4da245ab4950f630349f501f141336350ede93fc..0556f168501f66a827836032f7346178ab4f8a61 100644 (file)
 #include "framebuffer.h"
 #include "hash.h"
 #include "macros.h"
-#include "mipmap.h"
 #include "renderbuffer.h"
 #include "state.h"
 #include "teximage.h"
 #include "texobj.h"
-#include "texstore.h"
-#include "texstate.h"
 
 
 /** Set this to 1 to help debug FBO incompleteness problems */
index 5983f00e2dde5a357c6399ed519d6a3bb1345a71..d0c9c0028b2cea90d3bc0bedbe2410523f092c1d 100644 (file)
@@ -27,7 +27,6 @@
 #include "imports.h"
 #include "formats.h"
 #include "config.h"
-#include "texstore.h"
 
 
 /**
index fc278bb8afae59a77be1ddba5e7a1b1df4609b6d..81993e7063b4d13badb9ca542d78c61293923e7f 100644 (file)
@@ -37,7 +37,6 @@
 #include "image.h"
 #include "imports.h"
 #include "macros.h"
-#include "pixel.h"
 
 
 /**
index 81d0d33abb405ab9fd1ad5fbb246daedb447b213..cc63a759ec09fc47b6d627b7c5fcfa2563e0f53c 100644 (file)
 
 #include "glheader.h"
 #include "context.h"
-#include "depth.h"
 #include "lines.h"
 #include "macros.h"
-#include "texstate.h"
 #include "mtypes.h"
 
 
index 7350c7a3d2cf3933db86ffd54a182815b8bcb956..77cd1d4159578811882d3553308c87af9810642f 100644 (file)
@@ -30,7 +30,6 @@
 #include "imports.h"
 #include "formats.h"
 #include "mipmap.h"
-#include "texcompress.h"
 #include "teximage.h"
 #include "texstore.h"
 #include "image.h"
index 3820ebd88945849bf3fa52cf4995fb20555075cf..f6f9c1173a1473053280d61e293aa341e764681e 100644 (file)
@@ -32,7 +32,6 @@
 #include "bufferobj.h"
 #include "colormac.h"
 #include "context.h"
-#include "image.h"
 #include "macros.h"
 #include "pixel.h"
 #include "mtypes.h"
index 6a641f83f27fea499748db7b4d1388e245fba0fd..ec585ef0ccefb560d4fac4e3f09afbcccb70a2f9 100644 (file)
 
 #include "glheader.h"
 #include "bufferobj.h"
-#include "colormac.h"
 #include "context.h"
-#include "image.h"
-#include "macros.h"
 #include "pixelstore.h"
 #include "mtypes.h"
 
index dcaeccd90d4df4747320fae12024ee7f9065295d..e743a2e6bdb9c17c4181864d9bf626460ef42849 100644 (file)
@@ -32,7 +32,6 @@
 #include "context.h"
 #include "macros.h"
 #include "points.h"
-#include "texstate.h"
 #include "mtypes.h"
 
 
index 376a87a396770a8996980b27cd48d9dda9004d4b..dcde6758c3f7311bb34e0b4f9c039824859f61ec 100644 (file)
@@ -34,7 +34,6 @@
 #include "context.h"
 #include "image.h"
 #include "enums.h"
-#include "macros.h"
 #include "polygon.h"
 #include "mtypes.h"
 
index f10e6b04b7ccee4bb5a9072910bcb0ec24e9c616..904ad01205282209b6d92d4b3bb6a237583005dc 100644 (file)
@@ -48,7 +48,6 @@
 #include "texenvprogram.h"
 #include "texobj.h"
 #include "texstate.h"
-#include "viewport.h"
 
 
 static void
index a4f1926ab3789d11351f242fd60a88de3688ab82..cff6de89ee30bd2e0c8278902cfdae779c337d1e 100644 (file)
 #include "colormac.h"
 #include "context.h"
 #include "formats.h"
-#include "image.h"
-#include "mipmap.h"
 #include "texcompress.h"
-#include "texstore.h"
 
 
 /**
index 1a374e7bee51ecffb144c5322c3d6ed6e7e7a411..096945a6432b4dc50c797bd543848a177c1a9675 100644 (file)
@@ -35,8 +35,6 @@
 
 #include "context.h"
 #include "texcompress.h"
-#include "texcompress_fxt1.h"
-#include "texcompress_s3tc.h"
 #include "texformat.h"
 
 
index d7943eaa1e91b8c6a0a5f75d6fbdda4f17e2fc2c..66d01c15d04ffe657928dd00f6684941e45ed59d 100644 (file)
 #include "context.h"
 #include "formats.h"
 #include "image.h"
-#include "texcompress.h"
 #include "texgetimage.h"
 #include "teximage.h"
-#include "texstate.h"
 
 
 
index b946f3c69d7e846f9dc6c09ac60b377d4c82d62f..76273b02676b71b5de01af9c6322cf374ea3a1ae 100644 (file)
@@ -46,7 +46,6 @@
 #include "texfetch.h"
 #include "teximage.h"
 #include "texstate.h"
-#include "texstore.h"
 #include "mtypes.h"
 
 
index 7f0a246025ab1d7319b93f5eb423aa460c13375d..9db95814d0030f0b607d34309bc41393c27a8ed7 100644 (file)
@@ -38,7 +38,6 @@
 #include "imports.h"
 #include "macros.h"
 #include "teximage.h"
-#include "texstate.h"
 #include "texobj.h"
 #include "mtypes.h"
 #include "shader/prog_instruction.h"
index d917e21e744a3b76d5dfb6e8bfb29c870691ec2f..c4f249501878c530060d15c0f8bc949c1fc1a9fd 100644 (file)
@@ -33,7 +33,6 @@
 #include "main/glheader.h"
 #include "main/colormac.h"
 #include "main/context.h"
-#include "main/enums.h"
 #include "main/formats.h"
 #include "main/macros.h"
 #include "main/texcompress.h"
index c735e18affbea16ba73ad52025d556dc3c8cef38..25333d8994a4500c33f705437103d67f75c5ea8b 100644 (file)
 #include "context.h"
 #include "enums.h"
 #include "macros.h"
-#include "texcompress.h"
 #include "texobj.h"
 #include "teximage.h"
 #include "texstate.h"
-#include "texenvprogram.h"
 #include "mtypes.h"
 
 
index 792c83141ec67e813c91fbe5db56cf0fbc941740..fcd0a56d76aabf45a78a28ddd0034b2d27462725 100644 (file)
@@ -263,7 +263,7 @@ compute_component_mapping(GLenum inFormat, GLenum outFormat,
    map[ZERO] = ZERO;
    map[ONE] = ONE;   
 
-/*
+#if 0
    _mesa_printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
                inFormat, _mesa_lookup_enum_by_nr(inFormat),
                outFormat, _mesa_lookup_enum_by_nr(outFormat),
@@ -273,7 +273,7 @@ compute_component_mapping(GLenum inFormat, GLenum outFormat,
                map[3], 
                map[4], 
                map[5]); 
-*/
+#endif
 }
 
 
index c9eea8ab8300ab34ddf3d818eba289dddae03f0d..0dd3e5e52ee55969741adf4dc1ba9ce7d33efe51 100644 (file)
 
 #include "glheader.h"
 #include "api_arrayelt.h"
-#include "api_loopback.h"
 #include "context.h"
 #include "imports.h"
 #include "mtypes.h"
-#include "state.h"
 #include "vtxfmt.h"
 #include "eval.h"
 #include "dlist.h"
index 3e22a8a3057a5525f6af8eb7a9e3bdfaf104edf2..bdd26b7f3a7f1a43dac7ee1594bedf5d52e8d9ef 100644 (file)
@@ -54,10 +54,8 @@ having three separate program parameter arrays.
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/context.h"
-#include "main/macros.h"
 #include "main/mtypes.h"
 #include "arbprogparse.h"
-#include "program.h"
 #include "programopt.h"
 #include "prog_parameter.h"
 #include "prog_statevars.h"
index eb537cd1b99bc1e9a3987c7f9063e5a5052ac40f..746138071edaf882d9cb432c9058a9b7fcff2be1 100644 (file)
@@ -180,23 +180,24 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
          }
          else if (prog) {
             /* Unbind program if necessary */
-            if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */
-                prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
+            switch (prog->Target) {
+            case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
+            case GL_VERTEX_STATE_PROGRAM_NV:
                if (ctx->VertexProgram.Current &&
                    ctx->VertexProgram.Current->Base.Id == ids[i]) {
                   /* unbind this currently bound program */
                   _mesa_BindProgram(prog->Target, 0);
                }
-            }
-            else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
-                     prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
+               break;
+            case GL_FRAGMENT_PROGRAM_NV:
+            case GL_FRAGMENT_PROGRAM_ARB:
                if (ctx->FragmentProgram.Current &&
                    ctx->FragmentProgram.Current->Base.Id == ids[i]) {
                   /* unbind this currently bound program */
                   _mesa_BindProgram(prog->Target, 0);
                }
-            }
-            else {
+               break;
+            default:
                _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
                return;
             }
@@ -561,6 +562,8 @@ _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
    }
 }
 
+
+
 /**
  * Set a program env parameter register.
  * \note Called from the GL API dispatcher.
@@ -569,10 +572,35 @@ _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
  */
 void GLAPIENTRY
 _mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
-                                   const GLfloat *params)
+                                const GLfloat *params)
 {
-   _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
-                                  params[2], params[3]);
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+
+   if (target == GL_FRAGMENT_PROGRAM_ARB
+       && ctx->Extensions.ARB_fragment_program) {
+      if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter4fv(index)");
+         return;
+      }
+      memcpy(ctx->FragmentProgram.Parameters[index], params,
+             4 * sizeof(GLfloat));
+   }
+   else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
+       && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
+      if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter4fv(index)");
+         return;
+      }
+      memcpy(ctx->VertexProgram.Parameters[index], params,
+             4 * sizeof(GLfloat));
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter4fv(target)");
+      return;
+   }
 }
 
 
@@ -581,7 +609,6 @@ _mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
                                 const GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
-   GLint i;
    GLfloat * dest;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -612,11 +639,7 @@ _mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
       return;
    }
 
-   for ( i = 0 ; i < count ; i++ ) {
-      COPY_4V(dest, params);
-      params += 4;
-      dest += 4;
-   }
+   memcpy(dest, params, count * 4 * sizeof(GLfloat));
 }
 
 
@@ -729,8 +752,7 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
                                   const GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct gl_program *prog;
-   GLint i;
+   GLfloat *dest;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
@@ -745,7 +767,7 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
          _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
          return;
       }
-      prog = &(ctx->FragmentProgram.Current->Base);
+      dest = ctx->FragmentProgram.Current->Base.LocalParams[index];
    }
    else if (target == GL_VERTEX_PROGRAM_ARB
             && ctx->Extensions.ARB_vertex_program) {
@@ -753,18 +775,14 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
          _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
          return;
       }
-      prog = &(ctx->VertexProgram.Current->Base);
+      dest = ctx->VertexProgram.Current->Base.LocalParams[index];
    }
    else {
       _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
       return;
    }
 
-   for (i = 0; i < count; i++) {
-      ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
-      COPY_4V(prog->LocalParams[index + i], params);
-      params += 4;
-   }
+   memcpy(dest, params, count * 4 * sizeof(GLfloat));
 }
 
 
index 68543ae2e1282e6167bd9ccede29f3f67afba5d7..d1af35fedb6f0c89f149c5300011655f566dfc1b 100644 (file)
@@ -1043,12 +1043,12 @@ static yyconst flex_int16_t yy_chk[1368] =
  */
 #include "main/glheader.h"
 #include "main/imports.h"
-#include "prog_instruction.h"
-#include "prog_statevars.h"
+#include "shader/prog_instruction.h"
+#include "shader/prog_statevars.h"
 
-#include "symbol_table.h"
-#include "program_parser.h"
-#include "program_parse.tab.h"
+#include "shader/symbol_table.h"
+#include "shader/program_parser.h"
+#include "shader/program_parse.tab.h"
 
 #define require_ARB_vp (yyextra->mode == ARB_vertex)
 #define require_ARB_fp (yyextra->mode == ARB_fragment)
index 8574016050c60a63391b8a315ca5b75eb6985397..baff7658d1822bf29c543ef4df4f8716b1553806 100644 (file)
@@ -40,7 +40,6 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/imports.h"
-#include "main/macros.h"
 #include "nvprogram.h"
 #include "nvvertparse.h"
 #include "prog_instruction.h"
index 7f034520cd474ff967af35748107074fdfc3f15c..c212790dcd9f21c78cfe48ac8901432f427a9ba6 100644 (file)
@@ -38,7 +38,6 @@
 #include "main/glheader.h"
 #include "main/colormac.h"
 #include "main/context.h"
-#include "program.h"
 #include "prog_execute.h"
 #include "prog_instruction.h"
 #include "prog_parameter.h"
@@ -352,6 +351,28 @@ fetch_vector1(const struct prog_src_register *source,
 }
 
 
+static GLuint
+fetch_vector1ui(const struct prog_src_register *source,
+                const struct gl_program_machine *machine)
+{
+   const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
+   GLuint result;
+
+   ASSERT(src);
+
+   result = src[GET_SWZ(source->Swizzle, 0)];
+
+   if (source->Abs) {
+      result = FABSF(result);
+   }
+   if (source->Negate) {
+      result = -result;
+   }
+
+   return result;
+}
+
+
 /**
  * Fetch texel from texture.  Use partial derivatives when possible.
  */
@@ -1668,13 +1689,11 @@ _mesa_execute_program(GLcontext * ctx,
          break;
       case OPCODE_UP2H:        /* unpack two 16-bit floats */
          {
-            GLfloat a[4], result[4];
-            fi_type fi;
-            GLhalfNV hx, hy;
-            fetch_vector1(&inst->SrcReg[0], machine, a);
-            fi.f = a[0];
-            hx = fi.i & 0xffff;
-            hy = fi.i >> 16;
+            const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
+            GLfloat result[4];
+            GLushort hx, hy;
+            hx = raw & 0xffff;
+            hy = raw >> 16;
             result[0] = result[2] = _mesa_half_to_float(hx);
             result[1] = result[3] = _mesa_half_to_float(hy);
             store_vector4(inst, machine, result);
@@ -1682,13 +1701,11 @@ _mesa_execute_program(GLcontext * ctx,
          break;
       case OPCODE_UP2US:       /* unpack two GLushorts */
          {
-            GLfloat a[4], result[4];
-            fi_type fi;
+            const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
+            GLfloat result[4];
             GLushort usx, usy;
-            fetch_vector1(&inst->SrcReg[0], machine, a);
-            fi.f = a[0];
-            usx = fi.i & 0xffff;
-            usy = fi.i >> 16;
+            usx = raw & 0xffff;
+            usy = raw >> 16;
             result[0] = result[2] = usx * (1.0f / 65535.0f);
             result[1] = result[3] = usy * (1.0f / 65535.0f);
             store_vector4(inst, machine, result);
@@ -1696,27 +1713,23 @@ _mesa_execute_program(GLcontext * ctx,
          break;
       case OPCODE_UP4B:        /* unpack four GLbytes */
          {
-            GLfloat a[4], result[4];
-            fi_type fi;
-            fetch_vector1(&inst->SrcReg[0], machine, a);
-            fi.f = a[0];
-            result[0] = (((fi.i >> 0) & 0xff) - 128) / 127.0F;
-            result[1] = (((fi.i >> 8) & 0xff) - 128) / 127.0F;
-            result[2] = (((fi.i >> 16) & 0xff) - 128) / 127.0F;
-            result[3] = (((fi.i >> 24) & 0xff) - 128) / 127.0F;
+            const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
+            GLfloat result[4];
+            result[0] = (((raw >> 0) & 0xff) - 128) / 127.0F;
+            result[1] = (((raw >> 8) & 0xff) - 128) / 127.0F;
+            result[2] = (((raw >> 16) & 0xff) - 128) / 127.0F;
+            result[3] = (((raw >> 24) & 0xff) - 128) / 127.0F;
             store_vector4(inst, machine, result);
          }
          break;
       case OPCODE_UP4UB:       /* unpack four GLubytes */
          {
-            GLfloat a[4], result[4];
-            fi_type fi;
-            fetch_vector1(&inst->SrcReg[0], machine, a);
-            fi.f = a[0];
-            result[0] = ((fi.i >> 0) & 0xff) / 255.0F;
-            result[1] = ((fi.i >> 8) & 0xff) / 255.0F;
-            result[2] = ((fi.i >> 16) & 0xff) / 255.0F;
-            result[3] = ((fi.i >> 24) & 0xff) / 255.0F;
+            const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
+            GLfloat result[4];
+            result[0] = ((raw >> 0) & 0xff) / 255.0F;
+            result[1] = ((raw >> 8) & 0xff) / 255.0F;
+            result[2] = ((raw >> 16) & 0xff) / 255.0F;
+            result[3] = ((raw >> 24) & 0xff) / 255.0F;
             store_vector4(inst, machine, result);
          }
          break;
index 058d4bbafb7537355e7c9c6c0fcdb33fe2f7a60c..3a446fd9bb21e1dcfedad7ce071ba2ce3bf179ae 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "main/glheader.h"
 #include "main/context.h"
-#include "main/hash.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
index e2acb3c0c9601751a6febdde0937618d2d6f48db..83bc5089d9e157e5ffcd77a6570cdb3d4f4df605 100644 (file)
  */
 #include "main/glheader.h"
 #include "main/imports.h"
-#include "prog_instruction.h"
-#include "prog_statevars.h"
+#include "shader/prog_instruction.h"
+#include "shader/prog_statevars.h"
 
-#include "symbol_table.h"
-#include "program_parser.h"
-#include "program_parse.tab.h"
+#include "shader/symbol_table.h"
+#include "shader/program_parser.h"
+#include "shader/program_parse.tab.h"
 
 #define require_ARB_vp (yyextra->mode == ARB_vertex)
 #define require_ARB_fp (yyextra->mode == ARB_fragment)
index b12dcee9dfa0e816d270f68976be12285b22e1fd..2adfb409739d2ba983187317f6a6021cf5739519 100644 (file)
 
 #include "main/mtypes.h"
 #include "main/imports.h"
-#include "program.h"
-#include "prog_parameter.h"
-#include "prog_parameter_layout.h"
-#include "prog_statevars.h"
-#include "prog_instruction.h"
-
-#include "symbol_table.h"
-#include "program_parser.h"
+#include "shader/program.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_parameter_layout.h"
+#include "shader/prog_statevars.h"
+#include "shader/prog_instruction.h"
+
+#include "shader/symbol_table.h"
+#include "shader/program_parser.h"
 
 extern void *yy_scan_string(char *);
 extern void yy_delete_buffer(void *);
index 5c5d8d759088449c13360f6922b3ce2e592183ad..3880d549172223e152b95fe7e85267a09e8f7c71 100644 (file)
 
 #include "main/mtypes.h"
 #include "main/imports.h"
-#include "program.h"
-#include "prog_parameter.h"
-#include "prog_parameter_layout.h"
-#include "prog_statevars.h"
-#include "prog_instruction.h"
-
-#include "symbol_table.h"
-#include "program_parser.h"
+#include "shader/program.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_parameter_layout.h"
+#include "shader/prog_statevars.h"
+#include "shader/prog_instruction.h"
+
+#include "shader/symbol_table.h"
+#include "shader/program_parser.h"
 
 extern void *yy_scan_string(char *);
 extern void yy_delete_buffer(void *);
index 453cd3964afe6919eabfb0509fb02d900894b412..e522d7017a9bc545f88d00ca77edd9df7ad050c0 100644 (file)
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/hash.h"
-#include "main/macros.h"
 #include "shader/program.h"
 #include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
 #include "shader/prog_statevars.h"
 #include "shader/prog_uniform.h"
 #include "shader/shader_api.h"
index e5809509c93960fab5b01de9449cfded4368d2d8..0a9f0b97fb9e1319d6064554912a4dbaace1b2b5 100644 (file)
@@ -36,7 +36,6 @@
 #include "shader/prog_parameter.h"
 #include "shader/prog_statevars.h"
 #include "shader/slang/slang_ir.h"
-#include "shader/slang/slang_emit.h"
 #include "shader/slang/slang_builtin.h"
 
 
index 6499cfcb2fea6df802ed322c3afc703b8cdd13ff..63d10f45978705fafceb529c905335a242cdbcc1 100644 (file)
 #include "slang_codegen.h"
 #include "slang_compile.h"
 #include "slang_storage.h"
-#include "slang_emit.h"
 #include "slang_log.h"
 #include "slang_mem.h"
 #include "slang_vartable.h"
 #include "slang_simplify.h"
 
-#include "slang_print.h"
-
 /*
  * This is a straightforward implementation of the slang front-end
  * compiler.  Lots of error-checking functionality is missing but
index ce3f6ab7ea274d0b2b0117e7aeebdddfa24b7c12..c9ecbd275b8bf6d9da8a37747c2dec4185952d90 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "main/imports.h"
 #include "main/context.h"
-#include "main/macros.h"
 #include "shader/program.h"
 #include "shader/prog_instruction.h"
 #include "shader/prog_parameter.h"
index ed27821a951bd0320acfb2aefcc63662512fcf4a..21497b34e258ca2f16c9991ff2ecf43ab025c1ef 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "main/imports.h"
 #include "main/context.h"
-#include "main/hash.h"
 #include "main/macros.h"
 #include "shader/program.h"
 #include "shader/prog_instruction.h"
index d7d2b4fbfd00be226b5d4770209cbf62b970372f..4f6b8541c5a7022a8764107a90ae9e22cc25d505 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "main/imports.h"
-#include "main/context.h"
 #include "slang_log.h"
 #include "slang_utility.h"
 
index a4d09c75bb6f3cb26391a88ad1f193c0b9841c30..12d4c2831d864512002d2008bdc1dbf16376d6ad 100644 (file)
@@ -89,6 +89,7 @@ GLAPI_SOURCES = \
        main/dispatch.c \
        glapi/glapi.c \
        glapi/glapi_getproc.c \
+       glapi/glapi_nop.c \
        glapi/glthread.c
 
 MATH_SOURCES = \
index 8ca4335e3307f2e90bf541a197635e6f417a57af..8d045f2c6c06734aa8c15a154359f63091bd2cc5 100644 (file)
@@ -37,7 +37,6 @@
 #include "st_public.h"
 #include "st_texture.h"
 #include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
 #include "cso_cache/cso_context.h"
 #include "util/u_rect.h"
 #include "util/u_math.h"
index 6a5854e9ba5b4d0a4d0122cd776afd228ec5f627..0b2e3f53812861a2ec87899642287bd7e4e9ddce 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "st_context.h"
 #include "st_format.h"
-#include "st_program.h"
 #include "st_texture.h"
 #include "st_inlines.h"
 
index 7b84a86ba485d35762b8888cec48c776760c7b8b..9d63f1c6ab6583b251e8d4d6514b0311477f3421 100644 (file)
@@ -37,7 +37,6 @@
 #include "st_context.h"
 #include "st_cb_texture.h"
 #include "st_atom.h"
-#include "st_program.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 
index 176f3ea68d745f176dce0f33e24f7c779582163e..181f88a33486bd1a9704236088173705ea106719 100644 (file)
@@ -51,7 +51,6 @@
 #include "st_atom.h"
 #include "st_program.h"
 #include "st_atom_shader.h"
-#include "st_mesa_to_tgsi.h"
 
 
 
@@ -79,7 +78,7 @@ translate_fp(struct st_context *st,
 
       stfp->num_input_slots = numIn;
 
-      assert(stfp->Base.Base.NumInstructions > 1);
+      assert(stfp->Base.Base.NumInstructions > 0);
 
       st_translate_fragment_program(st, stfp, stfp->input_to_slot);
    }
index da7b97d3253c78b702a7ff664e0c3ea6b30c1955..798081ec8996c4981bd2a8530275f5e3d60a2584 100644 (file)
@@ -38,9 +38,7 @@
 #include "st_context.h"
 #include "st_cb_accum.h"
 #include "st_cb_fbo.h"
-#include "st_draw.h"
 #include "st_public.h"
-#include "st_format.h"
 #include "st_texture.h"
 #include "st_inlines.h"
 #include "pipe/p_context.h"
index 1bdeaccda3e1d83ae4e6432a6c36166c01fb7b21..d1b35f796ecd08518f24d86640e5275e50505c70 100644 (file)
@@ -34,9 +34,7 @@
 #include "main/image.h"
 #include "main/bufferobj.h"
 #include "main/macros.h"
-#include "main/texformat.h"
 #include "shader/program.h"
-#include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
 
 #include "st_context.h"
 #include "st_atom_constbuf.h"
 #include "st_program.h"
 #include "st_cb_bitmap.h"
-#include "st_cb_program.h"
-#include "st_mesa_to_tgsi.h"
 #include "st_texture.h"
 #include "st_inlines.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
-#include "util/u_tile.h"
 #include "util/u_draw_quad.h"
 #include "util/u_simple_shaders.h"
 #include "shader/prog_instruction.h"
@@ -386,11 +381,11 @@ setup_bitmap_vertex_data(struct st_context *st,
    }
 
    /* put vertex data into vbuf */
-   st_no_flush_pipe_buffer_write(st,
-                                st->bitmap.vbuf,
-                                st->bitmap.vbuf_slot * sizeof st->bitmap.vertices,
-                                sizeof st->bitmap.vertices,
-                                st->bitmap.vertices);
+   st_no_flush_pipe_buffer_write_nooverlap(st,
+                                           st->bitmap.vbuf,
+                                           st->bitmap.vbuf_slot * sizeof st->bitmap.vertices,
+                                           sizeof st->bitmap.vertices,
+                                           st->bitmap.vertices);
 
    return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices;
 }
index 563615ed0d10b9b982ba2e3cbabc78f749011d10..65aa2a28ac29fea8782d91388c61a363b74265bd 100644 (file)
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/macros.h"
-#include "main/texformat.h"
 #include "shader/program.h"
-#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
 
 #include "st_context.h"
 #include "st_texture.h"
-#include "st_program.h"
 #include "st_cb_blit.h"
 #include "st_cb_fbo.h"
 
index 192d765f45335a9846b3dcbf59fca93972c28857..398587ac4b1e5af476990c1847143674ea7a26f7 100644 (file)
 #include "st_cb_accum.h"
 #include "st_cb_clear.h"
 #include "st_cb_fbo.h"
-#include "st_draw.h"
 #include "st_program.h"
 #include "st_public.h"
-#include "st_mesa_to_tgsi.h"
 #include "st_inlines.h"
 
 #include "pipe/p_context.h"
@@ -53,7 +51,6 @@
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 #include "util/u_format.h"
-#include "util/u_pack_color.h"
 #include "util/u_simple_shaders.h"
 #include "util/u_draw_quad.h"
 
@@ -166,10 +163,10 @@ draw_quad(GLcontext *ctx,
    }
 
    /* put vertex data into vbuf */
-   st_no_flush_pipe_buffer_write(st, st->clear.vbuf,
-                                st->clear.vbuf_slot * sizeof(st->clear.vertices),
-                                sizeof(st->clear.vertices),
-                                st->clear.vertices);
+   st_no_flush_pipe_buffer_write_nooverlap(st, st->clear.vbuf,
+                                           st->clear.vbuf_slot * sizeof(st->clear.vertices),
+                                           sizeof(st->clear.vertices),
+                                           st->clear.vertices);
 
    /* draw */
    util_draw_vertex_buffer(pipe, 
index 7c664267d4e49d59936b4441f5689abe13bf8670..7afdc31ede98e3298f96b7660b9465eb32467074 100644 (file)
 #include "main/macros.h"
 #include "main/texformat.h"
 #include "main/texstore.h"
-#include "main/state.h"
 #include "shader/program.h"
-#include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
 
 #include "st_debug.h"
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_atom_constbuf.h"
-#include "st_draw.h"
 #include "st_program.h"
 #include "st_cb_drawpixels.h"
 #include "st_cb_readpixels.h"
 #include "st_cb_fbo.h"
-#include "st_cb_texture.h"
-#include "st_draw.h"
 #include "st_format.h"
-#include "st_mesa_to_tgsi.h"
 #include "st_texture.h"
 #include "st_inlines.h"
 
@@ -1138,6 +1132,8 @@ st_destroy_drawpix(struct st_context *st)
 {
    st_reference_fragprog(st, &st->drawpix.z_shader, NULL);
    st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL);
-   st_reference_vertprog(st, &st->drawpix.vert_shaders[0], NULL);
-   st_reference_vertprog(st, &st->drawpix.vert_shaders[1], NULL);
+   if (st->drawpix.vert_shaders[0])
+      free(st->drawpix.vert_shaders[0]);
+   if (st->drawpix.vert_shaders[1])
+      free(st->drawpix.vert_shaders[1]);
 }
index 45ce34a85f7e58ba46bc08f88459563dfff53cd6..f7350ef1e3c9ec5a5e3bc33cd11c08c44a97e806 100644 (file)
@@ -44,7 +44,6 @@
 #include "pipe/p_screen.h"
 #include "st_context.h"
 #include "st_cb_fbo.h"
-#include "st_cb_texture.h"
 #include "st_format.h"
 #include "st_public.h"
 #include "st_texture.h"
index 93f71452192037414ec0491a683541dd2cb603ef..17261f8321bdaea6fa044bff16618d9924a1f234 100644 (file)
 #include "vbo/vbo.h"
 
 #include "st_context.h"
-#include "st_atom.h"
 #include "st_draw.h"
 #include "st_cb_feedback.h"
-#include "st_cb_bufferobjects.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
-#include "cso_cache/cso_cache.h"
 
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
index 8c276f8128edb2046d2d02346a46112826ac803f..5138e596a9c35f1396b1aa04067d566e6042da88 100644 (file)
@@ -36,7 +36,6 @@
 #include "shader/prog_instruction.h"
 #include "shader/prog_parameter.h"
 #include "shader/program.h"
-#include "shader/programopt.h"
 #include "shader/shader_api.h"
 
 #include "cso_cache/cso_context.h"
index 10629e92254453e2f2f5a6049195ae1a5a1cce59..2281d10e99960c5b4c3f9f9792dac628a151ffb0 100644 (file)
@@ -41,7 +41,6 @@
 #include "pipe/p_defines.h"
 #include "st_context.h"
 #include "st_cb_queryobj.h"
-#include "st_public.h"
 
 
 static struct gl_query_object *
index d82b2a2035f4a62f4c4dfbe4935f4ee9157c8977..42a1377809a966cb46e5720ecd2bcae54df50ab4 100644 (file)
@@ -47,7 +47,6 @@
 #include "st_draw.h"
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
-#include "shader/prog_instruction.h"
 #include "vbo/vbo.h"
 
 
index 6fa7bb64f2eb2cf16ce906ef58faebccae264329..8eb825a6a4183f6b0b002f566fe0029cbc4155f2 100644 (file)
 
 #include "st_debug.h"
 #include "st_context.h"
-#include "st_cb_bitmap.h"
 #include "st_cb_readpixels.h"
 #include "st_cb_fbo.h"
-#include "st_format.h"
 #include "st_public.h"
 #include "st_texture.h"
 #include "st_inlines.h"
index bb931f17c4e0c20f123d3bdcca9445e823db7454..f22c5369e43236079931aa8717d176f0a6a2c68e 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "main/glheader.h"
 #include "main/macros.h"
-#include "main/version.h"
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
 #include "st_context.h"
index f01053cdacc0b344c32c56e237ee32c406f7f4dd..b94bfc853880556a4a8c3d30fc60a835523063c7 100644 (file)
 #include "main/convolve.h"
 #endif
 #include "main/enums.h"
+#include "main/fbobject.h"
 #include "main/formats.h"
 #include "main/image.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/mipmap.h"
-#include "main/pixel.h"
 #include "main/texcompress.h"
 #include "main/texfetch.h"
-#include "main/texformat.h"
 #include "main/texgetimage.h"
 #include "main/teximage.h"
 #include "main/texobj.h"
@@ -1368,33 +1367,64 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
 }
 
 
+
+/**
+ * If the format of the src renderbuffer and the format of the dest
+ * texture are compatible (in terms of blitting), return a TGSI writemask
+ * to be used during the blit.
+ * If the src/dest are incompatible, return 0.
+ */
 static unsigned
-compatible_src_dst_formats(const struct gl_renderbuffer *src,
+compatible_src_dst_formats(GLcontext *ctx,
+                           const struct gl_renderbuffer *src,
                            const struct gl_texture_image *dst)
 {
-   const GLenum srcFormat = _mesa_get_format_base_format(src->Format);
-   const GLenum dstLogicalFormat = _mesa_get_format_base_format(dst->TexFormat);
+   /* Get logical base formats for the src and dest.
+    * That is, use the user-requested formats and not the actual, device-
+    * chosen formats.
+    * For example, the user may have requested an A8 texture but the
+    * driver may actually be using an RGBA texture format.  When we
+    * copy/blit to that texture, we only want to copy the Alpha channel
+    * and not the RGB channels.
+    *
+    * Similarly, when the src FBO was created an RGB format may have been
+    * requested but the driver actually chose an RGBA format.  In that case,
+    * we don't want to copy the undefined Alpha channel to the dest texture
+    * (it should be 1.0).
+    */
+   const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
+   const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
 
-   if (srcFormat == dstLogicalFormat) {
+   /**
+    * XXX when we have red-only and red/green renderbuffers we'll need
+    * to add more cases here (or implement a general-purpose routine that
+    * queries the existance of the R,G,B,A channels in the src and dest).
+    */
+   if (srcFormat == dstFormat) {
       /* This is the same as matching_base_formats, which should
        * always pass, as it did previously.
        */
       return TGSI_WRITEMASK_XYZW;
    }
-   else if (srcFormat == GL_RGBA &&
-            dstLogicalFormat == GL_RGB) {
-      /* Add a single special case to cope with RGBA->RGB transfers,
-       * setting A to 1.0 to cope with situations where the RGB
-       * destination is actually stored as RGBA.
+   else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
+      /* Make sure that A in the dest is 1.  The actual src format
+       * may be RGBA and have undefined A values.
+       */
+      return TGSI_WRITEMASK_XYZ;
+   }
+   else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
+      /* Make sure that A in the dest is 1.  The actual dst format
+       * may be RGBA and will need A=1 to provide proper alpha values
+       * when sampled later.
        */
-      return TGSI_WRITEMASK_XYZ; /* A ==> 1.0 */
+      return TGSI_WRITEMASK_XYZ;
    }
    else {
       if (ST_DEBUG & DEBUG_FALLBACK)
          debug_printf("%s failed for src %s, dst %s\n",
                       __FUNCTION__, 
                       _mesa_lookup_enum_by_nr(srcFormat),
-                      _mesa_lookup_enum_by_nr(dstLogicalFormat));
+                      _mesa_lookup_enum_by_nr(dstFormat));
 
       /* Otherwise fail.
        */
@@ -1505,7 +1535,7 @@ st_copy_texsubimage(GLcontext *ctx,
    matching_base_formats =
       (_mesa_get_format_base_format(strb->Base.Format) ==
        _mesa_get_format_base_format(texImage->TexFormat));
-   format_writemask = compatible_src_dst_formats(&strb->Base, texImage);
+   format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
 
    if (ctx->_ImageTransferState == 0x0) {
 
index ab11c5b4fe0b766e49034f9cfcd3b13e03743d21..b29191abef661afdd9679f94f794031fa65db279 100644 (file)
 
 #include "main/glheader.h"
 #include "st_context.h"
-#include "st_public.h"
 #include "st_cb_viewport.h"
 
 #include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
 
 
 static void st_viewport(GLcontext * ctx, GLint x, GLint y,
index 9e6ce30db047031ca190a230f50615c7953e1436..a62ff248ce5992d7b611147f8a36fd2ce832b825 100644 (file)
 
 #include "main/imports.h"
 #include "main/context.h"
-#include "main/extensions.h"
-#include "main/matrix.h"
-#include "main/buffers.h"
-#include "main/scissor.h"
-#include "main/viewport.h"
 #include "vbo/vbo.h"
 #include "shader/shader_api.h"
 #include "glapi/glapi.h"
@@ -69,7 +64,6 @@
 #include "st_program.h"
 #include "pipe/p_context.h"
 #include "draw/draw_context.h"
-#include "cso_cache/cso_cache.h"
 #include "cso_cache/cso_context.h"
 
 
index 2c4943cfb0a2fa285eaec9fe0d2044c69f915542..50e98d7146a6626225082bfb0a85482f2b4f8c85 100644 (file)
@@ -159,7 +159,7 @@ struct st_context
    /** for glDraw/CopyPixels */
    struct {
       struct st_fragment_program *z_shader;
-      struct st_vertex_program *vert_shaders[2];
+      void *vert_shaders[2];   /**< ureg shaders */
    } drawpix;
 
    /** for glClear */
index a05d6dd06bd6a3c98cde8ff5578577aaa64c19e4..dd27a1e3a885817723b2d93182f2f690c34c1b51 100644 (file)
@@ -28,7 +28,6 @@
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/macros.h"
-#include "shader/prog_uniform.h"
 
 #include "vbo/vbo.h"
 
index 2a5fb27d8f3db7a15a6fb8752dea94c407422704..89a16c1cbccdd202e4d593927b80dec348df6136 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "main/imports.h"
 #include "main/context.h"
-#include "main/extensions.h"
 #include "main/macros.h"
 
 #include "pipe/p_context.h"
index d00b67a279ecd098d1fc4441f05461d91d72304d..3ffc2aee2a2b8d011abc08338531a211b7c56b29 100644 (file)
@@ -35,7 +35,6 @@
 #include "main/imports.h"
 #include "main/context.h"
 #include "main/texstore.h"
-#include "main/texformat.h"
 #include "main/enums.h"
 #include "main/macros.h"
 
@@ -288,6 +287,8 @@ st_pipe_format_to_mesa_format(enum pipe_format pipeFormat)
       return MESA_FORMAT_XRGB8888;
    case PIPE_FORMAT_B8G8R8A8_UNORM:
       return MESA_FORMAT_ARGB8888_REV;
+   case PIPE_FORMAT_B8G8R8X8_UNORM:
+      return MESA_FORMAT_XRGB8888_REV;
    case PIPE_FORMAT_A1R5G5B5_UNORM:
       return MESA_FORMAT_ARGB1555;
    case PIPE_FORMAT_A4R4G4B4_UNORM:
index a5d1ae3b034388dd713b35ee0ae7d82e20d84366..835142e3d41b3d4eb53ab1e6595ffcaeabd9ec45 100644 (file)
 #include "main/buffers.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
-#include "main/matrix.h"
 #include "main/renderbuffer.h"
-#include "main/scissor.h"
-#include "main/viewport.h"
 #include "st_context.h"
 #include "st_cb_fbo.h"
 #include "st_public.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_context.h"
 
 
 struct st_framebuffer *
index 2c283d464ae40e63e216fbfb8ca7aa879419d6bb..3823a59d37a63149920a40c038b8d86c33558f9c 100644 (file)
@@ -46,9 +46,7 @@
 
 #include "st_debug.h"
 #include "st_context.h"
-#include "st_draw.h"
 #include "st_gen_mipmap.h"
-#include "st_program.h"
 #include "st_texture.h"
 #include "st_cb_texture.h"
 #include "st_inlines.h"
index a41cfeb96f7aec3918744b2d3f179422952ba6dc..dccc46f12d7d32039405ebedbb3051e573a7e30f 100644 (file)
@@ -125,6 +125,16 @@ st_no_flush_pipe_buffer_write(struct st_context *st,
    pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
 }
 
+static INLINE void
+st_no_flush_pipe_buffer_write_nooverlap(struct st_context *st,
+                                        struct pipe_buffer *buf,
+                                        unsigned int offset,
+                                        unsigned int size,
+                                        const void * data)
+{
+   pipe_buffer_write_nooverlap(st->pipe->screen, buf, offset, size, data);
+}
+
 static INLINE void
 st_cond_flush_pipe_buffer_read(struct st_context *st,
                               struct pipe_buffer *buf,
index 0b6bb7e3ec96be589cf80d751421461ccbb0e02a..ac5dae2148b4e8e3cc6f2fcac44ae9bbfb96b1f1 100644 (file)
@@ -497,17 +497,24 @@ depth_test_span32( GLcontext *ctx, GLuint n,
    return passed;
 }
 
-/* Apply ARB_depth_clamp to span of fragments. */
+
+
+/**
+ * Clamp fragment Z values to the depth near/far range (glDepthRange()).
+ * This is used when GL_ARB_depth_clamp/GL_DEPTH_CLAMP is turned on.
+ * In that case, vertexes are not clipped against the near/far planes
+ * so rasterization will produce fragment Z values outside the usual
+ * [0,1] range.
+ */
 void
 _swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
 {
    struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct gl_renderbuffer *rb = fb->_DepthBuffer;
    const GLuint count = span->end;
-   GLuint *zValues = span->array->z;
-   GLuint min, max;
+   GLint *zValues = (GLint *) span->array->z; /* sign change */
+   GLint min, max;
    GLfloat min_f, max_f;
-   int i;
+   GLuint i;
 
    if (ctx->Viewport.Near < ctx->Viewport.Far) {
       min_f = ctx->Viewport.Near;
@@ -517,15 +524,21 @@ _swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
       max_f = ctx->Viewport.Near;
    }
 
-   if (rb->DataType == GL_UNSIGNED_SHORT) {
-      CLAMPED_FLOAT_TO_USHORT(min, min_f);
-      CLAMPED_FLOAT_TO_USHORT(max, max_f);
-   } else {
-      assert(rb->DataType == GL_UNSIGNED_INT);
-      min = FLOAT_TO_UINT(min_f);
-      max = FLOAT_TO_UINT(max_f);
-   }
-
+   /* Convert floating point values in [0,1] to device Z coordinates in
+    * [0, DepthMax].
+    * ex: If the the Z buffer has 24 bits, DepthMax = 0xffffff.
+    * 
+    * XXX this all falls apart if we have 31 or more bits of Z because
+    * the triangle rasterization code produces unsigned Z values.  Negative
+    * vertex Z values come out as large fragment Z uints.
+    */
+   min = (GLint) (min_f * fb->_DepthMaxF);
+   max = (GLint) (max_f * fb->_DepthMaxF);
+   if (max < 0)
+      max = 0x7fffffff; /* catch over flow for 30-bit z */
+
+   /* Note that we do the comparisons here using signed integers.
+    */
    for (i = 0; i < count; i++) {
       if (zValues[i] < min)
         zValues[i] = min;
index 4ea9547cd9203c84521df1612cbcf5a30248c707..874a37b2241abe83a29977992a6bacfdb4199a7f 100644 (file)
@@ -1316,6 +1316,13 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span)
 
    ASSERT(span->end <= MAX_WIDTH);
 
+   /* Depth bounds test */
+   if (ctx->Depth.BoundsTest && fb->Visual.depthBits > 0) {
+      if (!_swrast_depth_bounds_test(ctx, span)) {
+         return;
+      }
+   }
+
 #ifdef DEBUG
    /* Make sure all fragments are within window bounds */
    if (span->arrayMask & SPAN_XY) {