2012-09-06 05:54:15 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
|
|
|
* 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 the copyright holders not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS 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.
|
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
2012-09-06 06:06:26 +04:00
|
|
|
|
2012-11-13 22:10:28 +04:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
|
2012-09-06 05:59:35 +04:00
|
|
|
#include <stdlib.h>
|
2012-09-06 06:06:26 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2012-09-11 18:02:05 +04:00
|
|
|
#include <float.h>
|
|
|
|
#include <assert.h>
|
2012-11-08 19:20:46 +04:00
|
|
|
#include <linux/input.h>
|
2012-09-06 05:59:35 +04:00
|
|
|
|
2012-11-13 22:10:28 +04:00
|
|
|
#include "gl-renderer.h"
|
|
|
|
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#include "weston-egl-ext.h"
|
2012-09-06 05:54:15 +04:00
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_shader {
|
2012-11-13 22:10:25 +04:00
|
|
|
GLuint program;
|
|
|
|
GLuint vertex_shader, fragment_shader;
|
|
|
|
GLint proj_uniform;
|
|
|
|
GLint tex_uniforms[3];
|
|
|
|
GLint alpha_uniform;
|
|
|
|
GLint color_uniform;
|
2013-05-17 15:00:40 +04:00
|
|
|
const char *vertex_source, *fragment_source;
|
2012-11-13 22:10:25 +04:00
|
|
|
};
|
|
|
|
|
2013-03-05 19:30:30 +04:00
|
|
|
#define BUFFER_DAMAGE_COUNT 2
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_output_state {
|
2012-11-13 22:10:19 +04:00
|
|
|
EGLSurface egl_surface;
|
2013-03-05 19:30:30 +04:00
|
|
|
pixman_region32_t buffer_damage[BUFFER_DAMAGE_COUNT];
|
2012-11-13 22:10:19 +04:00
|
|
|
};
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_surface_state {
|
2012-11-13 22:10:23 +04:00
|
|
|
GLfloat color[4];
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_shader *shader;
|
2012-11-13 22:10:26 +04:00
|
|
|
|
|
|
|
GLuint textures[3];
|
|
|
|
int num_textures;
|
2012-12-04 17:58:16 +04:00
|
|
|
pixman_region32_t texture_damage;
|
2012-11-13 22:10:26 +04:00
|
|
|
|
|
|
|
EGLImageKHR images[3];
|
|
|
|
GLenum target;
|
|
|
|
int num_images;
|
2012-12-04 17:58:13 +04:00
|
|
|
|
|
|
|
struct weston_buffer_reference buffer_ref;
|
2012-12-04 17:58:15 +04:00
|
|
|
int pitch; /* in pixels */
|
2013-05-22 16:41:37 +04:00
|
|
|
int height; /* in pixels */
|
2012-11-13 22:10:23 +04:00
|
|
|
};
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer {
|
2012-11-08 19:20:46 +04:00
|
|
|
struct weston_renderer base;
|
|
|
|
int fragment_shader_debug;
|
2013-05-07 18:50:09 +04:00
|
|
|
int fan_debug;
|
2012-11-08 19:20:46 +04:00
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
EGLDisplay egl_display;
|
|
|
|
EGLContext egl_context;
|
|
|
|
EGLConfig egl_config;
|
2012-11-13 22:10:20 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int32_t top, bottom, left, right;
|
|
|
|
GLuint texture;
|
|
|
|
int32_t width, height;
|
|
|
|
} border;
|
2012-11-13 22:10:25 +04:00
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
struct wl_array vertices;
|
|
|
|
struct wl_array indices; /* only used in compositor-wayland */
|
|
|
|
struct wl_array vtxcnt;
|
|
|
|
|
2012-11-13 22:10:27 +04:00
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
|
|
|
|
PFNEGLCREATEIMAGEKHRPROC create_image;
|
|
|
|
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
|
|
|
|
|
|
|
|
int has_unpack_subimage;
|
|
|
|
|
|
|
|
PFNEGLBINDWAYLANDDISPLAYWL bind_display;
|
|
|
|
PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
|
|
|
|
PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
|
|
|
|
int has_bind_display;
|
|
|
|
|
|
|
|
int has_egl_image_external;
|
|
|
|
|
2013-03-05 19:30:30 +04:00
|
|
|
int has_egl_buffer_age;
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_shader texture_shader_rgba;
|
|
|
|
struct gl_shader texture_shader_rgbx;
|
|
|
|
struct gl_shader texture_shader_egl_external;
|
|
|
|
struct gl_shader texture_shader_y_uv;
|
|
|
|
struct gl_shader texture_shader_y_u_v;
|
|
|
|
struct gl_shader texture_shader_y_xuxv;
|
|
|
|
struct gl_shader invert_color_shader;
|
|
|
|
struct gl_shader solid_shader;
|
|
|
|
struct gl_shader *current_shader;
|
2012-11-13 22:10:18 +04:00
|
|
|
};
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
static inline struct gl_output_state *
|
2012-11-13 22:10:18 +04:00
|
|
|
get_output_state(struct weston_output *output)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
return (struct gl_output_state *)output->renderer_state;
|
2012-11-13 22:10:18 +04:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
static inline struct gl_surface_state *
|
2012-11-13 22:10:23 +04:00
|
|
|
get_surface_state(struct weston_surface *surface)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
return (struct gl_surface_state *)surface->renderer_state;
|
2012-11-13 22:10:23 +04:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
static inline struct gl_renderer *
|
2012-11-13 22:10:19 +04:00
|
|
|
get_renderer(struct weston_compositor *ec)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
return (struct gl_renderer *)ec->renderer;
|
2012-11-13 22:10:19 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 05:54:15 +04:00
|
|
|
static const char *
|
|
|
|
egl_error_string(EGLint code)
|
|
|
|
{
|
|
|
|
#define MYERRCODE(x) case x: return #x;
|
|
|
|
switch (code) {
|
|
|
|
MYERRCODE(EGL_SUCCESS)
|
|
|
|
MYERRCODE(EGL_NOT_INITIALIZED)
|
|
|
|
MYERRCODE(EGL_BAD_ACCESS)
|
|
|
|
MYERRCODE(EGL_BAD_ALLOC)
|
|
|
|
MYERRCODE(EGL_BAD_ATTRIBUTE)
|
|
|
|
MYERRCODE(EGL_BAD_CONTEXT)
|
|
|
|
MYERRCODE(EGL_BAD_CONFIG)
|
|
|
|
MYERRCODE(EGL_BAD_CURRENT_SURFACE)
|
|
|
|
MYERRCODE(EGL_BAD_DISPLAY)
|
|
|
|
MYERRCODE(EGL_BAD_SURFACE)
|
|
|
|
MYERRCODE(EGL_BAD_MATCH)
|
|
|
|
MYERRCODE(EGL_BAD_PARAMETER)
|
|
|
|
MYERRCODE(EGL_BAD_NATIVE_PIXMAP)
|
|
|
|
MYERRCODE(EGL_BAD_NATIVE_WINDOW)
|
|
|
|
MYERRCODE(EGL_CONTEXT_LOST)
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
#undef MYERRCODE
|
|
|
|
}
|
|
|
|
|
2012-11-27 14:25:25 +04:00
|
|
|
WL_EXPORT void
|
|
|
|
gl_renderer_print_egl_error_state(void)
|
2012-09-06 05:54:15 +04:00
|
|
|
{
|
|
|
|
EGLint code;
|
|
|
|
|
|
|
|
code = eglGetError();
|
|
|
|
weston_log("EGL error state: %s (0x%04lx)\n",
|
|
|
|
egl_error_string(code), (long)code);
|
|
|
|
}
|
|
|
|
|
2012-09-11 18:02:05 +04:00
|
|
|
struct polygon8 {
|
|
|
|
GLfloat x[8];
|
|
|
|
GLfloat y[8];
|
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct clip_context {
|
|
|
|
struct {
|
|
|
|
GLfloat x;
|
|
|
|
GLfloat y;
|
|
|
|
} prev;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GLfloat x1, y1;
|
|
|
|
GLfloat x2, y2;
|
|
|
|
} clip;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
GLfloat *x;
|
|
|
|
GLfloat *y;
|
|
|
|
} vertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GLfloat
|
|
|
|
float_difference(GLfloat a, GLfloat b)
|
|
|
|
{
|
|
|
|
/* http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/ */
|
|
|
|
static const GLfloat max_diff = 4.0f * FLT_MIN;
|
|
|
|
static const GLfloat max_rel_diff = 4.0e-5;
|
|
|
|
GLfloat diff = a - b;
|
|
|
|
GLfloat adiff = fabsf(diff);
|
|
|
|
|
|
|
|
if (adiff <= max_diff)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
a = fabsf(a);
|
|
|
|
b = fabsf(b);
|
|
|
|
if (adiff <= (a > b ? a : b) * max_rel_diff)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A line segment (p1x, p1y)-(p2x, p2y) intersects the line x = x_arg.
|
|
|
|
* Compute the y coordinate of the intersection.
|
|
|
|
*/
|
|
|
|
static GLfloat
|
|
|
|
clip_intersect_y(GLfloat p1x, GLfloat p1y, GLfloat p2x, GLfloat p2y,
|
|
|
|
GLfloat x_arg)
|
|
|
|
{
|
|
|
|
GLfloat a;
|
|
|
|
GLfloat diff = float_difference(p1x, p2x);
|
|
|
|
|
|
|
|
/* Practically vertical line segment, yet the end points have already
|
|
|
|
* been determined to be on different sides of the line. Therefore
|
|
|
|
* the line segment is part of the line and intersects everywhere.
|
|
|
|
* Return the end point, so we use the whole line segment.
|
|
|
|
*/
|
|
|
|
if (diff == 0.0f)
|
|
|
|
return p2y;
|
|
|
|
|
|
|
|
a = (x_arg - p2x) / diff;
|
|
|
|
return p2y + (p1y - p2y) * a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A line segment (p1x, p1y)-(p2x, p2y) intersects the line y = y_arg.
|
|
|
|
* Compute the x coordinate of the intersection.
|
|
|
|
*/
|
|
|
|
static GLfloat
|
|
|
|
clip_intersect_x(GLfloat p1x, GLfloat p1y, GLfloat p2x, GLfloat p2y,
|
|
|
|
GLfloat y_arg)
|
|
|
|
{
|
|
|
|
GLfloat a;
|
|
|
|
GLfloat diff = float_difference(p1y, p2y);
|
|
|
|
|
|
|
|
/* Practically horizontal line segment, yet the end points have already
|
|
|
|
* been determined to be on different sides of the line. Therefore
|
|
|
|
* the line segment is part of the line and intersects everywhere.
|
|
|
|
* Return the end point, so we use the whole line segment.
|
|
|
|
*/
|
|
|
|
if (diff == 0.0f)
|
|
|
|
return p2x;
|
|
|
|
|
|
|
|
a = (y_arg - p2y) / diff;
|
|
|
|
return p2x + (p1x - p2x) * a;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum path_transition {
|
|
|
|
PATH_TRANSITION_OUT_TO_OUT = 0,
|
|
|
|
PATH_TRANSITION_OUT_TO_IN = 1,
|
|
|
|
PATH_TRANSITION_IN_TO_OUT = 2,
|
|
|
|
PATH_TRANSITION_IN_TO_IN = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
clip_append_vertex(struct clip_context *ctx, GLfloat x, GLfloat y)
|
|
|
|
{
|
|
|
|
*ctx->vertices.x++ = x;
|
|
|
|
*ctx->vertices.y++ = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum path_transition
|
|
|
|
path_transition_left_edge(struct clip_context *ctx, GLfloat x, GLfloat y)
|
|
|
|
{
|
|
|
|
return ((ctx->prev.x >= ctx->clip.x1) << 1) | (x >= ctx->clip.x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum path_transition
|
|
|
|
path_transition_right_edge(struct clip_context *ctx, GLfloat x, GLfloat y)
|
|
|
|
{
|
|
|
|
return ((ctx->prev.x < ctx->clip.x2) << 1) | (x < ctx->clip.x2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum path_transition
|
|
|
|
path_transition_top_edge(struct clip_context *ctx, GLfloat x, GLfloat y)
|
|
|
|
{
|
|
|
|
return ((ctx->prev.y >= ctx->clip.y1) << 1) | (y >= ctx->clip.y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum path_transition
|
|
|
|
path_transition_bottom_edge(struct clip_context *ctx, GLfloat x, GLfloat y)
|
|
|
|
{
|
|
|
|
return ((ctx->prev.y < ctx->clip.y2) << 1) | (y < ctx->clip.y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clip_polygon_leftright(struct clip_context *ctx,
|
|
|
|
enum path_transition transition,
|
|
|
|
GLfloat x, GLfloat y, GLfloat clip_x)
|
|
|
|
{
|
|
|
|
GLfloat yi;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case PATH_TRANSITION_IN_TO_IN:
|
|
|
|
clip_append_vertex(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_IN_TO_OUT:
|
|
|
|
yi = clip_intersect_y(ctx->prev.x, ctx->prev.y, x, y, clip_x);
|
|
|
|
clip_append_vertex(ctx, clip_x, yi);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_OUT_TO_IN:
|
|
|
|
yi = clip_intersect_y(ctx->prev.x, ctx->prev.y, x, y, clip_x);
|
|
|
|
clip_append_vertex(ctx, clip_x, yi);
|
|
|
|
clip_append_vertex(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_OUT_TO_OUT:
|
|
|
|
/* nothing */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "bad enum path_transition");
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->prev.x = x;
|
|
|
|
ctx->prev.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clip_polygon_topbottom(struct clip_context *ctx,
|
|
|
|
enum path_transition transition,
|
|
|
|
GLfloat x, GLfloat y, GLfloat clip_y)
|
|
|
|
{
|
|
|
|
GLfloat xi;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case PATH_TRANSITION_IN_TO_IN:
|
|
|
|
clip_append_vertex(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_IN_TO_OUT:
|
|
|
|
xi = clip_intersect_x(ctx->prev.x, ctx->prev.y, x, y, clip_y);
|
|
|
|
clip_append_vertex(ctx, xi, clip_y);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_OUT_TO_IN:
|
|
|
|
xi = clip_intersect_x(ctx->prev.x, ctx->prev.y, x, y, clip_y);
|
|
|
|
clip_append_vertex(ctx, xi, clip_y);
|
|
|
|
clip_append_vertex(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case PATH_TRANSITION_OUT_TO_OUT:
|
|
|
|
/* nothing */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "bad enum path_transition");
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->prev.x = x;
|
|
|
|
ctx->prev.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clip_context_prepare(struct clip_context *ctx, const struct polygon8 *src,
|
|
|
|
GLfloat *dst_x, GLfloat *dst_y)
|
|
|
|
{
|
|
|
|
ctx->prev.x = src->x[src->n - 1];
|
|
|
|
ctx->prev.y = src->y[src->n - 1];
|
|
|
|
ctx->vertices.x = dst_x;
|
|
|
|
ctx->vertices.y = dst_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clip_polygon_left(struct clip_context *ctx, const struct polygon8 *src,
|
|
|
|
GLfloat *dst_x, GLfloat *dst_y)
|
|
|
|
{
|
|
|
|
enum path_transition trans;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clip_context_prepare(ctx, src, dst_x, dst_y);
|
|
|
|
for (i = 0; i < src->n; i++) {
|
|
|
|
trans = path_transition_left_edge(ctx, src->x[i], src->y[i]);
|
|
|
|
clip_polygon_leftright(ctx, trans, src->x[i], src->y[i],
|
|
|
|
ctx->clip.x1);
|
|
|
|
}
|
|
|
|
return ctx->vertices.x - dst_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clip_polygon_right(struct clip_context *ctx, const struct polygon8 *src,
|
|
|
|
GLfloat *dst_x, GLfloat *dst_y)
|
|
|
|
{
|
|
|
|
enum path_transition trans;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clip_context_prepare(ctx, src, dst_x, dst_y);
|
|
|
|
for (i = 0; i < src->n; i++) {
|
|
|
|
trans = path_transition_right_edge(ctx, src->x[i], src->y[i]);
|
|
|
|
clip_polygon_leftright(ctx, trans, src->x[i], src->y[i],
|
|
|
|
ctx->clip.x2);
|
|
|
|
}
|
|
|
|
return ctx->vertices.x - dst_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clip_polygon_top(struct clip_context *ctx, const struct polygon8 *src,
|
|
|
|
GLfloat *dst_x, GLfloat *dst_y)
|
|
|
|
{
|
|
|
|
enum path_transition trans;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clip_context_prepare(ctx, src, dst_x, dst_y);
|
|
|
|
for (i = 0; i < src->n; i++) {
|
|
|
|
trans = path_transition_top_edge(ctx, src->x[i], src->y[i]);
|
|
|
|
clip_polygon_topbottom(ctx, trans, src->x[i], src->y[i],
|
|
|
|
ctx->clip.y1);
|
|
|
|
}
|
|
|
|
return ctx->vertices.x - dst_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src,
|
|
|
|
GLfloat *dst_x, GLfloat *dst_y)
|
|
|
|
{
|
|
|
|
enum path_transition trans;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clip_context_prepare(ctx, src, dst_x, dst_y);
|
|
|
|
for (i = 0; i < src->n; i++) {
|
|
|
|
trans = path_transition_bottom_edge(ctx, src->x[i], src->y[i]);
|
|
|
|
clip_polygon_topbottom(ctx, trans, src->x[i], src->y[i],
|
|
|
|
ctx->clip.y2);
|
|
|
|
}
|
|
|
|
return ctx->vertices.x - dst_x;
|
|
|
|
}
|
|
|
|
|
2012-09-06 05:59:35 +04:00
|
|
|
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#define min(a, b) (((a) > (b)) ? (b) : (a))
|
|
|
|
#define clip(x, a, b) min(max(x, a), b)
|
|
|
|
|
2012-09-11 18:02:05 +04:00
|
|
|
/*
|
|
|
|
* Compute the boundary vertices of the intersection of the global coordinate
|
|
|
|
* aligned rectangle 'rect', and an arbitrary quadrilateral produced from
|
|
|
|
* 'surf_rect' when transformed from surface coordinates into global coordinates.
|
|
|
|
* The vertices are written to 'ex' and 'ey', and the return value is the
|
|
|
|
* number of vertices. Vertices are produced in clockwise winding order.
|
|
|
|
* Guarantees to produce either zero vertices, or 3-8 vertices with non-zero
|
|
|
|
* polygon area.
|
|
|
|
*/
|
2012-09-06 05:59:35 +04:00
|
|
|
static int
|
|
|
|
calculate_edges(struct weston_surface *es, pixman_box32_t *rect,
|
|
|
|
pixman_box32_t *surf_rect, GLfloat *ex, GLfloat *ey)
|
|
|
|
{
|
2012-09-11 18:02:05 +04:00
|
|
|
struct polygon8 polygon;
|
|
|
|
struct clip_context ctx;
|
|
|
|
int i, n;
|
2012-09-06 05:59:35 +04:00
|
|
|
GLfloat min_x, max_x, min_y, max_y;
|
2012-09-11 18:02:05 +04:00
|
|
|
struct polygon8 surf = {
|
|
|
|
{ surf_rect->x1, surf_rect->x2, surf_rect->x2, surf_rect->x1 },
|
|
|
|
{ surf_rect->y1, surf_rect->y1, surf_rect->y2, surf_rect->y2 },
|
|
|
|
4
|
2012-09-06 05:59:35 +04:00
|
|
|
};
|
|
|
|
|
2012-09-11 18:02:05 +04:00
|
|
|
ctx.clip.x1 = rect->x1;
|
|
|
|
ctx.clip.y1 = rect->y1;
|
|
|
|
ctx.clip.x2 = rect->x2;
|
|
|
|
ctx.clip.y2 = rect->y2;
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
/* transform surface to screen space: */
|
2012-09-11 18:02:05 +04:00
|
|
|
for (i = 0; i < surf.n; i++)
|
|
|
|
weston_surface_to_global_float(es, surf.x[i], surf.y[i],
|
|
|
|
&surf.x[i], &surf.y[i]);
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
/* find bounding box: */
|
2012-09-11 18:02:05 +04:00
|
|
|
min_x = max_x = surf.x[0];
|
|
|
|
min_y = max_y = surf.y[0];
|
|
|
|
|
|
|
|
for (i = 1; i < surf.n; i++) {
|
|
|
|
min_x = min(min_x, surf.x[i]);
|
|
|
|
max_x = max(max_x, surf.x[i]);
|
|
|
|
min_y = min(min_y, surf.y[i]);
|
|
|
|
max_y = max(max_y, surf.y[i]);
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* First, simple bounding box check to discard early transformed
|
|
|
|
* surface rects that do not intersect with the clip region:
|
|
|
|
*/
|
2012-09-11 18:02:05 +04:00
|
|
|
if ((min_x >= ctx.clip.x2) || (max_x <= ctx.clip.x1) ||
|
|
|
|
(min_y >= ctx.clip.y2) || (max_y <= ctx.clip.y1))
|
2012-09-06 05:59:35 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Simple case, bounding box edges are parallel to surface edges,
|
|
|
|
* there will be only four edges. We just need to clip the surface
|
|
|
|
* vertices to the clip rect bounds:
|
|
|
|
*/
|
|
|
|
if (!es->transform.enabled) {
|
2012-09-11 18:02:05 +04:00
|
|
|
for (i = 0; i < surf.n; i++) {
|
|
|
|
ex[i] = clip(surf.x[i], ctx.clip.x1, ctx.clip.x2);
|
|
|
|
ey[i] = clip(surf.y[i], ctx.clip.y1, ctx.clip.y2);
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
2012-09-11 18:02:05 +04:00
|
|
|
return surf.n;
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-11 18:02:05 +04:00
|
|
|
/* Transformed case: use a general polygon clipping algorithm to
|
|
|
|
* clip the surface rectangle with each side of 'rect'.
|
|
|
|
* The algorithm is Sutherland-Hodgman, as explained in
|
|
|
|
* http://www.codeguru.com/cpp/misc/misc/graphics/article.php/c8965/Polygon-Clipping.htm
|
|
|
|
* but without looking at any of that code.
|
2012-09-06 05:59:35 +04:00
|
|
|
*/
|
2012-09-11 18:02:05 +04:00
|
|
|
polygon.n = clip_polygon_left(&ctx, &surf, polygon.x, polygon.y);
|
|
|
|
surf.n = clip_polygon_right(&ctx, &polygon, surf.x, surf.y);
|
|
|
|
polygon.n = clip_polygon_top(&ctx, &surf, polygon.x, polygon.y);
|
|
|
|
surf.n = clip_polygon_bottom(&ctx, &polygon, surf.x, surf.y);
|
|
|
|
|
|
|
|
/* Get rid of duplicate vertices */
|
|
|
|
ex[0] = surf.x[0];
|
|
|
|
ey[0] = surf.y[0];
|
|
|
|
n = 1;
|
|
|
|
for (i = 1; i < surf.n; i++) {
|
|
|
|
if (float_difference(ex[n - 1], surf.x[i]) == 0.0f &&
|
|
|
|
float_difference(ey[n - 1], surf.y[i]) == 0.0f)
|
|
|
|
continue;
|
|
|
|
ex[n] = surf.x[i];
|
|
|
|
ey[n] = surf.y[i];
|
|
|
|
n++;
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
2012-09-11 18:02:05 +04:00
|
|
|
if (float_difference(ex[n - 1], surf.x[0]) == 0.0f &&
|
|
|
|
float_difference(ey[n - 1], surf.y[0]) == 0.0f)
|
|
|
|
n--;
|
|
|
|
|
|
|
|
if (n < 3)
|
|
|
|
return 0;
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
texture_region(struct weston_surface *es, pixman_region32_t *region,
|
|
|
|
pixman_region32_t *surf_region)
|
|
|
|
{
|
2012-12-04 17:58:15 +04:00
|
|
|
struct gl_surface_state *gs = get_surface_state(es);
|
2012-09-06 05:59:35 +04:00
|
|
|
struct weston_compositor *ec = es->compositor;
|
2013-05-09 06:38:05 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-09-06 05:59:35 +04:00
|
|
|
GLfloat *v, inv_width, inv_height;
|
|
|
|
unsigned int *vtxcnt, nvtx = 0;
|
|
|
|
pixman_box32_t *rects, *surf_rects;
|
|
|
|
int i, j, k, nrects, nsurf;
|
|
|
|
|
|
|
|
rects = pixman_region32_rectangles(region, &nrects);
|
|
|
|
surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
|
|
|
|
|
|
|
|
/* worst case we can have 8 vertices per rect (ie. clipped into
|
|
|
|
* an octagon):
|
|
|
|
*/
|
2013-05-09 06:38:05 +04:00
|
|
|
v = wl_array_add(&gr->vertices, nrects * nsurf * 8 * 4 * sizeof *v);
|
|
|
|
vtxcnt = wl_array_add(&gr->vtxcnt, nrects * nsurf * sizeof *vtxcnt);
|
2012-09-06 05:59:35 +04:00
|
|
|
|
2012-12-04 17:58:15 +04:00
|
|
|
inv_width = 1.0 / gs->pitch;
|
2013-05-22 16:41:37 +04:00
|
|
|
inv_height = 1.0 / gs->height;
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
for (i = 0; i < nrects; i++) {
|
|
|
|
pixman_box32_t *rect = &rects[i];
|
|
|
|
for (j = 0; j < nsurf; j++) {
|
|
|
|
pixman_box32_t *surf_rect = &surf_rects[j];
|
2012-11-28 19:10:26 +04:00
|
|
|
GLfloat sx, sy, bx, by;
|
2012-09-06 05:59:35 +04:00
|
|
|
GLfloat ex[8], ey[8]; /* edge points in screen space */
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* The transformed surface, after clipping to the clip region,
|
|
|
|
* can have as many as eight sides, emitted as a triangle-fan.
|
|
|
|
* The first vertex in the triangle fan can be chosen arbitrarily,
|
|
|
|
* since the area is guaranteed to be convex.
|
|
|
|
*
|
|
|
|
* If a corner of the transformed surface falls outside of the
|
|
|
|
* clip region, instead of emitting one vertex for the corner
|
|
|
|
* of the surface, up to two are emitted for two corresponding
|
|
|
|
* intersection point(s) between the surface and the clip region.
|
|
|
|
*
|
|
|
|
* To do this, we first calculate the (up to eight) points that
|
|
|
|
* form the intersection of the clip rect and the transformed
|
|
|
|
* surface.
|
|
|
|
*/
|
|
|
|
n = calculate_edges(es, rect, surf_rect, ex, ey);
|
|
|
|
if (n < 3)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* emit edge points: */
|
|
|
|
for (k = 0; k < n; k++) {
|
|
|
|
weston_surface_from_global_float(es, ex[k], ey[k], &sx, &sy);
|
|
|
|
/* position: */
|
|
|
|
*(v++) = ex[k];
|
|
|
|
*(v++) = ey[k];
|
|
|
|
/* texcoord: */
|
2012-11-28 19:10:26 +04:00
|
|
|
weston_surface_to_buffer_float(es, sx, sy,
|
|
|
|
&bx, &by);
|
|
|
|
*(v++) = bx * inv_width;
|
|
|
|
*(v++) = by * inv_height;
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
vtxcnt[nvtx++] = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nvtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
triangle_fan_debug(struct weston_surface *surface, int first, int count)
|
|
|
|
{
|
|
|
|
struct weston_compositor *compositor = surface->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(compositor);
|
2012-09-06 05:59:35 +04:00
|
|
|
int i;
|
|
|
|
GLushort *buffer;
|
|
|
|
GLushort *index;
|
|
|
|
int nelems;
|
|
|
|
static int color_idx = 0;
|
|
|
|
static const GLfloat color[][4] = {
|
|
|
|
{ 1.0, 0.0, 0.0, 1.0 },
|
|
|
|
{ 0.0, 1.0, 0.0, 1.0 },
|
|
|
|
{ 0.0, 0.0, 1.0, 1.0 },
|
|
|
|
{ 1.0, 1.0, 1.0, 1.0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
nelems = (count - 1 + count - 2) * 2;
|
|
|
|
|
|
|
|
buffer = malloc(sizeof(GLushort) * nelems);
|
|
|
|
index = buffer;
|
|
|
|
|
|
|
|
for (i = 1; i < count; i++) {
|
|
|
|
*index++ = first;
|
|
|
|
*index++ = first + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 2; i < count; i++) {
|
|
|
|
*index++ = first + i - 1;
|
|
|
|
*index++ = first + i;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
glUseProgram(gr->solid_shader.program);
|
|
|
|
glUniform4fv(gr->solid_shader.color_uniform, 1,
|
2012-09-06 05:59:35 +04:00
|
|
|
color[color_idx++ % ARRAY_LENGTH(color)]);
|
|
|
|
glDrawElements(GL_LINES, nelems, GL_UNSIGNED_SHORT, buffer);
|
2012-11-13 22:10:25 +04:00
|
|
|
glUseProgram(gr->current_shader->program);
|
2012-09-06 05:59:35 +04:00
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
repaint_region(struct weston_surface *es, pixman_region32_t *region,
|
|
|
|
pixman_region32_t *surf_region)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = es->compositor;
|
2013-05-07 18:50:09 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-09-06 05:59:35 +04:00
|
|
|
GLfloat *v;
|
|
|
|
unsigned int *vtxcnt;
|
|
|
|
int i, first, nfans;
|
|
|
|
|
|
|
|
/* The final region to be painted is the intersection of
|
|
|
|
* 'region' and 'surf_region'. However, 'region' is in the global
|
|
|
|
* coordinates, and 'surf_region' is in the surface-local
|
|
|
|
* coordinates. texture_region() will iterate over all pairs of
|
|
|
|
* rectangles from both regions, compute the intersection
|
|
|
|
* polygon for each pair, and store it as a triangle fan if
|
2013-05-09 06:38:05 +04:00
|
|
|
* it has a non-zero area (at least 3 vertices1, actually).
|
2012-09-06 05:59:35 +04:00
|
|
|
*/
|
|
|
|
nfans = texture_region(es, region, surf_region);
|
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
v = gr->vertices.data;
|
|
|
|
vtxcnt = gr->vtxcnt.data;
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
/* position: */
|
|
|
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
|
|
|
/* texcoord: */
|
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
|
|
|
|
for (i = 0, first = 0; i < nfans; i++) {
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, first, vtxcnt[i]);
|
2013-05-07 18:50:09 +04:00
|
|
|
if (gr->fan_debug)
|
2012-09-06 05:59:35 +04:00
|
|
|
triangle_fan_debug(es, first, vtxcnt[i]);
|
|
|
|
first += vtxcnt[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisableVertexAttribArray(1);
|
|
|
|
glDisableVertexAttribArray(0);
|
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
gr->vertices.size = 0;
|
|
|
|
gr->vtxcnt.size = 0;
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:21 +04:00
|
|
|
static int
|
|
|
|
use_output(struct weston_output *output)
|
|
|
|
{
|
|
|
|
static int errored;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_output_state *go = get_output_state(output);
|
|
|
|
struct gl_renderer *gr = get_renderer(output->compositor);
|
2012-11-13 22:10:21 +04:00
|
|
|
EGLBoolean ret;
|
|
|
|
|
|
|
|
ret = eglMakeCurrent(gr->egl_display, go->egl_surface,
|
|
|
|
go->egl_surface, gr->egl_context);
|
|
|
|
|
|
|
|
if (ret == EGL_FALSE) {
|
|
|
|
if (errored)
|
|
|
|
return -1;
|
|
|
|
errored = 1;
|
|
|
|
weston_log("Failed to make EGL context current.\n");
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-11-13 22:10:21 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-17 15:00:40 +04:00
|
|
|
static int
|
|
|
|
shader_init(struct gl_shader *shader, struct gl_renderer *gr,
|
|
|
|
const char *vertex_source, const char *fragment_source);
|
|
|
|
|
2012-09-06 05:59:35 +04:00
|
|
|
static void
|
2013-05-17 15:00:40 +04:00
|
|
|
use_shader(struct gl_renderer *gr, struct gl_shader *shader)
|
2012-09-06 05:59:35 +04:00
|
|
|
{
|
2013-05-17 15:00:40 +04:00
|
|
|
if (!shader->program) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = shader_init(shader, gr,
|
|
|
|
shader->vertex_source,
|
|
|
|
shader->fragment_source);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
weston_log("warning: failed to compile shader\n");
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
if (gr->current_shader == shader)
|
2012-09-06 05:59:35 +04:00
|
|
|
return;
|
|
|
|
glUseProgram(shader->program);
|
2012-11-13 22:10:25 +04:00
|
|
|
gr->current_shader = shader;
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
shader_uniforms(struct gl_shader *shader,
|
2012-09-06 05:59:35 +04:00
|
|
|
struct weston_surface *surface,
|
|
|
|
struct weston_output *output)
|
|
|
|
{
|
|
|
|
int i;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_surface_state *gs = get_surface_state(surface);
|
2012-09-06 05:59:35 +04:00
|
|
|
|
|
|
|
glUniformMatrix4fv(shader->proj_uniform,
|
|
|
|
1, GL_FALSE, output->matrix.d);
|
2012-11-13 22:10:23 +04:00
|
|
|
glUniform4fv(shader->color_uniform, 1, gs->color);
|
2012-09-06 05:59:35 +04:00
|
|
|
glUniform1f(shader->alpha_uniform, surface->alpha);
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = 0; i < gs->num_textures; i++)
|
2012-09-06 05:59:35 +04:00
|
|
|
glUniform1i(shader->tex_uniforms[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_surface(struct weston_surface *es, struct weston_output *output,
|
|
|
|
pixman_region32_t *damage) /* in global coordinates */
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = es->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
|
|
|
struct gl_surface_state *gs = get_surface_state(es);
|
2012-09-06 05:59:35 +04:00
|
|
|
/* repaint bounding region in global coordinates: */
|
|
|
|
pixman_region32_t repaint;
|
|
|
|
/* non-opaque region in surface coordinates: */
|
|
|
|
pixman_region32_t surface_blend;
|
|
|
|
GLint filter;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pixman_region32_init(&repaint);
|
|
|
|
pixman_region32_intersect(&repaint,
|
|
|
|
&es->transform.boundingbox, damage);
|
|
|
|
pixman_region32_subtract(&repaint, &repaint, &es->clip);
|
|
|
|
|
|
|
|
if (!pixman_region32_not_empty(&repaint))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2013-05-07 18:50:09 +04:00
|
|
|
if (gr->fan_debug) {
|
2012-11-13 22:10:25 +04:00
|
|
|
use_shader(gr, &gr->solid_shader);
|
|
|
|
shader_uniforms(&gr->solid_shader, es, output);
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
use_shader(gr, gs->shader);
|
|
|
|
shader_uniforms(gs->shader, es, output);
|
2012-09-06 05:59:35 +04:00
|
|
|
|
2013-05-22 16:41:37 +04:00
|
|
|
if (es->transform.enabled || output->zoom.active || output->scale != es->buffer_scale)
|
2012-09-06 05:59:35 +04:00
|
|
|
filter = GL_LINEAR;
|
|
|
|
else
|
|
|
|
filter = GL_NEAREST;
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = 0; i < gs->num_textures; i++) {
|
2012-09-06 05:59:35 +04:00
|
|
|
glActiveTexture(GL_TEXTURE0 + i);
|
2012-11-13 22:10:26 +04:00
|
|
|
glBindTexture(gs->target, gs->textures[i]);
|
|
|
|
glTexParameteri(gs->target, GL_TEXTURE_MIN_FILTER, filter);
|
|
|
|
glTexParameteri(gs->target, GL_TEXTURE_MAG_FILTER, filter);
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* blended region is whole surface minus opaque region: */
|
|
|
|
pixman_region32_init_rect(&surface_blend, 0, 0,
|
|
|
|
es->geometry.width, es->geometry.height);
|
|
|
|
pixman_region32_subtract(&surface_blend, &surface_blend, &es->opaque);
|
|
|
|
|
|
|
|
if (pixman_region32_not_empty(&es->opaque)) {
|
2012-11-13 22:10:25 +04:00
|
|
|
if (gs->shader == &gr->texture_shader_rgba) {
|
2012-09-06 05:59:35 +04:00
|
|
|
/* Special case for RGBA textures with possibly
|
|
|
|
* bad data in alpha channel: use the shader
|
|
|
|
* that forces texture alpha = 1.0.
|
|
|
|
* Xwayland surfaces need this.
|
|
|
|
*/
|
2012-11-13 22:10:25 +04:00
|
|
|
use_shader(gr, &gr->texture_shader_rgbx);
|
|
|
|
shader_uniforms(&gr->texture_shader_rgbx, es, output);
|
2012-09-06 05:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (es->alpha < 1.0)
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
else
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
repaint_region(es, &repaint, &es->opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixman_region32_not_empty(&surface_blend)) {
|
2012-11-13 22:10:25 +04:00
|
|
|
use_shader(gr, gs->shader);
|
2012-09-06 05:59:35 +04:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
repaint_region(es, &repaint, &surface_blend);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixman_region32_fini(&surface_blend);
|
|
|
|
|
|
|
|
out:
|
|
|
|
pixman_region32_fini(&repaint);
|
|
|
|
}
|
|
|
|
|
2012-09-06 05:54:15 +04:00
|
|
|
static void
|
|
|
|
repaint_surfaces(struct weston_output *output, pixman_region32_t *damage)
|
|
|
|
{
|
|
|
|
struct weston_compositor *compositor = output->compositor;
|
|
|
|
struct weston_surface *surface;
|
|
|
|
|
|
|
|
wl_list_for_each_reverse(surface, &compositor->surface_list, link)
|
|
|
|
if (surface->plane == &compositor->primary_plane)
|
2012-09-06 05:59:35 +04:00
|
|
|
draw_surface(surface, output, damage);
|
2012-09-06 05:54:15 +04:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:20 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
texture_border(struct weston_output *output)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = output->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-11-13 22:10:20 +04:00
|
|
|
GLfloat *d;
|
|
|
|
unsigned int *p;
|
|
|
|
int i, j, k, n;
|
|
|
|
GLfloat x[4], y[4], u[4], v[4];
|
|
|
|
|
|
|
|
x[0] = -gr->border.left;
|
|
|
|
x[1] = 0;
|
|
|
|
x[2] = output->current->width;
|
|
|
|
x[3] = output->current->width + gr->border.right;
|
|
|
|
|
|
|
|
y[0] = -gr->border.top;
|
|
|
|
y[1] = 0;
|
|
|
|
y[2] = output->current->height;
|
|
|
|
y[3] = output->current->height + gr->border.bottom;
|
|
|
|
|
|
|
|
u[0] = 0.0;
|
|
|
|
u[1] = (GLfloat) gr->border.left / gr->border.width;
|
|
|
|
u[2] = (GLfloat) (gr->border.width - gr->border.right) / gr->border.width;
|
|
|
|
u[3] = 1.0;
|
|
|
|
|
|
|
|
v[0] = 0.0;
|
|
|
|
v[1] = (GLfloat) gr->border.top / gr->border.height;
|
|
|
|
v[2] = (GLfloat) (gr->border.height - gr->border.bottom) / gr->border.height;
|
|
|
|
v[3] = 1.0;
|
|
|
|
|
|
|
|
n = 8;
|
2013-05-09 06:38:05 +04:00
|
|
|
d = wl_array_add(&gr->vertices, n * 16 * sizeof *d);
|
|
|
|
p = wl_array_add(&gr->indices, n * 6 * sizeof *p);
|
2012-11-13 22:10:20 +04:00
|
|
|
|
|
|
|
k = 0;
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
|
|
|
|
if (i == 1 && j == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d[ 0] = x[i];
|
|
|
|
d[ 1] = y[j];
|
|
|
|
d[ 2] = u[i];
|
|
|
|
d[ 3] = v[j];
|
|
|
|
|
|
|
|
d[ 4] = x[i];
|
|
|
|
d[ 5] = y[j + 1];
|
|
|
|
d[ 6] = u[i];
|
|
|
|
d[ 7] = v[j + 1];
|
|
|
|
|
|
|
|
d[ 8] = x[i + 1];
|
|
|
|
d[ 9] = y[j];
|
|
|
|
d[10] = u[i + 1];
|
|
|
|
d[11] = v[j];
|
|
|
|
|
|
|
|
d[12] = x[i + 1];
|
|
|
|
d[13] = y[j + 1];
|
|
|
|
d[14] = u[i + 1];
|
|
|
|
d[15] = v[j + 1];
|
|
|
|
|
|
|
|
p[0] = k + 0;
|
|
|
|
p[1] = k + 1;
|
|
|
|
p[2] = k + 2;
|
|
|
|
p[3] = k + 2;
|
|
|
|
p[4] = k + 1;
|
|
|
|
p[5] = k + 3;
|
|
|
|
|
|
|
|
d += 16;
|
|
|
|
p += 6;
|
|
|
|
k += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return k / 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_border(struct weston_output *output)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = output->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
|
|
|
struct gl_shader *shader = &gr->texture_shader_rgba;
|
2012-11-13 22:10:20 +04:00
|
|
|
GLfloat *v;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
2012-11-13 22:10:25 +04:00
|
|
|
use_shader(gr, shader);
|
2012-11-13 22:10:20 +04:00
|
|
|
|
|
|
|
glUniformMatrix4fv(shader->proj_uniform,
|
|
|
|
1, GL_FALSE, output->matrix.d);
|
|
|
|
|
|
|
|
glUniform1i(shader->tex_uniforms[0], 0);
|
|
|
|
glUniform1f(shader->alpha_uniform, 1);
|
|
|
|
|
|
|
|
n = texture_border(output);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gr->border.texture);
|
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
v = gr->vertices.data;
|
2012-11-13 22:10:20 +04:00
|
|
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]);
|
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, n * 6,
|
2013-05-09 06:38:05 +04:00
|
|
|
GL_UNSIGNED_INT, gr->indices.data);
|
2012-11-13 22:10:20 +04:00
|
|
|
|
|
|
|
glDisableVertexAttribArray(1);
|
|
|
|
glDisableVertexAttribArray(0);
|
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
gr->vertices.size = 0;
|
|
|
|
gr->indices.size = 0;
|
2012-11-13 22:10:20 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:30:30 +04:00
|
|
|
static void
|
|
|
|
output_get_buffer_damage(struct weston_output *output,
|
|
|
|
pixman_region32_t *buffer_damage)
|
|
|
|
{
|
|
|
|
struct gl_output_state *go = get_output_state(output);
|
|
|
|
struct gl_renderer *gr = get_renderer(output->compositor);
|
|
|
|
EGLint buffer_age = 0;
|
|
|
|
EGLBoolean ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (gr->has_egl_buffer_age) {
|
|
|
|
ret = eglQuerySurface(gr->egl_display, go->egl_surface,
|
|
|
|
EGL_BUFFER_AGE_EXT, &buffer_age);
|
|
|
|
if (ret == EGL_FALSE) {
|
|
|
|
weston_log("buffer age query failed.\n");
|
|
|
|
gl_renderer_print_egl_error_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer_age == 0 || buffer_age - 1 > BUFFER_DAMAGE_COUNT)
|
|
|
|
pixman_region32_copy(buffer_damage, &output->region);
|
|
|
|
else
|
|
|
|
for (i = 0; i < buffer_age - 1; i++)
|
|
|
|
pixman_region32_union(buffer_damage, buffer_damage,
|
|
|
|
&go->buffer_damage[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_rotate_damage(struct weston_output *output,
|
|
|
|
pixman_region32_t *output_damage)
|
|
|
|
{
|
|
|
|
struct gl_output_state *go = get_output_state(output);
|
|
|
|
struct gl_renderer *gr = get_renderer(output->compositor);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!gr->has_egl_buffer_age)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = BUFFER_DAMAGE_COUNT - 1; i >= 1; i--)
|
|
|
|
pixman_region32_copy(&go->buffer_damage[i],
|
|
|
|
&go->buffer_damage[i - 1]);
|
|
|
|
|
|
|
|
pixman_region32_copy(&go->buffer_damage[0], output_damage);
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:49:55 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_repaint_output(struct weston_output *output,
|
2012-09-06 05:54:15 +04:00
|
|
|
pixman_region32_t *output_damage)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_output_state *go = get_output_state(output);
|
2012-09-06 05:54:15 +04:00
|
|
|
struct weston_compositor *compositor = output->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(compositor);
|
2012-09-06 05:54:15 +04:00
|
|
|
EGLBoolean ret;
|
|
|
|
static int errored;
|
2013-03-05 19:30:30 +04:00
|
|
|
int32_t width, height;
|
|
|
|
pixman_region32_t buffer_damage, total_damage;
|
2012-09-06 05:54:15 +04:00
|
|
|
|
2013-05-28 18:23:36 +04:00
|
|
|
width = output->current->width +
|
2012-09-06 05:54:15 +04:00
|
|
|
output->border.left + output->border.right;
|
2013-05-28 18:23:36 +04:00
|
|
|
height = output->current->height +
|
2012-09-06 05:54:15 +04:00
|
|
|
output->border.top + output->border.bottom;
|
|
|
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
2012-11-13 22:10:21 +04:00
|
|
|
if (use_output(output) < 0)
|
2012-09-06 05:54:15 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* if debugging, redraw everything outside the damage to clean up
|
|
|
|
* debug lines from the previous draw on this buffer:
|
|
|
|
*/
|
2013-05-07 18:50:09 +04:00
|
|
|
if (gr->fan_debug) {
|
2012-09-06 05:54:15 +04:00
|
|
|
pixman_region32_t undamaged;
|
|
|
|
pixman_region32_init(&undamaged);
|
|
|
|
pixman_region32_subtract(&undamaged, &output->region,
|
|
|
|
output_damage);
|
2013-05-07 18:50:09 +04:00
|
|
|
gr->fan_debug = 0;
|
2012-09-06 05:54:15 +04:00
|
|
|
repaint_surfaces(output, &undamaged);
|
2013-05-07 18:50:09 +04:00
|
|
|
gr->fan_debug = 1;
|
2012-09-06 05:54:15 +04:00
|
|
|
pixman_region32_fini(&undamaged);
|
|
|
|
}
|
|
|
|
|
2013-03-05 19:30:28 +04:00
|
|
|
pixman_region32_init(&total_damage);
|
2013-03-05 19:30:30 +04:00
|
|
|
pixman_region32_init(&buffer_damage);
|
|
|
|
|
|
|
|
output_get_buffer_damage(output, &buffer_damage);
|
|
|
|
output_rotate_damage(output, output_damage);
|
|
|
|
|
|
|
|
pixman_region32_union(&total_damage, &buffer_damage, output_damage);
|
2012-09-14 17:12:03 +04:00
|
|
|
|
2013-03-05 19:30:28 +04:00
|
|
|
repaint_surfaces(output, &total_damage);
|
|
|
|
|
|
|
|
pixman_region32_fini(&total_damage);
|
2013-03-05 19:30:30 +04:00
|
|
|
pixman_region32_fini(&buffer_damage);
|
2012-09-06 05:54:15 +04:00
|
|
|
|
2012-11-13 22:10:20 +04:00
|
|
|
if (gr->border.texture)
|
|
|
|
draw_border(output);
|
|
|
|
|
2012-11-16 19:23:52 +04:00
|
|
|
pixman_region32_copy(&output->previous_damage, output_damage);
|
2012-09-06 05:54:15 +04:00
|
|
|
wl_signal_emit(&output->frame_signal, output);
|
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
ret = eglSwapBuffers(gr->egl_display, go->egl_surface);
|
2012-09-06 05:54:15 +04:00
|
|
|
if (ret == EGL_FALSE && !errored) {
|
|
|
|
errored = 1;
|
|
|
|
weston_log("Failed in eglSwapBuffers.\n");
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-09-06 05:54:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-09-06 06:06:26 +04:00
|
|
|
|
2012-11-13 22:10:21 +04:00
|
|
|
static int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_read_pixels(struct weston_output *output,
|
2012-11-13 22:10:21 +04:00
|
|
|
pixman_format_code_t format, void *pixels,
|
|
|
|
uint32_t x, uint32_t y,
|
|
|
|
uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
GLenum gl_format;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case PIXMAN_a8r8g8b8:
|
|
|
|
gl_format = GL_BGRA_EXT;
|
|
|
|
break;
|
|
|
|
case PIXMAN_a8b8g8r8:
|
|
|
|
gl_format = GL_RGBA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_output(output) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
|
|
glReadPixels(x, y, width, height, gl_format,
|
|
|
|
GL_UNSIGNED_BYTE, pixels);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:49:55 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_flush_damage(struct weston_surface *surface)
|
2012-09-06 06:13:58 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(surface->compositor);
|
|
|
|
struct gl_surface_state *gs = get_surface_state(surface);
|
2012-12-04 17:58:13 +04:00
|
|
|
struct wl_buffer *buffer = gs->buffer_ref.buffer;
|
2012-11-13 22:10:26 +04:00
|
|
|
|
2012-09-06 06:13:58 +04:00
|
|
|
#ifdef GL_UNPACK_ROW_LENGTH
|
|
|
|
pixman_box32_t *rectangles;
|
|
|
|
void *data;
|
|
|
|
int i, n;
|
|
|
|
#endif
|
|
|
|
|
2012-12-04 17:58:16 +04:00
|
|
|
pixman_region32_union(&gs->texture_damage,
|
|
|
|
&gs->texture_damage, &surface->damage);
|
2012-11-07 14:25:13 +04:00
|
|
|
|
2012-12-04 17:58:13 +04:00
|
|
|
if (!buffer)
|
|
|
|
return;
|
|
|
|
|
2012-11-07 14:25:13 +04:00
|
|
|
/* Avoid upload, if the texture won't be used this time.
|
2012-12-04 17:58:13 +04:00
|
|
|
* We still accumulate the damage in texture_damage, and
|
|
|
|
* hold the reference to the buffer, in case the surface
|
|
|
|
* migrates back to the primary plane.
|
2012-11-07 14:25:13 +04:00
|
|
|
*/
|
|
|
|
if (surface->plane != &surface->compositor->primary_plane)
|
|
|
|
return;
|
|
|
|
|
2012-12-04 17:58:16 +04:00
|
|
|
if (!pixman_region32_not_empty(&gs->texture_damage))
|
2012-12-04 17:58:13 +04:00
|
|
|
goto done;
|
2012-11-07 14:25:13 +04:00
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
|
2012-09-06 06:13:58 +04:00
|
|
|
|
2012-11-13 22:10:27 +04:00
|
|
|
if (!gr->has_unpack_subimage) {
|
2012-09-06 06:13:58 +04:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
|
2012-12-04 17:58:15 +04:00
|
|
|
gs->pitch, buffer->height, 0,
|
2012-09-06 06:13:58 +04:00
|
|
|
GL_BGRA_EXT, GL_UNSIGNED_BYTE,
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 17:58:12 +04:00
|
|
|
wl_shm_buffer_get_data(buffer));
|
2012-09-06 06:13:58 +04:00
|
|
|
|
2012-11-07 14:25:13 +04:00
|
|
|
goto done;
|
2012-09-06 06:13:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_UNPACK_ROW_LENGTH
|
|
|
|
/* Mesa does not define GL_EXT_unpack_subimage */
|
2012-12-04 17:58:15 +04:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, gs->pitch);
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 17:58:12 +04:00
|
|
|
data = wl_shm_buffer_get_data(buffer);
|
2012-12-04 17:58:16 +04:00
|
|
|
rectangles = pixman_region32_rectangles(&gs->texture_damage, &n);
|
2012-09-06 06:13:58 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-11-28 19:10:26 +04:00
|
|
|
pixman_box32_t r;
|
|
|
|
|
|
|
|
r = weston_surface_to_buffer_rect(surface, rectangles[i]);
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_SKIP_PIXELS, r.x1);
|
|
|
|
glPixelStorei(GL_UNPACK_SKIP_ROWS, r.y1);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, r.x1, r.y1,
|
|
|
|
r.x2 - r.x1, r.y2 - r.y1,
|
2012-09-06 06:13:58 +04:00
|
|
|
GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-07 14:25:13 +04:00
|
|
|
|
|
|
|
done:
|
2012-12-04 17:58:16 +04:00
|
|
|
pixman_region32_fini(&gs->texture_damage);
|
|
|
|
pixman_region32_init(&gs->texture_damage);
|
2012-12-04 17:58:13 +04:00
|
|
|
|
|
|
|
weston_buffer_reference(&gs->buffer_ref, NULL);
|
2012-09-06 06:13:58 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 06:38:18 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
ensure_textures(struct gl_surface_state *gs, int num_textures)
|
2012-09-06 06:38:18 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
if (num_textures <= gs->num_textures)
|
2012-09-06 06:38:18 +04:00
|
|
|
return;
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = gs->num_textures; i < num_textures; i++) {
|
|
|
|
glGenTextures(1, &gs->textures[i]);
|
|
|
|
glBindTexture(gs->target, gs->textures[i]);
|
|
|
|
glTexParameteri(gs->target,
|
2012-09-06 06:38:18 +04:00
|
|
|
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
2012-11-13 22:10:26 +04:00
|
|
|
glTexParameteri(gs->target,
|
2012-09-06 06:38:18 +04:00
|
|
|
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->num_textures = num_textures;
|
|
|
|
glBindTexture(gs->target, 0);
|
2012-09-06 06:38:18 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 06:49:55 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
|
2012-09-06 06:38:18 +04:00
|
|
|
{
|
|
|
|
struct weston_compositor *ec = es->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
|
|
|
struct gl_surface_state *gs = get_surface_state(es);
|
2012-09-06 06:38:18 +04:00
|
|
|
EGLint attribs[3], format;
|
|
|
|
int i, num_planes;
|
|
|
|
|
2012-12-04 17:58:13 +04:00
|
|
|
weston_buffer_reference(&gs->buffer_ref, buffer);
|
|
|
|
|
2012-09-06 06:38:18 +04:00
|
|
|
if (!buffer) {
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = 0; i < gs->num_images; i++) {
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->destroy_image(gr->egl_display, gs->images[i]);
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->images[i] = NULL;
|
2012-09-06 06:38:18 +04:00
|
|
|
}
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->num_images = 0;
|
|
|
|
glDeleteTextures(gs->num_textures, gs->textures);
|
|
|
|
gs->num_textures = 0;
|
2012-09-06 06:38:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl_buffer_is_shm(buffer)) {
|
2013-06-07 03:41:30 +04:00
|
|
|
/* Only allocate a texture if it doesn't match existing one.
|
|
|
|
* If gs->num_images is not 0, then a switch from DRM allocated
|
|
|
|
* buffer to a SHM buffer is happening, and we need to allocate
|
|
|
|
* a new texture buffer. */
|
|
|
|
if (wl_shm_buffer_get_stride(buffer) / 4 != gs->pitch ||
|
|
|
|
wl_shm_buffer_get_height(buffer) != gs->height ||
|
|
|
|
gs->num_images > 0) {
|
|
|
|
gs->pitch = wl_shm_buffer_get_stride(buffer) / 4;
|
|
|
|
gs->height = wl_shm_buffer_get_height(buffer);
|
|
|
|
gs->target = GL_TEXTURE_2D;
|
|
|
|
|
|
|
|
ensure_textures(gs, 1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
|
|
|
|
gs->pitch, buffer->height, 0,
|
|
|
|
GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
pixman_region32_union_rect(&gs->texture_damage,
|
|
|
|
&gs->texture_damage,
|
|
|
|
0, 0,
|
|
|
|
gs->pitch / es->buffer_scale,
|
|
|
|
gs->height / es->buffer_scale);
|
|
|
|
}
|
2012-09-06 06:38:18 +04:00
|
|
|
|
|
|
|
if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888)
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_rgbx;
|
2012-09-06 06:38:18 +04:00
|
|
|
else
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_rgba;
|
2012-11-13 22:10:27 +04:00
|
|
|
} else if (gr->query_buffer(gr->egl_display, buffer,
|
2012-09-06 06:38:18 +04:00
|
|
|
EGL_TEXTURE_FORMAT, &format)) {
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = 0; i < gs->num_images; i++)
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->destroy_image(gr->egl_display, gs->images[i]);
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->num_images = 0;
|
|
|
|
gs->target = GL_TEXTURE_2D;
|
2012-09-06 06:38:18 +04:00
|
|
|
switch (format) {
|
|
|
|
case EGL_TEXTURE_RGB:
|
|
|
|
case EGL_TEXTURE_RGBA:
|
|
|
|
default:
|
|
|
|
num_planes = 1;
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_rgba;
|
2012-09-06 06:38:18 +04:00
|
|
|
break;
|
|
|
|
case EGL_TEXTURE_EXTERNAL_WL:
|
|
|
|
num_planes = 1;
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->target = GL_TEXTURE_EXTERNAL_OES;
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_egl_external;
|
2012-09-06 06:38:18 +04:00
|
|
|
break;
|
|
|
|
case EGL_TEXTURE_Y_UV_WL:
|
|
|
|
num_planes = 2;
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_y_uv;
|
2012-09-06 06:38:18 +04:00
|
|
|
break;
|
|
|
|
case EGL_TEXTURE_Y_U_V_WL:
|
|
|
|
num_planes = 3;
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_y_u_v;
|
2012-09-06 06:38:18 +04:00
|
|
|
break;
|
|
|
|
case EGL_TEXTURE_Y_XUXV_WL:
|
|
|
|
num_planes = 2;
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->texture_shader_y_xuxv;
|
2012-09-06 06:38:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
ensure_textures(gs, num_planes);
|
2012-09-06 06:38:18 +04:00
|
|
|
for (i = 0; i < num_planes; i++) {
|
|
|
|
attribs[0] = EGL_WAYLAND_PLANE_WL;
|
|
|
|
attribs[1] = i;
|
|
|
|
attribs[2] = EGL_NONE;
|
2012-11-13 22:10:27 +04:00
|
|
|
gs->images[i] = gr->create_image(gr->egl_display,
|
2012-09-06 06:38:18 +04:00
|
|
|
NULL,
|
|
|
|
EGL_WAYLAND_BUFFER_WL,
|
|
|
|
buffer, attribs);
|
2012-11-13 22:10:26 +04:00
|
|
|
if (!gs->images[i]) {
|
2012-09-06 06:38:18 +04:00
|
|
|
weston_log("failed to create img for plane %d\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->num_images++;
|
2012-09-06 06:38:18 +04:00
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0 + i);
|
2012-11-13 22:10:26 +04:00
|
|
|
glBindTexture(gs->target, gs->textures[i]);
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->image_target_texture_2d(gs->target,
|
2012-11-13 22:10:26 +04:00
|
|
|
gs->images[i]);
|
2012-09-06 06:38:18 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 17:58:15 +04:00
|
|
|
gs->pitch = buffer->width;
|
2013-05-22 16:41:37 +04:00
|
|
|
gs->height = buffer->height;
|
2012-09-06 06:38:18 +04:00
|
|
|
} else {
|
|
|
|
weston_log("unhandled buffer type!\n");
|
2012-12-04 17:58:13 +04:00
|
|
|
weston_buffer_reference(&gs->buffer_ref, NULL);
|
2012-09-06 06:38:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:23 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_surface_set_color(struct weston_surface *surface,
|
2012-11-13 22:10:23 +04:00
|
|
|
float red, float green, float blue, float alpha)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_surface_state *gs = get_surface_state(surface);
|
|
|
|
struct gl_renderer *gr = get_renderer(surface->compositor);
|
2012-11-13 22:10:23 +04:00
|
|
|
|
|
|
|
gs->color[0] = red;
|
|
|
|
gs->color[1] = green;
|
|
|
|
gs->color[2] = blue;
|
|
|
|
gs->color[3] = alpha;
|
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
gs->shader = &gr->solid_shader;
|
2012-11-13 22:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_create_surface(struct weston_surface *surface)
|
2012-11-13 22:10:23 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_surface_state *gs;
|
2012-11-13 22:10:23 +04:00
|
|
|
|
|
|
|
gs = calloc(1, sizeof *gs);
|
|
|
|
if (!gs)
|
|
|
|
return -1;
|
|
|
|
|
2012-12-04 17:58:15 +04:00
|
|
|
/* A buffer is never attached to solid color surfaces, yet
|
|
|
|
* they still go through texcoord computations. Do not divide
|
|
|
|
* by zero there.
|
|
|
|
*/
|
|
|
|
gs->pitch = 1;
|
|
|
|
|
2012-12-04 17:58:16 +04:00
|
|
|
pixman_region32_init(&gs->texture_damage);
|
2012-11-13 22:10:23 +04:00
|
|
|
surface->renderer_state = gs;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-07 05:59:29 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_destroy_surface(struct weston_surface *surface)
|
2012-09-07 05:59:29 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_surface_state *gs = get_surface_state(surface);
|
|
|
|
struct gl_renderer *gr = get_renderer(surface->compositor);
|
2012-09-07 05:59:29 +04:00
|
|
|
int i;
|
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
glDeleteTextures(gs->num_textures, gs->textures);
|
2012-09-07 05:59:29 +04:00
|
|
|
|
2012-11-13 22:10:26 +04:00
|
|
|
for (i = 0; i < gs->num_images; i++)
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->destroy_image(gr->egl_display, gs->images[i]);
|
2012-11-13 22:10:23 +04:00
|
|
|
|
2012-12-04 17:58:13 +04:00
|
|
|
weston_buffer_reference(&gs->buffer_ref, NULL);
|
2012-12-04 17:58:16 +04:00
|
|
|
pixman_region32_fini(&gs->texture_damage);
|
2012-11-13 22:10:23 +04:00
|
|
|
free(gs);
|
2012-09-07 05:59:29 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
static const char vertex_shader[] =
|
|
|
|
"uniform mat4 proj;\n"
|
|
|
|
"attribute vec2 position;\n"
|
|
|
|
"attribute vec2 texcoord;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = proj * vec4(position, 0.0, 1.0);\n"
|
|
|
|
" v_texcoord = texcoord;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
/* Declare common fragment shader uniforms */
|
|
|
|
#define FRAGMENT_CONVERT_YUV \
|
|
|
|
" y *= alpha;\n" \
|
|
|
|
" u *= alpha;\n" \
|
|
|
|
" v *= alpha;\n" \
|
|
|
|
" gl_FragColor.r = y + 1.59602678 * v;\n" \
|
|
|
|
" gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n" \
|
|
|
|
" gl_FragColor.b = y + 2.01723214 * u;\n" \
|
|
|
|
" gl_FragColor.a = alpha;\n"
|
|
|
|
|
2012-11-08 19:20:46 +04:00
|
|
|
static const char fragment_debug[] =
|
|
|
|
" gl_FragColor = vec4(0.0, 0.3, 0.0, 0.2) + gl_FragColor * 0.8;\n";
|
|
|
|
|
|
|
|
static const char fragment_brace[] =
|
|
|
|
"}\n";
|
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
static const char texture_fragment_shader_rgba[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;"
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char texture_fragment_shader_rgbx[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb\n;"
|
|
|
|
" gl_FragColor.a = alpha;\n"
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char texture_fragment_shader_egl_external[] =
|
|
|
|
"#extension GL_OES_EGL_image_external : require\n"
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform samplerExternalOES tex;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;"
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char texture_fragment_shader_y_uv[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform sampler2D tex1;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
|
|
|
|
" float u = texture2D(tex1, v_texcoord).r - 0.5;\n"
|
|
|
|
" float v = texture2D(tex1, v_texcoord).g - 0.5;\n"
|
|
|
|
FRAGMENT_CONVERT_YUV
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char texture_fragment_shader_y_u_v[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform sampler2D tex1;\n"
|
|
|
|
"uniform sampler2D tex2;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
|
|
|
|
" float u = texture2D(tex1, v_texcoord).x - 0.5;\n"
|
|
|
|
" float v = texture2D(tex2, v_texcoord).x - 0.5;\n"
|
|
|
|
FRAGMENT_CONVERT_YUV
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char texture_fragment_shader_y_xuxv[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform sampler2D tex1;\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
|
|
|
|
" float u = texture2D(tex1, v_texcoord).g - 0.5;\n"
|
|
|
|
" float v = texture2D(tex1, v_texcoord).a - 0.5;\n"
|
|
|
|
FRAGMENT_CONVERT_YUV
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static const char solid_fragment_shader[] =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"uniform vec4 color;\n"
|
|
|
|
"uniform float alpha;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor = alpha * color\n;"
|
2012-11-08 19:20:46 +04:00
|
|
|
;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
static int
|
2012-11-08 19:20:46 +04:00
|
|
|
compile_shader(GLenum type, int count, const char **sources)
|
2012-09-06 06:06:26 +04:00
|
|
|
{
|
|
|
|
GLuint s;
|
|
|
|
char msg[512];
|
|
|
|
GLint status;
|
|
|
|
|
|
|
|
s = glCreateShader(type);
|
2012-11-08 19:20:46 +04:00
|
|
|
glShaderSource(s, count, sources, NULL);
|
2012-09-06 06:06:26 +04:00
|
|
|
glCompileShader(s);
|
|
|
|
glGetShaderiv(s, GL_COMPILE_STATUS, &status);
|
|
|
|
if (!status) {
|
|
|
|
glGetShaderInfoLog(s, sizeof msg, NULL, msg);
|
|
|
|
weston_log("shader info: %s\n", msg);
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-05-17 15:00:40 +04:00
|
|
|
shader_init(struct gl_shader *shader, struct gl_renderer *renderer,
|
2012-09-06 06:06:26 +04:00
|
|
|
const char *vertex_source, const char *fragment_source)
|
|
|
|
{
|
|
|
|
char msg[512];
|
|
|
|
GLint status;
|
2012-11-08 19:20:46 +04:00
|
|
|
int count;
|
|
|
|
const char *sources[3];
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
shader->vertex_shader =
|
2012-11-08 19:20:46 +04:00
|
|
|
compile_shader(GL_VERTEX_SHADER, 1, &vertex_source);
|
|
|
|
|
|
|
|
if (renderer->fragment_shader_debug) {
|
|
|
|
sources[0] = fragment_source;
|
|
|
|
sources[1] = fragment_debug;
|
|
|
|
sources[2] = fragment_brace;
|
|
|
|
count = 3;
|
|
|
|
} else {
|
|
|
|
sources[0] = fragment_source;
|
|
|
|
sources[1] = fragment_brace;
|
|
|
|
count = 2;
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
shader->fragment_shader =
|
2012-11-08 19:20:46 +04:00
|
|
|
compile_shader(GL_FRAGMENT_SHADER, count, sources);
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
shader->program = glCreateProgram();
|
|
|
|
glAttachShader(shader->program, shader->vertex_shader);
|
|
|
|
glAttachShader(shader->program, shader->fragment_shader);
|
|
|
|
glBindAttribLocation(shader->program, 0, "position");
|
|
|
|
glBindAttribLocation(shader->program, 1, "texcoord");
|
|
|
|
|
|
|
|
glLinkProgram(shader->program);
|
|
|
|
glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
|
|
|
|
if (!status) {
|
|
|
|
glGetProgramInfoLog(shader->program, sizeof msg, NULL, msg);
|
|
|
|
weston_log("link info: %s\n", msg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
shader->proj_uniform = glGetUniformLocation(shader->program, "proj");
|
|
|
|
shader->tex_uniforms[0] = glGetUniformLocation(shader->program, "tex");
|
|
|
|
shader->tex_uniforms[1] = glGetUniformLocation(shader->program, "tex1");
|
|
|
|
shader->tex_uniforms[2] = glGetUniformLocation(shader->program, "tex2");
|
|
|
|
shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha");
|
|
|
|
shader->color_uniform = glGetUniformLocation(shader->program, "color");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:20:46 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
shader_release(struct gl_shader *shader)
|
2012-11-08 19:20:46 +04:00
|
|
|
{
|
|
|
|
glDeleteShader(shader->vertex_shader);
|
|
|
|
glDeleteShader(shader->fragment_shader);
|
|
|
|
glDeleteProgram(shader->program);
|
|
|
|
|
|
|
|
shader->vertex_shader = 0;
|
|
|
|
shader->fragment_shader = 0;
|
|
|
|
shader->program = 0;
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
static void
|
|
|
|
log_extensions(const char *name, const char *extensions)
|
|
|
|
{
|
|
|
|
const char *p, *end;
|
|
|
|
int l;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
l = weston_log("%s:", name);
|
|
|
|
p = extensions;
|
|
|
|
while (*p) {
|
|
|
|
end = strchrnul(p, ' ');
|
|
|
|
len = end - p;
|
|
|
|
if (l + len > 78)
|
|
|
|
l = weston_log_continue("\n" STAMP_SPACE "%.*s",
|
|
|
|
len, p);
|
|
|
|
else
|
|
|
|
l += weston_log_continue(" %.*s", len, p);
|
|
|
|
for (p = end; isspace(*p); p++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
weston_log_continue("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
log_egl_gl_info(EGLDisplay egldpy)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
str = eglQueryString(egldpy, EGL_VERSION);
|
|
|
|
weston_log("EGL version: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = eglQueryString(egldpy, EGL_VENDOR);
|
|
|
|
weston_log("EGL vendor: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = eglQueryString(egldpy, EGL_CLIENT_APIS);
|
|
|
|
weston_log("EGL client APIs: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = eglQueryString(egldpy, EGL_EXTENSIONS);
|
|
|
|
log_extensions("EGL extensions", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = (char *)glGetString(GL_VERSION);
|
|
|
|
weston_log("GL version: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
|
|
|
weston_log("GLSL version: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = (char *)glGetString(GL_VENDOR);
|
|
|
|
weston_log("GL vendor: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = (char *)glGetString(GL_RENDERER);
|
|
|
|
weston_log("GL renderer: %s\n", str ? str : "(null)");
|
|
|
|
|
|
|
|
str = (char *)glGetString(GL_EXTENSIONS);
|
|
|
|
log_extensions("GL extensions", str ? str : "(null)");
|
|
|
|
}
|
|
|
|
|
2012-10-24 10:43:05 +04:00
|
|
|
static void
|
|
|
|
log_egl_config_info(EGLDisplay egldpy, EGLConfig eglconfig)
|
|
|
|
{
|
|
|
|
EGLint r, g, b, a;
|
|
|
|
|
|
|
|
weston_log("Chosen EGL config details:\n");
|
|
|
|
|
|
|
|
weston_log_continue(STAMP_SPACE "RGBA bits");
|
|
|
|
if (eglGetConfigAttrib(egldpy, eglconfig, EGL_RED_SIZE, &r) &&
|
|
|
|
eglGetConfigAttrib(egldpy, eglconfig, EGL_GREEN_SIZE, &g) &&
|
|
|
|
eglGetConfigAttrib(egldpy, eglconfig, EGL_BLUE_SIZE, &b) &&
|
|
|
|
eglGetConfigAttrib(egldpy, eglconfig, EGL_ALPHA_SIZE, &a))
|
|
|
|
weston_log_continue(": %d %d %d %d\n", r, g, b, a);
|
|
|
|
else
|
|
|
|
weston_log_continue(" unknown\n");
|
|
|
|
|
|
|
|
weston_log_continue(STAMP_SPACE "swap interval range");
|
|
|
|
if (eglGetConfigAttrib(egldpy, eglconfig, EGL_MIN_SWAP_INTERVAL, &a) &&
|
|
|
|
eglGetConfigAttrib(egldpy, eglconfig, EGL_MAX_SWAP_INTERVAL, &b))
|
|
|
|
weston_log_continue(": %d - %d\n", a, b);
|
|
|
|
else
|
|
|
|
weston_log_continue(" unknown\n");
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:20 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
output_apply_border(struct weston_output *output, struct gl_renderer *gr)
|
2012-11-13 22:10:20 +04:00
|
|
|
{
|
|
|
|
output->border.top = gr->border.top;
|
|
|
|
output->border.bottom = gr->border.bottom;
|
|
|
|
output->border.left = gr->border.left;
|
|
|
|
output->border.right = gr->border.right;
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_set_border(struct weston_compositor *ec, int32_t width, int32_t height, void *data,
|
2012-11-13 22:10:20 +04:00
|
|
|
int32_t *edges)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-11-13 22:10:20 +04:00
|
|
|
struct weston_output *output;
|
|
|
|
|
|
|
|
gr->border.left = edges[0];
|
|
|
|
gr->border.right = edges[1];
|
|
|
|
gr->border.top = edges[2];
|
|
|
|
gr->border.bottom = edges[3];
|
|
|
|
|
|
|
|
gr->border.width = width;
|
|
|
|
gr->border.height = height;
|
|
|
|
|
|
|
|
glGenTextures(1, &gr->border.texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gr->border.texture);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,
|
|
|
|
data);
|
|
|
|
|
|
|
|
wl_list_for_each(output, &ec->output_list, link)
|
|
|
|
output_apply_border(output, gr);
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:18 +04:00
|
|
|
static int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface);
|
2012-11-13 22:10:18 +04:00
|
|
|
|
|
|
|
WL_EXPORT int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_output_create(struct weston_output *output,
|
2012-11-13 22:10:18 +04:00
|
|
|
EGLNativeWindowType window)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = output->compositor;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
|
|
|
struct gl_output_state *go = calloc(1, sizeof *go);
|
2012-11-16 19:23:52 +04:00
|
|
|
int i;
|
2012-11-13 22:10:18 +04:00
|
|
|
|
|
|
|
if (!go)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
go->egl_surface =
|
2012-11-13 22:10:19 +04:00
|
|
|
eglCreateWindowSurface(gr->egl_display,
|
|
|
|
gr->egl_config,
|
2012-11-13 22:10:18 +04:00
|
|
|
window, NULL);
|
|
|
|
|
|
|
|
if (go->egl_surface == EGL_NO_SURFACE) {
|
|
|
|
weston_log("failed to create egl surface\n");
|
|
|
|
free(go);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
if (gr->egl_context == NULL)
|
2012-11-13 22:10:29 +04:00
|
|
|
if (gl_renderer_setup(ec, go->egl_surface) < 0) {
|
2012-11-13 22:10:18 +04:00
|
|
|
free(go);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-05 19:30:30 +04:00
|
|
|
for (i = 0; i < BUFFER_DAMAGE_COUNT; i++)
|
2012-11-16 19:23:52 +04:00
|
|
|
pixman_region32_init(&go->buffer_damage[i]);
|
|
|
|
|
2012-11-13 22:10:18 +04:00
|
|
|
output->renderer_state = go;
|
|
|
|
|
2012-11-13 22:10:20 +04:00
|
|
|
output_apply_border(output, gr);
|
|
|
|
|
2012-11-13 22:10:18 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_output_destroy(struct weston_output *output)
|
2012-11-13 22:10:18 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(output->compositor);
|
|
|
|
struct gl_output_state *go = get_output_state(output);
|
2012-11-16 19:23:52 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
pixman_region32_fini(&go->buffer_damage[i]);
|
2012-11-13 22:10:18 +04:00
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
eglDestroySurface(gr->egl_display, go->egl_surface);
|
2012-11-13 22:10:18 +04:00
|
|
|
|
|
|
|
free(go);
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT EGLSurface
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_output_surface(struct weston_output *output)
|
2012-11-13 22:10:18 +04:00
|
|
|
{
|
|
|
|
return get_output_state(output)->egl_surface;
|
|
|
|
}
|
|
|
|
|
2013-01-08 20:09:01 +04:00
|
|
|
static void
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_destroy(struct weston_compositor *ec)
|
2012-09-07 05:44:24 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-11-13 22:10:19 +04:00
|
|
|
|
2012-11-13 22:10:27 +04:00
|
|
|
if (gr->has_bind_display)
|
|
|
|
gr->unbind_display(gr->egl_display, ec->wl_display);
|
2012-11-13 22:10:19 +04:00
|
|
|
|
|
|
|
/* Work around crash in egl_dri2.c's dri2_make_current() - when does this apply? */
|
|
|
|
eglMakeCurrent(gr->egl_display,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
eglTerminate(gr->egl_display);
|
|
|
|
eglReleaseThread();
|
2013-03-07 21:15:17 +04:00
|
|
|
|
2013-05-09 06:38:05 +04:00
|
|
|
wl_array_release(&gr->vertices);
|
|
|
|
wl_array_release(&gr->indices);
|
|
|
|
wl_array_release(&gr->vtxcnt);
|
|
|
|
|
2013-03-07 21:15:17 +04:00
|
|
|
free(gr);
|
2012-11-13 22:10:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-11-13 22:10:29 +04:00
|
|
|
egl_choose_config(struct gl_renderer *gr, const EGLint *attribs,
|
2012-11-13 22:10:19 +04:00
|
|
|
const EGLint *visual_id)
|
|
|
|
{
|
|
|
|
EGLint count = 0;
|
|
|
|
EGLint matched = 0;
|
|
|
|
EGLConfig *configs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!eglGetConfigs(gr->egl_display, NULL, 0, &count) || count < 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
configs = calloc(count, sizeof *configs);
|
|
|
|
if (!configs)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!eglChooseConfig(gr->egl_display, attribs, configs,
|
|
|
|
count, &matched))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 0; i < matched; ++i) {
|
|
|
|
EGLint id;
|
|
|
|
|
|
|
|
if (visual_id) {
|
|
|
|
if (!eglGetConfigAttrib(gr->egl_display,
|
|
|
|
configs[i], EGL_NATIVE_VISUAL_ID,
|
|
|
|
&id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (id != *visual_id)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gr->egl_config = configs[i];
|
|
|
|
|
|
|
|
free(configs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(configs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
WL_EXPORT const EGLint gl_renderer_opaque_attribs[] = {
|
2012-11-13 22:10:19 +04:00
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
WL_EXPORT const EGLint gl_renderer_alpha_attribs[] = {
|
2012-11-13 22:10:19 +04:00
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 1,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
WL_EXPORT int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_create(struct weston_compositor *ec, EGLNativeDisplayType display,
|
2012-11-13 22:10:19 +04:00
|
|
|
const EGLint *attribs, const EGLint *visual_id)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr;
|
2012-11-13 22:10:19 +04:00
|
|
|
EGLint major, minor;
|
|
|
|
|
|
|
|
gr = calloc(1, sizeof *gr);
|
|
|
|
|
|
|
|
if (gr == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-11-13 22:10:29 +04:00
|
|
|
gr->base.read_pixels = gl_renderer_read_pixels;
|
|
|
|
gr->base.repaint_output = gl_renderer_repaint_output;
|
|
|
|
gr->base.flush_damage = gl_renderer_flush_damage;
|
|
|
|
gr->base.attach = gl_renderer_attach;
|
|
|
|
gr->base.create_surface = gl_renderer_create_surface;
|
|
|
|
gr->base.surface_set_color = gl_renderer_surface_set_color;
|
|
|
|
gr->base.destroy_surface = gl_renderer_destroy_surface;
|
2013-01-08 20:09:01 +04:00
|
|
|
gr->base.destroy = gl_renderer_destroy;
|
2012-11-13 22:10:19 +04:00
|
|
|
|
|
|
|
gr->egl_display = eglGetDisplay(display);
|
|
|
|
if (gr->egl_display == EGL_NO_DISPLAY) {
|
|
|
|
weston_log("failed to create display\n");
|
|
|
|
goto err_egl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglInitialize(gr->egl_display, &major, &minor)) {
|
|
|
|
weston_log("failed to initialize display\n");
|
|
|
|
goto err_egl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (egl_choose_config(gr, attribs, visual_id) < 0) {
|
|
|
|
weston_log("failed to choose EGL config\n");
|
|
|
|
goto err_egl;
|
|
|
|
}
|
|
|
|
|
|
|
|
ec->renderer = &gr->base;
|
2013-05-22 19:03:04 +04:00
|
|
|
ec->capabilities |= WESTON_CAP_ROTATION_ANY;
|
2013-05-22 19:03:05 +04:00
|
|
|
ec->capabilities |= WESTON_CAP_CAPTURE_YFLIP;
|
2012-11-13 22:10:19 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_egl:
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-11-13 22:10:19 +04:00
|
|
|
free(gr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT EGLDisplay
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_display(struct weston_compositor *ec)
|
2012-11-13 22:10:19 +04:00
|
|
|
{
|
|
|
|
return get_renderer(ec)->egl_display;
|
2012-09-07 05:44:24 +04:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:20:46 +04:00
|
|
|
static int
|
|
|
|
compile_shaders(struct weston_compositor *ec)
|
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-11-13 22:10:25 +04:00
|
|
|
|
2013-05-17 15:00:40 +04:00
|
|
|
gr->texture_shader_rgba.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_rgba.fragment_source = texture_fragment_shader_rgba;
|
|
|
|
|
|
|
|
gr->texture_shader_rgbx.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_rgbx.fragment_source = texture_fragment_shader_rgbx;
|
|
|
|
|
|
|
|
gr->texture_shader_egl_external.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_egl_external.fragment_source =
|
|
|
|
texture_fragment_shader_egl_external;
|
|
|
|
|
|
|
|
gr->texture_shader_y_uv.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_y_uv.fragment_source = texture_fragment_shader_y_uv;
|
|
|
|
|
|
|
|
gr->texture_shader_y_u_v.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_y_u_v.fragment_source =
|
|
|
|
texture_fragment_shader_y_u_v;
|
|
|
|
|
|
|
|
gr->texture_shader_y_u_v.vertex_source = vertex_shader;
|
|
|
|
gr->texture_shader_y_xuxv.fragment_source =
|
|
|
|
texture_fragment_shader_y_xuxv;
|
|
|
|
|
|
|
|
gr->solid_shader.vertex_source = vertex_shader;
|
|
|
|
gr->solid_shader.fragment_source = solid_fragment_shader;
|
2012-11-08 19:20:46 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-07 07:19:49 +04:00
|
|
|
fragment_debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
|
2012-11-08 19:20:46 +04:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = data;
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-11-08 19:20:46 +04:00
|
|
|
struct weston_output *output;
|
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
gr->fragment_shader_debug ^= 1;
|
2012-11-08 19:20:46 +04:00
|
|
|
|
2012-11-13 22:10:25 +04:00
|
|
|
shader_release(&gr->texture_shader_rgba);
|
|
|
|
shader_release(&gr->texture_shader_rgbx);
|
|
|
|
shader_release(&gr->texture_shader_egl_external);
|
|
|
|
shader_release(&gr->texture_shader_y_uv);
|
|
|
|
shader_release(&gr->texture_shader_y_u_v);
|
|
|
|
shader_release(&gr->texture_shader_y_xuxv);
|
|
|
|
shader_release(&gr->solid_shader);
|
2012-11-08 19:20:46 +04:00
|
|
|
|
2012-12-03 19:08:11 +04:00
|
|
|
/* Force use_shader() to call glUseProgram(), since we need to use
|
|
|
|
* the recompiled version of the shader. */
|
|
|
|
gr->current_shader = NULL;
|
|
|
|
|
2012-11-08 19:20:46 +04:00
|
|
|
wl_list_for_each(output, &ec->output_list, link)
|
|
|
|
weston_output_damage(output);
|
|
|
|
}
|
|
|
|
|
2013-05-07 18:50:09 +04:00
|
|
|
static void
|
|
|
|
fan_debug_repaint_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct weston_compositor *compositor = data;
|
|
|
|
struct gl_renderer *gr = get_renderer(compositor);
|
|
|
|
|
|
|
|
gr->fan_debug = !gr->fan_debug;
|
|
|
|
weston_compositor_damage_all(compositor);
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:18 +04:00
|
|
|
static int
|
2012-11-13 22:10:29 +04:00
|
|
|
gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
|
2012-09-06 06:06:26 +04:00
|
|
|
{
|
2012-11-13 22:10:29 +04:00
|
|
|
struct gl_renderer *gr = get_renderer(ec);
|
2012-09-06 06:06:26 +04:00
|
|
|
const char *extensions;
|
2012-09-07 04:51:00 +04:00
|
|
|
EGLBoolean ret;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
2012-09-07 05:07:40 +04:00
|
|
|
static const EGLint context_attribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
|
|
|
|
weston_log("failed to bind EGL_OPENGL_ES_API\n");
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-09-07 05:07:40 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-24 10:43:05 +04:00
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
log_egl_config_info(gr->egl_display, gr->egl_config);
|
2012-10-24 10:43:05 +04:00
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
gr->egl_context = eglCreateContext(gr->egl_display, gr->egl_config,
|
2012-09-07 05:07:40 +04:00
|
|
|
EGL_NO_CONTEXT, context_attribs);
|
2012-11-13 22:10:19 +04:00
|
|
|
if (gr->egl_context == NULL) {
|
2012-09-07 05:07:40 +04:00
|
|
|
weston_log("failed to create context\n");
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-09-07 05:07:40 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
ret = eglMakeCurrent(gr->egl_display, egl_surface,
|
|
|
|
egl_surface, gr->egl_context);
|
2012-09-07 04:51:00 +04:00
|
|
|
if (ret == EGL_FALSE) {
|
|
|
|
weston_log("Failed to make EGL context current.\n");
|
2012-11-27 14:25:25 +04:00
|
|
|
gl_renderer_print_egl_error_state();
|
2012-09-07 04:51:00 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
log_egl_gl_info(gr->egl_display);
|
2012-09-06 06:06:26 +04:00
|
|
|
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->image_target_texture_2d =
|
2012-09-06 06:06:26 +04:00
|
|
|
(void *) eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
|
|
|
|
gr->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
|
|
|
|
gr->bind_display =
|
2012-09-06 06:06:26 +04:00
|
|
|
(void *) eglGetProcAddress("eglBindWaylandDisplayWL");
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->unbind_display =
|
2012-09-06 06:06:26 +04:00
|
|
|
(void *) eglGetProcAddress("eglUnbindWaylandDisplayWL");
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->query_buffer =
|
2012-09-06 06:06:26 +04:00
|
|
|
(void *) eglGetProcAddress("eglQueryWaylandBufferWL");
|
|
|
|
|
|
|
|
extensions = (const char *) glGetString(GL_EXTENSIONS);
|
|
|
|
if (!extensions) {
|
|
|
|
weston_log("Retrieving GL extension string failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
|
|
|
|
weston_log("GL_EXT_texture_format_BGRA8888 not available\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(extensions, "GL_EXT_read_format_bgra"))
|
2012-11-13 22:10:22 +04:00
|
|
|
ec->read_format = PIXMAN_a8r8g8b8;
|
2012-09-06 06:06:26 +04:00
|
|
|
else
|
2012-11-13 22:10:22 +04:00
|
|
|
ec->read_format = PIXMAN_a8b8g8r8;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
if (strstr(extensions, "GL_EXT_unpack_subimage"))
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_unpack_subimage = 1;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
if (strstr(extensions, "GL_OES_EGL_image_external"))
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_egl_image_external = 1;
|
2012-09-06 06:06:26 +04:00
|
|
|
|
|
|
|
extensions =
|
2012-11-13 22:10:19 +04:00
|
|
|
(const char *) eglQueryString(gr->egl_display, EGL_EXTENSIONS);
|
2012-09-06 06:06:26 +04:00
|
|
|
if (!extensions) {
|
|
|
|
weston_log("Retrieving EGL extension string failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(extensions, "EGL_WL_bind_wayland_display"))
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_bind_display = 1;
|
|
|
|
if (gr->has_bind_display) {
|
|
|
|
ret = gr->bind_display(gr->egl_display, ec->wl_display);
|
2012-10-24 10:43:06 +04:00
|
|
|
if (!ret)
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_bind_display = 0;
|
2012-10-24 10:43:06 +04:00
|
|
|
}
|
2012-09-06 06:06:26 +04:00
|
|
|
|
2013-03-05 19:30:30 +04:00
|
|
|
if (strstr(extensions, "EGL_EXT_buffer_age"))
|
|
|
|
gr->has_egl_buffer_age = 1;
|
|
|
|
else
|
|
|
|
weston_log("warning: EGL_EXT_buffer_age not supported. "
|
|
|
|
"Performance could be affected.\n");
|
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2012-11-08 19:20:46 +04:00
|
|
|
if (compile_shaders(ec))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
weston_compositor_add_debug_binding(ec, KEY_S,
|
|
|
|
fragment_debug_binding, ec);
|
2013-05-07 18:50:09 +04:00
|
|
|
weston_compositor_add_debug_binding(ec, KEY_F,
|
|
|
|
fan_debug_repaint_binding, ec);
|
2012-11-08 19:20:46 +04:00
|
|
|
|
2012-10-24 10:43:06 +04:00
|
|
|
weston_log("GL ES 2 renderer features:\n");
|
|
|
|
weston_log_continue(STAMP_SPACE "read-back format: %s\n",
|
2013-01-10 18:50:42 +04:00
|
|
|
ec->read_format == PIXMAN_a8r8g8b8 ? "BGRA" : "RGBA");
|
2012-10-24 10:43:06 +04:00
|
|
|
weston_log_continue(STAMP_SPACE "wl_shm sub-image to texture: %s\n",
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_unpack_subimage ? "yes" : "no");
|
2012-10-24 10:43:06 +04:00
|
|
|
weston_log_continue(STAMP_SPACE "EGL Wayland extension: %s\n",
|
2012-11-13 22:10:27 +04:00
|
|
|
gr->has_bind_display ? "yes" : "no");
|
2012-10-24 10:43:06 +04:00
|
|
|
|
2012-11-13 22:10:19 +04:00
|
|
|
|
2012-09-06 06:06:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|