Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[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 "main/bufferobj.h"
31 #include "main/context.h"
32 #include "main/enable.h"
33 #include "main/matrix.h"
34 #include "main/texstate.h"
35 #include "main/varray.h"
36 #include "main/viewport.h"
37 #include "swrast/swrast.h"
38 #include "shader/arbprogram.h"
39 #include "shader/program.h"
40
41 #include "intel_context.h"
42 #include "intel_pixel.h"
43 #include "intel_regions.h"
44
45 #define FILE_DEBUG_FLAG DEBUG_PIXEL
46
47 static GLenum
48 effective_func(GLenum func, GLboolean src_alpha_is_one)
49 {
50 if (src_alpha_is_one) {
51 if (func == GL_SRC_ALPHA)
52 return GL_ONE;
53 if (func == GL_ONE_MINUS_SRC_ALPHA)
54 return GL_ZERO;
55 }
56
57 return func;
58 }
59
60 /**
61 * Check if any fragment operations are in effect which might effect
62 * glDraw/CopyPixels.
63 */
64 GLboolean
65 intel_check_blit_fragment_ops(GLcontext * ctx, GLboolean src_alpha_is_one)
66 {
67 if (ctx->NewState)
68 _mesa_update_state(ctx);
69
70 if (ctx->FragmentProgram._Enabled) {
71 DBG("fallback due to fragment program\n");
72 return GL_FALSE;
73 }
74
75 if (ctx->Color.BlendEnabled &&
76 (effective_func(ctx->Color.BlendSrcRGB, src_alpha_is_one) != GL_ONE ||
77 effective_func(ctx->Color.BlendDstRGB, src_alpha_is_one) != GL_ZERO ||
78 ctx->Color.BlendEquationRGB != GL_FUNC_ADD ||
79 effective_func(ctx->Color.BlendSrcA, src_alpha_is_one) != GL_ONE ||
80 effective_func(ctx->Color.BlendDstA, src_alpha_is_one) != GL_ZERO ||
81 ctx->Color.BlendEquationA != GL_FUNC_ADD)) {
82 DBG("fallback due to blend\n");
83 return GL_FALSE;
84 }
85
86 if (ctx->Texture._EnabledUnits) {
87 DBG("fallback due to texturing\n");
88 return GL_FALSE;
89 }
90
91 if (!(ctx->Color.ColorMask[0] &&
92 ctx->Color.ColorMask[1] &&
93 ctx->Color.ColorMask[2] &&
94 ctx->Color.ColorMask[3])) {
95 DBG("fallback due to color masking\n");
96 return GL_FALSE;
97 }
98
99 if (ctx->Color.AlphaEnabled) {
100 DBG("fallback due to alpha\n");
101 return GL_FALSE;
102 }
103
104 if (ctx->Depth.Test) {
105 DBG("fallback due to depth test\n");
106 return GL_FALSE;
107 }
108
109 if (ctx->Fog.Enabled) {
110 DBG("fallback due to fog\n");
111 return GL_FALSE;
112 }
113
114 if (ctx->_ImageTransferState) {
115 DBG("fallback due to image transfer\n");
116 return GL_FALSE;
117 }
118
119 if (ctx->Stencil._Enabled) {
120 DBG("fallback due to image stencil\n");
121 return GL_FALSE;
122 }
123
124 if (ctx->RenderMode != GL_RENDER) {
125 DBG("fallback due to render mode\n");
126 return GL_FALSE;
127 }
128
129 return GL_TRUE;
130 }
131
132
133 GLboolean
134 intel_check_meta_tex_fragment_ops(GLcontext * ctx)
135 {
136 if (ctx->NewState)
137 _mesa_update_state(ctx);
138
139 /* Some of _ImageTransferState (scale, bias) could be done with
140 * fragment programs on i915.
141 */
142 return !(ctx->_ImageTransferState || ctx->Fog.Enabled || /* not done yet */
143 ctx->Texture._EnabledUnits || ctx->FragmentProgram._Enabled);
144 }
145
146 /* The intel_region struct doesn't really do enough to capture the
147 * format of the pixels in the region. For now this code assumes that
148 * the region is a display surface and hence is either ARGB8888 or
149 * RGB565.
150 * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd
151 * know the buffer's pixel format.
152 *
153 * \param format as given to glDraw/ReadPixels
154 * \param type as given to glDraw/ReadPixels
155 */
156 GLboolean
157 intel_check_blit_format(struct intel_region * region,
158 GLenum format, GLenum type)
159 {
160 if (region->cpp == 4 &&
161 (type == GL_UNSIGNED_INT_8_8_8_8_REV ||
162 type == GL_UNSIGNED_BYTE) && format == GL_BGRA) {
163 return GL_TRUE;
164 }
165
166 if (region->cpp == 2 &&
167 type == GL_UNSIGNED_SHORT_5_6_5_REV && format == GL_BGR) {
168 return GL_TRUE;
169 }
170
171 if (INTEL_DEBUG & DEBUG_PIXEL)
172 fprintf(stderr, "%s: bad format for blit (cpp %d, type %s format %s)\n",
173 __FUNCTION__, region->cpp,
174 _mesa_lookup_enum_by_nr(type), _mesa_lookup_enum_by_nr(format));
175
176 return GL_FALSE;
177 }
178
179 void
180 intelInitPixelFuncs(struct dd_function_table *functions)
181 {
182 functions->Accum = _swrast_Accum;
183 if (!getenv("INTEL_NO_BLIT")) {
184 functions->Bitmap = intelBitmap;
185 functions->CopyPixels = intelCopyPixels;
186 functions->DrawPixels = intelDrawPixels;
187 }
188 functions->ReadPixels = intelReadPixels;
189 }
190