1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/image.h"
30 #include "main/state.h"
31 #include "main/mtypes.h"
32 #include "main/condrender.h"
33 #include "main/fbobject.h"
34 #include "drivers/common/meta.h"
36 #include "brw_context.h"
37 #include "intel_buffers.h"
38 #include "intel_mipmap_tree.h"
39 #include "intel_regions.h"
40 #include "intel_pixel.h"
41 #include "intel_fbo.h"
42 #include "intel_blit.h"
43 #include "intel_batchbuffer.h"
45 #define FILE_DEBUG_FLAG DEBUG_PIXEL
48 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
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
)
56 struct brw_context
*brw
= brw_context(ctx
);
57 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
58 struct gl_framebuffer
*read_fb
= ctx
->ReadBuffer
;
63 struct intel_renderbuffer
*draw_irb
= NULL
;
64 struct intel_renderbuffer
*read_irb
= NULL
;
66 /* Update draw buffer bounds */
67 _mesa_update_state(ctx
);
71 if (fb
->_NumColorDrawBuffers
!= 1) {
72 perf_debug("glCopyPixels() fallback: MRT\n");
76 draw_irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[0]);
77 read_irb
= intel_renderbuffer(read_fb
->_ColorReadBuffer
);
79 case GL_DEPTH_STENCIL_EXT
:
80 draw_irb
= intel_renderbuffer(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
82 intel_renderbuffer(read_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
85 perf_debug("glCopyPixels() fallback: GL_DEPTH\n");
88 perf_debug("glCopyPixels() fallback: GL_STENCIL\n");
91 perf_debug("glCopyPixels(): Unknown type\n");
96 perf_debug("glCopyPixels() fallback: missing draw buffer\n");
101 perf_debug("glCopyPixels() fallback: missing read buffer\n");
105 if (ctx
->_ImageTransferState
) {
106 perf_debug("glCopyPixels(): Unsupported image transfer state\n");
110 if (ctx
->Depth
.Test
) {
111 perf_debug("glCopyPixels(): Unsupported depth test state\n");
115 if (ctx
->Stencil
._Enabled
) {
116 perf_debug("glCopyPixels(): Unsupported stencil test state\n");
120 if (ctx
->Fog
.Enabled
||
121 ctx
->Texture
._EnabledUnits
||
122 ctx
->FragmentProgram
._Enabled
) {
123 perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
127 if (ctx
->Color
.AlphaEnabled
||
128 ctx
->Color
.BlendEnabled
) {
129 perf_debug("glCopyPixels(): Unsupported blend state\n");
133 if (!ctx
->Color
.ColorMask
[0][0] ||
134 !ctx
->Color
.ColorMask
[0][1] ||
135 !ctx
->Color
.ColorMask
[0][2] ||
136 !ctx
->Color
.ColorMask
[0][3]) {
137 perf_debug("glCopyPixels(): Unsupported color mask state\n");
141 if (ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
) {
142 perf_debug("glCopyPixles(): Unsupported pixel zoom\n");
146 intel_prepare_render(brw
);
148 intel_batchbuffer_flush(brw
);
150 /* Clip to destination buffer. */
153 if (!_mesa_clip_to_region(fb
->_Xmin
, fb
->_Ymin
,
154 fb
->_Xmax
, fb
->_Ymax
,
155 &dstx
, &dsty
, &width
, &height
))
157 /* Adjust src coords for our post-clipped destination origin */
158 srcx
+= dstx
- orig_dstx
;
159 srcy
+= dsty
- orig_dsty
;
161 /* Clip to source buffer. */
164 if (!_mesa_clip_to_region(0, 0,
165 read_fb
->Width
, read_fb
->Height
,
166 &srcx
, &srcy
, &width
, &height
))
168 /* Adjust dst coords for our post-clipped source origin */
169 dstx
+= srcx
- orig_srcx
;
170 dsty
+= srcy
- orig_srcy
;
172 if (!intel_miptree_blit(brw
,
173 read_irb
->mt
, read_irb
->mt_level
, read_irb
->mt_layer
,
174 srcx
, srcy
, _mesa_is_winsys_fbo(read_fb
),
175 draw_irb
->mt
, draw_irb
->mt_level
, draw_irb
->mt_layer
,
176 dstx
, dsty
, _mesa_is_winsys_fbo(fb
),
178 (ctx
->Color
.ColorLogicOpEnabled
?
179 ctx
->Color
.LogicOp
: GL_COPY
))) {
180 DBG("%s: blit failure\n", __FUNCTION__
);
184 if (ctx
->Query
.CurrentOcclusionObject
)
185 ctx
->Query
.CurrentOcclusionObject
->Result
+= width
* height
;
188 intel_check_front_buffer_rendering(brw
);
190 DBG("%s: success\n", __FUNCTION__
);
196 intelCopyPixels(struct gl_context
* ctx
,
197 GLint srcx
, GLint srcy
,
198 GLsizei width
, GLsizei height
,
199 GLint destx
, GLint desty
, GLenum type
)
201 DBG("%s\n", __FUNCTION__
);
203 if (!_mesa_check_conditional_render(ctx
))
206 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
209 /* this will use swrast if needed */
210 _mesa_meta_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);