1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2001 Keith Packard
3*4882a593Smuzhiyun * Copyright © 2008 Intel Corporation
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
10*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
13*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
14*4882a593Smuzhiyun * Software.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22*4882a593Smuzhiyun * IN THE SOFTWARE.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Authors:
25*4882a593Smuzhiyun * Eric Anholt <eric@anholt.net>
26*4882a593Smuzhiyun * Zhigang Gong <zhigang.gong@linux.intel.com>
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include <stdlib.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "glamor_priv.h"
33*4882a593Smuzhiyun /**
34*4882a593Smuzhiyun * Sets the offsets to add to coordinates to make them address the same bits in
35*4882a593Smuzhiyun * the backing drawable. These coordinates are nonzero only for redirected
36*4882a593Smuzhiyun * windows.
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun void
glamor_get_drawable_deltas(DrawablePtr drawable,PixmapPtr pixmap,int * x,int * y)39*4882a593Smuzhiyun glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
40*4882a593Smuzhiyun int *x, int *y)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun #ifdef COMPOSITE
43*4882a593Smuzhiyun if (drawable->type == DRAWABLE_WINDOW) {
44*4882a593Smuzhiyun *x = -pixmap->screen_x;
45*4882a593Smuzhiyun *y = -pixmap->screen_y;
46*4882a593Smuzhiyun return;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun #endif
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun *x = 0;
51*4882a593Smuzhiyun *y = 0;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun void
glamor_pixmap_init(ScreenPtr screen)55*4882a593Smuzhiyun glamor_pixmap_init(ScreenPtr screen)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun void
glamor_pixmap_fini(ScreenPtr screen)61*4882a593Smuzhiyun glamor_pixmap_fini(ScreenPtr screen)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun void
glamor_set_destination_pixmap_fbo(glamor_screen_private * glamor_priv,glamor_pixmap_fbo * fbo,int x0,int y0,int width,int height)66*4882a593Smuzhiyun glamor_set_destination_pixmap_fbo(glamor_screen_private *glamor_priv,
67*4882a593Smuzhiyun glamor_pixmap_fbo *fbo, int x0, int y0,
68*4882a593Smuzhiyun int width, int height)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun glamor_make_current(glamor_priv);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb);
73*4882a593Smuzhiyun glViewport(x0, y0, width, height);
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun void
glamor_set_destination_pixmap_priv_nc(glamor_screen_private * glamor_priv,PixmapPtr pixmap,glamor_pixmap_private * pixmap_priv)77*4882a593Smuzhiyun glamor_set_destination_pixmap_priv_nc(glamor_screen_private *glamor_priv,
78*4882a593Smuzhiyun PixmapPtr pixmap,
79*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun int w, h;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun PIXMAP_PRIV_GET_ACTUAL_SIZE(pixmap, pixmap_priv, w, h);
84*4882a593Smuzhiyun glamor_set_destination_pixmap_fbo(glamor_priv, pixmap_priv->fbo, 0, 0, w, h);
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun int
glamor_set_destination_pixmap_priv(glamor_screen_private * glamor_priv,PixmapPtr pixmap,glamor_pixmap_private * pixmap_priv)88*4882a593Smuzhiyun glamor_set_destination_pixmap_priv(glamor_screen_private *glamor_priv,
89*4882a593Smuzhiyun PixmapPtr pixmap,
90*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
93*4882a593Smuzhiyun return -1;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv);
96*4882a593Smuzhiyun return 0;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun int
glamor_set_destination_pixmap(PixmapPtr pixmap)100*4882a593Smuzhiyun glamor_set_destination_pixmap(PixmapPtr pixmap)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun int err;
103*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
104*4882a593Smuzhiyun ScreenPtr screen = pixmap->drawable.pScreen;
105*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun err = glamor_set_destination_pixmap_priv(glamor_priv, pixmap, pixmap_priv);
108*4882a593Smuzhiyun return err;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun Bool
glamor_set_planemask(int depth,unsigned long planemask)112*4882a593Smuzhiyun glamor_set_planemask(int depth, unsigned long planemask)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun if (glamor_pm_is_solid(depth, planemask)) {
115*4882a593Smuzhiyun return GL_TRUE;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun glamor_fallback("unsupported planemask %lx\n", planemask);
119*4882a593Smuzhiyun return GL_FALSE;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun Bool
glamor_set_alu(ScreenPtr screen,unsigned char alu)123*4882a593Smuzhiyun glamor_set_alu(ScreenPtr screen, unsigned char alu)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun if (glamor_priv->is_gles) {
128*4882a593Smuzhiyun if (alu != GXcopy)
129*4882a593Smuzhiyun return FALSE;
130*4882a593Smuzhiyun else
131*4882a593Smuzhiyun return TRUE;
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun if (alu == GXcopy) {
135*4882a593Smuzhiyun glDisable(GL_COLOR_LOGIC_OP);
136*4882a593Smuzhiyun return TRUE;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun glEnable(GL_COLOR_LOGIC_OP);
139*4882a593Smuzhiyun switch (alu) {
140*4882a593Smuzhiyun case GXclear:
141*4882a593Smuzhiyun glLogicOp(GL_CLEAR);
142*4882a593Smuzhiyun break;
143*4882a593Smuzhiyun case GXand:
144*4882a593Smuzhiyun glLogicOp(GL_AND);
145*4882a593Smuzhiyun break;
146*4882a593Smuzhiyun case GXandReverse:
147*4882a593Smuzhiyun glLogicOp(GL_AND_REVERSE);
148*4882a593Smuzhiyun break;
149*4882a593Smuzhiyun case GXandInverted:
150*4882a593Smuzhiyun glLogicOp(GL_AND_INVERTED);
151*4882a593Smuzhiyun break;
152*4882a593Smuzhiyun case GXnoop:
153*4882a593Smuzhiyun glLogicOp(GL_NOOP);
154*4882a593Smuzhiyun break;
155*4882a593Smuzhiyun case GXxor:
156*4882a593Smuzhiyun glLogicOp(GL_XOR);
157*4882a593Smuzhiyun break;
158*4882a593Smuzhiyun case GXor:
159*4882a593Smuzhiyun glLogicOp(GL_OR);
160*4882a593Smuzhiyun break;
161*4882a593Smuzhiyun case GXnor:
162*4882a593Smuzhiyun glLogicOp(GL_NOR);
163*4882a593Smuzhiyun break;
164*4882a593Smuzhiyun case GXequiv:
165*4882a593Smuzhiyun glLogicOp(GL_EQUIV);
166*4882a593Smuzhiyun break;
167*4882a593Smuzhiyun case GXinvert:
168*4882a593Smuzhiyun glLogicOp(GL_INVERT);
169*4882a593Smuzhiyun break;
170*4882a593Smuzhiyun case GXorReverse:
171*4882a593Smuzhiyun glLogicOp(GL_OR_REVERSE);
172*4882a593Smuzhiyun break;
173*4882a593Smuzhiyun case GXcopyInverted:
174*4882a593Smuzhiyun glLogicOp(GL_COPY_INVERTED);
175*4882a593Smuzhiyun break;
176*4882a593Smuzhiyun case GXorInverted:
177*4882a593Smuzhiyun glLogicOp(GL_OR_INVERTED);
178*4882a593Smuzhiyun break;
179*4882a593Smuzhiyun case GXnand:
180*4882a593Smuzhiyun glLogicOp(GL_NAND);
181*4882a593Smuzhiyun break;
182*4882a593Smuzhiyun case GXset:
183*4882a593Smuzhiyun glLogicOp(GL_SET);
184*4882a593Smuzhiyun break;
185*4882a593Smuzhiyun default:
186*4882a593Smuzhiyun glamor_fallback("unsupported alu %x\n", alu);
187*4882a593Smuzhiyun return FALSE;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun return TRUE;
191*4882a593Smuzhiyun }
192