psb_surface_gralloc.c revision 595e050675b1d8ecd0d6c17d6729bb663fa5fdce
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
50595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang#define HAL_PIXEL_FORMAT_NV12 0x3231564E
51595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang
52f31d5416a60f83e184b0906a7ec77ba021840531hdingVAStatus psb_DestroySurfaceGralloc(object_surface_p obj_surface)
53f31d5416a60f83e184b0906a7ec77ba021840531hding{
542db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    void *vaddr[GRALLOC_SUB_BUFFER_MAX];
556028b94d5c9bc36237c553878e7fe66ee74fe908wfeng    int usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER;
56f31d5416a60f83e184b0906a7ec77ba021840531hding    buffer_handle_t handle = obj_surface->psb_surface->buf.handle;
57f31d5416a60f83e184b0906a7ec77ba021840531hding    if (!gralloc_lock(handle, usage, 0, 0,
582db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu                      obj_surface->width, obj_surface->height, (void **)&vaddr[GRALLOC_SUB_BUFFER0])){
59595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang        if (obj_surface->share_info && vaddr[GRALLOC_SUB_BUFFER1] == obj_surface->share_info) {
60b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int metadata_rotate = obj_surface->share_info->metadata_rotate;
61b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int surface_protected = obj_surface->share_info->surface_protected;
62b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int force_output_method = obj_surface->share_info->force_output_method;
63b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            int bob_deinterlace = obj_surface->share_info->bob_deinterlace;
64b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang
65f31d5416a60f83e184b0906a7ec77ba021840531hding            memset(obj_surface->share_info, 0, sizeof(struct psb_surface_share_info_s));
66b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            /* Still need to keep these info so that hwc can get them after suspend/resume cycle */
67b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->metadata_rotate = metadata_rotate;
68b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->surface_protected = surface_protected;
69b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->force_output_method = force_output_method;
70b7f89c9efe4cecf957dee1f1d9f58dc1954746cfDan Liang            obj_surface->share_info->bob_deinterlace = bob_deinterlace;
71f31d5416a60f83e184b0906a7ec77ba021840531hding        }
72f31d5416a60f83e184b0906a7ec77ba021840531hding        gralloc_unlock(handle);
73f31d5416a60f83e184b0906a7ec77ba021840531hding    }
74f31d5416a60f83e184b0906a7ec77ba021840531hding
75f31d5416a60f83e184b0906a7ec77ba021840531hding    return VA_STATUS_SUCCESS;
76f31d5416a60f83e184b0906a7ec77ba021840531hding}
77f31d5416a60f83e184b0906a7ec77ba021840531hding
78f31d5416a60f83e184b0906a7ec77ba021840531hdingVAStatus psb_CreateSurfacesFromGralloc(
79f31d5416a60f83e184b0906a7ec77ba021840531hding    VADriverContextP ctx,
80f31d5416a60f83e184b0906a7ec77ba021840531hding    int width,
81f31d5416a60f83e184b0906a7ec77ba021840531hding    int height,
82f31d5416a60f83e184b0906a7ec77ba021840531hding    int format,
83f31d5416a60f83e184b0906a7ec77ba021840531hding    int num_surfaces,
84f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceID *surface_list,        /* out */
85f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceAttributeTPI *attribute_tpi
86f31d5416a60f83e184b0906a7ec77ba021840531hding)
87f31d5416a60f83e184b0906a7ec77ba021840531hding{
88f31d5416a60f83e184b0906a7ec77ba021840531hding    INIT_DRIVER_DATA
89f31d5416a60f83e184b0906a7ec77ba021840531hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
90f31d5416a60f83e184b0906a7ec77ba021840531hding    int i, height_origin, usage, buffer_stride = 0;
91f31d5416a60f83e184b0906a7ec77ba021840531hding    int protected = (VA_RT_FORMAT_PROTECTED & format);
92f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned long fourcc;
93f31d5416a60f83e184b0906a7ec77ba021840531hding    VASurfaceAttributeTPI *external_buffers = NULL;
94f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned int handle;
95f31d5416a60f83e184b0906a7ec77ba021840531hding    unsigned int *tmp_nativebuf_handle = NULL;
96f31d5416a60f83e184b0906a7ec77ba021840531hding    int size = num_surfaces * sizeof(unsigned int);
972db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu    void *vaddr[GRALLOC_SUB_BUFFER_MAX];
98f31d5416a60f83e184b0906a7ec77ba021840531hding
99f31d5416a60f83e184b0906a7ec77ba021840531hding
100f31d5416a60f83e184b0906a7ec77ba021840531hding    /* follow are gralloc-buffers */
101f31d5416a60f83e184b0906a7ec77ba021840531hding    format = format & (~VA_RT_FORMAT_PROTECTED);
1025ed159b49cff6b05d923bcf00d09c67ee2ce1f80hding    driver_data->protected = protected;
1035ed159b49cff6b05d923bcf00d09c67ee2ce1f80hding
1046d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_INVALID_PARAM(num_surfaces <= 0);
1056d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_SURFACE(surface_list);
106f31d5416a60f83e184b0906a7ec77ba021840531hding
107f31d5416a60f83e184b0906a7ec77ba021840531hding    external_buffers = attribute_tpi;
108f31d5416a60f83e184b0906a7ec77ba021840531hding
109f31d5416a60f83e184b0906a7ec77ba021840531hding    /* We only support one format */
110f31d5416a60f83e184b0906a7ec77ba021840531hding    if ((VA_RT_FORMAT_YUV420 != format)
111f31d5416a60f83e184b0906a7ec77ba021840531hding        && (VA_RT_FORMAT_YUV422 != format)) {
112f31d5416a60f83e184b0906a7ec77ba021840531hding        vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
113f31d5416a60f83e184b0906a7ec77ba021840531hding        DEBUG_FAILURE;
114f31d5416a60f83e184b0906a7ec77ba021840531hding        return vaStatus;
115f31d5416a60f83e184b0906a7ec77ba021840531hding    }
116f31d5416a60f83e184b0906a7ec77ba021840531hding
117595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang    CHECK_INVALID_PARAM(external_buffers == NULL);
118595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang
119f31d5416a60f83e184b0906a7ec77ba021840531hding    /*
120f31d5416a60f83e184b0906a7ec77ba021840531hding    vaStatus = psb__checkSurfaceDimensions(driver_data, width, height);
1216d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_VASTATUS();
122f31d5416a60f83e184b0906a7ec77ba021840531hding    */
123f31d5416a60f83e184b0906a7ec77ba021840531hding    /* Adjust height to be a multiple of 32 (height of macroblock in interlaced mode) */
124f31d5416a60f83e184b0906a7ec77ba021840531hding    height_origin = height;
125595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang    if (external_buffers->pixel_format != HAL_PIXEL_FORMAT_NV12)
126595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang        height = (height + 0x1f) & ~0x1f;
1276d37ae34fcae80f2e898b61e2506ed8e887bd16anguo
128f31d5416a60f83e184b0906a7ec77ba021840531hding    /* get native window from the reserved field */
129f31d5416a60f83e184b0906a7ec77ba021840531hding    driver_data->native_window = (void *)external_buffers->reserved[0];
130f31d5416a60f83e184b0906a7ec77ba021840531hding
131f31d5416a60f83e184b0906a7ec77ba021840531hding    tmp_nativebuf_handle = calloc(1, size);
1326d37ae34fcae80f2e898b61e2506ed8e887bd16anguo    CHECK_ALLOCATION(tmp_nativebuf_handle);
1336d37ae34fcae80f2e898b61e2506ed8e887bd16anguo
134f31d5416a60f83e184b0906a7ec77ba021840531hding    memcpy(tmp_nativebuf_handle, external_buffers->buffers, size);
135f31d5416a60f83e184b0906a7ec77ba021840531hding
136f31d5416a60f83e184b0906a7ec77ba021840531hding    for (i = 0; i < num_surfaces; i++) {
137f31d5416a60f83e184b0906a7ec77ba021840531hding        int surfaceID;
138f31d5416a60f83e184b0906a7ec77ba021840531hding        object_surface_p obj_surface;
139f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface_p psb_surface;
140f31d5416a60f83e184b0906a7ec77ba021840531hding
141f31d5416a60f83e184b0906a7ec77ba021840531hding        surfaceID = object_heap_allocate(&driver_data->surface_heap);
142f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface = SURFACE(surfaceID);
143f31d5416a60f83e184b0906a7ec77ba021840531hding        if (NULL == obj_surface) {
144f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
145f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
146f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
147f31d5416a60f83e184b0906a7ec77ba021840531hding        }
148f31d5416a60f83e184b0906a7ec77ba021840531hding        MEMSET_OBJECT(obj_surface, struct object_surface_s);
149f31d5416a60f83e184b0906a7ec77ba021840531hding
150f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->surface_id = surfaceID;
151f31d5416a60f83e184b0906a7ec77ba021840531hding        surface_list[i] = surfaceID;
152f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->context_id = -1;
153f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->width = width;
154f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height = height;
155f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->width_r = width;
156f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height_r = height;
157f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->height_origin = height_origin;
158f31d5416a60f83e184b0906a7ec77ba021840531hding
159f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface = (psb_surface_p) calloc(1, sizeof(struct psb_surface_s));
160f31d5416a60f83e184b0906a7ec77ba021840531hding        if (NULL == psb_surface) {
161f31d5416a60f83e184b0906a7ec77ba021840531hding            object_heap_free(&driver_data->surface_heap, (object_base_p) obj_surface);
162f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->surface_id = VA_INVALID_SURFACE;
163f31d5416a60f83e184b0906a7ec77ba021840531hding
164f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
165f31d5416a60f83e184b0906a7ec77ba021840531hding
166f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
167f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
168f31d5416a60f83e184b0906a7ec77ba021840531hding        }
169f31d5416a60f83e184b0906a7ec77ba021840531hding
170f31d5416a60f83e184b0906a7ec77ba021840531hding        switch (format) {
171f31d5416a60f83e184b0906a7ec77ba021840531hding        case VA_RT_FORMAT_YUV422:
172f31d5416a60f83e184b0906a7ec77ba021840531hding            fourcc = VA_FOURCC_YV16;
173f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
174f31d5416a60f83e184b0906a7ec77ba021840531hding        case VA_RT_FORMAT_YUV420:
175f31d5416a60f83e184b0906a7ec77ba021840531hding        default:
176f31d5416a60f83e184b0906a7ec77ba021840531hding            fourcc = VA_FOURCC_NV12;
177f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
178f31d5416a60f83e184b0906a7ec77ba021840531hding        }
1792db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu
180684f0e29e29ca32fad49439cfe0392417361d34dLi Zeng#ifdef PSBVIDEO_MSVDX_DEC_TILING
181684f0e29e29ca32fad49439cfe0392417361d34dLi Zeng        if (width > 1280)
182c7902b7f72b041c4f2317a9806505257a737d49bLi Zeng            external_buffers->tiling = 1;
183684f0e29e29ca32fad49439cfe0392417361d34dLi Zeng#endif
184f31d5416a60f83e184b0906a7ec77ba021840531hding        /*hard code the gralloc buffer usage*/
1856028b94d5c9bc36237c553878e7fe66ee74fe908wfeng        usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_COMPOSER;
186595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang
187595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang        if (external_buffers->pixel_format == HAL_PIXEL_FORMAT_NV12)
188595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            usage |= GRALLOC_USAGE_SW_READ_OFTEN;
189595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang        else {
1906de214bcbc7d730ad79905f74c9a39bf65686055Binglin Chen#ifdef PSBVIDEO_MRFL
191595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            usage |= GRALLOC_USAGE_SW_WRITE_OFTEN;
192595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            LOGE("will lock with usage %x", usage);
1936de214bcbc7d730ad79905f74c9a39bf65686055Binglin Chen#endif
194595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang        }
195595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang
196f31d5416a60f83e184b0906a7ec77ba021840531hding        handle = (unsigned int)external_buffers->buffers[i];
1972db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu        if (gralloc_lock(handle, usage, 0, 0, width, height, (void **)&vaddr[GRALLOC_SUB_BUFFER0])) {
198f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = VA_STATUS_ERROR_UNKNOWN;
199f31d5416a60f83e184b0906a7ec77ba021840531hding        } else {
20062d3f290968580b7ed3a00e0ffb458c2f0249dacLi Zeng            int cache_flag = PSB_USER_BUFFER_UNCACHED;
20162d3f290968580b7ed3a00e0ffb458c2f0249dacLi Zeng#ifdef PSBVIDEO_MRFL
20262d3f290968580b7ed3a00e0ffb458c2f0249dacLi Zeng            cache_flag = 0;
20362d3f290968580b7ed3a00e0ffb458c2f0249dacLi Zeng#endif
204f31d5416a60f83e184b0906a7ec77ba021840531hding            vaStatus = psb_surface_create_from_ub(driver_data, width, height, fourcc,
2052db64e390f8b1a9ac4cfea98d89f45ec94d11d65Jason Hu                    external_buffers, psb_surface, vaddr[GRALLOC_SUB_BUFFER0],
20662d3f290968580b7ed3a00e0ffb458c2f0249dacLi Zeng                    cache_flag);
207f31d5416a60f83e184b0906a7ec77ba021840531hding            psb_surface->buf.handle = handle;
208595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            obj_surface->share_info = NULL;
209595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang
210595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            if (external_buffers->pixel_format != HAL_PIXEL_FORMAT_NV12) {
211595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info = (psb_surface_share_info_t *)vaddr[GRALLOC_SUB_BUFFER1];
212595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                memset(obj_surface->share_info, 0, sizeof(struct psb_surface_share_info_s));
213595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->force_output_method = protected ? OUTPUT_FORCE_OVERLAY : 0;
214f31d5416a60f83e184b0906a7ec77ba021840531hding#ifdef PSBVIDEO_MSVDX_DEC_TILING
215595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->tiling = external_buffers->tiling;
216f31d5416a60f83e184b0906a7ec77ba021840531hding#endif
217595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->width = obj_surface->width;
218595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->height = obj_surface->height;
219f31d5416a60f83e184b0906a7ec77ba021840531hding
220595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->luma_stride = psb_surface->stride;
221595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->chroma_u_stride = psb_surface->stride;
222595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->chroma_v_stride = psb_surface->stride;
223595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->format = VA_FOURCC_NV12;
224f31d5416a60f83e184b0906a7ec77ba021840531hding
225595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->khandle = (uint32_t)(wsbmKBufHandle(wsbmKBuf(psb_surface->buf.drm_buf)));
226f31d5416a60f83e184b0906a7ec77ba021840531hding
227595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->renderStatus = 0;
228595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->used_by_widi = 0;
229595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                obj_surface->share_info->native_window = (void *)external_buffers->reserved[0] ;
230f31d5416a60f83e184b0906a7ec77ba021840531hding
231595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s : Create graphic buffer success"
232595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                                         "surface_id= 0x%x, vaddr[0] (0x%x), vaddr[1] (0x%x)\n",
233595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang                                         __FUNCTION__, surfaceID, vaddr[GRALLOC_SUB_BUFFER0], vaddr[GRALLOC_SUB_BUFFER1]);
234595e050675b1d8ecd0d6c17d6729bb663fa5fdceZhao Liang            }
235f31d5416a60f83e184b0906a7ec77ba021840531hding            gralloc_unlock(handle);
236f31d5416a60f83e184b0906a7ec77ba021840531hding        }
237f31d5416a60f83e184b0906a7ec77ba021840531hding
238f31d5416a60f83e184b0906a7ec77ba021840531hding        if (VA_STATUS_SUCCESS != vaStatus) {
239f31d5416a60f83e184b0906a7ec77ba021840531hding            free(psb_surface);
240f31d5416a60f83e184b0906a7ec77ba021840531hding            object_heap_free(&driver_data->surface_heap, (object_base_p) obj_surface);
241f31d5416a60f83e184b0906a7ec77ba021840531hding            obj_surface->surface_id = VA_INVALID_SURFACE;
242f31d5416a60f83e184b0906a7ec77ba021840531hding
243f31d5416a60f83e184b0906a7ec77ba021840531hding            DEBUG_FAILURE;
244f31d5416a60f83e184b0906a7ec77ba021840531hding            break;
245f31d5416a60f83e184b0906a7ec77ba021840531hding        }
246f31d5416a60f83e184b0906a7ec77ba021840531hding        buffer_stride = psb_surface->stride;
247f31d5416a60f83e184b0906a7ec77ba021840531hding        /* by default, surface fourcc is NV12 */
248f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface->extra_info[4] = fourcc;
249f31d5416a60f83e184b0906a7ec77ba021840531hding#ifdef PSBVIDEO_MSVDX_DEC_TILING
250f31d5416a60f83e184b0906a7ec77ba021840531hding        psb_surface->extra_info[7] = external_buffers->tiling;
251f31d5416a60f83e184b0906a7ec77ba021840531hding#endif
252f31d5416a60f83e184b0906a7ec77ba021840531hding        obj_surface->psb_surface = psb_surface;
253f31d5416a60f83e184b0906a7ec77ba021840531hding    }
254f31d5416a60f83e184b0906a7ec77ba021840531hding
255f31d5416a60f83e184b0906a7ec77ba021840531hding    /* Error recovery */
256f31d5416a60f83e184b0906a7ec77ba021840531hding    if (VA_STATUS_SUCCESS != vaStatus) {
257f31d5416a60f83e184b0906a7ec77ba021840531hding        /* surface_list[i-1] was the last successful allocation */
258f31d5416a60f83e184b0906a7ec77ba021840531hding        for (; i--;) {
259f31d5416a60f83e184b0906a7ec77ba021840531hding            object_surface_p obj_surface = SURFACE(surface_list[i]);
260f31d5416a60f83e184b0906a7ec77ba021840531hding            psb__destroy_surface(driver_data, obj_surface);
261f31d5416a60f83e184b0906a7ec77ba021840531hding            surface_list[i] = VA_INVALID_SURFACE;
262f31d5416a60f83e184b0906a7ec77ba021840531hding        }
263f31d5416a60f83e184b0906a7ec77ba021840531hding        drv_debug_msg(VIDEO_DEBUG_ERROR, "CreateSurfaces failed\n");
264f31d5416a60f83e184b0906a7ec77ba021840531hding
265f31d5416a60f83e184b0906a7ec77ba021840531hding        if (tmp_nativebuf_handle)
266f31d5416a60f83e184b0906a7ec77ba021840531hding            free(tmp_nativebuf_handle);
267f31d5416a60f83e184b0906a7ec77ba021840531hding
268f31d5416a60f83e184b0906a7ec77ba021840531hding        return vaStatus;
269f31d5416a60f83e184b0906a7ec77ba021840531hding    }
270f31d5416a60f83e184b0906a7ec77ba021840531hding
271f31d5416a60f83e184b0906a7ec77ba021840531hding    return vaStatus;
272f31d5416a60f83e184b0906a7ec77ba021840531hding}
273