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