Rev 4358 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4358 | Rev 4548 | ||
---|---|---|---|
1 | /************************************************************************** |
1 | /************************************************************************** |
2 | * |
2 | * |
3 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
3 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
4 | * All Rights Reserved. |
4 | * All Rights Reserved. |
5 | * |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the |
7 | * copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including |
8 | * "Software"), to deal in the Software without restriction, including |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
10 | * distribute, sub license, and/or sell copies of the Software, and to |
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 |
11 | * permit persons to whom the Software is furnished to do so, subject to |
12 | * the following conditions: |
12 | * the following conditions: |
13 | * |
13 | * |
14 | * The above copyright notice and this permission notice (including the |
14 | * The above copyright notice and this permission notice (including the |
15 | * next paragraph) shall be included in all copies or substantial portions |
15 | * next paragraph) shall be included in all copies or substantial portions |
16 | * of the Software. |
16 | * of the Software. |
17 | * |
17 | * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
21 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
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, |
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 |
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | * |
25 | * |
26 | **************************************************************************/ |
26 | **************************************************************************/ |
27 | 27 | ||
28 | #include |
28 | #include |
29 | #include |
29 | #include |
30 | #include "main/glheader.h" |
30 | #include "main/glheader.h" |
31 | #include "main/context.h" |
31 | #include "main/context.h" |
32 | #include "main/framebuffer.h" |
32 | #include "main/framebuffer.h" |
33 | #include "main/renderbuffer.h" |
33 | #include "main/renderbuffer.h" |
34 | #include "main/texobj.h" |
34 | #include "main/texobj.h" |
35 | #include "main/hash.h" |
35 | #include "main/hash.h" |
36 | #include "main/fbobject.h" |
36 | #include "main/fbobject.h" |
37 | #include "main/version.h" |
37 | #include "main/version.h" |
38 | #include "swrast/s_renderbuffer.h" |
38 | #include "swrast/s_renderbuffer.h" |
39 | 39 | ||
40 | #include "utils.h" |
40 | #include "utils.h" |
41 | #include "xmlpool.h" |
41 | #include "xmlpool.h" |
42 | 42 | ||
43 | PUBLIC const char __driConfigOptions[] = |
43 | PUBLIC const char __driConfigOptions[] = |
44 | DRI_CONF_BEGIN |
44 | DRI_CONF_BEGIN |
45 | DRI_CONF_SECTION_PERFORMANCE |
45 | DRI_CONF_SECTION_PERFORMANCE |
46 | DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC) |
46 | DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC) |
47 | /* Options correspond to DRI_CONF_BO_REUSE_DISABLED, |
47 | /* Options correspond to DRI_CONF_BO_REUSE_DISABLED, |
48 | * DRI_CONF_BO_REUSE_ALL |
48 | * DRI_CONF_BO_REUSE_ALL |
49 | */ |
49 | */ |
50 | DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1") |
50 | DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1") |
51 | DRI_CONF_DESC_BEGIN(en, "Buffer object reuse") |
51 | DRI_CONF_DESC_BEGIN(en, "Buffer object reuse") |
52 | DRI_CONF_ENUM(0, "Disable buffer object reuse") |
52 | DRI_CONF_ENUM(0, "Disable buffer object reuse") |
53 | DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects") |
53 | DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects") |
54 | DRI_CONF_DESC_END |
54 | DRI_CONF_DESC_END |
55 | DRI_CONF_OPT_END |
55 | DRI_CONF_OPT_END |
56 | 56 | ||
57 | DRI_CONF_OPT_BEGIN_B(early_z, "false") |
57 | DRI_CONF_OPT_BEGIN_B(early_z, "false") |
58 | DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).") |
58 | DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).") |
59 | DRI_CONF_OPT_END |
59 | DRI_CONF_OPT_END |
60 | 60 | ||
61 | DRI_CONF_SECTION_END |
61 | DRI_CONF_SECTION_END |
62 | DRI_CONF_SECTION_QUALITY |
62 | DRI_CONF_SECTION_QUALITY |
63 | DRI_CONF_FORCE_S3TC_ENABLE("false") |
63 | DRI_CONF_FORCE_S3TC_ENABLE("false") |
64 | DRI_CONF_SECTION_END |
64 | DRI_CONF_SECTION_END |
65 | DRI_CONF_SECTION_DEBUG |
65 | DRI_CONF_SECTION_DEBUG |
66 | DRI_CONF_NO_RAST("false") |
66 | DRI_CONF_NO_RAST("false") |
67 | DRI_CONF_ALWAYS_FLUSH_BATCH("false") |
67 | DRI_CONF_ALWAYS_FLUSH_BATCH("false") |
68 | DRI_CONF_ALWAYS_FLUSH_CACHE("false") |
68 | DRI_CONF_ALWAYS_FLUSH_CACHE("false") |
69 | DRI_CONF_DISABLE_THROTTLING("false") |
69 | DRI_CONF_DISABLE_THROTTLING("false") |
70 | DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false") |
70 | DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false") |
71 | DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false") |
71 | DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false") |
72 | DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false") |
72 | DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false") |
73 | 73 | ||
74 | DRI_CONF_OPT_BEGIN_B(shader_precompile, "true") |
74 | DRI_CONF_OPT_BEGIN_B(shader_precompile, "true") |
75 | DRI_CONF_DESC(en, "Perform code generation at shader link time.") |
75 | DRI_CONF_DESC(en, "Perform code generation at shader link time.") |
76 | DRI_CONF_OPT_END |
76 | DRI_CONF_OPT_END |
77 | DRI_CONF_SECTION_END |
77 | DRI_CONF_SECTION_END |
78 | DRI_CONF_END; |
78 | DRI_CONF_END; |
79 | 79 | ||
80 | const GLuint __driNConfigOptions = 12; |
80 | const GLuint __driNConfigOptions = 12; |
81 | 81 | ||
82 | #include "intel_batchbuffer.h" |
82 | #include "intel_batchbuffer.h" |
83 | #include "intel_buffers.h" |
83 | #include "intel_buffers.h" |
84 | #include "intel_bufmgr.h" |
84 | #include "intel_bufmgr.h" |
85 | #include "intel_chipset.h" |
85 | #include "intel_chipset.h" |
86 | #include "intel_fbo.h" |
86 | #include "intel_fbo.h" |
87 | #include "intel_mipmap_tree.h" |
87 | #include "intel_mipmap_tree.h" |
88 | #include "intel_screen.h" |
88 | #include "intel_screen.h" |
89 | #include "intel_tex.h" |
89 | #include "intel_tex.h" |
90 | #include "intel_regions.h" |
90 | #include "intel_regions.h" |
91 | 91 | ||
92 | #include "i915_drm.h" |
92 | #include "i915_drm.h" |
93 | 93 | ||
94 | #ifdef USE_NEW_INTERFACE |
94 | #ifdef USE_NEW_INTERFACE |
95 | static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; |
95 | static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; |
96 | #endif /*USE_NEW_INTERFACE */ |
96 | #endif /*USE_NEW_INTERFACE */ |
97 | 97 | ||
98 | /** |
98 | /** |
99 | * For debugging purposes, this returns a time in seconds. |
99 | * For debugging purposes, this returns a time in seconds. |
100 | */ |
100 | */ |
101 | double |
101 | double |
102 | get_time(void) |
102 | get_time(void) |
103 | { |
103 | { |
104 | struct timespec tp; |
104 | struct timespec tp; |
105 | 105 | ||
106 | clock_gettime(CLOCK_MONOTONIC, &tp); |
106 | // clock_gettime(CLOCK_MONOTONIC, &tp); |
107 | 107 | ||
108 | return tp.tv_sec + tp.tv_nsec / 1000000000.0; |
108 | return tp.tv_sec + tp.tv_nsec / 1000000000.0; |
109 | } |
109 | } |
110 | 110 | ||
111 | void |
111 | void |
112 | aub_dump_bmp(struct gl_context *ctx) |
112 | aub_dump_bmp(struct gl_context *ctx) |
113 | { |
113 | { |
114 | struct gl_framebuffer *fb = ctx->DrawBuffer; |
114 | struct gl_framebuffer *fb = ctx->DrawBuffer; |
115 | 115 | ||
116 | for (int i = 0; i < fb->_NumColorDrawBuffers; i++) { |
116 | for (int i = 0; i < fb->_NumColorDrawBuffers; i++) { |
117 | struct intel_renderbuffer *irb = |
117 | struct intel_renderbuffer *irb = |
118 | intel_renderbuffer(fb->_ColorDrawBuffers[i]); |
118 | intel_renderbuffer(fb->_ColorDrawBuffers[i]); |
119 | 119 | ||
120 | if (irb && irb->mt) { |
120 | if (irb && irb->mt) { |
121 | enum aub_dump_bmp_format format; |
121 | enum aub_dump_bmp_format format; |
122 | 122 | ||
123 | switch (irb->Base.Base.Format) { |
123 | switch (irb->Base.Base.Format) { |
124 | case MESA_FORMAT_ARGB8888: |
124 | case MESA_FORMAT_ARGB8888: |
125 | case MESA_FORMAT_XRGB8888: |
125 | case MESA_FORMAT_XRGB8888: |
126 | format = AUB_DUMP_BMP_FORMAT_ARGB_8888; |
126 | format = AUB_DUMP_BMP_FORMAT_ARGB_8888; |
127 | break; |
127 | break; |
128 | default: |
128 | default: |
129 | continue; |
129 | continue; |
130 | } |
130 | } |
131 | 131 | ||
132 | assert(irb->mt->region->pitch % irb->mt->region->cpp == 0); |
132 | assert(irb->mt->region->pitch % irb->mt->region->cpp == 0); |
133 | drm_intel_gem_bo_aub_dump_bmp(irb->mt->region->bo, |
133 | drm_intel_gem_bo_aub_dump_bmp(irb->mt->region->bo, |
134 | irb->draw_x, |
134 | irb->draw_x, |
135 | irb->draw_y, |
135 | irb->draw_y, |
136 | irb->Base.Base.Width, |
136 | irb->Base.Base.Width, |
137 | irb->Base.Base.Height, |
137 | irb->Base.Base.Height, |
138 | format, |
138 | format, |
139 | irb->mt->region->pitch, |
139 | irb->mt->region->pitch, |
140 | 0); |
140 | 0); |
141 | } |
141 | } |
142 | } |
142 | } |
143 | } |
143 | } |
144 | 144 | ||
145 | static const __DRItexBufferExtension intelTexBufferExtension = { |
145 | static const __DRItexBufferExtension intelTexBufferExtension = { |
146 | .base = { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, |
146 | .base = { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, |
147 | 147 | ||
148 | .setTexBuffer = intelSetTexBuffer, |
148 | .setTexBuffer = intelSetTexBuffer, |
149 | .setTexBuffer2 = intelSetTexBuffer2, |
149 | .setTexBuffer2 = intelSetTexBuffer2, |
150 | .releaseTexBuffer = NULL, |
150 | .releaseTexBuffer = NULL, |
151 | }; |
151 | }; |
152 | 152 | ||
153 | static void |
153 | static void |
154 | intelDRI2Flush(__DRIdrawable *drawable) |
154 | intelDRI2Flush(__DRIdrawable *drawable) |
155 | { |
155 | { |
156 | GET_CURRENT_CONTEXT(ctx); |
156 | GET_CURRENT_CONTEXT(ctx); |
157 | struct intel_context *intel = intel_context(ctx); |
157 | struct intel_context *intel = intel_context(ctx); |
158 | if (intel == NULL) |
158 | if (intel == NULL) |
159 | return; |
159 | return; |
160 | 160 | ||
161 | INTEL_FIREVERTICES(intel); |
161 | INTEL_FIREVERTICES(intel); |
162 | 162 | ||
163 | intel->need_throttle = true; |
163 | intel->need_throttle = true; |
164 | 164 | ||
165 | if (intel->batch.used) |
165 | if (intel->batch.used) |
166 | intel_batchbuffer_flush(intel); |
166 | intel_batchbuffer_flush(intel); |
167 | 167 | ||
168 | if (INTEL_DEBUG & DEBUG_AUB) { |
168 | if (INTEL_DEBUG & DEBUG_AUB) { |
169 | aub_dump_bmp(ctx); |
169 | aub_dump_bmp(ctx); |
170 | } |
170 | } |
171 | } |
171 | } |
172 | 172 | ||
173 | static const struct __DRI2flushExtensionRec intelFlushExtension = { |
173 | static const struct __DRI2flushExtensionRec intelFlushExtension = { |
174 | .base = { __DRI2_FLUSH, 3 }, |
174 | .base = { __DRI2_FLUSH, 3 }, |
175 | 175 | ||
176 | .flush = intelDRI2Flush, |
176 | .flush = intelDRI2Flush, |
177 | .invalidate = dri2InvalidateDrawable, |
177 | .invalidate = dri2InvalidateDrawable, |
178 | }; |
178 | }; |
179 | 179 | ||
180 | static struct intel_image_format intel_image_formats[] = { |
180 | static struct intel_image_format intel_image_formats[] = { |
181 | { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
181 | { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, |
182 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }, |
182 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }, |
183 | 183 | ||
184 | { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1, |
184 | { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1, |
185 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, |
185 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, |
186 | 186 | ||
187 | { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
187 | { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
188 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
188 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
189 | { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, |
189 | { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, |
190 | { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
190 | { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
191 | 191 | ||
192 | { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
192 | { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
193 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
193 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
194 | { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
194 | { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
195 | { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
195 | { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
196 | 196 | ||
197 | { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
197 | { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
198 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
198 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
199 | { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, |
199 | { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, |
200 | { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
200 | { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
201 | 201 | ||
202 | { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
202 | { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
203 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
203 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
204 | { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
204 | { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
205 | { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
205 | { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
206 | 206 | ||
207 | { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
207 | { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, |
208 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
208 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
209 | { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
209 | { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
210 | { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
210 | { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, |
211 | 211 | ||
212 | { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
212 | { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
213 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
213 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
214 | { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
214 | { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
215 | 215 | ||
216 | { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
216 | { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2, |
217 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
217 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, |
218 | { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
218 | { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, |
219 | 219 | ||
220 | /* For YUYV buffers, we set up two overlapping DRI images and treat |
220 | /* For YUYV buffers, we set up two overlapping DRI images and treat |
221 | * them as planar buffers in the compositors. Plane 0 is GR88 and |
221 | * them as planar buffers in the compositors. Plane 0 is GR88 and |
222 | * samples YU or YV pairs and places Y into the R component, while |
222 | * samples YU or YV pairs and places Y into the R component, while |
223 | * plane 1 is ARGB and samples YUYV clusters and places pairs and |
223 | * plane 1 is ARGB and samples YUYV clusters and places pairs and |
224 | * places U into the G component and V into A. This lets the |
224 | * places U into the G component and V into A. This lets the |
225 | * texture sampler interpolate the Y components correctly when |
225 | * texture sampler interpolate the Y components correctly when |
226 | * sampling from plane 0, and interpolate U and V correctly when |
226 | * sampling from plane 0, and interpolate U and V correctly when |
227 | * sampling from plane 1. */ |
227 | * sampling from plane 1. */ |
228 | { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2, |
228 | { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2, |
229 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, |
229 | { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, |
230 | { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } |
230 | { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } |
231 | }; |
231 | }; |
232 | 232 | ||
233 | static __DRIimage * |
233 | static __DRIimage * |
234 | intel_allocate_image(int dri_format, void *loaderPrivate) |
234 | intel_allocate_image(int dri_format, void *loaderPrivate) |
235 | { |
235 | { |
236 | __DRIimage *image; |
236 | __DRIimage *image; |
237 | 237 | ||
238 | image = calloc(1, sizeof *image); |
238 | image = calloc(1, sizeof *image); |
239 | if (image == NULL) |
239 | if (image == NULL) |
240 | return NULL; |
240 | return NULL; |
241 | 241 | ||
242 | image->dri_format = dri_format; |
242 | image->dri_format = dri_format; |
243 | image->offset = 0; |
243 | image->offset = 0; |
244 | 244 | ||
245 | switch (dri_format) { |
245 | switch (dri_format) { |
246 | case __DRI_IMAGE_FORMAT_RGB565: |
246 | case __DRI_IMAGE_FORMAT_RGB565: |
247 | image->format = MESA_FORMAT_RGB565; |
247 | image->format = MESA_FORMAT_RGB565; |
248 | break; |
248 | break; |
249 | case __DRI_IMAGE_FORMAT_XRGB8888: |
249 | case __DRI_IMAGE_FORMAT_XRGB8888: |
250 | image->format = MESA_FORMAT_XRGB8888; |
250 | image->format = MESA_FORMAT_XRGB8888; |
251 | break; |
251 | break; |
252 | case __DRI_IMAGE_FORMAT_ARGB8888: |
252 | case __DRI_IMAGE_FORMAT_ARGB8888: |
253 | image->format = MESA_FORMAT_ARGB8888; |
253 | image->format = MESA_FORMAT_ARGB8888; |
254 | break; |
254 | break; |
255 | case __DRI_IMAGE_FORMAT_ABGR8888: |
255 | case __DRI_IMAGE_FORMAT_ABGR8888: |
256 | image->format = MESA_FORMAT_RGBA8888_REV; |
256 | image->format = MESA_FORMAT_RGBA8888_REV; |
257 | break; |
257 | break; |
258 | case __DRI_IMAGE_FORMAT_XBGR8888: |
258 | case __DRI_IMAGE_FORMAT_XBGR8888: |
259 | image->format = MESA_FORMAT_RGBX8888_REV; |
259 | image->format = MESA_FORMAT_RGBX8888_REV; |
260 | break; |
260 | break; |
261 | case __DRI_IMAGE_FORMAT_R8: |
261 | case __DRI_IMAGE_FORMAT_R8: |
262 | image->format = MESA_FORMAT_R8; |
262 | image->format = MESA_FORMAT_R8; |
263 | break; |
263 | break; |
264 | case __DRI_IMAGE_FORMAT_GR88: |
264 | case __DRI_IMAGE_FORMAT_GR88: |
265 | image->format = MESA_FORMAT_GR88; |
265 | image->format = MESA_FORMAT_GR88; |
266 | break; |
266 | break; |
267 | case __DRI_IMAGE_FORMAT_NONE: |
267 | case __DRI_IMAGE_FORMAT_NONE: |
268 | image->format = MESA_FORMAT_NONE; |
268 | image->format = MESA_FORMAT_NONE; |
269 | break; |
269 | break; |
270 | default: |
270 | default: |
271 | free(image); |
271 | free(image); |
272 | return NULL; |
272 | return NULL; |
273 | } |
273 | } |
274 | 274 | ||
275 | image->internal_format = _mesa_get_format_base_format(image->format); |
275 | image->internal_format = _mesa_get_format_base_format(image->format); |
276 | image->data = loaderPrivate; |
276 | image->data = loaderPrivate; |
277 | 277 | ||
278 | return image; |
278 | return image; |
279 | } |
279 | } |
280 | 280 | ||
281 | /** |
281 | /** |
282 | * Sets up a DRIImage structure to point to our shared image in a region |
282 | * Sets up a DRIImage structure to point to our shared image in a region |
283 | */ |
283 | */ |
284 | static void |
284 | static void |
285 | intel_setup_image_from_mipmap_tree(struct intel_context *intel, __DRIimage *image, |
285 | intel_setup_image_from_mipmap_tree(struct intel_context *intel, __DRIimage *image, |
286 | struct intel_mipmap_tree *mt, GLuint level, |
286 | struct intel_mipmap_tree *mt, GLuint level, |
287 | GLuint zoffset) |
287 | GLuint zoffset) |
288 | { |
288 | { |
289 | unsigned int draw_x, draw_y; |
289 | unsigned int draw_x, draw_y; |
290 | uint32_t mask_x, mask_y; |
290 | uint32_t mask_x, mask_y; |
291 | 291 | ||
292 | intel_miptree_check_level_layer(mt, level, zoffset); |
292 | intel_miptree_check_level_layer(mt, level, zoffset); |
293 | 293 | ||
294 | intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false); |
294 | intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false); |
295 | intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y); |
295 | intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y); |
296 | 296 | ||
297 | image->width = mt->level[level].width; |
297 | image->width = mt->level[level].width; |
298 | image->height = mt->level[level].height; |
298 | image->height = mt->level[level].height; |
299 | image->tile_x = draw_x & mask_x; |
299 | image->tile_x = draw_x & mask_x; |
300 | image->tile_y = draw_y & mask_y; |
300 | image->tile_y = draw_y & mask_y; |
301 | 301 | ||
302 | image->offset = intel_region_get_aligned_offset(mt->region, |
302 | image->offset = intel_region_get_aligned_offset(mt->region, |
303 | draw_x & ~mask_x, |
303 | draw_x & ~mask_x, |
304 | draw_y & ~mask_y, |
304 | draw_y & ~mask_y, |
305 | false); |
305 | false); |
306 | 306 | ||
307 | intel_region_reference(&image->region, mt->region); |
307 | intel_region_reference(&image->region, mt->region); |
308 | } |
308 | } |
309 | 309 | ||
310 | static void |
310 | static void |
311 | intel_setup_image_from_dimensions(__DRIimage *image) |
311 | intel_setup_image_from_dimensions(__DRIimage *image) |
312 | { |
312 | { |
313 | image->width = image->region->width; |
313 | image->width = image->region->width; |
314 | image->height = image->region->height; |
314 | image->height = image->region->height; |
315 | image->tile_x = 0; |
315 | image->tile_x = 0; |
316 | image->tile_y = 0; |
316 | image->tile_y = 0; |
317 | } |
317 | } |
318 | 318 | ||
319 | static inline uint32_t |
319 | static inline uint32_t |
320 | intel_dri_format(GLuint format) |
320 | intel_dri_format(GLuint format) |
321 | { |
321 | { |
322 | switch (format) { |
322 | switch (format) { |
323 | case MESA_FORMAT_RGB565: |
323 | case MESA_FORMAT_RGB565: |
324 | return __DRI_IMAGE_FORMAT_RGB565; |
324 | return __DRI_IMAGE_FORMAT_RGB565; |
325 | case MESA_FORMAT_XRGB8888: |
325 | case MESA_FORMAT_XRGB8888: |
326 | return __DRI_IMAGE_FORMAT_XRGB8888; |
326 | return __DRI_IMAGE_FORMAT_XRGB8888; |
327 | case MESA_FORMAT_ARGB8888: |
327 | case MESA_FORMAT_ARGB8888: |
328 | return __DRI_IMAGE_FORMAT_ARGB8888; |
328 | return __DRI_IMAGE_FORMAT_ARGB8888; |
329 | case MESA_FORMAT_RGBA8888_REV: |
329 | case MESA_FORMAT_RGBA8888_REV: |
330 | return __DRI_IMAGE_FORMAT_ABGR8888; |
330 | return __DRI_IMAGE_FORMAT_ABGR8888; |
331 | case MESA_FORMAT_R8: |
331 | case MESA_FORMAT_R8: |
332 | return __DRI_IMAGE_FORMAT_R8; |
332 | return __DRI_IMAGE_FORMAT_R8; |
333 | case MESA_FORMAT_RG88: |
333 | case MESA_FORMAT_RG88: |
334 | return __DRI_IMAGE_FORMAT_GR88; |
334 | return __DRI_IMAGE_FORMAT_GR88; |
335 | } |
335 | } |
336 | 336 | ||
337 | return MESA_FORMAT_NONE; |
337 | return MESA_FORMAT_NONE; |
338 | } |
338 | } |
339 | 339 | ||
340 | static __DRIimage * |
340 | static __DRIimage * |
341 | intel_create_image_from_name(__DRIscreen *screen, |
341 | intel_create_image_from_name(__DRIscreen *screen, |
342 | int width, int height, int format, |
342 | int width, int height, int format, |
343 | int name, int pitch, void *loaderPrivate) |
343 | int name, int pitch, void *loaderPrivate) |
344 | { |
344 | { |
345 | struct intel_screen *intelScreen = screen->driverPrivate; |
345 | struct intel_screen *intelScreen = screen->driverPrivate; |
346 | __DRIimage *image; |
346 | __DRIimage *image; |
347 | int cpp; |
347 | int cpp; |
348 | 348 | ||
349 | image = intel_allocate_image(format, loaderPrivate); |
349 | image = intel_allocate_image(format, loaderPrivate); |
350 | if (image == NULL) |
350 | if (image == NULL) |
351 | return NULL; |
351 | return NULL; |
352 | 352 | ||
353 | if (image->format == MESA_FORMAT_NONE) |
353 | if (image->format == MESA_FORMAT_NONE) |
354 | cpp = 1; |
354 | cpp = 1; |
355 | else |
355 | else |
356 | cpp = _mesa_get_format_bytes(image->format); |
356 | cpp = _mesa_get_format_bytes(image->format); |
357 | image->region = intel_region_alloc_for_handle(intelScreen, |
357 | image->region = intel_region_alloc_for_handle(intelScreen, |
358 | cpp, width, height, |
358 | cpp, width, height, |
359 | pitch * cpp, name, "image"); |
359 | pitch * cpp, name, "image"); |
360 | if (image->region == NULL) { |
360 | if (image->region == NULL) { |
361 | free(image); |
361 | free(image); |
362 | return NULL; |
362 | return NULL; |
363 | } |
363 | } |
364 | 364 | ||
365 | intel_setup_image_from_dimensions(image); |
365 | intel_setup_image_from_dimensions(image); |
366 | 366 | ||
367 | return image; |
367 | return image; |
368 | } |
368 | } |
369 | 369 | ||
370 | static __DRIimage * |
370 | static __DRIimage * |
371 | intel_create_image_from_renderbuffer(__DRIcontext *context, |
371 | intel_create_image_from_renderbuffer(__DRIcontext *context, |
372 | int renderbuffer, void *loaderPrivate) |
372 | int renderbuffer, void *loaderPrivate) |
373 | { |
373 | { |
374 | __DRIimage *image; |
374 | __DRIimage *image; |
375 | struct intel_context *intel = context->driverPrivate; |
375 | struct intel_context *intel = context->driverPrivate; |
376 | struct gl_renderbuffer *rb; |
376 | struct gl_renderbuffer *rb; |
377 | struct intel_renderbuffer *irb; |
377 | struct intel_renderbuffer *irb; |
378 | 378 | ||
379 | rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer); |
379 | rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer); |
380 | if (!rb) { |
380 | if (!rb) { |
381 | _mesa_error(&intel->ctx, |
381 | _mesa_error(&intel->ctx, |
382 | GL_INVALID_OPERATION, "glRenderbufferExternalMESA"); |
382 | GL_INVALID_OPERATION, "glRenderbufferExternalMESA"); |
383 | return NULL; |
383 | return NULL; |
384 | } |
384 | } |
385 | 385 | ||
386 | irb = intel_renderbuffer(rb); |
386 | irb = intel_renderbuffer(rb); |
387 | image = calloc(1, sizeof *image); |
387 | image = calloc(1, sizeof *image); |
388 | if (image == NULL) |
388 | if (image == NULL) |
389 | return NULL; |
389 | return NULL; |
390 | 390 | ||
391 | image->internal_format = rb->InternalFormat; |
391 | image->internal_format = rb->InternalFormat; |
392 | image->format = rb->Format; |
392 | image->format = rb->Format; |
393 | image->offset = 0; |
393 | image->offset = 0; |
394 | image->data = loaderPrivate; |
394 | image->data = loaderPrivate; |
395 | intel_region_reference(&image->region, irb->mt->region); |
395 | intel_region_reference(&image->region, irb->mt->region); |
396 | intel_setup_image_from_dimensions(image); |
396 | intel_setup_image_from_dimensions(image); |
397 | image->dri_format = intel_dri_format(image->format); |
397 | image->dri_format = intel_dri_format(image->format); |
398 | 398 | ||
399 | rb->NeedsFinishRenderTexture = true; |
399 | rb->NeedsFinishRenderTexture = true; |
400 | return image; |
400 | return image; |
401 | } |
401 | } |
402 | 402 | ||
403 | static __DRIimage * |
403 | static __DRIimage * |
404 | intel_create_image_from_texture(__DRIcontext *context, int target, |
404 | intel_create_image_from_texture(__DRIcontext *context, int target, |
405 | unsigned texture, int zoffset, |
405 | unsigned texture, int zoffset, |
406 | int level, |
406 | int level, |
407 | unsigned *error, |
407 | unsigned *error, |
408 | void *loaderPrivate) |
408 | void *loaderPrivate) |
409 | { |
409 | { |
410 | __DRIimage *image; |
410 | __DRIimage *image; |
411 | struct intel_context *intel = context->driverPrivate; |
411 | struct intel_context *intel = context->driverPrivate; |
412 | struct gl_texture_object *obj; |
412 | struct gl_texture_object *obj; |
413 | struct intel_texture_object *iobj; |
413 | struct intel_texture_object *iobj; |
414 | GLuint face = 0; |
414 | GLuint face = 0; |
415 | 415 | ||
416 | obj = _mesa_lookup_texture(&intel->ctx, texture); |
416 | obj = _mesa_lookup_texture(&intel->ctx, texture); |
417 | if (!obj || obj->Target != target) { |
417 | if (!obj || obj->Target != target) { |
418 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
418 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
419 | return NULL; |
419 | return NULL; |
420 | } |
420 | } |
421 | 421 | ||
422 | if (target == GL_TEXTURE_CUBE_MAP) |
422 | if (target == GL_TEXTURE_CUBE_MAP) |
423 | face = zoffset; |
423 | face = zoffset; |
424 | 424 | ||
425 | _mesa_test_texobj_completeness(&intel->ctx, obj); |
425 | _mesa_test_texobj_completeness(&intel->ctx, obj); |
426 | iobj = intel_texture_object(obj); |
426 | iobj = intel_texture_object(obj); |
427 | if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) { |
427 | if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) { |
428 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
428 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
429 | return NULL; |
429 | return NULL; |
430 | } |
430 | } |
431 | 431 | ||
432 | if (level < obj->BaseLevel || level > obj->_MaxLevel) { |
432 | if (level < obj->BaseLevel || level > obj->_MaxLevel) { |
433 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
433 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
434 | return NULL; |
434 | return NULL; |
435 | } |
435 | } |
436 | 436 | ||
437 | if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < zoffset) { |
437 | if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < zoffset) { |
438 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
438 | *error = __DRI_IMAGE_ERROR_BAD_MATCH; |
439 | return NULL; |
439 | return NULL; |
440 | } |
440 | } |
441 | image = calloc(1, sizeof *image); |
441 | image = calloc(1, sizeof *image); |
442 | if (image == NULL) { |
442 | if (image == NULL) { |
443 | *error = __DRI_IMAGE_ERROR_BAD_ALLOC; |
443 | *error = __DRI_IMAGE_ERROR_BAD_ALLOC; |
444 | return NULL; |
444 | return NULL; |
445 | } |
445 | } |
446 | 446 | ||
447 | image->internal_format = obj->Image[face][level]->InternalFormat; |
447 | image->internal_format = obj->Image[face][level]->InternalFormat; |
448 | image->format = obj->Image[face][level]->TexFormat; |
448 | image->format = obj->Image[face][level]->TexFormat; |
449 | image->data = loaderPrivate; |
449 | image->data = loaderPrivate; |
450 | intel_setup_image_from_mipmap_tree(intel, image, iobj->mt, level, zoffset); |
450 | intel_setup_image_from_mipmap_tree(intel, image, iobj->mt, level, zoffset); |
451 | image->dri_format = intel_dri_format(image->format); |
451 | image->dri_format = intel_dri_format(image->format); |
452 | if (image->dri_format == MESA_FORMAT_NONE) { |
452 | if (image->dri_format == MESA_FORMAT_NONE) { |
453 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
453 | *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; |
454 | free(image); |
454 | free(image); |
455 | return NULL; |
455 | return NULL; |
456 | } |
456 | } |
457 | 457 | ||
458 | *error = __DRI_IMAGE_ERROR_SUCCESS; |
458 | *error = __DRI_IMAGE_ERROR_SUCCESS; |
459 | return image; |
459 | return image; |
460 | } |
460 | } |
461 | 461 | ||
462 | static void |
462 | static void |
463 | intel_destroy_image(__DRIimage *image) |
463 | intel_destroy_image(__DRIimage *image) |
464 | { |
464 | { |
465 | intel_region_release(&image->region); |
465 | intel_region_release(&image->region); |
466 | free(image); |
466 | free(image); |
467 | } |
467 | } |
468 | 468 | ||
469 | static __DRIimage * |
469 | static __DRIimage * |
470 | intel_create_image(__DRIscreen *screen, |
470 | intel_create_image(__DRIscreen *screen, |
471 | int width, int height, int format, |
471 | int width, int height, int format, |
472 | unsigned int use, |
472 | unsigned int use, |
473 | void *loaderPrivate) |
473 | void *loaderPrivate) |
474 | { |
474 | { |
475 | __DRIimage *image; |
475 | __DRIimage *image; |
476 | struct intel_screen *intelScreen = screen->driverPrivate; |
476 | struct intel_screen *intelScreen = screen->driverPrivate; |
477 | uint32_t tiling; |
477 | uint32_t tiling; |
478 | int cpp; |
478 | int cpp; |
479 | 479 | ||
480 | tiling = I915_TILING_X; |
480 | tiling = I915_TILING_X; |
481 | if (use & __DRI_IMAGE_USE_CURSOR) { |
481 | if (use & __DRI_IMAGE_USE_CURSOR) { |
482 | if (width != 64 || height != 64) |
482 | if (width != 64 || height != 64) |
483 | return NULL; |
483 | return NULL; |
484 | tiling = I915_TILING_NONE; |
484 | tiling = I915_TILING_NONE; |
485 | } |
485 | } |
486 | 486 | ||
487 | image = intel_allocate_image(format, loaderPrivate); |
487 | image = intel_allocate_image(format, loaderPrivate); |
488 | if (image == NULL) |
488 | if (image == NULL) |
489 | return NULL; |
489 | return NULL; |
490 | 490 | ||
491 | cpp = _mesa_get_format_bytes(image->format); |
491 | cpp = _mesa_get_format_bytes(image->format); |
492 | image->region = |
492 | image->region = |
493 | intel_region_alloc(intelScreen, tiling, cpp, width, height, true); |
493 | intel_region_alloc(intelScreen, tiling, cpp, width, height, true); |
494 | if (image->region == NULL) { |
494 | if (image->region == NULL) { |
495 | free(image); |
495 | free(image); |
496 | return NULL; |
496 | return NULL; |
497 | } |
497 | } |
498 | 498 | ||
499 | intel_setup_image_from_dimensions(image); |
499 | intel_setup_image_from_dimensions(image); |
500 | 500 | ||
501 | return image; |
501 | return image; |
502 | } |
502 | } |
503 | 503 | ||
504 | static GLboolean |
504 | static GLboolean |
505 | intel_query_image(__DRIimage *image, int attrib, int *value) |
505 | intel_query_image(__DRIimage *image, int attrib, int *value) |
506 | { |
506 | { |
507 | switch (attrib) { |
507 | switch (attrib) { |
508 | case __DRI_IMAGE_ATTRIB_STRIDE: |
508 | case __DRI_IMAGE_ATTRIB_STRIDE: |
509 | *value = image->region->pitch; |
509 | *value = image->region->pitch; |
510 | return true; |
510 | return true; |
511 | case __DRI_IMAGE_ATTRIB_HANDLE: |
511 | case __DRI_IMAGE_ATTRIB_HANDLE: |
512 | *value = image->region->bo->handle; |
512 | *value = image->region->bo->handle; |
513 | return true; |
513 | return true; |
514 | case __DRI_IMAGE_ATTRIB_NAME: |
514 | case __DRI_IMAGE_ATTRIB_NAME: |
515 | return intel_region_flink(image->region, (uint32_t *) value); |
515 | return intel_region_flink(image->region, (uint32_t *) value); |
516 | case __DRI_IMAGE_ATTRIB_FORMAT: |
516 | case __DRI_IMAGE_ATTRIB_FORMAT: |
517 | *value = image->dri_format; |
517 | *value = image->dri_format; |
518 | return true; |
518 | return true; |
519 | case __DRI_IMAGE_ATTRIB_WIDTH: |
519 | case __DRI_IMAGE_ATTRIB_WIDTH: |
520 | *value = image->region->width; |
520 | *value = image->region->width; |
521 | return true; |
521 | return true; |
522 | case __DRI_IMAGE_ATTRIB_HEIGHT: |
522 | case __DRI_IMAGE_ATTRIB_HEIGHT: |
523 | *value = image->region->height; |
523 | *value = image->region->height; |
524 | return true; |
524 | return true; |
525 | case __DRI_IMAGE_ATTRIB_COMPONENTS: |
525 | case __DRI_IMAGE_ATTRIB_COMPONENTS: |
526 | if (image->planar_format == NULL) |
526 | if (image->planar_format == NULL) |
527 | return false; |
527 | return false; |
528 | *value = image->planar_format->components; |
528 | *value = image->planar_format->components; |
529 | return true; |
529 | return true; |
530 | case __DRI_IMAGE_ATTRIB_FD: |
530 | case __DRI_IMAGE_ATTRIB_FD: |
531 | if (drm_intel_bo_gem_export_to_prime(image->region->bo, value) == 0) |
531 | // if (drm_intel_bo_gem_export_to_prime(image->region->bo, value) == 0) |
532 | return true; |
532 | // return true; |
533 | return false; |
533 | return false; |
534 | default: |
534 | default: |
535 | return false; |
535 | return false; |
536 | } |
536 | } |
537 | } |
537 | } |
538 | 538 | ||
539 | static __DRIimage * |
539 | static __DRIimage * |
540 | intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) |
540 | intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) |
541 | { |
541 | { |
542 | __DRIimage *image; |
542 | __DRIimage *image; |
543 | 543 | ||
544 | image = calloc(1, sizeof *image); |
544 | image = calloc(1, sizeof *image); |
545 | if (image == NULL) |
545 | if (image == NULL) |
546 | return NULL; |
546 | return NULL; |
547 | 547 | ||
548 | intel_region_reference(&image->region, orig_image->region); |
548 | intel_region_reference(&image->region, orig_image->region); |
549 | if (image->region == NULL) { |
549 | if (image->region == NULL) { |
550 | free(image); |
550 | free(image); |
551 | return NULL; |
551 | return NULL; |
552 | } |
552 | } |
553 | 553 | ||
554 | image->internal_format = orig_image->internal_format; |
554 | image->internal_format = orig_image->internal_format; |
555 | image->planar_format = orig_image->planar_format; |
555 | image->planar_format = orig_image->planar_format; |
556 | image->dri_format = orig_image->dri_format; |
556 | image->dri_format = orig_image->dri_format; |
557 | image->format = orig_image->format; |
557 | image->format = orig_image->format; |
558 | image->offset = orig_image->offset; |
558 | image->offset = orig_image->offset; |
559 | image->width = orig_image->width; |
559 | image->width = orig_image->width; |
560 | image->height = orig_image->height; |
560 | image->height = orig_image->height; |
561 | image->tile_x = orig_image->tile_x; |
561 | image->tile_x = orig_image->tile_x; |
562 | image->tile_y = orig_image->tile_y; |
562 | image->tile_y = orig_image->tile_y; |
563 | image->data = loaderPrivate; |
563 | image->data = loaderPrivate; |
564 | 564 | ||
565 | memcpy(image->strides, orig_image->strides, sizeof(image->strides)); |
565 | memcpy(image->strides, orig_image->strides, sizeof(image->strides)); |
566 | memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets)); |
566 | memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets)); |
567 | 567 | ||
568 | return image; |
568 | return image; |
569 | } |
569 | } |
570 | 570 | ||
571 | static GLboolean |
571 | static GLboolean |
572 | intel_validate_usage(__DRIimage *image, unsigned int use) |
572 | intel_validate_usage(__DRIimage *image, unsigned int use) |
573 | { |
573 | { |
574 | if (use & __DRI_IMAGE_USE_CURSOR) { |
574 | if (use & __DRI_IMAGE_USE_CURSOR) { |
575 | if (image->region->width != 64 || image->region->height != 64) |
575 | if (image->region->width != 64 || image->region->height != 64) |
576 | return GL_FALSE; |
576 | return GL_FALSE; |
577 | } |
577 | } |
578 | 578 | ||
579 | return GL_TRUE; |
579 | return GL_TRUE; |
580 | } |
580 | } |
581 | 581 | ||
582 | static __DRIimage * |
582 | static __DRIimage * |
583 | intel_create_image_from_names(__DRIscreen *screen, |
583 | intel_create_image_from_names(__DRIscreen *screen, |
584 | int width, int height, int fourcc, |
584 | int width, int height, int fourcc, |
585 | int *names, int num_names, |
585 | int *names, int num_names, |
586 | int *strides, int *offsets, |
586 | int *strides, int *offsets, |
587 | void *loaderPrivate) |
587 | void *loaderPrivate) |
588 | { |
588 | { |
589 | struct intel_image_format *f = NULL; |
589 | struct intel_image_format *f = NULL; |
590 | __DRIimage *image; |
590 | __DRIimage *image; |
591 | int i, index; |
591 | int i, index; |
592 | 592 | ||
593 | if (screen == NULL || names == NULL || num_names != 1) |
593 | if (screen == NULL || names == NULL || num_names != 1) |
594 | return NULL; |
594 | return NULL; |
595 | 595 | ||
596 | for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
596 | for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
597 | if (intel_image_formats[i].fourcc == fourcc) { |
597 | if (intel_image_formats[i].fourcc == fourcc) { |
598 | f = &intel_image_formats[i]; |
598 | f = &intel_image_formats[i]; |
599 | } |
599 | } |
600 | } |
600 | } |
601 | 601 | ||
602 | if (f == NULL) |
602 | if (f == NULL) |
603 | return NULL; |
603 | return NULL; |
604 | 604 | ||
605 | image = intel_create_image_from_name(screen, width, height, |
605 | image = intel_create_image_from_name(screen, width, height, |
606 | __DRI_IMAGE_FORMAT_NONE, |
606 | __DRI_IMAGE_FORMAT_NONE, |
607 | names[0], strides[0], |
607 | names[0], strides[0], |
608 | loaderPrivate); |
608 | loaderPrivate); |
609 | 609 | ||
610 | if (image == NULL) |
610 | if (image == NULL) |
611 | return NULL; |
611 | return NULL; |
612 | 612 | ||
613 | image->planar_format = f; |
613 | image->planar_format = f; |
614 | for (i = 0; i < f->nplanes; i++) { |
614 | for (i = 0; i < f->nplanes; i++) { |
615 | index = f->planes[i].buffer_index; |
615 | index = f->planes[i].buffer_index; |
616 | image->offsets[index] = offsets[index]; |
616 | image->offsets[index] = offsets[index]; |
617 | image->strides[index] = strides[index]; |
617 | image->strides[index] = strides[index]; |
618 | } |
618 | } |
619 | 619 | ||
620 | return image; |
620 | return image; |
621 | } |
621 | } |
- | 622 | ||
622 | 623 | #if 0 |
|
623 | static __DRIimage * |
624 | static __DRIimage * |
624 | intel_create_image_from_fds(__DRIscreen *screen, |
625 | intel_create_image_from_fds(__DRIscreen *screen, |
625 | int width, int height, int fourcc, |
626 | int width, int height, int fourcc, |
626 | int *fds, int num_fds, int *strides, int *offsets, |
627 | int *fds, int num_fds, int *strides, int *offsets, |
627 | void *loaderPrivate) |
628 | void *loaderPrivate) |
628 | { |
629 | { |
629 | struct intel_screen *intelScreen = screen->driverPrivate; |
630 | struct intel_screen *intelScreen = screen->driverPrivate; |
630 | struct intel_image_format *f = NULL; |
631 | struct intel_image_format *f = NULL; |
631 | __DRIimage *image; |
632 | __DRIimage *image; |
632 | int i, index; |
633 | int i, index; |
633 | 634 | ||
634 | if (fds == NULL || num_fds != 1) |
635 | if (fds == NULL || num_fds != 1) |
635 | return NULL; |
636 | return NULL; |
636 | 637 | ||
637 | for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
638 | for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { |
638 | if (intel_image_formats[i].fourcc == fourcc) { |
639 | if (intel_image_formats[i].fourcc == fourcc) { |
639 | f = &intel_image_formats[i]; |
640 | f = &intel_image_formats[i]; |
640 | } |
641 | } |
641 | } |
642 | } |
642 | 643 | ||
643 | if (f == NULL) |
644 | if (f == NULL) |
644 | return NULL; |
645 | return NULL; |
645 | 646 | ||
646 | image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate); |
647 | image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate); |
647 | if (image == NULL) |
648 | if (image == NULL) |
648 | return NULL; |
649 | return NULL; |
649 | 650 | ||
650 | image->region = intel_region_alloc_for_fd(intelScreen, |
651 | image->region = intel_region_alloc_for_fd(intelScreen, |
651 | 1, width, height, |
652 | 1, width, height, |
652 | strides[0], fds[0], "image"); |
653 | strides[0], fds[0], "image"); |
653 | if (image->region == NULL) { |
654 | if (image->region == NULL) { |
654 | free(image); |
655 | free(image); |
655 | return NULL; |
656 | return NULL; |
656 | } |
657 | } |
657 | 658 | ||
658 | image->planar_format = f; |
659 | image->planar_format = f; |
659 | for (i = 0; i < f->nplanes; i++) { |
660 | for (i = 0; i < f->nplanes; i++) { |
660 | index = f->planes[i].buffer_index; |
661 | index = f->planes[i].buffer_index; |
661 | image->offsets[index] = offsets[index]; |
662 | image->offsets[index] = offsets[index]; |
662 | image->strides[index] = strides[index]; |
663 | image->strides[index] = strides[index]; |
663 | } |
664 | } |
664 | 665 | ||
665 | return image; |
666 | return image; |
666 | } |
667 | } |
667 | 668 | #endif |
|
668 | 669 | ||
669 | static __DRIimage * |
670 | static __DRIimage * |
670 | intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) |
671 | intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) |
671 | { |
672 | { |
672 | int width, height, offset, stride, dri_format, index; |
673 | int width, height, offset, stride, dri_format, index; |
673 | struct intel_image_format *f; |
674 | struct intel_image_format *f; |
674 | uint32_t mask_x, mask_y; |
675 | uint32_t mask_x, mask_y; |
675 | __DRIimage *image; |
676 | __DRIimage *image; |
676 | 677 | ||
677 | if (parent == NULL || parent->planar_format == NULL) |
678 | if (parent == NULL || parent->planar_format == NULL) |
678 | return NULL; |
679 | return NULL; |
679 | 680 | ||
680 | f = parent->planar_format; |
681 | f = parent->planar_format; |
681 | 682 | ||
682 | if (plane >= f->nplanes) |
683 | if (plane >= f->nplanes) |
683 | return NULL; |
684 | return NULL; |
684 | 685 | ||
685 | width = parent->region->width >> f->planes[plane].width_shift; |
686 | width = parent->region->width >> f->planes[plane].width_shift; |
686 | height = parent->region->height >> f->planes[plane].height_shift; |
687 | height = parent->region->height >> f->planes[plane].height_shift; |
687 | dri_format = f->planes[plane].dri_format; |
688 | dri_format = f->planes[plane].dri_format; |
688 | index = f->planes[plane].buffer_index; |
689 | index = f->planes[plane].buffer_index; |
689 | offset = parent->offsets[index]; |
690 | offset = parent->offsets[index]; |
690 | stride = parent->strides[index]; |
691 | stride = parent->strides[index]; |
691 | 692 | ||
692 | image = intel_allocate_image(dri_format, loaderPrivate); |
693 | image = intel_allocate_image(dri_format, loaderPrivate); |
693 | if (image == NULL) |
694 | if (image == NULL) |
694 | return NULL; |
695 | return NULL; |
695 | 696 | ||
696 | if (offset + height * stride > parent->region->bo->size) { |
697 | if (offset + height * stride > parent->region->bo->size) { |
697 | _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds"); |
698 | _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds"); |
698 | free(image); |
699 | free(image); |
699 | return NULL; |
700 | return NULL; |
700 | } |
701 | } |
701 | 702 | ||
702 | image->region = calloc(sizeof(*image->region), 1); |
703 | image->region = calloc(sizeof(*image->region), 1); |
703 | if (image->region == NULL) { |
704 | if (image->region == NULL) { |
704 | free(image); |
705 | free(image); |
705 | return NULL; |
706 | return NULL; |
706 | } |
707 | } |
707 | 708 | ||
708 | image->region->cpp = _mesa_get_format_bytes(image->format); |
709 | image->region->cpp = _mesa_get_format_bytes(image->format); |
709 | image->region->width = width; |
710 | image->region->width = width; |
710 | image->region->height = height; |
711 | image->region->height = height; |
711 | image->region->pitch = stride; |
712 | image->region->pitch = stride; |
712 | image->region->refcount = 1; |
713 | image->region->refcount = 1; |
713 | image->region->bo = parent->region->bo; |
714 | image->region->bo = parent->region->bo; |
714 | drm_intel_bo_reference(image->region->bo); |
715 | drm_intel_bo_reference(image->region->bo); |
715 | image->region->tiling = parent->region->tiling; |
716 | image->region->tiling = parent->region->tiling; |
716 | image->offset = offset; |
717 | image->offset = offset; |
717 | intel_setup_image_from_dimensions(image); |
718 | intel_setup_image_from_dimensions(image); |
718 | 719 | ||
719 | intel_region_get_tile_masks(image->region, &mask_x, &mask_y, false); |
720 | intel_region_get_tile_masks(image->region, &mask_x, &mask_y, false); |
720 | if (offset & mask_x) |
721 | if (offset & mask_x) |
721 | _mesa_warning(NULL, |
722 | _mesa_warning(NULL, |
722 | "intel_create_sub_image: offset not on tile boundary"); |
723 | "intel_create_sub_image: offset not on tile boundary"); |
723 | 724 | ||
724 | return image; |
725 | return image; |
725 | } |
726 | } |
726 | 727 | ||
727 | static struct __DRIimageExtensionRec intelImageExtension = { |
728 | static struct __DRIimageExtensionRec intelImageExtension = { |
728 | .base = { __DRI_IMAGE, 7 }, |
729 | .base = { __DRI_IMAGE, 7 }, |
729 | 730 | ||
730 | .createImageFromName = intel_create_image_from_name, |
731 | .createImageFromName = intel_create_image_from_name, |
731 | .createImageFromRenderbuffer = intel_create_image_from_renderbuffer, |
732 | .createImageFromRenderbuffer = intel_create_image_from_renderbuffer, |
732 | .destroyImage = intel_destroy_image, |
733 | .destroyImage = intel_destroy_image, |
733 | .createImage = intel_create_image, |
734 | .createImage = intel_create_image, |
734 | .queryImage = intel_query_image, |
735 | .queryImage = intel_query_image, |
735 | .dupImage = intel_dup_image, |
736 | .dupImage = intel_dup_image, |
736 | .validateUsage = intel_validate_usage, |
737 | .validateUsage = intel_validate_usage, |
737 | .createImageFromNames = intel_create_image_from_names, |
738 | .createImageFromNames = intel_create_image_from_names, |
738 | .fromPlanar = intel_from_planar, |
739 | .fromPlanar = intel_from_planar, |
739 | .createImageFromTexture = intel_create_image_from_texture, |
740 | .createImageFromTexture = intel_create_image_from_texture, |
740 | .createImageFromFds = intel_create_image_from_fds |
741 | // .createImageFromFds = intel_create_image_from_fds |
741 | }; |
742 | }; |
742 | 743 | ||
743 | static const __DRIextension *intelScreenExtensions[] = { |
744 | static const __DRIextension *intelScreenExtensions[] = { |
744 | &intelTexBufferExtension.base, |
745 | &intelTexBufferExtension.base, |
745 | &intelFlushExtension.base, |
746 | &intelFlushExtension.base, |
746 | &intelImageExtension.base, |
747 | &intelImageExtension.base, |
747 | &dri2ConfigQueryExtension.base, |
748 | &dri2ConfigQueryExtension.base, |
748 | NULL |
749 | NULL |
749 | }; |
750 | }; |
750 | 751 | ||
751 | static bool |
752 | static bool |
752 | intel_get_param(__DRIscreen *psp, int param, int *value) |
753 | intel_get_param(__DRIscreen *psp, int param, int *value) |
753 | { |
754 | { |
754 | int ret; |
755 | int ret; |
755 | struct drm_i915_getparam gp; |
756 | struct drm_i915_getparam gp; |
756 | 757 | ||
757 | memset(&gp, 0, sizeof(gp)); |
758 | memset(&gp, 0, sizeof(gp)); |
758 | gp.param = param; |
759 | gp.param = param; |
759 | gp.value = value; |
760 | gp.value = value; |
760 | 761 | ||
761 | ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); |
762 | ret = drmIoctl(psp->fd, DRM_IOCTL_I915_GETPARAM, &gp); |
762 | if (ret) { |
763 | if (ret) { |
763 | if (ret != -EINVAL) |
764 | if (ret != -EINVAL) |
764 | _mesa_warning(NULL, "drm_i915_getparam: %d", ret); |
765 | _mesa_warning(NULL, "drm_i915_getparam: %d", ret); |
765 | return false; |
766 | return false; |
766 | } |
767 | } |
767 | 768 | ||
768 | return true; |
769 | return true; |
769 | } |
770 | } |
- | 771 | ||
770 | 772 | ||
771 | static bool |
773 | static bool |
772 | intel_get_boolean(__DRIscreen *psp, int param) |
774 | intel_get_boolean(__DRIscreen *psp, int param) |
773 | { |
775 | { |
774 | int value = 0; |
776 | int value = 0; |
775 | return intel_get_param(psp, param, &value) && value; |
777 | return intel_get_param(psp, param, &value) && value; |
776 | } |
778 | } |
777 | 779 | ||
778 | static void |
780 | static void |
779 | intelDestroyScreen(__DRIscreen * sPriv) |
781 | intelDestroyScreen(__DRIscreen * sPriv) |
780 | { |
782 | { |
781 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
783 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
782 | 784 | ||
783 | dri_bufmgr_destroy(intelScreen->bufmgr); |
785 | dri_bufmgr_destroy(intelScreen->bufmgr); |
784 | driDestroyOptionInfo(&intelScreen->optionCache); |
786 | driDestroyOptionInfo(&intelScreen->optionCache); |
785 | 787 | ||
786 | free(intelScreen); |
788 | free(intelScreen); |
787 | sPriv->driverPrivate = NULL; |
789 | sPriv->driverPrivate = NULL; |
788 | } |
790 | } |
789 | 791 | ||
790 | 792 | ||
791 | /** |
793 | /** |
792 | * This is called when we need to set up GL rendering to a new X window. |
794 | * This is called when we need to set up GL rendering to a new X window. |
793 | */ |
795 | */ |
794 | static GLboolean |
796 | static GLboolean |
795 | intelCreateBuffer(__DRIscreen * driScrnPriv, |
797 | intelCreateBuffer(__DRIscreen * driScrnPriv, |
796 | __DRIdrawable * driDrawPriv, |
798 | __DRIdrawable * driDrawPriv, |
797 | const struct gl_config * mesaVis, GLboolean isPixmap) |
799 | const struct gl_config * mesaVis, GLboolean isPixmap) |
798 | { |
800 | { |
799 | struct intel_renderbuffer *rb; |
801 | struct intel_renderbuffer *rb; |
800 | gl_format rgbFormat; |
802 | gl_format rgbFormat; |
801 | struct gl_framebuffer *fb; |
803 | struct gl_framebuffer *fb; |
802 | 804 | ||
803 | if (isPixmap) |
805 | if (isPixmap) |
804 | return false; |
806 | return false; |
805 | 807 | ||
806 | fb = CALLOC_STRUCT(gl_framebuffer); |
808 | fb = CALLOC_STRUCT(gl_framebuffer); |
807 | if (!fb) |
809 | if (!fb) |
808 | return false; |
810 | return false; |
809 | 811 | ||
810 | _mesa_initialize_window_framebuffer(fb, mesaVis); |
812 | _mesa_initialize_window_framebuffer(fb, mesaVis); |
811 | 813 | ||
812 | if (mesaVis->redBits == 5) |
814 | if (mesaVis->redBits == 5) |
813 | rgbFormat = MESA_FORMAT_RGB565; |
815 | rgbFormat = MESA_FORMAT_RGB565; |
814 | else if (mesaVis->sRGBCapable) |
816 | else if (mesaVis->sRGBCapable) |
815 | rgbFormat = MESA_FORMAT_SARGB8; |
817 | rgbFormat = MESA_FORMAT_SARGB8; |
816 | else if (mesaVis->alphaBits == 0) |
818 | else if (mesaVis->alphaBits == 0) |
817 | rgbFormat = MESA_FORMAT_XRGB8888; |
819 | rgbFormat = MESA_FORMAT_XRGB8888; |
818 | else |
820 | else |
819 | rgbFormat = MESA_FORMAT_ARGB8888; |
821 | rgbFormat = MESA_FORMAT_ARGB8888; |
820 | 822 | ||
821 | /* setup the hardware-based renderbuffers */ |
823 | /* setup the hardware-based renderbuffers */ |
822 | rb = intel_create_renderbuffer(rgbFormat); |
824 | rb = intel_create_renderbuffer(rgbFormat); |
823 | _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base); |
825 | _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base); |
824 | 826 | ||
825 | if (mesaVis->doubleBufferMode) { |
827 | if (mesaVis->doubleBufferMode) { |
826 | rb = intel_create_renderbuffer(rgbFormat); |
828 | rb = intel_create_renderbuffer(rgbFormat); |
827 | _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base); |
829 | _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base); |
828 | } |
830 | } |
829 | 831 | ||
830 | /* |
832 | /* |
831 | * Assert here that the gl_config has an expected depth/stencil bit |
833 | * Assert here that the gl_config has an expected depth/stencil bit |
832 | * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(), |
834 | * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(), |
833 | * which constructs the advertised configs.) |
835 | * which constructs the advertised configs.) |
834 | */ |
836 | */ |
835 | if (mesaVis->depthBits == 24) { |
837 | if (mesaVis->depthBits == 24) { |
836 | assert(mesaVis->stencilBits == 8); |
838 | assert(mesaVis->stencilBits == 8); |
837 | 839 | ||
838 | /* |
840 | /* |
839 | * Use combined depth/stencil. Note that the renderbuffer is |
841 | * Use combined depth/stencil. Note that the renderbuffer is |
840 | * attached to two attachment points. |
842 | * attached to two attachment points. |
841 | */ |
843 | */ |
842 | rb = intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24); |
844 | rb = intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24); |
843 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
845 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
844 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
846 | _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base); |
845 | } |
847 | } |
846 | else if (mesaVis->depthBits == 16) { |
848 | else if (mesaVis->depthBits == 16) { |
847 | assert(mesaVis->stencilBits == 0); |
849 | assert(mesaVis->stencilBits == 0); |
848 | rb = intel_create_private_renderbuffer(MESA_FORMAT_Z16); |
850 | rb = intel_create_private_renderbuffer(MESA_FORMAT_Z16); |
849 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
851 | _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base); |
850 | } |
852 | } |
851 | else { |
853 | else { |
852 | assert(mesaVis->depthBits == 0); |
854 | assert(mesaVis->depthBits == 0); |
853 | assert(mesaVis->stencilBits == 0); |
855 | assert(mesaVis->stencilBits == 0); |
854 | } |
856 | } |
855 | 857 | ||
856 | /* now add any/all software-based renderbuffers we may need */ |
858 | /* now add any/all software-based renderbuffers we may need */ |
857 | _swrast_add_soft_renderbuffers(fb, |
859 | _swrast_add_soft_renderbuffers(fb, |
858 | false, /* never sw color */ |
860 | false, /* never sw color */ |
859 | false, /* never sw depth */ |
861 | false, /* never sw depth */ |
860 | false, /* never sw stencil */ |
862 | false, /* never sw stencil */ |
861 | mesaVis->accumRedBits > 0, |
863 | mesaVis->accumRedBits > 0, |
862 | false, /* never sw alpha */ |
864 | false, /* never sw alpha */ |
863 | false /* never sw aux */ ); |
865 | false /* never sw aux */ ); |
864 | driDrawPriv->driverPrivate = fb; |
866 | driDrawPriv->driverPrivate = fb; |
865 | 867 | ||
866 | return true; |
868 | return true; |
867 | } |
869 | } |
868 | 870 | ||
869 | static void |
871 | static void |
870 | intelDestroyBuffer(__DRIdrawable * driDrawPriv) |
872 | intelDestroyBuffer(__DRIdrawable * driDrawPriv) |
871 | { |
873 | { |
872 | struct gl_framebuffer *fb = driDrawPriv->driverPrivate; |
874 | struct gl_framebuffer *fb = driDrawPriv->driverPrivate; |
873 | 875 | ||
874 | _mesa_reference_framebuffer(&fb, NULL); |
876 | _mesa_reference_framebuffer(&fb, NULL); |
875 | } |
877 | } |
876 | 878 | ||
877 | /* There are probably better ways to do this, such as an |
879 | /* There are probably better ways to do this, such as an |
878 | * init-designated function to register chipids and createcontext |
880 | * init-designated function to register chipids and createcontext |
879 | * functions. |
881 | * functions. |
880 | */ |
882 | */ |
881 | extern bool |
883 | extern bool |
882 | i830CreateContext(int api, |
884 | i830CreateContext(int api, |
883 | const struct gl_config *mesaVis, |
885 | const struct gl_config *mesaVis, |
884 | __DRIcontext *driContextPriv, |
886 | __DRIcontext *driContextPriv, |
885 | unsigned major_version, |
887 | unsigned major_version, |
886 | unsigned minor_version, |
888 | unsigned minor_version, |
887 | unsigned *error, |
889 | unsigned *error, |
888 | void *sharedContextPrivate); |
890 | void *sharedContextPrivate); |
889 | 891 | ||
890 | extern bool |
892 | extern bool |
891 | i915CreateContext(int api, |
893 | i915CreateContext(int api, |
892 | const struct gl_config *mesaVis, |
894 | const struct gl_config *mesaVis, |
893 | __DRIcontext *driContextPriv, |
895 | __DRIcontext *driContextPriv, |
894 | unsigned major_version, |
896 | unsigned major_version, |
895 | unsigned minor_version, |
897 | unsigned minor_version, |
896 | unsigned *error, |
898 | unsigned *error, |
897 | void *sharedContextPrivate); |
899 | void *sharedContextPrivate); |
898 | 900 | ||
899 | static GLboolean |
901 | static GLboolean |
900 | intelCreateContext(gl_api api, |
902 | intelCreateContext(gl_api api, |
901 | const struct gl_config * mesaVis, |
903 | const struct gl_config * mesaVis, |
902 | __DRIcontext * driContextPriv, |
904 | __DRIcontext * driContextPriv, |
903 | unsigned major_version, |
905 | unsigned major_version, |
904 | unsigned minor_version, |
906 | unsigned minor_version, |
905 | uint32_t flags, |
907 | uint32_t flags, |
906 | unsigned *error, |
908 | unsigned *error, |
907 | void *sharedContextPrivate) |
909 | void *sharedContextPrivate) |
908 | { |
910 | { |
909 | bool success = false; |
911 | bool success = false; |
910 | 912 | ||
911 | __DRIscreen *sPriv = driContextPriv->driScreenPriv; |
913 | __DRIscreen *sPriv = driContextPriv->driScreenPriv; |
912 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
914 | struct intel_screen *intelScreen = sPriv->driverPrivate; |
913 | 915 | ||
914 | if (IS_9XX(intelScreen->deviceID)) { |
916 | if (IS_9XX(intelScreen->deviceID)) { |
915 | success = i915CreateContext(api, mesaVis, driContextPriv, |
917 | success = i915CreateContext(api, mesaVis, driContextPriv, |
916 | major_version, minor_version, error, |
918 | major_version, minor_version, error, |
917 | sharedContextPrivate); |
919 | sharedContextPrivate); |
918 | } else { |
920 | } else { |
919 | intelScreen->no_vbo = true; |
921 | intelScreen->no_vbo = true; |
920 | success = i830CreateContext(api, mesaVis, driContextPriv, |
922 | success = i830CreateContext(api, mesaVis, driContextPriv, |
921 | major_version, minor_version, error, |
923 | major_version, minor_version, error, |
922 | sharedContextPrivate); |
924 | sharedContextPrivate); |
923 | } |
925 | } |
924 | 926 | ||
925 | if (success) |
927 | if (success) |
926 | return true; |
928 | return true; |
927 | 929 | ||
928 | if (driContextPriv->driverPrivate != NULL) |
930 | if (driContextPriv->driverPrivate != NULL) |
929 | intelDestroyContext(driContextPriv); |
931 | intelDestroyContext(driContextPriv); |
930 | 932 | ||
931 | return false; |
933 | return false; |
932 | } |
934 | } |
933 | 935 | ||
934 | static bool |
936 | static bool |
935 | intel_init_bufmgr(struct intel_screen *intelScreen) |
937 | intel_init_bufmgr(struct intel_screen *intelScreen) |
936 | { |
938 | { |
937 | __DRIscreen *spriv = intelScreen->driScrnPriv; |
939 | __DRIscreen *spriv = intelScreen->driScrnPriv; |
938 | 940 | ||
939 | intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL; |
941 | intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL; |
940 | 942 | ||
941 | intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ); |
943 | intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ); |
942 | if (intelScreen->bufmgr == NULL) { |
944 | if (intelScreen->bufmgr == NULL) { |
943 | fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", |
945 | fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", |
944 | __func__, __LINE__); |
946 | __func__, __LINE__); |
945 | return false; |
947 | return false; |
946 | } |
948 | } |
947 | 949 | ||
948 | drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr); |
950 | drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr); |
949 | 951 | ||
950 | if (!intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA)) { |
952 | if (!intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA)) { |
951 | fprintf(stderr, "[%s: %u] Kernel 2.6.39 required.\n", __func__, __LINE__); |
953 | fprintf(stderr, "[%s: %u] Kernel 2.6.39 required.\n", __func__, __LINE__); |
952 | return false; |
954 | return false; |
953 | } |
955 | } |
954 | 956 | ||
955 | return true; |
957 | return true; |
956 | } |
958 | } |
957 | 959 | ||
958 | static bool |
960 | static bool |
959 | intel_detect_swizzling(struct intel_screen *screen) |
961 | intel_detect_swizzling(struct intel_screen *screen) |
960 | { |
962 | { |
961 | drm_intel_bo *buffer; |
963 | drm_intel_bo *buffer; |
962 | unsigned long flags = 0; |
964 | unsigned long flags = 0; |
963 | unsigned long aligned_pitch; |
965 | unsigned long aligned_pitch; |
964 | uint32_t tiling = I915_TILING_X; |
966 | uint32_t tiling = I915_TILING_X; |
965 | uint32_t swizzle_mode = 0; |
967 | uint32_t swizzle_mode = 0; |
966 | 968 | ||
967 | buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test", |
969 | buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test", |
968 | 64, 64, 4, |
970 | 64, 64, 4, |
969 | &tiling, &aligned_pitch, flags); |
971 | &tiling, &aligned_pitch, flags); |
970 | if (buffer == NULL) |
972 | if (buffer == NULL) |
971 | return false; |
973 | return false; |
972 | 974 | ||
973 | drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode); |
975 | drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode); |
974 | drm_intel_bo_unreference(buffer); |
976 | drm_intel_bo_unreference(buffer); |
975 | 977 | ||
976 | if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE) |
978 | if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE) |
977 | return false; |
979 | return false; |
978 | else |
980 | else |
979 | return true; |
981 | return true; |
980 | } |
982 | } |
981 | 983 | ||
982 | static __DRIconfig** |
984 | static __DRIconfig** |
983 | intel_screen_make_configs(__DRIscreen *dri_screen) |
985 | intel_screen_make_configs(__DRIscreen *dri_screen) |
984 | { |
986 | { |
985 | static const gl_format formats[] = { |
987 | static const gl_format formats[] = { |
986 | MESA_FORMAT_RGB565, |
988 | MESA_FORMAT_RGB565, |
987 | MESA_FORMAT_ARGB8888 |
989 | MESA_FORMAT_ARGB8888 |
988 | }; |
990 | }; |
989 | 991 | ||
990 | /* GLX_SWAP_COPY_OML is not supported due to page flipping. */ |
992 | /* GLX_SWAP_COPY_OML is not supported due to page flipping. */ |
991 | static const GLenum back_buffer_modes[] = { |
993 | static const GLenum back_buffer_modes[] = { |
992 | GLX_SWAP_UNDEFINED_OML, GLX_NONE, |
994 | GLX_SWAP_UNDEFINED_OML, GLX_NONE, |
993 | }; |
995 | }; |
994 | 996 | ||
995 | static const uint8_t singlesample_samples[1] = {0}; |
997 | static const uint8_t singlesample_samples[1] = {0}; |
996 | 998 | ||
997 | uint8_t depth_bits[4], stencil_bits[4]; |
999 | uint8_t depth_bits[4], stencil_bits[4]; |
998 | __DRIconfig **configs = NULL; |
1000 | __DRIconfig **configs = NULL; |
999 | 1001 | ||
1000 | /* Generate singlesample configs without accumulation buffer. */ |
1002 | /* Generate singlesample configs without accumulation buffer. */ |
1001 | for (int i = 0; i < ARRAY_SIZE(formats); i++) { |
1003 | for (int i = 0; i < ARRAY_SIZE(formats); i++) { |
1002 | __DRIconfig **new_configs; |
1004 | __DRIconfig **new_configs; |
1003 | int num_depth_stencil_bits = 2; |
1005 | int num_depth_stencil_bits = 2; |
1004 | 1006 | ||
1005 | /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil |
1007 | /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil |
1006 | * buffer that has a different number of bits per pixel than the color |
1008 | * buffer that has a different number of bits per pixel than the color |
1007 | * buffer. |
1009 | * buffer. |
1008 | */ |
1010 | */ |
1009 | depth_bits[0] = 0; |
1011 | depth_bits[0] = 0; |
1010 | stencil_bits[0] = 0; |
1012 | stencil_bits[0] = 0; |
1011 | 1013 | ||
1012 | if (formats[i] == MESA_FORMAT_RGB565) { |
1014 | if (formats[i] == MESA_FORMAT_RGB565) { |
1013 | depth_bits[1] = 16; |
1015 | depth_bits[1] = 16; |
1014 | stencil_bits[1] = 0; |
1016 | stencil_bits[1] = 0; |
1015 | } else { |
1017 | } else { |
1016 | depth_bits[1] = 24; |
1018 | depth_bits[1] = 24; |
1017 | stencil_bits[1] = 8; |
1019 | stencil_bits[1] = 8; |
1018 | } |
1020 | } |
1019 | 1021 | ||
1020 | new_configs = driCreateConfigs(formats[i], |
1022 | new_configs = driCreateConfigs(formats[i], |
1021 | depth_bits, |
1023 | depth_bits, |
1022 | stencil_bits, |
1024 | stencil_bits, |
1023 | num_depth_stencil_bits, |
1025 | num_depth_stencil_bits, |
1024 | back_buffer_modes, 2, |
1026 | back_buffer_modes, 2, |
1025 | singlesample_samples, 1, |
1027 | singlesample_samples, 1, |
1026 | false); |
1028 | false); |
1027 | configs = driConcatConfigs(configs, new_configs); |
1029 | configs = driConcatConfigs(configs, new_configs); |
1028 | } |
1030 | } |
1029 | 1031 | ||
1030 | /* Generate the minimum possible set of configs that include an |
1032 | /* Generate the minimum possible set of configs that include an |
1031 | * accumulation buffer. |
1033 | * accumulation buffer. |
1032 | */ |
1034 | */ |
1033 | for (int i = 0; i < ARRAY_SIZE(formats); i++) { |
1035 | for (int i = 0; i < ARRAY_SIZE(formats); i++) { |
1034 | __DRIconfig **new_configs; |
1036 | __DRIconfig **new_configs; |
1035 | 1037 | ||
1036 | if (formats[i] == MESA_FORMAT_RGB565) { |
1038 | if (formats[i] == MESA_FORMAT_RGB565) { |
1037 | depth_bits[0] = 16; |
1039 | depth_bits[0] = 16; |
1038 | stencil_bits[0] = 0; |
1040 | stencil_bits[0] = 0; |
1039 | } else { |
1041 | } else { |
1040 | depth_bits[0] = 24; |
1042 | depth_bits[0] = 24; |
1041 | stencil_bits[0] = 8; |
1043 | stencil_bits[0] = 8; |
1042 | } |
1044 | } |
1043 | 1045 | ||
1044 | new_configs = driCreateConfigs(formats[i], |
1046 | new_configs = driCreateConfigs(formats[i], |
1045 | depth_bits, stencil_bits, 1, |
1047 | depth_bits, stencil_bits, 1, |
1046 | back_buffer_modes, 1, |
1048 | back_buffer_modes, 1, |
1047 | singlesample_samples, 1, |
1049 | singlesample_samples, 1, |
1048 | true); |
1050 | true); |
1049 | configs = driConcatConfigs(configs, new_configs); |
1051 | configs = driConcatConfigs(configs, new_configs); |
1050 | } |
1052 | } |
1051 | 1053 | ||
1052 | if (configs == NULL) { |
1054 | if (configs == NULL) { |
1053 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
1055 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
1054 | __LINE__); |
1056 | __LINE__); |
1055 | return NULL; |
1057 | return NULL; |
1056 | } |
1058 | } |
1057 | 1059 | ||
1058 | return configs; |
1060 | return configs; |
1059 | } |
1061 | } |
1060 | 1062 | ||
1061 | static void |
1063 | static void |
1062 | set_max_gl_versions(struct intel_screen *screen) |
1064 | set_max_gl_versions(struct intel_screen *screen) |
1063 | { |
1065 | { |
1064 | int gl_version_override = _mesa_get_gl_version_override(); |
1066 | int gl_version_override = _mesa_get_gl_version_override(); |
1065 | 1067 | ||
1066 | switch (screen->gen) { |
1068 | switch (screen->gen) { |
1067 | case 3: |
1069 | case 3: |
1068 | screen->max_gl_core_version = 0; |
1070 | screen->max_gl_core_version = 0; |
1069 | screen->max_gl_es1_version = 11; |
1071 | screen->max_gl_es1_version = 11; |
1070 | screen->max_gl_compat_version = 21; |
1072 | screen->max_gl_compat_version = 21; |
1071 | screen->max_gl_es2_version = 20; |
1073 | screen->max_gl_es2_version = 20; |
1072 | break; |
1074 | break; |
1073 | case 2: |
1075 | case 2: |
1074 | screen->max_gl_core_version = 0; |
1076 | screen->max_gl_core_version = 0; |
1075 | screen->max_gl_compat_version = 13; |
1077 | screen->max_gl_compat_version = 13; |
1076 | screen->max_gl_es1_version = 11; |
1078 | screen->max_gl_es1_version = 11; |
1077 | screen->max_gl_es2_version = 0; |
1079 | screen->max_gl_es2_version = 0; |
1078 | break; |
1080 | break; |
1079 | default: |
1081 | default: |
1080 | assert(!"unrecognized intel_screen::gen"); |
1082 | assert(!"unrecognized intel_screen::gen"); |
1081 | break; |
1083 | break; |
1082 | } |
1084 | } |
1083 | 1085 | ||
1084 | if (gl_version_override >= 31) { |
1086 | if (gl_version_override >= 31) { |
1085 | screen->max_gl_core_version = MAX2(screen->max_gl_core_version, |
1087 | screen->max_gl_core_version = MAX2(screen->max_gl_core_version, |
1086 | gl_version_override); |
1088 | gl_version_override); |
1087 | } else { |
1089 | } else { |
1088 | screen->max_gl_compat_version = MAX2(screen->max_gl_compat_version, |
1090 | screen->max_gl_compat_version = MAX2(screen->max_gl_compat_version, |
1089 | gl_version_override); |
1091 | gl_version_override); |
1090 | } |
1092 | } |
1091 | 1093 | ||
1092 | #ifndef FEATURE_ES1 |
1094 | #ifndef FEATURE_ES1 |
1093 | screen->max_gl_es1_version = 0; |
1095 | screen->max_gl_es1_version = 0; |
1094 | #endif |
1096 | #endif |
1095 | 1097 | ||
1096 | #ifndef FEATURE_ES2 |
1098 | #ifndef FEATURE_ES2 |
1097 | screen->max_gl_es2_version = 0; |
1099 | screen->max_gl_es2_version = 0; |
1098 | #endif |
1100 | #endif |
1099 | } |
1101 | } |
1100 | 1102 | ||
1101 | /** |
1103 | /** |
1102 | * This is the driver specific part of the createNewScreen entry point. |
1104 | * This is the driver specific part of the createNewScreen entry point. |
1103 | * Called when using DRI2. |
1105 | * Called when using DRI2. |
1104 | * |
1106 | * |
1105 | * \return the struct gl_config supported by this driver |
1107 | * \return the struct gl_config supported by this driver |
1106 | */ |
1108 | */ |
1107 | static const |
1109 | static const |
1108 | __DRIconfig **intelInitScreen2(__DRIscreen *psp) |
1110 | __DRIconfig **intelInitScreen2(__DRIscreen *psp) |
1109 | { |
1111 | { |
1110 | struct intel_screen *intelScreen; |
1112 | struct intel_screen *intelScreen; |
1111 | 1113 | ||
1112 | if (psp->dri2.loader->base.version <= 2 || |
1114 | if (psp->dri2.loader->base.version <= 2 || |
1113 | psp->dri2.loader->getBuffersWithFormat == NULL) { |
1115 | psp->dri2.loader->getBuffersWithFormat == NULL) { |
1114 | fprintf(stderr, |
1116 | fprintf(stderr, |
1115 | "\nERROR! DRI2 loader with getBuffersWithFormat() " |
1117 | "\nERROR! DRI2 loader with getBuffersWithFormat() " |
1116 | "support required\n"); |
1118 | "support required\n"); |
1117 | return false; |
1119 | return false; |
1118 | } |
1120 | } |
1119 | 1121 | ||
1120 | /* Allocate the private area */ |
1122 | /* Allocate the private area */ |
1121 | intelScreen = calloc(1, sizeof *intelScreen); |
1123 | intelScreen = calloc(1, sizeof *intelScreen); |
1122 | if (!intelScreen) { |
1124 | if (!intelScreen) { |
1123 | fprintf(stderr, "\nERROR! Allocating private area failed\n"); |
1125 | fprintf(stderr, "\nERROR! Allocating private area failed\n"); |
1124 | return false; |
1126 | return false; |
1125 | } |
1127 | } |
1126 | /* parse information in __driConfigOptions */ |
1128 | /* parse information in __driConfigOptions */ |
1127 | driParseOptionInfo(&intelScreen->optionCache, |
1129 | driParseOptionInfo(&intelScreen->optionCache, |
1128 | __driConfigOptions, __driNConfigOptions); |
1130 | __driConfigOptions, __driNConfigOptions); |
1129 | 1131 | ||
1130 | intelScreen->driScrnPriv = psp; |
1132 | intelScreen->driScrnPriv = psp; |
1131 | psp->driverPrivate = (void *) intelScreen; |
1133 | psp->driverPrivate = (void *) intelScreen; |
1132 | 1134 | ||
1133 | if (!intel_init_bufmgr(intelScreen)) |
1135 | if (!intel_init_bufmgr(intelScreen)) |
1134 | return false; |
1136 | return false; |
1135 | 1137 | ||
1136 | intelScreen->deviceID = drm_intel_bufmgr_gem_get_devid(intelScreen->bufmgr); |
1138 | intelScreen->deviceID = drm_intel_bufmgr_gem_get_devid(intelScreen->bufmgr); |
1137 | 1139 | ||
1138 | if (IS_9XX(intelScreen->deviceID)) { |
1140 | if (IS_9XX(intelScreen->deviceID)) { |
1139 | intelScreen->gen = 3; |
1141 | intelScreen->gen = 3; |
1140 | } else { |
1142 | } else { |
1141 | intelScreen->gen = 2; |
1143 | intelScreen->gen = 2; |
1142 | } |
1144 | } |
1143 | 1145 | ||
1144 | intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen); |
1146 | intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen); |
1145 | 1147 | ||
1146 | set_max_gl_versions(intelScreen); |
1148 | set_max_gl_versions(intelScreen); |
1147 | 1149 | ||
1148 | psp->api_mask = (1 << __DRI_API_OPENGL); |
1150 | psp->api_mask = (1 << __DRI_API_OPENGL); |
1149 | if (intelScreen->max_gl_core_version > 0) |
1151 | if (intelScreen->max_gl_core_version > 0) |
1150 | psp->api_mask |= (1 << __DRI_API_OPENGL_CORE); |
1152 | psp->api_mask |= (1 << __DRI_API_OPENGL_CORE); |
1151 | if (intelScreen->max_gl_es1_version > 0) |
1153 | if (intelScreen->max_gl_es1_version > 0) |
1152 | psp->api_mask |= (1 << __DRI_API_GLES); |
1154 | psp->api_mask |= (1 << __DRI_API_GLES); |
1153 | if (intelScreen->max_gl_es2_version > 0) |
1155 | if (intelScreen->max_gl_es2_version > 0) |
1154 | psp->api_mask |= (1 << __DRI_API_GLES2); |
1156 | psp->api_mask |= (1 << __DRI_API_GLES2); |
1155 | if (intelScreen->max_gl_es2_version >= 30) |
1157 | if (intelScreen->max_gl_es2_version >= 30) |
1156 | psp->api_mask |= (1 << __DRI_API_GLES3); |
1158 | psp->api_mask |= (1 << __DRI_API_GLES3); |
1157 | 1159 | ||
1158 | psp->extensions = intelScreenExtensions; |
1160 | psp->extensions = intelScreenExtensions; |
1159 | 1161 | ||
1160 | return (const __DRIconfig**) intel_screen_make_configs(psp); |
1162 | return (const __DRIconfig**) intel_screen_make_configs(psp); |
1161 | } |
1163 | } |
1162 | 1164 | ||
1163 | struct intel_buffer { |
1165 | struct intel_buffer { |
1164 | __DRIbuffer base; |
1166 | __DRIbuffer base; |
1165 | struct intel_region *region; |
1167 | struct intel_region *region; |
1166 | }; |
1168 | }; |
1167 | 1169 | ||
1168 | static __DRIbuffer * |
1170 | static __DRIbuffer * |
1169 | intelAllocateBuffer(__DRIscreen *screen, |
1171 | intelAllocateBuffer(__DRIscreen *screen, |
1170 | unsigned attachment, unsigned format, |
1172 | unsigned attachment, unsigned format, |
1171 | int width, int height) |
1173 | int width, int height) |
1172 | { |
1174 | { |
1173 | struct intel_buffer *intelBuffer; |
1175 | struct intel_buffer *intelBuffer; |
1174 | struct intel_screen *intelScreen = screen->driverPrivate; |
1176 | struct intel_screen *intelScreen = screen->driverPrivate; |
1175 | 1177 | ||
1176 | assert(attachment == __DRI_BUFFER_FRONT_LEFT || |
1178 | assert(attachment == __DRI_BUFFER_FRONT_LEFT || |
1177 | attachment == __DRI_BUFFER_BACK_LEFT); |
1179 | attachment == __DRI_BUFFER_BACK_LEFT); |
1178 | 1180 | ||
1179 | intelBuffer = calloc(1, sizeof *intelBuffer); |
1181 | intelBuffer = calloc(1, sizeof *intelBuffer); |
1180 | if (intelBuffer == NULL) |
1182 | if (intelBuffer == NULL) |
1181 | return NULL; |
1183 | return NULL; |
1182 | 1184 | ||
1183 | /* The front and back buffers are color buffers, which are X tiled. */ |
1185 | /* The front and back buffers are color buffers, which are X tiled. */ |
1184 | intelBuffer->region = intel_region_alloc(intelScreen, |
1186 | intelBuffer->region = intel_region_alloc(intelScreen, |
1185 | I915_TILING_X, |
1187 | I915_TILING_X, |
1186 | format / 8, |
1188 | format / 8, |
1187 | width, |
1189 | width, |
1188 | height, |
1190 | height, |
1189 | true); |
1191 | true); |
1190 | 1192 | ||
1191 | if (intelBuffer->region == NULL) { |
1193 | if (intelBuffer->region == NULL) { |
1192 | free(intelBuffer); |
1194 | free(intelBuffer); |
1193 | return NULL; |
1195 | return NULL; |
1194 | } |
1196 | } |
1195 | 1197 | ||
1196 | intel_region_flink(intelBuffer->region, &intelBuffer->base.name); |
1198 | intel_region_flink(intelBuffer->region, &intelBuffer->base.name); |
1197 | 1199 | ||
1198 | intelBuffer->base.attachment = attachment; |
1200 | intelBuffer->base.attachment = attachment; |
1199 | intelBuffer->base.cpp = intelBuffer->region->cpp; |
1201 | intelBuffer->base.cpp = intelBuffer->region->cpp; |
1200 | intelBuffer->base.pitch = intelBuffer->region->pitch; |
1202 | intelBuffer->base.pitch = intelBuffer->region->pitch; |
1201 | 1203 | ||
1202 | return &intelBuffer->base; |
1204 | return &intelBuffer->base; |
1203 | } |
1205 | } |
1204 | 1206 | ||
1205 | static void |
1207 | static void |
1206 | intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer) |
1208 | intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer) |
1207 | { |
1209 | { |
1208 | struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; |
1210 | struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; |
1209 | 1211 | ||
1210 | intel_region_release(&intelBuffer->region); |
1212 | intel_region_release(&intelBuffer->region); |
1211 | free(intelBuffer); |
1213 | free(intelBuffer); |
1212 | } |
1214 | } |
1213 | 1215 | ||
1214 | 1216 | ||
1215 | const struct __DriverAPIRec driDriverAPI = { |
1217 | const struct __DriverAPIRec driDriverAPI = { |
1216 | .InitScreen = intelInitScreen2, |
1218 | .InitScreen = intelInitScreen2, |
1217 | .DestroyScreen = intelDestroyScreen, |
1219 | .DestroyScreen = intelDestroyScreen, |
1218 | .CreateContext = intelCreateContext, |
1220 | .CreateContext = intelCreateContext, |
1219 | .DestroyContext = intelDestroyContext, |
1221 | .DestroyContext = intelDestroyContext, |
1220 | .CreateBuffer = intelCreateBuffer, |
1222 | .CreateBuffer = intelCreateBuffer, |
1221 | .DestroyBuffer = intelDestroyBuffer, |
1223 | .DestroyBuffer = intelDestroyBuffer, |
1222 | .MakeCurrent = intelMakeCurrent, |
1224 | .MakeCurrent = intelMakeCurrent, |
1223 | .UnbindContext = intelUnbindContext, |
1225 | .UnbindContext = intelUnbindContext, |
1224 | .AllocateBuffer = intelAllocateBuffer, |
1226 | .AllocateBuffer = intelAllocateBuffer, |
1225 | .ReleaseBuffer = intelReleaseBuffer |
1227 | .ReleaseBuffer = intelReleaseBuffer |
1226 | }; |
1228 | }; |
1227 | 1229 | ||
1228 | /* This is the table of extensions that the loader will dlsym() for. */ |
1230 | /* This is the table of extensions that the loader will dlsym() for. */ |
1229 | PUBLIC const __DRIextension *__driDriverExtensions[] = { |
1231 | __declspec(dllexport) const __DRIextension *__driDriverExtensions[] = { |
1230 | &driCoreExtension.base, |
1232 | &driCoreExtension.base, |
1231 | &driDRI2Extension.base, |
1233 | &driDRI2Extension.base, |
1232 | NULL |
1234 | NULL |
1233 | };><>><>><>><>><>=>>>>>>>>>> |
1235 | };><>><>><>><>><>=>>>>>>>>>> |