X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fi965_drv_video.c;h=68a6052b024c007a7d94a4780acd872be75d6215;hb=45481435f93b52f944c5f876e95fb7bfba56ed4f;hp=86a4937afb5443480a8c2efd548fa7673d4ae461;hpb=e6aff72b1674cf194ed9ea0caf8f37824c432e78;p=platform%2Fupstream%2Flibva-intel-driver.git diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c index 86a4937..68a6052 100755 --- a/src/i965_drv_video.c +++ b/src/i965_drv_video.c @@ -26,16 +26,8 @@ * Zou Nan hai * */ -#ifdef ANDROID -#include "config_android.h" -#else -#include "config.h" -#endif -#include -#include -#include -#include -#include + +#include "sysdeps.h" #ifdef HAVE_VA_X11 # include "i965_output_dri.h" @@ -63,6 +55,9 @@ #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \ (ctx)->intel.has_bsd) +#define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \ + (ctx)->intel.has_bsd) + #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \ (ctx)->intel.has_bsd) @@ -83,6 +78,22 @@ #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface) +#define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \ + (ctx)->intel.has_bsd) + +#define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \ + (ctx)->intel.has_bsd) + +#define HAS_H264_MVC_DECODING(ctx) \ + (HAS_H264_DECODING(ctx) && (ctx)->codec_info->h264_mvc_dec_profiles) + +#define HAS_H264_MVC_DECODING_PROFILE(ctx, profile) \ + (HAS_H264_MVC_DECODING(ctx) && \ + ((ctx)->codec_info->h264_mvc_dec_profiles & (1U << profile))) + +#define HAS_H264_MVC_ENCODING(ctx) ((ctx)->codec_info->has_h264_mvc_encoding && \ + (ctx)->intel.has_bsd) + static int get_sampling_from_fourcc(unsigned int fourcc); /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */ @@ -93,6 +104,117 @@ static int get_sampling_from_fourcc(unsigned int fourcc); #define IS_VA_WAYLAND(ctx) \ (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND) +#define I965_BIT 1 +#define I965_2BITS (I965_BIT << 1) +#define I965_4BITS (I965_BIT << 2) +#define I965_8BITS (I965_BIT << 3) +#define I965_16BITS (I965_BIT << 4) +#define I965_32BITS (I965_BIT << 5) + +#define PLANE_0 0 +#define PLANE_1 1 +#define PLANE_2 2 + +#define OFFSET_0 0 +#define OFFSET_4 4 +#define OFFSET_8 8 +#define OFFSET_16 16 +#define OFFSET_24 24 + +/* hfactor, vfactor, num_planes, bpp[], num_components, components[] */ +#define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} } +#define I_I420 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} } +#define I_IYUV I_I420 +#define I_IMC3 I_I420 +#define I_YV12 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} } +#define I_IMC1 I_YV12 + +#define I_422H 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} } +#define I_422V 1, 2, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} } +#define I_YV16 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} } +#define I_YUY2 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} } +#define I_UYVY 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} } + +#define I_444P 1, 1, 3, {I965_8BITS, I965_8BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} } + +#define I_411P 4, 1, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} } + +#define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} } + +#define I_RGBA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24} } +#define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} } +#define I_BGRA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_24} } +#define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} } + +#define I_ARGB 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_0} } +#define I_ABGR 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} } + +#define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} } +#define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} } + +#define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} } +#define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} } + +/* flag */ +#define I_S 1 +#define I_I 2 +#define I_SI (I_S | I_I) + +#define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC } +#define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG) +#define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG) +#define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG) + +static const i965_fourcc_info i965_fourcc_infos[] = { + DEF_YUV(NV12, YUV420, I_SI), + DEF_YUV(I420, YUV420, I_SI), + DEF_YUV(IYUV, YUV420, I_S), + DEF_YUV(IMC3, YUV420, I_S), + DEF_YUV(YV12, YUV420, I_SI), + DEF_YUV(IMC1, YUV420, I_S), + + DEF_YUV(422H, YUV422H, I_SI), + DEF_YUV(422V, YUV422V, I_S), + DEF_YUV(YV16, YUV422H, I_S), + DEF_YUV(YUY2, YUV422H, I_SI), + DEF_YUV(UYVY, YUV422H, I_SI), + + DEF_YUV(444P, YUV444, I_S), + + DEF_YUV(411P, YUV411, I_S), + + DEF_YUV(Y800, YUV400, I_S), + + DEF_RGB(RGBA, RGBX, I_SI), + DEF_RGB(RGBX, RGBX, I_SI), + DEF_RGB(BGRA, RGBX, I_SI), + DEF_RGB(BGRX, RGBX, I_SI), + + DEF_RGB(ARGB, RGBX, I_I), + DEF_RGB(ABGR, RGBX, I_I), + + DEF_INDEX(IA88, RGBX, I_I), + DEF_INDEX(AI88, RGBX, I_I), + + DEF_INDEX(IA44, RGBX, I_I), + DEF_INDEX(AI44, RGBX, I_I) +}; + +const i965_fourcc_info * +get_fourcc_info(unsigned int fourcc) +{ + unsigned int i; + + for (i = 0; ARRAY_ELEMS(i965_fourcc_infos); i++) { + const i965_fourcc_info * const info = &i965_fourcc_infos[i]; + + if (info->fourcc == fourcc) + return info; + } + + return NULL; +} + enum { I965_SURFACETYPE_RGBA = 1, I965_SURFACETYPE_YUV, @@ -102,6 +224,30 @@ enum { /* List of supported display attributes */ static const VADisplayAttribute i965_display_attributes[] = { { + VADisplayAttribBrightness, + -100, 100, DEFAULT_BRIGHTNESS, + VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE + }, + + { + VADisplayAttribContrast, + 0, 100, DEFAULT_CONTRAST, + VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE + }, + + { + VADisplayAttribHue, + -180, 180, DEFAULT_HUE, + VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE + }, + + { + VADisplayAttribSaturation, + 0, 100, DEFAULT_SATURATION, + VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE + }, + + { VADisplayAttribRotation, 0, 3, VA_ROTATION_NONE, VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE @@ -117,19 +263,21 @@ typedef struct { static const i965_image_format_map_t i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = { { I965_SURFACETYPE_YUV, - { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } }, + { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } }, { I965_SURFACETYPE_YUV, - { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } }, + { VA_FOURCC_I420, VA_LSB_FIRST, 12, } }, { I965_SURFACETYPE_YUV, - { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } }, + { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } }, { I965_SURFACETYPE_YUV, - { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } }, + { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } }, { I965_SURFACETYPE_YUV, - { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } }, + { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } }, + { I965_SURFACETYPE_YUV, + { VA_FOURCC_422H, VA_LSB_FIRST, 16, } }, { I965_SURFACETYPE_RGBA, - { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } }, + { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } }, { I965_SURFACETYPE_RGBA, - { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } }, + { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } }, }; /* List of supported subpicture formats */ @@ -140,28 +288,32 @@ typedef struct { unsigned int va_flags; } i965_subpic_format_map_t; +#define COMMON_SUBPICTURE_FLAGS \ + (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \ + VA_SUBPICTURE_GLOBAL_ALPHA) + static const i965_subpic_format_map_t i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = { { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM, - { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + { VA_FOURCC_IA44, VA_MSB_FIRST, 8, }, + COMMON_SUBPICTURE_FLAGS }, { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM, - { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + { VA_FOURCC_AI44, VA_MSB_FIRST, 8, }, + COMMON_SUBPICTURE_FLAGS }, { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM, - { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + { VA_FOURCC_IA88, VA_MSB_FIRST, 16, }, + COMMON_SUBPICTURE_FLAGS }, { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM, - { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + { VA_FOURCC_AI88, VA_MSB_FIRST, 16, }, + COMMON_SUBPICTURE_FLAGS }, { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM, - { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32, + { VA_FOURCC_BGRA, VA_LSB_FIRST, 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + COMMON_SUBPICTURE_FLAGS }, { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM, - { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32, + { VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, - VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD }, + COMMON_SUBPICTURE_FLAGS }, }; static const i965_subpic_format_map_t * @@ -182,90 +334,6 @@ get_subpic_format(const VAImageFormat *va_format) return NULL; } -extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *); -extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *); -static struct hw_codec_info g4x_hw_codec_info = { - .dec_hw_context_init = g4x_dec_hw_context_init, - .enc_hw_context_init = NULL, - .proc_hw_context_init = NULL, - .max_width = 2048, - .max_height = 2048, - - .has_mpeg2_decoding = 1, -}; - -extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *); -static struct hw_codec_info ironlake_hw_codec_info = { - .dec_hw_context_init = ironlake_dec_hw_context_init, - .enc_hw_context_init = NULL, - .proc_hw_context_init = i965_proc_context_init, - .max_width = 2048, - .max_height = 2048, - - .has_mpeg2_decoding = 1, - .has_h264_decoding = 1, - .has_vpp = 1, - .has_accelerated_putimage = 1, -}; - -extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *); -extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *); -static struct hw_codec_info gen6_hw_codec_info = { - .dec_hw_context_init = gen6_dec_hw_context_init, - .enc_hw_context_init = gen6_enc_hw_context_init, - .proc_hw_context_init = i965_proc_context_init, - .max_width = 2048, - .max_height = 2048, - - .has_mpeg2_decoding = 1, - .has_h264_decoding = 1, - .has_h264_encoding = 1, - .has_vc1_decoding = 1, - .has_vpp = 1, - .has_accelerated_getimage = 1, - .has_accelerated_putimage = 1, - .has_tiled_surface = 1, -}; - -extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *); -extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *); -static struct hw_codec_info gen7_hw_codec_info = { - .dec_hw_context_init = gen7_dec_hw_context_init, - .enc_hw_context_init = gen7_enc_hw_context_init, - .proc_hw_context_init = i965_proc_context_init, - .max_width = 4096, - .max_height = 4096, - - .has_mpeg2_decoding = 1, - .has_h264_decoding = 1, - .has_h264_encoding = 1, - .has_vc1_decoding = 1, - .has_jpeg_decoding = 1, - .has_vpp = 1, - .has_accelerated_getimage = 1, - .has_accelerated_putimage = 1, - .has_tiled_surface = 1, -}; - -extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *); -static struct hw_codec_info gen75_hw_codec_info = { - .dec_hw_context_init = gen75_dec_hw_context_init, - .enc_hw_context_init = gen75_enc_hw_context_init, - .proc_hw_context_init = gen75_proc_context_init, - .max_width = 4096, - .max_height = 4096, - - .has_mpeg2_decoding = 1, - .has_h264_decoding = 1, - .has_h264_encoding = 1, - .has_vc1_decoding = 1, - .has_jpeg_decoding = 1, - .has_vpp = 1, - .has_accelerated_getimage = 1, - .has_accelerated_putimage = 1, - .has_tiled_surface = 1, -}; - #define I965_PACKED_HEADER_BASE 0 #define I965_PACKED_MISC_HEADER_BASE 3 @@ -277,7 +345,7 @@ va_enc_packed_type_to_idx(int packed_type) if (packed_type & VAEncPackedHeaderMiscMask) { idx = I965_PACKED_MISC_HEADER_BASE; packed_type = (~VAEncPackedHeaderMiscMask & packed_type); - assert(packed_type > 0); + ASSERT_RET(packed_type > 0, 0); idx += (packed_type - 1); } else { idx = I965_PACKED_HEADER_BASE; @@ -297,16 +365,15 @@ va_enc_packed_type_to_idx(int packed_type) default: /* Should not get here */ - assert(0); + ASSERT_RET(0, 0); break; } } - assert(idx < 4); + ASSERT_RET(idx < 4, 0); return idx; } - VAStatus i965_QueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list, /* out */ @@ -315,17 +382,22 @@ i965_QueryConfigProfiles(VADriverContextP ctx, struct i965_driver_data * const i965 = i965_driver_data(ctx); int i = 0; - if (HAS_MPEG2_DECODING(i965)) { + if (HAS_MPEG2_DECODING(i965) || + HAS_MPEG2_ENCODING(i965)) { profile_list[i++] = VAProfileMPEG2Simple; profile_list[i++] = VAProfileMPEG2Main; } if (HAS_H264_DECODING(i965) || HAS_H264_ENCODING(i965)) { - profile_list[i++] = VAProfileH264Baseline; + profile_list[i++] = VAProfileH264ConstrainedBaseline; profile_list[i++] = VAProfileH264Main; profile_list[i++] = VAProfileH264High; } + if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh)) + profile_list[i++] = VAProfileH264MultiviewHigh; + if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh)) + profile_list[i++] = VAProfileH264StereoHigh; if (HAS_VC1_DECODING(i965)) { profile_list[i++] = VAProfileVC1Simple; @@ -341,8 +413,18 @@ i965_QueryConfigProfiles(VADriverContextP ctx, profile_list[i++] = VAProfileJPEGBaseline; } + if (HAS_VP8_DECODING(i965) || + HAS_VP8_ENCODING(i965)) { + profile_list[i++] = VAProfileVP8Version0_3; + } + + if (HAS_H264_MVC_ENCODING(i965)) { + profile_list[i++] = VAProfileH264MultiviewHigh; + profile_list[i++] = VAProfileH264StereoHigh; + } + /* If the assert fails then I965_MAX_PROFILES needs to be bigger */ - assert(i <= I965_MAX_PROFILES); + ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED); *num_profiles = i; return VA_STATUS_SUCCESS; @@ -362,18 +444,30 @@ i965_QueryConfigEntrypoints(VADriverContextP ctx, case VAProfileMPEG2Main: if (HAS_MPEG2_DECODING(i965)) entrypoint_list[n++] = VAEntrypointVLD; + + if (HAS_MPEG2_ENCODING(i965)) + entrypoint_list[n++] = VAEntrypointEncSlice; + break; - case VAProfileH264Baseline: + case VAProfileH264ConstrainedBaseline: case VAProfileH264Main: case VAProfileH264High: if (HAS_H264_DECODING(i965)) entrypoint_list[n++] = VAEntrypointVLD; - + if (HAS_H264_ENCODING(i965)) entrypoint_list[n++] = VAEntrypointEncSlice; break; + case VAProfileH264MultiviewHigh: + case VAProfileH264StereoHigh: + if (HAS_H264_MVC_DECODING_PROFILE(i965, profile)) + entrypoint_list[n++] = VAEntrypointVLD; + + if (HAS_H264_MVC_ENCODING(i965)) + entrypoint_list[n++] = VAEntrypointEncSlice; + break; case VAProfileVC1Simple: case VAProfileVC1Main: @@ -392,16 +486,139 @@ i965_QueryConfigEntrypoints(VADriverContextP ctx, entrypoint_list[n++] = VAEntrypointVLD; break; + case VAProfileVP8Version0_3: + if (HAS_VP8_DECODING(i965)) + entrypoint_list[n++] = VAEntrypointVLD; + + if (HAS_VP8_ENCODING(i965)) + entrypoint_list[n++] = VAEntrypointEncSlice; + default: break; } /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */ - assert(n <= I965_MAX_ENTRYPOINTS); + ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED); *num_entrypoints = n; return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE; } +static VAStatus +i965_validate_config(VADriverContextP ctx, VAProfile profile, + VAEntrypoint entrypoint) +{ + struct i965_driver_data * const i965 = i965_driver_data(ctx); + VAStatus va_status; + + /* Validate profile & entrypoint */ + switch (profile) { + case VAProfileMPEG2Simple: + case VAProfileMPEG2Main: + if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) || + (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileH264ConstrainedBaseline: + case VAProfileH264Main: + case VAProfileH264High: + if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) || + (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileVC1Simple: + case VAProfileVC1Main: + case VAProfileVC1Advanced: + if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileNone: + if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileJPEGBaseline: + if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileVP8Version0_3: + if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) || + (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + break; + + case VAProfileH264MultiviewHigh: + case VAProfileH264StereoHigh: + if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) && + entrypoint == VAEntrypointVLD) || + (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) { + va_status = VA_STATUS_SUCCESS; + } else { + va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } + + break; + + default: + va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + break; + } + return va_status; +} + +static uint32_t +i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile, + VAEntrypoint entrypoint) +{ + struct i965_driver_data * const i965 = i965_driver_data(ctx); + uint32_t chroma_formats = VA_RT_FORMAT_YUV420; + + switch (profile) { + case VAProfileH264ConstrainedBaseline: + case VAProfileH264Main: + case VAProfileH264High: + if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) + chroma_formats |= i965->codec_info->h264_dec_chroma_formats; + break; + + case VAProfileH264MultiviewHigh: + case VAProfileH264StereoHigh: + if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD) + chroma_formats |= i965->codec_info->h264_dec_chroma_formats; + break; + + case VAProfileJPEGBaseline: + if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) + chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats; + break; + + default: + break; + } + return chroma_formats; +} + VAStatus i965_GetConfigAttributes(VADriverContextP ctx, VAProfile profile, @@ -409,28 +626,52 @@ i965_GetConfigAttributes(VADriverContextP ctx, VAConfigAttrib *attrib_list, /* in/out */ int num_attribs) { + VAStatus va_status; int i; + va_status = i965_validate_config(ctx, profile, entrypoint); + if (va_status != VA_STATUS_SUCCESS) + return va_status; + /* Other attributes don't seem to be defined */ /* What to do if we don't know the attribute? */ for (i = 0; i < num_attribs; i++) { switch (attrib_list[i].type) { case VAConfigAttribRTFormat: - attrib_list[i].value = VA_RT_FORMAT_YUV420; + attrib_list[i].value = i965_get_default_chroma_formats(ctx, + profile, entrypoint); break; case VAConfigAttribRateControl: if (entrypoint == VAEntrypointEncSlice) { - attrib_list[i].value = VA_RC_CBR | VA_RC_CQP; + attrib_list[i].value = VA_RC_CQP; + + if (profile != VAProfileMPEG2Main && + profile != VAProfileMPEG2Simple) + attrib_list[i].value |= VA_RC_CBR; break; } case VAConfigAttribEncPackedHeaders: if (entrypoint == VAEntrypointEncSlice) { attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC; + if (profile == VAProfileH264ConstrainedBaseline || + profile == VAProfileH264Main || + profile == VAProfileH264High || + profile == VAProfileH264StereoHigh || + profile == VAProfileH264MultiviewHigh) { + attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA | + VA_ENC_PACKED_HEADER_SLICE); + } break; } + case VAConfigAttribEncMaxRefFrames: + if (entrypoint == VAEntrypointEncSlice) { + attrib_list[i].value = (1 << 16) | (1 << 0); + break; + } + default: /* Do nothing */ attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED; @@ -447,29 +688,49 @@ i965_destroy_config(struct object_heap *heap, struct object_base *obj) object_heap_free(heap, obj); } -static VAStatus -i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib) +static VAConfigAttrib * +i965_lookup_config_attribute(struct object_config *obj_config, + VAConfigAttribType type) { int i; - /* Check existing attrbiutes */ for (i = 0; i < obj_config->num_attribs; i++) { - if (obj_config->attrib_list[i].type == attrib->type) { - /* Update existing attribute */ - obj_config->attrib_list[i].value = attrib->value; - return VA_STATUS_SUCCESS; - } + VAConfigAttrib * const attrib = &obj_config->attrib_list[i]; + if (attrib->type == type) + return attrib; } + return NULL; +} + +static VAStatus +i965_append_config_attribute(struct object_config *obj_config, + const VAConfigAttrib *new_attrib) +{ + VAConfigAttrib *attrib; + + if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES) + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; - if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) { - i = obj_config->num_attribs; - obj_config->attrib_list[i].type = attrib->type; - obj_config->attrib_list[i].value = attrib->value; - obj_config->num_attribs++; + attrib = &obj_config->attrib_list[obj_config->num_attribs++]; + attrib->type = new_attrib->type; + attrib->value = new_attrib->value; + return VA_STATUS_SUCCESS; +} + +static VAStatus +i965_ensure_config_attribute(struct object_config *obj_config, + const VAConfigAttrib *new_attrib) +{ + VAConfigAttrib *attrib; + + /* Check for existing attributes */ + attrib = i965_lookup_config_attribute(obj_config, new_attrib->type); + if (attrib) { + /* Update existing attribute */ + attrib->value = new_attrib->value; return VA_STATUS_SUCCESS; } - - return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + return i965_append_config_attribute(obj_config, new_attrib); } VAStatus @@ -486,62 +747,7 @@ i965_CreateConfig(VADriverContextP ctx, int i; VAStatus vaStatus; - /* Validate profile & entrypoint */ - switch (profile) { - case VAProfileMPEG2Simple: - case VAProfileMPEG2Main: - if (HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) { - vaStatus = VA_STATUS_SUCCESS; - } else { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - } - break; - - case VAProfileH264Baseline: - case VAProfileH264Main: - case VAProfileH264High: - if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) || - (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) { - vaStatus = VA_STATUS_SUCCESS; - } else { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - } - - break; - - case VAProfileVC1Simple: - case VAProfileVC1Main: - case VAProfileVC1Advanced: - if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) { - vaStatus = VA_STATUS_SUCCESS; - } else { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - } - - break; - - case VAProfileNone: - if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) { - vaStatus = VA_STATUS_SUCCESS; - } else { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - } - - break; - - case VAProfileJPEGBaseline: - if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) { - vaStatus = VA_STATUS_SUCCESS; - } else { - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - } - - break; - - default: - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; - break; - } + vaStatus = i965_validate_config(ctx, profile, entrypoint); if (VA_STATUS_SUCCESS != vaStatus) { return vaStatus; @@ -557,16 +763,23 @@ i965_CreateConfig(VADriverContextP ctx, obj_config->profile = profile; obj_config->entrypoint = entrypoint; - obj_config->attrib_list[0].type = VAConfigAttribRTFormat; - obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420; - obj_config->num_attribs = 1; - - for(i = 0; i < num_attribs; i++) { - vaStatus = i965_update_attribute(obj_config, &(attrib_list[i])); + obj_config->num_attribs = 0; - if (VA_STATUS_SUCCESS != vaStatus) { + for (i = 0; i < num_attribs; i++) { + vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]); + if (vaStatus != VA_STATUS_SUCCESS) break; - } + } + + if (vaStatus == VA_STATUS_SUCCESS) { + VAConfigAttrib attrib, *attrib_found; + attrib.type = VAConfigAttribRTFormat; + attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint); + attrib_found = i965_lookup_config_attribute(obj_config, attrib.type); + if (!attrib_found || !attrib_found->value) + vaStatus = i965_append_config_attribute(obj_config, &attrib); + else if (!(attrib_found->value & attrib.value)) + vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; } /* Error recovery */ @@ -607,7 +820,7 @@ VAStatus i965_QueryConfigAttributes(VADriverContextP ctx, VAStatus vaStatus = VA_STATUS_SUCCESS; int i; - assert(obj_config); + ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG); *profile = obj_config->profile; *entrypoint = obj_config->entrypoint; *num_attribs = obj_config->num_attribs; @@ -616,23 +829,265 @@ VAStatus i965_QueryConfigAttributes(VADriverContextP ctx, attrib_list[i] = obj_config->attrib_list[i]; } - return vaStatus; + return vaStatus; +} + +void +i965_destroy_surface_storage(struct object_surface *obj_surface) +{ + if (!obj_surface) + return; + + dri_bo_unreference(obj_surface->bo); + obj_surface->bo = NULL; + + if (obj_surface->free_private_data != NULL) { + obj_surface->free_private_data(&obj_surface->private_data); + obj_surface->private_data = NULL; + } +} + +static void +i965_destroy_surface(struct object_heap *heap, struct object_base *obj) +{ + struct object_surface *obj_surface = (struct object_surface *)obj; + + i965_destroy_surface_storage(obj_surface); + object_heap_free(heap, obj); +} + +static VAStatus +i965_surface_native_memory(VADriverContextP ctx, + struct object_surface *obj_surface, + int format, + int expected_fourcc) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + int tiling = HAS_TILED_SURFACE(i965); + + if (!expected_fourcc) + return VA_STATUS_SUCCESS; + + // todo, should we disable tiling for 422 format? + if (expected_fourcc == VA_FOURCC_I420 || + expected_fourcc == VA_FOURCC_IYUV || + expected_fourcc == VA_FOURCC_YV12 || + expected_fourcc == VA_FOURCC_YV16) + tiling = 0; + + i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc)); + + return VA_STATUS_SUCCESS; +} + +static VAStatus +i965_suface_external_memory(VADriverContextP ctx, + struct object_surface *obj_surface, + int external_memory_type, + VASurfaceAttribExternalBuffers *memory_attibute, + int index) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + + if (!memory_attibute || + !memory_attibute->buffers || + index > memory_attibute->num_buffers) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->fourcc = memory_attibute->pixel_format; + obj_surface->width = memory_attibute->pitches[0]; + obj_surface->size = memory_attibute->data_size; + + if (memory_attibute->num_planes == 1) + obj_surface->height = memory_attibute->data_size / obj_surface->width; + else + obj_surface->height = memory_attibute->offsets[1] / obj_surface->width; + + obj_surface->x_cb_offset = 0; /* X offset is always 0 */ + obj_surface->x_cr_offset = 0; + + switch (obj_surface->fourcc) { + case VA_FOURCC_NV12: + ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV420; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->height; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_YV12: + case VA_FOURCC_IMC1: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV420; + obj_surface->y_cr_offset = obj_surface->height; + obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_I420: + case VA_FOURCC_IYUV: + case VA_FOURCC_IMC3: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV420; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: + ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV422H; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->cb_cr_pitch = memory_attibute->pitches[0]; + + break; + + case VA_FOURCC_RGBA: + case VA_FOURCC_RGBX: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: + ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_RGBX; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + obj_surface->cb_cr_width = 0; + obj_surface->cb_cr_height = 0; + obj_surface->cb_cr_pitch = 0; + + break; + + case VA_FOURCC_Y800: /* monochrome surface */ + ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV400; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + obj_surface->cb_cr_width = 0; + obj_surface->cb_cr_height = 0; + obj_surface->cb_cr_pitch = 0; + + break; + + case VA_FOURCC_411P: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV411; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + obj_surface->cb_cr_width = obj_surface->orig_width / 4; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_422H: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV422H; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_YV16: + assert(memory_attibute->num_planes == 3); + assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]); + + obj_surface->subsampling = SUBSAMPLE_YUV422H; + obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width; + obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_422V: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV422H; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + case VA_FOURCC_444P: + ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER); + + obj_surface->subsampling = SUBSAMPLE_YUV444; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->cb_cr_pitch = memory_attibute->pitches[1]; + + break; + + default: + + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK) + obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr, + "gem flinked vaapi surface", + memory_attibute->buffers[index]); + else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME) + obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr, + memory_attibute->buffers[index], + obj_surface->size); + + if (!obj_surface->bo) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + return VA_STATUS_SUCCESS; } -static void -i965_destroy_surface(struct object_heap *heap, struct object_base *obj) +/* byte-per-pixel of the first plane */ +static int +bpp_1stplane_by_fourcc(unsigned int fourcc) { - struct object_surface *obj_surface = (struct object_surface *)obj; - - dri_bo_unreference(obj_surface->bo); - obj_surface->bo = NULL; - - if (obj_surface->free_private_data != NULL) { - obj_surface->free_private_data(&obj_surface->private_data); - obj_surface->private_data = NULL; - } + const i965_fourcc_info *info = get_fourcc_info(fourcc); - object_heap_free(heap, obj); + if (info && (info->flag & I_S)) + return info->bpp[0] / 8; + else + return 0; } static VAStatus @@ -651,13 +1106,33 @@ i965_CreateSurfaces2( int i,j; VAStatus vaStatus = VA_STATUS_SUCCESS; int expected_fourcc = 0; + int memory_type = I965_SURFACE_MEM_NATIVE; /* native */ + VASurfaceAttribExternalBuffers *memory_attibute = NULL; for (i = 0; i < num_attribs && attrib_list; i++) { if ((attrib_list[i].type == VASurfaceAttribPixelFormat) && (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) { - assert(attrib_list[i].value.type == VAGenericValueTypeInteger); + ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER); expected_fourcc = attrib_list[i].value.value.i; - break; + } + + if ((attrib_list[i].type == VASurfaceAttribMemoryType) && + (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) { + + ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER); + + if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM) + memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */ + else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME) + memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */ + else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA) + memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */ + } + + if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) && + (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) { + ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER); + memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p; } } @@ -665,6 +1140,9 @@ i965_CreateSurfaces2( * for post-processing (including color conversion) */ if (VA_RT_FORMAT_YUV420 != format && VA_RT_FORMAT_YUV422 != format && + VA_RT_FORMAT_YUV444 != format && + VA_RT_FORMAT_YUV411 != format && + VA_RT_FORMAT_YUV400 != format && VA_RT_FORMAT_RGB32 != format) { return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; } @@ -682,14 +1160,20 @@ i965_CreateSurfaces2( obj_surface->status = VASurfaceReady; obj_surface->orig_width = width; obj_surface->orig_height = height; + obj_surface->user_disable_tiling = false; + obj_surface->user_h_stride_set = false; + obj_surface->user_v_stride_set = false; obj_surface->subpic_render_idx = 0; for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){ obj_surface->subpic[j] = VA_INVALID_ID; + obj_surface->obj_subpic[j] = NULL; } - obj_surface->width = ALIGN(width, 16); - obj_surface->height = ALIGN(height, 16); + assert(i965->codec_info->min_linear_wpitch); + assert(i965->codec_info->min_linear_hpitch); + obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch); + obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch); obj_surface->flags = SURFACE_REFERENCED; obj_surface->fourcc = 0; obj_surface->bo = NULL; @@ -698,29 +1182,50 @@ i965_CreateSurfaces2( obj_surface->free_private_data = NULL; obj_surface->subsampling = SUBSAMPLE_YUV420; - if (expected_fourcc) { - int tiling = HAS_TILED_SURFACE(i965); - - if (expected_fourcc != VA_FOURCC('N', 'V', '1', '2') && - expected_fourcc != VA_FOURCC('R', 'G', 'B', 'X') && - expected_fourcc != VA_FOURCC('R', 'G', 'B', 'A') ) - tiling = 0; - // todo, should we disable tiling for 422 format? - - if (VA_RT_FORMAT_YUV420 == format) { - obj_surface->subsampling = SUBSAMPLE_YUV420; - } - else if (VA_RT_FORMAT_YUV422 == format) { - obj_surface->subsampling = SUBSAMPLE_YUV422H; - } - else if (VA_RT_FORMAT_RGB32 == format) { - obj_surface->subsampling = SUBSAMPLE_RGBX; - } - else { - assert(0); + switch (memory_type) { + case I965_SURFACE_MEM_NATIVE: + if (memory_attibute) { + if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING)) + obj_surface->user_disable_tiling = true; + + if (memory_attibute->pixel_format) { + if (expected_fourcc) + ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER); + else + expected_fourcc = memory_attibute->pixel_format; + } + ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER); + if (memory_attibute->pitches[0]) { + int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc); + ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER); + obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane; + obj_surface->user_h_stride_set = true; + ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER); + + if (memory_attibute->offsets[1]) { + ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER); + obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0]; + obj_surface->user_v_stride_set = true; + ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER); + } + } } + i965_surface_native_memory(ctx, + obj_surface, + format, + expected_fourcc); + break; - i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, obj_surface->subsampling); + case I965_SURFACE_MEM_GEM_FLINK: + case I965_SURFACE_MEM_DRM_PRIME: + i965_suface_external_memory(ctx, + obj_surface, + memory_type, + memory_attibute, + i); + break; } } @@ -768,7 +1273,7 @@ i965_DestroySurfaces(VADriverContextP ctx, for (i = num_surfaces; i--; ) { struct object_surface *obj_surface = SURFACE(surface_list[i]); - assert(obj_surface); + ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE); i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface); } @@ -811,7 +1316,7 @@ i965_guess_surface_format(VADriverContextP ctx, struct object_context *obj_context = NULL; struct object_config *obj_config = NULL; - *fourcc = VA_FOURCC('Y', 'V', '1', '2'); + *fourcc = VA_FOURCC_YV12; *is_tiled = 0; if (i965->current_context_id == VA_INVALID_ID) @@ -819,16 +1324,19 @@ i965_guess_surface_format(VADriverContextP ctx, obj_context = CONTEXT(i965->current_context_id); - if (!obj_context || obj_context->config_id == VA_INVALID_ID) + if (!obj_context) return; - obj_config = CONFIG(obj_context->config_id); + obj_config = obj_context->obj_config; + assert(obj_config); if (!obj_config) return; - if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) { - *fourcc = VA_FOURCC('N', 'V', '1', '2'); + if (IS_GEN6(i965->intel.device_info) || + IS_GEN7(i965->intel.device_info) || + IS_GEN8(i965->intel.device_info)) { + *fourcc = VA_FOURCC_NV12; *is_tiled = 1; return; } @@ -836,12 +1344,12 @@ i965_guess_surface_format(VADriverContextP ctx, switch (obj_config->profile) { case VAProfileMPEG2Simple: case VAProfileMPEG2Main: - *fourcc = VA_FOURCC('I', '4', '2', '0'); + *fourcc = VA_FOURCC_I420; *is_tiled = 0; break; default: - *fourcc = VA_FOURCC('N', 'V', '1', '2'); + *fourcc = VA_FOURCC_NV12; *is_tiled = 0; break; } @@ -899,6 +1407,7 @@ i965_CreateSubpicture(VADriverContextP ctx, *subpicture = subpicID; obj_subpic->image = image; + obj_subpic->obj_image = obj_image; obj_subpic->format = m->format; obj_subpic->width = obj_image->image.width; obj_subpic->height = obj_image->image.height; @@ -915,6 +1424,11 @@ i965_DestroySubpicture(VADriverContextP ctx, { struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_subpic *obj_subpic = SUBPIC(subpicture); + + if (!obj_subpic) + return VA_STATUS_ERROR_INVALID_SUBPICTURE; + + ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE); i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic); return VA_STATUS_SUCCESS; } @@ -950,6 +1464,10 @@ i965_SetSubpictureGlobalAlpha(VADriverContextP ctx, if(global_alpha > 1.0 || global_alpha < 0.0){ return VA_STATUS_ERROR_INVALID_PARAMETER; } + + if (!obj_subpic) + return VA_STATUS_ERROR_INVALID_SUBPICTURE; + obj_subpic->global_alpha = global_alpha; return VA_STATUS_SUCCESS; @@ -978,6 +1496,11 @@ i965_AssociateSubpicture(VADriverContextP ctx, struct object_subpic *obj_subpic = SUBPIC(subpicture); int i, j; + if (!obj_subpic) + return VA_STATUS_ERROR_INVALID_SUBPICTURE; + + ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE); + obj_subpic->src_rect.x = src_x; obj_subpic->src_rect.y = src_y; obj_subpic->src_rect.width = src_width; @@ -995,8 +1518,10 @@ i965_AssociateSubpicture(VADriverContextP ctx, for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){ if(obj_surface->subpic[j] == VA_INVALID_ID){ - obj_surface->subpic[j] = subpicture; - break; + assert(obj_surface->obj_subpic[j] == NULL); + obj_surface->subpic[j] = subpicture; + obj_surface->obj_subpic[j] = obj_subpic; + break; } } @@ -1016,17 +1541,23 @@ i965_DeassociateSubpicture(VADriverContextP ctx, int num_surfaces) { struct i965_driver_data *i965 = i965_driver_data(ctx); + struct object_subpic *obj_subpic = SUBPIC(subpicture); int i, j; + if (!obj_subpic) + return VA_STATUS_ERROR_INVALID_SUBPICTURE; + for (i = 0; i < num_surfaces; i++) { struct object_surface *obj_surface = SURFACE(target_surfaces[i]); if (!obj_surface) return VA_STATUS_ERROR_INVALID_SURFACE; for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){ - if(obj_surface->subpic[j] == subpicture){ - obj_surface->subpic[j] = VA_INVALID_ID; - break; + if (obj_surface->subpic[j] == subpicture) { + assert(obj_surface->obj_subpic[j] == obj_subpic); + obj_surface->subpic[j] = VA_INVALID_ID; + obj_surface->obj_subpic[j] = NULL; + break; } } @@ -1113,6 +1644,28 @@ i965_destroy_context(struct object_heap *heap, struct object_base *obj) i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]); free(obj_context->codec_state.encode.slice_params_ext); + if (obj_context->codec_state.encode.slice_rawdata_index) { + free(obj_context->codec_state.encode.slice_rawdata_index); + obj_context->codec_state.encode.slice_rawdata_index = NULL; + } + if (obj_context->codec_state.encode.slice_rawdata_count) { + free(obj_context->codec_state.encode.slice_rawdata_count); + obj_context->codec_state.encode.slice_rawdata_count = NULL; + } + + if (obj_context->codec_state.encode.slice_header_index) { + free(obj_context->codec_state.encode.slice_header_index); + obj_context->codec_state.encode.slice_header_index = NULL; + } + + for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++) + i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]); + free(obj_context->codec_state.encode.packed_header_params_ext); + + for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++) + i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]); + free(obj_context->codec_state.encode.packed_header_data_ext); + } else { assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params); assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas); @@ -1149,6 +1702,7 @@ i965_CreateContext(VADriverContextP ctx, struct i965_render_state *render_state = &i965->render_state; struct object_config *obj_config = CONFIG(config_id); struct object_context *obj_context = NULL; + VAConfigAttrib *attrib; VAStatus vaStatus = VA_STATUS_SUCCESS; int contextID; int i; @@ -1177,7 +1731,7 @@ i965_CreateContext(VADriverContextP ctx, render_state->inited = 1; switch (obj_config->profile) { - case VAProfileH264Baseline: + case VAProfileH264ConstrainedBaseline: case VAProfileH264Main: case VAProfileH264High: if (!HAS_H264_DECODING(i965) && @@ -1185,15 +1739,21 @@ i965_CreateContext(VADriverContextP ctx, return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; render_state->interleaved_uv = 1; break; + case VAProfileH264MultiviewHigh: + case VAProfileH264StereoHigh: + if (!HAS_H264_MVC_DECODING(i965)) + return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + render_state->interleaved_uv = 1; + break; default: - render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)); + render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info)); break; } *context = contextID; obj_context->flags = flag; obj_context->context_id = contextID; - obj_context->config_id = config_id; + obj_context->obj_config = obj_config; obj_context->picture_width = picture_width; obj_context->picture_height = picture_height; obj_context->num_render_targets = num_render_targets; @@ -1224,6 +1784,25 @@ i965_CreateContext(VADriverContextP ctx, obj_context->codec_state.encode.max_slice_params = NUM_SLICES; obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params, sizeof(*obj_context->codec_state.encode.slice_params)); + obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES; + obj_context->codec_state.encode.packed_header_params_ext = + calloc(obj_context->codec_state.encode.max_packed_header_params_ext, + sizeof(struct buffer_store *)); + + obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES; + obj_context->codec_state.encode.packed_header_data_ext = + calloc(obj_context->codec_state.encode.max_packed_header_data_ext, + sizeof(struct buffer_store *)); + + obj_context->codec_state.encode.slice_num = NUM_SLICES; + obj_context->codec_state.encode.slice_rawdata_index = + calloc(obj_context->codec_state.encode.slice_num, sizeof(int)); + obj_context->codec_state.encode.slice_rawdata_count = + calloc(obj_context->codec_state.encode.slice_num, sizeof(int)); + + obj_context->codec_state.encode.slice_header_index = + calloc(obj_context->codec_state.encode.slice_num, sizeof(int)); + assert(i965->codec_info->enc_hw_context_init); obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config); } else { @@ -1242,6 +1821,11 @@ i965_CreateContext(VADriverContextP ctx, } } + attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat); + if (!attrib) + return VA_STATUS_ERROR_INVALID_CONFIG; + obj_context->codec_state.base.chroma_formats = attrib->value; + /* Error recovery */ if (VA_STATUS_SUCCESS != vaStatus) { i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context); @@ -1258,7 +1842,7 @@ i965_DestroyContext(VADriverContextP ctx, VAContextID context) struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_context *obj_context = CONTEXT(context); - assert(obj_context); + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); if (i965->current_context_id == context) i965->current_context_id = VA_INVALID_ID; @@ -1316,6 +1900,7 @@ i965_create_buffer_internal(VADriverContextP ctx, case VAProcPipelineParameterBufferType: case VAProcFilterParameterBufferType: case VAHuffmanTableBufferType: + case VAProbabilityBufferType: /* Ok */ break; @@ -1352,24 +1937,25 @@ i965_create_buffer_internal(VADriverContextP ctx, dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data); } else if (type == VASliceDataBufferType || type == VAImageBufferType || - type == VAEncCodedBufferType) { + type == VAEncCodedBufferType || + type == VAProbabilityBufferType) { buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Buffer", size * num_elements, 64); assert(buffer_store->bo); if (type == VAEncCodedBufferType) { - VACodedBufferSegment *coded_buffer_segment; - unsigned char *flag = NULL; + struct i965_coded_buffer_segment *coded_buffer_segment; + dri_bo_map(buffer_store->bo, 1); - coded_buffer_segment = (VACodedBufferSegment *)buffer_store->bo->virtual; - coded_buffer_segment->size = size - I965_CODEDBUFFER_HEADER_SIZE; - coded_buffer_segment->bit_offset = 0; - coded_buffer_segment->status = 0; - coded_buffer_segment->buf = NULL; - coded_buffer_segment->next = NULL; - flag = (unsigned char *)(coded_buffer_segment + 1); - *flag = 0; + coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual; + coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE; + coded_buffer_segment->base.bit_offset = 0; + coded_buffer_segment->base.status = 0; + coded_buffer_segment->base.buf = NULL; + coded_buffer_segment->base.next = NULL; + coded_buffer_segment->mapped = 0; + coded_buffer_segment->codec = 0; dri_bo_unmap(buffer_store->bo); } else if (data) { dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data); @@ -1419,11 +2005,11 @@ i965_BufferSetNumElements(VADriverContextP ctx, struct object_buffer *obj_buffer = BUFFER(buf_id); VAStatus vaStatus = VA_STATUS_SUCCESS; - assert(obj_buffer); + ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER); if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements)) { - vaStatus = VA_STATUS_ERROR_UNKNOWN; + vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED; } else { obj_buffer->num_elements = num_elements; if (obj_buffer->buffer_store != NULL) { @@ -1443,9 +2029,9 @@ i965_MapBuffer(VADriverContextP ctx, struct object_buffer *obj_buffer = BUFFER(buf_id); VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; - assert(obj_buffer && obj_buffer->buffer_store); - assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer); - assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer)); + ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER); if (NULL != obj_buffer->buffer_store->bo) { unsigned int tiling, swizzle; @@ -1457,35 +2043,53 @@ i965_MapBuffer(VADriverContextP ctx, else dri_bo_map(obj_buffer->buffer_store->bo, 1); - assert(obj_buffer->buffer_store->bo->virtual); + ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED); *pbuf = obj_buffer->buffer_store->bo->virtual; if (obj_buffer->type == VAEncCodedBufferType) { int i; unsigned char *buffer = NULL; - VACodedBufferSegment *coded_buffer_segment = (VACodedBufferSegment *)(obj_buffer->buffer_store->bo->virtual); - unsigned char *flag = (unsigned char *)(coded_buffer_segment + 1); + struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual); + + if (!coded_buffer_segment->mapped) { + unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4; + + coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE; + + if (coded_buffer_segment->codec == CODEC_H264 || + coded_buffer_segment->codec == CODEC_H264_MVC) { + delimiter0 = H264_DELIMITER0; + delimiter1 = H264_DELIMITER1; + delimiter2 = H264_DELIMITER2; + delimiter3 = H264_DELIMITER3; + delimiter4 = H264_DELIMITER4; + } else if (coded_buffer_segment->codec == CODEC_MPEG2) { + delimiter0 = MPEG2_DELIMITER0; + delimiter1 = MPEG2_DELIMITER1; + delimiter2 = MPEG2_DELIMITER2; + delimiter3 = MPEG2_DELIMITER3; + delimiter4 = MPEG2_DELIMITER4; + } else { + ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE); + } - if (*flag != 1) { - coded_buffer_segment->buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE; - for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) { - if (!buffer[i] && - !buffer[i + 1] && - !buffer[i + 2] && - !buffer[i + 3] && - !buffer[i + 4]) + if ((buffer[i] == delimiter0) && + (buffer[i + 1] == delimiter1) && + (buffer[i + 2] == delimiter2) && + (buffer[i + 3] == delimiter3) && + (buffer[i + 4] == delimiter4)) break; } if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) { - coded_buffer_segment->status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK; + coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK; } - coded_buffer_segment->size = i; - *flag = 1; + coded_buffer_segment->base.size = i; + coded_buffer_segment->mapped = 1; } else { - assert(coded_buffer_segment->buf); + assert(coded_buffer_segment->base.buf); } } @@ -1505,9 +2109,12 @@ i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id) struct object_buffer *obj_buffer = BUFFER(buf_id); VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; - assert(obj_buffer && obj_buffer->buffer_store); - assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer); - assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer)); + if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET) + return VA_STATUS_ERROR_INVALID_BUFFER; + + ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED); + ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED); if (NULL != obj_buffer->buffer_store->bo) { unsigned int tiling, swizzle; @@ -1534,7 +2141,8 @@ i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id) struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_buffer *obj_buffer = BUFFER(buffer_id); - assert(obj_buffer); + ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER); + i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer); return VA_STATUS_SUCCESS; @@ -1549,16 +2157,13 @@ i965_BeginPicture(VADriverContextP ctx, struct object_context *obj_context = CONTEXT(context); struct object_surface *obj_surface = SURFACE(render_target); struct object_config *obj_config; - VAContextID config; VAStatus vaStatus; int i; - assert(obj_context); - assert(obj_surface); - - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); + ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE); + obj_config = obj_context->obj_config; + ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG); switch (obj_config->profile) { case VAProfileMPEG2Simple: @@ -1566,12 +2171,22 @@ i965_BeginPicture(VADriverContextP ctx, vaStatus = VA_STATUS_SUCCESS; break; - case VAProfileH264Baseline: + case VAProfileH264ConstrainedBaseline: case VAProfileH264Main: case VAProfileH264High: vaStatus = VA_STATUS_SUCCESS; break; + case VAProfileH264MultiviewHigh: + case VAProfileH264StereoHigh: + if (HAS_H264_MVC_DECODING_PROFILE(i965, obj_config->profile) || + HAS_H264_MVC_ENCODING(i965)) { + vaStatus = VA_STATUS_SUCCESS; + } else { + ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE); + } + break; + case VAProfileVC1Simple: case VAProfileVC1Main: case VAProfileVC1Advanced: @@ -1586,9 +2201,12 @@ i965_BeginPicture(VADriverContextP ctx, vaStatus = VA_STATUS_SUCCESS; break; + case VAProfileVP8Version0_3: + vaStatus = VA_STATUS_SUCCESS; + break; + default: - assert(0); - vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE); break; } @@ -1618,6 +2236,19 @@ i965_BeginPicture(VADriverContextP ctx, obj_context->codec_state.encode.num_slice_params_ext = 0; obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/ obj_context->codec_state.encode.last_packed_header_type = 0; + memset(obj_context->codec_state.encode.slice_rawdata_index, 0, + sizeof(int) * obj_context->codec_state.encode.slice_num); + memset(obj_context->codec_state.encode.slice_rawdata_count, 0, + sizeof(int) * obj_context->codec_state.encode.slice_num); + memset(obj_context->codec_state.encode.slice_header_index, 0, + sizeof(int) * obj_context->codec_state.encode.slice_num); + + for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++) + i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]); + for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++) + i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]); + obj_context->codec_state.encode.num_packed_header_params_ext = 0; + obj_context->codec_state.encode.num_packed_header_data_ext = 0; } else { obj_context->codec_state.decode.current_render_target = render_target; i965_release_buffer_store(&obj_context->codec_state.decode.pic_param); @@ -1646,8 +2277,6 @@ i965_BeginPicture(VADriverContextP ctx, struct object_buffer *obj_buffer) \ { \ struct category##_state *category = &obj_context->codec_state.category; \ - assert(obj_buffer->buffer_store->bo == NULL); \ - assert(obj_buffer->buffer_store->buffer); \ i965_release_buffer_store(&category->member); \ i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \ return VA_STATUS_SUCCESS; \ @@ -1678,6 +2307,7 @@ DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param) DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix) DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane) DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table) +DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data) #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member) DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params) @@ -1693,10 +2323,14 @@ i965_decoder_render_picture(VADriverContextP ctx, struct object_context *obj_context = CONTEXT(context); VAStatus vaStatus = VA_STATUS_SUCCESS; int i; + + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) { struct object_buffer *obj_buffer = BUFFER(buffers[i]); - assert(obj_buffer); + + if (!obj_buffer) + return VA_STATUS_ERROR_INVALID_BUFFER; switch (obj_buffer->type) { case VAPictureParameterBufferType: @@ -1723,6 +2357,10 @@ i965_decoder_render_picture(VADriverContextP ctx, vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table); break; + case VAProbabilityBufferType: + vaStatus = I965_RENDER_DECODE_BUFFER(probability_data); + break; + default: vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE; break; @@ -1735,9 +2373,9 @@ i965_decoder_render_picture(VADriverContextP ctx, #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name) #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member) -DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param) -DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param) -DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control) +// DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param) +// DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param) +// DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control) DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix) DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix) /* extended buffer */ @@ -1745,9 +2383,12 @@ DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext) DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext) #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member) -DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params) +// DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params) DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext) +DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext) +DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext) + static VAStatus i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx, struct object_context *obj_context, @@ -1756,8 +2397,8 @@ i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx, { struct encode_state *encode = &obj_context->codec_state.encode; - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); + ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER); i965_release_buffer_store(&encode->packed_header_param[type_index]); i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store); @@ -1772,8 +2413,8 @@ i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx, { struct encode_state *encode = &obj_context->codec_state.encode; - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); + ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER); i965_release_buffer_store(&encode->packed_header_data[type_index]); i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store); @@ -1788,10 +2429,14 @@ i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx, struct encode_state *encode = &obj_context->codec_state.encode; VAEncMiscParameterBuffer *param = NULL; - assert(obj_buffer->buffer_store->bo == NULL); - assert(obj_buffer->buffer_store->buffer); + ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER); + ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER); param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer; + + if (param->type >= ARRAY_ELEMS(encode->misc_param)) + return VA_STATUS_ERROR_INVALID_PARAMETER; + i965_release_buffer_store(&encode->misc_param[param->type]); i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store); @@ -1807,11 +2452,17 @@ i965_encoder_render_picture(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_context *obj_context = CONTEXT(context); VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; + struct encode_state *encode; int i; + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); + + encode = &obj_context->codec_state.encode; for (i = 0; i < num_buffers; i++) { struct object_buffer *obj_buffer = BUFFER(buffers[i]); - assert(obj_buffer); + + if (!obj_buffer) + return VA_STATUS_ERROR_INVALID_BUFFER; switch (obj_buffer->type) { case VAQMatrixBufferType: @@ -1832,34 +2483,93 @@ i965_encoder_render_picture(VADriverContextP ctx, case VAEncSliceParameterBufferType: vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext); + if (vaStatus == VA_STATUS_SUCCESS) { + /* When the max number of slices is updated, it also needs + * to reallocate the arrays that is used to store + * the packed data index/count for the slice + */ + if (encode->max_slice_params_ext > encode->slice_num) { + int slice_num = encode->slice_num; + encode->slice_num = encode->max_slice_params_ext; + encode->slice_rawdata_index = realloc(encode->slice_rawdata_index, + encode->slice_num * sizeof(int)); + encode->slice_rawdata_count = realloc(encode->slice_rawdata_count, + encode->slice_num * sizeof(int)); + encode->slice_header_index = realloc(encode->slice_header_index, + encode->slice_num * sizeof(int)); + memset(encode->slice_rawdata_index + slice_num, 0, + sizeof(int) * NUM_SLICES); + memset(encode->slice_rawdata_count + slice_num, 0, + sizeof(int) * NUM_SLICES); + memset(encode->slice_header_index + slice_num, 0, + sizeof(int) * NUM_SLICES); + if ((encode->slice_rawdata_index == NULL) || + (encode->slice_header_index == NULL) || + (encode->slice_rawdata_count == NULL)) { + vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; + return vaStatus; + } + } + } break; case VAEncPackedHeaderParameterBufferType: { - struct encode_state *encode = &obj_context->codec_state.encode; VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer; encode->last_packed_header_type = param->type; - vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx, + if ((param->type == VAEncPackedHeaderRawData) || + (param->type == VAEncPackedHeaderSlice)) { + vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext); + } else { + vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx, obj_context, obj_buffer, va_enc_packed_type_to_idx(encode->last_packed_header_type)); + } break; } case VAEncPackedHeaderDataBufferType: { - struct encode_state *encode = &obj_context->codec_state.encode; - - assert(encode->last_packed_header_type == VAEncPackedHeaderSequence || - encode->last_packed_header_type == VAEncPackedHeaderPicture || - encode->last_packed_header_type == VAEncPackedHeaderSlice || - ((encode->last_packed_header_type & VAEncPackedHeaderMiscMask == VAEncPackedHeaderMiscMask) && - (encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask) != 0))); - vaStatus = i965_encoder_render_packed_header_data_buffer(ctx, + if (encode->last_packed_header_type == 0) { + WARN_ONCE("the packed header data is passed without type!\n"); + vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; + return vaStatus; + } + if (encode->last_packed_header_type == VAEncPackedHeaderRawData || + encode->last_packed_header_type == VAEncPackedHeaderSlice) { + vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext); + if (vaStatus == VA_STATUS_SUCCESS) { + /* store the first index of the packed header data for current slice */ + if (encode->slice_rawdata_index[encode->num_slice_params_ext] == 0) { + encode->slice_rawdata_index[encode->num_slice_params_ext] = + SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1); + } + encode->slice_rawdata_count[encode->num_slice_params_ext]++; + if (encode->last_packed_header_type == VAEncPackedHeaderSlice) { + if (encode->slice_header_index[encode->num_slice_params_ext] == 0) { + encode->slice_header_index[encode->num_slice_params_ext] = + SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1); + } else { + WARN_ONCE("Multi slice header data is passed for" + " slice %d!\n", encode->num_slice_params_ext); + } + } + } + } else { + ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence || + encode->last_packed_header_type == VAEncPackedHeaderPicture || + encode->last_packed_header_type == VAEncPackedHeaderSlice || + (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) && + ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)), + VA_STATUS_ERROR_ENCODING_ERROR); + vaStatus = i965_encoder_render_packed_header_data_buffer(ctx, obj_context, obj_buffer, va_enc_packed_type_to_idx(encode->last_packed_header_type)); + } + encode->last_packed_header_type = 0; break; } @@ -1894,9 +2604,13 @@ i965_proc_render_picture(VADriverContextP ctx, VAStatus vaStatus = VA_STATUS_SUCCESS; int i; + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); + for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) { struct object_buffer *obj_buffer = BUFFER(buffers[i]); - assert(obj_buffer); + + if (!obj_buffer) + return VA_STATUS_ERROR_INVALID_BUFFER; switch (obj_buffer->type) { case VAProcPipelineParameterBufferType: @@ -1921,15 +2635,16 @@ i965_RenderPicture(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_context *obj_context; struct object_config *obj_config; - VAContextID config; VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; obj_context = CONTEXT(context); - assert(obj_context); + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); + if (num_buffers <= 0) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + obj_config = obj_context->obj_config; + ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG); if (VAEntrypointVideoProc == obj_config->entrypoint) { vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers); @@ -1948,35 +2663,52 @@ i965_EndPicture(VADriverContextP ctx, VAContextID context) struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_context *obj_context = CONTEXT(context); struct object_config *obj_config; - VAContextID config; - assert(obj_context); - config = obj_context->config_id; - obj_config = CONFIG(config); - assert(obj_config); + ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT); + obj_config = obj_context->obj_config; + ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG); if (obj_context->codec_type == CODEC_PROC) { - assert(VAEntrypointVideoProc == obj_config->entrypoint); + ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT); } else if (obj_context->codec_type == CODEC_ENC) { - assert(VAEntrypointEncSlice == obj_config->entrypoint); - - assert(obj_context->codec_state.encode.pic_param || - obj_context->codec_state.encode.pic_param_ext); - assert(obj_context->codec_state.encode.seq_param || - obj_context->codec_state.encode.seq_param_ext); - assert(obj_context->codec_state.encode.num_slice_params >= 1 || - obj_context->codec_state.encode.num_slice_params_ext >= 1); + ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT); + + if (obj_context->codec_state.encode.num_packed_header_params_ext != + obj_context->codec_state.encode.num_packed_header_data_ext) { + WARN_ONCE("the packed header/data is not paired for encoding!\n"); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + if (!(obj_context->codec_state.encode.pic_param || + obj_context->codec_state.encode.pic_param_ext)) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + if (!(obj_context->codec_state.encode.seq_param || + obj_context->codec_state.encode.seq_param_ext)) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + if ((obj_context->codec_state.encode.num_slice_params <=0) && + (obj_context->codec_state.encode.num_slice_params_ext <=0)) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } } else { - assert(obj_context->codec_state.decode.pic_param); - assert(obj_context->codec_state.decode.num_slice_params >= 1); - assert(obj_context->codec_state.decode.num_slice_datas >= 1); - assert(obj_context->codec_state.decode.num_slice_params == obj_context->codec_state.decode.num_slice_datas); - } + if (obj_context->codec_state.decode.pic_param == NULL) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + if (obj_context->codec_state.decode.num_slice_params <=0) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + if (obj_context->codec_state.decode.num_slice_datas <=0) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } - assert(obj_context->hw_context->run); - obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context); + if (obj_context->codec_state.decode.num_slice_params != + obj_context->codec_state.decode.num_slice_datas) { + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + } - return VA_STATUS_SUCCESS; + ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED); + return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context); } VAStatus @@ -1986,7 +2718,7 @@ i965_SyncSurface(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_surface *obj_surface = SURFACE(render_target); - assert(obj_surface); + ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE); if(obj_surface->bo) drm_intel_bo_wait_rendering(obj_surface->bo); @@ -2002,7 +2734,7 @@ i965_QuerySurfaceStatus(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_surface *obj_surface = SURFACE(render_target); - assert(obj_surface); + ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE); if (obj_surface->bo) { if (drm_intel_bo_busy(obj_surface->bo)){ @@ -2034,6 +2766,18 @@ get_display_attribute(VADriverContextP ctx, VADisplayAttribType type) return NULL; } +static void +i965_display_attributes_terminate(VADriverContextP ctx) +{ + struct i965_driver_data * const i965 = i965_driver_data(ctx); + + if (i965->display_attributes) { + free(i965->display_attributes); + i965->display_attributes = NULL; + i965->num_display_attributes = 0; + } +} + static bool i965_display_attributes_init(VADriverContextP ctx) { @@ -2043,7 +2787,7 @@ i965_display_attributes_init(VADriverContextP ctx) i965->display_attributes = malloc( i965->num_display_attributes * sizeof(i965->display_attributes[0])); if (!i965->display_attributes) - return false; + goto error; memcpy( i965->display_attributes, @@ -2052,21 +2796,23 @@ i965_display_attributes_init(VADriverContextP ctx) ); i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation); - if (!i965->rotation_attrib) - return false; + i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness); + i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast); + i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue); + i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation); + + if (!i965->rotation_attrib || + !i965->brightness_attrib || + !i965->contrast_attrib || + !i965->hue_attrib || + !i965->saturation_attrib) { + goto error; + } return true; -} -static void -i965_display_attributes_terminate(VADriverContextP ctx) -{ - struct i965_driver_data * const i965 = i965_driver_data(ctx); - - if (i965->display_attributes) { - free(i965->display_attributes); - i965->display_attributes = NULL; - i965->num_display_attributes = 0; - } +error: + i965_display_attributes_terminate(ctx); + return false; } /* @@ -2168,54 +2914,6 @@ i965_DbgCopySurfaceToBuffer(VADriverContextP ctx, return VA_STATUS_ERROR_UNIMPLEMENTED; } -static VAStatus -i965_Init(VADriverContextP ctx) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - - if (intel_driver_init(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; - - if (IS_HASWELL(i965->intel.device_id)) - i965->codec_info = &gen75_hw_codec_info; - else if (IS_G4X(i965->intel.device_id)) - i965->codec_info = &g4x_hw_codec_info; - else if (IS_IRONLAKE(i965->intel.device_id)) - i965->codec_info = &ironlake_hw_codec_info; - else if (IS_GEN6(i965->intel.device_id)) - i965->codec_info = &gen6_hw_codec_info; - else if (IS_GEN7(i965->intel.device_id)) - i965->codec_info = &gen7_hw_codec_info; - else - return VA_STATUS_ERROR_UNKNOWN; - - i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0); - - if (!i965_display_attributes_init(ctx)) - return VA_STATUS_ERROR_UNKNOWN; - - if (i965_post_processing_init(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; - - if (i965_render_init(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; - -#ifdef HAVE_VA_WAYLAND - if (IS_VA_WAYLAND(ctx) && !i965_output_wayland_init(ctx)) - return VA_STATUS_ERROR_UNKNOWN; -#endif - -#ifdef HAVE_VA_X11 - if (IS_VA_X11(ctx) && !i965_output_dri_init(ctx)) - return VA_STATUS_ERROR_UNKNOWN; -#endif - - _i965InitMutex(&i965->render_mutex); - _i965InitMutex(&i965->pp_mutex); - - return VA_STATUS_SUCCESS; -} - static void i965_destroy_heap(struct object_heap *heap, void (*func)(struct object_heap *heap, struct object_base *object)) @@ -2250,7 +2948,7 @@ i965_CreateImage(VADriverContextP ctx, struct object_image *obj_image; VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED; VAImageID image_id; - unsigned int width2, height2, size2, size; + unsigned int size2, size, awidth, aheight; out_image->image_id = VA_INVALID_ID; out_image->buf = VA_INVALID_ID; @@ -2270,69 +2968,101 @@ i965_CreateImage(VADriverContextP ctx, image->image_id = image_id; image->buf = VA_INVALID_ID; - size = width * height; - width2 = (width + 1) / 2; - height2 = (height + 1) / 2; - size2 = width2 * height2; + awidth = ALIGN(width, i965->codec_info->min_linear_wpitch); + + if ((format->fourcc == VA_FOURCC_YV12) || + (format->fourcc == VA_FOURCC_I420)) { + if (awidth % 128 != 0) { + awidth = ALIGN(width, 128); + } + } + + aheight = ALIGN(height, i965->codec_info->min_linear_hpitch); + size = awidth * aheight; + size2 = (awidth / 2) * (aheight / 2); image->num_palette_entries = 0; image->entry_bytes = 0; memset(image->component_order, 0, sizeof(image->component_order)); switch (format->fourcc) { - case VA_FOURCC('I','A','4','4'): - case VA_FOURCC('A','I','4','4'): + case VA_FOURCC_IA44: + case VA_FOURCC_AI44: image->num_planes = 1; - image->pitches[0] = width; + image->pitches[0] = awidth; image->offsets[0] = 0; - image->data_size = image->offsets[0] + image->pitches[0] * height; + image->data_size = image->offsets[0] + image->pitches[0] * aheight; image->num_palette_entries = 16; image->entry_bytes = 3; image->component_order[0] = 'R'; image->component_order[1] = 'G'; image->component_order[2] = 'B'; break; - case VA_FOURCC('B','G','R','A'): - case VA_FOURCC('R','G','B','A'): - case VA_FOURCC('B','G','R','X'): - case VA_FOURCC('R','G','B','X'): + case VA_FOURCC_IA88: + case VA_FOURCC_AI88: + image->num_planes = 1; + image->pitches[0] = awidth * 2; + image->offsets[0] = 0; + image->data_size = image->offsets[0] + image->pitches[0] * aheight; + image->num_palette_entries = 256; + image->entry_bytes = 3; + image->component_order[0] = 'R'; + image->component_order[1] = 'G'; + image->component_order[2] = 'B'; + break; + case VA_FOURCC_ARGB: + case VA_FOURCC_ABGR: + case VA_FOURCC_BGRA: + case VA_FOURCC_RGBA: + case VA_FOURCC_BGRX: + case VA_FOURCC_RGBX: image->num_planes = 1; - image->pitches[0] = width * 4; + image->pitches[0] = awidth * 4; image->offsets[0] = 0; - image->data_size = image->offsets[0] + image->pitches[0] * height; + image->data_size = image->offsets[0] + image->pitches[0] * aheight; break; - case VA_FOURCC('Y','V','1','2'): + case VA_FOURCC_YV12: image->num_planes = 3; - image->pitches[0] = width; + image->pitches[0] = awidth; image->offsets[0] = 0; - image->pitches[1] = width2; - image->offsets[1] = size + size2; - image->pitches[2] = width2; - image->offsets[2] = size; + image->pitches[1] = awidth / 2; + image->offsets[1] = size; + image->pitches[2] = awidth / 2; + image->offsets[2] = size + size2; image->data_size = size + 2 * size2; break; - case VA_FOURCC('I','4','2','0'): + case VA_FOURCC_I420: image->num_planes = 3; - image->pitches[0] = width; + image->pitches[0] = awidth; image->offsets[0] = 0; - image->pitches[1] = width2; + image->pitches[1] = awidth / 2; image->offsets[1] = size; - image->pitches[2] = width2; + image->pitches[2] = awidth / 2; image->offsets[2] = size + size2; image->data_size = size + 2 * size2; break; - case VA_FOURCC('N','V','1','2'): + case VA_FOURCC_422H: + image->num_planes = 3; + image->pitches[0] = awidth; + image->offsets[0] = 0; + image->pitches[1] = awidth / 2; + image->offsets[1] = size; + image->pitches[2] = awidth / 2; + image->offsets[2] = size + (awidth / 2) * aheight; + image->data_size = size + 2 * ((awidth / 2) * aheight); + break; + case VA_FOURCC_NV12: image->num_planes = 2; - image->pitches[0] = width; + image->pitches[0] = awidth; image->offsets[0] = 0; - image->pitches[1] = width; + image->pitches[1] = awidth; image->offsets[1] = size; image->data_size = size + 2 * size2; break; - case VA_FOURCC('Y','U','Y','2'): - case VA_FOURCC('U','Y','V','Y'): + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: image->num_planes = 1; - image->pitches[0] = width * 2; + image->pitches[0] = awidth * 2; image->offsets[0] = 0; image->data_size = size * 2; break; @@ -2345,11 +3075,18 @@ i965_CreateImage(VADriverContextP ctx, if (va_status != VA_STATUS_SUCCESS) goto error; - obj_image->bo = BUFFER(image->buf)->buffer_store->bo; + struct object_buffer *obj_buffer = BUFFER(image->buf); + + if (!obj_buffer || + !obj_buffer->buffer_store || + !obj_buffer->buffer_store->bo) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + + obj_image->bo = obj_buffer->buffer_store->bo; dri_bo_reference(obj_image->bo); if (image->num_palette_entries > 0 && image->entry_bytes > 0) { - obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette)); + obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette)); if (!obj_image->palette) goto error; } @@ -2367,7 +3104,7 @@ i965_CreateImage(VADriverContextP ctx, return va_status; } -void +VAStatus i965_check_alloc_surface_bo(VADriverContextP ctx, struct object_surface *obj_surface, int tiled, @@ -2377,136 +3114,171 @@ i965_check_alloc_surface_bo(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); int region_width, region_height; - if (obj_surface->bo) { - assert(obj_surface->fourcc); - assert(obj_surface->fourcc == fourcc); - assert(obj_surface->subsampling == subsampling); - return; - } + if (obj_surface->bo) { + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE); + return VA_STATUS_SUCCESS; + } + + obj_surface->x_cb_offset = 0; /* X offset is always 0 */ + obj_surface->x_cr_offset = 0; + + if ((tiled && !obj_surface->user_disable_tiling)) { + ASSERT_RET(fourcc != VA_FOURCC_I420 && + fourcc != VA_FOURCC_IYUV && + fourcc != VA_FOURCC_YV12, + VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT); + if (obj_surface->user_h_stride_set) { + ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER); + } else + obj_surface->width = ALIGN(obj_surface->orig_width, 128); + + if (obj_surface->user_v_stride_set) { + ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER); + } else + obj_surface->height = ALIGN(obj_surface->orig_height, 32); + + region_height = obj_surface->height; + + switch (fourcc) { + case VA_FOURCC_NV12: + assert(subsampling == SUBSAMPLE_YUV420); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->height; + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32); + + break; + + case VA_FOURCC_IMC1: + assert(subsampling == SUBSAMPLE_YUV420); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->y_cr_offset = obj_surface->height; + obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32); + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; + + break; + + case VA_FOURCC_IMC3: + assert(subsampling == SUBSAMPLE_YUV420); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; + + break; + + case VA_FOURCC_422H: + assert(subsampling == SUBSAMPLE_YUV422H); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; - obj_surface->x_cb_offset = 0; /* X offset is always 0 */ - obj_surface->x_cr_offset = 0; + break; - if (tiled) { - assert(fourcc == VA_FOURCC('N', 'V', '1', '2') || - fourcc == VA_FOURCC('I', 'M', 'C', '1') || - fourcc == VA_FOURCC('I', 'M', 'C', '3') || - fourcc == VA_FOURCC('R', 'G', 'B', 'A') || - fourcc == VA_FOURCC('R', 'G', 'B', 'X') || - fourcc == VA_FOURCC('B', 'G', 'R', 'A') || - fourcc == VA_FOURCC('B', 'G', 'R', 'X') || - fourcc == VA_FOURCC('Y', 'U', 'Y', '2')); - - obj_surface->width = ALIGN(obj_surface->orig_width, 128); - obj_surface->height = ALIGN(obj_surface->orig_height, 32); - region_height = obj_surface->height; + case VA_FOURCC_422V: + assert(subsampling == SUBSAMPLE_YUV422V); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; + + break; - if (fourcc == VA_FOURCC('N', 'V', '1', '2') || - fourcc == VA_FOURCC('I', 'M', 'C', '1') || - fourcc == VA_FOURCC('I', 'M', 'C', '3')) { + case VA_FOURCC_411P: + assert(subsampling == SUBSAMPLE_YUV411); obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width / 4; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->y_cb_offset = obj_surface->height; + obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); region_width = obj_surface->width; - } - else if (fourcc == VA_FOURCC('Y','U', 'Y', '2')) { - obj_surface->cb_cr_pitch = obj_surface->width * 2; - region_width = obj_surface->width * 2; - } - else if (fourcc == VA_FOURCC('R', 'G', 'B', 'A') || - fourcc == VA_FOURCC('R', 'G', 'B', 'X') || - fourcc == VA_FOURCC('B', 'G', 'R', 'A') || - fourcc == VA_FOURCC('B', 'G', 'R', 'X')) { - region_width = obj_surface->width * 4; - } - else { - assert(0); - } - + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; - if (fourcc == VA_FOURCC('N', 'V', '1', '2')) { - assert(subsampling == SUBSAMPLE_YUV420); + break; + + case VA_FOURCC_444P: + assert(subsampling == SUBSAMPLE_YUV444); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->cb_cr_width = obj_surface->orig_width; + obj_surface->cb_cr_height = obj_surface->orig_height; obj_surface->y_cb_offset = obj_surface->height; - obj_surface->y_cr_offset = obj_surface->height; - obj_surface->cb_cr_width = obj_surface->orig_width / 2; - obj_surface->cb_cr_height = obj_surface->orig_height / 2; - region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32); - } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') || - fourcc == VA_FOURCC('I', 'M', 'C', '3') || - fourcc == VA_FOURCC('R', 'G', 'B', 'A') || - fourcc == VA_FOURCC('R', 'G', 'B', 'X') || - fourcc == VA_FOURCC('B', 'G', 'R', 'A') || - fourcc == VA_FOURCC('B', 'G', 'R', 'X') || - fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) { - switch (subsampling) { - case SUBSAMPLE_YUV400: - obj_surface->cb_cr_width = 0; - obj_surface->cb_cr_height = 0; - break; + obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); + region_width = obj_surface->width; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; - case SUBSAMPLE_YUV420: - obj_surface->cb_cr_width = obj_surface->orig_width / 2; - obj_surface->cb_cr_height = obj_surface->orig_height / 2; - break; + break; - case SUBSAMPLE_YUV422H: - obj_surface->cb_cr_width = obj_surface->orig_width / 2; - obj_surface->cb_cr_height = obj_surface->orig_height; - break; + case VA_FOURCC_Y800: + assert(subsampling == SUBSAMPLE_YUV400); + obj_surface->cb_cr_pitch = 0; + obj_surface->cb_cr_width = 0; + obj_surface->cb_cr_height = 0; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + region_width = obj_surface->width; + region_height = obj_surface->height; - case SUBSAMPLE_YUV422V: - obj_surface->cb_cr_width = obj_surface->orig_width; - obj_surface->cb_cr_height = obj_surface->orig_height / 2; - break; + break; - case SUBSAMPLE_YUV444: - obj_surface->cb_cr_width = obj_surface->orig_width; - obj_surface->cb_cr_height = obj_surface->orig_height; - break; + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: + assert(subsampling == SUBSAMPLE_YUV422H); + obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128); + obj_surface->cb_cr_pitch = obj_surface->width; + obj_surface->y_cb_offset = 0; + obj_surface->y_cr_offset = 0; + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height / 2; + region_width = obj_surface->width; + region_height = obj_surface->height; + + break; - case SUBSAMPLE_YUV411: - obj_surface->cb_cr_width = obj_surface->orig_width / 4; - obj_surface->cb_cr_height = obj_surface->orig_height; - break; - case SUBSAMPLE_RGBX: - break; - default: - assert(0); - break; - } + case VA_FOURCC_RGBA: + case VA_FOURCC_RGBX: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: + assert(subsampling == SUBSAMPLE_RGBX); - region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2; + obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128); + region_width = obj_surface->width; + region_height = obj_surface->height; + break; - if (fourcc == VA_FOURCC('I', 'M', 'C', '1')) { - obj_surface->y_cr_offset = obj_surface->height; - obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32); - } else if (fourcc == VA_FOURCC('I', 'M', 'C', '3')){ - obj_surface->y_cb_offset = obj_surface->height; - obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32); - } - else if (fourcc == VA_FOURCC('Y','U', 'Y', '2')) { - obj_surface->y_cb_offset = 0; - obj_surface->y_cr_offset = 0; - region_height = obj_surface->height; - } - else if (fourcc == VA_FOURCC('R', 'G', 'B', 'A') || - fourcc == VA_FOURCC('R', 'G', 'B', 'X') || - fourcc == VA_FOURCC('B', 'G', 'R', 'A') || - fourcc == VA_FOURCC('B', 'G', 'R', 'X')) { - region_height = obj_surface->height; - } + default: + /* Never get here */ + ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT); + break; } } else { - assert(fourcc != VA_FOURCC('I', 'M', 'C', '1') && - fourcc != VA_FOURCC('I', 'M', 'C', '3')); assert(subsampling == SUBSAMPLE_YUV420 || subsampling == SUBSAMPLE_YUV422H || - subsampling == SUBSAMPLE_YUV422V || + subsampling == SUBSAMPLE_YUV422V || subsampling == SUBSAMPLE_RGBX); region_width = obj_surface->width; region_height = obj_surface->height; switch (fourcc) { - case VA_FOURCC('N', 'V', '1', '2'): + case VA_FOURCC_NV12: obj_surface->y_cb_offset = obj_surface->height; obj_surface->y_cr_offset = obj_surface->height; obj_surface->cb_cr_width = obj_surface->orig_width / 2; @@ -2515,9 +3287,18 @@ i965_check_alloc_surface_bo(VADriverContextP ctx, region_height = obj_surface->height + obj_surface->height / 2; break; - case VA_FOURCC('Y', 'V', '1', '2'): - case VA_FOURCC('I', '4', '2', '0'): - if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) { + case VA_FOURCC_YV16: + obj_surface->cb_cr_width = obj_surface->orig_width / 2; + obj_surface->cb_cr_height = obj_surface->orig_height; + obj_surface->y_cr_offset = obj_surface->height; + obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2; + obj_surface->cb_cr_pitch = obj_surface->width / 2; + region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32); + break; + + case VA_FOURCC_YV12: + case VA_FOURCC_I420: + if (fourcc == VA_FOURCC_YV12) { obj_surface->y_cr_offset = obj_surface->height; obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4; } else { @@ -2531,32 +3312,36 @@ i965_check_alloc_surface_bo(VADriverContextP ctx, region_height = obj_surface->height + obj_surface->height / 2; break; - case VA_FOURCC('Y','U', 'Y', '2'): + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: + obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch); obj_surface->y_cb_offset = 0; obj_surface->y_cr_offset = 0; obj_surface->cb_cr_width = obj_surface->orig_width / 2; obj_surface->cb_cr_height = obj_surface->orig_height; - obj_surface->cb_cr_pitch = obj_surface->width * 2; - region_width = obj_surface->width * 2; + obj_surface->cb_cr_pitch = obj_surface->width; + region_width = obj_surface->width; region_height = obj_surface->height; break; - case VA_FOURCC('R', 'G', 'B', 'A'): - case VA_FOURCC('R', 'G', 'B', 'X'): - case VA_FOURCC('B', 'G', 'R', 'A'): - case VA_FOURCC('B', 'G', 'R', 'X'): - region_width = obj_surface->width * 4; + case VA_FOURCC_RGBA: + case VA_FOURCC_RGBX: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: + obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch); + region_width = obj_surface->width; region_height = obj_surface->height; break; default: - assert(0); + /* Never get here */ + ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT); break; } } obj_surface->size = ALIGN(region_width * region_height, 0x1000); - if (tiled) { + if ((tiled && !obj_surface->user_disable_tiling)) { uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */ unsigned long pitch; @@ -2569,9 +3354,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx, &pitch, 0); assert(tiling_mode == I915_TILING_Y); - assert(pitch == obj_surface->width || - pitch == obj_surface->width * 2 || - pitch == obj_surface->width * 4) ; + assert(pitch == obj_surface->width); } else { obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr, "vaapi surface", @@ -2582,6 +3365,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx, obj_surface->fourcc = fourcc; obj_surface->subsampling = subsampling; assert(obj_surface->bo); + return VA_STATUS_SUCCESS; } VAStatus i965_DeriveImage(VADriverContextP ctx, @@ -2592,7 +3376,7 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, struct object_image *obj_image; struct object_surface *obj_surface; VAImageID image_id; - unsigned int w_pitch, h_pitch; + unsigned int w_pitch; VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED; out_image->image_id = VA_INVALID_ID; @@ -2603,16 +3387,17 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, if (!obj_surface->bo) { unsigned int is_tiled = 0; - unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2'); + unsigned int fourcc = VA_FOURCC_YV12; i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled); int sampling = get_sampling_from_fourcc(fourcc); - i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling); + va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling); + if (va_status != VA_STATUS_SUCCESS) + return va_status; } - assert(obj_surface->fourcc); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); w_pitch = obj_surface->width; - h_pitch = obj_surface->height; image_id = NEW_IMAGE_ID(); @@ -2644,7 +3429,17 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, image->format.bits_per_pixel = 12; switch (image->format.fourcc) { - case VA_FOURCC('Y', 'V', '1', '2'): + case VA_FOURCC_YV12: + image->num_planes = 3; + image->pitches[0] = w_pitch; /* Y */ + image->offsets[0] = 0; + image->pitches[1] = obj_surface->cb_cr_pitch; /* V */ + image->offsets[1] = w_pitch * obj_surface->y_cr_offset; + image->pitches[2] = obj_surface->cb_cr_pitch; /* U */ + image->offsets[2] = w_pitch * obj_surface->y_cb_offset; + break; + + case VA_FOURCC_YV16: image->num_planes = 3; image->pitches[0] = w_pitch; /* Y */ image->offsets[0] = 0; @@ -2654,7 +3449,7 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, image->offsets[2] = w_pitch * obj_surface->y_cb_offset; break; - case VA_FOURCC('N', 'V', '1', '2'): + case VA_FOURCC_NV12: image->num_planes = 2; image->pitches[0] = w_pitch; /* Y */ image->offsets[0] = 0; @@ -2662,7 +3457,12 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, image->offsets[1] = w_pitch * obj_surface->y_cb_offset; break; - case VA_FOURCC('I', '4', '2', '0'): + case VA_FOURCC_I420: + case VA_FOURCC_422H: + case VA_FOURCC_IMC3: + case VA_FOURCC_444P: + case VA_FOURCC_422V: + case VA_FOURCC_411P: image->num_planes = 3; image->pitches[0] = w_pitch; /* Y */ image->offsets[0] = 0; @@ -2671,21 +3471,20 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, image->pitches[2] = obj_surface->cb_cr_pitch; /* V */ image->offsets[2] = w_pitch * obj_surface->y_cr_offset; break; - case VA_FOURCC('Y', 'U', 'Y', '2'): + + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: + case VA_FOURCC_Y800: image->num_planes = 1; - image->pitches[0] = obj_surface->width * 2; /* Y, width is aligned already */ + image->pitches[0] = obj_surface->width; /* Y, width is aligned already */ image->offsets[0] = 0; - image->pitches[1] = obj_surface->width * 2; /* U */ - image->offsets[1] = 0; - image->pitches[2] = obj_surface->width * 2; /* V */ - image->offsets[2] = 0; break; - case VA_FOURCC('R', 'G', 'B', 'A'): - case VA_FOURCC('R', 'G', 'B', 'X'): - case VA_FOURCC('B', 'G', 'R', 'A'): - case VA_FOURCC('B', 'G', 'R', 'X'): + case VA_FOURCC_RGBA: + case VA_FOURCC_RGBX: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: image->num_planes = 1; - image->pitches[0] = obj_surface->width * 4; + image->pitches[0] = obj_surface->width; break; default: goto error; @@ -2696,11 +3495,18 @@ VAStatus i965_DeriveImage(VADriverContextP ctx, if (va_status != VA_STATUS_SUCCESS) goto error; - obj_image->bo = BUFFER(image->buf)->buffer_store->bo; + struct object_buffer *obj_buffer = BUFFER(image->buf); + + if (!obj_buffer || + !obj_buffer->buffer_store || + !obj_buffer->buffer_store->bo) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + + obj_image->bo = obj_buffer->buffer_store->bo; dri_bo_reference(obj_image->bo); if (image->num_palette_entries > 0 && image->entry_bytes > 0) { - obj_image->palette = malloc(image->num_palette_entries * sizeof(obj_image->palette)); + obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette)); if (!obj_image->palette) { va_status = VA_STATUS_ERROR_ALLOCATION_FAILED; goto error; @@ -2789,28 +3595,12 @@ i965_SetImagePalette(VADriverContextP ctx, static int get_sampling_from_fourcc(unsigned int fourcc) { - int surface_sampling = -1; - switch (fourcc) { - case VA_FOURCC('N', 'V', '1', '2'): - case VA_FOURCC('Y', 'V', '1', '2'): - case VA_FOURCC('I', '4', '2', '0'): - case VA_FOURCC('I', 'M', 'C', '1'): - case VA_FOURCC('I', 'M', 'C', '3'): - surface_sampling = SUBSAMPLE_YUV420; - break; - case VA_FOURCC('Y', 'U', 'Y', '2'): - surface_sampling = SUBSAMPLE_YUV422H; - break; - case VA_FOURCC('R','G','B','A'): - case VA_FOURCC('R','G','B','X'): - case VA_FOURCC('B','G','R','A'): - case VA_FOURCC('B','G','R','X'): - surface_sampling = SUBSAMPLE_RGBX; - break; - default: - break; - } - return surface_sampling; + const i965_fourcc_info *info = get_fourcc_info(fourcc); + + if (info && (info->flag & I_S)) + return info->subsampling; + else + return -1; } static inline void @@ -2827,7 +3617,7 @@ memcpy_pic(uint8_t *dst, unsigned int dst_stride, } } -static void +static VAStatus get_image_i420(struct object_image *obj_image, uint8_t *image_data, struct object_surface *obj_surface, const VARectangle *rect) @@ -2837,11 +3627,12 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data, const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2; const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; if (!obj_surface->bo) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; - assert(obj_surface->fourcc); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); if (tiling != I915_TILING_NONE) @@ -2850,7 +3641,7 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Dest VA image has either I420 or YV12 format. Source VA surface alway has I420 format */ @@ -2886,18 +3677,21 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } -static void +static VAStatus get_image_nv12(struct object_image *obj_image, uint8_t *image_data, struct object_surface *obj_surface, const VARectangle *rect) { uint8_t *dst[2], *src[2]; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; if (!obj_surface->bo) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; assert(obj_surface->fourcc); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); @@ -2908,7 +3702,7 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Both dest VA image and source surface have NV12 format */ dst[0] = image_data + obj_image->image.offsets[0]; @@ -2934,18 +3728,21 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } -static void +static VAStatus get_image_yuy2(struct object_image *obj_image, uint8_t *image_data, struct object_surface *obj_surface, const VARectangle *rect) { uint8_t *dst, *src; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; if (!obj_surface->bo) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; assert(obj_surface->fourcc); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); @@ -2956,7 +3753,7 @@ get_image_yuy2(struct object_image *obj_image, uint8_t *image_data, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Both dest VA image and source surface have YUYV format */ dst = image_data + obj_image->image.offsets[0]; @@ -2973,6 +3770,8 @@ get_image_yuy2(struct object_image *obj_image, uint8_t *image_data, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } static VAStatus @@ -2986,6 +3785,7 @@ i965_sw_getimage(VADriverContextP ctx, { struct i965_driver_data *i965 = i965_driver_data(ctx); struct i965_render_state *render_state = &i965->render_state; + VAStatus va_status = VA_STATUS_SUCCESS; struct object_surface *obj_surface = SURFACE(surface); if (!obj_surface) @@ -3007,7 +3807,6 @@ i965_sw_getimage(VADriverContextP ctx, if (obj_surface->fourcc != obj_image->image.format.fourcc) return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT; - VAStatus va_status; void *image_data = NULL; va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data); @@ -3021,20 +3820,20 @@ i965_sw_getimage(VADriverContextP ctx, rect.height = height; switch (obj_image->image.format.fourcc) { - case VA_FOURCC('Y','V','1','2'): - case VA_FOURCC('I','4','2','0'): + case VA_FOURCC_YV12: + case VA_FOURCC_I420: /* I420 is native format for MPEG-2 decoded surfaces */ if (render_state->interleaved_uv) goto operation_failed; get_image_i420(obj_image, image_data, obj_surface, &rect); break; - case VA_FOURCC('N','V','1','2'): + case VA_FOURCC_NV12: /* NV12 is native format for H.264 decoded surfaces */ if (!render_state->interleaved_uv) goto operation_failed; get_image_nv12(obj_image, image_data, obj_surface, &rect); break; - case VA_FOURCC('Y','U','Y','2'): + case VA_FOURCC_YUY2: /* YUY2 is the format supported by overlay plane */ get_image_yuy2(obj_image, image_data, obj_surface, &rect); break; @@ -3044,7 +3843,10 @@ i965_sw_getimage(VADriverContextP ctx, break; } - i965_UnmapBuffer(ctx, obj_image->image.buf); + if (va_status != VA_STATUS_SUCCESS) + return va_status; + + va_status = i965_UnmapBuffer(ctx, obj_image->image.buf); return va_status; } @@ -3060,7 +3862,7 @@ i965_hw_getimage(VADriverContextP ctx, struct i965_driver_data *i965 = i965_driver_data(ctx); struct i965_surface src_surface; struct i965_surface dst_surface; - VAStatus va_status; + VAStatus va_status = VA_STATUS_SUCCESS; VARectangle rect; struct object_surface *obj_surface = SURFACE(surface); struct object_image *obj_image = IMAGE(image); @@ -3089,11 +3891,11 @@ i965_hw_getimage(VADriverContextP ctx, rect.width = width; rect.height = height; - src_surface.id = surface; + src_surface.base = (struct object_base *)obj_surface; src_surface.type = I965_SURFACE_TYPE_SURFACE; src_surface.flags = I965_SURFACE_FLAG_FRAME; - dst_surface.id = image; + dst_surface.base = (struct object_base *)obj_image; dst_surface.type = I965_SURFACE_TYPE_IMAGE; dst_surface.flags = I965_SURFACE_FLAG_FRAME; @@ -3117,7 +3919,7 @@ i965_GetImage(VADriverContextP ctx, VAImageID image) { struct i965_driver_data * const i965 = i965_driver_data(ctx); - VAStatus va_status; + VAStatus va_status = VA_STATUS_SUCCESS; if (HAS_ACCELERATED_GETIMAGE(i965)) va_status = i965_hw_getimage(ctx, @@ -3135,7 +3937,7 @@ i965_GetImage(VADriverContextP ctx, return va_status; } -static void +static VAStatus put_image_i420(struct object_surface *obj_surface, const VARectangle *dst_rect, struct object_image *obj_image, uint8_t *image_data, @@ -3146,13 +3948,13 @@ put_image_i420(struct object_surface *obj_surface, const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2; const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; - if (!obj_surface->bo) - return; + ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE); - assert(obj_surface->fourcc); - assert(dst_rect->width == src_rect->width); - assert(dst_rect->height == src_rect->height); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED); + ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); if (tiling != I915_TILING_NONE) @@ -3161,7 +3963,7 @@ put_image_i420(struct object_surface *obj_surface, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Dest VA image has either I420 or YV12 format. Source VA surface alway has I420 format */ @@ -3197,9 +3999,11 @@ put_image_i420(struct object_surface *obj_surface, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } -static void +static VAStatus put_image_nv12(struct object_surface *obj_surface, const VARectangle *dst_rect, struct object_image *obj_image, uint8_t *image_data, @@ -3207,13 +4011,14 @@ put_image_nv12(struct object_surface *obj_surface, { uint8_t *dst[2], *src[2]; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; if (!obj_surface->bo) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; - assert(obj_surface->fourcc); - assert(dst_rect->width == src_rect->width); - assert(dst_rect->height == src_rect->height); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED); + ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); if (tiling != I915_TILING_NONE) @@ -3222,7 +4027,7 @@ put_image_nv12(struct object_surface *obj_surface, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Both dest VA image and source surface have NV12 format */ dst[0] = (uint8_t *)obj_surface->bo->virtual; @@ -3248,9 +4053,11 @@ put_image_nv12(struct object_surface *obj_surface, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } -static void +static VAStatus put_image_yuy2(struct object_surface *obj_surface, const VARectangle *dst_rect, struct object_image *obj_image, uint8_t *image_data, @@ -3258,13 +4065,12 @@ put_image_yuy2(struct object_surface *obj_surface, { uint8_t *dst, *src; unsigned int tiling, swizzle; + VAStatus va_status = VA_STATUS_SUCCESS; - if (!obj_surface->bo) - return; - - assert(obj_surface->fourcc); - assert(dst_rect->width == src_rect->width); - assert(dst_rect->height == src_rect->height); + ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED); + ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED); dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle); if (tiling != I915_TILING_NONE) @@ -3273,7 +4079,7 @@ put_image_yuy2(struct object_surface *obj_surface, dri_bo_map(obj_surface->bo, 0); if (!obj_surface->bo->virtual) - return; + return VA_STATUS_ERROR_INVALID_SURFACE; /* Both dest VA image and source surface have YUY2 format */ dst = (uint8_t *)obj_surface->bo->virtual; @@ -3290,6 +4096,8 @@ put_image_yuy2(struct object_surface *obj_surface, drm_intel_gem_bo_unmap_gtt(obj_surface->bo); else dri_bo_unmap(obj_surface->bo); + + return va_status; } @@ -3308,13 +4116,12 @@ i965_sw_putimage(VADriverContextP ctx, { struct i965_driver_data *i965 = i965_driver_data(ctx); struct object_surface *obj_surface = SURFACE(surface); - - if (!obj_surface) - return VA_STATUS_ERROR_INVALID_SURFACE; - struct object_image *obj_image = IMAGE(image); - if (!obj_image) - return VA_STATUS_ERROR_INVALID_IMAGE; + VAStatus va_status = VA_STATUS_SUCCESS; + void *image_data = NULL; + + ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE); if (src_x < 0 || src_y < 0) return VA_STATUS_ERROR_INVALID_PARAMETER; @@ -3339,7 +4146,7 @@ i965_sw_putimage(VADriverContextP ctx, else { /* VA is surface not used for decoding, use same VA image format */ - i965_check_alloc_surface_bo( + va_status = i965_check_alloc_surface_bo( ctx, obj_surface, 0, /* XXX: don't use tiled surface */ @@ -3347,8 +4154,8 @@ i965_sw_putimage(VADriverContextP ctx, get_sampling_from_fourcc (obj_image->image.format.fourcc)); } - VAStatus va_status; - void *image_data = NULL; + if (va_status != VA_STATUS_SUCCESS) + return va_status; va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data); if (va_status != VA_STATUS_SUCCESS) @@ -3365,22 +4172,24 @@ i965_sw_putimage(VADriverContextP ctx, dest_rect.height = dest_height; switch (obj_image->image.format.fourcc) { - case VA_FOURCC('Y','V','1','2'): - case VA_FOURCC('I','4','2','0'): - put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect); + case VA_FOURCC_YV12: + case VA_FOURCC_I420: + va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect); break; - case VA_FOURCC('N','V','1','2'): - put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect); + case VA_FOURCC_NV12: + va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect); break; - case VA_FOURCC('Y','U','Y','2'): - put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect); + case VA_FOURCC_YUY2: + va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect); break; default: va_status = VA_STATUS_ERROR_OPERATION_FAILED; break; } + if (va_status != VA_STATUS_SUCCESS) + return va_status; - i965_UnmapBuffer(ctx, obj_image->image.buf); + va_status = i965_UnmapBuffer(ctx, obj_image->image.buf); return va_status; } @@ -3404,11 +4213,8 @@ i965_hw_putimage(VADriverContextP ctx, VAStatus va_status = VA_STATUS_SUCCESS; VARectangle src_rect, dst_rect; - if (!obj_surface) - return VA_STATUS_ERROR_INVALID_SURFACE; - - if (!obj_image || !obj_image->bo) - return VA_STATUS_ERROR_INVALID_IMAGE; + ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE); + ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE); if (src_x < 0 || src_y < 0 || @@ -3434,9 +4240,9 @@ i965_hw_putimage(VADriverContextP ctx, surface_sampling); } - assert(obj_surface->fourcc); + ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE); - src_surface.id = image; + src_surface.base = (struct object_base *)obj_image; src_surface.type = I965_SURFACE_TYPE_IMAGE; src_surface.flags = I965_SURFACE_FLAG_FRAME; src_rect.x = src_x; @@ -3444,7 +4250,7 @@ i965_hw_putimage(VADriverContextP ctx, src_rect.width = src_width; src_rect.height = src_height; - dst_surface.id = surface; + dst_surface.base = (struct object_base *)obj_surface; dst_surface.type = I965_SURFACE_TYPE_SURFACE; dst_surface.flags = I965_SURFACE_FLAG_FRAME; dst_rect.x = dest_x; @@ -3511,80 +4317,35 @@ i965_PutSurface(VADriverContextP ctx, void *draw, /* X Drawable */ short srcx, short srcy, - unsigned short srcw, - unsigned short srch, - short destx, - short desty, - unsigned short destw, - unsigned short desth, - VARectangle *cliprects, /* client supplied clip list */ - unsigned int number_cliprects, /* number of clip rects in the clip list */ - unsigned int flags) /* de-interlacing flags */ -{ -#ifdef HAVE_VA_X11 - if (IS_VA_X11(ctx)) { - VARectangle src_rect, dst_rect; - - src_rect.x = srcx; - src_rect.y = srcy; - src_rect.width = srcw; - src_rect.height = srch; - - dst_rect.x = destx; - dst_rect.y = desty; - dst_rect.width = destw; - dst_rect.height = desth; - - return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect, - cliprects, number_cliprects, flags); - } -#endif - return VA_STATUS_ERROR_UNIMPLEMENTED; -} - -VAStatus -i965_Terminate(VADriverContextP ctx) -{ - struct i965_driver_data *i965 = i965_driver_data(ctx); - - if (i965->batch) - intel_batchbuffer_free(i965->batch); - - _i965DestroyMutex(&i965->pp_mutex); - _i965DestroyMutex(&i965->render_mutex); - -#ifdef HAVE_VA_X11 - if (IS_VA_X11(ctx)) - i965_output_dri_terminate(ctx); -#endif - -#ifdef HAVE_VA_WAYLAND - if (IS_VA_WAYLAND(ctx)) - i965_output_wayland_terminate(ctx); -#endif - - if (i965_render_terminate(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; - - if (i965_post_processing_terminate(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; - - i965_display_attributes_terminate(ctx); - - i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer); - i965_destroy_heap(&i965->image_heap, i965_destroy_image); - i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic); - i965_destroy_heap(&i965->surface_heap, i965_destroy_surface); - i965_destroy_heap(&i965->context_heap, i965_destroy_context); - i965_destroy_heap(&i965->config_heap, i965_destroy_config); + unsigned short srcw, + unsigned short srch, + short destx, + short desty, + unsigned short destw, + unsigned short desth, + VARectangle *cliprects, /* client supplied clip list */ + unsigned int number_cliprects, /* number of clip rects in the clip list */ + unsigned int flags) /* de-interlacing flags */ +{ +#ifdef HAVE_VA_X11 + if (IS_VA_X11(ctx)) { + VARectangle src_rect, dst_rect; - if (intel_driver_terminate(ctx) == False) - return VA_STATUS_ERROR_UNKNOWN; + src_rect.x = srcx; + src_rect.y = srcy; + src_rect.width = srcw; + src_rect.height = srch; - free(ctx->pDriverData); - ctx->pDriverData = NULL; + dst_rect.x = destx; + dst_rect.y = desty; + dst_rect.width = destw; + dst_rect.height = desth; - return VA_STATUS_SUCCESS; + return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect, + cliprects, number_cliprects, flags); + } +#endif + return VA_STATUS_ERROR_UNIMPLEMENTED; } static VAStatus @@ -3602,6 +4363,8 @@ i965_BufferInfo( i965 = i965_driver_data(ctx); obj_buffer = BUFFER(buf_id); + ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER); + *type = obj_buffer->type; *size = obj_buffer->size_element; *num_elements = obj_buffer->num_elements; @@ -3629,15 +4392,15 @@ i965_LockSurface( struct object_surface *obj_surface = NULL; VAImage tmpImage; - assert(fourcc); - assert(luma_stride); - assert(chroma_u_stride); - assert(chroma_v_stride); - assert(luma_offset); - assert(chroma_u_offset); - assert(chroma_v_offset); - assert(buffer_name); - assert(buffer); + ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER); + ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER); tmpImage.image_id = VA_INVALID_ID; @@ -3772,41 +4535,42 @@ i965_GetSurfaceAttributes( attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; if (attrib_list[i].value.value.i == 0) { - if (IS_G4X(i965->intel.device_id)) { + if (IS_G4X(i965->intel.device_info)) { if (obj_config->profile == VAProfileMPEG2Simple || obj_config->profile == VAProfileMPEG2Main) { - attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0'); + attrib_list[i].value.value.i = VA_FOURCC_I420; } else { assert(0); attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED; } - } else if (IS_IRONLAKE(i965->intel.device_id)) { + } else if (IS_IRONLAKE(i965->intel.device_info)) { if (obj_config->profile == VAProfileMPEG2Simple || obj_config->profile == VAProfileMPEG2Main) { - attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0'); - } else if (obj_config->profile == VAProfileH264Baseline || + attrib_list[i].value.value.i = VA_FOURCC_I420; + } else if (obj_config->profile == VAProfileH264ConstrainedBaseline || obj_config->profile == VAProfileH264Main || obj_config->profile == VAProfileH264High) { - attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2'); + attrib_list[i].value.value.i = VA_FOURCC_NV12; } else if (obj_config->profile == VAProfileNone) { - attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2'); + attrib_list[i].value.value.i = VA_FOURCC_NV12; } else { assert(0); attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED; } - } else if (IS_GEN6(i965->intel.device_id)) { - attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2'); - } else if (IS_GEN7(i965->intel.device_id)) { + } else if (IS_GEN6(i965->intel.device_info)) { + attrib_list[i].value.value.i = VA_FOURCC_NV12; + } else if (IS_GEN7(i965->intel.device_info) || + IS_GEN8(i965->intel.device_info)) { if (obj_config->profile == VAProfileJPEGBaseline) attrib_list[i].value.value.i = 0; /* internal format */ else - attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2'); + attrib_list[i].value.value.i = VA_FOURCC_NV12; } } else { - if (IS_G4X(i965->intel.device_id)) { + if (IS_G4X(i965->intel.device_info)) { if (obj_config->profile == VAProfileMPEG2Simple || obj_config->profile == VAProfileMPEG2Main) { - if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) { + if (attrib_list[i].value.value.i != VA_FOURCC_I420) { attrib_list[i].value.value.i = 0; attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } @@ -3814,30 +4578,30 @@ i965_GetSurfaceAttributes( assert(0); attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED; } - } else if (IS_IRONLAKE(i965->intel.device_id)) { + } else if (IS_IRONLAKE(i965->intel.device_info)) { if (obj_config->profile == VAProfileMPEG2Simple || obj_config->profile == VAProfileMPEG2Main) { - if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) { + if (attrib_list[i].value.value.i != VA_FOURCC_I420) { attrib_list[i].value.value.i = 0; attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } - } else if (obj_config->profile == VAProfileH264Baseline || + } else if (obj_config->profile == VAProfileH264ConstrainedBaseline || obj_config->profile == VAProfileH264Main || obj_config->profile == VAProfileH264High) { - if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) { + if (attrib_list[i].value.value.i != VA_FOURCC_NV12) { attrib_list[i].value.value.i = 0; attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } } else if (obj_config->profile == VAProfileNone) { switch (attrib_list[i].value.value.i) { - case VA_FOURCC('N', 'V', '1', '2'): - case VA_FOURCC('I', '4', '2', '0'): - case VA_FOURCC('Y', 'V', '1', '2'): - case VA_FOURCC('Y', 'U', 'Y', '2'): - case VA_FOURCC('B', 'G', 'R', 'A'): - case VA_FOURCC('B', 'G', 'R', 'X'): - case VA_FOURCC('R', 'G', 'B', 'X'): - case VA_FOURCC('R', 'G', 'B', 'A'): + case VA_FOURCC_NV12: + case VA_FOURCC_I420: + case VA_FOURCC_YV12: + case VA_FOURCC_YUY2: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: + case VA_FOURCC_RGBX: + case VA_FOURCC_RGBA: break; default: attrib_list[i].value.value.i = 0; @@ -3848,18 +4612,18 @@ i965_GetSurfaceAttributes( assert(0); attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED; } - } else if (IS_GEN6(i965->intel.device_id)) { + } else if (IS_GEN6(i965->intel.device_info)) { if (obj_config->entrypoint == VAEntrypointEncSlice || obj_config->entrypoint == VAEntrypointVideoProc) { switch (attrib_list[i].value.value.i) { - case VA_FOURCC('N', 'V', '1', '2'): - case VA_FOURCC('I', '4', '2', '0'): - case VA_FOURCC('Y', 'V', '1', '2'): - case VA_FOURCC('Y', 'U', 'Y', '2'): - case VA_FOURCC('B', 'G', 'R', 'A'): - case VA_FOURCC('B', 'G', 'R', 'X'): - case VA_FOURCC('R', 'G', 'B', 'X'): - case VA_FOURCC('R', 'G', 'B', 'A'): + case VA_FOURCC_NV12: + case VA_FOURCC_I420: + case VA_FOURCC_YV12: + case VA_FOURCC_YUY2: + case VA_FOURCC_BGRA: + case VA_FOURCC_BGRX: + case VA_FOURCC_RGBX: + case VA_FOURCC_RGBA: break; default: attrib_list[i].value.value.i = 0; @@ -3867,18 +4631,19 @@ i965_GetSurfaceAttributes( break; } } else { - if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) { + if (attrib_list[i].value.value.i != VA_FOURCC_NV12) { attrib_list[i].value.value.i = 0; attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } } - } else if (IS_GEN7(i965->intel.device_id)) { + } else if (IS_GEN7(i965->intel.device_info) || + IS_GEN8(i965->intel.device_info)) { if (obj_config->entrypoint == VAEntrypointEncSlice || obj_config->entrypoint == VAEntrypointVideoProc) { switch (attrib_list[i].value.value.i) { - case VA_FOURCC('N', 'V', '1', '2'): - case VA_FOURCC('I', '4', '2', '0'): - case VA_FOURCC('Y', 'V', '1', '2'): + case VA_FOURCC_NV12: + case VA_FOURCC_I420: + case VA_FOURCC_YV12: break; default: attrib_list[i].value.value.i = 0; @@ -3890,7 +4655,7 @@ i965_GetSurfaceAttributes( attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */ attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } else { - if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) { + if (attrib_list[i].value.value.i != VA_FOURCC_NV12) { attrib_list[i].value.value.i = 0; attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE; } @@ -3922,6 +4687,410 @@ i965_GetSurfaceAttributes( return vaStatus; } +static VAStatus +i965_QuerySurfaceAttributes(VADriverContextP ctx, + VAConfigID config, + VASurfaceAttrib *attrib_list, + unsigned int *num_attribs) +{ + VAStatus vaStatus = VA_STATUS_SUCCESS; + struct i965_driver_data *i965 = i965_driver_data(ctx); + struct object_config *obj_config; + int i = 0; + VASurfaceAttrib *attribs = NULL; + + if (config == VA_INVALID_ID) + return VA_STATUS_ERROR_INVALID_CONFIG; + + obj_config = CONFIG(config); + + if (obj_config == NULL) + return VA_STATUS_ERROR_INVALID_CONFIG; + + if (!attrib_list && !num_attribs) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + if (attrib_list == NULL) { + *num_attribs = I965_MAX_SURFACE_ATTRIBUTES; + return VA_STATUS_SUCCESS; + } + + attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs)); + + if (attribs == NULL) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + + if (IS_G4X(i965->intel.device_info)) { + if (obj_config->profile == VAProfileMPEG2Simple || + obj_config->profile == VAProfileMPEG2Main) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + } + } else if (IS_IRONLAKE(i965->intel.device_info)) { + switch (obj_config->profile) { + case VAProfileMPEG2Simple: + case VAProfileMPEG2Main: + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + + break; + + case VAProfileH264ConstrainedBaseline: + case VAProfileH264Main: + case VAProfileH264High: + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + + case VAProfileNone: + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + + break; + + default: + break; + } + } else if (IS_GEN6(i965->intel.device_info)) { + if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */ + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */ + obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */ + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YV12; + i++; + + if (obj_config->entrypoint == VAEntrypointVideoProc) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YUY2; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBA; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBX; + i++; + } + } + } else if (IS_GEN7(i965->intel.device_info)) { + if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */ + if (obj_config->profile == VAProfileJPEGBaseline) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC3; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC1; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_Y800; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_411P; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_422H; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_422V; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_444P; + i++; + } else { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + } + } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */ + obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */ + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC3; + i++; + + if (obj_config->entrypoint == VAEntrypointVideoProc) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YUY2; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBA; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBX; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YV16; + i++; + } + } + } else if (IS_GEN8(i965->intel.device_info)) { + if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */ + if (obj_config->profile == VAProfileJPEGBaseline) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC3; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC1; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_Y800; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_411P; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_422H; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_422V; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_444P; + i++; + } else { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + } + } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */ + obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */ + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_NV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_I420; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YV12; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_IMC3; + i++; + + if (obj_config->entrypoint == VAEntrypointVideoProc) { + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YUY2; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBA; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_RGBX; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_BGRA; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_BGRX; + i++; + + attribs[i].type = VASurfaceAttribPixelFormat; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_FOURCC_YV16; + i++; + } + } + } + + attribs[i].type = VASurfaceAttribMemoryType; + attribs[i].value.type = VAGenericValueTypeInteger; + attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA | + VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM | + VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; + i++; + + attribs[i].type = VASurfaceAttribExternalBufferDescriptor; + attribs[i].value.type = VAGenericValueTypePointer; + attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE; + attribs[i].value.value.p = NULL; /* ignore */ + i++; + + if (i > *num_attribs) { + *num_attribs = i; + free(attribs); + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + } + + *num_attribs = i; + memcpy(attrib_list, attribs, i * sizeof(*attribs)); + free(attribs); + + return vaStatus; +} + +static int +i965_os_has_ring_support(VADriverContextP ctx, + int ring) +{ + struct i965_driver_data *const i965 = i965_driver_data(ctx); + + switch (ring) { + case I965_RING_BSD: + return i965->intel.has_bsd; + + case I965_RING_BLT: + return i965->intel.has_blt; + + case I965_RING_VEBOX: + return i965->intel.has_vebox; + + case I965_RING_NULL: + return 1; /* Always support */ + + default: + /* should never get here */ + assert(0); + break; + } + + return 0; +} + /* * Query video processing pipeline */ @@ -3933,21 +5102,24 @@ VAStatus i965_QueryVideoProcFilters( ) { struct i965_driver_data *const i965 = i965_driver_data(ctx); - unsigned int i = 0; - - if (HAS_VPP(i965)) { - filters[i++] = VAProcFilterNoiseReduction; - filters[i++] = VAProcFilterDeinterlacing; - } + unsigned int i = 0, num = 0; + + if (!num_filters || !filters) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + for (i = 0; i < i965->codec_info->num_filters; i++) { + if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) { + if (num == *num_filters) { + *num_filters = i965->codec_info->num_filters; - if(IS_HASWELL(i965->intel.device_id)){ - filters[i++] = VAProcFilterNone; - filters[i++] = VAProcFilterSharpening; - filters[i++] = VAProcFilterColorBalance; - filters[i++] = VAProcFilterColorStandard; + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + } + + filters[num++] = i965->codec_info->filters[i].type; + } } - *num_filters = i; + *num_filters = num; return VA_STATUS_SUCCESS; } @@ -3960,62 +5132,120 @@ VAStatus i965_QueryVideoProcFilterCaps( unsigned int *num_filter_caps ) { - struct i965_driver_data *const i965 = i965_driver_data(ctx); unsigned int i = 0; + struct i965_driver_data *const i965 = i965_driver_data(ctx); - if (type == VAProcFilterNoiseReduction) { - VAProcFilterCap *cap = filter_caps; + if (!filter_caps || !num_filter_caps) + return VA_STATUS_ERROR_INVALID_PARAMETER; - cap->range.min_value = 0.0; - cap->range.max_value = 1.0; - cap->range.default_value = 0.5; - cap->range.step = 0.03125; /* 1.0 / 32 */ - i++; - } else if (type == VAProcFilterDeinterlacing) { - VAProcFilterCapDeinterlacing *cap = filter_caps; - - cap->type = VAProcDeinterlacingBob; - i++; - cap++; + for (i = 0; i < i965->codec_info->num_filters; i++) { + if (type == i965->codec_info->filters[i].type && + i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) + break; } - if(IS_HASWELL(i965->intel.device_id)){ - if(type == VAProcFilterColorBalance){ - VAProcFilterCapColorBalance *cap = filter_caps; - cap->type = VAProcColorBalanceHue; - cap->range.min_value = -180.0; - cap->range.max_value = 180.0; - cap->range.default_value = 0.0; - cap->range.step = 1.0; - i++; - cap ++; + if (i == i965->codec_info->num_filters) + return VA_STATUS_ERROR_UNSUPPORTED_FILTER; + + i = 0; + + switch (type) { + case VAProcFilterNoiseReduction: + case VAProcFilterSharpening: + { + VAProcFilterCap *cap = filter_caps; + + if (*num_filter_caps < 1) { + *num_filter_caps = 1; + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + } + + cap->range.min_value = 0.0; + cap->range.max_value = 1.0; + cap->range.default_value = 0.5; + cap->range.step = 0.03125; /* 1.0 / 32 */ + i++; + } + + break; + + case VAProcFilterDeinterlacing: + { + VAProcFilterCapDeinterlacing *cap = filter_caps; + + if (*num_filter_caps < VAProcDeinterlacingCount) { + *num_filter_caps = VAProcDeinterlacingCount; + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + } + + cap->type = VAProcDeinterlacingBob; + i++; + cap++; + + + if (i965->codec_info->has_di_motion_adptive) { + cap->type = VAProcDeinterlacingMotionAdaptive; + i++; + cap++; + } + + if (i965->codec_info->has_di_motion_compensated) { + cap->type = VAProcDeinterlacingMotionCompensated; + i++; + cap++; + } + } + + break; + + case VAProcFilterColorBalance: + { + VAProcFilterCapColorBalance *cap = filter_caps; + + if (*num_filter_caps < VAProcColorBalanceCount) { + *num_filter_caps = VAProcColorBalanceCount; + return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; + } + + cap->type = VAProcColorBalanceHue; + cap->range.min_value = -180.0; + cap->range.max_value = 180.0; + cap->range.default_value = 0.0; + cap->range.step = 1.0; + i++; + cap++; - cap->type = VAProcColorBalanceSaturation; - cap->range.min_value = 0.0; - cap->range.max_value = 10.0; - cap->range.default_value = 0.0; - cap->range.step = 0.1; - i++; - cap ++; + cap->type = VAProcColorBalanceSaturation; + cap->range.min_value = 0.0; + cap->range.max_value = 10.0; + cap->range.default_value = 1.0; + cap->range.step = 0.1; + i++; + cap++; - cap->type = VAProcColorBalanceBrightness; - cap->range.min_value = -100.0; - cap->range.max_value = 100.0; - cap->range.default_value = 0.0; - cap->range.step = 1.0; - i++; - cap ++; + cap->type = VAProcColorBalanceBrightness; + cap->range.min_value = -100.0; + cap->range.max_value = 100.0; + cap->range.default_value = 0.0; + cap->range.step = 1.0; + i++; + cap++; - cap->type = VAProcColorBalanceContrast; - cap->range.min_value = 0.0; - cap->range.max_value = 10.0; - cap->range.default_value = 0.0; - cap->range.step = 0.1; - i++; - cap ++; - } - } + cap->type = VAProcColorBalanceContrast; + cap->range.min_value = 0.0; + cap->range.max_value = 10.0; + cap->range.default_value = 1.0; + cap->range.step = 0.1; + i++; + cap++; + } + break; + + default: + + break; + } *num_filter_caps = i; @@ -4052,6 +5282,12 @@ VAStatus i965_QueryVideoProcPipelineCaps( for (i = 0; i < num_filters; i++) { struct object_buffer *obj_buffer = BUFFER(filters[i]); + + if (!obj_buffer || + !obj_buffer->buffer_store || + !obj_buffer->buffer_store->buffer) + return VA_STATUS_ERROR_INVALID_BUFFER; + VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer; if (base->type == VAProcFilterNoiseReduction) { @@ -4060,9 +5296,226 @@ VAStatus i965_QueryVideoProcPipelineCaps( } else if (base->type == VAProcFilterDeinterlacing) { VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base; - assert(deint->algorithm == VAProcDeinterlacingWeave || - deint->algorithm == VAProcDeinterlacingBob); + ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob || + deint->algorithm == VAProcDeinterlacingMotionAdaptive || + deint->algorithm == VAProcDeinterlacingMotionCompensated, + VA_STATUS_ERROR_INVALID_PARAMETER); + + if (deint->algorithm == VAProcDeinterlacingMotionAdaptive || + deint->algorithm == VAProcDeinterlacingMotionCompensated); + pipeline_cap->num_forward_references++; + } else if (base->type == VAProcFilterSkinToneEnhancement) { + VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base; + (void)stde; + } + } + + return VA_STATUS_SUCCESS; +} + +extern const struct hw_codec_info *i965_get_codec_info(int devid); + +static bool +i965_driver_data_init(VADriverContextP ctx) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + + i965->codec_info = i965_get_codec_info(i965->intel.device_id); + + if (!i965->codec_info) + return false; + + if (object_heap_init(&i965->config_heap, + sizeof(struct object_config), + CONFIG_ID_OFFSET)) + goto err_config_heap; + if (object_heap_init(&i965->context_heap, + sizeof(struct object_context), + CONTEXT_ID_OFFSET)) + goto err_context_heap; + + if (object_heap_init(&i965->surface_heap, + sizeof(struct object_surface), + SURFACE_ID_OFFSET)) + goto err_surface_heap; + if (object_heap_init(&i965->buffer_heap, + sizeof(struct object_buffer), + BUFFER_ID_OFFSET)) + goto err_buffer_heap; + if (object_heap_init(&i965->image_heap, + sizeof(struct object_image), + IMAGE_ID_OFFSET)) + goto err_image_heap; + if (object_heap_init(&i965->subpic_heap, + sizeof(struct object_subpic), + SUBPIC_ID_OFFSET)) + goto err_subpic_heap; + + i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0); + i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0); + _i965InitMutex(&i965->render_mutex); + _i965InitMutex(&i965->pp_mutex); + + return true; + +err_subpic_heap: + object_heap_destroy(&i965->image_heap); +err_image_heap: + object_heap_destroy(&i965->buffer_heap); +err_buffer_heap: + object_heap_destroy(&i965->surface_heap); +err_surface_heap: + object_heap_destroy(&i965->context_heap); +err_context_heap: + object_heap_destroy(&i965->config_heap); +err_config_heap: + + return false; +} + +static void +i965_driver_data_terminate(VADriverContextP ctx) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + + _i965DestroyMutex(&i965->pp_mutex); + _i965DestroyMutex(&i965->render_mutex); + + if (i965->batch) + intel_batchbuffer_free(i965->batch); + + if (i965->pp_batch) + intel_batchbuffer_free(i965->pp_batch); + + i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic); + i965_destroy_heap(&i965->image_heap, i965_destroy_image); + i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer); + i965_destroy_heap(&i965->surface_heap, i965_destroy_surface); + i965_destroy_heap(&i965->context_heap, i965_destroy_context); + i965_destroy_heap(&i965->config_heap, i965_destroy_config); +} + +struct { + bool (*init)(VADriverContextP ctx); + void (*terminate)(VADriverContextP ctx); + int display_type; +} i965_sub_ops[] = { + { + intel_driver_init, + intel_driver_terminate, + 0, + }, + + { + i965_driver_data_init, + i965_driver_data_terminate, + 0, + }, + + { + i965_display_attributes_init, + i965_display_attributes_terminate, + 0, + }, + + { + i965_post_processing_init, + i965_post_processing_terminate, + 0, + }, + + { + i965_render_init, + i965_render_terminate, + 0, + }, + +#ifdef HAVE_VA_WAYLAND + { + i965_output_wayland_init, + i965_output_wayland_terminate, + VA_DISPLAY_WAYLAND, + }, +#endif + +#ifdef HAVE_VA_X11 + { + i965_output_dri_init, + i965_output_dri_terminate, + VA_DISPLAY_X11, + }, +#endif +}; + +static VAStatus +i965_Init(VADriverContextP ctx) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + int i; + const char *chipset; + + for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) { + if ((i965_sub_ops[i].display_type == 0 || + i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) && + !i965_sub_ops[i].init(ctx)) + break; + } + + if (i == ARRAY_ELEMS(i965_sub_ops)) { + switch (i965->intel.device_id) { +#undef CHIPSET +#define CHIPSET(id, family, dev, str) case id: chipset = str; break; +#include "i965_pciids.h" + default: + chipset = "Unknown Intel Chipset"; + break; + } + + sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d", + INTEL_STR_DRIVER_VENDOR, + INTEL_STR_DRIVER_NAME, + chipset, + INTEL_DRIVER_MAJOR_VERSION, + INTEL_DRIVER_MINOR_VERSION, + INTEL_DRIVER_MICRO_VERSION); + + if (INTEL_DRIVER_PRE_VERSION > 0) { + const int len = strlen(i965->va_vendor); + sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION); + } + + i965->current_context_id = VA_INVALID_ID; + + return VA_STATUS_SUCCESS; + } else { + i--; + + for (; i >= 0; i--) { + if (i965_sub_ops[i].display_type == 0 || + i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) { + i965_sub_ops[i].terminate(ctx); + } } + + return VA_STATUS_ERROR_UNKNOWN; + } +} + +VAStatus +i965_Terminate(VADriverContextP ctx) +{ + struct i965_driver_data *i965 = i965_driver_data(ctx); + int i; + + if (i965) { + for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--) + if (i965_sub_ops[i - 1].display_type == 0 || + i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) { + i965_sub_ops[i - 1].terminate(ctx); + } + + free(i965); + ctx->pDriverData = NULL; } return VA_STATUS_SUCCESS; @@ -4078,7 +5531,7 @@ VA_DRIVER_INIT_FUNC( VADriverContextP ctx ) struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp; struct i965_driver_data *i965; - int result; + VAStatus ret = VA_STATUS_ERROR_UNKNOWN; ctx->version_major = VA_MAJOR_VERSION; ctx->version_minor = VA_MINOR_VERSION; @@ -4092,7 +5545,6 @@ VA_DRIVER_INIT_FUNC( VADriverContextP ctx ) vtable->vaTerminate = i965_Terminate; vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints; vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles; - vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints; vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes; vtable->vaCreateConfig = i965_CreateConfig; vtable->vaDestroyConfig = i965_DestroyConfig; @@ -4134,6 +5586,7 @@ VA_DRIVER_INIT_FUNC( VADriverContextP ctx ) vtable->vaLockSurface = i965_LockSurface; vtable->vaUnlockSurface = i965_UnlockSurface; vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes; + vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes; vtable->vaCreateSurfaces2 = i965_CreateSurfaces2; vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters; @@ -4141,54 +5594,22 @@ VA_DRIVER_INIT_FUNC( VADriverContextP ctx ) vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps; i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965)); - assert(i965); - ctx->pDriverData = (void *)i965; - result = object_heap_init(&i965->config_heap, - sizeof(struct object_config), - CONFIG_ID_OFFSET); - assert(result == 0); - - result = object_heap_init(&i965->context_heap, - sizeof(struct object_context), - CONTEXT_ID_OFFSET); - assert(result == 0); - - result = object_heap_init(&i965->surface_heap, - sizeof(struct object_surface), - SURFACE_ID_OFFSET); - assert(result == 0); - - result = object_heap_init(&i965->buffer_heap, - sizeof(struct object_buffer), - BUFFER_ID_OFFSET); - assert(result == 0); - - result = object_heap_init(&i965->image_heap, - sizeof(struct object_image), - IMAGE_ID_OFFSET); - assert(result == 0); - - result = object_heap_init(&i965->subpic_heap, - sizeof(struct object_subpic), - SUBPIC_ID_OFFSET); - assert(result == 0); - - sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d", - INTEL_STR_DRIVER_VENDOR, - INTEL_STR_DRIVER_NAME, - INTEL_DRIVER_MAJOR_VERSION, - INTEL_DRIVER_MINOR_VERSION, - INTEL_DRIVER_MICRO_VERSION); - - if (INTEL_DRIVER_PRE_VERSION > 0) { - const int len = strlen(i965->va_vendor); - sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION); + if (i965 == NULL) { + ctx->pDriverData = NULL; + + return VA_STATUS_ERROR_ALLOCATION_FAILED; } - i965->current_context_id = VA_INVALID_ID; + ctx->pDriverData = (void *)i965; + ret = i965_Init(ctx); + + if (ret == VA_STATUS_SUCCESS) { + ctx->str_vendor = i965->va_vendor; + } else { + free(i965); + ctx->pDriverData = NULL; + } - ctx->str_vendor = i965->va_vendor; - - return i965_Init(ctx); + return ret; }