intel_pixel.c revision a6aa926e3f0b6237679db0d3331690d2a96adbc2
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 38static GLenum 39effective_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 */ 55GLboolean 56intel_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->RenderMode != GL_RENDER) { 116 DBG("fallback due to render mode\n"); 117 return GL_FALSE; 118 } 119 120 return GL_TRUE; 121} 122 123 124GLboolean 125intel_check_meta_tex_fragment_ops(GLcontext * ctx) 126{ 127 if (ctx->NewState) 128 _mesa_update_state(ctx); 129 130 /* Some of _ImageTransferState (scale, bias) could be done with 131 * fragment programs on i915. 132 */ 133 return !(ctx->_ImageTransferState || ctx->Fog.Enabled || /* not done yet */ 134 ctx->Texture._EnabledUnits || ctx->FragmentProgram._Enabled); 135} 136 137/* The intel_region struct doesn't really do enough to capture the 138 * format of the pixels in the region. For now this code assumes that 139 * the region is a display surface and hence is either ARGB8888 or 140 * RGB565. 141 * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd 142 * know the buffer's pixel format. 143 * 144 * \param format as given to glDraw/ReadPixels 145 * \param type as given to glDraw/ReadPixels 146 */ 147GLboolean 148intel_check_blit_format(struct intel_region * region, 149 GLenum format, GLenum type) 150{ 151 if (region->cpp == 4 && 152 (type == GL_UNSIGNED_INT_8_8_8_8_REV || 153 type == GL_UNSIGNED_BYTE) && format == GL_BGRA) { 154 return GL_TRUE; 155 } 156 157 if (region->cpp == 2 && 158 type == GL_UNSIGNED_SHORT_5_6_5_REV && format == GL_BGR) { 159 return GL_TRUE; 160 } 161 162 if (INTEL_DEBUG & DEBUG_PIXEL) 163 fprintf(stderr, "%s: bad format for blit (cpp %d, type %s format %s)\n", 164 __FUNCTION__, region->cpp, 165 _mesa_lookup_enum_by_nr(type), _mesa_lookup_enum_by_nr(format)); 166 167 return GL_FALSE; 168} 169 170 171void 172intelInitPixelFuncs(struct dd_function_table *functions) 173{ 174 functions->Accum = _swrast_Accum; 175 if (!getenv("INTEL_NO_BLIT")) { 176 functions->Bitmap = intelBitmap; 177 functions->CopyPixels = intelCopyPixels; 178 functions->DrawPixels = intelDrawPixels; 179#ifdef I915 180 functions->ReadPixels = intelReadPixels; 181#endif 182 } 183} 184