2012-04-28 08:13:47 +02:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-06-22 08:33:38 +02:00
|
|
|
#ifndef GLAMOR_PRIV_H
|
|
|
|
#error This file can only be included by glamor_priv.h
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GLAMOR_UTILS_H__
|
|
|
|
#define __GLAMOR_UTILS_H__
|
|
|
|
|
2014-03-15 21:27:14 +01:00
|
|
|
#include "glamor_prepare.h"
|
2015-07-02 22:11:20 +02:00
|
|
|
#include "mipict.h"
|
2014-03-15 21:27:14 +01:00
|
|
|
|
2011-06-22 08:33:38 +02:00
|
|
|
#define v_from_x_coord_x(_xscale_, _x_) ( 2 * (_x_) * (_xscale_) - 1.0)
|
2016-01-26 22:34:00 +01:00
|
|
|
#define v_from_x_coord_y(_yscale_, _y_) (2 * (_y_) * (_yscale_) - 1.0)
|
2011-11-02 06:44:50 +01:00
|
|
|
#define t_from_x_coord_x(_xscale_, _x_) ((_x_) * (_xscale_))
|
2016-01-26 22:34:00 +01:00
|
|
|
#define t_from_x_coord_y(_yscale_, _y_) ((_y_) * (_yscale_))
|
2011-06-22 08:33:38 +02:00
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define pixmap_priv_get_dest_scale(pixmap, _pixmap_priv_, _pxscale_, _pyscale_) \
|
2012-08-08 14:11:43 +02:00
|
|
|
do { \
|
|
|
|
int _w_,_h_; \
|
2014-10-30 06:50:53 +01:00
|
|
|
PIXMAP_PRIV_GET_ACTUAL_SIZE(pixmap, _pixmap_priv_, _w_, _h_); \
|
2012-08-08 14:11:43 +02:00
|
|
|
*(_pxscale_) = 1.0 / _w_; \
|
|
|
|
*(_pyscale_) = 1.0 / _h_; \
|
2012-06-11 03:36:56 +02:00
|
|
|
} while(0)
|
2012-05-15 09:25:41 +02:00
|
|
|
|
2011-06-22 08:33:38 +02:00
|
|
|
#define pixmap_priv_get_scale(_pixmap_priv_, _pxscale_, _pyscale_) \
|
2012-01-18 12:21:36 +01:00
|
|
|
do { \
|
2014-10-30 07:08:57 +01:00
|
|
|
*(_pxscale_) = 1.0 / (_pixmap_priv_)->fbo->width; \
|
|
|
|
*(_pyscale_) = 1.0 / (_pixmap_priv_)->fbo->height; \
|
2011-06-22 08:33:38 +02:00
|
|
|
} while(0)
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define PIXMAP_PRIV_GET_ACTUAL_SIZE(pixmap, priv, w, h) \
|
2012-06-10 19:02:30 +02:00
|
|
|
do { \
|
2014-10-30 07:20:11 +01:00
|
|
|
if (_X_UNLIKELY(glamor_pixmap_priv_is_large(priv))) { \
|
2014-10-30 07:08:57 +01:00
|
|
|
w = priv->box.x2 - priv->box.x1; \
|
|
|
|
h = priv->box.y2 - priv->box.y1; \
|
2012-06-10 19:02:30 +02:00
|
|
|
} else { \
|
2014-10-30 06:50:53 +01:00
|
|
|
w = (pixmap)->drawable.width; \
|
|
|
|
h = (pixmap)->drawable.height; \
|
2012-06-10 19:02:30 +02:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_pixmap_fbo_fix_wh_ratio(wh, pixmap, priv) \
|
2012-06-10 19:02:30 +02:00
|
|
|
do { \
|
|
|
|
int actual_w, actual_h; \
|
2014-10-30 06:50:53 +01:00
|
|
|
PIXMAP_PRIV_GET_ACTUAL_SIZE(pixmap, priv, actual_w, actual_h); \
|
2014-10-30 07:08:57 +01:00
|
|
|
wh[0] = (float)priv->fbo->width / actual_w; \
|
|
|
|
wh[1] = (float)priv->fbo->height / actual_h; \
|
|
|
|
wh[2] = 1.0 / priv->fbo->width; \
|
|
|
|
wh[3] = 1.0 / priv->fbo->height; \
|
2012-06-10 19:02:30 +02:00
|
|
|
} while(0)
|
2012-04-27 09:34:15 +02:00
|
|
|
|
2012-06-10 19:02:30 +02:00
|
|
|
#define pixmap_priv_get_fbo_off(_priv_, _xoff_, _yoff_) \
|
|
|
|
do { \
|
2014-10-30 07:20:11 +01:00
|
|
|
if (_X_UNLIKELY(_priv_ && glamor_pixmap_priv_is_large(_priv_))) { \
|
2014-10-30 07:08:57 +01:00
|
|
|
*(_xoff_) = - (_priv_)->box.x1; \
|
|
|
|
*(_yoff_) = - (_priv_)->box.y1; \
|
2012-06-10 19:02:30 +02:00
|
|
|
} else { \
|
|
|
|
*(_xoff_) = 0; \
|
|
|
|
*(_yoff_) = 0; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2012-04-27 09:34:15 +02:00
|
|
|
|
2011-06-22 08:33:38 +02:00
|
|
|
#define xFixedToFloat(_val_) ((float)xFixedToInt(_val_) \
|
|
|
|
+ ((float)xFixedFrac(_val_) / 65536.0))
|
|
|
|
|
|
|
|
#define glamor_picture_get_matrixf(_picture_, _matrix_) \
|
|
|
|
do { \
|
|
|
|
int _i_; \
|
|
|
|
if ((_picture_)->transform) \
|
|
|
|
{ \
|
|
|
|
for(_i_ = 0; _i_ < 3; _i_++) \
|
|
|
|
{ \
|
|
|
|
(_matrix_)[_i_ * 3 + 0] = \
|
|
|
|
xFixedToFloat((_picture_)->transform->matrix[_i_][0]); \
|
|
|
|
(_matrix_)[_i_ * 3 + 1] = \
|
|
|
|
xFixedToFloat((_picture_)->transform->matrix[_i_][1]); \
|
|
|
|
(_matrix_)[_i_ * 3 + 2] = \
|
|
|
|
xFixedToFloat((_picture_)->transform->matrix[_i_][2]); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2012-06-11 03:36:56 +02:00
|
|
|
#define fmod(x, w) (x - w * floor((float)x/w))
|
|
|
|
|
|
|
|
#define fmodulus(x, w, c) do {c = fmod(x, w); \
|
|
|
|
c = c >= 0 ? c : c + w;} \
|
|
|
|
while(0)
|
|
|
|
/* @x: is current coord
|
|
|
|
* @x2: is the right/bottom edge
|
|
|
|
* @w: is current width or height
|
|
|
|
* @odd: is output value, 0 means we are in an even region, 1 means we are in a
|
|
|
|
* odd region.
|
|
|
|
* @c: is output value, equal to x mod w. */
|
|
|
|
#define fodd_repeat_mod(x, x2, w, odd, c) \
|
|
|
|
do { \
|
|
|
|
float shift; \
|
|
|
|
fmodulus((x), w, c); \
|
|
|
|
shift = fabs((x) - (c)); \
|
|
|
|
shift = floor(fabs(round(shift)) / w); \
|
|
|
|
odd = (int)shift & 1; \
|
|
|
|
if (odd && (((x2 % w) == 0) && \
|
|
|
|
round(fabs(x)) == x2)) \
|
|
|
|
odd = 0; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* @txy: output value, is the corrected coords.
|
|
|
|
* @xy: input coords to be fixed up.
|
|
|
|
* @cd: xy mod wh, is a input value.
|
|
|
|
* @wh: current width or height.
|
|
|
|
* @bxy1,bxy2: current box edge's x1/x2 or y1/y2
|
|
|
|
*
|
|
|
|
* case 1:
|
|
|
|
* ----------
|
|
|
|
* | * |
|
|
|
|
* | |
|
|
|
|
* ----------
|
|
|
|
* tx = (c - x1) mod w
|
|
|
|
*
|
|
|
|
* case 2:
|
|
|
|
* ---------
|
|
|
|
* * | |
|
|
|
|
* | |
|
|
|
|
* ---------
|
|
|
|
* tx = - (c - (x1 mod w))
|
|
|
|
*
|
|
|
|
* case 3:
|
|
|
|
*
|
|
|
|
* ----------
|
|
|
|
* | | *
|
|
|
|
* | |
|
|
|
|
* ----------
|
|
|
|
* tx = ((x2 mod x) - c) + (x2 - x1)
|
|
|
|
**/
|
|
|
|
#define __glamor_repeat_reflect_fixup(txy, xy, \
|
|
|
|
cd, wh, bxy1, bxy2) \
|
|
|
|
do { \
|
|
|
|
cd = wh - cd; \
|
|
|
|
if ( xy >= bxy1 && xy < bxy2) { \
|
|
|
|
cd = cd - bxy1; \
|
|
|
|
fmodulus(cd, wh, txy); \
|
|
|
|
} else if (xy < bxy1) { \
|
|
|
|
float bxy1_mod; \
|
|
|
|
fmodulus(bxy1, wh, bxy1_mod); \
|
|
|
|
txy = -(cd - bxy1_mod); \
|
|
|
|
} \
|
|
|
|
else if (xy >= bxy2) { \
|
|
|
|
float bxy2_mod; \
|
|
|
|
fmodulus(bxy2, wh, bxy2_mod); \
|
|
|
|
if (bxy2_mod == 0) \
|
|
|
|
bxy2_mod = wh; \
|
|
|
|
txy = (bxy2_mod - cd) + bxy2 - bxy1; \
|
|
|
|
} else {assert(0); txy = 0;} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define _glamor_repeat_reflect_fixup(txy, xy, cd, odd, \
|
|
|
|
wh, bxy1, bxy2) \
|
|
|
|
do { \
|
|
|
|
if (odd) { \
|
|
|
|
__glamor_repeat_reflect_fixup(txy, xy, \
|
|
|
|
cd, wh, bxy1, bxy2); \
|
|
|
|
} else \
|
|
|
|
txy = xy - bxy1; \
|
|
|
|
} while(0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define _glamor_get_reflect_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
tx1, ty1, \
|
|
|
|
_x1_, _y1_) \
|
|
|
|
do { \
|
|
|
|
int odd_x, odd_y; \
|
|
|
|
float c, d; \
|
|
|
|
fodd_repeat_mod(_x1_,priv->box.x2, \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.width, \
|
2012-06-11 03:36:56 +02:00
|
|
|
odd_x, c); \
|
|
|
|
fodd_repeat_mod(_y1_, priv->box.y2, \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.height, \
|
2012-06-11 03:36:56 +02:00
|
|
|
odd_y, d); \
|
|
|
|
DEBUGF("c %f d %f oddx %d oddy %d \n", \
|
|
|
|
c, d, odd_x, odd_y); \
|
|
|
|
DEBUGF("x2 %d x1 %d fbo->width %d \n", priv->box.x2, \
|
2014-10-30 07:08:57 +01:00
|
|
|
priv->box.x1, priv->fbo->width); \
|
2012-06-11 03:36:56 +02:00
|
|
|
DEBUGF("y2 %d y1 %d fbo->height %d \n", priv->box.y2, \
|
2014-10-30 07:08:57 +01:00
|
|
|
priv->box.y1, priv->fbo->height); \
|
2012-06-11 03:36:56 +02:00
|
|
|
_glamor_repeat_reflect_fixup(tx1, _x1_, c, odd_x, \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.width, \
|
2012-06-11 03:36:56 +02:00
|
|
|
priv->box.x1, priv->box.x2); \
|
|
|
|
_glamor_repeat_reflect_fixup(ty1, _y1_, d, odd_y, \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.height, \
|
2012-06-11 03:36:56 +02:00
|
|
|
priv->box.y1, priv->box.y2); \
|
|
|
|
} while(0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define _glamor_get_repeat_coords(pixmap, priv, repeat_type, tx1, \
|
2012-06-10 19:52:14 +02:00
|
|
|
ty1, tx2, ty2, \
|
|
|
|
_x1_, _y1_, _x2_, \
|
|
|
|
_y2_, c, d, odd_x, odd_y) \
|
|
|
|
do { \
|
|
|
|
if (repeat_type == RepeatReflect) { \
|
2012-06-11 03:36:56 +02:00
|
|
|
DEBUGF("x1 y1 %d %d\n", \
|
|
|
|
_x1_, _y1_ ); \
|
|
|
|
DEBUGF("width %d box.x1 %d \n", \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.width, \
|
2012-06-11 03:36:56 +02:00
|
|
|
priv->box.x1); \
|
|
|
|
if (odd_x) { \
|
2014-10-30 06:50:53 +01:00
|
|
|
c = (pixmap)->drawable.width \
|
2012-06-11 03:36:56 +02:00
|
|
|
- c; \
|
|
|
|
tx1 = c - priv->box.x1; \
|
|
|
|
tx2 = tx1 - ((_x2_) - (_x1_)); \
|
|
|
|
} else { \
|
|
|
|
tx1 = c - priv->box.x1; \
|
|
|
|
tx2 = tx1 + ((_x2_) - (_x1_)); \
|
|
|
|
} \
|
|
|
|
if (odd_y){ \
|
2014-10-30 06:50:53 +01:00
|
|
|
d = (pixmap)->drawable.height\
|
2012-06-11 03:36:56 +02:00
|
|
|
- d; \
|
|
|
|
ty1 = d - priv->box.y1; \
|
|
|
|
ty2 = ty1 - ((_y2_) - (_y1_)); \
|
|
|
|
} else { \
|
|
|
|
ty1 = d - priv->box.y1; \
|
|
|
|
ty2 = ty1 + ((_y2_) - (_y1_)); \
|
|
|
|
} \
|
2012-06-15 03:03:42 +02:00
|
|
|
} else { /* RepeatNormal*/ \
|
2012-06-10 19:52:14 +02:00
|
|
|
tx1 = (c - priv->box.x1); \
|
|
|
|
ty1 = (d - priv->box.y1); \
|
|
|
|
tx2 = tx1 + ((_x2_) - (_x1_)); \
|
|
|
|
ty2 = ty1 + ((_y2_) - (_y1_)); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2012-06-11 03:36:56 +02:00
|
|
|
/* _x1_ ... _y2_ may has fractional. */
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_get_repeat_transform_coords(pixmap, priv, repeat_type, tx1, \
|
2012-06-11 03:36:56 +02:00
|
|
|
ty1, _x1_, _y1_) \
|
|
|
|
do { \
|
|
|
|
DEBUGF("width %d box.x1 %d x2 %d y1 %d y2 %d\n", \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.width, \
|
2012-06-11 03:36:56 +02:00
|
|
|
priv->box.x1, priv->box.x2, priv->box.y1, \
|
|
|
|
priv->box.y2); \
|
|
|
|
DEBUGF("x1 %f y1 %f \n", _x1_, _y1_); \
|
|
|
|
if (repeat_type != RepeatReflect) { \
|
|
|
|
tx1 = _x1_ - priv->box.x1; \
|
|
|
|
ty1 = _y1_ - priv->box.y1; \
|
|
|
|
} else \
|
2014-10-30 06:50:53 +01:00
|
|
|
_glamor_get_reflect_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
tx1, ty1, \
|
|
|
|
_x1_, _y1_); \
|
|
|
|
DEBUGF("tx1 %f ty1 %f \n", tx1, ty1); \
|
|
|
|
} while(0)
|
2012-06-10 19:52:14 +02:00
|
|
|
|
|
|
|
/* _x1_ ... _y2_ must be integer. */
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_get_repeat_coords(pixmap, priv, repeat_type, tx1, \
|
2012-06-10 19:52:14 +02:00
|
|
|
ty1, tx2, ty2, _x1_, _y1_, _x2_, \
|
|
|
|
_y2_) \
|
|
|
|
do { \
|
|
|
|
int c, d; \
|
|
|
|
int odd_x = 0, odd_y = 0; \
|
|
|
|
DEBUGF("width %d box.x1 %d x2 %d y1 %d y2 %d\n", \
|
2014-10-30 06:50:53 +01:00
|
|
|
(pixmap)->drawable.width, \
|
2012-06-10 19:52:14 +02:00
|
|
|
priv->box.x1, priv->box.x2, \
|
|
|
|
priv->box.y1, priv->box.y2); \
|
2014-10-30 06:50:53 +01:00
|
|
|
modulus((_x1_), (pixmap)->drawable.width, c); \
|
|
|
|
modulus((_y1_), (pixmap)->drawable.height, d); \
|
2012-06-10 19:52:14 +02:00
|
|
|
DEBUGF("c %d d %d \n", c, d); \
|
|
|
|
if (repeat_type == RepeatReflect) { \
|
|
|
|
odd_x = abs((_x1_ - c) \
|
2014-10-30 06:50:53 +01:00
|
|
|
/ ((pixmap)->drawable.width)) & 1; \
|
2012-06-10 19:52:14 +02:00
|
|
|
odd_y = abs((_y1_ - d) \
|
2014-10-30 06:50:53 +01:00
|
|
|
/ ((pixmap)->drawable.height)) & 1; \
|
2012-06-10 19:52:14 +02:00
|
|
|
} \
|
2014-10-30 06:50:53 +01:00
|
|
|
_glamor_get_repeat_coords(pixmap, priv, repeat_type, tx1, ty1, tx2, ty2, \
|
2012-06-10 19:52:14 +02:00
|
|
|
_x1_, _y1_, _x2_, _y2_, c, d, \
|
|
|
|
odd_x, odd_y); \
|
|
|
|
} while(0)
|
|
|
|
|
2012-06-10 19:02:30 +02:00
|
|
|
#define glamor_transform_point(matrix, tx, ty, x, y) \
|
2011-06-22 08:33:38 +02:00
|
|
|
do { \
|
2012-08-08 14:11:43 +02:00
|
|
|
int _i_; \
|
|
|
|
float _result_[4]; \
|
|
|
|
for (_i_ = 0; _i_ < 3; _i_++) { \
|
|
|
|
_result_[_i_] = (matrix)[_i_ * 3] * (x) + (matrix)[_i_ * 3 + 1] * (y) \
|
|
|
|
+ (matrix)[_i_ * 3 + 2]; \
|
2011-06-22 08:33:38 +02:00
|
|
|
} \
|
2012-08-08 14:11:43 +02:00
|
|
|
tx = _result_[0] / _result_[2]; \
|
|
|
|
ty = _result_[1] / _result_[2]; \
|
2012-06-10 19:02:30 +02:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define _glamor_set_normalize_tpoint(xscale, yscale, _tx_, _ty_, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoord) \
|
2012-06-10 19:02:30 +02:00
|
|
|
do { \
|
|
|
|
(texcoord)[0] = t_from_x_coord_x(xscale, _tx_); \
|
2016-01-26 22:34:00 +01:00
|
|
|
(texcoord)[1] = t_from_x_coord_y(yscale, _ty_); \
|
2012-06-10 19:02:30 +02:00
|
|
|
DEBUGF("normalized point tx %f ty %f \n", (texcoord)[0], \
|
|
|
|
(texcoord)[1]); \
|
|
|
|
} while(0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_set_transformed_point(priv, matrix, xscale, \
|
2012-06-10 19:02:30 +02:00
|
|
|
yscale, texcoord, \
|
2014-01-12 19:19:10 +01:00
|
|
|
x, y) \
|
2012-06-10 19:02:30 +02:00
|
|
|
do { \
|
|
|
|
float tx, ty; \
|
|
|
|
int fbo_x_off, fbo_y_off; \
|
|
|
|
pixmap_priv_get_fbo_off(priv, &fbo_x_off, &fbo_y_off); \
|
|
|
|
glamor_transform_point(matrix, tx, ty, x, y); \
|
|
|
|
DEBUGF("tx %f ty %f fbooff %d %d \n", \
|
|
|
|
tx, ty, fbo_x_off, fbo_y_off); \
|
2011-06-22 08:33:38 +02:00
|
|
|
\
|
2012-06-10 19:02:30 +02:00
|
|
|
tx += fbo_x_off; \
|
|
|
|
ty += fbo_y_off; \
|
2011-06-22 08:33:38 +02:00
|
|
|
(texcoord)[0] = t_from_x_coord_x(xscale, tx); \
|
2016-01-26 22:34:00 +01:00
|
|
|
(texcoord)[1] = t_from_x_coord_y(yscale, ty); \
|
2012-06-10 19:02:30 +02:00
|
|
|
DEBUGF("normalized tx %f ty %f \n", (texcoord)[0], (texcoord)[1]); \
|
2011-06-22 08:33:38 +02:00
|
|
|
} while(0)
|
|
|
|
|
2012-06-15 03:03:42 +02:00
|
|
|
#define glamor_set_transformed_normalize_tcoords_ext( priv, \
|
2012-06-10 19:02:30 +02:00
|
|
|
matrix, \
|
2011-06-22 08:33:38 +02:00
|
|
|
xscale, \
|
|
|
|
yscale, \
|
|
|
|
tx1, ty1, tx2, ty2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords, \
|
2012-06-15 03:03:42 +02:00
|
|
|
stride) \
|
2011-06-22 08:33:38 +02:00
|
|
|
do { \
|
2012-06-10 19:02:30 +02:00
|
|
|
glamor_set_transformed_point(priv, matrix, xscale, yscale, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords, tx1, ty1); \
|
2012-06-10 19:02:30 +02:00
|
|
|
glamor_set_transformed_point(priv, matrix, xscale, yscale, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 1 * stride, tx2, ty1); \
|
2012-06-10 19:02:30 +02:00
|
|
|
glamor_set_transformed_point(priv, matrix, xscale, yscale, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 2 * stride, tx2, ty2); \
|
2012-06-10 19:02:30 +02:00
|
|
|
glamor_set_transformed_point(priv, matrix, xscale, yscale, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 3 * stride, tx1, ty2); \
|
2011-06-22 08:33:38 +02:00
|
|
|
} while (0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_set_repeat_transformed_normalize_tcoords_ext(pixmap, priv, \
|
2012-06-11 03:36:56 +02:00
|
|
|
repeat_type, \
|
|
|
|
matrix, \
|
|
|
|
xscale, \
|
|
|
|
yscale, \
|
|
|
|
_x1_, _y1_, \
|
|
|
|
_x2_, _y2_, \
|
2012-06-15 03:03:42 +02:00
|
|
|
texcoords, \
|
|
|
|
stride) \
|
2012-06-11 03:36:56 +02:00
|
|
|
do { \
|
2014-10-30 07:20:11 +01:00
|
|
|
if (_X_LIKELY(glamor_pixmap_priv_is_small(priv))) { \
|
2012-06-15 03:03:42 +02:00
|
|
|
glamor_set_transformed_normalize_tcoords_ext(priv, matrix, xscale, \
|
2012-06-11 03:36:56 +02:00
|
|
|
yscale, _x1_, _y1_, \
|
2014-01-12 19:19:10 +01:00
|
|
|
_x2_, _y2_, \
|
2012-06-15 03:03:42 +02:00
|
|
|
texcoords, stride); \
|
2012-06-11 03:36:56 +02:00
|
|
|
} else { \
|
|
|
|
float tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4; \
|
|
|
|
float ttx1, tty1, ttx2, tty2, ttx3, tty3, ttx4, tty4; \
|
|
|
|
DEBUGF("original coords %d %d %d %d\n", _x1_, _y1_, _x2_, _y2_); \
|
|
|
|
glamor_transform_point(matrix, tx1, ty1, _x1_, _y1_); \
|
|
|
|
glamor_transform_point(matrix, tx2, ty2, _x2_, _y1_); \
|
|
|
|
glamor_transform_point(matrix, tx3, ty3, _x2_, _y2_); \
|
|
|
|
glamor_transform_point(matrix, tx4, ty4, _x1_, _y2_); \
|
|
|
|
DEBUGF("transformed %f %f %f %f %f %f %f %f\n", \
|
|
|
|
tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4); \
|
2014-10-30 07:08:57 +01:00
|
|
|
glamor_get_repeat_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
ttx1, tty1, \
|
|
|
|
tx1, ty1); \
|
2014-10-30 07:08:57 +01:00
|
|
|
glamor_get_repeat_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
ttx2, tty2, \
|
|
|
|
tx2, ty2); \
|
2014-10-30 07:08:57 +01:00
|
|
|
glamor_get_repeat_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
ttx3, tty3, \
|
|
|
|
tx3, ty3); \
|
2014-10-30 07:08:57 +01:00
|
|
|
glamor_get_repeat_transform_coords(pixmap, priv, repeat_type, \
|
2012-06-11 03:36:56 +02:00
|
|
|
ttx4, tty4, \
|
|
|
|
tx4, ty4); \
|
|
|
|
DEBUGF("repeat transformed %f %f %f %f %f %f %f %f\n", ttx1, tty1, \
|
|
|
|
ttx2, tty2, ttx3, tty3, ttx4, tty4); \
|
|
|
|
_glamor_set_normalize_tpoint(xscale, yscale, ttx1, tty1, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords); \
|
2012-06-11 03:36:56 +02:00
|
|
|
_glamor_set_normalize_tpoint(xscale, yscale, ttx2, tty2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 1 * stride); \
|
2012-06-11 03:36:56 +02:00
|
|
|
_glamor_set_normalize_tpoint(xscale, yscale, ttx3, tty3, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 2 * stride); \
|
2012-06-11 03:36:56 +02:00
|
|
|
_glamor_set_normalize_tpoint(xscale, yscale, ttx4, tty4, \
|
2014-01-12 19:19:10 +01:00
|
|
|
texcoords + 3 * stride); \
|
2012-06-11 03:36:56 +02:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_set_repeat_transformed_normalize_tcoords( pixmap, \
|
|
|
|
priv, \
|
2012-06-15 03:03:42 +02:00
|
|
|
repeat_type, \
|
|
|
|
matrix, \
|
|
|
|
xscale, \
|
|
|
|
yscale, \
|
|
|
|
_x1_, _y1_, \
|
|
|
|
_x2_, _y2_, \
|
|
|
|
texcoords) \
|
|
|
|
do { \
|
2014-10-30 06:50:53 +01:00
|
|
|
glamor_set_repeat_transformed_normalize_tcoords_ext( pixmap, \
|
|
|
|
priv, \
|
2012-06-15 03:03:42 +02:00
|
|
|
repeat_type, \
|
|
|
|
matrix, \
|
|
|
|
xscale, \
|
|
|
|
yscale, \
|
|
|
|
_x1_, _y1_, \
|
|
|
|
_x2_, _y2_, \
|
|
|
|
texcoords, \
|
|
|
|
2); \
|
|
|
|
} while (0)
|
|
|
|
|
2012-06-10 19:02:30 +02:00
|
|
|
#define _glamor_set_normalize_tcoords(xscale, yscale, tx1, \
|
|
|
|
ty1, tx2, ty2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices, stride) \
|
2011-06-22 08:33:38 +02:00
|
|
|
do { \
|
2012-06-15 03:03:42 +02:00
|
|
|
/* vertices may be write-only, so we use following \
|
|
|
|
* temporary variable. */ \
|
|
|
|
float _t0_, _t1_, _t2_, _t5_; \
|
|
|
|
(vertices)[0] = _t0_ = t_from_x_coord_x(xscale, tx1); \
|
|
|
|
(vertices)[1 * stride] = _t2_ = t_from_x_coord_x(xscale, tx2); \
|
|
|
|
(vertices)[2 * stride] = _t2_; \
|
|
|
|
(vertices)[3 * stride] = _t0_; \
|
2016-01-26 22:34:00 +01:00
|
|
|
(vertices)[1] = _t1_ = t_from_x_coord_y(yscale, ty1); \
|
|
|
|
(vertices)[2 * stride + 1] = _t5_ = t_from_x_coord_y(yscale, ty2); \
|
2012-06-15 03:03:42 +02:00
|
|
|
(vertices)[1 * stride + 1] = _t1_; \
|
|
|
|
(vertices)[3 * stride + 1] = _t5_; \
|
2011-06-22 08:33:38 +02:00
|
|
|
} while(0)
|
|
|
|
|
2012-06-15 03:03:42 +02:00
|
|
|
#define glamor_set_normalize_tcoords_ext(priv, xscale, yscale, \
|
|
|
|
x1, y1, x2, y2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices, stride) \
|
2012-06-15 03:03:42 +02:00
|
|
|
do { \
|
2014-10-30 07:20:11 +01:00
|
|
|
if (_X_UNLIKELY(glamor_pixmap_priv_is_large(priv))) { \
|
2012-06-15 03:03:42 +02:00
|
|
|
float tx1, tx2, ty1, ty2; \
|
|
|
|
int fbo_x_off, fbo_y_off; \
|
|
|
|
pixmap_priv_get_fbo_off(priv, &fbo_x_off, &fbo_y_off); \
|
|
|
|
tx1 = x1 + fbo_x_off; \
|
|
|
|
tx2 = x2 + fbo_x_off; \
|
|
|
|
ty1 = y1 + fbo_y_off; \
|
|
|
|
ty2 = y2 + fbo_y_off; \
|
|
|
|
_glamor_set_normalize_tcoords(xscale, yscale, tx1, ty1, \
|
2014-01-12 19:19:10 +01:00
|
|
|
tx2, ty2, vertices, \
|
2012-06-15 03:03:42 +02:00
|
|
|
stride); \
|
|
|
|
} else \
|
|
|
|
_glamor_set_normalize_tcoords(xscale, yscale, x1, y1, \
|
2014-01-12 19:19:10 +01:00
|
|
|
x2, y2, vertices, stride); \
|
2012-06-15 03:03:42 +02:00
|
|
|
} while(0)
|
|
|
|
|
2014-10-30 06:50:53 +01:00
|
|
|
#define glamor_set_repeat_normalize_tcoords_ext(pixmap, priv, repeat_type, \
|
2012-06-15 03:03:42 +02:00
|
|
|
xscale, yscale, \
|
|
|
|
_x1_, _y1_, _x2_, _y2_, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices, stride) \
|
2012-06-15 03:03:42 +02:00
|
|
|
do { \
|
2014-10-30 07:20:11 +01:00
|
|
|
if (_X_UNLIKELY(glamor_pixmap_priv_is_large(priv))) { \
|
2012-06-15 03:03:42 +02:00
|
|
|
float tx1, tx2, ty1, ty2; \
|
|
|
|
if (repeat_type == RepeatPad) { \
|
2014-10-30 07:08:57 +01:00
|
|
|
tx1 = _x1_ - priv->box.x1; \
|
|
|
|
ty1 = _y1_ - priv->box.y1; \
|
2012-06-15 03:03:42 +02:00
|
|
|
tx2 = tx1 + ((_x2_) - (_x1_)); \
|
|
|
|
ty2 = ty1 + ((_y2_) - (_y1_)); \
|
|
|
|
} else { \
|
2014-10-30 07:08:57 +01:00
|
|
|
glamor_get_repeat_coords(pixmap, priv, repeat_type, \
|
2012-06-15 03:03:42 +02:00
|
|
|
tx1, ty1, tx2, ty2, \
|
|
|
|
_x1_, _y1_, _x2_, _y2_); \
|
|
|
|
} \
|
|
|
|
_glamor_set_normalize_tcoords(xscale, yscale, tx1, ty1, \
|
2014-01-12 19:19:10 +01:00
|
|
|
tx2, ty2, vertices, \
|
2012-06-15 03:03:42 +02:00
|
|
|
stride); \
|
|
|
|
} else \
|
|
|
|
_glamor_set_normalize_tcoords(xscale, yscale, _x1_, _y1_, \
|
2014-01-12 19:19:10 +01:00
|
|
|
_x2_, _y2_, vertices, \
|
2012-06-15 03:03:42 +02:00
|
|
|
stride); \
|
|
|
|
} while(0)
|
2012-06-11 03:36:56 +02:00
|
|
|
|
2012-06-03 21:18:40 +02:00
|
|
|
#define glamor_set_normalize_tcoords_tri_stripe(xscale, yscale, \
|
|
|
|
x1, y1, x2, y2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices) \
|
2012-06-03 21:18:40 +02:00
|
|
|
do { \
|
|
|
|
(vertices)[0] = t_from_x_coord_x(xscale, x1); \
|
|
|
|
(vertices)[2] = t_from_x_coord_x(xscale, x2); \
|
|
|
|
(vertices)[6] = (vertices)[2]; \
|
|
|
|
(vertices)[4] = (vertices)[0]; \
|
2016-01-26 22:34:00 +01:00
|
|
|
(vertices)[1] = t_from_x_coord_y(yscale, y1); \
|
|
|
|
(vertices)[7] = t_from_x_coord_y(yscale, y2); \
|
2012-06-03 21:18:40 +02:00
|
|
|
(vertices)[3] = (vertices)[1]; \
|
|
|
|
(vertices)[5] = (vertices)[7]; \
|
|
|
|
} while(0)
|
2012-06-10 19:52:14 +02:00
|
|
|
|
2014-01-12 19:19:10 +01:00
|
|
|
#define glamor_set_tcoords_tri_strip(x1, y1, x2, y2, vertices) \
|
2012-06-03 21:18:40 +02:00
|
|
|
do { \
|
|
|
|
(vertices)[0] = (x1); \
|
|
|
|
(vertices)[2] = (x2); \
|
|
|
|
(vertices)[6] = (vertices)[2]; \
|
|
|
|
(vertices)[4] = (vertices)[0]; \
|
2014-01-12 19:19:10 +01:00
|
|
|
(vertices)[1] = (y1); \
|
|
|
|
(vertices)[7] = (y2); \
|
2012-06-03 21:18:40 +02:00
|
|
|
(vertices)[3] = (vertices)[1]; \
|
|
|
|
(vertices)[5] = (vertices)[7]; \
|
|
|
|
} while(0)
|
2011-06-22 08:33:38 +02:00
|
|
|
|
2012-06-15 03:03:42 +02:00
|
|
|
#define glamor_set_normalize_vcoords_ext(priv, xscale, yscale, \
|
2012-06-10 19:02:30 +02:00
|
|
|
x1, y1, x2, y2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices, stride) \
|
2012-06-10 19:02:30 +02:00
|
|
|
do { \
|
|
|
|
int fbo_x_off, fbo_y_off; \
|
2012-06-15 03:03:42 +02:00
|
|
|
/* vertices may be write-only, so we use following \
|
|
|
|
* temporary variable. */ \
|
|
|
|
float _t0_, _t1_, _t2_, _t5_; \
|
2012-06-10 19:02:30 +02:00
|
|
|
pixmap_priv_get_fbo_off(priv, &fbo_x_off, &fbo_y_off); \
|
2012-06-15 03:03:42 +02:00
|
|
|
(vertices)[0] = _t0_ = v_from_x_coord_x(xscale, x1 + fbo_x_off); \
|
|
|
|
(vertices)[1 * stride] = _t2_ = v_from_x_coord_x(xscale, \
|
|
|
|
x2 + fbo_x_off); \
|
|
|
|
(vertices)[2 * stride] = _t2_; \
|
|
|
|
(vertices)[3 * stride] = _t0_; \
|
2016-01-26 22:34:00 +01:00
|
|
|
(vertices)[1] = _t1_ = v_from_x_coord_y(yscale, y1 + fbo_y_off); \
|
2014-01-12 19:19:10 +01:00
|
|
|
(vertices)[2 * stride + 1] = _t5_ = \
|
2016-01-26 22:34:00 +01:00
|
|
|
v_from_x_coord_y(yscale, y2 + fbo_y_off); \
|
2012-06-15 03:03:42 +02:00
|
|
|
(vertices)[1 * stride + 1] = _t1_; \
|
|
|
|
(vertices)[3 * stride + 1] = _t5_; \
|
|
|
|
} while(0)
|
|
|
|
|
2012-06-03 21:18:40 +02:00
|
|
|
#define glamor_set_normalize_vcoords_tri_strip(xscale, yscale, \
|
|
|
|
x1, y1, x2, y2, \
|
2014-01-12 19:19:10 +01:00
|
|
|
vertices) \
|
2012-06-03 21:18:40 +02:00
|
|
|
do { \
|
|
|
|
(vertices)[0] = v_from_x_coord_x(xscale, x1); \
|
|
|
|
(vertices)[2] = v_from_x_coord_x(xscale, x2); \
|
|
|
|
(vertices)[6] = (vertices)[2]; \
|
|
|
|
(vertices)[4] = (vertices)[0]; \
|
2016-01-26 22:34:00 +01:00
|
|
|
(vertices)[1] = v_from_x_coord_y(yscale, y1); \
|
|
|
|
(vertices)[7] = v_from_x_coord_y(yscale, y2); \
|
2012-06-03 21:18:40 +02:00
|
|
|
(vertices)[3] = (vertices)[1]; \
|
|
|
|
(vertices)[5] = (vertices)[7]; \
|
|
|
|
} while(0)
|
|
|
|
|
2012-05-15 04:08:03 +02:00
|
|
|
#define glamor_set_normalize_pt(xscale, yscale, x, y, \
|
2014-01-12 19:19:10 +01:00
|
|
|
pt) \
|
2012-05-15 04:08:03 +02:00
|
|
|
do { \
|
|
|
|
(pt)[0] = t_from_x_coord_x(xscale, x); \
|
2016-01-26 22:34:00 +01:00
|
|
|
(pt)[1] = t_from_x_coord_y(yscale, y); \
|
2012-05-15 04:08:03 +02:00
|
|
|
} while(0)
|
2011-06-22 08:33:38 +02:00
|
|
|
|
2012-05-15 04:08:03 +02:00
|
|
|
#define glamor_set_circle_centre(width, height, x, y, \
|
2014-01-12 19:19:10 +01:00
|
|
|
c) \
|
2012-05-15 04:08:03 +02:00
|
|
|
do { \
|
|
|
|
(c)[0] = (float)x; \
|
2014-01-12 19:19:10 +01:00
|
|
|
(c)[1] = (float)y; \
|
2012-03-22 21:05:48 +01:00
|
|
|
} while(0)
|
2011-06-22 08:33:38 +02:00
|
|
|
|
2012-07-16 05:25:09 +02:00
|
|
|
#ifndef ARRAY_SIZE
|
2011-09-08 09:14:43 +02:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
2012-07-16 05:25:09 +02:00
|
|
|
#endif
|
|
|
|
|
2011-09-08 09:14:43 +02:00
|
|
|
#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1))
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
2012-06-10 19:02:30 +02:00
|
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
2011-09-08 09:14:43 +02:00
|
|
|
|
|
|
|
#define glamor_check_fbo_size(_glamor_,_w_, _h_) ((_w_) > 0 && (_h_) > 0 \
|
2012-06-10 19:02:30 +02:00
|
|
|
&& (_w_) <= _glamor_->max_fbo_size \
|
|
|
|
&& (_h_) <= _glamor_->max_fbo_size)
|
2011-09-08 09:14:43 +02:00
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
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;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
/* For 1bpp pixmap, we don't store it as texture. */
|
|
|
|
#define glamor_check_pixmap_fbo_depth(_depth_) ( \
|
|
|
|
_depth_ == 8 \
|
|
|
|
|| _depth_ == 15 \
|
|
|
|
|| _depth_ == 16 \
|
|
|
|
|| _depth_ == 24 \
|
|
|
|
|| _depth_ == 30 \
|
|
|
|
|| _depth_ == 32)
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2015-07-08 02:21:55 +02:00
|
|
|
#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) (pixmap_priv->gl_fbo == GLAMOR_FBO_NORMAL)
|
2011-09-08 09:14:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Borrow from uxa.
|
|
|
|
*/
|
|
|
|
static inline CARD32
|
|
|
|
format_for_depth(int depth)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
switch (depth) {
|
|
|
|
case 1:
|
|
|
|
return PICT_a1;
|
|
|
|
case 4:
|
|
|
|
return PICT_a4;
|
|
|
|
case 8:
|
|
|
|
return PICT_a8;
|
|
|
|
case 15:
|
|
|
|
return PICT_x1r5g5b5;
|
|
|
|
case 16:
|
|
|
|
return PICT_r5g6b5;
|
|
|
|
default:
|
|
|
|
case 24:
|
|
|
|
return PICT_x8r8g8b8;
|
2011-09-08 09:14:43 +02:00
|
|
|
#if XORG_VERSION_CURRENT >= 10699900
|
2013-12-18 20:59:07 +01:00
|
|
|
case 30:
|
|
|
|
return PICT_x2r10g10b10;
|
2011-09-08 09:14:43 +02:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
case 32:
|
|
|
|
return PICT_a8r8g8b8;
|
|
|
|
}
|
2011-09-08 09:14:43 +02:00
|
|
|
}
|
|
|
|
|
2013-12-27 10:23:15 +01:00
|
|
|
static inline GLenum
|
|
|
|
gl_iformat_for_pixmap(PixmapPtr pixmap)
|
2012-01-08 22:01:48 +01:00
|
|
|
{
|
2013-12-27 10:23:15 +01:00
|
|
|
glamor_screen_private *glamor_priv =
|
2014-10-30 06:50:53 +01:00
|
|
|
glamor_get_screen_private((pixmap)->drawable.pScreen);
|
2013-12-27 10:23:15 +01:00
|
|
|
|
|
|
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP &&
|
2014-10-30 06:50:53 +01:00
|
|
|
((pixmap)->drawable.depth == 1 || (pixmap)->drawable.depth == 8)) {
|
2014-09-11 04:02:55 +02:00
|
|
|
return glamor_priv->one_channel_format;
|
2013-12-27 10:23:15 +01:00
|
|
|
} else {
|
|
|
|
return GL_RGBA;
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
2012-01-08 22:01:48 +01:00
|
|
|
}
|
|
|
|
|
2011-09-08 09:14:43 +02:00
|
|
|
static inline CARD32
|
|
|
|
format_for_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
2015-07-02 21:21:41 +02:00
|
|
|
return format_for_depth((pixmap)->drawable.depth);
|
2011-09-08 09:14:43 +02:00
|
|
|
}
|
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
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;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
#define REVERT_NONE 0
|
|
|
|
#define REVERT_NORMAL 1
|
2012-04-05 16:31:44 +02:00
|
|
|
#define REVERT_UPLOADING_A1 3
|
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
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;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
#define SWAP_UPLOADING 2
|
|
|
|
#define SWAP_NONE_UPLOADING 3
|
|
|
|
|
2011-09-08 09:14:43 +02:00
|
|
|
/* borrowed from uxa */
|
|
|
|
static inline Bool
|
|
|
|
glamor_get_rgba_from_pixel(CARD32 pixel,
|
2013-12-18 20:59:07 +01:00
|
|
|
float *red,
|
|
|
|
float *green,
|
|
|
|
float *blue, float *alpha, CARD32 format)
|
2011-09-08 09:14:43 +02:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
int rbits, bbits, gbits, abits;
|
|
|
|
int rshift, bshift, gshift, ashift;
|
|
|
|
|
|
|
|
rbits = PICT_FORMAT_R(format);
|
|
|
|
gbits = PICT_FORMAT_G(format);
|
|
|
|
bbits = PICT_FORMAT_B(format);
|
|
|
|
abits = PICT_FORMAT_A(format);
|
|
|
|
|
|
|
|
if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) {
|
|
|
|
rshift = gshift = bshift = ashift = 0;
|
|
|
|
}
|
|
|
|
else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
|
|
|
|
bshift = 0;
|
|
|
|
gshift = bbits;
|
|
|
|
rshift = gshift + gbits;
|
|
|
|
ashift = rshift + rbits;
|
|
|
|
}
|
|
|
|
else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
|
|
|
|
rshift = 0;
|
|
|
|
gshift = rbits;
|
|
|
|
bshift = gshift + gbits;
|
|
|
|
ashift = bshift + bbits;
|
2011-09-08 09:14:43 +02:00
|
|
|
#if XORG_VERSION_CURRENT >= 10699900
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
|
|
|
|
ashift = 0;
|
|
|
|
rshift = abits;
|
|
|
|
if (abits == 0)
|
|
|
|
rshift = PICT_FORMAT_BPP(format) - (rbits + gbits + bbits);
|
|
|
|
gshift = rshift + rbits;
|
|
|
|
bshift = gshift + gbits;
|
2011-09-08 09:14:43 +02:00
|
|
|
#endif
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-08 09:14:43 +02:00
|
|
|
#define COLOR_INT_TO_FLOAT(_fc_, _p_, _s_, _bits_) \
|
|
|
|
*_fc_ = (((_p_) >> (_s_)) & (( 1 << (_bits_)) - 1)) \
|
2011-11-02 06:44:50 +01:00
|
|
|
/ (float)((1<<(_bits_)) - 1)
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
if (rbits)
|
|
|
|
COLOR_INT_TO_FLOAT(red, pixel, rshift, rbits);
|
|
|
|
else
|
|
|
|
*red = 0;
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
if (gbits)
|
|
|
|
COLOR_INT_TO_FLOAT(green, pixel, gshift, gbits);
|
|
|
|
else
|
|
|
|
*green = 0;
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
if (bbits)
|
|
|
|
COLOR_INT_TO_FLOAT(blue, pixel, bshift, bbits);
|
|
|
|
else
|
|
|
|
*blue = 0;
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
if (abits)
|
|
|
|
COLOR_INT_TO_FLOAT(alpha, pixel, ashift, abits);
|
|
|
|
else
|
|
|
|
*alpha = 1;
|
2011-09-08 09:14:43 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2011-09-08 09:14:43 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
inline static Bool
|
|
|
|
glamor_is_large_pixmap(PixmapPtr pixmap)
|
2012-06-10 19:02:30 +02:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_pixmap_private *priv;
|
2012-06-10 19:02:30 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
priv = glamor_get_pixmap_private(pixmap);
|
2014-10-30 07:20:11 +01:00
|
|
|
return (glamor_pixmap_priv_is_large(priv));
|
2012-06-10 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 21:18:20 +01:00
|
|
|
static inline void
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_screen_private *glamor_priv)
|
2012-02-10 13:54:44 +01:00
|
|
|
{
|
glamor: Store the actual EGL/GLX context pointer in lastGLContext
Fixes subtle breakage which could sometimes trigger after a server reset
with multiple screens using glamor:
Screen A enters glamor_close_screen last and calls various cleanup
functions, which at some point call glamor_make_current to make sure
screen A's GL context is current. This sets lastGLContext to screen A's
&glamor_priv->ctx. Finally, glamor_close_screen calls
glamor_release_screen_priv, which calls free(glamor_priv).
Later, screen B enters glamor_init, which allocates a new glamor_priv.
With bad luck, this can return the same pointer which was previously
used for screen A's glamor_priv. So when screen B's glamor_init calls
glamor_make_current, lastGLContext == &glamor_priv->ctx, so MakeCurrent
isn't called for screen B's GL context, and the following OpenGL API
calls triggered by glamor_init mess up screen A's GL context.
The observed end result of this was a crash in glamor_get_vbo_space
because glamor_priv->vbo didn't match the GL context, though there might
be other possible outcomes.
Assigning the actual GL context pointer to lastGLContext prevents this
by preventing the false negative test in glamor_make_current.
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-05-26 05:30:13 +02:00
|
|
|
if (lastGLContext != glamor_priv->ctx.ctx) {
|
|
|
|
lastGLContext = glamor_priv->ctx.ctx;
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_priv->ctx.make_current(&glamor_priv->ctx);
|
2014-03-15 01:20:12 +01:00
|
|
|
}
|
2012-02-10 13:54:44 +01:00
|
|
|
}
|
|
|
|
|
2015-02-04 23:38:15 +01:00
|
|
|
/**
|
|
|
|
* Helper function for implementing draws with GL_QUADS on GLES2,
|
|
|
|
* where we don't have them.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
glamor_glDrawArrays_GL_QUADS(glamor_screen_private *glamor_priv, unsigned count)
|
|
|
|
{
|
2015-06-20 03:40:47 +02:00
|
|
|
if (glamor_priv->use_quads) {
|
2015-02-04 23:38:15 +01:00
|
|
|
glDrawArrays(GL_QUADS, 0, count * 4);
|
|
|
|
} else {
|
2015-06-20 01:56:35 +02:00
|
|
|
glamor_gldrawarrays_quads_using_indices(glamor_priv, count);
|
2015-02-04 23:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-22 08:33:38 +02:00
|
|
|
#endif
|