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>
30 #include "config_android.h"
41 # include "i965_output_dri.h"
44 #ifdef HAVE_VA_WAYLAND
45 # include "i965_output_wayland.h"
48 #include "intel_driver.h"
49 #include "intel_memman.h"
50 #include "intel_batchbuffer.h"
51 #include "i965_defines.h"
52 #include "i965_drv_video.h"
53 #include "i965_decoder.h"
54 #include "i965_encoder.h"
56 #define CONFIG_ID_OFFSET 0x01000000
57 #define CONTEXT_ID_OFFSET 0x02000000
58 #define SURFACE_ID_OFFSET 0x04000000
59 #define BUFFER_ID_OFFSET 0x08000000
60 #define IMAGE_ID_OFFSET 0x0a000000
61 #define SUBPIC_ID_OFFSET 0x10000000
63 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
66 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
69 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
72 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
75 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
78 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
81 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
83 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
85 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
87 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
89 static int get_sampling_from_fourcc(unsigned int fourcc);
91 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
92 #define IS_VA_X11(ctx) \
93 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
95 /* Check whether we are rendering to Wayland */
96 #define IS_VA_WAYLAND(ctx) \
97 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
100 I965_SURFACETYPE_RGBA = 1,
101 I965_SURFACETYPE_YUV,
102 I965_SURFACETYPE_INDEXED
105 /* List of supported display attributes */
106 static const VADisplayAttribute i965_display_attributes[] = {
108 VADisplayAttribRotation,
109 0, 3, VA_ROTATION_NONE,
110 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
114 /* List of supported image formats */
117 VAImageFormat va_format;
118 } i965_image_format_map_t;
120 static const i965_image_format_map_t
121 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
122 { I965_SURFACETYPE_YUV,
123 { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
124 { I965_SURFACETYPE_YUV,
125 { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
126 { I965_SURFACETYPE_YUV,
127 { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
128 { I965_SURFACETYPE_YUV,
129 { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } },
130 { I965_SURFACETYPE_YUV,
131 { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } },
132 { I965_SURFACETYPE_RGBA,
133 { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
134 { I965_SURFACETYPE_RGBA,
135 { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
138 /* List of supported subpicture formats */
142 VAImageFormat va_format;
143 unsigned int va_flags;
144 } i965_subpic_format_map_t;
146 #define COMMON_SUBPICTURE_FLAGS \
147 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
148 VA_SUBPICTURE_GLOBAL_ALPHA)
150 static const i965_subpic_format_map_t
151 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
152 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
153 { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
154 COMMON_SUBPICTURE_FLAGS },
155 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
156 { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
157 COMMON_SUBPICTURE_FLAGS },
158 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
159 { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, },
160 COMMON_SUBPICTURE_FLAGS },
161 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
162 { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, },
163 COMMON_SUBPICTURE_FLAGS },
164 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
165 { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
166 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
167 COMMON_SUBPICTURE_FLAGS },
168 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
169 { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
170 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
171 COMMON_SUBPICTURE_FLAGS },
174 static const i965_subpic_format_map_t *
175 get_subpic_format(const VAImageFormat *va_format)
178 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
179 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
180 if (m->va_format.fourcc == va_format->fourcc &&
181 (m->type == I965_SURFACETYPE_RGBA ?
182 (m->va_format.byte_order == va_format->byte_order &&
183 m->va_format.red_mask == va_format->red_mask &&
184 m->va_format.green_mask == va_format->green_mask &&
185 m->va_format.blue_mask == va_format->blue_mask &&
186 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
192 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
193 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
194 static struct hw_codec_info g4x_hw_codec_info = {
195 .dec_hw_context_init = g4x_dec_hw_context_init,
196 .enc_hw_context_init = NULL,
197 .proc_hw_context_init = NULL,
201 .has_mpeg2_decoding = 1,
204 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
205 static struct hw_codec_info ironlake_hw_codec_info = {
206 .dec_hw_context_init = ironlake_dec_hw_context_init,
207 .enc_hw_context_init = NULL,
208 .proc_hw_context_init = i965_proc_context_init,
212 .has_mpeg2_decoding = 1,
213 .has_h264_decoding = 1,
215 .has_accelerated_putimage = 1,
218 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
219 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
220 static struct hw_codec_info gen6_hw_codec_info = {
221 .dec_hw_context_init = gen6_dec_hw_context_init,
222 .enc_hw_context_init = gen6_enc_hw_context_init,
223 .proc_hw_context_init = i965_proc_context_init,
227 .has_mpeg2_decoding = 1,
228 .has_h264_decoding = 1,
229 .has_h264_encoding = 1,
230 .has_vc1_decoding = 1,
232 .has_accelerated_getimage = 1,
233 .has_accelerated_putimage = 1,
234 .has_tiled_surface = 1,
237 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
238 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
239 static struct hw_codec_info gen7_hw_codec_info = {
240 .dec_hw_context_init = gen7_dec_hw_context_init,
241 .enc_hw_context_init = gen7_enc_hw_context_init,
242 .proc_hw_context_init = i965_proc_context_init,
246 .has_mpeg2_decoding = 1,
247 .has_h264_decoding = 1,
248 .has_h264_encoding = 1,
249 .has_vc1_decoding = 1,
250 .has_jpeg_decoding = 1,
252 .has_accelerated_getimage = 1,
253 .has_accelerated_putimage = 1,
254 .has_tiled_surface = 1,
257 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
258 static struct hw_codec_info gen75_hw_codec_info = {
259 .dec_hw_context_init = gen75_dec_hw_context_init,
260 .enc_hw_context_init = gen75_enc_hw_context_init,
261 .proc_hw_context_init = gen75_proc_context_init,
265 .has_mpeg2_decoding = 1,
266 .has_mpeg2_encoding = 1,
267 .has_h264_decoding = 1,
268 .has_h264_encoding = 1,
269 .has_vc1_decoding = 1,
270 .has_jpeg_decoding = 1,
272 .has_accelerated_getimage = 1,
273 .has_accelerated_putimage = 1,
274 .has_tiled_surface = 1,
277 #define I965_PACKED_HEADER_BASE 0
278 #define I965_PACKED_MISC_HEADER_BASE 3
281 va_enc_packed_type_to_idx(int packed_type)
285 if (packed_type & VAEncPackedHeaderMiscMask) {
286 idx = I965_PACKED_MISC_HEADER_BASE;
287 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
288 assert(packed_type > 0);
289 idx += (packed_type - 1);
291 idx = I965_PACKED_HEADER_BASE;
293 switch (packed_type) {
294 case VAEncPackedHeaderSequence:
295 idx = I965_PACKED_HEADER_BASE + 0;
298 case VAEncPackedHeaderPicture:
299 idx = I965_PACKED_HEADER_BASE + 1;
302 case VAEncPackedHeaderSlice:
303 idx = I965_PACKED_HEADER_BASE + 2;
307 /* Should not get here */
319 i965_QueryConfigProfiles(VADriverContextP ctx,
320 VAProfile *profile_list, /* out */
321 int *num_profiles) /* out */
323 struct i965_driver_data * const i965 = i965_driver_data(ctx);
326 if (HAS_MPEG2_DECODING(i965) ||
327 HAS_MPEG2_ENCODING(i965)) {
328 profile_list[i++] = VAProfileMPEG2Simple;
329 profile_list[i++] = VAProfileMPEG2Main;
332 if (HAS_H264_DECODING(i965) ||
333 HAS_H264_ENCODING(i965)) {
334 profile_list[i++] = VAProfileH264Baseline;
335 profile_list[i++] = VAProfileH264Main;
336 profile_list[i++] = VAProfileH264High;
339 if (HAS_VC1_DECODING(i965)) {
340 profile_list[i++] = VAProfileVC1Simple;
341 profile_list[i++] = VAProfileVC1Main;
342 profile_list[i++] = VAProfileVC1Advanced;
346 profile_list[i++] = VAProfileNone;
349 if (HAS_JPEG_DECODING(i965)) {
350 profile_list[i++] = VAProfileJPEGBaseline;
353 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
354 assert(i <= I965_MAX_PROFILES);
357 return VA_STATUS_SUCCESS;
361 i965_QueryConfigEntrypoints(VADriverContextP ctx,
363 VAEntrypoint *entrypoint_list, /* out */
364 int *num_entrypoints) /* out */
366 struct i965_driver_data * const i965 = i965_driver_data(ctx);
370 case VAProfileMPEG2Simple:
371 case VAProfileMPEG2Main:
372 if (HAS_MPEG2_DECODING(i965))
373 entrypoint_list[n++] = VAEntrypointVLD;
375 if (HAS_MPEG2_ENCODING(i965))
376 entrypoint_list[n++] = VAEntrypointEncSlice;
380 case VAProfileH264Baseline:
381 case VAProfileH264Main:
382 case VAProfileH264High:
383 if (HAS_H264_DECODING(i965))
384 entrypoint_list[n++] = VAEntrypointVLD;
386 if (HAS_H264_ENCODING(i965))
387 entrypoint_list[n++] = VAEntrypointEncSlice;
391 case VAProfileVC1Simple:
392 case VAProfileVC1Main:
393 case VAProfileVC1Advanced:
394 if (HAS_VC1_DECODING(i965))
395 entrypoint_list[n++] = VAEntrypointVLD;
400 entrypoint_list[n++] = VAEntrypointVideoProc;
403 case VAProfileJPEGBaseline:
404 if (HAS_JPEG_DECODING(i965))
405 entrypoint_list[n++] = VAEntrypointVLD;
412 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
413 assert(n <= I965_MAX_ENTRYPOINTS);
414 *num_entrypoints = n;
415 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
419 i965_GetConfigAttributes(VADriverContextP ctx,
421 VAEntrypoint entrypoint,
422 VAConfigAttrib *attrib_list, /* in/out */
427 /* Other attributes don't seem to be defined */
428 /* What to do if we don't know the attribute? */
429 for (i = 0; i < num_attribs; i++) {
430 switch (attrib_list[i].type) {
431 case VAConfigAttribRTFormat:
432 attrib_list[i].value = VA_RT_FORMAT_YUV420;
435 case VAConfigAttribRateControl:
436 if (entrypoint == VAEntrypointEncSlice) {
437 attrib_list[i].value = VA_RC_CBR | VA_RC_CQP;
441 case VAConfigAttribEncPackedHeaders:
442 if (entrypoint == VAEntrypointEncSlice) {
443 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
449 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
454 return VA_STATUS_SUCCESS;
458 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
460 object_heap_free(heap, obj);
464 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
468 /* Check existing attrbiutes */
469 for (i = 0; i < obj_config->num_attribs; i++) {
470 if (obj_config->attrib_list[i].type == attrib->type) {
471 /* Update existing attribute */
472 obj_config->attrib_list[i].value = attrib->value;
473 return VA_STATUS_SUCCESS;
477 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
478 i = obj_config->num_attribs;
479 obj_config->attrib_list[i].type = attrib->type;
480 obj_config->attrib_list[i].value = attrib->value;
481 obj_config->num_attribs++;
482 return VA_STATUS_SUCCESS;
485 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
489 i965_CreateConfig(VADriverContextP ctx,
491 VAEntrypoint entrypoint,
492 VAConfigAttrib *attrib_list,
494 VAConfigID *config_id) /* out */
496 struct i965_driver_data * const i965 = i965_driver_data(ctx);
497 struct object_config *obj_config;
502 /* Validate profile & entrypoint */
504 case VAProfileMPEG2Simple:
505 case VAProfileMPEG2Main:
506 if ((HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
507 (HAS_MPEG2_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
508 vaStatus = VA_STATUS_SUCCESS;
510 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
514 case VAProfileH264Baseline:
515 case VAProfileH264Main:
516 case VAProfileH264High:
517 if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
518 (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
519 vaStatus = VA_STATUS_SUCCESS;
521 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
526 case VAProfileVC1Simple:
527 case VAProfileVC1Main:
528 case VAProfileVC1Advanced:
529 if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) {
530 vaStatus = VA_STATUS_SUCCESS;
532 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
538 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
539 vaStatus = VA_STATUS_SUCCESS;
541 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
546 case VAProfileJPEGBaseline:
547 if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) {
548 vaStatus = VA_STATUS_SUCCESS;
550 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
556 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
560 if (VA_STATUS_SUCCESS != vaStatus) {
564 configID = NEW_CONFIG_ID();
565 obj_config = CONFIG(configID);
567 if (NULL == obj_config) {
568 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
572 obj_config->profile = profile;
573 obj_config->entrypoint = entrypoint;
574 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
575 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
576 obj_config->num_attribs = 1;
578 for(i = 0; i < num_attribs; i++) {
579 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
581 if (VA_STATUS_SUCCESS != vaStatus) {
587 if (VA_STATUS_SUCCESS != vaStatus) {
588 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
590 *config_id = configID;
597 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
599 struct i965_driver_data *i965 = i965_driver_data(ctx);
600 struct object_config *obj_config = CONFIG(config_id);
603 if (NULL == obj_config) {
604 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
608 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
609 return VA_STATUS_SUCCESS;
612 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
613 VAConfigID config_id,
614 VAProfile *profile, /* out */
615 VAEntrypoint *entrypoint, /* out */
616 VAConfigAttrib *attrib_list, /* out */
617 int *num_attribs) /* out */
619 struct i965_driver_data *i965 = i965_driver_data(ctx);
620 struct object_config *obj_config = CONFIG(config_id);
621 VAStatus vaStatus = VA_STATUS_SUCCESS;
625 *profile = obj_config->profile;
626 *entrypoint = obj_config->entrypoint;
627 *num_attribs = obj_config->num_attribs;
629 for(i = 0; i < obj_config->num_attribs; i++) {
630 attrib_list[i] = obj_config->attrib_list[i];
637 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
639 struct object_surface *obj_surface = (struct object_surface *)obj;
641 dri_bo_unreference(obj_surface->bo);
642 obj_surface->bo = NULL;
644 if (obj_surface->free_private_data != NULL) {
645 obj_surface->free_private_data(&obj_surface->private_data);
646 obj_surface->private_data = NULL;
649 object_heap_free(heap, obj);
653 i965_CreateSurfaces2(
654 VADriverContextP ctx,
658 VASurfaceID *surfaces,
659 unsigned int num_surfaces,
660 VASurfaceAttrib *attrib_list,
661 unsigned int num_attribs
664 struct i965_driver_data *i965 = i965_driver_data(ctx);
666 VAStatus vaStatus = VA_STATUS_SUCCESS;
667 int expected_fourcc = 0;
669 for (i = 0; i < num_attribs && attrib_list; i++) {
670 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
671 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
672 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
673 expected_fourcc = attrib_list[i].value.value.i;
678 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
679 * for post-processing (including color conversion) */
680 if (VA_RT_FORMAT_YUV420 != format &&
681 VA_RT_FORMAT_YUV422 != format &&
682 VA_RT_FORMAT_RGB32 != format) {
683 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
686 for (i = 0; i < num_surfaces; i++) {
687 int surfaceID = NEW_SURFACE_ID();
688 struct object_surface *obj_surface = SURFACE(surfaceID);
690 if (NULL == obj_surface) {
691 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
695 surfaces[i] = surfaceID;
696 obj_surface->status = VASurfaceReady;
697 obj_surface->orig_width = width;
698 obj_surface->orig_height = height;
700 obj_surface->subpic_render_idx = 0;
701 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
702 obj_surface->subpic[j] = VA_INVALID_ID;
705 obj_surface->width = ALIGN(width, 16);
706 obj_surface->height = ALIGN(height, 16);
707 obj_surface->flags = SURFACE_REFERENCED;
708 obj_surface->fourcc = 0;
709 obj_surface->bo = NULL;
710 obj_surface->locked_image_id = VA_INVALID_ID;
711 obj_surface->private_data = NULL;
712 obj_surface->free_private_data = NULL;
713 obj_surface->subsampling = SUBSAMPLE_YUV420;
715 if (expected_fourcc) {
716 int tiling = HAS_TILED_SURFACE(i965);
718 if (expected_fourcc != VA_FOURCC('N', 'V', '1', '2') &&
719 expected_fourcc != VA_FOURCC('R', 'G', 'B', 'X') &&
720 expected_fourcc != VA_FOURCC('R', 'G', 'B', 'A') )
722 // todo, should we disable tiling for 422 format?
724 if (VA_RT_FORMAT_YUV420 == format) {
725 obj_surface->subsampling = SUBSAMPLE_YUV420;
727 else if (VA_RT_FORMAT_YUV422 == format) {
728 obj_surface->subsampling = SUBSAMPLE_YUV422H;
730 else if (VA_RT_FORMAT_RGB32 == format) {
731 obj_surface->subsampling = SUBSAMPLE_RGBX;
737 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, obj_surface->subsampling);
742 if (VA_STATUS_SUCCESS != vaStatus) {
743 /* surfaces[i-1] was the last successful allocation */
745 struct object_surface *obj_surface = SURFACE(surfaces[i]);
747 surfaces[i] = VA_INVALID_SURFACE;
749 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
757 i965_CreateSurfaces(VADriverContextP ctx,
762 VASurfaceID *surfaces) /* out */
764 return i965_CreateSurfaces2(ctx,
775 i965_DestroySurfaces(VADriverContextP ctx,
776 VASurfaceID *surface_list,
779 struct i965_driver_data *i965 = i965_driver_data(ctx);
782 for (i = num_surfaces; i--; ) {
783 struct object_surface *obj_surface = SURFACE(surface_list[i]);
786 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
789 return VA_STATUS_SUCCESS;
793 i965_QueryImageFormats(VADriverContextP ctx,
794 VAImageFormat *format_list, /* out */
795 int *num_formats) /* out */
799 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
800 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
802 format_list[n] = m->va_format;
808 return VA_STATUS_SUCCESS;
812 * Guess the format when the usage of a VA surface is unknown
813 * 1. Without a valid context: YV12
814 * 2. The current context is valid:
815 * a) always NV12 on GEN6 and later
816 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
819 i965_guess_surface_format(VADriverContextP ctx,
821 unsigned int *fourcc,
822 unsigned int *is_tiled)
824 struct i965_driver_data *i965 = i965_driver_data(ctx);
825 struct object_context *obj_context = NULL;
826 struct object_config *obj_config = NULL;
828 *fourcc = VA_FOURCC('Y', 'V', '1', '2');
831 if (i965->current_context_id == VA_INVALID_ID)
834 obj_context = CONTEXT(i965->current_context_id);
836 if (!obj_context || obj_context->config_id == VA_INVALID_ID)
839 obj_config = CONFIG(obj_context->config_id);
844 if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) {
845 *fourcc = VA_FOURCC('N', 'V', '1', '2');
850 switch (obj_config->profile) {
851 case VAProfileMPEG2Simple:
852 case VAProfileMPEG2Main:
853 *fourcc = VA_FOURCC('I', '4', '2', '0');
858 *fourcc = VA_FOURCC('N', 'V', '1', '2');
865 i965_QuerySubpictureFormats(VADriverContextP ctx,
866 VAImageFormat *format_list, /* out */
867 unsigned int *flags, /* out */
868 unsigned int *num_formats) /* out */
872 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
873 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
875 format_list[n] = m->va_format;
877 flags[n] = m->va_flags;
883 return VA_STATUS_SUCCESS;
887 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
889 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
891 object_heap_free(heap, obj);
895 i965_CreateSubpicture(VADriverContextP ctx,
897 VASubpictureID *subpicture) /* out */
899 struct i965_driver_data *i965 = i965_driver_data(ctx);
900 VASubpictureID subpicID = NEW_SUBPIC_ID()
901 struct object_subpic *obj_subpic = SUBPIC(subpicID);
904 return VA_STATUS_ERROR_ALLOCATION_FAILED;
906 struct object_image *obj_image = IMAGE(image);
908 return VA_STATUS_ERROR_INVALID_IMAGE;
910 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
912 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
914 *subpicture = subpicID;
915 obj_subpic->image = image;
916 obj_subpic->format = m->format;
917 obj_subpic->width = obj_image->image.width;
918 obj_subpic->height = obj_image->image.height;
919 obj_subpic->pitch = obj_image->image.pitches[0];
920 obj_subpic->bo = obj_image->bo;
921 obj_subpic->global_alpha = 1.0;
923 return VA_STATUS_SUCCESS;
927 i965_DestroySubpicture(VADriverContextP ctx,
928 VASubpictureID subpicture)
930 struct i965_driver_data *i965 = i965_driver_data(ctx);
931 struct object_subpic *obj_subpic = SUBPIC(subpicture);
932 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
933 return VA_STATUS_SUCCESS;
937 i965_SetSubpictureImage(VADriverContextP ctx,
938 VASubpictureID subpicture,
942 return VA_STATUS_ERROR_UNIMPLEMENTED;
946 i965_SetSubpictureChromakey(VADriverContextP ctx,
947 VASubpictureID subpicture,
948 unsigned int chromakey_min,
949 unsigned int chromakey_max,
950 unsigned int chromakey_mask)
953 return VA_STATUS_ERROR_UNIMPLEMENTED;
957 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
958 VASubpictureID subpicture,
961 struct i965_driver_data *i965 = i965_driver_data(ctx);
962 struct object_subpic *obj_subpic = SUBPIC(subpicture);
964 if(global_alpha > 1.0 || global_alpha < 0.0){
965 return VA_STATUS_ERROR_INVALID_PARAMETER;
967 obj_subpic->global_alpha = global_alpha;
969 return VA_STATUS_SUCCESS;
973 i965_AssociateSubpicture(VADriverContextP ctx,
974 VASubpictureID subpicture,
975 VASurfaceID *target_surfaces,
977 short src_x, /* upper left offset in subpicture */
979 unsigned short src_width,
980 unsigned short src_height,
981 short dest_x, /* upper left offset in surface */
983 unsigned short dest_width,
984 unsigned short dest_height,
986 * whether to enable chroma-keying or global-alpha
987 * see VA_SUBPICTURE_XXX values
991 struct i965_driver_data *i965 = i965_driver_data(ctx);
992 struct object_subpic *obj_subpic = SUBPIC(subpicture);
995 obj_subpic->src_rect.x = src_x;
996 obj_subpic->src_rect.y = src_y;
997 obj_subpic->src_rect.width = src_width;
998 obj_subpic->src_rect.height = src_height;
999 obj_subpic->dst_rect.x = dest_x;
1000 obj_subpic->dst_rect.y = dest_y;
1001 obj_subpic->dst_rect.width = dest_width;
1002 obj_subpic->dst_rect.height = dest_height;
1003 obj_subpic->flags = flags;
1005 for (i = 0; i < num_surfaces; i++) {
1006 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1008 return VA_STATUS_ERROR_INVALID_SURFACE;
1010 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1011 if(obj_surface->subpic[j] == VA_INVALID_ID){
1012 obj_surface->subpic[j] = subpicture;
1017 if(j == I965_MAX_SUBPIC_SUM){
1018 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1022 return VA_STATUS_SUCCESS;
1027 i965_DeassociateSubpicture(VADriverContextP ctx,
1028 VASubpictureID subpicture,
1029 VASurfaceID *target_surfaces,
1032 struct i965_driver_data *i965 = i965_driver_data(ctx);
1035 for (i = 0; i < num_surfaces; i++) {
1036 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1038 return VA_STATUS_ERROR_INVALID_SURFACE;
1040 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1041 if(obj_surface->subpic[j] == subpicture){
1042 obj_surface->subpic[j] = VA_INVALID_ID;
1047 if(j == I965_MAX_SUBPIC_SUM){
1048 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1051 return VA_STATUS_SUCCESS;
1055 i965_reference_buffer_store(struct buffer_store **ptr,
1056 struct buffer_store *buffer_store)
1058 assert(*ptr == NULL);
1061 buffer_store->ref_count++;
1062 *ptr = buffer_store;
1067 i965_release_buffer_store(struct buffer_store **ptr)
1069 struct buffer_store *buffer_store = *ptr;
1071 if (buffer_store == NULL)
1074 assert(buffer_store->bo || buffer_store->buffer);
1075 assert(!(buffer_store->bo && buffer_store->buffer));
1076 buffer_store->ref_count--;
1078 if (buffer_store->ref_count == 0) {
1079 dri_bo_unreference(buffer_store->bo);
1080 free(buffer_store->buffer);
1081 buffer_store->bo = NULL;
1082 buffer_store->buffer = NULL;
1090 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1092 struct object_context *obj_context = (struct object_context *)obj;
1095 if (obj_context->hw_context) {
1096 obj_context->hw_context->destroy(obj_context->hw_context);
1097 obj_context->hw_context = NULL;
1100 if (obj_context->codec_type == CODEC_PROC) {
1101 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1103 } else if (obj_context->codec_type == CODEC_ENC) {
1104 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1105 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1106 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1108 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1109 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1111 free(obj_context->codec_state.encode.slice_params);
1113 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1114 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1115 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1117 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1118 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1120 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1121 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1123 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1124 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1126 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1127 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1129 free(obj_context->codec_state.encode.slice_params_ext);
1131 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1132 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1134 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1135 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1136 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1138 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1139 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1141 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1142 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1144 free(obj_context->codec_state.decode.slice_params);
1145 free(obj_context->codec_state.decode.slice_datas);
1148 free(obj_context->render_targets);
1149 object_heap_free(heap, obj);
1153 i965_CreateContext(VADriverContextP ctx,
1154 VAConfigID config_id,
1158 VASurfaceID *render_targets,
1159 int num_render_targets,
1160 VAContextID *context) /* out */
1162 struct i965_driver_data *i965 = i965_driver_data(ctx);
1163 struct i965_render_state *render_state = &i965->render_state;
1164 struct object_config *obj_config = CONFIG(config_id);
1165 struct object_context *obj_context = NULL;
1166 VAStatus vaStatus = VA_STATUS_SUCCESS;
1170 if (NULL == obj_config) {
1171 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1175 if (picture_width > i965->codec_info->max_width ||
1176 picture_height > i965->codec_info->max_height) {
1177 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1182 /* Validate picture dimensions */
1183 contextID = NEW_CONTEXT_ID();
1184 obj_context = CONTEXT(contextID);
1186 if (NULL == obj_context) {
1187 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1191 render_state->inited = 1;
1193 switch (obj_config->profile) {
1194 case VAProfileH264Baseline:
1195 case VAProfileH264Main:
1196 case VAProfileH264High:
1197 if (!HAS_H264_DECODING(i965) &&
1198 !HAS_H264_ENCODING(i965))
1199 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1200 render_state->interleaved_uv = 1;
1203 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id));
1207 *context = contextID;
1208 obj_context->flags = flag;
1209 obj_context->context_id = contextID;
1210 obj_context->config_id = config_id;
1211 obj_context->picture_width = picture_width;
1212 obj_context->picture_height = picture_height;
1213 obj_context->num_render_targets = num_render_targets;
1214 obj_context->render_targets =
1215 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1216 obj_context->hw_context = NULL;
1218 for(i = 0; i < num_render_targets; i++) {
1219 if (NULL == SURFACE(render_targets[i])) {
1220 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1224 obj_context->render_targets[i] = render_targets[i];
1227 if (VA_STATUS_SUCCESS == vaStatus) {
1228 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1229 obj_context->codec_type = CODEC_PROC;
1230 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1231 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1232 assert(i965->codec_info->proc_hw_context_init);
1233 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1234 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1235 obj_context->codec_type = CODEC_ENC;
1236 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1237 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1238 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1239 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1240 sizeof(*obj_context->codec_state.encode.slice_params));
1241 assert(i965->codec_info->enc_hw_context_init);
1242 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1244 obj_context->codec_type = CODEC_DEC;
1245 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1246 obj_context->codec_state.decode.current_render_target = -1;
1247 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1248 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1249 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1250 sizeof(*obj_context->codec_state.decode.slice_params));
1251 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1252 sizeof(*obj_context->codec_state.decode.slice_datas));
1254 assert(i965->codec_info->dec_hw_context_init);
1255 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1259 /* Error recovery */
1260 if (VA_STATUS_SUCCESS != vaStatus) {
1261 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1264 i965->current_context_id = contextID;
1270 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1272 struct i965_driver_data *i965 = i965_driver_data(ctx);
1273 struct object_context *obj_context = CONTEXT(context);
1275 assert(obj_context);
1277 if (i965->current_context_id == context)
1278 i965->current_context_id = VA_INVALID_ID;
1280 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1282 return VA_STATUS_SUCCESS;
1286 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1288 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1290 assert(obj_buffer->buffer_store);
1291 i965_release_buffer_store(&obj_buffer->buffer_store);
1292 object_heap_free(heap, obj);
1296 i965_create_buffer_internal(VADriverContextP ctx,
1297 VAContextID context,
1300 unsigned int num_elements,
1305 struct i965_driver_data *i965 = i965_driver_data(ctx);
1306 struct object_buffer *obj_buffer = NULL;
1307 struct buffer_store *buffer_store = NULL;
1312 case VAPictureParameterBufferType:
1313 case VAIQMatrixBufferType:
1314 case VAQMatrixBufferType:
1315 case VABitPlaneBufferType:
1316 case VASliceGroupMapBufferType:
1317 case VASliceParameterBufferType:
1318 case VASliceDataBufferType:
1319 case VAMacroblockParameterBufferType:
1320 case VAResidualDataBufferType:
1321 case VADeblockingParameterBufferType:
1322 case VAImageBufferType:
1323 case VAEncCodedBufferType:
1324 case VAEncSequenceParameterBufferType:
1325 case VAEncPictureParameterBufferType:
1326 case VAEncSliceParameterBufferType:
1327 case VAEncPackedHeaderParameterBufferType:
1328 case VAEncPackedHeaderDataBufferType:
1329 case VAEncMiscParameterBufferType:
1330 case VAProcPipelineParameterBufferType:
1331 case VAProcFilterParameterBufferType:
1332 case VAHuffmanTableBufferType:
1337 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1340 bufferID = NEW_BUFFER_ID();
1341 obj_buffer = BUFFER(bufferID);
1343 if (NULL == obj_buffer) {
1344 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1347 if (type == VAEncCodedBufferType) {
1348 size += I965_CODEDBUFFER_HEADER_SIZE;
1349 size += 0x1000; /* for upper bound check */
1352 obj_buffer->max_num_elements = num_elements;
1353 obj_buffer->num_elements = num_elements;
1354 obj_buffer->size_element = size;
1355 obj_buffer->type = type;
1356 obj_buffer->buffer_store = NULL;
1357 buffer_store = calloc(1, sizeof(struct buffer_store));
1358 assert(buffer_store);
1359 buffer_store->ref_count = 1;
1361 if (store_bo != NULL) {
1362 buffer_store->bo = store_bo;
1363 dri_bo_reference(buffer_store->bo);
1366 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1367 } else if (type == VASliceDataBufferType ||
1368 type == VAImageBufferType ||
1369 type == VAEncCodedBufferType) {
1370 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1372 size * num_elements, 64);
1373 assert(buffer_store->bo);
1375 if (type == VAEncCodedBufferType) {
1376 struct i965_coded_buffer_segment *coded_buffer_segment;
1378 dri_bo_map(buffer_store->bo, 1);
1379 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1380 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1381 coded_buffer_segment->base.bit_offset = 0;
1382 coded_buffer_segment->base.status = 0;
1383 coded_buffer_segment->base.buf = NULL;
1384 coded_buffer_segment->base.next = NULL;
1385 coded_buffer_segment->mapped = 0;
1386 coded_buffer_segment->codec = 0;
1387 dri_bo_unmap(buffer_store->bo);
1389 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1395 if (type == VAEncPackedHeaderDataBufferType) {
1396 msize = ALIGN(size, 4);
1399 buffer_store->buffer = malloc(msize * num_elements);
1400 assert(buffer_store->buffer);
1403 memcpy(buffer_store->buffer, data, size * num_elements);
1406 buffer_store->num_elements = obj_buffer->num_elements;
1407 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1408 i965_release_buffer_store(&buffer_store);
1411 return VA_STATUS_SUCCESS;
1415 i965_CreateBuffer(VADriverContextP ctx,
1416 VAContextID context, /* in */
1417 VABufferType type, /* in */
1418 unsigned int size, /* in */
1419 unsigned int num_elements, /* in */
1420 void *data, /* in */
1421 VABufferID *buf_id) /* out */
1423 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1428 i965_BufferSetNumElements(VADriverContextP ctx,
1429 VABufferID buf_id, /* in */
1430 unsigned int num_elements) /* in */
1432 struct i965_driver_data *i965 = i965_driver_data(ctx);
1433 struct object_buffer *obj_buffer = BUFFER(buf_id);
1434 VAStatus vaStatus = VA_STATUS_SUCCESS;
1438 if ((num_elements < 0) ||
1439 (num_elements > obj_buffer->max_num_elements)) {
1440 vaStatus = VA_STATUS_ERROR_UNKNOWN;
1442 obj_buffer->num_elements = num_elements;
1443 if (obj_buffer->buffer_store != NULL) {
1444 obj_buffer->buffer_store->num_elements = num_elements;
1452 i965_MapBuffer(VADriverContextP ctx,
1453 VABufferID buf_id, /* in */
1454 void **pbuf) /* out */
1456 struct i965_driver_data *i965 = i965_driver_data(ctx);
1457 struct object_buffer *obj_buffer = BUFFER(buf_id);
1458 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1460 assert(obj_buffer && obj_buffer->buffer_store);
1461 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1462 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1464 if (NULL != obj_buffer->buffer_store->bo) {
1465 unsigned int tiling, swizzle;
1467 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1469 if (tiling != I915_TILING_NONE)
1470 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1472 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1474 assert(obj_buffer->buffer_store->bo->virtual);
1475 *pbuf = obj_buffer->buffer_store->bo->virtual;
1477 if (obj_buffer->type == VAEncCodedBufferType) {
1479 unsigned char *buffer = NULL;
1480 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1482 if (!coded_buffer_segment->mapped) {
1483 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1485 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1487 if (coded_buffer_segment->codec == CODED_H264) {
1488 delimiter0 = H264_DELIMITER0;
1489 delimiter1 = H264_DELIMITER1;
1490 delimiter2 = H264_DELIMITER2;
1491 delimiter3 = H264_DELIMITER3;
1492 delimiter4 = H264_DELIMITER4;
1493 } else if (coded_buffer_segment->codec == CODED_MPEG2) {
1494 delimiter0 = MPEG2_DELIMITER0;
1495 delimiter1 = MPEG2_DELIMITER1;
1496 delimiter2 = MPEG2_DELIMITER2;
1497 delimiter3 = MPEG2_DELIMITER3;
1498 delimiter4 = MPEG2_DELIMITER4;
1503 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1504 if ((buffer[i] == delimiter0) &&
1505 (buffer[i + 1] == delimiter1) &&
1506 (buffer[i + 2] == delimiter2) &&
1507 (buffer[i + 3] == delimiter3) &&
1508 (buffer[i + 4] == delimiter4))
1512 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1513 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1516 coded_buffer_segment->base.size = i;
1517 coded_buffer_segment->mapped = 1;
1519 assert(coded_buffer_segment->base.buf);
1523 vaStatus = VA_STATUS_SUCCESS;
1524 } else if (NULL != obj_buffer->buffer_store->buffer) {
1525 *pbuf = obj_buffer->buffer_store->buffer;
1526 vaStatus = VA_STATUS_SUCCESS;
1533 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1535 struct i965_driver_data *i965 = i965_driver_data(ctx);
1536 struct object_buffer *obj_buffer = BUFFER(buf_id);
1537 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1539 assert(obj_buffer && obj_buffer->buffer_store);
1540 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1541 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1543 if (NULL != obj_buffer->buffer_store->bo) {
1544 unsigned int tiling, swizzle;
1546 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1548 if (tiling != I915_TILING_NONE)
1549 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1551 dri_bo_unmap(obj_buffer->buffer_store->bo);
1553 vaStatus = VA_STATUS_SUCCESS;
1554 } else if (NULL != obj_buffer->buffer_store->buffer) {
1556 vaStatus = VA_STATUS_SUCCESS;
1563 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1565 struct i965_driver_data *i965 = i965_driver_data(ctx);
1566 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1569 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1571 return VA_STATUS_SUCCESS;
1575 i965_BeginPicture(VADriverContextP ctx,
1576 VAContextID context,
1577 VASurfaceID render_target)
1579 struct i965_driver_data *i965 = i965_driver_data(ctx);
1580 struct object_context *obj_context = CONTEXT(context);
1581 struct object_surface *obj_surface = SURFACE(render_target);
1582 struct object_config *obj_config;
1587 assert(obj_context);
1588 assert(obj_surface);
1590 config = obj_context->config_id;
1591 obj_config = CONFIG(config);
1594 switch (obj_config->profile) {
1595 case VAProfileMPEG2Simple:
1596 case VAProfileMPEG2Main:
1597 vaStatus = VA_STATUS_SUCCESS;
1600 case VAProfileH264Baseline:
1601 case VAProfileH264Main:
1602 case VAProfileH264High:
1603 vaStatus = VA_STATUS_SUCCESS;
1606 case VAProfileVC1Simple:
1607 case VAProfileVC1Main:
1608 case VAProfileVC1Advanced:
1609 vaStatus = VA_STATUS_SUCCESS;
1612 case VAProfileJPEGBaseline:
1613 vaStatus = VA_STATUS_SUCCESS;
1617 vaStatus = VA_STATUS_SUCCESS;
1622 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1626 if (obj_context->codec_type == CODEC_PROC) {
1627 obj_context->codec_state.proc.current_render_target = render_target;
1628 } else if (obj_context->codec_type == CODEC_ENC) {
1629 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1631 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
1632 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1635 obj_context->codec_state.encode.num_slice_params = 0;
1638 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1640 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1641 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1643 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1644 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1646 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1647 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1649 obj_context->codec_state.encode.num_slice_params_ext = 0;
1650 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
1651 obj_context->codec_state.encode.last_packed_header_type = 0;
1653 obj_context->codec_state.decode.current_render_target = render_target;
1654 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1655 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1656 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1657 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
1659 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
1660 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1661 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1664 obj_context->codec_state.decode.num_slice_params = 0;
1665 obj_context->codec_state.decode.num_slice_datas = 0;
1671 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
1673 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
1675 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1676 struct object_context *obj_context, \
1677 struct object_buffer *obj_buffer) \
1679 struct category##_state *category = &obj_context->codec_state.category; \
1680 assert(obj_buffer->buffer_store->bo == NULL); \
1681 assert(obj_buffer->buffer_store->buffer); \
1682 i965_release_buffer_store(&category->member); \
1683 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
1684 return VA_STATUS_SUCCESS; \
1687 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
1689 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
1690 struct object_context *obj_context, \
1691 struct object_buffer *obj_buffer) \
1693 struct category##_state *category = &obj_context->codec_state.category; \
1694 if (category->num_##member == category->max_##member) { \
1695 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
1696 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
1697 category->max_##member += NUM_SLICES; \
1699 i965_release_buffer_store(&category->member[category->num_##member]); \
1700 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
1701 category->num_##member++; \
1702 return VA_STATUS_SUCCESS; \
1705 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
1707 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
1708 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
1709 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
1710 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
1711 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
1713 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
1714 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
1715 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
1718 i965_decoder_render_picture(VADriverContextP ctx,
1719 VAContextID context,
1720 VABufferID *buffers,
1723 struct i965_driver_data *i965 = i965_driver_data(ctx);
1724 struct object_context *obj_context = CONTEXT(context);
1725 VAStatus vaStatus = VA_STATUS_SUCCESS;
1728 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
1729 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1732 switch (obj_buffer->type) {
1733 case VAPictureParameterBufferType:
1734 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
1737 case VAIQMatrixBufferType:
1738 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
1741 case VABitPlaneBufferType:
1742 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
1745 case VASliceParameterBufferType:
1746 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
1749 case VASliceDataBufferType:
1750 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
1753 case VAHuffmanTableBufferType:
1754 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
1758 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1766 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
1768 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
1769 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
1770 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
1771 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
1772 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
1773 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
1774 /* extended buffer */
1775 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
1776 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
1778 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
1779 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
1780 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
1783 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
1784 struct object_context *obj_context,
1785 struct object_buffer *obj_buffer,
1788 struct encode_state *encode = &obj_context->codec_state.encode;
1790 assert(obj_buffer->buffer_store->bo == NULL);
1791 assert(obj_buffer->buffer_store->buffer);
1792 i965_release_buffer_store(&encode->packed_header_param[type_index]);
1793 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
1795 return VA_STATUS_SUCCESS;
1799 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
1800 struct object_context *obj_context,
1801 struct object_buffer *obj_buffer,
1804 struct encode_state *encode = &obj_context->codec_state.encode;
1806 assert(obj_buffer->buffer_store->bo == NULL);
1807 assert(obj_buffer->buffer_store->buffer);
1808 i965_release_buffer_store(&encode->packed_header_data[type_index]);
1809 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
1811 return VA_STATUS_SUCCESS;
1815 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
1816 struct object_context *obj_context,
1817 struct object_buffer *obj_buffer)
1819 struct encode_state *encode = &obj_context->codec_state.encode;
1820 VAEncMiscParameterBuffer *param = NULL;
1822 assert(obj_buffer->buffer_store->bo == NULL);
1823 assert(obj_buffer->buffer_store->buffer);
1825 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
1826 i965_release_buffer_store(&encode->misc_param[param->type]);
1827 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
1829 return VA_STATUS_SUCCESS;
1833 i965_encoder_render_picture(VADriverContextP ctx,
1834 VAContextID context,
1835 VABufferID *buffers,
1838 struct i965_driver_data *i965 = i965_driver_data(ctx);
1839 struct object_context *obj_context = CONTEXT(context);
1840 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1843 for (i = 0; i < num_buffers; i++) {
1844 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1847 switch (obj_buffer->type) {
1848 case VAQMatrixBufferType:
1849 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
1852 case VAIQMatrixBufferType:
1853 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
1856 case VAEncSequenceParameterBufferType:
1857 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
1860 case VAEncPictureParameterBufferType:
1861 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
1864 case VAEncSliceParameterBufferType:
1865 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
1868 case VAEncPackedHeaderParameterBufferType:
1870 struct encode_state *encode = &obj_context->codec_state.encode;
1871 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
1872 encode->last_packed_header_type = param->type;
1874 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
1877 va_enc_packed_type_to_idx(encode->last_packed_header_type));
1881 case VAEncPackedHeaderDataBufferType:
1883 struct encode_state *encode = &obj_context->codec_state.encode;
1885 assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
1886 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
1887 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
1888 ((encode->last_packed_header_type & VAEncPackedHeaderMiscMask == VAEncPackedHeaderMiscMask) &&
1889 (encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask) != 0)));
1890 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
1893 va_enc_packed_type_to_idx(encode->last_packed_header_type));
1897 case VAEncMiscParameterBufferType:
1898 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
1904 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1912 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
1914 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
1915 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
1918 i965_proc_render_picture(VADriverContextP ctx,
1919 VAContextID context,
1920 VABufferID *buffers,
1923 struct i965_driver_data *i965 = i965_driver_data(ctx);
1924 struct object_context *obj_context = CONTEXT(context);
1925 VAStatus vaStatus = VA_STATUS_SUCCESS;
1928 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
1929 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
1932 switch (obj_buffer->type) {
1933 case VAProcPipelineParameterBufferType:
1934 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
1938 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1947 i965_RenderPicture(VADriverContextP ctx,
1948 VAContextID context,
1949 VABufferID *buffers,
1952 struct i965_driver_data *i965 = i965_driver_data(ctx);
1953 struct object_context *obj_context;
1954 struct object_config *obj_config;
1956 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1958 obj_context = CONTEXT(context);
1959 assert(obj_context);
1961 config = obj_context->config_id;
1962 obj_config = CONFIG(config);
1965 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1966 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
1967 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
1968 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
1970 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
1977 i965_EndPicture(VADriverContextP ctx, VAContextID context)
1979 struct i965_driver_data *i965 = i965_driver_data(ctx);
1980 struct object_context *obj_context = CONTEXT(context);
1981 struct object_config *obj_config;
1984 assert(obj_context);
1985 config = obj_context->config_id;
1986 obj_config = CONFIG(config);
1989 if (obj_context->codec_type == CODEC_PROC) {
1990 assert(VAEntrypointVideoProc == obj_config->entrypoint);
1991 } else if (obj_context->codec_type == CODEC_ENC) {
1992 assert(VAEntrypointEncSlice == obj_config->entrypoint);
1994 assert(obj_context->codec_state.encode.pic_param ||
1995 obj_context->codec_state.encode.pic_param_ext);
1996 assert(obj_context->codec_state.encode.seq_param ||
1997 obj_context->codec_state.encode.seq_param_ext);
1998 assert(obj_context->codec_state.encode.num_slice_params >= 1 ||
1999 obj_context->codec_state.encode.num_slice_params_ext >= 1);
2001 assert(obj_context->codec_state.decode.pic_param);
2002 assert(obj_context->codec_state.decode.num_slice_params >= 1);
2003 assert(obj_context->codec_state.decode.num_slice_datas >= 1);
2004 assert(obj_context->codec_state.decode.num_slice_params == obj_context->codec_state.decode.num_slice_datas);
2007 assert(obj_context->hw_context->run);
2008 obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2010 return VA_STATUS_SUCCESS;
2014 i965_SyncSurface(VADriverContextP ctx,
2015 VASurfaceID render_target)
2017 struct i965_driver_data *i965 = i965_driver_data(ctx);
2018 struct object_surface *obj_surface = SURFACE(render_target);
2020 assert(obj_surface);
2023 drm_intel_bo_wait_rendering(obj_surface->bo);
2025 return VA_STATUS_SUCCESS;
2029 i965_QuerySurfaceStatus(VADriverContextP ctx,
2030 VASurfaceID render_target,
2031 VASurfaceStatus *status) /* out */
2033 struct i965_driver_data *i965 = i965_driver_data(ctx);
2034 struct object_surface *obj_surface = SURFACE(render_target);
2036 assert(obj_surface);
2038 if (obj_surface->bo) {
2039 if (drm_intel_bo_busy(obj_surface->bo)){
2040 *status = VASurfaceRendering;
2043 *status = VASurfaceReady;
2046 *status = VASurfaceReady;
2049 return VA_STATUS_SUCCESS;
2052 static VADisplayAttribute *
2053 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2055 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2058 if (!i965->display_attributes)
2061 for (i = 0; i < i965->num_display_attributes; i++) {
2062 if (i965->display_attributes[i].type == type)
2063 return &i965->display_attributes[i];
2069 i965_display_attributes_init(VADriverContextP ctx)
2071 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2073 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2074 i965->display_attributes = malloc(
2075 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2076 if (!i965->display_attributes)
2080 i965->display_attributes,
2081 i965_display_attributes,
2082 sizeof(i965_display_attributes)
2085 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2086 if (!i965->rotation_attrib)
2092 i965_display_attributes_terminate(VADriverContextP ctx)
2094 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2096 if (i965->display_attributes) {
2097 free(i965->display_attributes);
2098 i965->display_attributes = NULL;
2099 i965->num_display_attributes = 0;
2104 * Query display attributes
2105 * The caller must provide a "attr_list" array that can hold at
2106 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2107 * returned in "attr_list" is returned in "num_attributes".
2110 i965_QueryDisplayAttributes(
2111 VADriverContextP ctx,
2112 VADisplayAttribute *attribs, /* out */
2113 int *num_attribs_ptr /* out */
2116 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2118 if (attribs && num_attribs > 0)
2119 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2121 if (num_attribs_ptr)
2122 *num_attribs_ptr = num_attribs;
2124 return VA_STATUS_SUCCESS;
2128 * Get display attributes
2129 * This function returns the current attribute values in "attr_list".
2130 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2131 * from vaQueryDisplayAttributes() can have their values retrieved.
2134 i965_GetDisplayAttributes(
2135 VADriverContextP ctx,
2136 VADisplayAttribute *attribs, /* inout */
2137 int num_attribs /* in */
2142 for (i = 0; i < num_attribs; i++) {
2143 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2145 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2146 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2147 dst_attrib->min_value = src_attrib->min_value;
2148 dst_attrib->max_value = src_attrib->max_value;
2149 dst_attrib->value = src_attrib->value;
2152 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2154 return VA_STATUS_SUCCESS;
2158 * Set display attributes
2159 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2160 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2161 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2164 i965_SetDisplayAttributes(
2165 VADriverContextP ctx,
2166 VADisplayAttribute *attribs, /* in */
2167 int num_attribs /* in */
2172 for (i = 0; i < num_attribs; i++) {
2173 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2175 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2177 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2179 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2182 if (src_attrib->value < dst_attrib->min_value ||
2183 src_attrib->value > dst_attrib->max_value)
2184 return VA_STATUS_ERROR_INVALID_PARAMETER;
2186 dst_attrib->value = src_attrib->value;
2187 /* XXX: track modified attributes through timestamps */
2189 return VA_STATUS_SUCCESS;
2193 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2194 VASurfaceID surface,
2195 void **buffer, /* out */
2196 unsigned int *stride) /* out */
2199 return VA_STATUS_ERROR_UNIMPLEMENTED;
2203 i965_Init(VADriverContextP ctx)
2205 struct i965_driver_data *i965 = i965_driver_data(ctx);
2207 if (intel_driver_init(ctx) == False)
2208 return VA_STATUS_ERROR_UNKNOWN;
2210 if (IS_HASWELL(i965->intel.device_id))
2211 i965->codec_info = &gen75_hw_codec_info;
2212 else if (IS_G4X(i965->intel.device_id))
2213 i965->codec_info = &g4x_hw_codec_info;
2214 else if (IS_IRONLAKE(i965->intel.device_id))
2215 i965->codec_info = &ironlake_hw_codec_info;
2216 else if (IS_GEN6(i965->intel.device_id))
2217 i965->codec_info = &gen6_hw_codec_info;
2218 else if (IS_GEN7(i965->intel.device_id))
2219 i965->codec_info = &gen7_hw_codec_info;
2221 return VA_STATUS_ERROR_UNKNOWN;
2223 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
2225 if (!i965_display_attributes_init(ctx))
2226 return VA_STATUS_ERROR_UNKNOWN;
2228 if (i965_post_processing_init(ctx) == False)
2229 return VA_STATUS_ERROR_UNKNOWN;
2231 if (i965_render_init(ctx) == False)
2232 return VA_STATUS_ERROR_UNKNOWN;
2234 #ifdef HAVE_VA_WAYLAND
2235 if (IS_VA_WAYLAND(ctx) && !i965_output_wayland_init(ctx))
2236 return VA_STATUS_ERROR_UNKNOWN;
2240 if (IS_VA_X11(ctx) && !i965_output_dri_init(ctx))
2241 return VA_STATUS_ERROR_UNKNOWN;
2244 _i965InitMutex(&i965->render_mutex);
2245 _i965InitMutex(&i965->pp_mutex);
2247 return VA_STATUS_SUCCESS;
2251 i965_destroy_heap(struct object_heap *heap,
2252 void (*func)(struct object_heap *heap, struct object_base *object))
2254 struct object_base *object;
2255 object_heap_iterator iter;
2257 object = object_heap_first(heap, &iter);
2263 object = object_heap_next(heap, &iter);
2266 object_heap_destroy(heap);
2271 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2274 i965_CreateImage(VADriverContextP ctx,
2275 VAImageFormat *format,
2278 VAImage *out_image) /* out */
2280 struct i965_driver_data *i965 = i965_driver_data(ctx);
2281 struct object_image *obj_image;
2282 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2284 unsigned int width2, height2, size2, size;
2286 out_image->image_id = VA_INVALID_ID;
2287 out_image->buf = VA_INVALID_ID;
2289 image_id = NEW_IMAGE_ID();
2290 if (image_id == VA_INVALID_ID)
2291 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2293 obj_image = IMAGE(image_id);
2295 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2296 obj_image->bo = NULL;
2297 obj_image->palette = NULL;
2298 obj_image->derived_surface = VA_INVALID_ID;
2300 VAImage * const image = &obj_image->image;
2301 image->image_id = image_id;
2302 image->buf = VA_INVALID_ID;
2304 size = width * height;
2305 width2 = (width + 1) / 2;
2306 height2 = (height + 1) / 2;
2307 size2 = width2 * height2;
2309 image->num_palette_entries = 0;
2310 image->entry_bytes = 0;
2311 memset(image->component_order, 0, sizeof(image->component_order));
2313 switch (format->fourcc) {
2314 case VA_FOURCC('I','A','4','4'):
2315 case VA_FOURCC('A','I','4','4'):
2316 image->num_planes = 1;
2317 image->pitches[0] = width;
2318 image->offsets[0] = 0;
2319 image->data_size = image->offsets[0] + image->pitches[0] * height;
2320 image->num_palette_entries = 16;
2321 image->entry_bytes = 3;
2322 image->component_order[0] = 'R';
2323 image->component_order[1] = 'G';
2324 image->component_order[2] = 'B';
2326 case VA_FOURCC('B','G','R','A'):
2327 case VA_FOURCC('R','G','B','A'):
2328 case VA_FOURCC('B','G','R','X'):
2329 case VA_FOURCC('R','G','B','X'):
2330 image->num_planes = 1;
2331 image->pitches[0] = width * 4;
2332 image->offsets[0] = 0;
2333 image->data_size = image->offsets[0] + image->pitches[0] * height;
2335 case VA_FOURCC('Y','V','1','2'):
2336 image->num_planes = 3;
2337 image->pitches[0] = width;
2338 image->offsets[0] = 0;
2339 image->pitches[1] = width2;
2340 image->offsets[1] = size + size2;
2341 image->pitches[2] = width2;
2342 image->offsets[2] = size;
2343 image->data_size = size + 2 * size2;
2345 case VA_FOURCC('I','4','2','0'):
2346 image->num_planes = 3;
2347 image->pitches[0] = width;
2348 image->offsets[0] = 0;
2349 image->pitches[1] = width2;
2350 image->offsets[1] = size;
2351 image->pitches[2] = width2;
2352 image->offsets[2] = size + size2;
2353 image->data_size = size + 2 * size2;
2355 case VA_FOURCC('N','V','1','2'):
2356 image->num_planes = 2;
2357 image->pitches[0] = width;
2358 image->offsets[0] = 0;
2359 image->pitches[1] = width;
2360 image->offsets[1] = size;
2361 image->data_size = size + 2 * size2;
2363 case VA_FOURCC('Y','U','Y','2'):
2364 case VA_FOURCC('U','Y','V','Y'):
2365 image->num_planes = 1;
2366 image->pitches[0] = width * 2;
2367 image->offsets[0] = 0;
2368 image->data_size = size * 2;
2374 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2375 image->data_size, 1, NULL, &image->buf);
2376 if (va_status != VA_STATUS_SUCCESS)
2379 obj_image->bo = BUFFER(image->buf)->buffer_store->bo;
2380 dri_bo_reference(obj_image->bo);
2382 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2383 obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette));
2384 if (!obj_image->palette)
2388 image->image_id = image_id;
2389 image->format = *format;
2390 image->width = width;
2391 image->height = height;
2393 *out_image = *image;
2394 return VA_STATUS_SUCCESS;
2397 i965_DestroyImage(ctx, image_id);
2402 i965_check_alloc_surface_bo(VADriverContextP ctx,
2403 struct object_surface *obj_surface,
2405 unsigned int fourcc,
2406 unsigned int subsampling)
2408 struct i965_driver_data *i965 = i965_driver_data(ctx);
2409 int region_width, region_height;
2411 if (obj_surface->bo) {
2412 assert(obj_surface->fourcc);
2413 assert(obj_surface->fourcc == fourcc);
2414 assert(obj_surface->subsampling == subsampling);
2418 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2419 obj_surface->x_cr_offset = 0;
2422 assert(fourcc == VA_FOURCC('N', 'V', '1', '2') ||
2423 fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
2424 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
2425 fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2426 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2427 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2428 fourcc == VA_FOURCC('B', 'G', 'R', 'X') ||
2429 fourcc == VA_FOURCC('Y', 'U', 'Y', '2'));
2431 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2432 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2433 region_height = obj_surface->height;
2435 if (fourcc == VA_FOURCC('N', 'V', '1', '2') ||
2436 fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
2437 fourcc == VA_FOURCC('I', 'M', 'C', '3')) {
2438 obj_surface->cb_cr_pitch = obj_surface->width;
2439 region_width = obj_surface->width;
2441 else if (fourcc == VA_FOURCC('Y','U', 'Y', '2')) {
2442 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2443 region_width = obj_surface->width * 2;
2445 else if (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2446 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2447 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2448 fourcc == VA_FOURCC('B', 'G', 'R', 'X')) {
2449 region_width = obj_surface->width * 4;
2456 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2457 assert(subsampling == SUBSAMPLE_YUV420);
2458 obj_surface->y_cb_offset = obj_surface->height;
2459 obj_surface->y_cr_offset = obj_surface->height;
2460 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2461 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2462 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2463 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
2464 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
2465 fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2466 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2467 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2468 fourcc == VA_FOURCC('B', 'G', 'R', 'X') ||
2469 fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
2470 switch (subsampling) {
2471 case SUBSAMPLE_YUV400:
2472 obj_surface->cb_cr_width = 0;
2473 obj_surface->cb_cr_height = 0;
2476 case SUBSAMPLE_YUV420:
2477 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2478 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2481 case SUBSAMPLE_YUV422H:
2482 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2483 obj_surface->cb_cr_height = obj_surface->orig_height;
2486 case SUBSAMPLE_YUV422V:
2487 obj_surface->cb_cr_width = obj_surface->orig_width;
2488 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2491 case SUBSAMPLE_YUV444:
2492 obj_surface->cb_cr_width = obj_surface->orig_width;
2493 obj_surface->cb_cr_height = obj_surface->orig_height;
2496 case SUBSAMPLE_YUV411:
2497 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2498 obj_surface->cb_cr_height = obj_surface->orig_height;
2500 case SUBSAMPLE_RGBX:
2507 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2509 if (fourcc == VA_FOURCC('I', 'M', 'C', '1')) {
2510 obj_surface->y_cr_offset = obj_surface->height;
2511 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2512 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '3')){
2513 obj_surface->y_cb_offset = obj_surface->height;
2514 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2516 else if (fourcc == VA_FOURCC('Y','U', 'Y', '2')) {
2517 obj_surface->y_cb_offset = 0;
2518 obj_surface->y_cr_offset = 0;
2519 region_height = obj_surface->height;
2521 else if (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2522 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2523 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2524 fourcc == VA_FOURCC('B', 'G', 'R', 'X')) {
2525 region_height = obj_surface->height;
2529 assert(fourcc != VA_FOURCC('I', 'M', 'C', '1') &&
2530 fourcc != VA_FOURCC('I', 'M', 'C', '3'));
2531 assert(subsampling == SUBSAMPLE_YUV420 ||
2532 subsampling == SUBSAMPLE_YUV422H ||
2533 subsampling == SUBSAMPLE_YUV422V ||
2534 subsampling == SUBSAMPLE_RGBX);
2536 region_width = obj_surface->width;
2537 region_height = obj_surface->height;
2540 case VA_FOURCC('N', 'V', '1', '2'):
2541 obj_surface->y_cb_offset = obj_surface->height;
2542 obj_surface->y_cr_offset = obj_surface->height;
2543 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2544 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2545 obj_surface->cb_cr_pitch = obj_surface->width;
2546 region_height = obj_surface->height + obj_surface->height / 2;
2549 case VA_FOURCC('Y', 'V', '1', '2'):
2550 case VA_FOURCC('I', '4', '2', '0'):
2551 if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
2552 obj_surface->y_cr_offset = obj_surface->height;
2553 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
2555 obj_surface->y_cb_offset = obj_surface->height;
2556 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
2559 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2560 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2561 obj_surface->cb_cr_pitch = obj_surface->width / 2;
2562 region_height = obj_surface->height + obj_surface->height / 2;
2565 case VA_FOURCC('Y','U', 'Y', '2'):
2566 obj_surface->y_cb_offset = 0;
2567 obj_surface->y_cr_offset = 0;
2568 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2569 obj_surface->cb_cr_height = obj_surface->orig_height;
2570 obj_surface->cb_cr_pitch = obj_surface->width * 2;
2571 region_width = obj_surface->width * 2;
2572 region_height = obj_surface->height;
2574 case VA_FOURCC('R', 'G', 'B', 'A'):
2575 case VA_FOURCC('R', 'G', 'B', 'X'):
2576 case VA_FOURCC('B', 'G', 'R', 'A'):
2577 case VA_FOURCC('B', 'G', 'R', 'X'):
2578 region_width = obj_surface->width * 4;
2579 region_height = obj_surface->height;
2588 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
2591 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
2592 unsigned long pitch;
2594 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
2602 assert(tiling_mode == I915_TILING_Y);
2603 assert(pitch == obj_surface->width ||
2604 pitch == obj_surface->width * 2 ||
2605 pitch == obj_surface->width * 4) ;
2607 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
2613 obj_surface->fourcc = fourcc;
2614 obj_surface->subsampling = subsampling;
2615 assert(obj_surface->bo);
2618 VAStatus i965_DeriveImage(VADriverContextP ctx,
2619 VASurfaceID surface,
2620 VAImage *out_image) /* out */
2622 struct i965_driver_data *i965 = i965_driver_data(ctx);
2623 struct object_image *obj_image;
2624 struct object_surface *obj_surface;
2626 unsigned int w_pitch, h_pitch;
2627 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2629 out_image->image_id = VA_INVALID_ID;
2630 obj_surface = SURFACE(surface);
2633 return VA_STATUS_ERROR_INVALID_SURFACE;
2635 if (!obj_surface->bo) {
2636 unsigned int is_tiled = 0;
2637 unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
2638 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
2639 int sampling = get_sampling_from_fourcc(fourcc);
2640 i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
2643 assert(obj_surface->fourcc);
2645 w_pitch = obj_surface->width;
2646 h_pitch = obj_surface->height;
2648 image_id = NEW_IMAGE_ID();
2650 if (image_id == VA_INVALID_ID)
2651 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2653 obj_image = IMAGE(image_id);
2656 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2658 obj_image->bo = NULL;
2659 obj_image->palette = NULL;
2660 obj_image->derived_surface = VA_INVALID_ID;
2662 VAImage * const image = &obj_image->image;
2664 memset(image, 0, sizeof(*image));
2665 image->image_id = image_id;
2666 image->buf = VA_INVALID_ID;
2667 image->num_palette_entries = 0;
2668 image->entry_bytes = 0;
2669 image->width = obj_surface->orig_width;
2670 image->height = obj_surface->orig_height;
2671 image->data_size = obj_surface->size;
2673 image->format.fourcc = obj_surface->fourcc;
2674 image->format.byte_order = VA_LSB_FIRST;
2675 image->format.bits_per_pixel = 12;
2677 switch (image->format.fourcc) {
2678 case VA_FOURCC('Y', 'V', '1', '2'):
2679 image->num_planes = 3;
2680 image->pitches[0] = w_pitch; /* Y */
2681 image->offsets[0] = 0;
2682 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
2683 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
2684 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
2685 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
2688 case VA_FOURCC('N', 'V', '1', '2'):
2689 image->num_planes = 2;
2690 image->pitches[0] = w_pitch; /* Y */
2691 image->offsets[0] = 0;
2692 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
2693 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
2696 case VA_FOURCC('I', '4', '2', '0'):
2697 image->num_planes = 3;
2698 image->pitches[0] = w_pitch; /* Y */
2699 image->offsets[0] = 0;
2700 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
2701 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
2702 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
2703 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
2705 case VA_FOURCC('Y', 'U', 'Y', '2'):
2706 image->num_planes = 1;
2707 image->pitches[0] = obj_surface->width * 2; /* Y, width is aligned already */
2708 image->offsets[0] = 0;
2709 image->pitches[1] = obj_surface->width * 2; /* U */
2710 image->offsets[1] = 0;
2711 image->pitches[2] = obj_surface->width * 2; /* V */
2712 image->offsets[2] = 0;
2714 case VA_FOURCC('R', 'G', 'B', 'A'):
2715 case VA_FOURCC('R', 'G', 'B', 'X'):
2716 case VA_FOURCC('B', 'G', 'R', 'A'):
2717 case VA_FOURCC('B', 'G', 'R', 'X'):
2718 image->num_planes = 1;
2719 image->pitches[0] = obj_surface->width * 4;
2725 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
2726 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
2727 if (va_status != VA_STATUS_SUCCESS)
2730 obj_image->bo = BUFFER(image->buf)->buffer_store->bo;
2731 dri_bo_reference(obj_image->bo);
2733 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2734 obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette));
2735 if (!obj_image->palette) {
2736 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
2741 *out_image = *image;
2742 obj_surface->flags |= SURFACE_DERIVED;
2743 obj_image->derived_surface = surface;
2745 return VA_STATUS_SUCCESS;
2748 i965_DestroyImage(ctx, image_id);
2753 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
2755 object_heap_free(heap, obj);
2760 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
2762 struct i965_driver_data *i965 = i965_driver_data(ctx);
2763 struct object_image *obj_image = IMAGE(image);
2764 struct object_surface *obj_surface;
2767 return VA_STATUS_SUCCESS;
2769 dri_bo_unreference(obj_image->bo);
2770 obj_image->bo = NULL;
2772 if (obj_image->image.buf != VA_INVALID_ID) {
2773 i965_DestroyBuffer(ctx, obj_image->image.buf);
2774 obj_image->image.buf = VA_INVALID_ID;
2777 if (obj_image->palette) {
2778 free(obj_image->palette);
2779 obj_image->palette = NULL;
2782 obj_surface = SURFACE(obj_image->derived_surface);
2785 obj_surface->flags &= ~SURFACE_DERIVED;
2788 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
2790 return VA_STATUS_SUCCESS;
2794 * pointer to an array holding the palette data. The size of the array is
2795 * num_palette_entries * entry_bytes in size. The order of the components
2796 * in the palette is described by the component_order in VASubpicture struct
2799 i965_SetImagePalette(VADriverContextP ctx,
2801 unsigned char *palette)
2803 struct i965_driver_data *i965 = i965_driver_data(ctx);
2806 struct object_image *obj_image = IMAGE(image);
2808 return VA_STATUS_ERROR_INVALID_IMAGE;
2810 if (!obj_image->palette)
2811 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
2813 for (i = 0; i < obj_image->image.num_palette_entries; i++)
2814 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
2815 ((unsigned int)palette[3*i + 1] << 8) |
2816 (unsigned int)palette[3*i + 2]);
2817 return VA_STATUS_SUCCESS;
2821 get_sampling_from_fourcc(unsigned int fourcc)
2823 int surface_sampling = -1;
2825 case VA_FOURCC('N', 'V', '1', '2'):
2826 case VA_FOURCC('Y', 'V', '1', '2'):
2827 case VA_FOURCC('I', '4', '2', '0'):
2828 case VA_FOURCC('I', 'M', 'C', '1'):
2829 case VA_FOURCC('I', 'M', 'C', '3'):
2830 surface_sampling = SUBSAMPLE_YUV420;
2832 case VA_FOURCC('Y', 'U', 'Y', '2'):
2833 surface_sampling = SUBSAMPLE_YUV422H;
2835 case VA_FOURCC('R','G','B','A'):
2836 case VA_FOURCC('R','G','B','X'):
2837 case VA_FOURCC('B','G','R','A'):
2838 case VA_FOURCC('B','G','R','X'):
2839 surface_sampling = SUBSAMPLE_RGBX;
2844 return surface_sampling;
2848 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
2849 const uint8_t *src, unsigned int src_stride,
2850 unsigned int len, unsigned int height)
2854 for (i = 0; i < height; i++) {
2855 memcpy(dst, src, len);
2862 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
2863 struct object_surface *obj_surface,
2864 const VARectangle *rect)
2866 uint8_t *dst[3], *src[3];
2868 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
2869 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
2870 unsigned int tiling, swizzle;
2872 if (!obj_surface->bo)
2875 assert(obj_surface->fourcc);
2876 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2878 if (tiling != I915_TILING_NONE)
2879 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2881 dri_bo_map(obj_surface->bo, 0);
2883 if (!obj_surface->bo->virtual)
2886 /* Dest VA image has either I420 or YV12 format.
2887 Source VA surface alway has I420 format */
2888 dst[Y] = image_data + obj_image->image.offsets[Y];
2889 src[0] = (uint8_t *)obj_surface->bo->virtual;
2890 dst[U] = image_data + obj_image->image.offsets[U];
2891 src[1] = src[0] + obj_surface->width * obj_surface->height;
2892 dst[V] = image_data + obj_image->image.offsets[V];
2893 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
2896 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
2897 src[0] += rect->y * obj_surface->width + rect->x;
2898 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
2899 src[0], obj_surface->width,
2900 rect->width, rect->height);
2903 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
2904 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
2905 memcpy_pic(dst[U], obj_image->image.pitches[U],
2906 src[1], obj_surface->width / 2,
2907 rect->width / 2, rect->height / 2);
2910 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
2911 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
2912 memcpy_pic(dst[V], obj_image->image.pitches[V],
2913 src[2], obj_surface->width / 2,
2914 rect->width / 2, rect->height / 2);
2916 if (tiling != I915_TILING_NONE)
2917 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2919 dri_bo_unmap(obj_surface->bo);
2923 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
2924 struct object_surface *obj_surface,
2925 const VARectangle *rect)
2927 uint8_t *dst[2], *src[2];
2928 unsigned int tiling, swizzle;
2930 if (!obj_surface->bo)
2933 assert(obj_surface->fourcc);
2934 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2936 if (tiling != I915_TILING_NONE)
2937 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2939 dri_bo_map(obj_surface->bo, 0);
2941 if (!obj_surface->bo->virtual)
2944 /* Both dest VA image and source surface have NV12 format */
2945 dst[0] = image_data + obj_image->image.offsets[0];
2946 src[0] = (uint8_t *)obj_surface->bo->virtual;
2947 dst[1] = image_data + obj_image->image.offsets[1];
2948 src[1] = src[0] + obj_surface->width * obj_surface->height;
2951 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
2952 src[0] += rect->y * obj_surface->width + rect->x;
2953 memcpy_pic(dst[0], obj_image->image.pitches[0],
2954 src[0], obj_surface->width,
2955 rect->width, rect->height);
2958 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
2959 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
2960 memcpy_pic(dst[1], obj_image->image.pitches[1],
2961 src[1], obj_surface->width,
2962 rect->width, rect->height / 2);
2964 if (tiling != I915_TILING_NONE)
2965 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
2967 dri_bo_unmap(obj_surface->bo);
2971 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
2972 struct object_surface *obj_surface,
2973 const VARectangle *rect)
2976 unsigned int tiling, swizzle;
2978 if (!obj_surface->bo)
2981 assert(obj_surface->fourcc);
2982 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
2984 if (tiling != I915_TILING_NONE)
2985 drm_intel_gem_bo_map_gtt(obj_surface->bo);
2987 dri_bo_map(obj_surface->bo, 0);
2989 if (!obj_surface->bo->virtual)
2992 /* Both dest VA image and source surface have YUYV format */
2993 dst = image_data + obj_image->image.offsets[0];
2994 src = (uint8_t *)obj_surface->bo->virtual;
2997 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
2998 src += rect->y * obj_surface->width + rect->x*2;
2999 memcpy_pic(dst, obj_image->image.pitches[0],
3000 src, obj_surface->width*2,
3001 rect->width*2, rect->height);
3003 if (tiling != I915_TILING_NONE)
3004 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3006 dri_bo_unmap(obj_surface->bo);
3010 i965_sw_getimage(VADriverContextP ctx,
3011 VASurfaceID surface,
3012 int x, /* coordinates of the upper left source pixel */
3014 unsigned int width, /* width and height of the region */
3015 unsigned int height,
3018 struct i965_driver_data *i965 = i965_driver_data(ctx);
3019 struct i965_render_state *render_state = &i965->render_state;
3021 struct object_surface *obj_surface = SURFACE(surface);
3023 return VA_STATUS_ERROR_INVALID_SURFACE;
3025 struct object_image *obj_image = IMAGE(image);
3027 return VA_STATUS_ERROR_INVALID_IMAGE;
3030 return VA_STATUS_ERROR_INVALID_PARAMETER;
3031 if (x + width > obj_surface->orig_width ||
3032 y + height > obj_surface->orig_height)
3033 return VA_STATUS_ERROR_INVALID_PARAMETER;
3034 if (x + width > obj_image->image.width ||
3035 y + height > obj_image->image.height)
3036 return VA_STATUS_ERROR_INVALID_PARAMETER;
3038 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3039 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3042 void *image_data = NULL;
3044 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3045 if (va_status != VA_STATUS_SUCCESS)
3052 rect.height = height;
3054 switch (obj_image->image.format.fourcc) {
3055 case VA_FOURCC('Y','V','1','2'):
3056 case VA_FOURCC('I','4','2','0'):
3057 /* I420 is native format for MPEG-2 decoded surfaces */
3058 if (render_state->interleaved_uv)
3059 goto operation_failed;
3060 get_image_i420(obj_image, image_data, obj_surface, &rect);
3062 case VA_FOURCC('N','V','1','2'):
3063 /* NV12 is native format for H.264 decoded surfaces */
3064 if (!render_state->interleaved_uv)
3065 goto operation_failed;
3066 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3068 case VA_FOURCC('Y','U','Y','2'):
3069 /* YUY2 is the format supported by overlay plane */
3070 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3074 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3078 i965_UnmapBuffer(ctx, obj_image->image.buf);
3083 i965_hw_getimage(VADriverContextP ctx,
3084 VASurfaceID surface,
3085 int x, /* coordinates of the upper left source pixel */
3087 unsigned int width, /* width and height of the region */
3088 unsigned int height,
3091 struct i965_driver_data *i965 = i965_driver_data(ctx);
3092 struct i965_surface src_surface;
3093 struct i965_surface dst_surface;
3096 struct object_surface *obj_surface = SURFACE(surface);
3097 struct object_image *obj_image = IMAGE(image);
3100 return VA_STATUS_ERROR_INVALID_SURFACE;
3103 return VA_STATUS_ERROR_INVALID_IMAGE;
3106 return VA_STATUS_ERROR_INVALID_PARAMETER;
3107 if (x + width > obj_surface->orig_width ||
3108 y + height > obj_surface->orig_height)
3109 return VA_STATUS_ERROR_INVALID_PARAMETER;
3110 if (x + width > obj_image->image.width ||
3111 y + height > obj_image->image.height)
3112 return VA_STATUS_ERROR_INVALID_PARAMETER;
3114 if (!obj_surface->bo)
3115 return VA_STATUS_SUCCESS;
3116 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3121 rect.height = height;
3123 src_surface.id = surface;
3124 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3125 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3127 dst_surface.id = image;
3128 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3129 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3131 va_status = i965_image_processing(ctx,
3142 i965_GetImage(VADriverContextP ctx,
3143 VASurfaceID surface,
3144 int x, /* coordinates of the upper left source pixel */
3146 unsigned int width, /* width and height of the region */
3147 unsigned int height,
3150 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3153 if (HAS_ACCELERATED_GETIMAGE(i965))
3154 va_status = i965_hw_getimage(ctx,
3160 va_status = i965_sw_getimage(ctx,
3170 put_image_i420(struct object_surface *obj_surface,
3171 const VARectangle *dst_rect,
3172 struct object_image *obj_image, uint8_t *image_data,
3173 const VARectangle *src_rect)
3175 uint8_t *dst[3], *src[3];
3177 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3178 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3179 unsigned int tiling, swizzle;
3181 if (!obj_surface->bo)
3184 assert(obj_surface->fourcc);
3185 assert(dst_rect->width == src_rect->width);
3186 assert(dst_rect->height == src_rect->height);
3187 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3189 if (tiling != I915_TILING_NONE)
3190 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3192 dri_bo_map(obj_surface->bo, 0);
3194 if (!obj_surface->bo->virtual)
3197 /* Dest VA image has either I420 or YV12 format.
3198 Source VA surface alway has I420 format */
3199 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3200 src[Y] = image_data + obj_image->image.offsets[Y];
3201 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3202 src[U] = image_data + obj_image->image.offsets[U];
3203 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3204 src[V] = image_data + obj_image->image.offsets[V];
3207 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3208 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3209 memcpy_pic(dst[0], obj_surface->width,
3210 src[Y], obj_image->image.pitches[Y],
3211 src_rect->width, src_rect->height);
3214 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3215 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3216 memcpy_pic(dst[1], obj_surface->width / 2,
3217 src[U], obj_image->image.pitches[U],
3218 src_rect->width / 2, src_rect->height / 2);
3221 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3222 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3223 memcpy_pic(dst[2], obj_surface->width / 2,
3224 src[V], obj_image->image.pitches[V],
3225 src_rect->width / 2, src_rect->height / 2);
3227 if (tiling != I915_TILING_NONE)
3228 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3230 dri_bo_unmap(obj_surface->bo);
3234 put_image_nv12(struct object_surface *obj_surface,
3235 const VARectangle *dst_rect,
3236 struct object_image *obj_image, uint8_t *image_data,
3237 const VARectangle *src_rect)
3239 uint8_t *dst[2], *src[2];
3240 unsigned int tiling, swizzle;
3242 if (!obj_surface->bo)
3245 assert(obj_surface->fourcc);
3246 assert(dst_rect->width == src_rect->width);
3247 assert(dst_rect->height == src_rect->height);
3248 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3250 if (tiling != I915_TILING_NONE)
3251 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3253 dri_bo_map(obj_surface->bo, 0);
3255 if (!obj_surface->bo->virtual)
3258 /* Both dest VA image and source surface have NV12 format */
3259 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3260 src[0] = image_data + obj_image->image.offsets[0];
3261 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3262 src[1] = image_data + obj_image->image.offsets[1];
3265 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3266 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3267 memcpy_pic(dst[0], obj_surface->width,
3268 src[0], obj_image->image.pitches[0],
3269 src_rect->width, src_rect->height);
3272 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3273 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3274 memcpy_pic(dst[1], obj_surface->width,
3275 src[1], obj_image->image.pitches[1],
3276 src_rect->width, src_rect->height / 2);
3278 if (tiling != I915_TILING_NONE)
3279 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3281 dri_bo_unmap(obj_surface->bo);
3285 put_image_yuy2(struct object_surface *obj_surface,
3286 const VARectangle *dst_rect,
3287 struct object_image *obj_image, uint8_t *image_data,
3288 const VARectangle *src_rect)
3291 unsigned int tiling, swizzle;
3293 if (!obj_surface->bo)
3296 assert(obj_surface->fourcc);
3297 assert(dst_rect->width == src_rect->width);
3298 assert(dst_rect->height == src_rect->height);
3299 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3301 if (tiling != I915_TILING_NONE)
3302 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3304 dri_bo_map(obj_surface->bo, 0);
3306 if (!obj_surface->bo->virtual)
3309 /* Both dest VA image and source surface have YUY2 format */
3310 dst = (uint8_t *)obj_surface->bo->virtual;
3311 src = image_data + obj_image->image.offsets[0];
3313 /* YUYV packed plane */
3314 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3315 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3316 memcpy_pic(dst, obj_surface->width*2,
3317 src, obj_image->image.pitches[0],
3318 src_rect->width*2, src_rect->height);
3320 if (tiling != I915_TILING_NONE)
3321 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3323 dri_bo_unmap(obj_surface->bo);
3328 i965_sw_putimage(VADriverContextP ctx,
3329 VASurfaceID surface,
3333 unsigned int src_width,
3334 unsigned int src_height,
3337 unsigned int dest_width,
3338 unsigned int dest_height)
3340 struct i965_driver_data *i965 = i965_driver_data(ctx);
3341 struct object_surface *obj_surface = SURFACE(surface);
3344 return VA_STATUS_ERROR_INVALID_SURFACE;
3346 struct object_image *obj_image = IMAGE(image);
3348 return VA_STATUS_ERROR_INVALID_IMAGE;
3350 if (src_x < 0 || src_y < 0)
3351 return VA_STATUS_ERROR_INVALID_PARAMETER;
3352 if (src_x + src_width > obj_image->image.width ||
3353 src_y + src_height > obj_image->image.height)
3354 return VA_STATUS_ERROR_INVALID_PARAMETER;
3355 if (dest_x < 0 || dest_y < 0)
3356 return VA_STATUS_ERROR_INVALID_PARAMETER;
3357 if (dest_x + dest_width > obj_surface->orig_width ||
3358 dest_y + dest_height > obj_surface->orig_height)
3359 return VA_STATUS_ERROR_INVALID_PARAMETER;
3361 /* XXX: don't allow scaling */
3362 if (src_width != dest_width || src_height != dest_height)
3363 return VA_STATUS_ERROR_INVALID_PARAMETER;
3365 if (obj_surface->fourcc) {
3366 /* Don't allow format mismatch */
3367 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3368 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3372 /* VA is surface not used for decoding, use same VA image format */
3373 i965_check_alloc_surface_bo(
3376 0, /* XXX: don't use tiled surface */
3377 obj_image->image.format.fourcc,
3378 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3382 void *image_data = NULL;
3384 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3385 if (va_status != VA_STATUS_SUCCESS)
3388 VARectangle src_rect, dest_rect;
3391 src_rect.width = src_width;
3392 src_rect.height = src_height;
3393 dest_rect.x = dest_x;
3394 dest_rect.y = dest_y;
3395 dest_rect.width = dest_width;
3396 dest_rect.height = dest_height;
3398 switch (obj_image->image.format.fourcc) {
3399 case VA_FOURCC('Y','V','1','2'):
3400 case VA_FOURCC('I','4','2','0'):
3401 put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3403 case VA_FOURCC('N','V','1','2'):
3404 put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3406 case VA_FOURCC('Y','U','Y','2'):
3407 put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3410 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3414 i965_UnmapBuffer(ctx, obj_image->image.buf);
3419 i965_hw_putimage(VADriverContextP ctx,
3420 VASurfaceID surface,
3424 unsigned int src_width,
3425 unsigned int src_height,
3428 unsigned int dest_width,
3429 unsigned int dest_height)
3431 struct i965_driver_data *i965 = i965_driver_data(ctx);
3432 struct object_surface *obj_surface = SURFACE(surface);
3433 struct object_image *obj_image = IMAGE(image);
3434 struct i965_surface src_surface, dst_surface;
3435 VAStatus va_status = VA_STATUS_SUCCESS;
3436 VARectangle src_rect, dst_rect;
3439 return VA_STATUS_ERROR_INVALID_SURFACE;
3441 if (!obj_image || !obj_image->bo)
3442 return VA_STATUS_ERROR_INVALID_IMAGE;
3446 src_x + src_width > obj_image->image.width ||
3447 src_y + src_height > obj_image->image.height)
3448 return VA_STATUS_ERROR_INVALID_PARAMETER;
3452 dest_x + dest_width > obj_surface->orig_width ||
3453 dest_y + dest_height > obj_surface->orig_height)
3454 return VA_STATUS_ERROR_INVALID_PARAMETER;
3456 if (!obj_surface->bo) {
3457 unsigned int tiling, swizzle;
3458 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3459 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3461 i965_check_alloc_surface_bo(ctx,
3464 obj_image->image.format.fourcc,
3468 assert(obj_surface->fourcc);
3470 src_surface.id = image;
3471 src_surface.type = I965_SURFACE_TYPE_IMAGE;
3472 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3475 src_rect.width = src_width;
3476 src_rect.height = src_height;
3478 dst_surface.id = surface;
3479 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3480 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3481 dst_rect.x = dest_x;
3482 dst_rect.y = dest_y;
3483 dst_rect.width = dest_width;
3484 dst_rect.height = dest_height;
3486 va_status = i965_image_processing(ctx,
3496 i965_PutImage(VADriverContextP ctx,
3497 VASurfaceID surface,
3501 unsigned int src_width,
3502 unsigned int src_height,
3505 unsigned int dest_width,
3506 unsigned int dest_height)
3508 struct i965_driver_data *i965 = i965_driver_data(ctx);
3509 VAStatus va_status = VA_STATUS_SUCCESS;
3511 if (HAS_ACCELERATED_PUTIMAGE(i965))
3512 va_status = i965_hw_putimage(ctx,
3524 va_status = i965_sw_putimage(ctx,
3540 i965_PutSurface(VADriverContextP ctx,
3541 VASurfaceID surface,
3542 void *draw, /* X Drawable */
3545 unsigned short srcw,
3546 unsigned short srch,
3549 unsigned short destw,
3550 unsigned short desth,
3551 VARectangle *cliprects, /* client supplied clip list */
3552 unsigned int number_cliprects, /* number of clip rects in the clip list */
3553 unsigned int flags) /* de-interlacing flags */
3556 if (IS_VA_X11(ctx)) {
3557 VARectangle src_rect, dst_rect;
3561 src_rect.width = srcw;
3562 src_rect.height = srch;
3566 dst_rect.width = destw;
3567 dst_rect.height = desth;
3569 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
3570 cliprects, number_cliprects, flags);
3573 return VA_STATUS_ERROR_UNIMPLEMENTED;
3577 i965_Terminate(VADriverContextP ctx)
3579 struct i965_driver_data *i965 = i965_driver_data(ctx);
3582 intel_batchbuffer_free(i965->batch);
3584 _i965DestroyMutex(&i965->pp_mutex);
3585 _i965DestroyMutex(&i965->render_mutex);
3589 i965_output_dri_terminate(ctx);
3592 #ifdef HAVE_VA_WAYLAND
3593 if (IS_VA_WAYLAND(ctx))
3594 i965_output_wayland_terminate(ctx);
3597 if (i965_render_terminate(ctx) == False)
3598 return VA_STATUS_ERROR_UNKNOWN;
3600 if (i965_post_processing_terminate(ctx) == False)
3601 return VA_STATUS_ERROR_UNKNOWN;
3603 i965_display_attributes_terminate(ctx);
3605 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
3606 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
3607 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
3608 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
3609 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
3610 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
3612 if (intel_driver_terminate(ctx) == False)
3613 return VA_STATUS_ERROR_UNKNOWN;
3615 free(ctx->pDriverData);
3616 ctx->pDriverData = NULL;
3618 return VA_STATUS_SUCCESS;
3623 VADriverContextP ctx, /* in */
3624 VABufferID buf_id, /* in */
3625 VABufferType *type, /* out */
3626 unsigned int *size, /* out */
3627 unsigned int *num_elements /* out */
3630 struct i965_driver_data *i965 = NULL;
3631 struct object_buffer *obj_buffer = NULL;
3633 i965 = i965_driver_data(ctx);
3634 obj_buffer = BUFFER(buf_id);
3636 *type = obj_buffer->type;
3637 *size = obj_buffer->size_element;
3638 *num_elements = obj_buffer->num_elements;
3640 return VA_STATUS_SUCCESS;
3645 VADriverContextP ctx, /* in */
3646 VASurfaceID surface, /* in */
3647 unsigned int *fourcc, /* out */
3648 unsigned int *luma_stride, /* out */
3649 unsigned int *chroma_u_stride, /* out */
3650 unsigned int *chroma_v_stride, /* out */
3651 unsigned int *luma_offset, /* out */
3652 unsigned int *chroma_u_offset, /* out */
3653 unsigned int *chroma_v_offset, /* out */
3654 unsigned int *buffer_name, /* out */
3655 void **buffer /* out */
3658 VAStatus vaStatus = VA_STATUS_SUCCESS;
3659 struct i965_driver_data *i965 = i965_driver_data(ctx);
3660 struct object_surface *obj_surface = NULL;
3664 assert(luma_stride);
3665 assert(chroma_u_stride);
3666 assert(chroma_v_stride);
3667 assert(luma_offset);
3668 assert(chroma_u_offset);
3669 assert(chroma_v_offset);
3670 assert(buffer_name);
3673 tmpImage.image_id = VA_INVALID_ID;
3675 obj_surface = SURFACE(surface);
3676 if (obj_surface == NULL) {
3677 // Surface is absent.
3678 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3682 // Lock functionality is absent now.
3683 if (obj_surface->locked_image_id != VA_INVALID_ID) {
3684 // Surface is locked already.
3685 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3689 vaStatus = i965_DeriveImage(
3693 if (vaStatus != VA_STATUS_SUCCESS) {
3697 obj_surface->locked_image_id = tmpImage.image_id;
3699 vaStatus = i965_MapBuffer(
3703 if (vaStatus != VA_STATUS_SUCCESS) {
3707 *fourcc = tmpImage.format.fourcc;
3708 *luma_offset = tmpImage.offsets[0];
3709 *luma_stride = tmpImage.pitches[0];
3710 *chroma_u_offset = tmpImage.offsets[1];
3711 *chroma_u_stride = tmpImage.pitches[1];
3712 *chroma_v_offset = tmpImage.offsets[2];
3713 *chroma_v_stride = tmpImage.pitches[2];
3714 *buffer_name = tmpImage.buf;
3717 if (vaStatus != VA_STATUS_SUCCESS) {
3726 VADriverContextP ctx, /* in */
3727 VASurfaceID surface /* in */
3730 VAStatus vaStatus = VA_STATUS_SUCCESS;
3731 struct i965_driver_data *i965 = i965_driver_data(ctx);
3732 struct object_image *locked_img = NULL;
3733 struct object_surface *obj_surface = NULL;
3735 obj_surface = SURFACE(surface);
3737 if (obj_surface == NULL) {
3738 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
3741 if (obj_surface->locked_image_id == VA_INVALID_ID) {
3742 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
3746 locked_img = IMAGE(obj_surface->locked_image_id);
3747 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
3748 // Work image was deallocated before i965_UnlockSurface()
3749 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3753 vaStatus = i965_UnmapBuffer(
3755 locked_img->image.buf);
3756 if (vaStatus != VA_STATUS_SUCCESS) {
3760 vaStatus = i965_DestroyImage(
3762 locked_img->image.image_id);
3763 if (vaStatus != VA_STATUS_SUCCESS) {
3767 locked_img->image.image_id = VA_INVALID_ID;
3770 obj_surface->locked_image_id = VA_INVALID_ID;
3776 i965_GetSurfaceAttributes(
3777 VADriverContextP ctx,
3779 VASurfaceAttrib *attrib_list,
3780 unsigned int num_attribs
3783 VAStatus vaStatus = VA_STATUS_SUCCESS;
3784 struct i965_driver_data *i965 = i965_driver_data(ctx);
3785 struct object_config *obj_config;
3788 if (config == VA_INVALID_ID)
3789 return VA_STATUS_ERROR_INVALID_CONFIG;
3791 obj_config = CONFIG(config);
3793 if (obj_config == NULL)
3794 return VA_STATUS_ERROR_INVALID_CONFIG;
3796 if (attrib_list == NULL || num_attribs == 0)
3797 return VA_STATUS_ERROR_INVALID_PARAMETER;
3799 for (i = 0; i < num_attribs; i++) {
3800 switch (attrib_list[i].type) {
3801 case VASurfaceAttribPixelFormat:
3802 attrib_list[i].value.type = VAGenericValueTypeInteger;
3803 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
3805 if (attrib_list[i].value.value.i == 0) {
3806 if (IS_G4X(i965->intel.device_id)) {
3807 if (obj_config->profile == VAProfileMPEG2Simple ||
3808 obj_config->profile == VAProfileMPEG2Main) {
3809 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
3812 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3814 } else if (IS_IRONLAKE(i965->intel.device_id)) {
3815 if (obj_config->profile == VAProfileMPEG2Simple ||
3816 obj_config->profile == VAProfileMPEG2Main) {
3817 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
3818 } else if (obj_config->profile == VAProfileH264Baseline ||
3819 obj_config->profile == VAProfileH264Main ||
3820 obj_config->profile == VAProfileH264High) {
3821 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3822 } else if (obj_config->profile == VAProfileNone) {
3823 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3826 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3828 } else if (IS_GEN6(i965->intel.device_id)) {
3829 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3830 } else if (IS_GEN7(i965->intel.device_id)) {
3831 if (obj_config->profile == VAProfileJPEGBaseline)
3832 attrib_list[i].value.value.i = 0; /* internal format */
3834 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3837 if (IS_G4X(i965->intel.device_id)) {
3838 if (obj_config->profile == VAProfileMPEG2Simple ||
3839 obj_config->profile == VAProfileMPEG2Main) {
3840 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
3841 attrib_list[i].value.value.i = 0;
3842 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3846 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3848 } else if (IS_IRONLAKE(i965->intel.device_id)) {
3849 if (obj_config->profile == VAProfileMPEG2Simple ||
3850 obj_config->profile == VAProfileMPEG2Main) {
3851 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
3852 attrib_list[i].value.value.i = 0;
3853 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3855 } else if (obj_config->profile == VAProfileH264Baseline ||
3856 obj_config->profile == VAProfileH264Main ||
3857 obj_config->profile == VAProfileH264High) {
3858 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3859 attrib_list[i].value.value.i = 0;
3860 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3862 } else if (obj_config->profile == VAProfileNone) {
3863 switch (attrib_list[i].value.value.i) {
3864 case VA_FOURCC('N', 'V', '1', '2'):
3865 case VA_FOURCC('I', '4', '2', '0'):
3866 case VA_FOURCC('Y', 'V', '1', '2'):
3867 case VA_FOURCC('Y', 'U', 'Y', '2'):
3868 case VA_FOURCC('B', 'G', 'R', 'A'):
3869 case VA_FOURCC('B', 'G', 'R', 'X'):
3870 case VA_FOURCC('R', 'G', 'B', 'X'):
3871 case VA_FOURCC('R', 'G', 'B', 'A'):
3874 attrib_list[i].value.value.i = 0;
3875 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3880 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3882 } else if (IS_GEN6(i965->intel.device_id)) {
3883 if (obj_config->entrypoint == VAEntrypointEncSlice ||
3884 obj_config->entrypoint == VAEntrypointVideoProc) {
3885 switch (attrib_list[i].value.value.i) {
3886 case VA_FOURCC('N', 'V', '1', '2'):
3887 case VA_FOURCC('I', '4', '2', '0'):
3888 case VA_FOURCC('Y', 'V', '1', '2'):
3889 case VA_FOURCC('Y', 'U', 'Y', '2'):
3890 case VA_FOURCC('B', 'G', 'R', 'A'):
3891 case VA_FOURCC('B', 'G', 'R', 'X'):
3892 case VA_FOURCC('R', 'G', 'B', 'X'):
3893 case VA_FOURCC('R', 'G', 'B', 'A'):
3896 attrib_list[i].value.value.i = 0;
3897 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3901 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3902 attrib_list[i].value.value.i = 0;
3903 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3906 } else if (IS_GEN7(i965->intel.device_id)) {
3907 if (obj_config->entrypoint == VAEntrypointEncSlice ||
3908 obj_config->entrypoint == VAEntrypointVideoProc) {
3909 switch (attrib_list[i].value.value.i) {
3910 case VA_FOURCC('N', 'V', '1', '2'):
3911 case VA_FOURCC('I', '4', '2', '0'):
3912 case VA_FOURCC('Y', 'V', '1', '2'):
3915 attrib_list[i].value.value.i = 0;
3916 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3920 if (obj_config->profile == VAProfileJPEGBaseline) {
3921 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
3922 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3924 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
3925 attrib_list[i].value.value.i = 0;
3926 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
3934 case VASurfaceAttribMinWidth:
3935 /* FIXME: add support for it later */
3936 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3938 case VASurfaceAttribMaxWidth:
3939 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3941 case VASurfaceAttribMinHeight:
3942 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3944 case VASurfaceAttribMaxHeight:
3945 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3948 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
3957 * Query video processing pipeline
3959 VAStatus i965_QueryVideoProcFilters(
3960 VADriverContextP ctx,
3961 VAContextID context,
3962 VAProcFilterType *filters,
3963 unsigned int *num_filters
3966 struct i965_driver_data *const i965 = i965_driver_data(ctx);
3969 if (HAS_VPP(i965)) {
3970 filters[i++] = VAProcFilterNoiseReduction;
3971 filters[i++] = VAProcFilterDeinterlacing;
3974 if(IS_HASWELL(i965->intel.device_id)){
3975 filters[i++] = VAProcFilterNone;
3976 filters[i++] = VAProcFilterSharpening;
3977 filters[i++] = VAProcFilterColorBalance;
3978 filters[i++] = VAProcFilterColorStandard;
3983 return VA_STATUS_SUCCESS;
3986 VAStatus i965_QueryVideoProcFilterCaps(
3987 VADriverContextP ctx,
3988 VAContextID context,
3989 VAProcFilterType type,
3991 unsigned int *num_filter_caps
3994 struct i965_driver_data *const i965 = i965_driver_data(ctx);
3997 if (type == VAProcFilterNoiseReduction) {
3998 VAProcFilterCap *cap = filter_caps;
4000 cap->range.min_value = 0.0;
4001 cap->range.max_value = 1.0;
4002 cap->range.default_value = 0.5;
4003 cap->range.step = 0.03125; /* 1.0 / 32 */
4005 } else if (type == VAProcFilterDeinterlacing) {
4006 VAProcFilterCapDeinterlacing *cap = filter_caps;
4008 cap->type = VAProcDeinterlacingBob;
4013 if(IS_HASWELL(i965->intel.device_id)){
4014 if(type == VAProcFilterColorBalance){
4015 VAProcFilterCapColorBalance *cap = filter_caps;
4016 cap->type = VAProcColorBalanceHue;
4017 cap->range.min_value = -180.0;
4018 cap->range.max_value = 180.0;
4019 cap->range.default_value = 0.0;
4020 cap->range.step = 1.0;
4024 cap->type = VAProcColorBalanceSaturation;
4025 cap->range.min_value = 0.0;
4026 cap->range.max_value = 10.0;
4027 cap->range.default_value = 0.0;
4028 cap->range.step = 0.1;
4032 cap->type = VAProcColorBalanceBrightness;
4033 cap->range.min_value = -100.0;
4034 cap->range.max_value = 100.0;
4035 cap->range.default_value = 0.0;
4036 cap->range.step = 1.0;
4040 cap->type = VAProcColorBalanceContrast;
4041 cap->range.min_value = 0.0;
4042 cap->range.max_value = 10.0;
4043 cap->range.default_value = 0.0;
4044 cap->range.step = 0.1;
4051 *num_filter_caps = i;
4053 return VA_STATUS_SUCCESS;
4056 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
4057 VAProcColorStandardBT601,
4060 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
4061 VAProcColorStandardBT601,
4064 VAStatus i965_QueryVideoProcPipelineCaps(
4065 VADriverContextP ctx,
4066 VAContextID context,
4067 VABufferID *filters,
4068 unsigned int num_filters,
4069 VAProcPipelineCaps *pipeline_cap /* out */
4072 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4075 pipeline_cap->pipeline_flags = 0;
4076 pipeline_cap->filter_flags = 0;
4077 pipeline_cap->num_forward_references = 0;
4078 pipeline_cap->num_backward_references = 0;
4079 pipeline_cap->num_input_color_standards = 1;
4080 pipeline_cap->input_color_standards = vpp_input_color_standards;
4081 pipeline_cap->num_output_color_standards = 1;
4082 pipeline_cap->output_color_standards = vpp_output_color_standards;
4084 for (i = 0; i < num_filters; i++) {
4085 struct object_buffer *obj_buffer = BUFFER(filters[i]);
4086 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4088 if (base->type == VAProcFilterNoiseReduction) {
4089 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
4091 } else if (base->type == VAProcFilterDeinterlacing) {
4092 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
4094 assert(deint->algorithm == VAProcDeinterlacingWeave ||
4095 deint->algorithm == VAProcDeinterlacingBob);
4099 return VA_STATUS_SUCCESS;
4103 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
4106 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
4108 struct VADriverVTable * const vtable = ctx->vtable;
4109 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
4111 struct i965_driver_data *i965;
4114 ctx->version_major = VA_MAJOR_VERSION;
4115 ctx->version_minor = VA_MINOR_VERSION;
4116 ctx->max_profiles = I965_MAX_PROFILES;
4117 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
4118 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
4119 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
4120 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
4121 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
4123 vtable->vaTerminate = i965_Terminate;
4124 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
4125 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
4126 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
4127 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
4128 vtable->vaCreateConfig = i965_CreateConfig;
4129 vtable->vaDestroyConfig = i965_DestroyConfig;
4130 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
4131 vtable->vaCreateSurfaces = i965_CreateSurfaces;
4132 vtable->vaDestroySurfaces = i965_DestroySurfaces;
4133 vtable->vaCreateContext = i965_CreateContext;
4134 vtable->vaDestroyContext = i965_DestroyContext;
4135 vtable->vaCreateBuffer = i965_CreateBuffer;
4136 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
4137 vtable->vaMapBuffer = i965_MapBuffer;
4138 vtable->vaUnmapBuffer = i965_UnmapBuffer;
4139 vtable->vaDestroyBuffer = i965_DestroyBuffer;
4140 vtable->vaBeginPicture = i965_BeginPicture;
4141 vtable->vaRenderPicture = i965_RenderPicture;
4142 vtable->vaEndPicture = i965_EndPicture;
4143 vtable->vaSyncSurface = i965_SyncSurface;
4144 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
4145 vtable->vaPutSurface = i965_PutSurface;
4146 vtable->vaQueryImageFormats = i965_QueryImageFormats;
4147 vtable->vaCreateImage = i965_CreateImage;
4148 vtable->vaDeriveImage = i965_DeriveImage;
4149 vtable->vaDestroyImage = i965_DestroyImage;
4150 vtable->vaSetImagePalette = i965_SetImagePalette;
4151 vtable->vaGetImage = i965_GetImage;
4152 vtable->vaPutImage = i965_PutImage;
4153 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
4154 vtable->vaCreateSubpicture = i965_CreateSubpicture;
4155 vtable->vaDestroySubpicture = i965_DestroySubpicture;
4156 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
4157 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
4158 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
4159 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
4160 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
4161 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
4162 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
4163 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
4164 vtable->vaBufferInfo = i965_BufferInfo;
4165 vtable->vaLockSurface = i965_LockSurface;
4166 vtable->vaUnlockSurface = i965_UnlockSurface;
4167 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
4168 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
4170 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
4171 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
4172 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
4174 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
4176 ctx->pDriverData = (void *)i965;
4178 result = object_heap_init(&i965->config_heap,
4179 sizeof(struct object_config),
4181 assert(result == 0);
4183 result = object_heap_init(&i965->context_heap,
4184 sizeof(struct object_context),
4186 assert(result == 0);
4188 result = object_heap_init(&i965->surface_heap,
4189 sizeof(struct object_surface),
4191 assert(result == 0);
4193 result = object_heap_init(&i965->buffer_heap,
4194 sizeof(struct object_buffer),
4196 assert(result == 0);
4198 result = object_heap_init(&i965->image_heap,
4199 sizeof(struct object_image),
4201 assert(result == 0);
4203 result = object_heap_init(&i965->subpic_heap,
4204 sizeof(struct object_subpic),
4206 assert(result == 0);
4208 sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
4209 INTEL_STR_DRIVER_VENDOR,
4210 INTEL_STR_DRIVER_NAME,
4211 INTEL_DRIVER_MAJOR_VERSION,
4212 INTEL_DRIVER_MINOR_VERSION,
4213 INTEL_DRIVER_MICRO_VERSION);
4215 if (INTEL_DRIVER_PRE_VERSION > 0) {
4216 const int len = strlen(i965->va_vendor);
4217 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
4220 i965->current_context_id = VA_INVALID_ID;
4222 ctx->str_vendor = i965->va_vendor;
4224 return i965_Init(ctx);