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_validate_config(VADriverContextP ctx, VAProfile profile,
371 VAEntrypoint entrypoint)
373 struct i965_driver_data * const i965 = i965_driver_data(ctx);
376 /* Validate profile & entrypoint */
378 case VAProfileMPEG2Simple:
379 case VAProfileMPEG2Main:
380 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
381 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
382 va_status = VA_STATUS_SUCCESS;
384 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
388 case VAProfileH264ConstrainedBaseline:
389 case VAProfileH264Main:
390 case VAProfileH264High:
391 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
392 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
393 va_status = VA_STATUS_SUCCESS;
395 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
399 case VAProfileVC1Simple:
400 case VAProfileVC1Main:
401 case VAProfileVC1Advanced:
402 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
403 va_status = VA_STATUS_SUCCESS;
405 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
410 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
411 va_status = VA_STATUS_SUCCESS;
413 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
417 case VAProfileJPEGBaseline:
418 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) {
419 va_status = VA_STATUS_SUCCESS;
421 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
425 case VAProfileVP8Version0_3:
426 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
427 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
428 va_status = VA_STATUS_SUCCESS;
430 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
435 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
442 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
443 VAEntrypoint entrypoint)
445 struct i965_driver_data * const i965 = i965_driver_data(ctx);
446 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
449 case VAProfileH264ConstrainedBaseline:
450 case VAProfileH264Main:
451 case VAProfileH264High:
452 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
453 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
456 case VAProfileJPEGBaseline:
457 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
458 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
464 return chroma_formats;
468 i965_GetConfigAttributes(VADriverContextP ctx,
470 VAEntrypoint entrypoint,
471 VAConfigAttrib *attrib_list, /* in/out */
477 va_status = i965_validate_config(ctx, profile, entrypoint);
478 if (va_status != VA_STATUS_SUCCESS)
481 /* Other attributes don't seem to be defined */
482 /* What to do if we don't know the attribute? */
483 for (i = 0; i < num_attribs; i++) {
484 switch (attrib_list[i].type) {
485 case VAConfigAttribRTFormat:
486 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
487 profile, entrypoint);
490 case VAConfigAttribRateControl:
491 if (entrypoint == VAEntrypointEncSlice) {
492 attrib_list[i].value = VA_RC_CQP;
494 if (profile != VAProfileMPEG2Main &&
495 profile != VAProfileMPEG2Simple)
496 attrib_list[i].value |= VA_RC_CBR;
500 case VAConfigAttribEncPackedHeaders:
501 if (entrypoint == VAEntrypointEncSlice) {
502 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
506 case VAConfigAttribEncMaxRefFrames:
507 if (entrypoint == VAEntrypointEncSlice) {
508 attrib_list[i].value = (1 << 16) | (1 << 0);
514 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
519 return VA_STATUS_SUCCESS;
523 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
525 object_heap_free(heap, obj);
528 static VAConfigAttrib *
529 i965_lookup_config_attribute(struct object_config *obj_config,
530 VAConfigAttribType type)
534 for (i = 0; i < obj_config->num_attribs; i++) {
535 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
536 if (attrib->type == type)
543 i965_append_config_attribute(struct object_config *obj_config,
544 const VAConfigAttrib *new_attrib)
546 VAConfigAttrib *attrib;
548 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
549 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
551 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
552 attrib->type = new_attrib->type;
553 attrib->value = new_attrib->value;
554 return VA_STATUS_SUCCESS;
558 i965_ensure_config_attribute(struct object_config *obj_config,
559 const VAConfigAttrib *new_attrib)
561 VAConfigAttrib *attrib;
563 /* Check for existing attributes */
564 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
566 /* Update existing attribute */
567 attrib->value = new_attrib->value;
568 return VA_STATUS_SUCCESS;
570 return i965_append_config_attribute(obj_config, new_attrib);
574 i965_CreateConfig(VADriverContextP ctx,
576 VAEntrypoint entrypoint,
577 VAConfigAttrib *attrib_list,
579 VAConfigID *config_id) /* out */
581 struct i965_driver_data * const i965 = i965_driver_data(ctx);
582 struct object_config *obj_config;
587 vaStatus = i965_validate_config(ctx, profile, entrypoint);
588 if (VA_STATUS_SUCCESS != vaStatus) {
592 configID = NEW_CONFIG_ID();
593 obj_config = CONFIG(configID);
595 if (NULL == obj_config) {
596 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
600 obj_config->profile = profile;
601 obj_config->entrypoint = entrypoint;
602 obj_config->num_attribs = 0;
604 for (i = 0; i < num_attribs; i++) {
605 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
606 if (vaStatus != VA_STATUS_SUCCESS)
610 if (vaStatus == VA_STATUS_SUCCESS) {
611 VAConfigAttrib attrib, *attrib_found;
612 attrib.type = VAConfigAttribRTFormat;
613 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
614 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
615 if (!attrib_found || !attrib_found->value)
616 vaStatus = i965_append_config_attribute(obj_config, &attrib);
617 else if (!(attrib_found->value & attrib.value))
618 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
622 if (VA_STATUS_SUCCESS != vaStatus) {
623 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
625 *config_id = configID;
632 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
634 struct i965_driver_data *i965 = i965_driver_data(ctx);
635 struct object_config *obj_config = CONFIG(config_id);
638 if (NULL == obj_config) {
639 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
643 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
644 return VA_STATUS_SUCCESS;
647 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
648 VAConfigID config_id,
649 VAProfile *profile, /* out */
650 VAEntrypoint *entrypoint, /* out */
651 VAConfigAttrib *attrib_list, /* out */
652 int *num_attribs) /* out */
654 struct i965_driver_data *i965 = i965_driver_data(ctx);
655 struct object_config *obj_config = CONFIG(config_id);
656 VAStatus vaStatus = VA_STATUS_SUCCESS;
659 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
660 *profile = obj_config->profile;
661 *entrypoint = obj_config->entrypoint;
662 *num_attribs = obj_config->num_attribs;
664 for(i = 0; i < obj_config->num_attribs; i++) {
665 attrib_list[i] = obj_config->attrib_list[i];
672 i965_destroy_surface_storage(struct object_surface *obj_surface)
677 dri_bo_unreference(obj_surface->bo);
678 obj_surface->bo = NULL;
680 if (obj_surface->free_private_data != NULL) {
681 obj_surface->free_private_data(&obj_surface->private_data);
682 obj_surface->private_data = NULL;
687 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
689 struct object_surface *obj_surface = (struct object_surface *)obj;
691 i965_destroy_surface_storage(obj_surface);
692 object_heap_free(heap, obj);
696 i965_surface_native_memory(VADriverContextP ctx,
697 struct object_surface *obj_surface,
701 struct i965_driver_data *i965 = i965_driver_data(ctx);
702 int tiling = HAS_TILED_SURFACE(i965);
704 if (!expected_fourcc)
705 return VA_STATUS_SUCCESS;
707 // todo, should we disable tiling for 422 format?
708 if (expected_fourcc == VA_FOURCC_I420 ||
709 expected_fourcc == VA_FOURCC_IYUV ||
710 expected_fourcc == VA_FOURCC_YV12 ||
711 expected_fourcc == VA_FOURCC_YV16)
714 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
716 return VA_STATUS_SUCCESS;
720 i965_suface_external_memory(VADriverContextP ctx,
721 struct object_surface *obj_surface,
722 int external_memory_type,
723 VASurfaceAttribExternalBuffers *memory_attibute,
726 struct i965_driver_data *i965 = i965_driver_data(ctx);
728 if (!memory_attibute ||
729 !memory_attibute->buffers ||
730 index > memory_attibute->num_buffers)
731 return VA_STATUS_ERROR_INVALID_PARAMETER;
733 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
734 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
735 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
737 obj_surface->fourcc = memory_attibute->pixel_format;
738 obj_surface->width = memory_attibute->pitches[0];
739 obj_surface->size = memory_attibute->data_size;
741 if (memory_attibute->num_planes == 1)
742 obj_surface->height = memory_attibute->data_size / obj_surface->width;
744 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
746 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
747 obj_surface->x_cr_offset = 0;
749 switch (obj_surface->fourcc) {
751 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
752 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
754 obj_surface->subsampling = SUBSAMPLE_YUV420;
755 obj_surface->y_cb_offset = obj_surface->height;
756 obj_surface->y_cr_offset = obj_surface->height;
757 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
758 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
759 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
765 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
766 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
768 obj_surface->subsampling = SUBSAMPLE_YUV420;
769 obj_surface->y_cr_offset = obj_surface->height;
770 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
771 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
772 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
773 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
780 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
781 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
783 obj_surface->subsampling = SUBSAMPLE_YUV420;
784 obj_surface->y_cb_offset = obj_surface->height;
785 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
786 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
787 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
788 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
794 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
796 obj_surface->subsampling = SUBSAMPLE_YUV422H;
797 obj_surface->y_cb_offset = 0;
798 obj_surface->y_cr_offset = 0;
799 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
800 obj_surface->cb_cr_height = obj_surface->orig_height;
801 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
809 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
811 obj_surface->subsampling = SUBSAMPLE_RGBX;
812 obj_surface->y_cb_offset = 0;
813 obj_surface->y_cr_offset = 0;
814 obj_surface->cb_cr_width = 0;
815 obj_surface->cb_cr_height = 0;
816 obj_surface->cb_cr_pitch = 0;
820 case VA_FOURCC_Y800: /* monochrome surface */
821 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
823 obj_surface->subsampling = SUBSAMPLE_YUV400;
824 obj_surface->y_cb_offset = 0;
825 obj_surface->y_cr_offset = 0;
826 obj_surface->cb_cr_width = 0;
827 obj_surface->cb_cr_height = 0;
828 obj_surface->cb_cr_pitch = 0;
833 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
834 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
836 obj_surface->subsampling = SUBSAMPLE_YUV411;
837 obj_surface->y_cb_offset = 0;
838 obj_surface->y_cr_offset = 0;
839 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
840 obj_surface->cb_cr_height = obj_surface->orig_height;
841 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
846 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
847 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
849 obj_surface->subsampling = SUBSAMPLE_YUV422H;
850 obj_surface->y_cb_offset = obj_surface->height;
851 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
852 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
853 obj_surface->cb_cr_height = obj_surface->orig_height;
854 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
859 assert(memory_attibute->num_planes == 3);
860 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
862 obj_surface->subsampling = SUBSAMPLE_YUV422H;
863 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
864 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
865 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
866 obj_surface->cb_cr_height = obj_surface->orig_height;
867 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
872 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
873 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
875 obj_surface->subsampling = SUBSAMPLE_YUV422H;
876 obj_surface->y_cb_offset = obj_surface->height;
877 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
878 obj_surface->cb_cr_width = obj_surface->orig_width;
879 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
880 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
885 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
886 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
888 obj_surface->subsampling = SUBSAMPLE_YUV444;
889 obj_surface->y_cb_offset = obj_surface->height;
890 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
891 obj_surface->cb_cr_width = obj_surface->orig_width;
892 obj_surface->cb_cr_height = obj_surface->orig_height;
893 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
899 return VA_STATUS_ERROR_INVALID_PARAMETER;
902 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
903 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
904 "gem flinked vaapi surface",
905 memory_attibute->buffers[index]);
906 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
907 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
908 memory_attibute->buffers[index],
911 if (!obj_surface->bo)
912 return VA_STATUS_ERROR_INVALID_PARAMETER;
914 return VA_STATUS_SUCCESS;
917 /* byte-per-pixel of the first plane */
919 bpp_1stplane_by_fourcc(unsigned int fourcc)
953 i965_CreateSurfaces2(
954 VADriverContextP ctx,
958 VASurfaceID *surfaces,
959 unsigned int num_surfaces,
960 VASurfaceAttrib *attrib_list,
961 unsigned int num_attribs
964 struct i965_driver_data *i965 = i965_driver_data(ctx);
966 VAStatus vaStatus = VA_STATUS_SUCCESS;
967 int expected_fourcc = 0;
968 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
969 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
971 for (i = 0; i < num_attribs && attrib_list; i++) {
972 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
973 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
974 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
975 expected_fourcc = attrib_list[i].value.value.i;
978 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
979 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
981 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
983 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
984 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
985 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
986 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
987 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
988 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
991 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
992 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
993 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
994 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
998 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
999 * for post-processing (including color conversion) */
1000 if (VA_RT_FORMAT_YUV420 != format &&
1001 VA_RT_FORMAT_YUV422 != format &&
1002 VA_RT_FORMAT_YUV444 != format &&
1003 VA_RT_FORMAT_YUV411 != format &&
1004 VA_RT_FORMAT_YUV400 != format &&
1005 VA_RT_FORMAT_RGB32 != format) {
1006 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1009 for (i = 0; i < num_surfaces; i++) {
1010 int surfaceID = NEW_SURFACE_ID();
1011 struct object_surface *obj_surface = SURFACE(surfaceID);
1013 if (NULL == obj_surface) {
1014 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1018 surfaces[i] = surfaceID;
1019 obj_surface->status = VASurfaceReady;
1020 obj_surface->orig_width = width;
1021 obj_surface->orig_height = height;
1022 obj_surface->user_disable_tiling = false;
1023 obj_surface->user_h_stride_set = false;
1024 obj_surface->user_v_stride_set = false;
1026 obj_surface->subpic_render_idx = 0;
1027 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1028 obj_surface->subpic[j] = VA_INVALID_ID;
1029 obj_surface->obj_subpic[j] = NULL;
1032 assert(i965->codec_info->min_linear_wpitch);
1033 assert(i965->codec_info->min_linear_hpitch);
1034 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1035 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1036 obj_surface->flags = SURFACE_REFERENCED;
1037 obj_surface->fourcc = 0;
1038 obj_surface->bo = NULL;
1039 obj_surface->locked_image_id = VA_INVALID_ID;
1040 obj_surface->private_data = NULL;
1041 obj_surface->free_private_data = NULL;
1042 obj_surface->subsampling = SUBSAMPLE_YUV420;
1044 switch (memory_type) {
1045 case I965_SURFACE_MEM_NATIVE:
1046 if (memory_attibute) {
1047 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1048 obj_surface->user_disable_tiling = true;
1050 if (memory_attibute->pixel_format) {
1051 if (expected_fourcc)
1052 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1054 expected_fourcc = memory_attibute->pixel_format;
1056 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1057 if (memory_attibute->pitches[0]) {
1058 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1059 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1060 obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane;
1061 obj_surface->user_h_stride_set = true;
1062 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1063 ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER);
1065 if (memory_attibute->offsets[1]) {
1066 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1067 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1068 obj_surface->user_v_stride_set = true;
1069 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1070 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1074 i965_surface_native_memory(ctx,
1080 case I965_SURFACE_MEM_GEM_FLINK:
1081 case I965_SURFACE_MEM_DRM_PRIME:
1082 i965_suface_external_memory(ctx,
1091 /* Error recovery */
1092 if (VA_STATUS_SUCCESS != vaStatus) {
1093 /* surfaces[i-1] was the last successful allocation */
1095 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1097 surfaces[i] = VA_INVALID_SURFACE;
1098 assert(obj_surface);
1099 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1107 i965_CreateSurfaces(VADriverContextP ctx,
1112 VASurfaceID *surfaces) /* out */
1114 return i965_CreateSurfaces2(ctx,
1125 i965_DestroySurfaces(VADriverContextP ctx,
1126 VASurfaceID *surface_list,
1129 struct i965_driver_data *i965 = i965_driver_data(ctx);
1132 for (i = num_surfaces; i--; ) {
1133 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1135 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1136 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1139 return VA_STATUS_SUCCESS;
1143 i965_QueryImageFormats(VADriverContextP ctx,
1144 VAImageFormat *format_list, /* out */
1145 int *num_formats) /* out */
1149 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1150 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1152 format_list[n] = m->va_format;
1158 return VA_STATUS_SUCCESS;
1162 * Guess the format when the usage of a VA surface is unknown
1163 * 1. Without a valid context: YV12
1164 * 2. The current context is valid:
1165 * a) always NV12 on GEN6 and later
1166 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1169 i965_guess_surface_format(VADriverContextP ctx,
1170 VASurfaceID surface,
1171 unsigned int *fourcc,
1172 unsigned int *is_tiled)
1174 struct i965_driver_data *i965 = i965_driver_data(ctx);
1175 struct object_context *obj_context = NULL;
1176 struct object_config *obj_config = NULL;
1178 *fourcc = VA_FOURCC_YV12;
1181 if (i965->current_context_id == VA_INVALID_ID)
1184 obj_context = CONTEXT(i965->current_context_id);
1189 obj_config = obj_context->obj_config;
1195 if (IS_GEN6(i965->intel.device_info) ||
1196 IS_GEN7(i965->intel.device_info) ||
1197 IS_GEN8(i965->intel.device_info)) {
1198 *fourcc = VA_FOURCC_NV12;
1203 switch (obj_config->profile) {
1204 case VAProfileMPEG2Simple:
1205 case VAProfileMPEG2Main:
1206 *fourcc = VA_FOURCC_I420;
1211 *fourcc = VA_FOURCC_NV12;
1218 i965_QuerySubpictureFormats(VADriverContextP ctx,
1219 VAImageFormat *format_list, /* out */
1220 unsigned int *flags, /* out */
1221 unsigned int *num_formats) /* out */
1225 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1226 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1228 format_list[n] = m->va_format;
1230 flags[n] = m->va_flags;
1236 return VA_STATUS_SUCCESS;
1240 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1242 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1244 object_heap_free(heap, obj);
1248 i965_CreateSubpicture(VADriverContextP ctx,
1250 VASubpictureID *subpicture) /* out */
1252 struct i965_driver_data *i965 = i965_driver_data(ctx);
1253 VASubpictureID subpicID = NEW_SUBPIC_ID()
1254 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1257 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1259 struct object_image *obj_image = IMAGE(image);
1261 return VA_STATUS_ERROR_INVALID_IMAGE;
1263 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1265 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1267 *subpicture = subpicID;
1268 obj_subpic->image = image;
1269 obj_subpic->obj_image = obj_image;
1270 obj_subpic->format = m->format;
1271 obj_subpic->width = obj_image->image.width;
1272 obj_subpic->height = obj_image->image.height;
1273 obj_subpic->pitch = obj_image->image.pitches[0];
1274 obj_subpic->bo = obj_image->bo;
1275 obj_subpic->global_alpha = 1.0;
1277 return VA_STATUS_SUCCESS;
1281 i965_DestroySubpicture(VADriverContextP ctx,
1282 VASubpictureID subpicture)
1284 struct i965_driver_data *i965 = i965_driver_data(ctx);
1285 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1288 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1290 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1291 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1292 return VA_STATUS_SUCCESS;
1296 i965_SetSubpictureImage(VADriverContextP ctx,
1297 VASubpictureID subpicture,
1301 return VA_STATUS_ERROR_UNIMPLEMENTED;
1305 i965_SetSubpictureChromakey(VADriverContextP ctx,
1306 VASubpictureID subpicture,
1307 unsigned int chromakey_min,
1308 unsigned int chromakey_max,
1309 unsigned int chromakey_mask)
1312 return VA_STATUS_ERROR_UNIMPLEMENTED;
1316 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1317 VASubpictureID subpicture,
1320 struct i965_driver_data *i965 = i965_driver_data(ctx);
1321 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1323 if(global_alpha > 1.0 || global_alpha < 0.0){
1324 return VA_STATUS_ERROR_INVALID_PARAMETER;
1328 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1330 obj_subpic->global_alpha = global_alpha;
1332 return VA_STATUS_SUCCESS;
1336 i965_AssociateSubpicture(VADriverContextP ctx,
1337 VASubpictureID subpicture,
1338 VASurfaceID *target_surfaces,
1340 short src_x, /* upper left offset in subpicture */
1342 unsigned short src_width,
1343 unsigned short src_height,
1344 short dest_x, /* upper left offset in surface */
1346 unsigned short dest_width,
1347 unsigned short dest_height,
1349 * whether to enable chroma-keying or global-alpha
1350 * see VA_SUBPICTURE_XXX values
1354 struct i965_driver_data *i965 = i965_driver_data(ctx);
1355 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1359 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1361 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1363 obj_subpic->src_rect.x = src_x;
1364 obj_subpic->src_rect.y = src_y;
1365 obj_subpic->src_rect.width = src_width;
1366 obj_subpic->src_rect.height = src_height;
1367 obj_subpic->dst_rect.x = dest_x;
1368 obj_subpic->dst_rect.y = dest_y;
1369 obj_subpic->dst_rect.width = dest_width;
1370 obj_subpic->dst_rect.height = dest_height;
1371 obj_subpic->flags = flags;
1373 for (i = 0; i < num_surfaces; i++) {
1374 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1376 return VA_STATUS_ERROR_INVALID_SURFACE;
1378 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1379 if(obj_surface->subpic[j] == VA_INVALID_ID){
1380 assert(obj_surface->obj_subpic[j] == NULL);
1381 obj_surface->subpic[j] = subpicture;
1382 obj_surface->obj_subpic[j] = obj_subpic;
1387 if(j == I965_MAX_SUBPIC_SUM){
1388 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1392 return VA_STATUS_SUCCESS;
1397 i965_DeassociateSubpicture(VADriverContextP ctx,
1398 VASubpictureID subpicture,
1399 VASurfaceID *target_surfaces,
1402 struct i965_driver_data *i965 = i965_driver_data(ctx);
1403 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1407 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1409 for (i = 0; i < num_surfaces; i++) {
1410 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1412 return VA_STATUS_ERROR_INVALID_SURFACE;
1414 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1415 if (obj_surface->subpic[j] == subpicture) {
1416 assert(obj_surface->obj_subpic[j] == obj_subpic);
1417 obj_surface->subpic[j] = VA_INVALID_ID;
1418 obj_surface->obj_subpic[j] = NULL;
1423 if(j == I965_MAX_SUBPIC_SUM){
1424 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1427 return VA_STATUS_SUCCESS;
1431 i965_reference_buffer_store(struct buffer_store **ptr,
1432 struct buffer_store *buffer_store)
1434 assert(*ptr == NULL);
1437 buffer_store->ref_count++;
1438 *ptr = buffer_store;
1443 i965_release_buffer_store(struct buffer_store **ptr)
1445 struct buffer_store *buffer_store = *ptr;
1447 if (buffer_store == NULL)
1450 assert(buffer_store->bo || buffer_store->buffer);
1451 assert(!(buffer_store->bo && buffer_store->buffer));
1452 buffer_store->ref_count--;
1454 if (buffer_store->ref_count == 0) {
1455 dri_bo_unreference(buffer_store->bo);
1456 free(buffer_store->buffer);
1457 buffer_store->bo = NULL;
1458 buffer_store->buffer = NULL;
1466 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1468 struct object_context *obj_context = (struct object_context *)obj;
1471 if (obj_context->hw_context) {
1472 obj_context->hw_context->destroy(obj_context->hw_context);
1473 obj_context->hw_context = NULL;
1476 if (obj_context->codec_type == CODEC_PROC) {
1477 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1479 } else if (obj_context->codec_type == CODEC_ENC) {
1480 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1481 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1482 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1484 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1485 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1487 free(obj_context->codec_state.encode.slice_params);
1489 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1490 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1491 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1493 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1494 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1496 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1497 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1499 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1500 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1502 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1503 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1505 free(obj_context->codec_state.encode.slice_params_ext);
1507 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1508 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1510 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1511 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1512 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1514 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1515 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1517 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1518 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1520 free(obj_context->codec_state.decode.slice_params);
1521 free(obj_context->codec_state.decode.slice_datas);
1524 free(obj_context->render_targets);
1525 object_heap_free(heap, obj);
1529 i965_CreateContext(VADriverContextP ctx,
1530 VAConfigID config_id,
1534 VASurfaceID *render_targets,
1535 int num_render_targets,
1536 VAContextID *context) /* out */
1538 struct i965_driver_data *i965 = i965_driver_data(ctx);
1539 struct i965_render_state *render_state = &i965->render_state;
1540 struct object_config *obj_config = CONFIG(config_id);
1541 struct object_context *obj_context = NULL;
1542 VAConfigAttrib *attrib;
1543 VAStatus vaStatus = VA_STATUS_SUCCESS;
1547 if (NULL == obj_config) {
1548 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1552 if (picture_width > i965->codec_info->max_width ||
1553 picture_height > i965->codec_info->max_height) {
1554 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1559 /* Validate picture dimensions */
1560 contextID = NEW_CONTEXT_ID();
1561 obj_context = CONTEXT(contextID);
1563 if (NULL == obj_context) {
1564 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1568 render_state->inited = 1;
1570 switch (obj_config->profile) {
1571 case VAProfileH264ConstrainedBaseline:
1572 case VAProfileH264Main:
1573 case VAProfileH264High:
1574 if (!HAS_H264_DECODING(i965) &&
1575 !HAS_H264_ENCODING(i965))
1576 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1577 render_state->interleaved_uv = 1;
1580 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info));
1584 *context = contextID;
1585 obj_context->flags = flag;
1586 obj_context->context_id = contextID;
1587 obj_context->obj_config = obj_config;
1588 obj_context->picture_width = picture_width;
1589 obj_context->picture_height = picture_height;
1590 obj_context->num_render_targets = num_render_targets;
1591 obj_context->render_targets =
1592 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1593 obj_context->hw_context = NULL;
1595 for(i = 0; i < num_render_targets; i++) {
1596 if (NULL == SURFACE(render_targets[i])) {
1597 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1601 obj_context->render_targets[i] = render_targets[i];
1604 if (VA_STATUS_SUCCESS == vaStatus) {
1605 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1606 obj_context->codec_type = CODEC_PROC;
1607 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1608 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1609 assert(i965->codec_info->proc_hw_context_init);
1610 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1611 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1612 obj_context->codec_type = CODEC_ENC;
1613 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1614 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1615 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1616 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1617 sizeof(*obj_context->codec_state.encode.slice_params));
1618 assert(i965->codec_info->enc_hw_context_init);
1619 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1621 obj_context->codec_type = CODEC_DEC;
1622 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1623 obj_context->codec_state.decode.current_render_target = -1;
1624 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1625 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1626 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1627 sizeof(*obj_context->codec_state.decode.slice_params));
1628 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1629 sizeof(*obj_context->codec_state.decode.slice_datas));
1631 assert(i965->codec_info->dec_hw_context_init);
1632 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1636 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
1638 return VA_STATUS_ERROR_INVALID_CONFIG;
1639 obj_context->codec_state.base.chroma_formats = attrib->value;
1641 /* Error recovery */
1642 if (VA_STATUS_SUCCESS != vaStatus) {
1643 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1646 i965->current_context_id = contextID;
1652 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1654 struct i965_driver_data *i965 = i965_driver_data(ctx);
1655 struct object_context *obj_context = CONTEXT(context);
1657 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1659 if (i965->current_context_id == context)
1660 i965->current_context_id = VA_INVALID_ID;
1662 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1664 return VA_STATUS_SUCCESS;
1668 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1670 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1672 assert(obj_buffer->buffer_store);
1673 i965_release_buffer_store(&obj_buffer->buffer_store);
1674 object_heap_free(heap, obj);
1678 i965_create_buffer_internal(VADriverContextP ctx,
1679 VAContextID context,
1682 unsigned int num_elements,
1687 struct i965_driver_data *i965 = i965_driver_data(ctx);
1688 struct object_buffer *obj_buffer = NULL;
1689 struct buffer_store *buffer_store = NULL;
1694 case VAPictureParameterBufferType:
1695 case VAIQMatrixBufferType:
1696 case VAQMatrixBufferType:
1697 case VABitPlaneBufferType:
1698 case VASliceGroupMapBufferType:
1699 case VASliceParameterBufferType:
1700 case VASliceDataBufferType:
1701 case VAMacroblockParameterBufferType:
1702 case VAResidualDataBufferType:
1703 case VADeblockingParameterBufferType:
1704 case VAImageBufferType:
1705 case VAEncCodedBufferType:
1706 case VAEncSequenceParameterBufferType:
1707 case VAEncPictureParameterBufferType:
1708 case VAEncSliceParameterBufferType:
1709 case VAEncPackedHeaderParameterBufferType:
1710 case VAEncPackedHeaderDataBufferType:
1711 case VAEncMiscParameterBufferType:
1712 case VAProcPipelineParameterBufferType:
1713 case VAProcFilterParameterBufferType:
1714 case VAHuffmanTableBufferType:
1715 case VAProbabilityBufferType:
1720 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1723 bufferID = NEW_BUFFER_ID();
1724 obj_buffer = BUFFER(bufferID);
1726 if (NULL == obj_buffer) {
1727 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1730 if (type == VAEncCodedBufferType) {
1731 size += I965_CODEDBUFFER_HEADER_SIZE;
1732 size += 0x1000; /* for upper bound check */
1735 obj_buffer->max_num_elements = num_elements;
1736 obj_buffer->num_elements = num_elements;
1737 obj_buffer->size_element = size;
1738 obj_buffer->type = type;
1739 obj_buffer->buffer_store = NULL;
1740 buffer_store = calloc(1, sizeof(struct buffer_store));
1741 assert(buffer_store);
1742 buffer_store->ref_count = 1;
1744 if (store_bo != NULL) {
1745 buffer_store->bo = store_bo;
1746 dri_bo_reference(buffer_store->bo);
1749 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1750 } else if (type == VASliceDataBufferType ||
1751 type == VAImageBufferType ||
1752 type == VAEncCodedBufferType ||
1753 type == VAProbabilityBufferType) {
1754 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1756 size * num_elements, 64);
1757 assert(buffer_store->bo);
1759 if (type == VAEncCodedBufferType) {
1760 struct i965_coded_buffer_segment *coded_buffer_segment;
1762 dri_bo_map(buffer_store->bo, 1);
1763 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1764 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1765 coded_buffer_segment->base.bit_offset = 0;
1766 coded_buffer_segment->base.status = 0;
1767 coded_buffer_segment->base.buf = NULL;
1768 coded_buffer_segment->base.next = NULL;
1769 coded_buffer_segment->mapped = 0;
1770 coded_buffer_segment->codec = 0;
1771 dri_bo_unmap(buffer_store->bo);
1773 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1779 if (type == VAEncPackedHeaderDataBufferType) {
1780 msize = ALIGN(size, 4);
1783 buffer_store->buffer = malloc(msize * num_elements);
1784 assert(buffer_store->buffer);
1787 memcpy(buffer_store->buffer, data, size * num_elements);
1790 buffer_store->num_elements = obj_buffer->num_elements;
1791 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1792 i965_release_buffer_store(&buffer_store);
1795 return VA_STATUS_SUCCESS;
1799 i965_CreateBuffer(VADriverContextP ctx,
1800 VAContextID context, /* in */
1801 VABufferType type, /* in */
1802 unsigned int size, /* in */
1803 unsigned int num_elements, /* in */
1804 void *data, /* in */
1805 VABufferID *buf_id) /* out */
1807 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1812 i965_BufferSetNumElements(VADriverContextP ctx,
1813 VABufferID buf_id, /* in */
1814 unsigned int num_elements) /* in */
1816 struct i965_driver_data *i965 = i965_driver_data(ctx);
1817 struct object_buffer *obj_buffer = BUFFER(buf_id);
1818 VAStatus vaStatus = VA_STATUS_SUCCESS;
1820 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1822 if ((num_elements < 0) ||
1823 (num_elements > obj_buffer->max_num_elements)) {
1824 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1826 obj_buffer->num_elements = num_elements;
1827 if (obj_buffer->buffer_store != NULL) {
1828 obj_buffer->buffer_store->num_elements = num_elements;
1836 i965_MapBuffer(VADriverContextP ctx,
1837 VABufferID buf_id, /* in */
1838 void **pbuf) /* out */
1840 struct i965_driver_data *i965 = i965_driver_data(ctx);
1841 struct object_buffer *obj_buffer = BUFFER(buf_id);
1842 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1844 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
1845 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1846 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
1848 if (NULL != obj_buffer->buffer_store->bo) {
1849 unsigned int tiling, swizzle;
1851 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1853 if (tiling != I915_TILING_NONE)
1854 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1856 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1858 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
1859 *pbuf = obj_buffer->buffer_store->bo->virtual;
1861 if (obj_buffer->type == VAEncCodedBufferType) {
1863 unsigned char *buffer = NULL;
1864 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1866 if (!coded_buffer_segment->mapped) {
1867 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1869 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1871 if (coded_buffer_segment->codec == CODEC_H264) {
1872 delimiter0 = H264_DELIMITER0;
1873 delimiter1 = H264_DELIMITER1;
1874 delimiter2 = H264_DELIMITER2;
1875 delimiter3 = H264_DELIMITER3;
1876 delimiter4 = H264_DELIMITER4;
1877 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1878 delimiter0 = MPEG2_DELIMITER0;
1879 delimiter1 = MPEG2_DELIMITER1;
1880 delimiter2 = MPEG2_DELIMITER2;
1881 delimiter3 = MPEG2_DELIMITER3;
1882 delimiter4 = MPEG2_DELIMITER4;
1884 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
1887 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1888 if ((buffer[i] == delimiter0) &&
1889 (buffer[i + 1] == delimiter1) &&
1890 (buffer[i + 2] == delimiter2) &&
1891 (buffer[i + 3] == delimiter3) &&
1892 (buffer[i + 4] == delimiter4))
1896 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1897 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1900 coded_buffer_segment->base.size = i;
1901 coded_buffer_segment->mapped = 1;
1903 assert(coded_buffer_segment->base.buf);
1907 vaStatus = VA_STATUS_SUCCESS;
1908 } else if (NULL != obj_buffer->buffer_store->buffer) {
1909 *pbuf = obj_buffer->buffer_store->buffer;
1910 vaStatus = VA_STATUS_SUCCESS;
1917 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1919 struct i965_driver_data *i965 = i965_driver_data(ctx);
1920 struct object_buffer *obj_buffer = BUFFER(buf_id);
1921 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1923 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
1924 return VA_STATUS_ERROR_INVALID_BUFFER;
1926 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
1927 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
1928 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
1930 if (NULL != obj_buffer->buffer_store->bo) {
1931 unsigned int tiling, swizzle;
1933 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1935 if (tiling != I915_TILING_NONE)
1936 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1938 dri_bo_unmap(obj_buffer->buffer_store->bo);
1940 vaStatus = VA_STATUS_SUCCESS;
1941 } else if (NULL != obj_buffer->buffer_store->buffer) {
1943 vaStatus = VA_STATUS_SUCCESS;
1950 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1952 struct i965_driver_data *i965 = i965_driver_data(ctx);
1953 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1955 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1957 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1959 return VA_STATUS_SUCCESS;
1963 i965_BeginPicture(VADriverContextP ctx,
1964 VAContextID context,
1965 VASurfaceID render_target)
1967 struct i965_driver_data *i965 = i965_driver_data(ctx);
1968 struct object_context *obj_context = CONTEXT(context);
1969 struct object_surface *obj_surface = SURFACE(render_target);
1970 struct object_config *obj_config;
1974 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1975 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1976 obj_config = obj_context->obj_config;
1977 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1979 switch (obj_config->profile) {
1980 case VAProfileMPEG2Simple:
1981 case VAProfileMPEG2Main:
1982 vaStatus = VA_STATUS_SUCCESS;
1985 case VAProfileH264ConstrainedBaseline:
1986 case VAProfileH264Main:
1987 case VAProfileH264High:
1988 vaStatus = VA_STATUS_SUCCESS;
1991 case VAProfileVC1Simple:
1992 case VAProfileVC1Main:
1993 case VAProfileVC1Advanced:
1994 vaStatus = VA_STATUS_SUCCESS;
1997 case VAProfileJPEGBaseline:
1998 vaStatus = VA_STATUS_SUCCESS;
2002 vaStatus = VA_STATUS_SUCCESS;
2005 case VAProfileVP8Version0_3:
2006 vaStatus = VA_STATUS_SUCCESS;
2010 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2014 if (obj_context->codec_type == CODEC_PROC) {
2015 obj_context->codec_state.proc.current_render_target = render_target;
2016 } else if (obj_context->codec_type == CODEC_ENC) {
2017 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2019 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2020 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2023 obj_context->codec_state.encode.num_slice_params = 0;
2026 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2028 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2029 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2031 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2032 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2034 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2035 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2037 obj_context->codec_state.encode.num_slice_params_ext = 0;
2038 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2039 obj_context->codec_state.encode.last_packed_header_type = 0;
2041 obj_context->codec_state.decode.current_render_target = render_target;
2042 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2043 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2044 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2045 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2047 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2048 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2049 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2052 obj_context->codec_state.decode.num_slice_params = 0;
2053 obj_context->codec_state.decode.num_slice_datas = 0;
2059 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2061 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2063 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2064 struct object_context *obj_context, \
2065 struct object_buffer *obj_buffer) \
2067 struct category##_state *category = &obj_context->codec_state.category; \
2068 i965_release_buffer_store(&category->member); \
2069 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2070 return VA_STATUS_SUCCESS; \
2073 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2075 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2076 struct object_context *obj_context, \
2077 struct object_buffer *obj_buffer) \
2079 struct category##_state *category = &obj_context->codec_state.category; \
2080 if (category->num_##member == category->max_##member) { \
2081 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2082 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2083 category->max_##member += NUM_SLICES; \
2085 i965_release_buffer_store(&category->member[category->num_##member]); \
2086 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2087 category->num_##member++; \
2088 return VA_STATUS_SUCCESS; \
2091 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2093 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2094 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2095 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2096 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2097 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2098 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2100 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2101 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2102 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2105 i965_decoder_render_picture(VADriverContextP ctx,
2106 VAContextID context,
2107 VABufferID *buffers,
2110 struct i965_driver_data *i965 = i965_driver_data(ctx);
2111 struct object_context *obj_context = CONTEXT(context);
2112 VAStatus vaStatus = VA_STATUS_SUCCESS;
2115 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2117 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2118 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2121 return VA_STATUS_ERROR_INVALID_BUFFER;
2123 switch (obj_buffer->type) {
2124 case VAPictureParameterBufferType:
2125 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2128 case VAIQMatrixBufferType:
2129 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2132 case VABitPlaneBufferType:
2133 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2136 case VASliceParameterBufferType:
2137 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2140 case VASliceDataBufferType:
2141 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2144 case VAHuffmanTableBufferType:
2145 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2148 case VAProbabilityBufferType:
2149 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2153 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2161 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2163 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2164 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2165 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2166 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2167 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2168 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2169 /* extended buffer */
2170 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2171 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2173 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2174 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2175 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2178 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2179 struct object_context *obj_context,
2180 struct object_buffer *obj_buffer,
2183 struct encode_state *encode = &obj_context->codec_state.encode;
2185 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2186 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2187 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2188 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2190 return VA_STATUS_SUCCESS;
2194 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2195 struct object_context *obj_context,
2196 struct object_buffer *obj_buffer,
2199 struct encode_state *encode = &obj_context->codec_state.encode;
2201 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2202 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2203 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2204 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2206 return VA_STATUS_SUCCESS;
2210 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2211 struct object_context *obj_context,
2212 struct object_buffer *obj_buffer)
2214 struct encode_state *encode = &obj_context->codec_state.encode;
2215 VAEncMiscParameterBuffer *param = NULL;
2217 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2218 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2220 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2222 if (param->type >= ARRAY_ELEMS(encode->misc_param))
2223 return VA_STATUS_ERROR_INVALID_PARAMETER;
2225 i965_release_buffer_store(&encode->misc_param[param->type]);
2226 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2228 return VA_STATUS_SUCCESS;
2232 i965_encoder_render_picture(VADriverContextP ctx,
2233 VAContextID context,
2234 VABufferID *buffers,
2237 struct i965_driver_data *i965 = i965_driver_data(ctx);
2238 struct object_context *obj_context = CONTEXT(context);
2239 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2242 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2244 for (i = 0; i < num_buffers; i++) {
2245 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2248 return VA_STATUS_ERROR_INVALID_BUFFER;
2250 switch (obj_buffer->type) {
2251 case VAQMatrixBufferType:
2252 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2255 case VAIQMatrixBufferType:
2256 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2259 case VAEncSequenceParameterBufferType:
2260 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2263 case VAEncPictureParameterBufferType:
2264 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2267 case VAEncSliceParameterBufferType:
2268 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2271 case VAEncPackedHeaderParameterBufferType:
2273 struct encode_state *encode = &obj_context->codec_state.encode;
2274 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2275 encode->last_packed_header_type = param->type;
2277 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2280 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2284 case VAEncPackedHeaderDataBufferType:
2286 struct encode_state *encode = &obj_context->codec_state.encode;
2288 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2289 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2290 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2291 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2292 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
2293 VA_STATUS_ERROR_ENCODING_ERROR);
2294 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2297 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2301 case VAEncMiscParameterBufferType:
2302 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2308 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2316 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2318 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2319 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2322 i965_proc_render_picture(VADriverContextP ctx,
2323 VAContextID context,
2324 VABufferID *buffers,
2327 struct i965_driver_data *i965 = i965_driver_data(ctx);
2328 struct object_context *obj_context = CONTEXT(context);
2329 VAStatus vaStatus = VA_STATUS_SUCCESS;
2332 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2334 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2335 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2338 return VA_STATUS_ERROR_INVALID_BUFFER;
2340 switch (obj_buffer->type) {
2341 case VAProcPipelineParameterBufferType:
2342 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2346 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2355 i965_RenderPicture(VADriverContextP ctx,
2356 VAContextID context,
2357 VABufferID *buffers,
2360 struct i965_driver_data *i965 = i965_driver_data(ctx);
2361 struct object_context *obj_context;
2362 struct object_config *obj_config;
2363 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2365 obj_context = CONTEXT(context);
2366 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2368 if (num_buffers <= 0)
2369 return VA_STATUS_ERROR_INVALID_PARAMETER;
2371 obj_config = obj_context->obj_config;
2372 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2374 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2375 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2376 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2377 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2379 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2386 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2388 struct i965_driver_data *i965 = i965_driver_data(ctx);
2389 struct object_context *obj_context = CONTEXT(context);
2390 struct object_config *obj_config;
2392 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2393 obj_config = obj_context->obj_config;
2394 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2396 if (obj_context->codec_type == CODEC_PROC) {
2397 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2398 } else if (obj_context->codec_type == CODEC_ENC) {
2399 ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2401 if (!(obj_context->codec_state.encode.pic_param ||
2402 obj_context->codec_state.encode.pic_param_ext)) {
2403 return VA_STATUS_ERROR_INVALID_PARAMETER;
2405 if (!(obj_context->codec_state.encode.seq_param ||
2406 obj_context->codec_state.encode.seq_param_ext)) {
2407 return VA_STATUS_ERROR_INVALID_PARAMETER;
2409 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2410 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2411 return VA_STATUS_ERROR_INVALID_PARAMETER;
2414 if (obj_context->codec_state.decode.pic_param == NULL) {
2415 return VA_STATUS_ERROR_INVALID_PARAMETER;
2417 if (obj_context->codec_state.decode.num_slice_params <=0) {
2418 return VA_STATUS_ERROR_INVALID_PARAMETER;
2420 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2421 return VA_STATUS_ERROR_INVALID_PARAMETER;
2424 if (obj_context->codec_state.decode.num_slice_params !=
2425 obj_context->codec_state.decode.num_slice_datas) {
2426 return VA_STATUS_ERROR_INVALID_PARAMETER;
2430 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
2431 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2435 i965_SyncSurface(VADriverContextP ctx,
2436 VASurfaceID render_target)
2438 struct i965_driver_data *i965 = i965_driver_data(ctx);
2439 struct object_surface *obj_surface = SURFACE(render_target);
2441 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2444 drm_intel_bo_wait_rendering(obj_surface->bo);
2446 return VA_STATUS_SUCCESS;
2450 i965_QuerySurfaceStatus(VADriverContextP ctx,
2451 VASurfaceID render_target,
2452 VASurfaceStatus *status) /* out */
2454 struct i965_driver_data *i965 = i965_driver_data(ctx);
2455 struct object_surface *obj_surface = SURFACE(render_target);
2457 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2459 if (obj_surface->bo) {
2460 if (drm_intel_bo_busy(obj_surface->bo)){
2461 *status = VASurfaceRendering;
2464 *status = VASurfaceReady;
2467 *status = VASurfaceReady;
2470 return VA_STATUS_SUCCESS;
2473 static VADisplayAttribute *
2474 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2476 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2479 if (!i965->display_attributes)
2482 for (i = 0; i < i965->num_display_attributes; i++) {
2483 if (i965->display_attributes[i].type == type)
2484 return &i965->display_attributes[i];
2490 i965_display_attributes_terminate(VADriverContextP ctx)
2492 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2494 if (i965->display_attributes) {
2495 free(i965->display_attributes);
2496 i965->display_attributes = NULL;
2497 i965->num_display_attributes = 0;
2502 i965_display_attributes_init(VADriverContextP ctx)
2504 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2506 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2507 i965->display_attributes = malloc(
2508 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2509 if (!i965->display_attributes)
2513 i965->display_attributes,
2514 i965_display_attributes,
2515 sizeof(i965_display_attributes)
2518 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2519 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2520 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2521 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2522 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2524 if (!i965->rotation_attrib ||
2525 !i965->brightness_attrib ||
2526 !i965->contrast_attrib ||
2527 !i965->hue_attrib ||
2528 !i965->saturation_attrib) {
2534 i965_display_attributes_terminate(ctx);
2539 * Query display attributes
2540 * The caller must provide a "attr_list" array that can hold at
2541 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2542 * returned in "attr_list" is returned in "num_attributes".
2545 i965_QueryDisplayAttributes(
2546 VADriverContextP ctx,
2547 VADisplayAttribute *attribs, /* out */
2548 int *num_attribs_ptr /* out */
2551 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2553 if (attribs && num_attribs > 0)
2554 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2556 if (num_attribs_ptr)
2557 *num_attribs_ptr = num_attribs;
2559 return VA_STATUS_SUCCESS;
2563 * Get display attributes
2564 * This function returns the current attribute values in "attr_list".
2565 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2566 * from vaQueryDisplayAttributes() can have their values retrieved.
2569 i965_GetDisplayAttributes(
2570 VADriverContextP ctx,
2571 VADisplayAttribute *attribs, /* inout */
2572 int num_attribs /* in */
2577 for (i = 0; i < num_attribs; i++) {
2578 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2580 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2581 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2582 dst_attrib->min_value = src_attrib->min_value;
2583 dst_attrib->max_value = src_attrib->max_value;
2584 dst_attrib->value = src_attrib->value;
2587 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2589 return VA_STATUS_SUCCESS;
2593 * Set display attributes
2594 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2595 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2596 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2599 i965_SetDisplayAttributes(
2600 VADriverContextP ctx,
2601 VADisplayAttribute *attribs, /* in */
2602 int num_attribs /* in */
2607 for (i = 0; i < num_attribs; i++) {
2608 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2610 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2612 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2614 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2617 if (src_attrib->value < dst_attrib->min_value ||
2618 src_attrib->value > dst_attrib->max_value)
2619 return VA_STATUS_ERROR_INVALID_PARAMETER;
2621 dst_attrib->value = src_attrib->value;
2622 /* XXX: track modified attributes through timestamps */
2624 return VA_STATUS_SUCCESS;
2628 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2629 VASurfaceID surface,
2630 void **buffer, /* out */
2631 unsigned int *stride) /* out */
2634 return VA_STATUS_ERROR_UNIMPLEMENTED;
2638 i965_destroy_heap(struct object_heap *heap,
2639 void (*func)(struct object_heap *heap, struct object_base *object))
2641 struct object_base *object;
2642 object_heap_iterator iter;
2644 object = object_heap_first(heap, &iter);
2650 object = object_heap_next(heap, &iter);
2653 object_heap_destroy(heap);
2658 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2661 i965_CreateImage(VADriverContextP ctx,
2662 VAImageFormat *format,
2665 VAImage *out_image) /* out */
2667 struct i965_driver_data *i965 = i965_driver_data(ctx);
2668 struct object_image *obj_image;
2669 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2671 unsigned int size2, size, awidth, aheight;
2673 out_image->image_id = VA_INVALID_ID;
2674 out_image->buf = VA_INVALID_ID;
2676 image_id = NEW_IMAGE_ID();
2677 if (image_id == VA_INVALID_ID)
2678 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2680 obj_image = IMAGE(image_id);
2682 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2683 obj_image->bo = NULL;
2684 obj_image->palette = NULL;
2685 obj_image->derived_surface = VA_INVALID_ID;
2687 VAImage * const image = &obj_image->image;
2688 image->image_id = image_id;
2689 image->buf = VA_INVALID_ID;
2691 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
2693 if ((format->fourcc == VA_FOURCC_YV12) ||
2694 (format->fourcc == VA_FOURCC_I420)) {
2695 if (awidth % 128 != 0) {
2696 awidth = ALIGN(width, 128);
2700 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
2701 size = awidth * aheight;
2702 size2 = (awidth / 2) * (aheight / 2);
2704 image->num_palette_entries = 0;
2705 image->entry_bytes = 0;
2706 memset(image->component_order, 0, sizeof(image->component_order));
2708 switch (format->fourcc) {
2709 case VA_FOURCC_IA44:
2710 case VA_FOURCC_AI44:
2711 image->num_planes = 1;
2712 image->pitches[0] = awidth;
2713 image->offsets[0] = 0;
2714 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2715 image->num_palette_entries = 16;
2716 image->entry_bytes = 3;
2717 image->component_order[0] = 'R';
2718 image->component_order[1] = 'G';
2719 image->component_order[2] = 'B';
2721 case VA_FOURCC_IA88:
2722 case VA_FOURCC_AI88:
2723 image->num_planes = 1;
2724 image->pitches[0] = awidth * 2;
2725 image->offsets[0] = 0;
2726 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2727 image->num_palette_entries = 256;
2728 image->entry_bytes = 3;
2729 image->component_order[0] = 'R';
2730 image->component_order[1] = 'G';
2731 image->component_order[2] = 'B';
2733 case VA_FOURCC_ARGB:
2734 case VA_FOURCC_ABGR:
2735 case VA_FOURCC_BGRA:
2736 case VA_FOURCC_RGBA:
2737 case VA_FOURCC_BGRX:
2738 case VA_FOURCC_RGBX:
2739 image->num_planes = 1;
2740 image->pitches[0] = awidth * 4;
2741 image->offsets[0] = 0;
2742 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2744 case VA_FOURCC_YV12:
2745 image->num_planes = 3;
2746 image->pitches[0] = awidth;
2747 image->offsets[0] = 0;
2748 image->pitches[1] = awidth / 2;
2749 image->offsets[1] = size;
2750 image->pitches[2] = awidth / 2;
2751 image->offsets[2] = size + size2;
2752 image->data_size = size + 2 * size2;
2754 case VA_FOURCC_I420:
2755 image->num_planes = 3;
2756 image->pitches[0] = awidth;
2757 image->offsets[0] = 0;
2758 image->pitches[1] = awidth / 2;
2759 image->offsets[1] = size;
2760 image->pitches[2] = awidth / 2;
2761 image->offsets[2] = size + size2;
2762 image->data_size = size + 2 * size2;
2764 case VA_FOURCC_422H:
2765 image->num_planes = 3;
2766 image->pitches[0] = awidth;
2767 image->offsets[0] = 0;
2768 image->pitches[1] = awidth / 2;
2769 image->offsets[1] = size;
2770 image->pitches[2] = awidth / 2;
2771 image->offsets[2] = size + (awidth / 2) * aheight;
2772 image->data_size = size + 2 * ((awidth / 2) * aheight);
2774 case VA_FOURCC_NV12:
2775 image->num_planes = 2;
2776 image->pitches[0] = awidth;
2777 image->offsets[0] = 0;
2778 image->pitches[1] = awidth;
2779 image->offsets[1] = size;
2780 image->data_size = size + 2 * size2;
2782 case VA_FOURCC_YUY2:
2783 case VA_FOURCC_UYVY:
2784 image->num_planes = 1;
2785 image->pitches[0] = awidth * 2;
2786 image->offsets[0] = 0;
2787 image->data_size = size * 2;
2793 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2794 image->data_size, 1, NULL, &image->buf);
2795 if (va_status != VA_STATUS_SUCCESS)
2798 struct object_buffer *obj_buffer = BUFFER(image->buf);
2801 !obj_buffer->buffer_store ||
2802 !obj_buffer->buffer_store->bo)
2803 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2805 obj_image->bo = obj_buffer->buffer_store->bo;
2806 dri_bo_reference(obj_image->bo);
2808 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2809 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2810 if (!obj_image->palette)
2814 image->image_id = image_id;
2815 image->format = *format;
2816 image->width = width;
2817 image->height = height;
2819 *out_image = *image;
2820 return VA_STATUS_SUCCESS;
2823 i965_DestroyImage(ctx, image_id);
2828 i965_check_alloc_surface_bo(VADriverContextP ctx,
2829 struct object_surface *obj_surface,
2831 unsigned int fourcc,
2832 unsigned int subsampling)
2834 struct i965_driver_data *i965 = i965_driver_data(ctx);
2835 int region_width, region_height;
2837 if (obj_surface->bo) {
2838 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2839 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2840 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
2841 return VA_STATUS_SUCCESS;
2844 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2845 obj_surface->x_cr_offset = 0;
2847 if ((tiled && !obj_surface->user_disable_tiling)) {
2848 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
2849 fourcc != VA_FOURCC_IYUV &&
2850 fourcc != VA_FOURCC_YV12,
2851 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2852 if (obj_surface->user_h_stride_set) {
2853 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
2855 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2857 if (obj_surface->user_v_stride_set) {
2858 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
2860 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2862 region_height = obj_surface->height;
2865 case VA_FOURCC_NV12:
2866 assert(subsampling == SUBSAMPLE_YUV420);
2867 obj_surface->cb_cr_pitch = obj_surface->width;
2868 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2869 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2870 obj_surface->y_cb_offset = obj_surface->height;
2871 obj_surface->y_cr_offset = obj_surface->height;
2872 region_width = obj_surface->width;
2873 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2877 case VA_FOURCC_IMC1:
2878 assert(subsampling == SUBSAMPLE_YUV420);
2879 obj_surface->cb_cr_pitch = obj_surface->width;
2880 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2881 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2882 obj_surface->y_cr_offset = obj_surface->height;
2883 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2884 region_width = obj_surface->width;
2885 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2889 case VA_FOURCC_IMC3:
2890 assert(subsampling == SUBSAMPLE_YUV420);
2891 obj_surface->cb_cr_pitch = obj_surface->width;
2892 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2893 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2894 obj_surface->y_cb_offset = obj_surface->height;
2895 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2896 region_width = obj_surface->width;
2897 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2901 case VA_FOURCC_422H:
2902 assert(subsampling == SUBSAMPLE_YUV422H);
2903 obj_surface->cb_cr_pitch = obj_surface->width;
2904 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2905 obj_surface->cb_cr_height = obj_surface->orig_height;
2906 obj_surface->y_cb_offset = obj_surface->height;
2907 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2908 region_width = obj_surface->width;
2909 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2913 case VA_FOURCC_422V:
2914 assert(subsampling == SUBSAMPLE_YUV422V);
2915 obj_surface->cb_cr_pitch = obj_surface->width;
2916 obj_surface->cb_cr_width = obj_surface->orig_width;
2917 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2918 obj_surface->y_cb_offset = obj_surface->height;
2919 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2920 region_width = obj_surface->width;
2921 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2925 case VA_FOURCC_411P:
2926 assert(subsampling == SUBSAMPLE_YUV411);
2927 obj_surface->cb_cr_pitch = obj_surface->width;
2928 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2929 obj_surface->cb_cr_height = obj_surface->orig_height;
2930 obj_surface->y_cb_offset = obj_surface->height;
2931 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2932 region_width = obj_surface->width;
2933 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2937 case VA_FOURCC_444P:
2938 assert(subsampling == SUBSAMPLE_YUV444);
2939 obj_surface->cb_cr_pitch = obj_surface->width;
2940 obj_surface->cb_cr_width = obj_surface->orig_width;
2941 obj_surface->cb_cr_height = obj_surface->orig_height;
2942 obj_surface->y_cb_offset = obj_surface->height;
2943 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2944 region_width = obj_surface->width;
2945 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2949 case VA_FOURCC_Y800:
2950 assert(subsampling == SUBSAMPLE_YUV400);
2951 obj_surface->cb_cr_pitch = 0;
2952 obj_surface->cb_cr_width = 0;
2953 obj_surface->cb_cr_height = 0;
2954 obj_surface->y_cb_offset = 0;
2955 obj_surface->y_cr_offset = 0;
2956 region_width = obj_surface->width;
2957 region_height = obj_surface->height;
2961 case VA_FOURCC_YUY2:
2962 case VA_FOURCC_UYVY:
2963 assert(subsampling == SUBSAMPLE_YUV422H);
2964 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
2965 obj_surface->cb_cr_pitch = obj_surface->width;
2966 obj_surface->y_cb_offset = 0;
2967 obj_surface->y_cr_offset = 0;
2968 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2969 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2970 region_width = obj_surface->width;
2971 region_height = obj_surface->height;
2975 case VA_FOURCC_RGBA:
2976 case VA_FOURCC_RGBX:
2977 case VA_FOURCC_BGRA:
2978 case VA_FOURCC_BGRX:
2979 assert(subsampling == SUBSAMPLE_RGBX);
2981 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
2982 region_width = obj_surface->width;
2983 region_height = obj_surface->height;
2987 /* Never get here */
2988 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2992 assert(subsampling == SUBSAMPLE_YUV420 ||
2993 subsampling == SUBSAMPLE_YUV422H ||
2994 subsampling == SUBSAMPLE_YUV422V ||
2995 subsampling == SUBSAMPLE_RGBX);
2997 region_width = obj_surface->width;
2998 region_height = obj_surface->height;
3001 case VA_FOURCC_NV12:
3002 obj_surface->y_cb_offset = obj_surface->height;
3003 obj_surface->y_cr_offset = obj_surface->height;
3004 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3005 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3006 obj_surface->cb_cr_pitch = obj_surface->width;
3007 region_height = obj_surface->height + obj_surface->height / 2;
3010 case VA_FOURCC_YV16:
3011 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3012 obj_surface->cb_cr_height = obj_surface->orig_height;
3013 obj_surface->y_cr_offset = obj_surface->height;
3014 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
3015 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3016 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3019 case VA_FOURCC_YV12:
3020 case VA_FOURCC_I420:
3021 if (fourcc == VA_FOURCC_YV12) {
3022 obj_surface->y_cr_offset = obj_surface->height;
3023 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
3025 obj_surface->y_cb_offset = obj_surface->height;
3026 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
3029 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3030 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3031 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3032 region_height = obj_surface->height + obj_surface->height / 2;
3035 case VA_FOURCC_YUY2:
3036 case VA_FOURCC_UYVY:
3037 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
3038 obj_surface->y_cb_offset = 0;
3039 obj_surface->y_cr_offset = 0;
3040 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3041 obj_surface->cb_cr_height = obj_surface->orig_height;
3042 obj_surface->cb_cr_pitch = obj_surface->width;
3043 region_width = obj_surface->width;
3044 region_height = obj_surface->height;
3046 case VA_FOURCC_RGBA:
3047 case VA_FOURCC_RGBX:
3048 case VA_FOURCC_BGRA:
3049 case VA_FOURCC_BGRX:
3050 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
3051 region_width = obj_surface->width;
3052 region_height = obj_surface->height;
3056 /* Never get here */
3057 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3062 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
3064 if ((tiled && !obj_surface->user_disable_tiling)) {
3065 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
3066 unsigned long pitch;
3068 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
3076 assert(tiling_mode == I915_TILING_Y);
3077 assert(pitch == obj_surface->width);
3079 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
3085 obj_surface->fourcc = fourcc;
3086 obj_surface->subsampling = subsampling;
3087 assert(obj_surface->bo);
3088 return VA_STATUS_SUCCESS;
3091 VAStatus i965_DeriveImage(VADriverContextP ctx,
3092 VASurfaceID surface,
3093 VAImage *out_image) /* out */
3095 struct i965_driver_data *i965 = i965_driver_data(ctx);
3096 struct object_image *obj_image;
3097 struct object_surface *obj_surface;
3099 unsigned int w_pitch;
3100 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3102 out_image->image_id = VA_INVALID_ID;
3103 obj_surface = SURFACE(surface);
3106 return VA_STATUS_ERROR_INVALID_SURFACE;
3108 if (!obj_surface->bo) {
3109 unsigned int is_tiled = 0;
3110 unsigned int fourcc = VA_FOURCC_YV12;
3111 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3112 int sampling = get_sampling_from_fourcc(fourcc);
3113 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3114 if (va_status != VA_STATUS_SUCCESS)
3118 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3120 w_pitch = obj_surface->width;
3122 image_id = NEW_IMAGE_ID();
3124 if (image_id == VA_INVALID_ID)
3125 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3127 obj_image = IMAGE(image_id);
3130 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3132 obj_image->bo = NULL;
3133 obj_image->palette = NULL;
3134 obj_image->derived_surface = VA_INVALID_ID;
3136 VAImage * const image = &obj_image->image;
3138 memset(image, 0, sizeof(*image));
3139 image->image_id = image_id;
3140 image->buf = VA_INVALID_ID;
3141 image->num_palette_entries = 0;
3142 image->entry_bytes = 0;
3143 image->width = obj_surface->orig_width;
3144 image->height = obj_surface->orig_height;
3145 image->data_size = obj_surface->size;
3147 image->format.fourcc = obj_surface->fourcc;
3148 image->format.byte_order = VA_LSB_FIRST;
3149 image->format.bits_per_pixel = 12;
3151 switch (image->format.fourcc) {
3152 case VA_FOURCC_YV12:
3153 image->num_planes = 3;
3154 image->pitches[0] = w_pitch; /* Y */
3155 image->offsets[0] = 0;
3156 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3157 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3158 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3159 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3162 case VA_FOURCC_YV16:
3163 image->num_planes = 3;
3164 image->pitches[0] = w_pitch; /* Y */
3165 image->offsets[0] = 0;
3166 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3167 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3168 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3169 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3172 case VA_FOURCC_NV12:
3173 image->num_planes = 2;
3174 image->pitches[0] = w_pitch; /* Y */
3175 image->offsets[0] = 0;
3176 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3177 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3180 case VA_FOURCC_I420:
3181 case VA_FOURCC_422H:
3182 case VA_FOURCC_IMC3:
3183 case VA_FOURCC_444P:
3184 case VA_FOURCC_422V:
3185 case VA_FOURCC_411P:
3186 image->num_planes = 3;
3187 image->pitches[0] = w_pitch; /* Y */
3188 image->offsets[0] = 0;
3189 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3190 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3191 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3192 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3195 case VA_FOURCC_YUY2:
3196 case VA_FOURCC_UYVY:
3197 case VA_FOURCC_Y800:
3198 image->num_planes = 1;
3199 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
3200 image->offsets[0] = 0;
3202 case VA_FOURCC_RGBA:
3203 case VA_FOURCC_RGBX:
3204 case VA_FOURCC_BGRA:
3205 case VA_FOURCC_BGRX:
3206 image->num_planes = 1;
3207 image->pitches[0] = obj_surface->width;
3213 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3214 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3215 if (va_status != VA_STATUS_SUCCESS)
3218 struct object_buffer *obj_buffer = BUFFER(image->buf);
3221 !obj_buffer->buffer_store ||
3222 !obj_buffer->buffer_store->bo)
3223 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3225 obj_image->bo = obj_buffer->buffer_store->bo;
3226 dri_bo_reference(obj_image->bo);
3228 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3229 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3230 if (!obj_image->palette) {
3231 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3236 *out_image = *image;
3237 obj_surface->flags |= SURFACE_DERIVED;
3238 obj_image->derived_surface = surface;
3240 return VA_STATUS_SUCCESS;
3243 i965_DestroyImage(ctx, image_id);
3248 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3250 object_heap_free(heap, obj);
3255 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3257 struct i965_driver_data *i965 = i965_driver_data(ctx);
3258 struct object_image *obj_image = IMAGE(image);
3259 struct object_surface *obj_surface;
3262 return VA_STATUS_SUCCESS;
3264 dri_bo_unreference(obj_image->bo);
3265 obj_image->bo = NULL;
3267 if (obj_image->image.buf != VA_INVALID_ID) {
3268 i965_DestroyBuffer(ctx, obj_image->image.buf);
3269 obj_image->image.buf = VA_INVALID_ID;
3272 if (obj_image->palette) {
3273 free(obj_image->palette);
3274 obj_image->palette = NULL;
3277 obj_surface = SURFACE(obj_image->derived_surface);
3280 obj_surface->flags &= ~SURFACE_DERIVED;
3283 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3285 return VA_STATUS_SUCCESS;
3289 * pointer to an array holding the palette data. The size of the array is
3290 * num_palette_entries * entry_bytes in size. The order of the components
3291 * in the palette is described by the component_order in VASubpicture struct
3294 i965_SetImagePalette(VADriverContextP ctx,
3296 unsigned char *palette)
3298 struct i965_driver_data *i965 = i965_driver_data(ctx);
3301 struct object_image *obj_image = IMAGE(image);
3303 return VA_STATUS_ERROR_INVALID_IMAGE;
3305 if (!obj_image->palette)
3306 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3308 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3309 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3310 ((unsigned int)palette[3*i + 1] << 8) |
3311 (unsigned int)palette[3*i + 2]);
3312 return VA_STATUS_SUCCESS;
3316 get_sampling_from_fourcc(unsigned int fourcc)
3318 int surface_sampling = -1;
3321 case VA_FOURCC_NV12:
3322 case VA_FOURCC_YV12:
3323 case VA_FOURCC_I420:
3324 case VA_FOURCC_IYUV:
3325 case VA_FOURCC_IMC1:
3326 case VA_FOURCC_IMC3:
3327 surface_sampling = SUBSAMPLE_YUV420;
3329 case VA_FOURCC_YUY2:
3330 case VA_FOURCC_UYVY:
3331 case VA_FOURCC_422H:
3332 case VA_FOURCC_YV16:
3333 surface_sampling = SUBSAMPLE_YUV422H;
3335 case VA_FOURCC_422V:
3336 surface_sampling = SUBSAMPLE_YUV422V;
3339 case VA_FOURCC_444P:
3340 surface_sampling = SUBSAMPLE_YUV444;
3343 case VA_FOURCC_411P:
3344 surface_sampling = SUBSAMPLE_YUV411;
3347 case VA_FOURCC_Y800:
3348 surface_sampling = SUBSAMPLE_YUV400;
3350 case VA_FOURCC_RGBA:
3351 case VA_FOURCC_RGBX:
3352 case VA_FOURCC_BGRA:
3353 case VA_FOURCC_BGRX:
3354 surface_sampling = SUBSAMPLE_RGBX;
3357 /* Never get here */
3363 return surface_sampling;
3367 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3368 const uint8_t *src, unsigned int src_stride,
3369 unsigned int len, unsigned int height)
3373 for (i = 0; i < height; i++) {
3374 memcpy(dst, src, len);
3381 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3382 struct object_surface *obj_surface,
3383 const VARectangle *rect)
3385 uint8_t *dst[3], *src[3];
3387 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3388 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3389 unsigned int tiling, swizzle;
3390 VAStatus va_status = VA_STATUS_SUCCESS;
3392 if (!obj_surface->bo)
3393 return VA_STATUS_ERROR_INVALID_SURFACE;
3395 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3396 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3398 if (tiling != I915_TILING_NONE)
3399 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3401 dri_bo_map(obj_surface->bo, 0);
3403 if (!obj_surface->bo->virtual)
3404 return VA_STATUS_ERROR_INVALID_SURFACE;
3406 /* Dest VA image has either I420 or YV12 format.
3407 Source VA surface alway has I420 format */
3408 dst[Y] = image_data + obj_image->image.offsets[Y];
3409 src[0] = (uint8_t *)obj_surface->bo->virtual;
3410 dst[U] = image_data + obj_image->image.offsets[U];
3411 src[1] = src[0] + obj_surface->width * obj_surface->height;
3412 dst[V] = image_data + obj_image->image.offsets[V];
3413 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3416 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3417 src[0] += rect->y * obj_surface->width + rect->x;
3418 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3419 src[0], obj_surface->width,
3420 rect->width, rect->height);
3423 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3424 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3425 memcpy_pic(dst[U], obj_image->image.pitches[U],
3426 src[1], obj_surface->width / 2,
3427 rect->width / 2, rect->height / 2);
3430 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3431 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3432 memcpy_pic(dst[V], obj_image->image.pitches[V],
3433 src[2], obj_surface->width / 2,
3434 rect->width / 2, rect->height / 2);
3436 if (tiling != I915_TILING_NONE)
3437 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3439 dri_bo_unmap(obj_surface->bo);
3445 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3446 struct object_surface *obj_surface,
3447 const VARectangle *rect)
3449 uint8_t *dst[2], *src[2];
3450 unsigned int tiling, swizzle;
3451 VAStatus va_status = VA_STATUS_SUCCESS;
3453 if (!obj_surface->bo)
3454 return VA_STATUS_ERROR_INVALID_SURFACE;
3456 assert(obj_surface->fourcc);
3457 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3459 if (tiling != I915_TILING_NONE)
3460 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3462 dri_bo_map(obj_surface->bo, 0);
3464 if (!obj_surface->bo->virtual)
3465 return VA_STATUS_ERROR_INVALID_SURFACE;
3467 /* Both dest VA image and source surface have NV12 format */
3468 dst[0] = image_data + obj_image->image.offsets[0];
3469 src[0] = (uint8_t *)obj_surface->bo->virtual;
3470 dst[1] = image_data + obj_image->image.offsets[1];
3471 src[1] = src[0] + obj_surface->width * obj_surface->height;
3474 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3475 src[0] += rect->y * obj_surface->width + rect->x;
3476 memcpy_pic(dst[0], obj_image->image.pitches[0],
3477 src[0], obj_surface->width,
3478 rect->width, rect->height);
3481 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3482 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3483 memcpy_pic(dst[1], obj_image->image.pitches[1],
3484 src[1], obj_surface->width,
3485 rect->width, rect->height / 2);
3487 if (tiling != I915_TILING_NONE)
3488 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3490 dri_bo_unmap(obj_surface->bo);
3496 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3497 struct object_surface *obj_surface,
3498 const VARectangle *rect)
3501 unsigned int tiling, swizzle;
3502 VAStatus va_status = VA_STATUS_SUCCESS;
3504 if (!obj_surface->bo)
3505 return VA_STATUS_ERROR_INVALID_SURFACE;
3507 assert(obj_surface->fourcc);
3508 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3510 if (tiling != I915_TILING_NONE)
3511 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3513 dri_bo_map(obj_surface->bo, 0);
3515 if (!obj_surface->bo->virtual)
3516 return VA_STATUS_ERROR_INVALID_SURFACE;
3518 /* Both dest VA image and source surface have YUYV format */
3519 dst = image_data + obj_image->image.offsets[0];
3520 src = (uint8_t *)obj_surface->bo->virtual;
3523 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3524 src += rect->y * obj_surface->width + rect->x*2;
3525 memcpy_pic(dst, obj_image->image.pitches[0],
3526 src, obj_surface->width*2,
3527 rect->width*2, rect->height);
3529 if (tiling != I915_TILING_NONE)
3530 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3532 dri_bo_unmap(obj_surface->bo);
3538 i965_sw_getimage(VADriverContextP ctx,
3539 VASurfaceID surface,
3540 int x, /* coordinates of the upper left source pixel */
3542 unsigned int width, /* width and height of the region */
3543 unsigned int height,
3546 struct i965_driver_data *i965 = i965_driver_data(ctx);
3547 struct i965_render_state *render_state = &i965->render_state;
3548 VAStatus va_status = VA_STATUS_SUCCESS;
3550 struct object_surface *obj_surface = SURFACE(surface);
3552 return VA_STATUS_ERROR_INVALID_SURFACE;
3554 struct object_image *obj_image = IMAGE(image);
3556 return VA_STATUS_ERROR_INVALID_IMAGE;
3559 return VA_STATUS_ERROR_INVALID_PARAMETER;
3560 if (x + width > obj_surface->orig_width ||
3561 y + height > obj_surface->orig_height)
3562 return VA_STATUS_ERROR_INVALID_PARAMETER;
3563 if (x + width > obj_image->image.width ||
3564 y + height > obj_image->image.height)
3565 return VA_STATUS_ERROR_INVALID_PARAMETER;
3567 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3568 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3570 void *image_data = NULL;
3572 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3573 if (va_status != VA_STATUS_SUCCESS)
3580 rect.height = height;
3582 switch (obj_image->image.format.fourcc) {
3583 case VA_FOURCC_YV12:
3584 case VA_FOURCC_I420:
3585 /* I420 is native format for MPEG-2 decoded surfaces */
3586 if (render_state->interleaved_uv)
3587 goto operation_failed;
3588 get_image_i420(obj_image, image_data, obj_surface, &rect);
3590 case VA_FOURCC_NV12:
3591 /* NV12 is native format for H.264 decoded surfaces */
3592 if (!render_state->interleaved_uv)
3593 goto operation_failed;
3594 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3596 case VA_FOURCC_YUY2:
3597 /* YUY2 is the format supported by overlay plane */
3598 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3602 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3606 if (va_status != VA_STATUS_SUCCESS)
3609 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3614 i965_hw_getimage(VADriverContextP ctx,
3615 VASurfaceID surface,
3616 int x, /* coordinates of the upper left source pixel */
3618 unsigned int width, /* width and height of the region */
3619 unsigned int height,
3622 struct i965_driver_data *i965 = i965_driver_data(ctx);
3623 struct i965_surface src_surface;
3624 struct i965_surface dst_surface;
3625 VAStatus va_status = VA_STATUS_SUCCESS;
3627 struct object_surface *obj_surface = SURFACE(surface);
3628 struct object_image *obj_image = IMAGE(image);
3631 return VA_STATUS_ERROR_INVALID_SURFACE;
3634 return VA_STATUS_ERROR_INVALID_IMAGE;
3637 return VA_STATUS_ERROR_INVALID_PARAMETER;
3638 if (x + width > obj_surface->orig_width ||
3639 y + height > obj_surface->orig_height)
3640 return VA_STATUS_ERROR_INVALID_PARAMETER;
3641 if (x + width > obj_image->image.width ||
3642 y + height > obj_image->image.height)
3643 return VA_STATUS_ERROR_INVALID_PARAMETER;
3645 if (!obj_surface->bo)
3646 return VA_STATUS_SUCCESS;
3647 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3652 rect.height = height;
3654 src_surface.base = (struct object_base *)obj_surface;
3655 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3656 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3658 dst_surface.base = (struct object_base *)obj_image;
3659 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3660 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3662 va_status = i965_image_processing(ctx,
3673 i965_GetImage(VADriverContextP ctx,
3674 VASurfaceID surface,
3675 int x, /* coordinates of the upper left source pixel */
3677 unsigned int width, /* width and height of the region */
3678 unsigned int height,
3681 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3682 VAStatus va_status = VA_STATUS_SUCCESS;
3684 if (HAS_ACCELERATED_GETIMAGE(i965))
3685 va_status = i965_hw_getimage(ctx,
3691 va_status = i965_sw_getimage(ctx,
3701 put_image_i420(struct object_surface *obj_surface,
3702 const VARectangle *dst_rect,
3703 struct object_image *obj_image, uint8_t *image_data,
3704 const VARectangle *src_rect)
3706 uint8_t *dst[3], *src[3];
3708 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3709 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3710 unsigned int tiling, swizzle;
3711 VAStatus va_status = VA_STATUS_SUCCESS;
3713 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3715 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3716 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3717 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3718 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3720 if (tiling != I915_TILING_NONE)
3721 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3723 dri_bo_map(obj_surface->bo, 0);
3725 if (!obj_surface->bo->virtual)
3726 return VA_STATUS_ERROR_INVALID_SURFACE;
3728 /* Dest VA image has either I420 or YV12 format.
3729 Source VA surface alway has I420 format */
3730 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3731 src[Y] = image_data + obj_image->image.offsets[Y];
3732 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3733 src[U] = image_data + obj_image->image.offsets[U];
3734 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3735 src[V] = image_data + obj_image->image.offsets[V];
3738 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3739 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3740 memcpy_pic(dst[0], obj_surface->width,
3741 src[Y], obj_image->image.pitches[Y],
3742 src_rect->width, src_rect->height);
3745 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3746 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3747 memcpy_pic(dst[1], obj_surface->width / 2,
3748 src[U], obj_image->image.pitches[U],
3749 src_rect->width / 2, src_rect->height / 2);
3752 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3753 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3754 memcpy_pic(dst[2], obj_surface->width / 2,
3755 src[V], obj_image->image.pitches[V],
3756 src_rect->width / 2, src_rect->height / 2);
3758 if (tiling != I915_TILING_NONE)
3759 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3761 dri_bo_unmap(obj_surface->bo);
3767 put_image_nv12(struct object_surface *obj_surface,
3768 const VARectangle *dst_rect,
3769 struct object_image *obj_image, uint8_t *image_data,
3770 const VARectangle *src_rect)
3772 uint8_t *dst[2], *src[2];
3773 unsigned int tiling, swizzle;
3774 VAStatus va_status = VA_STATUS_SUCCESS;
3776 if (!obj_surface->bo)
3777 return VA_STATUS_ERROR_INVALID_SURFACE;
3779 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3780 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3781 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3782 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3784 if (tiling != I915_TILING_NONE)
3785 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3787 dri_bo_map(obj_surface->bo, 0);
3789 if (!obj_surface->bo->virtual)
3790 return VA_STATUS_ERROR_INVALID_SURFACE;
3792 /* Both dest VA image and source surface have NV12 format */
3793 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3794 src[0] = image_data + obj_image->image.offsets[0];
3795 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3796 src[1] = image_data + obj_image->image.offsets[1];
3799 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3800 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3801 memcpy_pic(dst[0], obj_surface->width,
3802 src[0], obj_image->image.pitches[0],
3803 src_rect->width, src_rect->height);
3806 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3807 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3808 memcpy_pic(dst[1], obj_surface->width,
3809 src[1], obj_image->image.pitches[1],
3810 src_rect->width, src_rect->height / 2);
3812 if (tiling != I915_TILING_NONE)
3813 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3815 dri_bo_unmap(obj_surface->bo);
3821 put_image_yuy2(struct object_surface *obj_surface,
3822 const VARectangle *dst_rect,
3823 struct object_image *obj_image, uint8_t *image_data,
3824 const VARectangle *src_rect)
3827 unsigned int tiling, swizzle;
3828 VAStatus va_status = VA_STATUS_SUCCESS;
3830 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3831 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3832 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3833 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3834 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3836 if (tiling != I915_TILING_NONE)
3837 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3839 dri_bo_map(obj_surface->bo, 0);
3841 if (!obj_surface->bo->virtual)
3842 return VA_STATUS_ERROR_INVALID_SURFACE;
3844 /* Both dest VA image and source surface have YUY2 format */
3845 dst = (uint8_t *)obj_surface->bo->virtual;
3846 src = image_data + obj_image->image.offsets[0];
3848 /* YUYV packed plane */
3849 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3850 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3851 memcpy_pic(dst, obj_surface->width*2,
3852 src, obj_image->image.pitches[0],
3853 src_rect->width*2, src_rect->height);
3855 if (tiling != I915_TILING_NONE)
3856 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3858 dri_bo_unmap(obj_surface->bo);
3865 i965_sw_putimage(VADriverContextP ctx,
3866 VASurfaceID surface,
3870 unsigned int src_width,
3871 unsigned int src_height,
3874 unsigned int dest_width,
3875 unsigned int dest_height)
3877 struct i965_driver_data *i965 = i965_driver_data(ctx);
3878 struct object_surface *obj_surface = SURFACE(surface);
3879 struct object_image *obj_image = IMAGE(image);
3880 VAStatus va_status = VA_STATUS_SUCCESS;
3881 void *image_data = NULL;
3883 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3884 ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE);
3886 if (src_x < 0 || src_y < 0)
3887 return VA_STATUS_ERROR_INVALID_PARAMETER;
3888 if (src_x + src_width > obj_image->image.width ||
3889 src_y + src_height > obj_image->image.height)
3890 return VA_STATUS_ERROR_INVALID_PARAMETER;
3891 if (dest_x < 0 || dest_y < 0)
3892 return VA_STATUS_ERROR_INVALID_PARAMETER;
3893 if (dest_x + dest_width > obj_surface->orig_width ||
3894 dest_y + dest_height > obj_surface->orig_height)
3895 return VA_STATUS_ERROR_INVALID_PARAMETER;
3897 /* XXX: don't allow scaling */
3898 if (src_width != dest_width || src_height != dest_height)
3899 return VA_STATUS_ERROR_INVALID_PARAMETER;
3901 if (obj_surface->fourcc) {
3902 /* Don't allow format mismatch */
3903 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3904 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3908 /* VA is surface not used for decoding, use same VA image format */
3909 va_status = i965_check_alloc_surface_bo(
3912 0, /* XXX: don't use tiled surface */
3913 obj_image->image.format.fourcc,
3914 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3917 if (va_status != VA_STATUS_SUCCESS)
3920 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3921 if (va_status != VA_STATUS_SUCCESS)
3924 VARectangle src_rect, dest_rect;
3927 src_rect.width = src_width;
3928 src_rect.height = src_height;
3929 dest_rect.x = dest_x;
3930 dest_rect.y = dest_y;
3931 dest_rect.width = dest_width;
3932 dest_rect.height = dest_height;
3934 switch (obj_image->image.format.fourcc) {
3935 case VA_FOURCC_YV12:
3936 case VA_FOURCC_I420:
3937 va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3939 case VA_FOURCC_NV12:
3940 va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3942 case VA_FOURCC_YUY2:
3943 va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3946 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3949 if (va_status != VA_STATUS_SUCCESS)
3952 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3957 i965_hw_putimage(VADriverContextP ctx,
3958 VASurfaceID surface,
3962 unsigned int src_width,
3963 unsigned int src_height,
3966 unsigned int dest_width,
3967 unsigned int dest_height)
3969 struct i965_driver_data *i965 = i965_driver_data(ctx);
3970 struct object_surface *obj_surface = SURFACE(surface);
3971 struct object_image *obj_image = IMAGE(image);
3972 struct i965_surface src_surface, dst_surface;
3973 VAStatus va_status = VA_STATUS_SUCCESS;
3974 VARectangle src_rect, dst_rect;
3976 ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE);
3977 ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE);
3981 src_x + src_width > obj_image->image.width ||
3982 src_y + src_height > obj_image->image.height)
3983 return VA_STATUS_ERROR_INVALID_PARAMETER;
3987 dest_x + dest_width > obj_surface->orig_width ||
3988 dest_y + dest_height > obj_surface->orig_height)
3989 return VA_STATUS_ERROR_INVALID_PARAMETER;
3991 if (!obj_surface->bo) {
3992 unsigned int tiling, swizzle;
3993 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3994 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3996 i965_check_alloc_surface_bo(ctx,
3999 obj_image->image.format.fourcc,
4003 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4005 src_surface.base = (struct object_base *)obj_image;
4006 src_surface.type = I965_SURFACE_TYPE_IMAGE;
4007 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4010 src_rect.width = src_width;
4011 src_rect.height = src_height;
4013 dst_surface.base = (struct object_base *)obj_surface;
4014 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4015 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4016 dst_rect.x = dest_x;
4017 dst_rect.y = dest_y;
4018 dst_rect.width = dest_width;
4019 dst_rect.height = dest_height;
4021 va_status = i965_image_processing(ctx,
4031 i965_PutImage(VADriverContextP ctx,
4032 VASurfaceID surface,
4036 unsigned int src_width,
4037 unsigned int src_height,
4040 unsigned int dest_width,
4041 unsigned int dest_height)
4043 struct i965_driver_data *i965 = i965_driver_data(ctx);
4044 VAStatus va_status = VA_STATUS_SUCCESS;
4046 if (HAS_ACCELERATED_PUTIMAGE(i965))
4047 va_status = i965_hw_putimage(ctx,
4059 va_status = i965_sw_putimage(ctx,
4075 i965_PutSurface(VADriverContextP ctx,
4076 VASurfaceID surface,
4077 void *draw, /* X Drawable */
4080 unsigned short srcw,
4081 unsigned short srch,
4084 unsigned short destw,
4085 unsigned short desth,
4086 VARectangle *cliprects, /* client supplied clip list */
4087 unsigned int number_cliprects, /* number of clip rects in the clip list */
4088 unsigned int flags) /* de-interlacing flags */
4091 if (IS_VA_X11(ctx)) {
4092 VARectangle src_rect, dst_rect;
4096 src_rect.width = srcw;
4097 src_rect.height = srch;
4101 dst_rect.width = destw;
4102 dst_rect.height = desth;
4104 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
4105 cliprects, number_cliprects, flags);
4108 return VA_STATUS_ERROR_UNIMPLEMENTED;
4113 VADriverContextP ctx, /* in */
4114 VABufferID buf_id, /* in */
4115 VABufferType *type, /* out */
4116 unsigned int *size, /* out */
4117 unsigned int *num_elements /* out */
4120 struct i965_driver_data *i965 = NULL;
4121 struct object_buffer *obj_buffer = NULL;
4123 i965 = i965_driver_data(ctx);
4124 obj_buffer = BUFFER(buf_id);
4126 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
4128 *type = obj_buffer->type;
4129 *size = obj_buffer->size_element;
4130 *num_elements = obj_buffer->num_elements;
4132 return VA_STATUS_SUCCESS;
4137 VADriverContextP ctx, /* in */
4138 VASurfaceID surface, /* in */
4139 unsigned int *fourcc, /* out */
4140 unsigned int *luma_stride, /* out */
4141 unsigned int *chroma_u_stride, /* out */
4142 unsigned int *chroma_v_stride, /* out */
4143 unsigned int *luma_offset, /* out */
4144 unsigned int *chroma_u_offset, /* out */
4145 unsigned int *chroma_v_offset, /* out */
4146 unsigned int *buffer_name, /* out */
4147 void **buffer /* out */
4150 VAStatus vaStatus = VA_STATUS_SUCCESS;
4151 struct i965_driver_data *i965 = i965_driver_data(ctx);
4152 struct object_surface *obj_surface = NULL;
4155 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
4156 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4157 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4158 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4159 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4160 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4161 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4162 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
4163 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
4165 tmpImage.image_id = VA_INVALID_ID;
4167 obj_surface = SURFACE(surface);
4168 if (obj_surface == NULL) {
4169 // Surface is absent.
4170 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4174 // Lock functionality is absent now.
4175 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4176 // Surface is locked already.
4177 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4181 vaStatus = i965_DeriveImage(
4185 if (vaStatus != VA_STATUS_SUCCESS) {
4189 obj_surface->locked_image_id = tmpImage.image_id;
4191 vaStatus = i965_MapBuffer(
4195 if (vaStatus != VA_STATUS_SUCCESS) {
4199 *fourcc = tmpImage.format.fourcc;
4200 *luma_offset = tmpImage.offsets[0];
4201 *luma_stride = tmpImage.pitches[0];
4202 *chroma_u_offset = tmpImage.offsets[1];
4203 *chroma_u_stride = tmpImage.pitches[1];
4204 *chroma_v_offset = tmpImage.offsets[2];
4205 *chroma_v_stride = tmpImage.pitches[2];
4206 *buffer_name = tmpImage.buf;
4209 if (vaStatus != VA_STATUS_SUCCESS) {
4218 VADriverContextP ctx, /* in */
4219 VASurfaceID surface /* in */
4222 VAStatus vaStatus = VA_STATUS_SUCCESS;
4223 struct i965_driver_data *i965 = i965_driver_data(ctx);
4224 struct object_image *locked_img = NULL;
4225 struct object_surface *obj_surface = NULL;
4227 obj_surface = SURFACE(surface);
4229 if (obj_surface == NULL) {
4230 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4233 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4234 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4238 locked_img = IMAGE(obj_surface->locked_image_id);
4239 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4240 // Work image was deallocated before i965_UnlockSurface()
4241 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4245 vaStatus = i965_UnmapBuffer(
4247 locked_img->image.buf);
4248 if (vaStatus != VA_STATUS_SUCCESS) {
4252 vaStatus = i965_DestroyImage(
4254 locked_img->image.image_id);
4255 if (vaStatus != VA_STATUS_SUCCESS) {
4259 locked_img->image.image_id = VA_INVALID_ID;
4262 obj_surface->locked_image_id = VA_INVALID_ID;
4268 i965_GetSurfaceAttributes(
4269 VADriverContextP ctx,
4271 VASurfaceAttrib *attrib_list,
4272 unsigned int num_attribs
4275 VAStatus vaStatus = VA_STATUS_SUCCESS;
4276 struct i965_driver_data *i965 = i965_driver_data(ctx);
4277 struct object_config *obj_config;
4280 if (config == VA_INVALID_ID)
4281 return VA_STATUS_ERROR_INVALID_CONFIG;
4283 obj_config = CONFIG(config);
4285 if (obj_config == NULL)
4286 return VA_STATUS_ERROR_INVALID_CONFIG;
4288 if (attrib_list == NULL || num_attribs == 0)
4289 return VA_STATUS_ERROR_INVALID_PARAMETER;
4291 for (i = 0; i < num_attribs; i++) {
4292 switch (attrib_list[i].type) {
4293 case VASurfaceAttribPixelFormat:
4294 attrib_list[i].value.type = VAGenericValueTypeInteger;
4295 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4297 if (attrib_list[i].value.value.i == 0) {
4298 if (IS_G4X(i965->intel.device_info)) {
4299 if (obj_config->profile == VAProfileMPEG2Simple ||
4300 obj_config->profile == VAProfileMPEG2Main) {
4301 attrib_list[i].value.value.i = VA_FOURCC_I420;
4304 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4306 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4307 if (obj_config->profile == VAProfileMPEG2Simple ||
4308 obj_config->profile == VAProfileMPEG2Main) {
4309 attrib_list[i].value.value.i = VA_FOURCC_I420;
4310 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4311 obj_config->profile == VAProfileH264Main ||
4312 obj_config->profile == VAProfileH264High) {
4313 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4314 } else if (obj_config->profile == VAProfileNone) {
4315 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4318 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4320 } else if (IS_GEN6(i965->intel.device_info)) {
4321 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4322 } else if (IS_GEN7(i965->intel.device_info) ||
4323 IS_GEN8(i965->intel.device_info)) {
4324 if (obj_config->profile == VAProfileJPEGBaseline)
4325 attrib_list[i].value.value.i = 0; /* internal format */
4327 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4330 if (IS_G4X(i965->intel.device_info)) {
4331 if (obj_config->profile == VAProfileMPEG2Simple ||
4332 obj_config->profile == VAProfileMPEG2Main) {
4333 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4334 attrib_list[i].value.value.i = 0;
4335 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4339 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4341 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4342 if (obj_config->profile == VAProfileMPEG2Simple ||
4343 obj_config->profile == VAProfileMPEG2Main) {
4344 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4345 attrib_list[i].value.value.i = 0;
4346 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4348 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4349 obj_config->profile == VAProfileH264Main ||
4350 obj_config->profile == VAProfileH264High) {
4351 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4352 attrib_list[i].value.value.i = 0;
4353 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4355 } else if (obj_config->profile == VAProfileNone) {
4356 switch (attrib_list[i].value.value.i) {
4357 case VA_FOURCC_NV12:
4358 case VA_FOURCC_I420:
4359 case VA_FOURCC_YV12:
4360 case VA_FOURCC_YUY2:
4361 case VA_FOURCC_BGRA:
4362 case VA_FOURCC_BGRX:
4363 case VA_FOURCC_RGBX:
4364 case VA_FOURCC_RGBA:
4367 attrib_list[i].value.value.i = 0;
4368 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4373 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4375 } else if (IS_GEN6(i965->intel.device_info)) {
4376 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4377 obj_config->entrypoint == VAEntrypointVideoProc) {
4378 switch (attrib_list[i].value.value.i) {
4379 case VA_FOURCC_NV12:
4380 case VA_FOURCC_I420:
4381 case VA_FOURCC_YV12:
4382 case VA_FOURCC_YUY2:
4383 case VA_FOURCC_BGRA:
4384 case VA_FOURCC_BGRX:
4385 case VA_FOURCC_RGBX:
4386 case VA_FOURCC_RGBA:
4389 attrib_list[i].value.value.i = 0;
4390 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4394 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4395 attrib_list[i].value.value.i = 0;
4396 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4399 } else if (IS_GEN7(i965->intel.device_info) ||
4400 IS_GEN8(i965->intel.device_info)) {
4401 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4402 obj_config->entrypoint == VAEntrypointVideoProc) {
4403 switch (attrib_list[i].value.value.i) {
4404 case VA_FOURCC_NV12:
4405 case VA_FOURCC_I420:
4406 case VA_FOURCC_YV12:
4409 attrib_list[i].value.value.i = 0;
4410 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4414 if (obj_config->profile == VAProfileJPEGBaseline) {
4415 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4416 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4418 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4419 attrib_list[i].value.value.i = 0;
4420 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4428 case VASurfaceAttribMinWidth:
4429 /* FIXME: add support for it later */
4430 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4432 case VASurfaceAttribMaxWidth:
4433 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4435 case VASurfaceAttribMinHeight:
4436 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4438 case VASurfaceAttribMaxHeight:
4439 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4442 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4451 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4453 VASurfaceAttrib *attrib_list,
4454 unsigned int *num_attribs)
4456 VAStatus vaStatus = VA_STATUS_SUCCESS;
4457 struct i965_driver_data *i965 = i965_driver_data(ctx);
4458 struct object_config *obj_config;
4460 VASurfaceAttrib *attribs = NULL;
4462 if (config == VA_INVALID_ID)
4463 return VA_STATUS_ERROR_INVALID_CONFIG;
4465 obj_config = CONFIG(config);
4467 if (obj_config == NULL)
4468 return VA_STATUS_ERROR_INVALID_CONFIG;
4470 if (!attrib_list && !num_attribs)
4471 return VA_STATUS_ERROR_INVALID_PARAMETER;
4473 if (attrib_list == NULL) {
4474 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4475 return VA_STATUS_SUCCESS;
4478 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4480 if (attribs == NULL)
4481 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4483 if (IS_G4X(i965->intel.device_info)) {
4484 if (obj_config->profile == VAProfileMPEG2Simple ||
4485 obj_config->profile == VAProfileMPEG2Main) {
4486 attribs[i].type = VASurfaceAttribPixelFormat;
4487 attribs[i].value.type = VAGenericValueTypeInteger;
4488 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4489 attribs[i].value.value.i = VA_FOURCC_I420;
4492 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4493 switch (obj_config->profile) {
4494 case VAProfileMPEG2Simple:
4495 case VAProfileMPEG2Main:
4496 attribs[i].type = VASurfaceAttribPixelFormat;
4497 attribs[i].value.type = VAGenericValueTypeInteger;
4498 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4499 attribs[i].value.value.i = VA_FOURCC_I420;
4504 case VAProfileH264ConstrainedBaseline:
4505 case VAProfileH264Main:
4506 case VAProfileH264High:
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_NV12;
4514 attribs[i].type = VASurfaceAttribPixelFormat;
4515 attribs[i].value.type = VAGenericValueTypeInteger;
4516 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4517 attribs[i].value.value.i = VA_FOURCC_NV12;
4520 attribs[i].type = VASurfaceAttribPixelFormat;
4521 attribs[i].value.type = VAGenericValueTypeInteger;
4522 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4523 attribs[i].value.value.i = VA_FOURCC_I420;
4531 } else if (IS_GEN6(i965->intel.device_info)) {
4532 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4533 attribs[i].type = VASurfaceAttribPixelFormat;
4534 attribs[i].value.type = VAGenericValueTypeInteger;
4535 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4536 attribs[i].value.value.i = VA_FOURCC_NV12;
4538 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4539 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4540 attribs[i].type = VASurfaceAttribPixelFormat;
4541 attribs[i].value.type = VAGenericValueTypeInteger;
4542 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4543 attribs[i].value.value.i = VA_FOURCC_NV12;
4546 attribs[i].type = VASurfaceAttribPixelFormat;
4547 attribs[i].value.type = VAGenericValueTypeInteger;
4548 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4549 attribs[i].value.value.i = VA_FOURCC_I420;
4552 attribs[i].type = VASurfaceAttribPixelFormat;
4553 attribs[i].value.type = VAGenericValueTypeInteger;
4554 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4555 attribs[i].value.value.i = VA_FOURCC_YV12;
4558 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4559 attribs[i].type = VASurfaceAttribPixelFormat;
4560 attribs[i].value.type = VAGenericValueTypeInteger;
4561 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4562 attribs[i].value.value.i = VA_FOURCC_YUY2;
4565 attribs[i].type = VASurfaceAttribPixelFormat;
4566 attribs[i].value.type = VAGenericValueTypeInteger;
4567 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4568 attribs[i].value.value.i = VA_FOURCC_RGBA;
4571 attribs[i].type = VASurfaceAttribPixelFormat;
4572 attribs[i].value.type = VAGenericValueTypeInteger;
4573 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4574 attribs[i].value.value.i = VA_FOURCC_RGBX;
4578 } else if (IS_GEN7(i965->intel.device_info)) {
4579 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4580 if (obj_config->profile == VAProfileJPEGBaseline) {
4581 attribs[i].type = VASurfaceAttribPixelFormat;
4582 attribs[i].value.type = VAGenericValueTypeInteger;
4583 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4584 attribs[i].value.value.i = VA_FOURCC_IMC3;
4587 attribs[i].type = VASurfaceAttribPixelFormat;
4588 attribs[i].value.type = VAGenericValueTypeInteger;
4589 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4590 attribs[i].value.value.i = VA_FOURCC_IMC1;
4593 attribs[i].type = VASurfaceAttribPixelFormat;
4594 attribs[i].value.type = VAGenericValueTypeInteger;
4595 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4596 attribs[i].value.value.i = VA_FOURCC_Y800;
4599 attribs[i].type = VASurfaceAttribPixelFormat;
4600 attribs[i].value.type = VAGenericValueTypeInteger;
4601 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4602 attribs[i].value.value.i = VA_FOURCC_411P;
4605 attribs[i].type = VASurfaceAttribPixelFormat;
4606 attribs[i].value.type = VAGenericValueTypeInteger;
4607 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4608 attribs[i].value.value.i = VA_FOURCC_422H;
4611 attribs[i].type = VASurfaceAttribPixelFormat;
4612 attribs[i].value.type = VAGenericValueTypeInteger;
4613 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4614 attribs[i].value.value.i = VA_FOURCC_422V;
4617 attribs[i].type = VASurfaceAttribPixelFormat;
4618 attribs[i].value.type = VAGenericValueTypeInteger;
4619 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4620 attribs[i].value.value.i = VA_FOURCC_444P;
4623 attribs[i].type = VASurfaceAttribPixelFormat;
4624 attribs[i].value.type = VAGenericValueTypeInteger;
4625 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4626 attribs[i].value.value.i = VA_FOURCC_NV12;
4629 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4630 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4631 attribs[i].type = VASurfaceAttribPixelFormat;
4632 attribs[i].value.type = VAGenericValueTypeInteger;
4633 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4634 attribs[i].value.value.i = VA_FOURCC_NV12;
4637 attribs[i].type = VASurfaceAttribPixelFormat;
4638 attribs[i].value.type = VAGenericValueTypeInteger;
4639 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4640 attribs[i].value.value.i = VA_FOURCC_I420;
4643 attribs[i].type = VASurfaceAttribPixelFormat;
4644 attribs[i].value.type = VAGenericValueTypeInteger;
4645 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4646 attribs[i].value.value.i = VA_FOURCC_YV12;
4649 attribs[i].type = VASurfaceAttribPixelFormat;
4650 attribs[i].value.type = VAGenericValueTypeInteger;
4651 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4652 attribs[i].value.value.i = VA_FOURCC_IMC3;
4655 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4656 attribs[i].type = VASurfaceAttribPixelFormat;
4657 attribs[i].value.type = VAGenericValueTypeInteger;
4658 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4659 attribs[i].value.value.i = VA_FOURCC_YUY2;
4662 attribs[i].type = VASurfaceAttribPixelFormat;
4663 attribs[i].value.type = VAGenericValueTypeInteger;
4664 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4665 attribs[i].value.value.i = VA_FOURCC_RGBA;
4668 attribs[i].type = VASurfaceAttribPixelFormat;
4669 attribs[i].value.type = VAGenericValueTypeInteger;
4670 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4671 attribs[i].value.value.i = VA_FOURCC_RGBX;
4674 attribs[i].type = VASurfaceAttribPixelFormat;
4675 attribs[i].value.type = VAGenericValueTypeInteger;
4676 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4677 attribs[i].value.value.i = VA_FOURCC_YV16;
4681 } else if (IS_GEN8(i965->intel.device_info)) {
4682 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4683 if (obj_config->profile == VAProfileJPEGBaseline) {
4684 attribs[i].type = VASurfaceAttribPixelFormat;
4685 attribs[i].value.type = VAGenericValueTypeInteger;
4686 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4687 attribs[i].value.value.i = VA_FOURCC_IMC3;
4690 attribs[i].type = VASurfaceAttribPixelFormat;
4691 attribs[i].value.type = VAGenericValueTypeInteger;
4692 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4693 attribs[i].value.value.i = VA_FOURCC_IMC1;
4696 attribs[i].type = VASurfaceAttribPixelFormat;
4697 attribs[i].value.type = VAGenericValueTypeInteger;
4698 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4699 attribs[i].value.value.i = VA_FOURCC_Y800;
4702 attribs[i].type = VASurfaceAttribPixelFormat;
4703 attribs[i].value.type = VAGenericValueTypeInteger;
4704 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4705 attribs[i].value.value.i = VA_FOURCC_411P;
4708 attribs[i].type = VASurfaceAttribPixelFormat;
4709 attribs[i].value.type = VAGenericValueTypeInteger;
4710 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4711 attribs[i].value.value.i = VA_FOURCC_422H;
4714 attribs[i].type = VASurfaceAttribPixelFormat;
4715 attribs[i].value.type = VAGenericValueTypeInteger;
4716 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4717 attribs[i].value.value.i = VA_FOURCC_422V;
4720 attribs[i].type = VASurfaceAttribPixelFormat;
4721 attribs[i].value.type = VAGenericValueTypeInteger;
4722 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4723 attribs[i].value.value.i = VA_FOURCC_444P;
4726 attribs[i].type = VASurfaceAttribPixelFormat;
4727 attribs[i].value.type = VAGenericValueTypeInteger;
4728 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4729 attribs[i].value.value.i = VA_FOURCC_NV12;
4732 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4733 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4735 attribs[i].type = VASurfaceAttribPixelFormat;
4736 attribs[i].value.type = VAGenericValueTypeInteger;
4737 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4738 attribs[i].value.value.i = VA_FOURCC_NV12;
4741 attribs[i].type = VASurfaceAttribPixelFormat;
4742 attribs[i].value.type = VAGenericValueTypeInteger;
4743 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4744 attribs[i].value.value.i = VA_FOURCC_I420;
4747 attribs[i].type = VASurfaceAttribPixelFormat;
4748 attribs[i].value.type = VAGenericValueTypeInteger;
4749 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4750 attribs[i].value.value.i = VA_FOURCC_YV12;
4753 attribs[i].type = VASurfaceAttribPixelFormat;
4754 attribs[i].value.type = VAGenericValueTypeInteger;
4755 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4756 attribs[i].value.value.i = VA_FOURCC_IMC3;
4759 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4760 attribs[i].type = VASurfaceAttribPixelFormat;
4761 attribs[i].value.type = VAGenericValueTypeInteger;
4762 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4763 attribs[i].value.value.i = VA_FOURCC_YUY2;
4766 attribs[i].type = VASurfaceAttribPixelFormat;
4767 attribs[i].value.type = VAGenericValueTypeInteger;
4768 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4769 attribs[i].value.value.i = VA_FOURCC_RGBA;
4772 attribs[i].type = VASurfaceAttribPixelFormat;
4773 attribs[i].value.type = VAGenericValueTypeInteger;
4774 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4775 attribs[i].value.value.i = VA_FOURCC_RGBX;
4778 attribs[i].type = VASurfaceAttribPixelFormat;
4779 attribs[i].value.type = VAGenericValueTypeInteger;
4780 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4781 attribs[i].value.value.i = VA_FOURCC_BGRA;
4784 attribs[i].type = VASurfaceAttribPixelFormat;
4785 attribs[i].value.type = VAGenericValueTypeInteger;
4786 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4787 attribs[i].value.value.i = VA_FOURCC_BGRX;
4790 attribs[i].type = VASurfaceAttribPixelFormat;
4791 attribs[i].value.type = VAGenericValueTypeInteger;
4792 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4793 attribs[i].value.value.i = VA_FOURCC_YV16;
4799 attribs[i].type = VASurfaceAttribMemoryType;
4800 attribs[i].value.type = VAGenericValueTypeInteger;
4801 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4802 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4803 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4804 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4807 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4808 attribs[i].value.type = VAGenericValueTypePointer;
4809 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4810 attribs[i].value.value.p = NULL; /* ignore */
4813 if (i > *num_attribs) {
4816 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4820 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4827 i965_os_has_ring_support(VADriverContextP ctx,
4830 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4834 return i965->intel.has_bsd;
4837 return i965->intel.has_blt;
4839 case I965_RING_VEBOX:
4840 return i965->intel.has_vebox;
4842 case I965_RING_NULL:
4843 return 1; /* Always support */
4846 /* should never get here */
4855 * Query video processing pipeline
4857 VAStatus i965_QueryVideoProcFilters(
4858 VADriverContextP ctx,
4859 VAContextID context,
4860 VAProcFilterType *filters,
4861 unsigned int *num_filters
4864 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4865 unsigned int i = 0, num = 0;
4867 if (!num_filters || !filters)
4868 return VA_STATUS_ERROR_INVALID_PARAMETER;
4870 for (i = 0; i < i965->codec_info->num_filters; i++) {
4871 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4872 if (num == *num_filters) {
4873 *num_filters = i965->codec_info->num_filters;
4875 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4878 filters[num++] = i965->codec_info->filters[i].type;
4884 return VA_STATUS_SUCCESS;
4887 VAStatus i965_QueryVideoProcFilterCaps(
4888 VADriverContextP ctx,
4889 VAContextID context,
4890 VAProcFilterType type,
4892 unsigned int *num_filter_caps
4896 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4898 if (!filter_caps || !num_filter_caps)
4899 return VA_STATUS_ERROR_INVALID_PARAMETER;
4901 for (i = 0; i < i965->codec_info->num_filters; i++) {
4902 if (type == i965->codec_info->filters[i].type &&
4903 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4907 if (i == i965->codec_info->num_filters)
4908 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4913 case VAProcFilterNoiseReduction:
4914 case VAProcFilterSharpening:
4916 VAProcFilterCap *cap = filter_caps;
4918 if (*num_filter_caps < 1) {
4919 *num_filter_caps = 1;
4920 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4923 cap->range.min_value = 0.0;
4924 cap->range.max_value = 1.0;
4925 cap->range.default_value = 0.5;
4926 cap->range.step = 0.03125; /* 1.0 / 32 */
4932 case VAProcFilterDeinterlacing:
4934 VAProcFilterCapDeinterlacing *cap = filter_caps;
4936 if (*num_filter_caps < VAProcDeinterlacingCount) {
4937 *num_filter_caps = VAProcDeinterlacingCount;
4938 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4941 cap->type = VAProcDeinterlacingBob;
4946 if (i965->codec_info->has_di_motion_adptive) {
4947 cap->type = VAProcDeinterlacingMotionAdaptive;
4952 if (i965->codec_info->has_di_motion_compensated) {
4953 cap->type = VAProcDeinterlacingMotionCompensated;
4961 case VAProcFilterColorBalance:
4963 VAProcFilterCapColorBalance *cap = filter_caps;
4965 if (*num_filter_caps < VAProcColorBalanceCount) {
4966 *num_filter_caps = VAProcColorBalanceCount;
4967 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4970 cap->type = VAProcColorBalanceHue;
4971 cap->range.min_value = -180.0;
4972 cap->range.max_value = 180.0;
4973 cap->range.default_value = 0.0;
4974 cap->range.step = 1.0;
4978 cap->type = VAProcColorBalanceSaturation;
4979 cap->range.min_value = 0.0;
4980 cap->range.max_value = 10.0;
4981 cap->range.default_value = 1.0;
4982 cap->range.step = 0.1;
4986 cap->type = VAProcColorBalanceBrightness;
4987 cap->range.min_value = -100.0;
4988 cap->range.max_value = 100.0;
4989 cap->range.default_value = 0.0;
4990 cap->range.step = 1.0;
4994 cap->type = VAProcColorBalanceContrast;
4995 cap->range.min_value = 0.0;
4996 cap->range.max_value = 10.0;
4997 cap->range.default_value = 1.0;
4998 cap->range.step = 0.1;
5010 *num_filter_caps = i;
5012 return VA_STATUS_SUCCESS;
5015 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
5016 VAProcColorStandardBT601,
5019 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
5020 VAProcColorStandardBT601,
5023 VAStatus i965_QueryVideoProcPipelineCaps(
5024 VADriverContextP ctx,
5025 VAContextID context,
5026 VABufferID *filters,
5027 unsigned int num_filters,
5028 VAProcPipelineCaps *pipeline_cap /* out */
5031 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5034 pipeline_cap->pipeline_flags = 0;
5035 pipeline_cap->filter_flags = 0;
5036 pipeline_cap->num_forward_references = 0;
5037 pipeline_cap->num_backward_references = 0;
5038 pipeline_cap->num_input_color_standards = 1;
5039 pipeline_cap->input_color_standards = vpp_input_color_standards;
5040 pipeline_cap->num_output_color_standards = 1;
5041 pipeline_cap->output_color_standards = vpp_output_color_standards;
5043 for (i = 0; i < num_filters; i++) {
5044 struct object_buffer *obj_buffer = BUFFER(filters[i]);
5047 !obj_buffer->buffer_store ||
5048 !obj_buffer->buffer_store->buffer)
5049 return VA_STATUS_ERROR_INVALID_BUFFER;
5051 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
5053 if (base->type == VAProcFilterNoiseReduction) {
5054 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
5056 } else if (base->type == VAProcFilterDeinterlacing) {
5057 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
5059 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
5060 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5061 deint->algorithm == VAProcDeinterlacingMotionCompensated,
5062 VA_STATUS_ERROR_INVALID_PARAMETER);
5064 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5065 deint->algorithm == VAProcDeinterlacingMotionCompensated);
5066 pipeline_cap->num_forward_references++;
5067 } else if (base->type == VAProcFilterSkinToneEnhancement) {
5068 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
5073 return VA_STATUS_SUCCESS;
5076 extern const struct hw_codec_info *i965_get_codec_info(int devid);
5079 i965_driver_data_init(VADriverContextP ctx)
5081 struct i965_driver_data *i965 = i965_driver_data(ctx);
5083 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
5085 if (!i965->codec_info)
5088 if (object_heap_init(&i965->config_heap,
5089 sizeof(struct object_config),
5091 goto err_config_heap;
5092 if (object_heap_init(&i965->context_heap,
5093 sizeof(struct object_context),
5095 goto err_context_heap;
5097 if (object_heap_init(&i965->surface_heap,
5098 sizeof(struct object_surface),
5100 goto err_surface_heap;
5101 if (object_heap_init(&i965->buffer_heap,
5102 sizeof(struct object_buffer),
5104 goto err_buffer_heap;
5105 if (object_heap_init(&i965->image_heap,
5106 sizeof(struct object_image),
5108 goto err_image_heap;
5109 if (object_heap_init(&i965->subpic_heap,
5110 sizeof(struct object_subpic),
5112 goto err_subpic_heap;
5114 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5115 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5116 _i965InitMutex(&i965->render_mutex);
5117 _i965InitMutex(&i965->pp_mutex);
5122 object_heap_destroy(&i965->image_heap);
5124 object_heap_destroy(&i965->buffer_heap);
5126 object_heap_destroy(&i965->surface_heap);
5128 object_heap_destroy(&i965->context_heap);
5130 object_heap_destroy(&i965->config_heap);
5137 i965_driver_data_terminate(VADriverContextP ctx)
5139 struct i965_driver_data *i965 = i965_driver_data(ctx);
5141 _i965DestroyMutex(&i965->pp_mutex);
5142 _i965DestroyMutex(&i965->render_mutex);
5145 intel_batchbuffer_free(i965->batch);
5148 intel_batchbuffer_free(i965->pp_batch);
5150 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
5151 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
5152 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
5153 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
5154 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
5155 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
5159 bool (*init)(VADriverContextP ctx);
5160 void (*terminate)(VADriverContextP ctx);
5162 } i965_sub_ops[] = {
5165 intel_driver_terminate,
5170 i965_driver_data_init,
5171 i965_driver_data_terminate,
5176 i965_display_attributes_init,
5177 i965_display_attributes_terminate,
5182 i965_post_processing_init,
5183 i965_post_processing_terminate,
5189 i965_render_terminate,
5193 #ifdef HAVE_VA_WAYLAND
5195 i965_output_wayland_init,
5196 i965_output_wayland_terminate,
5203 i965_output_dri_init,
5204 i965_output_dri_terminate,
5211 i965_Init(VADriverContextP ctx)
5213 struct i965_driver_data *i965 = i965_driver_data(ctx);
5215 const char *chipset;
5217 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
5218 if ((i965_sub_ops[i].display_type == 0 ||
5219 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
5220 !i965_sub_ops[i].init(ctx))
5224 if (i == ARRAY_ELEMS(i965_sub_ops)) {
5225 switch (i965->intel.device_id) {
5227 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
5228 #include "i965_pciids.h"
5230 chipset = "Unknown Intel Chipset";
5234 sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d",
5235 INTEL_STR_DRIVER_VENDOR,
5236 INTEL_STR_DRIVER_NAME,
5238 INTEL_DRIVER_MAJOR_VERSION,
5239 INTEL_DRIVER_MINOR_VERSION,
5240 INTEL_DRIVER_MICRO_VERSION);
5242 if (INTEL_DRIVER_PRE_VERSION > 0) {
5243 const int len = strlen(i965->va_vendor);
5244 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
5247 i965->current_context_id = VA_INVALID_ID;
5249 return VA_STATUS_SUCCESS;
5253 for (; i >= 0; i--) {
5254 if (i965_sub_ops[i].display_type == 0 ||
5255 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5256 i965_sub_ops[i].terminate(ctx);
5260 return VA_STATUS_ERROR_UNKNOWN;
5265 i965_Terminate(VADriverContextP ctx)
5267 struct i965_driver_data *i965 = i965_driver_data(ctx);
5271 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5272 if (i965_sub_ops[i - 1].display_type == 0 ||
5273 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5274 i965_sub_ops[i - 1].terminate(ctx);
5278 ctx->pDriverData = NULL;
5281 return VA_STATUS_SUCCESS;
5285 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5288 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5290 struct VADriverVTable * const vtable = ctx->vtable;
5291 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5293 struct i965_driver_data *i965;
5294 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5296 ctx->version_major = VA_MAJOR_VERSION;
5297 ctx->version_minor = VA_MINOR_VERSION;
5298 ctx->max_profiles = I965_MAX_PROFILES;
5299 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5300 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5301 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5302 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5303 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5305 vtable->vaTerminate = i965_Terminate;
5306 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5307 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5308 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5309 vtable->vaCreateConfig = i965_CreateConfig;
5310 vtable->vaDestroyConfig = i965_DestroyConfig;
5311 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5312 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5313 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5314 vtable->vaCreateContext = i965_CreateContext;
5315 vtable->vaDestroyContext = i965_DestroyContext;
5316 vtable->vaCreateBuffer = i965_CreateBuffer;
5317 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5318 vtable->vaMapBuffer = i965_MapBuffer;
5319 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5320 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5321 vtable->vaBeginPicture = i965_BeginPicture;
5322 vtable->vaRenderPicture = i965_RenderPicture;
5323 vtable->vaEndPicture = i965_EndPicture;
5324 vtable->vaSyncSurface = i965_SyncSurface;
5325 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5326 vtable->vaPutSurface = i965_PutSurface;
5327 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5328 vtable->vaCreateImage = i965_CreateImage;
5329 vtable->vaDeriveImage = i965_DeriveImage;
5330 vtable->vaDestroyImage = i965_DestroyImage;
5331 vtable->vaSetImagePalette = i965_SetImagePalette;
5332 vtable->vaGetImage = i965_GetImage;
5333 vtable->vaPutImage = i965_PutImage;
5334 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5335 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5336 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5337 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5338 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5339 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5340 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5341 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5342 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5343 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5344 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5345 vtable->vaBufferInfo = i965_BufferInfo;
5346 vtable->vaLockSurface = i965_LockSurface;
5347 vtable->vaUnlockSurface = i965_UnlockSurface;
5348 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5349 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5350 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5352 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5353 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5354 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5356 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5359 ctx->pDriverData = NULL;
5361 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5364 ctx->pDriverData = (void *)i965;
5365 ret = i965_Init(ctx);
5367 if (ret == VA_STATUS_SUCCESS) {
5368 ctx->str_vendor = i965->va_vendor;
5371 ctx->pDriverData = NULL;