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>
36 #include <va/va_dricommon.h>
38 #include "intel_driver.h"
39 #include "intel_memman.h"
40 #include "intel_batchbuffer.h"
41 #include "i965_defines.h"
42 #include "i965_drv_video.h"
44 #define CONFIG_ID_OFFSET 0x01000000
45 #define CONTEXT_ID_OFFSET 0x02000000
46 #define SURFACE_ID_OFFSET 0x04000000
47 #define BUFFER_ID_OFFSET 0x08000000
48 #define IMAGE_ID_OFFSET 0x0a000000
49 #define SUBPIC_ID_OFFSET 0x10000000
51 #define HAS_MPEG2(ctx) (IS_G4X((ctx)->intel.device_id) || \
52 IS_IRONLAKE((ctx)->intel.device_id) || \
53 ((IS_GEN6((ctx)->intel.device_id) || \
54 IS_GEN7((ctx)->intel.device_id)) && \
55 (ctx)->intel.has_bsd))
57 #define HAS_H264(ctx) ((IS_GEN7((ctx)->intel.device_id) || \
58 IS_GEN6((ctx)->intel.device_id) || \
59 IS_IRONLAKE((ctx)->intel.device_id)) && \
62 #define HAS_VC1(ctx) ((IS_GEN7((ctx)->intel.device_id) || \
63 IS_GEN6((ctx)->intel.device_id)) && \
66 #define HAS_TILED_SURFACE(ctx) ((IS_GEN7((ctx)->intel.device_id) || \
67 IS_GEN6((ctx)->intel.device_id)))
69 #define HAS_ENCODER(ctx) ((IS_GEN7((ctx)->intel.device_id) || \
70 IS_GEN6((ctx)->intel.device_id)) && \
73 #define HAS_VPP(ctx) (IS_IRONLAKE((ctx)->intel.device_id) || \
74 IS_GEN6((ctx)->intel.device_id) || \
75 IS_GEN7((ctx)->intel.device_id))
77 #define HAS_JPEG(ctx) (IS_GEN7((ctx)->intel.device_id) && \
80 #define HAS_ACCELERATED_GETIMAGE(ctx) (IS_GEN6((ctx)->intel.device_id) || \
81 IS_GEN7((ctx)->intel.device_id))
83 #define HAS_ACCELERATED_PUTIMAGE(ctx) HAS_VPP(ctx)
86 I965_SURFACETYPE_RGBA = 1,
88 I965_SURFACETYPE_INDEXED
91 /* List of supported image formats */
94 VAImageFormat va_format;
95 } i965_image_format_map_t;
97 static const i965_image_format_map_t
98 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
99 { I965_SURFACETYPE_YUV,
100 { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
101 { I965_SURFACETYPE_YUV,
102 { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
103 { I965_SURFACETYPE_YUV,
104 { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
107 /* List of supported subpicture formats */
111 VAImageFormat va_format;
112 unsigned int va_flags;
113 } i965_subpic_format_map_t;
115 static const i965_subpic_format_map_t
116 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
117 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
118 { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
119 VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD },
120 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
121 { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
122 VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD },
123 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
124 { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
125 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
126 VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD },
127 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
128 { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
129 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
130 VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD },
133 static const i965_subpic_format_map_t *
134 get_subpic_format(const VAImageFormat *va_format)
137 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
138 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
139 if (m->va_format.fourcc == va_format->fourcc &&
140 (m->type == I965_SURFACETYPE_RGBA ?
141 (m->va_format.byte_order == va_format->byte_order &&
142 m->va_format.red_mask == va_format->red_mask &&
143 m->va_format.green_mask == va_format->green_mask &&
144 m->va_format.blue_mask == va_format->blue_mask &&
145 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
151 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
152 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
153 static struct hw_codec_info g4x_hw_codec_info = {
154 .dec_hw_context_init = g4x_dec_hw_context_init,
155 .enc_hw_context_init = NULL,
156 .proc_hw_context_init = NULL,
159 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
160 static struct hw_codec_info ironlake_hw_codec_info = {
161 .dec_hw_context_init = ironlake_dec_hw_context_init,
162 .enc_hw_context_init = NULL,
163 .proc_hw_context_init = i965_proc_context_init,
166 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
167 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
168 static struct hw_codec_info gen6_hw_codec_info = {
169 .dec_hw_context_init = gen6_dec_hw_context_init,
170 .enc_hw_context_init = gen6_enc_hw_context_init,
171 .proc_hw_context_init = i965_proc_context_init,
174 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
175 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
176 static struct hw_codec_info gen7_hw_codec_info = {
177 .dec_hw_context_init = gen7_dec_hw_context_init,
178 .enc_hw_context_init = gen7_enc_hw_context_init,
179 .proc_hw_context_init = i965_proc_context_init,
183 i965_QueryConfigProfiles(VADriverContextP ctx,
184 VAProfile *profile_list, /* out */
185 int *num_profiles) /* out */
187 struct i965_driver_data * const i965 = i965_driver_data(ctx);
190 if (HAS_MPEG2(i965)) {
191 profile_list[i++] = VAProfileMPEG2Simple;
192 profile_list[i++] = VAProfileMPEG2Main;
195 if (HAS_H264(i965)) {
196 profile_list[i++] = VAProfileH264Baseline;
197 profile_list[i++] = VAProfileH264Main;
198 profile_list[i++] = VAProfileH264High;
202 profile_list[i++] = VAProfileVC1Simple;
203 profile_list[i++] = VAProfileVC1Main;
204 profile_list[i++] = VAProfileVC1Advanced;
208 profile_list[i++] = VAProfileNone;
211 if (HAS_JPEG(i965)) {
212 profile_list[i++] = VAProfileJPEGBaseline;
215 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
216 assert(i <= I965_MAX_PROFILES);
219 return VA_STATUS_SUCCESS;
223 i965_QueryConfigEntrypoints(VADriverContextP ctx,
225 VAEntrypoint *entrypoint_list, /* out */
226 int *num_entrypoints) /* out */
228 struct i965_driver_data * const i965 = i965_driver_data(ctx);
232 case VAProfileMPEG2Simple:
233 case VAProfileMPEG2Main:
235 entrypoint_list[n++] = VAEntrypointVLD;
238 case VAProfileH264Baseline:
239 case VAProfileH264Main:
240 case VAProfileH264High:
242 entrypoint_list[n++] = VAEntrypointVLD;
244 if (HAS_ENCODER(i965))
245 entrypoint_list[n++] = VAEntrypointEncSlice;
249 case VAProfileVC1Simple:
250 case VAProfileVC1Main:
251 case VAProfileVC1Advanced:
253 entrypoint_list[n++] = VAEntrypointVLD;
258 entrypoint_list[n++] = VAEntrypointVideoProc;
261 case VAProfileJPEGBaseline:
263 entrypoint_list[n++] = VAEntrypointVLD;
270 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
271 assert(n <= I965_MAX_ENTRYPOINTS);
272 *num_entrypoints = n;
273 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
277 i965_GetConfigAttributes(VADriverContextP ctx,
279 VAEntrypoint entrypoint,
280 VAConfigAttrib *attrib_list, /* in/out */
285 /* Other attributes don't seem to be defined */
286 /* What to do if we don't know the attribute? */
287 for (i = 0; i < num_attribs; i++) {
288 switch (attrib_list[i].type) {
289 case VAConfigAttribRTFormat:
290 attrib_list[i].value = VA_RT_FORMAT_YUV420;
293 case VAConfigAttribRateControl:
294 if (entrypoint == VAEntrypointEncSlice) {
295 attrib_list[i].value = VA_RC_CBR | VA_RC_CQP;
299 case VAConfigAttribEncPackedHeaders:
300 if (entrypoint == VAEntrypointEncSlice) {
301 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE;
307 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
312 return VA_STATUS_SUCCESS;
316 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
318 object_heap_free(heap, obj);
322 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
326 /* Check existing attrbiutes */
327 for (i = 0; i < obj_config->num_attribs; i++) {
328 if (obj_config->attrib_list[i].type == attrib->type) {
329 /* Update existing attribute */
330 obj_config->attrib_list[i].value = attrib->value;
331 return VA_STATUS_SUCCESS;
335 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
336 i = obj_config->num_attribs;
337 obj_config->attrib_list[i].type = attrib->type;
338 obj_config->attrib_list[i].value = attrib->value;
339 obj_config->num_attribs++;
340 return VA_STATUS_SUCCESS;
343 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
347 i965_CreateConfig(VADriverContextP ctx,
349 VAEntrypoint entrypoint,
350 VAConfigAttrib *attrib_list,
352 VAConfigID *config_id) /* out */
354 struct i965_driver_data * const i965 = i965_driver_data(ctx);
355 struct object_config *obj_config;
360 /* Validate profile & entrypoint */
362 case VAProfileMPEG2Simple:
363 case VAProfileMPEG2Main:
364 if (HAS_MPEG2(i965) && VAEntrypointVLD == entrypoint) {
365 vaStatus = VA_STATUS_SUCCESS;
367 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
371 case VAProfileH264Baseline:
372 case VAProfileH264Main:
373 case VAProfileH264High:
374 if ((HAS_H264(i965) && VAEntrypointVLD == entrypoint) ||
375 (HAS_ENCODER(i965) && VAEntrypointEncSlice == entrypoint)) {
376 vaStatus = VA_STATUS_SUCCESS;
378 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
383 case VAProfileVC1Simple:
384 case VAProfileVC1Main:
385 case VAProfileVC1Advanced:
386 if (HAS_VC1(i965) && VAEntrypointVLD == entrypoint) {
387 vaStatus = VA_STATUS_SUCCESS;
389 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
395 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
396 vaStatus = VA_STATUS_SUCCESS;
398 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
403 case VAProfileJPEGBaseline:
404 if (HAS_JPEG(i965) && VAEntrypointVLD == entrypoint) {
405 vaStatus = VA_STATUS_SUCCESS;
407 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
413 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
417 if (VA_STATUS_SUCCESS != vaStatus) {
421 configID = NEW_CONFIG_ID();
422 obj_config = CONFIG(configID);
424 if (NULL == obj_config) {
425 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
429 obj_config->profile = profile;
430 obj_config->entrypoint = entrypoint;
431 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
432 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
433 obj_config->num_attribs = 1;
435 for(i = 0; i < num_attribs; i++) {
436 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
438 if (VA_STATUS_SUCCESS != vaStatus) {
444 if (VA_STATUS_SUCCESS != vaStatus) {
445 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
447 *config_id = configID;
454 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
456 struct i965_driver_data *i965 = i965_driver_data(ctx);
457 struct object_config *obj_config = CONFIG(config_id);
460 if (NULL == obj_config) {
461 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
465 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
466 return VA_STATUS_SUCCESS;
469 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
470 VAConfigID config_id,
471 VAProfile *profile, /* out */
472 VAEntrypoint *entrypoint, /* out */
473 VAConfigAttrib *attrib_list, /* out */
474 int *num_attribs) /* out */
476 struct i965_driver_data *i965 = i965_driver_data(ctx);
477 struct object_config *obj_config = CONFIG(config_id);
478 VAStatus vaStatus = VA_STATUS_SUCCESS;
482 *profile = obj_config->profile;
483 *entrypoint = obj_config->entrypoint;
484 *num_attribs = obj_config->num_attribs;
486 for(i = 0; i < obj_config->num_attribs; i++) {
487 attrib_list[i] = obj_config->attrib_list[i];
494 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
496 struct object_surface *obj_surface = (struct object_surface *)obj;
498 dri_bo_unreference(obj_surface->bo);
499 obj_surface->bo = NULL;
501 if (obj_surface->free_private_data != NULL) {
502 obj_surface->free_private_data(&obj_surface->private_data);
503 obj_surface->private_data = NULL;
506 object_heap_free(heap, obj);
510 i965_CreateSurfaces2(
511 VADriverContextP ctx,
515 VASurfaceID *surfaces,
516 unsigned int num_surfaces,
517 VASurfaceAttrib *attrib_list,
518 unsigned int num_attribs
521 struct i965_driver_data *i965 = i965_driver_data(ctx);
523 VAStatus vaStatus = VA_STATUS_SUCCESS;
524 int expected_fourcc = 0;
526 for (i = 0; i < num_attribs && attrib_list; i++) {
527 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
528 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
529 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
530 expected_fourcc = attrib_list[i].value.value.i;
535 /* We only support one format */
536 if (VA_RT_FORMAT_YUV420 != format) {
537 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
540 for (i = 0; i < num_surfaces; i++) {
541 int surfaceID = NEW_SURFACE_ID();
542 struct object_surface *obj_surface = SURFACE(surfaceID);
544 if (NULL == obj_surface) {
545 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
549 surfaces[i] = surfaceID;
550 obj_surface->status = VASurfaceReady;
551 obj_surface->subpic = VA_INVALID_ID;
552 obj_surface->orig_width = width;
553 obj_surface->orig_height = height;
555 obj_surface->width = ALIGN(width, 16);
556 obj_surface->height = ALIGN(height, 16);
557 obj_surface->flags = SURFACE_REFERENCED;
558 obj_surface->fourcc = 0;
559 obj_surface->bo = NULL;
560 obj_surface->locked_image_id = VA_INVALID_ID;
561 obj_surface->private_data = NULL;
562 obj_surface->free_private_data = NULL;
563 obj_surface->subsampling = SUBSAMPLE_YUV420;
565 if (expected_fourcc) {
566 int tiling = HAS_TILED_SURFACE(i965);
568 if (expected_fourcc != VA_FOURCC('N', 'V', '1', '2'))
571 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, SUBSAMPLE_YUV420);
576 if (VA_STATUS_SUCCESS != vaStatus) {
577 /* surfaces[i-1] was the last successful allocation */
579 struct object_surface *obj_surface = SURFACE(surfaces[i]);
581 surfaces[i] = VA_INVALID_SURFACE;
583 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
591 i965_CreateSurfaces(VADriverContextP ctx,
596 VASurfaceID *surfaces) /* out */
598 return i965_CreateSurfaces2(ctx,
609 i965_DestroySurfaces(VADriverContextP ctx,
610 VASurfaceID *surface_list,
613 struct i965_driver_data *i965 = i965_driver_data(ctx);
616 for (i = num_surfaces; i--; ) {
617 struct object_surface *obj_surface = SURFACE(surface_list[i]);
620 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
623 return VA_STATUS_SUCCESS;
627 i965_QueryImageFormats(VADriverContextP ctx,
628 VAImageFormat *format_list, /* out */
629 int *num_formats) /* out */
633 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
634 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
636 format_list[n] = m->va_format;
642 return VA_STATUS_SUCCESS;
646 * Guess the format when the usage of a VA surface is unknown
647 * 1. Without a valid context: YV12
648 * 2. The current context is valid:
649 * a) always NV12 on GEN6 and later
650 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
653 i965_guess_surface_format(VADriverContextP ctx,
655 unsigned int *fourcc,
656 unsigned int *is_tiled)
658 struct i965_driver_data *i965 = i965_driver_data(ctx);
659 struct object_context *obj_context = NULL;
660 struct object_config *obj_config = NULL;
662 *fourcc = VA_FOURCC('Y', 'V', '1', '2');
665 if (i965->current_context_id == VA_INVALID_ID)
668 obj_context = CONTEXT(i965->current_context_id);
670 if (!obj_context || obj_context->config_id == VA_INVALID_ID)
673 obj_config = CONFIG(obj_context->config_id);
678 if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) {
679 *fourcc = VA_FOURCC('N', 'V', '1', '2');
684 switch (obj_config->profile) {
685 case VAProfileMPEG2Simple:
686 case VAProfileMPEG2Main:
687 *fourcc = VA_FOURCC('I', '4', '2', '0');
692 *fourcc = VA_FOURCC('N', 'V', '1', '2');
699 i965_QuerySubpictureFormats(VADriverContextP ctx,
700 VAImageFormat *format_list, /* out */
701 unsigned int *flags, /* out */
702 unsigned int *num_formats) /* out */
706 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
707 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
709 format_list[n] = m->va_format;
711 flags[n] = m->va_flags;
717 return VA_STATUS_SUCCESS;
721 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
723 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
725 object_heap_free(heap, obj);
729 i965_CreateSubpicture(VADriverContextP ctx,
731 VASubpictureID *subpicture) /* out */
733 struct i965_driver_data *i965 = i965_driver_data(ctx);
734 VASubpictureID subpicID = NEW_SUBPIC_ID()
735 struct object_subpic *obj_subpic = SUBPIC(subpicID);
738 return VA_STATUS_ERROR_ALLOCATION_FAILED;
740 struct object_image *obj_image = IMAGE(image);
742 return VA_STATUS_ERROR_INVALID_IMAGE;
744 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
746 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
748 *subpicture = subpicID;
749 obj_subpic->image = image;
750 obj_subpic->format = m->format;
751 obj_subpic->width = obj_image->image.width;
752 obj_subpic->height = obj_image->image.height;
753 obj_subpic->pitch = obj_image->image.pitches[0];
754 obj_subpic->bo = obj_image->bo;
755 return VA_STATUS_SUCCESS;
759 i965_DestroySubpicture(VADriverContextP ctx,
760 VASubpictureID subpicture)
762 struct i965_driver_data *i965 = i965_driver_data(ctx);
763 struct object_subpic *obj_subpic = SUBPIC(subpicture);
764 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
765 return VA_STATUS_SUCCESS;
769 i965_SetSubpictureImage(VADriverContextP ctx,
770 VASubpictureID subpicture,
774 return VA_STATUS_ERROR_UNIMPLEMENTED;
778 i965_SetSubpictureChromakey(VADriverContextP ctx,
779 VASubpictureID subpicture,
780 unsigned int chromakey_min,
781 unsigned int chromakey_max,
782 unsigned int chromakey_mask)
785 return VA_STATUS_ERROR_UNIMPLEMENTED;
789 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
790 VASubpictureID subpicture,
794 return VA_STATUS_ERROR_UNIMPLEMENTED;
798 i965_AssociateSubpicture(VADriverContextP ctx,
799 VASubpictureID subpicture,
800 VASurfaceID *target_surfaces,
802 short src_x, /* upper left offset in subpicture */
804 unsigned short src_width,
805 unsigned short src_height,
806 short dest_x, /* upper left offset in surface */
808 unsigned short dest_width,
809 unsigned short dest_height,
811 * whether to enable chroma-keying or global-alpha
812 * see VA_SUBPICTURE_XXX values
816 struct i965_driver_data *i965 = i965_driver_data(ctx);
817 struct object_subpic *obj_subpic = SUBPIC(subpicture);
820 obj_subpic->src_rect.x = src_x;
821 obj_subpic->src_rect.y = src_y;
822 obj_subpic->src_rect.width = src_width;
823 obj_subpic->src_rect.height = src_height;
824 obj_subpic->dst_rect.x = dest_x;
825 obj_subpic->dst_rect.y = dest_y;
826 obj_subpic->dst_rect.width = dest_width;
827 obj_subpic->dst_rect.height = dest_height;
828 obj_subpic->flags = flags;
830 for (i = 0; i < num_surfaces; i++) {
831 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
833 return VA_STATUS_ERROR_INVALID_SURFACE;
834 obj_surface->subpic = subpicture;
836 return VA_STATUS_SUCCESS;
841 i965_DeassociateSubpicture(VADriverContextP ctx,
842 VASubpictureID subpicture,
843 VASurfaceID *target_surfaces,
846 struct i965_driver_data *i965 = i965_driver_data(ctx);
849 for (i = 0; i < num_surfaces; i++) {
850 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
852 return VA_STATUS_ERROR_INVALID_SURFACE;
853 if (obj_surface->subpic == subpicture)
854 obj_surface->subpic = VA_INVALID_ID;
856 return VA_STATUS_SUCCESS;
860 i965_reference_buffer_store(struct buffer_store **ptr,
861 struct buffer_store *buffer_store)
863 assert(*ptr == NULL);
866 buffer_store->ref_count++;
872 i965_release_buffer_store(struct buffer_store **ptr)
874 struct buffer_store *buffer_store = *ptr;
876 if (buffer_store == NULL)
879 assert(buffer_store->bo || buffer_store->buffer);
880 assert(!(buffer_store->bo && buffer_store->buffer));
881 buffer_store->ref_count--;
883 if (buffer_store->ref_count == 0) {
884 dri_bo_unreference(buffer_store->bo);
885 free(buffer_store->buffer);
886 buffer_store->bo = NULL;
887 buffer_store->buffer = NULL;
895 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
897 struct object_context *obj_context = (struct object_context *)obj;
900 if (obj_context->hw_context) {
901 obj_context->hw_context->destroy(obj_context->hw_context);
902 obj_context->hw_context = NULL;
905 if (obj_context->codec_type == CODEC_PROC) {
906 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
908 } else if (obj_context->codec_type == CODEC_ENC) {
909 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
910 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
911 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
913 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
914 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
916 free(obj_context->codec_state.encode.slice_params);
918 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
919 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
920 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
922 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
923 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
925 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
926 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
928 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
929 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
931 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
932 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
934 free(obj_context->codec_state.encode.slice_params_ext);
936 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
937 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
939 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
940 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
941 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
943 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
944 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
946 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
947 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
949 free(obj_context->codec_state.decode.slice_params);
950 free(obj_context->codec_state.decode.slice_datas);
953 free(obj_context->render_targets);
954 object_heap_free(heap, obj);
958 i965_CreateContext(VADriverContextP ctx,
959 VAConfigID config_id,
963 VASurfaceID *render_targets,
964 int num_render_targets,
965 VAContextID *context) /* out */
967 struct i965_driver_data *i965 = i965_driver_data(ctx);
968 struct i965_render_state *render_state = &i965->render_state;
969 struct object_config *obj_config = CONFIG(config_id);
970 struct object_context *obj_context = NULL;
971 VAStatus vaStatus = VA_STATUS_SUCCESS;
975 if (NULL == obj_config) {
976 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
981 /* Validate picture dimensions */
982 contextID = NEW_CONTEXT_ID();
983 obj_context = CONTEXT(contextID);
985 if (NULL == obj_context) {
986 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
990 render_state->inited = 1;
992 switch (obj_config->profile) {
993 case VAProfileH264Baseline:
994 case VAProfileH264Main:
995 case VAProfileH264High:
997 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
998 render_state->interleaved_uv = 1;
1001 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id));
1005 *context = contextID;
1006 obj_context->flags = flag;
1007 obj_context->context_id = contextID;
1008 obj_context->config_id = config_id;
1009 obj_context->picture_width = picture_width;
1010 obj_context->picture_height = picture_height;
1011 obj_context->num_render_targets = num_render_targets;
1012 obj_context->render_targets =
1013 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1014 obj_context->hw_context = NULL;
1016 for(i = 0; i < num_render_targets; i++) {
1017 if (NULL == SURFACE(render_targets[i])) {
1018 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1022 obj_context->render_targets[i] = render_targets[i];
1025 if (VA_STATUS_SUCCESS == vaStatus) {
1026 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1027 obj_context->codec_type = CODEC_PROC;
1028 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1029 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1030 assert(i965->codec_info->proc_hw_context_init);
1031 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1032 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1033 obj_context->codec_type = CODEC_ENC;
1034 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1035 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1036 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1037 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1038 sizeof(*obj_context->codec_state.encode.slice_params));
1039 assert(i965->codec_info->enc_hw_context_init);
1040 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1042 obj_context->codec_type = CODEC_DEC;
1043 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1044 obj_context->codec_state.decode.current_render_target = -1;
1045 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1046 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1047 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1048 sizeof(*obj_context->codec_state.decode.slice_params));
1049 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1050 sizeof(*obj_context->codec_state.decode.slice_datas));
1052 assert(i965->codec_info->dec_hw_context_init);
1053 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1057 /* Error recovery */
1058 if (VA_STATUS_SUCCESS != vaStatus) {
1059 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1062 i965->current_context_id = contextID;
1068 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1070 struct i965_driver_data *i965 = i965_driver_data(ctx);
1071 struct object_context *obj_context = CONTEXT(context);
1073 assert(obj_context);
1075 if (i965->current_context_id == context)
1076 i965->current_context_id = VA_INVALID_ID;
1078 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1080 return VA_STATUS_SUCCESS;
1084 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1086 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1088 assert(obj_buffer->buffer_store);
1089 i965_release_buffer_store(&obj_buffer->buffer_store);
1090 object_heap_free(heap, obj);
1094 i965_create_buffer_internal(VADriverContextP ctx,
1095 VAContextID context,
1098 unsigned int num_elements,
1103 struct i965_driver_data *i965 = i965_driver_data(ctx);
1104 struct object_buffer *obj_buffer = NULL;
1105 struct buffer_store *buffer_store = NULL;
1110 case VAPictureParameterBufferType:
1111 case VAIQMatrixBufferType:
1112 case VAQMatrixBufferType:
1113 case VABitPlaneBufferType:
1114 case VASliceGroupMapBufferType:
1115 case VASliceParameterBufferType:
1116 case VASliceDataBufferType:
1117 case VAMacroblockParameterBufferType:
1118 case VAResidualDataBufferType:
1119 case VADeblockingParameterBufferType:
1120 case VAImageBufferType:
1121 case VAEncCodedBufferType:
1122 case VAEncSequenceParameterBufferType:
1123 case VAEncPictureParameterBufferType:
1124 case VAEncSliceParameterBufferType:
1125 case VAEncPackedHeaderParameterBufferType:
1126 case VAEncPackedHeaderDataBufferType:
1127 case VAEncMiscParameterBufferType:
1128 case VAProcPipelineParameterBufferType:
1129 case VAProcFilterParameterBufferType:
1130 #ifdef HAVE_JPEG_DECODING
1131 case VAHuffmanTableBufferType:
1137 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1140 bufferID = NEW_BUFFER_ID();
1141 obj_buffer = BUFFER(bufferID);
1143 if (NULL == obj_buffer) {
1144 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1147 if (type == VAEncCodedBufferType) {
1148 size += ALIGN(sizeof(VACodedBufferSegment), 64);
1149 size += 0x1000; /* for upper bound check */
1152 obj_buffer->max_num_elements = num_elements;
1153 obj_buffer->num_elements = num_elements;
1154 obj_buffer->size_element = size;
1155 obj_buffer->type = type;
1156 obj_buffer->buffer_store = NULL;
1157 buffer_store = calloc(1, sizeof(struct buffer_store));
1158 assert(buffer_store);
1159 buffer_store->ref_count = 1;
1161 if (store_bo != NULL) {
1162 buffer_store->bo = store_bo;
1163 dri_bo_reference(buffer_store->bo);
1166 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1167 } else if (type == VASliceDataBufferType ||
1168 type == VAImageBufferType ||
1169 type == VAEncCodedBufferType) {
1170 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1172 size * num_elements, 64);
1173 assert(buffer_store->bo);
1175 if (type == VAEncCodedBufferType) {
1176 VACodedBufferSegment *coded_buffer_segment;
1177 dri_bo_map(buffer_store->bo, 1);
1178 coded_buffer_segment = (VACodedBufferSegment *)buffer_store->bo->virtual;
1179 coded_buffer_segment->size = size - ALIGN(sizeof(VACodedBufferSegment), 64);
1180 coded_buffer_segment->bit_offset = 0;
1181 coded_buffer_segment->status = 0;
1182 coded_buffer_segment->buf = NULL;
1183 coded_buffer_segment->next = NULL;
1184 dri_bo_unmap(buffer_store->bo);
1186 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1192 if (type == VAEncPackedHeaderDataBufferType) {
1193 msize = ALIGN(size, 4);
1196 buffer_store->buffer = malloc(msize * num_elements);
1197 assert(buffer_store->buffer);
1200 memcpy(buffer_store->buffer, data, size * num_elements);
1203 buffer_store->num_elements = obj_buffer->num_elements;
1204 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1205 i965_release_buffer_store(&buffer_store);
1208 return VA_STATUS_SUCCESS;
1212 i965_CreateBuffer(VADriverContextP ctx,
1213 VAContextID context, /* in */
1214 VABufferType type, /* in */
1215 unsigned int size, /* in */
1216 unsigned int num_elements, /* in */
1217 void *data, /* in */
1218 VABufferID *buf_id) /* out */
1220 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1225 i965_BufferSetNumElements(VADriverContextP ctx,
1226 VABufferID buf_id, /* in */
1227 unsigned int num_elements) /* in */
1229 struct i965_driver_data *i965 = i965_driver_data(ctx);
1230 struct object_buffer *obj_buffer = BUFFER(buf_id);
1231 VAStatus vaStatus = VA_STATUS_SUCCESS;
1235 if ((num_elements < 0) ||
1236 (num_elements > obj_buffer->max_num_elements)) {
1237 vaStatus = VA_STATUS_ERROR_UNKNOWN;
1239 obj_buffer->num_elements = num_elements;
1240 if (obj_buffer->buffer_store != NULL) {
1241 obj_buffer->buffer_store->num_elements = num_elements;
1249 i965_MapBuffer(VADriverContextP ctx,
1250 VABufferID buf_id, /* in */
1251 void **pbuf) /* out */
1253 struct i965_driver_data *i965 = i965_driver_data(ctx);
1254 struct object_buffer *obj_buffer = BUFFER(buf_id);
1255 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1257 assert(obj_buffer && obj_buffer->buffer_store);
1258 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1259 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1261 if (NULL != obj_buffer->buffer_store->bo) {
1262 unsigned int tiling, swizzle;
1264 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1266 if (tiling != I915_TILING_NONE)
1267 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1269 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1271 assert(obj_buffer->buffer_store->bo->virtual);
1272 *pbuf = obj_buffer->buffer_store->bo->virtual;
1274 if (obj_buffer->type == VAEncCodedBufferType) {
1276 unsigned char *buffer = NULL;
1277 VACodedBufferSegment *coded_buffer_segment = (VACodedBufferSegment *)(obj_buffer->buffer_store->bo->virtual);
1279 coded_buffer_segment->buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + ALIGN(sizeof(VACodedBufferSegment), 64);
1281 for (i = 0; i < obj_buffer->size_element - ALIGN(sizeof(VACodedBufferSegment), 64) - 3 - 0x1000; i++) {
1290 if (i == obj_buffer->size_element - ALIGN(sizeof(VACodedBufferSegment), 64) - 3 - 0x1000) {
1291 coded_buffer_segment->status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1294 coded_buffer_segment->size = i;
1297 vaStatus = VA_STATUS_SUCCESS;
1298 } else if (NULL != obj_buffer->buffer_store->buffer) {
1299 *pbuf = obj_buffer->buffer_store->buffer;
1300 vaStatus = VA_STATUS_SUCCESS;
1307 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1309 struct i965_driver_data *i965 = i965_driver_data(ctx);
1310 struct object_buffer *obj_buffer = BUFFER(buf_id);
1311 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1313 assert(obj_buffer && obj_buffer->buffer_store);
1314 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1315 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1317 if (NULL != obj_buffer->buffer_store->bo) {
1318 unsigned int tiling, swizzle;
1320 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1322 if (tiling != I915_TILING_NONE)
1323 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1325 dri_bo_unmap(obj_buffer->buffer_store->bo);
1327 vaStatus = VA_STATUS_SUCCESS;
1328 } else if (NULL != obj_buffer->buffer_store->buffer) {
1330 vaStatus = VA_STATUS_SUCCESS;
1337 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1339 struct i965_driver_data *i965 = i965_driver_data(ctx);
1340 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1343 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1345 return VA_STATUS_SUCCESS;
1349 i965_BeginPicture(VADriverContextP ctx,
1350 VAContextID context,
1351 VASurfaceID render_target)
1353 struct i965_driver_data *i965 = i965_driver_data(ctx);
1354 struct object_context *obj_context = CONTEXT(context);
1355 struct object_surface *obj_surface = SURFACE(render_target);
1356 struct object_config *obj_config;
1361 assert(obj_context);
1362 assert(obj_surface);
1364 config = obj_context->config_id;
1365 obj_config = CONFIG(config);
1368 switch (obj_config->profile) {
1369 case VAProfileMPEG2Simple:
1370 case VAProfileMPEG2Main:
1371 vaStatus = VA_STATUS_SUCCESS;
1374 case VAProfileH264Baseline:
1375 case VAProfileH264Main:
1376 case VAProfileH264High:
1377 vaStatus = VA_STATUS_SUCCESS;
1380 case VAProfileVC1Simple:
1381 case VAProfileVC1Main:
1382 case VAProfileVC1Advanced:
1383 vaStatus = VA_STATUS_SUCCESS;
1386 case VAProfileJPEGBaseline:
1387 vaStatus = VA_STATUS_SUCCESS;
1391 vaStatus = VA_STATUS_SUCCESS;
1396 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1400 if (obj_context->codec_type == CODEC_PROC) {
1401 obj_context->codec_state.proc.current_render_target = render_target;
1402 } else if (obj_context->codec_type == CODEC_ENC) {
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]);
1410 obj_context->codec_state.encode.num_slice_params = 0;
1413 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1414 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1416 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1417 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1419 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1420 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1422 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1423 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1425 obj_context->codec_state.encode.num_slice_params_ext = 0;
1426 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
1427 obj_context->codec_state.encode.last_packed_header_type = 0;
1429 obj_context->codec_state.decode.current_render_target = render_target;
1430 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1431 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1432 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1433 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
1435 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
1436 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1437 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1440 obj_context->codec_state.decode.num_slice_params = 0;
1441 obj_context->codec_state.decode.num_slice_datas = 0;
1447 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
1449 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
1451 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1452 struct object_context *obj_context, \
1453 struct object_buffer *obj_buffer) \
1455 struct category##_state *category = &obj_context->codec_state.category; \
1456 assert(obj_buffer->buffer_store->bo == NULL); \
1457 assert(obj_buffer->buffer_store->buffer); \
1458 i965_release_buffer_store(&category->member); \
1459 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
1460 return VA_STATUS_SUCCESS; \
1463 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
1465 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1466 struct object_context *obj_context, \
1467 struct object_buffer *obj_buffer) \
1469 struct category##_state *category = &obj_context->codec_state.category; \
1470 if (category->num_##member == category->max_##member) { \
1471 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
1472 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
1473 category->max_##member += NUM_SLICES; \
1475 i965_release_buffer_store(&category->member[category->num_##member]); \
1476 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
1477 category->num_##member++; \
1478 return VA_STATUS_SUCCESS; \
1481 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
1483 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
1484 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
1485 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
1486 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
1487 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
1489 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
1490 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
1491 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
1494 i965_decoder_render_picture(VADriverContextP ctx,
1495 VAContextID context,
1496 VABufferID *buffers,
1499 struct i965_driver_data *i965 = i965_driver_data(ctx);
1500 struct object_context *obj_context = CONTEXT(context);
1501 VAStatus vaStatus = VA_STATUS_SUCCESS;
1504 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
1505 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1508 switch (obj_buffer->type) {
1509 case VAPictureParameterBufferType:
1510 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
1513 case VAIQMatrixBufferType:
1514 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
1517 case VABitPlaneBufferType:
1518 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
1521 case VASliceParameterBufferType:
1522 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
1525 case VASliceDataBufferType:
1526 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
1529 #ifdef HAVE_JPEG_DECODING
1530 case VAHuffmanTableBufferType:
1531 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
1536 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1544 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
1546 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
1547 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
1548 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
1549 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
1550 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
1551 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
1552 /* extended buffer */
1553 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
1554 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
1556 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
1557 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
1558 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
1561 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
1562 struct object_context *obj_context,
1563 struct object_buffer *obj_buffer,
1564 VAEncPackedHeaderType type)
1566 struct encode_state *encode = &obj_context->codec_state.encode;
1568 assert(obj_buffer->buffer_store->bo == NULL);
1569 assert(obj_buffer->buffer_store->buffer);
1570 i965_release_buffer_store(&encode->packed_header_param[type]);
1571 i965_reference_buffer_store(&encode->packed_header_param[type], obj_buffer->buffer_store);
1573 return VA_STATUS_SUCCESS;
1577 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
1578 struct object_context *obj_context,
1579 struct object_buffer *obj_buffer,
1580 VAEncPackedHeaderType type)
1582 struct encode_state *encode = &obj_context->codec_state.encode;
1584 assert(obj_buffer->buffer_store->bo == NULL);
1585 assert(obj_buffer->buffer_store->buffer);
1586 i965_release_buffer_store(&encode->packed_header_data[type]);
1587 i965_reference_buffer_store(&encode->packed_header_data[type], obj_buffer->buffer_store);
1589 return VA_STATUS_SUCCESS;
1593 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
1594 struct object_context *obj_context,
1595 struct object_buffer *obj_buffer)
1597 struct encode_state *encode = &obj_context->codec_state.encode;
1598 VAEncMiscParameterBuffer *param = NULL;
1600 assert(obj_buffer->buffer_store->bo == NULL);
1601 assert(obj_buffer->buffer_store->buffer);
1603 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
1604 i965_release_buffer_store(&encode->misc_param[param->type]);
1605 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
1607 return VA_STATUS_SUCCESS;
1611 i965_encoder_render_picture(VADriverContextP ctx,
1612 VAContextID context,
1613 VABufferID *buffers,
1616 struct i965_driver_data *i965 = i965_driver_data(ctx);
1617 struct object_context *obj_context = CONTEXT(context);
1618 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1621 for (i = 0; i < num_buffers; i++) {
1622 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1625 switch (obj_buffer->type) {
1626 case VAQMatrixBufferType:
1627 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
1630 case VAIQMatrixBufferType:
1631 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
1634 case VAEncSequenceParameterBufferType:
1635 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
1638 case VAEncPictureParameterBufferType:
1639 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
1642 case VAEncSliceParameterBufferType:
1643 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
1646 case VAEncPackedHeaderParameterBufferType:
1648 struct encode_state *encode = &obj_context->codec_state.encode;
1649 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
1650 encode->last_packed_header_type = param->type;
1652 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
1655 encode->last_packed_header_type);
1659 case VAEncPackedHeaderDataBufferType:
1661 struct encode_state *encode = &obj_context->codec_state.encode;
1663 assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
1664 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
1665 encode->last_packed_header_type == VAEncPackedHeaderSlice);
1666 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
1669 encode->last_packed_header_type);
1673 case VAEncMiscParameterBufferType:
1674 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
1680 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1688 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
1690 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
1691 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
1694 i965_proc_render_picture(VADriverContextP ctx,
1695 VAContextID context,
1696 VABufferID *buffers,
1699 struct i965_driver_data *i965 = i965_driver_data(ctx);
1700 struct object_context *obj_context = CONTEXT(context);
1701 VAStatus vaStatus = VA_STATUS_SUCCESS;
1704 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
1705 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1708 switch (obj_buffer->type) {
1709 case VAProcPipelineParameterBufferType:
1710 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
1714 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1723 i965_RenderPicture(VADriverContextP ctx,
1724 VAContextID context,
1725 VABufferID *buffers,
1728 struct i965_driver_data *i965 = i965_driver_data(ctx);
1729 struct object_context *obj_context;
1730 struct object_config *obj_config;
1732 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1734 obj_context = CONTEXT(context);
1735 assert(obj_context);
1737 config = obj_context->config_id;
1738 obj_config = CONFIG(config);
1741 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1742 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
1743 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
1744 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
1746 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
1753 i965_EndPicture(VADriverContextP ctx, VAContextID context)
1755 struct i965_driver_data *i965 = i965_driver_data(ctx);
1756 struct object_context *obj_context = CONTEXT(context);
1757 struct object_config *obj_config;
1760 assert(obj_context);
1761 config = obj_context->config_id;
1762 obj_config = CONFIG(config);
1765 if (obj_context->codec_type == CODEC_PROC) {
1766 assert(VAEntrypointVideoProc == obj_config->entrypoint);
1767 } else if (obj_context->codec_type == CODEC_ENC) {
1768 assert(VAEntrypointEncSlice == obj_config->entrypoint);
1770 assert(obj_context->codec_state.encode.pic_param ||
1771 obj_context->codec_state.encode.pic_param_ext);
1772 assert(obj_context->codec_state.encode.seq_param ||
1773 obj_context->codec_state.encode.seq_param_ext);
1774 assert(obj_context->codec_state.encode.num_slice_params >= 1 ||
1775 obj_context->codec_state.encode.num_slice_params_ext >= 1);
1777 assert(obj_context->codec_state.decode.pic_param);
1778 assert(obj_context->codec_state.decode.num_slice_params >= 1);
1779 assert(obj_context->codec_state.decode.num_slice_datas >= 1);
1780 assert(obj_context->codec_state.decode.num_slice_params == obj_context->codec_state.decode.num_slice_datas);
1783 assert(obj_context->hw_context->run);
1784 obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
1786 return VA_STATUS_SUCCESS;
1790 i965_SyncSurface(VADriverContextP ctx,
1791 VASurfaceID render_target)
1793 struct i965_driver_data *i965 = i965_driver_data(ctx);
1794 struct object_surface *obj_surface = SURFACE(render_target);
1796 assert(obj_surface);
1798 return VA_STATUS_SUCCESS;
1802 i965_QuerySurfaceStatus(VADriverContextP ctx,
1803 VASurfaceID render_target,
1804 VASurfaceStatus *status) /* out */
1806 struct i965_driver_data *i965 = i965_driver_data(ctx);
1807 struct object_surface *obj_surface = SURFACE(render_target);
1809 assert(obj_surface);
1811 /* Usually GEM will handle synchronization with the graphics hardware */
1813 if (obj_surface->bo) {
1814 dri_bo_map(obj_surface->bo, 0);
1815 dri_bo_unmap(obj_surface->bo);
1819 *status = obj_surface->status;
1821 return VA_STATUS_SUCCESS;
1826 * Query display attributes
1827 * The caller must provide a "attr_list" array that can hold at
1828 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1829 * returned in "attr_list" is returned in "num_attributes".
1832 i965_QueryDisplayAttributes(VADriverContextP ctx,
1833 VADisplayAttribute *attr_list, /* out */
1834 int *num_attributes) /* out */
1837 *num_attributes = 0;
1839 return VA_STATUS_SUCCESS;
1843 * Get display attributes
1844 * This function returns the current attribute values in "attr_list".
1845 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1846 * from vaQueryDisplayAttributes() can have their values retrieved.
1849 i965_GetDisplayAttributes(VADriverContextP ctx,
1850 VADisplayAttribute *attr_list, /* in/out */
1854 return VA_STATUS_ERROR_UNIMPLEMENTED;
1858 * Set display attributes
1859 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1860 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1861 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1864 i965_SetDisplayAttributes(VADriverContextP ctx,
1865 VADisplayAttribute *attr_list,
1869 return VA_STATUS_ERROR_UNIMPLEMENTED;
1873 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
1874 VASurfaceID surface,
1875 void **buffer, /* out */
1876 unsigned int *stride) /* out */
1879 return VA_STATUS_ERROR_UNIMPLEMENTED;
1883 i965_Init(VADriverContextP ctx)
1885 struct i965_driver_data *i965 = i965_driver_data(ctx);
1887 if (intel_driver_init(ctx) == False)
1888 return VA_STATUS_ERROR_UNKNOWN;
1890 if (IS_G4X(i965->intel.device_id))
1891 i965->codec_info = &g4x_hw_codec_info;
1892 else if (IS_IRONLAKE(i965->intel.device_id))
1893 i965->codec_info = &ironlake_hw_codec_info;
1894 else if (IS_GEN6(i965->intel.device_id))
1895 i965->codec_info = &gen6_hw_codec_info;
1896 else if (IS_GEN7(i965->intel.device_id))
1897 i965->codec_info = &gen7_hw_codec_info;
1899 return VA_STATUS_ERROR_UNKNOWN;
1901 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER);
1903 if (i965_post_processing_init(ctx) == False)
1904 return VA_STATUS_ERROR_UNKNOWN;
1906 if (i965_render_init(ctx) == False)
1907 return VA_STATUS_ERROR_UNKNOWN;
1909 _i965InitMutex(&i965->render_mutex);
1910 _i965InitMutex(&i965->pp_mutex);
1912 return VA_STATUS_SUCCESS;
1916 i965_destroy_heap(struct object_heap *heap,
1917 void (*func)(struct object_heap *heap, struct object_base *object))
1919 struct object_base *object;
1920 object_heap_iterator iter;
1922 object = object_heap_first(heap, &iter);
1928 object = object_heap_next(heap, &iter);
1931 object_heap_destroy(heap);
1936 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
1939 i965_CreateImage(VADriverContextP ctx,
1940 VAImageFormat *format,
1943 VAImage *out_image) /* out */
1945 struct i965_driver_data *i965 = i965_driver_data(ctx);
1946 struct object_image *obj_image;
1947 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
1949 unsigned int width2, height2, size2, size;
1951 out_image->image_id = VA_INVALID_ID;
1952 out_image->buf = VA_INVALID_ID;
1954 image_id = NEW_IMAGE_ID();
1955 if (image_id == VA_INVALID_ID)
1956 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1958 obj_image = IMAGE(image_id);
1960 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1961 obj_image->bo = NULL;
1962 obj_image->palette = NULL;
1963 obj_image->derived_surface = VA_INVALID_ID;
1965 VAImage * const image = &obj_image->image;
1966 image->image_id = image_id;
1967 image->buf = VA_INVALID_ID;
1969 size = width * height;
1970 width2 = (width + 1) / 2;
1971 height2 = (height + 1) / 2;
1972 size2 = width2 * height2;
1974 image->num_palette_entries = 0;
1975 image->entry_bytes = 0;
1976 memset(image->component_order, 0, sizeof(image->component_order));
1978 switch (format->fourcc) {
1979 case VA_FOURCC('I','A','4','4'):
1980 case VA_FOURCC('A','I','4','4'):
1981 image->num_planes = 1;
1982 image->pitches[0] = width;
1983 image->offsets[0] = 0;
1984 image->data_size = image->offsets[0] + image->pitches[0] * height;
1985 image->num_palette_entries = 16;
1986 image->entry_bytes = 3;
1987 image->component_order[0] = 'R';
1988 image->component_order[1] = 'G';
1989 image->component_order[2] = 'B';
1991 case VA_FOURCC('A','R','G','B'):
1992 case VA_FOURCC('A','B','G','R'):
1993 case VA_FOURCC('B','G','R','A'):
1994 case VA_FOURCC('R','G','B','A'):
1995 image->num_planes = 1;
1996 image->pitches[0] = width * 4;
1997 image->offsets[0] = 0;
1998 image->data_size = image->offsets[0] + image->pitches[0] * height;
2000 case VA_FOURCC('Y','V','1','2'):
2001 image->num_planes = 3;
2002 image->pitches[0] = width;
2003 image->offsets[0] = 0;
2004 image->pitches[1] = width2;
2005 image->offsets[1] = size + size2;
2006 image->pitches[2] = width2;
2007 image->offsets[2] = size;
2008 image->data_size = size + 2 * size2;
2010 case VA_FOURCC('I','4','2','0'):
2011 image->num_planes = 3;
2012 image->pitches[0] = width;
2013 image->offsets[0] = 0;
2014 image->pitches[1] = width2;
2015 image->offsets[1] = size;
2016 image->pitches[2] = width2;
2017 image->offsets[2] = size + size2;
2018 image->data_size = size + 2 * size2;
2020 case VA_FOURCC('N','V','1','2'):
2021 image->num_planes = 2;
2022 image->pitches[0] = width;
2023 image->offsets[0] = 0;
2024 image->pitches[1] = width;
2025 image->offsets[1] = size;
2026 image->data_size = size + 2 * size2;
2032 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2033 image->data_size, 1, NULL, &image->buf);
2034 if (va_status != VA_STATUS_SUCCESS)
2037 obj_image->bo = BUFFER(image->buf)->buffer_store->bo;
2038 dri_bo_reference(obj_image->bo);
2040 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2041 obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette));
2042 if (!obj_image->palette)
2046 image->image_id = image_id;
2047 image->format = *format;
2048 image->width = width;
2049 image->height = height;
2051 *out_image = *image;
2052 return VA_STATUS_SUCCESS;
2055 i965_DestroyImage(ctx, image_id);
2060 i965_check_alloc_surface_bo(VADriverContextP ctx,
2061 struct object_surface *obj_surface,
2063 unsigned int fourcc,
2064 unsigned int subsampling)
2066 struct i965_driver_data *i965 = i965_driver_data(ctx);
2067 int region_width, region_height;
2069 if (obj_surface->bo) {
2070 assert(obj_surface->fourcc);
2071 assert(obj_surface->fourcc == fourcc);
2072 assert(obj_surface->subsampling == subsampling);
2076 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2077 obj_surface->x_cr_offset = 0;
2080 assert(fourcc == VA_FOURCC('N', 'V', '1', '2') ||
2081 fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
2082 fourcc == VA_FOURCC('I', 'M', 'C', '3'));
2084 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2085 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2086 obj_surface->cb_cr_pitch = obj_surface->width;
2087 region_width = obj_surface->width;
2088 region_height = obj_surface->height;
2090 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2091 assert(subsampling == SUBSAMPLE_YUV420);
2092 obj_surface->y_cb_offset = obj_surface->height;
2093 obj_surface->y_cr_offset = obj_surface->height;
2094 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2095 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2096 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2097 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
2098 fourcc == VA_FOURCC('I', 'M', 'C', '3')) {
2099 switch (subsampling) {
2100 case SUBSAMPLE_YUV400:
2101 obj_surface->cb_cr_width = 0;
2102 obj_surface->cb_cr_height = 0;
2105 case SUBSAMPLE_YUV420:
2106 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2107 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2110 case SUBSAMPLE_YUV422H:
2111 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2112 obj_surface->cb_cr_height = obj_surface->orig_height;
2115 case SUBSAMPLE_YUV422V:
2116 obj_surface->cb_cr_width = obj_surface->orig_width;
2117 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2120 case SUBSAMPLE_YUV444:
2121 obj_surface->cb_cr_width = obj_surface->orig_width;
2122 obj_surface->cb_cr_height = obj_surface->orig_height;
2125 case SUBSAMPLE_YUV411:
2126 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2127 obj_surface->cb_cr_height = obj_surface->orig_height;
2135 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2137 if (fourcc == VA_FOURCC('I', 'M', 'C', '1')) {
2138 obj_surface->y_cr_offset = obj_surface->height;
2139 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2141 obj_surface->y_cb_offset = obj_surface->height;
2142 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2146 assert(fourcc != VA_FOURCC('I', 'M', 'C', '1') &&
2147 fourcc != VA_FOURCC('I', 'M', 'C', '3'));
2148 assert(subsampling == SUBSAMPLE_YUV420);
2150 region_width = obj_surface->width;
2151 region_height = obj_surface->height;
2154 case VA_FOURCC('N', 'V', '1', '2'):
2155 obj_surface->y_cb_offset = obj_surface->height;
2156 obj_surface->y_cr_offset = obj_surface->height;
2157 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2158 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2159 obj_surface->cb_cr_pitch = obj_surface->width;
2160 region_height = obj_surface->height + obj_surface->height / 2;
2163 case VA_FOURCC('Y', 'V', '1', '2'):
2164 case VA_FOURCC('I', '4', '2', '0'):
2165 if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
2166 obj_surface->y_cr_offset = obj_surface->height;
2167 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
2169 obj_surface->y_cb_offset = obj_surface->height;
2170 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
2173 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2174 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2175 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2176 region_height = obj_surface->height + obj_surface->height / 2;
2185 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
2188 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
2189 unsigned long pitch;
2191 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
2199 assert(tiling_mode == I915_TILING_Y);
2200 assert(pitch == obj_surface->width);
2202 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
2208 obj_surface->fourcc = fourcc;
2209 obj_surface->subsampling = subsampling;
2210 assert(obj_surface->bo);
2213 VAStatus i965_DeriveImage(VADriverContextP ctx,
2214 VASurfaceID surface,
2215 VAImage *out_image) /* out */
2217 struct i965_driver_data *i965 = i965_driver_data(ctx);
2218 struct object_image *obj_image;
2219 struct object_surface *obj_surface;
2221 unsigned int w_pitch, h_pitch;
2222 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2224 out_image->image_id = VA_INVALID_ID;
2225 obj_surface = SURFACE(surface);
2228 return VA_STATUS_ERROR_INVALID_SURFACE;
2230 if (!obj_surface->bo) {
2231 unsigned int is_tiled = 0;
2232 unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
2233 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
2234 i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, SUBSAMPLE_YUV420);
2237 assert(obj_surface->fourcc);
2239 w_pitch = obj_surface->width;
2240 h_pitch = obj_surface->height;
2242 image_id = NEW_IMAGE_ID();
2244 if (image_id == VA_INVALID_ID)
2245 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2247 obj_image = IMAGE(image_id);
2250 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2252 obj_image->bo = NULL;
2253 obj_image->palette = NULL;
2254 obj_image->derived_surface = VA_INVALID_ID;
2256 VAImage * const image = &obj_image->image;
2258 memset(image, 0, sizeof(*image));
2259 image->image_id = image_id;
2260 image->buf = VA_INVALID_ID;
2261 image->num_palette_entries = 0;
2262 image->entry_bytes = 0;
2263 image->width = obj_surface->orig_width;
2264 image->height = obj_surface->orig_height;
2265 image->data_size = obj_surface->size;
2267 image->format.fourcc = obj_surface->fourcc;
2268 image->format.byte_order = VA_LSB_FIRST;
2269 image->format.bits_per_pixel = 12;
2271 switch (image->format.fourcc) {
2272 case VA_FOURCC('Y', 'V', '1', '2'):
2273 image->num_planes = 3;
2274 image->pitches[0] = w_pitch; /* Y */
2275 image->offsets[0] = 0;
2276 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
2277 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
2278 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
2279 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
2282 case VA_FOURCC('N', 'V', '1', '2'):
2283 image->num_planes = 2;
2284 image->pitches[0] = w_pitch; /* Y */
2285 image->offsets[0] = 0;
2286 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
2287 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
2290 case VA_FOURCC('I', '4', '2', '0'):
2291 image->num_planes = 3;
2292 image->pitches[0] = w_pitch; /* Y */
2293 image->offsets[0] = 0;
2294 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
2295 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
2296 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
2297 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
2304 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
2305 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
2306 if (va_status != VA_STATUS_SUCCESS)
2309 obj_image->bo = BUFFER(image->buf)->buffer_store->bo;
2310 dri_bo_reference(obj_image->bo);
2312 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2313 obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette));
2314 if (!obj_image->palette) {
2315 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
2320 *out_image = *image;
2321 obj_surface->flags |= SURFACE_DERIVED;
2322 obj_image->derived_surface = surface;
2324 return VA_STATUS_SUCCESS;
2327 i965_DestroyImage(ctx, image_id);
2332 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
2334 object_heap_free(heap, obj);
2339 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
2341 struct i965_driver_data *i965 = i965_driver_data(ctx);
2342 struct object_image *obj_image = IMAGE(image);
2343 struct object_surface *obj_surface;
2346 return VA_STATUS_SUCCESS;
2348 dri_bo_unreference(obj_image->bo);
2349 obj_image->bo = NULL;
2351 if (obj_image->image.buf != VA_INVALID_ID) {
2352 i965_DestroyBuffer(ctx, obj_image->image.buf);
2353 obj_image->image.buf = VA_INVALID_ID;
2356 if (obj_image->palette) {
2357 free(obj_image->palette);
2358 obj_image->palette = NULL;
2361 obj_surface = SURFACE(obj_image->derived_surface);
2364 obj_surface->flags &= ~SURFACE_DERIVED;
2367 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
2369 return VA_STATUS_SUCCESS;
2373 * pointer to an array holding the palette data. The size of the array is
2374 * num_palette_entries * entry_bytes in size. The order of the components
2375 * in the palette is described by the component_order in VASubpicture struct
2378 i965_SetImagePalette(VADriverContextP ctx,
2380 unsigned char *palette)
2382 struct i965_driver_data *i965 = i965_driver_data(ctx);
2385 struct object_image *obj_image = IMAGE(image);
2387 return VA_STATUS_ERROR_INVALID_IMAGE;
2389 if (!obj_image->palette)
2390 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
2392 for (i = 0; i < obj_image->image.num_palette_entries; i++)
2393 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
2394 ((unsigned int)palette[3*i + 1] << 8) |
2395 (unsigned int)palette[3*i + 2]);
2396 return VA_STATUS_SUCCESS;
2400 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
2401 const uint8_t *src, unsigned int src_stride,
2402 unsigned int len, unsigned int height)
2406 for (i = 0; i < height; i++) {
2407 memcpy(dst, src, len);
2414 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
2415 struct object_surface *obj_surface,
2416 const VARectangle *rect)
2418 uint8_t *dst[3], *src[3];
2420 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
2421 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
2422 unsigned int tiling, swizzle;
2424 if (!obj_surface->bo)
2427 assert(obj_surface->fourcc);
2428 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2430 if (tiling != I915_TILING_NONE)
2431 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2433 dri_bo_map(obj_surface->bo, 0);
2435 if (!obj_surface->bo->virtual)
2438 /* Dest VA image has either I420 or YV12 format.
2439 Source VA surface alway has I420 format */
2440 dst[Y] = image_data + obj_image->image.offsets[Y];
2441 src[0] = (uint8_t *)obj_surface->bo->virtual;
2442 dst[U] = image_data + obj_image->image.offsets[U];
2443 src[1] = src[0] + obj_surface->width * obj_surface->height;
2444 dst[V] = image_data + obj_image->image.offsets[V];
2445 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
2448 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
2449 src[0] += rect->y * obj_surface->width + rect->x;
2450 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
2451 src[0], obj_surface->width,
2452 rect->width, rect->height);
2455 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
2456 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
2457 memcpy_pic(dst[U], obj_image->image.pitches[U],
2458 src[1], obj_surface->width / 2,
2459 rect->width / 2, rect->height / 2);
2462 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
2463 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
2464 memcpy_pic(dst[V], obj_image->image.pitches[V],
2465 src[2], obj_surface->width / 2,
2466 rect->width / 2, rect->height / 2);
2468 if (tiling != I915_TILING_NONE)
2469 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2471 dri_bo_unmap(obj_surface->bo);
2475 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
2476 struct object_surface *obj_surface,
2477 const VARectangle *rect)
2479 uint8_t *dst[2], *src[2];
2480 unsigned int tiling, swizzle;
2482 if (!obj_surface->bo)
2485 assert(obj_surface->fourcc);
2486 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2488 if (tiling != I915_TILING_NONE)
2489 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2491 dri_bo_map(obj_surface->bo, 0);
2493 if (!obj_surface->bo->virtual)
2496 /* Both dest VA image and source surface have NV12 format */
2497 dst[0] = image_data + obj_image->image.offsets[0];
2498 src[0] = (uint8_t *)obj_surface->bo->virtual;
2499 dst[1] = image_data + obj_image->image.offsets[1];
2500 src[1] = src[0] + obj_surface->width * obj_surface->height;
2503 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
2504 src[0] += rect->y * obj_surface->width + rect->x;
2505 memcpy_pic(dst[0], obj_image->image.pitches[0],
2506 src[0], obj_surface->width,
2507 rect->width, rect->height);
2510 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
2511 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
2512 memcpy_pic(dst[1], obj_image->image.pitches[1],
2513 src[1], obj_surface->width,
2514 rect->width, rect->height / 2);
2516 if (tiling != I915_TILING_NONE)
2517 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2519 dri_bo_unmap(obj_surface->bo);
2523 i965_sw_getimage(VADriverContextP ctx,
2524 VASurfaceID surface,
2525 int x, /* coordinates of the upper left source pixel */
2527 unsigned int width, /* width and height of the region */
2528 unsigned int height,
2531 struct i965_driver_data *i965 = i965_driver_data(ctx);
2532 struct i965_render_state *render_state = &i965->render_state;
2534 struct object_surface *obj_surface = SURFACE(surface);
2536 return VA_STATUS_ERROR_INVALID_SURFACE;
2538 struct object_image *obj_image = IMAGE(image);
2540 return VA_STATUS_ERROR_INVALID_IMAGE;
2543 return VA_STATUS_ERROR_INVALID_PARAMETER;
2544 if (x + width > obj_surface->orig_width ||
2545 y + height > obj_surface->orig_height)
2546 return VA_STATUS_ERROR_INVALID_PARAMETER;
2547 if (x + width > obj_image->image.width ||
2548 y + height > obj_image->image.height)
2549 return VA_STATUS_ERROR_INVALID_PARAMETER;
2552 void *image_data = NULL;
2554 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
2555 if (va_status != VA_STATUS_SUCCESS)
2562 rect.height = height;
2564 switch (obj_image->image.format.fourcc) {
2565 case VA_FOURCC('Y','V','1','2'):
2566 case VA_FOURCC('I','4','2','0'):
2567 /* I420 is native format for MPEG-2 decoded surfaces */
2568 if (render_state->interleaved_uv)
2569 goto operation_failed;
2570 get_image_i420(obj_image, image_data, obj_surface, &rect);
2572 case VA_FOURCC('N','V','1','2'):
2573 /* NV12 is native format for H.264 decoded surfaces */
2574 if (!render_state->interleaved_uv)
2575 goto operation_failed;
2576 get_image_nv12(obj_image, image_data, obj_surface, &rect);
2580 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2584 i965_UnmapBuffer(ctx, obj_image->image.buf);
2589 i965_hw_getimage(VADriverContextP ctx,
2590 VASurfaceID surface,
2591 int x, /* coordinates of the upper left source pixel */
2593 unsigned int width, /* width and height of the region */
2594 unsigned int height,
2597 struct i965_driver_data *i965 = i965_driver_data(ctx);
2598 struct i965_surface src_surface;
2599 struct i965_surface dst_surface;
2602 struct object_surface *obj_surface = SURFACE(surface);
2603 struct object_image *obj_image = IMAGE(image);
2606 return VA_STATUS_ERROR_INVALID_SURFACE;
2609 return VA_STATUS_ERROR_INVALID_IMAGE;
2612 return VA_STATUS_ERROR_INVALID_PARAMETER;
2613 if (x + width > obj_surface->orig_width ||
2614 y + height > obj_surface->orig_height)
2615 return VA_STATUS_ERROR_INVALID_PARAMETER;
2616 if (x + width > obj_image->image.width ||
2617 y + height > obj_image->image.height)
2618 return VA_STATUS_ERROR_INVALID_PARAMETER;
2620 if (!obj_surface->bo)
2621 return VA_STATUS_SUCCESS;
2626 rect.height = height;
2628 src_surface.id = surface;
2629 src_surface.type = I965_SURFACE_TYPE_SURFACE;
2630 src_surface.flags = I965_SURFACE_FLAG_FRAME;
2632 dst_surface.id = image;
2633 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
2634 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
2636 va_status = i965_image_processing(ctx,
2647 i965_GetImage(VADriverContextP ctx,
2648 VASurfaceID surface,
2649 int x, /* coordinates of the upper left source pixel */
2651 unsigned int width, /* width and height of the region */
2652 unsigned int height,
2655 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2658 if (HAS_ACCELERATED_GETIMAGE(i965))
2659 va_status = i965_hw_getimage(ctx,
2665 va_status = i965_sw_getimage(ctx,
2675 put_image_i420(struct object_surface *obj_surface,
2676 const VARectangle *dst_rect,
2677 struct object_image *obj_image, uint8_t *image_data,
2678 const VARectangle *src_rect)
2680 uint8_t *dst[3], *src[3];
2682 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
2683 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
2684 unsigned int tiling, swizzle;
2686 if (!obj_surface->bo)
2689 assert(obj_surface->fourcc);
2690 assert(dst_rect->width == src_rect->width);
2691 assert(dst_rect->height == src_rect->height);
2692 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2694 if (tiling != I915_TILING_NONE)
2695 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2697 dri_bo_map(obj_surface->bo, 0);
2699 if (!obj_surface->bo->virtual)
2702 /* Dest VA image has either I420 or YV12 format.
2703 Source VA surface alway has I420 format */
2704 dst[0] = (uint8_t *)obj_surface->bo->virtual;
2705 src[Y] = image_data + obj_image->image.offsets[Y];
2706 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
2707 src[U] = image_data + obj_image->image.offsets[U];
2708 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
2709 src[V] = image_data + obj_image->image.offsets[V];
2712 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
2713 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
2714 memcpy_pic(dst[0], obj_surface->width,
2715 src[Y], obj_image->image.pitches[Y],
2716 src_rect->width, src_rect->height);
2719 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
2720 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
2721 memcpy_pic(dst[1], obj_surface->width / 2,
2722 src[U], obj_image->image.pitches[U],
2723 src_rect->width / 2, src_rect->height / 2);
2726 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
2727 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
2728 memcpy_pic(dst[2], obj_surface->width / 2,
2729 src[V], obj_image->image.pitches[V],
2730 src_rect->width / 2, src_rect->height / 2);
2732 if (tiling != I915_TILING_NONE)
2733 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2735 dri_bo_unmap(obj_surface->bo);
2739 put_image_nv12(struct object_surface *obj_surface,
2740 const VARectangle *dst_rect,
2741 struct object_image *obj_image, uint8_t *image_data,
2742 const VARectangle *src_rect)
2744 uint8_t *dst[2], *src[2];
2745 unsigned int tiling, swizzle;
2747 if (!obj_surface->bo)
2750 assert(obj_surface->fourcc);
2751 assert(dst_rect->width == src_rect->width);
2752 assert(dst_rect->height == src_rect->height);
2753 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2755 if (tiling != I915_TILING_NONE)
2756 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2758 dri_bo_map(obj_surface->bo, 0);
2760 if (!obj_surface->bo->virtual)
2763 /* Both dest VA image and source surface have NV12 format */
2764 dst[0] = (uint8_t *)obj_surface->bo->virtual;
2765 src[0] = image_data + obj_image->image.offsets[0];
2766 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
2767 src[1] = image_data + obj_image->image.offsets[1];
2770 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
2771 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
2772 memcpy_pic(dst[0], obj_surface->width,
2773 src[0], obj_image->image.pitches[0],
2774 src_rect->width, src_rect->height);
2777 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
2778 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
2779 memcpy_pic(dst[1], obj_surface->width,
2780 src[1], obj_image->image.pitches[1],
2781 src_rect->width, src_rect->height / 2);
2783 if (tiling != I915_TILING_NONE)
2784 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2786 dri_bo_unmap(obj_surface->bo);
2790 i965_sw_putimage(VADriverContextP ctx,
2791 VASurfaceID surface,
2795 unsigned int src_width,
2796 unsigned int src_height,
2799 unsigned int dest_width,
2800 unsigned int dest_height)
2802 struct i965_driver_data *i965 = i965_driver_data(ctx);
2803 struct object_surface *obj_surface = SURFACE(surface);
2806 return VA_STATUS_ERROR_INVALID_SURFACE;
2808 struct object_image *obj_image = IMAGE(image);
2810 return VA_STATUS_ERROR_INVALID_IMAGE;
2812 if (src_x < 0 || src_y < 0)
2813 return VA_STATUS_ERROR_INVALID_PARAMETER;
2814 if (src_x + src_width > obj_image->image.width ||
2815 src_y + src_height > obj_image->image.height)
2816 return VA_STATUS_ERROR_INVALID_PARAMETER;
2817 if (dest_x < 0 || dest_y < 0)
2818 return VA_STATUS_ERROR_INVALID_PARAMETER;
2819 if (dest_x + dest_width > obj_surface->orig_width ||
2820 dest_y + dest_height > obj_surface->orig_height)
2821 return VA_STATUS_ERROR_INVALID_PARAMETER;
2823 /* XXX: don't allow scaling */
2824 if (src_width != dest_width || src_height != dest_height)
2825 return VA_STATUS_ERROR_INVALID_PARAMETER;
2827 if (obj_surface->fourcc) {
2828 /* Don't allow format mismatch */
2829 if (obj_surface->fourcc != obj_image->image.format.fourcc)
2830 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
2834 /* VA is surface not used for decoding, use same VA image format */
2835 i965_check_alloc_surface_bo(
2838 0, /* XXX: don't use tiled surface */
2839 obj_image->image.format.fourcc,
2844 void *image_data = NULL;
2846 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
2847 if (va_status != VA_STATUS_SUCCESS)
2850 VARectangle src_rect, dest_rect;
2853 src_rect.width = src_width;
2854 src_rect.height = src_height;
2855 dest_rect.x = dest_x;
2856 dest_rect.y = dest_y;
2857 dest_rect.width = dest_width;
2858 dest_rect.height = dest_height;
2860 switch (obj_image->image.format.fourcc) {
2861 case VA_FOURCC('Y','V','1','2'):
2862 case VA_FOURCC('I','4','2','0'):
2863 put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
2865 case VA_FOURCC('N','V','1','2'):
2866 put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
2869 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2873 i965_UnmapBuffer(ctx, obj_image->image.buf);
2878 i965_hw_putimage(VADriverContextP ctx,
2879 VASurfaceID surface,
2883 unsigned int src_width,
2884 unsigned int src_height,
2887 unsigned int dest_width,
2888 unsigned int dest_height)
2890 struct i965_driver_data *i965 = i965_driver_data(ctx);
2891 struct object_surface *obj_surface = SURFACE(surface);
2892 struct object_image *obj_image = IMAGE(image);
2893 struct i965_surface src_surface, dst_surface;
2894 VAStatus va_status = VA_STATUS_SUCCESS;
2895 VARectangle src_rect, dst_rect;
2898 return VA_STATUS_ERROR_INVALID_SURFACE;
2900 if (!obj_image || !obj_image->bo)
2901 return VA_STATUS_ERROR_INVALID_IMAGE;
2905 src_x + src_width > obj_image->image.width ||
2906 src_y + src_height > obj_image->image.height)
2907 return VA_STATUS_ERROR_INVALID_PARAMETER;
2911 dest_x + dest_width > obj_surface->orig_width ||
2912 dest_y + dest_height > obj_surface->orig_height)
2913 return VA_STATUS_ERROR_INVALID_PARAMETER;
2915 if (!obj_surface->bo) {
2916 unsigned int tiling, swizzle;
2917 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
2919 i965_check_alloc_surface_bo(ctx,
2922 obj_image->image.format.fourcc,
2926 assert(obj_surface->fourcc);
2928 src_surface.id = image;
2929 src_surface.type = I965_SURFACE_TYPE_IMAGE;
2930 src_surface.flags = I965_SURFACE_FLAG_FRAME;
2933 src_rect.width = src_width;
2934 src_rect.height = src_height;
2936 dst_surface.id = surface;
2937 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
2938 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
2939 dst_rect.x = dest_x;
2940 dst_rect.y = dest_y;
2941 dst_rect.width = dest_width;
2942 dst_rect.height = dest_height;
2944 va_status = i965_image_processing(ctx,
2954 i965_PutImage(VADriverContextP ctx,
2955 VASurfaceID surface,
2959 unsigned int src_width,
2960 unsigned int src_height,
2963 unsigned int dest_width,
2964 unsigned int dest_height)
2966 struct i965_driver_data *i965 = i965_driver_data(ctx);
2967 VAStatus va_status = VA_STATUS_SUCCESS;
2969 if (HAS_ACCELERATED_PUTIMAGE(i965))
2970 va_status = i965_hw_putimage(ctx,
2982 va_status = i965_sw_putimage(ctx,
2998 i965_PutSurface(VADriverContextP ctx,
2999 VASurfaceID surface,
3000 void *draw, /* X Drawable */
3003 unsigned short srcw,
3004 unsigned short srch,
3007 unsigned short destw,
3008 unsigned short desth,
3009 VARectangle *cliprects, /* client supplied clip list */
3010 unsigned int number_cliprects, /* number of clip rects in the clip list */
3011 unsigned int flags) /* de-interlacing flags */
3013 struct i965_driver_data *i965 = i965_driver_data(ctx);
3014 struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
3015 struct i965_render_state *render_state = &i965->render_state;
3016 struct dri_drawable *dri_drawable;
3017 union dri_buffer *buffer;
3018 struct intel_region *dest_region;
3019 struct object_surface *obj_surface;
3020 VARectangle src_rect, dst_rect;
3023 Bool new_region = False;
3026 /* Currently don't support DRI1 */
3027 if (dri_state->driConnectedFlag != VA_DRI2)
3028 return VA_STATUS_ERROR_UNKNOWN;
3030 /* Some broken sources such as H.264 conformance case FM2_SVA_C
3033 obj_surface = SURFACE(surface);
3034 if (!obj_surface || !obj_surface->bo)
3035 return VA_STATUS_SUCCESS;
3037 _i965LockMutex(&i965->render_mutex);
3039 dri_drawable = dri_get_drawable(ctx, (Drawable)draw);
3040 assert(dri_drawable);
3042 buffer = dri_get_rendering_buffer(ctx, dri_drawable);
3045 dest_region = render_state->draw_region;
3048 assert(dest_region->bo);
3049 dri_bo_flink(dest_region->bo, &name);
3051 if (buffer->dri2.name != name) {
3053 dri_bo_unreference(dest_region->bo);
3056 dest_region = (struct intel_region *)calloc(1, sizeof(*dest_region));
3057 assert(dest_region);
3058 render_state->draw_region = dest_region;
3063 dest_region->x = dri_drawable->x;
3064 dest_region->y = dri_drawable->y;
3065 dest_region->width = dri_drawable->width;
3066 dest_region->height = dri_drawable->height;
3067 dest_region->cpp = buffer->dri2.cpp;
3068 dest_region->pitch = buffer->dri2.pitch;
3070 dest_region->bo = intel_bo_gem_create_from_name(i965->intel.bufmgr, "rendering buffer", buffer->dri2.name);
3071 assert(dest_region->bo);
3073 ret = dri_bo_get_tiling(dest_region->bo, &(dest_region->tiling), &(dest_region->swizzle));
3077 if ((flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC)
3078 pp_flag |= I965_PP_FLAG_AVS;
3080 if (flags & VA_TOP_FIELD)
3081 pp_flag |= I965_PP_FLAG_DEINTERLACING_TOP_FISRT;
3082 else if (flags & VA_BOTTOM_FIELD)
3083 pp_flag |= I965_PP_FLAG_DEINTERLACING_BOTTOM_FIRST;
3087 src_rect.width = srcw;
3088 src_rect.height = srch;
3092 dst_rect.width = destw;
3093 dst_rect.height = desth;
3095 intel_render_put_surface(ctx, surface, &src_rect, &dst_rect, pp_flag);
3097 if(obj_surface->subpic != VA_INVALID_ID) {
3098 intel_render_put_subpicture(ctx, surface, &src_rect, &dst_rect);
3101 dri_swap_buffer(ctx, dri_drawable);
3102 obj_surface->flags |= SURFACE_DISPLAYED;
3104 if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
3105 dri_bo_unreference(obj_surface->bo);
3106 obj_surface->bo = NULL;
3107 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
3109 if (obj_surface->free_private_data)
3110 obj_surface->free_private_data(&obj_surface->private_data);
3113 _i965UnlockMutex(&i965->render_mutex);
3115 return VA_STATUS_SUCCESS;
3119 i965_Terminate(VADriverContextP ctx)
3121 struct i965_driver_data *i965 = i965_driver_data(ctx);
3124 intel_batchbuffer_free(i965->batch);
3126 _i965DestroyMutex(&i965->pp_mutex);
3127 _i965DestroyMutex(&i965->render_mutex);
3129 if (i965_render_terminate(ctx) == False)
3130 return VA_STATUS_ERROR_UNKNOWN;
3132 if (i965_post_processing_terminate(ctx) == False)
3133 return VA_STATUS_ERROR_UNKNOWN;
3135 if (intel_driver_terminate(ctx) == False)
3136 return VA_STATUS_ERROR_UNKNOWN;
3138 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
3139 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
3140 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
3141 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
3142 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
3143 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
3145 free(ctx->pDriverData);
3146 ctx->pDriverData = NULL;
3148 return VA_STATUS_SUCCESS;
3153 VADriverContextP ctx, /* in */
3154 VABufferID buf_id, /* in */
3155 VABufferType *type, /* out */
3156 unsigned int *size, /* out */
3157 unsigned int *num_elements /* out */
3160 struct i965_driver_data *i965 = NULL;
3161 struct object_buffer *obj_buffer = NULL;
3163 i965 = i965_driver_data(ctx);
3164 obj_buffer = BUFFER(buf_id);
3166 *type = obj_buffer->type;
3167 *size = obj_buffer->size_element;
3168 *num_elements = obj_buffer->num_elements;
3170 return VA_STATUS_SUCCESS;
3175 VADriverContextP ctx, /* in */
3176 VASurfaceID surface, /* in */
3177 unsigned int *fourcc, /* out */
3178 unsigned int *luma_stride, /* out */
3179 unsigned int *chroma_u_stride, /* out */
3180 unsigned int *chroma_v_stride, /* out */
3181 unsigned int *luma_offset, /* out */
3182 unsigned int *chroma_u_offset, /* out */
3183 unsigned int *chroma_v_offset, /* out */
3184 unsigned int *buffer_name, /* out */
3185 void **buffer /* out */
3188 VAStatus vaStatus = VA_STATUS_SUCCESS;
3189 struct i965_driver_data *i965 = i965_driver_data(ctx);
3190 struct object_surface *obj_surface = NULL;
3194 assert(luma_stride);
3195 assert(chroma_u_stride);
3196 assert(chroma_v_stride);
3197 assert(luma_offset);
3198 assert(chroma_u_offset);
3199 assert(chroma_v_offset);
3200 assert(buffer_name);
3203 tmpImage.image_id = VA_INVALID_ID;
3205 obj_surface = SURFACE(surface);
3206 if (obj_surface == NULL) {
3207 // Surface is absent.
3208 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3212 // Lock functionality is absent now.
3213 if (obj_surface->locked_image_id != VA_INVALID_ID) {
3214 // Surface is locked already.
3215 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3219 vaStatus = i965_DeriveImage(
3223 if (vaStatus != VA_STATUS_SUCCESS) {
3227 obj_surface->locked_image_id = tmpImage.image_id;
3229 vaStatus = i965_MapBuffer(
3233 if (vaStatus != VA_STATUS_SUCCESS) {
3237 *fourcc = tmpImage.format.fourcc;
3238 *luma_offset = tmpImage.offsets[0];
3239 *luma_stride = tmpImage.pitches[0];
3240 *chroma_u_offset = tmpImage.offsets[1];
3241 *chroma_u_stride = tmpImage.pitches[1];
3242 *chroma_v_offset = tmpImage.offsets[2];
3243 *chroma_v_stride = tmpImage.pitches[2];
3244 *buffer_name = tmpImage.buf;
3247 if (vaStatus != VA_STATUS_SUCCESS) {
3256 VADriverContextP ctx, /* in */
3257 VASurfaceID surface /* in */
3260 VAStatus vaStatus = VA_STATUS_SUCCESS;
3261 struct i965_driver_data *i965 = i965_driver_data(ctx);
3262 struct object_image *locked_img = NULL;
3263 struct object_surface *obj_surface = NULL;
3265 obj_surface = SURFACE(surface);
3267 if (obj_surface == NULL) {
3268 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
3271 if (obj_surface->locked_image_id == VA_INVALID_ID) {
3272 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
3276 locked_img = IMAGE(obj_surface->locked_image_id);
3277 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
3278 // Work image was deallocated before i965_UnlockSurface()
3279 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3283 vaStatus = i965_UnmapBuffer(
3285 locked_img->image.buf);
3286 if (vaStatus != VA_STATUS_SUCCESS) {
3290 vaStatus = i965_DestroyImage(
3292 locked_img->image.image_id);
3293 if (vaStatus != VA_STATUS_SUCCESS) {
3297 locked_img->image.image_id = VA_INVALID_ID;
3304 i965_GetSurfaceAttributes(
3305 VADriverContextP ctx,
3307 VASurfaceAttrib *attrib_list,
3308 unsigned int num_attribs
3311 VAStatus vaStatus = VA_STATUS_SUCCESS;
3312 struct i965_driver_data *i965 = i965_driver_data(ctx);
3313 struct object_config *obj_config;
3316 if (config == VA_INVALID_ID)
3317 return VA_STATUS_ERROR_INVALID_CONFIG;
3319 obj_config = CONFIG(config);
3321 if (obj_config == NULL)
3322 return VA_STATUS_ERROR_INVALID_CONFIG;
3324 if (attrib_list == NULL || num_attribs)
3325 return VA_STATUS_ERROR_INVALID_PARAMETER;
3327 for (i = 0; i < num_attribs; i++) {
3328 switch (attrib_list[i].type) {
3329 case VASurfaceAttribPixelFormat:
3330 attrib_list[i].value.type = VAGenericValueTypeInteger;
3331 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
3333 if (attrib_list[i].value.value.i == 0) {
3334 if (IS_G4X(i965->intel.device_id)) {
3335 if (obj_config->profile == VAProfileMPEG2Simple ||
3336 obj_config->profile == VAProfileMPEG2Main) {
3337 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
3340 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3342 } else if (IS_IRONLAKE(i965->intel.device_id)) {
3343 if (obj_config->profile == VAProfileMPEG2Simple ||
3344 obj_config->profile == VAProfileMPEG2Main) {
3345 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
3346 } else if (obj_config->profile == VAProfileH264Baseline ||
3347 obj_config->profile == VAProfileH264Main ||
3348 obj_config->profile == VAProfileH264High) {
3349 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3350 } else if (obj_config->profile == VAProfileNone) {
3351 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3354 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3356 } else if (IS_GEN6(i965->intel.device_id)) {
3357 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3358 } else if (IS_GEN7(i965->intel.device_id)) {
3359 if (obj_config->profile == VAProfileJPEGBaseline)
3360 attrib_list[i].value.value.i = 0; /* internal format */
3362 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3365 if (IS_G4X(i965->intel.device_id)) {
3366 if (obj_config->profile == VAProfileMPEG2Simple ||
3367 obj_config->profile == VAProfileMPEG2Main) {
3368 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
3369 attrib_list[i].value.value.i = 0;
3370 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3374 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3376 } else if (IS_IRONLAKE(i965->intel.device_id)) {
3377 if (obj_config->profile == VAProfileMPEG2Simple ||
3378 obj_config->profile == VAProfileMPEG2Main) {
3379 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
3380 attrib_list[i].value.value.i = 0;
3381 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3383 } else if (obj_config->profile == VAProfileH264Baseline ||
3384 obj_config->profile == VAProfileH264Main ||
3385 obj_config->profile == VAProfileH264High) {
3386 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3387 attrib_list[i].value.value.i = 0;
3388 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3390 } else if (obj_config->profile == VAProfileNone) {
3391 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2') &&
3392 attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0') &&
3393 attrib_list[i].value.value.i != VA_FOURCC('Y', 'V', '1', '2')) {
3394 attrib_list[i].value.value.i = 0;
3395 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3399 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3401 } else if (IS_GEN6(i965->intel.device_id)) {
3402 if (obj_config->entrypoint == VAEntrypointEncSlice ||
3403 obj_config->entrypoint == VAEntrypointVideoProc) {
3404 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2') &&
3405 attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0') &&
3406 attrib_list[i].value.value.i != VA_FOURCC('Y', 'V', '1', '2')) {
3407 attrib_list[i].value.value.i = 0;
3408 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3411 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3412 attrib_list[i].value.value.i = 0;
3413 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3416 } else if (IS_GEN7(i965->intel.device_id)) {
3417 if (obj_config->entrypoint == VAEntrypointEncSlice ||
3418 obj_config->entrypoint == VAEntrypointVideoProc) {
3419 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2') &&
3420 attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0') &&
3421 attrib_list[i].value.value.i != VA_FOURCC('Y', 'V', '1', '2')) {
3422 attrib_list[i].value.value.i = 0;
3423 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3426 if (obj_config->profile == VAProfileJPEGBaseline) {
3427 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
3428 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3430 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3431 attrib_list[i].value.value.i = 0;
3432 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3440 case VASurfaceAttribMinWidth:
3441 /* FIXME: add support for it later */
3442 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3444 case VASurfaceAttribMaxWidth:
3445 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3447 case VASurfaceAttribMinHeight:
3448 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3450 case VASurfaceAttribMaxHeight:
3451 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3454 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3463 * Query video processing pipeline
3465 VAStatus i965_QueryVideoProcFilters(
3466 VADriverContextP ctx,
3467 VAContextID context,
3468 VAProcFilterType *filters,
3469 unsigned int *num_filters
3472 struct i965_driver_data *const i965 = i965_driver_data(ctx);
3475 if (HAS_VPP(i965)) {
3476 filters[i++] = VAProcFilterNoiseReduction;
3477 filters[i++] = VAProcFilterDeinterlacing;
3482 return VA_STATUS_SUCCESS;
3485 VAStatus i965_QueryVideoProcFilterCaps(
3486 VADriverContextP ctx,
3487 VAContextID context,
3488 VAProcFilterType type,
3490 unsigned int *num_filter_caps
3495 if (type == VAProcFilterNoiseReduction) {
3496 VAProcFilterCap *cap = filter_caps;
3498 cap->range.min_value = 0.0;
3499 cap->range.max_value = 1.0;
3500 cap->range.default_value = 0.5;
3501 cap->range.step = 0.03125; /* 1.0 / 32 */
3503 } else if (type == VAProcFilterDeinterlacing) {
3504 VAProcFilterCapDeinterlacing *cap = filter_caps;
3506 cap->type = VAProcDeinterlacingBob;
3511 *num_filter_caps = i;
3513 return VA_STATUS_SUCCESS;
3516 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
3517 VAProcColorStandardBT601,
3520 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
3521 VAProcColorStandardBT601,
3524 VAStatus i965_QueryVideoProcPipelineCaps(
3525 VADriverContextP ctx,
3526 VAContextID context,
3527 VABufferID *filters,
3528 unsigned int num_filters,
3529 VAProcPipelineCaps *pipeline_cap /* out */
3532 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3535 pipeline_cap->flags = 0;
3536 pipeline_cap->pipeline_flags = 0;
3537 pipeline_cap->filter_flags = 0;
3538 pipeline_cap->num_forward_references = 0;
3539 pipeline_cap->num_backward_references = 0;
3540 pipeline_cap->num_input_color_standards = 1;
3541 pipeline_cap->input_color_standards = vpp_input_color_standards;
3542 pipeline_cap->num_output_color_standards = 1;
3543 pipeline_cap->output_color_standards = vpp_output_color_standards;
3545 for (i = 0; i < num_filters; i++) {
3546 struct object_buffer *obj_buffer = BUFFER(filters[i]);
3547 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
3549 if (base->type == VAProcFilterNoiseReduction) {
3550 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
3552 } else if (base->type == VAProcFilterDeinterlacing) {
3553 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
3555 assert(deint->algorithm == VAProcDeinterlacingWeave ||
3556 deint->algorithm == VAProcDeinterlacingBob);
3560 return VA_STATUS_SUCCESS;
3564 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
3567 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
3569 struct VADriverVTable * const vtable = ctx->vtable;
3570 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
3572 struct i965_driver_data *i965;
3575 ctx->version_major = VA_MAJOR_VERSION;
3576 ctx->version_minor = VA_MINOR_VERSION;
3577 ctx->max_profiles = I965_MAX_PROFILES;
3578 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
3579 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
3580 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
3581 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
3582 ctx->max_display_attributes = I965_MAX_DISPLAY_ATTRIBUTES;
3584 vtable->vaTerminate = i965_Terminate;
3585 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
3586 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
3587 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
3588 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
3589 vtable->vaCreateConfig = i965_CreateConfig;
3590 vtable->vaDestroyConfig = i965_DestroyConfig;
3591 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
3592 vtable->vaCreateSurfaces = i965_CreateSurfaces;
3593 vtable->vaDestroySurfaces = i965_DestroySurfaces;
3594 vtable->vaCreateContext = i965_CreateContext;
3595 vtable->vaDestroyContext = i965_DestroyContext;
3596 vtable->vaCreateBuffer = i965_CreateBuffer;
3597 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
3598 vtable->vaMapBuffer = i965_MapBuffer;
3599 vtable->vaUnmapBuffer = i965_UnmapBuffer;
3600 vtable->vaDestroyBuffer = i965_DestroyBuffer;
3601 vtable->vaBeginPicture = i965_BeginPicture;
3602 vtable->vaRenderPicture = i965_RenderPicture;
3603 vtable->vaEndPicture = i965_EndPicture;
3604 vtable->vaSyncSurface = i965_SyncSurface;
3605 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
3606 vtable->vaPutSurface = i965_PutSurface;
3607 vtable->vaQueryImageFormats = i965_QueryImageFormats;
3608 vtable->vaCreateImage = i965_CreateImage;
3609 vtable->vaDeriveImage = i965_DeriveImage;
3610 vtable->vaDestroyImage = i965_DestroyImage;
3611 vtable->vaSetImagePalette = i965_SetImagePalette;
3612 vtable->vaGetImage = i965_GetImage;
3613 vtable->vaPutImage = i965_PutImage;
3614 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
3615 vtable->vaCreateSubpicture = i965_CreateSubpicture;
3616 vtable->vaDestroySubpicture = i965_DestroySubpicture;
3617 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
3618 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
3619 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
3620 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
3621 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
3622 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
3623 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
3624 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
3625 vtable->vaBufferInfo = i965_BufferInfo;
3626 vtable->vaLockSurface = i965_LockSurface;
3627 vtable->vaUnlockSurface = i965_UnlockSurface;
3628 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
3629 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
3631 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
3632 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
3633 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
3635 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
3637 ctx->pDriverData = (void *)i965;
3639 result = object_heap_init(&i965->config_heap,
3640 sizeof(struct object_config),
3642 assert(result == 0);
3644 result = object_heap_init(&i965->context_heap,
3645 sizeof(struct object_context),
3647 assert(result == 0);
3649 result = object_heap_init(&i965->surface_heap,
3650 sizeof(struct object_surface),
3652 assert(result == 0);
3654 result = object_heap_init(&i965->buffer_heap,
3655 sizeof(struct object_buffer),
3657 assert(result == 0);
3659 result = object_heap_init(&i965->image_heap,
3660 sizeof(struct object_image),
3662 assert(result == 0);
3664 result = object_heap_init(&i965->subpic_heap,
3665 sizeof(struct object_subpic),
3667 assert(result == 0);
3669 sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
3670 INTEL_STR_DRIVER_VENDOR,
3671 INTEL_STR_DRIVER_NAME,
3672 INTEL_DRIVER_MAJOR_VERSION,
3673 INTEL_DRIVER_MINOR_VERSION,
3674 INTEL_DRIVER_MICRO_VERSION);
3676 if (INTEL_DRIVER_PRE_VERSION > 0) {
3677 const int len = strlen(i965->va_vendor);
3678 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
3681 i965->current_context_id = VA_INVALID_ID;
3683 ctx->str_vendor = i965->va_vendor;
3685 return i965_Init(ctx);