2 * Copyright 2003 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/image.h"
27 #include "main/state.h"
28 #include "main/mtypes.h"
29 #include "main/condrender.h"
30 #include "main/fbobject.h"
31 #include "drivers/common/meta.h"
33 #include "brw_context.h"
34 #include "intel_buffers.h"
35 #include "intel_mipmap_tree.h"
36 #include "intel_pixel.h"
37 #include "intel_fbo.h"
38 #include "intel_blit.h"
39 #include "intel_batchbuffer.h"
41 #define FILE_DEBUG_FLAG DEBUG_PIXEL
44 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
47 do_blit_copypixels(struct gl_context
* ctx
,
48 GLint srcx
, GLint srcy
,
49 GLsizei width
, GLsizei height
,
50 GLint dstx
, GLint dsty
, GLenum type
)
52 struct brw_context
*brw
= brw_context(ctx
);
53 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
54 struct gl_framebuffer
*read_fb
= ctx
->ReadBuffer
;
59 struct intel_renderbuffer
*draw_irb
= NULL
;
60 struct intel_renderbuffer
*read_irb
= NULL
;
62 /* Update draw buffer bounds */
63 _mesa_update_state(ctx
);
65 intel_prepare_render(brw
);
69 if (fb
->_NumColorDrawBuffers
!= 1) {
70 perf_debug("glCopyPixels() fallback: MRT\n");
74 draw_irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[0]);
75 read_irb
= intel_renderbuffer(read_fb
->_ColorReadBuffer
);
77 case GL_DEPTH_STENCIL_EXT
:
78 draw_irb
= intel_renderbuffer(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
80 intel_renderbuffer(read_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
83 perf_debug("glCopyPixels() fallback: GL_DEPTH\n");
86 perf_debug("glCopyPixels() fallback: GL_STENCIL\n");
89 perf_debug("glCopyPixels(): Unknown type\n");
94 perf_debug("glCopyPixels() fallback: missing draw buffer\n");
99 perf_debug("glCopyPixels() fallback: missing read buffer\n");
103 if (draw_irb
->mt
->num_samples
> 1 || read_irb
->mt
->num_samples
> 1) {
104 perf_debug("glCopyPixels() fallback: multisampled buffers\n");
108 if (ctx
->_ImageTransferState
) {
109 perf_debug("glCopyPixels(): Unsupported image transfer state\n");
113 if (ctx
->Depth
.Test
) {
114 perf_debug("glCopyPixels(): Unsupported depth test state\n");
118 if (ctx
->Stencil
._Enabled
) {
119 perf_debug("glCopyPixels(): Unsupported stencil test state\n");
123 if (ctx
->Fog
.Enabled
||
124 ctx
->Texture
._MaxEnabledTexImageUnit
!= -1 ||
125 ctx
->FragmentProgram
._Enabled
) {
126 perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
130 if (ctx
->Color
.AlphaEnabled
||
131 ctx
->Color
.BlendEnabled
) {
132 perf_debug("glCopyPixels(): Unsupported blend state\n");
136 if (!ctx
->Color
.ColorMask
[0][0] ||
137 !ctx
->Color
.ColorMask
[0][1] ||
138 !ctx
->Color
.ColorMask
[0][2] ||
139 !ctx
->Color
.ColorMask
[0][3]) {
140 perf_debug("glCopyPixels(): Unsupported color mask state\n");
144 if (ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
) {
145 perf_debug("glCopyPixels(): Unsupported pixel zoom\n");
149 intel_batchbuffer_flush(brw
);
151 /* Clip to destination buffer. */
154 if (!_mesa_clip_to_region(fb
->_Xmin
, fb
->_Ymin
,
155 fb
->_Xmax
, fb
->_Ymax
,
156 &dstx
, &dsty
, &width
, &height
))
158 /* Adjust src coords for our post-clipped destination origin */
159 srcx
+= dstx
- orig_dstx
;
160 srcy
+= dsty
- orig_dsty
;
162 /* Clip to source buffer. */
165 if (!_mesa_clip_to_region(0, 0,
166 read_fb
->Width
, read_fb
->Height
,
167 &srcx
, &srcy
, &width
, &height
))
169 /* Adjust dst coords for our post-clipped source origin */
170 dstx
+= srcx
- orig_srcx
;
171 dsty
+= srcy
- orig_srcy
;
173 if (!intel_miptree_blit(brw
,
174 read_irb
->mt
, read_irb
->mt_level
, read_irb
->mt_layer
,
175 srcx
, srcy
, _mesa_is_winsys_fbo(read_fb
),
176 draw_irb
->mt
, draw_irb
->mt_level
, draw_irb
->mt_layer
,
177 dstx
, dsty
, _mesa_is_winsys_fbo(fb
),
179 (ctx
->Color
.ColorLogicOpEnabled
?
180 ctx
->Color
.LogicOp
: GL_COPY
))) {
181 DBG("%s: blit failure\n", __func__
);
185 if (ctx
->Query
.CurrentOcclusionObject
)
186 ctx
->Query
.CurrentOcclusionObject
->Result
+= width
* height
;
190 DBG("%s: success\n", __func__
);
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", __func__
);
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
);