Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / intel / intel_pixel.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portionsalloc
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/enums.h"
29 #include "main/state.h"
30 #include "swrast/swrast.h"
31
32 #include "intel_context.h"
33 #include "intel_pixel.h"
34 #include "intel_regions.h"
35
36 #define FILE_DEBUG_FLAG DEBUG_PIXEL
37
38 static GLenum
39 effective_func(GLenum func, GLboolean src_alpha_is_one)
40 {
41 if (src_alpha_is_one) {
42 if (func == GL_SRC_ALPHA)
43 return GL_ONE;
44 if (func == GL_ONE_MINUS_SRC_ALPHA)
45 return GL_ZERO;
46 }
47
48 return func;
49 }
50
51 /**
52 * Check if any fragment operations are in effect which might effect
53 * glDraw/CopyPixels.
54 */
55 GLboolean
56 intel_check_blit_fragment_ops(GLcontext * ctx, GLboolean src_alpha_is_one)
57 {
58 if (ctx->NewState)
59 _mesa_update_state(ctx);
60
61 if (ctx->FragmentProgram._Enabled) {
62 DBG("fallback due to fragment program\n");
63 return GL_FALSE;
64 }
65
66 if (ctx->Color.BlendEnabled &&
67 (effective_func(ctx->Color.BlendSrcRGB, src_alpha_is_one) != GL_ONE ||
68 effective_func(ctx->Color.BlendDstRGB, src_alpha_is_one) != GL_ZERO ||
69 ctx->Color.BlendEquationRGB != GL_FUNC_ADD ||
70 effective_func(ctx->Color.BlendSrcA, src_alpha_is_one) != GL_ONE ||
71 effective_func(ctx->Color.BlendDstA, src_alpha_is_one) != GL_ZERO ||
72 ctx->Color.BlendEquationA != GL_FUNC_ADD)) {
73 DBG("fallback due to blend\n");
74 return GL_FALSE;
75 }
76
77 if (ctx->Texture._EnabledUnits) {
78 DBG("fallback due to texturing\n");
79 return GL_FALSE;
80 }
81
82 if (!(ctx->Color.ColorMask[0] &&
83 ctx->Color.ColorMask[1] &&
84 ctx->Color.ColorMask[2] &&
85 ctx->Color.ColorMask[3])) {
86 DBG("fallback due to color masking\n");
87 return GL_FALSE;
88 }
89
90 if (ctx->Color.AlphaEnabled) {
91 DBG("fallback due to alpha\n");
92 return GL_FALSE;
93 }
94
95 if (ctx->Depth.Test) {
96 DBG("fallback due to depth test\n");
97 return GL_FALSE;
98 }
99
100 if (ctx->Fog.Enabled) {
101 DBG("fallback due to fog\n");
102 return GL_FALSE;
103 }
104
105 if (ctx->_ImageTransferState) {
106 DBG("fallback due to image transfer\n");
107 return GL_FALSE;
108 }
109
110 if (ctx->Stencil.Enabled) {
111 DBG("fallback due to image stencil\n");
112 return GL_FALSE;
113 }
114
115 if (ctx->Scissor.Enabled) {
116 /* XXX Note: Scissor could be done with the blitter */
117 DBG("fallback due to image scissor\n");
118 return GL_FALSE;
119 }
120
121 if (ctx->RenderMode != GL_RENDER) {
122 DBG("fallback due to render mode\n");
123 return GL_FALSE;
124 }
125
126 return GL_TRUE;
127 }
128
129
130 GLboolean
131 intel_check_meta_tex_fragment_ops(GLcontext * ctx)
132 {
133 if (ctx->NewState)
134 _mesa_update_state(ctx);
135
136 /* Some of _ImageTransferState (scale, bias) could be done with
137 * fragment programs on i915.
138 */
139 return !(ctx->_ImageTransferState || ctx->Fog.Enabled || /* not done yet */
140 ctx->Texture._EnabledUnits || ctx->FragmentProgram._Enabled);
141 }
142
143 /* The intel_region struct doesn't really do enough to capture the
144 * format of the pixels in the region. For now this code assumes that
145 * the region is a display surface and hence is either ARGB8888 or
146 * RGB565.
147 * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd
148 * know the buffer's pixel format.
149 *
150 * \param format as given to glDraw/ReadPixels
151 * \param type as given to glDraw/ReadPixels
152 */
153 GLboolean
154 intel_check_blit_format(struct intel_region * region,
155 GLenum format, GLenum type)
156 {
157 if (region->cpp == 4 &&
158 (type == GL_UNSIGNED_INT_8_8_8_8_REV ||
159 type == GL_UNSIGNED_BYTE) && format == GL_BGRA) {
160 return GL_TRUE;
161 }
162
163 if (region->cpp == 2 &&
164 type == GL_UNSIGNED_SHORT_5_6_5_REV && format == GL_BGR) {
165 return GL_TRUE;
166 }
167
168 if (INTEL_DEBUG & DEBUG_PIXEL)
169 fprintf(stderr, "%s: bad format for blit (cpp %d, type %s format %s)\n",
170 __FUNCTION__, region->cpp,
171 _mesa_lookup_enum_by_nr(type), _mesa_lookup_enum_by_nr(format));
172
173 return GL_FALSE;
174 }
175
176
177 void
178 intelInitPixelFuncs(struct dd_function_table *functions)
179 {
180 functions->Accum = _swrast_Accum;
181 if (!getenv("INTEL_NO_BLIT")) {
182 functions->Bitmap = intelBitmap;
183 functions->CopyPixels = intelCopyPixels;
184 #ifdef I915
185 functions->ReadPixels = intelReadPixels;
186 functions->DrawPixels = intelDrawPixels;
187 #endif
188 }
189 }