OSDN Git Service

Allow build without VA/X11 API.
[android-x86/hardware-intel-common-vaapi.git] / src / i965_output_dri.c
1 /*
2  * Copyright (C) 2012 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "config.h"
26 #include <string.h>
27 #include <assert.h>
28 #include <va/va_dricommon.h>
29 #include "i965_drv_video.h"
30 #include "i965_output_dri.h"
31
32 bool
33 i965_output_dri_init(VADriverContextP ctx)
34 {
35     return true;
36 }
37
38 void
39 i965_output_dri_terminate(VADriverContextP ctx)
40 {
41 }
42
43 VAStatus
44 i965_put_surface_dri(
45     VADriverContextP    ctx,
46     VASurfaceID         surface,
47     void               *draw,
48     const VARectangle  *src_rect,
49     const VARectangle  *dst_rect,
50     const VARectangle  *cliprects,
51     unsigned int        num_cliprects,
52     unsigned int        flags
53 )
54 {
55     struct i965_driver_data * const i965 = i965_driver_data(ctx); 
56     struct dri_state * const dri_state = (struct dri_state *)ctx->drm_state;
57     struct i965_render_state * const render_state = &i965->render_state;
58     struct dri_drawable *dri_drawable;
59     union dri_buffer *buffer;
60     struct intel_region *dest_region;
61     struct object_surface *obj_surface; 
62     unsigned int pp_flag = 0;
63     bool new_region = false;
64     uint32_t name;
65     int ret;
66
67     /* Currently don't support DRI1 */
68     if (dri_state->base.auth_type != VA_DRM_AUTH_DRI2)
69         return VA_STATUS_ERROR_UNKNOWN;
70
71     /* Some broken sources such as H.264 conformance case FM2_SVA_C
72      * will get here
73      */
74     obj_surface = SURFACE(surface);
75     if (!obj_surface || !obj_surface->bo)
76         return VA_STATUS_SUCCESS;
77
78     _i965LockMutex(&i965->render_mutex);
79
80     dri_drawable = dri_get_drawable(ctx, (Drawable)draw);
81     assert(dri_drawable);
82
83     buffer = dri_get_rendering_buffer(ctx, dri_drawable);
84     assert(buffer);
85     
86     dest_region = render_state->draw_region;
87
88     if (dest_region) {
89         assert(dest_region->bo);
90         dri_bo_flink(dest_region->bo, &name);
91         
92         if (buffer->dri2.name != name) {
93             new_region = True;
94             dri_bo_unreference(dest_region->bo);
95         }
96     } else {
97         dest_region = (struct intel_region *)calloc(1, sizeof(*dest_region));
98         assert(dest_region);
99         render_state->draw_region = dest_region;
100         new_region = True;
101     }
102
103     if (new_region) {
104         dest_region->x = dri_drawable->x;
105         dest_region->y = dri_drawable->y;
106         dest_region->width = dri_drawable->width;
107         dest_region->height = dri_drawable->height;
108         dest_region->cpp = buffer->dri2.cpp;
109         dest_region->pitch = buffer->dri2.pitch;
110
111         dest_region->bo = intel_bo_gem_create_from_name(i965->intel.bufmgr, "rendering buffer", buffer->dri2.name);
112         assert(dest_region->bo);
113
114         ret = dri_bo_get_tiling(dest_region->bo, &(dest_region->tiling), &(dest_region->swizzle));
115         assert(ret == 0);
116     }
117
118     if ((flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC)
119         pp_flag |= I965_PP_FLAG_AVS;
120
121     if (flags & VA_TOP_FIELD)
122         pp_flag |= I965_PP_FLAG_TOP_FIELD;
123     else if (flags & VA_BOTTOM_FIELD)
124         pp_flag |= I965_PP_FLAG_BOTTOM_FIELD;
125
126     intel_render_put_surface(ctx, surface, src_rect, dst_rect, pp_flag);
127
128     if(obj_surface->subpic != VA_INVALID_ID) {
129         intel_render_put_subpicture(ctx, surface, src_rect, dst_rect);
130     }
131
132     dri_swap_buffer(ctx, dri_drawable);
133     obj_surface->flags |= SURFACE_DISPLAYED;
134
135     if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
136         dri_bo_unreference(obj_surface->bo);
137         obj_surface->bo = NULL;
138         obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
139
140         if (obj_surface->free_private_data)
141             obj_surface->free_private_data(&obj_surface->private_data);
142     }
143
144     _i965UnlockMutex(&i965->render_mutex);
145
146     return VA_STATUS_SUCCESS;
147 }