mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-14 05:34:56 -04:00
Use GL_ONE for the source in glBendFunc instead of pre-unmultiplying.
Eventually we need to allow both pre-multiplied alpha and not, but for now default to premultiplied.
This commit is contained in:
parent
61017b190a
commit
3f59e82c20
4 changed files with 3 additions and 91 deletions
|
|
@ -68,7 +68,9 @@ repaint(void *data)
|
||||||
glBindTexture(GL_TEXTURE_2D, sd->texture);
|
glBindTexture(GL_TEXTURE_2D, sd->texture);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
/* Assume pre-multiplied alpha for now, this probably
|
||||||
|
* needs to be a wayland visual type of thing. */
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
|
||||||
30
flower.c
30
flower.c
|
|
@ -18,34 +18,6 @@
|
||||||
static const char gem_device[] = "/dev/dri/card0";
|
static const char gem_device[] = "/dev/dri/card0";
|
||||||
static const char socket_name[] = "\0wayland";
|
static const char socket_name[] = "\0wayland";
|
||||||
|
|
||||||
static void
|
|
||||||
unpremultiply_data(uint8_t *data, int width, int height, int stride)
|
|
||||||
{
|
|
||||||
unsigned int i, j;
|
|
||||||
uint8_t *row;
|
|
||||||
|
|
||||||
for (j = 0; j < height; j++) {
|
|
||||||
row = data + j * stride;
|
|
||||||
|
|
||||||
for (i = 0; i < width; i++) {
|
|
||||||
uint8_t *b = &row[i * 4];
|
|
||||||
uint32_t pixel;
|
|
||||||
uint8_t alpha;
|
|
||||||
|
|
||||||
memcpy (&pixel, b, sizeof (uint32_t));
|
|
||||||
alpha = (pixel & 0xff000000) >> 24;
|
|
||||||
if (alpha == 0) {
|
|
||||||
b[0] = b[1] = b[2] = b[3] = 0;
|
|
||||||
} else {
|
|
||||||
b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
|
|
||||||
b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
|
|
||||||
b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
|
|
||||||
b[3] = alpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
{
|
{
|
||||||
struct drm_i915_gem_create create;
|
struct drm_i915_gem_create create;
|
||||||
|
|
@ -59,8 +31,6 @@ static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
stride = cairo_image_surface_get_stride(surface);
|
stride = cairo_image_surface_get_stride(surface);
|
||||||
data = cairo_image_surface_get_data(surface);
|
data = cairo_image_surface_get_data(surface);
|
||||||
|
|
||||||
unpremultiply_data(data, width, height, stride);
|
|
||||||
|
|
||||||
memset(&create, 0, sizeof(create));
|
memset(&create, 0, sizeof(create));
|
||||||
create.size = height * stride;
|
create.size = height * stride;
|
||||||
|
|
||||||
|
|
|
||||||
30
pointer.c
30
pointer.c
|
|
@ -16,34 +16,6 @@
|
||||||
static const char gem_device[] = "/dev/dri/card0";
|
static const char gem_device[] = "/dev/dri/card0";
|
||||||
static const char socket_name[] = "\0wayland";
|
static const char socket_name[] = "\0wayland";
|
||||||
|
|
||||||
static void
|
|
||||||
unpremultiply_data(uint8_t *data, int width, int height, int stride)
|
|
||||||
{
|
|
||||||
unsigned int i, j;
|
|
||||||
uint8_t *row;
|
|
||||||
|
|
||||||
for (j = 0; j < height; j++) {
|
|
||||||
row = data + j * stride;
|
|
||||||
|
|
||||||
for (i = 0; i < width; i++) {
|
|
||||||
uint8_t *b = &row[i * 4];
|
|
||||||
uint32_t pixel;
|
|
||||||
uint8_t alpha;
|
|
||||||
|
|
||||||
memcpy (&pixel, b, sizeof (uint32_t));
|
|
||||||
alpha = (pixel & 0xff000000) >> 24;
|
|
||||||
if (alpha == 0) {
|
|
||||||
b[0] = b[1] = b[2] = b[3] = 0;
|
|
||||||
} else {
|
|
||||||
b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
|
|
||||||
b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
|
|
||||||
b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
|
|
||||||
b[3] = alpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
{
|
{
|
||||||
struct drm_i915_gem_create create;
|
struct drm_i915_gem_create create;
|
||||||
|
|
@ -57,8 +29,6 @@ static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
stride = cairo_image_surface_get_stride(surface);
|
stride = cairo_image_surface_get_stride(surface);
|
||||||
data = cairo_image_surface_get_data(surface);
|
data = cairo_image_surface_get_data(surface);
|
||||||
|
|
||||||
unpremultiply_data(data, width, height, stride);
|
|
||||||
|
|
||||||
memset(&create, 0, sizeof(create));
|
memset(&create, 0, sizeof(create));
|
||||||
create.size = height * stride;
|
create.size = height * stride;
|
||||||
|
|
||||||
|
|
|
||||||
30
window.c
30
window.c
|
|
@ -16,34 +16,6 @@
|
||||||
static const char gem_device[] = "/dev/dri/card0";
|
static const char gem_device[] = "/dev/dri/card0";
|
||||||
static const char socket_name[] = "\0wayland";
|
static const char socket_name[] = "\0wayland";
|
||||||
|
|
||||||
static void
|
|
||||||
unpremultiply_data(uint8_t *data, int width, int height, int stride)
|
|
||||||
{
|
|
||||||
unsigned int i, j;
|
|
||||||
uint8_t *row;
|
|
||||||
|
|
||||||
for (j = 0; j < height; j++) {
|
|
||||||
row = data + j * stride;
|
|
||||||
|
|
||||||
for (i = 0; i < width; i++) {
|
|
||||||
uint8_t *b = &row[i * 4];
|
|
||||||
uint32_t pixel;
|
|
||||||
uint8_t alpha;
|
|
||||||
|
|
||||||
memcpy (&pixel, b, sizeof (uint32_t));
|
|
||||||
alpha = (pixel & 0xff000000) >> 24;
|
|
||||||
if (alpha == 0) {
|
|
||||||
b[0] = b[1] = b[2] = b[3] = 0;
|
|
||||||
} else {
|
|
||||||
b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
|
|
||||||
b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
|
|
||||||
b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
|
|
||||||
b[3] = alpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
{
|
{
|
||||||
struct drm_i915_gem_create create;
|
struct drm_i915_gem_create create;
|
||||||
|
|
@ -57,8 +29,6 @@ static uint32_t name_cairo_surface(int fd, cairo_surface_t *surface)
|
||||||
stride = cairo_image_surface_get_stride(surface);
|
stride = cairo_image_surface_get_stride(surface);
|
||||||
data = cairo_image_surface_get_data(surface);
|
data = cairo_image_surface_get_data(surface);
|
||||||
|
|
||||||
unpremultiply_data(data, width, height, stride);
|
|
||||||
|
|
||||||
memset(&create, 0, sizeof(create));
|
memset(&create, 0, sizeof(create));
|
||||||
create.size = height * stride;
|
create.size = height * stride;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue