1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
4 * Copyright 2011 Christian König.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include <vdpau/vdpau.h>
31 #include "util/u_debug.h"
32 #include "util/u_memory.h"
33 #include "util/u_sampler.h"
34 #include "util/u_format.h"
35 #include "util/u_surface.h"
37 #include "vl/vl_csc.h"
39 #include "state_tracker/drm_driver.h"
41 #include "vdpau_private.h"
44 * Create a VdpOutputSurface.
47 vlVdpOutputSurfaceCreate(VdpDevice device
,
48 VdpRGBAFormat rgba_format
,
49 uint32_t width
, uint32_t height
,
50 VdpOutputSurface
*surface
)
52 struct pipe_context
*pipe
;
53 struct pipe_resource res_tmpl
, *res
;
54 struct pipe_sampler_view sv_templ
;
55 struct pipe_surface surf_templ
;
57 vlVdpOutputSurface
*vlsurface
= NULL
;
59 if (!(width
&& height
))
60 return VDP_STATUS_INVALID_SIZE
;
62 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
64 return VDP_STATUS_INVALID_HANDLE
;
68 return VDP_STATUS_INVALID_HANDLE
;
70 vlsurface
= CALLOC(1, sizeof(vlVdpOutputSurface
));
72 return VDP_STATUS_RESOURCES
;
74 DeviceReference(&vlsurface
->device
, dev
);
76 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
78 res_tmpl
.target
= PIPE_TEXTURE_2D
;
79 res_tmpl
.format
= VdpFormatRGBAToPipe(rgba_format
);
80 res_tmpl
.width0
= width
;
81 res_tmpl
.height0
= height
;
83 res_tmpl
.array_size
= 1;
84 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
|
85 PIPE_BIND_LINEAR
| PIPE_BIND_SHARED
;
86 res_tmpl
.usage
= PIPE_USAGE_DEFAULT
;
88 pipe_mutex_lock(dev
->mutex
);
90 if (!CheckSurfaceParams(pipe
->screen
, &res_tmpl
))
93 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
97 vlVdpDefaultSamplerViewTemplate(&sv_templ
, res
);
98 vlsurface
->sampler_view
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
99 if (!vlsurface
->sampler_view
)
102 memset(&surf_templ
, 0, sizeof(surf_templ
));
103 surf_templ
.format
= res
->format
;
104 vlsurface
->surface
= pipe
->create_surface(pipe
, res
, &surf_templ
);
105 if (!vlsurface
->surface
)
108 *surface
= vlAddDataHTAB(vlsurface
);
112 pipe_resource_reference(&res
, NULL
);
114 vl_compositor_init_state(&vlsurface
->cstate
, pipe
);
115 vl_compositor_reset_dirty_area(&vlsurface
->dirty_area
);
116 pipe_mutex_unlock(dev
->mutex
);
118 return VDP_STATUS_OK
;
121 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
122 pipe_surface_reference(&vlsurface
->surface
, NULL
);
123 pipe_resource_reference(&res
, NULL
);
125 pipe_mutex_unlock(dev
->mutex
);
126 DeviceReference(&vlsurface
->device
, NULL
);
128 return VDP_STATUS_ERROR
;
132 * Destroy a VdpOutputSurface.
135 vlVdpOutputSurfaceDestroy(VdpOutputSurface surface
)
137 vlVdpOutputSurface
*vlsurface
;
138 struct pipe_context
*pipe
;
140 vlsurface
= vlGetDataHTAB(surface
);
142 return VDP_STATUS_INVALID_HANDLE
;
144 pipe
= vlsurface
->device
->context
;
146 pipe_mutex_lock(vlsurface
->device
->mutex
);
147 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
149 pipe_surface_reference(&vlsurface
->surface
, NULL
);
150 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
151 pipe
->screen
->fence_reference(pipe
->screen
, &vlsurface
->fence
, NULL
);
152 vl_compositor_cleanup_state(&vlsurface
->cstate
);
153 pipe_mutex_unlock(vlsurface
->device
->mutex
);
155 vlRemoveDataHTAB(surface
);
156 DeviceReference(&vlsurface
->device
, NULL
);
159 return VDP_STATUS_OK
;
163 * Retrieve the parameters used to create a VdpOutputSurface.
166 vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface
,
167 VdpRGBAFormat
*rgba_format
,
168 uint32_t *width
, uint32_t *height
)
170 vlVdpOutputSurface
*vlsurface
;
172 vlsurface
= vlGetDataHTAB(surface
);
174 return VDP_STATUS_INVALID_HANDLE
;
176 *rgba_format
= PipeToFormatRGBA(vlsurface
->sampler_view
->texture
->format
);
177 *width
= vlsurface
->sampler_view
->texture
->width0
;
178 *height
= vlsurface
->sampler_view
->texture
->height0
;
180 return VDP_STATUS_OK
;
184 * Copy image data from a VdpOutputSurface to application memory in the
185 * surface's native format.
188 vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface
,
189 VdpRect
const *source_rect
,
190 void *const *destination_data
,
191 uint32_t const *destination_pitches
)
193 vlVdpOutputSurface
*vlsurface
;
194 struct pipe_context
*pipe
;
195 struct pipe_resource
*res
;
197 struct pipe_transfer
*transfer
;
200 vlsurface
= vlGetDataHTAB(surface
);
202 return VDP_STATUS_INVALID_HANDLE
;
204 pipe
= vlsurface
->device
->context
;
206 return VDP_STATUS_INVALID_HANDLE
;
208 if (!destination_data
|| !destination_pitches
)
209 return VDP_STATUS_INVALID_POINTER
;
211 pipe_mutex_lock(vlsurface
->device
->mutex
);
212 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
214 res
= vlsurface
->sampler_view
->texture
;
215 box
= RectToPipeBox(source_rect
, res
);
216 map
= pipe
->transfer_map(pipe
, res
, 0, PIPE_TRANSFER_READ
, &box
, &transfer
);
218 pipe_mutex_unlock(vlsurface
->device
->mutex
);
219 return VDP_STATUS_RESOURCES
;
222 util_copy_rect(*destination_data
, res
->format
, *destination_pitches
, 0, 0,
223 box
.width
, box
.height
, map
, transfer
->stride
, 0, 0);
225 pipe_transfer_unmap(pipe
, transfer
);
226 pipe_mutex_unlock(vlsurface
->device
->mutex
);
228 return VDP_STATUS_OK
;
232 * Copy image data from application memory in the surface's native format to
233 * a VdpOutputSurface.
236 vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface
,
237 void const *const *source_data
,
238 uint32_t const *source_pitches
,
239 VdpRect
const *destination_rect
)
241 vlVdpOutputSurface
*vlsurface
;
242 struct pipe_box dst_box
;
243 struct pipe_context
*pipe
;
245 vlsurface
= vlGetDataHTAB(surface
);
247 return VDP_STATUS_INVALID_HANDLE
;
249 pipe
= vlsurface
->device
->context
;
251 return VDP_STATUS_INVALID_HANDLE
;
253 if (!source_data
|| !source_pitches
)
254 return VDP_STATUS_INVALID_POINTER
;
256 pipe_mutex_lock(vlsurface
->device
->mutex
);
257 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
259 dst_box
= RectToPipeBox(destination_rect
, vlsurface
->sampler_view
->texture
);
260 pipe
->transfer_inline_write(pipe
, vlsurface
->sampler_view
->texture
, 0,
261 PIPE_TRANSFER_WRITE
, &dst_box
, *source_data
,
263 pipe_mutex_unlock(vlsurface
->device
->mutex
);
265 return VDP_STATUS_OK
;
269 * Copy image data from application memory in a specific indexed format to
270 * a VdpOutputSurface.
273 vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface
,
274 VdpIndexedFormat source_indexed_format
,
275 void const *const *source_data
,
276 uint32_t const *source_pitch
,
277 VdpRect
const *destination_rect
,
278 VdpColorTableFormat color_table_format
,
279 void const *color_table
)
281 vlVdpOutputSurface
*vlsurface
;
282 struct pipe_context
*context
;
283 struct vl_compositor
*compositor
;
284 struct vl_compositor_state
*cstate
;
286 enum pipe_format index_format
;
287 enum pipe_format colortbl_format
;
289 struct pipe_resource
*res
, res_tmpl
;
290 struct pipe_sampler_view sv_tmpl
;
291 struct pipe_sampler_view
*sv_idx
= NULL
, *sv_tbl
= NULL
;
294 struct u_rect dst_rect
;
296 vlsurface
= vlGetDataHTAB(surface
);
298 return VDP_STATUS_INVALID_HANDLE
;
300 context
= vlsurface
->device
->context
;
301 compositor
= &vlsurface
->device
->compositor
;
302 cstate
= &vlsurface
->cstate
;
304 index_format
= FormatIndexedToPipe(source_indexed_format
);
305 if (index_format
== PIPE_FORMAT_NONE
)
306 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
308 if (!source_data
|| !source_pitch
)
309 return VDP_STATUS_INVALID_POINTER
;
311 colortbl_format
= FormatColorTableToPipe(color_table_format
);
312 if (colortbl_format
== PIPE_FORMAT_NONE
)
313 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
316 return VDP_STATUS_INVALID_POINTER
;
318 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
319 res_tmpl
.target
= PIPE_TEXTURE_2D
;
320 res_tmpl
.format
= index_format
;
322 if (destination_rect
) {
323 res_tmpl
.width0
= abs(destination_rect
->x0
-destination_rect
->x1
);
324 res_tmpl
.height0
= abs(destination_rect
->y0
-destination_rect
->y1
);
326 res_tmpl
.width0
= vlsurface
->surface
->texture
->width0
;
327 res_tmpl
.height0
= vlsurface
->surface
->texture
->height0
;
330 res_tmpl
.array_size
= 1;
331 res_tmpl
.usage
= PIPE_USAGE_STAGING
;
332 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
;
334 pipe_mutex_lock(vlsurface
->device
->mutex
);
335 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
337 if (!CheckSurfaceParams(context
->screen
, &res_tmpl
))
340 res
= context
->screen
->resource_create(context
->screen
, &res_tmpl
);
344 box
.x
= box
.y
= box
.z
= 0;
345 box
.width
= res
->width0
;
346 box
.height
= res
->height0
;
347 box
.depth
= res
->depth0
;
349 context
->transfer_inline_write(context
, res
, 0, PIPE_TRANSFER_WRITE
, &box
,
350 source_data
[0], source_pitch
[0],
351 source_pitch
[0] * res
->height0
);
353 memset(&sv_tmpl
, 0, sizeof(sv_tmpl
));
354 u_sampler_view_default_template(&sv_tmpl
, res
, res
->format
);
356 sv_idx
= context
->create_sampler_view(context
, res
, &sv_tmpl
);
357 pipe_resource_reference(&res
, NULL
);
362 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
363 res_tmpl
.target
= PIPE_TEXTURE_1D
;
364 res_tmpl
.format
= colortbl_format
;
365 res_tmpl
.width0
= 1 << util_format_get_component_bits(
366 index_format
, UTIL_FORMAT_COLORSPACE_RGB
, 0);
367 res_tmpl
.height0
= 1;
369 res_tmpl
.array_size
= 1;
370 res_tmpl
.usage
= PIPE_USAGE_STAGING
;
371 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
;
373 res
= context
->screen
->resource_create(context
->screen
, &res_tmpl
);
377 box
.x
= box
.y
= box
.z
= 0;
378 box
.width
= res
->width0
;
379 box
.height
= res
->height0
;
380 box
.depth
= res
->depth0
;
382 context
->transfer_inline_write(context
, res
, 0, PIPE_TRANSFER_WRITE
, &box
, color_table
,
383 util_format_get_stride(colortbl_format
, res
->width0
), 0);
385 memset(&sv_tmpl
, 0, sizeof(sv_tmpl
));
386 u_sampler_view_default_template(&sv_tmpl
, res
, res
->format
);
388 sv_tbl
= context
->create_sampler_view(context
, res
, &sv_tmpl
);
389 pipe_resource_reference(&res
, NULL
);
394 vl_compositor_clear_layers(cstate
);
395 vl_compositor_set_palette_layer(cstate
, compositor
, 0, sv_idx
, sv_tbl
, NULL
, NULL
, false);
396 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
397 vl_compositor_render(cstate
, compositor
, vlsurface
->surface
, &vlsurface
->dirty_area
, false);
399 pipe_sampler_view_reference(&sv_idx
, NULL
);
400 pipe_sampler_view_reference(&sv_tbl
, NULL
);
401 pipe_mutex_unlock(vlsurface
->device
->mutex
);
403 return VDP_STATUS_OK
;
406 pipe_sampler_view_reference(&sv_idx
, NULL
);
407 pipe_sampler_view_reference(&sv_tbl
, NULL
);
408 pipe_mutex_unlock(vlsurface
->device
->mutex
);
409 return VDP_STATUS_RESOURCES
;
413 * Copy image data from application memory in a specific YCbCr format to
414 * a VdpOutputSurface.
417 vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface
,
418 VdpYCbCrFormat source_ycbcr_format
,
419 void const *const *source_data
,
420 uint32_t const *source_pitches
,
421 VdpRect
const *destination_rect
,
422 VdpCSCMatrix
const *csc_matrix
)
424 vlVdpOutputSurface
*vlsurface
;
425 struct vl_compositor
*compositor
;
426 struct vl_compositor_state
*cstate
;
428 struct pipe_context
*pipe
;
429 enum pipe_format format
;
430 struct pipe_video_buffer vtmpl
, *vbuffer
;
431 struct u_rect dst_rect
;
432 struct pipe_sampler_view
**sampler_views
;
436 vlsurface
= vlGetDataHTAB(surface
);
438 return VDP_STATUS_INVALID_HANDLE
;
441 pipe
= vlsurface
->device
->context
;
442 compositor
= &vlsurface
->device
->compositor
;
443 cstate
= &vlsurface
->cstate
;
445 format
= FormatYCBCRToPipe(source_ycbcr_format
);
446 if (format
== PIPE_FORMAT_NONE
)
447 return VDP_STATUS_INVALID_Y_CB_CR_FORMAT
;
449 if (!source_data
|| !source_pitches
)
450 return VDP_STATUS_INVALID_POINTER
;
452 pipe_mutex_lock(vlsurface
->device
->mutex
);
453 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
454 memset(&vtmpl
, 0, sizeof(vtmpl
));
455 vtmpl
.buffer_format
= format
;
456 vtmpl
.chroma_format
= FormatYCBCRToPipeChroma(source_ycbcr_format
);
458 if (destination_rect
) {
459 vtmpl
.width
= abs(destination_rect
->x0
-destination_rect
->x1
);
460 vtmpl
.height
= abs(destination_rect
->y0
-destination_rect
->y1
);
462 vtmpl
.width
= vlsurface
->surface
->texture
->width0
;
463 vtmpl
.height
= vlsurface
->surface
->texture
->height0
;
466 vbuffer
= pipe
->create_video_buffer(pipe
, &vtmpl
);
468 pipe_mutex_unlock(vlsurface
->device
->mutex
);
469 return VDP_STATUS_RESOURCES
;
472 sampler_views
= vbuffer
->get_sampler_view_planes(vbuffer
);
473 if (!sampler_views
) {
474 vbuffer
->destroy(vbuffer
);
475 pipe_mutex_unlock(vlsurface
->device
->mutex
);
476 return VDP_STATUS_RESOURCES
;
479 for (i
= 0; i
< 3; ++i
) {
480 struct pipe_sampler_view
*sv
= sampler_views
[i
];
483 struct pipe_box dst_box
= {
485 sv
->texture
->width0
, sv
->texture
->height0
, 1
488 pipe
->transfer_inline_write(pipe
, sv
->texture
, 0, PIPE_TRANSFER_WRITE
, &dst_box
,
489 source_data
[i
], source_pitches
[i
], 0);
494 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, 1, &csc
);
495 vl_compositor_set_csc_matrix(cstate
, (const vl_csc_matrix
*)&csc
);
497 vl_compositor_set_csc_matrix(cstate
, csc_matrix
);
500 vl_compositor_clear_layers(cstate
);
501 vl_compositor_set_buffer_layer(cstate
, compositor
, 0, vbuffer
, NULL
, NULL
, VL_COMPOSITOR_WEAVE
);
502 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
503 vl_compositor_render(cstate
, compositor
, vlsurface
->surface
, &vlsurface
->dirty_area
, false);
505 vbuffer
->destroy(vbuffer
);
506 pipe_mutex_unlock(vlsurface
->device
->mutex
);
508 return VDP_STATUS_OK
;
512 BlendFactorToPipe(VdpOutputSurfaceRenderBlendFactor factor
)
515 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO
:
516 return PIPE_BLENDFACTOR_ZERO
;
517 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
:
518 return PIPE_BLENDFACTOR_ONE
;
519 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_COLOR
:
520 return PIPE_BLENDFACTOR_SRC_COLOR
;
521 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_COLOR
:
522 return PIPE_BLENDFACTOR_INV_SRC_COLOR
;
523 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA
:
524 return PIPE_BLENDFACTOR_SRC_ALPHA
;
525 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
:
526 return PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
527 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_DST_ALPHA
:
528 return PIPE_BLENDFACTOR_DST_ALPHA
;
529 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
:
530 return PIPE_BLENDFACTOR_INV_DST_ALPHA
;
531 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_DST_COLOR
:
532 return PIPE_BLENDFACTOR_DST_COLOR
;
533 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_DST_COLOR
:
534 return PIPE_BLENDFACTOR_INV_DST_COLOR
;
535 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA_SATURATE
:
536 return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
;
537 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_CONSTANT_COLOR
:
538 return PIPE_BLENDFACTOR_CONST_COLOR
;
539 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
:
540 return PIPE_BLENDFACTOR_INV_CONST_COLOR
;
541 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_CONSTANT_ALPHA
:
542 return PIPE_BLENDFACTOR_CONST_ALPHA
;
543 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
:
544 return PIPE_BLENDFACTOR_INV_CONST_ALPHA
;
547 return PIPE_BLENDFACTOR_ONE
;
552 BlendEquationToPipe(VdpOutputSurfaceRenderBlendEquation equation
)
555 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_SUBTRACT
:
556 return PIPE_BLEND_SUBTRACT
;
557 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_REVERSE_SUBTRACT
:
558 return PIPE_BLEND_REVERSE_SUBTRACT
;
559 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
:
560 return PIPE_BLEND_ADD
;
561 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_MIN
:
562 return PIPE_BLEND_MIN
;
563 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_MAX
:
564 return PIPE_BLEND_MAX
;
567 return PIPE_BLEND_ADD
;
572 BlenderToPipe(struct pipe_context
*context
,
573 VdpOutputSurfaceRenderBlendState
const *blend_state
)
575 struct pipe_blend_state blend
;
577 memset(&blend
, 0, sizeof blend
);
578 blend
.independent_blend_enable
= 0;
581 blend
.rt
[0].blend_enable
= 1;
582 blend
.rt
[0].rgb_src_factor
= BlendFactorToPipe(blend_state
->blend_factor_source_color
);
583 blend
.rt
[0].rgb_dst_factor
= BlendFactorToPipe(blend_state
->blend_factor_destination_color
);
584 blend
.rt
[0].alpha_src_factor
= BlendFactorToPipe(blend_state
->blend_factor_source_alpha
);
585 blend
.rt
[0].alpha_dst_factor
= BlendFactorToPipe(blend_state
->blend_factor_destination_alpha
);
586 blend
.rt
[0].rgb_func
= BlendEquationToPipe(blend_state
->blend_equation_color
);
587 blend
.rt
[0].alpha_func
= BlendEquationToPipe(blend_state
->blend_equation_alpha
);
589 blend
.rt
[0].blend_enable
= 0;
592 blend
.logicop_enable
= 0;
593 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
594 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
597 return context
->create_blend_state(context
, &blend
);
600 static struct vertex4f
*
601 ColorsToPipe(VdpColor
const *colors
, uint32_t flags
, struct vertex4f result
[4])
604 struct vertex4f
*dst
= result
;
609 for (i
= 0; i
< 4; ++i
) {
610 dst
->x
= colors
->red
;
611 dst
->y
= colors
->green
;
612 dst
->z
= colors
->blue
;
613 dst
->w
= colors
->alpha
;
616 if (flags
& VDP_OUTPUT_SURFACE_RENDER_COLOR_PER_VERTEX
)
623 * Composite a sub-rectangle of a VdpOutputSurface into a sub-rectangle of
624 * another VdpOutputSurface; Output Surface object VdpOutputSurface.
627 vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface
,
628 VdpRect
const *destination_rect
,
629 VdpOutputSurface source_surface
,
630 VdpRect
const *source_rect
,
631 VdpColor
const *colors
,
632 VdpOutputSurfaceRenderBlendState
const *blend_state
,
635 vlVdpOutputSurface
*dst_vlsurface
;
637 struct pipe_context
*context
;
638 struct pipe_sampler_view
*src_sv
;
639 struct vl_compositor
*compositor
;
640 struct vl_compositor_state
*cstate
;
642 struct u_rect src_rect
, dst_rect
;
644 struct vertex4f vlcolors
[4];
647 dst_vlsurface
= vlGetDataHTAB(destination_surface
);
649 return VDP_STATUS_INVALID_HANDLE
;
651 if (source_surface
== VDP_INVALID_HANDLE
) {
652 src_sv
= dst_vlsurface
->device
->dummy_sv
;
655 vlVdpOutputSurface
*src_vlsurface
= vlGetDataHTAB(source_surface
);
657 return VDP_STATUS_INVALID_HANDLE
;
659 if (dst_vlsurface
->device
!= src_vlsurface
->device
)
660 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
662 src_sv
= src_vlsurface
->sampler_view
;
665 pipe_mutex_lock(dst_vlsurface
->device
->mutex
);
666 vlVdpResolveDelayedRendering(dst_vlsurface
->device
, NULL
, NULL
);
668 context
= dst_vlsurface
->device
->context
;
669 compositor
= &dst_vlsurface
->device
->compositor
;
670 cstate
= &dst_vlsurface
->cstate
;
672 blend
= BlenderToPipe(context
, blend_state
);
674 vl_compositor_clear_layers(cstate
);
675 vl_compositor_set_layer_blend(cstate
, 0, blend
, false);
676 vl_compositor_set_rgba_layer(cstate
, compositor
, 0, src_sv
,
677 RectToPipe(source_rect
, &src_rect
), NULL
,
678 ColorsToPipe(colors
, flags
, vlcolors
));
679 STATIC_ASSERT(VL_COMPOSITOR_ROTATE_0
== VDP_OUTPUT_SURFACE_RENDER_ROTATE_0
);
680 STATIC_ASSERT(VL_COMPOSITOR_ROTATE_90
== VDP_OUTPUT_SURFACE_RENDER_ROTATE_90
);
681 STATIC_ASSERT(VL_COMPOSITOR_ROTATE_180
== VDP_OUTPUT_SURFACE_RENDER_ROTATE_180
);
682 STATIC_ASSERT(VL_COMPOSITOR_ROTATE_270
== VDP_OUTPUT_SURFACE_RENDER_ROTATE_270
);
683 vl_compositor_set_layer_rotation(cstate
, 0, flags
& 3);
684 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
685 vl_compositor_render(cstate
, compositor
, dst_vlsurface
->surface
, &dst_vlsurface
->dirty_area
, false);
687 context
->delete_blend_state(context
, blend
);
688 pipe_mutex_unlock(dst_vlsurface
->device
->mutex
);
690 return VDP_STATUS_OK
;
694 * Composite a sub-rectangle of a VdpBitmapSurface into a sub-rectangle of
695 * a VdpOutputSurface; Output Surface object VdpOutputSurface.
698 vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface
,
699 VdpRect
const *destination_rect
,
700 VdpBitmapSurface source_surface
,
701 VdpRect
const *source_rect
,
702 VdpColor
const *colors
,
703 VdpOutputSurfaceRenderBlendState
const *blend_state
,
706 vlVdpOutputSurface
*dst_vlsurface
;
708 struct pipe_context
*context
;
709 struct pipe_sampler_view
*src_sv
;
710 struct vl_compositor
*compositor
;
711 struct vl_compositor_state
*cstate
;
713 struct u_rect src_rect
, dst_rect
;
715 struct vertex4f vlcolors
[4];
718 dst_vlsurface
= vlGetDataHTAB(destination_surface
);
720 return VDP_STATUS_INVALID_HANDLE
;
722 if (source_surface
== VDP_INVALID_HANDLE
) {
723 src_sv
= dst_vlsurface
->device
->dummy_sv
;
726 vlVdpBitmapSurface
*src_vlsurface
= vlGetDataHTAB(source_surface
);
728 return VDP_STATUS_INVALID_HANDLE
;
730 if (dst_vlsurface
->device
!= src_vlsurface
->device
)
731 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
733 src_sv
= src_vlsurface
->sampler_view
;
736 context
= dst_vlsurface
->device
->context
;
737 compositor
= &dst_vlsurface
->device
->compositor
;
738 cstate
= &dst_vlsurface
->cstate
;
740 pipe_mutex_lock(dst_vlsurface
->device
->mutex
);
741 vlVdpResolveDelayedRendering(dst_vlsurface
->device
, NULL
, NULL
);
743 blend
= BlenderToPipe(context
, blend_state
);
745 vl_compositor_clear_layers(cstate
);
746 vl_compositor_set_layer_blend(cstate
, 0, blend
, false);
747 vl_compositor_set_rgba_layer(cstate
, compositor
, 0, src_sv
,
748 RectToPipe(source_rect
, &src_rect
), NULL
,
749 ColorsToPipe(colors
, flags
, vlcolors
));
750 vl_compositor_set_layer_rotation(cstate
, 0, flags
& 3);
751 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
752 vl_compositor_render(cstate
, compositor
, dst_vlsurface
->surface
, &dst_vlsurface
->dirty_area
, false);
754 context
->delete_blend_state(context
, blend
);
755 pipe_mutex_unlock(dst_vlsurface
->device
->mutex
);
757 return VDP_STATUS_OK
;
760 struct pipe_resource
*vlVdpOutputSurfaceGallium(VdpOutputSurface surface
)
762 vlVdpOutputSurface
*vlsurface
;
764 vlsurface
= vlGetDataHTAB(surface
);
765 if (!vlsurface
|| !vlsurface
->surface
)
768 pipe_mutex_lock(vlsurface
->device
->mutex
);
769 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
770 vlsurface
->device
->context
->flush(vlsurface
->device
->context
, NULL
, 0);
771 pipe_mutex_unlock(vlsurface
->device
->mutex
);
773 return vlsurface
->surface
->texture
;
776 VdpStatus
vlVdpOutputSurfaceDMABuf(VdpVideoSurface surface
,
777 struct VdpSurfaceDMABufDesc
*result
)
779 vlVdpOutputSurface
*vlsurface
;
780 struct pipe_screen
*pscreen
;
781 struct winsys_handle whandle
;
783 memset(result
, 0, sizeof(*result
));
786 vlsurface
= vlGetDataHTAB(surface
);
787 if (!vlsurface
|| !vlsurface
->surface
)
788 return VDP_STATUS_INVALID_HANDLE
;
790 pipe_mutex_lock(vlsurface
->device
->mutex
);
791 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
792 vlsurface
->device
->context
->flush(vlsurface
->device
->context
, NULL
, 0);
793 pipe_mutex_unlock(vlsurface
->device
->mutex
);
795 memset(&whandle
, 0, sizeof(struct winsys_handle
));
796 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
798 pscreen
= vlsurface
->surface
->texture
->screen
;
799 if (!pscreen
->resource_get_handle(pscreen
, vlsurface
->surface
->texture
, &whandle
,
800 PIPE_HANDLE_USAGE_READ_WRITE
))
801 return VDP_STATUS_NO_IMPLEMENTATION
;
803 result
->handle
= whandle
.handle
;
804 result
->width
= vlsurface
->surface
->width
;
805 result
->height
= vlsurface
->surface
->height
;
806 result
->offset
= whandle
.offset
;
807 result
->stride
= whandle
.stride
;
808 result
->format
= PipeToFormatRGBA(vlsurface
->surface
->format
);
810 return VDP_STATUS_OK
;