VPP: check the backing store buffer
authorXiang, Haihao <haihao.xiang@intel.com>
Thu, 14 Mar 2013 07:47:05 +0000 (15:47 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Fri, 15 Mar 2013 07:45:28 +0000 (15:45 +0800)
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
14 files changed:
src/gen75_picture_process.c
src/gen75_picture_process.h
src/gen75_vpp_gpe.c
src/gen75_vpp_gpe.h
src/gen75_vpp_vebox.c
src/gen75_vpp_vebox.h
src/i965_drv_video.c
src/i965_drv_video.h
src/i965_encoder.c
src/i965_output_dri.c
src/i965_post_processing.c
src/i965_post_processing.h
src/i965_render.c
src/i965_render.h

index 6e10de0..7ed1528 100644 (file)
@@ -82,8 +82,8 @@ gen75_vpp_vebox(VADriverContextP ctx,
      }
 
      proc_ctx->vpp_vebox_ctx->pipeline_param  = pipeline_param;
-     proc_ctx->vpp_vebox_ctx->surface_input   = pipeline_param->surface;
-     proc_ctx->vpp_vebox_ctx->surface_output  = proc_ctx->surface_render_output;
+     proc_ctx->vpp_vebox_ctx->surface_input_object = proc_ctx->surface_pipeline_input_object;
+     proc_ctx->vpp_vebox_ctx->surface_output_object  = proc_ctx->surface_render_output_object;
 
      va_status = gen75_vebox_process_picture(ctx, proc_ctx->vpp_vebox_ctx);
  
@@ -100,8 +100,9 @@ gen75_vpp_gpe(VADriverContextP ctx,
          proc_ctx->vpp_gpe_ctx = gen75_gpe_context_init(ctx);
      }
    
-     proc_ctx->vpp_gpe_ctx->pipeline_param = proc_ctx->pipeline_param; 
-     proc_ctx->vpp_gpe_ctx->surface_output = proc_ctx->surface_render_output;
+     proc_ctx->vpp_gpe_ctx->pipeline_param = proc_ctx->pipeline_param;
+     proc_ctx->vpp_gpe_ctx->surface_pipeline_input_object = proc_ctx->surface_pipeline_input_object;
+     proc_ctx->vpp_gpe_ctx->surface_output_object = proc_ctx->surface_render_output_object;
 
      va_status = gen75_gpe_process_picture(ctx, proc_ctx->vpp_gpe_ctx);
  
@@ -120,20 +121,34 @@ gen75_proc_picture(VADriverContextP ctx,
              (struct intel_video_process_context *)hw_context;
     VAProcPipelineParameterBuffer *pipeline_param = 
              (VAProcPipelineParameterBuffer *)proc_st->pipeline_param->buffer;
-
+    struct object_surface *obj_dst_surf = NULL;
+    struct object_surface *obj_src_surf = NULL;
     proc_ctx->pipeline_param = pipeline_param;
-    proc_ctx->surface_render_output = proc_st->current_render_target;
+    assert(proc_st->current_render_target != VA_INVALID_SURFACE);
+
+    if (proc_st->current_render_target == VA_INVALID_SURFACE ||
+        pipeline_param->surface == VA_INVALID_SURFACE)
+        goto error;
+
+    obj_dst_surf = SURFACE(proc_st->current_render_target);
+
+    if (!obj_dst_surf)
+        goto error;
+
+    obj_src_surf = SURFACE(proc_ctx->pipeline_param->surface);
 
-    assert(proc_ctx->surface_render_output != VA_INVALID_SURFACE);
+    if (!obj_src_surf)
+        goto error;
 
-    struct object_surface * obj_dst_surf = SURFACE(proc_ctx->surface_render_output);
-    if(!obj_dst_surf->bo){
-       unsigned int is_tiled = 0;
-       unsigned int fourcc = VA_FOURCC('N','V','1','2');
-       int sampling = SUBSAMPLE_YUV420;
-       i965_check_alloc_surface_bo(ctx, obj_dst_surf, is_tiled, fourcc, sampling);
+    if (!obj_dst_surf->bo) {
+        unsigned int is_tiled = 0;
+        unsigned int fourcc = VA_FOURCC('N','V','1','2');
+        int sampling = SUBSAMPLE_YUV420;
+        i965_check_alloc_surface_bo(ctx, obj_dst_surf, is_tiled, fourcc, sampling);
     }  
 
+    proc_ctx->surface_render_output_object = obj_dst_surf;
+    proc_ctx->surface_pipeline_input_object = obj_src_surf;
     assert(pipeline_param->num_filters <= 4);
 
     VABufferID *filter_id = (VABufferID*) pipeline_param->filters;
@@ -143,6 +158,12 @@ gen75_proc_picture(VADriverContextP ctx,
         gen75_vpp_fmt_cvt(ctx, profile, codec_state, hw_context);
     }else if(pipeline_param->num_filters == 1) {
        struct object_buffer * obj_buf = BUFFER((*filter_id) + 0);
+
+       assert(obj_buf && obj_buf->buffer_store);
+       
+       if (!obj_buf || !obj_buf->buffer_store)
+           goto error;
+
        VAProcFilterParameterBuffer* filter =
            (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
 
@@ -153,9 +174,13 @@ gen75_proc_picture(VADriverContextP ctx,
                  filter->type == VAProcFilterColorBalance){
            gen75_vpp_vebox(ctx, proc_ctx);
        }else if(filter->type == VAProcFilterSharpening){
-           struct object_surface *obj_src_surf = SURFACE(proc_ctx->pipeline_param->surface);
            assert(obj_src_surf->fourcc == VA_FOURCC('N','V','1','2') && 
-                  obj_dst_surf->fourcc == VA_FOURCC('N','V','1','2'));   
+                  obj_dst_surf->fourcc == VA_FOURCC('N','V','1','2'));
+
+           if (obj_src_surf->fourcc != VA_FOURCC('N', 'V', '1', '2') ||
+               obj_dst_surf->fourcc != VA_FOURCC('N', 'V', '1', '2'))
+               goto error;
+
            gen75_vpp_gpe(ctx, proc_ctx);
        } 
     }else if (pipeline_param->num_filters >= 2) {
@@ -177,6 +202,9 @@ gen75_proc_picture(VADriverContextP ctx,
     }     
 
     return VA_STATUS_SUCCESS;
+
+error:
+    return VA_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 static void 
index e6e9289..a7b04f7 100644 (file)
@@ -45,7 +45,8 @@ struct intel_video_process_context
     VAProcPipelineParameterBuffer* pipeline_param;
     VAProcFilterType filter_type;
 
-    VASurfaceID surface_render_output;
+    struct object_surface *surface_render_output_object;
+    struct object_surface *surface_pipeline_input_object;
 };
 
 struct hw_context *
index 24375b4..db6a82a 100644 (file)
@@ -102,7 +102,6 @@ static VAStatus
 gpe_surfaces_setup(VADriverContextP ctx, 
                    struct vpp_gpe_context *vpp_gpe_ctx)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
     unsigned int i = 0;
     unsigned char input_surface_sum = (1 + vpp_gpe_ctx->forward_surf_sum +
@@ -110,7 +109,7 @@ gpe_surfaces_setup(VADriverContextP ctx,
 
     /* Binding input NV12 surfaces (Luma + Chroma)*/
     for( i = 0; i < input_surface_sum; i += 2){ 
-         obj_surface = SURFACE(vpp_gpe_ctx->surface_input[i/2]);
+         obj_surface = vpp_gpe_ctx->surface_input_object[i/2];
          assert(obj_surface);
          vpp_gpe_ctx->vpp_media_rw_surface_setup(ctx,
                                                  &vpp_gpe_ctx->gpe_ctx,
@@ -126,7 +125,7 @@ gpe_surfaces_setup(VADriverContextP ctx,
     }
 
     /* Binding output NV12 surface(Luma + Chroma) */
-    obj_surface = SURFACE(vpp_gpe_ctx->surface_output);
+    obj_surface = vpp_gpe_ctx->surface_output_object;
     assert(obj_surface);
     vpp_gpe_ctx->vpp_media_rw_surface_setup(ctx,
                                             &vpp_gpe_ctx->gpe_ctx,
@@ -338,12 +337,18 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
 {
      VAStatus va_status = VA_STATUS_SUCCESS;
      struct i965_driver_data *i965 = i965_driver_data(ctx);
-     VASurfaceID origin_in_surf_id = vpp_gpe_ctx-> surface_input[0];
-     VASurfaceID origin_out_surf_id = vpp_gpe_ctx-> surface_output;
+     struct object_surface *origin_in_obj_surface = vpp_gpe_ctx->surface_input_object[0];
+     struct object_surface *origin_out_obj_surface = vpp_gpe_ctx->surface_output_object;
 
      VAProcPipelineParameterBuffer* pipe = vpp_gpe_ctx->pipeline_param;
      VABufferID *filter_ids = (VABufferID*)pipe->filters ;
      struct object_buffer *obj_buf = BUFFER((*(filter_ids + 0)));
+
+     assert(obj_buf && obj_buf->buffer_store);
+       
+     if (!obj_buf || !obj_buf->buffer_store)
+         goto error;
+
      VAProcFilterParameterBuffer* filter =
                   (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
      float sharpening_intensity = filter->value;
@@ -361,7 +366,7 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
                                vpp_gpe_ctx->sub_shader_sum);
      }
 
-     if(!vpp_gpe_ctx->surface_tmp){
+     if(vpp_gpe_ctx->surface_tmp == VA_INVALID_ID){
         va_status = i965_CreateSurfaces(ctx,
                                        vpp_gpe_ctx->in_frame_w,
                                        vpp_gpe_ctx->in_frame_h,
@@ -371,8 +376,13 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
        assert(va_status == VA_STATUS_SUCCESS);
     
        struct object_surface * obj_surf = SURFACE(vpp_gpe_ctx->surface_tmp);
-       i965_check_alloc_surface_bo(ctx, obj_surf, 1, VA_FOURCC('N','V','1','2'),
-                                   SUBSAMPLE_YUV420);
+       assert(obj_surf);
+
+       if (obj_surf) {
+           i965_check_alloc_surface_bo(ctx, obj_surf, 1, VA_FOURCC('N','V','1','2'),
+                                       SUBSAMPLE_YUV420);
+           vpp_gpe_ctx->surface_tmp_object = obj_surf;
+       }
     }                
 
     assert(sharpening_intensity >= 0.0 && sharpening_intensity <= 1.0);
@@ -403,8 +413,8 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
     free(vpp_gpe_ctx->thread_param);
 
     /* Step 2: vertical blur process */      
-    vpp_gpe_ctx->surface_input[0] = vpp_gpe_ctx->surface_output;
-    vpp_gpe_ctx->surface_output = vpp_gpe_ctx->surface_tmp;
+    vpp_gpe_ctx->surface_input_object[0] = vpp_gpe_ctx->surface_output_object;
+    vpp_gpe_ctx->surface_output_object = vpp_gpe_ctx->surface_tmp_object;
     vpp_gpe_ctx->forward_surf_sum = 0;
     vpp_gpe_ctx->backward_surf_sum = 0;
  
@@ -425,9 +435,9 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
     free(vpp_gpe_ctx->thread_param);
 
     /* Step 3: apply the blur to original surface */      
-    vpp_gpe_ctx->surface_input[0]  = origin_in_surf_id;
-    vpp_gpe_ctx->surface_input[1]  = vpp_gpe_ctx->surface_tmp;
-    vpp_gpe_ctx->surface_output    = origin_out_surf_id;
+    vpp_gpe_ctx->surface_input_object[0]  = origin_in_obj_surface;
+    vpp_gpe_ctx->surface_input_object[1]  = vpp_gpe_ctx->surface_tmp_object;
+    vpp_gpe_ctx->surface_output_object    = origin_out_obj_surface;
     vpp_gpe_ctx->forward_surf_sum  = 1;
     vpp_gpe_ctx->backward_surf_sum = 0;
  
@@ -448,6 +458,9 @@ gen75_gpe_process_sharpening(VADriverContextP ctx,
     free(vpp_gpe_ctx->thread_param);
 
     return va_status;
+
+error:
+    return VA_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 VAStatus gen75_gpe_process_picture(VADriverContextP ctx, 
@@ -458,9 +471,16 @@ VAStatus gen75_gpe_process_picture(VADriverContextP ctx,
     VAProcPipelineParameterBuffer* pipe = vpp_gpe_ctx->pipeline_param;
     VAProcFilterParameterBuffer* filter = NULL;
     unsigned int i;
+    struct object_surface *obj_surface = NULL;
 
     for(i = 0; i < pipe->num_filters; i++){
         struct object_buffer *obj_buf = BUFFER(pipe->filters[i]);
+
+        assert(obj_buf && obj_buf->buffer_store);
+
+        if (!obj_buf || !obj_buf->buffer_store)
+            goto error;
+
         filter = (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
         if(filter->type == VAProcFilterSharpening){
            break;
@@ -468,25 +488,30 @@ VAStatus gen75_gpe_process_picture(VADriverContextP ctx,
     }
        
     assert(pipe->num_forward_references + pipe->num_backward_references <= 4);
-    vpp_gpe_ctx->surface_input[0] = pipe->surface;
+    vpp_gpe_ctx->surface_input_object[0] = vpp_gpe_ctx->surface_pipeline_input_object;
 
     vpp_gpe_ctx->forward_surf_sum = 0;
     vpp_gpe_ctx->backward_surf_sum = 0;
  
     for(i = 0; i < pipe->num_forward_references; i ++)
     {
-        vpp_gpe_ctx->surface_input[i + 1] = pipe->forward_references[i]; 
-        vpp_gpe_ctx->forward_surf_sum ++;
+        obj_surface = SURFACE(pipe->forward_references[i]);
+
+        assert(obj_surface);
+        vpp_gpe_ctx->surface_input_object[i + 1] = obj_surface;
+        vpp_gpe_ctx->forward_surf_sum++;
     } 
 
     for(i = 0; i < pipe->num_backward_references; i ++)
     {
-         vpp_gpe_ctx->surface_input[vpp_gpe_ctx->forward_surf_sum + 1 + i ] = 
-                                    pipe->backward_references[i]; 
-         vpp_gpe_ctx->backward_surf_sum ++;
+        obj_surface = SURFACE(pipe->backward_references[i]);
+        
+        assert(obj_surface);
+        vpp_gpe_ctx->surface_input_object[vpp_gpe_ctx->forward_surf_sum + 1 + i ] = obj_surface;
+        vpp_gpe_ctx->backward_surf_sum++;
     } 
 
-    struct object_surface *obj_surface = SURFACE(vpp_gpe_ctx->surface_input[0]);
+    obj_surface = vpp_gpe_ctx->surface_input_object[0];
     vpp_gpe_ctx->in_frame_w = obj_surface->orig_width;
     vpp_gpe_ctx->in_frame_h = obj_surface->orig_height;
 
@@ -499,6 +524,9 @@ VAStatus gen75_gpe_process_picture(VADriverContextP ctx,
     vpp_gpe_ctx->is_first_frame = 0;
 
     return va_status;
+
+error:
+    return VA_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 void 
@@ -513,9 +541,11 @@ gen75_gpe_context_destroy(VADriverContextP ctx,
 
     i965_gpe_context_destroy(&vpp_gpe_ctx->gpe_ctx);
 
-    if(vpp_gpe_ctx->surface_tmp){
-       i965_DestroySurfaces(ctx, &vpp_gpe_ctx->surface_tmp, 1);
-       vpp_gpe_ctx->surface_tmp = 0;
+    if(vpp_gpe_ctx->surface_tmp != VA_INVALID_ID){
+        assert(vpp_gpe_ctx->surface_tmp_object != NULL);
+        i965_DestroySurfaces(ctx, &vpp_gpe_ctx->surface_tmp, 1);
+        vpp_gpe_ctx->surface_tmp = VA_INVALID_ID;
+        vpp_gpe_ctx->surface_tmp_object = NULL;
     }   
 
     free(vpp_gpe_ctx->batch);
@@ -547,6 +577,8 @@ gen75_gpe_context_init(VADriverContextP ctx)
     vpp_gpe_ctx->vpp_media_rw_surface_setup     = gen7_gpe_media_rw_surface_setup;
     vpp_gpe_ctx->vpp_buffer_surface_setup       = gen7_gpe_buffer_suface_setup;
     vpp_gpe_ctx->vpp_media_chroma_surface_setup = gen75_gpe_media_chroma_surface_setup;
+    vpp_gpe_ctx->surface_tmp = VA_INVALID_ID;
+    vpp_gpe_ctx->surface_tmp_object = NULL;
 
     vpp_gpe_ctx->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
 
index f03cc33..5232214 100644 (file)
@@ -83,9 +83,11 @@ struct vpp_gpe_context{
     unsigned int thread_param_size;
     unsigned int thread_num;
 
-    VASurfaceID  surface_output;
+    struct object_surface *surface_pipeline_input_object;
+    struct object_surface *surface_output_object;
     VASurfaceID  surface_tmp;
-    VASurfaceID  surface_input[MAX_SURF_IN_SUM];
+    struct object_surface *surface_tmp_object;
+    struct object_surface *surface_input_object[MAX_SURF_IN_SUM];
     unsigned  int forward_surf_sum;
     unsigned  int backward_surf_sum;
 
index be77607..b8ca677 100644 (file)
@@ -64,56 +64,12 @@ i965_CreateSurfaces(VADriverContextP ctx,
                     int format,
                     int num_surfaces,
                     VASurfaceID *surfaces);
-VAStatus
-vpp_surface_convert(VADriverContextP ctx,
-                    VASurfaceID dstSurfaceID,
-                    VASurfaceID srcSurfaceID);
 
-VAStatus vpp_surface_copy(VADriverContextP ctx, VASurfaceID dstSurfaceID, VASurfaceID srcSurfaceID)
+VAStatus vpp_surface_convert(VADriverContextP ctx,
+                             struct object_surface *src_obj_surf,
+                             struct object_surface *dst_obj_surf)
 {
     VAStatus va_status = VA_STATUS_SUCCESS;
-    VAImage srcImage, dstImage;
-    void *pBufferSrc, *pBufferDst;
-
-    va_status = vpp_surface_convert(ctx, dstSurfaceID, srcSurfaceID);
-    if(va_status == VA_STATUS_SUCCESS){
-       return va_status;
-    }
-
-    va_status = i965_DeriveImage(ctx, srcSurfaceID, &srcImage);
-    assert(va_status == VA_STATUS_SUCCESS);
-
-    va_status = i965_DeriveImage(ctx, dstSurfaceID, &dstImage);
-    assert(va_status == VA_STATUS_SUCCESS);
-
-    if(srcImage.width  != dstImage.width  ||
-       srcImage.height != dstImage.height ||
-       srcImage.format.fourcc != dstImage.format.fourcc) {
-        return VA_STATUS_ERROR_UNIMPLEMENTED;
-    }
-
-    va_status = i965_MapBuffer(ctx, srcImage.buf, &pBufferSrc);
-    assert(va_status == VA_STATUS_SUCCESS);
-
-    va_status = i965_MapBuffer(ctx, dstImage.buf, &pBufferDst);
-    assert(va_status == VA_STATUS_SUCCESS);
-
-    memcpy(pBufferDst, pBufferSrc, dstImage.data_size);
-
-    i965_UnmapBuffer(ctx, srcImage.buf);
-    i965_UnmapBuffer(ctx, dstImage.buf);
-    i965_DestroyImage(ctx, srcImage.image_id);
-    i965_DestroyImage(ctx, dstImage.image_id);
-
-    return va_status;;
-}
-
-VAStatus vpp_surface_convert(VADriverContextP ctx, VASurfaceID dstSurfaceID, VASurfaceID srcSurfaceID)
-{
-    VAStatus va_status = VA_STATUS_SUCCESS;
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
-    struct object_surface* src_obj_surf = SURFACE(srcSurfaceID);
-    struct object_surface* dst_obj_surf = SURFACE(dstSurfaceID);
 
     assert(src_obj_surf->orig_width  == dst_obj_surf->orig_width);
     assert(src_obj_surf->orig_height == dst_obj_surf->orig_height);
@@ -125,11 +81,11 @@ VAStatus vpp_surface_convert(VADriverContextP ctx, VASurfaceID dstSurfaceID, VAS
     src_rect.height = dst_rect.height = dst_obj_surf->orig_height;
 
     struct i965_surface src_surface, dst_surface;
-    src_surface.id    = srcSurfaceID;
+    src_surface.base  = (struct object_base *)src_obj_surf;
     src_surface.type  = I965_SURFACE_TYPE_SURFACE;
     src_surface.flags = I965_SURFACE_FLAG_FRAME;
 
-    dst_surface.id    = dstSurfaceID;
+    dst_surface.base  = (struct object_base *)dst_obj_surf;
     dst_surface.type  = I965_SURFACE_TYPE_SURFACE;
     dst_surface.flags = I965_SURFACE_FLAG_FRAME;
 
@@ -141,13 +97,12 @@ VAStatus vpp_surface_convert(VADriverContextP ctx, VASurfaceID dstSurfaceID, VAS
     return va_status;
 }
 
-VAStatus vpp_surface_scaling(VADriverContextP ctx, VASurfaceID dstSurfaceID, VASurfaceID srcSurfaceID)
+VAStatus vpp_surface_scaling(VADriverContextP ctx,
+                             struct object_surface *dst_obj_surf,
+                             struct object_surface *src_obj_surf)
 {
     VAStatus va_status = VA_STATUS_SUCCESS;
     int flags = I965_PP_FLAG_AVS;
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
-    struct object_surface* src_obj_surf = SURFACE(srcSurfaceID);
-    struct object_surface* dst_obj_surf = SURFACE(dstSurfaceID);
 
     assert(src_obj_surf->fourcc == VA_FOURCC('N','V','1','2'));
     assert(dst_obj_surf->fourcc == VA_FOURCC('N','V','1','2'));
@@ -164,9 +119,9 @@ VAStatus vpp_surface_scaling(VADriverContextP ctx, VASurfaceID dstSurfaceID, VAS
     dst_rect.height = dst_obj_surf->orig_height;
 
     va_status = i965_scaling_processing(ctx,
-                                       srcSurfaceID,
+                                       src_obj_surf,
                                        &src_rect,
-                                       dstSurfaceID,
+                                       dst_obj_surf,
                                        &dst_rect,
                                        flags);
      
@@ -606,7 +561,6 @@ void hsw_veb_state_command(VADriverContextP ctx, struct intel_vebox_context *pro
 
 void hsw_veb_surface_state(VADriverContextP ctx, struct intel_vebox_context *proc_ctx, unsigned int is_output)
 {
-    struct  i965_driver_data *i965 = i965_driver_data(ctx);
     struct intel_batchbuffer *batch = proc_ctx->batch;
     unsigned int u_offset_y = 0, v_offset_y = 0;
     unsigned int is_uv_interleaved = 0, tiling = 0, swizzle = 0;
@@ -616,9 +570,9 @@ void hsw_veb_surface_state(VADriverContextP ctx, struct intel_vebox_context *pro
     unsigned int half_pitch_chroma = 0;
 
     if(is_output){   
-         obj_surf = SURFACE(proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id);
+        obj_surf = proc_ctx->frame_store[FRAME_OUT_CURRENT].obj_surface;
     }else {
-         obj_surf = SURFACE(proc_ctx->frame_store[FRAME_IN_CURRENT].surface_id);
+        obj_surf = proc_ctx->frame_store[FRAME_IN_CURRENT].obj_surface;
     }
 
     assert(obj_surf->fourcc == VA_FOURCC_NV12 ||
@@ -720,28 +674,28 @@ void hsw_veb_dndi_iecp_command(VADriverContextP ctx, struct intel_vebox_context
                   startingX << 16 |
                   endingX);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_IN_CURRENT].bo,
+              proc_ctx->frame_store[FRAME_IN_CURRENT].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, 0, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_IN_PREVIOUS].bo,
+              proc_ctx->frame_store[FRAME_IN_PREVIOUS].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, 0, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_IN_STMM].bo,
+              proc_ctx->frame_store[FRAME_IN_STMM].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, 0, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_OUT_STMM].bo,
+              proc_ctx->frame_store[FRAME_OUT_STMM].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo,
+              proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_OUT_CURRENT].bo,
+              proc_ctx->frame_store[FRAME_OUT_CURRENT].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_OUT_PREVIOUS].bo,
+              proc_ctx->frame_store[FRAME_OUT_PREVIOUS].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, frame_ctrl_bits);
     OUT_RELOC(batch,
-              proc_ctx->frame_store[FRAME_OUT_STATISTIC].bo,
+              proc_ctx->frame_store[FRAME_OUT_STATISTIC].obj_surface->bo,
               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, frame_ctrl_bits);
 
     ADVANCE_VEB_BATCH(batch);
@@ -756,24 +710,21 @@ void hsw_veb_resource_prepare(VADriverContextP ctx,
     unsigned int input_fourcc, output_fourcc;
     unsigned int input_sampling, output_sampling;
     unsigned int input_tiling, output_tiling;
-    VAGenericID vebox_in_id, vebox_out_id;
     unsigned int i, swizzle;
+    struct object_surface *obj_surf_out = NULL, *obj_surf_in = NULL;
 
-    if(proc_ctx->surface_input_vebox != -1){
-       vebox_in_id = proc_ctx->surface_input_vebox;
-    }else{
-       vebox_in_id = proc_ctx->surface_input;
+    if (proc_ctx->surface_input_vebox_object != NULL) {
+        obj_surf_in = proc_ctx->surface_input_vebox_object;
+    } else {
+        obj_surf_in = proc_ctx->surface_input_object;
     } 
 
-    if(proc_ctx->surface_output_vebox != -1){
-       vebox_out_id = proc_ctx->surface_output_vebox;
-    }else{
-       vebox_out_id = proc_ctx->surface_output;
+    if (proc_ctx->surface_output_vebox_object != NULL) {
+        obj_surf_out = proc_ctx->surface_output_vebox_object;
+    } else {
+        obj_surf_out = proc_ctx->surface_output_object;
     } 
 
-    struct object_surface* obj_surf_in  = SURFACE(vebox_in_id);
-    struct object_surface* obj_surf_out = SURFACE(vebox_out_id);
-       
     if(obj_surf_in->bo == NULL){
           input_fourcc = VA_FOURCC('N','V','1','2');
           input_sampling = SUBSAMPLE_YUV420;
@@ -813,11 +764,13 @@ void hsw_veb_resource_prepare(VADriverContextP ctx,
     assert(va_status == VA_STATUS_SUCCESS);
 
     for(i = 0; i < FRAME_STORE_SUM; i ++) {
-        if(proc_ctx->frame_store[i].bo){
+        if(proc_ctx->frame_store[i].obj_surface){
             continue; //refer external surface for vebox pipeline
         }
     
         VASurfaceID new_surface;
+        struct object_surface *obj_surf = NULL;
+
         va_status =   i965_CreateSurfaces(ctx,
                                           proc_ctx ->width_input,
                                           proc_ctx ->height_input,
@@ -826,19 +779,20 @@ void hsw_veb_resource_prepare(VADriverContextP ctx,
                                           &new_surface);
         assert(va_status == VA_STATUS_SUCCESS);
 
-        proc_ctx->frame_store[i].surface_id = new_surface;
-        struct object_surface* obj_surf = SURFACE(new_surface);
+        obj_surf = SURFACE(new_surface);
+        assert(obj_surf);
 
         if( i <= FRAME_IN_PREVIOUS || i == FRAME_OUT_CURRENT_DN) {
-           i965_check_alloc_surface_bo(ctx, obj_surf, input_tiling, input_fourcc, input_sampling);
+            i965_check_alloc_surface_bo(ctx, obj_surf, input_tiling, input_fourcc, input_sampling);
         } else if( i == FRAME_IN_STMM || i == FRAME_OUT_STMM){
             i965_check_alloc_surface_bo(ctx, obj_surf, 1, input_fourcc, input_sampling);
         } else if( i >= FRAME_OUT_CURRENT){
             i965_check_alloc_surface_bo(ctx, obj_surf, output_tiling, output_fourcc, output_sampling);
         }
-        proc_ctx->frame_store[i].bo = obj_surf->bo;
-        dri_bo_reference(proc_ctx->frame_store[i].bo);
+
+        proc_ctx->frame_store[i].surface_id = new_surface;
         proc_ctx->frame_store[i].is_internal_surface = 1;
+        proc_ctx->frame_store[i].obj_surface = obj_surf;
     }
 
     /* alloc dndi state table  */
@@ -879,66 +833,53 @@ void hsw_veb_surface_reference(VADriverContextP ctx,
                               struct intel_vebox_context *proc_ctx)
 {
     struct object_surface * obj_surf; 
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
-    VAGenericID vebox_in_id, vebox_out_id;
-
-    if(proc_ctx->surface_input_vebox != -1){
-       vebox_in_id = proc_ctx->surface_input_vebox;
-    }else{
-       vebox_in_id = proc_ctx->surface_input;
-    } 
 
-    if(proc_ctx->surface_output_vebox != -1){
-       vebox_out_id = proc_ctx->surface_output_vebox;
-    }else{
-       vebox_out_id = proc_ctx->surface_output;
+    if (proc_ctx->surface_input_vebox_object != NULL) {
+        obj_surf = proc_ctx->surface_input_vebox_object;
+    } else {
+        obj_surf = proc_ctx->surface_input_object;
     } 
 
     /* update the input surface */ 
-     obj_surf = SURFACE(vebox_in_id);
-     dri_bo_unreference(proc_ctx->frame_store[FRAME_IN_CURRENT].bo);
-     proc_ctx->frame_store[FRAME_IN_CURRENT].surface_id = vebox_in_id;
-     proc_ctx->frame_store[FRAME_IN_CURRENT].bo = obj_surf->bo;
-     proc_ctx->frame_store[FRAME_IN_CURRENT].is_internal_surface = 0;
-     dri_bo_reference(proc_ctx->frame_store[FRAME_IN_CURRENT].bo);
+    proc_ctx->frame_store[FRAME_IN_CURRENT].surface_id = VA_INVALID_ID;
+    proc_ctx->frame_store[FRAME_IN_CURRENT].is_internal_surface = 0;
+    proc_ctx->frame_store[FRAME_IN_CURRENT].obj_surface = obj_surf;
+
+    if (proc_ctx->surface_output_vebox_object != NULL) {
+        obj_surf = proc_ctx->surface_output_vebox_object;
+    } else {
+        obj_surf = proc_ctx->surface_output_object;
+    } 
 
      /* update the output surface */ 
-     obj_surf = SURFACE(vebox_out_id);
-     if(proc_ctx->filters_mask == VPP_DNDI_DN){
-         dri_bo_unreference(proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo);
-         proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].surface_id = vebox_out_id;
-         proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo = obj_surf->bo;
-         proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].is_internal_surface = 0;
-         dri_bo_reference(proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo);
-     }else {
-         dri_bo_unreference(proc_ctx->frame_store[FRAME_OUT_CURRENT].bo);
-         proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id = vebox_out_id;
-         proc_ctx->frame_store[FRAME_OUT_CURRENT].bo = obj_surf->bo;
-         proc_ctx->frame_store[FRAME_OUT_CURRENT].is_internal_surface = 0;
-         dri_bo_reference(proc_ctx->frame_store[FRAME_OUT_CURRENT].bo);
-     } 
+    if (proc_ctx->filters_mask == VPP_DNDI_DN) {
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].surface_id = VA_INVALID_ID;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].is_internal_surface = 0;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].obj_surface = obj_surf;
+    } else {
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id = VA_INVALID_ID;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].is_internal_surface = 0;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].obj_surface = obj_surf;
+    }
 }
 
 void hsw_veb_surface_unreference(VADriverContextP ctx,
                                  struct intel_vebox_context *proc_ctx)
 {
     /* unreference the input surface */ 
-    dri_bo_unreference(proc_ctx->frame_store[FRAME_IN_CURRENT].bo);
-    proc_ctx->frame_store[FRAME_IN_CURRENT].surface_id = -1;
-    proc_ctx->frame_store[FRAME_IN_CURRENT].bo = NULL;
+    proc_ctx->frame_store[FRAME_IN_CURRENT].surface_id = VA_INVALID_ID;
     proc_ctx->frame_store[FRAME_IN_CURRENT].is_internal_surface = 0;
+    proc_ctx->frame_store[FRAME_IN_CURRENT].obj_surface = NULL;
 
     /* unreference the shared output surface */ 
-    if(proc_ctx->filters_mask == VPP_DNDI_DN){
-       dri_bo_unreference(proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo);
-       proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].surface_id = -1;
-       proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].bo = NULL;
-       proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].is_internal_surface = 0;
-    }else{
-       dri_bo_unreference(proc_ctx->frame_store[FRAME_OUT_CURRENT].bo);
-       proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id = -1;
-       proc_ctx->frame_store[FRAME_OUT_CURRENT].bo = NULL;
-       proc_ctx->frame_store[FRAME_OUT_CURRENT].is_internal_surface = 0;
+    if (proc_ctx->filters_mask == VPP_DNDI_DN) {
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].surface_id = VA_INVALID_ID;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].is_internal_surface = 0;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].obj_surface = NULL;
+    } else {
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id = VA_INVALID_ID;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].is_internal_surface = 0;
+        proc_ctx->frame_store[FRAME_OUT_CURRENT].obj_surface = NULL;
     }
 }
 
@@ -947,8 +888,8 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
 {
     VAStatus va_status;
     struct i965_driver_data *i965 = i965_driver_data(ctx);
-    struct object_surface* obj_surf_input = SURFACE(proc_ctx->surface_input);
-    struct object_surface* obj_surf_output = SURFACE(proc_ctx->surface_output);
+    struct object_surface* obj_surf_input = proc_ctx->surface_input_object;
+    struct object_surface* obj_surf_output = proc_ctx->surface_output_object;
     struct object_surface* obj_surf_input_vebox;
     struct object_surface* obj_surf_output_vebox;
 
@@ -988,8 +929,8 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
            assert(0);
      }
     
-     if(proc_ctx->format_convert_flags & PRE_FORMAT_CONVERT){
-        if(proc_ctx->surface_input_vebox == -1){
+     if (proc_ctx->format_convert_flags & PRE_FORMAT_CONVERT) {
+         if(proc_ctx->surface_input_vebox_object == NULL){
              va_status = i965_CreateSurfaces(ctx,
                                             proc_ctx->width_input,
                                             proc_ctx->height_input,
@@ -998,10 +939,15 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
                                             &(proc_ctx->surface_input_vebox));
              assert(va_status == VA_STATUS_SUCCESS);
              obj_surf_input_vebox = SURFACE(proc_ctx->surface_input_vebox);
-             i965_check_alloc_surface_bo(ctx, obj_surf_input_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             assert(obj_surf_input_vebox);
+
+             if (obj_surf_input_vebox) {
+                 proc_ctx->surface_input_vebox_object = obj_surf_input_vebox;
+                 i965_check_alloc_surface_bo(ctx, obj_surf_input_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             }
          }
        
-         vpp_surface_convert(ctx, proc_ctx->surface_input_vebox, proc_ctx->surface_input);
+         vpp_surface_convert(ctx, proc_ctx->surface_input_vebox_object, proc_ctx->surface_input_object);
       }
 
       /* create one temporary NV12 surfaces for conversion*/
@@ -1023,7 +969,7 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
   
      if(proc_ctx->format_convert_flags & POST_FORMAT_CONVERT ||
         proc_ctx->format_convert_flags & POST_SCALING_CONVERT){
-       if(proc_ctx->surface_output_vebox == -1){
+       if(proc_ctx->surface_output_vebox_object == NULL){
              va_status = i965_CreateSurfaces(ctx,
                                             proc_ctx->width_input,
                                             proc_ctx->height_input,
@@ -1032,12 +978,17 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
                                             &(proc_ctx->surface_output_vebox));
              assert(va_status == VA_STATUS_SUCCESS);
              obj_surf_output_vebox = SURFACE(proc_ctx->surface_output_vebox);
-             i965_check_alloc_surface_bo(ctx, obj_surf_output_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             assert(obj_surf_output_vebox);
+
+             if (obj_surf_output_vebox) {
+                 proc_ctx->surface_output_vebox_object = obj_surf_output_vebox;
+                 i965_check_alloc_surface_bo(ctx, obj_surf_output_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             }
        }
      }   
 
      if(proc_ctx->format_convert_flags & POST_SCALING_CONVERT){
-       if(proc_ctx->surface_output_scaled == -1){
+       if(proc_ctx->surface_output_scaled_object == NULL){
              va_status = i965_CreateSurfaces(ctx,
                                             proc_ctx->width_output,
                                             proc_ctx->height_output,
@@ -1046,7 +997,12 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
                                             &(proc_ctx->surface_output_scaled));
              assert(va_status == VA_STATUS_SUCCESS);
              obj_surf_output_vebox = SURFACE(proc_ctx->surface_output_scaled);
-             i965_check_alloc_surface_bo(ctx, obj_surf_output_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             assert(obj_surf_output_vebox);
+
+             if (obj_surf_output_vebox) {
+                 proc_ctx->surface_output_scaled_object = obj_surf_output_vebox;
+                 i965_check_alloc_surface_bo(ctx, obj_surf_output_vebox, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
+             }
        }
      } 
     
@@ -1056,13 +1012,12 @@ int hsw_veb_pre_format_convert(VADriverContextP ctx,
 int hsw_veb_post_format_convert(VADriverContextP ctx,
                            struct intel_vebox_context *proc_ctx)
 {
-     struct i965_driver_data *i965 = i965_driver_data(ctx);
-     VASurfaceID surf_id_pipe_out = 0;
+     struct object_surface *obj_surface = NULL;
 
      if(proc_ctx->filters_mask == VPP_DNDI_DN){
-         surf_id_pipe_out = proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].surface_id;
+         obj_surface = proc_ctx->frame_store[FRAME_OUT_CURRENT_DN].obj_surface;
      } else {
-         surf_id_pipe_out = proc_ctx->frame_store[FRAME_OUT_CURRENT].surface_id;
+         obj_surface = proc_ctx->frame_store[FRAME_OUT_CURRENT].obj_surface;
      }
  
     if(!(proc_ctx->format_convert_flags & POST_FORMAT_CONVERT) &&
@@ -1073,24 +1028,25 @@ int hsw_veb_post_format_convert(VADriverContextP ctx,
     } else if ((proc_ctx->format_convert_flags & POST_FORMAT_CONVERT) &&
                !(proc_ctx->format_convert_flags & POST_SCALING_CONVERT)){
        /* convert and copy NV12 to YV12/IMC3/IMC2 output*/
-        vpp_surface_convert(ctx,proc_ctx->surface_output, surf_id_pipe_out);
+        vpp_surface_convert(ctx,proc_ctx->surface_output_object, obj_surface);
 
     } else if(proc_ctx->format_convert_flags & POST_SCALING_CONVERT) {
        /* scaling, convert and copy NV12 to YV12/IMC3/IMC2/ output*/
-        assert((SURFACE(surf_id_pipe_out))->fourcc == VA_FOURCC('N','V','1','2'));
+        assert(obj_surface->fourcc == VA_FOURCC('N','V','1','2'));
      
         /* first step :surface scaling */
-        vpp_surface_scaling(ctx,proc_ctx->surface_output_scaled, surf_id_pipe_out);
+        vpp_surface_scaling(ctx,proc_ctx->surface_output_scaled_object, obj_surface);
 
         /* second step: color format convert and copy to output */
-        struct object_surface *obj_surf = SURFACE(proc_ctx->surface_output);
-        if(obj_surf->fourcc ==  VA_FOURCC('N','V','1','2') ||
-           obj_surf->fourcc ==  VA_FOURCC('Y','V','1','2') ||
-           obj_surf->fourcc ==  VA_FOURCC('I','4','2','0') ||
-           obj_surf->fourcc ==  VA_FOURCC('Y','U','Y','2') ||
-           obj_surf->fourcc ==  VA_FOURCC('I','M','C','1') ||
-           obj_surf->fourcc ==  VA_FOURCC('I','M','C','3')) {  
-           vpp_surface_convert(ctx,proc_ctx->surface_output, proc_ctx->surface_output_scaled);
+        obj_surface = proc_ctx->surface_output_object;
+
+        if(obj_surface->fourcc ==  VA_FOURCC('N','V','1','2') ||
+           obj_surface->fourcc ==  VA_FOURCC('Y','V','1','2') ||
+           obj_surface->fourcc ==  VA_FOURCC('I','4','2','0') ||
+           obj_surface->fourcc ==  VA_FOURCC('Y','U','Y','2') ||
+           obj_surface->fourcc ==  VA_FOURCC('I','M','C','1') ||
+           obj_surface->fourcc ==  VA_FOURCC('I','M','C','3')) {  
+           vpp_surface_convert(ctx, proc_ctx->surface_output_object, proc_ctx->surface_output_scaled_object);
        }else {
            assert(0); 
        }
@@ -1111,6 +1067,12 @@ VAStatus gen75_vebox_process_picture(VADriverContextP ctx,
 
     for (i = 0; i < pipe->num_filters; i ++) {
          obj_buf = BUFFER(pipe->filters[i]);
+         
+         assert(obj_buf && obj_buf->buffer_store);
+
+         if (!obj_buf || !obj_buf->buffer_store)
+             goto error;
+
          filter = (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
             
          if (filter->type == VAProcFilterNoiseReduction) {
@@ -1155,6 +1117,9 @@ VAStatus gen75_vebox_process_picture(VADriverContextP ctx,
        proc_ctx->is_first_frame = 0; 
      
     return VA_STATUS_SUCCESS;
+
+error:
+    return VA_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 void gen75_vebox_context_destroy(VADriverContextP ctx, 
@@ -1162,30 +1127,35 @@ void gen75_vebox_context_destroy(VADriverContextP ctx,
 {
     int i;
 
-    if(proc_ctx->surface_input_vebox != -1){
+    if(proc_ctx->surface_input_vebox != VA_INVALID_ID){
        i965_DestroySurfaces(ctx, &proc_ctx->surface_input_vebox, 1);
-       proc_ctx->surface_input_vebox = -1;
+       proc_ctx->surface_input_vebox = VA_INVALID_ID;
+       proc_ctx->surface_input_vebox_object = NULL;
      }
 
-    if(proc_ctx->surface_output_vebox != -1){
+    if(proc_ctx->surface_output_vebox != VA_INVALID_ID){
        i965_DestroySurfaces(ctx, &proc_ctx->surface_output_vebox, 1);
-       proc_ctx->surface_output_vebox = -1;
+       proc_ctx->surface_output_vebox = VA_INVALID_ID;
+       proc_ctx->surface_output_vebox_object = NULL;
      }
 
-    if(proc_ctx->surface_output_scaled != -1){
+    if(proc_ctx->surface_output_scaled != VA_INVALID_ID){
        i965_DestroySurfaces(ctx, &proc_ctx->surface_output_scaled, 1);
-       proc_ctx->surface_output_scaled = -1;
+       proc_ctx->surface_output_scaled = VA_INVALID_ID;
+       proc_ctx->surface_output_scaled_object = NULL;
      }
 
     for(i = 0; i < FRAME_STORE_SUM; i ++) {
-        if(proc_ctx->frame_store[i].bo){
-           dri_bo_unreference(proc_ctx->frame_store[i].bo);
-           i965_DestroySurfaces(ctx, &proc_ctx->frame_store[i].surface_id, 1);
+        if (proc_ctx->frame_store[i].is_internal_surface == 1) {
+            assert(proc_ctx->frame_store[i].surface_id != VA_INVALID_ID);
+
+            if (proc_ctx->frame_store[i].surface_id != VA_INVALID_ID)
+                i965_DestroySurfaces(ctx, &proc_ctx->frame_store[i].surface_id, 1);
         }
 
-       proc_ctx->frame_store[i].surface_id = -1;
-       proc_ctx->frame_store[i].bo = NULL;
-       proc_ctx->frame_store[i].valid = 0;
+        proc_ctx->frame_store[i].surface_id = VA_INVALID_ID;
+        proc_ctx->frame_store[i].is_internal_surface = 0;
+        proc_ctx->frame_store[i].obj_surface = NULL;
     }
 
     /* dndi state table  */
@@ -1213,15 +1183,27 @@ struct intel_vebox_context * gen75_vebox_context_init(VADriverContextP ctx)
 {
     struct intel_driver_data *intel = intel_driver_data(ctx);
     struct intel_vebox_context *proc_context = calloc(1, sizeof(struct intel_vebox_context));
+    int i;
 
     proc_context->batch = intel_batchbuffer_new(intel, I915_EXEC_VEBOX, 0);
     memset(proc_context->frame_store, 0, sizeof(VEBFrameStore)*FRAME_STORE_SUM);
+
+    for (i = 0; i < FRAME_STORE_SUM; i ++) {
+        proc_context->frame_store[i].surface_id = VA_INVALID_ID;
+        proc_context->frame_store[i].is_internal_surface = 0;
+        proc_context->frame_store[i].obj_surface = NULL;
+    }
   
     proc_context->filters_mask          = 0;
     proc_context->is_first_frame        = 1;
-    proc_context->surface_input_vebox   = -1;
-    proc_context->surface_output_vebox  = -1;
-    proc_context->surface_output_scaled = -1;
+    proc_context->surface_output_object = NULL;
+    proc_context->surface_input_object  = NULL;
+    proc_context->surface_input_vebox   = VA_INVALID_ID;
+    proc_context->surface_input_vebox_object = NULL;
+    proc_context->surface_output_vebox  = VA_INVALID_ID;
+    proc_context->surface_output_vebox_object = NULL;
+    proc_context->surface_output_scaled = VA_INVALID_ID;
+    proc_context->surface_output_scaled_object = NULL;
     proc_context->filters_mask          = 0;
     proc_context->format_convert_flags  = 0;
 
index 592c80c..ee5a4ef 100644 (file)
@@ -87,9 +87,8 @@ enum SURFACE_FORMAT{
 
 typedef struct veb_frame_store {
     VASurfaceID surface_id;
-    dri_bo  *bo;
-    unsigned char  valid;
     unsigned int is_internal_surface;
+    struct object_surface *obj_surface;
 } VEBFrameStore;
 
 typedef struct veb_buffer {
@@ -102,11 +101,14 @@ struct intel_vebox_context
 {
     struct intel_batchbuffer *batch;
 
-    VASurfaceID surface_input;
+    struct object_surface *surface_input_object;
+    struct object_surface *surface_output_object;
     VASurfaceID surface_input_vebox;
-    VASurfaceID surface_output;
+    struct object_surface *surface_input_vebox_object;    
     VASurfaceID surface_output_vebox;
+    struct object_surface *surface_output_vebox_object;
     VASurfaceID surface_output_scaled;
+    struct object_surface *surface_output_scaled_object;
 
     unsigned int fourcc_input;
     unsigned int fourcc_output;
index 7de8478..f4caaec 100755 (executable)
@@ -3088,11 +3088,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;
 
@@ -3435,7 +3435,7 @@ i965_hw_putimage(VADriverContextP ctx,
 
     assert(obj_surface->fourcc);
 
-    src_surface.id = image;
+    src_surface.base = (struct object_base *)image;
     src_surface.type = I965_SURFACE_TYPE_IMAGE;
     src_surface.flags = I965_SURFACE_FLAG_FRAME;
     src_rect.x = src_x;
@@ -3443,7 +3443,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;
index c1e009a..787755c 100644 (file)
@@ -60,7 +60,7 @@
 
 struct i965_surface
 {
-    VAGenericID id;
+    struct object_base *base;
     int type;
     int flags;
 };
index 8f82344..4384619 100644 (file)
@@ -98,7 +98,7 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
     rect.width = obj_surface->orig_width;
     rect.height = obj_surface->orig_height;
     
-    src_surface.id = encode_state->current_render_target;
+    src_surface.base = (struct object_base *)obj_surface;
     src_surface.type = I965_SURFACE_TYPE_SURFACE;
     src_surface.flags = I965_SURFACE_FLAG_FRAME;
     
@@ -115,9 +115,10 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
 
     obj_surface = SURFACE(encoder_context->input_yuv_surface);
     encode_state->input_yuv_object = obj_surface;
+    assert(obj_surface);
     i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
     
-    dst_surface.id = encoder_context->input_yuv_surface;
+    dst_surface.base = (struct object_base *)obj_surface;
     dst_surface.type = I965_SURFACE_TYPE_SURFACE;
     dst_surface.flags = I965_SURFACE_FLAG_FRAME;
 
index 8a95a0f..34854ac 100644 (file)
@@ -189,7 +189,7 @@ i965_put_surface_dri(
     else if (flags & VA_BOTTOM_FIELD)
         pp_flag |= I965_PP_FLAG_BOTTOM_FIELD;
 
-    intel_render_put_surface(ctx, surface, obj_surface, src_rect, dst_rect, pp_flag);
+    intel_render_put_surface(ctx, obj_surface, src_rect, dst_rect, pp_flag);
 
     for(i = 0; i < I965_MAX_SUBPIC_SUM; i++){
         if(obj_surface->subpic[i] != VA_INVALID_ID) {
index 0d5e4f5..898ed7b 100755 (executable)
@@ -1086,14 +1086,13 @@ static struct pp_module pp_modules_gen75[] = {
 static int
 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     int fourcc;
 
     if (surface->type == I965_SURFACE_TYPE_IMAGE) {
-        struct object_image *obj_image = IMAGE(surface->id);
+        struct object_image *obj_image = (struct object_image *)surface->base;
         fourcc = obj_image->image.format.fourcc;
     } else {
-        struct object_surface *obj_surface = SURFACE(surface->id);
+        struct object_surface *obj_surface = (struct object_surface *)surface->base;
         fourcc = obj_surface->fourcc;
     }
 
@@ -1621,7 +1620,6 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
                                 int base_index, int is_target,
                                 int *width, int *height, int *pitch, int *offset)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
     struct object_image *obj_image;
     dri_bo *bo;
@@ -1639,7 +1637,7 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
     int scale_factor_of_1st_plane_width_in_byte = 1;
                               
     if (surface->type == I965_SURFACE_TYPE_SURFACE) {
-        obj_surface = SURFACE(surface->id);
+        obj_surface = (struct object_surface *)surface->base;
         bo = obj_surface->bo;
         width[0] = obj_surface->orig_width;
         height[0] = obj_surface->orig_height;
@@ -1670,7 +1668,7 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
             offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
         }
     } else {
-        obj_image = IMAGE(surface->id);
+        obj_image = (struct object_image *)surface->base;
         bo = obj_image->bo;
         width[0] = obj_image->image.width;
         height[0] = obj_image->image.height;
@@ -1735,7 +1733,6 @@ gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_proc
                                      int base_index, int is_target,
                                      int *width, int *height, int *pitch, int *offset)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
     struct object_image *obj_image;
     dri_bo *bo;
@@ -1752,7 +1749,7 @@ gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_proc
                               fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
 
     if (surface->type == I965_SURFACE_TYPE_SURFACE) {
-        obj_surface = SURFACE(surface->id);
+        obj_surface = (struct object_surface *)surface->base;
         bo = obj_surface->bo;
         width[0] = obj_surface->orig_width;
         height[0] = obj_surface->orig_height;
@@ -1781,7 +1778,7 @@ gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_proc
         pitch[2] = obj_surface->cb_cr_pitch;
         offset[2] = obj_surface->y_cr_offset * obj_surface->width;
     } else {
-        obj_image = IMAGE(surface->id);
+        obj_image = (struct object_image *)surface->base;
         bo = obj_image->bo;
         width[0] = obj_image->image.width;
         height[0] = obj_image->image.height;
@@ -2088,7 +2085,6 @@ pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_con
                            const VARectangle *dst_rect,
                            void *filter_param)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
     struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
     struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
@@ -2098,7 +2094,7 @@ pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_con
     int out_w, out_h, out_wpitch, out_hpitch;
 
     /* source surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     in_w = obj_surface->orig_width;
     in_h = obj_surface->orig_height;
     in_wpitch = obj_surface->width;
@@ -2117,7 +2113,7 @@ pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_con
                               2, 0);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     out_w = obj_surface->orig_width;
     out_h = obj_surface->orig_height;
     out_wpitch = obj_surface->width;
@@ -2305,7 +2301,6 @@ pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context
                        void *filter_param,
                        int nlas)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
     struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
     struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
@@ -2318,7 +2313,7 @@ pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context
     int i;
 
     /* surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     in_w = obj_surface->orig_width;
     in_h = obj_surface->orig_height;
     in_wpitch = obj_surface->width;
@@ -2341,7 +2336,7 @@ pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context
                                2);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     out_w = obj_surface->orig_width;
     out_h = obj_surface->orig_height;
     out_wpitch = obj_surface->width;
@@ -3129,7 +3124,7 @@ pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_contex
         dndi_top_first = 0;
 
     /* surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3164,7 +3159,7 @@ pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_contex
                               20, 1);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3335,7 +3330,7 @@ pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context
     }
 
     /* surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3370,7 +3365,7 @@ pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context
                               20, 1);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3524,7 +3519,7 @@ gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_c
         dndi_top_first = 0;
 
     /* surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3567,7 +3562,7 @@ gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_c
                               5, 1);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3771,7 +3766,7 @@ gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_con
     }
 
     /* surface */
-    obj_surface = SURFACE(src_surface->id);
+    obj_surface = (struct object_surface *)src_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -3814,7 +3809,7 @@ gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_con
                               33, 1);
 
     /* destination surface */
-    obj_surface = SURFACE(dst_surface->id);
+    obj_surface = (struct object_surface *)dst_surface->base;
     orig_w = obj_surface->orig_width;
     orig_h = obj_surface->orig_height;
     w = obj_surface->width;
@@ -4547,12 +4542,11 @@ rgb_to_yuv(unsigned int argb,
 static void 
 i965_vpp_clear_surface(VADriverContextP ctx,
                        struct i965_post_processing_context *pp_context,
-                       VASurfaceID surface,
+                       struct object_surface *obj_surface,
                        unsigned int color)
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct intel_batchbuffer *batch = pp_context->batch;
-    struct object_surface *obj_surface = SURFACE(surface);
     unsigned int blt_cmd, br13;
     unsigned int tiling = 0, swizzle = 0;
     int pitch;
@@ -4626,16 +4620,14 @@ i965_vpp_clear_surface(VADriverContextP ctx,
 VAStatus
 i965_scaling_processing(
     VADriverContextP   ctx,
-    VASurfaceID        src_surface_id,
+    struct object_surface *src_surface_obj,
     const VARectangle *src_rect,
-    VASurfaceID        dst_surface_id,
+    struct object_surface *dst_surface_obj,
     const VARectangle *dst_rect,
     unsigned int       flags)
 {
     VAStatus va_status = VA_STATUS_SUCCESS;
     struct i965_driver_data *i965 = i965_driver_data(ctx);
-    struct object_surface *src_surface_obj = SURFACE(src_surface_id);
-    struct object_surface *dst_surface_obj = SURFACE(dst_surface_id);
  
     assert(src_surface_obj->fourcc == VA_FOURCC('N', 'V', '1', '2'));
     assert(dst_surface_obj->fourcc == VA_FOURCC('N', 'V', '1', '2'));
@@ -4646,10 +4638,10 @@ i965_scaling_processing(
 
          _i965LockMutex(&i965->pp_mutex);
 
-         src_surface.id = src_surface_id;
+         src_surface.base = (struct object_base *)src_surface_obj;
          src_surface.type = I965_SURFACE_TYPE_SURFACE;
          src_surface.flags = I965_SURFACE_FLAG_FRAME;
-         dst_surface.id = dst_surface_id;
+         dst_surface.base = (struct object_base *)dst_surface_obj;
          dst_surface.type = I965_SURFACE_TYPE_SURFACE;
          dst_surface.flags = I965_SURFACE_FLAG_FRAME;
 
@@ -4670,7 +4662,7 @@ i965_scaling_processing(
 VASurfaceID
 i965_post_processing(
     VADriverContextP   ctx,
-    VASurfaceID        surface,
+    struct object_surface *obj_surface,
     const VARectangle *src_rect,
     const VARectangle *dst_rect,
     unsigned int       flags,
@@ -4678,19 +4670,16 @@ i965_post_processing(
 )
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
-    VASurfaceID in_surface_id = surface;
     VASurfaceID out_surface_id = VA_INVALID_ID;
+    VASurfaceID tmp_id = VA_INVALID_ID;
     
     *has_done_scaling = 0;
 
     if (HAS_PP(i965)) {
-        struct object_surface *obj_surface;
         VAStatus status;
         struct i965_surface src_surface;
         struct i965_surface dst_surface;
 
-        obj_surface = SURFACE(in_surface_id);
-
         /* Currently only support post processing for NV12 surface */
         if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
             return out_surface_id;
@@ -4698,6 +4687,11 @@ i965_post_processing(
         _i965LockMutex(&i965->pp_mutex);
 
         if (flags & I965_PP_FLAG_MCDI) {
+            src_surface.base = (struct object_base *)obj_surface;
+            src_surface.type = I965_SURFACE_TYPE_SURFACE;
+            src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ? 
+                I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
+
             status = i965_CreateSurfaces(ctx,
                                          obj_surface->orig_width,
                                          obj_surface->orig_height,
@@ -4706,13 +4700,11 @@ i965_post_processing(
                                          &out_surface_id);
             assert(status == VA_STATUS_SUCCESS);
             obj_surface = SURFACE(out_surface_id);
+            assert(obj_surface);
             i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
-            i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0); 
-            src_surface.id = in_surface_id;
-            src_surface.type = I965_SURFACE_TYPE_SURFACE;
-            src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ? 
-                I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
-            dst_surface.id = out_surface_id;
+            i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0); 
+
+            dst_surface.base = (struct object_base *)obj_surface;
             dst_surface.type = I965_SURFACE_TYPE_SURFACE;
             dst_surface.flags = I965_SURFACE_FLAG_FRAME;
 
@@ -4730,7 +4722,11 @@ i965_post_processing(
             struct intel_region *dest_region = render_state->draw_region;
 
             if (out_surface_id != VA_INVALID_ID)
-                in_surface_id = out_surface_id;
+                tmp_id = out_surface_id;
+
+            src_surface.base = (struct object_base *)obj_surface;
+            src_surface.type = I965_SURFACE_TYPE_SURFACE;
+            src_surface.flags = I965_SURFACE_FLAG_FRAME;
 
             status = i965_CreateSurfaces(ctx,
                                          dest_region->width,
@@ -4740,12 +4736,11 @@ i965_post_processing(
                                          &out_surface_id);
             assert(status == VA_STATUS_SUCCESS);
             obj_surface = SURFACE(out_surface_id);
+            assert(obj_surface);
             i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
-            i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0); 
-            src_surface.id = in_surface_id;
-            src_surface.type = I965_SURFACE_TYPE_SURFACE;
-            src_surface.flags = I965_SURFACE_FLAG_FRAME;
-            dst_surface.id = out_surface_id;
+            i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0); 
+
+            dst_surface.base = (struct object_base *)obj_surface;
             dst_surface.type = I965_SURFACE_TYPE_SURFACE;
             dst_surface.flags = I965_SURFACE_FLAG_FRAME;
 
@@ -4757,8 +4752,8 @@ i965_post_processing(
                                           PP_NV12_AVS,
                                           NULL);
 
-            if (in_surface_id != surface)
-                i965_DestroySurfaces(ctx, &in_surface_id, 1);
+            if (tmp_id != VA_INVALID_ID)
+                i965_DestroySurfaces(ctx, &tmp_id, 1);
                 
             *has_done_scaling = 1;
         }
@@ -5191,17 +5186,22 @@ i965_proc_picture(VADriverContextP ctx,
     assert(proc_state->current_render_target != VA_INVALID_ID);
 
     obj_surface = SURFACE(pipeline_param->surface);
+    assert(obj_surface && obj_surface->bo);
+
+    if (!obj_surface || !obj_surface->bo)
+        goto error;
+
     in_width = obj_surface->orig_width;
     in_height = obj_surface->orig_height;
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
 
-    src_surface.id = pipeline_param->surface;
+    src_surface.base = (struct object_base *)obj_surface;
     src_surface.type = I965_SURFACE_TYPE_SURFACE;
     src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
 
     VASurfaceID out_surface_id = VA_INVALID_ID;
     if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
-        src_surface.id = pipeline_param->surface;
+        src_surface.base = (struct object_base *)obj_surface;
         src_surface.type = I965_SURFACE_TYPE_SURFACE;
         src_surface.flags = I965_SURFACE_FLAG_FRAME;
         src_rect.x = 0;
@@ -5218,9 +5218,10 @@ i965_proc_picture(VADriverContextP ctx,
         assert(status == VA_STATUS_SUCCESS);
         tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
         obj_surface = SURFACE(out_surface_id);
+        assert(obj_surface);
         i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
 
-        dst_surface.id = out_surface_id;
+        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 = 0;
@@ -5235,7 +5236,7 @@ i965_proc_picture(VADriverContextP ctx,
                                        &dst_rect);
         assert(status == VA_STATUS_SUCCESS);
 
-        src_surface.id = out_surface_id;
+        src_surface.base = (struct object_base *)obj_surface;
         src_surface.type = I965_SURFACE_TYPE_SURFACE;
         src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
     }
@@ -5266,10 +5267,19 @@ i965_proc_picture(VADriverContextP ctx,
 
     for (i = 0; i < pipeline_param->num_filters; i++) {
         struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
-        VAProcFilterParameterBufferBase *filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
-        VAProcFilterType filter_type = filter_param->type;
+        VAProcFilterParameterBufferBase *filter_param = NULL;
+        VAProcFilterType filter_type;
+        int kernel_index;
+
+        assert(obj_buffer && obj_buffer->buffer_store);
+
+        if (!obj_buffer || !obj_buffer->buffer_store)
+            goto error;
+
         out_surface_id = VA_INVALID_ID;
-        int kernel_index = procfilter_to_pp_flag[filter_type];
+        filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
+        filter_type = filter_param->type;
+        kernel_index = procfilter_to_pp_flag[filter_type];
 
         if (kernel_index != PP_NULL &&
             proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
@@ -5282,8 +5292,9 @@ i965_proc_picture(VADriverContextP ctx,
             assert(status == VA_STATUS_SUCCESS);
             tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
             obj_surface = SURFACE(out_surface_id);
+            assert(obj_surface);
             i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
-            dst_surface.id = out_surface_id;
+            dst_surface.base = (struct object_base *)obj_surface;
             dst_surface.type = I965_SURFACE_TYPE_SURFACE;
             status = i965_post_processing_internal(ctx, &proc_context->pp_context,
                                                    &src_surface,
@@ -5294,7 +5305,7 @@ i965_proc_picture(VADriverContextP ctx,
                                                    filter_param);
 
             if (status == VA_STATUS_SUCCESS) {
-                src_surface.id = dst_surface.id;
+                src_surface.base = dst_surface.base;
                 src_surface.type = dst_surface.type;
                 src_surface.flags = dst_surface.flags;
             }
@@ -5302,6 +5313,11 @@ i965_proc_picture(VADriverContextP ctx,
     }
 
     obj_surface = SURFACE(proc_state->current_render_target);
+    assert(obj_surface);
+    
+    if (!obj_surface)
+        goto error;
+
     int csc_needed = 0;
     if (obj_surface->fourcc && obj_surface->fourcc !=  VA_FOURCC('N','V','1','2')){
         csc_needed = 1;
@@ -5315,15 +5331,16 @@ i965_proc_picture(VADriverContextP ctx,
         assert(status == VA_STATUS_SUCCESS);
         tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
         struct object_surface *csc_surface = SURFACE(out_surface_id);
+        assert(csc_surface);
         i965_check_alloc_surface_bo(ctx, csc_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
-        dst_surface.id = out_surface_id;
+        dst_surface.base = (struct object_base *)csc_surface;
     } else {
         i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
-        dst_surface.id = proc_state->current_render_target;
+        dst_surface.base = (struct object_base *)obj_surface;
     }
 
     dst_surface.type = I965_SURFACE_TYPE_SURFACE;
-    i965_vpp_clear_surface(ctx, &proc_context->pp_context, proc_state->current_render_target, pipeline_param->output_background_color); 
+    i965_vpp_clear_surface(ctx, &proc_context->pp_context, obj_surface, pipeline_param->output_background_color); 
 
     // load/save doesn't support different origin offset for src and dst surface
     if (src_rect.width == dst_rect.width &&
@@ -5350,10 +5367,10 @@ i965_proc_picture(VADriverContextP ctx,
     }
 
     if (csc_needed) {
-        src_surface.id = dst_surface.id;
+        src_surface.base = dst_surface.base;
         src_surface.type = dst_surface.type;
         src_surface.flags = dst_surface.flags;
-        dst_surface.id = proc_state->current_render_target;
+        dst_surface.base = (struct object_base *)obj_surface;
         dst_surface.type = I965_SURFACE_TYPE_SURFACE;
         i965_image_processing(ctx, &src_surface, &dst_rect, &dst_surface, &dst_rect);
     }
@@ -5366,6 +5383,14 @@ i965_proc_picture(VADriverContextP ctx,
     intel_batchbuffer_flush(hw_context->batch);
 
     return VA_STATUS_SUCCESS;
+
+error:
+    if (num_tmp_surfaces)
+        i965_DestroySurfaces(ctx,
+                             tmp_surfaces,
+                             num_tmp_surfaces);
+
+    return VA_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 static void
index b7037e1..b652055 100755 (executable)
@@ -500,7 +500,7 @@ struct i965_proc_context
 VASurfaceID
 i965_post_processing(
     VADriverContextP   ctx,
-    VASurfaceID        surface,
+    struct object_surface *obj_surface,
     const VARectangle *src_rect,
     const VARectangle *dst_rect,
     unsigned int       flags,
@@ -510,9 +510,9 @@ i965_post_processing(
 VAStatus
 i965_scaling_processing(
     VADriverContextP   ctx,
-    VASurfaceID        src_surface_id,
+    struct object_surface *src_surface_obj,
     const VARectangle *src_rect,
-    VASurfaceID        dst_surface_id,
+    struct object_surface *dst_surface_obj,
     const VARectangle *dst_rect,
     unsigned int       flags
 );
index 26c3f9c..cdbe562 100644 (file)
@@ -3023,7 +3023,6 @@ i965_DestroySurfaces(VADriverContextP ctx,
 void
 intel_render_put_surface(
     VADriverContextP   ctx,
-    VASurfaceID        surface,
     struct object_surface *obj_surface,
     const VARectangle *src_rect,
     const VARectangle *dst_rect,
@@ -3032,7 +3031,12 @@ intel_render_put_surface(
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     int has_done_scaling = 0;
-    VASurfaceID out_surface_id = i965_post_processing(ctx, surface, src_rect, dst_rect, flags, &has_done_scaling);
+    VASurfaceID out_surface_id = i965_post_processing(ctx,
+                                                      obj_surface,
+                                                      src_rect,
+                                                      dst_rect,
+                                                      flags,
+                                                      &has_done_scaling);
 
     assert((!has_done_scaling) || (out_surface_id != VA_INVALID_ID));
 
index 6537873..f09b535 100644 (file)
@@ -86,7 +86,6 @@ void i965_render_terminate(VADriverContextP ctx);
 void
 intel_render_put_surface(
     VADriverContextP   ctx,
-    VASurfaceID        surface,
     struct object_surface *obj_surface,
     const VARectangle *src_rect,
     const VARectangle *dst_rect,