2008-12-17 00:14:31 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "glamor_priv.h"
|
|
|
|
|
2009-08-20 21:32:53 +02:00
|
|
|
Bool
|
2008-12-20 22:43:52 +01:00
|
|
|
glamor_set_destination_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
2009-08-21 00:28:13 +02:00
|
|
|
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2009-08-21 00:28:13 +02:00
|
|
|
if (pixmap_priv == NULL) {
|
|
|
|
ErrorF("no pixmap priv?");
|
2008-12-20 22:43:52 +01:00
|
|
|
return FALSE;
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|
2008-12-20 22:43:52 +01:00
|
|
|
|
2009-08-21 00:28:13 +02:00
|
|
|
if (pixmap_priv->fb == 0) {
|
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen);
|
|
|
|
|
|
|
|
if (pixmap != screen_pixmap) {
|
|
|
|
ErrorF("No FBO\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
|
|
|
|
|
2008-12-20 22:43:52 +01:00
|
|
|
glViewport(0, 0,
|
2009-08-21 00:28:13 +02:00
|
|
|
pixmap->drawable.width,
|
|
|
|
pixmap->drawable.height);
|
2008-12-20 22:43:52 +01:00
|
|
|
|
2009-08-20 21:32:53 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-12-20 22:43:52 +01:00
|
|
|
|
2009-08-24 17:59:52 +02:00
|
|
|
Bool
|
|
|
|
glamor_set_planemask(PixmapPtr pixmap, unsigned long planemask)
|
|
|
|
{
|
|
|
|
if (glamor_pm_is_solid(&pixmap->drawable, planemask)) {
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorF("unsupported planemask\n");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-24 16:00:32 +02:00
|
|
|
void
|
|
|
|
glamor_set_alu(unsigned char alu)
|
|
|
|
{
|
|
|
|
if (alu == GXcopy) {
|
|
|
|
glDisable(GL_LOGIC_OP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnable(GL_LOGIC_OP);
|
|
|
|
|
|
|
|
switch (alu) {
|
|
|
|
case GXclear:
|
|
|
|
glLogicOp(GL_CLEAR);
|
|
|
|
break;
|
|
|
|
case GXand:
|
|
|
|
glLogicOp(GL_AND);
|
|
|
|
break;
|
|
|
|
case GXandReverse:
|
|
|
|
glLogicOp(GL_AND_REVERSE);
|
|
|
|
break;
|
|
|
|
case GXandInverted:
|
|
|
|
glLogicOp(GL_AND_INVERTED);
|
|
|
|
break;
|
|
|
|
case GXnoop:
|
|
|
|
glLogicOp(GL_NOOP);
|
|
|
|
break;
|
|
|
|
case GXxor:
|
|
|
|
glLogicOp(GL_XOR);
|
|
|
|
break;
|
|
|
|
case GXor:
|
|
|
|
glLogicOp(GL_OR);
|
|
|
|
break;
|
|
|
|
case GXnor:
|
|
|
|
glLogicOp(GL_NOR);
|
|
|
|
break;
|
|
|
|
case GXequiv:
|
|
|
|
glLogicOp(GL_EQUIV);
|
|
|
|
break;
|
|
|
|
case GXinvert:
|
|
|
|
glLogicOp(GL_INVERT);
|
|
|
|
break;
|
|
|
|
case GXorReverse:
|
|
|
|
glLogicOp(GL_OR_REVERSE);
|
|
|
|
break;
|
|
|
|
case GXcopyInverted:
|
|
|
|
glLogicOp(GL_COPY_INVERTED);
|
|
|
|
break;
|
|
|
|
case GXorInverted:
|
|
|
|
glLogicOp(GL_OR_INVERTED);
|
|
|
|
break;
|
|
|
|
case GXnand:
|
|
|
|
glLogicOp(GL_NAND);
|
|
|
|
break;
|
|
|
|
case GXset:
|
|
|
|
glLogicOp(GL_SET);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FatalError("unknown logic op\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:32:53 +02:00
|
|
|
void
|
|
|
|
glamor_get_transform_uniform_locations(GLint prog,
|
|
|
|
glamor_transform_uniforms *uniform_locations)
|
|
|
|
{
|
|
|
|
uniform_locations->x_bias = glGetUniformLocationARB(prog, "x_bias");
|
|
|
|
uniform_locations->x_scale = glGetUniformLocationARB(prog, "x_scale");
|
|
|
|
uniform_locations->y_bias = glGetUniformLocationARB(prog, "y_bias");
|
|
|
|
uniform_locations->y_scale = glGetUniformLocationARB(prog, "y_scale");
|
|
|
|
}
|
2008-12-20 22:43:52 +01:00
|
|
|
|
2009-08-20 21:32:53 +02:00
|
|
|
/* We don't use a full matrix for our transformations because it's
|
|
|
|
* wasteful when all we want is to rescale to NDC and possibly do a flip
|
|
|
|
* if it's the front buffer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
glamor_set_transform_for_pixmap(PixmapPtr pixmap,
|
|
|
|
glamor_transform_uniforms *uniform_locations)
|
|
|
|
{
|
2009-08-21 00:28:13 +02:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen);
|
|
|
|
|
2009-08-20 21:32:53 +02:00
|
|
|
glUniform1fARB(uniform_locations->x_bias, -pixmap->drawable.width / 2.0f);
|
|
|
|
glUniform1fARB(uniform_locations->x_scale, 2.0f / pixmap->drawable.width);
|
|
|
|
glUniform1fARB(uniform_locations->y_bias, -pixmap->drawable.height / 2.0f);
|
2009-08-21 00:28:13 +02:00
|
|
|
if (pixmap == screen_pixmap)
|
|
|
|
glUniform1fARB(uniform_locations->y_scale,
|
|
|
|
-2.0f / pixmap->drawable.height);
|
|
|
|
else
|
|
|
|
glUniform1fARB(uniform_locations->y_scale,
|
|
|
|
2.0f / pixmap->drawable.height);
|
2009-08-20 21:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GLint
|
|
|
|
glamor_compile_glsl_prog(GLenum type, const char *source)
|
|
|
|
{
|
|
|
|
GLint ok;
|
|
|
|
GLint prog;
|
|
|
|
|
|
|
|
prog = glCreateShaderObjectARB(type);
|
|
|
|
glShaderSourceARB(prog, 1, (const GLchar **)&source, NULL);
|
|
|
|
glCompileShaderARB(prog);
|
|
|
|
glGetObjectParameterivARB(prog, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
|
|
|
|
if (!ok) {
|
|
|
|
GLchar *info;
|
|
|
|
GLint size;
|
|
|
|
|
|
|
|
glGetObjectParameterivARB(prog, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);
|
|
|
|
info = malloc(size);
|
|
|
|
|
|
|
|
glGetInfoLogARB(prog, size, NULL, info);
|
|
|
|
ErrorF("Failed to compile %s: %s\n",
|
|
|
|
type == GL_FRAGMENT_SHADER ? "FS" : "VS",
|
|
|
|
info);
|
|
|
|
ErrorF("Program source:\n%s", source);
|
|
|
|
FatalError("GLSL compile failure\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return prog;
|
2008-12-20 22:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-20 21:32:53 +02:00
|
|
|
glamor_link_glsl_prog(GLint prog)
|
2008-12-20 22:43:52 +01:00
|
|
|
{
|
2009-08-20 21:32:53 +02:00
|
|
|
GLint ok;
|
|
|
|
|
|
|
|
glLinkProgram(prog);
|
|
|
|
glGetObjectParameterivARB(prog, GL_OBJECT_LINK_STATUS_ARB, &ok);
|
|
|
|
if (!ok) {
|
|
|
|
GLchar *info;
|
|
|
|
GLint size;
|
|
|
|
|
|
|
|
glGetObjectParameterivARB(prog, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);
|
|
|
|
info = malloc(size);
|
|
|
|
|
|
|
|
glGetInfoLogARB(prog, size, NULL, info);
|
|
|
|
ErrorF("Failed to link: %s\n",
|
|
|
|
info);
|
|
|
|
FatalError("GLSL link failure\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static float ubyte_to_float(uint8_t b)
|
|
|
|
{
|
|
|
|
return b / 255.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_get_color_4f_from_pixel(PixmapPtr pixmap, unsigned long fg_pixel,
|
|
|
|
GLfloat *color)
|
|
|
|
{
|
2009-08-21 00:37:22 +02:00
|
|
|
switch (pixmap->drawable.depth) {
|
|
|
|
case 1:
|
|
|
|
color[0] = 0.0;
|
2009-08-20 21:32:53 +02:00
|
|
|
color[1] = 0.0;
|
2009-08-21 00:37:22 +02:00
|
|
|
color[2] = 0.0;
|
|
|
|
color[3] = fg_pixel & 0x01;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
color[0] = 0.0;
|
|
|
|
color[1] = 0.0;
|
|
|
|
color[2] = 0.0;
|
|
|
|
color[3] = (fg_pixel & 0xff) / 255.0;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
2009-08-20 21:32:53 +02:00
|
|
|
color[0] = ubyte_to_float(fg_pixel >> 16);
|
|
|
|
color[1] = ubyte_to_float(fg_pixel >> 8);
|
|
|
|
color[2] = ubyte_to_float(fg_pixel >> 0);
|
|
|
|
color[3] = ubyte_to_float(fg_pixel >> 24);
|
2009-08-21 00:37:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ErrorF("pixmap with bad depth: %d\n", pixmap->drawable.depth);
|
|
|
|
color[0] = 1.0;
|
|
|
|
color[1] = 0.0;
|
|
|
|
color[2] = 1.0;
|
|
|
|
color[3] = 1.0;
|
|
|
|
break;
|
2009-08-20 21:32:53 +02:00
|
|
|
}
|
2008-12-20 22:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
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)
|
|
|
|
{
|
2009-08-21 02:17:43 +02:00
|
|
|
ErrorF("stubbed out stipple depth %d\n", pixmap->drawable.depth);
|
|
|
|
glamor_solid_fail_region(pixmap, x, y, width, height);
|
2008-12-20 22:43:52 +01:00
|
|
|
}
|
|
|
|
|
2008-12-17 00:14:31 +01:00
|
|
|
/**
|
2008-12-17 00:20:49 +01:00
|
|
|
* glamor_poly_lines() checks if it can accelerate the lines as a group of
|
2008-12-17 00:14:31 +01:00
|
|
|
* horizontal or vertical lines (rectangles), and uses existing rectangle fill
|
|
|
|
* acceleration if so.
|
|
|
|
*/
|
|
|
|
static void
|
2008-12-17 00:20:49 +01:00
|
|
|
glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
|
|
|
|
DDXPointPtr points)
|
2008-12-17 00:14:31 +01:00
|
|
|
{
|
|
|
|
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 || gc->lineStyle != LineSolid ||
|
|
|
|
gc->fillStyle != FillSolid) {
|
2009-08-21 02:17:43 +02:00
|
|
|
ErrorF("stub poly_line depth %d\n", drawable->depth);
|
2008-12-17 00:14:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rects = xalloc(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) {
|
2009-08-21 02:17:43 +02:00
|
|
|
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
|
|
|
|
|
2008-12-17 00:14:31 +01:00
|
|
|
xfree(rects);
|
2009-08-21 02:17:43 +02:00
|
|
|
|
|
|
|
ErrorF("stub diagonal poly_line\n");
|
|
|
|
glamor_solid_fail_region(pixmap, x1, y1, x2 - x1, y2 - y1);
|
2008-12-17 00:14:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
xfree(rects);
|
|
|
|
}
|
|
|
|
|
|
|
|
GCOps glamor_gc_ops = {
|
2008-12-17 00:20:49 +01:00
|
|
|
.FillSpans = glamor_fill_spans,
|
|
|
|
.SetSpans = glamor_set_spans,
|
|
|
|
.PutImage = glamor_put_image,
|
|
|
|
.CopyArea = miCopyArea,
|
|
|
|
.CopyPlane = miCopyPlane,
|
|
|
|
.PolyPoint = miPolyPoint,
|
|
|
|
.Polylines = glamor_poly_lines,
|
|
|
|
.PolySegment = miPolySegment,
|
|
|
|
.PolyRectangle = miPolyRectangle,
|
|
|
|
.PolyArc = miPolyArc,
|
|
|
|
.FillPolygon = miFillPolygon,
|
|
|
|
.PolyFillRect = miPolyFillRect,
|
|
|
|
.PolyFillArc = miPolyFillArc,
|
|
|
|
.PolyText8 = miPolyText8,
|
|
|
|
.PolyText16 = miPolyText16,
|
|
|
|
.ImageText8 = miImageText8,
|
|
|
|
.ImageText16 = miImageText16,
|
|
|
|
.ImageGlyphBlt = miImageGlyphBlt,
|
|
|
|
.PolyGlyphBlt = miPolyGlyphBlt,
|
|
|
|
.PushPixels = miPushPixels,
|
2008-12-17 00:14:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* exaValidateGC() sets the ops to EXA's implementations, which may be
|
|
|
|
* accelerated or may sync the card and fall back to fb.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|