2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
33 # include "i965_output_dri.h"
36 #ifdef HAVE_VA_WAYLAND
37 # include "i965_output_wayland.h"
40 #include "intel_driver.h"
41 #include "intel_memman.h"
42 #include "intel_batchbuffer.h"
43 #include "i965_defines.h"
44 #include "i965_drv_video.h"
45 #include "i965_decoder.h"
46 #include "i965_encoder.h"
48 #define CONFIG_ID_OFFSET 0x01000000
49 #define CONTEXT_ID_OFFSET 0x02000000
50 #define SURFACE_ID_OFFSET 0x04000000
51 #define BUFFER_ID_OFFSET 0x08000000
52 #define IMAGE_ID_OFFSET 0x0a000000
53 #define SUBPIC_ID_OFFSET 0x10000000
55 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
58 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
61 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
64 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
67 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
70 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
73 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
75 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
77 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
79 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
81 static int get_sampling_from_fourcc(unsigned int fourcc);
83 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
84 #define IS_VA_X11(ctx) \
85 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
87 /* Check whether we are rendering to Wayland */
88 #define IS_VA_WAYLAND(ctx) \
89 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
92 I965_SURFACETYPE_RGBA = 1,
94 I965_SURFACETYPE_INDEXED
97 /* List of supported display attributes */
98 static const VADisplayAttribute i965_display_attributes[] = {
100 VADisplayAttribBrightness,
101 -100, 100, DEFAULT_BRIGHTNESS,
102 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
106 VADisplayAttribContrast,
107 0, 100, DEFAULT_CONTRAST,
108 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
113 -180, 180, DEFAULT_HUE,
114 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
118 VADisplayAttribSaturation,
119 0, 100, DEFAULT_SATURATION,
120 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
124 VADisplayAttribRotation,
125 0, 3, VA_ROTATION_NONE,
126 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
130 /* List of supported image formats */
133 VAImageFormat va_format;
134 } i965_image_format_map_t;
136 static const i965_image_format_map_t
137 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
138 { I965_SURFACETYPE_YUV,
139 { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
140 { I965_SURFACETYPE_YUV,
141 { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
142 { I965_SURFACETYPE_YUV,
143 { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
144 { I965_SURFACETYPE_YUV,
145 { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } },
146 { I965_SURFACETYPE_YUV,
147 { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } },
148 { I965_SURFACETYPE_RGBA,
149 { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
150 { I965_SURFACETYPE_RGBA,
151 { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
154 /* List of supported subpicture formats */
158 VAImageFormat va_format;
159 unsigned int va_flags;
160 } i965_subpic_format_map_t;
162 #define COMMON_SUBPICTURE_FLAGS \
163 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
164 VA_SUBPICTURE_GLOBAL_ALPHA)
166 static const i965_subpic_format_map_t
167 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
168 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
169 { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
170 COMMON_SUBPICTURE_FLAGS },
171 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
172 { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
173 COMMON_SUBPICTURE_FLAGS },
174 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
175 { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, },
176 COMMON_SUBPICTURE_FLAGS },
177 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
178 { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, },
179 COMMON_SUBPICTURE_FLAGS },
180 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
181 { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
182 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
183 COMMON_SUBPICTURE_FLAGS },
184 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
185 { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
186 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
187 COMMON_SUBPICTURE_FLAGS },
190 static const i965_subpic_format_map_t *
191 get_subpic_format(const VAImageFormat *va_format)
194 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
195 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
196 if (m->va_format.fourcc == va_format->fourcc &&
197 (m->type == I965_SURFACETYPE_RGBA ?
198 (m->va_format.byte_order == va_format->byte_order &&
199 m->va_format.red_mask == va_format->red_mask &&
200 m->va_format.green_mask == va_format->green_mask &&
201 m->va_format.blue_mask == va_format->blue_mask &&
202 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
208 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
209 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
210 static struct hw_codec_info g4x_hw_codec_info = {
211 .dec_hw_context_init = g4x_dec_hw_context_init,
212 .enc_hw_context_init = NULL,
213 .proc_hw_context_init = NULL,
217 .has_mpeg2_decoding = 1,
222 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
223 static struct hw_codec_info ironlake_hw_codec_info = {
224 .dec_hw_context_init = ironlake_dec_hw_context_init,
225 .enc_hw_context_init = NULL,
226 .proc_hw_context_init = i965_proc_context_init,
230 .has_mpeg2_decoding = 1,
231 .has_h264_decoding = 1,
233 .has_accelerated_putimage = 1,
238 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
239 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
240 static struct hw_codec_info gen6_hw_codec_info = {
241 .dec_hw_context_init = gen6_dec_hw_context_init,
242 .enc_hw_context_init = gen6_enc_hw_context_init,
243 .proc_hw_context_init = i965_proc_context_init,
247 .has_mpeg2_decoding = 1,
248 .has_mpeg2_encoding = 1,
249 .has_h264_decoding = 1,
250 .has_h264_encoding = 1,
251 .has_vc1_decoding = 1,
253 .has_accelerated_getimage = 1,
254 .has_accelerated_putimage = 1,
255 .has_tiled_surface = 1,
259 { VAProcFilterNoiseReduction, I965_RING_NULL },
260 { VAProcFilterDeinterlacing, I965_RING_NULL },
264 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
265 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
266 static struct hw_codec_info gen7_hw_codec_info = {
267 .dec_hw_context_init = gen7_dec_hw_context_init,
268 .enc_hw_context_init = gen7_enc_hw_context_init,
269 .proc_hw_context_init = i965_proc_context_init,
273 .has_mpeg2_decoding = 1,
274 .has_mpeg2_encoding = 1,
275 .has_h264_decoding = 1,
276 .has_h264_encoding = 1,
277 .has_vc1_decoding = 1,
278 .has_jpeg_decoding = 1,
280 .has_accelerated_getimage = 1,
281 .has_accelerated_putimage = 1,
282 .has_tiled_surface = 1,
283 .has_di_motion_adptive = 1,
287 { VAProcFilterNoiseReduction, I965_RING_NULL },
288 { VAProcFilterDeinterlacing, I965_RING_NULL },
292 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
293 static struct hw_codec_info gen75_hw_codec_info = {
294 .dec_hw_context_init = gen75_dec_hw_context_init,
295 .enc_hw_context_init = gen75_enc_hw_context_init,
296 .proc_hw_context_init = gen75_proc_context_init,
300 .has_mpeg2_decoding = 1,
301 .has_mpeg2_encoding = 1,
302 .has_h264_decoding = 1,
303 .has_h264_encoding = 1,
304 .has_vc1_decoding = 1,
305 .has_jpeg_decoding = 1,
307 .has_accelerated_getimage = 1,
308 .has_accelerated_putimage = 1,
309 .has_tiled_surface = 1,
310 .has_di_motion_adptive = 1,
311 .has_di_motion_compensated = 1,
315 { VAProcFilterNoiseReduction, I965_RING_VEBOX },
316 { VAProcFilterDeinterlacing, I965_RING_VEBOX },
317 { VAProcFilterSharpening, I965_RING_NULL },
318 { VAProcFilterColorBalance, I965_RING_VEBOX},
322 #define I965_PACKED_HEADER_BASE 0
323 #define I965_PACKED_MISC_HEADER_BASE 3
326 va_enc_packed_type_to_idx(int packed_type)
330 if (packed_type & VAEncPackedHeaderMiscMask) {
331 idx = I965_PACKED_MISC_HEADER_BASE;
332 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
333 assert(packed_type > 0);
334 idx += (packed_type - 1);
336 idx = I965_PACKED_HEADER_BASE;
338 switch (packed_type) {
339 case VAEncPackedHeaderSequence:
340 idx = I965_PACKED_HEADER_BASE + 0;
343 case VAEncPackedHeaderPicture:
344 idx = I965_PACKED_HEADER_BASE + 1;
347 case VAEncPackedHeaderSlice:
348 idx = I965_PACKED_HEADER_BASE + 2;
352 /* Should not get here */
364 i965_QueryConfigProfiles(VADriverContextP ctx,
365 VAProfile *profile_list, /* out */
366 int *num_profiles) /* out */
368 struct i965_driver_data * const i965 = i965_driver_data(ctx);
371 if (HAS_MPEG2_DECODING(i965) ||
372 HAS_MPEG2_ENCODING(i965)) {
373 profile_list[i++] = VAProfileMPEG2Simple;
374 profile_list[i++] = VAProfileMPEG2Main;
377 if (HAS_H264_DECODING(i965) ||
378 HAS_H264_ENCODING(i965)) {
379 profile_list[i++] = VAProfileH264Baseline;
380 profile_list[i++] = VAProfileH264Main;
381 profile_list[i++] = VAProfileH264High;
384 if (HAS_VC1_DECODING(i965)) {
385 profile_list[i++] = VAProfileVC1Simple;
386 profile_list[i++] = VAProfileVC1Main;
387 profile_list[i++] = VAProfileVC1Advanced;
391 profile_list[i++] = VAProfileNone;
394 if (HAS_JPEG_DECODING(i965)) {
395 profile_list[i++] = VAProfileJPEGBaseline;
398 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
399 assert(i <= I965_MAX_PROFILES);
402 return VA_STATUS_SUCCESS;
406 i965_QueryConfigEntrypoints(VADriverContextP ctx,
408 VAEntrypoint *entrypoint_list, /* out */
409 int *num_entrypoints) /* out */
411 struct i965_driver_data * const i965 = i965_driver_data(ctx);
415 case VAProfileMPEG2Simple:
416 case VAProfileMPEG2Main:
417 if (HAS_MPEG2_DECODING(i965))
418 entrypoint_list[n++] = VAEntrypointVLD;
420 if (HAS_MPEG2_ENCODING(i965))
421 entrypoint_list[n++] = VAEntrypointEncSlice;
425 case VAProfileH264Baseline:
426 case VAProfileH264Main:
427 case VAProfileH264High:
428 if (HAS_H264_DECODING(i965))
429 entrypoint_list[n++] = VAEntrypointVLD;
431 if (HAS_H264_ENCODING(i965))
432 entrypoint_list[n++] = VAEntrypointEncSlice;
436 case VAProfileVC1Simple:
437 case VAProfileVC1Main:
438 case VAProfileVC1Advanced:
439 if (HAS_VC1_DECODING(i965))
440 entrypoint_list[n++] = VAEntrypointVLD;
445 entrypoint_list[n++] = VAEntrypointVideoProc;
448 case VAProfileJPEGBaseline:
449 if (HAS_JPEG_DECODING(i965))
450 entrypoint_list[n++] = VAEntrypointVLD;
457 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
458 assert(n <= I965_MAX_ENTRYPOINTS);
459 *num_entrypoints = n;
460 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
464 i965_GetConfigAttributes(VADriverContextP ctx,
466 VAEntrypoint entrypoint,
467 VAConfigAttrib *attrib_list, /* in/out */
472 /* Other attributes don't seem to be defined */
473 /* What to do if we don't know the attribute? */
474 for (i = 0; i < num_attribs; i++) {
475 switch (attrib_list[i].type) {
476 case VAConfigAttribRTFormat:
477 attrib_list[i].value = VA_RT_FORMAT_YUV420;
480 case VAConfigAttribRateControl:
481 if (entrypoint == VAEntrypointEncSlice) {
482 attrib_list[i].value = VA_RC_CBR | VA_RC_CQP;
486 case VAConfigAttribEncPackedHeaders:
487 if (entrypoint == VAEntrypointEncSlice) {
488 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
492 case VAConfigAttribEncMaxRefFrames:
493 if (entrypoint == VAEntrypointEncSlice) {
494 attrib_list[i].value = (1 << 16) | (1 << 0);
500 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
505 return VA_STATUS_SUCCESS;
509 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
511 object_heap_free(heap, obj);
515 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
519 /* Check existing attrbiutes */
520 for (i = 0; i < obj_config->num_attribs; i++) {
521 if (obj_config->attrib_list[i].type == attrib->type) {
522 /* Update existing attribute */
523 obj_config->attrib_list[i].value = attrib->value;
524 return VA_STATUS_SUCCESS;
528 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
529 i = obj_config->num_attribs;
530 obj_config->attrib_list[i].type = attrib->type;
531 obj_config->attrib_list[i].value = attrib->value;
532 obj_config->num_attribs++;
533 return VA_STATUS_SUCCESS;
536 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
540 i965_CreateConfig(VADriverContextP ctx,
542 VAEntrypoint entrypoint,
543 VAConfigAttrib *attrib_list,
545 VAConfigID *config_id) /* out */
547 struct i965_driver_data * const i965 = i965_driver_data(ctx);
548 struct object_config *obj_config;
553 /* Validate profile & entrypoint */
555 case VAProfileMPEG2Simple:
556 case VAProfileMPEG2Main:
557 if ((HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
558 (HAS_MPEG2_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
559 vaStatus = VA_STATUS_SUCCESS;
561 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
565 case VAProfileH264Baseline:
566 case VAProfileH264Main:
567 case VAProfileH264High:
568 if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
569 (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
570 vaStatus = VA_STATUS_SUCCESS;
572 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
577 case VAProfileVC1Simple:
578 case VAProfileVC1Main:
579 case VAProfileVC1Advanced:
580 if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) {
581 vaStatus = VA_STATUS_SUCCESS;
583 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
589 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
590 vaStatus = VA_STATUS_SUCCESS;
592 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
597 case VAProfileJPEGBaseline:
598 if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) {
599 vaStatus = VA_STATUS_SUCCESS;
601 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
607 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
611 if (VA_STATUS_SUCCESS != vaStatus) {
615 configID = NEW_CONFIG_ID();
616 obj_config = CONFIG(configID);
618 if (NULL == obj_config) {
619 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
623 obj_config->profile = profile;
624 obj_config->entrypoint = entrypoint;
625 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
626 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
627 obj_config->num_attribs = 1;
629 for(i = 0; i < num_attribs; i++) {
630 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
632 if (VA_STATUS_SUCCESS != vaStatus) {
638 if (VA_STATUS_SUCCESS != vaStatus) {
639 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
641 *config_id = configID;
648 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
650 struct i965_driver_data *i965 = i965_driver_data(ctx);
651 struct object_config *obj_config = CONFIG(config_id);
654 if (NULL == obj_config) {
655 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
659 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
660 return VA_STATUS_SUCCESS;
663 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
664 VAConfigID config_id,
665 VAProfile *profile, /* out */
666 VAEntrypoint *entrypoint, /* out */
667 VAConfigAttrib *attrib_list, /* out */
668 int *num_attribs) /* out */
670 struct i965_driver_data *i965 = i965_driver_data(ctx);
671 struct object_config *obj_config = CONFIG(config_id);
672 VAStatus vaStatus = VA_STATUS_SUCCESS;
676 *profile = obj_config->profile;
677 *entrypoint = obj_config->entrypoint;
678 *num_attribs = obj_config->num_attribs;
680 for(i = 0; i < obj_config->num_attribs; i++) {
681 attrib_list[i] = obj_config->attrib_list[i];
688 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
690 struct object_surface *obj_surface = (struct object_surface *)obj;
692 dri_bo_unreference(obj_surface->bo);
693 obj_surface->bo = NULL;
695 if (obj_surface->free_private_data != NULL) {
696 obj_surface->free_private_data(&obj_surface->private_data);
697 obj_surface->private_data = NULL;
700 object_heap_free(heap, obj);
704 i965_surface_native_memory(VADriverContextP ctx,
705 struct object_surface *obj_surface,
709 struct i965_driver_data *i965 = i965_driver_data(ctx);
710 int tiling = HAS_TILED_SURFACE(i965);
712 if (!expected_fourcc)
713 return VA_STATUS_SUCCESS;
715 // todo, should we disable tiling for 422 format?
716 if (expected_fourcc == VA_FOURCC('I', '4', '2', '0') ||
717 expected_fourcc == VA_FOURCC('I', 'Y', 'U', 'V') ||
718 expected_fourcc == VA_FOURCC('Y', 'V', '1', '2'))
721 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
723 return VA_STATUS_SUCCESS;
727 i965_suface_external_memory(VADriverContextP ctx,
728 struct object_surface *obj_surface,
729 int external_memory_type,
730 VASurfaceAttribExternalBuffers *memory_attibute,
733 struct i965_driver_data *i965 = i965_driver_data(ctx);
735 if (!memory_attibute ||
736 !memory_attibute->buffers ||
737 index > memory_attibute->num_buffers)
738 return VA_STATUS_ERROR_INVALID_PARAMETER;
740 assert(obj_surface->orig_width == memory_attibute->width);
741 assert(obj_surface->orig_height == memory_attibute->height);
742 assert(memory_attibute->num_planes >= 1);
744 obj_surface->fourcc = memory_attibute->pixel_format;
745 obj_surface->width = memory_attibute->pitches[0];
746 obj_surface->size = memory_attibute->data_size;
748 if (memory_attibute->num_planes == 1)
749 obj_surface->height = memory_attibute->data_size / obj_surface->width;
751 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
753 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
754 obj_surface->x_cr_offset = 0;
756 switch (obj_surface->fourcc) {
757 case VA_FOURCC('N', 'V', '1', '2'):
758 assert(memory_attibute->num_planes == 2);
759 assert(memory_attibute->pitches[0] == memory_attibute->pitches[1]);
761 obj_surface->subsampling = SUBSAMPLE_YUV420;
762 obj_surface->y_cb_offset = obj_surface->height;
763 obj_surface->y_cr_offset = obj_surface->height;
764 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
765 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
766 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
770 case VA_FOURCC('Y', 'V', '1', '2'):
771 case VA_FOURCC('I', 'M', 'C', '1'):
772 assert(memory_attibute->num_planes == 3);
773 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
775 obj_surface->subsampling = SUBSAMPLE_YUV420;
776 obj_surface->y_cr_offset = obj_surface->height;
777 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
778 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
779 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
780 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
784 case VA_FOURCC('I', '4', '2', '0'):
785 case VA_FOURCC('I', 'Y', 'U', 'V'):
786 case VA_FOURCC('I', 'M', 'C', '3'):
787 assert(memory_attibute->num_planes == 3);
788 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
790 obj_surface->subsampling = SUBSAMPLE_YUV420;
791 obj_surface->y_cb_offset = obj_surface->height;
792 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
793 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
794 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
795 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
799 case VA_FOURCC('Y', 'U', 'Y', '2'):
800 case VA_FOURCC('U', 'Y', 'V', 'Y'):
801 assert(memory_attibute->num_planes == 1);
803 obj_surface->subsampling = SUBSAMPLE_YUV422H;
804 obj_surface->y_cb_offset = 0;
805 obj_surface->y_cr_offset = 0;
806 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
807 obj_surface->cb_cr_height = obj_surface->orig_height;
808 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
812 case VA_FOURCC('R', 'G', 'B', 'A'):
813 case VA_FOURCC('R', 'G', 'B', 'X'):
814 case VA_FOURCC('B', 'G', 'R', 'A'):
815 case VA_FOURCC('B', 'G', 'R', 'X'):
816 assert(memory_attibute->num_planes == 1);
818 obj_surface->subsampling = SUBSAMPLE_RGBX;
819 obj_surface->y_cb_offset = 0;
820 obj_surface->y_cr_offset = 0;
821 obj_surface->cb_cr_width = 0;
822 obj_surface->cb_cr_height = 0;
823 obj_surface->cb_cr_pitch = 0;
827 case VA_FOURCC('Y', '8', '0', '0'): /* monochrome surface */
828 assert(memory_attibute->num_planes == 1);
830 obj_surface->subsampling = SUBSAMPLE_YUV400;
831 obj_surface->y_cb_offset = 0;
832 obj_surface->y_cr_offset = 0;
833 obj_surface->cb_cr_width = 0;
834 obj_surface->cb_cr_height = 0;
835 obj_surface->cb_cr_pitch = 0;
839 case VA_FOURCC('4', '1', '1', 'P'):
840 assert(memory_attibute->num_planes == 3);
841 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
843 obj_surface->subsampling = SUBSAMPLE_YUV411;
844 obj_surface->y_cb_offset = 0;
845 obj_surface->y_cr_offset = 0;
846 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
847 obj_surface->cb_cr_height = obj_surface->orig_height;
848 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
852 case VA_FOURCC('4', '2', '2', 'H'):
853 assert(memory_attibute->num_planes == 3);
854 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
856 obj_surface->subsampling = SUBSAMPLE_YUV422H;
857 obj_surface->y_cb_offset = obj_surface->height;
858 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
859 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
860 obj_surface->cb_cr_height = obj_surface->orig_height;
861 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
865 case VA_FOURCC('4', '2', '2', 'V'):
866 assert(memory_attibute->num_planes == 3);
867 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
869 obj_surface->subsampling = SUBSAMPLE_YUV422H;
870 obj_surface->y_cb_offset = obj_surface->height;
871 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
872 obj_surface->cb_cr_width = obj_surface->orig_width;
873 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
874 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
878 case VA_FOURCC('4', '4', '4', 'P'):
879 assert(memory_attibute->num_planes == 3);
880 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
882 obj_surface->subsampling = SUBSAMPLE_YUV444;
883 obj_surface->y_cb_offset = obj_surface->height;
884 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
885 obj_surface->cb_cr_width = obj_surface->orig_width;
886 obj_surface->cb_cr_height = obj_surface->orig_height;
887 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
893 return VA_STATUS_ERROR_INVALID_PARAMETER;
896 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
897 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
898 "gem flinked vaapi surface",
899 memory_attibute->buffers[index]);
900 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
901 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
902 memory_attibute->buffers[index],
905 if (!obj_surface->bo)
906 return VA_STATUS_ERROR_INVALID_PARAMETER;
908 return VA_STATUS_SUCCESS;
912 i965_CreateSurfaces2(
913 VADriverContextP ctx,
917 VASurfaceID *surfaces,
918 unsigned int num_surfaces,
919 VASurfaceAttrib *attrib_list,
920 unsigned int num_attribs
923 struct i965_driver_data *i965 = i965_driver_data(ctx);
925 VAStatus vaStatus = VA_STATUS_SUCCESS;
926 int expected_fourcc = 0;
927 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
928 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
930 for (i = 0; i < num_attribs && attrib_list; i++) {
931 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
932 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
933 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
934 expected_fourcc = attrib_list[i].value.value.i;
937 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
938 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
940 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
942 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
943 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
944 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
945 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
948 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
949 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
950 assert(attrib_list[i].value.type == VAGenericValueTypePointer);
951 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
955 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
956 * for post-processing (including color conversion) */
957 if (VA_RT_FORMAT_YUV420 != format &&
958 VA_RT_FORMAT_YUV422 != format &&
959 VA_RT_FORMAT_YUV444 != format &&
960 VA_RT_FORMAT_YUV411 != format &&
961 VA_RT_FORMAT_YUV400 != format &&
962 VA_RT_FORMAT_RGB32 != format) {
963 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
966 for (i = 0; i < num_surfaces; i++) {
967 int surfaceID = NEW_SURFACE_ID();
968 struct object_surface *obj_surface = SURFACE(surfaceID);
970 if (NULL == obj_surface) {
971 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
975 surfaces[i] = surfaceID;
976 obj_surface->status = VASurfaceReady;
977 obj_surface->orig_width = width;
978 obj_surface->orig_height = height;
980 obj_surface->subpic_render_idx = 0;
981 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
982 obj_surface->subpic[j] = VA_INVALID_ID;
983 obj_surface->obj_subpic[j] = NULL;
986 obj_surface->width = ALIGN(width, 16);
987 obj_surface->height = ALIGN(height, 16);
988 obj_surface->flags = SURFACE_REFERENCED;
989 obj_surface->fourcc = 0;
990 obj_surface->bo = NULL;
991 obj_surface->locked_image_id = VA_INVALID_ID;
992 obj_surface->private_data = NULL;
993 obj_surface->free_private_data = NULL;
994 obj_surface->subsampling = SUBSAMPLE_YUV420;
996 switch (memory_type) {
997 case I965_SURFACE_MEM_NATIVE:
998 i965_surface_native_memory(ctx,
1004 case I965_SURFACE_MEM_GEM_FLINK:
1005 case I965_SURFACE_MEM_DRM_PRIME:
1006 i965_suface_external_memory(ctx,
1015 /* Error recovery */
1016 if (VA_STATUS_SUCCESS != vaStatus) {
1017 /* surfaces[i-1] was the last successful allocation */
1019 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1021 surfaces[i] = VA_INVALID_SURFACE;
1022 assert(obj_surface);
1023 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1031 i965_CreateSurfaces(VADriverContextP ctx,
1036 VASurfaceID *surfaces) /* out */
1038 return i965_CreateSurfaces2(ctx,
1049 i965_DestroySurfaces(VADriverContextP ctx,
1050 VASurfaceID *surface_list,
1053 struct i965_driver_data *i965 = i965_driver_data(ctx);
1056 for (i = num_surfaces; i--; ) {
1057 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1059 assert(obj_surface);
1060 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1063 return VA_STATUS_SUCCESS;
1067 i965_QueryImageFormats(VADriverContextP ctx,
1068 VAImageFormat *format_list, /* out */
1069 int *num_formats) /* out */
1073 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1074 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1076 format_list[n] = m->va_format;
1082 return VA_STATUS_SUCCESS;
1086 * Guess the format when the usage of a VA surface is unknown
1087 * 1. Without a valid context: YV12
1088 * 2. The current context is valid:
1089 * a) always NV12 on GEN6 and later
1090 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1093 i965_guess_surface_format(VADriverContextP ctx,
1094 VASurfaceID surface,
1095 unsigned int *fourcc,
1096 unsigned int *is_tiled)
1098 struct i965_driver_data *i965 = i965_driver_data(ctx);
1099 struct object_context *obj_context = NULL;
1100 struct object_config *obj_config = NULL;
1102 *fourcc = VA_FOURCC('Y', 'V', '1', '2');
1105 if (i965->current_context_id == VA_INVALID_ID)
1108 obj_context = CONTEXT(i965->current_context_id);
1113 obj_config = obj_context->obj_config;
1119 if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) {
1120 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1125 switch (obj_config->profile) {
1126 case VAProfileMPEG2Simple:
1127 case VAProfileMPEG2Main:
1128 *fourcc = VA_FOURCC('I', '4', '2', '0');
1133 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1140 i965_QuerySubpictureFormats(VADriverContextP ctx,
1141 VAImageFormat *format_list, /* out */
1142 unsigned int *flags, /* out */
1143 unsigned int *num_formats) /* out */
1147 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1148 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1150 format_list[n] = m->va_format;
1152 flags[n] = m->va_flags;
1158 return VA_STATUS_SUCCESS;
1162 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1164 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1166 object_heap_free(heap, obj);
1170 i965_CreateSubpicture(VADriverContextP ctx,
1172 VASubpictureID *subpicture) /* out */
1174 struct i965_driver_data *i965 = i965_driver_data(ctx);
1175 VASubpictureID subpicID = NEW_SUBPIC_ID()
1176 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1179 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1181 struct object_image *obj_image = IMAGE(image);
1183 return VA_STATUS_ERROR_INVALID_IMAGE;
1185 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1187 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1189 *subpicture = subpicID;
1190 obj_subpic->image = image;
1191 obj_subpic->obj_image = obj_image;
1192 obj_subpic->format = m->format;
1193 obj_subpic->width = obj_image->image.width;
1194 obj_subpic->height = obj_image->image.height;
1195 obj_subpic->pitch = obj_image->image.pitches[0];
1196 obj_subpic->bo = obj_image->bo;
1197 obj_subpic->global_alpha = 1.0;
1199 return VA_STATUS_SUCCESS;
1203 i965_DestroySubpicture(VADriverContextP ctx,
1204 VASubpictureID subpicture)
1206 struct i965_driver_data *i965 = i965_driver_data(ctx);
1207 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1210 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1212 assert(obj_subpic->obj_image);
1213 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1214 return VA_STATUS_SUCCESS;
1218 i965_SetSubpictureImage(VADriverContextP ctx,
1219 VASubpictureID subpicture,
1223 return VA_STATUS_ERROR_UNIMPLEMENTED;
1227 i965_SetSubpictureChromakey(VADriverContextP ctx,
1228 VASubpictureID subpicture,
1229 unsigned int chromakey_min,
1230 unsigned int chromakey_max,
1231 unsigned int chromakey_mask)
1234 return VA_STATUS_ERROR_UNIMPLEMENTED;
1238 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1239 VASubpictureID subpicture,
1242 struct i965_driver_data *i965 = i965_driver_data(ctx);
1243 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1245 if(global_alpha > 1.0 || global_alpha < 0.0){
1246 return VA_STATUS_ERROR_INVALID_PARAMETER;
1250 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1252 obj_subpic->global_alpha = global_alpha;
1254 return VA_STATUS_SUCCESS;
1258 i965_AssociateSubpicture(VADriverContextP ctx,
1259 VASubpictureID subpicture,
1260 VASurfaceID *target_surfaces,
1262 short src_x, /* upper left offset in subpicture */
1264 unsigned short src_width,
1265 unsigned short src_height,
1266 short dest_x, /* upper left offset in surface */
1268 unsigned short dest_width,
1269 unsigned short dest_height,
1271 * whether to enable chroma-keying or global-alpha
1272 * see VA_SUBPICTURE_XXX values
1276 struct i965_driver_data *i965 = i965_driver_data(ctx);
1277 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1281 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1283 assert(obj_subpic->obj_image);
1285 obj_subpic->src_rect.x = src_x;
1286 obj_subpic->src_rect.y = src_y;
1287 obj_subpic->src_rect.width = src_width;
1288 obj_subpic->src_rect.height = src_height;
1289 obj_subpic->dst_rect.x = dest_x;
1290 obj_subpic->dst_rect.y = dest_y;
1291 obj_subpic->dst_rect.width = dest_width;
1292 obj_subpic->dst_rect.height = dest_height;
1293 obj_subpic->flags = flags;
1295 for (i = 0; i < num_surfaces; i++) {
1296 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1298 return VA_STATUS_ERROR_INVALID_SURFACE;
1300 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1301 if(obj_surface->subpic[j] == VA_INVALID_ID){
1302 assert(obj_surface->obj_subpic[j] == NULL);
1303 obj_surface->subpic[j] = subpicture;
1304 obj_surface->obj_subpic[j] = obj_subpic;
1309 if(j == I965_MAX_SUBPIC_SUM){
1310 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1314 return VA_STATUS_SUCCESS;
1319 i965_DeassociateSubpicture(VADriverContextP ctx,
1320 VASubpictureID subpicture,
1321 VASurfaceID *target_surfaces,
1324 struct i965_driver_data *i965 = i965_driver_data(ctx);
1325 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1329 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1331 for (i = 0; i < num_surfaces; i++) {
1332 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1334 return VA_STATUS_ERROR_INVALID_SURFACE;
1336 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1337 if (obj_surface->subpic[j] == subpicture) {
1338 assert(obj_surface->obj_subpic[j] == obj_subpic);
1339 obj_surface->subpic[j] = VA_INVALID_ID;
1340 obj_surface->obj_subpic[j] = NULL;
1345 if(j == I965_MAX_SUBPIC_SUM){
1346 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1349 return VA_STATUS_SUCCESS;
1353 i965_reference_buffer_store(struct buffer_store **ptr,
1354 struct buffer_store *buffer_store)
1356 assert(*ptr == NULL);
1359 buffer_store->ref_count++;
1360 *ptr = buffer_store;
1365 i965_release_buffer_store(struct buffer_store **ptr)
1367 struct buffer_store *buffer_store = *ptr;
1369 if (buffer_store == NULL)
1372 assert(buffer_store->bo || buffer_store->buffer);
1373 assert(!(buffer_store->bo && buffer_store->buffer));
1374 buffer_store->ref_count--;
1376 if (buffer_store->ref_count == 0) {
1377 dri_bo_unreference(buffer_store->bo);
1378 free(buffer_store->buffer);
1379 buffer_store->bo = NULL;
1380 buffer_store->buffer = NULL;
1388 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1390 struct object_context *obj_context = (struct object_context *)obj;
1393 if (obj_context->hw_context) {
1394 obj_context->hw_context->destroy(obj_context->hw_context);
1395 obj_context->hw_context = NULL;
1398 if (obj_context->codec_type == CODEC_PROC) {
1399 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1401 } else if (obj_context->codec_type == CODEC_ENC) {
1402 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1403 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1404 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1406 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1407 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1409 free(obj_context->codec_state.encode.slice_params);
1411 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1412 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1413 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1415 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1416 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1418 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1419 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1421 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1422 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1424 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1425 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1427 free(obj_context->codec_state.encode.slice_params_ext);
1429 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1430 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1432 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1433 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1434 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1436 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1437 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1439 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1440 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1442 free(obj_context->codec_state.decode.slice_params);
1443 free(obj_context->codec_state.decode.slice_datas);
1446 free(obj_context->render_targets);
1447 object_heap_free(heap, obj);
1451 i965_CreateContext(VADriverContextP ctx,
1452 VAConfigID config_id,
1456 VASurfaceID *render_targets,
1457 int num_render_targets,
1458 VAContextID *context) /* out */
1460 struct i965_driver_data *i965 = i965_driver_data(ctx);
1461 struct i965_render_state *render_state = &i965->render_state;
1462 struct object_config *obj_config = CONFIG(config_id);
1463 struct object_context *obj_context = NULL;
1464 VAStatus vaStatus = VA_STATUS_SUCCESS;
1468 if (NULL == obj_config) {
1469 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1473 if (picture_width > i965->codec_info->max_width ||
1474 picture_height > i965->codec_info->max_height) {
1475 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1480 /* Validate picture dimensions */
1481 contextID = NEW_CONTEXT_ID();
1482 obj_context = CONTEXT(contextID);
1484 if (NULL == obj_context) {
1485 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1489 render_state->inited = 1;
1491 switch (obj_config->profile) {
1492 case VAProfileH264Baseline:
1493 case VAProfileH264Main:
1494 case VAProfileH264High:
1495 if (!HAS_H264_DECODING(i965) &&
1496 !HAS_H264_ENCODING(i965))
1497 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1498 render_state->interleaved_uv = 1;
1501 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id));
1505 *context = contextID;
1506 obj_context->flags = flag;
1507 obj_context->context_id = contextID;
1508 obj_context->obj_config = obj_config;
1509 obj_context->picture_width = picture_width;
1510 obj_context->picture_height = picture_height;
1511 obj_context->num_render_targets = num_render_targets;
1512 obj_context->render_targets =
1513 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1514 obj_context->hw_context = NULL;
1516 for(i = 0; i < num_render_targets; i++) {
1517 if (NULL == SURFACE(render_targets[i])) {
1518 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1522 obj_context->render_targets[i] = render_targets[i];
1525 if (VA_STATUS_SUCCESS == vaStatus) {
1526 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1527 obj_context->codec_type = CODEC_PROC;
1528 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1529 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1530 assert(i965->codec_info->proc_hw_context_init);
1531 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1532 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1533 obj_context->codec_type = CODEC_ENC;
1534 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1535 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1536 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1537 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1538 sizeof(*obj_context->codec_state.encode.slice_params));
1539 assert(i965->codec_info->enc_hw_context_init);
1540 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1542 obj_context->codec_type = CODEC_DEC;
1543 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1544 obj_context->codec_state.decode.current_render_target = -1;
1545 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1546 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1547 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1548 sizeof(*obj_context->codec_state.decode.slice_params));
1549 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1550 sizeof(*obj_context->codec_state.decode.slice_datas));
1552 assert(i965->codec_info->dec_hw_context_init);
1553 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1557 /* Error recovery */
1558 if (VA_STATUS_SUCCESS != vaStatus) {
1559 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1562 i965->current_context_id = contextID;
1568 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1570 struct i965_driver_data *i965 = i965_driver_data(ctx);
1571 struct object_context *obj_context = CONTEXT(context);
1573 assert(obj_context);
1575 if (i965->current_context_id == context)
1576 i965->current_context_id = VA_INVALID_ID;
1578 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1580 return VA_STATUS_SUCCESS;
1584 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1586 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1588 assert(obj_buffer->buffer_store);
1589 i965_release_buffer_store(&obj_buffer->buffer_store);
1590 object_heap_free(heap, obj);
1594 i965_create_buffer_internal(VADriverContextP ctx,
1595 VAContextID context,
1598 unsigned int num_elements,
1603 struct i965_driver_data *i965 = i965_driver_data(ctx);
1604 struct object_buffer *obj_buffer = NULL;
1605 struct buffer_store *buffer_store = NULL;
1610 case VAPictureParameterBufferType:
1611 case VAIQMatrixBufferType:
1612 case VAQMatrixBufferType:
1613 case VABitPlaneBufferType:
1614 case VASliceGroupMapBufferType:
1615 case VASliceParameterBufferType:
1616 case VASliceDataBufferType:
1617 case VAMacroblockParameterBufferType:
1618 case VAResidualDataBufferType:
1619 case VADeblockingParameterBufferType:
1620 case VAImageBufferType:
1621 case VAEncCodedBufferType:
1622 case VAEncSequenceParameterBufferType:
1623 case VAEncPictureParameterBufferType:
1624 case VAEncSliceParameterBufferType:
1625 case VAEncPackedHeaderParameterBufferType:
1626 case VAEncPackedHeaderDataBufferType:
1627 case VAEncMiscParameterBufferType:
1628 case VAProcPipelineParameterBufferType:
1629 case VAProcFilterParameterBufferType:
1630 case VAHuffmanTableBufferType:
1635 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1638 bufferID = NEW_BUFFER_ID();
1639 obj_buffer = BUFFER(bufferID);
1641 if (NULL == obj_buffer) {
1642 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1645 if (type == VAEncCodedBufferType) {
1646 size += I965_CODEDBUFFER_HEADER_SIZE;
1647 size += 0x1000; /* for upper bound check */
1650 obj_buffer->max_num_elements = num_elements;
1651 obj_buffer->num_elements = num_elements;
1652 obj_buffer->size_element = size;
1653 obj_buffer->type = type;
1654 obj_buffer->buffer_store = NULL;
1655 buffer_store = calloc(1, sizeof(struct buffer_store));
1656 assert(buffer_store);
1657 buffer_store->ref_count = 1;
1659 if (store_bo != NULL) {
1660 buffer_store->bo = store_bo;
1661 dri_bo_reference(buffer_store->bo);
1664 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1665 } else if (type == VASliceDataBufferType ||
1666 type == VAImageBufferType ||
1667 type == VAEncCodedBufferType) {
1668 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1670 size * num_elements, 64);
1671 assert(buffer_store->bo);
1673 if (type == VAEncCodedBufferType) {
1674 struct i965_coded_buffer_segment *coded_buffer_segment;
1676 dri_bo_map(buffer_store->bo, 1);
1677 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1678 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1679 coded_buffer_segment->base.bit_offset = 0;
1680 coded_buffer_segment->base.status = 0;
1681 coded_buffer_segment->base.buf = NULL;
1682 coded_buffer_segment->base.next = NULL;
1683 coded_buffer_segment->mapped = 0;
1684 coded_buffer_segment->codec = 0;
1685 dri_bo_unmap(buffer_store->bo);
1687 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1693 if (type == VAEncPackedHeaderDataBufferType) {
1694 msize = ALIGN(size, 4);
1697 buffer_store->buffer = malloc(msize * num_elements);
1698 assert(buffer_store->buffer);
1701 memcpy(buffer_store->buffer, data, size * num_elements);
1704 buffer_store->num_elements = obj_buffer->num_elements;
1705 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1706 i965_release_buffer_store(&buffer_store);
1709 return VA_STATUS_SUCCESS;
1713 i965_CreateBuffer(VADriverContextP ctx,
1714 VAContextID context, /* in */
1715 VABufferType type, /* in */
1716 unsigned int size, /* in */
1717 unsigned int num_elements, /* in */
1718 void *data, /* in */
1719 VABufferID *buf_id) /* out */
1721 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1726 i965_BufferSetNumElements(VADriverContextP ctx,
1727 VABufferID buf_id, /* in */
1728 unsigned int num_elements) /* in */
1730 struct i965_driver_data *i965 = i965_driver_data(ctx);
1731 struct object_buffer *obj_buffer = BUFFER(buf_id);
1732 VAStatus vaStatus = VA_STATUS_SUCCESS;
1737 return VA_STATUS_ERROR_INVALID_BUFFER;
1739 if ((num_elements < 0) ||
1740 (num_elements > obj_buffer->max_num_elements)) {
1741 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1743 obj_buffer->num_elements = num_elements;
1744 if (obj_buffer->buffer_store != NULL) {
1745 obj_buffer->buffer_store->num_elements = num_elements;
1753 i965_MapBuffer(VADriverContextP ctx,
1754 VABufferID buf_id, /* in */
1755 void **pbuf) /* out */
1757 struct i965_driver_data *i965 = i965_driver_data(ctx);
1758 struct object_buffer *obj_buffer = BUFFER(buf_id);
1759 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1761 assert(obj_buffer && obj_buffer->buffer_store);
1762 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1763 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1765 if (!obj_buffer || !obj_buffer->buffer_store)
1766 return VA_STATUS_ERROR_INVALID_BUFFER;
1768 if (NULL != obj_buffer->buffer_store->bo) {
1769 unsigned int tiling, swizzle;
1771 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1773 if (tiling != I915_TILING_NONE)
1774 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1776 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1778 assert(obj_buffer->buffer_store->bo->virtual);
1779 *pbuf = obj_buffer->buffer_store->bo->virtual;
1781 if (obj_buffer->type == VAEncCodedBufferType) {
1783 unsigned char *buffer = NULL;
1784 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1786 if (!coded_buffer_segment->mapped) {
1787 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1789 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1791 if (coded_buffer_segment->codec == CODEC_H264) {
1792 delimiter0 = H264_DELIMITER0;
1793 delimiter1 = H264_DELIMITER1;
1794 delimiter2 = H264_DELIMITER2;
1795 delimiter3 = H264_DELIMITER3;
1796 delimiter4 = H264_DELIMITER4;
1797 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1798 delimiter0 = MPEG2_DELIMITER0;
1799 delimiter1 = MPEG2_DELIMITER1;
1800 delimiter2 = MPEG2_DELIMITER2;
1801 delimiter3 = MPEG2_DELIMITER3;
1802 delimiter4 = MPEG2_DELIMITER4;
1807 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1808 if ((buffer[i] == delimiter0) &&
1809 (buffer[i + 1] == delimiter1) &&
1810 (buffer[i + 2] == delimiter2) &&
1811 (buffer[i + 3] == delimiter3) &&
1812 (buffer[i + 4] == delimiter4))
1816 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1817 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1820 coded_buffer_segment->base.size = i;
1821 coded_buffer_segment->mapped = 1;
1823 assert(coded_buffer_segment->base.buf);
1827 vaStatus = VA_STATUS_SUCCESS;
1828 } else if (NULL != obj_buffer->buffer_store->buffer) {
1829 *pbuf = obj_buffer->buffer_store->buffer;
1830 vaStatus = VA_STATUS_SUCCESS;
1837 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1839 struct i965_driver_data *i965 = i965_driver_data(ctx);
1840 struct object_buffer *obj_buffer = BUFFER(buf_id);
1841 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1843 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
1844 return VA_STATUS_ERROR_INVALID_BUFFER;
1846 assert(obj_buffer && obj_buffer->buffer_store);
1847 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1848 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1850 if (!obj_buffer || !obj_buffer->buffer_store)
1851 return VA_STATUS_ERROR_INVALID_BUFFER;
1853 if (NULL != obj_buffer->buffer_store->bo) {
1854 unsigned int tiling, swizzle;
1856 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1858 if (tiling != I915_TILING_NONE)
1859 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1861 dri_bo_unmap(obj_buffer->buffer_store->bo);
1863 vaStatus = VA_STATUS_SUCCESS;
1864 } else if (NULL != obj_buffer->buffer_store->buffer) {
1866 vaStatus = VA_STATUS_SUCCESS;
1873 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1875 struct i965_driver_data *i965 = i965_driver_data(ctx);
1876 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1881 return VA_STATUS_ERROR_INVALID_BUFFER;
1883 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1885 return VA_STATUS_SUCCESS;
1889 i965_BeginPicture(VADriverContextP ctx,
1890 VAContextID context,
1891 VASurfaceID render_target)
1893 struct i965_driver_data *i965 = i965_driver_data(ctx);
1894 struct object_context *obj_context = CONTEXT(context);
1895 struct object_surface *obj_surface = SURFACE(render_target);
1896 struct object_config *obj_config;
1900 assert(obj_context);
1903 return VA_STATUS_ERROR_INVALID_CONTEXT;
1905 assert(obj_surface);
1908 return VA_STATUS_ERROR_INVALID_SURFACE;
1910 obj_config = obj_context->obj_config;
1913 switch (obj_config->profile) {
1914 case VAProfileMPEG2Simple:
1915 case VAProfileMPEG2Main:
1916 vaStatus = VA_STATUS_SUCCESS;
1919 case VAProfileH264Baseline:
1920 case VAProfileH264Main:
1921 case VAProfileH264High:
1922 vaStatus = VA_STATUS_SUCCESS;
1925 case VAProfileVC1Simple:
1926 case VAProfileVC1Main:
1927 case VAProfileVC1Advanced:
1928 vaStatus = VA_STATUS_SUCCESS;
1931 case VAProfileJPEGBaseline:
1932 vaStatus = VA_STATUS_SUCCESS;
1936 vaStatus = VA_STATUS_SUCCESS;
1941 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1945 if (obj_context->codec_type == CODEC_PROC) {
1946 obj_context->codec_state.proc.current_render_target = render_target;
1947 } else if (obj_context->codec_type == CODEC_ENC) {
1948 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1950 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
1951 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1954 obj_context->codec_state.encode.num_slice_params = 0;
1957 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1959 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1960 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1962 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1963 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1965 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1966 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1968 obj_context->codec_state.encode.num_slice_params_ext = 0;
1969 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
1970 obj_context->codec_state.encode.last_packed_header_type = 0;
1972 obj_context->codec_state.decode.current_render_target = render_target;
1973 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1974 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1975 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1976 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
1978 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
1979 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1980 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1983 obj_context->codec_state.decode.num_slice_params = 0;
1984 obj_context->codec_state.decode.num_slice_datas = 0;
1990 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
1992 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
1994 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1995 struct object_context *obj_context, \
1996 struct object_buffer *obj_buffer) \
1998 struct category##_state *category = &obj_context->codec_state.category; \
1999 assert(obj_buffer->buffer_store->bo == NULL); \
2000 assert(obj_buffer->buffer_store->buffer); \
2001 i965_release_buffer_store(&category->member); \
2002 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2003 return VA_STATUS_SUCCESS; \
2006 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2008 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2009 struct object_context *obj_context, \
2010 struct object_buffer *obj_buffer) \
2012 struct category##_state *category = &obj_context->codec_state.category; \
2013 if (category->num_##member == category->max_##member) { \
2014 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2015 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2016 category->max_##member += NUM_SLICES; \
2018 i965_release_buffer_store(&category->member[category->num_##member]); \
2019 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2020 category->num_##member++; \
2021 return VA_STATUS_SUCCESS; \
2024 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2026 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2027 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2028 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2029 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2030 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2032 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2033 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2034 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2037 i965_decoder_render_picture(VADriverContextP ctx,
2038 VAContextID context,
2039 VABufferID *buffers,
2042 struct i965_driver_data *i965 = i965_driver_data(ctx);
2043 struct object_context *obj_context = CONTEXT(context);
2044 VAStatus vaStatus = VA_STATUS_SUCCESS;
2047 assert(obj_context);
2050 return VA_STATUS_ERROR_INVALID_CONTEXT;
2052 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2053 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2056 return VA_STATUS_ERROR_INVALID_BUFFER;
2058 switch (obj_buffer->type) {
2059 case VAPictureParameterBufferType:
2060 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2063 case VAIQMatrixBufferType:
2064 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2067 case VABitPlaneBufferType:
2068 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2071 case VASliceParameterBufferType:
2072 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2075 case VASliceDataBufferType:
2076 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2079 case VAHuffmanTableBufferType:
2080 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2084 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2092 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2094 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2095 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2096 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2097 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2098 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2099 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2100 /* extended buffer */
2101 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2102 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2104 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2105 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2106 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2109 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2110 struct object_context *obj_context,
2111 struct object_buffer *obj_buffer,
2114 struct encode_state *encode = &obj_context->codec_state.encode;
2116 assert(obj_buffer->buffer_store->bo == NULL);
2117 assert(obj_buffer->buffer_store->buffer);
2118 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2119 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2121 return VA_STATUS_SUCCESS;
2125 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2126 struct object_context *obj_context,
2127 struct object_buffer *obj_buffer,
2130 struct encode_state *encode = &obj_context->codec_state.encode;
2132 assert(obj_buffer->buffer_store->bo == NULL);
2133 assert(obj_buffer->buffer_store->buffer);
2134 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2135 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2137 return VA_STATUS_SUCCESS;
2141 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2142 struct object_context *obj_context,
2143 struct object_buffer *obj_buffer)
2145 struct encode_state *encode = &obj_context->codec_state.encode;
2146 VAEncMiscParameterBuffer *param = NULL;
2148 assert(obj_buffer->buffer_store->bo == NULL);
2149 assert(obj_buffer->buffer_store->buffer);
2151 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2152 i965_release_buffer_store(&encode->misc_param[param->type]);
2153 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2155 return VA_STATUS_SUCCESS;
2159 i965_encoder_render_picture(VADriverContextP ctx,
2160 VAContextID context,
2161 VABufferID *buffers,
2164 struct i965_driver_data *i965 = i965_driver_data(ctx);
2165 struct object_context *obj_context = CONTEXT(context);
2166 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2169 assert(obj_context);
2172 return VA_STATUS_ERROR_INVALID_CONTEXT;
2174 for (i = 0; i < num_buffers; i++) {
2175 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2178 return VA_STATUS_ERROR_INVALID_BUFFER;
2180 switch (obj_buffer->type) {
2181 case VAQMatrixBufferType:
2182 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2185 case VAIQMatrixBufferType:
2186 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2189 case VAEncSequenceParameterBufferType:
2190 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2193 case VAEncPictureParameterBufferType:
2194 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2197 case VAEncSliceParameterBufferType:
2198 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2201 case VAEncPackedHeaderParameterBufferType:
2203 struct encode_state *encode = &obj_context->codec_state.encode;
2204 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2205 encode->last_packed_header_type = param->type;
2207 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2210 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2214 case VAEncPackedHeaderDataBufferType:
2216 struct encode_state *encode = &obj_context->codec_state.encode;
2218 assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2219 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2220 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2221 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2222 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)));
2223 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2226 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2230 case VAEncMiscParameterBufferType:
2231 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2237 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2245 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2247 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2248 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2251 i965_proc_render_picture(VADriverContextP ctx,
2252 VAContextID context,
2253 VABufferID *buffers,
2256 struct i965_driver_data *i965 = i965_driver_data(ctx);
2257 struct object_context *obj_context = CONTEXT(context);
2258 VAStatus vaStatus = VA_STATUS_SUCCESS;
2261 assert(obj_context);
2264 return VA_STATUS_ERROR_INVALID_CONTEXT;
2266 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2267 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2270 return VA_STATUS_ERROR_INVALID_BUFFER;
2272 switch (obj_buffer->type) {
2273 case VAProcPipelineParameterBufferType:
2274 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2278 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2287 i965_RenderPicture(VADriverContextP ctx,
2288 VAContextID context,
2289 VABufferID *buffers,
2292 struct i965_driver_data *i965 = i965_driver_data(ctx);
2293 struct object_context *obj_context;
2294 struct object_config *obj_config;
2295 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2297 obj_context = CONTEXT(context);
2298 assert(obj_context);
2301 return VA_STATUS_ERROR_INVALID_CONTEXT;
2303 if (num_buffers <= 0)
2304 return VA_STATUS_ERROR_INVALID_PARAMETER;
2306 obj_config = obj_context->obj_config;
2309 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2310 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2311 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2312 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2314 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2321 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2323 struct i965_driver_data *i965 = i965_driver_data(ctx);
2324 struct object_context *obj_context = CONTEXT(context);
2325 struct object_config *obj_config;
2327 assert(obj_context);
2330 return VA_STATUS_ERROR_INVALID_CONTEXT;
2332 obj_config = obj_context->obj_config;
2335 if (obj_context->codec_type == CODEC_PROC) {
2336 assert(VAEntrypointVideoProc == obj_config->entrypoint);
2337 } else if (obj_context->codec_type == CODEC_ENC) {
2338 assert(VAEntrypointEncSlice == obj_config->entrypoint);
2340 if (!(obj_context->codec_state.encode.pic_param ||
2341 obj_context->codec_state.encode.pic_param_ext)) {
2342 return VA_STATUS_ERROR_INVALID_PARAMETER;
2344 if (!(obj_context->codec_state.encode.seq_param ||
2345 obj_context->codec_state.encode.seq_param_ext)) {
2346 return VA_STATUS_ERROR_INVALID_PARAMETER;
2348 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2349 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2350 return VA_STATUS_ERROR_INVALID_PARAMETER;
2353 if (obj_context->codec_state.decode.pic_param == NULL) {
2354 return VA_STATUS_ERROR_INVALID_PARAMETER;
2356 if (obj_context->codec_state.decode.num_slice_params <=0) {
2357 return VA_STATUS_ERROR_INVALID_PARAMETER;
2359 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2360 return VA_STATUS_ERROR_INVALID_PARAMETER;
2363 if (obj_context->codec_state.decode.num_slice_params !=
2364 obj_context->codec_state.decode.num_slice_datas) {
2365 return VA_STATUS_ERROR_INVALID_PARAMETER;
2369 assert(obj_context->hw_context->run);
2370 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2374 i965_SyncSurface(VADriverContextP ctx,
2375 VASurfaceID render_target)
2377 struct i965_driver_data *i965 = i965_driver_data(ctx);
2378 struct object_surface *obj_surface = SURFACE(render_target);
2380 assert(obj_surface);
2383 drm_intel_bo_wait_rendering(obj_surface->bo);
2385 return VA_STATUS_SUCCESS;
2389 i965_QuerySurfaceStatus(VADriverContextP ctx,
2390 VASurfaceID render_target,
2391 VASurfaceStatus *status) /* out */
2393 struct i965_driver_data *i965 = i965_driver_data(ctx);
2394 struct object_surface *obj_surface = SURFACE(render_target);
2396 assert(obj_surface);
2398 if (obj_surface->bo) {
2399 if (drm_intel_bo_busy(obj_surface->bo)){
2400 *status = VASurfaceRendering;
2403 *status = VASurfaceReady;
2406 *status = VASurfaceReady;
2409 return VA_STATUS_SUCCESS;
2412 static VADisplayAttribute *
2413 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2415 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2418 if (!i965->display_attributes)
2421 for (i = 0; i < i965->num_display_attributes; i++) {
2422 if (i965->display_attributes[i].type == type)
2423 return &i965->display_attributes[i];
2429 i965_display_attributes_terminate(VADriverContextP ctx)
2431 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2433 if (i965->display_attributes) {
2434 free(i965->display_attributes);
2435 i965->display_attributes = NULL;
2436 i965->num_display_attributes = 0;
2441 i965_display_attributes_init(VADriverContextP ctx)
2443 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2445 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2446 i965->display_attributes = malloc(
2447 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2448 if (!i965->display_attributes)
2452 i965->display_attributes,
2453 i965_display_attributes,
2454 sizeof(i965_display_attributes)
2457 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2458 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2459 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2460 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2461 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2463 if (!i965->rotation_attrib ||
2464 !i965->brightness_attrib ||
2465 !i965->contrast_attrib ||
2466 !i965->hue_attrib ||
2467 !i965->saturation_attrib) {
2473 i965_display_attributes_terminate(ctx);
2478 * Query display attributes
2479 * The caller must provide a "attr_list" array that can hold at
2480 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2481 * returned in "attr_list" is returned in "num_attributes".
2484 i965_QueryDisplayAttributes(
2485 VADriverContextP ctx,
2486 VADisplayAttribute *attribs, /* out */
2487 int *num_attribs_ptr /* out */
2490 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2492 if (attribs && num_attribs > 0)
2493 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2495 if (num_attribs_ptr)
2496 *num_attribs_ptr = num_attribs;
2498 return VA_STATUS_SUCCESS;
2502 * Get display attributes
2503 * This function returns the current attribute values in "attr_list".
2504 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2505 * from vaQueryDisplayAttributes() can have their values retrieved.
2508 i965_GetDisplayAttributes(
2509 VADriverContextP ctx,
2510 VADisplayAttribute *attribs, /* inout */
2511 int num_attribs /* in */
2516 for (i = 0; i < num_attribs; i++) {
2517 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2519 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2520 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2521 dst_attrib->min_value = src_attrib->min_value;
2522 dst_attrib->max_value = src_attrib->max_value;
2523 dst_attrib->value = src_attrib->value;
2526 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2528 return VA_STATUS_SUCCESS;
2532 * Set display attributes
2533 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2534 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2535 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2538 i965_SetDisplayAttributes(
2539 VADriverContextP ctx,
2540 VADisplayAttribute *attribs, /* in */
2541 int num_attribs /* in */
2546 for (i = 0; i < num_attribs; i++) {
2547 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2549 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2551 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2553 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2556 if (src_attrib->value < dst_attrib->min_value ||
2557 src_attrib->value > dst_attrib->max_value)
2558 return VA_STATUS_ERROR_INVALID_PARAMETER;
2560 dst_attrib->value = src_attrib->value;
2561 /* XXX: track modified attributes through timestamps */
2563 return VA_STATUS_SUCCESS;
2567 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2568 VASurfaceID surface,
2569 void **buffer, /* out */
2570 unsigned int *stride) /* out */
2573 return VA_STATUS_ERROR_UNIMPLEMENTED;
2577 i965_destroy_heap(struct object_heap *heap,
2578 void (*func)(struct object_heap *heap, struct object_base *object))
2580 struct object_base *object;
2581 object_heap_iterator iter;
2583 object = object_heap_first(heap, &iter);
2589 object = object_heap_next(heap, &iter);
2592 object_heap_destroy(heap);
2597 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2600 i965_CreateImage(VADriverContextP ctx,
2601 VAImageFormat *format,
2604 VAImage *out_image) /* out */
2606 struct i965_driver_data *i965 = i965_driver_data(ctx);
2607 struct object_image *obj_image;
2608 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2610 unsigned int width2, height2, size2, size;
2612 out_image->image_id = VA_INVALID_ID;
2613 out_image->buf = VA_INVALID_ID;
2615 image_id = NEW_IMAGE_ID();
2616 if (image_id == VA_INVALID_ID)
2617 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2619 obj_image = IMAGE(image_id);
2621 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2622 obj_image->bo = NULL;
2623 obj_image->palette = NULL;
2624 obj_image->derived_surface = VA_INVALID_ID;
2626 VAImage * const image = &obj_image->image;
2627 image->image_id = image_id;
2628 image->buf = VA_INVALID_ID;
2630 size = width * height;
2631 width2 = (width + 1) / 2;
2632 height2 = (height + 1) / 2;
2633 size2 = width2 * height2;
2635 image->num_palette_entries = 0;
2636 image->entry_bytes = 0;
2637 memset(image->component_order, 0, sizeof(image->component_order));
2639 switch (format->fourcc) {
2640 case VA_FOURCC('I','A','4','4'):
2641 case VA_FOURCC('A','I','4','4'):
2642 image->num_planes = 1;
2643 image->pitches[0] = width;
2644 image->offsets[0] = 0;
2645 image->data_size = image->offsets[0] + image->pitches[0] * height;
2646 image->num_palette_entries = 16;
2647 image->entry_bytes = 3;
2648 image->component_order[0] = 'R';
2649 image->component_order[1] = 'G';
2650 image->component_order[2] = 'B';
2652 case VA_FOURCC('I','A','8','8'):
2653 case VA_FOURCC('A','I','8','8'):
2654 image->num_planes = 1;
2655 image->pitches[0] = width * 2;
2656 image->offsets[0] = 0;
2657 image->data_size = image->offsets[0] + image->pitches[0] * height;
2658 image->num_palette_entries = 256;
2659 image->entry_bytes = 3;
2660 image->component_order[0] = 'R';
2661 image->component_order[1] = 'G';
2662 image->component_order[2] = 'B';
2664 case VA_FOURCC('A','R','G','B'):
2665 case VA_FOURCC('A','B','G','R'):
2666 case VA_FOURCC('B','G','R','A'):
2667 case VA_FOURCC('R','G','B','A'):
2668 case VA_FOURCC('B','G','R','X'):
2669 case VA_FOURCC('R','G','B','X'):
2670 image->num_planes = 1;
2671 image->pitches[0] = width * 4;
2672 image->offsets[0] = 0;
2673 image->data_size = image->offsets[0] + image->pitches[0] * height;
2675 case VA_FOURCC('Y','V','1','2'):
2676 image->num_planes = 3;
2677 image->pitches[0] = width;
2678 image->offsets[0] = 0;
2679 image->pitches[1] = width2;
2680 image->offsets[1] = size + size2;
2681 image->pitches[2] = width2;
2682 image->offsets[2] = size;
2683 image->data_size = size + 2 * size2;
2685 case VA_FOURCC('I','4','2','0'):
2686 image->num_planes = 3;
2687 image->pitches[0] = width;
2688 image->offsets[0] = 0;
2689 image->pitches[1] = width2;
2690 image->offsets[1] = size;
2691 image->pitches[2] = width2;
2692 image->offsets[2] = size + size2;
2693 image->data_size = size + 2 * size2;
2695 case VA_FOURCC('N','V','1','2'):
2696 image->num_planes = 2;
2697 image->pitches[0] = width;
2698 image->offsets[0] = 0;
2699 image->pitches[1] = width;
2700 image->offsets[1] = size;
2701 image->data_size = size + 2 * size2;
2703 case VA_FOURCC('Y','U','Y','2'):
2704 case VA_FOURCC('U','Y','V','Y'):
2705 image->num_planes = 1;
2706 image->pitches[0] = width * 2;
2707 image->offsets[0] = 0;
2708 image->data_size = size * 2;
2714 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2715 image->data_size, 1, NULL, &image->buf);
2716 if (va_status != VA_STATUS_SUCCESS)
2719 struct object_buffer *obj_buffer = BUFFER(image->buf);
2722 !obj_buffer->buffer_store ||
2723 !obj_buffer->buffer_store->bo)
2724 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2726 obj_image->bo = obj_buffer->buffer_store->bo;
2727 dri_bo_reference(obj_image->bo);
2729 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2730 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2731 if (!obj_image->palette)
2735 image->image_id = image_id;
2736 image->format = *format;
2737 image->width = width;
2738 image->height = height;
2740 *out_image = *image;
2741 return VA_STATUS_SUCCESS;
2744 i965_DestroyImage(ctx, image_id);
2749 i965_check_alloc_surface_bo(VADriverContextP ctx,
2750 struct object_surface *obj_surface,
2752 unsigned int fourcc,
2753 unsigned int subsampling)
2755 struct i965_driver_data *i965 = i965_driver_data(ctx);
2756 int region_width, region_height;
2758 if (obj_surface->bo) {
2759 assert(obj_surface->fourcc);
2760 assert(obj_surface->fourcc == fourcc);
2761 assert(obj_surface->subsampling == subsampling);
2765 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2766 obj_surface->x_cr_offset = 0;
2769 assert(fourcc != VA_FOURCC('I', '4', '2', '0') &&
2770 fourcc != VA_FOURCC('I', 'Y', 'U', 'V') &&
2771 fourcc != VA_FOURCC('Y', 'V', '1', '2'));
2773 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2774 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2775 region_height = obj_surface->height;
2778 case VA_FOURCC('N', 'V', '1', '2'):
2779 assert(subsampling == SUBSAMPLE_YUV420);
2780 obj_surface->cb_cr_pitch = obj_surface->width;
2781 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2782 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2783 obj_surface->y_cb_offset = obj_surface->height;
2784 obj_surface->y_cr_offset = obj_surface->height;
2785 region_width = obj_surface->width;
2786 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2790 case VA_FOURCC('I', 'M', 'C', '1'):
2791 assert(subsampling == SUBSAMPLE_YUV420);
2792 obj_surface->cb_cr_pitch = obj_surface->width;
2793 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2794 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2795 obj_surface->y_cr_offset = obj_surface->height;
2796 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2797 region_width = obj_surface->width;
2798 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2802 case VA_FOURCC('I', 'M', 'C', '3'):
2803 assert(subsampling == SUBSAMPLE_YUV420);
2804 obj_surface->cb_cr_pitch = obj_surface->width;
2805 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2806 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2807 obj_surface->y_cb_offset = obj_surface->height;
2808 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2809 region_width = obj_surface->width;
2810 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2814 case VA_FOURCC('4', '2', '2', 'H'):
2815 assert(subsampling == SUBSAMPLE_YUV422H);
2816 obj_surface->cb_cr_pitch = obj_surface->width;
2817 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2818 obj_surface->cb_cr_height = obj_surface->orig_height;
2819 obj_surface->y_cb_offset = obj_surface->height;
2820 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2821 region_width = obj_surface->width;
2822 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2826 case VA_FOURCC('4', '2', '2', 'V'):
2827 assert(subsampling == SUBSAMPLE_YUV422V);
2828 obj_surface->cb_cr_pitch = obj_surface->width;
2829 obj_surface->cb_cr_width = obj_surface->orig_width;
2830 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2831 obj_surface->y_cb_offset = obj_surface->height;
2832 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2833 region_width = obj_surface->width;
2834 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2838 case VA_FOURCC('4', '1', '1', 'P'):
2839 assert(subsampling == SUBSAMPLE_YUV411);
2840 obj_surface->cb_cr_pitch = obj_surface->width;
2841 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2842 obj_surface->cb_cr_height = obj_surface->orig_height;
2843 obj_surface->y_cb_offset = obj_surface->height;
2844 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2845 region_width = obj_surface->width;
2846 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2850 case VA_FOURCC('4', '4', '4', 'P'):
2851 assert(subsampling == SUBSAMPLE_YUV444);
2852 obj_surface->cb_cr_pitch = obj_surface->width;
2853 obj_surface->cb_cr_width = obj_surface->orig_width;
2854 obj_surface->cb_cr_height = obj_surface->orig_height;
2855 obj_surface->y_cb_offset = obj_surface->height;
2856 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2857 region_width = obj_surface->width;
2858 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2862 case VA_FOURCC('Y', '8', '0', '0'):
2863 assert(subsampling == SUBSAMPLE_YUV400);
2864 obj_surface->cb_cr_pitch = obj_surface->width;
2865 obj_surface->cb_cr_width = 0;
2866 obj_surface->cb_cr_height = 0;
2867 obj_surface->y_cb_offset = obj_surface->height;
2868 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2869 region_width = obj_surface->width;
2870 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2874 case VA_FOURCC('Y', 'U', 'Y', '2'):
2875 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2876 assert(subsampling == SUBSAMPLE_YUV422H);
2877 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2878 obj_surface->y_cb_offset = 0;
2879 obj_surface->y_cr_offset = 0;
2880 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2881 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2882 region_width = obj_surface->width * 2;
2883 region_height = obj_surface->height;
2887 case VA_FOURCC('R', 'G', 'B', 'A'):
2888 case VA_FOURCC('R', 'G', 'B', 'X'):
2889 case VA_FOURCC('B', 'G', 'R', 'A'):
2890 case VA_FOURCC('B', 'G', 'R', 'X'):
2891 assert(subsampling == SUBSAMPLE_RGBX);
2893 region_width = obj_surface->width * 4;
2894 region_height = obj_surface->height;
2898 /* Never get here */
2903 assert(subsampling == SUBSAMPLE_YUV420 ||
2904 subsampling == SUBSAMPLE_YUV422H ||
2905 subsampling == SUBSAMPLE_YUV422V ||
2906 subsampling == SUBSAMPLE_RGBX);
2908 region_width = obj_surface->width;
2909 region_height = obj_surface->height;
2912 case VA_FOURCC('N', 'V', '1', '2'):
2913 obj_surface->y_cb_offset = obj_surface->height;
2914 obj_surface->y_cr_offset = obj_surface->height;
2915 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2916 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2917 obj_surface->cb_cr_pitch = obj_surface->width;
2918 region_height = obj_surface->height + obj_surface->height / 2;
2921 case VA_FOURCC('Y', 'V', '1', '2'):
2922 case VA_FOURCC('I', '4', '2', '0'):
2923 if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
2924 obj_surface->y_cr_offset = obj_surface->height;
2925 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
2927 obj_surface->y_cb_offset = obj_surface->height;
2928 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
2931 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2932 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2933 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2934 region_height = obj_surface->height + obj_surface->height / 2;
2937 case VA_FOURCC('Y', 'U', 'Y', '2'):
2938 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2939 obj_surface->y_cb_offset = 0;
2940 obj_surface->y_cr_offset = 0;
2941 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2942 obj_surface->cb_cr_height = obj_surface->orig_height;
2943 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2944 region_width = obj_surface->width * 2;
2945 region_height = obj_surface->height;
2947 case VA_FOURCC('R', 'G', 'B', 'A'):
2948 case VA_FOURCC('R', 'G', 'B', 'X'):
2949 case VA_FOURCC('B', 'G', 'R', 'A'):
2950 case VA_FOURCC('B', 'G', 'R', 'X'):
2951 region_width = obj_surface->width * 4;
2952 region_height = obj_surface->height;
2956 /* Never get here */
2962 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
2965 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
2966 unsigned long pitch;
2968 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
2976 assert(tiling_mode == I915_TILING_Y);
2977 assert(pitch == obj_surface->width ||
2978 pitch == obj_surface->width * 2 ||
2979 pitch == obj_surface->width * 4) ;
2981 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
2987 obj_surface->fourcc = fourcc;
2988 obj_surface->subsampling = subsampling;
2989 assert(obj_surface->bo);
2992 VAStatus i965_DeriveImage(VADriverContextP ctx,
2993 VASurfaceID surface,
2994 VAImage *out_image) /* out */
2996 struct i965_driver_data *i965 = i965_driver_data(ctx);
2997 struct object_image *obj_image;
2998 struct object_surface *obj_surface;
3000 unsigned int w_pitch;
3001 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3003 out_image->image_id = VA_INVALID_ID;
3004 obj_surface = SURFACE(surface);
3007 return VA_STATUS_ERROR_INVALID_SURFACE;
3009 if (!obj_surface->bo) {
3010 unsigned int is_tiled = 0;
3011 unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
3012 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3013 int sampling = get_sampling_from_fourcc(fourcc);
3014 i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3017 assert(obj_surface->fourcc);
3019 w_pitch = obj_surface->width;
3021 image_id = NEW_IMAGE_ID();
3023 if (image_id == VA_INVALID_ID)
3024 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3026 obj_image = IMAGE(image_id);
3029 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3031 obj_image->bo = NULL;
3032 obj_image->palette = NULL;
3033 obj_image->derived_surface = VA_INVALID_ID;
3035 VAImage * const image = &obj_image->image;
3037 memset(image, 0, sizeof(*image));
3038 image->image_id = image_id;
3039 image->buf = VA_INVALID_ID;
3040 image->num_palette_entries = 0;
3041 image->entry_bytes = 0;
3042 image->width = obj_surface->orig_width;
3043 image->height = obj_surface->orig_height;
3044 image->data_size = obj_surface->size;
3046 image->format.fourcc = obj_surface->fourcc;
3047 image->format.byte_order = VA_LSB_FIRST;
3048 image->format.bits_per_pixel = 12;
3050 switch (image->format.fourcc) {
3051 case VA_FOURCC('Y', 'V', '1', '2'):
3052 image->num_planes = 3;
3053 image->pitches[0] = w_pitch; /* Y */
3054 image->offsets[0] = 0;
3055 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3056 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3057 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3058 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3061 case VA_FOURCC('N', 'V', '1', '2'):
3062 image->num_planes = 2;
3063 image->pitches[0] = w_pitch; /* Y */
3064 image->offsets[0] = 0;
3065 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3066 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3069 case VA_FOURCC('I', '4', '2', '0'):
3070 image->num_planes = 3;
3071 image->pitches[0] = w_pitch; /* Y */
3072 image->offsets[0] = 0;
3073 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3074 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3075 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3076 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3078 case VA_FOURCC('Y', 'U', 'Y', '2'):
3079 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3080 image->num_planes = 1;
3081 image->pitches[0] = obj_surface->width * 2; /* Y, width is aligned already */
3082 image->offsets[0] = 0;
3084 case VA_FOURCC('R', 'G', 'B', 'A'):
3085 case VA_FOURCC('R', 'G', 'B', 'X'):
3086 case VA_FOURCC('B', 'G', 'R', 'A'):
3087 case VA_FOURCC('B', 'G', 'R', 'X'):
3088 image->num_planes = 1;
3089 image->pitches[0] = obj_surface->width * 4;
3095 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3096 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3097 if (va_status != VA_STATUS_SUCCESS)
3100 struct object_buffer *obj_buffer = BUFFER(image->buf);
3103 !obj_buffer->buffer_store ||
3104 !obj_buffer->buffer_store->bo)
3105 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3107 obj_image->bo = obj_buffer->buffer_store->bo;
3108 dri_bo_reference(obj_image->bo);
3110 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3111 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3112 if (!obj_image->palette) {
3113 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3118 *out_image = *image;
3119 obj_surface->flags |= SURFACE_DERIVED;
3120 obj_image->derived_surface = surface;
3122 return VA_STATUS_SUCCESS;
3125 i965_DestroyImage(ctx, image_id);
3130 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3132 object_heap_free(heap, obj);
3137 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3139 struct i965_driver_data *i965 = i965_driver_data(ctx);
3140 struct object_image *obj_image = IMAGE(image);
3141 struct object_surface *obj_surface;
3144 return VA_STATUS_SUCCESS;
3146 dri_bo_unreference(obj_image->bo);
3147 obj_image->bo = NULL;
3149 if (obj_image->image.buf != VA_INVALID_ID) {
3150 i965_DestroyBuffer(ctx, obj_image->image.buf);
3151 obj_image->image.buf = VA_INVALID_ID;
3154 if (obj_image->palette) {
3155 free(obj_image->palette);
3156 obj_image->palette = NULL;
3159 obj_surface = SURFACE(obj_image->derived_surface);
3162 obj_surface->flags &= ~SURFACE_DERIVED;
3165 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3167 return VA_STATUS_SUCCESS;
3171 * pointer to an array holding the palette data. The size of the array is
3172 * num_palette_entries * entry_bytes in size. The order of the components
3173 * in the palette is described by the component_order in VASubpicture struct
3176 i965_SetImagePalette(VADriverContextP ctx,
3178 unsigned char *palette)
3180 struct i965_driver_data *i965 = i965_driver_data(ctx);
3183 struct object_image *obj_image = IMAGE(image);
3185 return VA_STATUS_ERROR_INVALID_IMAGE;
3187 if (!obj_image->palette)
3188 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3190 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3191 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3192 ((unsigned int)palette[3*i + 1] << 8) |
3193 (unsigned int)palette[3*i + 2]);
3194 return VA_STATUS_SUCCESS;
3198 get_sampling_from_fourcc(unsigned int fourcc)
3200 int surface_sampling = -1;
3203 case VA_FOURCC('N', 'V', '1', '2'):
3204 case VA_FOURCC('Y', 'V', '1', '2'):
3205 case VA_FOURCC('I', '4', '2', '0'):
3206 case VA_FOURCC('I', 'Y', 'U', 'V'):
3207 case VA_FOURCC('I', 'M', 'C', '1'):
3208 case VA_FOURCC('I', 'M', 'C', '3'):
3209 surface_sampling = SUBSAMPLE_YUV420;
3211 case VA_FOURCC('Y', 'U', 'Y', '2'):
3212 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3213 case VA_FOURCC('4', '2', '2', 'H'):
3214 surface_sampling = SUBSAMPLE_YUV422H;
3216 case VA_FOURCC('4', '2', '2', 'V'):
3217 surface_sampling = SUBSAMPLE_YUV422V;
3220 case VA_FOURCC('4', '4', '4', 'P'):
3221 surface_sampling = SUBSAMPLE_YUV444;
3224 case VA_FOURCC('4', '1', '1', 'P'):
3225 surface_sampling = SUBSAMPLE_YUV411;
3228 case VA_FOURCC('Y', '8', '0', '0'):
3229 surface_sampling = SUBSAMPLE_YUV400;
3231 case VA_FOURCC('R','G','B','A'):
3232 case VA_FOURCC('R','G','B','X'):
3233 case VA_FOURCC('B','G','R','A'):
3234 case VA_FOURCC('B','G','R','X'):
3235 surface_sampling = SUBSAMPLE_RGBX;
3238 /* Never get here */
3244 return surface_sampling;
3248 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3249 const uint8_t *src, unsigned int src_stride,
3250 unsigned int len, unsigned int height)
3254 for (i = 0; i < height; i++) {
3255 memcpy(dst, src, len);
3262 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3263 struct object_surface *obj_surface,
3264 const VARectangle *rect)
3266 uint8_t *dst[3], *src[3];
3268 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3269 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3270 unsigned int tiling, swizzle;
3272 if (!obj_surface->bo)
3275 assert(obj_surface->fourcc);
3276 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3278 if (tiling != I915_TILING_NONE)
3279 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3281 dri_bo_map(obj_surface->bo, 0);
3283 if (!obj_surface->bo->virtual)
3286 /* Dest VA image has either I420 or YV12 format.
3287 Source VA surface alway has I420 format */
3288 dst[Y] = image_data + obj_image->image.offsets[Y];
3289 src[0] = (uint8_t *)obj_surface->bo->virtual;
3290 dst[U] = image_data + obj_image->image.offsets[U];
3291 src[1] = src[0] + obj_surface->width * obj_surface->height;
3292 dst[V] = image_data + obj_image->image.offsets[V];
3293 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3296 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3297 src[0] += rect->y * obj_surface->width + rect->x;
3298 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3299 src[0], obj_surface->width,
3300 rect->width, rect->height);
3303 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3304 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3305 memcpy_pic(dst[U], obj_image->image.pitches[U],
3306 src[1], obj_surface->width / 2,
3307 rect->width / 2, rect->height / 2);
3310 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3311 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3312 memcpy_pic(dst[V], obj_image->image.pitches[V],
3313 src[2], obj_surface->width / 2,
3314 rect->width / 2, rect->height / 2);
3316 if (tiling != I915_TILING_NONE)
3317 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3319 dri_bo_unmap(obj_surface->bo);
3323 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3324 struct object_surface *obj_surface,
3325 const VARectangle *rect)
3327 uint8_t *dst[2], *src[2];
3328 unsigned int tiling, swizzle;
3330 if (!obj_surface->bo)
3333 assert(obj_surface->fourcc);
3334 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3336 if (tiling != I915_TILING_NONE)
3337 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3339 dri_bo_map(obj_surface->bo, 0);
3341 if (!obj_surface->bo->virtual)
3344 /* Both dest VA image and source surface have NV12 format */
3345 dst[0] = image_data + obj_image->image.offsets[0];
3346 src[0] = (uint8_t *)obj_surface->bo->virtual;
3347 dst[1] = image_data + obj_image->image.offsets[1];
3348 src[1] = src[0] + obj_surface->width * obj_surface->height;
3351 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3352 src[0] += rect->y * obj_surface->width + rect->x;
3353 memcpy_pic(dst[0], obj_image->image.pitches[0],
3354 src[0], obj_surface->width,
3355 rect->width, rect->height);
3358 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3359 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3360 memcpy_pic(dst[1], obj_image->image.pitches[1],
3361 src[1], obj_surface->width,
3362 rect->width, rect->height / 2);
3364 if (tiling != I915_TILING_NONE)
3365 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3367 dri_bo_unmap(obj_surface->bo);
3371 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3372 struct object_surface *obj_surface,
3373 const VARectangle *rect)
3376 unsigned int tiling, swizzle;
3378 if (!obj_surface->bo)
3381 assert(obj_surface->fourcc);
3382 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3384 if (tiling != I915_TILING_NONE)
3385 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3387 dri_bo_map(obj_surface->bo, 0);
3389 if (!obj_surface->bo->virtual)
3392 /* Both dest VA image and source surface have YUYV format */
3393 dst = image_data + obj_image->image.offsets[0];
3394 src = (uint8_t *)obj_surface->bo->virtual;
3397 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3398 src += rect->y * obj_surface->width + rect->x*2;
3399 memcpy_pic(dst, obj_image->image.pitches[0],
3400 src, obj_surface->width*2,
3401 rect->width*2, rect->height);
3403 if (tiling != I915_TILING_NONE)
3404 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3406 dri_bo_unmap(obj_surface->bo);
3410 i965_sw_getimage(VADriverContextP ctx,
3411 VASurfaceID surface,
3412 int x, /* coordinates of the upper left source pixel */
3414 unsigned int width, /* width and height of the region */
3415 unsigned int height,
3418 struct i965_driver_data *i965 = i965_driver_data(ctx);
3419 struct i965_render_state *render_state = &i965->render_state;
3421 struct object_surface *obj_surface = SURFACE(surface);
3423 return VA_STATUS_ERROR_INVALID_SURFACE;
3425 struct object_image *obj_image = IMAGE(image);
3427 return VA_STATUS_ERROR_INVALID_IMAGE;
3430 return VA_STATUS_ERROR_INVALID_PARAMETER;
3431 if (x + width > obj_surface->orig_width ||
3432 y + height > obj_surface->orig_height)
3433 return VA_STATUS_ERROR_INVALID_PARAMETER;
3434 if (x + width > obj_image->image.width ||
3435 y + height > obj_image->image.height)
3436 return VA_STATUS_ERROR_INVALID_PARAMETER;
3438 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3439 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3442 void *image_data = NULL;
3444 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3445 if (va_status != VA_STATUS_SUCCESS)
3452 rect.height = height;
3454 switch (obj_image->image.format.fourcc) {
3455 case VA_FOURCC('Y','V','1','2'):
3456 case VA_FOURCC('I','4','2','0'):
3457 /* I420 is native format for MPEG-2 decoded surfaces */
3458 if (render_state->interleaved_uv)
3459 goto operation_failed;
3460 get_image_i420(obj_image, image_data, obj_surface, &rect);
3462 case VA_FOURCC('N','V','1','2'):
3463 /* NV12 is native format for H.264 decoded surfaces */
3464 if (!render_state->interleaved_uv)
3465 goto operation_failed;
3466 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3468 case VA_FOURCC('Y','U','Y','2'):
3469 /* YUY2 is the format supported by overlay plane */
3470 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3474 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3478 i965_UnmapBuffer(ctx, obj_image->image.buf);
3483 i965_hw_getimage(VADriverContextP ctx,
3484 VASurfaceID surface,
3485 int x, /* coordinates of the upper left source pixel */
3487 unsigned int width, /* width and height of the region */
3488 unsigned int height,
3491 struct i965_driver_data *i965 = i965_driver_data(ctx);
3492 struct i965_surface src_surface;
3493 struct i965_surface dst_surface;
3496 struct object_surface *obj_surface = SURFACE(surface);
3497 struct object_image *obj_image = IMAGE(image);
3500 return VA_STATUS_ERROR_INVALID_SURFACE;
3503 return VA_STATUS_ERROR_INVALID_IMAGE;
3506 return VA_STATUS_ERROR_INVALID_PARAMETER;
3507 if (x + width > obj_surface->orig_width ||
3508 y + height > obj_surface->orig_height)
3509 return VA_STATUS_ERROR_INVALID_PARAMETER;
3510 if (x + width > obj_image->image.width ||
3511 y + height > obj_image->image.height)
3512 return VA_STATUS_ERROR_INVALID_PARAMETER;
3514 if (!obj_surface->bo)
3515 return VA_STATUS_SUCCESS;
3516 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3521 rect.height = height;
3523 src_surface.base = (struct object_base *)obj_surface;
3524 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3525 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3527 dst_surface.base = (struct object_base *)obj_image;
3528 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3529 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3531 va_status = i965_image_processing(ctx,
3542 i965_GetImage(VADriverContextP ctx,
3543 VASurfaceID surface,
3544 int x, /* coordinates of the upper left source pixel */
3546 unsigned int width, /* width and height of the region */
3547 unsigned int height,
3550 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3553 if (HAS_ACCELERATED_GETIMAGE(i965))
3554 va_status = i965_hw_getimage(ctx,
3560 va_status = i965_sw_getimage(ctx,
3570 put_image_i420(struct object_surface *obj_surface,
3571 const VARectangle *dst_rect,
3572 struct object_image *obj_image, uint8_t *image_data,
3573 const VARectangle *src_rect)
3575 uint8_t *dst[3], *src[3];
3577 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3578 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3579 unsigned int tiling, swizzle;
3581 if (!obj_surface->bo)
3584 assert(obj_surface->fourcc);
3585 assert(dst_rect->width == src_rect->width);
3586 assert(dst_rect->height == src_rect->height);
3587 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3589 if (tiling != I915_TILING_NONE)
3590 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3592 dri_bo_map(obj_surface->bo, 0);
3594 if (!obj_surface->bo->virtual)
3597 /* Dest VA image has either I420 or YV12 format.
3598 Source VA surface alway has I420 format */
3599 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3600 src[Y] = image_data + obj_image->image.offsets[Y];
3601 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3602 src[U] = image_data + obj_image->image.offsets[U];
3603 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3604 src[V] = image_data + obj_image->image.offsets[V];
3607 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3608 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3609 memcpy_pic(dst[0], obj_surface->width,
3610 src[Y], obj_image->image.pitches[Y],
3611 src_rect->width, src_rect->height);
3614 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3615 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3616 memcpy_pic(dst[1], obj_surface->width / 2,
3617 src[U], obj_image->image.pitches[U],
3618 src_rect->width / 2, src_rect->height / 2);
3621 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3622 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3623 memcpy_pic(dst[2], obj_surface->width / 2,
3624 src[V], obj_image->image.pitches[V],
3625 src_rect->width / 2, src_rect->height / 2);
3627 if (tiling != I915_TILING_NONE)
3628 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3630 dri_bo_unmap(obj_surface->bo);
3634 put_image_nv12(struct object_surface *obj_surface,
3635 const VARectangle *dst_rect,
3636 struct object_image *obj_image, uint8_t *image_data,
3637 const VARectangle *src_rect)
3639 uint8_t *dst[2], *src[2];
3640 unsigned int tiling, swizzle;
3642 if (!obj_surface->bo)
3645 assert(obj_surface->fourcc);
3646 assert(dst_rect->width == src_rect->width);
3647 assert(dst_rect->height == src_rect->height);
3648 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3650 if (tiling != I915_TILING_NONE)
3651 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3653 dri_bo_map(obj_surface->bo, 0);
3655 if (!obj_surface->bo->virtual)
3658 /* Both dest VA image and source surface have NV12 format */
3659 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3660 src[0] = image_data + obj_image->image.offsets[0];
3661 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3662 src[1] = image_data + obj_image->image.offsets[1];
3665 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3666 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3667 memcpy_pic(dst[0], obj_surface->width,
3668 src[0], obj_image->image.pitches[0],
3669 src_rect->width, src_rect->height);
3672 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3673 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3674 memcpy_pic(dst[1], obj_surface->width,
3675 src[1], obj_image->image.pitches[1],
3676 src_rect->width, src_rect->height / 2);
3678 if (tiling != I915_TILING_NONE)
3679 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3681 dri_bo_unmap(obj_surface->bo);
3685 put_image_yuy2(struct object_surface *obj_surface,
3686 const VARectangle *dst_rect,
3687 struct object_image *obj_image, uint8_t *image_data,
3688 const VARectangle *src_rect)
3691 unsigned int tiling, swizzle;
3693 if (!obj_surface->bo)
3696 assert(obj_surface->fourcc);
3697 assert(dst_rect->width == src_rect->width);
3698 assert(dst_rect->height == src_rect->height);
3699 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3701 if (tiling != I915_TILING_NONE)
3702 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3704 dri_bo_map(obj_surface->bo, 0);
3706 if (!obj_surface->bo->virtual)
3709 /* Both dest VA image and source surface have YUY2 format */
3710 dst = (uint8_t *)obj_surface->bo->virtual;
3711 src = image_data + obj_image->image.offsets[0];
3713 /* YUYV packed plane */
3714 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3715 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3716 memcpy_pic(dst, obj_surface->width*2,
3717 src, obj_image->image.pitches[0],
3718 src_rect->width*2, src_rect->height);
3720 if (tiling != I915_TILING_NONE)
3721 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3723 dri_bo_unmap(obj_surface->bo);
3728 i965_sw_putimage(VADriverContextP ctx,
3729 VASurfaceID surface,
3733 unsigned int src_width,
3734 unsigned int src_height,
3737 unsigned int dest_width,
3738 unsigned int dest_height)
3740 struct i965_driver_data *i965 = i965_driver_data(ctx);
3741 struct object_surface *obj_surface = SURFACE(surface);
3744 return VA_STATUS_ERROR_INVALID_SURFACE;
3746 struct object_image *obj_image = IMAGE(image);
3748 return VA_STATUS_ERROR_INVALID_IMAGE;
3750 if (src_x < 0 || src_y < 0)
3751 return VA_STATUS_ERROR_INVALID_PARAMETER;
3752 if (src_x + src_width > obj_image->image.width ||
3753 src_y + src_height > obj_image->image.height)
3754 return VA_STATUS_ERROR_INVALID_PARAMETER;
3755 if (dest_x < 0 || dest_y < 0)
3756 return VA_STATUS_ERROR_INVALID_PARAMETER;
3757 if (dest_x + dest_width > obj_surface->orig_width ||
3758 dest_y + dest_height > obj_surface->orig_height)
3759 return VA_STATUS_ERROR_INVALID_PARAMETER;
3761 /* XXX: don't allow scaling */
3762 if (src_width != dest_width || src_height != dest_height)
3763 return VA_STATUS_ERROR_INVALID_PARAMETER;
3765 if (obj_surface->fourcc) {
3766 /* Don't allow format mismatch */
3767 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3768 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3772 /* VA is surface not used for decoding, use same VA image format */
3773 i965_check_alloc_surface_bo(
3776 0, /* XXX: don't use tiled surface */
3777 obj_image->image.format.fourcc,
3778 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3782 void *image_data = NULL;
3784 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3785 if (va_status != VA_STATUS_SUCCESS)
3788 VARectangle src_rect, dest_rect;
3791 src_rect.width = src_width;
3792 src_rect.height = src_height;
3793 dest_rect.x = dest_x;
3794 dest_rect.y = dest_y;
3795 dest_rect.width = dest_width;
3796 dest_rect.height = dest_height;
3798 switch (obj_image->image.format.fourcc) {
3799 case VA_FOURCC('Y','V','1','2'):
3800 case VA_FOURCC('I','4','2','0'):
3801 put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3803 case VA_FOURCC('N','V','1','2'):
3804 put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3806 case VA_FOURCC('Y','U','Y','2'):
3807 put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3810 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3814 i965_UnmapBuffer(ctx, obj_image->image.buf);
3819 i965_hw_putimage(VADriverContextP ctx,
3820 VASurfaceID surface,
3824 unsigned int src_width,
3825 unsigned int src_height,
3828 unsigned int dest_width,
3829 unsigned int dest_height)
3831 struct i965_driver_data *i965 = i965_driver_data(ctx);
3832 struct object_surface *obj_surface = SURFACE(surface);
3833 struct object_image *obj_image = IMAGE(image);
3834 struct i965_surface src_surface, dst_surface;
3835 VAStatus va_status = VA_STATUS_SUCCESS;
3836 VARectangle src_rect, dst_rect;
3839 return VA_STATUS_ERROR_INVALID_SURFACE;
3841 if (!obj_image || !obj_image->bo)
3842 return VA_STATUS_ERROR_INVALID_IMAGE;
3846 src_x + src_width > obj_image->image.width ||
3847 src_y + src_height > obj_image->image.height)
3848 return VA_STATUS_ERROR_INVALID_PARAMETER;
3852 dest_x + dest_width > obj_surface->orig_width ||
3853 dest_y + dest_height > obj_surface->orig_height)
3854 return VA_STATUS_ERROR_INVALID_PARAMETER;
3856 if (!obj_surface->bo) {
3857 unsigned int tiling, swizzle;
3858 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3859 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3861 i965_check_alloc_surface_bo(ctx,
3864 obj_image->image.format.fourcc,
3868 assert(obj_surface->fourcc);
3870 src_surface.base = (struct object_base *)obj_image;
3871 src_surface.type = I965_SURFACE_TYPE_IMAGE;
3872 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3875 src_rect.width = src_width;
3876 src_rect.height = src_height;
3878 dst_surface.base = (struct object_base *)obj_surface;
3879 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3880 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3881 dst_rect.x = dest_x;
3882 dst_rect.y = dest_y;
3883 dst_rect.width = dest_width;
3884 dst_rect.height = dest_height;
3886 va_status = i965_image_processing(ctx,
3896 i965_PutImage(VADriverContextP ctx,
3897 VASurfaceID surface,
3901 unsigned int src_width,
3902 unsigned int src_height,
3905 unsigned int dest_width,
3906 unsigned int dest_height)
3908 struct i965_driver_data *i965 = i965_driver_data(ctx);
3909 VAStatus va_status = VA_STATUS_SUCCESS;
3911 if (HAS_ACCELERATED_PUTIMAGE(i965))
3912 va_status = i965_hw_putimage(ctx,
3924 va_status = i965_sw_putimage(ctx,
3940 i965_PutSurface(VADriverContextP ctx,
3941 VASurfaceID surface,
3942 void *draw, /* X Drawable */
3945 unsigned short srcw,
3946 unsigned short srch,
3949 unsigned short destw,
3950 unsigned short desth,
3951 VARectangle *cliprects, /* client supplied clip list */
3952 unsigned int number_cliprects, /* number of clip rects in the clip list */
3953 unsigned int flags) /* de-interlacing flags */
3956 if (IS_VA_X11(ctx)) {
3957 VARectangle src_rect, dst_rect;
3961 src_rect.width = srcw;
3962 src_rect.height = srch;
3966 dst_rect.width = destw;
3967 dst_rect.height = desth;
3969 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
3970 cliprects, number_cliprects, flags);
3973 return VA_STATUS_ERROR_UNIMPLEMENTED;
3978 VADriverContextP ctx, /* in */
3979 VABufferID buf_id, /* in */
3980 VABufferType *type, /* out */
3981 unsigned int *size, /* out */
3982 unsigned int *num_elements /* out */
3985 struct i965_driver_data *i965 = NULL;
3986 struct object_buffer *obj_buffer = NULL;
3988 i965 = i965_driver_data(ctx);
3989 obj_buffer = BUFFER(buf_id);
3994 return VA_STATUS_ERROR_INVALID_BUFFER;
3996 *type = obj_buffer->type;
3997 *size = obj_buffer->size_element;
3998 *num_elements = obj_buffer->num_elements;
4000 return VA_STATUS_SUCCESS;
4005 VADriverContextP ctx, /* in */
4006 VASurfaceID surface, /* in */
4007 unsigned int *fourcc, /* out */
4008 unsigned int *luma_stride, /* out */
4009 unsigned int *chroma_u_stride, /* out */
4010 unsigned int *chroma_v_stride, /* out */
4011 unsigned int *luma_offset, /* out */
4012 unsigned int *chroma_u_offset, /* out */
4013 unsigned int *chroma_v_offset, /* out */
4014 unsigned int *buffer_name, /* out */
4015 void **buffer /* out */
4018 VAStatus vaStatus = VA_STATUS_SUCCESS;
4019 struct i965_driver_data *i965 = i965_driver_data(ctx);
4020 struct object_surface *obj_surface = NULL;
4024 assert(luma_stride);
4025 assert(chroma_u_stride);
4026 assert(chroma_v_stride);
4027 assert(luma_offset);
4028 assert(chroma_u_offset);
4029 assert(chroma_v_offset);
4030 assert(buffer_name);
4033 tmpImage.image_id = VA_INVALID_ID;
4035 obj_surface = SURFACE(surface);
4036 if (obj_surface == NULL) {
4037 // Surface is absent.
4038 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4042 // Lock functionality is absent now.
4043 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4044 // Surface is locked already.
4045 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4049 vaStatus = i965_DeriveImage(
4053 if (vaStatus != VA_STATUS_SUCCESS) {
4057 obj_surface->locked_image_id = tmpImage.image_id;
4059 vaStatus = i965_MapBuffer(
4063 if (vaStatus != VA_STATUS_SUCCESS) {
4067 *fourcc = tmpImage.format.fourcc;
4068 *luma_offset = tmpImage.offsets[0];
4069 *luma_stride = tmpImage.pitches[0];
4070 *chroma_u_offset = tmpImage.offsets[1];
4071 *chroma_u_stride = tmpImage.pitches[1];
4072 *chroma_v_offset = tmpImage.offsets[2];
4073 *chroma_v_stride = tmpImage.pitches[2];
4074 *buffer_name = tmpImage.buf;
4077 if (vaStatus != VA_STATUS_SUCCESS) {
4086 VADriverContextP ctx, /* in */
4087 VASurfaceID surface /* in */
4090 VAStatus vaStatus = VA_STATUS_SUCCESS;
4091 struct i965_driver_data *i965 = i965_driver_data(ctx);
4092 struct object_image *locked_img = NULL;
4093 struct object_surface *obj_surface = NULL;
4095 obj_surface = SURFACE(surface);
4097 if (obj_surface == NULL) {
4098 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4101 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4102 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4106 locked_img = IMAGE(obj_surface->locked_image_id);
4107 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4108 // Work image was deallocated before i965_UnlockSurface()
4109 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4113 vaStatus = i965_UnmapBuffer(
4115 locked_img->image.buf);
4116 if (vaStatus != VA_STATUS_SUCCESS) {
4120 vaStatus = i965_DestroyImage(
4122 locked_img->image.image_id);
4123 if (vaStatus != VA_STATUS_SUCCESS) {
4127 locked_img->image.image_id = VA_INVALID_ID;
4130 obj_surface->locked_image_id = VA_INVALID_ID;
4136 i965_GetSurfaceAttributes(
4137 VADriverContextP ctx,
4139 VASurfaceAttrib *attrib_list,
4140 unsigned int num_attribs
4143 VAStatus vaStatus = VA_STATUS_SUCCESS;
4144 struct i965_driver_data *i965 = i965_driver_data(ctx);
4145 struct object_config *obj_config;
4148 if (config == VA_INVALID_ID)
4149 return VA_STATUS_ERROR_INVALID_CONFIG;
4151 obj_config = CONFIG(config);
4153 if (obj_config == NULL)
4154 return VA_STATUS_ERROR_INVALID_CONFIG;
4156 if (attrib_list == NULL || num_attribs == 0)
4157 return VA_STATUS_ERROR_INVALID_PARAMETER;
4159 for (i = 0; i < num_attribs; i++) {
4160 switch (attrib_list[i].type) {
4161 case VASurfaceAttribPixelFormat:
4162 attrib_list[i].value.type = VAGenericValueTypeInteger;
4163 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4165 if (attrib_list[i].value.value.i == 0) {
4166 if (IS_G4X(i965->intel.device_id)) {
4167 if (obj_config->profile == VAProfileMPEG2Simple ||
4168 obj_config->profile == VAProfileMPEG2Main) {
4169 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4172 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4174 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4175 if (obj_config->profile == VAProfileMPEG2Simple ||
4176 obj_config->profile == VAProfileMPEG2Main) {
4177 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4178 } else if (obj_config->profile == VAProfileH264Baseline ||
4179 obj_config->profile == VAProfileH264Main ||
4180 obj_config->profile == VAProfileH264High) {
4181 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4182 } else if (obj_config->profile == VAProfileNone) {
4183 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4186 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4188 } else if (IS_GEN6(i965->intel.device_id)) {
4189 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4190 } else if (IS_GEN7(i965->intel.device_id)) {
4191 if (obj_config->profile == VAProfileJPEGBaseline)
4192 attrib_list[i].value.value.i = 0; /* internal format */
4194 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4197 if (IS_G4X(i965->intel.device_id)) {
4198 if (obj_config->profile == VAProfileMPEG2Simple ||
4199 obj_config->profile == VAProfileMPEG2Main) {
4200 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4201 attrib_list[i].value.value.i = 0;
4202 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4206 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4208 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4209 if (obj_config->profile == VAProfileMPEG2Simple ||
4210 obj_config->profile == VAProfileMPEG2Main) {
4211 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4212 attrib_list[i].value.value.i = 0;
4213 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4215 } else if (obj_config->profile == VAProfileH264Baseline ||
4216 obj_config->profile == VAProfileH264Main ||
4217 obj_config->profile == VAProfileH264High) {
4218 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4219 attrib_list[i].value.value.i = 0;
4220 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4222 } else if (obj_config->profile == VAProfileNone) {
4223 switch (attrib_list[i].value.value.i) {
4224 case VA_FOURCC('N', 'V', '1', '2'):
4225 case VA_FOURCC('I', '4', '2', '0'):
4226 case VA_FOURCC('Y', 'V', '1', '2'):
4227 case VA_FOURCC('Y', 'U', 'Y', '2'):
4228 case VA_FOURCC('B', 'G', 'R', 'A'):
4229 case VA_FOURCC('B', 'G', 'R', 'X'):
4230 case VA_FOURCC('R', 'G', 'B', 'X'):
4231 case VA_FOURCC('R', 'G', 'B', 'A'):
4234 attrib_list[i].value.value.i = 0;
4235 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4240 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4242 } else if (IS_GEN6(i965->intel.device_id)) {
4243 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4244 obj_config->entrypoint == VAEntrypointVideoProc) {
4245 switch (attrib_list[i].value.value.i) {
4246 case VA_FOURCC('N', 'V', '1', '2'):
4247 case VA_FOURCC('I', '4', '2', '0'):
4248 case VA_FOURCC('Y', 'V', '1', '2'):
4249 case VA_FOURCC('Y', 'U', 'Y', '2'):
4250 case VA_FOURCC('B', 'G', 'R', 'A'):
4251 case VA_FOURCC('B', 'G', 'R', 'X'):
4252 case VA_FOURCC('R', 'G', 'B', 'X'):
4253 case VA_FOURCC('R', 'G', 'B', 'A'):
4256 attrib_list[i].value.value.i = 0;
4257 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4261 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4262 attrib_list[i].value.value.i = 0;
4263 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4266 } else if (IS_GEN7(i965->intel.device_id)) {
4267 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4268 obj_config->entrypoint == VAEntrypointVideoProc) {
4269 switch (attrib_list[i].value.value.i) {
4270 case VA_FOURCC('N', 'V', '1', '2'):
4271 case VA_FOURCC('I', '4', '2', '0'):
4272 case VA_FOURCC('Y', 'V', '1', '2'):
4275 attrib_list[i].value.value.i = 0;
4276 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4280 if (obj_config->profile == VAProfileJPEGBaseline) {
4281 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4282 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4284 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4285 attrib_list[i].value.value.i = 0;
4286 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4294 case VASurfaceAttribMinWidth:
4295 /* FIXME: add support for it later */
4296 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4298 case VASurfaceAttribMaxWidth:
4299 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4301 case VASurfaceAttribMinHeight:
4302 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4304 case VASurfaceAttribMaxHeight:
4305 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4308 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4317 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4319 VASurfaceAttrib *attrib_list,
4320 unsigned int *num_attribs)
4322 VAStatus vaStatus = VA_STATUS_SUCCESS;
4323 struct i965_driver_data *i965 = i965_driver_data(ctx);
4324 struct object_config *obj_config;
4326 VASurfaceAttrib *attribs = NULL;
4328 if (config == VA_INVALID_ID)
4329 return VA_STATUS_ERROR_INVALID_CONFIG;
4331 obj_config = CONFIG(config);
4333 if (obj_config == NULL)
4334 return VA_STATUS_ERROR_INVALID_CONFIG;
4336 if (!attrib_list && !num_attribs)
4337 return VA_STATUS_ERROR_INVALID_PARAMETER;
4339 if (attrib_list == NULL) {
4340 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4341 return VA_STATUS_SUCCESS;
4344 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4346 if (attribs == NULL)
4347 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4349 if (IS_G4X(i965->intel.device_id)) {
4350 if (obj_config->profile == VAProfileMPEG2Simple ||
4351 obj_config->profile == VAProfileMPEG2Main) {
4352 attribs[i].type = VASurfaceAttribPixelFormat;
4353 attribs[i].value.type = VAGenericValueTypeInteger;
4354 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4355 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4358 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4359 switch (obj_config->profile) {
4360 case VAProfileMPEG2Simple:
4361 case VAProfileMPEG2Main:
4362 attribs[i].type = VASurfaceAttribPixelFormat;
4363 attribs[i].value.type = VAGenericValueTypeInteger;
4364 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4365 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4370 case VAProfileH264Baseline:
4371 case VAProfileH264Main:
4372 case VAProfileH264High:
4373 attribs[i].type = VASurfaceAttribPixelFormat;
4374 attribs[i].value.type = VAGenericValueTypeInteger;
4375 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4376 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4380 attribs[i].type = VASurfaceAttribPixelFormat;
4381 attribs[i].value.type = VAGenericValueTypeInteger;
4382 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4383 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4386 attribs[i].type = VASurfaceAttribPixelFormat;
4387 attribs[i].value.type = VAGenericValueTypeInteger;
4388 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4389 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4397 } else if (IS_GEN6(i965->intel.device_id)) {
4398 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4399 attribs[i].type = VASurfaceAttribPixelFormat;
4400 attribs[i].value.type = VAGenericValueTypeInteger;
4401 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4402 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4404 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4405 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4406 attribs[i].type = VASurfaceAttribPixelFormat;
4407 attribs[i].value.type = VAGenericValueTypeInteger;
4408 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4409 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4412 attribs[i].type = VASurfaceAttribPixelFormat;
4413 attribs[i].value.type = VAGenericValueTypeInteger;
4414 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4415 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4418 attribs[i].type = VASurfaceAttribPixelFormat;
4419 attribs[i].value.type = VAGenericValueTypeInteger;
4420 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4421 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4424 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4425 attribs[i].type = VASurfaceAttribPixelFormat;
4426 attribs[i].value.type = VAGenericValueTypeInteger;
4427 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4428 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4431 attribs[i].type = VASurfaceAttribPixelFormat;
4432 attribs[i].value.type = VAGenericValueTypeInteger;
4433 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4434 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4437 attribs[i].type = VASurfaceAttribPixelFormat;
4438 attribs[i].value.type = VAGenericValueTypeInteger;
4439 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4440 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4444 } else if (IS_GEN7(i965->intel.device_id)) {
4445 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4446 if (obj_config->profile == VAProfileJPEGBaseline) {
4447 attribs[i].type = VASurfaceAttribPixelFormat;
4448 attribs[i].value.type = VAGenericValueTypeInteger;
4449 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4450 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4453 attribs[i].type = VASurfaceAttribPixelFormat;
4454 attribs[i].value.type = VAGenericValueTypeInteger;
4455 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4456 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '1');
4459 attribs[i].type = VASurfaceAttribPixelFormat;
4460 attribs[i].value.type = VAGenericValueTypeInteger;
4461 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4462 attribs[i].value.value.i = VA_FOURCC('Y', '8', '0', '0');
4465 attribs[i].type = VASurfaceAttribPixelFormat;
4466 attribs[i].value.type = VAGenericValueTypeInteger;
4467 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4468 attribs[i].value.value.i = VA_FOURCC('4', '1', '1', 'P');
4471 attribs[i].type = VASurfaceAttribPixelFormat;
4472 attribs[i].value.type = VAGenericValueTypeInteger;
4473 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4474 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'H');
4477 attribs[i].type = VASurfaceAttribPixelFormat;
4478 attribs[i].value.type = VAGenericValueTypeInteger;
4479 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4480 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'V');
4483 attribs[i].type = VASurfaceAttribPixelFormat;
4484 attribs[i].value.type = VAGenericValueTypeInteger;
4485 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4486 attribs[i].value.value.i = VA_FOURCC('4', '4', '4', 'P');
4489 attribs[i].type = VASurfaceAttribPixelFormat;
4490 attribs[i].value.type = VAGenericValueTypeInteger;
4491 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4492 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4495 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4496 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4497 attribs[i].type = VASurfaceAttribPixelFormat;
4498 attribs[i].value.type = VAGenericValueTypeInteger;
4499 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4500 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4503 attribs[i].type = VASurfaceAttribPixelFormat;
4504 attribs[i].value.type = VAGenericValueTypeInteger;
4505 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4506 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4509 attribs[i].type = VASurfaceAttribPixelFormat;
4510 attribs[i].value.type = VAGenericValueTypeInteger;
4511 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4512 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4515 attribs[i].type = VASurfaceAttribPixelFormat;
4516 attribs[i].value.type = VAGenericValueTypeInteger;
4517 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4518 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4521 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4522 attribs[i].type = VASurfaceAttribPixelFormat;
4523 attribs[i].value.type = VAGenericValueTypeInteger;
4524 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4525 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4528 attribs[i].type = VASurfaceAttribPixelFormat;
4529 attribs[i].value.type = VAGenericValueTypeInteger;
4530 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4531 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4534 attribs[i].type = VASurfaceAttribPixelFormat;
4535 attribs[i].value.type = VAGenericValueTypeInteger;
4536 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4537 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4543 attribs[i].type = VASurfaceAttribMemoryType;
4544 attribs[i].value.type = VAGenericValueTypeInteger;
4545 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4546 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4547 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4548 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4551 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4552 attribs[i].value.type = VAGenericValueTypePointer;
4553 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4554 attribs[i].value.value.p = NULL; /* ignore */
4557 if (i > *num_attribs) {
4560 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4564 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4571 i965_os_has_ring_support(VADriverContextP ctx,
4574 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4578 return i965->intel.has_bsd;
4581 return i965->intel.has_blt;
4583 case I965_RING_VEBOX:
4584 return i965->intel.has_vebox;
4586 case I965_RING_NULL:
4587 return 1; /* Always support */
4590 /* should never get here */
4599 * Query video processing pipeline
4601 VAStatus i965_QueryVideoProcFilters(
4602 VADriverContextP ctx,
4603 VAContextID context,
4604 VAProcFilterType *filters,
4605 unsigned int *num_filters
4608 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4609 unsigned int i = 0, num = 0;
4611 if (!num_filters || !filters)
4612 return VA_STATUS_ERROR_INVALID_PARAMETER;
4614 for (i = 0; i < i965->codec_info->num_filters; i++) {
4615 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4616 if (num == *num_filters) {
4617 *num_filters = i965->codec_info->num_filters;
4619 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4622 filters[num++] = i965->codec_info->filters[i].type;
4628 return VA_STATUS_SUCCESS;
4631 VAStatus i965_QueryVideoProcFilterCaps(
4632 VADriverContextP ctx,
4633 VAContextID context,
4634 VAProcFilterType type,
4636 unsigned int *num_filter_caps
4640 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4642 if (!filter_caps || !num_filter_caps)
4643 return VA_STATUS_ERROR_INVALID_PARAMETER;
4645 for (i = 0; i < i965->codec_info->num_filters; i++) {
4646 if (type == i965->codec_info->filters[i].type &&
4647 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4651 if (i == i965->codec_info->num_filters)
4652 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4657 case VAProcFilterNoiseReduction:
4658 case VAProcFilterSharpening:
4660 VAProcFilterCap *cap = filter_caps;
4662 if (*num_filter_caps < 1) {
4663 *num_filter_caps = 1;
4664 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4667 cap->range.min_value = 0.0;
4668 cap->range.max_value = 1.0;
4669 cap->range.default_value = 0.5;
4670 cap->range.step = 0.03125; /* 1.0 / 32 */
4676 case VAProcFilterDeinterlacing:
4678 VAProcFilterCapDeinterlacing *cap = filter_caps;
4680 if (*num_filter_caps < VAProcDeinterlacingCount) {
4681 *num_filter_caps = VAProcDeinterlacingCount;
4682 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4685 cap->type = VAProcDeinterlacingBob;
4690 if (i965->codec_info->has_di_motion_adptive) {
4691 cap->type = VAProcDeinterlacingMotionAdaptive;
4696 if (i965->codec_info->has_di_motion_compensated) {
4697 cap->type = VAProcDeinterlacingMotionCompensated;
4705 case VAProcFilterColorBalance:
4707 VAProcFilterCapColorBalance *cap = filter_caps;
4709 if (*num_filter_caps < VAProcColorBalanceCount) {
4710 *num_filter_caps = VAProcColorBalanceCount;
4711 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4714 cap->type = VAProcColorBalanceHue;
4715 cap->range.min_value = -180.0;
4716 cap->range.max_value = 180.0;
4717 cap->range.default_value = 0.0;
4718 cap->range.step = 1.0;
4722 cap->type = VAProcColorBalanceSaturation;
4723 cap->range.min_value = 0.0;
4724 cap->range.max_value = 10.0;
4725 cap->range.default_value = 1.0;
4726 cap->range.step = 0.1;
4730 cap->type = VAProcColorBalanceBrightness;
4731 cap->range.min_value = -100.0;
4732 cap->range.max_value = 100.0;
4733 cap->range.default_value = 0.0;
4734 cap->range.step = 1.0;
4738 cap->type = VAProcColorBalanceContrast;
4739 cap->range.min_value = 0.0;
4740 cap->range.max_value = 10.0;
4741 cap->range.default_value = 1.0;
4742 cap->range.step = 0.1;
4754 *num_filter_caps = i;
4756 return VA_STATUS_SUCCESS;
4759 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
4760 VAProcColorStandardBT601,
4763 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
4764 VAProcColorStandardBT601,
4767 VAStatus i965_QueryVideoProcPipelineCaps(
4768 VADriverContextP ctx,
4769 VAContextID context,
4770 VABufferID *filters,
4771 unsigned int num_filters,
4772 VAProcPipelineCaps *pipeline_cap /* out */
4775 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4778 pipeline_cap->pipeline_flags = 0;
4779 pipeline_cap->filter_flags = 0;
4780 pipeline_cap->num_forward_references = 0;
4781 pipeline_cap->num_backward_references = 0;
4782 pipeline_cap->num_input_color_standards = 1;
4783 pipeline_cap->input_color_standards = vpp_input_color_standards;
4784 pipeline_cap->num_output_color_standards = 1;
4785 pipeline_cap->output_color_standards = vpp_output_color_standards;
4787 for (i = 0; i < num_filters; i++) {
4788 struct object_buffer *obj_buffer = BUFFER(filters[i]);
4791 !obj_buffer->buffer_store ||
4792 !obj_buffer->buffer_store->buffer)
4793 return VA_STATUS_ERROR_INVALID_BUFFER;
4795 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4797 if (base->type == VAProcFilterNoiseReduction) {
4798 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
4800 } else if (base->type == VAProcFilterDeinterlacing) {
4801 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
4803 assert(deint->algorithm == VAProcDeinterlacingBob ||
4804 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4805 deint->algorithm == VAProcDeinterlacingMotionCompensated);
4807 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
4808 deint->algorithm == VAProcDeinterlacingMotionCompensated);
4809 pipeline_cap->num_forward_references++;
4813 return VA_STATUS_SUCCESS;
4817 i965_driver_data_init(VADriverContextP ctx)
4819 struct i965_driver_data *i965 = i965_driver_data(ctx);
4821 if (IS_HASWELL(i965->intel.device_id))
4822 i965->codec_info = &gen75_hw_codec_info;
4823 else if (IS_G4X(i965->intel.device_id))
4824 i965->codec_info = &g4x_hw_codec_info;
4825 else if (IS_IRONLAKE(i965->intel.device_id))
4826 i965->codec_info = &ironlake_hw_codec_info;
4827 else if (IS_GEN6(i965->intel.device_id))
4828 i965->codec_info = &gen6_hw_codec_info;
4829 else if (IS_GEN7(i965->intel.device_id))
4830 i965->codec_info = &gen7_hw_codec_info;
4834 if (object_heap_init(&i965->config_heap,
4835 sizeof(struct object_config),
4837 goto err_config_heap;
4838 if (object_heap_init(&i965->context_heap,
4839 sizeof(struct object_context),
4841 goto err_context_heap;
4843 if (object_heap_init(&i965->surface_heap,
4844 sizeof(struct object_surface),
4846 goto err_surface_heap;
4847 if (object_heap_init(&i965->buffer_heap,
4848 sizeof(struct object_buffer),
4850 goto err_buffer_heap;
4851 if (object_heap_init(&i965->image_heap,
4852 sizeof(struct object_image),
4854 goto err_image_heap;
4855 if (object_heap_init(&i965->subpic_heap,
4856 sizeof(struct object_subpic),
4858 goto err_subpic_heap;
4860 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
4861 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
4862 _i965InitMutex(&i965->render_mutex);
4863 _i965InitMutex(&i965->pp_mutex);
4868 object_heap_destroy(&i965->image_heap);
4870 object_heap_destroy(&i965->buffer_heap);
4872 object_heap_destroy(&i965->surface_heap);
4874 object_heap_destroy(&i965->context_heap);
4876 object_heap_destroy(&i965->config_heap);
4883 i965_driver_data_terminate(VADriverContextP ctx)
4885 struct i965_driver_data *i965 = i965_driver_data(ctx);
4887 _i965DestroyMutex(&i965->pp_mutex);
4888 _i965DestroyMutex(&i965->render_mutex);
4891 intel_batchbuffer_free(i965->batch);
4894 intel_batchbuffer_free(i965->pp_batch);
4896 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
4897 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
4898 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
4899 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
4900 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
4901 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
4905 bool (*init)(VADriverContextP ctx);
4906 void (*terminate)(VADriverContextP ctx);
4908 } i965_sub_ops[] = {
4911 intel_driver_terminate,
4916 i965_driver_data_init,
4917 i965_driver_data_terminate,
4922 i965_display_attributes_init,
4923 i965_display_attributes_terminate,
4928 i965_post_processing_init,
4929 i965_post_processing_terminate,
4935 i965_render_terminate,
4939 #ifdef HAVE_VA_WAYLAND
4941 i965_output_wayland_init,
4942 i965_output_wayland_terminate,
4949 i965_output_dri_init,
4950 i965_output_dri_terminate,
4957 i965_Init(VADriverContextP ctx)
4959 struct i965_driver_data *i965 = i965_driver_data(ctx);
4962 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
4963 if ((i965_sub_ops[i].display_type == 0 ||
4964 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
4965 !i965_sub_ops[i].init(ctx))
4969 if (i == ARRAY_ELEMS(i965_sub_ops)) {
4970 sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
4971 INTEL_STR_DRIVER_VENDOR,
4972 INTEL_STR_DRIVER_NAME,
4973 INTEL_DRIVER_MAJOR_VERSION,
4974 INTEL_DRIVER_MINOR_VERSION,
4975 INTEL_DRIVER_MICRO_VERSION);
4977 if (INTEL_DRIVER_PRE_VERSION > 0) {
4978 const int len = strlen(i965->va_vendor);
4979 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
4982 i965->current_context_id = VA_INVALID_ID;
4984 return VA_STATUS_SUCCESS;
4988 for (; i >= 0; i--) {
4989 if (i965_sub_ops[i].display_type == 0 ||
4990 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
4991 i965_sub_ops[i].terminate(ctx);
4995 return VA_STATUS_ERROR_UNKNOWN;
5000 i965_Terminate(VADriverContextP ctx)
5002 struct i965_driver_data *i965 = i965_driver_data(ctx);
5006 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5007 if (i965_sub_ops[i - 1].display_type == 0 ||
5008 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5009 i965_sub_ops[i - 1].terminate(ctx);
5013 ctx->pDriverData = NULL;
5016 return VA_STATUS_SUCCESS;
5020 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5023 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5025 struct VADriverVTable * const vtable = ctx->vtable;
5026 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5028 struct i965_driver_data *i965;
5029 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5031 ctx->version_major = VA_MAJOR_VERSION;
5032 ctx->version_minor = VA_MINOR_VERSION;
5033 ctx->max_profiles = I965_MAX_PROFILES;
5034 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5035 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5036 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5037 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5038 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5040 vtable->vaTerminate = i965_Terminate;
5041 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5042 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5043 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5044 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5045 vtable->vaCreateConfig = i965_CreateConfig;
5046 vtable->vaDestroyConfig = i965_DestroyConfig;
5047 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5048 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5049 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5050 vtable->vaCreateContext = i965_CreateContext;
5051 vtable->vaDestroyContext = i965_DestroyContext;
5052 vtable->vaCreateBuffer = i965_CreateBuffer;
5053 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5054 vtable->vaMapBuffer = i965_MapBuffer;
5055 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5056 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5057 vtable->vaBeginPicture = i965_BeginPicture;
5058 vtable->vaRenderPicture = i965_RenderPicture;
5059 vtable->vaEndPicture = i965_EndPicture;
5060 vtable->vaSyncSurface = i965_SyncSurface;
5061 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5062 vtable->vaPutSurface = i965_PutSurface;
5063 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5064 vtable->vaCreateImage = i965_CreateImage;
5065 vtable->vaDeriveImage = i965_DeriveImage;
5066 vtable->vaDestroyImage = i965_DestroyImage;
5067 vtable->vaSetImagePalette = i965_SetImagePalette;
5068 vtable->vaGetImage = i965_GetImage;
5069 vtable->vaPutImage = i965_PutImage;
5070 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5071 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5072 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5073 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5074 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5075 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5076 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5077 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5078 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5079 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5080 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5081 vtable->vaBufferInfo = i965_BufferInfo;
5082 vtable->vaLockSurface = i965_LockSurface;
5083 vtable->vaUnlockSurface = i965_UnlockSurface;
5084 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5085 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5086 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5088 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5089 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5090 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5092 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5095 ctx->pDriverData = NULL;
5097 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5100 ctx->pDriverData = (void *)i965;
5101 ret = i965_Init(ctx);
5103 if (ret == VA_STATUS_SUCCESS) {
5104 ctx->str_vendor = i965->va_vendor;
5107 ctx->pDriverData = NULL;