Merge remote-tracking branch 'anholt/glamor-external-rebase'
This commit is contained in:
commit
1d76b02fac
71
glamor/Makefile.am
Normal file
71
glamor/Makefile.am
Normal file
|
@ -0,0 +1,71 @@
|
|||
lib_LTLIBRARIES = libglamor.la
|
||||
|
||||
if GLAMOR_GLES2
|
||||
libglamor_la_LIBADD = $(GLESV2_LIBS)
|
||||
else
|
||||
libglamor_la_LIBADD = $(GL_LIBS)
|
||||
endif
|
||||
|
||||
AM_CFLAGS = $(CWARNFLAGS) $(XORG_CFLAGS) $(LIBDRM_CFLAGS)
|
||||
|
||||
libglamor_la_LDFLAGS = -version-info 0:0:0
|
||||
|
||||
libglamor_la_SOURCES = \
|
||||
compat-api.h \
|
||||
compiler.h \
|
||||
glamor.c \
|
||||
glamor_copyarea.c \
|
||||
glamor_copywindow.c \
|
||||
glamor_core.c \
|
||||
glamor_debug.h \
|
||||
glamor_gl_dispatch.h \
|
||||
glamor_fill.c \
|
||||
glamor_fillspans.c \
|
||||
glamor_getspans.c \
|
||||
glamor_glext.h \
|
||||
glamor_glyphs.c \
|
||||
glamor_polyfillrect.c \
|
||||
glamor_polylines.c \
|
||||
glamor_putimage.c \
|
||||
glamor_setspans.c \
|
||||
glamor_render.c \
|
||||
glamor_gradient.c \
|
||||
glamor_trapezoid.c \
|
||||
glamor_tile.c \
|
||||
glamor_triangles.c\
|
||||
glamor_addtraps.c\
|
||||
glamor_getimage.c\
|
||||
glamor_copyplane.c\
|
||||
glamor_glyphblt.c\
|
||||
glamor_polyops.c\
|
||||
glamor_priv.h\
|
||||
glamor_pixmap.c\
|
||||
glamor_largepixmap.c\
|
||||
glamor_picture.c\
|
||||
glamor_window.c\
|
||||
glamor_gl_dispatch.c\
|
||||
glamor_fbo.c\
|
||||
glamor_compositerects.c\
|
||||
glamor_xv.c\
|
||||
glamor_utils.h\
|
||||
glamor.h\
|
||||
glapi.h
|
||||
|
||||
sdk_HEADERS = glamor.h
|
||||
|
||||
if EGL
|
||||
LIBGLAMOREGL = libglamoregl.la
|
||||
module_LTLIBRARIES = $(LIBGLAMOREGL)
|
||||
libglamoregl_la_DEPENDENCIES = libglamor.la
|
||||
libglamoregl_la_LDFLAGS = -avoid-version -module
|
||||
libglamoregl_la_LIBADD = $(EGL_LIBS) $(GLX_SYS_LIBS) $(GBM_LIBS) libglamor.la
|
||||
libglamoregl_la_SOURCES = glamor_eglmodule.c glamor_egl.c
|
||||
libglamoregl_la_CFLAGS = \
|
||||
$(AM_CFLAGS) \
|
||||
$(GLX_DEFINES) \
|
||||
$(LIBDRM_CFLAGS) \
|
||||
$(EGL_CFLAGS) \
|
||||
$(GBM_CFLAGS)
|
||||
endif
|
||||
|
||||
|
107
glamor/compat-api.h
Normal file
107
glamor/compat-api.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright 2012 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Author: Dave Airlie <airlied@redhat.com>
|
||||
*/
|
||||
|
||||
/* this file provides API compat between server post 1.13 and pre it,
|
||||
it should be reused inside as many drivers as possible */
|
||||
#ifndef COMPAT_API_H
|
||||
#define COMPAT_API_H
|
||||
|
||||
#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
|
||||
#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
|
||||
#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
|
||||
#endif
|
||||
|
||||
#ifndef XF86_HAS_SCRN_CONV
|
||||
#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
|
||||
#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
|
||||
#endif
|
||||
|
||||
#ifndef XF86_SCRN_INTERFACE
|
||||
|
||||
#define SCRN_ARG_TYPE int
|
||||
#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = xf86Screens[(arg1)]
|
||||
|
||||
#define SCREEN_ARG_TYPE int
|
||||
#define SCREEN_PTR(arg1) ScreenPtr screen = screenInfo.screens[(arg1)]
|
||||
|
||||
#define SCREEN_INIT_ARGS_DECL int scrnIndex, ScreenPtr screen, int argc, char **argv
|
||||
|
||||
#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer timeout, pointer read_mask
|
||||
#define BLOCKHANDLER_ARGS arg, blockData, timeout, read_mask
|
||||
|
||||
#define WAKEUPHANDLER_ARGS_DECL int arg, pointer wakeupData, unsigned long result, pointer read_mask
|
||||
#define WAKEUPHANDLER_ARGS arg, wakeupData, result, read_mask
|
||||
|
||||
#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr screen
|
||||
#define CLOSE_SCREEN_ARGS scrnIndex, screen
|
||||
|
||||
#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
|
||||
#define ADJUST_FRAME_ARGS(arg, x, y) (arg)->scrnIndex, x, y, 0
|
||||
|
||||
#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
|
||||
#define SWITCH_MODE_ARGS(arg, m) (arg)->scrnIndex, m, 0
|
||||
|
||||
#define FREE_SCREEN_ARGS_DECL int arg, int flags
|
||||
#define FREE_SCREEN_ARGS arg, flags
|
||||
|
||||
#define VT_FUNC_ARGS_DECL int arg, int flags
|
||||
#define VT_FUNC_ARGS(flags) scrn->scrnIndex, (flags)
|
||||
|
||||
#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
|
||||
|
||||
#else
|
||||
#define SCRN_ARG_TYPE ScrnInfoPtr
|
||||
#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = (arg1)
|
||||
|
||||
#define SCREEN_ARG_TYPE ScreenPtr
|
||||
#define SCREEN_PTR(arg1) ScreenPtr screen = (arg1)
|
||||
|
||||
#define SCREEN_INIT_ARGS_DECL ScreenPtr screen, int argc, char **argv
|
||||
|
||||
#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer timeout, pointer read_mask
|
||||
#define BLOCKHANDLER_ARGS arg, timeout, read_mask
|
||||
|
||||
#define WAKEUPHANDLER_ARGS_DECL ScreenPtr arg, unsigned long result, pointer read_mask
|
||||
#define WAKEUPHANDLER_ARGS arg, result, read_mask
|
||||
|
||||
#define CLOSE_SCREEN_ARGS_DECL ScreenPtr screen
|
||||
#define CLOSE_SCREEN_ARGS screen
|
||||
|
||||
#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
|
||||
#define ADJUST_FRAME_ARGS(arg, x, y) arg, x, y
|
||||
|
||||
#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
|
||||
#define SWITCH_MODE_ARGS(arg, m) arg, m
|
||||
|
||||
#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
|
||||
#define FREE_SCREEN_ARGS arg
|
||||
|
||||
#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
|
||||
#define VT_FUNC_ARGS(flags) scrn
|
||||
|
||||
#define XF86_ENABLEDISABLEFB_ARG(x) (x)
|
||||
|
||||
#endif
|
||||
#endif
|
59
glamor/compiler.h
Normal file
59
glamor/compiler.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Chris Wilson <chris@chris-wilson.co.uk>
|
||||
*
|
||||
* Copied from sna
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _GLAMOR_COMPILER_H_
|
||||
#define _GLAMOR_COMPILER_H_
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
|
||||
#define likely(expr) (__builtin_expect (!!(expr), 1))
|
||||
#define unlikely(expr) (__builtin_expect (!!(expr), 0))
|
||||
#define noinline __attribute__((noinline))
|
||||
#define fastcall __attribute__((regparm(3)))
|
||||
#define must_check __attribute__((warn_unused_result))
|
||||
#define constant __attribute__((const))
|
||||
#else
|
||||
#define likely(expr) (expr)
|
||||
#define unlikely(expr) (expr)
|
||||
#define noinline
|
||||
#define fastcall
|
||||
#define must_check
|
||||
#define constant
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VALGRIND
|
||||
#define VG(x) x
|
||||
#else
|
||||
#define VG(x)
|
||||
#endif
|
||||
|
||||
#define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s)))
|
||||
|
||||
#define COMPILE_TIME_ASSERT(E) ((void)sizeof(char[1 - 2*!(E)]))
|
||||
|
||||
#endif /* _SNA_COMPILER_H_ */
|
628
glamor/glamor.c
Normal file
628
glamor/glamor.c
Normal file
|
@ -0,0 +1,628 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/** @file glamor.c
|
||||
* This file covers the initialization and teardown of glamor, and has various
|
||||
* functions not responsible for performing rendering.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static DevPrivateKeyRec glamor_screen_private_key_index;
|
||||
DevPrivateKey glamor_screen_private_key = &glamor_screen_private_key_index;
|
||||
static DevPrivateKeyRec glamor_pixmap_private_key_index;
|
||||
DevPrivateKey glamor_pixmap_private_key = &glamor_pixmap_private_key_index;
|
||||
|
||||
/**
|
||||
* glamor_get_drawable_pixmap() returns a backing pixmap for a given drawable.
|
||||
*
|
||||
* @param drawable the drawable being requested.
|
||||
*
|
||||
* This function returns the backing pixmap for a drawable, whether it is a
|
||||
* redirected window, unredirected window, or already a pixmap. Note that
|
||||
* coordinate translation is needed when drawing to the backing pixmap of a
|
||||
* redirected window, and the translation coordinates are provided by calling
|
||||
* exaGetOffscreenPixmap() on the drawable.
|
||||
*/
|
||||
PixmapPtr
|
||||
glamor_get_drawable_pixmap(DrawablePtr drawable)
|
||||
{
|
||||
if (drawable->type == DRAWABLE_WINDOW)
|
||||
return drawable->
|
||||
pScreen->GetWindowPixmap((WindowPtr) drawable);
|
||||
else
|
||||
return (PixmapPtr) drawable;
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(pixmap->drawable.pScreen);
|
||||
|
||||
pixmap_priv = dixLookupPrivate(&pixmap->devPrivates,
|
||||
glamor_pixmap_private_key);
|
||||
if (pixmap_priv == NULL) {
|
||||
pixmap_priv = calloc(sizeof(*pixmap_priv), 1);
|
||||
glamor_set_pixmap_private(pixmap, pixmap_priv);
|
||||
pixmap_priv->base.pixmap = pixmap;
|
||||
pixmap_priv->base.glamor_priv = glamor_priv;
|
||||
}
|
||||
pixmap_priv->type = type;
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_pixmap_fbo *fbo;
|
||||
GLenum format;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (pixmap_priv->base.fbo) {
|
||||
fbo = glamor_pixmap_detach_fbo(pixmap_priv);
|
||||
glamor_destroy_fbo(fbo);
|
||||
}
|
||||
|
||||
gl_iformat_for_depth(pixmap->drawable.depth, &format);
|
||||
fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap->drawable.width,
|
||||
pixmap->drawable.height,
|
||||
format, tex, 0);
|
||||
|
||||
if (fbo == NULL) {
|
||||
ErrorF("XXX fail to create fbo.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
glamor_pixmap_attach_fbo(pixmap, fbo);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_set_screen_pixmap(PixmapPtr screen_pixmap, PixmapPtr *back_pixmap)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen_pixmap->drawable.pScreen);
|
||||
pixmap_priv = glamor_get_pixmap_private(screen_pixmap);
|
||||
glamor_priv->screen_fbo = pixmap_priv->base.fbo->fb;
|
||||
|
||||
pixmap_priv->base.fbo->width = screen_pixmap->drawable.width;
|
||||
pixmap_priv->base.fbo->height = screen_pixmap->drawable.height;
|
||||
|
||||
glamor_priv->back_pixmap = back_pixmap;
|
||||
}
|
||||
|
||||
PixmapPtr
|
||||
glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
|
||||
unsigned int usage)
|
||||
{
|
||||
PixmapPtr pixmap;
|
||||
glamor_pixmap_type_t type = GLAMOR_TEXTURE_ONLY;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_pixmap_fbo *fbo;
|
||||
int pitch;
|
||||
GLenum format;
|
||||
|
||||
if (w > 32767 || h > 32767)
|
||||
return NullPixmap;
|
||||
|
||||
if ((usage == GLAMOR_CREATE_PIXMAP_CPU
|
||||
|| (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 64 && h <= 64)
|
||||
|| (w == 0 && h == 0)
|
||||
|| !glamor_check_pixmap_fbo_depth(depth))
|
||||
|| (!GLAMOR_TEXTURED_LARGE_PIXMAP &&
|
||||
!glamor_check_fbo_size(glamor_priv, w, h)))
|
||||
return fbCreatePixmap(screen, w, h, depth, usage);
|
||||
else
|
||||
pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
|
||||
|
||||
pixmap_priv = calloc(1, sizeof(*pixmap_priv));
|
||||
|
||||
if (!pixmap_priv) {
|
||||
fbDestroyPixmap(pixmap);
|
||||
return fbCreatePixmap(screen, w, h, depth, usage);
|
||||
}
|
||||
glamor_set_pixmap_private(pixmap, pixmap_priv);
|
||||
|
||||
if (usage == GLAMOR_CREATE_PIXMAP_MAP)
|
||||
type = GLAMOR_MEMORY_MAP;
|
||||
|
||||
pixmap_priv->base.pixmap = pixmap;
|
||||
pixmap_priv->base.glamor_priv = glamor_priv;
|
||||
|
||||
gl_iformat_for_depth(depth, &format);
|
||||
|
||||
pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3;
|
||||
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL);
|
||||
|
||||
if (type == GLAMOR_MEMORY_MAP || glamor_check_fbo_size(glamor_priv, w, h)) {
|
||||
pixmap_priv->type = type;
|
||||
fbo = glamor_create_fbo(glamor_priv, w, h, format, usage);
|
||||
}
|
||||
else {
|
||||
DEBUGF("Create LARGE pixmap %p width %d height %d\n", pixmap, w, h);
|
||||
pixmap_priv->type = GLAMOR_TEXTURE_LARGE;
|
||||
fbo = glamor_create_fbo_array(glamor_priv, w, h, format, usage,
|
||||
glamor_priv->max_fbo_size,
|
||||
glamor_priv->max_fbo_size,
|
||||
pixmap_priv);
|
||||
}
|
||||
|
||||
if (fbo == NULL) {
|
||||
fbDestroyPixmap(pixmap);
|
||||
free(pixmap_priv);
|
||||
return fbCreatePixmap(screen, w, h, depth, usage);
|
||||
}
|
||||
|
||||
glamor_pixmap_attach_fbo(pixmap, fbo);
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_destroy_textured_pixmap(PixmapPtr pixmap)
|
||||
{
|
||||
if (pixmap->refcnt == 1) {
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
if (pixmap_priv != NULL)
|
||||
glamor_pixmap_destroy_fbo(pixmap_priv);
|
||||
}
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_destroy_pixmap(PixmapPtr pixmap)
|
||||
{
|
||||
glamor_screen_private
|
||||
*glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
|
||||
if (glamor_priv->dri3_enabled)
|
||||
glamor_egl_destroy_textured_pixmap(pixmap);
|
||||
else
|
||||
glamor_destroy_textured_pixmap(pixmap);
|
||||
return fbDestroyPixmap(pixmap);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_block_handler(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_priv->tick++;
|
||||
dispatch->glFlush();
|
||||
glamor_fbo_expire(glamor_priv);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
if (glamor_priv->state == RENDER_STATE
|
||||
&& glamor_priv->render_idle_cnt++ > RENDER_IDEL_MAX) {
|
||||
glamor_priv->state = IDLE_STATE;
|
||||
glamor_priv->render_idle_cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_glamor_block_handler(void *data, OSTimePtr timeout,
|
||||
void *last_select_mask)
|
||||
{
|
||||
glamor_screen_private *glamor_priv = data;
|
||||
glamor_gl_dispatch *dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glFlush();
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
static void
|
||||
_glamor_wakeup_handler(void *data, int result, void *last_select_mask)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_set_debug_level(int *debug_level)
|
||||
{
|
||||
char *debug_level_string;
|
||||
debug_level_string = getenv("GLAMOR_DEBUG");
|
||||
if (debug_level_string
|
||||
&& sscanf(debug_level_string, "%d", debug_level) == 1)
|
||||
return;
|
||||
*debug_level = 0;
|
||||
}
|
||||
|
||||
int glamor_debug_level;
|
||||
|
||||
/** Set up glamor for an already-configured GL context. */
|
||||
Bool
|
||||
glamor_init(ScreenPtr screen, unsigned int flags)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
int gl_version;
|
||||
|
||||
#ifdef RENDER
|
||||
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
||||
#endif
|
||||
if (flags & ~GLAMOR_VALID_FLAGS) {
|
||||
ErrorF("glamor_init: Invalid flags %x\n", flags);
|
||||
return FALSE;
|
||||
}
|
||||
glamor_priv = calloc(1, sizeof(*glamor_priv));
|
||||
if (glamor_priv == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (flags & GLAMOR_INVERTED_Y_AXIS) {
|
||||
glamor_priv->yInverted = 1;
|
||||
} else
|
||||
glamor_priv->yInverted = 0;
|
||||
|
||||
if (!dixRegisterPrivateKey
|
||||
(glamor_screen_private_key, PRIVATE_SCREEN, 0)) {
|
||||
LogMessage(X_WARNING,
|
||||
"glamor%d: Failed to allocate screen private\n",
|
||||
screen->myNum);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
glamor_set_screen_private(screen, glamor_priv);
|
||||
|
||||
if (!dixRegisterPrivateKey
|
||||
(glamor_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
|
||||
LogMessage(X_WARNING,
|
||||
"glamor%d: Failed to allocate pixmap private\n",
|
||||
screen->myNum);
|
||||
goto fail;;
|
||||
}
|
||||
|
||||
gl_version = glamor_gl_get_version();
|
||||
|
||||
#ifndef GLAMOR_GLES2
|
||||
if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) {
|
||||
ErrorF("Require OpenGL version 1.3 or latter.\n");
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) {
|
||||
ErrorF("Require Open GLES2.0 or latter.\n");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
glamor_gl_dispatch_init(screen, &glamor_priv->_dispatch, gl_version);
|
||||
|
||||
#ifdef GLAMOR_GLES2
|
||||
if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
|
||||
ErrorF("GL_EXT_texture_format_BGRA8888 required\n");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
glamor_priv->has_pack_invert =
|
||||
glamor_gl_has_extension("GL_MESA_pack_invert");
|
||||
glamor_priv->has_fbo_blit =
|
||||
glamor_gl_has_extension("GL_EXT_framebuffer_blit");
|
||||
glamor_priv->_dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE,
|
||||
&glamor_priv->max_fbo_size);
|
||||
#ifdef MAX_FBO_SIZE
|
||||
glamor_priv->max_fbo_size = MAX_FBO_SIZE;
|
||||
#endif
|
||||
|
||||
glamor_set_debug_level(&glamor_debug_level);
|
||||
|
||||
#ifdef GLAMOR_GLES2
|
||||
glamor_priv->gl_flavor = GLAMOR_GL_ES2;
|
||||
#else
|
||||
glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP;
|
||||
#endif
|
||||
/* If we are using egl screen, call egl screen init to
|
||||
* register correct close screen function. */
|
||||
if (flags & GLAMOR_USE_EGL_SCREEN)
|
||||
glamor_egl_screen_init(screen);
|
||||
|
||||
glamor_priv->saved_procs.close_screen = screen->CloseScreen;
|
||||
screen->CloseScreen = glamor_close_screen;
|
||||
|
||||
if (flags & GLAMOR_USE_SCREEN) {
|
||||
if (!RegisterBlockAndWakeupHandlers(_glamor_block_handler,
|
||||
_glamor_wakeup_handler,
|
||||
glamor_priv)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
glamor_priv->saved_procs.create_gc = screen->CreateGC;
|
||||
screen->CreateGC = glamor_create_gc;
|
||||
|
||||
glamor_priv->saved_procs.create_pixmap = screen->CreatePixmap;
|
||||
screen->CreatePixmap = glamor_create_pixmap;
|
||||
|
||||
glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
|
||||
screen->DestroyPixmap = glamor_destroy_pixmap;
|
||||
|
||||
glamor_priv->saved_procs.get_spans = screen->GetSpans;
|
||||
screen->GetSpans = glamor_get_spans;
|
||||
|
||||
glamor_priv->saved_procs.get_image = screen->GetImage;
|
||||
screen->GetImage = glamor_get_image;
|
||||
|
||||
glamor_priv->saved_procs.change_window_attributes =
|
||||
screen->ChangeWindowAttributes;
|
||||
screen->ChangeWindowAttributes =
|
||||
glamor_change_window_attributes;
|
||||
|
||||
glamor_priv->saved_procs.copy_window = screen->CopyWindow;
|
||||
screen->CopyWindow = glamor_copy_window;
|
||||
|
||||
glamor_priv->saved_procs.bitmap_to_region =
|
||||
screen->BitmapToRegion;
|
||||
screen->BitmapToRegion = glamor_bitmap_to_region;
|
||||
}
|
||||
#ifdef RENDER
|
||||
if (flags & GLAMOR_USE_PICTURE_SCREEN) {
|
||||
glamor_priv->saved_procs.composite = ps->Composite;
|
||||
ps->Composite = glamor_composite;
|
||||
|
||||
|
||||
glamor_priv->saved_procs.trapezoids = ps->Trapezoids;
|
||||
ps->Trapezoids = glamor_trapezoids;
|
||||
|
||||
|
||||
glamor_priv->saved_procs.triangles = ps->Triangles;
|
||||
ps->Triangles = glamor_triangles;
|
||||
|
||||
glamor_priv->saved_procs.addtraps = ps->AddTraps;
|
||||
ps->AddTraps = glamor_add_traps;
|
||||
|
||||
}
|
||||
|
||||
glamor_priv->saved_procs.composite_rects = ps->CompositeRects;
|
||||
ps->CompositeRects = glamor_composite_rectangles;
|
||||
|
||||
glamor_priv->saved_procs.glyphs = ps->Glyphs;
|
||||
ps->Glyphs = glamor_glyphs;
|
||||
|
||||
glamor_priv->saved_procs.unrealize_glyph = ps->UnrealizeGlyph;
|
||||
ps->UnrealizeGlyph = glamor_glyph_unrealize;
|
||||
|
||||
glamor_priv->saved_procs.create_picture = ps->CreatePicture;
|
||||
ps->CreatePicture = glamor_create_picture;
|
||||
|
||||
glamor_priv->saved_procs.set_window_pixmap = screen->SetWindowPixmap;
|
||||
screen->SetWindowPixmap = glamor_set_window_pixmap;
|
||||
|
||||
glamor_priv->saved_procs.destroy_picture = ps->DestroyPicture;
|
||||
ps->DestroyPicture = glamor_destroy_picture;
|
||||
glamor_init_composite_shaders(screen);
|
||||
#endif
|
||||
glamor_init_pixmap_fbo(screen);
|
||||
glamor_init_solid_shader(screen);
|
||||
glamor_init_tile_shader(screen);
|
||||
#ifdef GLAMOR_TRAPEZOID_SHADER
|
||||
glamor_init_trapezoid_shader(screen);
|
||||
#endif
|
||||
glamor_init_putimage_shaders(screen);
|
||||
glamor_init_finish_access_shaders(screen);
|
||||
#ifdef GLAMOR_GRADIENT_SHADER
|
||||
glamor_init_gradient_shader(screen);
|
||||
#endif
|
||||
#ifdef GLAMOR_XV
|
||||
glamor_init_xv_shader(screen);
|
||||
#endif
|
||||
glamor_pixmap_init(screen);
|
||||
|
||||
glamor_priv->flags = flags;
|
||||
glamor_priv->screen = screen;
|
||||
|
||||
return TRUE;
|
||||
|
||||
fail:
|
||||
free(glamor_priv);
|
||||
glamor_set_screen_private(screen, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_release_screen_priv(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
#ifdef GLAMOR_XV
|
||||
glamor_fini_xv_shader(screen);
|
||||
#endif
|
||||
#ifdef RENDER
|
||||
glamor_fini_composite_shaders(screen);
|
||||
#endif
|
||||
glamor_fini_pixmap_fbo(screen);
|
||||
glamor_fini_solid_shader(screen);
|
||||
glamor_fini_tile_shader(screen);
|
||||
#ifdef GLAMOR_TRAPEZOID_SHADER
|
||||
glamor_fini_trapezoid_shader(screen);
|
||||
#endif
|
||||
glamor_fini_putimage_shaders(screen);
|
||||
glamor_fini_finish_access_shaders(screen);
|
||||
#ifdef GLAMOR_GRADIENT_SHADER
|
||||
glamor_fini_gradient_shader(screen);
|
||||
#endif
|
||||
glamor_pixmap_fini(screen);
|
||||
free(glamor_priv);
|
||||
|
||||
glamor_set_screen_private(screen, NULL);
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv)
|
||||
{
|
||||
glamor_pixmap_private *old_priv;
|
||||
glamor_pixmap_fbo *fbo;
|
||||
|
||||
old_priv = dixGetPrivate(&pixmap->devPrivates, glamor_pixmap_private_key);
|
||||
|
||||
if (priv) {
|
||||
assert(old_priv == NULL);
|
||||
} else {
|
||||
if (old_priv == NULL)
|
||||
return;
|
||||
fbo = glamor_pixmap_detach_fbo(old_priv);
|
||||
glamor_purge_fbo(fbo);
|
||||
free(old_priv);
|
||||
}
|
||||
|
||||
dixSetPrivate(&pixmap->devPrivates,
|
||||
glamor_pixmap_private_key,
|
||||
priv);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_close_screen(CLOSE_SCREEN_ARGS_DECL)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
PixmapPtr screen_pixmap;
|
||||
int flags;
|
||||
#ifdef RENDER
|
||||
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
||||
#endif
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
flags = glamor_priv->flags;
|
||||
glamor_glyphs_fini(screen);
|
||||
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
|
||||
if (flags & GLAMOR_USE_SCREEN) {
|
||||
|
||||
screen->CreateGC = glamor_priv->saved_procs.create_gc;
|
||||
screen->CreatePixmap = glamor_priv->saved_procs.create_pixmap;
|
||||
screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap;
|
||||
screen->GetSpans = glamor_priv->saved_procs.get_spans;
|
||||
screen->ChangeWindowAttributes =
|
||||
glamor_priv->saved_procs.change_window_attributes;
|
||||
screen->CopyWindow = glamor_priv->saved_procs.copy_window;
|
||||
screen->BitmapToRegion = glamor_priv->saved_procs.bitmap_to_region;
|
||||
}
|
||||
#ifdef RENDER
|
||||
if (ps && (flags & GLAMOR_USE_PICTURE_SCREEN)) {
|
||||
|
||||
ps->Composite = glamor_priv->saved_procs.composite;
|
||||
ps->Trapezoids = glamor_priv->saved_procs.trapezoids;
|
||||
ps->Triangles = glamor_priv->saved_procs.triangles;
|
||||
ps->CreatePicture = glamor_priv->saved_procs.create_picture;
|
||||
}
|
||||
ps->CompositeRects = glamor_priv->saved_procs.composite_rects;
|
||||
ps->Glyphs = glamor_priv->saved_procs.glyphs;
|
||||
ps->UnrealizeGlyph = glamor_priv->saved_procs.unrealize_glyph;
|
||||
screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
|
||||
#endif
|
||||
screen_pixmap = screen->GetScreenPixmap(screen);
|
||||
glamor_set_pixmap_private(screen_pixmap, NULL);
|
||||
if (glamor_priv->back_pixmap && *glamor_priv->back_pixmap)
|
||||
glamor_set_pixmap_private(*glamor_priv->back_pixmap, NULL);
|
||||
|
||||
glamor_release_screen_priv(screen);
|
||||
|
||||
return screen->CloseScreen(CLOSE_SCREEN_ARGS);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glamor_fini(ScreenPtr screen)
|
||||
{
|
||||
/* Do nothing currently. */
|
||||
}
|
||||
|
||||
void glamor_enable_dri3(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_priv->dri3_enabled = TRUE;
|
||||
}
|
||||
|
||||
Bool glamor_is_dri3_support_enabled(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
return glamor_priv->dri3_enabled;
|
||||
}
|
||||
|
||||
int
|
||||
glamor_dri3_fd_from_pixmap (ScreenPtr screen,
|
||||
PixmapPtr pixmap,
|
||||
CARD16 *stride,
|
||||
CARD32 *size)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(pixmap->drawable.pScreen);
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
|
||||
return -1;
|
||||
switch (pixmap_priv->type)
|
||||
{
|
||||
case GLAMOR_TEXTURE_DRM:
|
||||
case GLAMOR_TEXTURE_ONLY:
|
||||
glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0);
|
||||
return glamor_egl_dri3_fd_name_from_tex(screen,
|
||||
pixmap,
|
||||
pixmap_priv->base.fbo->tex,
|
||||
FALSE,
|
||||
stride,
|
||||
size);
|
||||
default: break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
glamor_dri3_name_from_pixmap (PixmapPtr pixmap)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(pixmap->drawable.pScreen);
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
|
||||
return -1;
|
||||
switch (pixmap_priv->type)
|
||||
{
|
||||
case GLAMOR_TEXTURE_DRM:
|
||||
case GLAMOR_TEXTURE_ONLY:
|
||||
glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0);
|
||||
return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,
|
||||
pixmap,
|
||||
pixmap_priv->base.fbo->tex,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL);
|
||||
default: break;
|
||||
}
|
||||
return -1;
|
||||
}
|
432
glamor/glamor.h
Normal file
432
glamor/glamor.h
Normal file
|
@ -0,0 +1,432 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GLAMOR_H
|
||||
#define GLAMOR_H
|
||||
|
||||
#include <scrnintstr.h>
|
||||
#include <xf86.h>
|
||||
#include <xf86str.h>
|
||||
#include <pixmapstr.h>
|
||||
#include <gcstruct.h>
|
||||
#include <picturestr.h>
|
||||
#include <fb.h>
|
||||
#include <fbpict.h>
|
||||
#include <xf86xv.h>
|
||||
/*
|
||||
* glamor_pixmap_type : glamor pixmap's type.
|
||||
* @MEMORY: pixmap is in memory.
|
||||
* @TEXTURE_DRM: pixmap is in a texture created from a DRM buffer.
|
||||
* @SEPARATE_TEXTURE: The texture is created from a DRM buffer, but
|
||||
* the format is incompatible, so this type of pixmap
|
||||
* will never fallback to DDX layer.
|
||||
* @DRM_ONLY: pixmap is in a external DRM buffer.
|
||||
* @TEXTURE_ONLY: pixmap is in an internal texture.
|
||||
*/
|
||||
typedef enum glamor_pixmap_type {
|
||||
GLAMOR_MEMORY,
|
||||
GLAMOR_MEMORY_MAP,
|
||||
GLAMOR_TEXTURE_DRM,
|
||||
GLAMOR_SEPARATE_TEXTURE,
|
||||
GLAMOR_DRM_ONLY,
|
||||
GLAMOR_TEXTURE_ONLY,
|
||||
GLAMOR_TEXTURE_LARGE,
|
||||
GLAMOR_TEXTURE_PACK
|
||||
} glamor_pixmap_type_t;
|
||||
|
||||
#define GLAMOR_EGL_EXTERNAL_BUFFER 3
|
||||
#define GLAMOR_INVERTED_Y_AXIS 1
|
||||
#define GLAMOR_USE_SCREEN (1 << 1)
|
||||
#define GLAMOR_USE_PICTURE_SCREEN (1 << 2)
|
||||
#define GLAMOR_USE_EGL_SCREEN (1 << 3)
|
||||
#define GLAMOR_VALID_FLAGS (GLAMOR_INVERTED_Y_AXIS \
|
||||
| GLAMOR_USE_SCREEN \
|
||||
| GLAMOR_USE_PICTURE_SCREEN \
|
||||
| GLAMOR_USE_EGL_SCREEN)
|
||||
|
||||
/* @glamor_init: Initialize glamor internal data structure.
|
||||
*
|
||||
* @screen: Current screen pointer.
|
||||
* @flags: Please refer the flags description above.
|
||||
*
|
||||
* @GLAMOR_INVERTED_Y_AXIS:
|
||||
* set 1 means the GL env's origin (0,0) is at top-left.
|
||||
* EGL/DRM platform is an example need to set this bit.
|
||||
* glx platform's origin is at bottom-left thus need to
|
||||
* clear this bit.
|
||||
*
|
||||
* @GLAMOR_USE_SCREEN:
|
||||
* If running in an pre-existing X environment, and the
|
||||
* gl context is GLX, then you should set this bit and
|
||||
* let the glamor to handle all the screen related
|
||||
* functions such as GC ops and CreatePixmap/DestroyPixmap.
|
||||
*
|
||||
* @GLAMOR_USE_PICTURE_SCREEN:
|
||||
* If don't use any other underlying DDX driver to handle
|
||||
* the picture related rendering functions, please set this
|
||||
* bit on. Otherwise, clear this bit. And then it is the DDX
|
||||
* driver's responsibility to determine how/when to jump to
|
||||
* glamor's picture compositing path.
|
||||
*
|
||||
* @GLAMOR_USE_EGL_SCREEN:
|
||||
* If you are using EGL layer, then please set this bit
|
||||
* on, otherwise, clear it.
|
||||
*
|
||||
* This function initializes necessary internal data structure
|
||||
* for glamor. And before calling into this function, the OpenGL
|
||||
* environment should be ready. Should be called before any real
|
||||
* glamor rendering or texture allocation functions. And should
|
||||
* be called after the DDX's screen initialization or at the last
|
||||
* step of the DDX's screen initialization.
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_init(ScreenPtr screen, unsigned int flags);
|
||||
extern _X_EXPORT void glamor_fini(ScreenPtr screen);
|
||||
|
||||
/* This function is used to free the glamor private screen's
|
||||
* resources. If the DDX driver is not set GLAMOR_USE_SCREEN,
|
||||
* then, DDX need to call this function at proper stage, if
|
||||
* it is the xorg DDX driver,then it should be called at free
|
||||
* screen stage not the close screen stage. The reason is after
|
||||
* call to this function, the xorg DDX may need to destroy the
|
||||
* screen pixmap which must be a glamor pixmap and requires
|
||||
* the internal data structure still exist at that time.
|
||||
* Otherwise, the glamor internal structure will not be freed.*/
|
||||
#ifndef XF86_SCRN_INTERFACE
|
||||
extern _X_EXPORT Bool glamor_close_screen(int scrnIndex, ScreenPtr screen);
|
||||
#else
|
||||
extern _X_EXPORT Bool glamor_close_screen(ScreenPtr screen);
|
||||
#endif
|
||||
|
||||
|
||||
/* Let glamor to know the screen's fbo. The low level
|
||||
* driver should already assign a tex
|
||||
* to this pixmap through the set_pixmap_texture. */
|
||||
extern _X_EXPORT void glamor_set_screen_pixmap(PixmapPtr screen_pixmap, PixmapPtr *back_pixmap);
|
||||
|
||||
/* @glamor_glyphs_init: Initialize glyphs internal data structures.
|
||||
*
|
||||
* @pScreen: Current screen pointer.
|
||||
*
|
||||
* This function must be called after the glamor_init and the texture
|
||||
* can be allocated. An example is to call it when create the screen
|
||||
* resources at DDX layer.
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_glyphs_init(ScreenPtr pScreen);
|
||||
|
||||
extern _X_EXPORT void glamor_set_pixmap_texture(PixmapPtr pixmap,
|
||||
unsigned int tex);
|
||||
|
||||
extern _X_EXPORT void glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type);
|
||||
extern _X_EXPORT void glamor_destroy_textured_pixmap(PixmapPtr pixmap);
|
||||
extern _X_EXPORT void glamor_block_handler(ScreenPtr screen);
|
||||
extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
|
||||
unsigned int usage);
|
||||
|
||||
extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen);
|
||||
|
||||
extern _X_EXPORT void glamor_egl_make_current(ScreenPtr screen);
|
||||
extern _X_EXPORT void glamor_egl_restore_context(ScreenPtr screen);
|
||||
|
||||
/* @glamor_egl_exchange_buffers: Exchange the underlying buffers(KHR image,fbo).
|
||||
*
|
||||
* @front: front pixmap.
|
||||
* @back: back pixmap.
|
||||
*
|
||||
* Used by the DRI2 page flip. This function will exchange the KHR images and
|
||||
* fbos of the two pixmaps.
|
||||
* */
|
||||
extern _X_EXPORT void glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back);
|
||||
|
||||
extern _X_EXPORT void glamor_pixmap_exchange_fbos(PixmapPtr front, PixmapPtr back);
|
||||
|
||||
/* The DDX is not supposed to call these three functions */
|
||||
extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen);
|
||||
extern _X_EXPORT unsigned int glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h);
|
||||
extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr, unsigned int, Bool, CARD16*, CARD32*);
|
||||
|
||||
/* @glamor_is_dri3_support_enabled: Returns if DRI3 support is enabled.
|
||||
*
|
||||
* @screen: Current screen pointer.
|
||||
*
|
||||
* To have DRI3 support enabled, glamor and glamor_egl need to be initialized,
|
||||
* and glamor_egl_init_textured_pixmap need to be called. glamor also
|
||||
* has to be compiled with gbm support.
|
||||
* The EGL layer need to have the following extensions working:
|
||||
* .EGL_KHR_gl_texture_2D_image
|
||||
* .EGL_EXT_image_dma_buf_import
|
||||
* If DRI3 support is not enabled, the following helpers will return an error.
|
||||
* */
|
||||
extern _X_EXPORT Bool glamor_is_dri3_support_enabled(ScreenPtr screen);
|
||||
|
||||
/* @glamor_dri3_fd_from_pixmap: DRI3 helper to get a dma-buf fd from a pixmap.
|
||||
*
|
||||
* @screen: Current screen pointer.
|
||||
* @pixmap: The pixmap from which we want the fd.
|
||||
* @stride, @size: Pointers to fill the stride and size of the
|
||||
* buffer associated to the fd.
|
||||
*
|
||||
* the pixmap and the buffer associated by the fd will share the same
|
||||
* content.
|
||||
* Returns the fd on success, -1 on error.
|
||||
* */
|
||||
extern _X_EXPORT int glamor_dri3_fd_from_pixmap (ScreenPtr screen,
|
||||
PixmapPtr pixmap,
|
||||
CARD16 *stride,
|
||||
CARD32 *size);
|
||||
|
||||
/* @glamor_dri3_name_from_pixmap: helper to get an gem name from a pixmap.
|
||||
*
|
||||
* @pixmap: The pixmap from which we want the gem name.
|
||||
*
|
||||
* the pixmap and the buffer associated by the gem name will share the same
|
||||
* content. This function can be used by the DDX to support DRI2, but needs
|
||||
* glamor DRI3 support to be activated.
|
||||
* Returns the name on success, -1 on error.
|
||||
* */
|
||||
extern _X_EXPORT int glamor_dri3_name_from_pixmap (PixmapPtr pixmap);
|
||||
|
||||
/* @glamor_egl_dri3_pixmap_from_fd: DRI3 helper to get a pixmap from a dma-buf fd.
|
||||
*
|
||||
* @screen: Current screen pointer.
|
||||
* @fd: The dma-buf fd to import.
|
||||
* @width: The width of the buffer.
|
||||
* @height: The height of the buffer.
|
||||
* @stride: The stride of the buffer.
|
||||
* @depth: The depth of the buffer.
|
||||
* @bpp: The number of bpp of the buffer.
|
||||
*
|
||||
* Returns a valid pixmap if the import succeeded, else NULL.
|
||||
* */
|
||||
extern _X_EXPORT PixmapPtr glamor_egl_dri3_pixmap_from_fd (ScreenPtr screen,
|
||||
int fd,
|
||||
CARD16 width,
|
||||
CARD16 height,
|
||||
CARD16 stride,
|
||||
CARD8 depth,
|
||||
CARD8 bpp);
|
||||
|
||||
#ifdef GLAMOR_FOR_XORG
|
||||
|
||||
#define GLAMOR_EGL_MODULE_NAME "glamoregl"
|
||||
|
||||
/* @glamor_egl_init: Initialize EGL environment.
|
||||
*
|
||||
* @scrn: Current screen info pointer.
|
||||
* @fd: Current drm fd.
|
||||
*
|
||||
* This function creates and intialize EGL contexts.
|
||||
* Should be called from DDX's preInit function.
|
||||
* Return TRUE if success, otherwise return FALSE.
|
||||
* */
|
||||
extern _X_EXPORT Bool glamor_egl_init(ScrnInfoPtr scrn, int fd);
|
||||
|
||||
/* @glamor_egl_init_textured_pixmap: Initialization for textured pixmap allocation.
|
||||
*
|
||||
* @screen: Current screen pointer.
|
||||
*
|
||||
* This function must be called before any textured pixmap's creation including
|
||||
* the screen pixmap. Could be called from DDX's screenInit function after the calling
|
||||
* to glamor_init..
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_egl_init_textured_pixmap(ScreenPtr screen);
|
||||
|
||||
/* @glamor_egl_create_textured_screen: Create textured screen pixmap.
|
||||
*
|
||||
* @screen: screen pointer to be processed.
|
||||
* @handle: screen pixmap's BO handle.
|
||||
* @stride: screen pixmap's stride in bytes.
|
||||
*
|
||||
* This function is similar with the create_textured_pixmap. As the
|
||||
* screen pixmap is a special, we handle it separately in this function.
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_egl_create_textured_screen(ScreenPtr screen,
|
||||
int handle,
|
||||
int stride);
|
||||
|
||||
/* @glamor_egl_create_textured_screen_ext:
|
||||
*
|
||||
* extent one parameter to track the pointer of the DDX layer's back pixmap.
|
||||
* We need this pointer during the closing screen stage. As before back to
|
||||
* the DDX's close screen, we have to free all the glamor related resources.
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_egl_create_textured_screen_ext(ScreenPtr screen,
|
||||
int handle,
|
||||
int stride,
|
||||
PixmapPtr *back_pixmap);
|
||||
|
||||
/*
|
||||
* @glamor_egl_create_textured_pixmap: Try to create a textured pixmap from
|
||||
* a BO handle.
|
||||
*
|
||||
* @pixmap: The pixmap need to be processed.
|
||||
* @handle: The BO's handle attached to this pixmap at DDX layer.
|
||||
* @stride: Stride in bytes for this pixmap.
|
||||
*
|
||||
* This function try to create a texture from the handle and attach
|
||||
* the texture to the pixmap , thus glamor can render to this pixmap
|
||||
* as well. Return true if successful, otherwise return FALSE.
|
||||
*/
|
||||
extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap,
|
||||
int handle,
|
||||
int stride);
|
||||
|
||||
/*
|
||||
* @glamor_egl_create_textured_pixmap_from_bo: Try to create a textured pixmap
|
||||
* from a gbm_bo.
|
||||
*
|
||||
* @pixmap: The pixmap need to be processed.
|
||||
* @bo: a pointer on a gbm_bo structure attached to this pixmap at DDX layer.
|
||||
*
|
||||
* This function is similar to glamor_egl_create_textured_pixmap.
|
||||
*/
|
||||
extern _X_EXPORT Bool
|
||||
glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
|
||||
void *bo);
|
||||
|
||||
#endif
|
||||
|
||||
extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);
|
||||
|
||||
extern _X_EXPORT int glamor_create_gc(GCPtr gc);
|
||||
|
||||
extern _X_EXPORT void glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable);
|
||||
/* Glamor rendering/drawing functions with XXX_nf.
|
||||
* nf means no fallback within glamor internal if possible. If glamor
|
||||
* fail to accelerate the operation, glamor will return a false, and the
|
||||
* caller need to implement fallback method. Return a true means the
|
||||
* rendering request get done successfully. */
|
||||
extern _X_EXPORT Bool glamor_fill_spans_nf(DrawablePtr drawable,
|
||||
GCPtr gc,
|
||||
int n, DDXPointPtr points,
|
||||
int *widths, int sorted);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_fill_rect_nf(DrawablePtr drawable,
|
||||
GCPtr gc,
|
||||
int nrect,
|
||||
xRectangle * prect);
|
||||
|
||||
extern _X_EXPORT Bool glamor_put_image_nf(DrawablePtr drawable,
|
||||
GCPtr gc, int depth, int x, int y,
|
||||
int w, int h, int left_pad,
|
||||
int image_format, char *bits);
|
||||
|
||||
extern _X_EXPORT Bool glamor_copy_n_to_n_nf(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc,
|
||||
BoxPtr box,
|
||||
int nbox,
|
||||
int dx,
|
||||
int dy,
|
||||
Bool reverse,
|
||||
Bool upsidedown, Pixel bitplane,
|
||||
void *closure);
|
||||
|
||||
extern _X_EXPORT Bool glamor_composite_nf(CARD8 op,
|
||||
PicturePtr source,
|
||||
PicturePtr mask,
|
||||
PicturePtr dest,
|
||||
INT16 x_source,
|
||||
INT16 y_source,
|
||||
INT16 x_mask,
|
||||
INT16 y_mask,
|
||||
INT16 x_dest, INT16 y_dest,
|
||||
CARD16 width, CARD16 height);
|
||||
|
||||
extern _X_EXPORT Bool glamor_trapezoids_nf(CARD8 op,
|
||||
PicturePtr src, PicturePtr dst,
|
||||
PictFormatPtr mask_format,
|
||||
INT16 x_src, INT16 y_src,
|
||||
int ntrap, xTrapezoid * traps);
|
||||
|
||||
extern _X_EXPORT Bool glamor_glyphs_nf(CARD8 op,
|
||||
PicturePtr src,
|
||||
PicturePtr dst,
|
||||
PictFormatPtr mask_format,
|
||||
INT16 x_src,
|
||||
INT16 y_src, int nlist,
|
||||
GlyphListPtr list, GlyphPtr * glyphs);
|
||||
|
||||
extern _X_EXPORT Bool glamor_triangles_nf(CARD8 op,
|
||||
PicturePtr pSrc,
|
||||
PicturePtr pDst,
|
||||
PictFormatPtr maskFormat,
|
||||
INT16 xSrc, INT16 ySrc,
|
||||
int ntris, xTriangle * tris);
|
||||
|
||||
|
||||
extern _X_EXPORT void glamor_glyph_unrealize(ScreenPtr screen, GlyphPtr glyph);
|
||||
|
||||
extern _X_EXPORT Bool glamor_set_spans_nf(DrawablePtr drawable, GCPtr gc, char *src,
|
||||
DDXPointPtr points, int *widths, int n, int sorted);
|
||||
|
||||
extern _X_EXPORT Bool glamor_get_spans_nf(DrawablePtr drawable, int wmax,
|
||||
DDXPointPtr points, int *widths, int count, char *dst);
|
||||
|
||||
extern _X_EXPORT Bool glamor_composite_rects_nf (CARD8 op,
|
||||
PicturePtr pDst,
|
||||
xRenderColor *color,
|
||||
int nRect,
|
||||
xRectangle *rects);
|
||||
|
||||
extern _X_EXPORT Bool glamor_get_image_nf(DrawablePtr pDrawable, int x, int y, int w, int h,
|
||||
unsigned int format, unsigned long planeMask, char *d);
|
||||
|
||||
extern _X_EXPORT Bool glamor_add_traps_nf(PicturePtr pPicture,
|
||||
INT16 x_off,
|
||||
INT16 y_off, int ntrap, xTrap * traps);
|
||||
|
||||
extern _X_EXPORT Bool glamor_copy_plane_nf(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
|
||||
int srcx, int srcy, int w, int h, int dstx, int dsty,
|
||||
unsigned long bitPlane, RegionPtr *pRegion);
|
||||
|
||||
extern _X_EXPORT Bool glamor_image_glyph_blt_nf(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_glyph_blt_nf(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase);
|
||||
|
||||
extern _X_EXPORT Bool glamor_push_pixels_nf(GCPtr pGC, PixmapPtr pBitmap,
|
||||
DrawablePtr pDrawable, int w, int h, int x, int y);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_point_nf(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
|
||||
DDXPointPtr ppt);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_segment_nf(DrawablePtr pDrawable, GCPtr pGC, int nseg,
|
||||
xSegment *pSeg);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_line_nf(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
|
||||
DDXPointPtr ppt);
|
||||
|
||||
extern _X_EXPORT Bool glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, int mode, int n,
|
||||
DDXPointPtr points);
|
||||
|
||||
extern _X_EXPORT XF86VideoAdaptorPtr glamor_xv_init(ScreenPtr pScreen, int num_texture_ports);
|
||||
|
||||
#endif /* GLAMOR_H */
|
65
glamor/glamor_addtraps.c
Normal file
65
glamor/glamor_addtraps.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_add_traps(PicturePtr pPicture,
|
||||
INT16 x_off,
|
||||
INT16 y_off, int ntrap, xTrap * traps,
|
||||
Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& ( !pPicture->pDrawable
|
||||
|| glamor_ddx_fallback_check_pixmap(pPicture->pDrawable)))
|
||||
return FALSE;
|
||||
|
||||
if (glamor_prepare_access_picture(pPicture, GLAMOR_ACCESS_RW)) {
|
||||
fbAddTraps(pPicture, x_off, y_off, ntrap, traps);
|
||||
glamor_finish_access_picture(pPicture, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_add_traps(PicturePtr pPicture,
|
||||
INT16 x_off,
|
||||
INT16 y_off, int ntrap, xTrap * traps)
|
||||
{
|
||||
_glamor_add_traps(pPicture, x_off, y_off, ntrap, traps, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_add_traps_nf(PicturePtr pPicture,
|
||||
INT16 x_off,
|
||||
INT16 y_off, int ntrap, xTrap * traps)
|
||||
{
|
||||
return _glamor_add_traps(pPicture, x_off, y_off, ntrap, traps, FALSE);
|
||||
}
|
||||
|
278
glamor/glamor_compositerects.c
Normal file
278
glamor/glamor_compositerects.c
Normal file
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
* original author is Chris Wilson at sna.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
#include "mipict.h"
|
||||
#include "damage.h"
|
||||
|
||||
/** @file glamor_compositerects.
|
||||
*
|
||||
* compositeRects acceleration implementation
|
||||
*/
|
||||
|
||||
static int16_t bound(int16_t a, uint16_t b)
|
||||
{
|
||||
int v = (int)a + (int)b;
|
||||
if (v > MAXSHORT)
|
||||
return MAXSHORT;
|
||||
return v;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_pixman_region_init_clipped_rectangles(pixman_region16_t *region,
|
||||
unsigned int num_rects,
|
||||
xRectangle *rects,
|
||||
int tx, int ty,
|
||||
BoxPtr extents)
|
||||
{
|
||||
pixman_box16_t stack_boxes[64], *boxes = stack_boxes;
|
||||
pixman_bool_t ret;
|
||||
unsigned int i, j;
|
||||
|
||||
if (num_rects > ARRAY_SIZE(stack_boxes)) {
|
||||
boxes = malloc(sizeof(pixman_box16_t) * num_rects);
|
||||
if (boxes == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = j = 0; i < num_rects; i++) {
|
||||
boxes[j].x1 = rects[i].x + tx;
|
||||
if (boxes[j].x1 < extents->x1)
|
||||
boxes[j].x1 = extents->x1;
|
||||
|
||||
boxes[j].y1 = rects[i].y + ty;
|
||||
if (boxes[j].y1 < extents->y1)
|
||||
boxes[j].y1 = extents->y1;
|
||||
|
||||
boxes[j].x2 = bound(rects[i].x + tx, rects[i].width);
|
||||
if (boxes[j].x2 > extents->x2)
|
||||
boxes[j].x2 = extents->x2;
|
||||
|
||||
boxes[j].y2 = bound(rects[i].y + ty, rects[i].height);
|
||||
if (boxes[j].y2 > extents->y2)
|
||||
boxes[j].y2 = extents->y2;
|
||||
|
||||
if (boxes[j].x2 > boxes[j].x1 && boxes[j].y2 > boxes[j].y1)
|
||||
j++;
|
||||
}
|
||||
|
||||
ret = FALSE;
|
||||
if (j)
|
||||
ret = pixman_region_init_rects(region, boxes, j);
|
||||
|
||||
if (boxes != stack_boxes)
|
||||
free(boxes);
|
||||
|
||||
DEBUGF("%s: nrects=%d, region=(%d, %d), (%d, %d) x %d\n",
|
||||
__FUNCTION__, num_rects,
|
||||
region->extents.x1, region->extents.y1,
|
||||
region->extents.x2, region->extents.y2,
|
||||
j);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glamor_composite_rectangles(CARD8 op,
|
||||
PicturePtr dst,
|
||||
xRenderColor *color,
|
||||
int num_rects,
|
||||
xRectangle *rects)
|
||||
{
|
||||
PixmapPtr pixmap;
|
||||
struct glamor_pixmap_private *priv;
|
||||
pixman_region16_t region;
|
||||
pixman_box16_t *boxes;
|
||||
int dst_x, dst_y;
|
||||
int num_boxes;
|
||||
PicturePtr source = NULL;
|
||||
Bool need_free_region = FALSE;
|
||||
|
||||
DEBUGF("%s(op=%d, %08x x %d [(%d, %d)x(%d, %d) ...])\n",
|
||||
__FUNCTION__, op,
|
||||
(color->alpha >> 8 << 24) |
|
||||
(color->red >> 8 << 16) |
|
||||
(color->green >> 8 << 8) |
|
||||
(color->blue >> 8 << 0),
|
||||
num_rects,
|
||||
rects[0].x, rects[0].y, rects[0].width, rects[0].height);
|
||||
|
||||
if (!num_rects)
|
||||
return;
|
||||
|
||||
if (region_is_empty(dst->pCompositeClip)) {
|
||||
DEBUGF("%s: empty clip, skipping\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((color->red|color->green|color->blue|color->alpha) <= 0x00ff) {
|
||||
switch (op) {
|
||||
case PictOpOver:
|
||||
case PictOpOutReverse:
|
||||
case PictOpAdd:
|
||||
return;
|
||||
case PictOpInReverse:
|
||||
case PictOpSrc:
|
||||
op = PictOpClear;
|
||||
break;
|
||||
case PictOpAtopReverse:
|
||||
op = PictOpOut;
|
||||
break;
|
||||
case PictOpXor:
|
||||
op = PictOpOverReverse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (color->alpha <= 0x00ff) {
|
||||
switch (op) {
|
||||
case PictOpOver:
|
||||
case PictOpOutReverse:
|
||||
return;
|
||||
case PictOpInReverse:
|
||||
op = PictOpClear;
|
||||
break;
|
||||
case PictOpAtopReverse:
|
||||
op = PictOpOut;
|
||||
break;
|
||||
case PictOpXor:
|
||||
op = PictOpOverReverse;
|
||||
break;
|
||||
}
|
||||
} else if (color->alpha >= 0xff00) {
|
||||
switch (op) {
|
||||
case PictOpOver:
|
||||
op = PictOpSrc;
|
||||
break;
|
||||
case PictOpInReverse:
|
||||
return;
|
||||
case PictOpOutReverse:
|
||||
op = PictOpClear;
|
||||
break;
|
||||
case PictOpAtopReverse:
|
||||
op = PictOpOverReverse;
|
||||
break;
|
||||
case PictOpXor:
|
||||
op = PictOpOut;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DEBUGF("%s: converted to op %d\n", __FUNCTION__, op);
|
||||
|
||||
if (!_pixman_region_init_clipped_rectangles(®ion,
|
||||
num_rects, rects,
|
||||
dst->pDrawable->x,
|
||||
dst->pDrawable->y,
|
||||
&dst->pCompositeClip->extents))
|
||||
{
|
||||
DEBUGF("%s: allocation failed for region\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
pixmap = glamor_get_drawable_pixmap(dst->pDrawable);
|
||||
priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv))
|
||||
goto fallback;
|
||||
if (dst->alphaMap) {
|
||||
DEBUGF("%s: fallback, dst has an alpha-map\n", __FUNCTION__);
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
need_free_region = TRUE;
|
||||
|
||||
DEBUGF("%s: drawable extents (%d, %d),(%d, %d) x %d\n",
|
||||
__FUNCTION__,
|
||||
RegionExtents(®ion)->x1, RegionExtents(®ion)->y1,
|
||||
RegionExtents(®ion)->x2, RegionExtents(®ion)->y2,
|
||||
RegionNumRects(®ion));
|
||||
|
||||
if (dst->pCompositeClip->data &&
|
||||
(!pixman_region_intersect(®ion, ®ion, dst->pCompositeClip) ||
|
||||
region_is_empty(®ion))) {
|
||||
DEBUGF("%s: zero-intersection between rectangles and clip\n",
|
||||
__FUNCTION__);
|
||||
pixman_region_fini(®ion);
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUGF("%s: clipped extents (%d, %d),(%d, %d) x %d\n",
|
||||
__FUNCTION__,
|
||||
RegionExtents(®ion)->x1, RegionExtents(®ion)->y1,
|
||||
RegionExtents(®ion)->x2, RegionExtents(®ion)->y2,
|
||||
RegionNumRects(®ion));
|
||||
|
||||
glamor_get_drawable_deltas(dst->pDrawable, pixmap, &dst_x, &dst_y);
|
||||
pixman_region_translate(®ion, dst_x, dst_y);
|
||||
|
||||
DEBUGF("%s: pixmap +(%d, %d) extents (%d, %d),(%d, %d)\n",
|
||||
__FUNCTION__, dst_x, dst_y,
|
||||
RegionExtents(®ion)->x1, RegionExtents(®ion)->y1,
|
||||
RegionExtents(®ion)->x2, RegionExtents(®ion)->y2);
|
||||
|
||||
|
||||
boxes = pixman_region_rectangles(®ion, &num_boxes);
|
||||
if (op == PictOpSrc || op == PictOpClear) {
|
||||
CARD32 pixel;
|
||||
if (op == PictOpClear)
|
||||
pixel = 0;
|
||||
else
|
||||
miRenderColorToPixel(dst->pFormat, color, &pixel);
|
||||
glamor_solid_boxes(pixmap, boxes, num_boxes, pixel);
|
||||
|
||||
goto done;
|
||||
} else {
|
||||
if (likely(priv->type != GLAMOR_TEXTURE_LARGE)) {
|
||||
int error;
|
||||
|
||||
source = CreateSolidPicture(0, color, &error);
|
||||
if (!source)
|
||||
goto done;
|
||||
if (glamor_composite_clipped_region(op, source,
|
||||
NULL, dst,
|
||||
NULL, NULL, priv,
|
||||
®ion,
|
||||
0,0,0,0,0,0))
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
fallback:
|
||||
miCompositeRects(op, dst, color, num_rects, rects);
|
||||
done:
|
||||
/* XXX xserver-1.8: CompositeRects is not tracked by Damage, so we must
|
||||
* manually append the damaged regions ourselves.
|
||||
*/
|
||||
DamageRegionAppend(&pixmap->drawable, ®ion);
|
||||
DamageRegionProcessPending(&pixmap->drawable);
|
||||
|
||||
if (need_free_region)
|
||||
pixman_region_fini(®ion);
|
||||
if (source)
|
||||
FreePicture(source, 0);
|
||||
return;
|
||||
}
|
676
glamor/glamor_copyarea.c
Normal file
676
glamor/glamor_copyarea.c
Normal file
|
@ -0,0 +1,676 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_copyarea.c
|
||||
*
|
||||
* GC CopyArea implementation
|
||||
*/
|
||||
#ifndef GLAMOR_GLES2
|
||||
static Bool
|
||||
glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
|
||||
{
|
||||
ScreenPtr screen = dst->pScreen;
|
||||
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
|
||||
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
|
||||
glamor_pixmap_private *src_pixmap_priv, *dst_pixmap_priv;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_gl_dispatch *dispatch;
|
||||
int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
|
||||
int fbo_x_off, fbo_y_off;
|
||||
int src_fbo_x_off, src_fbo_y_off;
|
||||
|
||||
if (!glamor_priv->has_fbo_blit) {
|
||||
glamor_delayed_fallback(screen,
|
||||
"no EXT_framebuffer_blit\n");
|
||||
return FALSE;
|
||||
}
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
||||
|
||||
if (gc) {
|
||||
if (gc->alu != GXcopy) {
|
||||
glamor_delayed_fallback(screen, "non-copy ALU\n");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)) {
|
||||
glamor_delayed_fallback(screen, "no src fbo\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (glamor_set_destination_pixmap(dst_pixmap))
|
||||
return FALSE;
|
||||
|
||||
pixmap_priv_get_fbo_off(dst_pixmap_priv, &fbo_x_off, &fbo_y_off);
|
||||
pixmap_priv_get_fbo_off(src_pixmap_priv, &src_fbo_x_off, &src_fbo_y_off);
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT,
|
||||
src_pixmap_priv->base.fbo->fb);
|
||||
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
||||
&dst_y_off);
|
||||
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
||||
&src_y_off);
|
||||
dst_x_off += fbo_x_off;
|
||||
dst_y_off += fbo_y_off;
|
||||
src_y_off += dy + src_fbo_y_off;
|
||||
src_x_off += src_fbo_x_off;
|
||||
|
||||
for (i = 0; i < nbox; i++) {
|
||||
if (glamor_priv->yInverted) {
|
||||
dispatch->glBlitFramebuffer((box[i].x1 + dx +
|
||||
src_x_off),
|
||||
(box[i].y1 +
|
||||
src_y_off),
|
||||
(box[i].x2 + dx +
|
||||
src_x_off),
|
||||
(box[i].y2 +
|
||||
src_y_off),
|
||||
(box[i].x1 +
|
||||
dst_x_off),
|
||||
(box[i].y1 +
|
||||
dst_y_off),
|
||||
(box[i].x2 +
|
||||
dst_x_off),
|
||||
(box[i].y2 +
|
||||
dst_y_off),
|
||||
GL_COLOR_BUFFER_BIT,
|
||||
GL_NEAREST);
|
||||
} else {
|
||||
int flip_dst_y1 =
|
||||
dst_pixmap->drawable.height - (box[i].y2 +
|
||||
dst_y_off);
|
||||
int flip_dst_y2 =
|
||||
dst_pixmap->drawable.height - (box[i].y1 +
|
||||
dst_y_off);
|
||||
int flip_src_y1 =
|
||||
src_pixmap->drawable.height - (box[i].y2 +
|
||||
src_y_off);
|
||||
int flip_src_y2 =
|
||||
src_pixmap->drawable.height - (box[i].y1 +
|
||||
src_y_off);
|
||||
|
||||
dispatch->glBlitFramebuffer(box[i].x1 + dx +
|
||||
src_x_off,
|
||||
flip_src_y1,
|
||||
box[i].x2 + dx +
|
||||
src_x_off,
|
||||
flip_src_y2,
|
||||
box[i].x1 +
|
||||
dst_x_off,
|
||||
flip_dst_y1,
|
||||
box[i].x2 +
|
||||
dst_x_off,
|
||||
flip_dst_y2,
|
||||
GL_COLOR_BUFFER_BIT,
|
||||
GL_NEAREST);
|
||||
}
|
||||
}
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
glamor_priv->state = BLIT_STATE;
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static Bool
|
||||
glamor_copy_n_to_n_textured(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
|
||||
{
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(dst->pScreen);
|
||||
glamor_gl_dispatch *dispatch;
|
||||
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
|
||||
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
|
||||
int i;
|
||||
float vertices[8], texcoords[8];
|
||||
glamor_pixmap_private *src_pixmap_priv;
|
||||
glamor_pixmap_private *dst_pixmap_priv;
|
||||
int src_x_off, src_y_off, dst_x_off, dst_y_off;
|
||||
enum glamor_pixmap_status src_status = GLAMOR_NONE;
|
||||
GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale;
|
||||
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
||||
|
||||
if (!src_pixmap_priv->base.gl_fbo) {
|
||||
#ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
|
||||
glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n");
|
||||
return FALSE;
|
||||
#else
|
||||
src_status = glamor_upload_pixmap_to_texture(src_pixmap);
|
||||
if (src_status != GLAMOR_UPLOAD_DONE)
|
||||
return FALSE;
|
||||
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale);
|
||||
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale);
|
||||
|
||||
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
||||
&dst_y_off);
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
|
||||
|
||||
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
|
||||
GL_FALSE, 2 * sizeof(float),
|
||||
vertices);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
|
||||
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
||||
&src_y_off);
|
||||
dx += src_x_off;
|
||||
dy += src_y_off;
|
||||
|
||||
dispatch->glActiveTexture(GL_TEXTURE0);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D,
|
||||
src_pixmap_priv->base.fbo->tex);
|
||||
#ifndef GLAMOR_GLES2
|
||||
dispatch->glEnable(GL_TEXTURE_2D);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_BORDER);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_BORDER);
|
||||
#endif
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
|
||||
GL_FLOAT, GL_FALSE,
|
||||
2 * sizeof(float),
|
||||
texcoords);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
dispatch->glUseProgram(glamor_priv->finish_access_prog[0]);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_revert[0],
|
||||
REVERT_NONE);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0],
|
||||
SWAP_NONE_UPLOADING);
|
||||
|
||||
for (i = 0; i < nbox; i++) {
|
||||
|
||||
glamor_set_normalize_vcoords(dst_pixmap_priv,
|
||||
dst_xscale, dst_yscale,
|
||||
box[i].x1 + dst_x_off,
|
||||
box[i].y1 + dst_y_off,
|
||||
box[i].x2 + dst_x_off,
|
||||
box[i].y2 + dst_y_off,
|
||||
glamor_priv->yInverted,
|
||||
vertices);
|
||||
|
||||
glamor_set_normalize_tcoords(src_pixmap_priv,
|
||||
src_xscale,
|
||||
src_yscale,
|
||||
box[i].x1 + dx,
|
||||
box[i].y1 + dy,
|
||||
box[i].x2 + dx,
|
||||
box[i].y2 + dy,
|
||||
glamor_priv->yInverted,
|
||||
texcoords);
|
||||
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
#ifndef GLAMOR_GLES2
|
||||
dispatch->glDisable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
dispatch->glUseProgram(0);
|
||||
/* The source texture is bound to a fbo, we have to flush it here. */
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
glamor_priv->state = RENDER_STATE;
|
||||
glamor_priv->render_idle_cnt = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Bool
|
||||
__glamor_copy_n_to_n(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc,
|
||||
BoxPtr box,
|
||||
int nbox,
|
||||
int dx,
|
||||
int dy,
|
||||
Bool reverse,
|
||||
Bool upsidedown, Pixel bitplane,
|
||||
void *closure)
|
||||
{
|
||||
PixmapPtr dst_pixmap, src_pixmap, temp_pixmap = NULL;
|
||||
DrawablePtr temp_src = src;
|
||||
glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
|
||||
glamor_screen_private *glamor_priv;
|
||||
BoxRec bound;
|
||||
ScreenPtr screen;
|
||||
int temp_dx = dx;
|
||||
int temp_dy = dy;
|
||||
int src_x_off, src_y_off, dst_x_off, dst_y_off;
|
||||
int i;
|
||||
int overlaped = 0;
|
||||
Bool ret = FALSE;
|
||||
|
||||
dst_pixmap = glamor_get_drawable_pixmap(dst);
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
||||
src_pixmap = glamor_get_drawable_pixmap(src);
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
screen = dst_pixmap->drawable.pScreen;
|
||||
glamor_priv = glamor_get_screen_private(dst->pScreen);
|
||||
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
||||
&src_y_off);
|
||||
|
||||
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
||||
&dst_y_off);
|
||||
|
||||
if (src_pixmap_priv->base.fbo
|
||||
&& src_pixmap_priv->base.fbo->fb == dst_pixmap_priv->base.fbo->fb) {
|
||||
int x_shift = abs(src_x_off - dx - dst_x_off);
|
||||
int y_shift = abs(src_y_off - dy - dst_y_off);
|
||||
for (i = 0; i < nbox; i++) {
|
||||
if (x_shift < abs(box[i].x2 - box[i].x1)
|
||||
&& y_shift < abs(box[i].y2 - box[i].y1)) {
|
||||
overlaped = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUGF("Copy %d %d %dx%d dx %d dy %d from %p to %p \n",
|
||||
box[0].x1, box[0].y1,
|
||||
box[0].x2 - box[0].x1, box[0].y2 - box[0].y1,
|
||||
dx, dy,
|
||||
src_pixmap, dst_pixmap);
|
||||
#ifndef GLAMOR_GLES2
|
||||
if (!overlaped &&
|
||||
(glamor_priv->state != RENDER_STATE
|
||||
|| !src_pixmap_priv->base.gl_tex || !dst_pixmap_priv->base.gl_tex)
|
||||
&& glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx,
|
||||
dy)) {
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
glamor_calculate_boxes_bound(&bound, box, nbox);
|
||||
|
||||
/* Overlaped indicate the src and dst are the same pixmap. */
|
||||
if (overlaped || (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)
|
||||
&& (((bound.x2 - bound.x1) * (bound.y2 - bound.y1)
|
||||
* 4 >
|
||||
src_pixmap->drawable.width *
|
||||
src_pixmap->drawable.height)
|
||||
|| !(glamor_check_fbo_size(glamor_priv,
|
||||
src_pixmap->drawable.width,
|
||||
src_pixmap->drawable.height))))) {
|
||||
|
||||
temp_pixmap = glamor_create_pixmap(screen,
|
||||
bound.x2 - bound.x1,
|
||||
bound.y2 - bound.y1,
|
||||
src_pixmap->
|
||||
drawable.depth,
|
||||
overlaped ? 0 :
|
||||
GLAMOR_CREATE_PIXMAP_CPU);
|
||||
assert(bound.x2 - bound.x1 <= glamor_priv->max_fbo_size);
|
||||
assert(bound.y2 - bound.y1 <= glamor_priv->max_fbo_size);
|
||||
if (!temp_pixmap)
|
||||
goto done;
|
||||
glamor_translate_boxes(box, nbox, -bound.x1, -bound.y1);
|
||||
temp_src = &temp_pixmap->drawable;
|
||||
|
||||
if (overlaped)
|
||||
glamor_copy_n_to_n_textured(src, temp_src, gc, box,
|
||||
nbox,
|
||||
temp_dx + bound.x1,
|
||||
temp_dy + bound.y1);
|
||||
else
|
||||
fbCopyNtoN(src, temp_src, gc, box, nbox,
|
||||
temp_dx + bound.x1, temp_dy + bound.y1,
|
||||
reverse, upsidedown, bitplane, closure);
|
||||
glamor_translate_boxes(box, nbox, bound.x1, bound.y1);
|
||||
temp_dx = -bound.x1;
|
||||
temp_dy = -bound.y1;
|
||||
} else {
|
||||
temp_dx = dx;
|
||||
temp_dy = dy;
|
||||
temp_src = src;
|
||||
}
|
||||
|
||||
if (glamor_copy_n_to_n_textured
|
||||
(temp_src, dst, gc, box, nbox, temp_dx, temp_dy)) {
|
||||
ret = TRUE;
|
||||
}
|
||||
done:
|
||||
if (temp_src != src)
|
||||
glamor_destroy_pixmap(temp_pixmap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_glamor_copy_n_to_n(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc,
|
||||
BoxPtr box,
|
||||
int nbox,
|
||||
int dx,
|
||||
int dy,
|
||||
Bool reverse,
|
||||
Bool upsidedown, Pixel bitplane,
|
||||
void *closure, Bool fallback)
|
||||
{
|
||||
PixmapPtr dst_pixmap, src_pixmap;
|
||||
glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
BoxPtr extent;
|
||||
RegionRec region;
|
||||
int src_x_off, src_y_off, dst_x_off, dst_y_off;
|
||||
Bool ok = FALSE;
|
||||
int force_clip = 0;
|
||||
|
||||
if (nbox == 0)
|
||||
return TRUE;
|
||||
dst_pixmap = glamor_get_drawable_pixmap(dst);
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
||||
src_pixmap = glamor_get_drawable_pixmap(src);
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
|
||||
glamor_priv = glamor_get_screen_private(dst->pScreen);
|
||||
|
||||
DEBUGF("Copy %d %d %dx%d dx %d dy %d from %p to %p \n",
|
||||
box[0].x1, box[0].y1,
|
||||
box[0].x2 - box[0].x1, box[0].y2 - box[0].y1,
|
||||
dx, dy,
|
||||
src_pixmap, dst_pixmap);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv))
|
||||
goto fall_back;
|
||||
|
||||
if (gc) {
|
||||
if (!glamor_set_planemask(dst_pixmap, gc->planemask))
|
||||
goto fall_back;
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
if (!glamor_set_alu(dispatch, gc->alu)) {
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
goto fail;
|
||||
}
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
if (!src_pixmap_priv) {
|
||||
glamor_set_pixmap_type(src_pixmap, GLAMOR_MEMORY);
|
||||
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
||||
}
|
||||
|
||||
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
||||
&src_y_off);
|
||||
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
||||
&dst_y_off);
|
||||
|
||||
RegionInitBoxes(®ion, box, nbox);
|
||||
extent = RegionExtents(®ion);
|
||||
|
||||
if (!glamor_check_fbo_size(glamor_priv,
|
||||
extent->x2 - extent->x1, extent->y2 - extent->y1)
|
||||
&& (src_pixmap_priv->type == GLAMOR_MEMORY
|
||||
|| (src_pixmap_priv == dst_pixmap_priv))) {
|
||||
force_clip = 1;
|
||||
}
|
||||
|
||||
if (force_clip || dst_pixmap_priv->type == GLAMOR_TEXTURE_LARGE
|
||||
|| src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
glamor_pixmap_clipped_regions *clipped_dst_regions;
|
||||
int n_dst_region, i, j;
|
||||
PixmapPtr temp_source_pixmap;
|
||||
glamor_pixmap_private *temp_source_priv = NULL;
|
||||
|
||||
RegionTranslate(®ion, dst_x_off, dst_y_off);
|
||||
if (!force_clip)
|
||||
clipped_dst_regions = glamor_compute_clipped_regions(dst_pixmap_priv,
|
||||
®ion, &n_dst_region, 0,
|
||||
reverse, upsidedown);
|
||||
else
|
||||
clipped_dst_regions = glamor_compute_clipped_regions_ext(dst_pixmap_priv,
|
||||
®ion, &n_dst_region,
|
||||
glamor_priv->max_fbo_size,
|
||||
glamor_priv->max_fbo_size,
|
||||
reverse, upsidedown);
|
||||
for(i = 0; i < n_dst_region; i++)
|
||||
{
|
||||
int n_src_region;
|
||||
glamor_pixmap_clipped_regions *clipped_src_regions;
|
||||
BoxPtr current_boxes;
|
||||
int n_current_boxes;
|
||||
|
||||
SET_PIXMAP_FBO_CURRENT(dst_pixmap_priv, clipped_dst_regions[i].block_idx);
|
||||
|
||||
temp_source_pixmap = NULL;
|
||||
if (src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
RegionTranslate(clipped_dst_regions[i].region,
|
||||
-dst_x_off + src_x_off + dx, -dst_y_off + src_y_off + dy);
|
||||
clipped_src_regions = glamor_compute_clipped_regions(src_pixmap_priv,
|
||||
clipped_dst_regions[i].region,
|
||||
&n_src_region, 0,
|
||||
reverse, upsidedown);
|
||||
DEBUGF("Source is large pixmap.\n");
|
||||
for (j = 0; j < n_src_region; j++)
|
||||
{
|
||||
if (src_pixmap_priv != dst_pixmap_priv)
|
||||
SET_PIXMAP_FBO_CURRENT(src_pixmap_priv, clipped_src_regions[j].block_idx);
|
||||
else if (src_pixmap_priv == dst_pixmap_priv &&
|
||||
clipped_src_regions[j].block_idx != clipped_dst_regions[i].block_idx) {
|
||||
/* source and the dest are the same, but need different block_idx.
|
||||
* we create a empty pixmap and fill the required source fbo and box to
|
||||
* it. It's a little hacky, but avoid extra copy. */
|
||||
temp_source_pixmap = glamor_create_pixmap(src->pScreen, 0, 0,
|
||||
src->depth, 0);
|
||||
if (!temp_source_pixmap) {
|
||||
ok = FALSE;
|
||||
goto fail;
|
||||
}
|
||||
src->pScreen->ModifyPixmapHeader(temp_source_pixmap,
|
||||
src_pixmap->drawable.width,
|
||||
src_pixmap->drawable.height,
|
||||
0, 0, src_pixmap->devKind, NULL);
|
||||
temp_source_priv = glamor_get_pixmap_private(temp_source_pixmap);
|
||||
*temp_source_priv = *src_pixmap_priv;
|
||||
temp_source_priv->large.box = src_pixmap_priv->large.box_array[clipped_src_regions[j].block_idx];
|
||||
temp_source_priv->base.fbo = src_pixmap_priv->large.fbo_array[clipped_src_regions[j].block_idx];
|
||||
temp_source_priv->base.pixmap = temp_source_pixmap;
|
||||
}
|
||||
assert(temp_source_pixmap || !(src_pixmap_priv == dst_pixmap_priv
|
||||
&& (clipped_src_regions[j].block_idx != clipped_dst_regions[i].block_idx)));
|
||||
|
||||
RegionTranslate(clipped_src_regions[j].region,
|
||||
-src_x_off - dx,
|
||||
-src_y_off - dy);
|
||||
current_boxes = RegionRects(clipped_src_regions[j].region);
|
||||
n_current_boxes = RegionNumRects(clipped_src_regions[j].region);
|
||||
DEBUGF("dst pixmap fbo idx %d src pixmap fbo idx %d \n",
|
||||
clipped_dst_regions[i].block_idx,
|
||||
clipped_src_regions[j].block_idx);
|
||||
DEBUGF("Copy %d %d %d %d dx %d dy %d from %p to %p \n",
|
||||
current_boxes[0].x1, current_boxes[0].y1,
|
||||
current_boxes[0].x2, current_boxes[0].y2,
|
||||
dx, dy, src_pixmap, dst_pixmap);
|
||||
if (!temp_source_pixmap)
|
||||
ok = __glamor_copy_n_to_n(src, dst, gc, current_boxes,
|
||||
n_current_boxes, dx, dy, reverse,
|
||||
upsidedown, bitplane, closure);
|
||||
else {
|
||||
ok = __glamor_copy_n_to_n(&temp_source_pixmap->drawable,
|
||||
dst, gc, current_boxes,
|
||||
n_current_boxes, dx, dy, reverse,
|
||||
upsidedown, bitplane, closure);
|
||||
temp_source_priv->type = GLAMOR_MEMORY;
|
||||
temp_source_priv->base.fbo = NULL;
|
||||
glamor_destroy_pixmap(temp_source_pixmap);
|
||||
temp_source_pixmap = NULL;
|
||||
}
|
||||
|
||||
RegionDestroy(clipped_src_regions[j].region);
|
||||
if (!ok) {
|
||||
assert(0);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (n_src_region == 0)
|
||||
ok = TRUE;
|
||||
free(clipped_src_regions);
|
||||
} else {
|
||||
RegionTranslate(clipped_dst_regions[i].region,
|
||||
- dst_x_off,
|
||||
- dst_y_off);
|
||||
current_boxes = RegionRects(clipped_dst_regions[i].region);
|
||||
n_current_boxes = RegionNumRects(clipped_dst_regions[i].region);
|
||||
|
||||
DEBUGF("dest pixmap fbo idx %d \n",
|
||||
clipped_dst_regions[i].block_idx);
|
||||
DEBUGF("Copy %d %d %d %d dx %d dy %d from %p to %p \n",
|
||||
current_boxes[0].x1, current_boxes[0].y1,
|
||||
current_boxes[0].x2, current_boxes[0].y2,
|
||||
dx, dy, src_pixmap, dst_pixmap);
|
||||
|
||||
ok = __glamor_copy_n_to_n(src, dst, gc, current_boxes,
|
||||
n_current_boxes, dx, dy, reverse,
|
||||
upsidedown, bitplane, closure);
|
||||
|
||||
}
|
||||
RegionDestroy(clipped_dst_regions[i].region);
|
||||
}
|
||||
if (n_dst_region == 0)
|
||||
ok = TRUE;
|
||||
free(clipped_dst_regions);
|
||||
RegionUninit(®ion);
|
||||
} else {
|
||||
ok = __glamor_copy_n_to_n(src, dst, gc, box, nbox, dx, dy,
|
||||
reverse, upsidedown, bitplane,
|
||||
closure);
|
||||
}
|
||||
|
||||
fail:
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_set_alu(dispatch, GXcopy);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
|
||||
if (ok)
|
||||
return TRUE;
|
||||
fall_back:
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(src)
|
||||
&& glamor_ddx_fallback_check_pixmap(dst))
|
||||
goto done;
|
||||
|
||||
if (src_pixmap_priv->type == GLAMOR_DRM_ONLY
|
||||
|| dst_pixmap_priv->type == GLAMOR_DRM_ONLY) {
|
||||
LogMessage(X_WARNING,
|
||||
"Access a DRM only pixmap is not allowed within glamor.\n");
|
||||
return TRUE;
|
||||
}
|
||||
glamor_report_delayed_fallbacks(src->pScreen);
|
||||
glamor_report_delayed_fallbacks(dst->pScreen);
|
||||
|
||||
glamor_fallback("from %p to %p (%c,%c)\n", src, dst,
|
||||
glamor_get_drawable_location(src),
|
||||
glamor_get_drawable_location(dst));
|
||||
|
||||
if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW)) {
|
||||
if (dst == src
|
||||
|| glamor_prepare_access(src, GLAMOR_ACCESS_RO)) {
|
||||
fbCopyNtoN(src, dst, gc, box, nbox,
|
||||
dx, dy, reverse, upsidedown, bitplane,
|
||||
closure);
|
||||
if (dst != src)
|
||||
glamor_finish_access(src, GLAMOR_ACCESS_RO);
|
||||
}
|
||||
glamor_finish_access(dst, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
ok = TRUE;
|
||||
|
||||
done:
|
||||
glamor_clear_delayed_fallbacks(src->pScreen);
|
||||
glamor_clear_delayed_fallbacks(dst->pScreen);
|
||||
return ok;
|
||||
}
|
||||
|
||||
RegionPtr
|
||||
glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
|
||||
int srcx, int srcy, int width, int height, int dstx,
|
||||
int dsty)
|
||||
{
|
||||
RegionPtr region;
|
||||
region = miDoCopy(src, dst, gc,
|
||||
srcx, srcy, width, height,
|
||||
dstx, dsty, glamor_copy_n_to_n, 0, NULL);
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_copy_n_to_n(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc,
|
||||
BoxPtr box,
|
||||
int nbox,
|
||||
int dx,
|
||||
int dy,
|
||||
Bool reverse,
|
||||
Bool upsidedown, Pixel bitplane,
|
||||
void *closure)
|
||||
{
|
||||
_glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
|
||||
dy, reverse, upsidedown, bitplane, closure, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_copy_n_to_n_nf(DrawablePtr src,
|
||||
DrawablePtr dst,
|
||||
GCPtr gc,
|
||||
BoxPtr box,
|
||||
int nbox,
|
||||
int dx,
|
||||
int dy,
|
||||
Bool reverse,
|
||||
Bool upsidedown, Pixel bitplane,
|
||||
void *closure)
|
||||
{
|
||||
return _glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
|
||||
dy, reverse, upsidedown, bitplane, closure, FALSE);
|
||||
}
|
||||
|
72
glamor/glamor_copyplane.c
Normal file
72
glamor/glamor_copyplane.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
|
||||
int srcx, int srcy, int w, int h, int dstx, int dsty,
|
||||
unsigned long bitPlane, RegionPtr *pRegion, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_gc(pGC)
|
||||
&& glamor_ddx_fallback_check_pixmap(pSrc)
|
||||
&& glamor_ddx_fallback_check_pixmap(pDst))
|
||||
goto fail;
|
||||
|
||||
glamor_prepare_access(pDst, GLAMOR_ACCESS_RW);
|
||||
glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO);
|
||||
*pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h,
|
||||
dstx, dsty, bitPlane);
|
||||
glamor_finish_access(pSrc, GLAMOR_ACCESS_RO);
|
||||
glamor_finish_access(pDst, GLAMOR_ACCESS_RW);
|
||||
return TRUE;
|
||||
|
||||
fail:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RegionPtr
|
||||
glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
|
||||
int srcx, int srcy, int w, int h, int dstx, int dsty,
|
||||
unsigned long bitPlane)
|
||||
{
|
||||
RegionPtr ret;
|
||||
_glamor_copy_plane(pSrc, pDst, pGC, srcx, srcy, w, h,
|
||||
dstx, dsty, bitPlane, &ret, TRUE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_copy_plane_nf(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
|
||||
int srcx, int srcy, int w, int h, int dstx, int dsty,
|
||||
unsigned long bitPlane, RegionPtr *pRegion)
|
||||
{
|
||||
return _glamor_copy_plane(pSrc, pDst, pGC, srcx, srcy, w, h,
|
||||
dstx, dsty, bitPlane, pRegion, FALSE);
|
||||
}
|
58
glamor/glamor_copywindow.c
Normal file
58
glamor/glamor_copywindow.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_copywindow.c
|
||||
*
|
||||
* Screen CopyWindow implementation.
|
||||
*/
|
||||
|
||||
void
|
||||
glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
|
||||
RegionPtr src_region)
|
||||
{
|
||||
RegionRec dst_region;
|
||||
int dx, dy;
|
||||
PixmapPtr pixmap = win->drawable.pScreen->GetWindowPixmap(win);
|
||||
|
||||
dx = old_origin.x - win->drawable.x;
|
||||
dy = old_origin.y - win->drawable.y;
|
||||
REGION_TRANSLATE(win->drawable.pScreen, src_region, -dx, -dy);
|
||||
|
||||
REGION_INIT(win->drawable.pScreen, &dst_region, NullBox, 0);
|
||||
|
||||
REGION_INTERSECT(win->drawable.pScreen, &dst_region,
|
||||
&win->borderClip, src_region);
|
||||
#ifdef COMPOSITE
|
||||
if (pixmap->screen_x || pixmap->screen_y)
|
||||
REGION_TRANSLATE(win->drawable.pScreen, &dst_region,
|
||||
-pixmap->screen_x, -pixmap->screen_y);
|
||||
#endif
|
||||
|
||||
miCopyRegion(&pixmap->drawable, &pixmap->drawable,
|
||||
NULL, &dst_region, dx, dy, glamor_copy_n_to_n, 0,
|
||||
NULL);
|
||||
|
||||
REGION_UNINIT(win->drawable.pScreen, &dst_region);
|
||||
}
|
612
glamor/glamor_core.c
Normal file
612
glamor/glamor_core.c
Normal file
|
@ -0,0 +1,612 @@
|
|||
/*
|
||||
* Copyright © 2001 Keith Packard
|
||||
* Copyright © 2008 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
*
|
||||
*/
|
||||
|
||||
/** @file glamor_core.c
|
||||
*
|
||||
* This file covers core X rendering in glamor.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
const Bool
|
||||
glamor_get_drawable_location(const DrawablePtr drawable)
|
||||
{
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(pixmap);
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(drawable->pScreen);
|
||||
if (pixmap_priv == NULL || pixmap_priv->base.gl_fbo == 0)
|
||||
return 'm';
|
||||
if (pixmap_priv->base.fbo->fb == glamor_priv->screen_fbo)
|
||||
return 's';
|
||||
else
|
||||
return 'f';
|
||||
}
|
||||
|
||||
GLint
|
||||
glamor_compile_glsl_prog(glamor_gl_dispatch * dispatch, GLenum type,
|
||||
const char *source)
|
||||
{
|
||||
GLint ok;
|
||||
GLint prog;
|
||||
|
||||
prog = dispatch->glCreateShader(type);
|
||||
dispatch->glShaderSource(prog, 1, (const GLchar **) &source, NULL);
|
||||
dispatch->glCompileShader(prog);
|
||||
dispatch->glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
|
||||
if (!ok) {
|
||||
GLchar *info;
|
||||
GLint size;
|
||||
|
||||
dispatch->glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
|
||||
info = malloc(size);
|
||||
if (info) {
|
||||
dispatch->glGetShaderInfoLog(prog, size, NULL, info);
|
||||
ErrorF("Failed to compile %s: %s\n",
|
||||
type == GL_FRAGMENT_SHADER ? "FS" : "VS", info);
|
||||
ErrorF("Program source:\n%s", source);
|
||||
free(info);
|
||||
} else
|
||||
ErrorF("Failed to get shader compilation info.\n");
|
||||
FatalError("GLSL compile failure\n");
|
||||
}
|
||||
|
||||
return prog;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_link_glsl_prog(glamor_gl_dispatch * dispatch, GLint prog)
|
||||
{
|
||||
GLint ok;
|
||||
|
||||
dispatch->glLinkProgram(prog);
|
||||
dispatch->glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
||||
if (!ok) {
|
||||
GLchar *info;
|
||||
GLint size;
|
||||
|
||||
dispatch->glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
|
||||
info = malloc(size);
|
||||
|
||||
dispatch->glGetProgramInfoLog(prog, size, NULL, info);
|
||||
ErrorF("Failed to link: %s\n", info);
|
||||
FatalError("GLSL link failure\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
glamor_prepare_access(DrawablePtr drawable, glamor_access_t access)
|
||||
{
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
return glamor_download_pixmap_to_cpu(pixmap, access);
|
||||
}
|
||||
|
||||
/*
|
||||
* When downloading a unsupported color format to CPU memory,
|
||||
we need to shuffle the color elements and then use a supported
|
||||
color format to read it back to CPU memory.
|
||||
|
||||
For an example, the picture's format is PICT_b8g8r8a8,
|
||||
Then the expecting color layout is as below (little endian):
|
||||
0 1 2 3 : address
|
||||
a r g b
|
||||
|
||||
Now the in GLES2 the supported color format is GL_RGBA, type is
|
||||
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
|
||||
color as :
|
||||
frag_color = sample(texture).argb;
|
||||
before we use glReadPixel to get it back.
|
||||
|
||||
For the uploading process, the shuffle is a revert shuffle.
|
||||
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
|
||||
to a texture, then let's see
|
||||
0 1 2 3 : address
|
||||
a r g b : correct colors
|
||||
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
|
||||
|
||||
Now we need to shuffle again, the mapping rule is
|
||||
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
|
||||
below:
|
||||
frag_color = sample(texture).gbar;
|
||||
*/
|
||||
|
||||
void
|
||||
glamor_init_finish_access_shaders(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
const char *vs_source =
|
||||
"attribute vec4 v_position;\n"
|
||||
"attribute vec4 v_texcoord0;\n"
|
||||
"varying vec2 source_texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = v_position;\n"
|
||||
" source_texture = v_texcoord0.xy;\n" "}\n";
|
||||
|
||||
const char *common_source =
|
||||
GLAMOR_DEFAULT_PRECISION
|
||||
"varying vec2 source_texture;\n"
|
||||
"uniform sampler2D sampler;\n"
|
||||
"uniform int revert;\n"
|
||||
"uniform int swap_rb;\n"
|
||||
|
||||
"#define REVERT_NONE 0\n"
|
||||
"#define REVERT_NORMAL 1\n"
|
||||
"#define SWAP_NONE_DOWNLOADING 0\n"
|
||||
"#define SWAP_DOWNLOADING 1\n"
|
||||
"#define SWAP_UPLOADING 2\n"
|
||||
"#define SWAP_NONE_UPLOADING 3\n";
|
||||
|
||||
const char *fs_source =
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" if (revert == REVERT_NONE) \n"
|
||||
" { \n"
|
||||
" if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING)) \n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).bgra;\n"
|
||||
" else \n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).rgba;\n"
|
||||
" } \n"
|
||||
" else \n"
|
||||
" { \n"
|
||||
" if (swap_rb == SWAP_DOWNLOADING) \n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).argb;\n"
|
||||
" else if (swap_rb == SWAP_NONE_DOWNLOADING)\n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).abgr;\n"
|
||||
" else if (swap_rb == SWAP_UPLOADING)\n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).gbar;\n"
|
||||
" else if (swap_rb == SWAP_NONE_UPLOADING)\n"
|
||||
" gl_FragColor = texture2D(sampler, source_texture).abgr;\n"
|
||||
" } \n" "}\n";
|
||||
|
||||
const char *set_alpha_source =
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" if (revert == REVERT_NONE) \n"
|
||||
" { \n"
|
||||
" if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING)) \n"
|
||||
" gl_FragColor = vec4(texture2D(sampler, source_texture).bgr, 1);\n"
|
||||
" else \n"
|
||||
" gl_FragColor = vec4(texture2D(sampler, source_texture).rgb, 1);\n"
|
||||
" } \n"
|
||||
" else \n"
|
||||
" { \n"
|
||||
" if (swap_rb == SWAP_DOWNLOADING) \n"
|
||||
" gl_FragColor = vec4(1, texture2D(sampler, source_texture).rgb);\n"
|
||||
" else if (swap_rb == SWAP_NONE_DOWNLOADING)\n"
|
||||
" gl_FragColor = vec4(1, texture2D(sampler, source_texture).bgr);\n"
|
||||
" else if (swap_rb == SWAP_UPLOADING)\n"
|
||||
" gl_FragColor = vec4(texture2D(sampler, source_texture).gba, 1);\n"
|
||||
" else if (swap_rb == SWAP_NONE_UPLOADING)\n"
|
||||
" gl_FragColor = vec4(texture2D(sampler, source_texture).abg, 1);\n"
|
||||
" } \n"
|
||||
"}\n";
|
||||
GLint fs_prog, vs_prog, avs_prog, set_alpha_prog;
|
||||
GLint sampler_uniform_location;
|
||||
char *source;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_priv->finish_access_prog[0] = dispatch->glCreateProgram();
|
||||
glamor_priv->finish_access_prog[1] = dispatch->glCreateProgram();
|
||||
|
||||
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER,
|
||||
vs_source);
|
||||
|
||||
XNFasprintf(&source, "%s%s", common_source, fs_source);
|
||||
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER,
|
||||
source);
|
||||
free(source);
|
||||
|
||||
dispatch->glAttachShader(glamor_priv->finish_access_prog[0],
|
||||
vs_prog);
|
||||
dispatch->glAttachShader(glamor_priv->finish_access_prog[0],
|
||||
fs_prog);
|
||||
|
||||
avs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER,
|
||||
vs_source);
|
||||
|
||||
XNFasprintf(&source, "%s%s", common_source, set_alpha_source);
|
||||
set_alpha_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER,
|
||||
source);
|
||||
free(source);
|
||||
|
||||
dispatch->glAttachShader(glamor_priv->finish_access_prog[1],
|
||||
avs_prog);
|
||||
dispatch->glAttachShader(glamor_priv->finish_access_prog[1],
|
||||
set_alpha_prog);
|
||||
|
||||
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[0],
|
||||
GLAMOR_VERTEX_POS, "v_position");
|
||||
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[0],
|
||||
GLAMOR_VERTEX_SOURCE,
|
||||
"v_texcoord0");
|
||||
glamor_link_glsl_prog(dispatch,
|
||||
glamor_priv->finish_access_prog[0]);
|
||||
|
||||
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[1],
|
||||
GLAMOR_VERTEX_POS, "v_position");
|
||||
dispatch->glBindAttribLocation(glamor_priv->finish_access_prog[1],
|
||||
GLAMOR_VERTEX_SOURCE,
|
||||
"v_texcoord0");
|
||||
glamor_link_glsl_prog(dispatch,
|
||||
glamor_priv->finish_access_prog[1]);
|
||||
|
||||
glamor_priv->finish_access_revert[0] =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[0],
|
||||
"revert");
|
||||
|
||||
glamor_priv->finish_access_swap_rb[0] =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[0],
|
||||
"swap_rb");
|
||||
sampler_uniform_location =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[0],
|
||||
"sampler");
|
||||
dispatch->glUseProgram(glamor_priv->finish_access_prog[0]);
|
||||
dispatch->glUniform1i(sampler_uniform_location, 0);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_revert[0], 0);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[0], 0);
|
||||
dispatch->glUseProgram(0);
|
||||
|
||||
glamor_priv->finish_access_revert[1] =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[1],
|
||||
"revert");
|
||||
glamor_priv->finish_access_swap_rb[1] =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[1],
|
||||
"swap_rb");
|
||||
sampler_uniform_location =
|
||||
dispatch->
|
||||
glGetUniformLocation(glamor_priv->finish_access_prog[1],
|
||||
"sampler");
|
||||
dispatch->glUseProgram(glamor_priv->finish_access_prog[1]);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_revert[1], 0);
|
||||
dispatch->glUniform1i(sampler_uniform_location, 0);
|
||||
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[1], 0);
|
||||
dispatch->glUseProgram(0);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_fini_finish_access_shaders(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glDeleteProgram(glamor_priv->finish_access_prog[0]);
|
||||
dispatch->glDeleteProgram(glamor_priv->finish_access_prog[1]);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode)
|
||||
{
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(pixmap);
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(drawable->pScreen);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO_DOWNLOADED(pixmap_priv))
|
||||
return;
|
||||
|
||||
if (access_mode != GLAMOR_ACCESS_RO) {
|
||||
glamor_restore_pixmap_to_texture(pixmap);
|
||||
}
|
||||
|
||||
if (pixmap_priv->base.fbo->pbo != 0 && pixmap_priv->base.fbo->pbo_valid) {
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
dispatch->glDeleteBuffers(1, &pixmap_priv->base.fbo->pbo);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
|
||||
pixmap_priv->base.fbo->pbo_valid = FALSE;
|
||||
pixmap_priv->base.fbo->pbo = 0;
|
||||
} else {
|
||||
free(pixmap->devPrivate.ptr);
|
||||
}
|
||||
|
||||
if (pixmap_priv->type == GLAMOR_TEXTURE_DRM)
|
||||
pixmap->devKind = pixmap_priv->base.drm_stride;
|
||||
|
||||
if (pixmap_priv->base.gl_fbo == GLAMOR_FBO_DOWNLOADED)
|
||||
pixmap_priv->base.gl_fbo = GLAMOR_FBO_NORMAL;
|
||||
|
||||
pixmap->devPrivate.ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls uxa_prepare_access with UXA_PREPARE_SRC for the tile, if that is the
|
||||
* current fill style.
|
||||
*
|
||||
* Solid doesn't use an extra pixmap source, so we don't worry about them.
|
||||
* Stippled/OpaqueStippled are 1bpp and can be in fb, so we should worry
|
||||
* about them.
|
||||
*/
|
||||
Bool
|
||||
glamor_prepare_access_gc(GCPtr gc)
|
||||
{
|
||||
if (gc->stipple) {
|
||||
if (!glamor_prepare_access
|
||||
(&gc->stipple->drawable, GLAMOR_ACCESS_RO))
|
||||
return FALSE;
|
||||
}
|
||||
if (gc->fillStyle == FillTiled) {
|
||||
if (!glamor_prepare_access(&gc->tile.pixmap->drawable,
|
||||
GLAMOR_ACCESS_RO)) {
|
||||
if (gc->stipple)
|
||||
glamor_finish_access(&gc->
|
||||
stipple->drawable,
|
||||
GLAMOR_ACCESS_RO);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes access to the tile in the GC, if used.
|
||||
*/
|
||||
void
|
||||
glamor_finish_access_gc(GCPtr gc)
|
||||
{
|
||||
if (gc->fillStyle == FillTiled)
|
||||
glamor_finish_access(&gc->tile.pixmap->drawable, GLAMOR_ACCESS_RO);
|
||||
if (gc->stipple)
|
||||
glamor_finish_access(&gc->stipple->drawable, GLAMOR_ACCESS_RO);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple,
|
||||
int x, int y, int width, int height,
|
||||
unsigned char alu, unsigned long planemask,
|
||||
unsigned long fg_pixel, unsigned long bg_pixel,
|
||||
int stipple_x, int stipple_y)
|
||||
{
|
||||
glamor_fallback("stubbed out stipple depth %d\n",
|
||||
pixmap->drawable.depth);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GCOps glamor_gc_ops = {
|
||||
.FillSpans = glamor_fill_spans,
|
||||
.SetSpans = glamor_set_spans,
|
||||
.PutImage = glamor_put_image,
|
||||
.CopyArea = glamor_copy_area,
|
||||
.CopyPlane = glamor_copy_plane,
|
||||
.PolyPoint = glamor_poly_point,
|
||||
.Polylines = glamor_poly_lines,
|
||||
.PolySegment = glamor_poly_segment,
|
||||
.PolyRectangle = miPolyRectangle,
|
||||
.PolyArc = miPolyArc,
|
||||
.FillPolygon = miFillPolygon,
|
||||
.PolyFillRect = glamor_poly_fill_rect,
|
||||
.PolyFillArc = miPolyFillArc,
|
||||
.PolyText8 = miPolyText8,
|
||||
.PolyText16 = miPolyText16,
|
||||
.ImageText8 = miImageText8,
|
||||
.ImageText16 = miImageText16,
|
||||
.ImageGlyphBlt = glamor_image_glyph_blt, //miImageGlyphBlt,
|
||||
.PolyGlyphBlt = glamor_poly_glyph_blt, //miPolyGlyphBlt,
|
||||
.PushPixels = glamor_push_pixels, //miPushPixels,
|
||||
};
|
||||
|
||||
/**
|
||||
* uxa_validate_gc() sets the ops to glamor's implementations, which may be
|
||||
* accelerated or may sync the card and fall back to fb.
|
||||
*/
|
||||
void
|
||||
glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
|
||||
{
|
||||
/* fbValidateGC will do direct access to pixmaps if the tiling has changed.
|
||||
* Preempt fbValidateGC by doing its work and masking the change out, so
|
||||
* that we can do the Prepare/finish_access.
|
||||
*/
|
||||
#ifdef FB_24_32BIT
|
||||
if ((changes & GCTile) && fbGetRotatedPixmap(gc)) {
|
||||
gc->pScreen->DestroyPixmap(fbGetRotatedPixmap(gc));
|
||||
fbGetRotatedPixmap(gc) = 0;
|
||||
}
|
||||
|
||||
if (gc->fillStyle == FillTiled) {
|
||||
PixmapPtr old_tile, new_tile;
|
||||
|
||||
old_tile = gc->tile.pixmap;
|
||||
if (old_tile->drawable.bitsPerPixel !=
|
||||
drawable->bitsPerPixel) {
|
||||
new_tile = fbGetRotatedPixmap(gc);
|
||||
if (!new_tile ||
|
||||
new_tile->drawable.bitsPerPixel !=
|
||||
drawable->bitsPerPixel) {
|
||||
if (new_tile)
|
||||
gc->pScreen->DestroyPixmap
|
||||
(new_tile);
|
||||
/* fb24_32ReformatTile will do direct access of a newly-
|
||||
* allocated pixmap.
|
||||
*/
|
||||
glamor_fallback
|
||||
("GC %p tile FB_24_32 transformat %p.\n",
|
||||
gc, old_tile);
|
||||
|
||||
if (glamor_prepare_access
|
||||
(&old_tile->drawable,
|
||||
GLAMOR_ACCESS_RO)) {
|
||||
new_tile =
|
||||
fb24_32ReformatTile
|
||||
(old_tile,
|
||||
drawable->bitsPerPixel);
|
||||
glamor_finish_access
|
||||
(&old_tile->drawable, GLAMOR_ACCESS_RO);
|
||||
}
|
||||
}
|
||||
if (new_tile) {
|
||||
fbGetRotatedPixmap(gc) = old_tile;
|
||||
gc->tile.pixmap = new_tile;
|
||||
changes |= GCTile;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (changes & GCTile) {
|
||||
if (!gc->tileIsPixel) {
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(gc->tile.pixmap);
|
||||
if ((!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
||||
&& FbEvenTile(gc->tile.pixmap->drawable.width *
|
||||
drawable->bitsPerPixel)) {
|
||||
glamor_fallback
|
||||
("GC %p tile changed %p.\n", gc,
|
||||
gc->tile.pixmap);
|
||||
if (glamor_prepare_access
|
||||
(&gc->tile.pixmap->drawable,
|
||||
GLAMOR_ACCESS_RW)) {
|
||||
fbPadPixmap(gc->tile.pixmap);
|
||||
glamor_finish_access
|
||||
(&gc->tile.pixmap->drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Mask out the GCTile change notification, now that we've done FB's
|
||||
* job for it.
|
||||
*/
|
||||
changes &= ~GCTile;
|
||||
}
|
||||
|
||||
if (changes & GCStipple && gc->stipple) {
|
||||
/* We can't inline stipple handling like we do for GCTile because
|
||||
* it sets fbgc privates.
|
||||
*/
|
||||
if (glamor_prepare_access
|
||||
(&gc->stipple->drawable, GLAMOR_ACCESS_RW)) {
|
||||
fbValidateGC(gc, changes, drawable);
|
||||
glamor_finish_access(&gc->stipple->drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
} else {
|
||||
fbValidateGC(gc, changes, drawable);
|
||||
}
|
||||
|
||||
gc->ops = &glamor_gc_ops;
|
||||
}
|
||||
|
||||
static GCFuncs glamor_gc_funcs = {
|
||||
glamor_validate_gc,
|
||||
miChangeGC,
|
||||
miCopyGC,
|
||||
miDestroyGC,
|
||||
miChangeClip,
|
||||
miDestroyClip,
|
||||
miCopyClip
|
||||
};
|
||||
|
||||
/**
|
||||
* exaCreateGC makes a new GC and hooks up its funcs handler, so that
|
||||
* exaValidateGC() will get called.
|
||||
*/
|
||||
int
|
||||
glamor_create_gc(GCPtr gc)
|
||||
{
|
||||
if (!fbCreateGC(gc))
|
||||
return FALSE;
|
||||
|
||||
gc->funcs = &glamor_gc_funcs;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
RegionPtr
|
||||
glamor_bitmap_to_region(PixmapPtr pixmap)
|
||||
{
|
||||
RegionPtr ret;
|
||||
glamor_fallback("pixmap %p \n", pixmap);
|
||||
if (!glamor_prepare_access(&pixmap->drawable, GLAMOR_ACCESS_RO))
|
||||
return NULL;
|
||||
ret = fbPixmapToRegion(pixmap);
|
||||
glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RO);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Borrow from cairo. */
|
||||
Bool
|
||||
glamor_gl_has_extension(const char *extension)
|
||||
{
|
||||
const char *pext;
|
||||
int ext_len;
|
||||
ext_len = strlen(extension);
|
||||
|
||||
pext = (const char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
if (pext == NULL || extension == NULL)
|
||||
return FALSE;
|
||||
|
||||
while ((pext = strstr(pext, extension)) != NULL) {
|
||||
if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
|
||||
return TRUE;
|
||||
pext += ext_len;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
glamor_gl_get_version(void)
|
||||
{
|
||||
int major, minor;
|
||||
const char *version = (const char *) glGetString(GL_VERSION);
|
||||
const char *dot = version == NULL ? NULL : strchr(version, '.');
|
||||
const char *major_start = dot;
|
||||
|
||||
/* Sanity check */
|
||||
if (dot == NULL || dot == version || *(dot + 1) == '\0') {
|
||||
major = 0;
|
||||
minor = 0;
|
||||
} else {
|
||||
/* Find the start of the major version in the string */
|
||||
while (major_start > version && *major_start != ' ')
|
||||
--major_start;
|
||||
major = strtol(major_start, NULL, 10);
|
||||
minor = strtol(dot + 1, NULL, 10);
|
||||
}
|
||||
|
||||
return GLAMOR_GL_VERSION_ENCODE(major, minor);
|
||||
}
|
116
glamor/glamor_debug.h
Normal file
116
glamor/glamor_debug.h
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GLAMOR_DEBUG_H__
|
||||
#define __GLAMOR_DEBUG_H__
|
||||
|
||||
|
||||
#define GLAMOR_DELAYED_STRING_MAX 64
|
||||
|
||||
#define GLAMOR_DEBUG_NONE 0
|
||||
#define GLAMOR_DEBUG_UNIMPL 0
|
||||
#define GLAMOR_DEBUG_FALLBACK 1
|
||||
#define GLAMOR_DEBUG_TEXTURE_DOWNLOAD 2
|
||||
#define GLAMOR_DEBUG_TEXTURE_DYNAMIC_UPLOAD 3
|
||||
|
||||
extern void
|
||||
AbortServer(void)
|
||||
_X_NORETURN;
|
||||
|
||||
#define GLAMOR_PANIC(_format_, ...) \
|
||||
do { \
|
||||
LogMessageVerb(X_NONE, 0, "Glamor Fatal Error" \
|
||||
" at %32s line %d: " _format_ "\n", \
|
||||
__FUNCTION__, __LINE__, \
|
||||
##__VA_ARGS__ ); \
|
||||
exit(1); \
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
|
||||
#define __debug_output_message(_format_, _prefix_, ...) \
|
||||
LogMessageVerb(X_NONE, 0, \
|
||||
"%32s:\t" _format_ , \
|
||||
/*_prefix_,*/ \
|
||||
__FUNCTION__, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
#define glamor_debug_output(_level_, _format_,...) \
|
||||
do { \
|
||||
if (glamor_debug_level >= _level_) \
|
||||
__debug_output_message(_format_, \
|
||||
"Glamor debug", \
|
||||
##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define glamor_fallback(_format_,...) \
|
||||
do { \
|
||||
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) \
|
||||
__debug_output_message(_format_, \
|
||||
"Glamor fallback", \
|
||||
##__VA_ARGS__);} while(0)
|
||||
|
||||
|
||||
|
||||
#define glamor_delayed_fallback(_screen_, _format_,...) \
|
||||
do { \
|
||||
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
|
||||
glamor_screen_private *_glamor_priv_; \
|
||||
_glamor_priv_ = glamor_get_screen_private(_screen_); \
|
||||
_glamor_priv_->delayed_fallback_pending = 1; \
|
||||
snprintf(_glamor_priv_->delayed_fallback_string, \
|
||||
GLAMOR_DELAYED_STRING_MAX, \
|
||||
"glamor delayed fallback: \t%s " _format_ , \
|
||||
__FUNCTION__, ##__VA_ARGS__); } } while(0)
|
||||
|
||||
|
||||
#define glamor_clear_delayed_fallbacks(_screen_) \
|
||||
do { \
|
||||
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
|
||||
glamor_screen_private *_glamor_priv_; \
|
||||
_glamor_priv_ = glamor_get_screen_private(_screen_); \
|
||||
_glamor_priv_->delayed_fallback_pending = 0; } } while(0)
|
||||
|
||||
#define glamor_report_delayed_fallbacks(_screen_) \
|
||||
do { \
|
||||
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
|
||||
glamor_screen_private *_glamor_priv_; \
|
||||
_glamor_priv_ = glamor_get_screen_private(_screen_); \
|
||||
LogMessageVerb(X_INFO, 0, "%s", \
|
||||
_glamor_priv_->delayed_fallback_string); \
|
||||
_glamor_priv_->delayed_fallback_pending = 0; } } while(0)
|
||||
|
||||
#define DEBUGF(str, ...) do {} while(0)
|
||||
//#define DEBUGF(str, ...) ErrorF(str, ##__VA_ARGS__)
|
||||
#define DEBUGRegionPrint(x) do {} while (0)
|
||||
//#define DEBUGRegionPrint RegionPrint
|
||||
|
||||
|
||||
#endif
|
860
glamor/glamor_egl.c
Normal file
860
glamor/glamor_egl.c
Normal file
|
@ -0,0 +1,860 @@
|
|||
/*
|
||||
* Copyright © 2010 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including
|
||||
* the next paragraph) shall be included in all copies or substantial
|
||||
* portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define GLAMOR_FOR_XORG
|
||||
#include <xorg-server.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <xf86.h>
|
||||
#include <xf86drm.h>
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#define EGL_DISPLAY_NO_X_MESA
|
||||
|
||||
#ifdef GLAMOR_HAS_GBM
|
||||
#include <gbm.h>
|
||||
#include <drm_fourcc.h>
|
||||
#endif
|
||||
|
||||
#if GLAMOR_GLES2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#define MESA_EGL_NO_X11_HEADERS
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "glamor.h"
|
||||
#include "compat-api.h"
|
||||
#include "glamor_gl_dispatch.h"
|
||||
#ifdef GLX_USE_SHARED_DISPATCH
|
||||
#include "glapi.h"
|
||||
#endif
|
||||
|
||||
static const char glamor_name[] = "glamor";
|
||||
|
||||
static DevPrivateKeyRec glamor_egl_pixmap_private_key_index;
|
||||
DevPrivateKey glamor_egl_pixmap_private_key = &glamor_egl_pixmap_private_key_index;
|
||||
|
||||
static void
|
||||
glamor_identify(int flags)
|
||||
{
|
||||
xf86Msg(X_INFO, "%s: OpenGL accelerated X.org driver based.\n",
|
||||
glamor_name);
|
||||
}
|
||||
|
||||
struct glamor_egl_screen_private {
|
||||
EGLDisplay display;
|
||||
EGLContext context;
|
||||
EGLint major, minor;
|
||||
|
||||
CreateScreenResourcesProcPtr CreateScreenResources;
|
||||
CloseScreenProcPtr CloseScreen;
|
||||
int fd;
|
||||
EGLImageKHR front_image;
|
||||
PixmapPtr *back_pixmap;
|
||||
int cpp;
|
||||
#ifdef GLAMOR_HAS_GBM
|
||||
struct gbm_device *gbm;
|
||||
#endif
|
||||
int has_gem;
|
||||
void *glamor_context;
|
||||
void *current_context;
|
||||
int gl_context_depth;
|
||||
int dri3_capable;
|
||||
|
||||
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
|
||||
PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr;
|
||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture2d_oes;
|
||||
struct glamor_gl_dispatch *dispatch;
|
||||
CloseScreenProcPtr saved_close_screen;
|
||||
xf86FreeScreenProc *saved_free_screen;
|
||||
};
|
||||
|
||||
int xf86GlamorEGLPrivateIndex = -1;
|
||||
|
||||
static struct glamor_egl_screen_private *
|
||||
glamor_egl_get_screen_private(ScrnInfoPtr scrn)
|
||||
{
|
||||
return (struct glamor_egl_screen_private *)
|
||||
scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
|
||||
}
|
||||
#ifdef GLX_USE_SHARED_DISPATCH
|
||||
_X_EXPORT void
|
||||
glamor_egl_make_current(ScreenPtr screen)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
|
||||
if (glamor_egl->gl_context_depth++)
|
||||
return;
|
||||
|
||||
GET_CURRENT_CONTEXT(glamor_egl->current_context);
|
||||
|
||||
if (glamor_egl->glamor_context != glamor_egl->current_context) {
|
||||
eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE,
|
||||
EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
if (!eglMakeCurrent(glamor_egl->display,
|
||||
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
glamor_egl->context)) {
|
||||
FatalError("Failed to make EGL context current\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_egl_restore_context(ScreenPtr screen)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
|
||||
if (--glamor_egl->gl_context_depth)
|
||||
return;
|
||||
|
||||
if (glamor_egl->current_context &&
|
||||
glamor_egl->glamor_context != glamor_egl->current_context)
|
||||
SET_CURRENT_CONTEXT(glamor_egl->current_context);
|
||||
}
|
||||
#else
|
||||
#define glamor_egl_make_current(x)
|
||||
#define glamor_egl_restore_context(s)
|
||||
#endif
|
||||
|
||||
static EGLImageKHR
|
||||
_glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl,
|
||||
int width, int height, int stride, int name, int depth)
|
||||
{
|
||||
EGLImageKHR image;
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_DRM_BUFFER_STRIDE_MESA, 0,
|
||||
EGL_DRM_BUFFER_FORMAT_MESA,
|
||||
EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
|
||||
EGL_DRM_BUFFER_USE_MESA,
|
||||
EGL_DRM_BUFFER_USE_SHARE_MESA |
|
||||
EGL_DRM_BUFFER_USE_SCANOUT_MESA,
|
||||
EGL_NONE
|
||||
};
|
||||
attribs[1] = width;
|
||||
attribs[3] = height;
|
||||
attribs[5] = stride;
|
||||
if (depth != 32 && depth != 24)
|
||||
return EGL_NO_IMAGE_KHR;
|
||||
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
||||
glamor_egl->context,
|
||||
EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)name, attribs);
|
||||
if (image == EGL_NO_IMAGE_KHR)
|
||||
return EGL_NO_IMAGE_KHR;
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
static int
|
||||
glamor_get_flink_name(int fd, int handle, int *name)
|
||||
{
|
||||
struct drm_gem_flink flink;
|
||||
flink.handle = handle;
|
||||
if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0)
|
||||
return FALSE;
|
||||
*name = flink.name;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Bool
|
||||
glamor_create_texture_from_image(struct glamor_egl_screen_private
|
||||
*glamor_egl,
|
||||
EGLImageKHR image, GLuint * texture)
|
||||
{
|
||||
glamor_egl->dispatch->glGenTextures(1, texture);
|
||||
glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
glamor_egl->dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
|
||||
(glamor_egl->egl_image_target_texture2d_oes) (GL_TEXTURE_2D,
|
||||
image);
|
||||
glamor_egl->dispatch->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
glamor_egl_create_argb8888_based_texture(ScreenPtr screen,
|
||||
int w,
|
||||
int h)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
EGLImageKHR image;
|
||||
GLuint texture;
|
||||
#ifdef GLAMOR_HAS_DRI3_SUPPORT
|
||||
struct gbm_bo *bo;
|
||||
EGLNativePixmapType native_pixmap;
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
bo = gbm_bo_create (glamor_egl->gbm, w, h, GBM_FORMAT_ARGB8888,
|
||||
GBM_BO_USE_RENDERING |
|
||||
GBM_BO_USE_SCANOUT);
|
||||
if (!bo)
|
||||
return 0;
|
||||
|
||||
/* If the following assignment raises an error or a warning
|
||||
* then that means EGLNativePixmapType is not struct gbm_bo *
|
||||
* on your platform: This code won't work and you should not
|
||||
* compile with dri3 support enabled */
|
||||
native_pixmap = bo;
|
||||
|
||||
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
||||
EGL_NO_CONTEXT,
|
||||
EGL_NATIVE_PIXMAP_KHR,
|
||||
native_pixmap, NULL);
|
||||
gbm_bo_destroy(bo);
|
||||
if (image == EGL_NO_IMAGE_KHR)
|
||||
return 0;
|
||||
glamor_create_texture_from_image(glamor_egl, image, &texture);
|
||||
glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);
|
||||
|
||||
return texture;
|
||||
#else
|
||||
return 0; /* this path should never happen */
|
||||
#endif
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
PixmapPtr screen_pixmap;
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
screen_pixmap = screen->GetScreenPixmap(screen);
|
||||
|
||||
if (!glamor_egl_create_textured_pixmap(screen_pixmap, handle, stride)) {
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed to create textured screen.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
glamor_egl->front_image = dixLookupPrivate(&screen_pixmap->devPrivates,
|
||||
glamor_egl_pixmap_private_key);
|
||||
glamor_set_screen_pixmap(screen_pixmap, glamor_egl->back_pixmap);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_create_textured_screen_ext(ScreenPtr screen,
|
||||
int handle,
|
||||
int stride,
|
||||
PixmapPtr *back_pixmap)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
|
||||
glamor_egl->back_pixmap = back_pixmap;
|
||||
if (!glamor_egl_create_textured_screen(screen, handle, stride))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Bool
|
||||
glamor_egl_check_has_gem(int fd)
|
||||
{
|
||||
struct drm_gem_flink flink;
|
||||
flink.handle = 0;
|
||||
|
||||
ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
|
||||
if (errno == ENOENT || errno == EINVAL)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
EGLImageKHR image;
|
||||
GLuint texture;
|
||||
int name;
|
||||
Bool ret = FALSE;
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
|
||||
glamor_egl_make_current(screen);
|
||||
if (glamor_egl->has_gem) {
|
||||
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
||||
"Couldn't flink pixmap handle\n");
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
||||
assert(0);
|
||||
return FALSE;
|
||||
}
|
||||
} else
|
||||
name = handle;
|
||||
|
||||
image = _glamor_egl_create_image(glamor_egl,
|
||||
pixmap->drawable.width,
|
||||
pixmap->drawable.height,
|
||||
((stride * 8 + 7) / pixmap->drawable.bitsPerPixel),
|
||||
name,
|
||||
pixmap->drawable.depth);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
||||
goto done;
|
||||
}
|
||||
glamor_create_texture_from_image(glamor_egl, image, &texture);
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
||||
glamor_set_pixmap_texture(pixmap, texture);
|
||||
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
|
||||
image);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
glamor_egl_restore_context(screen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
EGLImageKHR image;
|
||||
GLuint texture;
|
||||
Bool ret = FALSE;
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
|
||||
glamor_egl_make_current(screen);
|
||||
|
||||
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
||||
glamor_egl->context,
|
||||
EGL_NATIVE_PIXMAP_KHR,
|
||||
bo, NULL);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
|
||||
goto done;
|
||||
}
|
||||
glamor_create_texture_from_image(glamor_egl, image, &texture);
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
||||
glamor_set_pixmap_texture(pixmap, texture);
|
||||
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
|
||||
image);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
glamor_egl_restore_context(screen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef GLAMOR_HAS_DRI3_SUPPORT
|
||||
int glamor_get_fd_from_bo (int gbm_fd, struct gbm_bo *bo, int *fd);
|
||||
void glamor_get_name_from_bo (int gbm_fd, struct gbm_bo *bo, int *name);
|
||||
int
|
||||
glamor_get_fd_from_bo (int gbm_fd, struct gbm_bo *bo, int *fd)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
struct drm_prime_handle args;
|
||||
|
||||
handle = gbm_bo_get_handle(bo);
|
||||
args.handle = handle.u32;
|
||||
args.flags = DRM_CLOEXEC;
|
||||
if (ioctl (gbm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))
|
||||
return FALSE;
|
||||
*fd = args.fd;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_get_name_from_bo (int gbm_fd, struct gbm_bo *bo, int *name)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
|
||||
handle = gbm_bo_get_handle(bo);
|
||||
if (!glamor_get_flink_name(gbm_fd, handle.u32, name))
|
||||
*name = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int glamor_egl_dri3_fd_name_from_tex (ScreenPtr screen,
|
||||
PixmapPtr pixmap,
|
||||
unsigned int tex,
|
||||
Bool want_name,
|
||||
CARD16 *stride,
|
||||
CARD32 *size)
|
||||
{
|
||||
#ifdef GLAMOR_HAS_DRI3_SUPPORT
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
EGLImageKHR image;
|
||||
struct gbm_bo* bo;
|
||||
int fd = -1;
|
||||
|
||||
EGLint attribs[] = {
|
||||
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
|
||||
EGL_GL_TEXTURE_LEVEL_KHR, 0,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
|
||||
glamor_egl_make_current(screen);
|
||||
|
||||
image = dixLookupPrivate(&pixmap->devPrivates,
|
||||
glamor_egl_pixmap_private_key);
|
||||
|
||||
if (image == EGL_NO_IMAGE_KHR || image == NULL)
|
||||
{
|
||||
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
||||
glamor_egl->context,
|
||||
EGL_GL_TEXTURE_2D_KHR,
|
||||
(EGLClientBuffer)(uintptr_t)tex, attribs);
|
||||
if (image == EGL_NO_IMAGE_KHR)
|
||||
goto failure;
|
||||
|
||||
dixSetPrivate(&pixmap->devPrivates,
|
||||
glamor_egl_pixmap_private_key,
|
||||
image);
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
|
||||
}
|
||||
|
||||
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
|
||||
if (!bo)
|
||||
goto failure;
|
||||
|
||||
pixmap->devKind = gbm_bo_get_stride(bo);
|
||||
|
||||
if (want_name)
|
||||
{
|
||||
if (glamor_egl->has_gem)
|
||||
glamor_get_name_from_bo(glamor_egl->fd, bo, &fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (glamor_get_fd_from_bo(glamor_egl->fd, bo, &fd))
|
||||
{
|
||||
*stride = pixmap->devKind;
|
||||
*size = pixmap->devKind * gbm_bo_get_height(bo);
|
||||
}
|
||||
}
|
||||
|
||||
gbm_bo_destroy(bo);
|
||||
failure:
|
||||
glamor_egl_restore_context(screen);
|
||||
return fd;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
PixmapPtr glamor_egl_dri3_pixmap_from_fd (ScreenPtr screen,
|
||||
int fd,
|
||||
CARD16 width,
|
||||
CARD16 height,
|
||||
CARD16 stride,
|
||||
CARD8 depth,
|
||||
CARD8 bpp)
|
||||
{
|
||||
#ifdef GLAMOR_HAS_DRI3_SUPPORT
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
struct gbm_bo* bo;
|
||||
EGLImageKHR image;
|
||||
PixmapPtr pixmap;
|
||||
Bool ret = FALSE;
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
|
||||
EGL_DMA_BUF_PLANE0_FD_EXT, 0,
|
||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
|
||||
EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
|
||||
if (!glamor_egl->dri3_capable)
|
||||
return NULL;
|
||||
|
||||
if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)
|
||||
return NULL;
|
||||
|
||||
attribs[1] = width;
|
||||
attribs[3] = height;
|
||||
attribs[7] = fd;
|
||||
attribs[11] = stride;
|
||||
image = glamor_egl->egl_create_image_khr(glamor_egl->display,
|
||||
EGL_NO_CONTEXT,
|
||||
EGL_LINUX_DMA_BUF_EXT,
|
||||
NULL, attribs);
|
||||
|
||||
if (image == EGL_NO_IMAGE_KHR)
|
||||
return NULL;
|
||||
|
||||
/* EGL_EXT_image_dma_buf_import can impose restrictions on the
|
||||
* usage of the image. Use gbm_bo to bypass the limitations. */
|
||||
|
||||
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
|
||||
glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);
|
||||
|
||||
if (!bo)
|
||||
return NULL;
|
||||
|
||||
pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
|
||||
screen->ModifyPixmapHeader (pixmap, width, height, 0, 0, stride, NULL);
|
||||
|
||||
ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);
|
||||
gbm_bo_destroy(bo);
|
||||
|
||||
if (ret)
|
||||
return pixmap;
|
||||
else
|
||||
{
|
||||
screen->DestroyPixmap(pixmap);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
_glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
|
||||
EGLImageKHR image;
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
|
||||
image = dixLookupPrivate(&pixmap->devPrivates,
|
||||
glamor_egl_pixmap_private_key);
|
||||
if (image != EGL_NO_IMAGE_KHR && image != NULL) {
|
||||
/* Before destroy an image which was attached to
|
||||
* a texture. we must call glFlush to make sure the
|
||||
* operation on that texture has been done.*/
|
||||
glamor_block_handler(pixmap->drawable.pScreen);
|
||||
glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);
|
||||
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(front->drawable.pScreen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
EGLImageKHR old_front_image;
|
||||
EGLImageKHR new_front_image;
|
||||
|
||||
glamor_pixmap_exchange_fbos(front, back);
|
||||
new_front_image = dixLookupPrivate(&back->devPrivates, glamor_egl_pixmap_private_key);
|
||||
old_front_image = dixLookupPrivate(&front->devPrivates, glamor_egl_pixmap_private_key);
|
||||
dixSetPrivate(&front->devPrivates, glamor_egl_pixmap_private_key, new_front_image);
|
||||
dixSetPrivate(&back->devPrivates, glamor_egl_pixmap_private_key, old_front_image);
|
||||
glamor_set_pixmap_type(front, GLAMOR_TEXTURE_DRM);
|
||||
glamor_set_pixmap_type(back, GLAMOR_TEXTURE_DRM);
|
||||
glamor_egl->front_image = new_front_image;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
|
||||
{
|
||||
if (pixmap->refcnt == 1)
|
||||
_glamor_egl_destroy_pixmap_image(pixmap);
|
||||
glamor_destroy_textured_pixmap(pixmap);
|
||||
}
|
||||
|
||||
static Bool
|
||||
glamor_egl_close_screen(CLOSE_SCREEN_ARGS_DECL)
|
||||
{
|
||||
ScrnInfoPtr scrn;
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
PixmapPtr screen_pixmap;
|
||||
EGLImageKHR back_image;
|
||||
|
||||
scrn = xf86ScreenToScrn(screen);
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
screen_pixmap = screen->GetScreenPixmap(screen);
|
||||
|
||||
glamor_egl->egl_destroy_image_khr(glamor_egl->display, glamor_egl->front_image);
|
||||
dixSetPrivate(&screen_pixmap->devPrivates, glamor_egl_pixmap_private_key, NULL);
|
||||
glamor_egl->front_image = NULL;
|
||||
if (glamor_egl->back_pixmap && *glamor_egl->back_pixmap) {
|
||||
back_image = dixLookupPrivate(&(*glamor_egl->back_pixmap)->devPrivates,
|
||||
glamor_egl_pixmap_private_key);
|
||||
if (back_image != NULL && back_image != EGL_NO_IMAGE_KHR) {
|
||||
glamor_egl->egl_destroy_image_khr(glamor_egl->display, back_image);
|
||||
dixSetPrivate(&(*glamor_egl->back_pixmap)->devPrivates,
|
||||
glamor_egl_pixmap_private_key, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
screen->CloseScreen = glamor_egl->saved_close_screen;
|
||||
|
||||
return screen->CloseScreen(CLOSE_SCREEN_ARGS);
|
||||
}
|
||||
|
||||
static Bool
|
||||
glamor_egl_has_extension(struct glamor_egl_screen_private *glamor_egl,
|
||||
const char *extension)
|
||||
{
|
||||
const char *pext;
|
||||
int ext_len;
|
||||
|
||||
ext_len = strlen(extension);
|
||||
pext =
|
||||
(const char *) eglQueryString(glamor_egl->display,
|
||||
EGL_EXTENSIONS);
|
||||
if (pext == NULL || extension == NULL)
|
||||
return FALSE;
|
||||
while ((pext = strstr(pext, extension)) != NULL) {
|
||||
if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
|
||||
return TRUE;
|
||||
pext += ext_len;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_egl_screen_init(ScreenPtr screen)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
|
||||
glamor_egl->saved_close_screen = screen->CloseScreen;
|
||||
screen->CloseScreen = glamor_egl_close_screen;
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_egl_free_screen(FREE_SCREEN_ARGS_DECL)
|
||||
{
|
||||
ScrnInfoPtr scrn;
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
#ifndef XF86_SCRN_INTERFACE
|
||||
scrn = xf86Screens[arg];
|
||||
#else
|
||||
scrn = arg;
|
||||
#endif
|
||||
|
||||
glamor_egl = glamor_egl_get_screen_private(scrn);
|
||||
if (glamor_egl != NULL) {
|
||||
|
||||
eglMakeCurrent(glamor_egl->display,
|
||||
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
EGL_NO_CONTEXT);
|
||||
#ifdef GLAMOR_HAS_GBM
|
||||
if (glamor_egl->gbm)
|
||||
gbm_device_destroy(glamor_egl->gbm);
|
||||
#endif
|
||||
scrn->FreeScreen = glamor_egl->saved_free_screen;
|
||||
free(glamor_egl);
|
||||
scrn->FreeScreen(FREE_SCREEN_ARGS);
|
||||
}
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_init(ScrnInfoPtr scrn, int fd)
|
||||
{
|
||||
struct glamor_egl_screen_private *glamor_egl;
|
||||
const char *version;
|
||||
EGLint config_attribs[] = {
|
||||
#ifdef GLAMOR_GLES2
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
#endif
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
glamor_identify(0);
|
||||
glamor_egl = calloc(sizeof(*glamor_egl), 1);
|
||||
if (glamor_egl == NULL)
|
||||
return FALSE;
|
||||
if (xf86GlamorEGLPrivateIndex == -1)
|
||||
xf86GlamorEGLPrivateIndex =
|
||||
xf86AllocateScrnInfoPrivateIndex();
|
||||
|
||||
scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
|
||||
glamor_egl->fd = fd;
|
||||
#ifdef GLAMOR_HAS_GBM
|
||||
glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
|
||||
if (glamor_egl->gbm == NULL) {
|
||||
ErrorF("couldn't get display device\n");
|
||||
return FALSE;
|
||||
}
|
||||
glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
|
||||
#else
|
||||
glamor_egl->display = eglGetDisplay((EGLNativeDisplayType)(intptr_t)fd);
|
||||
#endif
|
||||
|
||||
glamor_egl->has_gem = glamor_egl_check_has_gem(fd);
|
||||
|
||||
#ifndef GLAMOR_GLES2
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
#else
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
#endif
|
||||
if (!eglInitialize
|
||||
(glamor_egl->display, &glamor_egl->major, &glamor_egl->minor))
|
||||
{
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
||||
"eglInitialize() failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
version = eglQueryString(glamor_egl->display, EGL_VERSION);
|
||||
xf86Msg(X_INFO, "%s: EGL version %s:\n", glamor_name, version);
|
||||
|
||||
#define GLAMOR_CHECK_EGL_EXTENSION(EXT) \
|
||||
if (!glamor_egl_has_extension(glamor_egl, "EGL_" #EXT)) { \
|
||||
ErrorF("EGL_" #EXT " required.\n"); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
#define GLAMOR_CHECK_EGL_EXTENSIONS(EXT1, EXT2) \
|
||||
if (!glamor_egl_has_extension(glamor_egl, "EGL_" #EXT1) && \
|
||||
!glamor_egl_has_extension(glamor_egl, "EGL_" #EXT2)) { \
|
||||
ErrorF("EGL_" #EXT1 " or EGL_" #EXT2 " required.\n"); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
|
||||
GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_renderbuffer_image);
|
||||
#ifdef GLAMOR_GLES2
|
||||
GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_gles2);
|
||||
#else
|
||||
GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_opengl);
|
||||
#endif
|
||||
|
||||
#ifdef GLAMOR_HAS_DRI3_SUPPORT
|
||||
if (glamor_egl_has_extension(glamor_egl, "EGL_KHR_gl_texture_2D_image") &&
|
||||
glamor_egl_has_extension(glamor_egl, "EGL_EXT_image_dma_buf_import") )
|
||||
glamor_egl->dri3_capable = TRUE;
|
||||
#endif
|
||||
glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)
|
||||
eglGetProcAddress("eglCreateImageKHR");
|
||||
|
||||
glamor_egl->egl_destroy_image_khr = (PFNEGLDESTROYIMAGEKHRPROC)
|
||||
eglGetProcAddress("eglDestroyImageKHR");
|
||||
|
||||
glamor_egl->egl_image_target_texture2d_oes =
|
||||
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
|
||||
eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
||||
|
||||
if (!glamor_egl->egl_create_image_khr
|
||||
|| !glamor_egl->egl_image_target_texture2d_oes) {
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
||||
"eglGetProcAddress() failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
glamor_egl->context = eglCreateContext(glamor_egl->display,
|
||||
NULL, EGL_NO_CONTEXT,
|
||||
config_attribs);
|
||||
if (glamor_egl->context == EGL_NO_CONTEXT) {
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
||||
"Failed to create EGL context\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!eglMakeCurrent(glamor_egl->display,
|
||||
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
glamor_egl->context)) {
|
||||
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
||||
"Failed to make EGL context current\n");
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef GLX_USE_SHARED_DISPATCH
|
||||
GET_CURRENT_CONTEXT(glamor_egl->glamor_context);
|
||||
#endif
|
||||
glamor_egl->saved_free_screen = scrn->FreeScreen;
|
||||
scrn->FreeScreen = glamor_egl_free_screen;
|
||||
#ifdef GLAMOR_GLES2
|
||||
xf86DrvMsg(scrn->scrnIndex, X_INFO, "Using GLES2.\n");
|
||||
#ifdef GLX_USE_SHARED_DISPATCH
|
||||
xf86DrvMsg(scrn->scrnIndex, X_WARNING, "Glamor is using GLES2 but GLX needs GL. "
|
||||
"Indirect GLX may not work correctly.\n");
|
||||
#endif
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_egl_init_textured_pixmap(ScreenPtr screen)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
if (!dixRegisterPrivateKey
|
||||
(glamor_egl_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
|
||||
LogMessage(X_WARNING,
|
||||
"glamor%d: Failed to allocate egl pixmap private\n",
|
||||
screen->myNum);
|
||||
return FALSE;
|
||||
}
|
||||
if (glamor_egl->dri3_capable)
|
||||
glamor_enable_dri3(screen);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_gl_dispatch_init(ScreenPtr screen,
|
||||
struct glamor_gl_dispatch *dispatch,
|
||||
int gl_version)
|
||||
{
|
||||
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
|
||||
struct glamor_egl_screen_private *glamor_egl =
|
||||
glamor_egl_get_screen_private(scrn);
|
||||
if (!glamor_gl_dispatch_init_impl
|
||||
(dispatch, gl_version, (get_proc_address_t)eglGetProcAddress))
|
||||
return FALSE;
|
||||
glamor_egl->dispatch = dispatch;
|
||||
return TRUE;
|
||||
}
|
52
glamor/glamor_eglmodule.c
Normal file
52
glamor/glamor_eglmodule.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 1998 The XFree86 Project, 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
|
||||
* XFREE86 PROJECT 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.
|
||||
*
|
||||
* Except as contained in this notice, the name of the XFree86 Project shall
|
||||
* not be used in advertising or otherwise to promote the sale, use or other
|
||||
* dealings in this Software without prior written authorization from the
|
||||
* XFree86 Project.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <xorg-server.h>
|
||||
#define GLAMOR_FOR_XORG
|
||||
#include <xf86Module.h>
|
||||
#include "glamor.h"
|
||||
|
||||
static XF86ModuleVersionInfo VersRec = {
|
||||
GLAMOR_EGL_MODULE_NAME,
|
||||
MODULEVENDORSTRING,
|
||||
MODINFOSTRING1,
|
||||
MODINFOSTRING2,
|
||||
XORG_VERSION_CURRENT,
|
||||
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
|
||||
ABI_CLASS_ANSIC, /* Only need the ansic layer */
|
||||
ABI_ANSIC_VERSION,
|
||||
MOD_CLASS_NONE,
|
||||
{0, 0, 0, 0} /* signature, to be patched into the file by a tool */
|
||||
};
|
||||
|
||||
_X_EXPORT XF86ModuleData glamoreglModuleData = { &VersRec, NULL, NULL };
|
590
glamor/glamor_fbo.c
Normal file
590
glamor/glamor_fbo.c
Normal file
|
@ -0,0 +1,590 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
#define GLAMOR_CACHE_EXPIRE_MAX 100
|
||||
|
||||
#define GLAMOR_CACHE_DEFAULT 0
|
||||
#define GLAMOR_CACHE_EXACT_SIZE 1
|
||||
|
||||
//#define NO_FBO_CACHE 1
|
||||
#define FBO_CACHE_THRESHOLD (256*1024*1024)
|
||||
|
||||
/* Loop from the tail to the head. */
|
||||
#define xorg_list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = __container_of((head)->prev, pos, member); \
|
||||
&pos->member != (head); \
|
||||
pos = __container_of(pos->member.prev, pos, member))
|
||||
|
||||
|
||||
#define xorg_list_for_each_entry_safe_reverse(pos, tmp, head, member) \
|
||||
for (pos = __container_of((head)->prev, pos, member), \
|
||||
tmp = __container_of(pos->member.prev, pos, member); \
|
||||
&pos->member != (head); \
|
||||
pos = tmp, tmp = __container_of(pos->member.prev, tmp, member))
|
||||
|
||||
inline static int cache_wbucket(int size)
|
||||
{
|
||||
int order = __fls(size / 32);
|
||||
if (order >= CACHE_BUCKET_WCOUNT)
|
||||
order = CACHE_BUCKET_WCOUNT - 1;
|
||||
return order;
|
||||
}
|
||||
|
||||
inline static int cache_hbucket(int size)
|
||||
{
|
||||
int order = __fls(size / 32);
|
||||
if (order >= CACHE_BUCKET_HCOUNT)
|
||||
order = CACHE_BUCKET_HCOUNT - 1;
|
||||
return order;
|
||||
}
|
||||
|
||||
static glamor_pixmap_fbo *
|
||||
glamor_pixmap_fbo_cache_get(glamor_screen_private *glamor_priv,
|
||||
int w, int h, GLenum format, int flag)
|
||||
{
|
||||
struct xorg_list *cache;
|
||||
glamor_pixmap_fbo *fbo_entry, *ret_fbo = NULL;
|
||||
int n_format;
|
||||
#ifdef NO_FBO_CACHE
|
||||
return NULL;
|
||||
#else
|
||||
n_format = cache_format(format);
|
||||
if (n_format == -1)
|
||||
return NULL;
|
||||
cache = &glamor_priv->fbo_cache[n_format]
|
||||
[cache_wbucket(w)]
|
||||
[cache_hbucket(h)];
|
||||
if (!(flag & GLAMOR_CACHE_EXACT_SIZE)) {
|
||||
xorg_list_for_each_entry(fbo_entry, cache, list) {
|
||||
if (fbo_entry->width >= w && fbo_entry->height >= h) {
|
||||
|
||||
DEBUGF("Request w %d h %d format %x \n", w, h, format);
|
||||
DEBUGF("got cache entry %p w %d h %d fbo %d tex %d format %x\n",
|
||||
fbo_entry, fbo_entry->width, fbo_entry->height,
|
||||
fbo_entry->fb, fbo_entry->tex);
|
||||
xorg_list_del(&fbo_entry->list);
|
||||
ret_fbo = fbo_entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
xorg_list_for_each_entry(fbo_entry, cache, list) {
|
||||
if (fbo_entry->width == w && fbo_entry->height == h) {
|
||||
|
||||
DEBUGF("Request w %d h %d format %x \n", w, h, format);
|
||||
DEBUGF("got cache entry %p w %d h %d fbo %d tex %d format %x\n",
|
||||
fbo_entry, fbo_entry->width, fbo_entry->height,
|
||||
fbo_entry->fb, fbo_entry->tex, fbo_entry->format);
|
||||
assert(format == fbo_entry->format);
|
||||
xorg_list_del(&fbo_entry->list);
|
||||
ret_fbo = fbo_entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret_fbo)
|
||||
glamor_priv->fbo_cache_watermark -= ret_fbo->width * ret_fbo->height;
|
||||
|
||||
assert(glamor_priv->fbo_cache_watermark >= 0);
|
||||
|
||||
return ret_fbo;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
glamor_purge_fbo(glamor_pixmap_fbo *fbo)
|
||||
{
|
||||
glamor_gl_dispatch *dispatch = glamor_get_dispatch(fbo->glamor_priv);
|
||||
if (fbo->fb)
|
||||
dispatch->glDeleteFramebuffers(1, &fbo->fb);
|
||||
if (fbo->tex)
|
||||
dispatch->glDeleteTextures(1, &fbo->tex);
|
||||
if (fbo->pbo)
|
||||
dispatch->glDeleteBuffers(1, &fbo->pbo);
|
||||
glamor_put_dispatch(fbo->glamor_priv);
|
||||
|
||||
free(fbo);
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_pixmap_fbo_cache_put(glamor_pixmap_fbo *fbo)
|
||||
{
|
||||
struct xorg_list *cache;
|
||||
int n_format;
|
||||
|
||||
#ifdef NO_FBO_CACHE
|
||||
glamor_purge_fbo(fbo);
|
||||
return;
|
||||
#else
|
||||
n_format = cache_format(fbo->format);
|
||||
|
||||
if (fbo->fb == 0 || n_format == -1
|
||||
|| fbo->glamor_priv->fbo_cache_watermark >= FBO_CACHE_THRESHOLD) {
|
||||
fbo->glamor_priv->tick += GLAMOR_CACHE_EXPIRE_MAX;
|
||||
glamor_fbo_expire(fbo->glamor_priv);
|
||||
glamor_purge_fbo(fbo);
|
||||
return;
|
||||
}
|
||||
|
||||
cache = &fbo->glamor_priv->fbo_cache[n_format]
|
||||
[cache_wbucket(fbo->width)]
|
||||
[cache_hbucket(fbo->height)];
|
||||
DEBUGF("Put cache entry %p to cache %p w %d h %d format %x fbo %d tex %d \n", fbo, cache,
|
||||
fbo->width, fbo->height, fbo->format, fbo->fb, fbo->tex);
|
||||
|
||||
fbo->glamor_priv->fbo_cache_watermark += fbo->width * fbo->height;
|
||||
xorg_list_add(&fbo->list, cache);
|
||||
fbo->expire = fbo->glamor_priv->tick + GLAMOR_CACHE_EXPIRE_MAX;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_pixmap_ensure_fb(glamor_pixmap_fbo *fbo)
|
||||
{
|
||||
glamor_gl_dispatch *dispatch;
|
||||
int status;
|
||||
|
||||
dispatch = glamor_get_dispatch(fbo->glamor_priv);
|
||||
|
||||
if (fbo->fb == 0)
|
||||
dispatch->glGenFramebuffers(1, &fbo->fb);
|
||||
assert(fbo->tex != 0);
|
||||
dispatch->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb);
|
||||
dispatch->glFramebufferTexture2D(GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, fbo->tex,
|
||||
0);
|
||||
status = dispatch->glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
const char *str;
|
||||
switch (status) {
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
str = "incomplete attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
str = "incomplete/missing attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
str = "incomplete draw buffer";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
str = "incomplete read buffer";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
str = "unsupported";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
str = "incomplete multiple";
|
||||
break;
|
||||
default:
|
||||
str = "unknown error";
|
||||
break;
|
||||
}
|
||||
|
||||
FatalError("destination is framebuffer incomplete: %s [%x]\n",
|
||||
str, status);
|
||||
}
|
||||
glamor_put_dispatch(fbo->glamor_priv);
|
||||
}
|
||||
|
||||
glamor_pixmap_fbo *
|
||||
glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
|
||||
int w, int h, GLenum format, GLint tex, int flag)
|
||||
{
|
||||
glamor_pixmap_fbo *fbo;
|
||||
|
||||
fbo = calloc(1, sizeof(*fbo));
|
||||
if (fbo == NULL)
|
||||
return NULL;
|
||||
|
||||
xorg_list_init(&fbo->list);
|
||||
|
||||
fbo->tex = tex;
|
||||
fbo->width = w;
|
||||
fbo->height = h;
|
||||
fbo->format = format;
|
||||
fbo->glamor_priv = glamor_priv;
|
||||
|
||||
if (flag == GLAMOR_CREATE_PIXMAP_MAP) {
|
||||
glamor_gl_dispatch *dispatch;
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glGenBuffers(1, &fbo->pbo);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (flag != GLAMOR_CREATE_FBO_NO_FBO)
|
||||
glamor_pixmap_ensure_fb(fbo);
|
||||
|
||||
done:
|
||||
return fbo;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glamor_fbo_expire(glamor_screen_private *glamor_priv)
|
||||
{
|
||||
struct xorg_list *cache;
|
||||
glamor_pixmap_fbo *fbo_entry, *tmp;
|
||||
int i,j,k;
|
||||
|
||||
for(i = 0; i < CACHE_FORMAT_COUNT; i++)
|
||||
for(j = 0; j < CACHE_BUCKET_WCOUNT; j++)
|
||||
for(k = 0; k < CACHE_BUCKET_HCOUNT; k++) {
|
||||
cache = &glamor_priv->fbo_cache[i][j][k];
|
||||
xorg_list_for_each_entry_safe_reverse(fbo_entry, tmp, cache, list) {
|
||||
if (GLAMOR_TICK_AFTER(fbo_entry->expire, glamor_priv->tick)) {
|
||||
break;
|
||||
}
|
||||
|
||||
glamor_priv->fbo_cache_watermark -= fbo_entry->width * fbo_entry->height;
|
||||
xorg_list_del(&fbo_entry->list);
|
||||
DEBUGF("cache %p fbo %p expired %d current %d \n", cache, fbo_entry,
|
||||
fbo_entry->expire, glamor_priv->tick);
|
||||
glamor_purge_fbo(fbo_entry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
glamor_init_pixmap_fbo(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
int i,j,k;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
for(i = 0; i < CACHE_FORMAT_COUNT; i++)
|
||||
for(j = 0; j < CACHE_BUCKET_WCOUNT; j++)
|
||||
for(k = 0; k < CACHE_BUCKET_HCOUNT; k++)
|
||||
{
|
||||
xorg_list_init(&glamor_priv->fbo_cache[i][j][k]);
|
||||
}
|
||||
glamor_priv->fbo_cache_watermark = 0;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_fini_pixmap_fbo(ScreenPtr screen)
|
||||
{
|
||||
struct xorg_list *cache;
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_pixmap_fbo *fbo_entry, *tmp;
|
||||
int i,j,k;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
for(i = 0; i < CACHE_FORMAT_COUNT; i++)
|
||||
for(j = 0; j < CACHE_BUCKET_WCOUNT; j++)
|
||||
for(k = 0; k < CACHE_BUCKET_HCOUNT; k++)
|
||||
{
|
||||
cache = &glamor_priv->fbo_cache[i][j][k];
|
||||
xorg_list_for_each_entry_safe_reverse(fbo_entry, tmp, cache, list) {
|
||||
xorg_list_del(&fbo_entry->list);
|
||||
glamor_purge_fbo(fbo_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glamor_destroy_fbo(glamor_pixmap_fbo *fbo)
|
||||
{
|
||||
xorg_list_del(&fbo->list);
|
||||
glamor_pixmap_fbo_cache_put(fbo);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
_glamor_create_tex(glamor_screen_private *glamor_priv,
|
||||
int w, int h, GLenum format)
|
||||
{
|
||||
glamor_gl_dispatch *dispatch;
|
||||
unsigned int tex = 0;
|
||||
|
||||
/* With dri3, we want to allocate ARGB8888 pixmaps only.
|
||||
* Depending on the implementation, GL_RGBA might not
|
||||
* give us ARGB8888. We ask glamor_egl to use get
|
||||
* an ARGB8888 based texture for us. */
|
||||
if (glamor_priv->dri3_enabled && format == GL_RGBA)
|
||||
{
|
||||
tex = glamor_egl_create_argb8888_based_texture(glamor_priv->screen,
|
||||
w, h);
|
||||
}
|
||||
if (!tex)
|
||||
{
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glGenTextures(1, &tex);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D, tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
|
||||
format, GL_UNSIGNED_BYTE, NULL);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
return tex;
|
||||
}
|
||||
|
||||
glamor_pixmap_fbo *
|
||||
glamor_create_fbo(glamor_screen_private *glamor_priv,
|
||||
int w, int h,
|
||||
GLenum format,
|
||||
int flag)
|
||||
{
|
||||
glamor_pixmap_fbo *fbo;
|
||||
GLint tex = 0;
|
||||
int cache_flag;
|
||||
|
||||
if (!glamor_check_fbo_size(glamor_priv, w, h))
|
||||
return NULL;
|
||||
|
||||
if (flag == GLAMOR_CREATE_FBO_NO_FBO)
|
||||
goto new_fbo;
|
||||
|
||||
if (flag == GLAMOR_CREATE_PIXMAP_MAP)
|
||||
goto no_tex;
|
||||
|
||||
if (flag == GLAMOR_CREATE_PIXMAP_FIXUP)
|
||||
cache_flag = GLAMOR_CACHE_EXACT_SIZE;
|
||||
else
|
||||
cache_flag = 0;
|
||||
|
||||
fbo = glamor_pixmap_fbo_cache_get(glamor_priv, w, h,
|
||||
format, cache_flag);
|
||||
if (fbo)
|
||||
return fbo;
|
||||
new_fbo:
|
||||
tex = _glamor_create_tex(glamor_priv, w, h, format);
|
||||
no_tex:
|
||||
fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, format, tex, flag);
|
||||
|
||||
return fbo;
|
||||
}
|
||||
|
||||
static glamor_pixmap_fbo *
|
||||
_glamor_create_fbo_array(glamor_screen_private *glamor_priv,
|
||||
int w, int h, GLenum format, int flag,
|
||||
int block_w, int block_h,
|
||||
glamor_pixmap_private *pixmap_priv,
|
||||
int has_fbo)
|
||||
{
|
||||
int block_wcnt;
|
||||
int block_hcnt;
|
||||
glamor_pixmap_fbo **fbo_array;
|
||||
BoxPtr box_array;
|
||||
int i,j;
|
||||
glamor_pixmap_private_large_t *priv;
|
||||
|
||||
priv = &pixmap_priv->large;
|
||||
|
||||
block_wcnt = (w + block_w - 1) / block_w;
|
||||
block_hcnt = (h + block_h - 1) / block_h;
|
||||
|
||||
box_array = calloc(block_wcnt * block_hcnt, sizeof(box_array[0]));
|
||||
if (box_array == NULL)
|
||||
return NULL;
|
||||
|
||||
fbo_array = calloc(block_wcnt * block_hcnt, sizeof(glamor_pixmap_fbo*));
|
||||
if (fbo_array == NULL) {
|
||||
free(box_array);
|
||||
return FALSE;
|
||||
}
|
||||
for(i = 0; i < block_hcnt; i++)
|
||||
{
|
||||
int block_y1, block_y2;
|
||||
int fbo_w, fbo_h;
|
||||
|
||||
block_y1 = i * block_h;
|
||||
block_y2 = (block_y1 + block_h) > h ? h : (block_y1 + block_h);
|
||||
fbo_h = block_y2 - block_y1;
|
||||
|
||||
for (j = 0; j < block_wcnt; j++)
|
||||
{
|
||||
box_array[i * block_wcnt + j].x1 = j * block_w;
|
||||
box_array[i * block_wcnt + j].y1 = block_y1;
|
||||
box_array[i * block_wcnt + j].x2 = (j + 1) * block_w > w ? w : (j + 1) * block_w;
|
||||
box_array[i * block_wcnt + j].y2 = block_y2;
|
||||
fbo_w = box_array[i * block_wcnt + j].x2 - box_array[i * block_wcnt + j].x1;
|
||||
if (!has_fbo)
|
||||
fbo_array[i * block_wcnt + j] = glamor_create_fbo(glamor_priv,
|
||||
fbo_w, fbo_h, format,
|
||||
GLAMOR_CREATE_PIXMAP_FIXUP);
|
||||
else
|
||||
fbo_array[i * block_wcnt + j] = priv->base.fbo;
|
||||
if (fbo_array[i * block_wcnt + j] == NULL)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
priv->box = box_array[0];
|
||||
priv->box_array = box_array;
|
||||
priv->fbo_array = fbo_array;
|
||||
priv->block_wcnt = block_wcnt;
|
||||
priv->block_hcnt = block_hcnt;
|
||||
return fbo_array[0];
|
||||
|
||||
cleanup:
|
||||
for(i = 0; i < block_wcnt * block_hcnt; i++)
|
||||
if ((fbo_array)[i])
|
||||
glamor_destroy_fbo((fbo_array)[i]);
|
||||
free(box_array);
|
||||
free(fbo_array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Create a fbo array to cover the w*h region, by using block_w*block_h
|
||||
* block.*/
|
||||
glamor_pixmap_fbo *
|
||||
glamor_create_fbo_array(glamor_screen_private *glamor_priv,
|
||||
int w, int h, GLenum format, int flag,
|
||||
int block_w, int block_h,
|
||||
glamor_pixmap_private *pixmap_priv)
|
||||
{
|
||||
pixmap_priv->large.block_w = block_w;
|
||||
pixmap_priv->large.block_h = block_h;
|
||||
return _glamor_create_fbo_array(glamor_priv, w, h, format, flag,
|
||||
block_w, block_h, pixmap_priv, 0);
|
||||
}
|
||||
|
||||
glamor_pixmap_fbo *
|
||||
glamor_pixmap_detach_fbo(glamor_pixmap_private *pixmap_priv)
|
||||
{
|
||||
glamor_pixmap_fbo *fbo;
|
||||
|
||||
if (pixmap_priv == NULL)
|
||||
return NULL;
|
||||
|
||||
fbo = pixmap_priv->base.fbo;
|
||||
if (fbo == NULL)
|
||||
return NULL;
|
||||
|
||||
pixmap_priv->base.fbo = NULL;
|
||||
return fbo;
|
||||
}
|
||||
|
||||
/* The pixmap must not be attached to another fbo. */
|
||||
void
|
||||
glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (pixmap_priv->base.fbo)
|
||||
return;
|
||||
|
||||
pixmap_priv->base.fbo = fbo;
|
||||
|
||||
switch (pixmap_priv->type) {
|
||||
case GLAMOR_TEXTURE_LARGE:
|
||||
case GLAMOR_TEXTURE_ONLY:
|
||||
case GLAMOR_TEXTURE_DRM:
|
||||
pixmap_priv->base.gl_fbo = 1;
|
||||
if (fbo->tex != 0)
|
||||
pixmap_priv->base.gl_tex = 1;
|
||||
else {
|
||||
/* XXX For the Xephyr only, may be broken now.*/
|
||||
pixmap_priv->base.gl_tex = 0;
|
||||
}
|
||||
case GLAMOR_MEMORY_MAP:
|
||||
pixmap->devPrivate.ptr = NULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glamor_pixmap_destroy_fbo(glamor_pixmap_private *priv)
|
||||
{
|
||||
glamor_pixmap_fbo *fbo;
|
||||
if (priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
int i;
|
||||
glamor_pixmap_private_large_t *large = &priv->large;
|
||||
for(i = 0; i < large->block_wcnt * large->block_hcnt; i++)
|
||||
glamor_destroy_fbo(large->fbo_array[i]);
|
||||
free(large->fbo_array);
|
||||
} else {
|
||||
fbo = glamor_pixmap_detach_fbo(priv);
|
||||
if (fbo)
|
||||
glamor_destroy_fbo(fbo);
|
||||
}
|
||||
|
||||
free(priv);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_pixmap_fbo *fbo;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
if (pixmap_priv->base.fbo == NULL) {
|
||||
|
||||
fbo = glamor_create_fbo(glamor_priv, pixmap->drawable.width,
|
||||
pixmap->drawable.height,
|
||||
format,
|
||||
flag);
|
||||
if (fbo == NULL)
|
||||
return FALSE;
|
||||
|
||||
glamor_pixmap_attach_fbo(pixmap, fbo);
|
||||
} else {
|
||||
/* We do have a fbo, but it may lack of fb or tex. */
|
||||
if (!pixmap_priv->base.fbo->tex)
|
||||
pixmap_priv->base.fbo->tex = _glamor_create_tex(glamor_priv, pixmap->drawable.width,
|
||||
pixmap->drawable.height, format);
|
||||
|
||||
if (flag != GLAMOR_CREATE_FBO_NO_FBO && pixmap_priv->base.fbo->fb == 0)
|
||||
glamor_pixmap_ensure_fb(pixmap_priv->base.fbo);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_X_EXPORT void
|
||||
glamor_pixmap_exchange_fbos(PixmapPtr front, PixmapPtr back)
|
||||
{
|
||||
glamor_pixmap_private *front_priv, *back_priv;
|
||||
glamor_pixmap_fbo *temp_fbo;
|
||||
|
||||
front_priv = glamor_get_pixmap_private(front);
|
||||
back_priv = glamor_get_pixmap_private(back);
|
||||
temp_fbo = front_priv->base.fbo;
|
||||
front_priv->base.fbo = back_priv->base.fbo;
|
||||
back_priv->base.fbo = temp_fbo;
|
||||
}
|
364
glamor/glamor_fill.c
Normal file
364
glamor/glamor_fill.c
Normal file
|
@ -0,0 +1,364 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_fillspans.c
|
||||
*
|
||||
* GC fill implementation, based loosely on fb_fill.c
|
||||
*/
|
||||
Bool
|
||||
glamor_fill(DrawablePtr drawable,
|
||||
GCPtr gc, int x, int y, int width, int height, Bool fallback)
|
||||
{
|
||||
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
int off_x, off_y;
|
||||
PixmapPtr sub_pixmap = NULL;
|
||||
glamor_access_t sub_pixmap_access;
|
||||
DrawablePtr saved_drawable = NULL;
|
||||
int saved_x = x, saved_y = y;
|
||||
|
||||
glamor_get_drawable_deltas(drawable, dst_pixmap, &off_x, &off_y);
|
||||
|
||||
switch (gc->fillStyle) {
|
||||
case FillSolid:
|
||||
if (!glamor_solid(dst_pixmap,
|
||||
x + off_x,
|
||||
y + off_y,
|
||||
width, height, gc->alu, gc->planemask,
|
||||
gc->fgPixel))
|
||||
goto fail;
|
||||
break;
|
||||
case FillStippled:
|
||||
case FillOpaqueStippled:
|
||||
if (!glamor_stipple(dst_pixmap,
|
||||
gc->stipple,
|
||||
x + off_x,
|
||||
y + off_y,
|
||||
width,
|
||||
height,
|
||||
gc->alu,
|
||||
gc->planemask,
|
||||
gc->fgPixel,
|
||||
gc->bgPixel, gc->patOrg.x,
|
||||
gc->patOrg.y))
|
||||
goto fail;
|
||||
break;
|
||||
case FillTiled:
|
||||
if (!glamor_tile(dst_pixmap,
|
||||
gc->tile.pixmap,
|
||||
x + off_x,
|
||||
y + off_y,
|
||||
width,
|
||||
height,
|
||||
gc->alu,
|
||||
gc->planemask,
|
||||
x - drawable->x - gc->patOrg.x,
|
||||
y - drawable->y - gc->patOrg.y))
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
fail:
|
||||
if (!fallback) {
|
||||
if (glamor_ddx_fallback_check_pixmap(&dst_pixmap->drawable)
|
||||
&& glamor_ddx_fallback_check_gc(gc))
|
||||
return FALSE;
|
||||
}
|
||||
/* Is it possible to set the access as WO? */
|
||||
|
||||
sub_pixmap_access = GLAMOR_ACCESS_RW;
|
||||
|
||||
sub_pixmap = glamor_get_sub_pixmap(dst_pixmap, x + off_x,
|
||||
y + off_y, width, height,
|
||||
sub_pixmap_access);
|
||||
|
||||
if (sub_pixmap != NULL) {
|
||||
if (gc->fillStyle != FillSolid) {
|
||||
gc->patOrg.x += (drawable->x - x);
|
||||
gc->patOrg.y += (drawable->y - y);
|
||||
}
|
||||
saved_drawable = drawable;
|
||||
drawable = &sub_pixmap->drawable;
|
||||
saved_x = x;
|
||||
saved_y = y;
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
if (glamor_prepare_access_gc(gc)) {
|
||||
fbFill(drawable, gc, x, y, width, height);
|
||||
glamor_finish_access_gc(gc);
|
||||
}
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
|
||||
if (sub_pixmap != NULL) {
|
||||
if (gc->fillStyle != FillSolid) {
|
||||
gc->patOrg.x -= (saved_drawable->x - saved_x);
|
||||
gc->patOrg.y -= (saved_drawable->y - saved_y);
|
||||
}
|
||||
|
||||
x = saved_x;
|
||||
y = saved_y;
|
||||
|
||||
glamor_put_sub_pixmap(sub_pixmap, dst_pixmap,
|
||||
x + off_x, y + off_y,
|
||||
width, height, sub_pixmap_access);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_init_solid_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
const char *solid_vs =
|
||||
"attribute vec4 v_position;"
|
||||
"void main()\n" "{\n" " gl_Position = v_position;\n"
|
||||
"}\n";
|
||||
const char *solid_fs =
|
||||
GLAMOR_DEFAULT_PRECISION "uniform vec4 color;\n"
|
||||
"void main()\n" "{\n" " gl_FragColor = color;\n" "}\n";
|
||||
GLint fs_prog, vs_prog;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_priv->solid_prog = dispatch->glCreateProgram();
|
||||
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, solid_vs);
|
||||
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER,
|
||||
solid_fs);
|
||||
dispatch->glAttachShader(glamor_priv->solid_prog, vs_prog);
|
||||
dispatch->glAttachShader(glamor_priv->solid_prog, fs_prog);
|
||||
|
||||
dispatch->glBindAttribLocation(glamor_priv->solid_prog,
|
||||
GLAMOR_VERTEX_POS, "v_position");
|
||||
glamor_link_glsl_prog(dispatch, glamor_priv->solid_prog);
|
||||
|
||||
glamor_priv->solid_color_uniform_location =
|
||||
dispatch->glGetUniformLocation(glamor_priv->solid_prog,
|
||||
"color");
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_fini_solid_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glDeleteProgram(glamor_priv->solid_prog);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
static void
|
||||
_glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(pixmap);
|
||||
glamor_gl_dispatch *dispatch;
|
||||
GLfloat xscale, yscale;
|
||||
float vertices[32];
|
||||
float *pvertices = vertices;
|
||||
int valid_nbox = ARRAY_SIZE(vertices);
|
||||
|
||||
glamor_set_destination_pixmap_priv_nc(pixmap_priv);
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glUseProgram(glamor_priv->solid_prog);
|
||||
|
||||
dispatch->glUniform4fv(glamor_priv->solid_color_uniform_location,
|
||||
1, color);
|
||||
|
||||
pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale);
|
||||
|
||||
if (unlikely(nbox*4*2 > ARRAY_SIZE(vertices))) {
|
||||
int allocated_box;
|
||||
|
||||
if (nbox * 6 > GLAMOR_COMPOSITE_VBO_VERT_CNT) {
|
||||
allocated_box = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6;
|
||||
} else
|
||||
allocated_box = nbox;
|
||||
pvertices = malloc(allocated_box * 4 * 2 * sizeof(float));
|
||||
if (pvertices)
|
||||
valid_nbox = allocated_box;
|
||||
else {
|
||||
pvertices = vertices;
|
||||
valid_nbox = ARRAY_SIZE(vertices) / (4*2);
|
||||
}
|
||||
}
|
||||
|
||||
if (unlikely(nbox > 1))
|
||||
dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
|
||||
GL_FALSE, 2 * sizeof(float),
|
||||
pvertices);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
|
||||
while(nbox) {
|
||||
int box_cnt, i;
|
||||
float *valid_vertices;
|
||||
valid_vertices = pvertices;
|
||||
box_cnt = nbox > valid_nbox ? valid_nbox : nbox;
|
||||
for (i = 0; i < box_cnt; i++) {
|
||||
glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale,
|
||||
box[i].x1, box[i].y1,
|
||||
box[i].x2, box[i].y2,
|
||||
glamor_priv->yInverted,
|
||||
valid_vertices);
|
||||
valid_vertices += 4*2;
|
||||
}
|
||||
if (box_cnt == 1)
|
||||
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4);
|
||||
else
|
||||
#ifndef GLAMOR_GLES2
|
||||
dispatch->glDrawRangeElements(GL_TRIANGLES,
|
||||
0,
|
||||
box_cnt * 4,
|
||||
box_cnt * 6,
|
||||
GL_UNSIGNED_SHORT,
|
||||
NULL);
|
||||
#else
|
||||
dispatch->glDrawElements(GL_TRIANGLES,
|
||||
box_cnt * 6,
|
||||
GL_UNSIGNED_SHORT,
|
||||
NULL);
|
||||
#endif
|
||||
nbox -= box_cnt;
|
||||
box += box_cnt;
|
||||
}
|
||||
|
||||
if (pvertices != vertices)
|
||||
free(pvertices);
|
||||
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
dispatch->glUseProgram(0);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
glamor_priv->state = RENDER_STATE;
|
||||
glamor_priv->render_idle_cnt = 0;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_solid_boxes(PixmapPtr pixmap,
|
||||
BoxPtr box, int nbox,
|
||||
unsigned long fg_pixel)
|
||||
{
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
GLfloat color[4];
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
||||
return FALSE;
|
||||
|
||||
glamor_get_rgba_from_pixel(fg_pixel,
|
||||
&color[0],
|
||||
&color[1],
|
||||
&color[2],
|
||||
&color[3], format_for_pixmap(pixmap));
|
||||
|
||||
if (pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
RegionRec region;
|
||||
int n_region;
|
||||
glamor_pixmap_clipped_regions *clipped_regions;
|
||||
int i;
|
||||
|
||||
RegionInitBoxes(®ion, box, nbox);
|
||||
clipped_regions = glamor_compute_clipped_regions(pixmap_priv, ®ion, &n_region, 0, 0, 0);
|
||||
for(i = 0; i < n_region; i++)
|
||||
{
|
||||
BoxPtr inner_box;
|
||||
int inner_nbox;
|
||||
SET_PIXMAP_FBO_CURRENT(pixmap_priv, clipped_regions[i].block_idx);
|
||||
|
||||
inner_box = RegionRects(clipped_regions[i].region);
|
||||
inner_nbox = RegionNumRects(clipped_regions[i].region);
|
||||
_glamor_solid_boxes(pixmap, inner_box, inner_nbox, color);
|
||||
RegionDestroy(clipped_regions[i].region);
|
||||
}
|
||||
free(clipped_regions);
|
||||
RegionUninit(®ion);
|
||||
} else
|
||||
_glamor_solid_boxes(pixmap, box, nbox, color);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
|
||||
unsigned char alu, unsigned long planemask,
|
||||
unsigned long fg_pixel)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
BoxRec box;
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
||||
return FALSE;
|
||||
|
||||
if (!glamor_set_planemask(pixmap, planemask)) {
|
||||
glamor_fallback
|
||||
("Failedto set planemask in glamor_solid.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
if (!glamor_set_alu(dispatch, alu)) {
|
||||
if (alu == GXclear)
|
||||
fg_pixel = 0;
|
||||
else {
|
||||
glamor_fallback("unsupported alu %x\n", alu);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
box.x1 = x;
|
||||
box.y1 = y;
|
||||
box.x2 = x + width;
|
||||
box.y2 = y + height;
|
||||
glamor_solid_boxes(pixmap, &box, 1, fg_pixel);
|
||||
|
||||
glamor_set_alu(dispatch, GXcopy);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
113
glamor/glamor_fillspans.c
Normal file
113
glamor/glamor_fillspans.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/** @file glamor_fillspans.c
|
||||
*
|
||||
* FillSpans implementation, taken from fb_fillsp.c
|
||||
*/
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_fill_spans(DrawablePtr drawable,
|
||||
GCPtr gc,
|
||||
int n, DDXPointPtr points, int *widths, int sorted, Bool fallback)
|
||||
{
|
||||
DDXPointPtr ppt;
|
||||
int nbox;
|
||||
BoxPtr pbox;
|
||||
int x1, x2, y;
|
||||
RegionPtr pClip = fbGetCompositeClip(gc);
|
||||
Bool ret = FALSE;
|
||||
|
||||
if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled)
|
||||
goto fail;
|
||||
|
||||
ppt = points;
|
||||
while (n--) {
|
||||
x1 = ppt->x;
|
||||
y = ppt->y;
|
||||
x2 = x1 + (int) *widths;
|
||||
ppt++;
|
||||
widths++;
|
||||
|
||||
nbox = REGION_NUM_RECTS(pClip);
|
||||
pbox = REGION_RECTS(pClip);
|
||||
while (nbox--) {
|
||||
int real_x1 = x1, real_x2 = x2;
|
||||
|
||||
if (real_x1 < pbox->x1)
|
||||
real_x1 = pbox->x1;
|
||||
|
||||
if (real_x2 > pbox->x2)
|
||||
real_x2 = pbox->x2;
|
||||
|
||||
if (real_x2 > real_x1 && pbox->y1 <= y && pbox->y2 > y) {
|
||||
if (!glamor_fill(drawable, gc, real_x1, y,
|
||||
real_x2 - real_x1, 1, fallback))
|
||||
goto fail;
|
||||
}
|
||||
pbox++;
|
||||
}
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
|
||||
fail:
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(drawable)
|
||||
&& glamor_ddx_fallback_check_gc(gc)) {
|
||||
goto done;
|
||||
}
|
||||
glamor_fallback("to %p (%c)\n", drawable,
|
||||
glamor_get_drawable_location(drawable));
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
if (glamor_prepare_access_gc(gc)) {
|
||||
fbFillSpans(drawable, gc, n, points, widths,
|
||||
sorted);
|
||||
glamor_finish_access_gc(gc);
|
||||
}
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glamor_fill_spans(DrawablePtr drawable,
|
||||
GCPtr gc,
|
||||
int n, DDXPointPtr points, int *widths, int sorted)
|
||||
{
|
||||
_glamor_fill_spans(drawable, gc, n, points, widths, sorted, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_fill_spans_nf(DrawablePtr drawable,
|
||||
GCPtr gc,
|
||||
int n, DDXPointPtr points, int *widths, int sorted)
|
||||
{
|
||||
return _glamor_fill_spans(drawable, gc, n, points, widths, sorted, FALSE);
|
||||
}
|
||||
|
||||
|
101
glamor/glamor_getimage.c
Normal file
101
glamor/glamor_getimage.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
|
||||
static Bool
|
||||
_glamor_get_image(DrawablePtr drawable, int x, int y, int w, int h,
|
||||
unsigned int format, unsigned long planeMask, char *d,
|
||||
Bool fallback)
|
||||
{
|
||||
PixmapPtr pixmap, sub_pixmap;
|
||||
struct glamor_pixmap_private *pixmap_priv;
|
||||
int x_off, y_off;
|
||||
int stride;
|
||||
void *data;
|
||||
|
||||
pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
|
||||
|
||||
if (format != ZPixmap)
|
||||
goto fall_back;
|
||||
pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
|
||||
|
||||
if (!glamor_set_planemask(pixmap, planeMask)) {
|
||||
glamor_fallback
|
||||
("Failedto set planemask in glamor_solid.\n");
|
||||
goto fall_back;
|
||||
}
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
||||
goto fall_back;
|
||||
stride = PixmapBytePad(w, drawable->depth);
|
||||
|
||||
x += drawable->x + x_off;
|
||||
y += drawable->y + y_off;
|
||||
|
||||
data = glamor_download_sub_pixmap_to_cpu(pixmap, x, y, w, h, stride,
|
||||
d, 0, GLAMOR_ACCESS_RO);
|
||||
if (data != NULL) {
|
||||
assert(data == d);
|
||||
return TRUE;
|
||||
}
|
||||
fall_back:
|
||||
sub_pixmap = glamor_get_sub_pixmap(pixmap, x + x_off + drawable->x,
|
||||
y + y_off + drawable->y, w, h,
|
||||
GLAMOR_ACCESS_RO);
|
||||
if (sub_pixmap) {
|
||||
fbGetImage(&sub_pixmap->drawable, 0, 0, w, h, format, planeMask, d);
|
||||
glamor_put_sub_pixmap(sub_pixmap, pixmap,
|
||||
x + x_off + drawable->x,
|
||||
y + y_off + drawable->y,
|
||||
w, h, GLAMOR_ACCESS_RO);
|
||||
} else
|
||||
miGetImage(drawable, x, y, w, h, format, planeMask, d);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
|
||||
unsigned int format, unsigned long planeMask, char *d)
|
||||
{
|
||||
_glamor_get_image(pDrawable, x, y, w, h, format, planeMask, d, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_get_image_nf(DrawablePtr pDrawable, int x, int y, int w, int h,
|
||||
unsigned int format, unsigned long planeMask, char *d)
|
||||
{
|
||||
return _glamor_get_image(pDrawable, x, y, w,
|
||||
h, format, planeMask, d, FALSE);
|
||||
}
|
95
glamor/glamor_getspans.c
Normal file
95
glamor/glamor_getspans.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_get_spans(DrawablePtr drawable,
|
||||
int wmax,
|
||||
DDXPointPtr points, int *widths, int count, char *dst,
|
||||
Bool fallback)
|
||||
{
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(pixmap);
|
||||
int i;
|
||||
uint8_t *readpixels_dst = (uint8_t *) dst;
|
||||
void *data;
|
||||
int x_off, y_off;
|
||||
Bool ret = FALSE;
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
||||
goto fail;
|
||||
|
||||
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
|
||||
for (i = 0; i < count; i++) {
|
||||
data = glamor_download_sub_pixmap_to_cpu(pixmap, points[i].x + x_off,
|
||||
points[i].y + y_off, widths[i], 1,
|
||||
PixmapBytePad(widths[i], drawable->depth),
|
||||
readpixels_dst, 0, GLAMOR_ACCESS_RO);
|
||||
assert(data == readpixels_dst);
|
||||
readpixels_dst += PixmapBytePad(widths[i], drawable->depth);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
fail:
|
||||
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(drawable))
|
||||
goto done;
|
||||
|
||||
ret = TRUE;
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) {
|
||||
fbGetSpans(drawable, wmax, points, widths, count, dst);
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RO);
|
||||
}
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_get_spans(DrawablePtr drawable,
|
||||
int wmax,
|
||||
DDXPointPtr points, int *widths, int count, char *dst)
|
||||
{
|
||||
_glamor_get_spans(drawable, wmax, points,
|
||||
widths, count, dst, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_get_spans_nf(DrawablePtr drawable,
|
||||
int wmax,
|
||||
DDXPointPtr points, int *widths, int count, char *dst)
|
||||
{
|
||||
return _glamor_get_spans(drawable, wmax, points,
|
||||
widths, count, dst, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
118
glamor/glamor_gl_dispatch.c
Normal file
118
glamor/glamor_gl_dispatch.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define INIT_FUNC(dst,func_name,get) \
|
||||
dst->func_name = get(#func_name); \
|
||||
if (dst->func_name == NULL) { \
|
||||
dst->func_name = (void *)dlsym(NULL, #func_name); \
|
||||
if (dst->func_name == NULL) { \
|
||||
ErrorF("Failed to get function %s\n", #func_name);\
|
||||
goto fail; \
|
||||
} \
|
||||
} \
|
||||
|
||||
_X_EXPORT Bool
|
||||
glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch,
|
||||
int gl_version,
|
||||
void *(*get_proc_address) (const char *))
|
||||
{
|
||||
#ifndef GLAMOR_GLES2
|
||||
INIT_FUNC(dispatch, glMatrixMode, get_proc_address);
|
||||
INIT_FUNC(dispatch, glLoadIdentity, get_proc_address);
|
||||
INIT_FUNC(dispatch, glRasterPos2i, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDrawPixels, get_proc_address);
|
||||
INIT_FUNC(dispatch, glLogicOp, get_proc_address);
|
||||
INIT_FUNC(dispatch, glMapBuffer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glMapBufferRange, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUnmapBuffer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBlitFramebuffer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDrawRangeElements, get_proc_address);
|
||||
#endif
|
||||
INIT_FUNC(dispatch, glViewport, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDrawArrays, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDrawElements, get_proc_address);
|
||||
INIT_FUNC(dispatch, glReadPixels, get_proc_address);
|
||||
INIT_FUNC(dispatch, glPixelStorei, get_proc_address);
|
||||
INIT_FUNC(dispatch, glTexParameteri, get_proc_address);
|
||||
INIT_FUNC(dispatch, glTexImage2D, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGenTextures, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDeleteTextures, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBindTexture, get_proc_address);
|
||||
INIT_FUNC(dispatch, glTexSubImage2D, get_proc_address);
|
||||
INIT_FUNC(dispatch, glFlush, get_proc_address);
|
||||
INIT_FUNC(dispatch, glFinish, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetIntegerv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetString, get_proc_address);
|
||||
INIT_FUNC(dispatch, glScissor, get_proc_address);
|
||||
INIT_FUNC(dispatch, glEnable, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDisable, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBlendFunc, get_proc_address);
|
||||
INIT_FUNC(dispatch, glActiveTexture, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGenBuffers, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBufferData, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBindBuffer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDeleteBuffers, get_proc_address);
|
||||
INIT_FUNC(dispatch, glFramebufferTexture2D, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBindFramebuffer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDeleteFramebuffers, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGenFramebuffers, get_proc_address);
|
||||
INIT_FUNC(dispatch, glCheckFramebufferStatus, get_proc_address);
|
||||
INIT_FUNC(dispatch, glVertexAttribPointer, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDisableVertexAttribArray, get_proc_address);
|
||||
INIT_FUNC(dispatch, glEnableVertexAttribArray, get_proc_address);
|
||||
INIT_FUNC(dispatch, glBindAttribLocation, get_proc_address);
|
||||
INIT_FUNC(dispatch, glLinkProgram, get_proc_address);
|
||||
INIT_FUNC(dispatch, glShaderSource, get_proc_address);
|
||||
|
||||
INIT_FUNC(dispatch, glUseProgram, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform1i, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform1f, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform4f, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform4fv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform1fv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniform2fv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glUniformMatrix3fv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glCreateProgram, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDeleteProgram, get_proc_address);
|
||||
INIT_FUNC(dispatch, glCreateShader, get_proc_address);
|
||||
INIT_FUNC(dispatch, glCompileShader, get_proc_address);
|
||||
INIT_FUNC(dispatch, glAttachShader, get_proc_address);
|
||||
INIT_FUNC(dispatch, glDeleteShader, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetShaderiv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetShaderInfoLog, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetProgramiv, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetProgramInfoLog, get_proc_address);
|
||||
INIT_FUNC(dispatch, glGetUniformLocation, get_proc_address);
|
||||
|
||||
return TRUE;
|
||||
fail:
|
||||
return FALSE;
|
||||
}
|
138
glamor/glamor_gl_dispatch.h
Normal file
138
glamor/glamor_gl_dispatch.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
typedef struct glamor_gl_dispatch {
|
||||
/* Transformation functions */
|
||||
void (*glMatrixMode) (GLenum mode);
|
||||
void (*glLoadIdentity) (void);
|
||||
void (*glViewport) (GLint x, GLint y, GLsizei width,
|
||||
GLsizei height);
|
||||
/* Drawing functions */
|
||||
void (*glRasterPos2i) (GLint x, GLint y);
|
||||
|
||||
/* Vertex Array */
|
||||
void (*glDrawArrays) (GLenum mode, GLint first, GLsizei count);
|
||||
|
||||
/* Elements Array*/
|
||||
void (*glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid * indices);
|
||||
void (*glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices);
|
||||
|
||||
/* Raster functions */
|
||||
void (*glReadPixels) (GLint x, GLint y,
|
||||
GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type, GLvoid * pixels);
|
||||
|
||||
void (*glDrawPixels) (GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type,
|
||||
const GLvoid * pixels);
|
||||
void (*glPixelStorei) (GLenum pname, GLint param);
|
||||
/* Texture Mapping */
|
||||
|
||||
void (*glTexParameteri) (GLenum target, GLenum pname, GLint param);
|
||||
void (*glTexImage2D) (GLenum target, GLint level,
|
||||
GLint internalFormat,
|
||||
GLsizei width, GLsizei height,
|
||||
GLint border, GLenum format, GLenum type,
|
||||
const GLvoid * pixels);
|
||||
/* 1.1 */
|
||||
void (*glGenTextures) (GLsizei n, GLuint * textures);
|
||||
void (*glDeleteTextures) (GLsizei n, const GLuint * textures);
|
||||
void (*glBindTexture) (GLenum target, GLuint texture);
|
||||
void (*glTexSubImage2D) (GLenum target, GLint level,
|
||||
GLint xoffset, GLint yoffset,
|
||||
GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type,
|
||||
const GLvoid * pixels);
|
||||
/* MISC */
|
||||
void (*glFlush) (void);
|
||||
void (*glFinish) (void);
|
||||
void (*glGetIntegerv) (GLenum pname, GLint * params);
|
||||
const GLubyte *(*glGetString) (GLenum name);
|
||||
void (*glScissor) (GLint x, GLint y, GLsizei width,
|
||||
GLsizei height);
|
||||
void (*glEnable) (GLenum cap);
|
||||
void (*glDisable) (GLenum cap);
|
||||
void (*glBlendFunc) (GLenum sfactor, GLenum dfactor);
|
||||
void (*glLogicOp) (GLenum opcode);
|
||||
|
||||
/* 1.3 */
|
||||
void (*glActiveTexture) (GLenum texture);
|
||||
|
||||
/* GL Extentions */
|
||||
void (*glGenBuffers) (GLsizei n, GLuint * buffers);
|
||||
void (*glBufferData) (GLenum target, GLsizeiptr size,
|
||||
const GLvoid * data, GLenum usage);
|
||||
GLvoid *(*glMapBuffer) (GLenum target, GLenum access);
|
||||
GLvoid *(*glMapBufferRange) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
|
||||
GLboolean (*glUnmapBuffer) (GLenum target);
|
||||
void (*glBindBuffer) (GLenum target, GLuint buffer);
|
||||
void (*glDeleteBuffers) (GLsizei n, const GLuint * buffers);
|
||||
|
||||
void (*glFramebufferTexture2D) (GLenum target, GLenum attachment,
|
||||
GLenum textarget, GLuint texture,
|
||||
GLint level);
|
||||
void (*glBindFramebuffer) (GLenum target, GLuint framebuffer);
|
||||
void (*glDeleteFramebuffers) (GLsizei n,
|
||||
const GLuint * framebuffers);
|
||||
void (*glGenFramebuffers) (GLsizei n, GLuint * framebuffers);
|
||||
GLenum (*glCheckFramebufferStatus) (GLenum target);
|
||||
void (*glBlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1,
|
||||
GLint srcY1, GLint dstX0, GLint dstY0,
|
||||
GLint dstX1, GLint dstY1,
|
||||
GLbitfield mask, GLenum filter);
|
||||
|
||||
void (*glVertexAttribPointer) (GLuint index, GLint size,
|
||||
GLenum type, GLboolean normalized,
|
||||
GLsizei stride,
|
||||
const GLvoid * pointer);
|
||||
void (*glDisableVertexAttribArray) (GLuint index);
|
||||
void (*glEnableVertexAttribArray) (GLuint index);
|
||||
void (*glBindAttribLocation) (GLuint program, GLuint index,
|
||||
const GLchar * name);
|
||||
|
||||
void (*glLinkProgram) (GLuint program);
|
||||
void (*glShaderSource) (GLuint shader, GLsizei count,
|
||||
const GLchar * *string,
|
||||
const GLint * length);
|
||||
void (*glUseProgram) (GLuint program);
|
||||
void (*glUniform1i) (GLint location, GLint v0);
|
||||
void (*glUniform1f) (GLint location, GLfloat v0);
|
||||
void (*glUniform4f) (GLint location, GLfloat v0, GLfloat v1,
|
||||
GLfloat v2, GLfloat v3);
|
||||
void (*glUniform1fv) (GLint location, GLsizei count,
|
||||
const GLfloat * value);
|
||||
void (*glUniform2fv) (GLint location, GLsizei count,
|
||||
const GLfloat * value);
|
||||
void (*glUniform4fv) (GLint location, GLsizei count,
|
||||
const GLfloat * value);
|
||||
void (*glUniformMatrix3fv) (GLint location, GLsizei count,
|
||||
GLboolean transpose, const GLfloat* value);
|
||||
GLuint (*glCreateProgram) (void);
|
||||
GLuint (*glDeleteProgram) (GLuint);
|
||||
GLuint (*glCreateShader) (GLenum type);
|
||||
void (*glCompileShader) (GLuint shader);
|
||||
void (*glAttachShader) (GLuint program, GLuint shader);
|
||||
void (*glDeleteShader) (GLuint shader);
|
||||
void (*glGetShaderiv) (GLuint shader, GLenum pname,
|
||||
GLint * params);
|
||||
void (*glGetShaderInfoLog) (GLuint shader, GLsizei bufSize,
|
||||
GLsizei * length, GLchar * infoLog);
|
||||
void (*glGetProgramiv) (GLuint program, GLenum pname,
|
||||
GLint * params);
|
||||
void (*glGetProgramInfoLog) (GLuint program, GLsizei bufSize,
|
||||
GLsizei * length, GLchar * infoLog);
|
||||
GLint (*glGetUniformLocation) (GLuint program,
|
||||
const GLchar * name);
|
||||
|
||||
} glamor_gl_dispatch;
|
||||
|
||||
|
||||
typedef void *(*get_proc_address_t) (const char *);
|
||||
|
||||
_X_EXPORT Bool
|
||||
glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch,
|
||||
int gl_version,
|
||||
get_proc_address_t get_proc_address);
|
||||
|
||||
|
||||
_X_EXPORT Bool
|
||||
glamor_gl_dispatch_init(ScreenPtr screen,
|
||||
struct glamor_gl_dispatch *dispatch,
|
||||
int gl_version);
|
64
glamor/glamor_glext.h
Normal file
64
glamor/glamor_glext.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright © 2001 Keith Packard
|
||||
* Copyright © 2008 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef GLAMOR_GLES2
|
||||
|
||||
#define GL_BGRA GL_BGRA_EXT
|
||||
#define GL_COLOR_INDEX 0x1900
|
||||
#define GL_BITMAP 0x1A00
|
||||
#define GL_UNSIGNED_INT_8_8_8_8 0x8035
|
||||
#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
|
||||
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
|
||||
#define GL_UNSIGNED_INT_10_10_10_2 0x8036
|
||||
#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
|
||||
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
|
||||
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
|
||||
|
||||
#define GL_PIXEL_PACK_BUFFER 0x88EB
|
||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||
#define GL_CLAMP_TO_BORDER 0x812D
|
||||
|
||||
#define GL_READ_WRITE 0x88BA
|
||||
#define GL_READ_ONLY 0x88B8
|
||||
#define GL_WRITE_ONLY 0x88B9
|
||||
#define GL_STREAM_DRAW 0x88E0
|
||||
#define GL_STREAM_READ 0x88E1
|
||||
#define GL_PACK_ROW_LENGTH 0x0D02
|
||||
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||
|
||||
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
|
||||
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
|
||||
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56
|
||||
|
||||
#define GL_PACK_INVERT_MESA 0x8758
|
||||
#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
|
||||
#define GL_MAP_READ_BIT 0x0001
|
||||
#define GL_MAP_WRITE_BIT 0x0002
|
||||
|
||||
#endif
|
118
glamor/glamor_glyphblt.c
Normal file
118
glamor/glamor_glyphblt.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(pDrawable)
|
||||
&& glamor_ddx_fallback_check_gc(pGC))
|
||||
return FALSE;
|
||||
|
||||
miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase)
|
||||
{
|
||||
_glamor_image_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_image_glyph_blt_nf(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase)
|
||||
{
|
||||
return _glamor_image_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase, FALSE);
|
||||
}
|
||||
|
||||
static Bool
|
||||
_glamor_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(pDrawable)
|
||||
&& glamor_ddx_fallback_check_gc(pGC))
|
||||
return FALSE;
|
||||
|
||||
miPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase)
|
||||
{
|
||||
_glamor_poly_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_poly_glyph_blt_nf(DrawablePtr pDrawable, GCPtr pGC,
|
||||
int x, int y, unsigned int nglyph,
|
||||
CharInfoPtr * ppci, pointer pglyphBase)
|
||||
{
|
||||
return _glamor_poly_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase, FALSE);
|
||||
}
|
||||
|
||||
static Bool
|
||||
_glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
|
||||
DrawablePtr pDrawable, int w, int h, int x, int y, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(pDrawable)
|
||||
&& glamor_ddx_fallback_check_pixmap(&pBitmap->drawable)
|
||||
&& glamor_ddx_fallback_check_gc(pGC))
|
||||
return FALSE;
|
||||
|
||||
miPushPixels(pGC, pBitmap, pDrawable, w, h, x, y);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
|
||||
DrawablePtr pDrawable, int w, int h, int x, int y)
|
||||
{
|
||||
_glamor_push_pixels(pGC, pBitmap, pDrawable, w, h, x, y, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_push_pixels_nf(GCPtr pGC, PixmapPtr pBitmap,
|
||||
DrawablePtr pDrawable, int w, int h, int x, int y)
|
||||
{
|
||||
return _glamor_push_pixels(pGC, pBitmap, pDrawable, w, h, x, y, FALSE);
|
||||
}
|
||||
|
1806
glamor/glamor_glyphs.c
Normal file
1806
glamor/glamor_glyphs.c
Normal file
File diff suppressed because it is too large
Load Diff
1584
glamor/glamor_gradient.c
Normal file
1584
glamor/glamor_gradient.c
Normal file
File diff suppressed because it is too large
Load Diff
1324
glamor/glamor_largepixmap.c
Normal file
1324
glamor/glamor_largepixmap.c
Normal file
File diff suppressed because it is too large
Load Diff
131
glamor/glamor_picture.c
Normal file
131
glamor/glamor_picture.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "glamor_priv.h"
|
||||
#include "mipict.h"
|
||||
|
||||
/* Upload picture to texture. We may need to flip the y axis or
|
||||
* wire alpha to 1. So we may conditional create fbo for the picture.
|
||||
* */
|
||||
enum glamor_pixmap_status
|
||||
glamor_upload_picture_to_texture(PicturePtr picture)
|
||||
{
|
||||
PixmapPtr pixmap;
|
||||
assert(picture->pDrawable);
|
||||
pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
|
||||
|
||||
return glamor_upload_pixmap_to_texture(pixmap);
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access)
|
||||
{
|
||||
if (!picture || !picture->pDrawable)
|
||||
return TRUE;
|
||||
|
||||
return glamor_prepare_access(picture->pDrawable, access);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_finish_access_picture(PicturePtr picture, glamor_access_t access)
|
||||
{
|
||||
if (!picture || !picture->pDrawable)
|
||||
return;
|
||||
|
||||
glamor_finish_access(picture->pDrawable, access);
|
||||
}
|
||||
|
||||
/*
|
||||
* We should already have drawable attached to it, if it has one.
|
||||
* Then set the attached pixmap to is_picture format, and set
|
||||
* the pict format.
|
||||
* */
|
||||
int
|
||||
glamor_create_picture(PicturePtr picture)
|
||||
{
|
||||
PixmapPtr pixmap;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
if (!picture || !picture->pDrawable)
|
||||
return 0;
|
||||
|
||||
pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
if (!pixmap_priv) {
|
||||
/* We must create a pixmap priv to track the picture format even
|
||||
* if the pixmap is a pure in memory pixmap. The reason is that
|
||||
* we may need to upload this pixmap to a texture on the fly. During
|
||||
* the uploading, we need to know the picture format. */
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
} else {
|
||||
if (GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
|
||||
/* If the picture format is not compatible with glamor fbo format,
|
||||
* we have to mark this pixmap as a separated texture, and don't
|
||||
* fallback to DDX layer. */
|
||||
if (pixmap_priv->type == GLAMOR_TEXTURE_DRM
|
||||
&& !glamor_pict_format_is_compatible(picture->format,
|
||||
pixmap->drawable.depth))
|
||||
glamor_set_pixmap_type(pixmap, GLAMOR_SEPARATE_TEXTURE);
|
||||
}
|
||||
}
|
||||
|
||||
pixmap_priv->base.is_picture = 1;
|
||||
pixmap_priv->base.picture = picture;
|
||||
|
||||
return miCreatePicture(picture);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_destroy_picture(PicturePtr picture)
|
||||
{
|
||||
PixmapPtr pixmap;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
if (!picture || !picture->pDrawable)
|
||||
return;
|
||||
|
||||
pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
if (pixmap_priv) {
|
||||
pixmap_priv->base.is_picture = 0;
|
||||
pixmap_priv->base.picture = NULL;
|
||||
}
|
||||
miDestroyPicture(picture);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_picture_format_fixup(PicturePtr picture,
|
||||
glamor_pixmap_private * pixmap_priv)
|
||||
{
|
||||
pixmap_priv->base.picture = picture;
|
||||
}
|
1433
glamor/glamor_pixmap.c
Normal file
1433
glamor/glamor_pixmap.c
Normal file
File diff suppressed because it is too large
Load Diff
127
glamor/glamor_polyfillrect.c
Normal file
127
glamor/glamor_polyfillrect.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_fillspans.c
|
||||
*
|
||||
* GC PolyFillRect implementation, taken straight from fb_fill.c
|
||||
*/
|
||||
|
||||
static Bool
|
||||
_glamor_poly_fill_rect(DrawablePtr drawable,
|
||||
GCPtr gc, int nrect, xRectangle * prect, Bool fallback)
|
||||
{
|
||||
int fullX1, fullX2, fullY1, fullY2;
|
||||
int xorg, yorg;
|
||||
int n;
|
||||
register BoxPtr pbox;
|
||||
RegionPtr pClip = fbGetCompositeClip(gc);
|
||||
Bool ret = FALSE;
|
||||
|
||||
xorg = drawable->x;
|
||||
yorg = drawable->y;
|
||||
|
||||
while (nrect--) {
|
||||
fullX1 = prect->x + xorg;
|
||||
fullY1 = prect->y + yorg;
|
||||
fullX2 = fullX1 + (int) prect->width;
|
||||
fullY2 = fullY1 + (int) prect->height;
|
||||
|
||||
n = REGION_NUM_RECTS(pClip);
|
||||
pbox = REGION_RECTS(pClip);
|
||||
/*
|
||||
* clip the rectangle to each box in the clip region
|
||||
* this is logically equivalent to calling Intersect(),
|
||||
* but rectangles may overlap each other here.
|
||||
*/
|
||||
while (n--) {
|
||||
int x1 = fullX1;
|
||||
int x2 = fullX2;
|
||||
int y1 = fullY1;
|
||||
int y2 = fullY2;
|
||||
|
||||
if (pbox->x1 > x1)
|
||||
x1 = pbox->x1;
|
||||
if (pbox->x2 < x2)
|
||||
x2 = pbox->x2;
|
||||
if (pbox->y1 > y1)
|
||||
y1 = pbox->y1;
|
||||
if (pbox->y2 < y2)
|
||||
y2 = pbox->y2;
|
||||
|
||||
pbox++;
|
||||
if (x1 >= x2 || y1 >= y2)
|
||||
continue;
|
||||
if (!glamor_fill(drawable, gc, x1, y1, x2 - x1,
|
||||
y2 - y1, fallback)) {
|
||||
nrect++;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
prect++;
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
|
||||
fail:
|
||||
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(drawable)
|
||||
&& glamor_ddx_fallback_check_gc(gc))
|
||||
goto done;
|
||||
|
||||
glamor_fallback(" to %p (%c)\n",
|
||||
drawable, glamor_get_drawable_location(drawable));
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
if (glamor_prepare_access_gc(gc)) {
|
||||
fbPolyFillRect(drawable, gc, nrect, prect);
|
||||
glamor_finish_access_gc(gc);
|
||||
}
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glamor_poly_fill_rect(DrawablePtr drawable,
|
||||
GCPtr gc, int nrect, xRectangle * prect)
|
||||
{
|
||||
_glamor_poly_fill_rect(drawable, gc, nrect, prect, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_poly_fill_rect_nf(DrawablePtr drawable,
|
||||
GCPtr gc, int nrect, xRectangle * prect)
|
||||
{
|
||||
return _glamor_poly_fill_rect(drawable, gc, nrect, prect, FALSE);
|
||||
}
|
135
glamor/glamor_polylines.c
Normal file
135
glamor/glamor_polylines.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_polylines.c
|
||||
*
|
||||
* GC PolyFillRect implementation, taken straight from fb_fill.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* glamor_poly_lines() checks if it can accelerate the lines as a group of
|
||||
* horizontal or vertical lines (rectangles), and uses existing rectangle fill
|
||||
* acceleration if so.
|
||||
*/
|
||||
static Bool
|
||||
_glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
|
||||
DDXPointPtr points, Bool fallback)
|
||||
{
|
||||
xRectangle *rects;
|
||||
int x1, x2, y1, y2;
|
||||
int i;
|
||||
|
||||
/* Don't try to do wide lines or non-solid fill style. */
|
||||
if (gc->lineWidth != 0) {
|
||||
/* This ends up in miSetSpans, which is accelerated as well as we
|
||||
* can hope X wide lines will be.
|
||||
*/
|
||||
goto wide_line;
|
||||
}
|
||||
if (gc->lineStyle != LineSolid) {
|
||||
glamor_fallback
|
||||
("non-solid fill line style %d\n",
|
||||
gc->lineStyle);
|
||||
goto fail;
|
||||
}
|
||||
rects = malloc(sizeof(xRectangle) * (n - 1));
|
||||
x1 = points[0].x;
|
||||
y1 = points[0].y;
|
||||
/* If we have any non-horizontal/vertical, fall back. */
|
||||
for (i = 0; i < n - 1; i++) {
|
||||
if (mode == CoordModePrevious) {
|
||||
x2 = x1 + points[i + 1].x;
|
||||
y2 = y1 + points[i + 1].y;
|
||||
} else {
|
||||
x2 = points[i + 1].x;
|
||||
y2 = points[i + 1].y;
|
||||
}
|
||||
if (x1 != x2 && y1 != y2) {
|
||||
free(rects);
|
||||
glamor_fallback("stub diagonal poly_line\n");
|
||||
goto fail;
|
||||
}
|
||||
if (x1 < x2) {
|
||||
rects[i].x = x1;
|
||||
rects[i].width = x2 - x1 + 1;
|
||||
} else {
|
||||
rects[i].x = x2;
|
||||
rects[i].width = x1 - x2 + 1;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
rects[i].y = y1;
|
||||
rects[i].height = y2 - y1 + 1;
|
||||
} else {
|
||||
rects[i].y = y2;
|
||||
rects[i].height = y1 - y2 + 1;
|
||||
}
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
gc->ops->PolyFillRect(drawable, gc, n - 1, rects);
|
||||
free(rects);
|
||||
return TRUE;
|
||||
|
||||
fail:
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(drawable)
|
||||
&& glamor_ddx_fallback_check_gc(gc))
|
||||
return FALSE;
|
||||
|
||||
if (gc->lineWidth == 0) {
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
if (glamor_prepare_access_gc(gc)) {
|
||||
fbPolyLine(drawable, gc, mode, n, points);
|
||||
glamor_finish_access_gc(gc);
|
||||
}
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
} else {
|
||||
wide_line:
|
||||
/* fb calls mi functions in the lineWidth != 0 case. */
|
||||
fbPolyLine(drawable, gc, mode, n, points);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
|
||||
DDXPointPtr points)
|
||||
{
|
||||
_glamor_poly_lines(drawable, gc, mode, n, points, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, int mode, int n,
|
||||
DDXPointPtr points)
|
||||
{
|
||||
return _glamor_poly_lines(drawable, gc, mode, n, points, FALSE);
|
||||
}
|
85
glamor/glamor_polyops.c
Normal file
85
glamor/glamor_polyops.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
|
||||
DDXPointPtr ppt, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_gc(pGC)
|
||||
&& glamor_ddx_fallback_check_pixmap(pDrawable))
|
||||
return FALSE;
|
||||
|
||||
miPolyPoint(pDrawable, pGC, mode, npt, ppt);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
|
||||
DDXPointPtr ppt)
|
||||
{
|
||||
_glamor_poly_point(pDrawable, pGC, mode, npt, ppt, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_poly_point_nf(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
|
||||
DDXPointPtr ppt)
|
||||
{
|
||||
return _glamor_poly_point(pDrawable, pGC, mode, npt, ppt, FALSE);
|
||||
}
|
||||
|
||||
static Bool
|
||||
_glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
|
||||
xSegment *pSeg, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_gc(pGC)
|
||||
&& glamor_ddx_fallback_check_pixmap(pDrawable))
|
||||
return FALSE;
|
||||
|
||||
miPolySegment(pDrawable, pGC, nseg, pSeg);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
|
||||
xSegment *pSeg)
|
||||
{
|
||||
_glamor_poly_segment(pDrawable, pGC, nseg, pSeg, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_poly_segment_nf(DrawablePtr pDrawable, GCPtr pGC, int nseg,
|
||||
xSegment *pSeg)
|
||||
{
|
||||
return _glamor_poly_segment(pDrawable, pGC, nseg, pSeg, FALSE);
|
||||
}
|
1047
glamor/glamor_priv.h
Normal file
1047
glamor/glamor_priv.h
Normal file
File diff suppressed because it is too large
Load Diff
363
glamor/glamor_putimage.c
Normal file
363
glamor/glamor_putimage.c
Normal file
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/** @file glamor_putaimge.c
|
||||
*
|
||||
* XPutImage implementation
|
||||
*/
|
||||
#include "glamor_priv.h"
|
||||
|
||||
void
|
||||
glamor_init_putimage_shaders(ScreenPtr screen)
|
||||
{
|
||||
#if 0
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
const char *xybitmap_vs =
|
||||
"uniform float x_bias;\n" "uniform float x_scale;\n"
|
||||
"uniform float y_bias;\n" "uniform float y_scale;\n"
|
||||
"varying vec2 bitmap_coords;\n" "void main()\n" "{\n"
|
||||
" gl_Position = vec4((gl_Vertex.x + x_bias) * x_scale,\n"
|
||||
" (gl_Vertex.y + y_bias) * y_scale,\n"
|
||||
" 0,\n"
|
||||
" 1);\n"
|
||||
" bitmap_coords = gl_MultiTexCoord0.xy;\n" "}\n";
|
||||
const char *xybitmap_fs =
|
||||
"uniform vec4 fg, bg;\n" "varying vec2 bitmap_coords;\n"
|
||||
"uniform sampler2D bitmap_sampler;\n" "void main()\n" "{\n"
|
||||
" float bitmap_value = texture2D(bitmap_sampler,\n"
|
||||
" bitmap_coords).x;\n"
|
||||
" gl_FragColor = mix(bg, fg, bitmap_value);\n" "}\n";
|
||||
GLint fs_prog, vs_prog, prog;
|
||||
GLint sampler_uniform_location;
|
||||
|
||||
if (!GLEW_ARB_fragment_shader)
|
||||
return;
|
||||
|
||||
prog = dispatch->glCreateProgram();
|
||||
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, xybitmap_vs);
|
||||
fs_prog =
|
||||
glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, xybitmap_fs);
|
||||
dispatch->glAttachShader(prog, vs_prog);
|
||||
dispatch->glAttachShader(prog, fs_prog);
|
||||
glamor_link_glsl_prog(prog);
|
||||
|
||||
dispatch->glUseProgram(prog);
|
||||
sampler_uniform_location =
|
||||
dispatch->glGetUniformLocation(prog, "bitmap_sampler");
|
||||
dispatch->glUniform1i(sampler_uniform_location, 0);
|
||||
|
||||
glamor_priv->put_image_xybitmap_fg_uniform_location =
|
||||
dispatch->glGetUniformLocation(prog, "fg");
|
||||
glamor_priv->put_image_xybitmap_bg_uniform_location =
|
||||
dispatch->glGetUniformLocation(prog, "bg");
|
||||
glamor_get_transform_uniform_locations(prog,
|
||||
&glamor_priv->put_image_xybitmap_transform);
|
||||
glamor_priv->put_image_xybitmap_prog = prog;
|
||||
dispatch->glUseProgram(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Do an XYBitmap putimage. The bits are byte-aligned rows of bitmap
|
||||
* data (where each row starts at a bit index of left_pad), and the
|
||||
* destination gets filled with the gc's fg color where the bitmap is set
|
||||
* and the bg color where the bitmap is unset.
|
||||
*
|
||||
* Implement this by passing the bitmap right through to GL, and sampling
|
||||
* it to choose between fg and bg in the fragment shader. The driver may
|
||||
* be exploding the bitmap up to be an 8-bit alpha texture, in which
|
||||
* case we might be better off just doing the fg/bg choosing in the CPU
|
||||
* and just draw the resulting texture to the destination.
|
||||
*/
|
||||
#if 0
|
||||
|
||||
static int
|
||||
y_flip(PixmapPtr pixmap, int y)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen);
|
||||
|
||||
if (pixmap == screen_pixmap)
|
||||
return (pixmap->drawable.height - 1) - y;
|
||||
else
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
glamor_put_image_xybitmap(DrawablePtr drawable, GCPtr gc,
|
||||
int x, int y, int w, int h, int left_pad,
|
||||
int image_format, char *bits)
|
||||
{
|
||||
ScreenPtr screen = drawable->pScreen;
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
float fg[4], bg[4];
|
||||
GLuint tex;
|
||||
unsigned int stride = PixmapBytePad(1, w + left_pad);
|
||||
RegionPtr clip;
|
||||
BoxPtr box;
|
||||
int nbox;
|
||||
float dest_coords[8];
|
||||
const float bitmap_coords[8] = {
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0, 1.0,
|
||||
};
|
||||
GLfloat xscale, yscale;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
pixmap_priv_get_scale(pixmap_priv, &xscale, &yscale);
|
||||
|
||||
glamor_set_normalize_vcoords(xscale, yscale,
|
||||
x, y,
|
||||
x + w, y + h,
|
||||
glamor_priv->yInverted, dest_coords);
|
||||
|
||||
glamor_fallback("glamor_put_image_xybitmap: disabled\n");
|
||||
goto fail;
|
||||
|
||||
if (glamor_priv->put_image_xybitmap_prog == 0) {
|
||||
ErrorF("no program for xybitmap putimage\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
glamor_set_alu(gc->alu);
|
||||
if (!glamor_set_planemask(pixmap, gc->planemask))
|
||||
goto fail;
|
||||
|
||||
dispatch->glUseProgram(glamor_priv->put_image_xybitmap_prog);
|
||||
|
||||
glamor_get_color_4f_from_pixel(pixmap, gc->fgPixel, fg);
|
||||
dispatch->glUniform4fv
|
||||
(glamor_priv->put_image_xybitmap_fg_uniform_location, 1, fg);
|
||||
glamor_get_color_4f_from_pixel(pixmap, gc->bgPixel, bg);
|
||||
dispatch->glUniform4fv
|
||||
(glamor_priv->put_image_xybitmap_bg_uniform_location, 1, bg);
|
||||
|
||||
dispatch->glGenTextures(1, &tex);
|
||||
dispatch->glActiveTexture(GL_TEXTURE0);
|
||||
dispatch->glEnable(GL_TEXTURE_2D);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D, tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, stride * 8);
|
||||
dispatch->glPixelStorei(GL_UNPACK_SKIP_PIXELS, left_pad);
|
||||
dispatch->glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
|
||||
w, h, 0, GL_COLOR_INDEX, GL_BITMAP, bits);
|
||||
dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
dispatch->glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
||||
|
||||
/* Now that we've set up our bitmap texture and the shader, shove
|
||||
* the destination rectangle through the cliprects and run the
|
||||
* shader on the resulting fragments.
|
||||
*/
|
||||
dispatch->glVertexPointer(2, GL_FLOAT, 0, dest_coords);
|
||||
dispatch->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
dispatch->glClientActiveTexture(GL_TEXTURE0);
|
||||
dispatch->glTexCoordPointer(2, GL_FLOAT, 0, bitmap_coords);
|
||||
dispatch->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
dispatch->glEnable(GL_SCISSOR_TEST);
|
||||
clip = fbGetCompositeClip(gc);
|
||||
for (nbox = REGION_NUM_RECTS(clip),
|
||||
box = REGION_RECTS(clip); nbox--; box++) {
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = x + w;
|
||||
int y2 = y + h;
|
||||
|
||||
if (x1 < box->x1)
|
||||
x1 = box->x1;
|
||||
if (y1 < box->y1)
|
||||
y1 = box->y1;
|
||||
if (x2 > box->x2)
|
||||
x2 = box->x2;
|
||||
if (y2 > box->y2)
|
||||
y2 = box->y2;
|
||||
if (x1 >= x2 || y1 >= y2)
|
||||
continue;
|
||||
|
||||
dispatch->glScissor(box->x1,
|
||||
y_flip(pixmap, box->y1),
|
||||
box->x2 - box->x1, box->y2 - box->y1);
|
||||
dispatch->glDrawArrays(GL_QUADS, 0, 4);
|
||||
}
|
||||
|
||||
dispatch->glDisable(GL_SCISSOR_TEST);
|
||||
glamor_set_alu(GXcopy);
|
||||
glamor_set_planemask(pixmap, ~0);
|
||||
dispatch->glDeleteTextures(1, &tex);
|
||||
dispatch->glDisable(GL_TEXTURE_2D);
|
||||
dispatch->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
dispatch->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
return;
|
||||
glamor_set_alu(GXcopy);
|
||||
glamor_set_planemask(pixmap, ~0);
|
||||
glamor_fallback(": to %p (%c)\n",
|
||||
drawable, glamor_get_drawable_location(drawable));
|
||||
fail:
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
fbPutImage(drawable, gc, 1, x, y, w, h, left_pad, XYBitmap,
|
||||
bits);
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
glamor_fini_putimage_shaders(ScreenPtr screen)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
_glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
|
||||
int w, int h, int left_pad, int image_format, char *bits, Bool fallback)
|
||||
{
|
||||
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(pixmap);
|
||||
RegionPtr clip;
|
||||
int x_off, y_off;
|
||||
Bool ret = FALSE;
|
||||
PixmapPtr temp_pixmap, sub_pixmap;
|
||||
glamor_pixmap_private *temp_pixmap_priv;
|
||||
BoxRec box;
|
||||
|
||||
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
|
||||
clip = fbGetCompositeClip(gc);
|
||||
if (image_format == XYBitmap) {
|
||||
assert(depth == 1);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
|
||||
glamor_fallback("has no fbo.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (image_format != ZPixmap) {
|
||||
glamor_fallback("non-ZPixmap\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!glamor_set_planemask(pixmap, gc->planemask)) {
|
||||
goto fail;
|
||||
}
|
||||
/* create a temporary pixmap and upload the bits to that
|
||||
* pixmap, then apply clip copy it to the destination pixmap.*/
|
||||
box.x1 = x + drawable->x;
|
||||
box.y1 = y + drawable->y;
|
||||
box.x2 = x + w + drawable->x;
|
||||
box.y2 = y + h + drawable->y;
|
||||
|
||||
if ((clip != NULL && RegionContainsRect(clip, &box) != rgnIN)
|
||||
|| gc->alu != GXcopy) {
|
||||
temp_pixmap = glamor_create_pixmap(drawable->pScreen, w, h, depth, 0);
|
||||
if (temp_pixmap == NULL)
|
||||
goto fail;
|
||||
|
||||
temp_pixmap_priv = glamor_get_pixmap_private(temp_pixmap);
|
||||
|
||||
if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv)) {
|
||||
temp_pixmap_priv->base.picture = pixmap_priv->base.picture;
|
||||
temp_pixmap_priv->base.is_picture = pixmap_priv->base.is_picture;
|
||||
}
|
||||
|
||||
glamor_upload_sub_pixmap_to_texture(temp_pixmap, 0, 0, w, h,
|
||||
pixmap->devKind, bits, 0);
|
||||
|
||||
glamor_copy_area(&temp_pixmap->drawable, drawable, gc, 0, 0, w, h, x, y);
|
||||
glamor_destroy_pixmap(temp_pixmap);
|
||||
} else
|
||||
glamor_upload_sub_pixmap_to_texture(pixmap, x + drawable->x + x_off, y + drawable->y + y_off,
|
||||
w, h, PixmapBytePad(w, depth), bits, 0);
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
|
||||
fail:
|
||||
glamor_set_planemask(pixmap, ~0);
|
||||
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(&pixmap->drawable))
|
||||
goto done;
|
||||
|
||||
glamor_fallback("to %p (%c)\n",
|
||||
drawable, glamor_get_drawable_location(drawable));
|
||||
|
||||
sub_pixmap = glamor_get_sub_pixmap(pixmap, x + x_off + drawable->x,
|
||||
y + y_off + drawable->y, w, h,
|
||||
GLAMOR_ACCESS_RW);
|
||||
if (sub_pixmap) {
|
||||
if (clip != NULL)
|
||||
pixman_region_translate (clip, -x - drawable->x, -y - drawable->y);
|
||||
|
||||
fbPutImage(&sub_pixmap->drawable, gc, depth, 0, 0, w, h,
|
||||
left_pad, image_format, bits);
|
||||
|
||||
glamor_put_sub_pixmap(sub_pixmap, pixmap,
|
||||
x + x_off + drawable->x,
|
||||
y + y_off + drawable->y,
|
||||
w, h, GLAMOR_ACCESS_RW);
|
||||
if (clip != NULL)
|
||||
pixman_region_translate (clip, x + drawable->x, y + drawable->y);
|
||||
} else
|
||||
fbPutImage(drawable, gc, depth, x, y, w, h,
|
||||
left_pad, image_format, bits);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
|
||||
int w, int h, int left_pad, int image_format, char *bits)
|
||||
{
|
||||
_glamor_put_image(drawable, gc, depth, x, y, w, h,
|
||||
left_pad, image_format, bits, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_put_image_nf(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
|
||||
int w, int h, int left_pad, int image_format, char *bits)
|
||||
{
|
||||
return _glamor_put_image(drawable, gc, depth, x, y, w, h,
|
||||
left_pad, image_format, bits, FALSE);
|
||||
}
|
||||
|
2135
glamor/glamor_render.c
Normal file
2135
glamor/glamor_render.c
Normal file
File diff suppressed because it is too large
Load Diff
111
glamor/glamor_setspans.c
Normal file
111
glamor/glamor_setspans.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
|
||||
DDXPointPtr points, int *widths, int numPoints, int sorted,
|
||||
Bool fallback)
|
||||
{
|
||||
PixmapPtr dest_pixmap = glamor_get_drawable_pixmap(drawable);
|
||||
glamor_pixmap_private *dest_pixmap_priv;
|
||||
int i;
|
||||
uint8_t *drawpixels_src = (uint8_t *) src;
|
||||
RegionPtr clip = fbGetCompositeClip(gc);
|
||||
BoxRec *pbox;
|
||||
int x_off, y_off;
|
||||
Bool ret = FALSE;
|
||||
|
||||
dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) {
|
||||
glamor_fallback("pixmap has no fbo.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* XXX Shall we set alu here? */
|
||||
if (!glamor_set_planemask(dest_pixmap, gc->planemask))
|
||||
goto fail;
|
||||
|
||||
glamor_get_drawable_deltas(drawable, dest_pixmap, &x_off, &y_off);
|
||||
for (i = 0; i < numPoints; i++) {
|
||||
|
||||
int n = REGION_NUM_RECTS(clip);
|
||||
pbox = REGION_RECTS(clip);
|
||||
while (n--) {
|
||||
int x1 = points[i].x;
|
||||
int x2 = x1 + widths[i];
|
||||
int y1 = points[i].y;
|
||||
|
||||
if (pbox->y1 > points[i].y || pbox->y2 < points[i].y)
|
||||
break;
|
||||
x1 = x1 > pbox->x1 ? x1 : pbox->x1;
|
||||
x2 = x2 < pbox->x2 ? x2 : pbox->x2;
|
||||
if (x1 >= x2)
|
||||
continue;
|
||||
glamor_upload_sub_pixmap_to_texture(dest_pixmap, x1 + x_off, y1 + y_off, x2 - x1, 1,
|
||||
PixmapBytePad(widths[i], drawable->depth),
|
||||
drawpixels_src, 0);
|
||||
}
|
||||
drawpixels_src += PixmapBytePad(widths[i], drawable->depth);
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
|
||||
fail:
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(drawable))
|
||||
goto done;
|
||||
|
||||
glamor_fallback("to %p (%c)\n",
|
||||
drawable, glamor_get_drawable_location(drawable));
|
||||
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
|
||||
fbSetSpans(drawable, gc, src, points, widths, numPoints, sorted);
|
||||
glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
|
||||
DDXPointPtr points, int *widths, int n, int sorted)
|
||||
{
|
||||
_glamor_set_spans(drawable, gc, src, points,
|
||||
widths, n, sorted, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_set_spans_nf(DrawablePtr drawable, GCPtr gc, char *src,
|
||||
DDXPointPtr points, int *widths, int n, int sorted)
|
||||
{
|
||||
return _glamor_set_spans(drawable, gc, src, points,
|
||||
widths, n, sorted, FALSE);
|
||||
}
|
325
glamor/glamor_tile.c
Normal file
325
glamor/glamor_tile.c
Normal file
|
@ -0,0 +1,325 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Eric Anholt <eric@anholt.net>
|
||||
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_tile.c
|
||||
*
|
||||
* Implements the basic fill-with-a-tile support used by multiple GC ops.
|
||||
*/
|
||||
|
||||
void
|
||||
glamor_init_tile_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
const char *tile_vs =
|
||||
"attribute vec4 v_position;\n"
|
||||
"attribute vec4 v_texcoord0;\n"
|
||||
"varying vec2 tile_texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = v_position;\n"
|
||||
" tile_texture = v_texcoord0.xy;\n" "}\n";
|
||||
const char *tile_fs =
|
||||
GLAMOR_DEFAULT_PRECISION
|
||||
"varying vec2 tile_texture;\n"
|
||||
"uniform sampler2D sampler;\n"
|
||||
"uniform vec2 wh;"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec2 rel_tex;"
|
||||
" rel_tex = tile_texture * wh; \n"
|
||||
" rel_tex = floor(rel_tex) + (fract(rel_tex) / wh); \n"
|
||||
" gl_FragColor = texture2D(sampler, rel_tex);\n"
|
||||
"}\n";
|
||||
GLint fs_prog, vs_prog;
|
||||
GLint sampler_uniform_location;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_priv->tile_prog = dispatch->glCreateProgram();
|
||||
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, tile_vs);
|
||||
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER,
|
||||
tile_fs);
|
||||
dispatch->glAttachShader(glamor_priv->tile_prog, vs_prog);
|
||||
dispatch->glAttachShader(glamor_priv->tile_prog, fs_prog);
|
||||
|
||||
dispatch->glBindAttribLocation(glamor_priv->tile_prog,
|
||||
GLAMOR_VERTEX_POS, "v_position");
|
||||
dispatch->glBindAttribLocation(glamor_priv->tile_prog,
|
||||
GLAMOR_VERTEX_SOURCE,
|
||||
"v_texcoord0");
|
||||
glamor_link_glsl_prog(dispatch, glamor_priv->tile_prog);
|
||||
|
||||
sampler_uniform_location =
|
||||
dispatch->glGetUniformLocation(glamor_priv->tile_prog,
|
||||
"sampler");
|
||||
dispatch->glUseProgram(glamor_priv->tile_prog);
|
||||
dispatch->glUniform1i(sampler_uniform_location, 0);
|
||||
|
||||
glamor_priv->tile_wh =
|
||||
dispatch->glGetUniformLocation(glamor_priv->tile_prog,
|
||||
"wh");
|
||||
dispatch->glUseProgram(0);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_fini_tile_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glDeleteProgram(glamor_priv->tile_prog);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
static void
|
||||
_glamor_tile(PixmapPtr pixmap, PixmapPtr tile,
|
||||
int x, int y, int width, int height,
|
||||
int tile_x, int tile_y)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_gl_dispatch *dispatch;
|
||||
int x1 = x;
|
||||
int x2 = x + width;
|
||||
int y1 = y;
|
||||
int y2 = y + height;
|
||||
int tile_x1 = tile_x;
|
||||
int tile_x2 = tile_x + width;
|
||||
int tile_y1 = tile_y;
|
||||
int tile_y2 = tile_y + height;
|
||||
float vertices[8];
|
||||
float source_texcoords[8];
|
||||
GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale;
|
||||
glamor_pixmap_private *src_pixmap_priv;
|
||||
glamor_pixmap_private *dst_pixmap_priv;
|
||||
float wh[4];
|
||||
src_pixmap_priv = glamor_get_pixmap_private(tile);
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
|
||||
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
|
||||
pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale);
|
||||
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale,
|
||||
&src_yscale);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glUseProgram(glamor_priv->tile_prog);
|
||||
|
||||
glamor_pixmap_fbo_fix_wh_ratio(wh, src_pixmap_priv);
|
||||
dispatch->glUniform2fv(glamor_priv->tile_wh, 1, wh);
|
||||
dispatch->glActiveTexture(GL_TEXTURE0);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D,
|
||||
src_pixmap_priv->base.fbo->tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
|
||||
GL_REPEAT);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
GL_REPEAT);
|
||||
#ifndef GLAMOR_GLES2
|
||||
dispatch->glEnable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
glamor_set_repeat_normalize_tcoords
|
||||
(src_pixmap_priv, RepeatNormal,
|
||||
src_xscale, src_yscale,
|
||||
tile_x1, tile_y1,
|
||||
tile_x2, tile_y2,
|
||||
glamor_priv->yInverted,
|
||||
source_texcoords);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
|
||||
GL_FLOAT, GL_FALSE,
|
||||
2 * sizeof(float),
|
||||
source_texcoords);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
|
||||
glamor_set_normalize_vcoords(dst_pixmap_priv, dst_xscale, dst_yscale,
|
||||
x1, y1,
|
||||
x2, y2,
|
||||
glamor_priv->yInverted, vertices);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
|
||||
GL_FALSE, 2 * sizeof(float),
|
||||
vertices);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
#ifndef GLAMOR_GLES2
|
||||
dispatch->glDisable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
dispatch->glUseProgram(0);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
|
||||
glamor_priv->state = RENDER_STATE;
|
||||
glamor_priv->render_idle_cnt = 0;
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_tile(PixmapPtr pixmap, PixmapPtr tile,
|
||||
int x, int y, int width, int height,
|
||||
unsigned char alu, unsigned long planemask,
|
||||
int tile_x, int tile_y)
|
||||
{
|
||||
ScreenPtr screen = pixmap->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_pixmap_private *dst_pixmap_priv;
|
||||
glamor_pixmap_private *src_pixmap_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
dst_pixmap_priv = glamor_get_pixmap_private(pixmap);
|
||||
src_pixmap_priv = glamor_get_pixmap_private(tile);
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv))
|
||||
return FALSE;
|
||||
|
||||
if (glamor_priv->tile_prog == 0) {
|
||||
glamor_fallback("Tiling unsupported\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)) {
|
||||
/* XXX dynamic uploading candidate. */
|
||||
glamor_fallback("Non-texture tile pixmap\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!glamor_set_planemask(pixmap, planemask)) {
|
||||
glamor_fallback("unsupported planemask %lx\n", planemask);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
if (!glamor_set_alu(dispatch, alu)) {
|
||||
glamor_fallback("unsupported alu %x\n", alu);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (dst_pixmap_priv->type == GLAMOR_TEXTURE_LARGE
|
||||
|| src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
glamor_pixmap_clipped_regions *clipped_dst_regions;
|
||||
int n_dst_region, i, j, k;
|
||||
BoxRec box;
|
||||
RegionRec region;
|
||||
|
||||
box.x1 = x;
|
||||
box.y1 = y;
|
||||
box.x2 = x + width;
|
||||
box.y2 = y + height;
|
||||
RegionInitBoxes(®ion, &box, 1);
|
||||
clipped_dst_regions = glamor_compute_clipped_regions(dst_pixmap_priv,
|
||||
®ion, &n_dst_region, 0, 0, 0);
|
||||
for(i = 0; i < n_dst_region; i++)
|
||||
{
|
||||
int n_src_region;
|
||||
glamor_pixmap_clipped_regions *clipped_src_regions;
|
||||
BoxPtr current_boxes;
|
||||
int n_current_boxes;
|
||||
|
||||
SET_PIXMAP_FBO_CURRENT(dst_pixmap_priv, clipped_dst_regions[i].block_idx);
|
||||
|
||||
if (src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
|
||||
RegionTranslate(clipped_dst_regions[i].region,
|
||||
tile_x - x, tile_y - y);
|
||||
DEBUGF("tiled a large src pixmap. %dx%d \n", tile->drawable.width, tile->drawable.height);
|
||||
clipped_src_regions = glamor_compute_clipped_regions(src_pixmap_priv,
|
||||
clipped_dst_regions[i].region,
|
||||
&n_src_region, 1, 0, 0);
|
||||
DEBUGF("got %d src regions %d \n", n_src_region);
|
||||
for (j = 0; j < n_src_region; j++)
|
||||
{
|
||||
|
||||
SET_PIXMAP_FBO_CURRENT(src_pixmap_priv, clipped_src_regions[j].block_idx);
|
||||
|
||||
RegionTranslate(clipped_src_regions[j].region,
|
||||
x - tile_x,
|
||||
y - tile_y);
|
||||
current_boxes = RegionRects(clipped_src_regions[j].region);
|
||||
n_current_boxes = RegionNumRects(clipped_src_regions[j].region);
|
||||
for(k = 0; k < n_current_boxes; k++)
|
||||
{
|
||||
DEBUGF("Tile on %d %d %d %d dst block id %d tile block id %d tilex %d tiley %d\n",
|
||||
current_boxes[k].x1, current_boxes[k].y1,
|
||||
current_boxes[k].x2 - current_boxes[k].x1,
|
||||
current_boxes[k].y2 - current_boxes[k].y1,
|
||||
clipped_dst_regions[i].block_idx,
|
||||
clipped_src_regions[j].block_idx,
|
||||
(tile_x + (current_boxes[k].x1 - x)),
|
||||
tile_y + (current_boxes[k].y1 - y));
|
||||
|
||||
_glamor_tile(pixmap, tile,
|
||||
current_boxes[k].x1, current_boxes[k].y1,
|
||||
current_boxes[k].x2 - current_boxes[k].x1,
|
||||
current_boxes[k].y2 - current_boxes[k].y1,
|
||||
(tile_x + (current_boxes[k].x1 - x)),
|
||||
(tile_y + (current_boxes[k].y1 - y)));
|
||||
}
|
||||
|
||||
RegionDestroy(clipped_src_regions[j].region);
|
||||
}
|
||||
free(clipped_src_regions);
|
||||
} else {
|
||||
current_boxes = RegionRects(clipped_dst_regions[i].region);
|
||||
n_current_boxes = RegionNumRects(clipped_dst_regions[i].region);
|
||||
for(k = 0; k < n_current_boxes; k++)
|
||||
{
|
||||
_glamor_tile(pixmap, tile,
|
||||
current_boxes[k].x1, current_boxes[k].y1,
|
||||
current_boxes[k].x2 - current_boxes[k].x1,
|
||||
current_boxes[k].y2 - current_boxes[k].y1,
|
||||
(tile_x + (current_boxes[k].x1 - x)),
|
||||
(tile_y + (current_boxes[k].y1 - y)));
|
||||
}
|
||||
}
|
||||
RegionDestroy(clipped_dst_regions[i].region);
|
||||
}
|
||||
free(clipped_dst_regions);
|
||||
RegionUninit(®ion);
|
||||
}
|
||||
else
|
||||
_glamor_tile(pixmap, tile, x, y, width, height, tile_x, tile_y);
|
||||
|
||||
glamor_set_alu(dispatch, GXcopy);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
return TRUE;
|
||||
fail:
|
||||
return FALSE;
|
||||
|
||||
}
|
1819
glamor/glamor_trapezoid.c
Normal file
1819
glamor/glamor_trapezoid.c
Normal file
File diff suppressed because it is too large
Load Diff
80
glamor/glamor_triangles.c
Normal file
80
glamor/glamor_triangles.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright © 2009 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Zhigang Gong <zhigang.gong@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
static Bool
|
||||
_glamor_triangles(CARD8 op,
|
||||
PicturePtr pSrc,
|
||||
PicturePtr pDst,
|
||||
PictFormatPtr maskFormat,
|
||||
INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris, Bool fallback)
|
||||
{
|
||||
if (!fallback
|
||||
&& glamor_ddx_fallback_check_pixmap(pDst->pDrawable)
|
||||
&& (!pSrc->pDrawable
|
||||
|| glamor_ddx_fallback_check_pixmap(pSrc->pDrawable)))
|
||||
return FALSE;
|
||||
|
||||
if (glamor_prepare_access_picture(pDst, GLAMOR_ACCESS_RW)) {
|
||||
if (glamor_prepare_access_picture(pSrc,
|
||||
GLAMOR_ACCESS_RO)) {
|
||||
|
||||
fbTriangles(op, pSrc, pDst, maskFormat, xSrc,
|
||||
ySrc, ntris, tris);
|
||||
|
||||
glamor_finish_access_picture(pSrc, GLAMOR_ACCESS_RO);
|
||||
}
|
||||
|
||||
glamor_finish_access_picture(pDst, GLAMOR_ACCESS_RW);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_triangles(CARD8 op,
|
||||
PicturePtr pSrc,
|
||||
PicturePtr pDst,
|
||||
PictFormatPtr maskFormat,
|
||||
INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris)
|
||||
{
|
||||
_glamor_triangles(op, pSrc, pDst, maskFormat,
|
||||
xSrc, ySrc, ntris, tris, TRUE);
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_triangles_nf(CARD8 op,
|
||||
PicturePtr pSrc,
|
||||
PicturePtr pDst,
|
||||
PictFormatPtr maskFormat,
|
||||
INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris)
|
||||
{
|
||||
return _glamor_triangles(op, pSrc, pDst, maskFormat,
|
||||
xSrc, ySrc, ntris, tris, FALSE);
|
||||
}
|
||||
|
1835
glamor/glamor_utils.h
Normal file
1835
glamor/glamor_utils.h
Normal file
File diff suppressed because it is too large
Load Diff
103
glamor/glamor_window.c
Normal file
103
glamor/glamor_window.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright © 2008 Intel Corporation
|
||||
* Copyright © 1998 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
/** @file glamor_window.c
|
||||
*
|
||||
* Screen Change Window Attribute implementation.
|
||||
*/
|
||||
|
||||
|
||||
static void
|
||||
glamor_fixup_window_pixmap(DrawablePtr pDrawable, PixmapPtr * ppPixmap)
|
||||
{
|
||||
PixmapPtr pPixmap = *ppPixmap;
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
|
||||
if (pPixmap->drawable.bitsPerPixel != pDrawable->bitsPerPixel) {
|
||||
pixmap_priv = glamor_get_pixmap_private(pPixmap);
|
||||
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
|
||||
glamor_fallback("pixmap %p has no fbo\n", pPixmap);
|
||||
goto fail;
|
||||
}
|
||||
glamor_debug_output(GLAMOR_DEBUG_UNIMPL,
|
||||
"To be implemented.\n");
|
||||
}
|
||||
return;
|
||||
|
||||
fail:
|
||||
GLAMOR_PANIC
|
||||
(" We can't fall back to fbFixupWindowPixmap, as the fb24_32ReformatTile"
|
||||
" is broken for glamor. \n");
|
||||
}
|
||||
|
||||
Bool
|
||||
glamor_change_window_attributes(WindowPtr pWin, unsigned long mask)
|
||||
{
|
||||
if (mask & CWBackPixmap) {
|
||||
if (pWin->backgroundState == BackgroundPixmap)
|
||||
glamor_fixup_window_pixmap(&pWin->drawable,
|
||||
&pWin->
|
||||
background.pixmap);
|
||||
}
|
||||
|
||||
if (mask & CWBorderPixmap) {
|
||||
if (pWin->borderIsPixel == FALSE)
|
||||
glamor_fixup_window_pixmap(&pWin->drawable,
|
||||
&pWin->border.pixmap);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
glamor_set_window_pixmap(WindowPtr win, PixmapPtr pPixmap)
|
||||
{
|
||||
ScreenPtr screen = win->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
PixmapPtr old = screen->GetWindowPixmap(win);
|
||||
|
||||
if (pPixmap != old) {
|
||||
glamor_pixmap_private *pixmap_priv;
|
||||
PicturePtr pic = NULL;
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(old);
|
||||
if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) && pixmap_priv->base.picture->pDrawable == (DrawablePtr)win) {
|
||||
pic = pixmap_priv->base.picture;
|
||||
pixmap_priv->base.is_picture = 0;
|
||||
pixmap_priv->base.picture = NULL;
|
||||
}
|
||||
|
||||
pixmap_priv = glamor_get_pixmap_private(pPixmap);
|
||||
if (pixmap_priv) {
|
||||
pixmap_priv->base.is_picture = !!pic;
|
||||
pixmap_priv->base.picture = pic;
|
||||
}
|
||||
}
|
||||
|
||||
screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
|
||||
(screen->SetWindowPixmap)(win, pPixmap);
|
||||
glamor_priv->saved_procs.set_window_pixmap = screen->SetWindowPixmap;
|
||||
screen->SetWindowPixmap = glamor_set_window_pixmap;
|
||||
}
|
645
glamor/glamor_xv.c
Normal file
645
glamor/glamor_xv.c
Normal file
|
@ -0,0 +1,645 @@
|
|||
/*
|
||||
* Copyright © 2013 Red Hat
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Dave Airlie <airlied@redhat.com>
|
||||
*
|
||||
* some code is derived from the xf86-video-ati radeon driver, mainly
|
||||
* the calculations.
|
||||
*/
|
||||
|
||||
/** @file glamor_xv.c
|
||||
*
|
||||
* Xv acceleration implementation
|
||||
*/
|
||||
|
||||
#include "glamor_priv.h"
|
||||
|
||||
#ifdef GLAMOR_XV
|
||||
#include "xf86xv.h"
|
||||
#include <X11/extensions/Xv.h>
|
||||
#include "fourcc.h"
|
||||
/* Reference color space transform data */
|
||||
typedef struct tagREF_TRANSFORM
|
||||
{
|
||||
float RefLuma;
|
||||
float RefRCb;
|
||||
float RefRCr;
|
||||
float RefGCb;
|
||||
float RefGCr;
|
||||
float RefBCb;
|
||||
float RefBCr;
|
||||
} REF_TRANSFORM;
|
||||
|
||||
#define RTFSaturation(a) (1.0 + ((a)*1.0)/1000.0)
|
||||
#define RTFBrightness(a) (((a)*1.0)/2000.0)
|
||||
#define RTFIntensity(a) (((a)*1.0)/2000.0)
|
||||
#define RTFContrast(a) (1.0 + ((a)*1.0)/1000.0)
|
||||
#define RTFHue(a) (((a)*3.1416)/1000.0)
|
||||
|
||||
static const char *xv_vs= "attribute vec4 v_position;\n"
|
||||
"attribute vec4 v_texcoord0;\n"
|
||||
"varying vec2 tcs;\n"
|
||||
"void main()\n" "{\n" " gl_Position = v_position;\n"
|
||||
"tcs = v_texcoord0.xy;\n"
|
||||
"}\n";
|
||||
|
||||
static const char *xv_ps = GLAMOR_DEFAULT_PRECISION
|
||||
"uniform sampler2D y_sampler;\n"
|
||||
"uniform sampler2D u_sampler;\n"
|
||||
"uniform sampler2D v_sampler;\n"
|
||||
"uniform vec4 offsetyco;\n"
|
||||
"uniform vec4 ucogamma;\n"
|
||||
"uniform vec4 vco;\n"
|
||||
"varying vec2 tcs;\n"
|
||||
"float sample;\n"
|
||||
"vec4 temp1;\n"
|
||||
"void main()\n" "{\n"
|
||||
"sample = texture2D(y_sampler, tcs).w;\n"
|
||||
"temp1.xyz = offsetyco.www * vec3(sample) + offsetyco.xyz;\n"
|
||||
"sample = texture2D(u_sampler, tcs).w;\n"
|
||||
"temp1.xyz = ucogamma.xyz * vec3(sample) + temp1.xyz;\n"
|
||||
"sample = texture2D(v_sampler, tcs).w;\n"
|
||||
"temp1.xyz = clamp(vco.xyz * vec3(sample) + temp1.xyz, 0.0, 1.0);\n"
|
||||
"temp1.w = 1.0;\n"
|
||||
"gl_FragColor = temp1;\n"
|
||||
"}\n";
|
||||
|
||||
void
|
||||
glamor_init_xv_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
GLint fs_prog, vs_prog;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
glamor_priv->xv_prog = dispatch->glCreateProgram();
|
||||
|
||||
vs_prog = glamor_compile_glsl_prog(dispatch, GL_VERTEX_SHADER, xv_vs);
|
||||
fs_prog = glamor_compile_glsl_prog(dispatch, GL_FRAGMENT_SHADER, xv_ps);
|
||||
dispatch->glAttachShader(glamor_priv->xv_prog, vs_prog);
|
||||
dispatch->glAttachShader(glamor_priv->xv_prog, fs_prog);
|
||||
|
||||
dispatch->glBindAttribLocation(glamor_priv->xv_prog,
|
||||
GLAMOR_VERTEX_POS, "v_position");
|
||||
dispatch->glBindAttribLocation(glamor_priv->xv_prog,
|
||||
GLAMOR_VERTEX_SOURCE, "v_texcoord0");
|
||||
glamor_link_glsl_prog(dispatch, glamor_priv->xv_prog);
|
||||
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
void
|
||||
glamor_fini_xv_shader(ScreenPtr screen)
|
||||
{
|
||||
glamor_screen_private *glamor_priv;
|
||||
glamor_gl_dispatch *dispatch;
|
||||
|
||||
glamor_priv = glamor_get_screen_private(screen);
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
|
||||
dispatch->glDeleteProgram(glamor_priv->xv_prog);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
}
|
||||
|
||||
#define ClipValue(v,min,max) ((v) < (min) ? (min) : (v) > (max) ? (max) : (v))
|
||||
#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
|
||||
|
||||
static Atom xvBrightness, xvContrast, xvSaturation, xvHue, xvColorspace, xvGamma;
|
||||
|
||||
#define NUM_ATTRIBUTES 5
|
||||
static XF86AttributeRec Attributes_glamor[NUM_ATTRIBUTES+1] =
|
||||
{
|
||||
{XvSettable | XvGettable, -1000, 1000, "XV_BRIGHTNESS"},
|
||||
{XvSettable | XvGettable, -1000, 1000, "XV_CONTRAST"},
|
||||
{XvSettable | XvGettable, -1000, 1000, "XV_SATURATION"},
|
||||
{XvSettable | XvGettable, -1000, 1000, "XV_HUE"},
|
||||
{XvSettable | XvGettable, 0, 1, "XV_COLORSPACE"},
|
||||
{0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
#define NUM_FORMATS 3
|
||||
|
||||
static XF86VideoFormatRec Formats[NUM_FORMATS] =
|
||||
{
|
||||
{15, TrueColor}, {16, TrueColor}, {24, TrueColor}
|
||||
};
|
||||
|
||||
#define NUM_IMAGES 2
|
||||
|
||||
static XF86ImageRec Images[NUM_IMAGES] =
|
||||
{
|
||||
XVIMAGE_YV12,
|
||||
XVIMAGE_I420,
|
||||
};
|
||||
|
||||
static void
|
||||
glamor_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup)
|
||||
{
|
||||
glamor_port_private *port_priv = (glamor_port_private *)data;
|
||||
int i;
|
||||
if (!cleanup)
|
||||
return;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (port_priv->src_pix[i]) {
|
||||
glamor_destroy_pixmap(port_priv->src_pix[i]);
|
||||
port_priv->src_pix[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
glamor_xv_set_port_attribute(ScrnInfoPtr pScrn,
|
||||
Atom attribute,
|
||||
INT32 value,
|
||||
pointer data)
|
||||
{
|
||||
glamor_port_private *port_priv = (glamor_port_private *)data;
|
||||
if (attribute == xvBrightness)
|
||||
port_priv->brightness = ClipValue(value, -1000, 1000);
|
||||
else if (attribute == xvHue)
|
||||
port_priv->hue = ClipValue(value, -1000, 1000);
|
||||
else if (attribute == xvContrast)
|
||||
port_priv->contrast = ClipValue(value, -1000, 1000);
|
||||
else if (attribute == xvSaturation)
|
||||
port_priv->saturation = ClipValue(value, -1000, 1000);
|
||||
else if (attribute == xvGamma)
|
||||
port_priv->gamma = ClipValue (value, 100, 10000);
|
||||
else if(attribute == xvColorspace)
|
||||
port_priv->transform_index = ClipValue (value, 0, 1);
|
||||
else
|
||||
return BadMatch;
|
||||
return Success;
|
||||
}
|
||||
|
||||
static int
|
||||
glamor_xv_get_port_attribute(ScrnInfoPtr pScrn,
|
||||
Atom attribute,
|
||||
INT32 *value,
|
||||
pointer data)
|
||||
{
|
||||
glamor_port_private *port_priv = (glamor_port_private *)data;
|
||||
if (attribute == xvBrightness)
|
||||
*value = port_priv->brightness;
|
||||
else if (attribute == xvHue)
|
||||
*value = port_priv->hue;
|
||||
else if (attribute == xvContrast)
|
||||
*value = port_priv->contrast;
|
||||
else if (attribute == xvSaturation)
|
||||
*value = port_priv->saturation;
|
||||
else if (attribute == xvGamma)
|
||||
*value = port_priv->gamma;
|
||||
else if(attribute == xvColorspace)
|
||||
*value = port_priv->transform_index;
|
||||
else
|
||||
return BadMatch;
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
static void
|
||||
glamor_xv_query_best_size(ScrnInfoPtr pScrn,
|
||||
Bool motion,
|
||||
short vid_w, short vid_h,
|
||||
short drw_w, short drw_h,
|
||||
unsigned int *p_w, unsigned int *p_h,
|
||||
pointer data)
|
||||
{
|
||||
*p_w = drw_w;
|
||||
*p_h = drw_h;
|
||||
}
|
||||
|
||||
static int
|
||||
glamor_xv_query_image_attributes(ScrnInfoPtr pScrn,
|
||||
int id,
|
||||
unsigned short *w, unsigned short *h,
|
||||
int *pitches, int *offsets)
|
||||
{
|
||||
int size = 0, tmp;
|
||||
|
||||
if (offsets) offsets[0] = 0;
|
||||
switch (id) {
|
||||
case FOURCC_YV12:
|
||||
case FOURCC_I420:
|
||||
*h = *h;
|
||||
*w = *w;
|
||||
size = *w;
|
||||
if (pitches) pitches[0] = size;
|
||||
size *= *h;
|
||||
if (offsets) offsets[1] = size;
|
||||
tmp = *w >> 1;
|
||||
if (pitches) pitches[1] = pitches[2] = tmp;
|
||||
tmp *= (*h >> 1);
|
||||
size += tmp;
|
||||
if (offsets) offsets[2] = size;
|
||||
size += tmp;
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
/* Parameters for ITU-R BT.601 and ITU-R BT.709 colour spaces
|
||||
note the difference to the parameters used in overlay are due
|
||||
to 10bit vs. float calcs */
|
||||
static REF_TRANSFORM trans[2] =
|
||||
{
|
||||
{1.1643, 0.0, 1.5960, -0.3918, -0.8129, 2.0172, 0.0}, /* BT.601 */
|
||||
{1.1643, 0.0, 1.7927, -0.2132, -0.5329, 2.1124, 0.0} /* BT.709 */
|
||||
};
|
||||
|
||||
static void
|
||||
glamor_display_textured_video(glamor_port_private *port_priv)
|
||||
{
|
||||
ScreenPtr screen = port_priv->pPixmap->drawable.pScreen;
|
||||
glamor_screen_private *glamor_priv =
|
||||
glamor_get_screen_private(screen);
|
||||
glamor_pixmap_private *pixmap_priv =
|
||||
glamor_get_pixmap_private(port_priv->pPixmap);
|
||||
glamor_pixmap_private *src_pixmap_priv[3];
|
||||
glamor_gl_dispatch *dispatch;
|
||||
float vertices[32], texcoords[8];
|
||||
BoxPtr box = REGION_RECTS(&port_priv->clip);
|
||||
int nBox = REGION_NUM_RECTS(&port_priv->clip);
|
||||
int dst_x_off, dst_y_off;
|
||||
GLfloat dst_xscale, dst_yscale;
|
||||
GLfloat src_xscale[3], src_yscale[3];
|
||||
int i;
|
||||
const float Loff = -0.0627;
|
||||
const float Coff = -0.502;
|
||||
float uvcosf, uvsinf;
|
||||
float yco;
|
||||
float uco[3], vco[3], off[3];
|
||||
float bright, cont, gamma;
|
||||
int ref = port_priv->transform_index;
|
||||
GLint uloc, sampler_loc;
|
||||
|
||||
cont = RTFContrast(port_priv->contrast);
|
||||
bright = RTFBrightness(port_priv->brightness);
|
||||
gamma = (float)port_priv->gamma / 1000.0;
|
||||
uvcosf = RTFSaturation(port_priv->saturation) * cos(RTFHue(port_priv->hue));
|
||||
uvsinf = RTFSaturation(port_priv->saturation) * sin(RTFHue(port_priv->hue));
|
||||
/* overlay video also does pre-gamma contrast/sat adjust, should we? */
|
||||
|
||||
yco = trans[ref].RefLuma * cont;
|
||||
uco[0] = -trans[ref].RefRCr * uvsinf;
|
||||
uco[1] = trans[ref].RefGCb * uvcosf - trans[ref].RefGCr * uvsinf;
|
||||
uco[2] = trans[ref].RefBCb * uvcosf;
|
||||
vco[0] = trans[ref].RefRCr * uvcosf;
|
||||
vco[1] = trans[ref].RefGCb * uvsinf + trans[ref].RefGCr * uvcosf;
|
||||
vco[2] = trans[ref].RefBCb * uvsinf;
|
||||
off[0] = Loff * yco + Coff * (uco[0] + vco[0]) + bright;
|
||||
off[1] = Loff * yco + Coff * (uco[1] + vco[1]) + bright;
|
||||
off[2] = Loff * yco + Coff * (uco[2] + vco[2]) + bright;
|
||||
gamma = 1.0;
|
||||
|
||||
pixmap_priv_get_dest_scale(pixmap_priv, &dst_xscale, &dst_yscale);
|
||||
glamor_get_drawable_deltas(port_priv->pDraw, port_priv->pPixmap, &dst_x_off,
|
||||
&dst_y_off);
|
||||
glamor_set_destination_pixmap_priv_nc(pixmap_priv);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (port_priv->src_pix[i]) {
|
||||
src_pixmap_priv[i] = glamor_get_pixmap_private(port_priv->src_pix[i]);
|
||||
pixmap_priv_get_scale(src_pixmap_priv[i], &src_xscale[i], &src_yscale[i]);
|
||||
}
|
||||
}
|
||||
dispatch = glamor_get_dispatch(glamor_priv);
|
||||
dispatch->glUseProgram(glamor_priv->xv_prog);
|
||||
|
||||
uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "offsetyco");
|
||||
dispatch->glUniform4f(uloc, off[0], off[1], off[2], yco);
|
||||
uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "ucogamma");
|
||||
dispatch->glUniform4f(uloc, uco[0], uco[1], uco[2], gamma);
|
||||
uloc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "vco");
|
||||
dispatch->glUniform4f(uloc, vco[0], vco[1], vco[2], 0);
|
||||
|
||||
dispatch->glActiveTexture(GL_TEXTURE0);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[0]->base.fbo->tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
|
||||
dispatch->glActiveTexture(GL_TEXTURE1);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[1]->base.fbo->tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
|
||||
dispatch->glActiveTexture(GL_TEXTURE2);
|
||||
dispatch->glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[2]->base.fbo->tex);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_LINEAR);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
|
||||
sampler_loc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "y_sampler");
|
||||
dispatch->glUniform1i(sampler_loc, 0);
|
||||
sampler_loc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "u_sampler");
|
||||
dispatch->glUniform1i(sampler_loc, 1);
|
||||
sampler_loc = dispatch->glGetUniformLocation(glamor_priv->xv_prog, "v_sampler");
|
||||
dispatch->glUniform1i(sampler_loc, 2);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
|
||||
GL_FLOAT, GL_FALSE,
|
||||
2 * sizeof(float),
|
||||
texcoords);
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
|
||||
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
|
||||
GL_FALSE, 2 * sizeof(float),
|
||||
vertices);
|
||||
|
||||
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
for (i = 0; i < nBox; i++) {
|
||||
float off_x = box[i].x1 - port_priv->drw_x;
|
||||
float off_y = box[i].y1 - port_priv->drw_y;
|
||||
float diff_x = (float)port_priv->src_w / (float)port_priv->dst_w;
|
||||
float diff_y = (float)port_priv->src_h / (float)port_priv->dst_h;
|
||||
float srcx, srcy, srcw, srch;
|
||||
int dstx, dsty, dstw, dsth;
|
||||
|
||||
|
||||
dstx = box[i].x1 + dst_x_off;
|
||||
dsty = box[i].y1 + dst_y_off;
|
||||
dstw = box[i].x2 - box[i].x1;
|
||||
dsth = box[i].y2 - box[i].y1;
|
||||
|
||||
srcx = port_priv->src_x + off_x * diff_x;
|
||||
srcy = port_priv->src_y + off_y * diff_y;
|
||||
srcw = (port_priv->src_w * dstw) / (float)port_priv->dst_w;
|
||||
srch = (port_priv->src_h * dsth) / (float)port_priv->dst_h;
|
||||
|
||||
glamor_set_normalize_vcoords(pixmap_priv,
|
||||
dst_xscale, dst_yscale,
|
||||
dstx,
|
||||
dsty,
|
||||
dstx + dstw,
|
||||
dsty + dsth,
|
||||
glamor_priv->yInverted,
|
||||
vertices);
|
||||
|
||||
glamor_set_normalize_tcoords(src_pixmap_priv[0],
|
||||
src_xscale[0],
|
||||
src_yscale[0],
|
||||
srcx,
|
||||
srcy,
|
||||
srcx + srcw,
|
||||
srcy + srch,
|
||||
glamor_priv->yInverted,
|
||||
texcoords);
|
||||
|
||||
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
||||
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
||||
|
||||
dispatch->glUseProgram(0);
|
||||
glamor_put_dispatch(glamor_priv);
|
||||
DamageDamageRegion(port_priv->pDraw, &port_priv->clip);
|
||||
}
|
||||
|
||||
static int glamor_xv_put_image(ScrnInfoPtr pScrn,
|
||||
short src_x, short src_y,
|
||||
short drw_x, short drw_y,
|
||||
short src_w, short src_h,
|
||||
short drw_w, short drw_h,
|
||||
int id,
|
||||
unsigned char *buf,
|
||||
short width,
|
||||
short height,
|
||||
Bool sync,
|
||||
RegionPtr clipBoxes,
|
||||
pointer data,
|
||||
DrawablePtr pDrawable)
|
||||
{
|
||||
ScreenPtr screen = xf86ScrnToScreen(pScrn);
|
||||
glamor_port_private *port_priv = (glamor_port_private *)data;
|
||||
INT32 x1, x2, y1, y2;
|
||||
int srcPitch, srcPitch2;
|
||||
BoxRec dstBox;
|
||||
int top, nlines;
|
||||
int s2offset, s3offset, tmp;
|
||||
|
||||
s2offset = s3offset = srcPitch2 = 0;
|
||||
|
||||
/* Clip */
|
||||
x1 = src_x;
|
||||
x2 = src_x + src_w;
|
||||
y1 = src_y;
|
||||
y2 = src_y + src_h;
|
||||
|
||||
dstBox.x1 = drw_x;
|
||||
dstBox.x2 = drw_x + drw_w;
|
||||
dstBox.y1 = drw_y;
|
||||
dstBox.y2 = drw_y + drw_h;
|
||||
if (!xf86XVClipVideoHelper(&dstBox, &x1, &x2, &y1, &y2, clipBoxes, width, height))
|
||||
return Success;
|
||||
|
||||
if ((x1 >= x2) || (y1 >= y2))
|
||||
return Success;
|
||||
|
||||
srcPitch = width;
|
||||
srcPitch2 = width >> 1;
|
||||
|
||||
if (!port_priv->src_pix[0] || (width != port_priv->src_pix_w || height != port_priv->src_pix_h)) {
|
||||
int i;
|
||||
for (i = 0; i < 3; i++)
|
||||
if (port_priv->src_pix[i])
|
||||
glamor_destroy_pixmap(port_priv->src_pix[i]);
|
||||
|
||||
port_priv->src_pix[0] = glamor_create_pixmap(screen, width, height, 8, 0);
|
||||
port_priv->src_pix[1] = glamor_create_pixmap(screen, width >> 1, height >> 1, 8, 0);
|
||||
port_priv->src_pix[2] = glamor_create_pixmap(screen, width >> 1, height >> 1, 8, 0);
|
||||
port_priv->src_pix_w = width;
|
||||
port_priv->src_pix_h = height;
|
||||
|
||||
if (!port_priv->src_pix[0] || !port_priv->src_pix[1] || !port_priv->src_pix[2])
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
top = (y1 >> 16) & ~1;
|
||||
nlines = ((y2 + 0xffff) >> 16) - top;
|
||||
|
||||
switch (id) {
|
||||
case FOURCC_YV12:
|
||||
case FOURCC_I420:
|
||||
s2offset = srcPitch * height;
|
||||
s3offset = s2offset + (srcPitch2 * ((height + 1) >> 1));
|
||||
s2offset += ((top >> 1) * srcPitch2);
|
||||
s3offset += ((top >> 1) * srcPitch2);
|
||||
if (id == FOURCC_YV12) {
|
||||
tmp = s2offset;
|
||||
s2offset = s3offset;
|
||||
s3offset = tmp;
|
||||
}
|
||||
glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[0],
|
||||
0, 0, srcPitch, nlines,
|
||||
port_priv->src_pix[0]->devKind,
|
||||
buf + (top * srcPitch), 0);
|
||||
|
||||
glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[1],
|
||||
0, 0, srcPitch2, (nlines + 1) >> 1,
|
||||
port_priv->src_pix[1]->devKind,
|
||||
buf + s2offset, 0);
|
||||
|
||||
glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[2],
|
||||
0, 0, srcPitch2, (nlines + 1) >> 1,
|
||||
port_priv->src_pix[2]->devKind,
|
||||
buf + s3offset, 0);
|
||||
break;
|
||||
default:
|
||||
return BadMatch;
|
||||
}
|
||||
|
||||
if (pDrawable->type == DRAWABLE_WINDOW)
|
||||
port_priv->pPixmap = (*screen->GetWindowPixmap)((WindowPtr)pDrawable);
|
||||
else
|
||||
port_priv->pPixmap = (PixmapPtr)pDrawable;
|
||||
|
||||
if (!RegionEqual(&port_priv->clip, clipBoxes)) {
|
||||
RegionCopy(&port_priv->clip, clipBoxes);
|
||||
}
|
||||
|
||||
port_priv->src_x = src_x;
|
||||
port_priv->src_y = src_y;
|
||||
port_priv->src_w = src_w;
|
||||
port_priv->src_h = src_h;
|
||||
port_priv->dst_w = drw_w;
|
||||
port_priv->dst_h = drw_h;
|
||||
port_priv->drw_x = drw_x;
|
||||
port_priv->drw_y = drw_y;
|
||||
port_priv->w = width;
|
||||
port_priv->h = height;
|
||||
port_priv->pDraw = pDrawable;
|
||||
glamor_display_textured_video(port_priv);
|
||||
return Success;
|
||||
}
|
||||
|
||||
static XF86VideoEncodingRec DummyEncodingGLAMOR[1] =
|
||||
{
|
||||
{
|
||||
0,
|
||||
"XV_IMAGE",
|
||||
8192, 8192,
|
||||
{1, 1}
|
||||
}
|
||||
};
|
||||
|
||||
XF86VideoAdaptorPtr
|
||||
glamor_xv_init(ScreenPtr screen, int num_texture_ports)
|
||||
{
|
||||
glamor_port_private *port_priv;
|
||||
XF86VideoAdaptorPtr adapt;
|
||||
int i;
|
||||
|
||||
adapt = calloc(1, sizeof(XF86VideoAdaptorRec) + num_texture_ports *
|
||||
(sizeof(glamor_port_private) + sizeof(DevUnion)));
|
||||
if (adapt == NULL)
|
||||
return NULL;
|
||||
|
||||
xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
|
||||
xvContrast = MAKE_ATOM("XV_CONTRAST");
|
||||
xvSaturation = MAKE_ATOM("XV_SATURATION");
|
||||
xvHue = MAKE_ATOM("XV_HUE");
|
||||
xvGamma = MAKE_ATOM("XV_GAMMA");
|
||||
xvColorspace = MAKE_ATOM("XV_COLORSPACE");
|
||||
|
||||
adapt->type = XvWindowMask | XvInputMask | XvImageMask;
|
||||
adapt->flags = 0;
|
||||
adapt->name = "GLAMOR Textured Video";
|
||||
adapt->nEncodings = 1;
|
||||
adapt->pEncodings = DummyEncodingGLAMOR;
|
||||
|
||||
adapt->nFormats = NUM_FORMATS;
|
||||
adapt->pFormats = Formats;
|
||||
adapt->nPorts = num_texture_ports;
|
||||
adapt->pPortPrivates = (DevUnion*)(&adapt[1]);
|
||||
|
||||
adapt->pAttributes = Attributes_glamor;
|
||||
adapt->nAttributes = NUM_ATTRIBUTES;
|
||||
|
||||
port_priv = (glamor_port_private *)(&adapt->pPortPrivates[num_texture_ports]);
|
||||
adapt->pImages = Images;
|
||||
adapt->nImages = NUM_IMAGES;
|
||||
adapt->PutVideo = NULL;
|
||||
adapt->PutStill = NULL;
|
||||
adapt->GetVideo = NULL;
|
||||
adapt->GetStill = NULL;
|
||||
adapt->StopVideo = glamor_xv_stop_video;
|
||||
adapt->SetPortAttribute = glamor_xv_set_port_attribute;
|
||||
adapt->GetPortAttribute = glamor_xv_get_port_attribute;
|
||||
adapt->QueryBestSize = glamor_xv_query_best_size;
|
||||
adapt->PutImage = glamor_xv_put_image;
|
||||
adapt->ReputImage = NULL;
|
||||
adapt->QueryImageAttributes = glamor_xv_query_image_attributes;
|
||||
|
||||
for (i = 0; i < num_texture_ports; i++) {
|
||||
glamor_port_private *pPriv = &port_priv[i];
|
||||
|
||||
pPriv->brightness = 0;
|
||||
pPriv->contrast = 0;
|
||||
pPriv->saturation = 0;
|
||||
pPriv->hue = 0;
|
||||
pPriv->gamma = 1000;
|
||||
pPriv->transform_index = 0;
|
||||
|
||||
REGION_NULL(pScreen, &pPriv->clip);
|
||||
|
||||
adapt->pPortPrivates[i].ptr = (pointer)(pPriv);
|
||||
}
|
||||
return adapt;
|
||||
}
|
||||
#else
|
||||
XF86VideoAdaptorPtr
|
||||
glamor_xv_init(ScreenPtr screen, int num_texture_ports)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
121
glamor/glapi.h
Normal file
121
glamor/glapi.h
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Mesa 3-D graphics library
|
||||
* Version: 7.1
|
||||
*
|
||||
* Copyright (C) 1999-2008 Brian Paul 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \mainpage Mesa GL API Module
|
||||
*
|
||||
* \section GLAPIIntroduction Introduction
|
||||
*
|
||||
* The Mesa GL API module is responsible for dispatching all the
|
||||
* gl*() functions. All GL functions are dispatched by jumping through
|
||||
* the current dispatch table (basically a struct full of function
|
||||
* pointers.)
|
||||
*
|
||||
* A per-thread current dispatch table and per-thread current context
|
||||
* pointer are managed by this module too.
|
||||
*
|
||||
* This module is intended to be non-Mesa-specific so it can be used
|
||||
* with the X/DRI libGL also.
|
||||
*/
|
||||
|
||||
#ifndef _GLAPI_H
|
||||
#define _GLAPI_H
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#if GLAMOR_GLES2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include "GL/glext.h"
|
||||
#endif
|
||||
|
||||
/* Is this needed? It is incomplete anyway. */
|
||||
#ifdef USE_MGL_NAMESPACE
|
||||
#define _glapi_set_dispatch _mglapi_set_dispatch
|
||||
#define _glapi_get_dispatch _mglapi_get_dispatch
|
||||
#define _glapi_set_context _mglapi_set_context
|
||||
#define _glapi_get_context _mglapi_get_context
|
||||
#define _glapi_Dispatch _mglapi_Dispatch
|
||||
#define _glapi_Context _mglapi_Context
|
||||
#endif
|
||||
|
||||
typedef void (*_glapi_proc)(void);
|
||||
struct _glapi_table;
|
||||
|
||||
|
||||
#if defined (GLX_USE_TLS)
|
||||
|
||||
extern __thread struct _glapi_table * _glapi_tls_Dispatch
|
||||
__attribute__((tls_model("initial-exec")));
|
||||
|
||||
extern __thread void * _glapi_tls_Context
|
||||
__attribute__((tls_model("initial-exec")));
|
||||
|
||||
extern const struct _glapi_table *_glapi_Dispatch;
|
||||
extern const void *_glapi_Context;
|
||||
|
||||
# define GET_DISPATCH() _glapi_tls_Dispatch
|
||||
# define GET_CURRENT_CONTEXT(C) C = (typeof(C)) _glapi_tls_Context
|
||||
# define SET_CURRENT_CONTEXT(C) _glapi_tls_Context = (void*)C
|
||||
|
||||
#else
|
||||
|
||||
extern struct _glapi_table *_glapi_Dispatch;
|
||||
extern void *_glapi_Context;
|
||||
|
||||
# ifdef THREADS
|
||||
|
||||
# define GET_DISPATCH() \
|
||||
(likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch())
|
||||
|
||||
# define GET_CURRENT_CONTEXT(C) C = (typeof(C)) \
|
||||
(likely(_glapi_Context) ? _glapi_Context : _glapi_get_context())
|
||||
|
||||
|
||||
# define SET_CURRENT_CONTEXT(C) do { if (likely(_glapi_Context)) \
|
||||
_glapi_Context = (void*)C; \
|
||||
else \
|
||||
_glapi_set_context(C); } while(0)
|
||||
|
||||
# else
|
||||
|
||||
# define GET_DISPATCH() _glapi_Dispatch
|
||||
# define GET_CURRENT_CONTEXT(C) C = (typeof(C)) _glapi_Context
|
||||
# define SET_CURRENT_CONTEXT(C) _glapi_Context = (void*)C
|
||||
|
||||
# endif
|
||||
|
||||
#endif /* defined (GLX_USE_TLS) */
|
||||
|
||||
|
||||
extern void
|
||||
_glapi_set_context(void *context);
|
||||
|
||||
extern void *
|
||||
_glapi_get_context(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user