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 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
84 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
88 static int get_sampling_from_fourcc(unsigned int fourcc);
90 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
91 #define IS_VA_X11(ctx) \
92 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
94 /* Check whether we are rendering to Wayland */
95 #define IS_VA_WAYLAND(ctx) \
96 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
99 I965_SURFACETYPE_RGBA = 1,
100 I965_SURFACETYPE_YUV,
101 I965_SURFACETYPE_INDEXED
104 /* List of supported display attributes */
105 static const VADisplayAttribute i965_display_attributes[] = {
107 VADisplayAttribBrightness,
108 -100, 100, DEFAULT_BRIGHTNESS,
109 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
113 VADisplayAttribContrast,
114 0, 100, DEFAULT_CONTRAST,
115 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
120 -180, 180, DEFAULT_HUE,
121 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
125 VADisplayAttribSaturation,
126 0, 100, DEFAULT_SATURATION,
127 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
131 VADisplayAttribRotation,
132 0, 3, VA_ROTATION_NONE,
133 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
137 /* List of supported image formats */
140 VAImageFormat va_format;
141 } i965_image_format_map_t;
143 static const i965_image_format_map_t
144 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
145 { I965_SURFACETYPE_YUV,
146 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
147 { I965_SURFACETYPE_YUV,
148 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
149 { I965_SURFACETYPE_YUV,
150 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
151 { I965_SURFACETYPE_YUV,
152 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
153 { I965_SURFACETYPE_YUV,
154 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
155 { I965_SURFACETYPE_YUV,
156 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
157 { I965_SURFACETYPE_RGBA,
158 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
159 { I965_SURFACETYPE_RGBA,
160 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
163 /* List of supported subpicture formats */
167 VAImageFormat va_format;
168 unsigned int va_flags;
169 } i965_subpic_format_map_t;
171 #define COMMON_SUBPICTURE_FLAGS \
172 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
173 VA_SUBPICTURE_GLOBAL_ALPHA)
175 static const i965_subpic_format_map_t
176 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
177 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
178 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
179 COMMON_SUBPICTURE_FLAGS },
180 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
181 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
182 COMMON_SUBPICTURE_FLAGS },
183 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
184 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
185 COMMON_SUBPICTURE_FLAGS },
186 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
187 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
188 COMMON_SUBPICTURE_FLAGS },
189 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
190 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
191 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
192 COMMON_SUBPICTURE_FLAGS },
193 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
194 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
195 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
196 COMMON_SUBPICTURE_FLAGS },
199 static const i965_subpic_format_map_t *
200 get_subpic_format(const VAImageFormat *va_format)
203 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
204 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
205 if (m->va_format.fourcc == va_format->fourcc &&
206 (m->type == I965_SURFACETYPE_RGBA ?
207 (m->va_format.byte_order == va_format->byte_order &&
208 m->va_format.red_mask == va_format->red_mask &&
209 m->va_format.green_mask == va_format->green_mask &&
210 m->va_format.blue_mask == va_format->blue_mask &&
211 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
217 #define I965_PACKED_HEADER_BASE 0
218 #define I965_PACKED_MISC_HEADER_BASE 3
221 va_enc_packed_type_to_idx(int packed_type)
225 if (packed_type & VAEncPackedHeaderMiscMask) {
226 idx = I965_PACKED_MISC_HEADER_BASE;
227 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
228 ASSERT_RET(packed_type > 0, 0);
229 idx += (packed_type - 1);
231 idx = I965_PACKED_HEADER_BASE;
233 switch (packed_type) {
234 case VAEncPackedHeaderSequence:
235 idx = I965_PACKED_HEADER_BASE + 0;
238 case VAEncPackedHeaderPicture:
239 idx = I965_PACKED_HEADER_BASE + 1;
242 case VAEncPackedHeaderSlice:
243 idx = I965_PACKED_HEADER_BASE + 2;
247 /* Should not get here */
253 ASSERT_RET(idx < 4, 0);
258 i965_QueryConfigProfiles(VADriverContextP ctx,
259 VAProfile *profile_list, /* out */
260 int *num_profiles) /* out */
262 struct i965_driver_data * const i965 = i965_driver_data(ctx);
265 if (HAS_MPEG2_DECODING(i965) ||
266 HAS_MPEG2_ENCODING(i965)) {
267 profile_list[i++] = VAProfileMPEG2Simple;
268 profile_list[i++] = VAProfileMPEG2Main;
271 if (HAS_H264_DECODING(i965) ||
272 HAS_H264_ENCODING(i965)) {
273 profile_list[i++] = VAProfileH264ConstrainedBaseline;
274 profile_list[i++] = VAProfileH264Main;
275 profile_list[i++] = VAProfileH264High;
278 if (HAS_VC1_DECODING(i965)) {
279 profile_list[i++] = VAProfileVC1Simple;
280 profile_list[i++] = VAProfileVC1Main;
281 profile_list[i++] = VAProfileVC1Advanced;
285 profile_list[i++] = VAProfileNone;
288 if (HAS_JPEG_DECODING(i965)) {
289 profile_list[i++] = VAProfileJPEGBaseline;
292 if (HAS_VP8_DECODING(i965) ||
293 HAS_VP8_ENCODING(i965)) {
294 profile_list[i++] = VAProfileVP8Version0_3;
297 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
298 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
301 return VA_STATUS_SUCCESS;
305 i965_QueryConfigEntrypoints(VADriverContextP ctx,
307 VAEntrypoint *entrypoint_list, /* out */
308 int *num_entrypoints) /* out */
310 struct i965_driver_data * const i965 = i965_driver_data(ctx);
314 case VAProfileMPEG2Simple:
315 case VAProfileMPEG2Main:
316 if (HAS_MPEG2_DECODING(i965))
317 entrypoint_list[n++] = VAEntrypointVLD;
319 if (HAS_MPEG2_ENCODING(i965))
320 entrypoint_list[n++] = VAEntrypointEncSlice;
324 case VAProfileH264ConstrainedBaseline:
325 case VAProfileH264Main:
326 case VAProfileH264High:
327 if (HAS_H264_DECODING(i965))
328 entrypoint_list[n++] = VAEntrypointVLD;
330 if (HAS_H264_ENCODING(i965))
331 entrypoint_list[n++] = VAEntrypointEncSlice;
335 case VAProfileVC1Simple:
336 case VAProfileVC1Main:
337 case VAProfileVC1Advanced:
338 if (HAS_VC1_DECODING(i965))
339 entrypoint_list[n++] = VAEntrypointVLD;
344 entrypoint_list[n++] = VAEntrypointVideoProc;
347 case VAProfileJPEGBaseline:
348 if (HAS_JPEG_DECODING(i965))
349 entrypoint_list[n++] = VAEntrypointVLD;
352 case VAProfileVP8Version0_3:
353 if (HAS_VP8_DECODING(i965))
354 entrypoint_list[n++] = VAEntrypointVLD;
356 if (HAS_VP8_ENCODING(i965))
357 entrypoint_list[n++] = VAEntrypointEncSlice;
363 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
364 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
365 *num_entrypoints = n;
366 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
370 i965_GetConfigAttributes(VADriverContextP ctx,
372 VAEntrypoint entrypoint,
373 VAConfigAttrib *attrib_list, /* in/out */
378 /* Other attributes don't seem to be defined */
379 /* What to do if we don't know the attribute? */
380 for (i = 0; i < num_attribs; i++) {
381 switch (attrib_list[i].type) {
382 case VAConfigAttribRTFormat:
383 attrib_list[i].value = VA_RT_FORMAT_YUV420;
386 case VAConfigAttribRateControl:
387 if (entrypoint == VAEntrypointEncSlice) {
388 attrib_list[i].value = VA_RC_CQP;
390 if (profile != VAProfileMPEG2Main &&
391 profile != VAProfileMPEG2Simple)
392 attrib_list[i].value |= VA_RC_CBR;
396 case VAConfigAttribEncPackedHeaders:
397 if (entrypoint == VAEntrypointEncSlice) {
398 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
402 case VAConfigAttribEncMaxRefFrames:
403 if (entrypoint == VAEntrypointEncSlice) {
404 attrib_list[i].value = (1 << 16) | (1 << 0);
410 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
415 return VA_STATUS_SUCCESS;
419 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
421 object_heap_free(heap, obj);
425 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
429 /* Check existing attrbiutes */
430 for (i = 0; i < obj_config->num_attribs; i++) {
431 if (obj_config->attrib_list[i].type == attrib->type) {
432 /* Update existing attribute */
433 obj_config->attrib_list[i].value = attrib->value;
434 return VA_STATUS_SUCCESS;
438 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
439 i = obj_config->num_attribs;
440 obj_config->attrib_list[i].type = attrib->type;
441 obj_config->attrib_list[i].value = attrib->value;
442 obj_config->num_attribs++;
443 return VA_STATUS_SUCCESS;
446 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
450 i965_CreateConfig(VADriverContextP ctx,
452 VAEntrypoint entrypoint,
453 VAConfigAttrib *attrib_list,
455 VAConfigID *config_id) /* out */
457 struct i965_driver_data * const i965 = i965_driver_data(ctx);
458 struct object_config *obj_config;
463 /* Validate profile & entrypoint */
465 case VAProfileMPEG2Simple:
466 case VAProfileMPEG2Main:
467 if ((HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
468 (HAS_MPEG2_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
469 vaStatus = VA_STATUS_SUCCESS;
471 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
475 case VAProfileH264ConstrainedBaseline:
476 case VAProfileH264Main:
477 case VAProfileH264High:
478 if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
479 (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
480 vaStatus = VA_STATUS_SUCCESS;
482 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
487 case VAProfileVC1Simple:
488 case VAProfileVC1Main:
489 case VAProfileVC1Advanced:
490 if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) {
491 vaStatus = VA_STATUS_SUCCESS;
493 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
499 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
500 vaStatus = VA_STATUS_SUCCESS;
502 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
507 case VAProfileJPEGBaseline:
508 if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) {
509 vaStatus = VA_STATUS_SUCCESS;
511 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
516 case VAProfileVP8Version0_3:
517 if ((HAS_VP8_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
518 (HAS_VP8_ENCODING(i965) && VAEntrypointEncSlice == entrypoint))
519 vaStatus = VA_STATUS_SUCCESS;
521 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
526 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
530 if (VA_STATUS_SUCCESS != vaStatus) {
534 configID = NEW_CONFIG_ID();
535 obj_config = CONFIG(configID);
537 if (NULL == obj_config) {
538 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
542 obj_config->profile = profile;
543 obj_config->entrypoint = entrypoint;
544 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
545 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
546 obj_config->num_attribs = 1;
548 for(i = 0; i < num_attribs; i++) {
549 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
551 if (VA_STATUS_SUCCESS != vaStatus) {
557 if (VA_STATUS_SUCCESS != vaStatus) {
558 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
560 *config_id = configID;
567 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
569 struct i965_driver_data *i965 = i965_driver_data(ctx);
570 struct object_config *obj_config = CONFIG(config_id);
573 if (NULL == obj_config) {
574 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
578 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
579 return VA_STATUS_SUCCESS;
582 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
583 VAConfigID config_id,
584 VAProfile *profile, /* out */
585 VAEntrypoint *entrypoint, /* out */
586 VAConfigAttrib *attrib_list, /* out */
587 int *num_attribs) /* out */
589 struct i965_driver_data *i965 = i965_driver_data(ctx);
590 struct object_config *obj_config = CONFIG(config_id);
591 VAStatus vaStatus = VA_STATUS_SUCCESS;
594 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
595 *profile = obj_config->profile;
596 *entrypoint = obj_config->entrypoint;
597 *num_attribs = obj_config->num_attribs;
599 for(i = 0; i < obj_config->num_attribs; i++) {
600 attrib_list[i] = obj_config->attrib_list[i];
607 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
609 struct object_surface *obj_surface = (struct object_surface *)obj;
611 dri_bo_unreference(obj_surface->bo);
612 obj_surface->bo = NULL;
614 if (obj_surface->free_private_data != NULL) {
615 obj_surface->free_private_data(&obj_surface->private_data);
616 obj_surface->private_data = NULL;
619 object_heap_free(heap, obj);
623 i965_surface_native_memory(VADriverContextP ctx,
624 struct object_surface *obj_surface,
628 struct i965_driver_data *i965 = i965_driver_data(ctx);
629 int tiling = HAS_TILED_SURFACE(i965);
631 if (!expected_fourcc)
632 return VA_STATUS_SUCCESS;
634 // todo, should we disable tiling for 422 format?
635 if (expected_fourcc == VA_FOURCC_I420 ||
636 expected_fourcc == VA_FOURCC_IYUV ||
637 expected_fourcc == VA_FOURCC_YV12 ||
638 expected_fourcc == VA_FOURCC_YV16)
641 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
643 return VA_STATUS_SUCCESS;
647 i965_suface_external_memory(VADriverContextP ctx,
648 struct object_surface *obj_surface,
649 int external_memory_type,
650 VASurfaceAttribExternalBuffers *memory_attibute,
653 struct i965_driver_data *i965 = i965_driver_data(ctx);
655 if (!memory_attibute ||
656 !memory_attibute->buffers ||
657 index > memory_attibute->num_buffers)
658 return VA_STATUS_ERROR_INVALID_PARAMETER;
660 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
661 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
662 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
664 obj_surface->fourcc = memory_attibute->pixel_format;
665 obj_surface->width = memory_attibute->pitches[0];
666 obj_surface->size = memory_attibute->data_size;
668 if (memory_attibute->num_planes == 1)
669 obj_surface->height = memory_attibute->data_size / obj_surface->width;
671 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
673 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
674 obj_surface->x_cr_offset = 0;
676 switch (obj_surface->fourcc) {
678 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
679 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
681 obj_surface->subsampling = SUBSAMPLE_YUV420;
682 obj_surface->y_cb_offset = obj_surface->height;
683 obj_surface->y_cr_offset = obj_surface->height;
684 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
685 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
686 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
692 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
693 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
695 obj_surface->subsampling = SUBSAMPLE_YUV420;
696 obj_surface->y_cr_offset = obj_surface->height;
697 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
698 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
699 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
700 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
707 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
708 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
710 obj_surface->subsampling = SUBSAMPLE_YUV420;
711 obj_surface->y_cb_offset = obj_surface->height;
712 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
713 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
714 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
715 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
721 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
723 obj_surface->subsampling = SUBSAMPLE_YUV422H;
724 obj_surface->y_cb_offset = 0;
725 obj_surface->y_cr_offset = 0;
726 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
727 obj_surface->cb_cr_height = obj_surface->orig_height;
728 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
736 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
738 obj_surface->subsampling = SUBSAMPLE_RGBX;
739 obj_surface->y_cb_offset = 0;
740 obj_surface->y_cr_offset = 0;
741 obj_surface->cb_cr_width = 0;
742 obj_surface->cb_cr_height = 0;
743 obj_surface->cb_cr_pitch = 0;
747 case VA_FOURCC_Y800: /* monochrome surface */
748 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
750 obj_surface->subsampling = SUBSAMPLE_YUV400;
751 obj_surface->y_cb_offset = 0;
752 obj_surface->y_cr_offset = 0;
753 obj_surface->cb_cr_width = 0;
754 obj_surface->cb_cr_height = 0;
755 obj_surface->cb_cr_pitch = 0;
760 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
761 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
763 obj_surface->subsampling = SUBSAMPLE_YUV411;
764 obj_surface->y_cb_offset = 0;
765 obj_surface->y_cr_offset = 0;
766 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
767 obj_surface->cb_cr_height = obj_surface->orig_height;
768 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
773 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
774 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
776 obj_surface->subsampling = SUBSAMPLE_YUV422H;
777 obj_surface->y_cb_offset = obj_surface->height;
778 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
779 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
780 obj_surface->cb_cr_height = obj_surface->orig_height;
781 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
786 assert(memory_attibute->num_planes == 3);
787 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
789 obj_surface->subsampling = SUBSAMPLE_YUV422H;
790 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
791 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
792 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
793 obj_surface->cb_cr_height = obj_surface->orig_height;
794 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
799 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
800 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
802 obj_surface->subsampling = SUBSAMPLE_YUV422H;
803 obj_surface->y_cb_offset = obj_surface->height;
804 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
805 obj_surface->cb_cr_width = obj_surface->orig_width;
806 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
807 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
812 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
813 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
815 obj_surface->subsampling = SUBSAMPLE_YUV444;
816 obj_surface->y_cb_offset = obj_surface->height;
817 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
818 obj_surface->cb_cr_width = obj_surface->orig_width;
819 obj_surface->cb_cr_height = obj_surface->orig_height;
820 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
826 return VA_STATUS_ERROR_INVALID_PARAMETER;
829 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
830 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
831 "gem flinked vaapi surface",
832 memory_attibute->buffers[index]);
833 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
834 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
835 memory_attibute->buffers[index],
838 if (!obj_surface->bo)
839 return VA_STATUS_ERROR_INVALID_PARAMETER;
841 return VA_STATUS_SUCCESS;
844 /* byte-per-pixel of the first plane */
846 bpp_1stplane_by_fourcc(unsigned int fourcc)
879 i965_CreateSurfaces2(
880 VADriverContextP ctx,
884 VASurfaceID *surfaces,
885 unsigned int num_surfaces,
886 VASurfaceAttrib *attrib_list,
887 unsigned int num_attribs
890 struct i965_driver_data *i965 = i965_driver_data(ctx);
892 VAStatus vaStatus = VA_STATUS_SUCCESS;
893 int expected_fourcc = 0;
894 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
895 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
897 for (i = 0; i < num_attribs && attrib_list; i++) {
898 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
899 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
900 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
901 expected_fourcc = attrib_list[i].value.value.i;
904 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
905 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
907 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
909 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
910 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
911 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
912 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
913 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
914 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
917 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
918 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
919 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
920 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
924 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
925 * for post-processing (including color conversion) */
926 if (VA_RT_FORMAT_YUV420 != format &&
927 VA_RT_FORMAT_YUV422 != format &&
928 VA_RT_FORMAT_YUV444 != format &&
929 VA_RT_FORMAT_YUV411 != format &&
930 VA_RT_FORMAT_YUV400 != format &&
931 VA_RT_FORMAT_RGB32 != format) {
932 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
935 for (i = 0; i < num_surfaces; i++) {
936 int surfaceID = NEW_SURFACE_ID();
937 struct object_surface *obj_surface = SURFACE(surfaceID);
939 if (NULL == obj_surface) {
940 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
944 surfaces[i] = surfaceID;
945 obj_surface->status = VASurfaceReady;
946 obj_surface->orig_width = width;
947 obj_surface->orig_height = height;
948 obj_surface->user_disable_tiling = false;
949 obj_surface->user_h_stride_set = false;
950 obj_surface->user_v_stride_set = false;
952 obj_surface->subpic_render_idx = 0;
953 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
954 obj_surface->subpic[j] = VA_INVALID_ID;
955 obj_surface->obj_subpic[j] = NULL;
958 assert(i965->codec_info->min_linear_wpitch);
959 assert(i965->codec_info->min_linear_hpitch);
960 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
961 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
962 obj_surface->flags = SURFACE_REFERENCED;
963 obj_surface->fourcc = 0;
964 obj_surface->bo = NULL;
965 obj_surface->locked_image_id = VA_INVALID_ID;
966 obj_surface->private_data = NULL;
967 obj_surface->free_private_data = NULL;
968 obj_surface->subsampling = SUBSAMPLE_YUV420;
970 switch (memory_type) {
971 case I965_SURFACE_MEM_NATIVE:
972 if (memory_attibute) {
973 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
974 obj_surface->user_disable_tiling = true;
976 if (memory_attibute->pixel_format) {
978 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
980 expected_fourcc = memory_attibute->pixel_format;
982 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
983 if (memory_attibute->pitches[0]) {
984 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
985 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
986 obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane;
987 obj_surface->user_h_stride_set = true;
988 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
989 ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER);
991 if (memory_attibute->offsets[1]) {
992 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
993 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
994 obj_surface->user_v_stride_set = true;
995 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
996 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1000 i965_surface_native_memory(ctx,
1006 case I965_SURFACE_MEM_GEM_FLINK:
1007 case I965_SURFACE_MEM_DRM_PRIME:
1008 i965_suface_external_memory(ctx,
1017 /* Error recovery */
1018 if (VA_STATUS_SUCCESS != vaStatus) {
1019 /* surfaces[i-1] was the last successful allocation */
1021 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1023 surfaces[i] = VA_INVALID_SURFACE;
1024 assert(obj_surface);
1025 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1033 i965_CreateSurfaces(VADriverContextP ctx,
1038 VASurfaceID *surfaces) /* out */
1040 return i965_CreateSurfaces2(ctx,
1051 i965_DestroySurfaces(VADriverContextP ctx,
1052 VASurfaceID *surface_list,
1055 struct i965_driver_data *i965 = i965_driver_data(ctx);
1058 for (i = num_surfaces; i--; ) {
1059 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1061 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1062 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1065 return VA_STATUS_SUCCESS;
1069 i965_QueryImageFormats(VADriverContextP ctx,
1070 VAImageFormat *format_list, /* out */
1071 int *num_formats) /* out */
1075 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1076 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1078 format_list[n] = m->va_format;
1084 return VA_STATUS_SUCCESS;
1088 * Guess the format when the usage of a VA surface is unknown
1089 * 1. Without a valid context: YV12
1090 * 2. The current context is valid:
1091 * a) always NV12 on GEN6 and later
1092 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1095 i965_guess_surface_format(VADriverContextP ctx,
1096 VASurfaceID surface,
1097 unsigned int *fourcc,
1098 unsigned int *is_tiled)
1100 struct i965_driver_data *i965 = i965_driver_data(ctx);
1101 struct object_context *obj_context = NULL;
1102 struct object_config *obj_config = NULL;
1104 *fourcc = VA_FOURCC_YV12;
1107 if (i965->current_context_id == VA_INVALID_ID)
1110 obj_context = CONTEXT(i965->current_context_id);
1115 obj_config = obj_context->obj_config;
1121 if (IS_GEN6(i965->intel.device_info) ||
1122 IS_GEN7(i965->intel.device_info) ||
1123 IS_GEN8(i965->intel.device_info)) {
1124 *fourcc = VA_FOURCC_NV12;
1129 switch (obj_config->profile) {
1130 case VAProfileMPEG2Simple:
1131 case VAProfileMPEG2Main:
1132 *fourcc = VA_FOURCC_I420;
1137 *fourcc = VA_FOURCC_NV12;
1144 i965_QuerySubpictureFormats(VADriverContextP ctx,
1145 VAImageFormat *format_list, /* out */
1146 unsigned int *flags, /* out */
1147 unsigned int *num_formats) /* out */
1151 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1152 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1154 format_list[n] = m->va_format;
1156 flags[n] = m->va_flags;
1162 return VA_STATUS_SUCCESS;
1166 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1168 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1170 object_heap_free(heap, obj);
1174 i965_CreateSubpicture(VADriverContextP ctx,
1176 VASubpictureID *subpicture) /* out */
1178 struct i965_driver_data *i965 = i965_driver_data(ctx);
1179 VASubpictureID subpicID = NEW_SUBPIC_ID()
1180 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1183 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1185 struct object_image *obj_image = IMAGE(image);
1187 return VA_STATUS_ERROR_INVALID_IMAGE;
1189 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1191 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1193 *subpicture = subpicID;
1194 obj_subpic->image = image;
1195 obj_subpic->obj_image = obj_image;
1196 obj_subpic->format = m->format;
1197 obj_subpic->width = obj_image->image.width;
1198 obj_subpic->height = obj_image->image.height;
1199 obj_subpic->pitch = obj_image->image.pitches[0];
1200 obj_subpic->bo = obj_image->bo;
1201 obj_subpic->global_alpha = 1.0;
1203 return VA_STATUS_SUCCESS;
1207 i965_DestroySubpicture(VADriverContextP ctx,
1208 VASubpictureID subpicture)
1210 struct i965_driver_data *i965 = i965_driver_data(ctx);
1211 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1214 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1216 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1217 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1218 return VA_STATUS_SUCCESS;
1222 i965_SetSubpictureImage(VADriverContextP ctx,
1223 VASubpictureID subpicture,
1227 return VA_STATUS_ERROR_UNIMPLEMENTED;
1231 i965_SetSubpictureChromakey(VADriverContextP ctx,
1232 VASubpictureID subpicture,
1233 unsigned int chromakey_min,
1234 unsigned int chromakey_max,
1235 unsigned int chromakey_mask)
1238 return VA_STATUS_ERROR_UNIMPLEMENTED;
1242 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1243 VASubpictureID subpicture,
1246 struct i965_driver_data *i965 = i965_driver_data(ctx);
1247 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1249 if(global_alpha > 1.0 || global_alpha < 0.0){
1250 return VA_STATUS_ERROR_INVALID_PARAMETER;
1254 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1256 obj_subpic->global_alpha = global_alpha;
1258 return VA_STATUS_SUCCESS;
1262 i965_AssociateSubpicture(VADriverContextP ctx,
1263 VASubpictureID subpicture,
1264 VASurfaceID *target_surfaces,
1266 short src_x, /* upper left offset in subpicture */
1268 unsigned short src_width,
1269 unsigned short src_height,
1270 short dest_x, /* upper left offset in surface */
1272 unsigned short dest_width,
1273 unsigned short dest_height,
1275 * whether to enable chroma-keying or global-alpha
1276 * see VA_SUBPICTURE_XXX values
1280 struct i965_driver_data *i965 = i965_driver_data(ctx);
1281 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1285 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1287 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1289 obj_subpic->src_rect.x = src_x;
1290 obj_subpic->src_rect.y = src_y;
1291 obj_subpic->src_rect.width = src_width;
1292 obj_subpic->src_rect.height = src_height;
1293 obj_subpic->dst_rect.x = dest_x;
1294 obj_subpic->dst_rect.y = dest_y;
1295 obj_subpic->dst_rect.width = dest_width;
1296 obj_subpic->dst_rect.height = dest_height;
1297 obj_subpic->flags = flags;
1299 for (i = 0; i < num_surfaces; i++) {
1300 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1302 return VA_STATUS_ERROR_INVALID_SURFACE;
1304 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1305 if(obj_surface->subpic[j] == VA_INVALID_ID){
1306 assert(obj_surface->obj_subpic[j] == NULL);
1307 obj_surface->subpic[j] = subpicture;
1308 obj_surface->obj_subpic[j] = obj_subpic;
1313 if(j == I965_MAX_SUBPIC_SUM){
1314 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1318 return VA_STATUS_SUCCESS;
1323 i965_DeassociateSubpicture(VADriverContextP ctx,
1324 VASubpictureID subpicture,
1325 VASurfaceID *target_surfaces,
1328 struct i965_driver_data *i965 = i965_driver_data(ctx);
1329 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1333 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1335 for (i = 0; i < num_surfaces; i++) {
1336 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1338 return VA_STATUS_ERROR_INVALID_SURFACE;
1340 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1341 if (obj_surface->subpic[j] == subpicture) {
1342 assert(obj_surface->obj_subpic[j] == obj_subpic);
1343 obj_surface->subpic[j] = VA_INVALID_ID;
1344 obj_surface->obj_subpic[j] = NULL;
1349 if(j == I965_MAX_SUBPIC_SUM){
1350 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1353 return VA_STATUS_SUCCESS;
1357 i965_reference_buffer_store(struct buffer_store **ptr,
1358 struct buffer_store *buffer_store)
1360 assert(*ptr == NULL);
1363 buffer_store->ref_count++;
1364 *ptr = buffer_store;
1369 i965_release_buffer_store(struct buffer_store **ptr)
1371 struct buffer_store *buffer_store = *ptr;
1373 if (buffer_store == NULL)
1376 assert(buffer_store->bo || buffer_store->buffer);
1377 assert(!(buffer_store->bo && buffer_store->buffer));
1378 buffer_store->ref_count--;
1380 if (buffer_store->ref_count == 0) {
1381 dri_bo_unreference(buffer_store->bo);
1382 free(buffer_store->buffer);
1383 buffer_store->bo = NULL;
1384 buffer_store->buffer = NULL;
1392 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1394 struct object_context *obj_context = (struct object_context *)obj;
1397 if (obj_context->hw_context) {
1398 obj_context->hw_context->destroy(obj_context->hw_context);
1399 obj_context->hw_context = NULL;
1402 if (obj_context->codec_type == CODEC_PROC) {
1403 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1405 } else if (obj_context->codec_type == CODEC_ENC) {
1406 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1407 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1408 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1410 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1411 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1413 free(obj_context->codec_state.encode.slice_params);
1415 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1416 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1417 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1419 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1420 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1422 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1423 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1425 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1426 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1428 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1429 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1431 free(obj_context->codec_state.encode.slice_params_ext);
1433 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1434 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1436 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1437 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1438 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1440 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1441 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1443 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1444 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1446 free(obj_context->codec_state.decode.slice_params);
1447 free(obj_context->codec_state.decode.slice_datas);
1450 free(obj_context->render_targets);
1451 object_heap_free(heap, obj);
1455 i965_CreateContext(VADriverContextP ctx,
1456 VAConfigID config_id,
1460 VASurfaceID *render_targets,
1461 int num_render_targets,
1462 VAContextID *context) /* out */
1464 struct i965_driver_data *i965 = i965_driver_data(ctx);
1465 struct i965_render_state *render_state = &i965->render_state;
1466 struct object_config *obj_config = CONFIG(config_id);
1467 struct object_context *obj_context = NULL;
1468 VAStatus vaStatus = VA_STATUS_SUCCESS;
1472 if (NULL == obj_config) {
1473 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1477 if (picture_width > i965->codec_info->max_width ||
1478 picture_height > i965->codec_info->max_height) {
1479 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1484 /* Validate picture dimensions */
1485 contextID = NEW_CONTEXT_ID();
1486 obj_context = CONTEXT(contextID);
1488 if (NULL == obj_context) {
1489 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1493 render_state->inited = 1;
1495 switch (obj_config->profile) {
1496 case VAProfileH264ConstrainedBaseline:
1497 case VAProfileH264Main:
1498 case VAProfileH264High:
1499 if (!HAS_H264_DECODING(i965) &&
1500 !HAS_H264_ENCODING(i965))
1501 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1502 render_state->interleaved_uv = 1;
1505 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info));
1509 *context = contextID;
1510 obj_context->flags = flag;
1511 obj_context->context_id = contextID;
1512 obj_context->obj_config = obj_config;
1513 obj_context->picture_width = picture_width;
1514 obj_context->picture_height = picture_height;
1515 obj_context->num_render_targets = num_render_targets;
1516 obj_context->render_targets =
1517 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1518 obj_context->hw_context = NULL;
1520 for(i = 0; i < num_render_targets; i++) {
1521 if (NULL == SURFACE(render_targets[i])) {
1522 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1526 obj_context->render_targets[i] = render_targets[i];
1529 if (VA_STATUS_SUCCESS == vaStatus) {
1530 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1531 obj_context->codec_type = CODEC_PROC;
1532 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1533 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1534 assert(i965->codec_info->proc_hw_context_init);
1535 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1536 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1537 obj_context->codec_type = CODEC_ENC;
1538 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1539 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1540 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1541 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1542 sizeof(*obj_context->codec_state.encode.slice_params));
1543 assert(i965->codec_info->enc_hw_context_init);
1544 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1546 obj_context->codec_type = CODEC_DEC;
1547 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1548 obj_context->codec_state.decode.current_render_target = -1;
1549 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1550 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1551 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1552 sizeof(*obj_context->codec_state.decode.slice_params));
1553 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1554 sizeof(*obj_context->codec_state.decode.slice_datas));
1556 assert(i965->codec_info->dec_hw_context_init);
1557 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1561 /* Error recovery */
1562 if (VA_STATUS_SUCCESS != vaStatus) {
1563 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1566 i965->current_context_id = contextID;
1572 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1574 struct i965_driver_data *i965 = i965_driver_data(ctx);
1575 struct object_context *obj_context = CONTEXT(context);
1577 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1579 if (i965->current_context_id == context)
1580 i965->current_context_id = VA_INVALID_ID;
1582 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1584 return VA_STATUS_SUCCESS;
1588 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1590 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1592 assert(obj_buffer->buffer_store);
1593 i965_release_buffer_store(&obj_buffer->buffer_store);
1594 object_heap_free(heap, obj);
1598 i965_create_buffer_internal(VADriverContextP ctx,
1599 VAContextID context,
1602 unsigned int num_elements,
1607 struct i965_driver_data *i965 = i965_driver_data(ctx);
1608 struct object_buffer *obj_buffer = NULL;
1609 struct buffer_store *buffer_store = NULL;
1614 case VAPictureParameterBufferType:
1615 case VAIQMatrixBufferType:
1616 case VAQMatrixBufferType:
1617 case VABitPlaneBufferType:
1618 case VASliceGroupMapBufferType:
1619 case VASliceParameterBufferType:
1620 case VASliceDataBufferType:
1621 case VAMacroblockParameterBufferType:
1622 case VAResidualDataBufferType:
1623 case VADeblockingParameterBufferType:
1624 case VAImageBufferType:
1625 case VAEncCodedBufferType:
1626 case VAEncSequenceParameterBufferType:
1627 case VAEncPictureParameterBufferType:
1628 case VAEncSliceParameterBufferType:
1629 case VAEncPackedHeaderParameterBufferType:
1630 case VAEncPackedHeaderDataBufferType:
1631 case VAEncMiscParameterBufferType:
1632 case VAProcPipelineParameterBufferType:
1633 case VAProcFilterParameterBufferType:
1634 case VAHuffmanTableBufferType:
1635 case VAProbabilityBufferType:
1640 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1643 bufferID = NEW_BUFFER_ID();
1644 obj_buffer = BUFFER(bufferID);
1646 if (NULL == obj_buffer) {
1647 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1650 if (type == VAEncCodedBufferType) {
1651 size += I965_CODEDBUFFER_HEADER_SIZE;
1652 size += 0x1000; /* for upper bound check */
1655 obj_buffer->max_num_elements = num_elements;
1656 obj_buffer->num_elements = num_elements;
1657 obj_buffer->size_element = size;
1658 obj_buffer->type = type;
1659 obj_buffer->buffer_store = NULL;
1660 buffer_store = calloc(1, sizeof(struct buffer_store));
1661 assert(buffer_store);
1662 buffer_store->ref_count = 1;
1664 if (store_bo != NULL) {
1665 buffer_store->bo = store_bo;
1666 dri_bo_reference(buffer_store->bo);
1669 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1670 } else if (type == VASliceDataBufferType ||
1671 type == VAImageBufferType ||
1672 type == VAEncCodedBufferType ||
1673 type == VAProbabilityBufferType) {
1674 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1676 size * num_elements, 64);
1677 assert(buffer_store->bo);
1679 if (type == VAEncCodedBufferType) {
1680 struct i965_coded_buffer_segment *coded_buffer_segment;
1682 dri_bo_map(buffer_store->bo, 1);
1683 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1684 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1685 coded_buffer_segment->base.bit_offset = 0;
1686 coded_buffer_segment->base.status = 0;
1687 coded_buffer_segment->base.buf = NULL;
1688 coded_buffer_segment->base.next = NULL;
1689 coded_buffer_segment->mapped = 0;
1690 coded_buffer_segment->codec = 0;
1691 dri_bo_unmap(buffer_store->bo);
1693 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1699 if (type == VAEncPackedHeaderDataBufferType) {
1700 msize = ALIGN(size, 4);
1703 buffer_store->buffer = malloc(msize * num_elements);
1704 assert(buffer_store->buffer);
1707 memcpy(buffer_store->buffer, data, size * num_elements);
1710 buffer_store->num_elements = obj_buffer->num_elements;
1711 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1712 i965_release_buffer_store(&buffer_store);
1715 return VA_STATUS_SUCCESS;
1719 i965_CreateBuffer(VADriverContextP ctx,
1720 VAContextID context, /* in */
1721 VABufferType type, /* in */
1722 unsigned int size, /* in */
1723 unsigned int num_elements, /* in */
1724 void *data, /* in */
1725 VABufferID *buf_id) /* out */
1727 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1732 i965_BufferSetNumElements(VADriverContextP ctx,
1733 VABufferID buf_id, /* in */
1734 unsigned int num_elements) /* in */
1736 struct i965_driver_data *i965 = i965_driver_data(ctx);
1737 struct object_buffer *obj_buffer = BUFFER(buf_id);
1738 VAStatus vaStatus = VA_STATUS_SUCCESS;
1740 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1742 if ((num_elements < 0) ||
1743 (num_elements > obj_buffer->max_num_elements)) {
1744 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1746 obj_buffer->num_elements = num_elements;
1747 if (obj_buffer->buffer_store != NULL) {
1748 obj_buffer->buffer_store->num_elements = num_elements;
1756 i965_MapBuffer(VADriverContextP ctx,
1757 VABufferID buf_id, /* in */
1758 void **pbuf) /* out */
1760 struct i965_driver_data *i965 = i965_driver_data(ctx);
1761 struct object_buffer *obj_buffer = BUFFER(buf_id);
1762 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1764 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
1765 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1766 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
1768 if (NULL != obj_buffer->buffer_store->bo) {
1769 unsigned int tiling, swizzle;
1771 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1773 if (tiling != I915_TILING_NONE)
1774 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1776 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1778 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
1779 *pbuf = obj_buffer->buffer_store->bo->virtual;
1781 if (obj_buffer->type == VAEncCodedBufferType) {
1783 unsigned char *buffer = NULL;
1784 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1786 if (!coded_buffer_segment->mapped) {
1787 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1789 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1791 if (coded_buffer_segment->codec == CODEC_H264) {
1792 delimiter0 = H264_DELIMITER0;
1793 delimiter1 = H264_DELIMITER1;
1794 delimiter2 = H264_DELIMITER2;
1795 delimiter3 = H264_DELIMITER3;
1796 delimiter4 = H264_DELIMITER4;
1797 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1798 delimiter0 = MPEG2_DELIMITER0;
1799 delimiter1 = MPEG2_DELIMITER1;
1800 delimiter2 = MPEG2_DELIMITER2;
1801 delimiter3 = MPEG2_DELIMITER3;
1802 delimiter4 = MPEG2_DELIMITER4;
1804 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
1807 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1808 if ((buffer[i] == delimiter0) &&
1809 (buffer[i + 1] == delimiter1) &&
1810 (buffer[i + 2] == delimiter2) &&
1811 (buffer[i + 3] == delimiter3) &&
1812 (buffer[i + 4] == delimiter4))
1816 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1817 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1820 coded_buffer_segment->base.size = i;
1821 coded_buffer_segment->mapped = 1;
1823 assert(coded_buffer_segment->base.buf);
1827 vaStatus = VA_STATUS_SUCCESS;
1828 } else if (NULL != obj_buffer->buffer_store->buffer) {
1829 *pbuf = obj_buffer->buffer_store->buffer;
1830 vaStatus = VA_STATUS_SUCCESS;
1837 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1839 struct i965_driver_data *i965 = i965_driver_data(ctx);
1840 struct object_buffer *obj_buffer = BUFFER(buf_id);
1841 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1843 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
1844 return VA_STATUS_ERROR_INVALID_BUFFER;
1846 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
1847 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
1848 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
1850 if (NULL != obj_buffer->buffer_store->bo) {
1851 unsigned int tiling, swizzle;
1853 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1855 if (tiling != I915_TILING_NONE)
1856 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1858 dri_bo_unmap(obj_buffer->buffer_store->bo);
1860 vaStatus = VA_STATUS_SUCCESS;
1861 } else if (NULL != obj_buffer->buffer_store->buffer) {
1863 vaStatus = VA_STATUS_SUCCESS;
1870 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1872 struct i965_driver_data *i965 = i965_driver_data(ctx);
1873 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1875 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1877 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1879 return VA_STATUS_SUCCESS;
1883 i965_BeginPicture(VADriverContextP ctx,
1884 VAContextID context,
1885 VASurfaceID render_target)
1887 struct i965_driver_data *i965 = i965_driver_data(ctx);
1888 struct object_context *obj_context = CONTEXT(context);
1889 struct object_surface *obj_surface = SURFACE(render_target);
1890 struct object_config *obj_config;
1894 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1895 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1896 obj_config = obj_context->obj_config;
1897 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1899 switch (obj_config->profile) {
1900 case VAProfileMPEG2Simple:
1901 case VAProfileMPEG2Main:
1902 vaStatus = VA_STATUS_SUCCESS;
1905 case VAProfileH264ConstrainedBaseline:
1906 case VAProfileH264Main:
1907 case VAProfileH264High:
1908 vaStatus = VA_STATUS_SUCCESS;
1911 case VAProfileVC1Simple:
1912 case VAProfileVC1Main:
1913 case VAProfileVC1Advanced:
1914 vaStatus = VA_STATUS_SUCCESS;
1917 case VAProfileJPEGBaseline:
1918 vaStatus = VA_STATUS_SUCCESS;
1922 vaStatus = VA_STATUS_SUCCESS;
1925 case VAProfileVP8Version0_3:
1926 vaStatus = VA_STATUS_SUCCESS;
1930 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
1934 if (obj_context->codec_type == CODEC_PROC) {
1935 obj_context->codec_state.proc.current_render_target = render_target;
1936 } else if (obj_context->codec_type == CODEC_ENC) {
1937 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1939 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
1940 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1943 obj_context->codec_state.encode.num_slice_params = 0;
1946 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1948 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1949 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1951 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1952 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1954 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1955 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1957 obj_context->codec_state.encode.num_slice_params_ext = 0;
1958 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
1959 obj_context->codec_state.encode.last_packed_header_type = 0;
1961 obj_context->codec_state.decode.current_render_target = render_target;
1962 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1963 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1964 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1965 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
1967 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
1968 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1969 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1972 obj_context->codec_state.decode.num_slice_params = 0;
1973 obj_context->codec_state.decode.num_slice_datas = 0;
1979 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
1981 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
1983 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1984 struct object_context *obj_context, \
1985 struct object_buffer *obj_buffer) \
1987 struct category##_state *category = &obj_context->codec_state.category; \
1988 i965_release_buffer_store(&category->member); \
1989 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
1990 return VA_STATUS_SUCCESS; \
1993 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
1995 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1996 struct object_context *obj_context, \
1997 struct object_buffer *obj_buffer) \
1999 struct category##_state *category = &obj_context->codec_state.category; \
2000 if (category->num_##member == category->max_##member) { \
2001 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2002 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2003 category->max_##member += NUM_SLICES; \
2005 i965_release_buffer_store(&category->member[category->num_##member]); \
2006 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2007 category->num_##member++; \
2008 return VA_STATUS_SUCCESS; \
2011 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2013 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2014 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2015 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2016 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2017 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2018 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2020 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2021 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2022 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2025 i965_decoder_render_picture(VADriverContextP ctx,
2026 VAContextID context,
2027 VABufferID *buffers,
2030 struct i965_driver_data *i965 = i965_driver_data(ctx);
2031 struct object_context *obj_context = CONTEXT(context);
2032 VAStatus vaStatus = VA_STATUS_SUCCESS;
2035 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2037 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2038 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2041 return VA_STATUS_ERROR_INVALID_BUFFER;
2043 switch (obj_buffer->type) {
2044 case VAPictureParameterBufferType:
2045 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2048 case VAIQMatrixBufferType:
2049 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2052 case VABitPlaneBufferType:
2053 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2056 case VASliceParameterBufferType:
2057 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2060 case VASliceDataBufferType:
2061 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2064 case VAHuffmanTableBufferType:
2065 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2068 case VAProbabilityBufferType:
2069 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2073 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2081 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2083 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2084 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2085 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2086 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2087 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2088 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2089 /* extended buffer */
2090 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2091 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2093 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2094 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2095 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2098 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2099 struct object_context *obj_context,
2100 struct object_buffer *obj_buffer,
2103 struct encode_state *encode = &obj_context->codec_state.encode;
2105 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2106 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2107 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2108 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2110 return VA_STATUS_SUCCESS;
2114 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2115 struct object_context *obj_context,
2116 struct object_buffer *obj_buffer,
2119 struct encode_state *encode = &obj_context->codec_state.encode;
2121 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2122 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2123 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2124 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2126 return VA_STATUS_SUCCESS;
2130 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2131 struct object_context *obj_context,
2132 struct object_buffer *obj_buffer)
2134 struct encode_state *encode = &obj_context->codec_state.encode;
2135 VAEncMiscParameterBuffer *param = NULL;
2137 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2138 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2140 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2142 if (param->type >= ARRAY_ELEMS(encode->misc_param))
2143 return VA_STATUS_ERROR_INVALID_PARAMETER;
2145 i965_release_buffer_store(&encode->misc_param[param->type]);
2146 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2148 return VA_STATUS_SUCCESS;
2152 i965_encoder_render_picture(VADriverContextP ctx,
2153 VAContextID context,
2154 VABufferID *buffers,
2157 struct i965_driver_data *i965 = i965_driver_data(ctx);
2158 struct object_context *obj_context = CONTEXT(context);
2159 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2162 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2164 for (i = 0; i < num_buffers; i++) {
2165 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2168 return VA_STATUS_ERROR_INVALID_BUFFER;
2170 switch (obj_buffer->type) {
2171 case VAQMatrixBufferType:
2172 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2175 case VAIQMatrixBufferType:
2176 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2179 case VAEncSequenceParameterBufferType:
2180 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2183 case VAEncPictureParameterBufferType:
2184 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2187 case VAEncSliceParameterBufferType:
2188 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2191 case VAEncPackedHeaderParameterBufferType:
2193 struct encode_state *encode = &obj_context->codec_state.encode;
2194 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2195 encode->last_packed_header_type = param->type;
2197 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2200 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2204 case VAEncPackedHeaderDataBufferType:
2206 struct encode_state *encode = &obj_context->codec_state.encode;
2208 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2209 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2210 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2211 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2212 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
2213 VA_STATUS_ERROR_ENCODING_ERROR);
2214 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2217 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2221 case VAEncMiscParameterBufferType:
2222 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2228 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2236 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2238 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2239 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2242 i965_proc_render_picture(VADriverContextP ctx,
2243 VAContextID context,
2244 VABufferID *buffers,
2247 struct i965_driver_data *i965 = i965_driver_data(ctx);
2248 struct object_context *obj_context = CONTEXT(context);
2249 VAStatus vaStatus = VA_STATUS_SUCCESS;
2252 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2254 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2255 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2258 return VA_STATUS_ERROR_INVALID_BUFFER;
2260 switch (obj_buffer->type) {
2261 case VAProcPipelineParameterBufferType:
2262 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2266 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2275 i965_RenderPicture(VADriverContextP ctx,
2276 VAContextID context,
2277 VABufferID *buffers,
2280 struct i965_driver_data *i965 = i965_driver_data(ctx);
2281 struct object_context *obj_context;
2282 struct object_config *obj_config;
2283 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2285 obj_context = CONTEXT(context);
2286 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2288 if (num_buffers <= 0)
2289 return VA_STATUS_ERROR_INVALID_PARAMETER;
2291 obj_config = obj_context->obj_config;
2292 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2294 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2295 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2296 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2297 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2299 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2306 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2308 struct i965_driver_data *i965 = i965_driver_data(ctx);
2309 struct object_context *obj_context = CONTEXT(context);
2310 struct object_config *obj_config;
2312 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2313 obj_config = obj_context->obj_config;
2314 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2316 if (obj_context->codec_type == CODEC_PROC) {
2317 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2318 } else if (obj_context->codec_type == CODEC_ENC) {
2319 ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2321 if (!(obj_context->codec_state.encode.pic_param ||
2322 obj_context->codec_state.encode.pic_param_ext)) {
2323 return VA_STATUS_ERROR_INVALID_PARAMETER;
2325 if (!(obj_context->codec_state.encode.seq_param ||
2326 obj_context->codec_state.encode.seq_param_ext)) {
2327 return VA_STATUS_ERROR_INVALID_PARAMETER;
2329 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2330 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2331 return VA_STATUS_ERROR_INVALID_PARAMETER;
2334 if (obj_context->codec_state.decode.pic_param == NULL) {
2335 return VA_STATUS_ERROR_INVALID_PARAMETER;
2337 if (obj_context->codec_state.decode.num_slice_params <=0) {
2338 return VA_STATUS_ERROR_INVALID_PARAMETER;
2340 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2341 return VA_STATUS_ERROR_INVALID_PARAMETER;
2344 if (obj_context->codec_state.decode.num_slice_params !=
2345 obj_context->codec_state.decode.num_slice_datas) {
2346 return VA_STATUS_ERROR_INVALID_PARAMETER;
2350 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
2351 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2355 i965_SyncSurface(VADriverContextP ctx,
2356 VASurfaceID render_target)
2358 struct i965_driver_data *i965 = i965_driver_data(ctx);
2359 struct object_surface *obj_surface = SURFACE(render_target);
2361 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2364 drm_intel_bo_wait_rendering(obj_surface->bo);
2366 return VA_STATUS_SUCCESS;
2370 i965_QuerySurfaceStatus(VADriverContextP ctx,
2371 VASurfaceID render_target,
2372 VASurfaceStatus *status) /* out */
2374 struct i965_driver_data *i965 = i965_driver_data(ctx);
2375 struct object_surface *obj_surface = SURFACE(render_target);
2377 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2379 if (obj_surface->bo) {
2380 if (drm_intel_bo_busy(obj_surface->bo)){
2381 *status = VASurfaceRendering;
2384 *status = VASurfaceReady;
2387 *status = VASurfaceReady;
2390 return VA_STATUS_SUCCESS;
2393 static VADisplayAttribute *
2394 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2396 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2399 if (!i965->display_attributes)
2402 for (i = 0; i < i965->num_display_attributes; i++) {
2403 if (i965->display_attributes[i].type == type)
2404 return &i965->display_attributes[i];
2410 i965_display_attributes_terminate(VADriverContextP ctx)
2412 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2414 if (i965->display_attributes) {
2415 free(i965->display_attributes);
2416 i965->display_attributes = NULL;
2417 i965->num_display_attributes = 0;
2422 i965_display_attributes_init(VADriverContextP ctx)
2424 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2426 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2427 i965->display_attributes = malloc(
2428 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2429 if (!i965->display_attributes)
2433 i965->display_attributes,
2434 i965_display_attributes,
2435 sizeof(i965_display_attributes)
2438 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2439 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2440 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2441 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2442 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2444 if (!i965->rotation_attrib ||
2445 !i965->brightness_attrib ||
2446 !i965->contrast_attrib ||
2447 !i965->hue_attrib ||
2448 !i965->saturation_attrib) {
2454 i965_display_attributes_terminate(ctx);
2459 * Query display attributes
2460 * The caller must provide a "attr_list" array that can hold at
2461 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2462 * returned in "attr_list" is returned in "num_attributes".
2465 i965_QueryDisplayAttributes(
2466 VADriverContextP ctx,
2467 VADisplayAttribute *attribs, /* out */
2468 int *num_attribs_ptr /* out */
2471 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2473 if (attribs && num_attribs > 0)
2474 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2476 if (num_attribs_ptr)
2477 *num_attribs_ptr = num_attribs;
2479 return VA_STATUS_SUCCESS;
2483 * Get display attributes
2484 * This function returns the current attribute values in "attr_list".
2485 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2486 * from vaQueryDisplayAttributes() can have their values retrieved.
2489 i965_GetDisplayAttributes(
2490 VADriverContextP ctx,
2491 VADisplayAttribute *attribs, /* inout */
2492 int num_attribs /* in */
2497 for (i = 0; i < num_attribs; i++) {
2498 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2500 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2501 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2502 dst_attrib->min_value = src_attrib->min_value;
2503 dst_attrib->max_value = src_attrib->max_value;
2504 dst_attrib->value = src_attrib->value;
2507 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2509 return VA_STATUS_SUCCESS;
2513 * Set display attributes
2514 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2515 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2516 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2519 i965_SetDisplayAttributes(
2520 VADriverContextP ctx,
2521 VADisplayAttribute *attribs, /* in */
2522 int num_attribs /* in */
2527 for (i = 0; i < num_attribs; i++) {
2528 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2530 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2532 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2534 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2537 if (src_attrib->value < dst_attrib->min_value ||
2538 src_attrib->value > dst_attrib->max_value)
2539 return VA_STATUS_ERROR_INVALID_PARAMETER;
2541 dst_attrib->value = src_attrib->value;
2542 /* XXX: track modified attributes through timestamps */
2544 return VA_STATUS_SUCCESS;
2548 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2549 VASurfaceID surface,
2550 void **buffer, /* out */
2551 unsigned int *stride) /* out */
2554 return VA_STATUS_ERROR_UNIMPLEMENTED;
2558 i965_destroy_heap(struct object_heap *heap,
2559 void (*func)(struct object_heap *heap, struct object_base *object))
2561 struct object_base *object;
2562 object_heap_iterator iter;
2564 object = object_heap_first(heap, &iter);
2570 object = object_heap_next(heap, &iter);
2573 object_heap_destroy(heap);
2578 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2581 i965_CreateImage(VADriverContextP ctx,
2582 VAImageFormat *format,
2585 VAImage *out_image) /* out */
2587 struct i965_driver_data *i965 = i965_driver_data(ctx);
2588 struct object_image *obj_image;
2589 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2591 unsigned int size2, size, awidth, aheight;
2593 out_image->image_id = VA_INVALID_ID;
2594 out_image->buf = VA_INVALID_ID;
2596 image_id = NEW_IMAGE_ID();
2597 if (image_id == VA_INVALID_ID)
2598 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2600 obj_image = IMAGE(image_id);
2602 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2603 obj_image->bo = NULL;
2604 obj_image->palette = NULL;
2605 obj_image->derived_surface = VA_INVALID_ID;
2607 VAImage * const image = &obj_image->image;
2608 image->image_id = image_id;
2609 image->buf = VA_INVALID_ID;
2611 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
2613 if ((format->fourcc == VA_FOURCC_YV12) ||
2614 (format->fourcc == VA_FOURCC_I420)) {
2615 if (awidth % 128 != 0) {
2616 awidth = ALIGN(width, 128);
2620 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
2621 size = awidth * aheight;
2622 size2 = (awidth / 2) * (aheight / 2);
2624 image->num_palette_entries = 0;
2625 image->entry_bytes = 0;
2626 memset(image->component_order, 0, sizeof(image->component_order));
2628 switch (format->fourcc) {
2629 case VA_FOURCC_IA44:
2630 case VA_FOURCC_AI44:
2631 image->num_planes = 1;
2632 image->pitches[0] = awidth;
2633 image->offsets[0] = 0;
2634 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2635 image->num_palette_entries = 16;
2636 image->entry_bytes = 3;
2637 image->component_order[0] = 'R';
2638 image->component_order[1] = 'G';
2639 image->component_order[2] = 'B';
2641 case VA_FOURCC_IA88:
2642 case VA_FOURCC_AI88:
2643 image->num_planes = 1;
2644 image->pitches[0] = awidth * 2;
2645 image->offsets[0] = 0;
2646 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2647 image->num_palette_entries = 256;
2648 image->entry_bytes = 3;
2649 image->component_order[0] = 'R';
2650 image->component_order[1] = 'G';
2651 image->component_order[2] = 'B';
2653 case VA_FOURCC_ARGB:
2654 case VA_FOURCC_ABGR:
2655 case VA_FOURCC_BGRA:
2656 case VA_FOURCC_RGBA:
2657 case VA_FOURCC_BGRX:
2658 case VA_FOURCC_RGBX:
2659 image->num_planes = 1;
2660 image->pitches[0] = awidth * 4;
2661 image->offsets[0] = 0;
2662 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2664 case VA_FOURCC_YV12:
2665 image->num_planes = 3;
2666 image->pitches[0] = awidth;
2667 image->offsets[0] = 0;
2668 image->pitches[1] = awidth / 2;
2669 image->offsets[1] = size;
2670 image->pitches[2] = awidth / 2;
2671 image->offsets[2] = size + size2;
2672 image->data_size = size + 2 * size2;
2674 case VA_FOURCC_I420:
2675 image->num_planes = 3;
2676 image->pitches[0] = awidth;
2677 image->offsets[0] = 0;
2678 image->pitches[1] = awidth / 2;
2679 image->offsets[1] = size;
2680 image->pitches[2] = awidth / 2;
2681 image->offsets[2] = size + size2;
2682 image->data_size = size + 2 * size2;
2684 case VA_FOURCC_422H:
2685 image->num_planes = 3;
2686 image->pitches[0] = awidth;
2687 image->offsets[0] = 0;
2688 image->pitches[1] = awidth / 2;
2689 image->offsets[1] = size;
2690 image->pitches[2] = awidth / 2;
2691 image->offsets[2] = size + (awidth / 2) * aheight;
2692 image->data_size = size + 2 * ((awidth / 2) * aheight);
2694 case VA_FOURCC_NV12:
2695 image->num_planes = 2;
2696 image->pitches[0] = awidth;
2697 image->offsets[0] = 0;
2698 image->pitches[1] = awidth;
2699 image->offsets[1] = size;
2700 image->data_size = size + 2 * size2;
2702 case VA_FOURCC_YUY2:
2703 case VA_FOURCC_UYVY:
2704 image->num_planes = 1;
2705 image->pitches[0] = awidth * 2;
2706 image->offsets[0] = 0;
2707 image->data_size = size * 2;
2713 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2714 image->data_size, 1, NULL, &image->buf);
2715 if (va_status != VA_STATUS_SUCCESS)
2718 struct object_buffer *obj_buffer = BUFFER(image->buf);
2721 !obj_buffer->buffer_store ||
2722 !obj_buffer->buffer_store->bo)
2723 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2725 obj_image->bo = obj_buffer->buffer_store->bo;
2726 dri_bo_reference(obj_image->bo);
2728 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2729 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2730 if (!obj_image->palette)
2734 image->image_id = image_id;
2735 image->format = *format;
2736 image->width = width;
2737 image->height = height;
2739 *out_image = *image;
2740 return VA_STATUS_SUCCESS;
2743 i965_DestroyImage(ctx, image_id);
2748 i965_check_alloc_surface_bo(VADriverContextP ctx,
2749 struct object_surface *obj_surface,
2751 unsigned int fourcc,
2752 unsigned int subsampling)
2754 struct i965_driver_data *i965 = i965_driver_data(ctx);
2755 int region_width, region_height;
2757 if (obj_surface->bo) {
2758 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2759 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2760 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
2761 return VA_STATUS_SUCCESS;
2764 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2765 obj_surface->x_cr_offset = 0;
2767 if ((tiled && !obj_surface->user_disable_tiling)) {
2768 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
2769 fourcc != VA_FOURCC_IYUV &&
2770 fourcc != VA_FOURCC_YV12,
2771 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2772 if (obj_surface->user_h_stride_set) {
2773 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
2775 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2777 if (obj_surface->user_v_stride_set) {
2778 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
2780 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2782 region_height = obj_surface->height;
2785 case VA_FOURCC_NV12:
2786 assert(subsampling == SUBSAMPLE_YUV420);
2787 obj_surface->cb_cr_pitch = obj_surface->width;
2788 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2789 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2790 obj_surface->y_cb_offset = obj_surface->height;
2791 obj_surface->y_cr_offset = obj_surface->height;
2792 region_width = obj_surface->width;
2793 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2797 case VA_FOURCC_IMC1:
2798 assert(subsampling == SUBSAMPLE_YUV420);
2799 obj_surface->cb_cr_pitch = obj_surface->width;
2800 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2801 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2802 obj_surface->y_cr_offset = obj_surface->height;
2803 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2804 region_width = obj_surface->width;
2805 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2809 case VA_FOURCC_IMC3:
2810 assert(subsampling == SUBSAMPLE_YUV420);
2811 obj_surface->cb_cr_pitch = obj_surface->width;
2812 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2813 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2814 obj_surface->y_cb_offset = obj_surface->height;
2815 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2816 region_width = obj_surface->width;
2817 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2821 case VA_FOURCC_422H:
2822 assert(subsampling == SUBSAMPLE_YUV422H);
2823 obj_surface->cb_cr_pitch = obj_surface->width;
2824 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2825 obj_surface->cb_cr_height = obj_surface->orig_height;
2826 obj_surface->y_cb_offset = obj_surface->height;
2827 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2828 region_width = obj_surface->width;
2829 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2833 case VA_FOURCC_422V:
2834 assert(subsampling == SUBSAMPLE_YUV422V);
2835 obj_surface->cb_cr_pitch = obj_surface->width;
2836 obj_surface->cb_cr_width = obj_surface->orig_width;
2837 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2838 obj_surface->y_cb_offset = obj_surface->height;
2839 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2840 region_width = obj_surface->width;
2841 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2845 case VA_FOURCC_411P:
2846 assert(subsampling == SUBSAMPLE_YUV411);
2847 obj_surface->cb_cr_pitch = obj_surface->width;
2848 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2849 obj_surface->cb_cr_height = obj_surface->orig_height;
2850 obj_surface->y_cb_offset = obj_surface->height;
2851 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2852 region_width = obj_surface->width;
2853 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2857 case VA_FOURCC_444P:
2858 assert(subsampling == SUBSAMPLE_YUV444);
2859 obj_surface->cb_cr_pitch = obj_surface->width;
2860 obj_surface->cb_cr_width = obj_surface->orig_width;
2861 obj_surface->cb_cr_height = obj_surface->orig_height;
2862 obj_surface->y_cb_offset = obj_surface->height;
2863 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2864 region_width = obj_surface->width;
2865 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2869 case VA_FOURCC_Y800:
2870 assert(subsampling == SUBSAMPLE_YUV400);
2871 obj_surface->cb_cr_pitch = obj_surface->width;
2872 obj_surface->cb_cr_width = 0;
2873 obj_surface->cb_cr_height = 0;
2874 obj_surface->y_cb_offset = obj_surface->height;
2875 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2876 region_width = obj_surface->width;
2877 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2881 case VA_FOURCC_YUY2:
2882 case VA_FOURCC_UYVY:
2883 assert(subsampling == SUBSAMPLE_YUV422H);
2884 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
2885 obj_surface->cb_cr_pitch = obj_surface->width;
2886 obj_surface->y_cb_offset = 0;
2887 obj_surface->y_cr_offset = 0;
2888 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2889 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2890 region_width = obj_surface->width;
2891 region_height = obj_surface->height;
2895 case VA_FOURCC_RGBA:
2896 case VA_FOURCC_RGBX:
2897 case VA_FOURCC_BGRA:
2898 case VA_FOURCC_BGRX:
2899 assert(subsampling == SUBSAMPLE_RGBX);
2901 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
2902 region_width = obj_surface->width;
2903 region_height = obj_surface->height;
2907 /* Never get here */
2908 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2912 assert(subsampling == SUBSAMPLE_YUV420 ||
2913 subsampling == SUBSAMPLE_YUV422H ||
2914 subsampling == SUBSAMPLE_YUV422V ||
2915 subsampling == SUBSAMPLE_RGBX);
2917 region_width = obj_surface->width;
2918 region_height = obj_surface->height;
2921 case VA_FOURCC_NV12:
2922 obj_surface->y_cb_offset = obj_surface->height;
2923 obj_surface->y_cr_offset = obj_surface->height;
2924 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2925 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2926 obj_surface->cb_cr_pitch = obj_surface->width;
2927 region_height = obj_surface->height + obj_surface->height / 2;
2930 case VA_FOURCC_YV16:
2931 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2932 obj_surface->cb_cr_height = obj_surface->orig_height;
2933 obj_surface->y_cr_offset = obj_surface->height;
2934 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
2935 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2936 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2939 case VA_FOURCC_YV12:
2940 case VA_FOURCC_I420:
2941 if (fourcc == VA_FOURCC_YV12) {
2942 obj_surface->y_cr_offset = obj_surface->height;
2943 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
2945 obj_surface->y_cb_offset = obj_surface->height;
2946 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
2949 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2950 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2951 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2952 region_height = obj_surface->height + obj_surface->height / 2;
2955 case VA_FOURCC_YUY2:
2956 case VA_FOURCC_UYVY:
2957 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
2958 obj_surface->y_cb_offset = 0;
2959 obj_surface->y_cr_offset = 0;
2960 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2961 obj_surface->cb_cr_height = obj_surface->orig_height;
2962 obj_surface->cb_cr_pitch = obj_surface->width;
2963 region_width = obj_surface->width;
2964 region_height = obj_surface->height;
2966 case VA_FOURCC_RGBA:
2967 case VA_FOURCC_RGBX:
2968 case VA_FOURCC_BGRA:
2969 case VA_FOURCC_BGRX:
2970 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
2971 region_width = obj_surface->width;
2972 region_height = obj_surface->height;
2976 /* Never get here */
2977 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2982 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
2984 if ((tiled && !obj_surface->user_disable_tiling)) {
2985 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
2986 unsigned long pitch;
2988 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
2996 assert(tiling_mode == I915_TILING_Y);
2997 assert(pitch == obj_surface->width);
2999 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
3005 obj_surface->fourcc = fourcc;
3006 obj_surface->subsampling = subsampling;
3007 assert(obj_surface->bo);
3008 return VA_STATUS_SUCCESS;
3011 VAStatus i965_DeriveImage(VADriverContextP ctx,
3012 VASurfaceID surface,
3013 VAImage *out_image) /* out */
3015 struct i965_driver_data *i965 = i965_driver_data(ctx);
3016 struct object_image *obj_image;
3017 struct object_surface *obj_surface;
3019 unsigned int w_pitch;
3020 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3022 out_image->image_id = VA_INVALID_ID;
3023 obj_surface = SURFACE(surface);
3026 return VA_STATUS_ERROR_INVALID_SURFACE;
3028 if (!obj_surface->bo) {
3029 unsigned int is_tiled = 0;
3030 unsigned int fourcc = VA_FOURCC_YV12;
3031 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3032 int sampling = get_sampling_from_fourcc(fourcc);
3033 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3034 if (va_status != VA_STATUS_SUCCESS)
3038 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3040 w_pitch = obj_surface->width;
3042 image_id = NEW_IMAGE_ID();
3044 if (image_id == VA_INVALID_ID)
3045 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3047 obj_image = IMAGE(image_id);
3050 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3052 obj_image->bo = NULL;
3053 obj_image->palette = NULL;
3054 obj_image->derived_surface = VA_INVALID_ID;
3056 VAImage * const image = &obj_image->image;
3058 memset(image, 0, sizeof(*image));
3059 image->image_id = image_id;
3060 image->buf = VA_INVALID_ID;
3061 image->num_palette_entries = 0;
3062 image->entry_bytes = 0;
3063 image->width = obj_surface->orig_width;
3064 image->height = obj_surface->orig_height;
3065 image->data_size = obj_surface->size;
3067 image->format.fourcc = obj_surface->fourcc;
3068 image->format.byte_order = VA_LSB_FIRST;
3069 image->format.bits_per_pixel = 12;
3071 switch (image->format.fourcc) {
3072 case VA_FOURCC_YV12:
3073 image->num_planes = 3;
3074 image->pitches[0] = w_pitch; /* Y */
3075 image->offsets[0] = 0;
3076 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3077 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3078 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3079 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3082 case VA_FOURCC_YV16:
3083 image->num_planes = 3;
3084 image->pitches[0] = w_pitch; /* Y */
3085 image->offsets[0] = 0;
3086 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3087 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3088 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3089 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3092 case VA_FOURCC_NV12:
3093 image->num_planes = 2;
3094 image->pitches[0] = w_pitch; /* Y */
3095 image->offsets[0] = 0;
3096 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3097 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3100 case VA_FOURCC_I420:
3101 case VA_FOURCC_422H:
3102 case VA_FOURCC_IMC3:
3103 case VA_FOURCC_444P:
3104 case VA_FOURCC_422V:
3105 case VA_FOURCC_411P:
3106 image->num_planes = 3;
3107 image->pitches[0] = w_pitch; /* Y */
3108 image->offsets[0] = 0;
3109 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3110 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3111 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3112 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3115 case VA_FOURCC_YUY2:
3116 case VA_FOURCC_UYVY:
3117 case VA_FOURCC_Y800:
3118 image->num_planes = 1;
3119 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
3120 image->offsets[0] = 0;
3122 case VA_FOURCC_RGBA:
3123 case VA_FOURCC_RGBX:
3124 case VA_FOURCC_BGRA:
3125 case VA_FOURCC_BGRX:
3126 image->num_planes = 1;
3127 image->pitches[0] = obj_surface->width;
3133 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3134 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3135 if (va_status != VA_STATUS_SUCCESS)
3138 struct object_buffer *obj_buffer = BUFFER(image->buf);
3141 !obj_buffer->buffer_store ||
3142 !obj_buffer->buffer_store->bo)
3143 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3145 obj_image->bo = obj_buffer->buffer_store->bo;
3146 dri_bo_reference(obj_image->bo);
3148 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3149 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3150 if (!obj_image->palette) {
3151 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3156 *out_image = *image;
3157 obj_surface->flags |= SURFACE_DERIVED;
3158 obj_image->derived_surface = surface;
3160 return VA_STATUS_SUCCESS;
3163 i965_DestroyImage(ctx, image_id);
3168 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3170 object_heap_free(heap, obj);
3175 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3177 struct i965_driver_data *i965 = i965_driver_data(ctx);
3178 struct object_image *obj_image = IMAGE(image);
3179 struct object_surface *obj_surface;
3182 return VA_STATUS_SUCCESS;
3184 dri_bo_unreference(obj_image->bo);
3185 obj_image->bo = NULL;
3187 if (obj_image->image.buf != VA_INVALID_ID) {
3188 i965_DestroyBuffer(ctx, obj_image->image.buf);
3189 obj_image->image.buf = VA_INVALID_ID;
3192 if (obj_image->palette) {
3193 free(obj_image->palette);
3194 obj_image->palette = NULL;
3197 obj_surface = SURFACE(obj_image->derived_surface);
3200 obj_surface->flags &= ~SURFACE_DERIVED;
3203 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3205 return VA_STATUS_SUCCESS;
3209 * pointer to an array holding the palette data. The size of the array is
3210 * num_palette_entries * entry_bytes in size. The order of the components
3211 * in the palette is described by the component_order in VASubpicture struct
3214 i965_SetImagePalette(VADriverContextP ctx,
3216 unsigned char *palette)
3218 struct i965_driver_data *i965 = i965_driver_data(ctx);
3221 struct object_image *obj_image = IMAGE(image);
3223 return VA_STATUS_ERROR_INVALID_IMAGE;
3225 if (!obj_image->palette)
3226 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3228 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3229 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3230 ((unsigned int)palette[3*i + 1] << 8) |
3231 (unsigned int)palette[3*i + 2]);
3232 return VA_STATUS_SUCCESS;
3236 get_sampling_from_fourcc(unsigned int fourcc)
3238 int surface_sampling = -1;
3241 case VA_FOURCC_NV12:
3242 case VA_FOURCC_YV12:
3243 case VA_FOURCC_I420:
3244 case VA_FOURCC_IYUV:
3245 case VA_FOURCC_IMC1:
3246 case VA_FOURCC_IMC3:
3247 surface_sampling = SUBSAMPLE_YUV420;
3249 case VA_FOURCC_YUY2:
3250 case VA_FOURCC_UYVY:
3251 case VA_FOURCC_422H:
3252 case VA_FOURCC_YV16:
3253 surface_sampling = SUBSAMPLE_YUV422H;
3255 case VA_FOURCC_422V:
3256 surface_sampling = SUBSAMPLE_YUV422V;
3259 case VA_FOURCC_444P:
3260 surface_sampling = SUBSAMPLE_YUV444;
3263 case VA_FOURCC_411P:
3264 surface_sampling = SUBSAMPLE_YUV411;
3267 case VA_FOURCC_Y800:
3268 surface_sampling = SUBSAMPLE_YUV400;
3270 case VA_FOURCC_RGBA:
3271 case VA_FOURCC_RGBX:
3272 case VA_FOURCC_BGRA:
3273 case VA_FOURCC_BGRX:
3274 surface_sampling = SUBSAMPLE_RGBX;
3277 /* Never get here */
3283 return surface_sampling;
3287 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3288 const uint8_t *src, unsigned int src_stride,
3289 unsigned int len, unsigned int height)
3293 for (i = 0; i < height; i++) {
3294 memcpy(dst, src, len);
3301 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3302 struct object_surface *obj_surface,
3303 const VARectangle *rect)
3305 uint8_t *dst[3], *src[3];
3307 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3308 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3309 unsigned int tiling, swizzle;
3310 VAStatus va_status = VA_STATUS_SUCCESS;
3312 if (!obj_surface->bo)
3313 return VA_STATUS_ERROR_INVALID_SURFACE;
3315 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3316 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3318 if (tiling != I915_TILING_NONE)
3319 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3321 dri_bo_map(obj_surface->bo, 0);
3323 if (!obj_surface->bo->virtual)
3324 return VA_STATUS_ERROR_INVALID_SURFACE;
3326 /* Dest VA image has either I420 or YV12 format.
3327 Source VA surface alway has I420 format */
3328 dst[Y] = image_data + obj_image->image.offsets[Y];
3329 src[0] = (uint8_t *)obj_surface->bo->virtual;
3330 dst[U] = image_data + obj_image->image.offsets[U];
3331 src[1] = src[0] + obj_surface->width * obj_surface->height;
3332 dst[V] = image_data + obj_image->image.offsets[V];
3333 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3336 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3337 src[0] += rect->y * obj_surface->width + rect->x;
3338 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3339 src[0], obj_surface->width,
3340 rect->width, rect->height);
3343 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3344 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3345 memcpy_pic(dst[U], obj_image->image.pitches[U],
3346 src[1], obj_surface->width / 2,
3347 rect->width / 2, rect->height / 2);
3350 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3351 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3352 memcpy_pic(dst[V], obj_image->image.pitches[V],
3353 src[2], obj_surface->width / 2,
3354 rect->width / 2, rect->height / 2);
3356 if (tiling != I915_TILING_NONE)
3357 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3359 dri_bo_unmap(obj_surface->bo);
3365 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3366 struct object_surface *obj_surface,
3367 const VARectangle *rect)
3369 uint8_t *dst[2], *src[2];
3370 unsigned int tiling, swizzle;
3371 VAStatus va_status = VA_STATUS_SUCCESS;
3373 if (!obj_surface->bo)
3374 return VA_STATUS_ERROR_INVALID_SURFACE;
3376 assert(obj_surface->fourcc);
3377 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3379 if (tiling != I915_TILING_NONE)
3380 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3382 dri_bo_map(obj_surface->bo, 0);
3384 if (!obj_surface->bo->virtual)
3385 return VA_STATUS_ERROR_INVALID_SURFACE;
3387 /* Both dest VA image and source surface have NV12 format */
3388 dst[0] = image_data + obj_image->image.offsets[0];
3389 src[0] = (uint8_t *)obj_surface->bo->virtual;
3390 dst[1] = image_data + obj_image->image.offsets[1];
3391 src[1] = src[0] + obj_surface->width * obj_surface->height;
3394 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3395 src[0] += rect->y * obj_surface->width + rect->x;
3396 memcpy_pic(dst[0], obj_image->image.pitches[0],
3397 src[0], obj_surface->width,
3398 rect->width, rect->height);
3401 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3402 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3403 memcpy_pic(dst[1], obj_image->image.pitches[1],
3404 src[1], obj_surface->width,
3405 rect->width, rect->height / 2);
3407 if (tiling != I915_TILING_NONE)
3408 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3410 dri_bo_unmap(obj_surface->bo);
3416 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3417 struct object_surface *obj_surface,
3418 const VARectangle *rect)
3421 unsigned int tiling, swizzle;
3422 VAStatus va_status = VA_STATUS_SUCCESS;
3424 if (!obj_surface->bo)
3425 return VA_STATUS_ERROR_INVALID_SURFACE;
3427 assert(obj_surface->fourcc);
3428 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3430 if (tiling != I915_TILING_NONE)
3431 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3433 dri_bo_map(obj_surface->bo, 0);
3435 if (!obj_surface->bo->virtual)
3436 return VA_STATUS_ERROR_INVALID_SURFACE;
3438 /* Both dest VA image and source surface have YUYV format */
3439 dst = image_data + obj_image->image.offsets[0];
3440 src = (uint8_t *)obj_surface->bo->virtual;
3443 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3444 src += rect->y * obj_surface->width + rect->x*2;
3445 memcpy_pic(dst, obj_image->image.pitches[0],
3446 src, obj_surface->width*2,
3447 rect->width*2, rect->height);
3449 if (tiling != I915_TILING_NONE)
3450 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3452 dri_bo_unmap(obj_surface->bo);
3458 i965_sw_getimage(VADriverContextP ctx,
3459 VASurfaceID surface,
3460 int x, /* coordinates of the upper left source pixel */
3462 unsigned int width, /* width and height of the region */
3463 unsigned int height,
3466 struct i965_driver_data *i965 = i965_driver_data(ctx);
3467 struct i965_render_state *render_state = &i965->render_state;
3468 VAStatus va_status = VA_STATUS_SUCCESS;
3470 struct object_surface *obj_surface = SURFACE(surface);
3472 return VA_STATUS_ERROR_INVALID_SURFACE;
3474 struct object_image *obj_image = IMAGE(image);
3476 return VA_STATUS_ERROR_INVALID_IMAGE;
3479 return VA_STATUS_ERROR_INVALID_PARAMETER;
3480 if (x + width > obj_surface->orig_width ||
3481 y + height > obj_surface->orig_height)
3482 return VA_STATUS_ERROR_INVALID_PARAMETER;
3483 if (x + width > obj_image->image.width ||
3484 y + height > obj_image->image.height)
3485 return VA_STATUS_ERROR_INVALID_PARAMETER;
3487 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3488 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3490 void *image_data = NULL;
3492 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3493 if (va_status != VA_STATUS_SUCCESS)
3500 rect.height = height;
3502 switch (obj_image->image.format.fourcc) {
3503 case VA_FOURCC_YV12:
3504 case VA_FOURCC_I420:
3505 /* I420 is native format for MPEG-2 decoded surfaces */
3506 if (render_state->interleaved_uv)
3507 goto operation_failed;
3508 get_image_i420(obj_image, image_data, obj_surface, &rect);
3510 case VA_FOURCC_NV12:
3511 /* NV12 is native format for H.264 decoded surfaces */
3512 if (!render_state->interleaved_uv)
3513 goto operation_failed;
3514 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3516 case VA_FOURCC_YUY2:
3517 /* YUY2 is the format supported by overlay plane */
3518 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3522 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3526 if (va_status != VA_STATUS_SUCCESS)
3529 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3534 i965_hw_getimage(VADriverContextP ctx,
3535 VASurfaceID surface,
3536 int x, /* coordinates of the upper left source pixel */
3538 unsigned int width, /* width and height of the region */
3539 unsigned int height,
3542 struct i965_driver_data *i965 = i965_driver_data(ctx);
3543 struct i965_surface src_surface;
3544 struct i965_surface dst_surface;
3545 VAStatus va_status = VA_STATUS_SUCCESS;
3547 struct object_surface *obj_surface = SURFACE(surface);
3548 struct object_image *obj_image = IMAGE(image);
3551 return VA_STATUS_ERROR_INVALID_SURFACE;
3554 return VA_STATUS_ERROR_INVALID_IMAGE;
3557 return VA_STATUS_ERROR_INVALID_PARAMETER;
3558 if (x + width > obj_surface->orig_width ||
3559 y + height > obj_surface->orig_height)
3560 return VA_STATUS_ERROR_INVALID_PARAMETER;
3561 if (x + width > obj_image->image.width ||
3562 y + height > obj_image->image.height)
3563 return VA_STATUS_ERROR_INVALID_PARAMETER;
3565 if (!obj_surface->bo)
3566 return VA_STATUS_SUCCESS;
3567 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3572 rect.height = height;
3574 src_surface.base = (struct object_base *)obj_surface;
3575 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3576 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3578 dst_surface.base = (struct object_base *)obj_image;
3579 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3580 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3582 va_status = i965_image_processing(ctx,
3593 i965_GetImage(VADriverContextP ctx,
3594 VASurfaceID surface,
3595 int x, /* coordinates of the upper left source pixel */
3597 unsigned int width, /* width and height of the region */
3598 unsigned int height,
3601 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3602 VAStatus va_status = VA_STATUS_SUCCESS;
3604 if (HAS_ACCELERATED_GETIMAGE(i965))
3605 va_status = i965_hw_getimage(ctx,
3611 va_status = i965_sw_getimage(ctx,
3621 put_image_i420(struct object_surface *obj_surface,
3622 const VARectangle *dst_rect,
3623 struct object_image *obj_image, uint8_t *image_data,
3624 const VARectangle *src_rect)
3626 uint8_t *dst[3], *src[3];
3628 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3629 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3630 unsigned int tiling, swizzle;
3631 VAStatus va_status = VA_STATUS_SUCCESS;
3633 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3635 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3636 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3637 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3638 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3640 if (tiling != I915_TILING_NONE)
3641 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3643 dri_bo_map(obj_surface->bo, 0);
3645 if (!obj_surface->bo->virtual)
3646 return VA_STATUS_ERROR_INVALID_SURFACE;
3648 /* Dest VA image has either I420 or YV12 format.
3649 Source VA surface alway has I420 format */
3650 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3651 src[Y] = image_data + obj_image->image.offsets[Y];
3652 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3653 src[U] = image_data + obj_image->image.offsets[U];
3654 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3655 src[V] = image_data + obj_image->image.offsets[V];
3658 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3659 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3660 memcpy_pic(dst[0], obj_surface->width,
3661 src[Y], obj_image->image.pitches[Y],
3662 src_rect->width, src_rect->height);
3665 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3666 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3667 memcpy_pic(dst[1], obj_surface->width / 2,
3668 src[U], obj_image->image.pitches[U],
3669 src_rect->width / 2, src_rect->height / 2);
3672 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3673 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3674 memcpy_pic(dst[2], obj_surface->width / 2,
3675 src[V], obj_image->image.pitches[V],
3676 src_rect->width / 2, src_rect->height / 2);
3678 if (tiling != I915_TILING_NONE)
3679 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3681 dri_bo_unmap(obj_surface->bo);
3687 put_image_nv12(struct object_surface *obj_surface,
3688 const VARectangle *dst_rect,
3689 struct object_image *obj_image, uint8_t *image_data,
3690 const VARectangle *src_rect)
3692 uint8_t *dst[2], *src[2];
3693 unsigned int tiling, swizzle;
3694 VAStatus va_status = VA_STATUS_SUCCESS;
3696 if (!obj_surface->bo)
3697 return VA_STATUS_ERROR_INVALID_SURFACE;
3699 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3700 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3701 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3702 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3704 if (tiling != I915_TILING_NONE)
3705 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3707 dri_bo_map(obj_surface->bo, 0);
3709 if (!obj_surface->bo->virtual)
3710 return VA_STATUS_ERROR_INVALID_SURFACE;
3712 /* Both dest VA image and source surface have NV12 format */
3713 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3714 src[0] = image_data + obj_image->image.offsets[0];
3715 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3716 src[1] = image_data + obj_image->image.offsets[1];
3719 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3720 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3721 memcpy_pic(dst[0], obj_surface->width,
3722 src[0], obj_image->image.pitches[0],
3723 src_rect->width, src_rect->height);
3726 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3727 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3728 memcpy_pic(dst[1], obj_surface->width,
3729 src[1], obj_image->image.pitches[1],
3730 src_rect->width, src_rect->height / 2);
3732 if (tiling != I915_TILING_NONE)
3733 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3735 dri_bo_unmap(obj_surface->bo);
3741 put_image_yuy2(struct object_surface *obj_surface,
3742 const VARectangle *dst_rect,
3743 struct object_image *obj_image, uint8_t *image_data,
3744 const VARectangle *src_rect)
3747 unsigned int tiling, swizzle;
3748 VAStatus va_status = VA_STATUS_SUCCESS;
3750 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3751 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3752 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3753 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3754 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3756 if (tiling != I915_TILING_NONE)
3757 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3759 dri_bo_map(obj_surface->bo, 0);
3761 if (!obj_surface->bo->virtual)
3762 return VA_STATUS_ERROR_INVALID_SURFACE;
3764 /* Both dest VA image and source surface have YUY2 format */
3765 dst = (uint8_t *)obj_surface->bo->virtual;
3766 src = image_data + obj_image->image.offsets[0];
3768 /* YUYV packed plane */
3769 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3770 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3771 memcpy_pic(dst, obj_surface->width*2,
3772 src, obj_image->image.pitches[0],
3773 src_rect->width*2, src_rect->height);
3775 if (tiling != I915_TILING_NONE)
3776 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3778 dri_bo_unmap(obj_surface->bo);
3785 i965_sw_putimage(VADriverContextP ctx,
3786 VASurfaceID surface,
3790 unsigned int src_width,
3791 unsigned int src_height,
3794 unsigned int dest_width,
3795 unsigned int dest_height)
3797 struct i965_driver_data *i965 = i965_driver_data(ctx);
3798 struct object_surface *obj_surface = SURFACE(surface);
3799 struct object_image *obj_image = IMAGE(image);
3800 VAStatus va_status = VA_STATUS_SUCCESS;
3801 void *image_data = NULL;
3803 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3804 ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE);
3806 if (src_x < 0 || src_y < 0)
3807 return VA_STATUS_ERROR_INVALID_PARAMETER;
3808 if (src_x + src_width > obj_image->image.width ||
3809 src_y + src_height > obj_image->image.height)
3810 return VA_STATUS_ERROR_INVALID_PARAMETER;
3811 if (dest_x < 0 || dest_y < 0)
3812 return VA_STATUS_ERROR_INVALID_PARAMETER;
3813 if (dest_x + dest_width > obj_surface->orig_width ||
3814 dest_y + dest_height > obj_surface->orig_height)
3815 return VA_STATUS_ERROR_INVALID_PARAMETER;
3817 /* XXX: don't allow scaling */
3818 if (src_width != dest_width || src_height != dest_height)
3819 return VA_STATUS_ERROR_INVALID_PARAMETER;
3821 if (obj_surface->fourcc) {
3822 /* Don't allow format mismatch */
3823 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3824 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3828 /* VA is surface not used for decoding, use same VA image format */
3829 va_status = i965_check_alloc_surface_bo(
3832 0, /* XXX: don't use tiled surface */
3833 obj_image->image.format.fourcc,
3834 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3837 if (va_status != VA_STATUS_SUCCESS)
3840 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3841 if (va_status != VA_STATUS_SUCCESS)
3844 VARectangle src_rect, dest_rect;
3847 src_rect.width = src_width;
3848 src_rect.height = src_height;
3849 dest_rect.x = dest_x;
3850 dest_rect.y = dest_y;
3851 dest_rect.width = dest_width;
3852 dest_rect.height = dest_height;
3854 switch (obj_image->image.format.fourcc) {
3855 case VA_FOURCC_YV12:
3856 case VA_FOURCC_I420:
3857 va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3859 case VA_FOURCC_NV12:
3860 va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3862 case VA_FOURCC_YUY2:
3863 va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3866 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3869 if (va_status != VA_STATUS_SUCCESS)
3872 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3877 i965_hw_putimage(VADriverContextP ctx,
3878 VASurfaceID surface,
3882 unsigned int src_width,
3883 unsigned int src_height,
3886 unsigned int dest_width,
3887 unsigned int dest_height)
3889 struct i965_driver_data *i965 = i965_driver_data(ctx);
3890 struct object_surface *obj_surface = SURFACE(surface);
3891 struct object_image *obj_image = IMAGE(image);
3892 struct i965_surface src_surface, dst_surface;
3893 VAStatus va_status = VA_STATUS_SUCCESS;
3894 VARectangle src_rect, dst_rect;
3896 ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE);
3897 ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE);
3901 src_x + src_width > obj_image->image.width ||
3902 src_y + src_height > obj_image->image.height)
3903 return VA_STATUS_ERROR_INVALID_PARAMETER;
3907 dest_x + dest_width > obj_surface->orig_width ||
3908 dest_y + dest_height > obj_surface->orig_height)
3909 return VA_STATUS_ERROR_INVALID_PARAMETER;
3911 if (!obj_surface->bo) {
3912 unsigned int tiling, swizzle;
3913 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3914 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3916 i965_check_alloc_surface_bo(ctx,
3919 obj_image->image.format.fourcc,
3923 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3925 src_surface.base = (struct object_base *)obj_image;
3926 src_surface.type = I965_SURFACE_TYPE_IMAGE;
3927 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3930 src_rect.width = src_width;
3931 src_rect.height = src_height;
3933 dst_surface.base = (struct object_base *)obj_surface;
3934 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3935 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3936 dst_rect.x = dest_x;
3937 dst_rect.y = dest_y;
3938 dst_rect.width = dest_width;
3939 dst_rect.height = dest_height;
3941 va_status = i965_image_processing(ctx,
3951 i965_PutImage(VADriverContextP ctx,
3952 VASurfaceID surface,
3956 unsigned int src_width,
3957 unsigned int src_height,
3960 unsigned int dest_width,
3961 unsigned int dest_height)
3963 struct i965_driver_data *i965 = i965_driver_data(ctx);
3964 VAStatus va_status = VA_STATUS_SUCCESS;
3966 if (HAS_ACCELERATED_PUTIMAGE(i965))
3967 va_status = i965_hw_putimage(ctx,
3979 va_status = i965_sw_putimage(ctx,
3995 i965_PutSurface(VADriverContextP ctx,
3996 VASurfaceID surface,
3997 void *draw, /* X Drawable */
4000 unsigned short srcw,
4001 unsigned short srch,
4004 unsigned short destw,
4005 unsigned short desth,
4006 VARectangle *cliprects, /* client supplied clip list */
4007 unsigned int number_cliprects, /* number of clip rects in the clip list */
4008 unsigned int flags) /* de-interlacing flags */
4011 if (IS_VA_X11(ctx)) {
4012 VARectangle src_rect, dst_rect;
4016 src_rect.width = srcw;
4017 src_rect.height = srch;
4021 dst_rect.width = destw;
4022 dst_rect.height = desth;
4024 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
4025 cliprects, number_cliprects, flags);
4028 return VA_STATUS_ERROR_UNIMPLEMENTED;
4033 VADriverContextP ctx, /* in */
4034 VABufferID buf_id, /* in */
4035 VABufferType *type, /* out */
4036 unsigned int *size, /* out */
4037 unsigned int *num_elements /* out */
4040 struct i965_driver_data *i965 = NULL;
4041 struct object_buffer *obj_buffer = NULL;
4043 i965 = i965_driver_data(ctx);
4044 obj_buffer = BUFFER(buf_id);
4046 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
4048 *type = obj_buffer->type;
4049 *size = obj_buffer->size_element;
4050 *num_elements = obj_buffer->num_elements;
4052 return VA_STATUS_SUCCESS;
4057 VADriverContextP ctx, /* in */
4058 VASurfaceID surface, /* in */
4059 unsigned int *fourcc, /* out */
4060 unsigned int *luma_stride, /* out */
4061 unsigned int *chroma_u_stride, /* out */
4062 unsigned int *chroma_v_stride, /* out */
4063 unsigned int *luma_offset, /* out */
4064 unsigned int *chroma_u_offset, /* out */
4065 unsigned int *chroma_v_offset, /* out */
4066 unsigned int *buffer_name, /* out */
4067 void **buffer /* out */
4070 VAStatus vaStatus = VA_STATUS_SUCCESS;
4071 struct i965_driver_data *i965 = i965_driver_data(ctx);
4072 struct object_surface *obj_surface = NULL;
4075 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
4076 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4077 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4078 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4079 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4080 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4081 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4082 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
4083 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
4085 tmpImage.image_id = VA_INVALID_ID;
4087 obj_surface = SURFACE(surface);
4088 if (obj_surface == NULL) {
4089 // Surface is absent.
4090 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4094 // Lock functionality is absent now.
4095 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4096 // Surface is locked already.
4097 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4101 vaStatus = i965_DeriveImage(
4105 if (vaStatus != VA_STATUS_SUCCESS) {
4109 obj_surface->locked_image_id = tmpImage.image_id;
4111 vaStatus = i965_MapBuffer(
4115 if (vaStatus != VA_STATUS_SUCCESS) {
4119 *fourcc = tmpImage.format.fourcc;
4120 *luma_offset = tmpImage.offsets[0];
4121 *luma_stride = tmpImage.pitches[0];
4122 *chroma_u_offset = tmpImage.offsets[1];
4123 *chroma_u_stride = tmpImage.pitches[1];
4124 *chroma_v_offset = tmpImage.offsets[2];
4125 *chroma_v_stride = tmpImage.pitches[2];
4126 *buffer_name = tmpImage.buf;
4129 if (vaStatus != VA_STATUS_SUCCESS) {
4138 VADriverContextP ctx, /* in */
4139 VASurfaceID surface /* in */
4142 VAStatus vaStatus = VA_STATUS_SUCCESS;
4143 struct i965_driver_data *i965 = i965_driver_data(ctx);
4144 struct object_image *locked_img = NULL;
4145 struct object_surface *obj_surface = NULL;
4147 obj_surface = SURFACE(surface);
4149 if (obj_surface == NULL) {
4150 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4153 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4154 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4158 locked_img = IMAGE(obj_surface->locked_image_id);
4159 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4160 // Work image was deallocated before i965_UnlockSurface()
4161 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4165 vaStatus = i965_UnmapBuffer(
4167 locked_img->image.buf);
4168 if (vaStatus != VA_STATUS_SUCCESS) {
4172 vaStatus = i965_DestroyImage(
4174 locked_img->image.image_id);
4175 if (vaStatus != VA_STATUS_SUCCESS) {
4179 locked_img->image.image_id = VA_INVALID_ID;
4182 obj_surface->locked_image_id = VA_INVALID_ID;
4188 i965_GetSurfaceAttributes(
4189 VADriverContextP ctx,
4191 VASurfaceAttrib *attrib_list,
4192 unsigned int num_attribs
4195 VAStatus vaStatus = VA_STATUS_SUCCESS;
4196 struct i965_driver_data *i965 = i965_driver_data(ctx);
4197 struct object_config *obj_config;
4200 if (config == VA_INVALID_ID)
4201 return VA_STATUS_ERROR_INVALID_CONFIG;
4203 obj_config = CONFIG(config);
4205 if (obj_config == NULL)
4206 return VA_STATUS_ERROR_INVALID_CONFIG;
4208 if (attrib_list == NULL || num_attribs == 0)
4209 return VA_STATUS_ERROR_INVALID_PARAMETER;
4211 for (i = 0; i < num_attribs; i++) {
4212 switch (attrib_list[i].type) {
4213 case VASurfaceAttribPixelFormat:
4214 attrib_list[i].value.type = VAGenericValueTypeInteger;
4215 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4217 if (attrib_list[i].value.value.i == 0) {
4218 if (IS_G4X(i965->intel.device_info)) {
4219 if (obj_config->profile == VAProfileMPEG2Simple ||
4220 obj_config->profile == VAProfileMPEG2Main) {
4221 attrib_list[i].value.value.i = VA_FOURCC_I420;
4224 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4226 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4227 if (obj_config->profile == VAProfileMPEG2Simple ||
4228 obj_config->profile == VAProfileMPEG2Main) {
4229 attrib_list[i].value.value.i = VA_FOURCC_I420;
4230 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4231 obj_config->profile == VAProfileH264Main ||
4232 obj_config->profile == VAProfileH264High) {
4233 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4234 } else if (obj_config->profile == VAProfileNone) {
4235 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4238 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4240 } else if (IS_GEN6(i965->intel.device_info)) {
4241 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4242 } else if (IS_GEN7(i965->intel.device_info) ||
4243 IS_GEN8(i965->intel.device_info)) {
4244 if (obj_config->profile == VAProfileJPEGBaseline)
4245 attrib_list[i].value.value.i = 0; /* internal format */
4247 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4250 if (IS_G4X(i965->intel.device_info)) {
4251 if (obj_config->profile == VAProfileMPEG2Simple ||
4252 obj_config->profile == VAProfileMPEG2Main) {
4253 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4254 attrib_list[i].value.value.i = 0;
4255 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4259 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4261 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4262 if (obj_config->profile == VAProfileMPEG2Simple ||
4263 obj_config->profile == VAProfileMPEG2Main) {
4264 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4265 attrib_list[i].value.value.i = 0;
4266 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4268 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4269 obj_config->profile == VAProfileH264Main ||
4270 obj_config->profile == VAProfileH264High) {
4271 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4272 attrib_list[i].value.value.i = 0;
4273 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4275 } else if (obj_config->profile == VAProfileNone) {
4276 switch (attrib_list[i].value.value.i) {
4277 case VA_FOURCC_NV12:
4278 case VA_FOURCC_I420:
4279 case VA_FOURCC_YV12:
4280 case VA_FOURCC_YUY2:
4281 case VA_FOURCC_BGRA:
4282 case VA_FOURCC_BGRX:
4283 case VA_FOURCC_RGBX:
4284 case VA_FOURCC_RGBA:
4287 attrib_list[i].value.value.i = 0;
4288 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4293 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4295 } else if (IS_GEN6(i965->intel.device_info)) {
4296 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4297 obj_config->entrypoint == VAEntrypointVideoProc) {
4298 switch (attrib_list[i].value.value.i) {
4299 case VA_FOURCC_NV12:
4300 case VA_FOURCC_I420:
4301 case VA_FOURCC_YV12:
4302 case VA_FOURCC_YUY2:
4303 case VA_FOURCC_BGRA:
4304 case VA_FOURCC_BGRX:
4305 case VA_FOURCC_RGBX:
4306 case VA_FOURCC_RGBA:
4309 attrib_list[i].value.value.i = 0;
4310 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4314 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4315 attrib_list[i].value.value.i = 0;
4316 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4319 } else if (IS_GEN7(i965->intel.device_info) ||
4320 IS_GEN8(i965->intel.device_info)) {
4321 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4322 obj_config->entrypoint == VAEntrypointVideoProc) {
4323 switch (attrib_list[i].value.value.i) {
4324 case VA_FOURCC_NV12:
4325 case VA_FOURCC_I420:
4326 case VA_FOURCC_YV12:
4329 attrib_list[i].value.value.i = 0;
4330 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4334 if (obj_config->profile == VAProfileJPEGBaseline) {
4335 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4336 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4338 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4339 attrib_list[i].value.value.i = 0;
4340 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4348 case VASurfaceAttribMinWidth:
4349 /* FIXME: add support for it later */
4350 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4352 case VASurfaceAttribMaxWidth:
4353 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4355 case VASurfaceAttribMinHeight:
4356 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4358 case VASurfaceAttribMaxHeight:
4359 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4362 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4371 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4373 VASurfaceAttrib *attrib_list,
4374 unsigned int *num_attribs)
4376 VAStatus vaStatus = VA_STATUS_SUCCESS;
4377 struct i965_driver_data *i965 = i965_driver_data(ctx);
4378 struct object_config *obj_config;
4380 VASurfaceAttrib *attribs = NULL;
4382 if (config == VA_INVALID_ID)
4383 return VA_STATUS_ERROR_INVALID_CONFIG;
4385 obj_config = CONFIG(config);
4387 if (obj_config == NULL)
4388 return VA_STATUS_ERROR_INVALID_CONFIG;
4390 if (!attrib_list && !num_attribs)
4391 return VA_STATUS_ERROR_INVALID_PARAMETER;
4393 if (attrib_list == NULL) {
4394 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4395 return VA_STATUS_SUCCESS;
4398 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4400 if (attribs == NULL)
4401 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4403 if (IS_G4X(i965->intel.device_info)) {
4404 if (obj_config->profile == VAProfileMPEG2Simple ||
4405 obj_config->profile == VAProfileMPEG2Main) {
4406 attribs[i].type = VASurfaceAttribPixelFormat;
4407 attribs[i].value.type = VAGenericValueTypeInteger;
4408 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4409 attribs[i].value.value.i = VA_FOURCC_I420;
4412 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4413 switch (obj_config->profile) {
4414 case VAProfileMPEG2Simple:
4415 case VAProfileMPEG2Main:
4416 attribs[i].type = VASurfaceAttribPixelFormat;
4417 attribs[i].value.type = VAGenericValueTypeInteger;
4418 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4419 attribs[i].value.value.i = VA_FOURCC_I420;
4424 case VAProfileH264ConstrainedBaseline:
4425 case VAProfileH264Main:
4426 case VAProfileH264High:
4427 attribs[i].type = VASurfaceAttribPixelFormat;
4428 attribs[i].value.type = VAGenericValueTypeInteger;
4429 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4430 attribs[i].value.value.i = VA_FOURCC_NV12;
4434 attribs[i].type = VASurfaceAttribPixelFormat;
4435 attribs[i].value.type = VAGenericValueTypeInteger;
4436 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4437 attribs[i].value.value.i = VA_FOURCC_NV12;
4440 attribs[i].type = VASurfaceAttribPixelFormat;
4441 attribs[i].value.type = VAGenericValueTypeInteger;
4442 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4443 attribs[i].value.value.i = VA_FOURCC_I420;
4451 } else if (IS_GEN6(i965->intel.device_info)) {
4452 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4453 attribs[i].type = VASurfaceAttribPixelFormat;
4454 attribs[i].value.type = VAGenericValueTypeInteger;
4455 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4456 attribs[i].value.value.i = VA_FOURCC_NV12;
4458 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4459 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4460 attribs[i].type = VASurfaceAttribPixelFormat;
4461 attribs[i].value.type = VAGenericValueTypeInteger;
4462 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4463 attribs[i].value.value.i = VA_FOURCC_NV12;
4466 attribs[i].type = VASurfaceAttribPixelFormat;
4467 attribs[i].value.type = VAGenericValueTypeInteger;
4468 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4469 attribs[i].value.value.i = VA_FOURCC_I420;
4472 attribs[i].type = VASurfaceAttribPixelFormat;
4473 attribs[i].value.type = VAGenericValueTypeInteger;
4474 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4475 attribs[i].value.value.i = VA_FOURCC_YV12;
4478 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4479 attribs[i].type = VASurfaceAttribPixelFormat;
4480 attribs[i].value.type = VAGenericValueTypeInteger;
4481 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4482 attribs[i].value.value.i = VA_FOURCC_YUY2;
4485 attribs[i].type = VASurfaceAttribPixelFormat;
4486 attribs[i].value.type = VAGenericValueTypeInteger;
4487 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4488 attribs[i].value.value.i = VA_FOURCC_RGBA;
4491 attribs[i].type = VASurfaceAttribPixelFormat;
4492 attribs[i].value.type = VAGenericValueTypeInteger;
4493 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4494 attribs[i].value.value.i = VA_FOURCC_RGBX;
4498 } else if (IS_GEN7(i965->intel.device_info)) {
4499 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4500 if (obj_config->profile == VAProfileJPEGBaseline) {
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_IMC3;
4507 attribs[i].type = VASurfaceAttribPixelFormat;
4508 attribs[i].value.type = VAGenericValueTypeInteger;
4509 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4510 attribs[i].value.value.i = VA_FOURCC_IMC1;
4513 attribs[i].type = VASurfaceAttribPixelFormat;
4514 attribs[i].value.type = VAGenericValueTypeInteger;
4515 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4516 attribs[i].value.value.i = VA_FOURCC_Y800;
4519 attribs[i].type = VASurfaceAttribPixelFormat;
4520 attribs[i].value.type = VAGenericValueTypeInteger;
4521 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4522 attribs[i].value.value.i = VA_FOURCC_411P;
4525 attribs[i].type = VASurfaceAttribPixelFormat;
4526 attribs[i].value.type = VAGenericValueTypeInteger;
4527 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4528 attribs[i].value.value.i = VA_FOURCC_422H;
4531 attribs[i].type = VASurfaceAttribPixelFormat;
4532 attribs[i].value.type = VAGenericValueTypeInteger;
4533 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4534 attribs[i].value.value.i = VA_FOURCC_422V;
4537 attribs[i].type = VASurfaceAttribPixelFormat;
4538 attribs[i].value.type = VAGenericValueTypeInteger;
4539 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4540 attribs[i].value.value.i = VA_FOURCC_444P;
4543 attribs[i].type = VASurfaceAttribPixelFormat;
4544 attribs[i].value.type = VAGenericValueTypeInteger;
4545 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4546 attribs[i].value.value.i = VA_FOURCC_NV12;
4549 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4550 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4551 attribs[i].type = VASurfaceAttribPixelFormat;
4552 attribs[i].value.type = VAGenericValueTypeInteger;
4553 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4554 attribs[i].value.value.i = VA_FOURCC_NV12;
4557 attribs[i].type = VASurfaceAttribPixelFormat;
4558 attribs[i].value.type = VAGenericValueTypeInteger;
4559 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4560 attribs[i].value.value.i = VA_FOURCC_I420;
4563 attribs[i].type = VASurfaceAttribPixelFormat;
4564 attribs[i].value.type = VAGenericValueTypeInteger;
4565 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4566 attribs[i].value.value.i = VA_FOURCC_YV12;
4569 attribs[i].type = VASurfaceAttribPixelFormat;
4570 attribs[i].value.type = VAGenericValueTypeInteger;
4571 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4572 attribs[i].value.value.i = VA_FOURCC_IMC3;
4575 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4576 attribs[i].type = VASurfaceAttribPixelFormat;
4577 attribs[i].value.type = VAGenericValueTypeInteger;
4578 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4579 attribs[i].value.value.i = VA_FOURCC_YUY2;
4582 attribs[i].type = VASurfaceAttribPixelFormat;
4583 attribs[i].value.type = VAGenericValueTypeInteger;
4584 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4585 attribs[i].value.value.i = VA_FOURCC_RGBA;
4588 attribs[i].type = VASurfaceAttribPixelFormat;
4589 attribs[i].value.type = VAGenericValueTypeInteger;
4590 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4591 attribs[i].value.value.i = VA_FOURCC_RGBX;
4594 attribs[i].type = VASurfaceAttribPixelFormat;
4595 attribs[i].value.type = VAGenericValueTypeInteger;
4596 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4597 attribs[i].value.value.i = VA_FOURCC_YV16;
4601 } else if (IS_GEN8(i965->intel.device_info)) {
4602 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4603 if (obj_config->profile == VAProfileJPEGBaseline) {
4604 attribs[i].type = VASurfaceAttribPixelFormat;
4605 attribs[i].value.type = VAGenericValueTypeInteger;
4606 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4607 attribs[i].value.value.i = VA_FOURCC_IMC3;
4610 attribs[i].type = VASurfaceAttribPixelFormat;
4611 attribs[i].value.type = VAGenericValueTypeInteger;
4612 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4613 attribs[i].value.value.i = VA_FOURCC_IMC1;
4616 attribs[i].type = VASurfaceAttribPixelFormat;
4617 attribs[i].value.type = VAGenericValueTypeInteger;
4618 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4619 attribs[i].value.value.i = VA_FOURCC_Y800;
4622 attribs[i].type = VASurfaceAttribPixelFormat;
4623 attribs[i].value.type = VAGenericValueTypeInteger;
4624 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4625 attribs[i].value.value.i = VA_FOURCC_411P;
4628 attribs[i].type = VASurfaceAttribPixelFormat;
4629 attribs[i].value.type = VAGenericValueTypeInteger;
4630 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4631 attribs[i].value.value.i = VA_FOURCC_422H;
4634 attribs[i].type = VASurfaceAttribPixelFormat;
4635 attribs[i].value.type = VAGenericValueTypeInteger;
4636 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4637 attribs[i].value.value.i = VA_FOURCC_422V;
4640 attribs[i].type = VASurfaceAttribPixelFormat;
4641 attribs[i].value.type = VAGenericValueTypeInteger;
4642 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4643 attribs[i].value.value.i = VA_FOURCC_444P;
4646 attribs[i].type = VASurfaceAttribPixelFormat;
4647 attribs[i].value.type = VAGenericValueTypeInteger;
4648 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4649 attribs[i].value.value.i = VA_FOURCC_NV12;
4652 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4653 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4655 attribs[i].type = VASurfaceAttribPixelFormat;
4656 attribs[i].value.type = VAGenericValueTypeInteger;
4657 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4658 attribs[i].value.value.i = VA_FOURCC_NV12;
4661 attribs[i].type = VASurfaceAttribPixelFormat;
4662 attribs[i].value.type = VAGenericValueTypeInteger;
4663 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4664 attribs[i].value.value.i = VA_FOURCC_I420;
4667 attribs[i].type = VASurfaceAttribPixelFormat;
4668 attribs[i].value.type = VAGenericValueTypeInteger;
4669 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4670 attribs[i].value.value.i = VA_FOURCC_YV12;
4673 attribs[i].type = VASurfaceAttribPixelFormat;
4674 attribs[i].value.type = VAGenericValueTypeInteger;
4675 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4676 attribs[i].value.value.i = VA_FOURCC_IMC3;
4679 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4680 attribs[i].type = VASurfaceAttribPixelFormat;
4681 attribs[i].value.type = VAGenericValueTypeInteger;
4682 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4683 attribs[i].value.value.i = VA_FOURCC_YUY2;
4686 attribs[i].type = VASurfaceAttribPixelFormat;
4687 attribs[i].value.type = VAGenericValueTypeInteger;
4688 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4689 attribs[i].value.value.i = VA_FOURCC_RGBA;
4692 attribs[i].type = VASurfaceAttribPixelFormat;
4693 attribs[i].value.type = VAGenericValueTypeInteger;
4694 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4695 attribs[i].value.value.i = VA_FOURCC_RGBX;
4698 attribs[i].type = VASurfaceAttribPixelFormat;
4699 attribs[i].value.type = VAGenericValueTypeInteger;
4700 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4701 attribs[i].value.value.i = VA_FOURCC_BGRA;
4704 attribs[i].type = VASurfaceAttribPixelFormat;
4705 attribs[i].value.type = VAGenericValueTypeInteger;
4706 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4707 attribs[i].value.value.i = VA_FOURCC_BGRX;
4710 attribs[i].type = VASurfaceAttribPixelFormat;
4711 attribs[i].value.type = VAGenericValueTypeInteger;
4712 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4713 attribs[i].value.value.i = VA_FOURCC_YV16;
4719 attribs[i].type = VASurfaceAttribMemoryType;
4720 attribs[i].value.type = VAGenericValueTypeInteger;
4721 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4722 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4723 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4724 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4727 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4728 attribs[i].value.type = VAGenericValueTypePointer;
4729 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4730 attribs[i].value.value.p = NULL; /* ignore */
4733 if (i > *num_attribs) {
4736 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4740 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4747 i965_os_has_ring_support(VADriverContextP ctx,
4750 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4754 return i965->intel.has_bsd;
4757 return i965->intel.has_blt;
4759 case I965_RING_VEBOX:
4760 return i965->intel.has_vebox;
4762 case I965_RING_NULL:
4763 return 1; /* Always support */
4766 /* should never get here */
4775 * Query video processing pipeline
4777 VAStatus i965_QueryVideoProcFilters(
4778 VADriverContextP ctx,
4779 VAContextID context,
4780 VAProcFilterType *filters,
4781 unsigned int *num_filters
4784 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4785 unsigned int i = 0, num = 0;
4787 if (!num_filters || !filters)
4788 return VA_STATUS_ERROR_INVALID_PARAMETER;
4790 for (i = 0; i < i965->codec_info->num_filters; i++) {
4791 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4792 if (num == *num_filters) {
4793 *num_filters = i965->codec_info->num_filters;
4795 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4798 filters[num++] = i965->codec_info->filters[i].type;
4804 return VA_STATUS_SUCCESS;
4807 VAStatus i965_QueryVideoProcFilterCaps(
4808 VADriverContextP ctx,
4809 VAContextID context,
4810 VAProcFilterType type,
4812 unsigned int *num_filter_caps
4816 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4818 if (!filter_caps || !num_filter_caps)
4819 return VA_STATUS_ERROR_INVALID_PARAMETER;
4821 for (i = 0; i < i965->codec_info->num_filters; i++) {
4822 if (type == i965->codec_info->filters[i].type &&
4823 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4827 if (i == i965->codec_info->num_filters)
4828 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4833 case VAProcFilterNoiseReduction:
4834 case VAProcFilterSharpening:
4836 VAProcFilterCap *cap = filter_caps;
4838 if (*num_filter_caps < 1) {
4839 *num_filter_caps = 1;
4840 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4843 cap->range.min_value = 0.0;
4844 cap->range.max_value = 1.0;
4845 cap->range.default_value = 0.5;
4846 cap->range.step = 0.03125; /* 1.0 / 32 */
4852 case VAProcFilterDeinterlacing:
4854 VAProcFilterCapDeinterlacing *cap = filter_caps;
4856 if (*num_filter_caps < VAProcDeinterlacingCount) {
4857 *num_filter_caps = VAProcDeinterlacingCount;
4858 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4861 cap->type = VAProcDeinterlacingBob;
4866 if (i965->codec_info->has_di_motion_adptive) {
4867 cap->type = VAProcDeinterlacingMotionAdaptive;
4872 if (i965->codec_info->has_di_motion_compensated) {
4873 cap->type = VAProcDeinterlacingMotionCompensated;
4881 case VAProcFilterColorBalance:
4883 VAProcFilterCapColorBalance *cap = filter_caps;
4885 if (*num_filter_caps < VAProcColorBalanceCount) {
4886 *num_filter_caps = VAProcColorBalanceCount;
4887 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4890 cap->type = VAProcColorBalanceHue;
4891 cap->range.min_value = -180.0;
4892 cap->range.max_value = 180.0;
4893 cap->range.default_value = 0.0;
4894 cap->range.step = 1.0;
4898 cap->type = VAProcColorBalanceSaturation;
4899 cap->range.min_value = 0.0;
4900 cap->range.max_value = 10.0;
4901 cap->range.default_value = 1.0;
4902 cap->range.step = 0.1;
4906 cap->type = VAProcColorBalanceBrightness;
4907 cap->range.min_value = -100.0;
4908 cap->range.max_value = 100.0;
4909 cap->range.default_value = 0.0;
4910 cap->range.step = 1.0;
4914 cap->type = VAProcColorBalanceContrast;
4915 cap->range.min_value = 0.0;
4916 cap->range.max_value = 10.0;
4917 cap->range.default_value = 1.0;
4918 cap->range.step = 0.1;
4930 *num_filter_caps = i;
4932 return VA_STATUS_SUCCESS;
4935 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
4936 VAProcColorStandardBT601,
4939 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
4940 VAProcColorStandardBT601,
4943 VAStatus i965_QueryVideoProcPipelineCaps(
4944 VADriverContextP ctx,
4945 VAContextID context,
4946 VABufferID *filters,
4947 unsigned int num_filters,
4948 VAProcPipelineCaps *pipeline_cap /* out */
4951 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4954 pipeline_cap->pipeline_flags = 0;
4955 pipeline_cap->filter_flags = 0;
4956 pipeline_cap->num_forward_references = 0;
4957 pipeline_cap->num_backward_references = 0;
4958 pipeline_cap->num_input_color_standards = 1;
4959 pipeline_cap->input_color_standards = vpp_input_color_standards;
4960 pipeline_cap->num_output_color_standards = 1;
4961 pipeline_cap->output_color_standards = vpp_output_color_standards;
4963 for (i = 0; i < num_filters; i++) {
4964 struct object_buffer *obj_buffer = BUFFER(filters[i]);
4967 !obj_buffer->buffer_store ||
4968 !obj_buffer->buffer_store->buffer)
4969 return VA_STATUS_ERROR_INVALID_BUFFER;
4971 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4973 if (base->type == VAProcFilterNoiseReduction) {
4974 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
4976 } else if (base->type == VAProcFilterDeinterlacing) {
4977 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
4979 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
4980 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4981 deint->algorithm == VAProcDeinterlacingMotionCompensated,
4982 VA_STATUS_ERROR_INVALID_PARAMETER);
4984 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4985 deint->algorithm == VAProcDeinterlacingMotionCompensated);
4986 pipeline_cap->num_forward_references++;
4987 } else if (base->type == VAProcFilterSkinToneEnhancement) {
4988 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
4993 return VA_STATUS_SUCCESS;
4996 extern const struct hw_codec_info *i965_get_codec_info(int devid);
4999 i965_driver_data_init(VADriverContextP ctx)
5001 struct i965_driver_data *i965 = i965_driver_data(ctx);
5003 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
5005 if (!i965->codec_info)
5008 if (object_heap_init(&i965->config_heap,
5009 sizeof(struct object_config),
5011 goto err_config_heap;
5012 if (object_heap_init(&i965->context_heap,
5013 sizeof(struct object_context),
5015 goto err_context_heap;
5017 if (object_heap_init(&i965->surface_heap,
5018 sizeof(struct object_surface),
5020 goto err_surface_heap;
5021 if (object_heap_init(&i965->buffer_heap,
5022 sizeof(struct object_buffer),
5024 goto err_buffer_heap;
5025 if (object_heap_init(&i965->image_heap,
5026 sizeof(struct object_image),
5028 goto err_image_heap;
5029 if (object_heap_init(&i965->subpic_heap,
5030 sizeof(struct object_subpic),
5032 goto err_subpic_heap;
5034 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5035 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5036 _i965InitMutex(&i965->render_mutex);
5037 _i965InitMutex(&i965->pp_mutex);
5042 object_heap_destroy(&i965->image_heap);
5044 object_heap_destroy(&i965->buffer_heap);
5046 object_heap_destroy(&i965->surface_heap);
5048 object_heap_destroy(&i965->context_heap);
5050 object_heap_destroy(&i965->config_heap);
5057 i965_driver_data_terminate(VADriverContextP ctx)
5059 struct i965_driver_data *i965 = i965_driver_data(ctx);
5061 _i965DestroyMutex(&i965->pp_mutex);
5062 _i965DestroyMutex(&i965->render_mutex);
5065 intel_batchbuffer_free(i965->batch);
5068 intel_batchbuffer_free(i965->pp_batch);
5070 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
5071 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
5072 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
5073 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
5074 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
5075 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
5079 bool (*init)(VADriverContextP ctx);
5080 void (*terminate)(VADriverContextP ctx);
5082 } i965_sub_ops[] = {
5085 intel_driver_terminate,
5090 i965_driver_data_init,
5091 i965_driver_data_terminate,
5096 i965_display_attributes_init,
5097 i965_display_attributes_terminate,
5102 i965_post_processing_init,
5103 i965_post_processing_terminate,
5109 i965_render_terminate,
5113 #ifdef HAVE_VA_WAYLAND
5115 i965_output_wayland_init,
5116 i965_output_wayland_terminate,
5123 i965_output_dri_init,
5124 i965_output_dri_terminate,
5131 i965_Init(VADriverContextP ctx)
5133 struct i965_driver_data *i965 = i965_driver_data(ctx);
5135 const char *chipset;
5137 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
5138 if ((i965_sub_ops[i].display_type == 0 ||
5139 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
5140 !i965_sub_ops[i].init(ctx))
5144 if (i == ARRAY_ELEMS(i965_sub_ops)) {
5145 switch (i965->intel.device_id) {
5147 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
5148 #include "i965_pciids.h"
5150 chipset = "Unknown Intel Chipset";
5154 sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d",
5155 INTEL_STR_DRIVER_VENDOR,
5156 INTEL_STR_DRIVER_NAME,
5158 INTEL_DRIVER_MAJOR_VERSION,
5159 INTEL_DRIVER_MINOR_VERSION,
5160 INTEL_DRIVER_MICRO_VERSION);
5162 if (INTEL_DRIVER_PRE_VERSION > 0) {
5163 const int len = strlen(i965->va_vendor);
5164 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
5167 i965->current_context_id = VA_INVALID_ID;
5169 return VA_STATUS_SUCCESS;
5173 for (; i >= 0; i--) {
5174 if (i965_sub_ops[i].display_type == 0 ||
5175 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5176 i965_sub_ops[i].terminate(ctx);
5180 return VA_STATUS_ERROR_UNKNOWN;
5185 i965_Terminate(VADriverContextP ctx)
5187 struct i965_driver_data *i965 = i965_driver_data(ctx);
5191 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5192 if (i965_sub_ops[i - 1].display_type == 0 ||
5193 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5194 i965_sub_ops[i - 1].terminate(ctx);
5198 ctx->pDriverData = NULL;
5201 return VA_STATUS_SUCCESS;
5205 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5208 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5210 struct VADriverVTable * const vtable = ctx->vtable;
5211 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5213 struct i965_driver_data *i965;
5214 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5216 ctx->version_major = VA_MAJOR_VERSION;
5217 ctx->version_minor = VA_MINOR_VERSION;
5218 ctx->max_profiles = I965_MAX_PROFILES;
5219 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5220 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5221 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5222 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5223 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5225 vtable->vaTerminate = i965_Terminate;
5226 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5227 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5228 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5229 vtable->vaCreateConfig = i965_CreateConfig;
5230 vtable->vaDestroyConfig = i965_DestroyConfig;
5231 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5232 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5233 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5234 vtable->vaCreateContext = i965_CreateContext;
5235 vtable->vaDestroyContext = i965_DestroyContext;
5236 vtable->vaCreateBuffer = i965_CreateBuffer;
5237 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5238 vtable->vaMapBuffer = i965_MapBuffer;
5239 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5240 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5241 vtable->vaBeginPicture = i965_BeginPicture;
5242 vtable->vaRenderPicture = i965_RenderPicture;
5243 vtable->vaEndPicture = i965_EndPicture;
5244 vtable->vaSyncSurface = i965_SyncSurface;
5245 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5246 vtable->vaPutSurface = i965_PutSurface;
5247 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5248 vtable->vaCreateImage = i965_CreateImage;
5249 vtable->vaDeriveImage = i965_DeriveImage;
5250 vtable->vaDestroyImage = i965_DestroyImage;
5251 vtable->vaSetImagePalette = i965_SetImagePalette;
5252 vtable->vaGetImage = i965_GetImage;
5253 vtable->vaPutImage = i965_PutImage;
5254 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5255 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5256 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5257 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5258 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5259 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5260 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5261 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5262 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5263 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5264 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5265 vtable->vaBufferInfo = i965_BufferInfo;
5266 vtable->vaLockSurface = i965_LockSurface;
5267 vtable->vaUnlockSurface = i965_UnlockSurface;
5268 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5269 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5270 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5272 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5273 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5274 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5276 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5279 ctx->pDriverData = NULL;
5281 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5284 ctx->pDriverData = (void *)i965;
5285 ret = i965_Init(ctx);
5287 if (ret == VA_STATUS_SUCCESS) {
5288 ctx->str_vendor = i965->va_vendor;
5291 ctx->pDriverData = NULL;