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