2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
34 # include "i965_output_dri.h"
37 #ifdef HAVE_VA_WAYLAND
38 # include "i965_output_wayland.h"
41 #include "intel_driver.h"
42 #include "intel_memman.h"
43 #include "intel_batchbuffer.h"
44 #include "i965_defines.h"
45 #include "i965_drv_video.h"
46 #include "i965_decoder.h"
47 #include "i965_encoder.h"
49 #define CONFIG_ID_OFFSET 0x01000000
50 #define CONTEXT_ID_OFFSET 0x02000000
51 #define SURFACE_ID_OFFSET 0x04000000
52 #define BUFFER_ID_OFFSET 0x08000000
53 #define IMAGE_ID_OFFSET 0x0a000000
54 #define SUBPIC_ID_OFFSET 0x10000000
56 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
59 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
62 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
65 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
68 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
71 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
74 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
76 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
78 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
80 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
82 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
85 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
88 #define HAS_H264_MVC_DECODING(ctx) \
89 (HAS_H264_DECODING(ctx) && (ctx)->codec_info->h264_mvc_dec_profiles)
91 #define HAS_H264_MVC_DECODING_PROFILE(ctx, profile) \
92 (HAS_H264_MVC_DECODING(ctx) && \
93 ((ctx)->codec_info->h264_mvc_dec_profiles & (1U << profile)))
95 #define HAS_H264_MVC_ENCODING(ctx) ((ctx)->codec_info->has_h264_mvc_encoding && \
98 static int get_sampling_from_fourcc(unsigned int fourcc);
100 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
101 #define IS_VA_X11(ctx) \
102 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
104 /* Check whether we are rendering to Wayland */
105 #define IS_VA_WAYLAND(ctx) \
106 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
109 #define I965_2BITS (I965_BIT << 1)
110 #define I965_4BITS (I965_BIT << 2)
111 #define I965_8BITS (I965_BIT << 3)
112 #define I965_16BITS (I965_BIT << 4)
113 #define I965_32BITS (I965_BIT << 5)
125 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
126 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
127 #define I_I420 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
128 #define I_IYUV I_I420
129 #define I_IMC3 I_I420
130 #define I_YV12 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
131 #define I_IMC1 I_YV12
133 #define I_422H 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
134 #define I_422V 1, 2, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
135 #define I_YV16 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
136 #define I_YUY2 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
137 #define I_UYVY 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
139 #define I_444P 1, 1, 3, {I965_8BITS, I965_8BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
141 #define I_411P 4, 1, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
143 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
145 #define I_RGBA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24} }
146 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
147 #define I_BGRA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_24} }
148 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
150 #define I_ARGB 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_0} }
151 #define I_ABGR 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
153 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
154 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
156 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
157 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
162 #define I_SI (I_S | I_I)
164 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
165 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
166 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
167 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
169 static const i965_fourcc_info i965_fourcc_infos[] = {
170 DEF_YUV(NV12, YUV420, I_SI),
171 DEF_YUV(I420, YUV420, I_SI),
172 DEF_YUV(IYUV, YUV420, I_S),
173 DEF_YUV(IMC3, YUV420, I_S),
174 DEF_YUV(YV12, YUV420, I_SI),
175 DEF_YUV(IMC1, YUV420, I_S),
177 DEF_YUV(422H, YUV422H, I_SI),
178 DEF_YUV(422V, YUV422V, I_S),
179 DEF_YUV(YV16, YUV422H, I_S),
180 DEF_YUV(YUY2, YUV422H, I_SI),
181 DEF_YUV(UYVY, YUV422H, I_SI),
183 DEF_YUV(444P, YUV444, I_S),
185 DEF_YUV(411P, YUV411, I_S),
187 DEF_YUV(Y800, YUV400, I_S),
189 DEF_RGB(RGBA, RGBX, I_SI),
190 DEF_RGB(RGBX, RGBX, I_SI),
191 DEF_RGB(BGRA, RGBX, I_SI),
192 DEF_RGB(BGRX, RGBX, I_SI),
194 DEF_RGB(ARGB, RGBX, I_I),
195 DEF_RGB(ABGR, RGBX, I_I),
197 DEF_INDEX(IA88, RGBX, I_I),
198 DEF_INDEX(AI88, RGBX, I_I),
200 DEF_INDEX(IA44, RGBX, I_I),
201 DEF_INDEX(AI44, RGBX, I_I)
204 const i965_fourcc_info *
205 get_fourcc_info(unsigned int fourcc)
209 for (i = 0; ARRAY_ELEMS(i965_fourcc_infos); i++) {
210 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
212 if (info->fourcc == fourcc)
220 I965_SURFACETYPE_RGBA = 1,
221 I965_SURFACETYPE_YUV,
222 I965_SURFACETYPE_INDEXED
225 /* List of supported display attributes */
226 static const VADisplayAttribute i965_display_attributes[] = {
228 VADisplayAttribBrightness,
229 -100, 100, DEFAULT_BRIGHTNESS,
230 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
234 VADisplayAttribContrast,
235 0, 100, DEFAULT_CONTRAST,
236 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
241 -180, 180, DEFAULT_HUE,
242 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
246 VADisplayAttribSaturation,
247 0, 100, DEFAULT_SATURATION,
248 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
252 VADisplayAttribRotation,
253 0, 3, VA_ROTATION_NONE,
254 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
258 /* List of supported image formats */
261 VAImageFormat va_format;
262 } i965_image_format_map_t;
264 static const i965_image_format_map_t
265 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
266 { I965_SURFACETYPE_YUV,
267 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
268 { I965_SURFACETYPE_YUV,
269 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
270 { I965_SURFACETYPE_YUV,
271 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
272 { I965_SURFACETYPE_YUV,
273 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
274 { I965_SURFACETYPE_YUV,
275 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
276 { I965_SURFACETYPE_YUV,
277 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
278 { I965_SURFACETYPE_RGBA,
279 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
280 { I965_SURFACETYPE_RGBA,
281 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
284 /* List of supported subpicture formats */
288 VAImageFormat va_format;
289 unsigned int va_flags;
290 } i965_subpic_format_map_t;
292 #define COMMON_SUBPICTURE_FLAGS \
293 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
294 VA_SUBPICTURE_GLOBAL_ALPHA)
296 static const i965_subpic_format_map_t
297 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
298 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
299 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
300 COMMON_SUBPICTURE_FLAGS },
301 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
302 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
303 COMMON_SUBPICTURE_FLAGS },
304 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
305 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
306 COMMON_SUBPICTURE_FLAGS },
307 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
308 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
309 COMMON_SUBPICTURE_FLAGS },
310 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
311 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
312 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
313 COMMON_SUBPICTURE_FLAGS },
314 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
315 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
316 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
317 COMMON_SUBPICTURE_FLAGS },
320 static const i965_subpic_format_map_t *
321 get_subpic_format(const VAImageFormat *va_format)
324 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
325 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
326 if (m->va_format.fourcc == va_format->fourcc &&
327 (m->type == I965_SURFACETYPE_RGBA ?
328 (m->va_format.byte_order == va_format->byte_order &&
329 m->va_format.red_mask == va_format->red_mask &&
330 m->va_format.green_mask == va_format->green_mask &&
331 m->va_format.blue_mask == va_format->blue_mask &&
332 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
338 #define I965_PACKED_HEADER_BASE 0
339 #define I965_PACKED_MISC_HEADER_BASE 3
342 va_enc_packed_type_to_idx(int packed_type)
346 if (packed_type & VAEncPackedHeaderMiscMask) {
347 idx = I965_PACKED_MISC_HEADER_BASE;
348 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
349 ASSERT_RET(packed_type > 0, 0);
350 idx += (packed_type - 1);
352 idx = I965_PACKED_HEADER_BASE;
354 switch (packed_type) {
355 case VAEncPackedHeaderSequence:
356 idx = I965_PACKED_HEADER_BASE + 0;
359 case VAEncPackedHeaderPicture:
360 idx = I965_PACKED_HEADER_BASE + 1;
363 case VAEncPackedHeaderSlice:
364 idx = I965_PACKED_HEADER_BASE + 2;
368 /* Should not get here */
374 ASSERT_RET(idx < 4, 0);
379 i965_QueryConfigProfiles(VADriverContextP ctx,
380 VAProfile *profile_list, /* out */
381 int *num_profiles) /* out */
383 struct i965_driver_data * const i965 = i965_driver_data(ctx);
386 if (HAS_MPEG2_DECODING(i965) ||
387 HAS_MPEG2_ENCODING(i965)) {
388 profile_list[i++] = VAProfileMPEG2Simple;
389 profile_list[i++] = VAProfileMPEG2Main;
392 if (HAS_H264_DECODING(i965) ||
393 HAS_H264_ENCODING(i965)) {
394 profile_list[i++] = VAProfileH264ConstrainedBaseline;
395 profile_list[i++] = VAProfileH264Main;
396 profile_list[i++] = VAProfileH264High;
398 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh))
399 profile_list[i++] = VAProfileH264MultiviewHigh;
400 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh))
401 profile_list[i++] = VAProfileH264StereoHigh;
403 if (HAS_VC1_DECODING(i965)) {
404 profile_list[i++] = VAProfileVC1Simple;
405 profile_list[i++] = VAProfileVC1Main;
406 profile_list[i++] = VAProfileVC1Advanced;
410 profile_list[i++] = VAProfileNone;
413 if (HAS_JPEG_DECODING(i965)) {
414 profile_list[i++] = VAProfileJPEGBaseline;
417 if (HAS_VP8_DECODING(i965) ||
418 HAS_VP8_ENCODING(i965)) {
419 profile_list[i++] = VAProfileVP8Version0_3;
422 if (HAS_H264_MVC_ENCODING(i965)) {
423 profile_list[i++] = VAProfileH264MultiviewHigh;
424 profile_list[i++] = VAProfileH264StereoHigh;
427 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
428 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
431 return VA_STATUS_SUCCESS;
435 i965_QueryConfigEntrypoints(VADriverContextP ctx,
437 VAEntrypoint *entrypoint_list, /* out */
438 int *num_entrypoints) /* out */
440 struct i965_driver_data * const i965 = i965_driver_data(ctx);
444 case VAProfileMPEG2Simple:
445 case VAProfileMPEG2Main:
446 if (HAS_MPEG2_DECODING(i965))
447 entrypoint_list[n++] = VAEntrypointVLD;
449 if (HAS_MPEG2_ENCODING(i965))
450 entrypoint_list[n++] = VAEntrypointEncSlice;
454 case VAProfileH264ConstrainedBaseline:
455 case VAProfileH264Main:
456 case VAProfileH264High:
457 if (HAS_H264_DECODING(i965))
458 entrypoint_list[n++] = VAEntrypointVLD;
460 if (HAS_H264_ENCODING(i965))
461 entrypoint_list[n++] = VAEntrypointEncSlice;
464 case VAProfileH264MultiviewHigh:
465 case VAProfileH264StereoHigh:
466 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
467 entrypoint_list[n++] = VAEntrypointVLD;
469 if (HAS_H264_MVC_ENCODING(i965))
470 entrypoint_list[n++] = VAEntrypointEncSlice;
473 case VAProfileVC1Simple:
474 case VAProfileVC1Main:
475 case VAProfileVC1Advanced:
476 if (HAS_VC1_DECODING(i965))
477 entrypoint_list[n++] = VAEntrypointVLD;
482 entrypoint_list[n++] = VAEntrypointVideoProc;
485 case VAProfileJPEGBaseline:
486 if (HAS_JPEG_DECODING(i965))
487 entrypoint_list[n++] = VAEntrypointVLD;
490 case VAProfileVP8Version0_3:
491 if (HAS_VP8_DECODING(i965))
492 entrypoint_list[n++] = VAEntrypointVLD;
494 if (HAS_VP8_ENCODING(i965))
495 entrypoint_list[n++] = VAEntrypointEncSlice;
501 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
502 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
503 *num_entrypoints = n;
504 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
508 i965_validate_config(VADriverContextP ctx, VAProfile profile,
509 VAEntrypoint entrypoint)
511 struct i965_driver_data * const i965 = i965_driver_data(ctx);
514 /* Validate profile & entrypoint */
516 case VAProfileMPEG2Simple:
517 case VAProfileMPEG2Main:
518 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
519 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
520 va_status = VA_STATUS_SUCCESS;
522 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
526 case VAProfileH264ConstrainedBaseline:
527 case VAProfileH264Main:
528 case VAProfileH264High:
529 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
530 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
531 va_status = VA_STATUS_SUCCESS;
533 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
537 case VAProfileVC1Simple:
538 case VAProfileVC1Main:
539 case VAProfileVC1Advanced:
540 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
541 va_status = VA_STATUS_SUCCESS;
543 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
548 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
549 va_status = VA_STATUS_SUCCESS;
551 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
555 case VAProfileJPEGBaseline:
556 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) {
557 va_status = VA_STATUS_SUCCESS;
559 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
563 case VAProfileVP8Version0_3:
564 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
565 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
566 va_status = VA_STATUS_SUCCESS;
568 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
572 case VAProfileH264MultiviewHigh:
573 case VAProfileH264StereoHigh:
574 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
575 entrypoint == VAEntrypointVLD) ||
576 (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
577 va_status = VA_STATUS_SUCCESS;
579 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
585 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
592 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
593 VAEntrypoint entrypoint)
595 struct i965_driver_data * const i965 = i965_driver_data(ctx);
596 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
599 case VAProfileH264ConstrainedBaseline:
600 case VAProfileH264Main:
601 case VAProfileH264High:
602 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
603 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
606 case VAProfileH264MultiviewHigh:
607 case VAProfileH264StereoHigh:
608 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
609 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
612 case VAProfileJPEGBaseline:
613 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
614 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
620 return chroma_formats;
624 i965_GetConfigAttributes(VADriverContextP ctx,
626 VAEntrypoint entrypoint,
627 VAConfigAttrib *attrib_list, /* in/out */
631 struct i965_driver_data *i965 = i965_driver_data(ctx);
634 va_status = i965_validate_config(ctx, profile, entrypoint);
635 if (va_status != VA_STATUS_SUCCESS)
638 /* Other attributes don't seem to be defined */
639 /* What to do if we don't know the attribute? */
640 for (i = 0; i < num_attribs; i++) {
641 switch (attrib_list[i].type) {
642 case VAConfigAttribRTFormat:
643 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
644 profile, entrypoint);
647 case VAConfigAttribRateControl:
648 if (entrypoint == VAEntrypointEncSlice) {
649 attrib_list[i].value = VA_RC_CQP;
651 if (profile != VAProfileMPEG2Main &&
652 profile != VAProfileMPEG2Simple)
653 attrib_list[i].value |= VA_RC_CBR;
657 case VAConfigAttribEncPackedHeaders:
658 if (entrypoint == VAEntrypointEncSlice) {
659 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
660 if (profile == VAProfileH264ConstrainedBaseline ||
661 profile == VAProfileH264Main ||
662 profile == VAProfileH264High ||
663 profile == VAProfileH264StereoHigh ||
664 profile == VAProfileH264MultiviewHigh) {
665 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
666 VA_ENC_PACKED_HEADER_SLICE);
671 case VAConfigAttribEncMaxRefFrames:
672 if (entrypoint == VAEntrypointEncSlice) {
673 attrib_list[i].value = (1 << 16) | (1 << 0);
677 case VAConfigAttribEncQualityRange:
678 if (entrypoint == VAEntrypointEncSlice) {
679 attrib_list[i].value = 1;
680 if (profile == VAProfileH264ConstrainedBaseline ||
681 profile == VAProfileH264Main ||
682 profile == VAProfileH264High )
683 attrib_list[i].value = ENCODER_QUALITY_RANGE;
689 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
694 return VA_STATUS_SUCCESS;
698 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
700 object_heap_free(heap, obj);
703 static VAConfigAttrib *
704 i965_lookup_config_attribute(struct object_config *obj_config,
705 VAConfigAttribType type)
709 for (i = 0; i < obj_config->num_attribs; i++) {
710 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
711 if (attrib->type == type)
718 i965_append_config_attribute(struct object_config *obj_config,
719 const VAConfigAttrib *new_attrib)
721 VAConfigAttrib *attrib;
723 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
724 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
726 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
727 attrib->type = new_attrib->type;
728 attrib->value = new_attrib->value;
729 return VA_STATUS_SUCCESS;
733 i965_ensure_config_attribute(struct object_config *obj_config,
734 const VAConfigAttrib *new_attrib)
736 VAConfigAttrib *attrib;
738 /* Check for existing attributes */
739 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
741 /* Update existing attribute */
742 attrib->value = new_attrib->value;
743 return VA_STATUS_SUCCESS;
745 return i965_append_config_attribute(obj_config, new_attrib);
749 i965_CreateConfig(VADriverContextP ctx,
751 VAEntrypoint entrypoint,
752 VAConfigAttrib *attrib_list,
754 VAConfigID *config_id) /* out */
756 struct i965_driver_data * const i965 = i965_driver_data(ctx);
757 struct object_config *obj_config;
762 vaStatus = i965_validate_config(ctx, profile, entrypoint);
764 if (VA_STATUS_SUCCESS != vaStatus) {
768 configID = NEW_CONFIG_ID();
769 obj_config = CONFIG(configID);
771 if (NULL == obj_config) {
772 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
776 obj_config->profile = profile;
777 obj_config->entrypoint = entrypoint;
778 obj_config->num_attribs = 0;
780 for (i = 0; i < num_attribs; i++) {
781 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
782 if (vaStatus != VA_STATUS_SUCCESS)
786 if (vaStatus == VA_STATUS_SUCCESS) {
787 VAConfigAttrib attrib, *attrib_found;
788 attrib.type = VAConfigAttribRTFormat;
789 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
790 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
791 if (!attrib_found || !attrib_found->value)
792 vaStatus = i965_append_config_attribute(obj_config, &attrib);
793 else if (!(attrib_found->value & attrib.value))
794 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
798 if (VA_STATUS_SUCCESS != vaStatus) {
799 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
801 *config_id = configID;
808 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
810 struct i965_driver_data *i965 = i965_driver_data(ctx);
811 struct object_config *obj_config = CONFIG(config_id);
814 if (NULL == obj_config) {
815 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
819 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
820 return VA_STATUS_SUCCESS;
823 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
824 VAConfigID config_id,
825 VAProfile *profile, /* out */
826 VAEntrypoint *entrypoint, /* out */
827 VAConfigAttrib *attrib_list, /* out */
828 int *num_attribs) /* out */
830 struct i965_driver_data *i965 = i965_driver_data(ctx);
831 struct object_config *obj_config = CONFIG(config_id);
832 VAStatus vaStatus = VA_STATUS_SUCCESS;
835 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
836 *profile = obj_config->profile;
837 *entrypoint = obj_config->entrypoint;
838 *num_attribs = obj_config->num_attribs;
840 for(i = 0; i < obj_config->num_attribs; i++) {
841 attrib_list[i] = obj_config->attrib_list[i];
848 i965_destroy_surface_storage(struct object_surface *obj_surface)
853 dri_bo_unreference(obj_surface->bo);
854 obj_surface->bo = NULL;
856 if (obj_surface->free_private_data != NULL) {
857 obj_surface->free_private_data(&obj_surface->private_data);
858 obj_surface->private_data = NULL;
863 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
865 struct object_surface *obj_surface = (struct object_surface *)obj;
867 i965_destroy_surface_storage(obj_surface);
868 object_heap_free(heap, obj);
872 i965_surface_native_memory(VADriverContextP ctx,
873 struct object_surface *obj_surface,
877 struct i965_driver_data *i965 = i965_driver_data(ctx);
878 int tiling = HAS_TILED_SURFACE(i965);
880 if (!expected_fourcc)
881 return VA_STATUS_SUCCESS;
883 // todo, should we disable tiling for 422 format?
884 if (expected_fourcc == VA_FOURCC_I420 ||
885 expected_fourcc == VA_FOURCC_IYUV ||
886 expected_fourcc == VA_FOURCC_YV12 ||
887 expected_fourcc == VA_FOURCC_YV16)
890 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
892 return VA_STATUS_SUCCESS;
896 i965_suface_external_memory(VADriverContextP ctx,
897 struct object_surface *obj_surface,
898 int external_memory_type,
899 VASurfaceAttribExternalBuffers *memory_attibute,
902 struct i965_driver_data *i965 = i965_driver_data(ctx);
904 if (!memory_attibute ||
905 !memory_attibute->buffers ||
906 index > memory_attibute->num_buffers)
907 return VA_STATUS_ERROR_INVALID_PARAMETER;
909 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
910 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
911 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
913 obj_surface->fourcc = memory_attibute->pixel_format;
914 obj_surface->width = memory_attibute->pitches[0];
915 obj_surface->size = memory_attibute->data_size;
917 if (memory_attibute->num_planes == 1)
918 obj_surface->height = memory_attibute->data_size / obj_surface->width;
920 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
922 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
923 obj_surface->x_cr_offset = 0;
925 switch (obj_surface->fourcc) {
927 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
928 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
930 obj_surface->subsampling = SUBSAMPLE_YUV420;
931 obj_surface->y_cb_offset = obj_surface->height;
932 obj_surface->y_cr_offset = obj_surface->height;
933 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
934 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
935 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
941 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
942 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
944 obj_surface->subsampling = SUBSAMPLE_YUV420;
945 obj_surface->y_cr_offset = obj_surface->height;
946 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
947 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
948 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
949 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
956 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
957 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
959 obj_surface->subsampling = SUBSAMPLE_YUV420;
960 obj_surface->y_cb_offset = obj_surface->height;
961 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
962 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
963 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
964 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
970 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
972 obj_surface->subsampling = SUBSAMPLE_YUV422H;
973 obj_surface->y_cb_offset = 0;
974 obj_surface->y_cr_offset = 0;
975 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
976 obj_surface->cb_cr_height = obj_surface->orig_height;
977 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
985 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
987 obj_surface->subsampling = SUBSAMPLE_RGBX;
988 obj_surface->y_cb_offset = 0;
989 obj_surface->y_cr_offset = 0;
990 obj_surface->cb_cr_width = 0;
991 obj_surface->cb_cr_height = 0;
992 obj_surface->cb_cr_pitch = 0;
996 case VA_FOURCC_Y800: /* monochrome surface */
997 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
999 obj_surface->subsampling = SUBSAMPLE_YUV400;
1000 obj_surface->y_cb_offset = 0;
1001 obj_surface->y_cr_offset = 0;
1002 obj_surface->cb_cr_width = 0;
1003 obj_surface->cb_cr_height = 0;
1004 obj_surface->cb_cr_pitch = 0;
1008 case VA_FOURCC_411P:
1009 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1010 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1012 obj_surface->subsampling = SUBSAMPLE_YUV411;
1013 obj_surface->y_cb_offset = 0;
1014 obj_surface->y_cr_offset = 0;
1015 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1016 obj_surface->cb_cr_height = obj_surface->orig_height;
1017 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1021 case VA_FOURCC_422H:
1022 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1023 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1025 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1026 obj_surface->y_cb_offset = obj_surface->height;
1027 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1028 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1029 obj_surface->cb_cr_height = obj_surface->orig_height;
1030 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1034 case VA_FOURCC_YV16:
1035 assert(memory_attibute->num_planes == 3);
1036 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1038 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1039 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1040 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1041 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1042 obj_surface->cb_cr_height = obj_surface->orig_height;
1043 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1047 case VA_FOURCC_422V:
1048 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1049 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1051 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1052 obj_surface->y_cb_offset = obj_surface->height;
1053 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1054 obj_surface->cb_cr_width = obj_surface->orig_width;
1055 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1056 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1060 case VA_FOURCC_444P:
1061 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1062 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1064 obj_surface->subsampling = SUBSAMPLE_YUV444;
1065 obj_surface->y_cb_offset = obj_surface->height;
1066 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1067 obj_surface->cb_cr_width = obj_surface->orig_width;
1068 obj_surface->cb_cr_height = obj_surface->orig_height;
1069 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1075 return VA_STATUS_ERROR_INVALID_PARAMETER;
1078 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1079 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1080 "gem flinked vaapi surface",
1081 memory_attibute->buffers[index]);
1082 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1083 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1084 memory_attibute->buffers[index],
1087 if (!obj_surface->bo)
1088 return VA_STATUS_ERROR_INVALID_PARAMETER;
1090 return VA_STATUS_SUCCESS;
1093 /* byte-per-pixel of the first plane */
1095 bpp_1stplane_by_fourcc(unsigned int fourcc)
1097 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1099 if (info && (info->flag & I_S))
1100 return info->bpp[0] / 8;
1106 i965_CreateSurfaces2(
1107 VADriverContextP ctx,
1108 unsigned int format,
1110 unsigned int height,
1111 VASurfaceID *surfaces,
1112 unsigned int num_surfaces,
1113 VASurfaceAttrib *attrib_list,
1114 unsigned int num_attribs
1117 struct i965_driver_data *i965 = i965_driver_data(ctx);
1119 VAStatus vaStatus = VA_STATUS_SUCCESS;
1120 int expected_fourcc = 0;
1121 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1122 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1124 for (i = 0; i < num_attribs && attrib_list; i++) {
1125 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1126 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1127 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1128 expected_fourcc = attrib_list[i].value.value.i;
1131 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1132 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1134 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1136 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1137 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1138 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1139 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1140 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1141 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1144 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1145 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1146 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1147 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1151 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1152 * for post-processing (including color conversion) */
1153 if (VA_RT_FORMAT_YUV420 != format &&
1154 VA_RT_FORMAT_YUV422 != format &&
1155 VA_RT_FORMAT_YUV444 != format &&
1156 VA_RT_FORMAT_YUV411 != format &&
1157 VA_RT_FORMAT_YUV400 != format &&
1158 VA_RT_FORMAT_RGB32 != format) {
1159 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1162 for (i = 0; i < num_surfaces; i++) {
1163 int surfaceID = NEW_SURFACE_ID();
1164 struct object_surface *obj_surface = SURFACE(surfaceID);
1166 if (NULL == obj_surface) {
1167 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1171 surfaces[i] = surfaceID;
1172 obj_surface->status = VASurfaceReady;
1173 obj_surface->orig_width = width;
1174 obj_surface->orig_height = height;
1175 obj_surface->user_disable_tiling = false;
1176 obj_surface->user_h_stride_set = false;
1177 obj_surface->user_v_stride_set = false;
1179 obj_surface->subpic_render_idx = 0;
1180 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1181 obj_surface->subpic[j] = VA_INVALID_ID;
1182 obj_surface->obj_subpic[j] = NULL;
1185 assert(i965->codec_info->min_linear_wpitch);
1186 assert(i965->codec_info->min_linear_hpitch);
1187 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1188 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1189 obj_surface->flags = SURFACE_REFERENCED;
1190 obj_surface->fourcc = 0;
1191 obj_surface->bo = NULL;
1192 obj_surface->locked_image_id = VA_INVALID_ID;
1193 obj_surface->private_data = NULL;
1194 obj_surface->free_private_data = NULL;
1195 obj_surface->subsampling = SUBSAMPLE_YUV420;
1197 switch (memory_type) {
1198 case I965_SURFACE_MEM_NATIVE:
1199 if (memory_attibute) {
1200 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1201 obj_surface->user_disable_tiling = true;
1203 if (memory_attibute->pixel_format) {
1204 if (expected_fourcc)
1205 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1207 expected_fourcc = memory_attibute->pixel_format;
1209 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1210 if (memory_attibute->pitches[0]) {
1211 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1212 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1213 obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane;
1214 obj_surface->user_h_stride_set = true;
1215 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1216 ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER);
1218 if (memory_attibute->offsets[1]) {
1219 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1220 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1221 obj_surface->user_v_stride_set = true;
1222 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1223 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1227 i965_surface_native_memory(ctx,
1233 case I965_SURFACE_MEM_GEM_FLINK:
1234 case I965_SURFACE_MEM_DRM_PRIME:
1235 i965_suface_external_memory(ctx,
1244 /* Error recovery */
1245 if (VA_STATUS_SUCCESS != vaStatus) {
1246 /* surfaces[i-1] was the last successful allocation */
1248 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1250 surfaces[i] = VA_INVALID_SURFACE;
1251 assert(obj_surface);
1252 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1260 i965_CreateSurfaces(VADriverContextP ctx,
1265 VASurfaceID *surfaces) /* out */
1267 return i965_CreateSurfaces2(ctx,
1278 i965_DestroySurfaces(VADriverContextP ctx,
1279 VASurfaceID *surface_list,
1282 struct i965_driver_data *i965 = i965_driver_data(ctx);
1285 for (i = num_surfaces; i--; ) {
1286 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1288 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1289 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1292 return VA_STATUS_SUCCESS;
1296 i965_QueryImageFormats(VADriverContextP ctx,
1297 VAImageFormat *format_list, /* out */
1298 int *num_formats) /* out */
1302 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1303 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1305 format_list[n] = m->va_format;
1311 return VA_STATUS_SUCCESS;
1315 * Guess the format when the usage of a VA surface is unknown
1316 * 1. Without a valid context: YV12
1317 * 2. The current context is valid:
1318 * a) always NV12 on GEN6 and later
1319 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1322 i965_guess_surface_format(VADriverContextP ctx,
1323 VASurfaceID surface,
1324 unsigned int *fourcc,
1325 unsigned int *is_tiled)
1327 struct i965_driver_data *i965 = i965_driver_data(ctx);
1328 struct object_context *obj_context = NULL;
1329 struct object_config *obj_config = NULL;
1331 *fourcc = VA_FOURCC_YV12;
1334 if (i965->current_context_id == VA_INVALID_ID)
1337 obj_context = CONTEXT(i965->current_context_id);
1342 obj_config = obj_context->obj_config;
1348 if (IS_GEN6(i965->intel.device_info) ||
1349 IS_GEN7(i965->intel.device_info) ||
1350 IS_GEN8(i965->intel.device_info)) {
1351 *fourcc = VA_FOURCC_NV12;
1356 switch (obj_config->profile) {
1357 case VAProfileMPEG2Simple:
1358 case VAProfileMPEG2Main:
1359 *fourcc = VA_FOURCC_I420;
1364 *fourcc = VA_FOURCC_NV12;
1371 i965_QuerySubpictureFormats(VADriverContextP ctx,
1372 VAImageFormat *format_list, /* out */
1373 unsigned int *flags, /* out */
1374 unsigned int *num_formats) /* out */
1378 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1379 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1381 format_list[n] = m->va_format;
1383 flags[n] = m->va_flags;
1389 return VA_STATUS_SUCCESS;
1393 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1395 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1397 object_heap_free(heap, obj);
1401 i965_CreateSubpicture(VADriverContextP ctx,
1403 VASubpictureID *subpicture) /* out */
1405 struct i965_driver_data *i965 = i965_driver_data(ctx);
1406 VASubpictureID subpicID = NEW_SUBPIC_ID()
1407 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1410 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1412 struct object_image *obj_image = IMAGE(image);
1414 return VA_STATUS_ERROR_INVALID_IMAGE;
1416 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1418 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1420 *subpicture = subpicID;
1421 obj_subpic->image = image;
1422 obj_subpic->obj_image = obj_image;
1423 obj_subpic->format = m->format;
1424 obj_subpic->width = obj_image->image.width;
1425 obj_subpic->height = obj_image->image.height;
1426 obj_subpic->pitch = obj_image->image.pitches[0];
1427 obj_subpic->bo = obj_image->bo;
1428 obj_subpic->global_alpha = 1.0;
1430 return VA_STATUS_SUCCESS;
1434 i965_DestroySubpicture(VADriverContextP ctx,
1435 VASubpictureID subpicture)
1437 struct i965_driver_data *i965 = i965_driver_data(ctx);
1438 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1441 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1443 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1444 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1445 return VA_STATUS_SUCCESS;
1449 i965_SetSubpictureImage(VADriverContextP ctx,
1450 VASubpictureID subpicture,
1454 return VA_STATUS_ERROR_UNIMPLEMENTED;
1458 i965_SetSubpictureChromakey(VADriverContextP ctx,
1459 VASubpictureID subpicture,
1460 unsigned int chromakey_min,
1461 unsigned int chromakey_max,
1462 unsigned int chromakey_mask)
1465 return VA_STATUS_ERROR_UNIMPLEMENTED;
1469 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1470 VASubpictureID subpicture,
1473 struct i965_driver_data *i965 = i965_driver_data(ctx);
1474 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1476 if(global_alpha > 1.0 || global_alpha < 0.0){
1477 return VA_STATUS_ERROR_INVALID_PARAMETER;
1481 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1483 obj_subpic->global_alpha = global_alpha;
1485 return VA_STATUS_SUCCESS;
1489 i965_AssociateSubpicture(VADriverContextP ctx,
1490 VASubpictureID subpicture,
1491 VASurfaceID *target_surfaces,
1493 short src_x, /* upper left offset in subpicture */
1495 unsigned short src_width,
1496 unsigned short src_height,
1497 short dest_x, /* upper left offset in surface */
1499 unsigned short dest_width,
1500 unsigned short dest_height,
1502 * whether to enable chroma-keying or global-alpha
1503 * see VA_SUBPICTURE_XXX values
1507 struct i965_driver_data *i965 = i965_driver_data(ctx);
1508 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1512 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1514 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1516 obj_subpic->src_rect.x = src_x;
1517 obj_subpic->src_rect.y = src_y;
1518 obj_subpic->src_rect.width = src_width;
1519 obj_subpic->src_rect.height = src_height;
1520 obj_subpic->dst_rect.x = dest_x;
1521 obj_subpic->dst_rect.y = dest_y;
1522 obj_subpic->dst_rect.width = dest_width;
1523 obj_subpic->dst_rect.height = dest_height;
1524 obj_subpic->flags = flags;
1526 for (i = 0; i < num_surfaces; i++) {
1527 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1529 return VA_STATUS_ERROR_INVALID_SURFACE;
1531 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1532 if(obj_surface->subpic[j] == VA_INVALID_ID){
1533 assert(obj_surface->obj_subpic[j] == NULL);
1534 obj_surface->subpic[j] = subpicture;
1535 obj_surface->obj_subpic[j] = obj_subpic;
1540 if(j == I965_MAX_SUBPIC_SUM){
1541 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1545 return VA_STATUS_SUCCESS;
1550 i965_DeassociateSubpicture(VADriverContextP ctx,
1551 VASubpictureID subpicture,
1552 VASurfaceID *target_surfaces,
1555 struct i965_driver_data *i965 = i965_driver_data(ctx);
1556 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1560 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1562 for (i = 0; i < num_surfaces; i++) {
1563 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1565 return VA_STATUS_ERROR_INVALID_SURFACE;
1567 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1568 if (obj_surface->subpic[j] == subpicture) {
1569 assert(obj_surface->obj_subpic[j] == obj_subpic);
1570 obj_surface->subpic[j] = VA_INVALID_ID;
1571 obj_surface->obj_subpic[j] = NULL;
1576 if(j == I965_MAX_SUBPIC_SUM){
1577 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1580 return VA_STATUS_SUCCESS;
1584 i965_reference_buffer_store(struct buffer_store **ptr,
1585 struct buffer_store *buffer_store)
1587 assert(*ptr == NULL);
1590 buffer_store->ref_count++;
1591 *ptr = buffer_store;
1596 i965_release_buffer_store(struct buffer_store **ptr)
1598 struct buffer_store *buffer_store = *ptr;
1600 if (buffer_store == NULL)
1603 assert(buffer_store->bo || buffer_store->buffer);
1604 assert(!(buffer_store->bo && buffer_store->buffer));
1605 buffer_store->ref_count--;
1607 if (buffer_store->ref_count == 0) {
1608 dri_bo_unreference(buffer_store->bo);
1609 free(buffer_store->buffer);
1610 buffer_store->bo = NULL;
1611 buffer_store->buffer = NULL;
1619 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1621 struct object_context *obj_context = (struct object_context *)obj;
1624 if (obj_context->hw_context) {
1625 obj_context->hw_context->destroy(obj_context->hw_context);
1626 obj_context->hw_context = NULL;
1629 if (obj_context->codec_type == CODEC_PROC) {
1630 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1632 } else if (obj_context->codec_type == CODEC_ENC) {
1633 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1634 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1635 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1637 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1638 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1640 free(obj_context->codec_state.encode.slice_params);
1642 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1643 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1644 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1646 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1647 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1649 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1650 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1652 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1653 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1655 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1656 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1658 free(obj_context->codec_state.encode.slice_params_ext);
1659 if (obj_context->codec_state.encode.slice_rawdata_index) {
1660 free(obj_context->codec_state.encode.slice_rawdata_index);
1661 obj_context->codec_state.encode.slice_rawdata_index = NULL;
1663 if (obj_context->codec_state.encode.slice_rawdata_count) {
1664 free(obj_context->codec_state.encode.slice_rawdata_count);
1665 obj_context->codec_state.encode.slice_rawdata_count = NULL;
1668 if (obj_context->codec_state.encode.slice_header_index) {
1669 free(obj_context->codec_state.encode.slice_header_index);
1670 obj_context->codec_state.encode.slice_header_index = NULL;
1673 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
1674 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
1675 free(obj_context->codec_state.encode.packed_header_params_ext);
1677 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
1678 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
1679 free(obj_context->codec_state.encode.packed_header_data_ext);
1682 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1683 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1685 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1686 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1687 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1689 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1690 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1692 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1693 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1695 free(obj_context->codec_state.decode.slice_params);
1696 free(obj_context->codec_state.decode.slice_datas);
1699 free(obj_context->render_targets);
1700 object_heap_free(heap, obj);
1704 i965_CreateContext(VADriverContextP ctx,
1705 VAConfigID config_id,
1709 VASurfaceID *render_targets,
1710 int num_render_targets,
1711 VAContextID *context) /* out */
1713 struct i965_driver_data *i965 = i965_driver_data(ctx);
1714 struct i965_render_state *render_state = &i965->render_state;
1715 struct object_config *obj_config = CONFIG(config_id);
1716 struct object_context *obj_context = NULL;
1717 VAConfigAttrib *attrib;
1718 VAStatus vaStatus = VA_STATUS_SUCCESS;
1722 if (NULL == obj_config) {
1723 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1727 if (picture_width > i965->codec_info->max_width ||
1728 picture_height > i965->codec_info->max_height) {
1729 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1734 /* Validate picture dimensions */
1735 contextID = NEW_CONTEXT_ID();
1736 obj_context = CONTEXT(contextID);
1738 if (NULL == obj_context) {
1739 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1743 render_state->inited = 1;
1745 switch (obj_config->profile) {
1746 case VAProfileH264ConstrainedBaseline:
1747 case VAProfileH264Main:
1748 case VAProfileH264High:
1749 if (!HAS_H264_DECODING(i965) &&
1750 !HAS_H264_ENCODING(i965))
1751 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1752 render_state->interleaved_uv = 1;
1754 case VAProfileH264MultiviewHigh:
1755 case VAProfileH264StereoHigh:
1756 if (!HAS_H264_MVC_DECODING(i965))
1757 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1758 render_state->interleaved_uv = 1;
1761 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info));
1765 *context = contextID;
1766 obj_context->flags = flag;
1767 obj_context->context_id = contextID;
1768 obj_context->obj_config = obj_config;
1769 obj_context->picture_width = picture_width;
1770 obj_context->picture_height = picture_height;
1771 obj_context->num_render_targets = num_render_targets;
1772 obj_context->render_targets =
1773 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1774 obj_context->hw_context = NULL;
1776 for(i = 0; i < num_render_targets; i++) {
1777 if (NULL == SURFACE(render_targets[i])) {
1778 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1782 obj_context->render_targets[i] = render_targets[i];
1785 if (VA_STATUS_SUCCESS == vaStatus) {
1786 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1787 obj_context->codec_type = CODEC_PROC;
1788 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1789 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1790 assert(i965->codec_info->proc_hw_context_init);
1791 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1792 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1793 VAConfigAttrib *packed_attrib;
1794 obj_context->codec_type = CODEC_ENC;
1795 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1796 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1797 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1798 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1799 sizeof(*obj_context->codec_state.encode.slice_params));
1800 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
1801 obj_context->codec_state.encode.packed_header_params_ext =
1802 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
1803 sizeof(struct buffer_store *));
1805 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
1806 obj_context->codec_state.encode.packed_header_data_ext =
1807 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
1808 sizeof(struct buffer_store *));
1810 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
1811 obj_context->codec_state.encode.slice_rawdata_index =
1812 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
1813 obj_context->codec_state.encode.slice_rawdata_count =
1814 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
1816 obj_context->codec_state.encode.slice_header_index =
1817 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
1819 obj_context->codec_state.encode.slice_index = 0;
1820 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
1822 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
1824 /* use the default value. SPS/PPS/RAWDATA is passed from user
1825 * while Slice_header data is generated by driver.
1827 obj_context->codec_state.encode.packed_header_flag =
1828 VA_ENC_PACKED_HEADER_SEQUENCE |
1829 VA_ENC_PACKED_HEADER_PICTURE |
1830 VA_ENC_PACKED_HEADER_RAW_DATA;
1832 assert(i965->codec_info->enc_hw_context_init);
1833 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1835 obj_context->codec_type = CODEC_DEC;
1836 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1837 obj_context->codec_state.decode.current_render_target = -1;
1838 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1839 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1840 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1841 sizeof(*obj_context->codec_state.decode.slice_params));
1842 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1843 sizeof(*obj_context->codec_state.decode.slice_datas));
1845 assert(i965->codec_info->dec_hw_context_init);
1846 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1850 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
1852 return VA_STATUS_ERROR_INVALID_CONFIG;
1853 obj_context->codec_state.base.chroma_formats = attrib->value;
1855 /* Error recovery */
1856 if (VA_STATUS_SUCCESS != vaStatus) {
1857 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1860 i965->current_context_id = contextID;
1866 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1868 struct i965_driver_data *i965 = i965_driver_data(ctx);
1869 struct object_context *obj_context = CONTEXT(context);
1871 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1873 if (i965->current_context_id == context)
1874 i965->current_context_id = VA_INVALID_ID;
1876 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1878 return VA_STATUS_SUCCESS;
1882 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1884 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1886 assert(obj_buffer->buffer_store);
1887 i965_release_buffer_store(&obj_buffer->buffer_store);
1888 object_heap_free(heap, obj);
1892 i965_create_buffer_internal(VADriverContextP ctx,
1893 VAContextID context,
1896 unsigned int num_elements,
1901 struct i965_driver_data *i965 = i965_driver_data(ctx);
1902 struct object_buffer *obj_buffer = NULL;
1903 struct buffer_store *buffer_store = NULL;
1908 case VAPictureParameterBufferType:
1909 case VAIQMatrixBufferType:
1910 case VAQMatrixBufferType:
1911 case VABitPlaneBufferType:
1912 case VASliceGroupMapBufferType:
1913 case VASliceParameterBufferType:
1914 case VASliceDataBufferType:
1915 case VAMacroblockParameterBufferType:
1916 case VAResidualDataBufferType:
1917 case VADeblockingParameterBufferType:
1918 case VAImageBufferType:
1919 case VAEncCodedBufferType:
1920 case VAEncSequenceParameterBufferType:
1921 case VAEncPictureParameterBufferType:
1922 case VAEncSliceParameterBufferType:
1923 case VAEncPackedHeaderParameterBufferType:
1924 case VAEncPackedHeaderDataBufferType:
1925 case VAEncMiscParameterBufferType:
1926 case VAProcPipelineParameterBufferType:
1927 case VAProcFilterParameterBufferType:
1928 case VAHuffmanTableBufferType:
1929 case VAProbabilityBufferType:
1934 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1937 bufferID = NEW_BUFFER_ID();
1938 obj_buffer = BUFFER(bufferID);
1940 if (NULL == obj_buffer) {
1941 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1944 if (type == VAEncCodedBufferType) {
1945 size += I965_CODEDBUFFER_HEADER_SIZE;
1946 size += 0x1000; /* for upper bound check */
1949 obj_buffer->max_num_elements = num_elements;
1950 obj_buffer->num_elements = num_elements;
1951 obj_buffer->size_element = size;
1952 obj_buffer->type = type;
1953 obj_buffer->buffer_store = NULL;
1954 buffer_store = calloc(1, sizeof(struct buffer_store));
1955 assert(buffer_store);
1956 buffer_store->ref_count = 1;
1958 if (store_bo != NULL) {
1959 buffer_store->bo = store_bo;
1960 dri_bo_reference(buffer_store->bo);
1963 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1964 } else if (type == VASliceDataBufferType ||
1965 type == VAImageBufferType ||
1966 type == VAEncCodedBufferType ||
1967 type == VAProbabilityBufferType) {
1968 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1970 size * num_elements, 64);
1971 assert(buffer_store->bo);
1973 if (type == VAEncCodedBufferType) {
1974 struct i965_coded_buffer_segment *coded_buffer_segment;
1976 dri_bo_map(buffer_store->bo, 1);
1977 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1978 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1979 coded_buffer_segment->base.bit_offset = 0;
1980 coded_buffer_segment->base.status = 0;
1981 coded_buffer_segment->base.buf = NULL;
1982 coded_buffer_segment->base.next = NULL;
1983 coded_buffer_segment->mapped = 0;
1984 coded_buffer_segment->codec = 0;
1985 dri_bo_unmap(buffer_store->bo);
1987 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1993 if (type == VAEncPackedHeaderDataBufferType) {
1994 msize = ALIGN(size, 4);
1997 buffer_store->buffer = malloc(msize * num_elements);
1998 assert(buffer_store->buffer);
2001 memcpy(buffer_store->buffer, data, size * num_elements);
2004 buffer_store->num_elements = obj_buffer->num_elements;
2005 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2006 i965_release_buffer_store(&buffer_store);
2009 return VA_STATUS_SUCCESS;
2013 i965_CreateBuffer(VADriverContextP ctx,
2014 VAContextID context, /* in */
2015 VABufferType type, /* in */
2016 unsigned int size, /* in */
2017 unsigned int num_elements, /* in */
2018 void *data, /* in */
2019 VABufferID *buf_id) /* out */
2021 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2026 i965_BufferSetNumElements(VADriverContextP ctx,
2027 VABufferID buf_id, /* in */
2028 unsigned int num_elements) /* in */
2030 struct i965_driver_data *i965 = i965_driver_data(ctx);
2031 struct object_buffer *obj_buffer = BUFFER(buf_id);
2032 VAStatus vaStatus = VA_STATUS_SUCCESS;
2034 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2036 if ((num_elements < 0) ||
2037 (num_elements > obj_buffer->max_num_elements)) {
2038 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2040 obj_buffer->num_elements = num_elements;
2041 if (obj_buffer->buffer_store != NULL) {
2042 obj_buffer->buffer_store->num_elements = num_elements;
2050 i965_MapBuffer(VADriverContextP ctx,
2051 VABufferID buf_id, /* in */
2052 void **pbuf) /* out */
2054 struct i965_driver_data *i965 = i965_driver_data(ctx);
2055 struct object_buffer *obj_buffer = BUFFER(buf_id);
2056 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2058 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2059 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2060 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2062 if (NULL != obj_buffer->buffer_store->bo) {
2063 unsigned int tiling, swizzle;
2065 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2067 if (tiling != I915_TILING_NONE)
2068 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2070 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2072 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2073 *pbuf = obj_buffer->buffer_store->bo->virtual;
2075 if (obj_buffer->type == VAEncCodedBufferType) {
2077 unsigned char *buffer = NULL;
2078 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2080 if (!coded_buffer_segment->mapped) {
2081 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2083 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2085 if (coded_buffer_segment->codec == CODEC_H264 ||
2086 coded_buffer_segment->codec == CODEC_H264_MVC) {
2087 delimiter0 = H264_DELIMITER0;
2088 delimiter1 = H264_DELIMITER1;
2089 delimiter2 = H264_DELIMITER2;
2090 delimiter3 = H264_DELIMITER3;
2091 delimiter4 = H264_DELIMITER4;
2092 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2093 delimiter0 = MPEG2_DELIMITER0;
2094 delimiter1 = MPEG2_DELIMITER1;
2095 delimiter2 = MPEG2_DELIMITER2;
2096 delimiter3 = MPEG2_DELIMITER3;
2097 delimiter4 = MPEG2_DELIMITER4;
2099 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2102 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
2103 if ((buffer[i] == delimiter0) &&
2104 (buffer[i + 1] == delimiter1) &&
2105 (buffer[i + 2] == delimiter2) &&
2106 (buffer[i + 3] == delimiter3) &&
2107 (buffer[i + 4] == delimiter4))
2111 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
2112 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2115 coded_buffer_segment->base.size = i;
2116 coded_buffer_segment->mapped = 1;
2118 assert(coded_buffer_segment->base.buf);
2122 vaStatus = VA_STATUS_SUCCESS;
2123 } else if (NULL != obj_buffer->buffer_store->buffer) {
2124 *pbuf = obj_buffer->buffer_store->buffer;
2125 vaStatus = VA_STATUS_SUCCESS;
2132 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2134 struct i965_driver_data *i965 = i965_driver_data(ctx);
2135 struct object_buffer *obj_buffer = BUFFER(buf_id);
2136 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2138 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2139 return VA_STATUS_ERROR_INVALID_BUFFER;
2141 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2142 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2143 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2145 if (NULL != obj_buffer->buffer_store->bo) {
2146 unsigned int tiling, swizzle;
2148 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2150 if (tiling != I915_TILING_NONE)
2151 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2153 dri_bo_unmap(obj_buffer->buffer_store->bo);
2155 vaStatus = VA_STATUS_SUCCESS;
2156 } else if (NULL != obj_buffer->buffer_store->buffer) {
2158 vaStatus = VA_STATUS_SUCCESS;
2165 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2167 struct i965_driver_data *i965 = i965_driver_data(ctx);
2168 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2170 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2172 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2174 return VA_STATUS_SUCCESS;
2178 i965_BeginPicture(VADriverContextP ctx,
2179 VAContextID context,
2180 VASurfaceID render_target)
2182 struct i965_driver_data *i965 = i965_driver_data(ctx);
2183 struct object_context *obj_context = CONTEXT(context);
2184 struct object_surface *obj_surface = SURFACE(render_target);
2185 struct object_config *obj_config;
2189 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2190 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2191 obj_config = obj_context->obj_config;
2192 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2194 switch (obj_config->profile) {
2195 case VAProfileMPEG2Simple:
2196 case VAProfileMPEG2Main:
2197 vaStatus = VA_STATUS_SUCCESS;
2200 case VAProfileH264ConstrainedBaseline:
2201 case VAProfileH264Main:
2202 case VAProfileH264High:
2203 vaStatus = VA_STATUS_SUCCESS;
2206 case VAProfileH264MultiviewHigh:
2207 case VAProfileH264StereoHigh:
2208 if (HAS_H264_MVC_DECODING_PROFILE(i965, obj_config->profile) ||
2209 HAS_H264_MVC_ENCODING(i965)) {
2210 vaStatus = VA_STATUS_SUCCESS;
2212 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2216 case VAProfileVC1Simple:
2217 case VAProfileVC1Main:
2218 case VAProfileVC1Advanced:
2219 vaStatus = VA_STATUS_SUCCESS;
2222 case VAProfileJPEGBaseline:
2223 vaStatus = VA_STATUS_SUCCESS;
2227 vaStatus = VA_STATUS_SUCCESS;
2230 case VAProfileVP8Version0_3:
2231 vaStatus = VA_STATUS_SUCCESS;
2235 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2239 if (obj_context->codec_type == CODEC_PROC) {
2240 obj_context->codec_state.proc.current_render_target = render_target;
2241 } else if (obj_context->codec_type == CODEC_ENC) {
2242 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2244 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2245 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2248 obj_context->codec_state.encode.num_slice_params = 0;
2251 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2253 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2254 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2256 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2257 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2259 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2260 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2262 obj_context->codec_state.encode.num_slice_params_ext = 0;
2263 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2264 obj_context->codec_state.encode.last_packed_header_type = 0;
2265 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2266 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2267 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2268 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2269 memset(obj_context->codec_state.encode.slice_header_index, 0,
2270 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2272 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2273 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2274 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2275 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2276 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2277 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2278 obj_context->codec_state.encode.slice_index = 0;
2280 obj_context->codec_state.decode.current_render_target = render_target;
2281 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2282 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2283 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2284 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2286 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2287 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2288 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2291 obj_context->codec_state.decode.num_slice_params = 0;
2292 obj_context->codec_state.decode.num_slice_datas = 0;
2298 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2300 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2302 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2303 struct object_context *obj_context, \
2304 struct object_buffer *obj_buffer) \
2306 struct category##_state *category = &obj_context->codec_state.category; \
2307 i965_release_buffer_store(&category->member); \
2308 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2309 return VA_STATUS_SUCCESS; \
2312 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2314 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2315 struct object_context *obj_context, \
2316 struct object_buffer *obj_buffer) \
2318 struct category##_state *category = &obj_context->codec_state.category; \
2319 if (category->num_##member == category->max_##member) { \
2320 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2321 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2322 category->max_##member += NUM_SLICES; \
2324 i965_release_buffer_store(&category->member[category->num_##member]); \
2325 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2326 category->num_##member++; \
2327 return VA_STATUS_SUCCESS; \
2330 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2332 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2333 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2334 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2335 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2336 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2337 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2339 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2340 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2341 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2344 i965_decoder_render_picture(VADriverContextP ctx,
2345 VAContextID context,
2346 VABufferID *buffers,
2349 struct i965_driver_data *i965 = i965_driver_data(ctx);
2350 struct object_context *obj_context = CONTEXT(context);
2351 VAStatus vaStatus = VA_STATUS_SUCCESS;
2354 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2356 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2357 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2360 return VA_STATUS_ERROR_INVALID_BUFFER;
2362 switch (obj_buffer->type) {
2363 case VAPictureParameterBufferType:
2364 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2367 case VAIQMatrixBufferType:
2368 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2371 case VABitPlaneBufferType:
2372 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2375 case VASliceParameterBufferType:
2376 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2379 case VASliceDataBufferType:
2380 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2383 case VAHuffmanTableBufferType:
2384 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2387 case VAProbabilityBufferType:
2388 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2392 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2400 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2402 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2403 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2404 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2405 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2406 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2407 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2408 /* extended buffer */
2409 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2410 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2412 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2413 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2414 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2416 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
2417 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
2420 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2421 struct object_context *obj_context,
2422 struct object_buffer *obj_buffer,
2425 struct encode_state *encode = &obj_context->codec_state.encode;
2427 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2428 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2429 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2430 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2432 return VA_STATUS_SUCCESS;
2436 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2437 struct object_context *obj_context,
2438 struct object_buffer *obj_buffer,
2441 struct encode_state *encode = &obj_context->codec_state.encode;
2443 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2444 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2445 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2446 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2448 return VA_STATUS_SUCCESS;
2452 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2453 struct object_context *obj_context,
2454 struct object_buffer *obj_buffer)
2456 struct encode_state *encode = &obj_context->codec_state.encode;
2457 VAEncMiscParameterBuffer *param = NULL;
2459 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2460 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2462 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2464 if (param->type >= ARRAY_ELEMS(encode->misc_param))
2465 return VA_STATUS_ERROR_INVALID_PARAMETER;
2467 i965_release_buffer_store(&encode->misc_param[param->type]);
2468 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2470 return VA_STATUS_SUCCESS;
2474 i965_encoder_render_picture(VADriverContextP ctx,
2475 VAContextID context,
2476 VABufferID *buffers,
2479 struct i965_driver_data *i965 = i965_driver_data(ctx);
2480 struct object_context *obj_context = CONTEXT(context);
2481 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2482 struct encode_state *encode;
2485 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2487 encode = &obj_context->codec_state.encode;
2488 for (i = 0; i < num_buffers; i++) {
2489 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2492 return VA_STATUS_ERROR_INVALID_BUFFER;
2494 switch (obj_buffer->type) {
2495 case VAQMatrixBufferType:
2496 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2499 case VAIQMatrixBufferType:
2500 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2503 case VAEncSequenceParameterBufferType:
2504 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2507 case VAEncPictureParameterBufferType:
2508 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2511 case VAEncSliceParameterBufferType:
2512 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2513 if (vaStatus == VA_STATUS_SUCCESS) {
2514 /* When the max number of slices is updated, it also needs
2515 * to reallocate the arrays that is used to store
2516 * the packed data index/count for the slice
2518 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
2519 encode->slice_index++;
2521 if (encode->slice_index == encode->max_slice_num) {
2522 int slice_num = encode->max_slice_num;
2523 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
2524 (slice_num + NUM_SLICES) * sizeof(int));
2525 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
2526 (slice_num + NUM_SLICES) * sizeof(int));
2527 encode->slice_header_index = realloc(encode->slice_header_index,
2528 (slice_num + NUM_SLICES) * sizeof(int));
2529 memset(encode->slice_rawdata_index + slice_num, 0,
2530 sizeof(int) * NUM_SLICES);
2531 memset(encode->slice_rawdata_count + slice_num, 0,
2532 sizeof(int) * NUM_SLICES);
2533 memset(encode->slice_header_index + slice_num, 0,
2534 sizeof(int) * NUM_SLICES);
2536 encode->max_slice_num += NUM_SLICES;
2537 if ((encode->slice_rawdata_index == NULL) ||
2538 (encode->slice_header_index == NULL) ||
2539 (encode->slice_rawdata_count == NULL)) {
2540 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2547 case VAEncPackedHeaderParameterBufferType:
2549 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2550 encode->last_packed_header_type = param->type;
2552 if ((param->type == VAEncPackedHeaderRawData) ||
2553 (param->type == VAEncPackedHeaderSlice)) {
2554 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
2556 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2559 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2564 case VAEncPackedHeaderDataBufferType:
2566 if (encode->last_packed_header_type == 0) {
2567 WARN_ONCE("the packed header data is passed without type!\n");
2568 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
2571 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
2572 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
2573 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
2575 /* When the PACKED_SLICE_HEADER flag is passed, it will use
2576 * the packed_slice_header as the delimeter to decide how
2577 * the packed rawdata is inserted for the given slice.
2578 * Otherwise it will use the VAEncSequenceParameterBuffer
2581 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
2582 /* store the first index of the packed header data for current slice */
2583 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
2584 encode->slice_rawdata_index[encode->slice_index] =
2585 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
2587 encode->slice_rawdata_count[encode->slice_index]++;
2588 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
2589 /* find one packed slice_header delimeter. And the following
2590 * packed data is for the next slice
2592 encode->slice_header_index[encode->slice_index] =
2593 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
2594 encode->slice_index++;
2595 /* Reallocate the buffer to record the index/count of
2596 * packed_data for one slice.
2598 if (encode->slice_index == encode->max_slice_num) {
2599 int slice_num = encode->max_slice_num;
2601 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
2602 (slice_num + NUM_SLICES) * sizeof(int));
2603 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
2604 (slice_num + NUM_SLICES) * sizeof(int));
2605 encode->slice_header_index = realloc(encode->slice_header_index,
2606 (slice_num + NUM_SLICES) * sizeof(int));
2607 memset(encode->slice_rawdata_index + slice_num, 0,
2608 sizeof(int) * NUM_SLICES);
2609 memset(encode->slice_rawdata_count + slice_num, 0,
2610 sizeof(int) * NUM_SLICES);
2611 memset(encode->slice_header_index + slice_num, 0,
2612 sizeof(int) * NUM_SLICES);
2613 encode->max_slice_num += NUM_SLICES;
2617 if (vaStatus == VA_STATUS_SUCCESS) {
2618 /* store the first index of the packed header data for current slice */
2619 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
2620 encode->slice_rawdata_index[encode->slice_index] =
2621 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
2623 encode->slice_rawdata_count[encode->slice_index]++;
2624 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
2625 if (encode->slice_header_index[encode->slice_index] == 0) {
2626 encode->slice_header_index[encode->slice_index] =
2627 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
2629 WARN_ONCE("Multi slice header data is passed for"
2630 " slice %d!\n", encode->slice_index);
2636 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2637 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2638 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2639 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2640 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
2641 VA_STATUS_ERROR_ENCODING_ERROR);
2642 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2645 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2647 encode->last_packed_header_type = 0;
2651 case VAEncMiscParameterBufferType:
2652 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2658 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2666 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2668 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2669 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2672 i965_proc_render_picture(VADriverContextP ctx,
2673 VAContextID context,
2674 VABufferID *buffers,
2677 struct i965_driver_data *i965 = i965_driver_data(ctx);
2678 struct object_context *obj_context = CONTEXT(context);
2679 VAStatus vaStatus = VA_STATUS_SUCCESS;
2682 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2684 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2685 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2688 return VA_STATUS_ERROR_INVALID_BUFFER;
2690 switch (obj_buffer->type) {
2691 case VAProcPipelineParameterBufferType:
2692 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2696 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2705 i965_RenderPicture(VADriverContextP ctx,
2706 VAContextID context,
2707 VABufferID *buffers,
2710 struct i965_driver_data *i965 = i965_driver_data(ctx);
2711 struct object_context *obj_context;
2712 struct object_config *obj_config;
2713 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2715 obj_context = CONTEXT(context);
2716 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2718 if (num_buffers <= 0)
2719 return VA_STATUS_ERROR_INVALID_PARAMETER;
2721 obj_config = obj_context->obj_config;
2722 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2724 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2725 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2726 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2727 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2729 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2736 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2738 struct i965_driver_data *i965 = i965_driver_data(ctx);
2739 struct object_context *obj_context = CONTEXT(context);
2740 struct object_config *obj_config;
2742 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2743 obj_config = obj_context->obj_config;
2744 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2746 if (obj_context->codec_type == CODEC_PROC) {
2747 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2748 } else if (obj_context->codec_type == CODEC_ENC) {
2749 ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2751 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
2752 obj_context->codec_state.encode.num_packed_header_data_ext) {
2753 WARN_ONCE("the packed header/data is not paired for encoding!\n");
2754 return VA_STATUS_ERROR_INVALID_PARAMETER;
2756 if (!(obj_context->codec_state.encode.pic_param ||
2757 obj_context->codec_state.encode.pic_param_ext)) {
2758 return VA_STATUS_ERROR_INVALID_PARAMETER;
2760 if (!(obj_context->codec_state.encode.seq_param ||
2761 obj_context->codec_state.encode.seq_param_ext)) {
2762 return VA_STATUS_ERROR_INVALID_PARAMETER;
2764 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2765 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2766 return VA_STATUS_ERROR_INVALID_PARAMETER;
2769 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
2770 (obj_context->codec_state.encode.num_slice_params_ext !=
2771 obj_context->codec_state.encode.slice_index)) {
2772 WARN_ONCE("packed slice_header data is missing for some slice"
2773 " under packed SLICE_HEADER mode\n");
2774 return VA_STATUS_ERROR_INVALID_PARAMETER;
2777 if (obj_context->codec_state.decode.pic_param == NULL) {
2778 return VA_STATUS_ERROR_INVALID_PARAMETER;
2780 if (obj_context->codec_state.decode.num_slice_params <=0) {
2781 return VA_STATUS_ERROR_INVALID_PARAMETER;
2783 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2784 return VA_STATUS_ERROR_INVALID_PARAMETER;
2787 if (obj_context->codec_state.decode.num_slice_params !=
2788 obj_context->codec_state.decode.num_slice_datas) {
2789 return VA_STATUS_ERROR_INVALID_PARAMETER;
2793 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
2794 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2798 i965_SyncSurface(VADriverContextP ctx,
2799 VASurfaceID render_target)
2801 struct i965_driver_data *i965 = i965_driver_data(ctx);
2802 struct object_surface *obj_surface = SURFACE(render_target);
2804 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2807 drm_intel_bo_wait_rendering(obj_surface->bo);
2809 return VA_STATUS_SUCCESS;
2813 i965_QuerySurfaceStatus(VADriverContextP ctx,
2814 VASurfaceID render_target,
2815 VASurfaceStatus *status) /* out */
2817 struct i965_driver_data *i965 = i965_driver_data(ctx);
2818 struct object_surface *obj_surface = SURFACE(render_target);
2820 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2822 if (obj_surface->bo) {
2823 if (drm_intel_bo_busy(obj_surface->bo)){
2824 *status = VASurfaceRendering;
2827 *status = VASurfaceReady;
2830 *status = VASurfaceReady;
2833 return VA_STATUS_SUCCESS;
2836 static VADisplayAttribute *
2837 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2839 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2842 if (!i965->display_attributes)
2845 for (i = 0; i < i965->num_display_attributes; i++) {
2846 if (i965->display_attributes[i].type == type)
2847 return &i965->display_attributes[i];
2853 i965_display_attributes_terminate(VADriverContextP ctx)
2855 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2857 if (i965->display_attributes) {
2858 free(i965->display_attributes);
2859 i965->display_attributes = NULL;
2860 i965->num_display_attributes = 0;
2865 i965_display_attributes_init(VADriverContextP ctx)
2867 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2869 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2870 i965->display_attributes = malloc(
2871 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2872 if (!i965->display_attributes)
2876 i965->display_attributes,
2877 i965_display_attributes,
2878 sizeof(i965_display_attributes)
2881 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2882 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2883 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2884 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2885 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2887 if (!i965->rotation_attrib ||
2888 !i965->brightness_attrib ||
2889 !i965->contrast_attrib ||
2890 !i965->hue_attrib ||
2891 !i965->saturation_attrib) {
2897 i965_display_attributes_terminate(ctx);
2902 * Query display attributes
2903 * The caller must provide a "attr_list" array that can hold at
2904 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2905 * returned in "attr_list" is returned in "num_attributes".
2908 i965_QueryDisplayAttributes(
2909 VADriverContextP ctx,
2910 VADisplayAttribute *attribs, /* out */
2911 int *num_attribs_ptr /* out */
2914 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2916 if (attribs && num_attribs > 0)
2917 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2919 if (num_attribs_ptr)
2920 *num_attribs_ptr = num_attribs;
2922 return VA_STATUS_SUCCESS;
2926 * Get display attributes
2927 * This function returns the current attribute values in "attr_list".
2928 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2929 * from vaQueryDisplayAttributes() can have their values retrieved.
2932 i965_GetDisplayAttributes(
2933 VADriverContextP ctx,
2934 VADisplayAttribute *attribs, /* inout */
2935 int num_attribs /* in */
2940 for (i = 0; i < num_attribs; i++) {
2941 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2943 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2944 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2945 dst_attrib->min_value = src_attrib->min_value;
2946 dst_attrib->max_value = src_attrib->max_value;
2947 dst_attrib->value = src_attrib->value;
2950 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2952 return VA_STATUS_SUCCESS;
2956 * Set display attributes
2957 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2958 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2959 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2962 i965_SetDisplayAttributes(
2963 VADriverContextP ctx,
2964 VADisplayAttribute *attribs, /* in */
2965 int num_attribs /* in */
2970 for (i = 0; i < num_attribs; i++) {
2971 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2973 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2975 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2977 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2980 if (src_attrib->value < dst_attrib->min_value ||
2981 src_attrib->value > dst_attrib->max_value)
2982 return VA_STATUS_ERROR_INVALID_PARAMETER;
2984 dst_attrib->value = src_attrib->value;
2985 /* XXX: track modified attributes through timestamps */
2987 return VA_STATUS_SUCCESS;
2991 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2992 VASurfaceID surface,
2993 void **buffer, /* out */
2994 unsigned int *stride) /* out */
2997 return VA_STATUS_ERROR_UNIMPLEMENTED;
3001 i965_destroy_heap(struct object_heap *heap,
3002 void (*func)(struct object_heap *heap, struct object_base *object))
3004 struct object_base *object;
3005 object_heap_iterator iter;
3007 object = object_heap_first(heap, &iter);
3013 object = object_heap_next(heap, &iter);
3016 object_heap_destroy(heap);
3021 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3024 i965_CreateImage(VADriverContextP ctx,
3025 VAImageFormat *format,
3028 VAImage *out_image) /* out */
3030 struct i965_driver_data *i965 = i965_driver_data(ctx);
3031 struct object_image *obj_image;
3032 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3034 unsigned int size2, size, awidth, aheight;
3036 out_image->image_id = VA_INVALID_ID;
3037 out_image->buf = VA_INVALID_ID;
3039 image_id = NEW_IMAGE_ID();
3040 if (image_id == VA_INVALID_ID)
3041 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3043 obj_image = IMAGE(image_id);
3045 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3046 obj_image->bo = NULL;
3047 obj_image->palette = NULL;
3048 obj_image->derived_surface = VA_INVALID_ID;
3050 VAImage * const image = &obj_image->image;
3051 image->image_id = image_id;
3052 image->buf = VA_INVALID_ID;
3054 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3056 if ((format->fourcc == VA_FOURCC_YV12) ||
3057 (format->fourcc == VA_FOURCC_I420)) {
3058 if (awidth % 128 != 0) {
3059 awidth = ALIGN(width, 128);
3063 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3064 size = awidth * aheight;
3065 size2 = (awidth / 2) * (aheight / 2);
3067 image->num_palette_entries = 0;
3068 image->entry_bytes = 0;
3069 memset(image->component_order, 0, sizeof(image->component_order));
3071 switch (format->fourcc) {
3072 case VA_FOURCC_IA44:
3073 case VA_FOURCC_AI44:
3074 image->num_planes = 1;
3075 image->pitches[0] = awidth;
3076 image->offsets[0] = 0;
3077 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3078 image->num_palette_entries = 16;
3079 image->entry_bytes = 3;
3080 image->component_order[0] = 'R';
3081 image->component_order[1] = 'G';
3082 image->component_order[2] = 'B';
3084 case VA_FOURCC_IA88:
3085 case VA_FOURCC_AI88:
3086 image->num_planes = 1;
3087 image->pitches[0] = awidth * 2;
3088 image->offsets[0] = 0;
3089 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3090 image->num_palette_entries = 256;
3091 image->entry_bytes = 3;
3092 image->component_order[0] = 'R';
3093 image->component_order[1] = 'G';
3094 image->component_order[2] = 'B';
3096 case VA_FOURCC_ARGB:
3097 case VA_FOURCC_ABGR:
3098 case VA_FOURCC_BGRA:
3099 case VA_FOURCC_RGBA:
3100 case VA_FOURCC_BGRX:
3101 case VA_FOURCC_RGBX:
3102 image->num_planes = 1;
3103 image->pitches[0] = awidth * 4;
3104 image->offsets[0] = 0;
3105 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3107 case VA_FOURCC_YV12:
3108 image->num_planes = 3;
3109 image->pitches[0] = awidth;
3110 image->offsets[0] = 0;
3111 image->pitches[1] = awidth / 2;
3112 image->offsets[1] = size;
3113 image->pitches[2] = awidth / 2;
3114 image->offsets[2] = size + size2;
3115 image->data_size = size + 2 * size2;
3117 case VA_FOURCC_I420:
3118 image->num_planes = 3;
3119 image->pitches[0] = awidth;
3120 image->offsets[0] = 0;
3121 image->pitches[1] = awidth / 2;
3122 image->offsets[1] = size;
3123 image->pitches[2] = awidth / 2;
3124 image->offsets[2] = size + size2;
3125 image->data_size = size + 2 * size2;
3127 case VA_FOURCC_422H:
3128 image->num_planes = 3;
3129 image->pitches[0] = awidth;
3130 image->offsets[0] = 0;
3131 image->pitches[1] = awidth / 2;
3132 image->offsets[1] = size;
3133 image->pitches[2] = awidth / 2;
3134 image->offsets[2] = size + (awidth / 2) * aheight;
3135 image->data_size = size + 2 * ((awidth / 2) * aheight);
3137 case VA_FOURCC_NV12:
3138 image->num_planes = 2;
3139 image->pitches[0] = awidth;
3140 image->offsets[0] = 0;
3141 image->pitches[1] = awidth;
3142 image->offsets[1] = size;
3143 image->data_size = size + 2 * size2;
3145 case VA_FOURCC_YUY2:
3146 case VA_FOURCC_UYVY:
3147 image->num_planes = 1;
3148 image->pitches[0] = awidth * 2;
3149 image->offsets[0] = 0;
3150 image->data_size = size * 2;
3156 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3157 image->data_size, 1, NULL, &image->buf);
3158 if (va_status != VA_STATUS_SUCCESS)
3161 struct object_buffer *obj_buffer = BUFFER(image->buf);
3164 !obj_buffer->buffer_store ||
3165 !obj_buffer->buffer_store->bo)
3166 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3168 obj_image->bo = obj_buffer->buffer_store->bo;
3169 dri_bo_reference(obj_image->bo);
3171 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3172 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3173 if (!obj_image->palette)
3177 image->image_id = image_id;
3178 image->format = *format;
3179 image->width = width;
3180 image->height = height;
3182 *out_image = *image;
3183 return VA_STATUS_SUCCESS;
3186 i965_DestroyImage(ctx, image_id);
3191 i965_check_alloc_surface_bo(VADriverContextP ctx,
3192 struct object_surface *obj_surface,
3194 unsigned int fourcc,
3195 unsigned int subsampling)
3197 struct i965_driver_data *i965 = i965_driver_data(ctx);
3198 int region_width, region_height;
3200 if (obj_surface->bo) {
3201 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3202 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3203 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
3204 return VA_STATUS_SUCCESS;
3207 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
3208 obj_surface->x_cr_offset = 0;
3210 if ((tiled && !obj_surface->user_disable_tiling)) {
3211 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
3212 fourcc != VA_FOURCC_IYUV &&
3213 fourcc != VA_FOURCC_YV12,
3214 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3215 if (obj_surface->user_h_stride_set) {
3216 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
3218 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
3220 if (obj_surface->user_v_stride_set) {
3221 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
3223 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
3225 region_height = obj_surface->height;
3228 case VA_FOURCC_NV12:
3229 assert(subsampling == SUBSAMPLE_YUV420);
3230 obj_surface->cb_cr_pitch = obj_surface->width;
3231 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3232 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3233 obj_surface->y_cb_offset = obj_surface->height;
3234 obj_surface->y_cr_offset = obj_surface->height;
3235 region_width = obj_surface->width;
3236 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3240 case VA_FOURCC_IMC1:
3241 assert(subsampling == SUBSAMPLE_YUV420);
3242 obj_surface->cb_cr_pitch = obj_surface->width;
3243 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3244 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3245 obj_surface->y_cr_offset = obj_surface->height;
3246 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
3247 region_width = obj_surface->width;
3248 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3252 case VA_FOURCC_IMC3:
3253 assert(subsampling == SUBSAMPLE_YUV420);
3254 obj_surface->cb_cr_pitch = obj_surface->width;
3255 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3256 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3257 obj_surface->y_cb_offset = obj_surface->height;
3258 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3259 region_width = obj_surface->width;
3260 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3264 case VA_FOURCC_422H:
3265 assert(subsampling == SUBSAMPLE_YUV422H);
3266 obj_surface->cb_cr_pitch = obj_surface->width;
3267 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3268 obj_surface->cb_cr_height = obj_surface->orig_height;
3269 obj_surface->y_cb_offset = obj_surface->height;
3270 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3271 region_width = obj_surface->width;
3272 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3276 case VA_FOURCC_422V:
3277 assert(subsampling == SUBSAMPLE_YUV422V);
3278 obj_surface->cb_cr_pitch = obj_surface->width;
3279 obj_surface->cb_cr_width = obj_surface->orig_width;
3280 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3281 obj_surface->y_cb_offset = obj_surface->height;
3282 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3283 region_width = obj_surface->width;
3284 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3288 case VA_FOURCC_411P:
3289 assert(subsampling == SUBSAMPLE_YUV411);
3290 obj_surface->cb_cr_pitch = obj_surface->width;
3291 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
3292 obj_surface->cb_cr_height = obj_surface->orig_height;
3293 obj_surface->y_cb_offset = obj_surface->height;
3294 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3295 region_width = obj_surface->width;
3296 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3300 case VA_FOURCC_444P:
3301 assert(subsampling == SUBSAMPLE_YUV444);
3302 obj_surface->cb_cr_pitch = obj_surface->width;
3303 obj_surface->cb_cr_width = obj_surface->orig_width;
3304 obj_surface->cb_cr_height = obj_surface->orig_height;
3305 obj_surface->y_cb_offset = obj_surface->height;
3306 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3307 region_width = obj_surface->width;
3308 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3312 case VA_FOURCC_Y800:
3313 assert(subsampling == SUBSAMPLE_YUV400);
3314 obj_surface->cb_cr_pitch = 0;
3315 obj_surface->cb_cr_width = 0;
3316 obj_surface->cb_cr_height = 0;
3317 obj_surface->y_cb_offset = 0;
3318 obj_surface->y_cr_offset = 0;
3319 region_width = obj_surface->width;
3320 region_height = obj_surface->height;
3324 case VA_FOURCC_YUY2:
3325 case VA_FOURCC_UYVY:
3326 assert(subsampling == SUBSAMPLE_YUV422H);
3327 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
3328 obj_surface->cb_cr_pitch = obj_surface->width;
3329 obj_surface->y_cb_offset = 0;
3330 obj_surface->y_cr_offset = 0;
3331 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3332 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3333 region_width = obj_surface->width;
3334 region_height = obj_surface->height;
3338 case VA_FOURCC_RGBA:
3339 case VA_FOURCC_RGBX:
3340 case VA_FOURCC_BGRA:
3341 case VA_FOURCC_BGRX:
3342 assert(subsampling == SUBSAMPLE_RGBX);
3344 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
3345 region_width = obj_surface->width;
3346 region_height = obj_surface->height;
3350 /* Never get here */
3351 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3355 assert(subsampling == SUBSAMPLE_YUV420 ||
3356 subsampling == SUBSAMPLE_YUV422H ||
3357 subsampling == SUBSAMPLE_YUV422V ||
3358 subsampling == SUBSAMPLE_RGBX);
3360 region_width = obj_surface->width;
3361 region_height = obj_surface->height;
3364 case VA_FOURCC_NV12:
3365 obj_surface->y_cb_offset = obj_surface->height;
3366 obj_surface->y_cr_offset = obj_surface->height;
3367 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3368 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3369 obj_surface->cb_cr_pitch = obj_surface->width;
3370 region_height = obj_surface->height + obj_surface->height / 2;
3373 case VA_FOURCC_YV16:
3374 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3375 obj_surface->cb_cr_height = obj_surface->orig_height;
3376 obj_surface->y_cr_offset = obj_surface->height;
3377 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
3378 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3379 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3382 case VA_FOURCC_YV12:
3383 case VA_FOURCC_I420:
3384 if (fourcc == VA_FOURCC_YV12) {
3385 obj_surface->y_cr_offset = obj_surface->height;
3386 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
3388 obj_surface->y_cb_offset = obj_surface->height;
3389 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
3392 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3393 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3394 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3395 region_height = obj_surface->height + obj_surface->height / 2;
3398 case VA_FOURCC_YUY2:
3399 case VA_FOURCC_UYVY:
3400 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
3401 obj_surface->y_cb_offset = 0;
3402 obj_surface->y_cr_offset = 0;
3403 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3404 obj_surface->cb_cr_height = obj_surface->orig_height;
3405 obj_surface->cb_cr_pitch = obj_surface->width;
3406 region_width = obj_surface->width;
3407 region_height = obj_surface->height;
3409 case VA_FOURCC_RGBA:
3410 case VA_FOURCC_RGBX:
3411 case VA_FOURCC_BGRA:
3412 case VA_FOURCC_BGRX:
3413 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
3414 region_width = obj_surface->width;
3415 region_height = obj_surface->height;
3419 /* Never get here */
3420 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3425 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
3427 if ((tiled && !obj_surface->user_disable_tiling)) {
3428 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
3429 unsigned long pitch;
3431 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
3439 assert(tiling_mode == I915_TILING_Y);
3440 assert(pitch == obj_surface->width);
3442 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
3448 obj_surface->fourcc = fourcc;
3449 obj_surface->subsampling = subsampling;
3450 assert(obj_surface->bo);
3451 return VA_STATUS_SUCCESS;
3454 VAStatus i965_DeriveImage(VADriverContextP ctx,
3455 VASurfaceID surface,
3456 VAImage *out_image) /* out */
3458 struct i965_driver_data *i965 = i965_driver_data(ctx);
3459 struct object_image *obj_image;
3460 struct object_surface *obj_surface;
3462 unsigned int w_pitch;
3463 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3465 out_image->image_id = VA_INVALID_ID;
3466 obj_surface = SURFACE(surface);
3469 return VA_STATUS_ERROR_INVALID_SURFACE;
3471 if (!obj_surface->bo) {
3472 unsigned int is_tiled = 0;
3473 unsigned int fourcc = VA_FOURCC_YV12;
3474 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3475 int sampling = get_sampling_from_fourcc(fourcc);
3476 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3477 if (va_status != VA_STATUS_SUCCESS)
3481 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3483 w_pitch = obj_surface->width;
3485 image_id = NEW_IMAGE_ID();
3487 if (image_id == VA_INVALID_ID)
3488 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3490 obj_image = IMAGE(image_id);
3493 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3495 obj_image->bo = NULL;
3496 obj_image->palette = NULL;
3497 obj_image->derived_surface = VA_INVALID_ID;
3499 VAImage * const image = &obj_image->image;
3501 memset(image, 0, sizeof(*image));
3502 image->image_id = image_id;
3503 image->buf = VA_INVALID_ID;
3504 image->num_palette_entries = 0;
3505 image->entry_bytes = 0;
3506 image->width = obj_surface->orig_width;
3507 image->height = obj_surface->orig_height;
3508 image->data_size = obj_surface->size;
3510 image->format.fourcc = obj_surface->fourcc;
3511 image->format.byte_order = VA_LSB_FIRST;
3512 image->format.bits_per_pixel = 12;
3514 switch (image->format.fourcc) {
3515 case VA_FOURCC_YV12:
3516 image->num_planes = 3;
3517 image->pitches[0] = w_pitch; /* Y */
3518 image->offsets[0] = 0;
3519 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3520 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3521 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3522 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3525 case VA_FOURCC_YV16:
3526 image->num_planes = 3;
3527 image->pitches[0] = w_pitch; /* Y */
3528 image->offsets[0] = 0;
3529 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3530 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3531 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3532 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3535 case VA_FOURCC_NV12:
3536 image->num_planes = 2;
3537 image->pitches[0] = w_pitch; /* Y */
3538 image->offsets[0] = 0;
3539 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3540 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3543 case VA_FOURCC_I420:
3544 case VA_FOURCC_422H:
3545 case VA_FOURCC_IMC3:
3546 case VA_FOURCC_444P:
3547 case VA_FOURCC_422V:
3548 case VA_FOURCC_411P:
3549 image->num_planes = 3;
3550 image->pitches[0] = w_pitch; /* Y */
3551 image->offsets[0] = 0;
3552 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3553 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3554 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3555 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3558 case VA_FOURCC_YUY2:
3559 case VA_FOURCC_UYVY:
3560 case VA_FOURCC_Y800:
3561 image->num_planes = 1;
3562 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
3563 image->offsets[0] = 0;
3565 case VA_FOURCC_RGBA:
3566 case VA_FOURCC_RGBX:
3567 case VA_FOURCC_BGRA:
3568 case VA_FOURCC_BGRX:
3569 image->num_planes = 1;
3570 image->pitches[0] = obj_surface->width;
3576 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3577 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3578 if (va_status != VA_STATUS_SUCCESS)
3581 struct object_buffer *obj_buffer = BUFFER(image->buf);
3584 !obj_buffer->buffer_store ||
3585 !obj_buffer->buffer_store->bo)
3586 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3588 obj_image->bo = obj_buffer->buffer_store->bo;
3589 dri_bo_reference(obj_image->bo);
3591 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3592 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3593 if (!obj_image->palette) {
3594 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3599 *out_image = *image;
3600 obj_surface->flags |= SURFACE_DERIVED;
3601 obj_image->derived_surface = surface;
3603 return VA_STATUS_SUCCESS;
3606 i965_DestroyImage(ctx, image_id);
3611 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3613 object_heap_free(heap, obj);
3618 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3620 struct i965_driver_data *i965 = i965_driver_data(ctx);
3621 struct object_image *obj_image = IMAGE(image);
3622 struct object_surface *obj_surface;
3625 return VA_STATUS_SUCCESS;
3627 dri_bo_unreference(obj_image->bo);
3628 obj_image->bo = NULL;
3630 if (obj_image->image.buf != VA_INVALID_ID) {
3631 i965_DestroyBuffer(ctx, obj_image->image.buf);
3632 obj_image->image.buf = VA_INVALID_ID;
3635 if (obj_image->palette) {
3636 free(obj_image->palette);
3637 obj_image->palette = NULL;
3640 obj_surface = SURFACE(obj_image->derived_surface);
3643 obj_surface->flags &= ~SURFACE_DERIVED;
3646 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3648 return VA_STATUS_SUCCESS;
3652 * pointer to an array holding the palette data. The size of the array is
3653 * num_palette_entries * entry_bytes in size. The order of the components
3654 * in the palette is described by the component_order in VASubpicture struct
3657 i965_SetImagePalette(VADriverContextP ctx,
3659 unsigned char *palette)
3661 struct i965_driver_data *i965 = i965_driver_data(ctx);
3664 struct object_image *obj_image = IMAGE(image);
3666 return VA_STATUS_ERROR_INVALID_IMAGE;
3668 if (!obj_image->palette)
3669 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3671 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3672 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3673 ((unsigned int)palette[3*i + 1] << 8) |
3674 (unsigned int)palette[3*i + 2]);
3675 return VA_STATUS_SUCCESS;
3679 get_sampling_from_fourcc(unsigned int fourcc)
3681 const i965_fourcc_info *info = get_fourcc_info(fourcc);
3683 if (info && (info->flag & I_S))
3684 return info->subsampling;
3690 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3691 const uint8_t *src, unsigned int src_stride,
3692 unsigned int len, unsigned int height)
3696 for (i = 0; i < height; i++) {
3697 memcpy(dst, src, len);
3704 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3705 struct object_surface *obj_surface,
3706 const VARectangle *rect)
3708 uint8_t *dst[3], *src[3];
3710 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3711 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3712 unsigned int tiling, swizzle;
3713 VAStatus va_status = VA_STATUS_SUCCESS;
3715 if (!obj_surface->bo)
3716 return VA_STATUS_ERROR_INVALID_SURFACE;
3718 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3719 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3721 if (tiling != I915_TILING_NONE)
3722 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3724 dri_bo_map(obj_surface->bo, 0);
3726 if (!obj_surface->bo->virtual)
3727 return VA_STATUS_ERROR_INVALID_SURFACE;
3729 /* Dest VA image has either I420 or YV12 format.
3730 Source VA surface alway has I420 format */
3731 dst[Y] = image_data + obj_image->image.offsets[Y];
3732 src[0] = (uint8_t *)obj_surface->bo->virtual;
3733 dst[U] = image_data + obj_image->image.offsets[U];
3734 src[1] = src[0] + obj_surface->width * obj_surface->height;
3735 dst[V] = image_data + obj_image->image.offsets[V];
3736 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3739 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3740 src[0] += rect->y * obj_surface->width + rect->x;
3741 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3742 src[0], obj_surface->width,
3743 rect->width, rect->height);
3746 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3747 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3748 memcpy_pic(dst[U], obj_image->image.pitches[U],
3749 src[1], obj_surface->width / 2,
3750 rect->width / 2, rect->height / 2);
3753 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3754 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3755 memcpy_pic(dst[V], obj_image->image.pitches[V],
3756 src[2], obj_surface->width / 2,
3757 rect->width / 2, rect->height / 2);
3759 if (tiling != I915_TILING_NONE)
3760 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3762 dri_bo_unmap(obj_surface->bo);
3768 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3769 struct object_surface *obj_surface,
3770 const VARectangle *rect)
3772 uint8_t *dst[2], *src[2];
3773 unsigned int tiling, swizzle;
3774 VAStatus va_status = VA_STATUS_SUCCESS;
3776 if (!obj_surface->bo)
3777 return VA_STATUS_ERROR_INVALID_SURFACE;
3779 assert(obj_surface->fourcc);
3780 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3782 if (tiling != I915_TILING_NONE)
3783 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3785 dri_bo_map(obj_surface->bo, 0);
3787 if (!obj_surface->bo->virtual)
3788 return VA_STATUS_ERROR_INVALID_SURFACE;
3790 /* Both dest VA image and source surface have NV12 format */
3791 dst[0] = image_data + obj_image->image.offsets[0];
3792 src[0] = (uint8_t *)obj_surface->bo->virtual;
3793 dst[1] = image_data + obj_image->image.offsets[1];
3794 src[1] = src[0] + obj_surface->width * obj_surface->height;
3797 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3798 src[0] += rect->y * obj_surface->width + rect->x;
3799 memcpy_pic(dst[0], obj_image->image.pitches[0],
3800 src[0], obj_surface->width,
3801 rect->width, rect->height);
3804 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3805 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3806 memcpy_pic(dst[1], obj_image->image.pitches[1],
3807 src[1], obj_surface->width,
3808 rect->width, rect->height / 2);
3810 if (tiling != I915_TILING_NONE)
3811 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3813 dri_bo_unmap(obj_surface->bo);
3819 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3820 struct object_surface *obj_surface,
3821 const VARectangle *rect)
3824 unsigned int tiling, swizzle;
3825 VAStatus va_status = VA_STATUS_SUCCESS;
3827 if (!obj_surface->bo)
3828 return VA_STATUS_ERROR_INVALID_SURFACE;
3830 assert(obj_surface->fourcc);
3831 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3833 if (tiling != I915_TILING_NONE)
3834 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3836 dri_bo_map(obj_surface->bo, 0);
3838 if (!obj_surface->bo->virtual)
3839 return VA_STATUS_ERROR_INVALID_SURFACE;
3841 /* Both dest VA image and source surface have YUYV format */
3842 dst = image_data + obj_image->image.offsets[0];
3843 src = (uint8_t *)obj_surface->bo->virtual;
3846 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3847 src += rect->y * obj_surface->width + rect->x*2;
3848 memcpy_pic(dst, obj_image->image.pitches[0],
3849 src, obj_surface->width*2,
3850 rect->width*2, rect->height);
3852 if (tiling != I915_TILING_NONE)
3853 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3855 dri_bo_unmap(obj_surface->bo);
3861 i965_sw_getimage(VADriverContextP ctx,
3862 VASurfaceID surface,
3863 int x, /* coordinates of the upper left source pixel */
3865 unsigned int width, /* width and height of the region */
3866 unsigned int height,
3869 struct i965_driver_data *i965 = i965_driver_data(ctx);
3870 struct i965_render_state *render_state = &i965->render_state;
3871 VAStatus va_status = VA_STATUS_SUCCESS;
3873 struct object_surface *obj_surface = SURFACE(surface);
3875 return VA_STATUS_ERROR_INVALID_SURFACE;
3877 struct object_image *obj_image = IMAGE(image);
3879 return VA_STATUS_ERROR_INVALID_IMAGE;
3882 return VA_STATUS_ERROR_INVALID_PARAMETER;
3883 if (x + width > obj_surface->orig_width ||
3884 y + height > obj_surface->orig_height)
3885 return VA_STATUS_ERROR_INVALID_PARAMETER;
3886 if (x + width > obj_image->image.width ||
3887 y + height > obj_image->image.height)
3888 return VA_STATUS_ERROR_INVALID_PARAMETER;
3890 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3891 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3893 void *image_data = NULL;
3895 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3896 if (va_status != VA_STATUS_SUCCESS)
3903 rect.height = height;
3905 switch (obj_image->image.format.fourcc) {
3906 case VA_FOURCC_YV12:
3907 case VA_FOURCC_I420:
3908 /* I420 is native format for MPEG-2 decoded surfaces */
3909 if (render_state->interleaved_uv)
3910 goto operation_failed;
3911 get_image_i420(obj_image, image_data, obj_surface, &rect);
3913 case VA_FOURCC_NV12:
3914 /* NV12 is native format for H.264 decoded surfaces */
3915 if (!render_state->interleaved_uv)
3916 goto operation_failed;
3917 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3919 case VA_FOURCC_YUY2:
3920 /* YUY2 is the format supported by overlay plane */
3921 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3925 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3929 if (va_status != VA_STATUS_SUCCESS)
3932 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3937 i965_hw_getimage(VADriverContextP ctx,
3938 VASurfaceID surface,
3939 int x, /* coordinates of the upper left source pixel */
3941 unsigned int width, /* width and height of the region */
3942 unsigned int height,
3945 struct i965_driver_data *i965 = i965_driver_data(ctx);
3946 struct i965_surface src_surface;
3947 struct i965_surface dst_surface;
3948 VAStatus va_status = VA_STATUS_SUCCESS;
3950 struct object_surface *obj_surface = SURFACE(surface);
3951 struct object_image *obj_image = IMAGE(image);
3954 return VA_STATUS_ERROR_INVALID_SURFACE;
3957 return VA_STATUS_ERROR_INVALID_IMAGE;
3960 return VA_STATUS_ERROR_INVALID_PARAMETER;
3961 if (x + width > obj_surface->orig_width ||
3962 y + height > obj_surface->orig_height)
3963 return VA_STATUS_ERROR_INVALID_PARAMETER;
3964 if (x + width > obj_image->image.width ||
3965 y + height > obj_image->image.height)
3966 return VA_STATUS_ERROR_INVALID_PARAMETER;
3968 if (!obj_surface->bo)
3969 return VA_STATUS_SUCCESS;
3970 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3975 rect.height = height;
3977 src_surface.base = (struct object_base *)obj_surface;
3978 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3979 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3981 dst_surface.base = (struct object_base *)obj_image;
3982 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3983 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3985 va_status = i965_image_processing(ctx,
3996 i965_GetImage(VADriverContextP ctx,
3997 VASurfaceID surface,
3998 int x, /* coordinates of the upper left source pixel */
4000 unsigned int width, /* width and height of the region */
4001 unsigned int height,
4004 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4005 VAStatus va_status = VA_STATUS_SUCCESS;
4007 if (HAS_ACCELERATED_GETIMAGE(i965))
4008 va_status = i965_hw_getimage(ctx,
4014 va_status = i965_sw_getimage(ctx,
4024 put_image_i420(struct object_surface *obj_surface,
4025 const VARectangle *dst_rect,
4026 struct object_image *obj_image, uint8_t *image_data,
4027 const VARectangle *src_rect)
4029 uint8_t *dst[3], *src[3];
4031 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4032 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4033 unsigned int tiling, swizzle;
4034 VAStatus va_status = VA_STATUS_SUCCESS;
4036 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4038 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4039 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4040 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4041 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4043 if (tiling != I915_TILING_NONE)
4044 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4046 dri_bo_map(obj_surface->bo, 0);
4048 if (!obj_surface->bo->virtual)
4049 return VA_STATUS_ERROR_INVALID_SURFACE;
4051 /* Dest VA image has either I420 or YV12 format.
4052 Source VA surface alway has I420 format */
4053 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4054 src[Y] = image_data + obj_image->image.offsets[Y];
4055 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4056 src[U] = image_data + obj_image->image.offsets[U];
4057 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4058 src[V] = image_data + obj_image->image.offsets[V];
4061 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4062 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4063 memcpy_pic(dst[0], obj_surface->width,
4064 src[Y], obj_image->image.pitches[Y],
4065 src_rect->width, src_rect->height);
4068 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4069 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4070 memcpy_pic(dst[1], obj_surface->width / 2,
4071 src[U], obj_image->image.pitches[U],
4072 src_rect->width / 2, src_rect->height / 2);
4075 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4076 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4077 memcpy_pic(dst[2], obj_surface->width / 2,
4078 src[V], obj_image->image.pitches[V],
4079 src_rect->width / 2, src_rect->height / 2);
4081 if (tiling != I915_TILING_NONE)
4082 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4084 dri_bo_unmap(obj_surface->bo);
4090 put_image_nv12(struct object_surface *obj_surface,
4091 const VARectangle *dst_rect,
4092 struct object_image *obj_image, uint8_t *image_data,
4093 const VARectangle *src_rect)
4095 uint8_t *dst[2], *src[2];
4096 unsigned int tiling, swizzle;
4097 VAStatus va_status = VA_STATUS_SUCCESS;
4099 if (!obj_surface->bo)
4100 return VA_STATUS_ERROR_INVALID_SURFACE;
4102 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4103 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4104 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4105 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4107 if (tiling != I915_TILING_NONE)
4108 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4110 dri_bo_map(obj_surface->bo, 0);
4112 if (!obj_surface->bo->virtual)
4113 return VA_STATUS_ERROR_INVALID_SURFACE;
4115 /* Both dest VA image and source surface have NV12 format */
4116 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4117 src[0] = image_data + obj_image->image.offsets[0];
4118 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4119 src[1] = image_data + obj_image->image.offsets[1];
4122 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4123 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4124 memcpy_pic(dst[0], obj_surface->width,
4125 src[0], obj_image->image.pitches[0],
4126 src_rect->width, src_rect->height);
4129 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4130 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4131 memcpy_pic(dst[1], obj_surface->width,
4132 src[1], obj_image->image.pitches[1],
4133 src_rect->width, src_rect->height / 2);
4135 if (tiling != I915_TILING_NONE)
4136 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4138 dri_bo_unmap(obj_surface->bo);
4144 put_image_yuy2(struct object_surface *obj_surface,
4145 const VARectangle *dst_rect,
4146 struct object_image *obj_image, uint8_t *image_data,
4147 const VARectangle *src_rect)
4150 unsigned int tiling, swizzle;
4151 VAStatus va_status = VA_STATUS_SUCCESS;
4153 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4154 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4155 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4156 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4157 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4159 if (tiling != I915_TILING_NONE)
4160 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4162 dri_bo_map(obj_surface->bo, 0);
4164 if (!obj_surface->bo->virtual)
4165 return VA_STATUS_ERROR_INVALID_SURFACE;
4167 /* Both dest VA image and source surface have YUY2 format */
4168 dst = (uint8_t *)obj_surface->bo->virtual;
4169 src = image_data + obj_image->image.offsets[0];
4171 /* YUYV packed plane */
4172 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4173 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4174 memcpy_pic(dst, obj_surface->width*2,
4175 src, obj_image->image.pitches[0],
4176 src_rect->width*2, src_rect->height);
4178 if (tiling != I915_TILING_NONE)
4179 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4181 dri_bo_unmap(obj_surface->bo);
4188 i965_sw_putimage(VADriverContextP ctx,
4189 VASurfaceID surface,
4193 unsigned int src_width,
4194 unsigned int src_height,
4197 unsigned int dest_width,
4198 unsigned int dest_height)
4200 struct i965_driver_data *i965 = i965_driver_data(ctx);
4201 struct object_surface *obj_surface = SURFACE(surface);
4202 struct object_image *obj_image = IMAGE(image);
4203 VAStatus va_status = VA_STATUS_SUCCESS;
4204 void *image_data = NULL;
4206 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
4207 ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE);
4209 if (src_x < 0 || src_y < 0)
4210 return VA_STATUS_ERROR_INVALID_PARAMETER;
4211 if (src_x + src_width > obj_image->image.width ||
4212 src_y + src_height > obj_image->image.height)
4213 return VA_STATUS_ERROR_INVALID_PARAMETER;
4214 if (dest_x < 0 || dest_y < 0)
4215 return VA_STATUS_ERROR_INVALID_PARAMETER;
4216 if (dest_x + dest_width > obj_surface->orig_width ||
4217 dest_y + dest_height > obj_surface->orig_height)
4218 return VA_STATUS_ERROR_INVALID_PARAMETER;
4220 /* XXX: don't allow scaling */
4221 if (src_width != dest_width || src_height != dest_height)
4222 return VA_STATUS_ERROR_INVALID_PARAMETER;
4224 if (obj_surface->fourcc) {
4225 /* Don't allow format mismatch */
4226 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4227 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4231 /* VA is surface not used for decoding, use same VA image format */
4232 va_status = i965_check_alloc_surface_bo(
4235 0, /* XXX: don't use tiled surface */
4236 obj_image->image.format.fourcc,
4237 get_sampling_from_fourcc (obj_image->image.format.fourcc));
4240 if (va_status != VA_STATUS_SUCCESS)
4243 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4244 if (va_status != VA_STATUS_SUCCESS)
4247 VARectangle src_rect, dest_rect;
4250 src_rect.width = src_width;
4251 src_rect.height = src_height;
4252 dest_rect.x = dest_x;
4253 dest_rect.y = dest_y;
4254 dest_rect.width = dest_width;
4255 dest_rect.height = dest_height;
4257 switch (obj_image->image.format.fourcc) {
4258 case VA_FOURCC_YV12:
4259 case VA_FOURCC_I420:
4260 va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
4262 case VA_FOURCC_NV12:
4263 va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
4265 case VA_FOURCC_YUY2:
4266 va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
4269 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4272 if (va_status != VA_STATUS_SUCCESS)
4275 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4280 i965_hw_putimage(VADriverContextP ctx,
4281 VASurfaceID surface,
4285 unsigned int src_width,
4286 unsigned int src_height,
4289 unsigned int dest_width,
4290 unsigned int dest_height)
4292 struct i965_driver_data *i965 = i965_driver_data(ctx);
4293 struct object_surface *obj_surface = SURFACE(surface);
4294 struct object_image *obj_image = IMAGE(image);
4295 struct i965_surface src_surface, dst_surface;
4296 VAStatus va_status = VA_STATUS_SUCCESS;
4297 VARectangle src_rect, dst_rect;
4299 ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE);
4300 ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE);
4304 src_x + src_width > obj_image->image.width ||
4305 src_y + src_height > obj_image->image.height)
4306 return VA_STATUS_ERROR_INVALID_PARAMETER;
4310 dest_x + dest_width > obj_surface->orig_width ||
4311 dest_y + dest_height > obj_surface->orig_height)
4312 return VA_STATUS_ERROR_INVALID_PARAMETER;
4314 if (!obj_surface->bo) {
4315 unsigned int tiling, swizzle;
4316 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
4317 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
4319 i965_check_alloc_surface_bo(ctx,
4322 obj_image->image.format.fourcc,
4326 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4328 src_surface.base = (struct object_base *)obj_image;
4329 src_surface.type = I965_SURFACE_TYPE_IMAGE;
4330 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4333 src_rect.width = src_width;
4334 src_rect.height = src_height;
4336 dst_surface.base = (struct object_base *)obj_surface;
4337 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4338 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4339 dst_rect.x = dest_x;
4340 dst_rect.y = dest_y;
4341 dst_rect.width = dest_width;
4342 dst_rect.height = dest_height;
4344 va_status = i965_image_processing(ctx,
4354 i965_PutImage(VADriverContextP ctx,
4355 VASurfaceID surface,
4359 unsigned int src_width,
4360 unsigned int src_height,
4363 unsigned int dest_width,
4364 unsigned int dest_height)
4366 struct i965_driver_data *i965 = i965_driver_data(ctx);
4367 VAStatus va_status = VA_STATUS_SUCCESS;
4369 if (HAS_ACCELERATED_PUTIMAGE(i965))
4370 va_status = i965_hw_putimage(ctx,
4382 va_status = i965_sw_putimage(ctx,
4398 i965_PutSurface(VADriverContextP ctx,
4399 VASurfaceID surface,
4400 void *draw, /* X Drawable */
4403 unsigned short srcw,
4404 unsigned short srch,
4407 unsigned short destw,
4408 unsigned short desth,
4409 VARectangle *cliprects, /* client supplied clip list */
4410 unsigned int number_cliprects, /* number of clip rects in the clip list */
4411 unsigned int flags) /* de-interlacing flags */
4414 if (IS_VA_X11(ctx)) {
4415 VARectangle src_rect, dst_rect;
4419 src_rect.width = srcw;
4420 src_rect.height = srch;
4424 dst_rect.width = destw;
4425 dst_rect.height = desth;
4427 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
4428 cliprects, number_cliprects, flags);
4431 return VA_STATUS_ERROR_UNIMPLEMENTED;
4436 VADriverContextP ctx, /* in */
4437 VABufferID buf_id, /* in */
4438 VABufferType *type, /* out */
4439 unsigned int *size, /* out */
4440 unsigned int *num_elements /* out */
4443 struct i965_driver_data *i965 = NULL;
4444 struct object_buffer *obj_buffer = NULL;
4446 i965 = i965_driver_data(ctx);
4447 obj_buffer = BUFFER(buf_id);
4449 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
4451 *type = obj_buffer->type;
4452 *size = obj_buffer->size_element;
4453 *num_elements = obj_buffer->num_elements;
4455 return VA_STATUS_SUCCESS;
4460 VADriverContextP ctx, /* in */
4461 VASurfaceID surface, /* in */
4462 unsigned int *fourcc, /* out */
4463 unsigned int *luma_stride, /* out */
4464 unsigned int *chroma_u_stride, /* out */
4465 unsigned int *chroma_v_stride, /* out */
4466 unsigned int *luma_offset, /* out */
4467 unsigned int *chroma_u_offset, /* out */
4468 unsigned int *chroma_v_offset, /* out */
4469 unsigned int *buffer_name, /* out */
4470 void **buffer /* out */
4473 VAStatus vaStatus = VA_STATUS_SUCCESS;
4474 struct i965_driver_data *i965 = i965_driver_data(ctx);
4475 struct object_surface *obj_surface = NULL;
4478 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
4479 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4480 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4481 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4482 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4483 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4484 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4485 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
4486 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
4488 tmpImage.image_id = VA_INVALID_ID;
4490 obj_surface = SURFACE(surface);
4491 if (obj_surface == NULL) {
4492 // Surface is absent.
4493 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4497 // Lock functionality is absent now.
4498 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4499 // Surface is locked already.
4500 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4504 vaStatus = i965_DeriveImage(
4508 if (vaStatus != VA_STATUS_SUCCESS) {
4512 obj_surface->locked_image_id = tmpImage.image_id;
4514 vaStatus = i965_MapBuffer(
4518 if (vaStatus != VA_STATUS_SUCCESS) {
4522 *fourcc = tmpImage.format.fourcc;
4523 *luma_offset = tmpImage.offsets[0];
4524 *luma_stride = tmpImage.pitches[0];
4525 *chroma_u_offset = tmpImage.offsets[1];
4526 *chroma_u_stride = tmpImage.pitches[1];
4527 *chroma_v_offset = tmpImage.offsets[2];
4528 *chroma_v_stride = tmpImage.pitches[2];
4529 *buffer_name = tmpImage.buf;
4532 if (vaStatus != VA_STATUS_SUCCESS) {
4541 VADriverContextP ctx, /* in */
4542 VASurfaceID surface /* in */
4545 VAStatus vaStatus = VA_STATUS_SUCCESS;
4546 struct i965_driver_data *i965 = i965_driver_data(ctx);
4547 struct object_image *locked_img = NULL;
4548 struct object_surface *obj_surface = NULL;
4550 obj_surface = SURFACE(surface);
4552 if (obj_surface == NULL) {
4553 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4556 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4557 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4561 locked_img = IMAGE(obj_surface->locked_image_id);
4562 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4563 // Work image was deallocated before i965_UnlockSurface()
4564 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4568 vaStatus = i965_UnmapBuffer(
4570 locked_img->image.buf);
4571 if (vaStatus != VA_STATUS_SUCCESS) {
4575 vaStatus = i965_DestroyImage(
4577 locked_img->image.image_id);
4578 if (vaStatus != VA_STATUS_SUCCESS) {
4582 locked_img->image.image_id = VA_INVALID_ID;
4585 obj_surface->locked_image_id = VA_INVALID_ID;
4591 i965_GetSurfaceAttributes(
4592 VADriverContextP ctx,
4594 VASurfaceAttrib *attrib_list,
4595 unsigned int num_attribs
4598 VAStatus vaStatus = VA_STATUS_SUCCESS;
4599 struct i965_driver_data *i965 = i965_driver_data(ctx);
4600 struct object_config *obj_config;
4603 if (config == VA_INVALID_ID)
4604 return VA_STATUS_ERROR_INVALID_CONFIG;
4606 obj_config = CONFIG(config);
4608 if (obj_config == NULL)
4609 return VA_STATUS_ERROR_INVALID_CONFIG;
4611 if (attrib_list == NULL || num_attribs == 0)
4612 return VA_STATUS_ERROR_INVALID_PARAMETER;
4614 for (i = 0; i < num_attribs; i++) {
4615 switch (attrib_list[i].type) {
4616 case VASurfaceAttribPixelFormat:
4617 attrib_list[i].value.type = VAGenericValueTypeInteger;
4618 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4620 if (attrib_list[i].value.value.i == 0) {
4621 if (IS_G4X(i965->intel.device_info)) {
4622 if (obj_config->profile == VAProfileMPEG2Simple ||
4623 obj_config->profile == VAProfileMPEG2Main) {
4624 attrib_list[i].value.value.i = VA_FOURCC_I420;
4627 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4629 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4630 if (obj_config->profile == VAProfileMPEG2Simple ||
4631 obj_config->profile == VAProfileMPEG2Main) {
4632 attrib_list[i].value.value.i = VA_FOURCC_I420;
4633 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4634 obj_config->profile == VAProfileH264Main ||
4635 obj_config->profile == VAProfileH264High) {
4636 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4637 } else if (obj_config->profile == VAProfileNone) {
4638 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4641 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4643 } else if (IS_GEN6(i965->intel.device_info)) {
4644 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4645 } else if (IS_GEN7(i965->intel.device_info) ||
4646 IS_GEN8(i965->intel.device_info)) {
4647 if (obj_config->profile == VAProfileJPEGBaseline)
4648 attrib_list[i].value.value.i = 0; /* internal format */
4650 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4653 if (IS_G4X(i965->intel.device_info)) {
4654 if (obj_config->profile == VAProfileMPEG2Simple ||
4655 obj_config->profile == VAProfileMPEG2Main) {
4656 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4657 attrib_list[i].value.value.i = 0;
4658 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4662 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4664 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4665 if (obj_config->profile == VAProfileMPEG2Simple ||
4666 obj_config->profile == VAProfileMPEG2Main) {
4667 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4668 attrib_list[i].value.value.i = 0;
4669 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4671 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4672 obj_config->profile == VAProfileH264Main ||
4673 obj_config->profile == VAProfileH264High) {
4674 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4675 attrib_list[i].value.value.i = 0;
4676 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4678 } else if (obj_config->profile == VAProfileNone) {
4679 switch (attrib_list[i].value.value.i) {
4680 case VA_FOURCC_NV12:
4681 case VA_FOURCC_I420:
4682 case VA_FOURCC_YV12:
4683 case VA_FOURCC_YUY2:
4684 case VA_FOURCC_BGRA:
4685 case VA_FOURCC_BGRX:
4686 case VA_FOURCC_RGBX:
4687 case VA_FOURCC_RGBA:
4690 attrib_list[i].value.value.i = 0;
4691 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4696 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4698 } else if (IS_GEN6(i965->intel.device_info)) {
4699 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4700 obj_config->entrypoint == VAEntrypointVideoProc) {
4701 switch (attrib_list[i].value.value.i) {
4702 case VA_FOURCC_NV12:
4703 case VA_FOURCC_I420:
4704 case VA_FOURCC_YV12:
4705 case VA_FOURCC_YUY2:
4706 case VA_FOURCC_BGRA:
4707 case VA_FOURCC_BGRX:
4708 case VA_FOURCC_RGBX:
4709 case VA_FOURCC_RGBA:
4712 attrib_list[i].value.value.i = 0;
4713 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4717 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4718 attrib_list[i].value.value.i = 0;
4719 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4722 } else if (IS_GEN7(i965->intel.device_info) ||
4723 IS_GEN8(i965->intel.device_info)) {
4724 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4725 obj_config->entrypoint == VAEntrypointVideoProc) {
4726 switch (attrib_list[i].value.value.i) {
4727 case VA_FOURCC_NV12:
4728 case VA_FOURCC_I420:
4729 case VA_FOURCC_YV12:
4732 attrib_list[i].value.value.i = 0;
4733 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4737 if (obj_config->profile == VAProfileJPEGBaseline) {
4738 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4739 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4741 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4742 attrib_list[i].value.value.i = 0;
4743 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4751 case VASurfaceAttribMinWidth:
4752 /* FIXME: add support for it later */
4753 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4755 case VASurfaceAttribMaxWidth:
4756 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4758 case VASurfaceAttribMinHeight:
4759 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4761 case VASurfaceAttribMaxHeight:
4762 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4765 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4774 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4776 VASurfaceAttrib *attrib_list,
4777 unsigned int *num_attribs)
4779 VAStatus vaStatus = VA_STATUS_SUCCESS;
4780 struct i965_driver_data *i965 = i965_driver_data(ctx);
4781 struct object_config *obj_config;
4783 VASurfaceAttrib *attribs = NULL;
4785 if (config == VA_INVALID_ID)
4786 return VA_STATUS_ERROR_INVALID_CONFIG;
4788 obj_config = CONFIG(config);
4790 if (obj_config == NULL)
4791 return VA_STATUS_ERROR_INVALID_CONFIG;
4793 if (!attrib_list && !num_attribs)
4794 return VA_STATUS_ERROR_INVALID_PARAMETER;
4796 if (attrib_list == NULL) {
4797 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4798 return VA_STATUS_SUCCESS;
4801 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4803 if (attribs == NULL)
4804 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4806 if (IS_G4X(i965->intel.device_info)) {
4807 if (obj_config->profile == VAProfileMPEG2Simple ||
4808 obj_config->profile == VAProfileMPEG2Main) {
4809 attribs[i].type = VASurfaceAttribPixelFormat;
4810 attribs[i].value.type = VAGenericValueTypeInteger;
4811 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4812 attribs[i].value.value.i = VA_FOURCC_I420;
4815 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4816 switch (obj_config->profile) {
4817 case VAProfileMPEG2Simple:
4818 case VAProfileMPEG2Main:
4819 attribs[i].type = VASurfaceAttribPixelFormat;
4820 attribs[i].value.type = VAGenericValueTypeInteger;
4821 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4822 attribs[i].value.value.i = VA_FOURCC_I420;
4827 case VAProfileH264ConstrainedBaseline:
4828 case VAProfileH264Main:
4829 case VAProfileH264High:
4830 attribs[i].type = VASurfaceAttribPixelFormat;
4831 attribs[i].value.type = VAGenericValueTypeInteger;
4832 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4833 attribs[i].value.value.i = VA_FOURCC_NV12;
4837 attribs[i].type = VASurfaceAttribPixelFormat;
4838 attribs[i].value.type = VAGenericValueTypeInteger;
4839 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4840 attribs[i].value.value.i = VA_FOURCC_NV12;
4843 attribs[i].type = VASurfaceAttribPixelFormat;
4844 attribs[i].value.type = VAGenericValueTypeInteger;
4845 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4846 attribs[i].value.value.i = VA_FOURCC_I420;
4854 } else if (IS_GEN6(i965->intel.device_info)) {
4855 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4856 attribs[i].type = VASurfaceAttribPixelFormat;
4857 attribs[i].value.type = VAGenericValueTypeInteger;
4858 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4859 attribs[i].value.value.i = VA_FOURCC_NV12;
4861 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4862 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4863 attribs[i].type = VASurfaceAttribPixelFormat;
4864 attribs[i].value.type = VAGenericValueTypeInteger;
4865 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4866 attribs[i].value.value.i = VA_FOURCC_NV12;
4869 attribs[i].type = VASurfaceAttribPixelFormat;
4870 attribs[i].value.type = VAGenericValueTypeInteger;
4871 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4872 attribs[i].value.value.i = VA_FOURCC_I420;
4875 attribs[i].type = VASurfaceAttribPixelFormat;
4876 attribs[i].value.type = VAGenericValueTypeInteger;
4877 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4878 attribs[i].value.value.i = VA_FOURCC_YV12;
4881 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4882 attribs[i].type = VASurfaceAttribPixelFormat;
4883 attribs[i].value.type = VAGenericValueTypeInteger;
4884 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4885 attribs[i].value.value.i = VA_FOURCC_YUY2;
4888 attribs[i].type = VASurfaceAttribPixelFormat;
4889 attribs[i].value.type = VAGenericValueTypeInteger;
4890 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4891 attribs[i].value.value.i = VA_FOURCC_RGBA;
4894 attribs[i].type = VASurfaceAttribPixelFormat;
4895 attribs[i].value.type = VAGenericValueTypeInteger;
4896 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4897 attribs[i].value.value.i = VA_FOURCC_RGBX;
4901 } else if (IS_GEN7(i965->intel.device_info)) {
4902 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4903 if (obj_config->profile == VAProfileJPEGBaseline) {
4904 attribs[i].type = VASurfaceAttribPixelFormat;
4905 attribs[i].value.type = VAGenericValueTypeInteger;
4906 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4907 attribs[i].value.value.i = VA_FOURCC_IMC3;
4910 attribs[i].type = VASurfaceAttribPixelFormat;
4911 attribs[i].value.type = VAGenericValueTypeInteger;
4912 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4913 attribs[i].value.value.i = VA_FOURCC_IMC1;
4916 attribs[i].type = VASurfaceAttribPixelFormat;
4917 attribs[i].value.type = VAGenericValueTypeInteger;
4918 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4919 attribs[i].value.value.i = VA_FOURCC_Y800;
4922 attribs[i].type = VASurfaceAttribPixelFormat;
4923 attribs[i].value.type = VAGenericValueTypeInteger;
4924 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4925 attribs[i].value.value.i = VA_FOURCC_411P;
4928 attribs[i].type = VASurfaceAttribPixelFormat;
4929 attribs[i].value.type = VAGenericValueTypeInteger;
4930 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4931 attribs[i].value.value.i = VA_FOURCC_422H;
4934 attribs[i].type = VASurfaceAttribPixelFormat;
4935 attribs[i].value.type = VAGenericValueTypeInteger;
4936 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4937 attribs[i].value.value.i = VA_FOURCC_422V;
4940 attribs[i].type = VASurfaceAttribPixelFormat;
4941 attribs[i].value.type = VAGenericValueTypeInteger;
4942 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4943 attribs[i].value.value.i = VA_FOURCC_444P;
4946 attribs[i].type = VASurfaceAttribPixelFormat;
4947 attribs[i].value.type = VAGenericValueTypeInteger;
4948 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4949 attribs[i].value.value.i = VA_FOURCC_NV12;
4952 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4953 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4954 attribs[i].type = VASurfaceAttribPixelFormat;
4955 attribs[i].value.type = VAGenericValueTypeInteger;
4956 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4957 attribs[i].value.value.i = VA_FOURCC_NV12;
4960 attribs[i].type = VASurfaceAttribPixelFormat;
4961 attribs[i].value.type = VAGenericValueTypeInteger;
4962 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4963 attribs[i].value.value.i = VA_FOURCC_I420;
4966 attribs[i].type = VASurfaceAttribPixelFormat;
4967 attribs[i].value.type = VAGenericValueTypeInteger;
4968 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4969 attribs[i].value.value.i = VA_FOURCC_YV12;
4972 attribs[i].type = VASurfaceAttribPixelFormat;
4973 attribs[i].value.type = VAGenericValueTypeInteger;
4974 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4975 attribs[i].value.value.i = VA_FOURCC_IMC3;
4978 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4979 attribs[i].type = VASurfaceAttribPixelFormat;
4980 attribs[i].value.type = VAGenericValueTypeInteger;
4981 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4982 attribs[i].value.value.i = VA_FOURCC_YUY2;
4985 attribs[i].type = VASurfaceAttribPixelFormat;
4986 attribs[i].value.type = VAGenericValueTypeInteger;
4987 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4988 attribs[i].value.value.i = VA_FOURCC_RGBA;
4991 attribs[i].type = VASurfaceAttribPixelFormat;
4992 attribs[i].value.type = VAGenericValueTypeInteger;
4993 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4994 attribs[i].value.value.i = VA_FOURCC_RGBX;
4997 attribs[i].type = VASurfaceAttribPixelFormat;
4998 attribs[i].value.type = VAGenericValueTypeInteger;
4999 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5000 attribs[i].value.value.i = VA_FOURCC_YV16;
5004 } else if (IS_GEN8(i965->intel.device_info)) {
5005 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5006 if (obj_config->profile == VAProfileJPEGBaseline) {
5007 attribs[i].type = VASurfaceAttribPixelFormat;
5008 attribs[i].value.type = VAGenericValueTypeInteger;
5009 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5010 attribs[i].value.value.i = VA_FOURCC_IMC3;
5013 attribs[i].type = VASurfaceAttribPixelFormat;
5014 attribs[i].value.type = VAGenericValueTypeInteger;
5015 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5016 attribs[i].value.value.i = VA_FOURCC_IMC1;
5019 attribs[i].type = VASurfaceAttribPixelFormat;
5020 attribs[i].value.type = VAGenericValueTypeInteger;
5021 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5022 attribs[i].value.value.i = VA_FOURCC_Y800;
5025 attribs[i].type = VASurfaceAttribPixelFormat;
5026 attribs[i].value.type = VAGenericValueTypeInteger;
5027 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5028 attribs[i].value.value.i = VA_FOURCC_411P;
5031 attribs[i].type = VASurfaceAttribPixelFormat;
5032 attribs[i].value.type = VAGenericValueTypeInteger;
5033 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5034 attribs[i].value.value.i = VA_FOURCC_422H;
5037 attribs[i].type = VASurfaceAttribPixelFormat;
5038 attribs[i].value.type = VAGenericValueTypeInteger;
5039 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5040 attribs[i].value.value.i = VA_FOURCC_422V;
5043 attribs[i].type = VASurfaceAttribPixelFormat;
5044 attribs[i].value.type = VAGenericValueTypeInteger;
5045 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5046 attribs[i].value.value.i = VA_FOURCC_444P;
5049 attribs[i].type = VASurfaceAttribPixelFormat;
5050 attribs[i].value.type = VAGenericValueTypeInteger;
5051 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5052 attribs[i].value.value.i = VA_FOURCC_NV12;
5055 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5056 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5058 attribs[i].type = VASurfaceAttribPixelFormat;
5059 attribs[i].value.type = VAGenericValueTypeInteger;
5060 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5061 attribs[i].value.value.i = VA_FOURCC_NV12;
5064 attribs[i].type = VASurfaceAttribPixelFormat;
5065 attribs[i].value.type = VAGenericValueTypeInteger;
5066 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5067 attribs[i].value.value.i = VA_FOURCC_I420;
5070 attribs[i].type = VASurfaceAttribPixelFormat;
5071 attribs[i].value.type = VAGenericValueTypeInteger;
5072 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5073 attribs[i].value.value.i = VA_FOURCC_YV12;
5076 attribs[i].type = VASurfaceAttribPixelFormat;
5077 attribs[i].value.type = VAGenericValueTypeInteger;
5078 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5079 attribs[i].value.value.i = VA_FOURCC_IMC3;
5082 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5083 attribs[i].type = VASurfaceAttribPixelFormat;
5084 attribs[i].value.type = VAGenericValueTypeInteger;
5085 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5086 attribs[i].value.value.i = VA_FOURCC_YUY2;
5089 attribs[i].type = VASurfaceAttribPixelFormat;
5090 attribs[i].value.type = VAGenericValueTypeInteger;
5091 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5092 attribs[i].value.value.i = VA_FOURCC_RGBA;
5095 attribs[i].type = VASurfaceAttribPixelFormat;
5096 attribs[i].value.type = VAGenericValueTypeInteger;
5097 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5098 attribs[i].value.value.i = VA_FOURCC_RGBX;
5101 attribs[i].type = VASurfaceAttribPixelFormat;
5102 attribs[i].value.type = VAGenericValueTypeInteger;
5103 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5104 attribs[i].value.value.i = VA_FOURCC_BGRA;
5107 attribs[i].type = VASurfaceAttribPixelFormat;
5108 attribs[i].value.type = VAGenericValueTypeInteger;
5109 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5110 attribs[i].value.value.i = VA_FOURCC_BGRX;
5113 attribs[i].type = VASurfaceAttribPixelFormat;
5114 attribs[i].value.type = VAGenericValueTypeInteger;
5115 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5116 attribs[i].value.value.i = VA_FOURCC_YV16;
5122 attribs[i].type = VASurfaceAttribMemoryType;
5123 attribs[i].value.type = VAGenericValueTypeInteger;
5124 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5125 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5126 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5127 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5130 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5131 attribs[i].value.type = VAGenericValueTypePointer;
5132 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5133 attribs[i].value.value.p = NULL; /* ignore */
5136 if (i > *num_attribs) {
5139 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5143 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5149 /* Acquires buffer handle for external API usage (internal implementation) */
5151 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5152 uint32_t mem_type, VABufferInfo *out_buf_info)
5154 struct buffer_store *buffer_store;
5156 buffer_store = obj_buffer->buffer_store;
5157 if (!buffer_store || !buffer_store->bo)
5158 return VA_STATUS_ERROR_INVALID_BUFFER;
5160 /* Synchronization point */
5161 drm_intel_bo_wait_rendering(buffer_store->bo);
5163 if (obj_buffer->export_refcount > 0) {
5164 if (obj_buffer->export_state.mem_type != mem_type)
5165 return VA_STATUS_ERROR_INVALID_PARAMETER;
5168 VABufferInfo * const buf_info = &obj_buffer->export_state;
5171 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
5173 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
5174 return VA_STATUS_ERROR_INVALID_BUFFER;
5175 buf_info->handle = name;
5178 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5180 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
5181 return VA_STATUS_ERROR_INVALID_BUFFER;
5182 buf_info->handle = (intptr_t)fd;
5187 buf_info->type = obj_buffer->type;
5188 buf_info->mem_type = mem_type;
5189 buf_info->mem_size =
5190 obj_buffer->num_elements * obj_buffer->size_element;
5193 obj_buffer->export_refcount++;
5194 *out_buf_info = obj_buffer->export_state;
5195 return VA_STATUS_SUCCESS;
5198 /* Releases buffer handle after usage (internal implementation) */
5200 i965_release_buffer_handle(struct object_buffer *obj_buffer)
5202 if (obj_buffer->export_refcount == 0)
5203 return VA_STATUS_ERROR_INVALID_BUFFER;
5205 if (--obj_buffer->export_refcount == 0) {
5206 VABufferInfo * const buf_info = &obj_buffer->export_state;
5208 switch (buf_info->mem_type) {
5209 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5210 close((intptr_t)buf_info->handle);
5214 buf_info->mem_type = 0;
5216 return VA_STATUS_SUCCESS;
5219 /** Acquires buffer handle for external API usage */
5221 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
5222 VABufferInfo *buf_info)
5224 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5225 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5226 uint32_t i, mem_type;
5228 /* List of supported memory types, in preferred order */
5229 static const uint32_t mem_types[] = {
5230 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
5231 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
5236 return VA_STATUS_ERROR_INVALID_BUFFER;
5237 /* XXX: only VA surface|image like buffers are supported for now */
5238 if (obj_buffer->type != VAImageBufferType)
5239 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5242 return VA_STATUS_ERROR_INVALID_PARAMETER;
5244 if (!buf_info->mem_type)
5245 mem_type = mem_types[0];
5248 for (i = 0; mem_types[i] != 0; i++) {
5249 if (buf_info->mem_type & mem_types[i]) {
5250 mem_type = buf_info->mem_type;
5255 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
5257 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
5260 /** Releases buffer handle after usage from external API */
5262 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
5264 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5265 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5268 return VA_STATUS_ERROR_INVALID_BUFFER;
5270 return i965_release_buffer_handle(obj_buffer);
5274 i965_os_has_ring_support(VADriverContextP ctx,
5277 struct i965_driver_data *const i965 = i965_driver_data(ctx);
5281 return i965->intel.has_bsd;
5284 return i965->intel.has_blt;
5286 case I965_RING_VEBOX:
5287 return i965->intel.has_vebox;
5289 case I965_RING_NULL:
5290 return 1; /* Always support */
5293 /* should never get here */
5302 * Query video processing pipeline
5304 VAStatus i965_QueryVideoProcFilters(
5305 VADriverContextP ctx,
5306 VAContextID context,
5307 VAProcFilterType *filters,
5308 unsigned int *num_filters
5311 struct i965_driver_data *const i965 = i965_driver_data(ctx);
5312 unsigned int i = 0, num = 0;
5314 if (!num_filters || !filters)
5315 return VA_STATUS_ERROR_INVALID_PARAMETER;
5317 for (i = 0; i < i965->codec_info->num_filters; i++) {
5318 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
5319 if (num == *num_filters) {
5320 *num_filters = i965->codec_info->num_filters;
5322 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5325 filters[num++] = i965->codec_info->filters[i].type;
5331 return VA_STATUS_SUCCESS;
5334 VAStatus i965_QueryVideoProcFilterCaps(
5335 VADriverContextP ctx,
5336 VAContextID context,
5337 VAProcFilterType type,
5339 unsigned int *num_filter_caps
5343 struct i965_driver_data *const i965 = i965_driver_data(ctx);
5345 if (!filter_caps || !num_filter_caps)
5346 return VA_STATUS_ERROR_INVALID_PARAMETER;
5348 for (i = 0; i < i965->codec_info->num_filters; i++) {
5349 if (type == i965->codec_info->filters[i].type &&
5350 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
5354 if (i == i965->codec_info->num_filters)
5355 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
5360 case VAProcFilterNoiseReduction:
5361 case VAProcFilterSharpening:
5363 VAProcFilterCap *cap = filter_caps;
5365 if (*num_filter_caps < 1) {
5366 *num_filter_caps = 1;
5367 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5370 cap->range.min_value = 0.0;
5371 cap->range.max_value = 1.0;
5372 cap->range.default_value = 0.5;
5373 cap->range.step = 0.03125; /* 1.0 / 32 */
5379 case VAProcFilterDeinterlacing:
5381 VAProcFilterCapDeinterlacing *cap = filter_caps;
5383 if (*num_filter_caps < VAProcDeinterlacingCount) {
5384 *num_filter_caps = VAProcDeinterlacingCount;
5385 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5388 cap->type = VAProcDeinterlacingBob;
5393 if (i965->codec_info->has_di_motion_adptive) {
5394 cap->type = VAProcDeinterlacingMotionAdaptive;
5399 if (i965->codec_info->has_di_motion_compensated) {
5400 cap->type = VAProcDeinterlacingMotionCompensated;
5408 case VAProcFilterColorBalance:
5410 VAProcFilterCapColorBalance *cap = filter_caps;
5412 if (*num_filter_caps < VAProcColorBalanceCount) {
5413 *num_filter_caps = VAProcColorBalanceCount;
5414 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5417 cap->type = VAProcColorBalanceHue;
5418 cap->range.min_value = -180.0;
5419 cap->range.max_value = 180.0;
5420 cap->range.default_value = 0.0;
5421 cap->range.step = 1.0;
5425 cap->type = VAProcColorBalanceSaturation;
5426 cap->range.min_value = 0.0;
5427 cap->range.max_value = 10.0;
5428 cap->range.default_value = 1.0;
5429 cap->range.step = 0.1;
5433 cap->type = VAProcColorBalanceBrightness;
5434 cap->range.min_value = -100.0;
5435 cap->range.max_value = 100.0;
5436 cap->range.default_value = 0.0;
5437 cap->range.step = 1.0;
5441 cap->type = VAProcColorBalanceContrast;
5442 cap->range.min_value = 0.0;
5443 cap->range.max_value = 10.0;
5444 cap->range.default_value = 1.0;
5445 cap->range.step = 0.1;
5457 *num_filter_caps = i;
5459 return VA_STATUS_SUCCESS;
5462 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
5463 VAProcColorStandardBT601,
5466 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
5467 VAProcColorStandardBT601,
5470 VAStatus i965_QueryVideoProcPipelineCaps(
5471 VADriverContextP ctx,
5472 VAContextID context,
5473 VABufferID *filters,
5474 unsigned int num_filters,
5475 VAProcPipelineCaps *pipeline_cap /* out */
5478 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5481 pipeline_cap->pipeline_flags = 0;
5482 pipeline_cap->filter_flags = 0;
5483 pipeline_cap->num_forward_references = 0;
5484 pipeline_cap->num_backward_references = 0;
5485 pipeline_cap->num_input_color_standards = 1;
5486 pipeline_cap->input_color_standards = vpp_input_color_standards;
5487 pipeline_cap->num_output_color_standards = 1;
5488 pipeline_cap->output_color_standards = vpp_output_color_standards;
5490 for (i = 0; i < num_filters; i++) {
5491 struct object_buffer *obj_buffer = BUFFER(filters[i]);
5494 !obj_buffer->buffer_store ||
5495 !obj_buffer->buffer_store->buffer)
5496 return VA_STATUS_ERROR_INVALID_BUFFER;
5498 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
5500 if (base->type == VAProcFilterNoiseReduction) {
5501 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
5503 } else if (base->type == VAProcFilterDeinterlacing) {
5504 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
5506 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
5507 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5508 deint->algorithm == VAProcDeinterlacingMotionCompensated,
5509 VA_STATUS_ERROR_INVALID_PARAMETER);
5511 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5512 deint->algorithm == VAProcDeinterlacingMotionCompensated);
5513 pipeline_cap->num_forward_references++;
5514 } else if (base->type == VAProcFilterSkinToneEnhancement) {
5515 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
5520 return VA_STATUS_SUCCESS;
5523 extern const struct hw_codec_info *i965_get_codec_info(int devid);
5526 i965_driver_data_init(VADriverContextP ctx)
5528 struct i965_driver_data *i965 = i965_driver_data(ctx);
5530 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
5532 if (!i965->codec_info)
5535 if (object_heap_init(&i965->config_heap,
5536 sizeof(struct object_config),
5538 goto err_config_heap;
5539 if (object_heap_init(&i965->context_heap,
5540 sizeof(struct object_context),
5542 goto err_context_heap;
5544 if (object_heap_init(&i965->surface_heap,
5545 sizeof(struct object_surface),
5547 goto err_surface_heap;
5548 if (object_heap_init(&i965->buffer_heap,
5549 sizeof(struct object_buffer),
5551 goto err_buffer_heap;
5552 if (object_heap_init(&i965->image_heap,
5553 sizeof(struct object_image),
5555 goto err_image_heap;
5556 if (object_heap_init(&i965->subpic_heap,
5557 sizeof(struct object_subpic),
5559 goto err_subpic_heap;
5561 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5562 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5563 _i965InitMutex(&i965->render_mutex);
5564 _i965InitMutex(&i965->pp_mutex);
5569 object_heap_destroy(&i965->image_heap);
5571 object_heap_destroy(&i965->buffer_heap);
5573 object_heap_destroy(&i965->surface_heap);
5575 object_heap_destroy(&i965->context_heap);
5577 object_heap_destroy(&i965->config_heap);
5584 i965_driver_data_terminate(VADriverContextP ctx)
5586 struct i965_driver_data *i965 = i965_driver_data(ctx);
5588 _i965DestroyMutex(&i965->pp_mutex);
5589 _i965DestroyMutex(&i965->render_mutex);
5592 intel_batchbuffer_free(i965->batch);
5595 intel_batchbuffer_free(i965->pp_batch);
5597 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
5598 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
5599 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
5600 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
5601 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
5602 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
5606 bool (*init)(VADriverContextP ctx);
5607 void (*terminate)(VADriverContextP ctx);
5609 } i965_sub_ops[] = {
5612 intel_driver_terminate,
5617 i965_driver_data_init,
5618 i965_driver_data_terminate,
5623 i965_display_attributes_init,
5624 i965_display_attributes_terminate,
5629 i965_post_processing_init,
5630 i965_post_processing_terminate,
5636 i965_render_terminate,
5640 #ifdef HAVE_VA_WAYLAND
5642 i965_output_wayland_init,
5643 i965_output_wayland_terminate,
5650 i965_output_dri_init,
5651 i965_output_dri_terminate,
5658 i965_Init(VADriverContextP ctx)
5660 struct i965_driver_data *i965 = i965_driver_data(ctx);
5662 const char *chipset;
5664 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
5665 if ((i965_sub_ops[i].display_type == 0 ||
5666 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
5667 !i965_sub_ops[i].init(ctx))
5671 if (i == ARRAY_ELEMS(i965_sub_ops)) {
5672 switch (i965->intel.device_id) {
5674 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
5675 #include "i965_pciids.h"
5677 chipset = "Unknown Intel Chipset";
5681 sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d",
5682 INTEL_STR_DRIVER_VENDOR,
5683 INTEL_STR_DRIVER_NAME,
5685 INTEL_DRIVER_MAJOR_VERSION,
5686 INTEL_DRIVER_MINOR_VERSION,
5687 INTEL_DRIVER_MICRO_VERSION);
5689 if (INTEL_DRIVER_PRE_VERSION > 0) {
5690 const int len = strlen(i965->va_vendor);
5691 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
5694 i965->current_context_id = VA_INVALID_ID;
5696 return VA_STATUS_SUCCESS;
5700 for (; i >= 0; i--) {
5701 if (i965_sub_ops[i].display_type == 0 ||
5702 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5703 i965_sub_ops[i].terminate(ctx);
5707 return VA_STATUS_ERROR_UNKNOWN;
5712 i965_Terminate(VADriverContextP ctx)
5714 struct i965_driver_data *i965 = i965_driver_data(ctx);
5718 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5719 if (i965_sub_ops[i - 1].display_type == 0 ||
5720 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5721 i965_sub_ops[i - 1].terminate(ctx);
5725 ctx->pDriverData = NULL;
5728 return VA_STATUS_SUCCESS;
5732 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5735 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5737 struct VADriverVTable * const vtable = ctx->vtable;
5738 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5740 struct i965_driver_data *i965;
5741 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5743 ctx->version_major = VA_MAJOR_VERSION;
5744 ctx->version_minor = VA_MINOR_VERSION;
5745 ctx->max_profiles = I965_MAX_PROFILES;
5746 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5747 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5748 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5749 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5750 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5752 vtable->vaTerminate = i965_Terminate;
5753 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5754 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5755 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5756 vtable->vaCreateConfig = i965_CreateConfig;
5757 vtable->vaDestroyConfig = i965_DestroyConfig;
5758 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5759 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5760 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5761 vtable->vaCreateContext = i965_CreateContext;
5762 vtable->vaDestroyContext = i965_DestroyContext;
5763 vtable->vaCreateBuffer = i965_CreateBuffer;
5764 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5765 vtable->vaMapBuffer = i965_MapBuffer;
5766 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5767 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5768 vtable->vaBeginPicture = i965_BeginPicture;
5769 vtable->vaRenderPicture = i965_RenderPicture;
5770 vtable->vaEndPicture = i965_EndPicture;
5771 vtable->vaSyncSurface = i965_SyncSurface;
5772 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5773 vtable->vaPutSurface = i965_PutSurface;
5774 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5775 vtable->vaCreateImage = i965_CreateImage;
5776 vtable->vaDeriveImage = i965_DeriveImage;
5777 vtable->vaDestroyImage = i965_DestroyImage;
5778 vtable->vaSetImagePalette = i965_SetImagePalette;
5779 vtable->vaGetImage = i965_GetImage;
5780 vtable->vaPutImage = i965_PutImage;
5781 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5782 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5783 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5784 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5785 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5786 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5787 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5788 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5789 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5790 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5791 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5792 vtable->vaBufferInfo = i965_BufferInfo;
5793 vtable->vaLockSurface = i965_LockSurface;
5794 vtable->vaUnlockSurface = i965_UnlockSurface;
5795 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5796 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5797 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5800 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
5801 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
5803 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5804 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5805 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5807 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5810 ctx->pDriverData = NULL;
5812 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5815 ctx->pDriverData = (void *)i965;
5816 ret = i965_Init(ctx);
5818 if (ret == VA_STATUS_SUCCESS) {
5819 ctx->str_vendor = i965->va_vendor;
5822 ctx->pDriverData = NULL;