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>
33 # include "i965_output_dri.h"
36 #ifdef HAVE_VA_WAYLAND
37 # include "i965_output_wayland.h"
40 #include "intel_driver.h"
41 #include "intel_memman.h"
42 #include "intel_batchbuffer.h"
43 #include "i965_defines.h"
44 #include "i965_drv_video.h"
45 #include "i965_decoder.h"
46 #include "i965_encoder.h"
48 #define CONFIG_ID_OFFSET 0x01000000
49 #define CONTEXT_ID_OFFSET 0x02000000
50 #define SURFACE_ID_OFFSET 0x04000000
51 #define BUFFER_ID_OFFSET 0x08000000
52 #define IMAGE_ID_OFFSET 0x0a000000
53 #define SUBPIC_ID_OFFSET 0x10000000
55 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
58 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
61 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
64 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
67 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
70 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
73 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
75 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
77 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
79 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
81 static int get_sampling_from_fourcc(unsigned int fourcc);
83 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
84 #define IS_VA_X11(ctx) \
85 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
87 /* Check whether we are rendering to Wayland */
88 #define IS_VA_WAYLAND(ctx) \
89 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
92 I965_SURFACETYPE_RGBA = 1,
94 I965_SURFACETYPE_INDEXED
97 /* List of supported display attributes */
98 static const VADisplayAttribute i965_display_attributes[] = {
100 VADisplayAttribRotation,
101 0, 3, VA_ROTATION_NONE,
102 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
106 /* List of supported image formats */
109 VAImageFormat va_format;
110 } i965_image_format_map_t;
112 static const i965_image_format_map_t
113 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
114 { I965_SURFACETYPE_YUV,
115 { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
116 { I965_SURFACETYPE_YUV,
117 { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
118 { I965_SURFACETYPE_YUV,
119 { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
120 { I965_SURFACETYPE_YUV,
121 { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } },
122 { I965_SURFACETYPE_YUV,
123 { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } },
124 { I965_SURFACETYPE_RGBA,
125 { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
126 { I965_SURFACETYPE_RGBA,
127 { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
130 /* List of supported subpicture formats */
134 VAImageFormat va_format;
135 unsigned int va_flags;
136 } i965_subpic_format_map_t;
138 #define COMMON_SUBPICTURE_FLAGS \
139 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
140 VA_SUBPICTURE_GLOBAL_ALPHA)
142 static const i965_subpic_format_map_t
143 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
144 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
145 { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
146 COMMON_SUBPICTURE_FLAGS },
147 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
148 { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
149 COMMON_SUBPICTURE_FLAGS },
150 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
151 { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, },
152 COMMON_SUBPICTURE_FLAGS },
153 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
154 { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, },
155 COMMON_SUBPICTURE_FLAGS },
156 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
157 { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
158 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
159 COMMON_SUBPICTURE_FLAGS },
160 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
161 { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
162 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
163 COMMON_SUBPICTURE_FLAGS },
166 static const i965_subpic_format_map_t *
167 get_subpic_format(const VAImageFormat *va_format)
170 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
171 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
172 if (m->va_format.fourcc == va_format->fourcc &&
173 (m->type == I965_SURFACETYPE_RGBA ?
174 (m->va_format.byte_order == va_format->byte_order &&
175 m->va_format.red_mask == va_format->red_mask &&
176 m->va_format.green_mask == va_format->green_mask &&
177 m->va_format.blue_mask == va_format->blue_mask &&
178 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
184 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
185 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
186 static struct hw_codec_info g4x_hw_codec_info = {
187 .dec_hw_context_init = g4x_dec_hw_context_init,
188 .enc_hw_context_init = NULL,
189 .proc_hw_context_init = NULL,
193 .has_mpeg2_decoding = 1,
198 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
199 static struct hw_codec_info ironlake_hw_codec_info = {
200 .dec_hw_context_init = ironlake_dec_hw_context_init,
201 .enc_hw_context_init = NULL,
202 .proc_hw_context_init = i965_proc_context_init,
206 .has_mpeg2_decoding = 1,
207 .has_h264_decoding = 1,
209 .has_accelerated_putimage = 1,
214 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
215 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
216 static struct hw_codec_info gen6_hw_codec_info = {
217 .dec_hw_context_init = gen6_dec_hw_context_init,
218 .enc_hw_context_init = gen6_enc_hw_context_init,
219 .proc_hw_context_init = i965_proc_context_init,
223 .has_mpeg2_decoding = 1,
224 .has_mpeg2_encoding = 1,
225 .has_h264_decoding = 1,
226 .has_h264_encoding = 1,
227 .has_vc1_decoding = 1,
229 .has_accelerated_getimage = 1,
230 .has_accelerated_putimage = 1,
231 .has_tiled_surface = 1,
235 { VAProcFilterNoiseReduction, I965_RING_NULL },
236 { VAProcFilterDeinterlacing, I965_RING_NULL },
240 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
241 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
242 static struct hw_codec_info gen7_hw_codec_info = {
243 .dec_hw_context_init = gen7_dec_hw_context_init,
244 .enc_hw_context_init = gen7_enc_hw_context_init,
245 .proc_hw_context_init = i965_proc_context_init,
249 .has_mpeg2_decoding = 1,
250 .has_mpeg2_encoding = 1,
251 .has_h264_decoding = 1,
252 .has_h264_encoding = 1,
253 .has_vc1_decoding = 1,
254 .has_jpeg_decoding = 1,
256 .has_accelerated_getimage = 1,
257 .has_accelerated_putimage = 1,
258 .has_tiled_surface = 1,
259 .has_di_motion_adptive = 1,
263 { VAProcFilterNoiseReduction, I965_RING_NULL },
264 { VAProcFilterDeinterlacing, I965_RING_NULL },
268 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
269 static struct hw_codec_info gen75_hw_codec_info = {
270 .dec_hw_context_init = gen75_dec_hw_context_init,
271 .enc_hw_context_init = gen75_enc_hw_context_init,
272 .proc_hw_context_init = gen75_proc_context_init,
276 .has_mpeg2_decoding = 1,
277 .has_mpeg2_encoding = 1,
278 .has_h264_decoding = 1,
279 .has_h264_encoding = 1,
280 .has_vc1_decoding = 1,
281 .has_jpeg_decoding = 1,
283 .has_accelerated_getimage = 1,
284 .has_accelerated_putimage = 1,
285 .has_tiled_surface = 1,
286 .has_di_motion_adptive = 1,
287 .has_di_motion_compensated = 1,
291 { VAProcFilterNoiseReduction, I965_RING_VEBOX },
292 { VAProcFilterDeinterlacing, I965_RING_VEBOX },
293 { VAProcFilterSharpening, I965_RING_NULL },
294 { VAProcFilterColorBalance, I965_RING_VEBOX},
298 #define I965_PACKED_HEADER_BASE 0
299 #define I965_PACKED_MISC_HEADER_BASE 3
302 va_enc_packed_type_to_idx(int packed_type)
306 if (packed_type & VAEncPackedHeaderMiscMask) {
307 idx = I965_PACKED_MISC_HEADER_BASE;
308 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
309 assert(packed_type > 0);
310 idx += (packed_type - 1);
312 idx = I965_PACKED_HEADER_BASE;
314 switch (packed_type) {
315 case VAEncPackedHeaderSequence:
316 idx = I965_PACKED_HEADER_BASE + 0;
319 case VAEncPackedHeaderPicture:
320 idx = I965_PACKED_HEADER_BASE + 1;
323 case VAEncPackedHeaderSlice:
324 idx = I965_PACKED_HEADER_BASE + 2;
328 /* Should not get here */
340 i965_QueryConfigProfiles(VADriverContextP ctx,
341 VAProfile *profile_list, /* out */
342 int *num_profiles) /* out */
344 struct i965_driver_data * const i965 = i965_driver_data(ctx);
347 if (HAS_MPEG2_DECODING(i965) ||
348 HAS_MPEG2_ENCODING(i965)) {
349 profile_list[i++] = VAProfileMPEG2Simple;
350 profile_list[i++] = VAProfileMPEG2Main;
353 if (HAS_H264_DECODING(i965) ||
354 HAS_H264_ENCODING(i965)) {
355 profile_list[i++] = VAProfileH264Baseline;
356 profile_list[i++] = VAProfileH264Main;
357 profile_list[i++] = VAProfileH264High;
360 if (HAS_VC1_DECODING(i965)) {
361 profile_list[i++] = VAProfileVC1Simple;
362 profile_list[i++] = VAProfileVC1Main;
363 profile_list[i++] = VAProfileVC1Advanced;
367 profile_list[i++] = VAProfileNone;
370 if (HAS_JPEG_DECODING(i965)) {
371 profile_list[i++] = VAProfileJPEGBaseline;
374 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
375 assert(i <= I965_MAX_PROFILES);
378 return VA_STATUS_SUCCESS;
382 i965_QueryConfigEntrypoints(VADriverContextP ctx,
384 VAEntrypoint *entrypoint_list, /* out */
385 int *num_entrypoints) /* out */
387 struct i965_driver_data * const i965 = i965_driver_data(ctx);
391 case VAProfileMPEG2Simple:
392 case VAProfileMPEG2Main:
393 if (HAS_MPEG2_DECODING(i965))
394 entrypoint_list[n++] = VAEntrypointVLD;
396 if (HAS_MPEG2_ENCODING(i965))
397 entrypoint_list[n++] = VAEntrypointEncSlice;
401 case VAProfileH264Baseline:
402 case VAProfileH264Main:
403 case VAProfileH264High:
404 if (HAS_H264_DECODING(i965))
405 entrypoint_list[n++] = VAEntrypointVLD;
407 if (HAS_H264_ENCODING(i965))
408 entrypoint_list[n++] = VAEntrypointEncSlice;
412 case VAProfileVC1Simple:
413 case VAProfileVC1Main:
414 case VAProfileVC1Advanced:
415 if (HAS_VC1_DECODING(i965))
416 entrypoint_list[n++] = VAEntrypointVLD;
421 entrypoint_list[n++] = VAEntrypointVideoProc;
424 case VAProfileJPEGBaseline:
425 if (HAS_JPEG_DECODING(i965))
426 entrypoint_list[n++] = VAEntrypointVLD;
433 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
434 assert(n <= I965_MAX_ENTRYPOINTS);
435 *num_entrypoints = n;
436 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
440 i965_GetConfigAttributes(VADriverContextP ctx,
442 VAEntrypoint entrypoint,
443 VAConfigAttrib *attrib_list, /* in/out */
448 /* Other attributes don't seem to be defined */
449 /* What to do if we don't know the attribute? */
450 for (i = 0; i < num_attribs; i++) {
451 switch (attrib_list[i].type) {
452 case VAConfigAttribRTFormat:
453 attrib_list[i].value = VA_RT_FORMAT_YUV420;
456 case VAConfigAttribRateControl:
457 if (entrypoint == VAEntrypointEncSlice) {
458 attrib_list[i].value = VA_RC_CBR | VA_RC_CQP;
462 case VAConfigAttribEncPackedHeaders:
463 if (entrypoint == VAEntrypointEncSlice) {
464 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
468 case VAConfigAttribEncMaxRefFrames:
469 if (entrypoint == VAEntrypointEncSlice) {
470 attrib_list[i].value = (1 << 16) | (1 << 0);
476 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
481 return VA_STATUS_SUCCESS;
485 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
487 object_heap_free(heap, obj);
491 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
495 /* Check existing attrbiutes */
496 for (i = 0; i < obj_config->num_attribs; i++) {
497 if (obj_config->attrib_list[i].type == attrib->type) {
498 /* Update existing attribute */
499 obj_config->attrib_list[i].value = attrib->value;
500 return VA_STATUS_SUCCESS;
504 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
505 i = obj_config->num_attribs;
506 obj_config->attrib_list[i].type = attrib->type;
507 obj_config->attrib_list[i].value = attrib->value;
508 obj_config->num_attribs++;
509 return VA_STATUS_SUCCESS;
512 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
516 i965_CreateConfig(VADriverContextP ctx,
518 VAEntrypoint entrypoint,
519 VAConfigAttrib *attrib_list,
521 VAConfigID *config_id) /* out */
523 struct i965_driver_data * const i965 = i965_driver_data(ctx);
524 struct object_config *obj_config;
529 /* Validate profile & entrypoint */
531 case VAProfileMPEG2Simple:
532 case VAProfileMPEG2Main:
533 if ((HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
534 (HAS_MPEG2_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
535 vaStatus = VA_STATUS_SUCCESS;
537 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
541 case VAProfileH264Baseline:
542 case VAProfileH264Main:
543 case VAProfileH264High:
544 if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
545 (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
546 vaStatus = VA_STATUS_SUCCESS;
548 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
553 case VAProfileVC1Simple:
554 case VAProfileVC1Main:
555 case VAProfileVC1Advanced:
556 if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) {
557 vaStatus = VA_STATUS_SUCCESS;
559 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
565 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
566 vaStatus = VA_STATUS_SUCCESS;
568 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
573 case VAProfileJPEGBaseline:
574 if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) {
575 vaStatus = VA_STATUS_SUCCESS;
577 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
583 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
587 if (VA_STATUS_SUCCESS != vaStatus) {
591 configID = NEW_CONFIG_ID();
592 obj_config = CONFIG(configID);
594 if (NULL == obj_config) {
595 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
599 obj_config->profile = profile;
600 obj_config->entrypoint = entrypoint;
601 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
602 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
603 obj_config->num_attribs = 1;
605 for(i = 0; i < num_attribs; i++) {
606 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
608 if (VA_STATUS_SUCCESS != vaStatus) {
614 if (VA_STATUS_SUCCESS != vaStatus) {
615 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
617 *config_id = configID;
624 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
626 struct i965_driver_data *i965 = i965_driver_data(ctx);
627 struct object_config *obj_config = CONFIG(config_id);
630 if (NULL == obj_config) {
631 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
635 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
636 return VA_STATUS_SUCCESS;
639 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
640 VAConfigID config_id,
641 VAProfile *profile, /* out */
642 VAEntrypoint *entrypoint, /* out */
643 VAConfigAttrib *attrib_list, /* out */
644 int *num_attribs) /* out */
646 struct i965_driver_data *i965 = i965_driver_data(ctx);
647 struct object_config *obj_config = CONFIG(config_id);
648 VAStatus vaStatus = VA_STATUS_SUCCESS;
652 *profile = obj_config->profile;
653 *entrypoint = obj_config->entrypoint;
654 *num_attribs = obj_config->num_attribs;
656 for(i = 0; i < obj_config->num_attribs; i++) {
657 attrib_list[i] = obj_config->attrib_list[i];
664 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
666 struct object_surface *obj_surface = (struct object_surface *)obj;
668 dri_bo_unreference(obj_surface->bo);
669 obj_surface->bo = NULL;
671 if (obj_surface->free_private_data != NULL) {
672 obj_surface->free_private_data(&obj_surface->private_data);
673 obj_surface->private_data = NULL;
676 object_heap_free(heap, obj);
680 i965_surface_native_memory(VADriverContextP ctx,
681 struct object_surface *obj_surface,
685 struct i965_driver_data *i965 = i965_driver_data(ctx);
686 int tiling = HAS_TILED_SURFACE(i965);
688 if (!expected_fourcc)
689 return VA_STATUS_SUCCESS;
691 // todo, should we disable tiling for 422 format?
692 if (expected_fourcc == VA_FOURCC('I', '4', '2', '0') ||
693 expected_fourcc == VA_FOURCC('I', 'Y', 'U', 'V') ||
694 expected_fourcc == VA_FOURCC('Y', 'V', '1', '2'))
697 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
699 return VA_STATUS_SUCCESS;
703 i965_suface_external_memory(VADriverContextP ctx,
704 struct object_surface *obj_surface,
705 int external_memory_type,
706 VASurfaceAttribExternalBuffers *memory_attibute,
709 struct i965_driver_data *i965 = i965_driver_data(ctx);
711 if (!memory_attibute ||
712 !memory_attibute->buffers ||
713 index > memory_attibute->num_buffers)
714 return VA_STATUS_ERROR_INVALID_PARAMETER;
716 assert(obj_surface->orig_width == memory_attibute->width);
717 assert(obj_surface->orig_height == memory_attibute->height);
718 assert(memory_attibute->num_planes >= 1);
720 obj_surface->fourcc = memory_attibute->pixel_format;
721 obj_surface->width = memory_attibute->pitches[0];
722 obj_surface->size = memory_attibute->data_size;
724 if (memory_attibute->num_planes == 1)
725 obj_surface->height = memory_attibute->data_size / obj_surface->width;
727 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
729 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
730 obj_surface->x_cr_offset = 0;
732 switch (obj_surface->fourcc) {
733 case VA_FOURCC('N', 'V', '1', '2'):
734 assert(memory_attibute->num_planes == 2);
735 assert(memory_attibute->pitches[0] == memory_attibute->pitches[1]);
737 obj_surface->subsampling = SUBSAMPLE_YUV420;
738 obj_surface->y_cb_offset = obj_surface->height;
739 obj_surface->y_cr_offset = obj_surface->height;
740 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
741 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
742 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
746 case VA_FOURCC('Y', 'V', '1', '2'):
747 case VA_FOURCC('I', 'M', 'C', '1'):
748 assert(memory_attibute->num_planes == 3);
749 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
751 obj_surface->subsampling = SUBSAMPLE_YUV420;
752 obj_surface->y_cr_offset = obj_surface->height;
753 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
754 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
755 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
756 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
760 case VA_FOURCC('I', '4', '2', '0'):
761 case VA_FOURCC('I', 'Y', 'U', 'V'):
762 case VA_FOURCC('I', 'M', 'C', '3'):
763 assert(memory_attibute->num_planes == 3);
764 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
766 obj_surface->subsampling = SUBSAMPLE_YUV420;
767 obj_surface->y_cb_offset = obj_surface->height;
768 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
769 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
770 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
771 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
775 case VA_FOURCC('Y', 'U', 'Y', '2'):
776 case VA_FOURCC('U', 'Y', 'V', 'Y'):
777 assert(memory_attibute->num_planes == 1);
779 obj_surface->subsampling = SUBSAMPLE_YUV422H;
780 obj_surface->y_cb_offset = 0;
781 obj_surface->y_cr_offset = 0;
782 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
783 obj_surface->cb_cr_height = obj_surface->orig_height;
784 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
788 case VA_FOURCC('R', 'G', 'B', 'A'):
789 case VA_FOURCC('R', 'G', 'B', 'X'):
790 case VA_FOURCC('B', 'G', 'R', 'A'):
791 case VA_FOURCC('B', 'G', 'R', 'X'):
792 assert(memory_attibute->num_planes == 1);
794 obj_surface->subsampling = SUBSAMPLE_RGBX;
795 obj_surface->y_cb_offset = 0;
796 obj_surface->y_cr_offset = 0;
797 obj_surface->cb_cr_width = 0;
798 obj_surface->cb_cr_height = 0;
799 obj_surface->cb_cr_pitch = 0;
803 case VA_FOURCC('Y', '8', '0', '0'): /* monochrome surface */
804 assert(memory_attibute->num_planes == 1);
806 obj_surface->subsampling = SUBSAMPLE_YUV400;
807 obj_surface->y_cb_offset = 0;
808 obj_surface->y_cr_offset = 0;
809 obj_surface->cb_cr_width = 0;
810 obj_surface->cb_cr_height = 0;
811 obj_surface->cb_cr_pitch = 0;
815 case VA_FOURCC('4', '1', '1', 'P'):
816 assert(memory_attibute->num_planes == 3);
817 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
819 obj_surface->subsampling = SUBSAMPLE_YUV411;
820 obj_surface->y_cb_offset = 0;
821 obj_surface->y_cr_offset = 0;
822 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
823 obj_surface->cb_cr_height = obj_surface->orig_height;
824 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
828 case VA_FOURCC('4', '2', '2', 'H'):
829 assert(memory_attibute->num_planes == 3);
830 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
832 obj_surface->subsampling = SUBSAMPLE_YUV422H;
833 obj_surface->y_cb_offset = obj_surface->height;
834 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
835 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
836 obj_surface->cb_cr_height = obj_surface->orig_height;
837 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
841 case VA_FOURCC('4', '2', '2', 'V'):
842 assert(memory_attibute->num_planes == 3);
843 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
845 obj_surface->subsampling = SUBSAMPLE_YUV422H;
846 obj_surface->y_cb_offset = obj_surface->height;
847 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
848 obj_surface->cb_cr_width = obj_surface->orig_width;
849 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
850 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
854 case VA_FOURCC('4', '4', '4', 'P'):
855 assert(memory_attibute->num_planes == 3);
856 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
858 obj_surface->subsampling = SUBSAMPLE_YUV444;
859 obj_surface->y_cb_offset = obj_surface->height;
860 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
861 obj_surface->cb_cr_width = obj_surface->orig_width;
862 obj_surface->cb_cr_height = obj_surface->orig_height;
863 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
869 return VA_STATUS_ERROR_INVALID_PARAMETER;
872 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
873 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
874 "gem flinked vaapi surface",
875 memory_attibute->buffers[index]);
876 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
877 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
878 memory_attibute->buffers[index],
881 if (!obj_surface->bo)
882 return VA_STATUS_ERROR_INVALID_PARAMETER;
884 return VA_STATUS_SUCCESS;
888 i965_CreateSurfaces2(
889 VADriverContextP ctx,
893 VASurfaceID *surfaces,
894 unsigned int num_surfaces,
895 VASurfaceAttrib *attrib_list,
896 unsigned int num_attribs
899 struct i965_driver_data *i965 = i965_driver_data(ctx);
901 VAStatus vaStatus = VA_STATUS_SUCCESS;
902 int expected_fourcc = 0;
903 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
904 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
906 for (i = 0; i < num_attribs && attrib_list; i++) {
907 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
908 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
909 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
910 expected_fourcc = attrib_list[i].value.value.i;
913 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
914 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
916 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
918 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
919 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
920 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
921 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
924 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
925 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
926 assert(attrib_list[i].value.type == VAGenericValueTypePointer);
927 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
931 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
932 * for post-processing (including color conversion) */
933 if (VA_RT_FORMAT_YUV420 != format &&
934 VA_RT_FORMAT_YUV422 != format &&
935 VA_RT_FORMAT_YUV444 != format &&
936 VA_RT_FORMAT_YUV411 != format &&
937 VA_RT_FORMAT_YUV400 != format &&
938 VA_RT_FORMAT_RGB32 != format) {
939 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
942 for (i = 0; i < num_surfaces; i++) {
943 int surfaceID = NEW_SURFACE_ID();
944 struct object_surface *obj_surface = SURFACE(surfaceID);
946 if (NULL == obj_surface) {
947 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
951 surfaces[i] = surfaceID;
952 obj_surface->status = VASurfaceReady;
953 obj_surface->orig_width = width;
954 obj_surface->orig_height = height;
956 obj_surface->subpic_render_idx = 0;
957 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
958 obj_surface->subpic[j] = VA_INVALID_ID;
959 obj_surface->obj_subpic[j] = NULL;
962 obj_surface->width = ALIGN(width, 16);
963 obj_surface->height = ALIGN(height, 16);
964 obj_surface->flags = SURFACE_REFERENCED;
965 obj_surface->fourcc = 0;
966 obj_surface->bo = NULL;
967 obj_surface->locked_image_id = VA_INVALID_ID;
968 obj_surface->private_data = NULL;
969 obj_surface->free_private_data = NULL;
970 obj_surface->subsampling = SUBSAMPLE_YUV420;
972 switch (memory_type) {
973 case I965_SURFACE_MEM_NATIVE:
974 i965_surface_native_memory(ctx,
980 case I965_SURFACE_MEM_GEM_FLINK:
981 case I965_SURFACE_MEM_DRM_PRIME:
982 i965_suface_external_memory(ctx,
992 if (VA_STATUS_SUCCESS != vaStatus) {
993 /* surfaces[i-1] was the last successful allocation */
995 struct object_surface *obj_surface = SURFACE(surfaces[i]);
997 surfaces[i] = VA_INVALID_SURFACE;
999 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1007 i965_CreateSurfaces(VADriverContextP ctx,
1012 VASurfaceID *surfaces) /* out */
1014 return i965_CreateSurfaces2(ctx,
1025 i965_DestroySurfaces(VADriverContextP ctx,
1026 VASurfaceID *surface_list,
1029 struct i965_driver_data *i965 = i965_driver_data(ctx);
1032 for (i = num_surfaces; i--; ) {
1033 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1035 assert(obj_surface);
1036 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1039 return VA_STATUS_SUCCESS;
1043 i965_QueryImageFormats(VADriverContextP ctx,
1044 VAImageFormat *format_list, /* out */
1045 int *num_formats) /* out */
1049 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1050 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1052 format_list[n] = m->va_format;
1058 return VA_STATUS_SUCCESS;
1062 * Guess the format when the usage of a VA surface is unknown
1063 * 1. Without a valid context: YV12
1064 * 2. The current context is valid:
1065 * a) always NV12 on GEN6 and later
1066 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1069 i965_guess_surface_format(VADriverContextP ctx,
1070 VASurfaceID surface,
1071 unsigned int *fourcc,
1072 unsigned int *is_tiled)
1074 struct i965_driver_data *i965 = i965_driver_data(ctx);
1075 struct object_context *obj_context = NULL;
1076 struct object_config *obj_config = NULL;
1078 *fourcc = VA_FOURCC('Y', 'V', '1', '2');
1081 if (i965->current_context_id == VA_INVALID_ID)
1084 obj_context = CONTEXT(i965->current_context_id);
1089 obj_config = obj_context->obj_config;
1095 if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) {
1096 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1101 switch (obj_config->profile) {
1102 case VAProfileMPEG2Simple:
1103 case VAProfileMPEG2Main:
1104 *fourcc = VA_FOURCC('I', '4', '2', '0');
1109 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1116 i965_QuerySubpictureFormats(VADriverContextP ctx,
1117 VAImageFormat *format_list, /* out */
1118 unsigned int *flags, /* out */
1119 unsigned int *num_formats) /* out */
1123 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1124 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1126 format_list[n] = m->va_format;
1128 flags[n] = m->va_flags;
1134 return VA_STATUS_SUCCESS;
1138 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1140 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1142 object_heap_free(heap, obj);
1146 i965_CreateSubpicture(VADriverContextP ctx,
1148 VASubpictureID *subpicture) /* out */
1150 struct i965_driver_data *i965 = i965_driver_data(ctx);
1151 VASubpictureID subpicID = NEW_SUBPIC_ID()
1152 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1155 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1157 struct object_image *obj_image = IMAGE(image);
1159 return VA_STATUS_ERROR_INVALID_IMAGE;
1161 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1163 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1165 *subpicture = subpicID;
1166 obj_subpic->image = image;
1167 obj_subpic->obj_image = obj_image;
1168 obj_subpic->format = m->format;
1169 obj_subpic->width = obj_image->image.width;
1170 obj_subpic->height = obj_image->image.height;
1171 obj_subpic->pitch = obj_image->image.pitches[0];
1172 obj_subpic->bo = obj_image->bo;
1173 obj_subpic->global_alpha = 1.0;
1175 return VA_STATUS_SUCCESS;
1179 i965_DestroySubpicture(VADriverContextP ctx,
1180 VASubpictureID subpicture)
1182 struct i965_driver_data *i965 = i965_driver_data(ctx);
1183 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1186 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1188 assert(obj_subpic->obj_image);
1189 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1190 return VA_STATUS_SUCCESS;
1194 i965_SetSubpictureImage(VADriverContextP ctx,
1195 VASubpictureID subpicture,
1199 return VA_STATUS_ERROR_UNIMPLEMENTED;
1203 i965_SetSubpictureChromakey(VADriverContextP ctx,
1204 VASubpictureID subpicture,
1205 unsigned int chromakey_min,
1206 unsigned int chromakey_max,
1207 unsigned int chromakey_mask)
1210 return VA_STATUS_ERROR_UNIMPLEMENTED;
1214 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1215 VASubpictureID subpicture,
1218 struct i965_driver_data *i965 = i965_driver_data(ctx);
1219 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1221 if(global_alpha > 1.0 || global_alpha < 0.0){
1222 return VA_STATUS_ERROR_INVALID_PARAMETER;
1226 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1228 obj_subpic->global_alpha = global_alpha;
1230 return VA_STATUS_SUCCESS;
1234 i965_AssociateSubpicture(VADriverContextP ctx,
1235 VASubpictureID subpicture,
1236 VASurfaceID *target_surfaces,
1238 short src_x, /* upper left offset in subpicture */
1240 unsigned short src_width,
1241 unsigned short src_height,
1242 short dest_x, /* upper left offset in surface */
1244 unsigned short dest_width,
1245 unsigned short dest_height,
1247 * whether to enable chroma-keying or global-alpha
1248 * see VA_SUBPICTURE_XXX values
1252 struct i965_driver_data *i965 = i965_driver_data(ctx);
1253 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1257 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1259 assert(obj_subpic->obj_image);
1261 obj_subpic->src_rect.x = src_x;
1262 obj_subpic->src_rect.y = src_y;
1263 obj_subpic->src_rect.width = src_width;
1264 obj_subpic->src_rect.height = src_height;
1265 obj_subpic->dst_rect.x = dest_x;
1266 obj_subpic->dst_rect.y = dest_y;
1267 obj_subpic->dst_rect.width = dest_width;
1268 obj_subpic->dst_rect.height = dest_height;
1269 obj_subpic->flags = flags;
1271 for (i = 0; i < num_surfaces; i++) {
1272 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1274 return VA_STATUS_ERROR_INVALID_SURFACE;
1276 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1277 if(obj_surface->subpic[j] == VA_INVALID_ID){
1278 assert(obj_surface->obj_subpic[j] == NULL);
1279 obj_surface->subpic[j] = subpicture;
1280 obj_surface->obj_subpic[j] = obj_subpic;
1285 if(j == I965_MAX_SUBPIC_SUM){
1286 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1290 return VA_STATUS_SUCCESS;
1295 i965_DeassociateSubpicture(VADriverContextP ctx,
1296 VASubpictureID subpicture,
1297 VASurfaceID *target_surfaces,
1300 struct i965_driver_data *i965 = i965_driver_data(ctx);
1301 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1305 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1307 for (i = 0; i < num_surfaces; i++) {
1308 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1310 return VA_STATUS_ERROR_INVALID_SURFACE;
1312 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1313 if (obj_surface->subpic[j] == subpicture) {
1314 assert(obj_surface->obj_subpic[j] == obj_subpic);
1315 obj_surface->subpic[j] = VA_INVALID_ID;
1316 obj_surface->obj_subpic[j] = NULL;
1321 if(j == I965_MAX_SUBPIC_SUM){
1322 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1325 return VA_STATUS_SUCCESS;
1329 i965_reference_buffer_store(struct buffer_store **ptr,
1330 struct buffer_store *buffer_store)
1332 assert(*ptr == NULL);
1335 buffer_store->ref_count++;
1336 *ptr = buffer_store;
1341 i965_release_buffer_store(struct buffer_store **ptr)
1343 struct buffer_store *buffer_store = *ptr;
1345 if (buffer_store == NULL)
1348 assert(buffer_store->bo || buffer_store->buffer);
1349 assert(!(buffer_store->bo && buffer_store->buffer));
1350 buffer_store->ref_count--;
1352 if (buffer_store->ref_count == 0) {
1353 dri_bo_unreference(buffer_store->bo);
1354 free(buffer_store->buffer);
1355 buffer_store->bo = NULL;
1356 buffer_store->buffer = NULL;
1364 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1366 struct object_context *obj_context = (struct object_context *)obj;
1369 if (obj_context->hw_context) {
1370 obj_context->hw_context->destroy(obj_context->hw_context);
1371 obj_context->hw_context = NULL;
1374 if (obj_context->codec_type == CODEC_PROC) {
1375 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1377 } else if (obj_context->codec_type == CODEC_ENC) {
1378 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1379 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1380 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1382 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1383 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1385 free(obj_context->codec_state.encode.slice_params);
1387 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1388 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1389 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1391 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1392 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1394 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1395 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1397 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1398 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1400 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1401 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1403 free(obj_context->codec_state.encode.slice_params_ext);
1405 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1406 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1408 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1409 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1410 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1412 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1413 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1415 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1416 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1418 free(obj_context->codec_state.decode.slice_params);
1419 free(obj_context->codec_state.decode.slice_datas);
1422 free(obj_context->render_targets);
1423 object_heap_free(heap, obj);
1427 i965_CreateContext(VADriverContextP ctx,
1428 VAConfigID config_id,
1432 VASurfaceID *render_targets,
1433 int num_render_targets,
1434 VAContextID *context) /* out */
1436 struct i965_driver_data *i965 = i965_driver_data(ctx);
1437 struct i965_render_state *render_state = &i965->render_state;
1438 struct object_config *obj_config = CONFIG(config_id);
1439 struct object_context *obj_context = NULL;
1440 VAStatus vaStatus = VA_STATUS_SUCCESS;
1444 if (NULL == obj_config) {
1445 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1449 if (picture_width > i965->codec_info->max_width ||
1450 picture_height > i965->codec_info->max_height) {
1451 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1456 /* Validate picture dimensions */
1457 contextID = NEW_CONTEXT_ID();
1458 obj_context = CONTEXT(contextID);
1460 if (NULL == obj_context) {
1461 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1465 render_state->inited = 1;
1467 switch (obj_config->profile) {
1468 case VAProfileH264Baseline:
1469 case VAProfileH264Main:
1470 case VAProfileH264High:
1471 if (!HAS_H264_DECODING(i965) &&
1472 !HAS_H264_ENCODING(i965))
1473 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1474 render_state->interleaved_uv = 1;
1477 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id));
1481 *context = contextID;
1482 obj_context->flags = flag;
1483 obj_context->context_id = contextID;
1484 obj_context->obj_config = obj_config;
1485 obj_context->picture_width = picture_width;
1486 obj_context->picture_height = picture_height;
1487 obj_context->num_render_targets = num_render_targets;
1488 obj_context->render_targets =
1489 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1490 obj_context->hw_context = NULL;
1492 for(i = 0; i < num_render_targets; i++) {
1493 if (NULL == SURFACE(render_targets[i])) {
1494 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1498 obj_context->render_targets[i] = render_targets[i];
1501 if (VA_STATUS_SUCCESS == vaStatus) {
1502 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1503 obj_context->codec_type = CODEC_PROC;
1504 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1505 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1506 assert(i965->codec_info->proc_hw_context_init);
1507 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1508 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1509 obj_context->codec_type = CODEC_ENC;
1510 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1511 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1512 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1513 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1514 sizeof(*obj_context->codec_state.encode.slice_params));
1515 assert(i965->codec_info->enc_hw_context_init);
1516 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1518 obj_context->codec_type = CODEC_DEC;
1519 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1520 obj_context->codec_state.decode.current_render_target = -1;
1521 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1522 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1523 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1524 sizeof(*obj_context->codec_state.decode.slice_params));
1525 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1526 sizeof(*obj_context->codec_state.decode.slice_datas));
1528 assert(i965->codec_info->dec_hw_context_init);
1529 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1533 /* Error recovery */
1534 if (VA_STATUS_SUCCESS != vaStatus) {
1535 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1538 i965->current_context_id = contextID;
1544 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1546 struct i965_driver_data *i965 = i965_driver_data(ctx);
1547 struct object_context *obj_context = CONTEXT(context);
1549 assert(obj_context);
1551 if (i965->current_context_id == context)
1552 i965->current_context_id = VA_INVALID_ID;
1554 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1556 return VA_STATUS_SUCCESS;
1560 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1562 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1564 assert(obj_buffer->buffer_store);
1565 i965_release_buffer_store(&obj_buffer->buffer_store);
1566 object_heap_free(heap, obj);
1570 i965_create_buffer_internal(VADriverContextP ctx,
1571 VAContextID context,
1574 unsigned int num_elements,
1579 struct i965_driver_data *i965 = i965_driver_data(ctx);
1580 struct object_buffer *obj_buffer = NULL;
1581 struct buffer_store *buffer_store = NULL;
1586 case VAPictureParameterBufferType:
1587 case VAIQMatrixBufferType:
1588 case VAQMatrixBufferType:
1589 case VABitPlaneBufferType:
1590 case VASliceGroupMapBufferType:
1591 case VASliceParameterBufferType:
1592 case VASliceDataBufferType:
1593 case VAMacroblockParameterBufferType:
1594 case VAResidualDataBufferType:
1595 case VADeblockingParameterBufferType:
1596 case VAImageBufferType:
1597 case VAEncCodedBufferType:
1598 case VAEncSequenceParameterBufferType:
1599 case VAEncPictureParameterBufferType:
1600 case VAEncSliceParameterBufferType:
1601 case VAEncPackedHeaderParameterBufferType:
1602 case VAEncPackedHeaderDataBufferType:
1603 case VAEncMiscParameterBufferType:
1604 case VAProcPipelineParameterBufferType:
1605 case VAProcFilterParameterBufferType:
1606 case VAHuffmanTableBufferType:
1611 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1614 bufferID = NEW_BUFFER_ID();
1615 obj_buffer = BUFFER(bufferID);
1617 if (NULL == obj_buffer) {
1618 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1621 if (type == VAEncCodedBufferType) {
1622 size += I965_CODEDBUFFER_HEADER_SIZE;
1623 size += 0x1000; /* for upper bound check */
1626 obj_buffer->max_num_elements = num_elements;
1627 obj_buffer->num_elements = num_elements;
1628 obj_buffer->size_element = size;
1629 obj_buffer->type = type;
1630 obj_buffer->buffer_store = NULL;
1631 buffer_store = calloc(1, sizeof(struct buffer_store));
1632 assert(buffer_store);
1633 buffer_store->ref_count = 1;
1635 if (store_bo != NULL) {
1636 buffer_store->bo = store_bo;
1637 dri_bo_reference(buffer_store->bo);
1640 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1641 } else if (type == VASliceDataBufferType ||
1642 type == VAImageBufferType ||
1643 type == VAEncCodedBufferType) {
1644 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1646 size * num_elements, 64);
1647 assert(buffer_store->bo);
1649 if (type == VAEncCodedBufferType) {
1650 struct i965_coded_buffer_segment *coded_buffer_segment;
1652 dri_bo_map(buffer_store->bo, 1);
1653 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1654 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1655 coded_buffer_segment->base.bit_offset = 0;
1656 coded_buffer_segment->base.status = 0;
1657 coded_buffer_segment->base.buf = NULL;
1658 coded_buffer_segment->base.next = NULL;
1659 coded_buffer_segment->mapped = 0;
1660 coded_buffer_segment->codec = 0;
1661 dri_bo_unmap(buffer_store->bo);
1663 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1669 if (type == VAEncPackedHeaderDataBufferType) {
1670 msize = ALIGN(size, 4);
1673 buffer_store->buffer = malloc(msize * num_elements);
1674 assert(buffer_store->buffer);
1677 memcpy(buffer_store->buffer, data, size * num_elements);
1680 buffer_store->num_elements = obj_buffer->num_elements;
1681 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1682 i965_release_buffer_store(&buffer_store);
1685 return VA_STATUS_SUCCESS;
1689 i965_CreateBuffer(VADriverContextP ctx,
1690 VAContextID context, /* in */
1691 VABufferType type, /* in */
1692 unsigned int size, /* in */
1693 unsigned int num_elements, /* in */
1694 void *data, /* in */
1695 VABufferID *buf_id) /* out */
1697 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1702 i965_BufferSetNumElements(VADriverContextP ctx,
1703 VABufferID buf_id, /* in */
1704 unsigned int num_elements) /* in */
1706 struct i965_driver_data *i965 = i965_driver_data(ctx);
1707 struct object_buffer *obj_buffer = BUFFER(buf_id);
1708 VAStatus vaStatus = VA_STATUS_SUCCESS;
1713 return VA_STATUS_ERROR_INVALID_BUFFER;
1715 if ((num_elements < 0) ||
1716 (num_elements > obj_buffer->max_num_elements)) {
1717 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1719 obj_buffer->num_elements = num_elements;
1720 if (obj_buffer->buffer_store != NULL) {
1721 obj_buffer->buffer_store->num_elements = num_elements;
1729 i965_MapBuffer(VADriverContextP ctx,
1730 VABufferID buf_id, /* in */
1731 void **pbuf) /* out */
1733 struct i965_driver_data *i965 = i965_driver_data(ctx);
1734 struct object_buffer *obj_buffer = BUFFER(buf_id);
1735 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1737 assert(obj_buffer && obj_buffer->buffer_store);
1738 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1739 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1741 if (!obj_buffer || !obj_buffer->buffer_store)
1742 return VA_STATUS_ERROR_INVALID_BUFFER;
1744 if (NULL != obj_buffer->buffer_store->bo) {
1745 unsigned int tiling, swizzle;
1747 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1749 if (tiling != I915_TILING_NONE)
1750 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1752 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1754 assert(obj_buffer->buffer_store->bo->virtual);
1755 *pbuf = obj_buffer->buffer_store->bo->virtual;
1757 if (obj_buffer->type == VAEncCodedBufferType) {
1759 unsigned char *buffer = NULL;
1760 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1762 if (!coded_buffer_segment->mapped) {
1763 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1765 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1767 if (coded_buffer_segment->codec == CODEC_H264) {
1768 delimiter0 = H264_DELIMITER0;
1769 delimiter1 = H264_DELIMITER1;
1770 delimiter2 = H264_DELIMITER2;
1771 delimiter3 = H264_DELIMITER3;
1772 delimiter4 = H264_DELIMITER4;
1773 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1774 delimiter0 = MPEG2_DELIMITER0;
1775 delimiter1 = MPEG2_DELIMITER1;
1776 delimiter2 = MPEG2_DELIMITER2;
1777 delimiter3 = MPEG2_DELIMITER3;
1778 delimiter4 = MPEG2_DELIMITER4;
1783 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1784 if ((buffer[i] == delimiter0) &&
1785 (buffer[i + 1] == delimiter1) &&
1786 (buffer[i + 2] == delimiter2) &&
1787 (buffer[i + 3] == delimiter3) &&
1788 (buffer[i + 4] == delimiter4))
1792 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1793 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1796 coded_buffer_segment->base.size = i;
1797 coded_buffer_segment->mapped = 1;
1799 assert(coded_buffer_segment->base.buf);
1803 vaStatus = VA_STATUS_SUCCESS;
1804 } else if (NULL != obj_buffer->buffer_store->buffer) {
1805 *pbuf = obj_buffer->buffer_store->buffer;
1806 vaStatus = VA_STATUS_SUCCESS;
1813 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1815 struct i965_driver_data *i965 = i965_driver_data(ctx);
1816 struct object_buffer *obj_buffer = BUFFER(buf_id);
1817 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1819 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
1820 return VA_STATUS_ERROR_INVALID_BUFFER;
1822 assert(obj_buffer && obj_buffer->buffer_store);
1823 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1824 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1826 if (!obj_buffer || !obj_buffer->buffer_store)
1827 return VA_STATUS_ERROR_INVALID_BUFFER;
1829 if (NULL != obj_buffer->buffer_store->bo) {
1830 unsigned int tiling, swizzle;
1832 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1834 if (tiling != I915_TILING_NONE)
1835 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1837 dri_bo_unmap(obj_buffer->buffer_store->bo);
1839 vaStatus = VA_STATUS_SUCCESS;
1840 } else if (NULL != obj_buffer->buffer_store->buffer) {
1842 vaStatus = VA_STATUS_SUCCESS;
1849 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1851 struct i965_driver_data *i965 = i965_driver_data(ctx);
1852 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1857 return VA_STATUS_ERROR_INVALID_BUFFER;
1859 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1861 return VA_STATUS_SUCCESS;
1865 i965_BeginPicture(VADriverContextP ctx,
1866 VAContextID context,
1867 VASurfaceID render_target)
1869 struct i965_driver_data *i965 = i965_driver_data(ctx);
1870 struct object_context *obj_context = CONTEXT(context);
1871 struct object_surface *obj_surface = SURFACE(render_target);
1872 struct object_config *obj_config;
1876 assert(obj_context);
1879 return VA_STATUS_ERROR_INVALID_CONTEXT;
1881 assert(obj_surface);
1884 return VA_STATUS_ERROR_INVALID_SURFACE;
1886 obj_config = obj_context->obj_config;
1889 switch (obj_config->profile) {
1890 case VAProfileMPEG2Simple:
1891 case VAProfileMPEG2Main:
1892 vaStatus = VA_STATUS_SUCCESS;
1895 case VAProfileH264Baseline:
1896 case VAProfileH264Main:
1897 case VAProfileH264High:
1898 vaStatus = VA_STATUS_SUCCESS;
1901 case VAProfileVC1Simple:
1902 case VAProfileVC1Main:
1903 case VAProfileVC1Advanced:
1904 vaStatus = VA_STATUS_SUCCESS;
1907 case VAProfileJPEGBaseline:
1908 vaStatus = VA_STATUS_SUCCESS;
1912 vaStatus = VA_STATUS_SUCCESS;
1917 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1921 if (obj_context->codec_type == CODEC_PROC) {
1922 obj_context->codec_state.proc.current_render_target = render_target;
1923 } else if (obj_context->codec_type == CODEC_ENC) {
1924 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1926 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
1927 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1930 obj_context->codec_state.encode.num_slice_params = 0;
1933 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1935 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1936 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1938 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1939 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1941 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1942 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1944 obj_context->codec_state.encode.num_slice_params_ext = 0;
1945 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
1946 obj_context->codec_state.encode.last_packed_header_type = 0;
1948 obj_context->codec_state.decode.current_render_target = render_target;
1949 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1950 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1951 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1952 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
1954 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
1955 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1956 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1959 obj_context->codec_state.decode.num_slice_params = 0;
1960 obj_context->codec_state.decode.num_slice_datas = 0;
1966 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
1968 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
1970 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1971 struct object_context *obj_context, \
1972 struct object_buffer *obj_buffer) \
1974 struct category##_state *category = &obj_context->codec_state.category; \
1975 assert(obj_buffer->buffer_store->bo == NULL); \
1976 assert(obj_buffer->buffer_store->buffer); \
1977 i965_release_buffer_store(&category->member); \
1978 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
1979 return VA_STATUS_SUCCESS; \
1982 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
1984 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1985 struct object_context *obj_context, \
1986 struct object_buffer *obj_buffer) \
1988 struct category##_state *category = &obj_context->codec_state.category; \
1989 if (category->num_##member == category->max_##member) { \
1990 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
1991 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
1992 category->max_##member += NUM_SLICES; \
1994 i965_release_buffer_store(&category->member[category->num_##member]); \
1995 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
1996 category->num_##member++; \
1997 return VA_STATUS_SUCCESS; \
2000 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2002 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2003 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2004 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2005 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2006 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2008 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2009 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2010 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2013 i965_decoder_render_picture(VADriverContextP ctx,
2014 VAContextID context,
2015 VABufferID *buffers,
2018 struct i965_driver_data *i965 = i965_driver_data(ctx);
2019 struct object_context *obj_context = CONTEXT(context);
2020 VAStatus vaStatus = VA_STATUS_SUCCESS;
2023 assert(obj_context);
2026 return VA_STATUS_ERROR_INVALID_CONTEXT;
2028 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2029 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2032 return VA_STATUS_ERROR_INVALID_BUFFER;
2034 switch (obj_buffer->type) {
2035 case VAPictureParameterBufferType:
2036 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2039 case VAIQMatrixBufferType:
2040 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2043 case VABitPlaneBufferType:
2044 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2047 case VASliceParameterBufferType:
2048 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2051 case VASliceDataBufferType:
2052 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2055 case VAHuffmanTableBufferType:
2056 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2060 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2068 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2070 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2071 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2072 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2073 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2074 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2075 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2076 /* extended buffer */
2077 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2078 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2080 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2081 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2082 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2085 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2086 struct object_context *obj_context,
2087 struct object_buffer *obj_buffer,
2090 struct encode_state *encode = &obj_context->codec_state.encode;
2092 assert(obj_buffer->buffer_store->bo == NULL);
2093 assert(obj_buffer->buffer_store->buffer);
2094 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2095 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2097 return VA_STATUS_SUCCESS;
2101 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2102 struct object_context *obj_context,
2103 struct object_buffer *obj_buffer,
2106 struct encode_state *encode = &obj_context->codec_state.encode;
2108 assert(obj_buffer->buffer_store->bo == NULL);
2109 assert(obj_buffer->buffer_store->buffer);
2110 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2111 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2113 return VA_STATUS_SUCCESS;
2117 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2118 struct object_context *obj_context,
2119 struct object_buffer *obj_buffer)
2121 struct encode_state *encode = &obj_context->codec_state.encode;
2122 VAEncMiscParameterBuffer *param = NULL;
2124 assert(obj_buffer->buffer_store->bo == NULL);
2125 assert(obj_buffer->buffer_store->buffer);
2127 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2128 i965_release_buffer_store(&encode->misc_param[param->type]);
2129 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2131 return VA_STATUS_SUCCESS;
2135 i965_encoder_render_picture(VADriverContextP ctx,
2136 VAContextID context,
2137 VABufferID *buffers,
2140 struct i965_driver_data *i965 = i965_driver_data(ctx);
2141 struct object_context *obj_context = CONTEXT(context);
2142 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2145 assert(obj_context);
2148 return VA_STATUS_ERROR_INVALID_CONTEXT;
2150 for (i = 0; i < num_buffers; i++) {
2151 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2154 return VA_STATUS_ERROR_INVALID_BUFFER;
2156 switch (obj_buffer->type) {
2157 case VAQMatrixBufferType:
2158 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2161 case VAIQMatrixBufferType:
2162 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2165 case VAEncSequenceParameterBufferType:
2166 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2169 case VAEncPictureParameterBufferType:
2170 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2173 case VAEncSliceParameterBufferType:
2174 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2177 case VAEncPackedHeaderParameterBufferType:
2179 struct encode_state *encode = &obj_context->codec_state.encode;
2180 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2181 encode->last_packed_header_type = param->type;
2183 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2186 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2190 case VAEncPackedHeaderDataBufferType:
2192 struct encode_state *encode = &obj_context->codec_state.encode;
2194 assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2195 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2196 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2197 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2198 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)));
2199 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2202 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2206 case VAEncMiscParameterBufferType:
2207 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2213 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2221 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2223 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2224 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2227 i965_proc_render_picture(VADriverContextP ctx,
2228 VAContextID context,
2229 VABufferID *buffers,
2232 struct i965_driver_data *i965 = i965_driver_data(ctx);
2233 struct object_context *obj_context = CONTEXT(context);
2234 VAStatus vaStatus = VA_STATUS_SUCCESS;
2237 assert(obj_context);
2240 return VA_STATUS_ERROR_INVALID_CONTEXT;
2242 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2243 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2246 return VA_STATUS_ERROR_INVALID_BUFFER;
2248 switch (obj_buffer->type) {
2249 case VAProcPipelineParameterBufferType:
2250 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2254 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2263 i965_RenderPicture(VADriverContextP ctx,
2264 VAContextID context,
2265 VABufferID *buffers,
2268 struct i965_driver_data *i965 = i965_driver_data(ctx);
2269 struct object_context *obj_context;
2270 struct object_config *obj_config;
2271 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2273 obj_context = CONTEXT(context);
2274 assert(obj_context);
2277 return VA_STATUS_ERROR_INVALID_CONTEXT;
2279 if (num_buffers <= 0)
2280 return VA_STATUS_ERROR_INVALID_PARAMETER;
2282 obj_config = obj_context->obj_config;
2285 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2286 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2287 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2288 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2290 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2297 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2299 struct i965_driver_data *i965 = i965_driver_data(ctx);
2300 struct object_context *obj_context = CONTEXT(context);
2301 struct object_config *obj_config;
2303 assert(obj_context);
2306 return VA_STATUS_ERROR_INVALID_CONTEXT;
2308 obj_config = obj_context->obj_config;
2311 if (obj_context->codec_type == CODEC_PROC) {
2312 assert(VAEntrypointVideoProc == obj_config->entrypoint);
2313 } else if (obj_context->codec_type == CODEC_ENC) {
2314 assert(VAEntrypointEncSlice == obj_config->entrypoint);
2316 if (!(obj_context->codec_state.encode.pic_param ||
2317 obj_context->codec_state.encode.pic_param_ext)) {
2318 return VA_STATUS_ERROR_INVALID_PARAMETER;
2320 if (!(obj_context->codec_state.encode.seq_param ||
2321 obj_context->codec_state.encode.seq_param_ext)) {
2322 return VA_STATUS_ERROR_INVALID_PARAMETER;
2324 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2325 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2326 return VA_STATUS_ERROR_INVALID_PARAMETER;
2329 if (obj_context->codec_state.decode.pic_param == NULL) {
2330 return VA_STATUS_ERROR_INVALID_PARAMETER;
2332 if (obj_context->codec_state.decode.num_slice_params <=0) {
2333 return VA_STATUS_ERROR_INVALID_PARAMETER;
2335 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2336 return VA_STATUS_ERROR_INVALID_PARAMETER;
2339 if (obj_context->codec_state.decode.num_slice_params !=
2340 obj_context->codec_state.decode.num_slice_datas) {
2341 return VA_STATUS_ERROR_INVALID_PARAMETER;
2345 assert(obj_context->hw_context->run);
2346 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2350 i965_SyncSurface(VADriverContextP ctx,
2351 VASurfaceID render_target)
2353 struct i965_driver_data *i965 = i965_driver_data(ctx);
2354 struct object_surface *obj_surface = SURFACE(render_target);
2356 assert(obj_surface);
2359 drm_intel_bo_wait_rendering(obj_surface->bo);
2361 return VA_STATUS_SUCCESS;
2365 i965_QuerySurfaceStatus(VADriverContextP ctx,
2366 VASurfaceID render_target,
2367 VASurfaceStatus *status) /* out */
2369 struct i965_driver_data *i965 = i965_driver_data(ctx);
2370 struct object_surface *obj_surface = SURFACE(render_target);
2372 assert(obj_surface);
2374 if (obj_surface->bo) {
2375 if (drm_intel_bo_busy(obj_surface->bo)){
2376 *status = VASurfaceRendering;
2379 *status = VASurfaceReady;
2382 *status = VASurfaceReady;
2385 return VA_STATUS_SUCCESS;
2388 static VADisplayAttribute *
2389 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2391 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2394 if (!i965->display_attributes)
2397 for (i = 0; i < i965->num_display_attributes; i++) {
2398 if (i965->display_attributes[i].type == type)
2399 return &i965->display_attributes[i];
2405 i965_display_attributes_terminate(VADriverContextP ctx)
2407 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2409 if (i965->display_attributes) {
2410 free(i965->display_attributes);
2411 i965->display_attributes = NULL;
2412 i965->num_display_attributes = 0;
2417 i965_display_attributes_init(VADriverContextP ctx)
2419 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2421 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2422 i965->display_attributes = malloc(
2423 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2424 if (!i965->display_attributes)
2428 i965->display_attributes,
2429 i965_display_attributes,
2430 sizeof(i965_display_attributes)
2433 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2434 if (!i965->rotation_attrib) {
2440 i965_display_attributes_terminate(ctx);
2445 * Query display attributes
2446 * The caller must provide a "attr_list" array that can hold at
2447 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2448 * returned in "attr_list" is returned in "num_attributes".
2451 i965_QueryDisplayAttributes(
2452 VADriverContextP ctx,
2453 VADisplayAttribute *attribs, /* out */
2454 int *num_attribs_ptr /* out */
2457 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2459 if (attribs && num_attribs > 0)
2460 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2462 if (num_attribs_ptr)
2463 *num_attribs_ptr = num_attribs;
2465 return VA_STATUS_SUCCESS;
2469 * Get display attributes
2470 * This function returns the current attribute values in "attr_list".
2471 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2472 * from vaQueryDisplayAttributes() can have their values retrieved.
2475 i965_GetDisplayAttributes(
2476 VADriverContextP ctx,
2477 VADisplayAttribute *attribs, /* inout */
2478 int num_attribs /* in */
2483 for (i = 0; i < num_attribs; i++) {
2484 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2486 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2487 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2488 dst_attrib->min_value = src_attrib->min_value;
2489 dst_attrib->max_value = src_attrib->max_value;
2490 dst_attrib->value = src_attrib->value;
2493 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2495 return VA_STATUS_SUCCESS;
2499 * Set display attributes
2500 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2501 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2502 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2505 i965_SetDisplayAttributes(
2506 VADriverContextP ctx,
2507 VADisplayAttribute *attribs, /* in */
2508 int num_attribs /* in */
2513 for (i = 0; i < num_attribs; i++) {
2514 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2516 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2518 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2520 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2523 if (src_attrib->value < dst_attrib->min_value ||
2524 src_attrib->value > dst_attrib->max_value)
2525 return VA_STATUS_ERROR_INVALID_PARAMETER;
2527 dst_attrib->value = src_attrib->value;
2528 /* XXX: track modified attributes through timestamps */
2530 return VA_STATUS_SUCCESS;
2534 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2535 VASurfaceID surface,
2536 void **buffer, /* out */
2537 unsigned int *stride) /* out */
2540 return VA_STATUS_ERROR_UNIMPLEMENTED;
2544 i965_destroy_heap(struct object_heap *heap,
2545 void (*func)(struct object_heap *heap, struct object_base *object))
2547 struct object_base *object;
2548 object_heap_iterator iter;
2550 object = object_heap_first(heap, &iter);
2556 object = object_heap_next(heap, &iter);
2559 object_heap_destroy(heap);
2564 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2567 i965_CreateImage(VADriverContextP ctx,
2568 VAImageFormat *format,
2571 VAImage *out_image) /* out */
2573 struct i965_driver_data *i965 = i965_driver_data(ctx);
2574 struct object_image *obj_image;
2575 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2577 unsigned int width2, height2, size2, size;
2579 out_image->image_id = VA_INVALID_ID;
2580 out_image->buf = VA_INVALID_ID;
2582 image_id = NEW_IMAGE_ID();
2583 if (image_id == VA_INVALID_ID)
2584 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2586 obj_image = IMAGE(image_id);
2588 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2589 obj_image->bo = NULL;
2590 obj_image->palette = NULL;
2591 obj_image->derived_surface = VA_INVALID_ID;
2593 VAImage * const image = &obj_image->image;
2594 image->image_id = image_id;
2595 image->buf = VA_INVALID_ID;
2597 size = width * height;
2598 width2 = (width + 1) / 2;
2599 height2 = (height + 1) / 2;
2600 size2 = width2 * height2;
2602 image->num_palette_entries = 0;
2603 image->entry_bytes = 0;
2604 memset(image->component_order, 0, sizeof(image->component_order));
2606 switch (format->fourcc) {
2607 case VA_FOURCC('I','A','4','4'):
2608 case VA_FOURCC('A','I','4','4'):
2609 image->num_planes = 1;
2610 image->pitches[0] = width;
2611 image->offsets[0] = 0;
2612 image->data_size = image->offsets[0] + image->pitches[0] * height;
2613 image->num_palette_entries = 16;
2614 image->entry_bytes = 3;
2615 image->component_order[0] = 'R';
2616 image->component_order[1] = 'G';
2617 image->component_order[2] = 'B';
2619 case VA_FOURCC('I','A','8','8'):
2620 case VA_FOURCC('A','I','8','8'):
2621 image->num_planes = 1;
2622 image->pitches[0] = width * 2;
2623 image->offsets[0] = 0;
2624 image->data_size = image->offsets[0] + image->pitches[0] * height;
2625 image->num_palette_entries = 256;
2626 image->entry_bytes = 3;
2627 image->component_order[0] = 'R';
2628 image->component_order[1] = 'G';
2629 image->component_order[2] = 'B';
2631 case VA_FOURCC('A','R','G','B'):
2632 case VA_FOURCC('A','B','G','R'):
2633 case VA_FOURCC('B','G','R','A'):
2634 case VA_FOURCC('R','G','B','A'):
2635 case VA_FOURCC('B','G','R','X'):
2636 case VA_FOURCC('R','G','B','X'):
2637 image->num_planes = 1;
2638 image->pitches[0] = width * 4;
2639 image->offsets[0] = 0;
2640 image->data_size = image->offsets[0] + image->pitches[0] * height;
2642 case VA_FOURCC('Y','V','1','2'):
2643 image->num_planes = 3;
2644 image->pitches[0] = width;
2645 image->offsets[0] = 0;
2646 image->pitches[1] = width2;
2647 image->offsets[1] = size + size2;
2648 image->pitches[2] = width2;
2649 image->offsets[2] = size;
2650 image->data_size = size + 2 * size2;
2652 case VA_FOURCC('I','4','2','0'):
2653 image->num_planes = 3;
2654 image->pitches[0] = width;
2655 image->offsets[0] = 0;
2656 image->pitches[1] = width2;
2657 image->offsets[1] = size;
2658 image->pitches[2] = width2;
2659 image->offsets[2] = size + size2;
2660 image->data_size = size + 2 * size2;
2662 case VA_FOURCC('N','V','1','2'):
2663 image->num_planes = 2;
2664 image->pitches[0] = width;
2665 image->offsets[0] = 0;
2666 image->pitches[1] = width;
2667 image->offsets[1] = size;
2668 image->data_size = size + 2 * size2;
2670 case VA_FOURCC('Y','U','Y','2'):
2671 case VA_FOURCC('U','Y','V','Y'):
2672 image->num_planes = 1;
2673 image->pitches[0] = width * 2;
2674 image->offsets[0] = 0;
2675 image->data_size = size * 2;
2681 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2682 image->data_size, 1, NULL, &image->buf);
2683 if (va_status != VA_STATUS_SUCCESS)
2686 struct object_buffer *obj_buffer = BUFFER(image->buf);
2689 !obj_buffer->buffer_store ||
2690 !obj_buffer->buffer_store->bo)
2691 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2693 obj_image->bo = obj_buffer->buffer_store->bo;
2694 dri_bo_reference(obj_image->bo);
2696 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2697 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2698 if (!obj_image->palette)
2702 image->image_id = image_id;
2703 image->format = *format;
2704 image->width = width;
2705 image->height = height;
2707 *out_image = *image;
2708 return VA_STATUS_SUCCESS;
2711 i965_DestroyImage(ctx, image_id);
2716 i965_check_alloc_surface_bo(VADriverContextP ctx,
2717 struct object_surface *obj_surface,
2719 unsigned int fourcc,
2720 unsigned int subsampling)
2722 struct i965_driver_data *i965 = i965_driver_data(ctx);
2723 int region_width, region_height;
2725 if (obj_surface->bo) {
2726 assert(obj_surface->fourcc);
2727 assert(obj_surface->fourcc == fourcc);
2728 assert(obj_surface->subsampling == subsampling);
2732 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2733 obj_surface->x_cr_offset = 0;
2736 assert(fourcc != VA_FOURCC('I', '4', '2', '0') &&
2737 fourcc != VA_FOURCC('I', 'Y', 'U', 'V') &&
2738 fourcc != VA_FOURCC('Y', 'V', '1', '2'));
2740 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2741 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2742 region_height = obj_surface->height;
2745 case VA_FOURCC('N', 'V', '1', '2'):
2746 assert(subsampling == SUBSAMPLE_YUV420);
2747 obj_surface->cb_cr_pitch = obj_surface->width;
2748 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2749 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2750 obj_surface->y_cb_offset = obj_surface->height;
2751 obj_surface->y_cr_offset = obj_surface->height;
2752 region_width = obj_surface->width;
2753 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2757 case VA_FOURCC('I', 'M', 'C', '1'):
2758 assert(subsampling == SUBSAMPLE_YUV420);
2759 obj_surface->cb_cr_pitch = obj_surface->width;
2760 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2761 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2762 obj_surface->y_cr_offset = obj_surface->height;
2763 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2764 region_width = obj_surface->width;
2765 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2769 case VA_FOURCC('I', 'M', 'C', '3'):
2770 assert(subsampling == SUBSAMPLE_YUV420);
2771 obj_surface->cb_cr_pitch = obj_surface->width;
2772 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2773 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2774 obj_surface->y_cb_offset = obj_surface->height;
2775 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2776 region_width = obj_surface->width;
2777 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2781 case VA_FOURCC('4', '2', '2', 'H'):
2782 assert(subsampling == SUBSAMPLE_YUV422H);
2783 obj_surface->cb_cr_pitch = obj_surface->width;
2784 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2785 obj_surface->cb_cr_height = obj_surface->orig_height;
2786 obj_surface->y_cb_offset = obj_surface->height;
2787 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2788 region_width = obj_surface->width;
2789 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2793 case VA_FOURCC('4', '2', '2', 'V'):
2794 assert(subsampling == SUBSAMPLE_YUV422V);
2795 obj_surface->cb_cr_pitch = obj_surface->width;
2796 obj_surface->cb_cr_width = obj_surface->orig_width;
2797 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2798 obj_surface->y_cb_offset = obj_surface->height;
2799 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2800 region_width = obj_surface->width;
2801 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2805 case VA_FOURCC('4', '1', '1', 'P'):
2806 assert(subsampling == SUBSAMPLE_YUV411);
2807 obj_surface->cb_cr_pitch = obj_surface->width;
2808 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2809 obj_surface->cb_cr_height = obj_surface->orig_height;
2810 obj_surface->y_cb_offset = obj_surface->height;
2811 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2812 region_width = obj_surface->width;
2813 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2817 case VA_FOURCC('4', '4', '4', 'P'):
2818 assert(subsampling == SUBSAMPLE_YUV444);
2819 obj_surface->cb_cr_pitch = obj_surface->width;
2820 obj_surface->cb_cr_width = obj_surface->orig_width;
2821 obj_surface->cb_cr_height = obj_surface->orig_height;
2822 obj_surface->y_cb_offset = obj_surface->height;
2823 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2824 region_width = obj_surface->width;
2825 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2829 case VA_FOURCC('Y', '8', '0', '0'):
2830 assert(subsampling == SUBSAMPLE_YUV400);
2831 obj_surface->cb_cr_pitch = obj_surface->width;
2832 obj_surface->cb_cr_width = 0;
2833 obj_surface->cb_cr_height = 0;
2834 obj_surface->y_cb_offset = obj_surface->height;
2835 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2836 region_width = obj_surface->width;
2837 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2841 case VA_FOURCC('Y', 'U', 'Y', '2'):
2842 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2843 assert(subsampling == SUBSAMPLE_YUV422H);
2844 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2845 obj_surface->y_cb_offset = 0;
2846 obj_surface->y_cr_offset = 0;
2847 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2848 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2849 region_width = obj_surface->width * 2;
2850 region_height = obj_surface->height;
2854 case VA_FOURCC('R', 'G', 'B', 'A'):
2855 case VA_FOURCC('R', 'G', 'B', 'X'):
2856 case VA_FOURCC('B', 'G', 'R', 'A'):
2857 case VA_FOURCC('B', 'G', 'R', 'X'):
2858 assert(subsampling == SUBSAMPLE_RGBX);
2860 region_width = obj_surface->width * 4;
2861 region_height = obj_surface->height;
2865 /* Never get here */
2870 assert(subsampling == SUBSAMPLE_YUV420 ||
2871 subsampling == SUBSAMPLE_YUV422H ||
2872 subsampling == SUBSAMPLE_YUV422V ||
2873 subsampling == SUBSAMPLE_RGBX);
2875 region_width = obj_surface->width;
2876 region_height = obj_surface->height;
2879 case VA_FOURCC('N', 'V', '1', '2'):
2880 obj_surface->y_cb_offset = obj_surface->height;
2881 obj_surface->y_cr_offset = obj_surface->height;
2882 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2883 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2884 obj_surface->cb_cr_pitch = obj_surface->width;
2885 region_height = obj_surface->height + obj_surface->height / 2;
2888 case VA_FOURCC('Y', 'V', '1', '2'):
2889 case VA_FOURCC('I', '4', '2', '0'):
2890 if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
2891 obj_surface->y_cr_offset = obj_surface->height;
2892 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
2894 obj_surface->y_cb_offset = obj_surface->height;
2895 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
2898 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2899 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2900 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2901 region_height = obj_surface->height + obj_surface->height / 2;
2904 case VA_FOURCC('Y', 'U', 'Y', '2'):
2905 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2906 obj_surface->y_cb_offset = 0;
2907 obj_surface->y_cr_offset = 0;
2908 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2909 obj_surface->cb_cr_height = obj_surface->orig_height;
2910 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2911 region_width = obj_surface->width * 2;
2912 region_height = obj_surface->height;
2914 case VA_FOURCC('R', 'G', 'B', 'A'):
2915 case VA_FOURCC('R', 'G', 'B', 'X'):
2916 case VA_FOURCC('B', 'G', 'R', 'A'):
2917 case VA_FOURCC('B', 'G', 'R', 'X'):
2918 region_width = obj_surface->width * 4;
2919 region_height = obj_surface->height;
2923 /* Never get here */
2929 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
2932 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
2933 unsigned long pitch;
2935 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
2943 assert(tiling_mode == I915_TILING_Y);
2944 assert(pitch == obj_surface->width ||
2945 pitch == obj_surface->width * 2 ||
2946 pitch == obj_surface->width * 4) ;
2948 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
2954 obj_surface->fourcc = fourcc;
2955 obj_surface->subsampling = subsampling;
2956 assert(obj_surface->bo);
2959 VAStatus i965_DeriveImage(VADriverContextP ctx,
2960 VASurfaceID surface,
2961 VAImage *out_image) /* out */
2963 struct i965_driver_data *i965 = i965_driver_data(ctx);
2964 struct object_image *obj_image;
2965 struct object_surface *obj_surface;
2967 unsigned int w_pitch;
2968 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2970 out_image->image_id = VA_INVALID_ID;
2971 obj_surface = SURFACE(surface);
2974 return VA_STATUS_ERROR_INVALID_SURFACE;
2976 if (!obj_surface->bo) {
2977 unsigned int is_tiled = 0;
2978 unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
2979 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
2980 int sampling = get_sampling_from_fourcc(fourcc);
2981 i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
2984 assert(obj_surface->fourcc);
2986 w_pitch = obj_surface->width;
2988 image_id = NEW_IMAGE_ID();
2990 if (image_id == VA_INVALID_ID)
2991 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2993 obj_image = IMAGE(image_id);
2996 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2998 obj_image->bo = NULL;
2999 obj_image->palette = NULL;
3000 obj_image->derived_surface = VA_INVALID_ID;
3002 VAImage * const image = &obj_image->image;
3004 memset(image, 0, sizeof(*image));
3005 image->image_id = image_id;
3006 image->buf = VA_INVALID_ID;
3007 image->num_palette_entries = 0;
3008 image->entry_bytes = 0;
3009 image->width = obj_surface->orig_width;
3010 image->height = obj_surface->orig_height;
3011 image->data_size = obj_surface->size;
3013 image->format.fourcc = obj_surface->fourcc;
3014 image->format.byte_order = VA_LSB_FIRST;
3015 image->format.bits_per_pixel = 12;
3017 switch (image->format.fourcc) {
3018 case VA_FOURCC('Y', 'V', '1', '2'):
3019 image->num_planes = 3;
3020 image->pitches[0] = w_pitch; /* Y */
3021 image->offsets[0] = 0;
3022 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3023 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3024 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3025 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3028 case VA_FOURCC('N', 'V', '1', '2'):
3029 image->num_planes = 2;
3030 image->pitches[0] = w_pitch; /* Y */
3031 image->offsets[0] = 0;
3032 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3033 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3036 case VA_FOURCC('I', '4', '2', '0'):
3037 image->num_planes = 3;
3038 image->pitches[0] = w_pitch; /* Y */
3039 image->offsets[0] = 0;
3040 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3041 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3042 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3043 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3045 case VA_FOURCC('Y', 'U', 'Y', '2'):
3046 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3047 image->num_planes = 1;
3048 image->pitches[0] = obj_surface->width * 2; /* Y, width is aligned already */
3049 image->offsets[0] = 0;
3051 case VA_FOURCC('R', 'G', 'B', 'A'):
3052 case VA_FOURCC('R', 'G', 'B', 'X'):
3053 case VA_FOURCC('B', 'G', 'R', 'A'):
3054 case VA_FOURCC('B', 'G', 'R', 'X'):
3055 image->num_planes = 1;
3056 image->pitches[0] = obj_surface->width * 4;
3062 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3063 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3064 if (va_status != VA_STATUS_SUCCESS)
3067 struct object_buffer *obj_buffer = BUFFER(image->buf);
3070 !obj_buffer->buffer_store ||
3071 !obj_buffer->buffer_store->bo)
3072 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3074 obj_image->bo = obj_buffer->buffer_store->bo;
3075 dri_bo_reference(obj_image->bo);
3077 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3078 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3079 if (!obj_image->palette) {
3080 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3085 *out_image = *image;
3086 obj_surface->flags |= SURFACE_DERIVED;
3087 obj_image->derived_surface = surface;
3089 return VA_STATUS_SUCCESS;
3092 i965_DestroyImage(ctx, image_id);
3097 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3099 object_heap_free(heap, obj);
3104 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3106 struct i965_driver_data *i965 = i965_driver_data(ctx);
3107 struct object_image *obj_image = IMAGE(image);
3108 struct object_surface *obj_surface;
3111 return VA_STATUS_SUCCESS;
3113 dri_bo_unreference(obj_image->bo);
3114 obj_image->bo = NULL;
3116 if (obj_image->image.buf != VA_INVALID_ID) {
3117 i965_DestroyBuffer(ctx, obj_image->image.buf);
3118 obj_image->image.buf = VA_INVALID_ID;
3121 if (obj_image->palette) {
3122 free(obj_image->palette);
3123 obj_image->palette = NULL;
3126 obj_surface = SURFACE(obj_image->derived_surface);
3129 obj_surface->flags &= ~SURFACE_DERIVED;
3132 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3134 return VA_STATUS_SUCCESS;
3138 * pointer to an array holding the palette data. The size of the array is
3139 * num_palette_entries * entry_bytes in size. The order of the components
3140 * in the palette is described by the component_order in VASubpicture struct
3143 i965_SetImagePalette(VADriverContextP ctx,
3145 unsigned char *palette)
3147 struct i965_driver_data *i965 = i965_driver_data(ctx);
3150 struct object_image *obj_image = IMAGE(image);
3152 return VA_STATUS_ERROR_INVALID_IMAGE;
3154 if (!obj_image->palette)
3155 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3157 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3158 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3159 ((unsigned int)palette[3*i + 1] << 8) |
3160 (unsigned int)palette[3*i + 2]);
3161 return VA_STATUS_SUCCESS;
3165 get_sampling_from_fourcc(unsigned int fourcc)
3167 int surface_sampling = -1;
3170 case VA_FOURCC('N', 'V', '1', '2'):
3171 case VA_FOURCC('Y', 'V', '1', '2'):
3172 case VA_FOURCC('I', '4', '2', '0'):
3173 case VA_FOURCC('I', 'Y', 'U', 'V'):
3174 case VA_FOURCC('I', 'M', 'C', '1'):
3175 case VA_FOURCC('I', 'M', 'C', '3'):
3176 surface_sampling = SUBSAMPLE_YUV420;
3178 case VA_FOURCC('Y', 'U', 'Y', '2'):
3179 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3180 case VA_FOURCC('4', '2', '2', 'H'):
3181 surface_sampling = SUBSAMPLE_YUV422H;
3183 case VA_FOURCC('4', '2', '2', 'V'):
3184 surface_sampling = SUBSAMPLE_YUV422V;
3187 case VA_FOURCC('4', '4', '4', 'P'):
3188 surface_sampling = SUBSAMPLE_YUV444;
3191 case VA_FOURCC('4', '1', '1', 'P'):
3192 surface_sampling = SUBSAMPLE_YUV411;
3195 case VA_FOURCC('Y', '8', '0', '0'):
3196 surface_sampling = SUBSAMPLE_YUV400;
3198 case VA_FOURCC('R','G','B','A'):
3199 case VA_FOURCC('R','G','B','X'):
3200 case VA_FOURCC('B','G','R','A'):
3201 case VA_FOURCC('B','G','R','X'):
3202 surface_sampling = SUBSAMPLE_RGBX;
3205 /* Never get here */
3211 return surface_sampling;
3215 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3216 const uint8_t *src, unsigned int src_stride,
3217 unsigned int len, unsigned int height)
3221 for (i = 0; i < height; i++) {
3222 memcpy(dst, src, len);
3229 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3230 struct object_surface *obj_surface,
3231 const VARectangle *rect)
3233 uint8_t *dst[3], *src[3];
3235 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3236 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3237 unsigned int tiling, swizzle;
3239 if (!obj_surface->bo)
3242 assert(obj_surface->fourcc);
3243 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3245 if (tiling != I915_TILING_NONE)
3246 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3248 dri_bo_map(obj_surface->bo, 0);
3250 if (!obj_surface->bo->virtual)
3253 /* Dest VA image has either I420 or YV12 format.
3254 Source VA surface alway has I420 format */
3255 dst[Y] = image_data + obj_image->image.offsets[Y];
3256 src[0] = (uint8_t *)obj_surface->bo->virtual;
3257 dst[U] = image_data + obj_image->image.offsets[U];
3258 src[1] = src[0] + obj_surface->width * obj_surface->height;
3259 dst[V] = image_data + obj_image->image.offsets[V];
3260 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3263 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3264 src[0] += rect->y * obj_surface->width + rect->x;
3265 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3266 src[0], obj_surface->width,
3267 rect->width, rect->height);
3270 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3271 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3272 memcpy_pic(dst[U], obj_image->image.pitches[U],
3273 src[1], obj_surface->width / 2,
3274 rect->width / 2, rect->height / 2);
3277 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3278 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3279 memcpy_pic(dst[V], obj_image->image.pitches[V],
3280 src[2], obj_surface->width / 2,
3281 rect->width / 2, rect->height / 2);
3283 if (tiling != I915_TILING_NONE)
3284 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3286 dri_bo_unmap(obj_surface->bo);
3290 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3291 struct object_surface *obj_surface,
3292 const VARectangle *rect)
3294 uint8_t *dst[2], *src[2];
3295 unsigned int tiling, swizzle;
3297 if (!obj_surface->bo)
3300 assert(obj_surface->fourcc);
3301 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3303 if (tiling != I915_TILING_NONE)
3304 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3306 dri_bo_map(obj_surface->bo, 0);
3308 if (!obj_surface->bo->virtual)
3311 /* Both dest VA image and source surface have NV12 format */
3312 dst[0] = image_data + obj_image->image.offsets[0];
3313 src[0] = (uint8_t *)obj_surface->bo->virtual;
3314 dst[1] = image_data + obj_image->image.offsets[1];
3315 src[1] = src[0] + obj_surface->width * obj_surface->height;
3318 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3319 src[0] += rect->y * obj_surface->width + rect->x;
3320 memcpy_pic(dst[0], obj_image->image.pitches[0],
3321 src[0], obj_surface->width,
3322 rect->width, rect->height);
3325 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3326 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3327 memcpy_pic(dst[1], obj_image->image.pitches[1],
3328 src[1], obj_surface->width,
3329 rect->width, rect->height / 2);
3331 if (tiling != I915_TILING_NONE)
3332 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3334 dri_bo_unmap(obj_surface->bo);
3338 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3339 struct object_surface *obj_surface,
3340 const VARectangle *rect)
3343 unsigned int tiling, swizzle;
3345 if (!obj_surface->bo)
3348 assert(obj_surface->fourcc);
3349 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3351 if (tiling != I915_TILING_NONE)
3352 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3354 dri_bo_map(obj_surface->bo, 0);
3356 if (!obj_surface->bo->virtual)
3359 /* Both dest VA image and source surface have YUYV format */
3360 dst = image_data + obj_image->image.offsets[0];
3361 src = (uint8_t *)obj_surface->bo->virtual;
3364 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3365 src += rect->y * obj_surface->width + rect->x*2;
3366 memcpy_pic(dst, obj_image->image.pitches[0],
3367 src, obj_surface->width*2,
3368 rect->width*2, rect->height);
3370 if (tiling != I915_TILING_NONE)
3371 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3373 dri_bo_unmap(obj_surface->bo);
3377 i965_sw_getimage(VADriverContextP ctx,
3378 VASurfaceID surface,
3379 int x, /* coordinates of the upper left source pixel */
3381 unsigned int width, /* width and height of the region */
3382 unsigned int height,
3385 struct i965_driver_data *i965 = i965_driver_data(ctx);
3386 struct i965_render_state *render_state = &i965->render_state;
3388 struct object_surface *obj_surface = SURFACE(surface);
3390 return VA_STATUS_ERROR_INVALID_SURFACE;
3392 struct object_image *obj_image = IMAGE(image);
3394 return VA_STATUS_ERROR_INVALID_IMAGE;
3397 return VA_STATUS_ERROR_INVALID_PARAMETER;
3398 if (x + width > obj_surface->orig_width ||
3399 y + height > obj_surface->orig_height)
3400 return VA_STATUS_ERROR_INVALID_PARAMETER;
3401 if (x + width > obj_image->image.width ||
3402 y + height > obj_image->image.height)
3403 return VA_STATUS_ERROR_INVALID_PARAMETER;
3405 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3406 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3409 void *image_data = NULL;
3411 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3412 if (va_status != VA_STATUS_SUCCESS)
3419 rect.height = height;
3421 switch (obj_image->image.format.fourcc) {
3422 case VA_FOURCC('Y','V','1','2'):
3423 case VA_FOURCC('I','4','2','0'):
3424 /* I420 is native format for MPEG-2 decoded surfaces */
3425 if (render_state->interleaved_uv)
3426 goto operation_failed;
3427 get_image_i420(obj_image, image_data, obj_surface, &rect);
3429 case VA_FOURCC('N','V','1','2'):
3430 /* NV12 is native format for H.264 decoded surfaces */
3431 if (!render_state->interleaved_uv)
3432 goto operation_failed;
3433 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3435 case VA_FOURCC('Y','U','Y','2'):
3436 /* YUY2 is the format supported by overlay plane */
3437 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3441 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3445 i965_UnmapBuffer(ctx, obj_image->image.buf);
3450 i965_hw_getimage(VADriverContextP ctx,
3451 VASurfaceID surface,
3452 int x, /* coordinates of the upper left source pixel */
3454 unsigned int width, /* width and height of the region */
3455 unsigned int height,
3458 struct i965_driver_data *i965 = i965_driver_data(ctx);
3459 struct i965_surface src_surface;
3460 struct i965_surface dst_surface;
3463 struct object_surface *obj_surface = SURFACE(surface);
3464 struct object_image *obj_image = IMAGE(image);
3467 return VA_STATUS_ERROR_INVALID_SURFACE;
3470 return VA_STATUS_ERROR_INVALID_IMAGE;
3473 return VA_STATUS_ERROR_INVALID_PARAMETER;
3474 if (x + width > obj_surface->orig_width ||
3475 y + height > obj_surface->orig_height)
3476 return VA_STATUS_ERROR_INVALID_PARAMETER;
3477 if (x + width > obj_image->image.width ||
3478 y + height > obj_image->image.height)
3479 return VA_STATUS_ERROR_INVALID_PARAMETER;
3481 if (!obj_surface->bo)
3482 return VA_STATUS_SUCCESS;
3483 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3488 rect.height = height;
3490 src_surface.base = (struct object_base *)obj_surface;
3491 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3492 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3494 dst_surface.base = (struct object_base *)obj_image;
3495 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3496 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3498 va_status = i965_image_processing(ctx,
3509 i965_GetImage(VADriverContextP ctx,
3510 VASurfaceID surface,
3511 int x, /* coordinates of the upper left source pixel */
3513 unsigned int width, /* width and height of the region */
3514 unsigned int height,
3517 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3520 if (HAS_ACCELERATED_GETIMAGE(i965))
3521 va_status = i965_hw_getimage(ctx,
3527 va_status = i965_sw_getimage(ctx,
3537 put_image_i420(struct object_surface *obj_surface,
3538 const VARectangle *dst_rect,
3539 struct object_image *obj_image, uint8_t *image_data,
3540 const VARectangle *src_rect)
3542 uint8_t *dst[3], *src[3];
3544 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3545 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3546 unsigned int tiling, swizzle;
3548 if (!obj_surface->bo)
3551 assert(obj_surface->fourcc);
3552 assert(dst_rect->width == src_rect->width);
3553 assert(dst_rect->height == src_rect->height);
3554 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3556 if (tiling != I915_TILING_NONE)
3557 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3559 dri_bo_map(obj_surface->bo, 0);
3561 if (!obj_surface->bo->virtual)
3564 /* Dest VA image has either I420 or YV12 format.
3565 Source VA surface alway has I420 format */
3566 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3567 src[Y] = image_data + obj_image->image.offsets[Y];
3568 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3569 src[U] = image_data + obj_image->image.offsets[U];
3570 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3571 src[V] = image_data + obj_image->image.offsets[V];
3574 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3575 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3576 memcpy_pic(dst[0], obj_surface->width,
3577 src[Y], obj_image->image.pitches[Y],
3578 src_rect->width, src_rect->height);
3581 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3582 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3583 memcpy_pic(dst[1], obj_surface->width / 2,
3584 src[U], obj_image->image.pitches[U],
3585 src_rect->width / 2, src_rect->height / 2);
3588 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3589 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3590 memcpy_pic(dst[2], obj_surface->width / 2,
3591 src[V], obj_image->image.pitches[V],
3592 src_rect->width / 2, src_rect->height / 2);
3594 if (tiling != I915_TILING_NONE)
3595 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3597 dri_bo_unmap(obj_surface->bo);
3601 put_image_nv12(struct object_surface *obj_surface,
3602 const VARectangle *dst_rect,
3603 struct object_image *obj_image, uint8_t *image_data,
3604 const VARectangle *src_rect)
3606 uint8_t *dst[2], *src[2];
3607 unsigned int tiling, swizzle;
3609 if (!obj_surface->bo)
3612 assert(obj_surface->fourcc);
3613 assert(dst_rect->width == src_rect->width);
3614 assert(dst_rect->height == src_rect->height);
3615 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3617 if (tiling != I915_TILING_NONE)
3618 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3620 dri_bo_map(obj_surface->bo, 0);
3622 if (!obj_surface->bo->virtual)
3625 /* Both dest VA image and source surface have NV12 format */
3626 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3627 src[0] = image_data + obj_image->image.offsets[0];
3628 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3629 src[1] = image_data + obj_image->image.offsets[1];
3632 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3633 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3634 memcpy_pic(dst[0], obj_surface->width,
3635 src[0], obj_image->image.pitches[0],
3636 src_rect->width, src_rect->height);
3639 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3640 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3641 memcpy_pic(dst[1], obj_surface->width,
3642 src[1], obj_image->image.pitches[1],
3643 src_rect->width, src_rect->height / 2);
3645 if (tiling != I915_TILING_NONE)
3646 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3648 dri_bo_unmap(obj_surface->bo);
3652 put_image_yuy2(struct object_surface *obj_surface,
3653 const VARectangle *dst_rect,
3654 struct object_image *obj_image, uint8_t *image_data,
3655 const VARectangle *src_rect)
3658 unsigned int tiling, swizzle;
3660 if (!obj_surface->bo)
3663 assert(obj_surface->fourcc);
3664 assert(dst_rect->width == src_rect->width);
3665 assert(dst_rect->height == src_rect->height);
3666 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3668 if (tiling != I915_TILING_NONE)
3669 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3671 dri_bo_map(obj_surface->bo, 0);
3673 if (!obj_surface->bo->virtual)
3676 /* Both dest VA image and source surface have YUY2 format */
3677 dst = (uint8_t *)obj_surface->bo->virtual;
3678 src = image_data + obj_image->image.offsets[0];
3680 /* YUYV packed plane */
3681 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3682 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3683 memcpy_pic(dst, obj_surface->width*2,
3684 src, obj_image->image.pitches[0],
3685 src_rect->width*2, src_rect->height);
3687 if (tiling != I915_TILING_NONE)
3688 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3690 dri_bo_unmap(obj_surface->bo);
3695 i965_sw_putimage(VADriverContextP ctx,
3696 VASurfaceID surface,
3700 unsigned int src_width,
3701 unsigned int src_height,
3704 unsigned int dest_width,
3705 unsigned int dest_height)
3707 struct i965_driver_data *i965 = i965_driver_data(ctx);
3708 struct object_surface *obj_surface = SURFACE(surface);
3711 return VA_STATUS_ERROR_INVALID_SURFACE;
3713 struct object_image *obj_image = IMAGE(image);
3715 return VA_STATUS_ERROR_INVALID_IMAGE;
3717 if (src_x < 0 || src_y < 0)
3718 return VA_STATUS_ERROR_INVALID_PARAMETER;
3719 if (src_x + src_width > obj_image->image.width ||
3720 src_y + src_height > obj_image->image.height)
3721 return VA_STATUS_ERROR_INVALID_PARAMETER;
3722 if (dest_x < 0 || dest_y < 0)
3723 return VA_STATUS_ERROR_INVALID_PARAMETER;
3724 if (dest_x + dest_width > obj_surface->orig_width ||
3725 dest_y + dest_height > obj_surface->orig_height)
3726 return VA_STATUS_ERROR_INVALID_PARAMETER;
3728 /* XXX: don't allow scaling */
3729 if (src_width != dest_width || src_height != dest_height)
3730 return VA_STATUS_ERROR_INVALID_PARAMETER;
3732 if (obj_surface->fourcc) {
3733 /* Don't allow format mismatch */
3734 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3735 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3739 /* VA is surface not used for decoding, use same VA image format */
3740 i965_check_alloc_surface_bo(
3743 0, /* XXX: don't use tiled surface */
3744 obj_image->image.format.fourcc,
3745 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3749 void *image_data = NULL;
3751 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3752 if (va_status != VA_STATUS_SUCCESS)
3755 VARectangle src_rect, dest_rect;
3758 src_rect.width = src_width;
3759 src_rect.height = src_height;
3760 dest_rect.x = dest_x;
3761 dest_rect.y = dest_y;
3762 dest_rect.width = dest_width;
3763 dest_rect.height = dest_height;
3765 switch (obj_image->image.format.fourcc) {
3766 case VA_FOURCC('Y','V','1','2'):
3767 case VA_FOURCC('I','4','2','0'):
3768 put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3770 case VA_FOURCC('N','V','1','2'):
3771 put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3773 case VA_FOURCC('Y','U','Y','2'):
3774 put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3777 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3781 i965_UnmapBuffer(ctx, obj_image->image.buf);
3786 i965_hw_putimage(VADriverContextP ctx,
3787 VASurfaceID surface,
3791 unsigned int src_width,
3792 unsigned int src_height,
3795 unsigned int dest_width,
3796 unsigned int dest_height)
3798 struct i965_driver_data *i965 = i965_driver_data(ctx);
3799 struct object_surface *obj_surface = SURFACE(surface);
3800 struct object_image *obj_image = IMAGE(image);
3801 struct i965_surface src_surface, dst_surface;
3802 VAStatus va_status = VA_STATUS_SUCCESS;
3803 VARectangle src_rect, dst_rect;
3806 return VA_STATUS_ERROR_INVALID_SURFACE;
3808 if (!obj_image || !obj_image->bo)
3809 return VA_STATUS_ERROR_INVALID_IMAGE;
3813 src_x + src_width > obj_image->image.width ||
3814 src_y + src_height > obj_image->image.height)
3815 return VA_STATUS_ERROR_INVALID_PARAMETER;
3819 dest_x + dest_width > obj_surface->orig_width ||
3820 dest_y + dest_height > obj_surface->orig_height)
3821 return VA_STATUS_ERROR_INVALID_PARAMETER;
3823 if (!obj_surface->bo) {
3824 unsigned int tiling, swizzle;
3825 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3826 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3828 i965_check_alloc_surface_bo(ctx,
3831 obj_image->image.format.fourcc,
3835 assert(obj_surface->fourcc);
3837 src_surface.base = (struct object_base *)obj_image;
3838 src_surface.type = I965_SURFACE_TYPE_IMAGE;
3839 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3842 src_rect.width = src_width;
3843 src_rect.height = src_height;
3845 dst_surface.base = (struct object_base *)obj_surface;
3846 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3847 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3848 dst_rect.x = dest_x;
3849 dst_rect.y = dest_y;
3850 dst_rect.width = dest_width;
3851 dst_rect.height = dest_height;
3853 va_status = i965_image_processing(ctx,
3863 i965_PutImage(VADriverContextP ctx,
3864 VASurfaceID surface,
3868 unsigned int src_width,
3869 unsigned int src_height,
3872 unsigned int dest_width,
3873 unsigned int dest_height)
3875 struct i965_driver_data *i965 = i965_driver_data(ctx);
3876 VAStatus va_status = VA_STATUS_SUCCESS;
3878 if (HAS_ACCELERATED_PUTIMAGE(i965))
3879 va_status = i965_hw_putimage(ctx,
3891 va_status = i965_sw_putimage(ctx,
3907 i965_PutSurface(VADriverContextP ctx,
3908 VASurfaceID surface,
3909 void *draw, /* X Drawable */
3912 unsigned short srcw,
3913 unsigned short srch,
3916 unsigned short destw,
3917 unsigned short desth,
3918 VARectangle *cliprects, /* client supplied clip list */
3919 unsigned int number_cliprects, /* number of clip rects in the clip list */
3920 unsigned int flags) /* de-interlacing flags */
3923 if (IS_VA_X11(ctx)) {
3924 VARectangle src_rect, dst_rect;
3928 src_rect.width = srcw;
3929 src_rect.height = srch;
3933 dst_rect.width = destw;
3934 dst_rect.height = desth;
3936 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
3937 cliprects, number_cliprects, flags);
3940 return VA_STATUS_ERROR_UNIMPLEMENTED;
3945 VADriverContextP ctx, /* in */
3946 VABufferID buf_id, /* in */
3947 VABufferType *type, /* out */
3948 unsigned int *size, /* out */
3949 unsigned int *num_elements /* out */
3952 struct i965_driver_data *i965 = NULL;
3953 struct object_buffer *obj_buffer = NULL;
3955 i965 = i965_driver_data(ctx);
3956 obj_buffer = BUFFER(buf_id);
3961 return VA_STATUS_ERROR_INVALID_BUFFER;
3963 *type = obj_buffer->type;
3964 *size = obj_buffer->size_element;
3965 *num_elements = obj_buffer->num_elements;
3967 return VA_STATUS_SUCCESS;
3972 VADriverContextP ctx, /* in */
3973 VASurfaceID surface, /* in */
3974 unsigned int *fourcc, /* out */
3975 unsigned int *luma_stride, /* out */
3976 unsigned int *chroma_u_stride, /* out */
3977 unsigned int *chroma_v_stride, /* out */
3978 unsigned int *luma_offset, /* out */
3979 unsigned int *chroma_u_offset, /* out */
3980 unsigned int *chroma_v_offset, /* out */
3981 unsigned int *buffer_name, /* out */
3982 void **buffer /* out */
3985 VAStatus vaStatus = VA_STATUS_SUCCESS;
3986 struct i965_driver_data *i965 = i965_driver_data(ctx);
3987 struct object_surface *obj_surface = NULL;
3991 assert(luma_stride);
3992 assert(chroma_u_stride);
3993 assert(chroma_v_stride);
3994 assert(luma_offset);
3995 assert(chroma_u_offset);
3996 assert(chroma_v_offset);
3997 assert(buffer_name);
4000 tmpImage.image_id = VA_INVALID_ID;
4002 obj_surface = SURFACE(surface);
4003 if (obj_surface == NULL) {
4004 // Surface is absent.
4005 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4009 // Lock functionality is absent now.
4010 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4011 // Surface is locked already.
4012 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4016 vaStatus = i965_DeriveImage(
4020 if (vaStatus != VA_STATUS_SUCCESS) {
4024 obj_surface->locked_image_id = tmpImage.image_id;
4026 vaStatus = i965_MapBuffer(
4030 if (vaStatus != VA_STATUS_SUCCESS) {
4034 *fourcc = tmpImage.format.fourcc;
4035 *luma_offset = tmpImage.offsets[0];
4036 *luma_stride = tmpImage.pitches[0];
4037 *chroma_u_offset = tmpImage.offsets[1];
4038 *chroma_u_stride = tmpImage.pitches[1];
4039 *chroma_v_offset = tmpImage.offsets[2];
4040 *chroma_v_stride = tmpImage.pitches[2];
4041 *buffer_name = tmpImage.buf;
4044 if (vaStatus != VA_STATUS_SUCCESS) {
4053 VADriverContextP ctx, /* in */
4054 VASurfaceID surface /* in */
4057 VAStatus vaStatus = VA_STATUS_SUCCESS;
4058 struct i965_driver_data *i965 = i965_driver_data(ctx);
4059 struct object_image *locked_img = NULL;
4060 struct object_surface *obj_surface = NULL;
4062 obj_surface = SURFACE(surface);
4064 if (obj_surface == NULL) {
4065 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4068 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4069 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4073 locked_img = IMAGE(obj_surface->locked_image_id);
4074 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4075 // Work image was deallocated before i965_UnlockSurface()
4076 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4080 vaStatus = i965_UnmapBuffer(
4082 locked_img->image.buf);
4083 if (vaStatus != VA_STATUS_SUCCESS) {
4087 vaStatus = i965_DestroyImage(
4089 locked_img->image.image_id);
4090 if (vaStatus != VA_STATUS_SUCCESS) {
4094 locked_img->image.image_id = VA_INVALID_ID;
4097 obj_surface->locked_image_id = VA_INVALID_ID;
4103 i965_GetSurfaceAttributes(
4104 VADriverContextP ctx,
4106 VASurfaceAttrib *attrib_list,
4107 unsigned int num_attribs
4110 VAStatus vaStatus = VA_STATUS_SUCCESS;
4111 struct i965_driver_data *i965 = i965_driver_data(ctx);
4112 struct object_config *obj_config;
4115 if (config == VA_INVALID_ID)
4116 return VA_STATUS_ERROR_INVALID_CONFIG;
4118 obj_config = CONFIG(config);
4120 if (obj_config == NULL)
4121 return VA_STATUS_ERROR_INVALID_CONFIG;
4123 if (attrib_list == NULL || num_attribs == 0)
4124 return VA_STATUS_ERROR_INVALID_PARAMETER;
4126 for (i = 0; i < num_attribs; i++) {
4127 switch (attrib_list[i].type) {
4128 case VASurfaceAttribPixelFormat:
4129 attrib_list[i].value.type = VAGenericValueTypeInteger;
4130 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4132 if (attrib_list[i].value.value.i == 0) {
4133 if (IS_G4X(i965->intel.device_id)) {
4134 if (obj_config->profile == VAProfileMPEG2Simple ||
4135 obj_config->profile == VAProfileMPEG2Main) {
4136 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4139 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4141 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4142 if (obj_config->profile == VAProfileMPEG2Simple ||
4143 obj_config->profile == VAProfileMPEG2Main) {
4144 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4145 } else if (obj_config->profile == VAProfileH264Baseline ||
4146 obj_config->profile == VAProfileH264Main ||
4147 obj_config->profile == VAProfileH264High) {
4148 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4149 } else if (obj_config->profile == VAProfileNone) {
4150 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4153 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4155 } else if (IS_GEN6(i965->intel.device_id)) {
4156 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4157 } else if (IS_GEN7(i965->intel.device_id)) {
4158 if (obj_config->profile == VAProfileJPEGBaseline)
4159 attrib_list[i].value.value.i = 0; /* internal format */
4161 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4164 if (IS_G4X(i965->intel.device_id)) {
4165 if (obj_config->profile == VAProfileMPEG2Simple ||
4166 obj_config->profile == VAProfileMPEG2Main) {
4167 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4168 attrib_list[i].value.value.i = 0;
4169 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4173 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4175 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4176 if (obj_config->profile == VAProfileMPEG2Simple ||
4177 obj_config->profile == VAProfileMPEG2Main) {
4178 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4179 attrib_list[i].value.value.i = 0;
4180 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4182 } else if (obj_config->profile == VAProfileH264Baseline ||
4183 obj_config->profile == VAProfileH264Main ||
4184 obj_config->profile == VAProfileH264High) {
4185 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4186 attrib_list[i].value.value.i = 0;
4187 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4189 } else if (obj_config->profile == VAProfileNone) {
4190 switch (attrib_list[i].value.value.i) {
4191 case VA_FOURCC('N', 'V', '1', '2'):
4192 case VA_FOURCC('I', '4', '2', '0'):
4193 case VA_FOURCC('Y', 'V', '1', '2'):
4194 case VA_FOURCC('Y', 'U', 'Y', '2'):
4195 case VA_FOURCC('B', 'G', 'R', 'A'):
4196 case VA_FOURCC('B', 'G', 'R', 'X'):
4197 case VA_FOURCC('R', 'G', 'B', 'X'):
4198 case VA_FOURCC('R', 'G', 'B', 'A'):
4201 attrib_list[i].value.value.i = 0;
4202 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4207 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4209 } else if (IS_GEN6(i965->intel.device_id)) {
4210 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4211 obj_config->entrypoint == VAEntrypointVideoProc) {
4212 switch (attrib_list[i].value.value.i) {
4213 case VA_FOURCC('N', 'V', '1', '2'):
4214 case VA_FOURCC('I', '4', '2', '0'):
4215 case VA_FOURCC('Y', 'V', '1', '2'):
4216 case VA_FOURCC('Y', 'U', 'Y', '2'):
4217 case VA_FOURCC('B', 'G', 'R', 'A'):
4218 case VA_FOURCC('B', 'G', 'R', 'X'):
4219 case VA_FOURCC('R', 'G', 'B', 'X'):
4220 case VA_FOURCC('R', 'G', 'B', 'A'):
4223 attrib_list[i].value.value.i = 0;
4224 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4228 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4229 attrib_list[i].value.value.i = 0;
4230 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4233 } else if (IS_GEN7(i965->intel.device_id)) {
4234 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4235 obj_config->entrypoint == VAEntrypointVideoProc) {
4236 switch (attrib_list[i].value.value.i) {
4237 case VA_FOURCC('N', 'V', '1', '2'):
4238 case VA_FOURCC('I', '4', '2', '0'):
4239 case VA_FOURCC('Y', 'V', '1', '2'):
4242 attrib_list[i].value.value.i = 0;
4243 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4247 if (obj_config->profile == VAProfileJPEGBaseline) {
4248 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4249 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4251 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4252 attrib_list[i].value.value.i = 0;
4253 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4261 case VASurfaceAttribMinWidth:
4262 /* FIXME: add support for it later */
4263 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4265 case VASurfaceAttribMaxWidth:
4266 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4268 case VASurfaceAttribMinHeight:
4269 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4271 case VASurfaceAttribMaxHeight:
4272 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4275 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4284 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4286 VASurfaceAttrib *attrib_list,
4287 unsigned int *num_attribs)
4289 VAStatus vaStatus = VA_STATUS_SUCCESS;
4290 struct i965_driver_data *i965 = i965_driver_data(ctx);
4291 struct object_config *obj_config;
4293 VASurfaceAttrib *attribs = NULL;
4295 if (config == VA_INVALID_ID)
4296 return VA_STATUS_ERROR_INVALID_CONFIG;
4298 obj_config = CONFIG(config);
4300 if (obj_config == NULL)
4301 return VA_STATUS_ERROR_INVALID_CONFIG;
4303 if (!attrib_list && !num_attribs)
4304 return VA_STATUS_ERROR_INVALID_PARAMETER;
4306 if (attrib_list == NULL) {
4307 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4308 return VA_STATUS_SUCCESS;
4311 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4313 if (attribs == NULL)
4314 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4316 if (IS_G4X(i965->intel.device_id)) {
4317 if (obj_config->profile == VAProfileMPEG2Simple ||
4318 obj_config->profile == VAProfileMPEG2Main) {
4319 attribs[i].type = VASurfaceAttribPixelFormat;
4320 attribs[i].value.type = VAGenericValueTypeInteger;
4321 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4322 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4325 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4326 switch (obj_config->profile) {
4327 case VAProfileMPEG2Simple:
4328 case VAProfileMPEG2Main:
4329 attribs[i].type = VASurfaceAttribPixelFormat;
4330 attribs[i].value.type = VAGenericValueTypeInteger;
4331 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4332 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4337 case VAProfileH264Baseline:
4338 case VAProfileH264Main:
4339 case VAProfileH264High:
4340 attribs[i].type = VASurfaceAttribPixelFormat;
4341 attribs[i].value.type = VAGenericValueTypeInteger;
4342 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4343 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4347 attribs[i].type = VASurfaceAttribPixelFormat;
4348 attribs[i].value.type = VAGenericValueTypeInteger;
4349 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4350 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4353 attribs[i].type = VASurfaceAttribPixelFormat;
4354 attribs[i].value.type = VAGenericValueTypeInteger;
4355 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4356 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4364 } else if (IS_GEN6(i965->intel.device_id)) {
4365 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4366 attribs[i].type = VASurfaceAttribPixelFormat;
4367 attribs[i].value.type = VAGenericValueTypeInteger;
4368 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4369 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4371 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4372 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4373 attribs[i].type = VASurfaceAttribPixelFormat;
4374 attribs[i].value.type = VAGenericValueTypeInteger;
4375 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4376 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4379 attribs[i].type = VASurfaceAttribPixelFormat;
4380 attribs[i].value.type = VAGenericValueTypeInteger;
4381 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4382 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4385 attribs[i].type = VASurfaceAttribPixelFormat;
4386 attribs[i].value.type = VAGenericValueTypeInteger;
4387 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4388 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4391 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4392 attribs[i].type = VASurfaceAttribPixelFormat;
4393 attribs[i].value.type = VAGenericValueTypeInteger;
4394 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4395 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4398 attribs[i].type = VASurfaceAttribPixelFormat;
4399 attribs[i].value.type = VAGenericValueTypeInteger;
4400 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4401 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4404 attribs[i].type = VASurfaceAttribPixelFormat;
4405 attribs[i].value.type = VAGenericValueTypeInteger;
4406 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4407 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4411 } else if (IS_GEN7(i965->intel.device_id)) {
4412 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4413 if (obj_config->profile == VAProfileJPEGBaseline) {
4414 attribs[i].type = VASurfaceAttribPixelFormat;
4415 attribs[i].value.type = VAGenericValueTypeInteger;
4416 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4417 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4420 attribs[i].type = VASurfaceAttribPixelFormat;
4421 attribs[i].value.type = VAGenericValueTypeInteger;
4422 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4423 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '1');
4426 attribs[i].type = VASurfaceAttribPixelFormat;
4427 attribs[i].value.type = VAGenericValueTypeInteger;
4428 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4429 attribs[i].value.value.i = VA_FOURCC('Y', '8', '0', '0');
4432 attribs[i].type = VASurfaceAttribPixelFormat;
4433 attribs[i].value.type = VAGenericValueTypeInteger;
4434 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4435 attribs[i].value.value.i = VA_FOURCC('4', '1', '1', 'P');
4438 attribs[i].type = VASurfaceAttribPixelFormat;
4439 attribs[i].value.type = VAGenericValueTypeInteger;
4440 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4441 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'H');
4444 attribs[i].type = VASurfaceAttribPixelFormat;
4445 attribs[i].value.type = VAGenericValueTypeInteger;
4446 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4447 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'V');
4450 attribs[i].type = VASurfaceAttribPixelFormat;
4451 attribs[i].value.type = VAGenericValueTypeInteger;
4452 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4453 attribs[i].value.value.i = VA_FOURCC('4', '4', '4', 'P');
4456 attribs[i].type = VASurfaceAttribPixelFormat;
4457 attribs[i].value.type = VAGenericValueTypeInteger;
4458 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4459 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4462 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4463 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4464 attribs[i].type = VASurfaceAttribPixelFormat;
4465 attribs[i].value.type = VAGenericValueTypeInteger;
4466 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4467 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4470 attribs[i].type = VASurfaceAttribPixelFormat;
4471 attribs[i].value.type = VAGenericValueTypeInteger;
4472 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4473 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4476 attribs[i].type = VASurfaceAttribPixelFormat;
4477 attribs[i].value.type = VAGenericValueTypeInteger;
4478 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4479 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4482 attribs[i].type = VASurfaceAttribPixelFormat;
4483 attribs[i].value.type = VAGenericValueTypeInteger;
4484 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4485 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4488 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4489 attribs[i].type = VASurfaceAttribPixelFormat;
4490 attribs[i].value.type = VAGenericValueTypeInteger;
4491 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4492 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4495 attribs[i].type = VASurfaceAttribPixelFormat;
4496 attribs[i].value.type = VAGenericValueTypeInteger;
4497 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4498 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4501 attribs[i].type = VASurfaceAttribPixelFormat;
4502 attribs[i].value.type = VAGenericValueTypeInteger;
4503 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4504 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4510 attribs[i].type = VASurfaceAttribMemoryType;
4511 attribs[i].value.type = VAGenericValueTypeInteger;
4512 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4513 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4514 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4515 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4518 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4519 attribs[i].value.type = VAGenericValueTypePointer;
4520 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4521 attribs[i].value.value.p = NULL; /* ignore */
4524 if (i > *num_attribs) {
4527 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4531 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4538 i965_os_has_ring_support(VADriverContextP ctx,
4541 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4545 return i965->intel.has_bsd;
4548 return i965->intel.has_blt;
4550 case I965_RING_VEBOX:
4551 return i965->intel.has_vebox;
4553 case I965_RING_NULL:
4554 return 1; /* Always support */
4557 /* should never get here */
4566 * Query video processing pipeline
4568 VAStatus i965_QueryVideoProcFilters(
4569 VADriverContextP ctx,
4570 VAContextID context,
4571 VAProcFilterType *filters,
4572 unsigned int *num_filters
4575 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4576 unsigned int i = 0, num = 0;
4578 if (!num_filters || !filters)
4579 return VA_STATUS_ERROR_INVALID_PARAMETER;
4581 for (i = 0; i < i965->codec_info->num_filters; i++) {
4582 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4583 if (num == *num_filters) {
4584 *num_filters = i965->codec_info->num_filters;
4586 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4589 filters[num++] = i965->codec_info->filters[i].type;
4595 return VA_STATUS_SUCCESS;
4598 VAStatus i965_QueryVideoProcFilterCaps(
4599 VADriverContextP ctx,
4600 VAContextID context,
4601 VAProcFilterType type,
4603 unsigned int *num_filter_caps
4607 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4609 if (!filter_caps || !num_filter_caps)
4610 return VA_STATUS_ERROR_INVALID_PARAMETER;
4612 for (i = 0; i < i965->codec_info->num_filters; i++) {
4613 if (type == i965->codec_info->filters[i].type &&
4614 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4618 if (i == i965->codec_info->num_filters)
4619 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4624 case VAProcFilterNoiseReduction:
4625 case VAProcFilterSharpening:
4627 VAProcFilterCap *cap = filter_caps;
4629 if (*num_filter_caps < 1) {
4630 *num_filter_caps = 1;
4631 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4634 cap->range.min_value = 0.0;
4635 cap->range.max_value = 1.0;
4636 cap->range.default_value = 0.5;
4637 cap->range.step = 0.03125; /* 1.0 / 32 */
4643 case VAProcFilterDeinterlacing:
4645 VAProcFilterCapDeinterlacing *cap = filter_caps;
4647 if (*num_filter_caps < VAProcDeinterlacingCount) {
4648 *num_filter_caps = VAProcDeinterlacingCount;
4649 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4652 cap->type = VAProcDeinterlacingBob;
4657 if (i965->codec_info->has_di_motion_adptive) {
4658 cap->type = VAProcDeinterlacingMotionAdaptive;
4663 if (i965->codec_info->has_di_motion_compensated) {
4664 cap->type = VAProcDeinterlacingMotionCompensated;
4672 case VAProcFilterColorBalance:
4674 VAProcFilterCapColorBalance *cap = filter_caps;
4676 if (*num_filter_caps < VAProcColorBalanceCount) {
4677 *num_filter_caps = VAProcColorBalanceCount;
4678 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4681 cap->type = VAProcColorBalanceHue;
4682 cap->range.min_value = -180.0;
4683 cap->range.max_value = 180.0;
4684 cap->range.default_value = 0.0;
4685 cap->range.step = 1.0;
4689 cap->type = VAProcColorBalanceSaturation;
4690 cap->range.min_value = 0.0;
4691 cap->range.max_value = 10.0;
4692 cap->range.default_value = 1.0;
4693 cap->range.step = 0.1;
4697 cap->type = VAProcColorBalanceBrightness;
4698 cap->range.min_value = -100.0;
4699 cap->range.max_value = 100.0;
4700 cap->range.default_value = 0.0;
4701 cap->range.step = 1.0;
4705 cap->type = VAProcColorBalanceContrast;
4706 cap->range.min_value = 0.0;
4707 cap->range.max_value = 10.0;
4708 cap->range.default_value = 1.0;
4709 cap->range.step = 0.1;
4721 *num_filter_caps = i;
4723 return VA_STATUS_SUCCESS;
4726 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
4727 VAProcColorStandardBT601,
4730 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
4731 VAProcColorStandardBT601,
4734 VAStatus i965_QueryVideoProcPipelineCaps(
4735 VADriverContextP ctx,
4736 VAContextID context,
4737 VABufferID *filters,
4738 unsigned int num_filters,
4739 VAProcPipelineCaps *pipeline_cap /* out */
4742 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4745 pipeline_cap->pipeline_flags = 0;
4746 pipeline_cap->filter_flags = 0;
4747 pipeline_cap->num_forward_references = 0;
4748 pipeline_cap->num_backward_references = 0;
4749 pipeline_cap->num_input_color_standards = 1;
4750 pipeline_cap->input_color_standards = vpp_input_color_standards;
4751 pipeline_cap->num_output_color_standards = 1;
4752 pipeline_cap->output_color_standards = vpp_output_color_standards;
4754 for (i = 0; i < num_filters; i++) {
4755 struct object_buffer *obj_buffer = BUFFER(filters[i]);
4758 !obj_buffer->buffer_store ||
4759 !obj_buffer->buffer_store->buffer)
4760 return VA_STATUS_ERROR_INVALID_BUFFER;
4762 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4764 if (base->type == VAProcFilterNoiseReduction) {
4765 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
4767 } else if (base->type == VAProcFilterDeinterlacing) {
4768 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
4770 assert(deint->algorithm == VAProcDeinterlacingBob ||
4771 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4772 deint->algorithm == VAProcDeinterlacingMotionCompensated);
4774 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4775 deint->algorithm == VAProcDeinterlacingMotionCompensated);
4776 pipeline_cap->num_forward_references++;
4780 return VA_STATUS_SUCCESS;
4784 i965_driver_data_init(VADriverContextP ctx)
4786 struct i965_driver_data *i965 = i965_driver_data(ctx);
4788 if (IS_HASWELL(i965->intel.device_id))
4789 i965->codec_info = &gen75_hw_codec_info;
4790 else if (IS_G4X(i965->intel.device_id))
4791 i965->codec_info = &g4x_hw_codec_info;
4792 else if (IS_IRONLAKE(i965->intel.device_id))
4793 i965->codec_info = &ironlake_hw_codec_info;
4794 else if (IS_GEN6(i965->intel.device_id))
4795 i965->codec_info = &gen6_hw_codec_info;
4796 else if (IS_GEN7(i965->intel.device_id))
4797 i965->codec_info = &gen7_hw_codec_info;
4801 if (object_heap_init(&i965->config_heap,
4802 sizeof(struct object_config),
4804 goto err_config_heap;
4805 if (object_heap_init(&i965->context_heap,
4806 sizeof(struct object_context),
4808 goto err_context_heap;
4810 if (object_heap_init(&i965->surface_heap,
4811 sizeof(struct object_surface),
4813 goto err_surface_heap;
4814 if (object_heap_init(&i965->buffer_heap,
4815 sizeof(struct object_buffer),
4817 goto err_buffer_heap;
4818 if (object_heap_init(&i965->image_heap,
4819 sizeof(struct object_image),
4821 goto err_image_heap;
4822 if (object_heap_init(&i965->subpic_heap,
4823 sizeof(struct object_subpic),
4825 goto err_subpic_heap;
4827 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
4828 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
4829 _i965InitMutex(&i965->render_mutex);
4830 _i965InitMutex(&i965->pp_mutex);
4835 object_heap_destroy(&i965->image_heap);
4837 object_heap_destroy(&i965->buffer_heap);
4839 object_heap_destroy(&i965->surface_heap);
4841 object_heap_destroy(&i965->context_heap);
4843 object_heap_destroy(&i965->config_heap);
4850 i965_driver_data_terminate(VADriverContextP ctx)
4852 struct i965_driver_data *i965 = i965_driver_data(ctx);
4854 _i965DestroyMutex(&i965->pp_mutex);
4855 _i965DestroyMutex(&i965->render_mutex);
4858 intel_batchbuffer_free(i965->batch);
4861 intel_batchbuffer_free(i965->pp_batch);
4863 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
4864 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
4865 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
4866 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
4867 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
4868 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
4872 bool (*init)(VADriverContextP ctx);
4873 void (*terminate)(VADriverContextP ctx);
4875 } i965_sub_ops[] = {
4878 intel_driver_terminate,
4883 i965_driver_data_init,
4884 i965_driver_data_terminate,
4889 i965_display_attributes_init,
4890 i965_display_attributes_terminate,
4895 i965_post_processing_init,
4896 i965_post_processing_terminate,
4902 i965_render_terminate,
4906 #ifdef HAVE_VA_WAYLAND
4908 i965_output_wayland_init,
4909 i965_output_wayland_terminate,
4916 i965_output_dri_init,
4917 i965_output_dri_terminate,
4924 i965_Init(VADriverContextP ctx)
4926 struct i965_driver_data *i965 = i965_driver_data(ctx);
4929 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
4930 if ((i965_sub_ops[i].display_type == 0 ||
4931 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
4932 !i965_sub_ops[i].init(ctx))
4936 if (i == ARRAY_ELEMS(i965_sub_ops)) {
4937 sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
4938 INTEL_STR_DRIVER_VENDOR,
4939 INTEL_STR_DRIVER_NAME,
4940 INTEL_DRIVER_MAJOR_VERSION,
4941 INTEL_DRIVER_MINOR_VERSION,
4942 INTEL_DRIVER_MICRO_VERSION);
4944 if (INTEL_DRIVER_PRE_VERSION > 0) {
4945 const int len = strlen(i965->va_vendor);
4946 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
4949 i965->current_context_id = VA_INVALID_ID;
4951 return VA_STATUS_SUCCESS;
4955 for (; i >= 0; i--) {
4956 if (i965_sub_ops[i].display_type == 0 ||
4957 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
4958 i965_sub_ops[i].terminate(ctx);
4962 return VA_STATUS_ERROR_UNKNOWN;
4967 i965_Terminate(VADriverContextP ctx)
4969 struct i965_driver_data *i965 = i965_driver_data(ctx);
4973 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
4974 if (i965_sub_ops[i - 1].display_type == 0 ||
4975 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
4976 i965_sub_ops[i - 1].terminate(ctx);
4980 ctx->pDriverData = NULL;
4983 return VA_STATUS_SUCCESS;
4987 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
4990 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
4992 struct VADriverVTable * const vtable = ctx->vtable;
4993 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
4995 struct i965_driver_data *i965;
4996 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
4998 ctx->version_major = VA_MAJOR_VERSION;
4999 ctx->version_minor = VA_MINOR_VERSION;
5000 ctx->max_profiles = I965_MAX_PROFILES;
5001 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5002 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5003 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5004 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5005 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5007 vtable->vaTerminate = i965_Terminate;
5008 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5009 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5010 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5011 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5012 vtable->vaCreateConfig = i965_CreateConfig;
5013 vtable->vaDestroyConfig = i965_DestroyConfig;
5014 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5015 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5016 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5017 vtable->vaCreateContext = i965_CreateContext;
5018 vtable->vaDestroyContext = i965_DestroyContext;
5019 vtable->vaCreateBuffer = i965_CreateBuffer;
5020 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5021 vtable->vaMapBuffer = i965_MapBuffer;
5022 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5023 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5024 vtable->vaBeginPicture = i965_BeginPicture;
5025 vtable->vaRenderPicture = i965_RenderPicture;
5026 vtable->vaEndPicture = i965_EndPicture;
5027 vtable->vaSyncSurface = i965_SyncSurface;
5028 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5029 vtable->vaPutSurface = i965_PutSurface;
5030 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5031 vtable->vaCreateImage = i965_CreateImage;
5032 vtable->vaDeriveImage = i965_DeriveImage;
5033 vtable->vaDestroyImage = i965_DestroyImage;
5034 vtable->vaSetImagePalette = i965_SetImagePalette;
5035 vtable->vaGetImage = i965_GetImage;
5036 vtable->vaPutImage = i965_PutImage;
5037 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5038 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5039 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5040 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5041 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5042 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5043 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5044 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5045 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5046 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5047 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5048 vtable->vaBufferInfo = i965_BufferInfo;
5049 vtable->vaLockSurface = i965_LockSurface;
5050 vtable->vaUnlockSurface = i965_UnlockSurface;
5051 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5052 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5053 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5055 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5056 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5057 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5059 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5062 ctx->pDriverData = NULL;
5064 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5067 ctx->pDriverData = (void *)i965;
5068 ret = i965_Init(ctx);
5070 if (ret == VA_STATUS_SUCCESS) {
5071 ctx->str_vendor = i965->va_vendor;
5074 ctx->pDriverData = NULL;