intel_pixel.c revision 8b23755ce978247a92c00e390de2e459c0a9d5ad
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
47static GLenum
48effective_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 */
64GLboolean
65intel_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/* The intel_region struct doesn't really do enough to capture the
133 * format of the pixels in the region.  For now this code assumes that
134 * the region is a display surface and hence is either ARGB8888 or
135 * RGB565.
136 * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd
137 * know the buffer's pixel format.
138 *
139 * \param format  as given to glDraw/ReadPixels
140 * \param type  as given to glDraw/ReadPixels
141 */
142GLboolean
143intel_check_blit_format(struct intel_region * region,
144                        GLenum format, GLenum type)
145{
146   if (region->cpp == 4 &&
147       (type == GL_UNSIGNED_INT_8_8_8_8_REV ||
148        type == GL_UNSIGNED_BYTE) && format == GL_BGRA) {
149      return GL_TRUE;
150   }
151
152   if (region->cpp == 2 &&
153       type == GL_UNSIGNED_SHORT_5_6_5_REV && format == GL_BGR) {
154      return GL_TRUE;
155   }
156
157   if (INTEL_DEBUG & DEBUG_PIXEL)
158      fprintf(stderr, "%s: bad format for blit (cpp %d, type %s format %s)\n",
159              __FUNCTION__, region->cpp,
160              _mesa_lookup_enum_by_nr(type), _mesa_lookup_enum_by_nr(format));
161
162   return GL_FALSE;
163}
164
165void
166intelInitPixelFuncs(struct dd_function_table *functions)
167{
168   functions->Accum = _swrast_Accum;
169   if (!getenv("INTEL_NO_BLIT")) {
170      functions->Bitmap = intelBitmap;
171      functions->CopyPixels = intelCopyPixels;
172      functions->DrawPixels = intelDrawPixels;
173   }
174   functions->ReadPixels = intelReadPixels;
175}
176
177