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     char                                *vs_defines;
60     char                                *fs_defines;
61     const char                          *vs_vars;
62     const char                          *vs_exec;
63     const char                          *fs_vars;
64     const char                          *fs_exec;
65     const glamor_program_location       locations;
66     const glamor_program_flag           flags;
67     const char                          *source_name;
68     glamor_use                          use;
69     glamor_use_render                   use_render;
70 } glamor_facet;
71 
72 struct _glamor_program {
73     GLint                       prog;
74     GLint                       failed;
75     GLint                       matrix_uniform;
76     GLint                       fg_uniform;
77     GLint                       bg_uniform;
78     GLint                       fill_size_inv_uniform;
79     GLint                       fill_offset_uniform;
80     GLint                       font_uniform;
81     GLint                       bitplane_uniform;
82     GLint                       bitmul_uniform;
83     GLint                       dash_uniform;
84     GLint                       dash_length_uniform;
85     GLint                       atlas_uniform;
86     glamor_program_location     locations;
87     glamor_program_flag         flags;
88     glamor_use                  prim_use;
89     glamor_use                  fill_use;
90     glamor_program_alpha        alpha;
91     glamor_use_render           prim_use_render;
92     glamor_use_render           fill_use_render;
93 };
94 
95 typedef struct {
96     glamor_program      progs[4];
97 } glamor_program_fill;
98 
99 extern const glamor_facet glamor_fill_solid;
100 
101 Bool
102 glamor_build_program(ScreenPtr          screen,
103                      glamor_program     *prog,
104                      const glamor_facet *prim,
105                      const glamor_facet *fill,
106                      const char         *combine,
107                      const char         *defines);
108 
109 Bool
110 glamor_use_program(PixmapPtr            pixmap,
111                    GCPtr                gc,
112                    glamor_program       *prog,
113                    void                 *arg);
114 
115 glamor_program *
116 glamor_use_program_fill(PixmapPtr               pixmap,
117                         GCPtr                   gc,
118                         glamor_program_fill     *program_fill,
119                         const glamor_facet      *prim);
120 
121 typedef enum {
122     glamor_program_source_solid,
123     glamor_program_source_picture,
124     glamor_program_source_1x1_picture,
125     glamor_program_source_count,
126 } glamor_program_source;
127 
128 typedef struct {
129     glamor_program      progs[glamor_program_source_count][glamor_program_alpha_count];
130 } glamor_program_render;
131 
132 static inline Bool
glamor_is_component_alpha(PicturePtr mask)133 glamor_is_component_alpha(PicturePtr mask) {
134     if (mask && mask->componentAlpha && PICT_FORMAT_RGB(mask->format))
135         return TRUE;
136     return FALSE;
137 }
138 
139 glamor_program *
140 glamor_setup_program_render(CARD8                 op,
141                             PicturePtr            src,
142                             PicturePtr            mask,
143                             PicturePtr            dst,
144                             glamor_program_render *program_render,
145                             const glamor_facet    *prim,
146                             const char            *defines);
147 
148 Bool
149 glamor_use_program_render(glamor_program        *prog,
150                           CARD8                 op,
151                           PicturePtr            src,
152                           PicturePtr            dst);
153 
154 #endif /* _GLAMOR_PROGRAM_H_ */
155