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