psb_surface_gralloc.c revision b7f89c9efe4cecf957dee1f1d9f58dc1954746cf
1f31d5416a60f83e184b0906a7ec77ba021840531hding/*
2f31d5416a60f83e184b0906a7ec77ba021840531hding * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3f31d5416a60f83e184b0906a7ec77ba021840531hding *
4f31d5416a60f83e184b0906a7ec77ba021840531hding * Permission is hereby granted, free of charge, to any person obtaining a
5f31d5416a60f83e184b0906a7ec77ba021840531hding * copy of this software and associated documentation files (the
6f31d5416a60f83e184b0906a7ec77ba021840531hding * "Software"), to deal in the Software without restriction, including
7f31d5416a60f83e184b0906a7ec77ba021840531hding * without limitation the rights to use, copy, modify, merge, publish,
8f31d5416a60f83e184b0906a7ec77ba021840531hding * distribute, sub license, and/or sell copies of the Software, and to
9f31d5416a60f83e184b0906a7ec77ba021840531hding * permit persons to whom the Software is furnished to do so, subject to
10f31d5416a60f83e184b0906a7ec77ba021840531hding * the following conditions:
11f31d5416a60f83e184b0906a7ec77ba021840531hding *
12f31d5416a60f83e184b0906a7ec77ba021840531hding * The above copyright notice and this permission notice (including the
13f31d5416a60f83e184b0906a7ec77ba021840531hding * next paragraph) shall be included in all copies or substantial portions
14f31d5416a60f83e184b0906a7ec77ba021840531hding * of the Software.
15f31d5416a60f83e184b0906a7ec77ba021840531hding *
16f31d5416a60f83e184b0906a7ec77ba021840531hding * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17f31d5416a60f83e184b0906a7ec77ba021840531hding * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18f31d5416a60f83e184b0906a7ec77ba021840531hding * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19f31d5416a60f83e184b0906a7ec77ba021840531hding * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20f31d5416a60f83e184b0906a7ec77ba021840531hding * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21f31d5416a60f83e184b0906a7ec77ba021840531hding * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22f31d5416a60f83e184b0906a7ec77ba021840531hding * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23f31d5416a60f83e184b0906a7ec77ba021840531hding *
24f31d5416a60f83e184b0906a7ec77ba021840531hding */
25f31d5416a60f83e184b0906a7ec77ba021840531hding
26f31d5416a60f83e184b0906a7ec77ba021840531hding#include <sys/mman.h>
27f31d5416a60f83e184b0906a7ec77ba021840531hding#include <va/va_tpi.h>
28f31d5416a60f83e184b0906a7ec77ba021840531hding#include "psb_drv_video.h"
29f31d5416a60f83e184b0906a7ec77ba021840531hding#include "psb_drv_debug.h"
30f31d5416a60f83e184b0906a7ec77ba021840531hding#include "psb_surface.h"
31f31d5416a60f83e184b0906a7ec77ba021840531hding
32f31d5416a60f83e184b0906a7ec77ba021840531hding#include <gralloc.h>
33f31d5416a60f83e184b0906a7ec77ba021840531hding#include "android/psb_gralloc.h"
34f31d5416a60f83e184b0906a7ec77ba021840531hding#include "android/psb_android_glue.h"
35f31d5416a60f83e184b0906a7ec77ba021840531hding
36f31d5416a60f83e184b0906a7ec77ba021840531hding#define INIT_DRIVER_DATA    psb_driver_data_p driver_data = (psb_driver_data_p) ctx->pDriverData;
37f31d5416a60f83e184b0906a7ec77ba021840531hding#define CONFIG(id)  ((object_config_p) object_heap_lookup( &driver_data->config_heap, id ))
38f31d5416a60f83e184b0906a7ec77ba021840531hding#define CONTEXT(id) ((object_context_p) object_heap_lookup( &driver_data->context_heap, id ))
39f31d5416a60f83e184b0906a7ec77ba021840531hding#define SURFACE(id)    ((object_surface_p) object_heap_lookup( &driver_data->surface_heap, id ))
40f31d5416a60f83e184b0906a7ec77ba021840531hding#define BUFFER(id)  ((object_buffer_p) object_heap_lookup( &driver_data->buffer_heap, id ))
41f31d5416a60f83e184b0906a7ec77ba021840531hding
422db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu/*FIXME: include hal_public.h instead of define it here*/
432db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Huenum {
442db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    GRALLOC_SUB_BUFFER0 = 0,
452db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    GRALLOC_SUB_BUFFER1,
462db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    GRALLOC_SUB_BUFFER2,
472db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    GRALLOC_SUB_BUFFER_MAX,
482db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu};
49f31d5416a60f83e184b0906a7ec77ba021840531hding
50f31d5416a60f83e184b0906a7ec77ba021840531hdingVAStatus psb_DestroySurfaceGralloc(object_surface_p obj_surface)
51f31d5416a60f83e184b0906a7ec77ba021840531hding{
522db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    void *vaddr[GRALLOC_SUB_BUFFER_MAX];
536028b94d5c9bc36237c553878e7fe66ee74fe908wfeng    int usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER;
54f31d5416a60f83e184b0906a7ec77ba021840531hding    buffer_handle_t handle = obj_surface->psb_surface->buf.handle;
55f31d5416a60f83e184b0906a7ec77ba021840531hding    if (!gralloc_lock(handle, usage, 0, 0,
562db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu                      obj_surface->width, obj_surface->height, (void **)&vaddr[GRALLOC_SUB_BUFFER0])){
572db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu        if (vaddr[GRALLOC_SUB_BUFFER1] == obj_surface->share_info) {
58b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int metadata_rotate = obj_surface->share_info->metadata_rotate;
59b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int surface_protected = obj_surface->share_info->surface_protected;
60b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int force_output_method = obj_surface->share_info->force_output_method;
61b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int bob_deinterlace = obj_surface->share_info->bob_deinterlace;
62b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang
63f31d5416a60f83e184b0906a7ec77ba021840531hding            memset(obj_surface->share_info, 0, sizeof(struct psb_surface_share_info_s));
64b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            /* Still need to keep these info so that hwc can get them after suspend/resume cycle */
65b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->metadata_rotate = metadata_rotate;
66b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->surface_protected = surface_protected;
67b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->force_output_method = force_output_method;
68b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->bob_deinterlace = bob_deinterlace;
69f31d5416a60f83e184b0906a7ec77ba021840531hding        }
70f31d5416a60f83e184b0906a7ec77ba021840531hding        gralloc_unlock(handle);
71f31d5416a60f83e184b0906a7ec77ba021840531hding    }
72f31d5416a60f83e184b0906a7ec77ba021840531hding
73f31d5416a60f83e184b0906a7ec77ba021840531hding    return VA_STATUS_SUCCESS;
74f31d5416a60f83e184b0906a7ec77ba021840531hding}
75f31d5416a60f83e184b0906a7ec77ba021840531hding
76f31d5416a60f83e184b0906a7ec77ba021840531hdingVAStatus psb_CreateSurfacesFromGralloc(
77f31d5416a60f83e184b0906a7ec77ba021840531hding    VADriverContextP ctx,
78f31d5416a60f83e184b0906a7ec77ba021840531hding    int width,
79f31d5416a60f83e184b0906a7ec77ba021840531hding    int height,
80f31d5416a60f83e184b0906a7ec77ba021840531hding    int format,
81f31d5416a60f83e184b0906a7ec77ba021840531hding    int num_surfaces,
82f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceID *surface_list,        /* out */
83f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceAttributeTPI *attribute_tpi
84f31d5416a60f83e184b0906a7ec77ba021840531hding)
85f31d5416a60f83e184b0906a7ec77ba021840531hding{
86f31d5416a60f83e184b0906a7ec77ba021840531hding    INIT_DRIVER_DATA
87f31d5416a60f83e184b0906a7ec77ba021840531hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
88f31d5416a60f83e184b0906a7ec77ba021840531hding    int i, height_origin, usage, buffer_stride = 0;
89f31d5416a60f83e184b0906a7ec77ba021840531hding    int protected = (VA_RT_FORMAT_PROTECTED & format);
90f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned long fourcc;
91f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceAttributeTPI *external_buffers = NULL;
92f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned int handle;
93f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned int *tmp_nativebuf_handle = NULL;
94f31d5416a60f83e184b0906a7ec77ba021840531hding    int size = num_surfaces * sizeof(unsigned int);
952db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    void *vaddr[GRALLOC_SUB_BUFFER_MAX];
96f31d5416a60f83e184b0906a7ec77ba021840531hding
97f31d5416a60f83e184b0906a7ec77ba021840531hding
98f31d5416a60f83e184b0906a7ec77ba021840531hding    /* follow are gralloc-buffers */
99f31d5416a60f83e184b0906a7ec77ba021840531hding    format = format & (~VA_RT_FORMAT_PROTECTED);
1005ed159b49cff6b05d923bcf00d09c67ee2ce1f80hding    driver_data->protected = protected;
1015ed159b49cff6b05d923bcf00d09c67ee2ce1f80hding
1026d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_INVALID_PARAM(num_surfaces <= 0);
1036d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_SURFACE(surface_list);
104f31d5416a60f83e184b0906a7ec77ba021840531hding
105f31d5416a60f83e184b0906a7ec77ba021840531hding    external_buffers = attribute_tpi;
106f31d5416a60f83e184b0906a7ec77ba021840531hding
107f31d5416a60f83e184b0906a7ec77ba021840531hding    /* We only support one format */
108f31d5416a60f83e184b0906a7ec77ba021840531hding    if ((VA_RT_FORMAT_YUV420 != format)
109f31d5416a60f83e184b0906a7ec77ba021840531hding        && (VA_RT_FORMAT_YUV422 != format)) {
110f31d5416a60f83e184b0906a7ec77ba021840531hding        vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
111f31d5416a60f83e184b0906a7ec77ba021840531hding        DEBUG_FAILURE;
112f31d5416a60f83e184b0906a7ec77ba021840531hding        return vaStatus;
113f31d5416a60f83e184b0906a7ec77ba021840531hding    }
114f31d5416a60f83e184b0906a7ec77ba021840531hding
115f31d5416a60f83e184b0906a7ec77ba021840531hding    /*
116f31d5416a60f83e184b0906a7ec77ba021840531hding    vaStatus = psb__checkSurfaceDimensions(driver_data, width, height);
1176d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_VASTATUS();
118f31d5416a60f83e184b0906a7ec77ba021840531hding    */
119f31d5416a60f83e184b0906a7ec77ba021840531hding    /* Adjust height to be a multiple of 32 (height of macroblock in interlaced mode) */
120f31d5416a60f83e184b0906a7ec77ba021840531hding    height_origin = height;
121f31d5416a60f83e184b0906a7ec77ba021840531hding    height = (height + 0x1f) & ~0x1f;
122f31d5416a60f83e184b0906a7ec77ba021840531hding
1236d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_INVALID_PARAM(external_buffers == NULL);
1246d37ae34fcae80f2e898b61e2506ed8e887bd16anguo
125f31d5416a60f83e184b0906a7ec77ba021840531hding    /* get native window from the reserved field */
126f31d5416a60f83e184b0906a7ec77ba021840531hding    driver_data->native_window = (void *)external_buffers->reserved[0];
127f31d5416a60f83e184b0906a7ec77ba021840531hding
128f31d5416a60f83e184b0906a7ec77ba021840531hding    tmp_nativebuf_handle = calloc(1, size);
1296d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_ALLOCATION(tmp_nativebuf_handle);
1306d37ae34fcae80f2e898b61e2506ed8e887bd16anguo
131f31d5416a60f83e184b0906a7ec77ba021840531hding    memcpy(tmp_nativebuf_handle, external_buffers->buffers, size);
132f31d5416a60f83e184b0906a7ec77ba021840531hding
133f31d5416a60f83e184b0906a7ec77ba021840531hding    for (i = 0; i < num_surfaces; i++) {
134f31d5416a60f83e184b0906a7ec77ba021840531hding        int surfaceID;
135f31d5416a60f83e184b0906a7ec77ba021840531hding        object_surface_p obj_surface;
136f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface_p psb_surface;
137f31d5416a60f83e184b0906a7ec77ba021840531hding
138f31d5416a60f83e184b0906a7ec77ba021840531hding        surfaceID = object_heap_allocate(&driver_data->surface_heap);
139f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface = SURFACE(surfaceID);
140f31d5416a60f83e184b0906a7ec77ba021840531hding        if (NULL == obj_surface) {
141f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
142f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
143f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
144f31d5416a60f83e184b0906a7ec77ba021840531hding        }
145f31d5416a60f83e184b0906a7ec77ba021840531hding        MEMSET_OBJECT(obj_surface, struct object_surface_s);
146f31d5416a60f83e184b0906a7ec77ba021840531hding
147f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->surface_id = surfaceID;
148f31d5416a60f83e184b0906a7ec77ba021840531hding        surface_list[i] = surfaceID;
149f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->context_id = -1;
150f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->width = width;
151f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height = height;
152f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->width_r = width;
153f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height_r = height;
154f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height_origin = height_origin;
155f31d5416a60f83e184b0906a7ec77ba021840531hding
156f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface = (psb_surface_p) calloc(1, sizeof(struct psb_surface_s));
157f31d5416a60f83e184b0906a7ec77ba021840531hding        if (NULL == psb_surface) {
158f31d5416a60f83e184b0906a7ec77ba021840531hding            object_heap_free(&driver_data->surface_heap, (object_base_p) obj_surface);
159f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->surface_id = VA_INVALID_SURFACE;
160f31d5416a60f83e184b0906a7ec77ba021840531hding
161f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
162f31d5416a60f83e184b0906a7ec77ba021840531hding
163f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
164f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
165f31d5416a60f83e184b0906a7ec77ba021840531hding        }
166f31d5416a60f83e184b0906a7ec77ba021840531hding
167f31d5416a60f83e184b0906a7ec77ba021840531hding        switch (format) {
168f31d5416a60f83e184b0906a7ec77ba021840531hding        case VA_RT_FORMAT_YUV422:
169f31d5416a60f83e184b0906a7ec77ba021840531hding            fourcc = VA_FOURCC_YV16;
170f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
171f31d5416a60f83e184b0906a7ec77ba021840531hding        case VA_RT_FORMAT_YUV420:
172f31d5416a60f83e184b0906a7ec77ba021840531hding        default:
173f31d5416a60f83e184b0906a7ec77ba021840531hding            fourcc = VA_FOURCC_NV12;
174f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
175f31d5416a60f83e184b0906a7ec77ba021840531hding        }
1762db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu
177f31d5416a60f83e184b0906a7ec77ba021840531hding        /*hard code the gralloc buffer usage*/
1786028b94d5c9bc36237c553878e7fe66ee74fe908wfeng        usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER;
179f31d5416a60f83e184b0906a7ec77ba021840531hding        handle = (unsigned int)external_buffers->buffers[i];
1802db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu        if (gralloc_lock(handle, usage, 0, 0, width, height, (void **)&vaddr[GRALLOC_SUB_BUFFER0])) {
181f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_UNKNOWN;
182f31d5416a60f83e184b0906a7ec77ba021840531hding        } else {
183f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = psb_surface_create_from_ub(driver_data, width, height, fourcc,
1842db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu                    external_buffers, psb_surface, vaddr[GRALLOC_SUB_BUFFER0],
1855ed159b49cff6b05d923bcf00d09c67ee2ce1f80hding                    PSB_USER_BUFFER_UNCACHED);
186f31d5416a60f83e184b0906a7ec77ba021840531hding            psb_surface->buf.handle = handle;
1872db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu            obj_surface->share_info = (psb_surface_share_info_t *)vaddr[GRALLOC_SUB_BUFFER1];
188f31d5416a60f83e184b0906a7ec77ba021840531hding            memset(obj_surface->share_info, 0, sizeof(struct psb_surface_share_info_s));
189f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->force_output_method = protected ? OUTPUT_FORCE_OVERLAY : 0;
190f31d5416a60f83e184b0906a7ec77ba021840531hding#ifdef PSBVIDEO_MSVDX_DEC_TILING
191f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->tiling = external_buffers->tiling;
192f31d5416a60f83e184b0906a7ec77ba021840531hding#endif
193f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->width = obj_surface->width;
194f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->height = obj_surface->height;
195f31d5416a60f83e184b0906a7ec77ba021840531hding
196f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->luma_stride = psb_surface->stride;
197f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->chroma_u_stride = psb_surface->stride;
198f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->chroma_v_stride = psb_surface->stride;
199f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->format = VA_FOURCC_NV12;
200f31d5416a60f83e184b0906a7ec77ba021840531hding
201f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->khandle = (uint32_t)(wsbmKBufHandle(wsbmKBuf(psb_surface->buf.drm_buf)));
202f31d5416a60f83e184b0906a7ec77ba021840531hding
203f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->renderStatus = 0;
204f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->share_info->used_by_widi = 0;
2057c683a316b6623e75c0d2ebe5d6c00c832968375ashish singhi            obj_surface->share_info->native_window = (void *)external_buffers->reserved[0] ;
206f31d5416a60f83e184b0906a7ec77ba021840531hding
207f31d5416a60f83e184b0906a7ec77ba021840531hding            drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s : Create graphic buffer success"
208f31d5416a60f83e184b0906a7ec77ba021840531hding                                     "surface_id= 0x%x, vaddr[0] (0x%x), vaddr[1] (0x%x)\n",
2092db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu                                     __FUNCTION__, surfaceID, vaddr[GRALLOC_SUB_BUFFER0], vaddr[GRALLOC_SUB_BUFFER1]);
210f31d5416a60f83e184b0906a7ec77ba021840531hding            gralloc_unlock(handle);
211f31d5416a60f83e184b0906a7ec77ba021840531hding        }
212f31d5416a60f83e184b0906a7ec77ba021840531hding
213f31d5416a60f83e184b0906a7ec77ba021840531hding        if (VA_STATUS_SUCCESS != vaStatus) {
214f31d5416a60f83e184b0906a7ec77ba021840531hding            free(psb_surface);
215f31d5416a60f83e184b0906a7ec77ba021840531hding            object_heap_free(&driver_data->surface_heap, (object_base_p) obj_surface);
216f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->surface_id = VA_INVALID_SURFACE;
217f31d5416a60f83e184b0906a7ec77ba021840531hding
218f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
219f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
220f31d5416a60f83e184b0906a7ec77ba021840531hding        }
221f31d5416a60f83e184b0906a7ec77ba021840531hding        buffer_stride = psb_surface->stride;
222f31d5416a60f83e184b0906a7ec77ba021840531hding        /* by default, surface fourcc is NV12 */
223f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface->extra_info[4] = fourcc;
224f31d5416a60f83e184b0906a7ec77ba021840531hding#ifdef PSBVIDEO_MSVDX_DEC_TILING
225f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface->extra_info[7] = external_buffers->tiling;
226f31d5416a60f83e184b0906a7ec77ba021840531hding#endif
227f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->psb_surface = psb_surface;
228f31d5416a60f83e184b0906a7ec77ba021840531hding    }
229f31d5416a60f83e184b0906a7ec77ba021840531hding
230f31d5416a60f83e184b0906a7ec77ba021840531hding    /* Error recovery */
231f31d5416a60f83e184b0906a7ec77ba021840531hding    if (VA_STATUS_SUCCESS != vaStatus) {
232f31d5416a60f83e184b0906a7ec77ba021840531hding        /* surface_list[i-1] was the last successful allocation */
233f31d5416a60f83e184b0906a7ec77ba021840531hding        for (; i--;) {
234f31d5416a60f83e184b0906a7ec77ba021840531hding            object_surface_p obj_surface = SURFACE(surface_list[i]);
235f31d5416a60f83e184b0906a7ec77ba021840531hding            psb__destroy_surface(driver_data, obj_surface);
236f31d5416a60f83e184b0906a7ec77ba021840531hding            surface_list[i] = VA_INVALID_SURFACE;
237f31d5416a60f83e184b0906a7ec77ba021840531hding        }
238f31d5416a60f83e184b0906a7ec77ba021840531hding        drv_debug_msg(VIDEO_DEBUG_ERROR, "CreateSurfaces failed\n");
239f31d5416a60f83e184b0906a7ec77ba021840531hding
240f31d5416a60f83e184b0906a7ec77ba021840531hding        if (tmp_nativebuf_handle)
241f31d5416a60f83e184b0906a7ec77ba021840531hding            free(tmp_nativebuf_handle);
242f31d5416a60f83e184b0906a7ec77ba021840531hding
243f31d5416a60f83e184b0906a7ec77ba021840531hding        return vaStatus;
244f31d5416a60f83e184b0906a7ec77ba021840531hding    }
245f31d5416a60f83e184b0906a7ec77ba021840531hding
246f31d5416a60f83e184b0906a7ec77ba021840531hding    return vaStatus;
247f31d5416a60f83e184b0906a7ec77ba021840531hding}
248