1 /**************************************************************************
2 *
3 * Copyright 2003 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 portions
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/glheader.h"
29 #include "main/image.h"
30 #include "main/state.h"
31 #include "main/stencil.h"
32 #include "main/mtypes.h"
33 #include "main/condrender.h"
34 #include "main/fbobject.h"
35 #include "drivers/common/meta.h"
36
37 #include "intel_context.h"
38 #include "intel_buffers.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41 #include "intel_pixel.h"
42 #include "intel_fbo.h"
43 #include "intel_blit.h"
44
45 #define FILE_DEBUG_FLAG DEBUG_PIXEL
46
47 /**
48 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
49 */
50 static bool
do_blit_copypixels(struct gl_context * ctx,GLint srcx,GLint srcy,GLsizei width,GLsizei height,GLint dstx,GLint dsty,GLenum type)51 do_blit_copypixels(struct gl_context * ctx,
52 GLint srcx, GLint srcy,
53 GLsizei width, GLsizei height,
54 GLint dstx, GLint dsty, GLenum type)
55 {
56 struct intel_context *intel = intel_context(ctx);
57 struct gl_framebuffer *fb = ctx->DrawBuffer;
58 struct gl_framebuffer *read_fb = ctx->ReadBuffer;
59 GLint orig_dstx;
60 GLint orig_dsty;
61 GLint orig_srcx;
62 GLint orig_srcy;
63 struct intel_renderbuffer *draw_irb = NULL;
64 struct intel_renderbuffer *read_irb = NULL;
65
66 /* Update draw buffer bounds */
67 _mesa_update_state(ctx);
68
69 switch (type) {
70 case GL_COLOR:
71 if (fb->_NumColorDrawBuffers != 1) {
72 perf_debug("glCopyPixels() fallback: MRT\n");
73 return false;
74 }
75
76 draw_irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]);
77 read_irb = intel_renderbuffer(read_fb->_ColorReadBuffer);
78 break;
79 case GL_DEPTH_STENCIL_EXT:
80 draw_irb = intel_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
81 read_irb =
82 intel_renderbuffer(read_fb->Attachment[BUFFER_DEPTH].Renderbuffer);
83 break;
84 case GL_DEPTH:
85 perf_debug("glCopyPixels() fallback: GL_DEPTH\n");
86 return false;
87 case GL_STENCIL:
88 perf_debug("glCopyPixels() fallback: GL_STENCIL\n");
89 return false;
90 default:
91 perf_debug("glCopyPixels(): Unknown type\n");
92 return false;
93 }
94
95 if (!draw_irb) {
96 perf_debug("glCopyPixels() fallback: missing draw buffer\n");
97 return false;
98 }
99
100 if (!read_irb) {
101 perf_debug("glCopyPixels() fallback: missing read buffer\n");
102 return false;
103 }
104
105 if (ctx->_ImageTransferState) {
106 perf_debug("glCopyPixels(): Unsupported image transfer state\n");
107 return false;
108 }
109
110 if (ctx->Depth.Test) {
111 perf_debug("glCopyPixels(): Unsupported depth test state\n");
112 return false;
113 }
114
115 if (_mesa_stencil_is_enabled(ctx)) {
116 perf_debug("glCopyPixels(): Unsupported stencil test state\n");
117 return false;
118 }
119
120 if (ctx->Fog.Enabled ||
121 ctx->Texture._MaxEnabledTexImageUnit != -1 ||
122 _mesa_arb_fragment_program_enabled(ctx)) {
123 perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
124 return false;
125 }
126
127 if (ctx->Color.AlphaEnabled ||
128 ctx->Color.BlendEnabled) {
129 perf_debug("glCopyPixels(): Unsupported blend state\n");
130 return false;
131 }
132
133 if (GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf) {
134 perf_debug("glCopyPixels(): Unsupported color mask state\n");
135 return false;
136 }
137
138 if (ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F) {
139 perf_debug("glCopyPixels(): Unsupported pixel zoom\n");
140 return false;
141 }
142
143 intel_prepare_render(intel);
144
145 intel_flush(&intel->ctx);
146
147 /* Clip to destination buffer. */
148 orig_dstx = dstx;
149 orig_dsty = dsty;
150 if (!_mesa_clip_to_region(fb->_Xmin, fb->_Ymin,
151 fb->_Xmax, fb->_Ymax,
152 &dstx, &dsty, &width, &height))
153 goto out;
154 /* Adjust src coords for our post-clipped destination origin */
155 srcx += dstx - orig_dstx;
156 srcy += dsty - orig_dsty;
157
158 /* Clip to source buffer. */
159 orig_srcx = srcx;
160 orig_srcy = srcy;
161 if (!_mesa_clip_to_region(0, 0,
162 read_fb->Width, read_fb->Height,
163 &srcx, &srcy, &width, &height))
164 goto out;
165 /* Adjust dst coords for our post-clipped source origin */
166 dstx += srcx - orig_srcx;
167 dsty += srcy - orig_srcy;
168
169 if (!intel_miptree_blit(intel,
170 read_irb->mt, read_irb->mt_level, read_irb->mt_layer,
171 srcx, srcy, _mesa_is_winsys_fbo(read_fb),
172 draw_irb->mt, draw_irb->mt_level, draw_irb->mt_layer,
173 dstx, dsty, _mesa_is_winsys_fbo(fb),
174 width, height,
175 (ctx->Color.ColorLogicOpEnabled ?
176 ctx->Color._LogicOp : COLOR_LOGICOP_COPY))) {
177 DBG("%s: blit failure\n", __func__);
178 return false;
179 }
180
181 if (ctx->Query.CurrentOcclusionObject)
182 ctx->Query.CurrentOcclusionObject->Result += width * height;
183
184 out:
185 intel_check_front_buffer_rendering(intel);
186
187 DBG("%s: success\n", __func__);
188 return true;
189 }
190
191
192 void
intelCopyPixels(struct gl_context * ctx,GLint srcx,GLint srcy,GLsizei width,GLsizei height,GLint destx,GLint desty,GLenum type)193 intelCopyPixels(struct gl_context * ctx,
194 GLint srcx, GLint srcy,
195 GLsizei width, GLsizei height,
196 GLint destx, GLint desty, GLenum type)
197 {
198 DBG("%s\n", __func__);
199
200 if (!_mesa_check_conditional_render(ctx))
201 return;
202
203 if (do_blit_copypixels(ctx, srcx, srcy, width, height, destx, desty, type))
204 return;
205
206 /* this will use swrast if needed */
207 _mesa_meta_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type);
208 }
209