Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 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/glheader.h" |
||
29 | #include "main/enums.h" |
||
30 | #include "main/image.h" |
||
31 | #include "main/mtypes.h" |
||
32 | #include "main/condrender.h" |
||
33 | #include "main/fbobject.h" |
||
34 | #include "main/teximage.h" |
||
35 | #include "main/texobj.h" |
||
36 | #include "main/texstate.h" |
||
37 | #include "main/bufferobj.h" |
||
38 | #include "swrast/swrast.h" |
||
39 | #include "drivers/common/meta.h" |
||
40 | |||
41 | #include "brw_context.h" |
||
42 | #include "intel_screen.h" |
||
43 | #include "intel_blit.h" |
||
44 | #include "intel_buffers.h" |
||
45 | #include "intel_fbo.h" |
||
46 | #include "intel_mipmap_tree.h" |
||
47 | #include "intel_pixel.h" |
||
48 | #include "intel_buffer_objects.h" |
||
49 | |||
50 | #define FILE_DEBUG_FLAG DEBUG_PIXEL |
||
51 | |||
52 | static bool |
||
53 | do_blit_drawpixels(struct gl_context * ctx, |
||
54 | GLint x, GLint y, GLsizei width, GLsizei height, |
||
55 | GLenum format, GLenum type, |
||
56 | const struct gl_pixelstore_attrib *unpack, |
||
57 | const GLvoid * pixels) |
||
58 | { |
||
59 | struct brw_context *brw = brw_context(ctx); |
||
60 | struct intel_buffer_object *src = intel_buffer_object(unpack->BufferObj); |
||
61 | GLuint src_offset; |
||
62 | drm_intel_bo *src_buffer; |
||
63 | |||
64 | DBG("%s\n", __func__); |
||
65 | |||
66 | if (!intel_check_blit_fragment_ops(ctx, false)) |
||
67 | return false; |
||
68 | |||
69 | if (ctx->DrawBuffer->_NumColorDrawBuffers != 1) { |
||
70 | DBG("%s: fallback due to MRT\n", __func__); |
||
71 | return false; |
||
72 | } |
||
73 | |||
74 | intel_prepare_render(brw); |
||
75 | |||
76 | struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; |
||
77 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
78 | |||
79 | if (!_mesa_format_matches_format_and_type(irb->mt->format, format, type, |
||
80 | false)) { |
||
81 | DBG("%s: bad format for blit\n", __func__); |
||
82 | return false; |
||
83 | } |
||
84 | |||
85 | if (unpack->SwapBytes || unpack->LsbFirst || |
||
86 | unpack->SkipPixels || unpack->SkipRows) { |
||
87 | DBG("%s: bad packing params\n", __func__); |
||
88 | return false; |
||
89 | } |
||
90 | |||
91 | int src_stride = _mesa_image_row_stride(unpack, width, format, type); |
||
92 | bool src_flip = false; |
||
93 | /* Mesa flips the src_stride for unpack->Invert, but we want our mt to have |
||
94 | * a normal src_stride. |
||
95 | */ |
||
96 | if (unpack->Invert) { |
||
97 | src_stride = -src_stride; |
||
98 | src_flip = true; |
||
99 | } |
||
100 | |||
101 | src_offset = (GLintptr)pixels; |
||
102 | src_offset += _mesa_image_offset(2, unpack, width, height, |
||
103 | format, type, 0, 0, 0); |
||
104 | |||
105 | src_buffer = intel_bufferobj_buffer(brw, src, src_offset, |
||
106 | height * src_stride); |
||
107 | |||
108 | struct intel_mipmap_tree *pbo_mt = |
||
109 | intel_miptree_create_for_bo(brw, |
||
110 | src_buffer, |
||
111 | irb->mt->format, |
||
112 | src_offset, |
||
113 | width, height, 1, |
||
114 | src_stride, |
||
115 | false /*disable_aux_buffers*/); |
||
116 | if (!pbo_mt) |
||
117 | return false; |
||
118 | |||
119 | if (!intel_miptree_blit(brw, |
||
120 | pbo_mt, 0, 0, |
||
121 | 0, 0, src_flip, |
||
122 | irb->mt, irb->mt_level, irb->mt_layer, |
||
123 | x, y, _mesa_is_winsys_fbo(ctx->DrawBuffer), |
||
124 | width, height, GL_COPY)) { |
||
125 | DBG("%s: blit failed\n", __func__); |
||
126 | intel_miptree_release(&pbo_mt); |
||
127 | return false; |
||
128 | } |
||
129 | |||
130 | intel_miptree_release(&pbo_mt); |
||
131 | |||
132 | if (ctx->Query.CurrentOcclusionObject) |
||
133 | ctx->Query.CurrentOcclusionObject->Result += width * height; |
||
134 | |||
135 | DBG("%s: success\n", __func__); |
||
136 | return true; |
||
137 | } |
||
138 | |||
139 | void |
||
140 | intelDrawPixels(struct gl_context * ctx, |
||
141 | GLint x, GLint y, |
||
142 | GLsizei width, GLsizei height, |
||
143 | GLenum format, |
||
144 | GLenum type, |
||
145 | const struct gl_pixelstore_attrib *unpack, |
||
146 | const GLvoid * pixels) |
||
147 | { |
||
148 | struct brw_context *brw = brw_context(ctx); |
||
149 | |||
150 | if (!_mesa_check_conditional_render(ctx)) |
||
151 | return; |
||
152 | |||
153 | if (format == GL_STENCIL_INDEX) { |
||
154 | _swrast_DrawPixels(ctx, x, y, width, height, format, type, |
||
155 | unpack, pixels); |
||
156 | return; |
||
157 | } |
||
158 | |||
159 | if (_mesa_is_bufferobj(unpack->BufferObj)) { |
||
160 | if (do_blit_drawpixels(ctx, x, y, width, height, format, type, unpack, |
||
161 | pixels)) { |
||
162 | return; |
||
163 | } |
||
164 | |||
165 | perf_debug("%s: fallback to generic code in PBO case\n", __func__); |
||
166 | } |
||
167 | |||
168 | _mesa_meta_DrawPixels(ctx, x, y, width, height, format, type, |
||
169 | unpack, pixels); |
||
170 | } |