1 /*
2 * Copyright © 2014 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23 #ifndef _GLAMOR_PROGRAM_H_
24 #define _GLAMOR_PROGRAM_H_
25
26 typedef enum {
27 glamor_program_location_none = 0,
28 glamor_program_location_fg = 1,
29 glamor_program_location_bg = 2,
30 glamor_program_location_fillsamp = 4,
31 glamor_program_location_fillpos = 8,
32 glamor_program_location_font = 16,
33 glamor_program_location_bitplane = 32,
34 glamor_program_location_dash = 64,
35 glamor_program_location_atlas = 128,
36 } glamor_program_location;
37
38 typedef enum {
39 glamor_program_flag_none = 0,
40 } glamor_program_flag;
41
42 typedef enum {
43 glamor_program_alpha_normal,
44 glamor_program_alpha_ca_first,
45 glamor_program_alpha_ca_second,
46 glamor_program_alpha_dual_blend,
47 glamor_program_alpha_count
48 } glamor_program_alpha;
49
50 typedef struct _glamor_program glamor_program;
51
52 typedef Bool (*glamor_use) (PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg);
53
54 typedef Bool (*glamor_use_render) (CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog);
55
56 typedef struct {
57 const char *name;
58 const int version;
59 const char *fs_extensions;
60 char *vs_defines;
61 char *fs_defines;
62 const char *vs_vars;
63 const char *vs_exec;
64 const char *fs_vars;
65 const char *fs_exec;
66 const glamor_program_location locations;
67 const glamor_program_flag flags;
68 const char *source_name;
69 glamor_use use;
70 glamor_use_render use_render;
71 } glamor_facet;
72
73 struct _glamor_program {
74 GLint prog;
75 GLint failed;
76 GLint matrix_uniform;
77 GLint fg_uniform;
78 GLint bg_uniform;
79 GLint fill_size_inv_uniform;
80 GLint fill_offset_uniform;
81 GLint font_uniform;
82 GLint bitplane_uniform;
83 GLint bitmul_uniform;
84 GLint dash_uniform;
85 GLint dash_length_uniform;
86 GLint atlas_uniform;
87 glamor_program_location locations;
88 glamor_program_flag flags;
89 glamor_use prim_use;
90 glamor_use fill_use;
91 glamor_program_alpha alpha;
92 glamor_use_render prim_use_render;
93 glamor_use_render fill_use_render;
94 };
95
96 typedef struct {
97 glamor_program progs[4];
98 } glamor_program_fill;
99
100 extern const glamor_facet glamor_fill_solid;
101
102 Bool
103 glamor_build_program(ScreenPtr screen,
104 glamor_program *prog,
105 const glamor_facet *prim,
106 const glamor_facet *fill,
107 const char *combine,
108 const char *defines);
109
110 Bool
111 glamor_use_program(PixmapPtr pixmap,
112 GCPtr gc,
113 glamor_program *prog,
114 void *arg);
115
116 glamor_program *
117 glamor_use_program_fill(PixmapPtr pixmap,
118 GCPtr gc,
119 glamor_program_fill *program_fill,
120 const glamor_facet *prim);
121
122 typedef enum {
123 glamor_program_source_solid,
124 glamor_program_source_picture,
125 glamor_program_source_1x1_picture,
126 glamor_program_source_count,
127 } glamor_program_source;
128
129 typedef struct {
130 glamor_program progs[glamor_program_source_count][glamor_program_alpha_count];
131 } glamor_program_render;
132
133 static inline Bool
glamor_is_component_alpha(PicturePtr mask)134 glamor_is_component_alpha(PicturePtr mask) {
135 if (mask && mask->componentAlpha && PICT_FORMAT_RGB(mask->format))
136 return TRUE;
137 return FALSE;
138 }
139
140 glamor_program *
141 glamor_setup_program_render(CARD8 op,
142 PicturePtr src,
143 PicturePtr mask,
144 PicturePtr dst,
145 glamor_program_render *program_render,
146 const glamor_facet *prim,
147 const char *defines);
148
149 Bool
150 glamor_use_program_render(glamor_program *prog,
151 CARD8 op,
152 PicturePtr src,
153 PicturePtr dst);
154
155 #endif /* _GLAMOR_PROGRAM_H_ */
156