1afa6c269163503893fdb7f36af8e7bc6ee686ad
2 * Copyright 2006 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, sub license, 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 portionsalloc
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 NON-INFRINGEMENT.
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/glheader.h"
27 #include "main/enums.h"
28 #include "main/image.h"
29 #include "main/glformats.h"
30 #include "main/mtypes.h"
31 #include "main/condrender.h"
32 #include "main/fbobject.h"
33 #include "main/teximage.h"
34 #include "main/texobj.h"
35 #include "main/texstate.h"
36 #include "main/bufferobj.h"
37 #include "swrast/swrast.h"
38 #include "drivers/common/meta.h"
40 #include "brw_context.h"
41 #include "intel_screen.h"
42 #include "intel_blit.h"
43 #include "intel_buffers.h"
44 #include "intel_fbo.h"
45 #include "intel_mipmap_tree.h"
46 #include "intel_pixel.h"
47 #include "intel_buffer_objects.h"
49 #define FILE_DEBUG_FLAG DEBUG_PIXEL
52 do_blit_drawpixels(struct gl_context
* ctx
,
53 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
54 GLenum format
, GLenum type
,
55 const struct gl_pixelstore_attrib
*unpack
,
56 const GLvoid
* pixels
)
58 struct brw_context
*brw
= brw_context(ctx
);
59 struct intel_buffer_object
*src
= intel_buffer_object(unpack
->BufferObj
);
61 drm_intel_bo
*src_buffer
;
63 DBG("%s\n", __func__
);
65 if (!intel_check_blit_fragment_ops(ctx
, false))
68 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
!= 1) {
69 DBG("%s: fallback due to MRT\n", __func__
);
73 intel_prepare_render(brw
);
75 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
76 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
78 mesa_format src_format
= _mesa_format_from_format_and_type(format
, type
);
79 if (_mesa_format_is_mesa_array_format(src_format
))
80 src_format
= _mesa_format_from_array_format(src_format
);
81 mesa_format dst_format
= irb
->mt
->format
;
83 /* We can safely discard sRGB encode/decode for the DrawPixels interface */
84 src_format
= _mesa_get_srgb_format_linear(src_format
);
85 dst_format
= _mesa_get_srgb_format_linear(dst_format
);
87 if (!intel_miptree_blit_compatible_formats(src_format
, dst_format
)) {
88 DBG("%s: bad format for blit\n", __func__
);
92 if (unpack
->SwapBytes
|| unpack
->LsbFirst
||
93 unpack
->SkipPixels
|| unpack
->SkipRows
) {
94 DBG("%s: bad packing params\n", __func__
);
98 int src_stride
= _mesa_image_row_stride(unpack
, width
, format
, type
);
99 bool src_flip
= false;
100 /* Mesa flips the src_stride for unpack->Invert, but we want our mt to have
101 * a normal src_stride.
103 if (unpack
->Invert
) {
104 src_stride
= -src_stride
;
108 src_offset
= (GLintptr
)pixels
;
109 src_offset
+= _mesa_image_offset(2, unpack
, width
, height
,
110 format
, type
, 0, 0, 0);
112 src_buffer
= intel_bufferobj_buffer(brw
, src
, src_offset
,
113 height
* src_stride
);
115 struct intel_mipmap_tree
*pbo_mt
=
116 intel_miptree_create_for_bo(brw
,
126 if (!intel_miptree_blit(brw
,
129 irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
130 x
, y
, _mesa_is_winsys_fbo(ctx
->DrawBuffer
),
131 width
, height
, GL_COPY
)) {
132 DBG("%s: blit failed\n", __func__
);
133 intel_miptree_release(&pbo_mt
);
137 intel_miptree_release(&pbo_mt
);
139 if (ctx
->Query
.CurrentOcclusionObject
)
140 ctx
->Query
.CurrentOcclusionObject
->Result
+= width
* height
;
142 DBG("%s: success\n", __func__
);
147 intelDrawPixels(struct gl_context
* ctx
,
149 GLsizei width
, GLsizei height
,
152 const struct gl_pixelstore_attrib
*unpack
,
153 const GLvoid
* pixels
)
155 struct brw_context
*brw
= brw_context(ctx
);
157 if (!_mesa_check_conditional_render(ctx
))
160 if (format
== GL_STENCIL_INDEX
) {
161 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
166 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
167 if (do_blit_drawpixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
,
172 perf_debug("%s: fallback to generic code in PBO case\n", __func__
);
175 _mesa_meta_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,