mesa: replace VP/FP/ATIfs _Enabled flags with helper functions
[mesa.git] / src / mesa / drivers / dri / i915 / intel_pixel.c
1 /**************************************************************************
2 *
3 * Copyright 2006 VMware, Inc.
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 VMWARE 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/accum.h"
29 #include "main/enums.h"
30 #include "main/state.h"
31 #include "main/stencil.h"
32 #include "main/bufferobj.h"
33 #include "main/context.h"
34 #include "swrast/swrast.h"
35
36 #include "intel_context.h"
37 #include "intel_pixel.h"
38 #include "intel_regions.h"
39
40 #define FILE_DEBUG_FLAG DEBUG_PIXEL
41
42 static GLenum
43 effective_func(GLenum func, bool src_alpha_is_one)
44 {
45 if (src_alpha_is_one) {
46 if (func == GL_SRC_ALPHA)
47 return GL_ONE;
48 if (func == GL_ONE_MINUS_SRC_ALPHA)
49 return GL_ZERO;
50 }
51
52 return func;
53 }
54
55 /**
56 * Check if any fragment operations are in effect which might effect
57 * glDraw/CopyPixels.
58 */
59 bool
60 intel_check_blit_fragment_ops(struct gl_context * ctx, bool src_alpha_is_one)
61 {
62 if (ctx->NewState)
63 _mesa_update_state(ctx);
64
65 if (_mesa_arb_fragment_program_enabled(ctx)) {
66 DBG("fallback due to fragment program\n");
67 return false;
68 }
69
70 if (ctx->Color.BlendEnabled &&
71 (effective_func(ctx->Color.Blend[0].SrcRGB, src_alpha_is_one) != GL_ONE ||
72 effective_func(ctx->Color.Blend[0].DstRGB, src_alpha_is_one) != GL_ZERO ||
73 ctx->Color.Blend[0].EquationRGB != GL_FUNC_ADD ||
74 effective_func(ctx->Color.Blend[0].SrcA, src_alpha_is_one) != GL_ONE ||
75 effective_func(ctx->Color.Blend[0].DstA, src_alpha_is_one) != GL_ZERO ||
76 ctx->Color.Blend[0].EquationA != GL_FUNC_ADD)) {
77 DBG("fallback due to blend\n");
78 return false;
79 }
80
81 if (ctx->Texture._MaxEnabledTexImageUnit != -1) {
82 DBG("fallback due to texturing\n");
83 return false;
84 }
85
86 if (!(ctx->Color.ColorMask[0][0] &&
87 ctx->Color.ColorMask[0][1] &&
88 ctx->Color.ColorMask[0][2] &&
89 ctx->Color.ColorMask[0][3])) {
90 DBG("fallback due to color masking\n");
91 return false;
92 }
93
94 if (ctx->Color.AlphaEnabled) {
95 DBG("fallback due to alpha\n");
96 return false;
97 }
98
99 if (ctx->Depth.Test) {
100 DBG("fallback due to depth test\n");
101 return false;
102 }
103
104 if (ctx->Fog.Enabled) {
105 DBG("fallback due to fog\n");
106 return false;
107 }
108
109 if (ctx->_ImageTransferState) {
110 DBG("fallback due to image transfer\n");
111 return false;
112 }
113
114 if (_mesa_stencil_is_enabled(ctx)) {
115 DBG("fallback due to image stencil\n");
116 return false;
117 }
118
119 if (ctx->RenderMode != GL_RENDER) {
120 DBG("fallback due to render mode\n");
121 return false;
122 }
123
124 return true;
125 }
126
127 void
128 intelInitPixelFuncs(struct dd_function_table *functions)
129 {
130 functions->Bitmap = intelBitmap;
131 functions->CopyPixels = intelCopyPixels;
132 functions->DrawPixels = intelDrawPixels;
133 functions->ReadPixels = intelReadPixels;
134 }
135