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 "vdpau_private.h"
42 * Create a VdpOutputSurface.
45 vlVdpOutputSurfaceCreate(VdpDevice device
,
46 VdpRGBAFormat rgba_format
,
47 uint32_t width
, uint32_t height
,
48 VdpOutputSurface
*surface
)
50 struct pipe_context
*pipe
;
51 struct pipe_resource res_tmpl
, *res
;
52 struct pipe_sampler_view sv_templ
;
53 struct pipe_surface surf_templ
;
55 vlVdpOutputSurface
*vlsurface
= NULL
;
57 if (!(width
&& height
))
58 return VDP_STATUS_INVALID_SIZE
;
60 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
62 return VDP_STATUS_INVALID_HANDLE
;
66 return VDP_STATUS_INVALID_HANDLE
;
68 vlsurface
= CALLOC(1, sizeof(vlVdpOutputSurface
));
70 return VDP_STATUS_RESOURCES
;
72 vlsurface
->device
= dev
;
74 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
76 res_tmpl
.target
= PIPE_TEXTURE_2D
;
77 res_tmpl
.format
= FormatRGBAToPipe(rgba_format
);
78 res_tmpl
.width0
= width
;
79 res_tmpl
.height0
= height
;
81 res_tmpl
.array_size
= 1;
82 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
83 res_tmpl
.usage
= PIPE_USAGE_DEFAULT
;
85 pipe_mutex_lock(dev
->mutex
);
87 if (!CheckSurfaceParams(pipe
->screen
, &res_tmpl
))
90 res
= pipe
->screen
->resource_create(pipe
->screen
, &res_tmpl
);
94 vlVdpDefaultSamplerViewTemplate(&sv_templ
, res
);
95 vlsurface
->sampler_view
= pipe
->create_sampler_view(pipe
, res
, &sv_templ
);
96 if (!vlsurface
->sampler_view
)
99 memset(&surf_templ
, 0, sizeof(surf_templ
));
100 surf_templ
.format
= res
->format
;
101 vlsurface
->surface
= pipe
->create_surface(pipe
, res
, &surf_templ
);
102 if (!vlsurface
->surface
)
105 *surface
= vlAddDataHTAB(vlsurface
);
109 pipe_resource_reference(&res
, NULL
);
111 vl_compositor_init_state(&vlsurface
->cstate
, pipe
);
112 vl_compositor_reset_dirty_area(&vlsurface
->dirty_area
);
113 pipe_mutex_unlock(dev
->mutex
);
115 return VDP_STATUS_OK
;
118 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
119 pipe_surface_reference(&vlsurface
->surface
, NULL
);
120 pipe_resource_reference(&res
, NULL
);
122 pipe_mutex_unlock(dev
->mutex
);
124 return VDP_STATUS_ERROR
;
128 * Destroy a VdpOutputSurface.
131 vlVdpOutputSurfaceDestroy(VdpOutputSurface surface
)
133 vlVdpOutputSurface
*vlsurface
;
134 struct pipe_context
*pipe
;
136 vlsurface
= vlGetDataHTAB(surface
);
138 return VDP_STATUS_INVALID_HANDLE
;
140 pipe
= vlsurface
->device
->context
;
142 pipe_mutex_lock(vlsurface
->device
->mutex
);
143 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
145 pipe_surface_reference(&vlsurface
->surface
, NULL
);
146 pipe_sampler_view_reference(&vlsurface
->sampler_view
, NULL
);
147 pipe
->screen
->fence_reference(pipe
->screen
, &vlsurface
->fence
, NULL
);
148 vl_compositor_cleanup_state(&vlsurface
->cstate
);
149 pipe_mutex_unlock(vlsurface
->device
->mutex
);
151 vlRemoveDataHTAB(surface
);
154 return VDP_STATUS_OK
;
158 * Retrieve the parameters used to create a VdpOutputSurface.
161 vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface
,
162 VdpRGBAFormat
*rgba_format
,
163 uint32_t *width
, uint32_t *height
)
165 vlVdpOutputSurface
*vlsurface
;
167 vlsurface
= vlGetDataHTAB(surface
);
169 return VDP_STATUS_INVALID_HANDLE
;
171 *rgba_format
= PipeToFormatRGBA(vlsurface
->sampler_view
->texture
->format
);
172 *width
= vlsurface
->sampler_view
->texture
->width0
;
173 *height
= vlsurface
->sampler_view
->texture
->height0
;
175 return VDP_STATUS_OK
;
179 * Copy image data from a VdpOutputSurface to application memory in the
180 * surface's native format.
183 vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface
,
184 VdpRect
const *source_rect
,
185 void *const *destination_data
,
186 uint32_t const *destination_pitches
)
188 vlVdpOutputSurface
*vlsurface
;
189 struct pipe_context
*pipe
;
190 struct pipe_resource
*res
;
192 struct pipe_transfer
*transfer
;
195 vlsurface
= vlGetDataHTAB(surface
);
197 return VDP_STATUS_INVALID_HANDLE
;
199 pipe
= vlsurface
->device
->context
;
201 return VDP_STATUS_INVALID_HANDLE
;
203 pipe_mutex_lock(vlsurface
->device
->mutex
);
204 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
206 res
= vlsurface
->sampler_view
->texture
;
207 box
= RectToPipeBox(source_rect
, res
);
208 map
= pipe
->transfer_map(pipe
, res
, 0, PIPE_TRANSFER_READ
, &box
, &transfer
);
210 pipe_mutex_unlock(vlsurface
->device
->mutex
);
211 return VDP_STATUS_RESOURCES
;
214 util_copy_rect(*destination_data
, res
->format
, *destination_pitches
, 0, 0,
215 box
.width
, box
.height
, map
, transfer
->stride
, 0, 0);
217 pipe_transfer_unmap(pipe
, transfer
);
218 pipe_mutex_unlock(vlsurface
->device
->mutex
);
220 return VDP_STATUS_OK
;
224 * Copy image data from application memory in the surface's native format to
225 * a VdpOutputSurface.
228 vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface
,
229 void const *const *source_data
,
230 uint32_t const *source_pitches
,
231 VdpRect
const *destination_rect
)
233 vlVdpOutputSurface
*vlsurface
;
234 struct pipe_box dst_box
;
235 struct pipe_context
*pipe
;
237 vlsurface
= vlGetDataHTAB(surface
);
239 return VDP_STATUS_INVALID_HANDLE
;
241 pipe
= vlsurface
->device
->context
;
243 return VDP_STATUS_INVALID_HANDLE
;
245 pipe_mutex_lock(vlsurface
->device
->mutex
);
246 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
248 dst_box
= RectToPipeBox(destination_rect
, vlsurface
->sampler_view
->texture
);
249 pipe
->transfer_inline_write(pipe
, vlsurface
->sampler_view
->texture
, 0,
250 PIPE_TRANSFER_WRITE
, &dst_box
, *source_data
,
252 pipe_mutex_unlock(vlsurface
->device
->mutex
);
254 return VDP_STATUS_OK
;
258 * Copy image data from application memory in a specific indexed format to
259 * a VdpOutputSurface.
262 vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface
,
263 VdpIndexedFormat source_indexed_format
,
264 void const *const *source_data
,
265 uint32_t const *source_pitch
,
266 VdpRect
const *destination_rect
,
267 VdpColorTableFormat color_table_format
,
268 void const *color_table
)
270 vlVdpOutputSurface
*vlsurface
;
271 struct pipe_context
*context
;
272 struct vl_compositor
*compositor
;
273 struct vl_compositor_state
*cstate
;
275 enum pipe_format index_format
;
276 enum pipe_format colortbl_format
;
278 struct pipe_resource
*res
, res_tmpl
;
279 struct pipe_sampler_view sv_tmpl
;
280 struct pipe_sampler_view
*sv_idx
= NULL
, *sv_tbl
= NULL
;
283 struct u_rect dst_rect
;
285 vlsurface
= vlGetDataHTAB(surface
);
287 return VDP_STATUS_INVALID_HANDLE
;
289 context
= vlsurface
->device
->context
;
290 compositor
= &vlsurface
->device
->compositor
;
291 cstate
= &vlsurface
->cstate
;
293 index_format
= FormatIndexedToPipe(source_indexed_format
);
294 if (index_format
== PIPE_FORMAT_NONE
)
295 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
297 if (!source_data
|| !source_pitch
)
298 return VDP_STATUS_INVALID_POINTER
;
300 colortbl_format
= FormatColorTableToPipe(color_table_format
);
301 if (colortbl_format
== PIPE_FORMAT_NONE
)
302 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
305 return VDP_STATUS_INVALID_POINTER
;
307 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
308 res_tmpl
.target
= PIPE_TEXTURE_2D
;
309 res_tmpl
.format
= index_format
;
311 if (destination_rect
) {
312 res_tmpl
.width0
= abs(destination_rect
->x0
-destination_rect
->x1
);
313 res_tmpl
.height0
= abs(destination_rect
->y0
-destination_rect
->y1
);
315 res_tmpl
.width0
= vlsurface
->surface
->texture
->width0
;
316 res_tmpl
.height0
= vlsurface
->surface
->texture
->height0
;
319 res_tmpl
.array_size
= 1;
320 res_tmpl
.usage
= PIPE_USAGE_STAGING
;
321 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
;
323 pipe_mutex_lock(vlsurface
->device
->mutex
);
324 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
326 if (!CheckSurfaceParams(context
->screen
, &res_tmpl
))
329 res
= context
->screen
->resource_create(context
->screen
, &res_tmpl
);
333 box
.x
= box
.y
= box
.z
= 0;
334 box
.width
= res
->width0
;
335 box
.height
= res
->height0
;
336 box
.depth
= res
->depth0
;
338 context
->transfer_inline_write(context
, res
, 0, PIPE_TRANSFER_WRITE
, &box
,
339 source_data
[0], source_pitch
[0],
340 source_pitch
[0] * res
->height0
);
342 memset(&sv_tmpl
, 0, sizeof(sv_tmpl
));
343 u_sampler_view_default_template(&sv_tmpl
, res
, res
->format
);
345 sv_idx
= context
->create_sampler_view(context
, res
, &sv_tmpl
);
346 pipe_resource_reference(&res
, NULL
);
351 memset(&res_tmpl
, 0, sizeof(res_tmpl
));
352 res_tmpl
.target
= PIPE_TEXTURE_1D
;
353 res_tmpl
.format
= colortbl_format
;
354 res_tmpl
.width0
= 1 << util_format_get_component_bits(
355 index_format
, UTIL_FORMAT_COLORSPACE_RGB
, 0);
356 res_tmpl
.height0
= 1;
358 res_tmpl
.array_size
= 1;
359 res_tmpl
.usage
= PIPE_USAGE_STAGING
;
360 res_tmpl
.bind
= PIPE_BIND_SAMPLER_VIEW
;
362 res
= context
->screen
->resource_create(context
->screen
, &res_tmpl
);
366 box
.x
= box
.y
= box
.z
= 0;
367 box
.width
= res
->width0
;
368 box
.height
= res
->height0
;
369 box
.depth
= res
->depth0
;
371 context
->transfer_inline_write(context
, res
, 0, PIPE_TRANSFER_WRITE
, &box
, color_table
,
372 util_format_get_stride(colortbl_format
, res
->width0
), 0);
374 memset(&sv_tmpl
, 0, sizeof(sv_tmpl
));
375 u_sampler_view_default_template(&sv_tmpl
, res
, res
->format
);
377 sv_tbl
= context
->create_sampler_view(context
, res
, &sv_tmpl
);
378 pipe_resource_reference(&res
, NULL
);
383 vl_compositor_clear_layers(cstate
);
384 vl_compositor_set_palette_layer(cstate
, compositor
, 0, sv_idx
, sv_tbl
, NULL
, NULL
, false);
385 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
386 vl_compositor_render(cstate
, compositor
, vlsurface
->surface
, &vlsurface
->dirty_area
, false);
388 pipe_sampler_view_reference(&sv_idx
, NULL
);
389 pipe_sampler_view_reference(&sv_tbl
, NULL
);
390 pipe_mutex_unlock(vlsurface
->device
->mutex
);
392 return VDP_STATUS_OK
;
395 pipe_sampler_view_reference(&sv_idx
, NULL
);
396 pipe_sampler_view_reference(&sv_tbl
, NULL
);
397 pipe_mutex_unlock(vlsurface
->device
->mutex
);
398 return VDP_STATUS_RESOURCES
;
402 * Copy image data from application memory in a specific YCbCr format to
403 * a VdpOutputSurface.
406 vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface
,
407 VdpYCbCrFormat source_ycbcr_format
,
408 void const *const *source_data
,
409 uint32_t const *source_pitches
,
410 VdpRect
const *destination_rect
,
411 VdpCSCMatrix
const *csc_matrix
)
413 vlVdpOutputSurface
*vlsurface
;
414 struct vl_compositor
*compositor
;
415 struct vl_compositor_state
*cstate
;
417 struct pipe_context
*pipe
;
418 enum pipe_format format
;
419 struct pipe_video_buffer vtmpl
, *vbuffer
;
420 struct u_rect dst_rect
;
421 struct pipe_sampler_view
**sampler_views
;
425 vlsurface
= vlGetDataHTAB(surface
);
427 return VDP_STATUS_INVALID_HANDLE
;
430 pipe
= vlsurface
->device
->context
;
431 compositor
= &vlsurface
->device
->compositor
;
432 cstate
= &vlsurface
->cstate
;
434 format
= FormatYCBCRToPipe(source_ycbcr_format
);
435 if (format
== PIPE_FORMAT_NONE
)
436 return VDP_STATUS_INVALID_Y_CB_CR_FORMAT
;
438 if (!source_data
|| !source_pitches
)
439 return VDP_STATUS_INVALID_POINTER
;
441 pipe_mutex_lock(vlsurface
->device
->mutex
);
442 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
443 memset(&vtmpl
, 0, sizeof(vtmpl
));
444 vtmpl
.buffer_format
= format
;
445 vtmpl
.chroma_format
= FormatYCBCRToPipeChroma(source_ycbcr_format
);
447 if (destination_rect
) {
448 vtmpl
.width
= abs(destination_rect
->x0
-destination_rect
->x1
);
449 vtmpl
.height
= abs(destination_rect
->y0
-destination_rect
->y1
);
451 vtmpl
.width
= vlsurface
->surface
->texture
->width0
;
452 vtmpl
.height
= vlsurface
->surface
->texture
->height0
;
455 vbuffer
= pipe
->create_video_buffer(pipe
, &vtmpl
);
457 pipe_mutex_unlock(vlsurface
->device
->mutex
);
458 return VDP_STATUS_RESOURCES
;
461 sampler_views
= vbuffer
->get_sampler_view_planes(vbuffer
);
462 if (!sampler_views
) {
463 vbuffer
->destroy(vbuffer
);
464 pipe_mutex_unlock(vlsurface
->device
->mutex
);
465 return VDP_STATUS_RESOURCES
;
468 for (i
= 0; i
< 3; ++i
) {
469 struct pipe_sampler_view
*sv
= sampler_views
[i
];
472 struct pipe_box dst_box
= {
474 sv
->texture
->width0
, sv
->texture
->height0
, 1
477 pipe
->transfer_inline_write(pipe
, sv
->texture
, 0, PIPE_TRANSFER_WRITE
, &dst_box
,
478 source_data
[i
], source_pitches
[i
], 0);
483 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, 1, &csc
);
484 vl_compositor_set_csc_matrix(cstate
, (const vl_csc_matrix
*)&csc
);
486 vl_compositor_set_csc_matrix(cstate
, csc_matrix
);
489 vl_compositor_clear_layers(cstate
);
490 vl_compositor_set_buffer_layer(cstate
, compositor
, 0, vbuffer
, NULL
, NULL
, VL_COMPOSITOR_WEAVE
);
491 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
492 vl_compositor_render(cstate
, compositor
, vlsurface
->surface
, &vlsurface
->dirty_area
, false);
494 vbuffer
->destroy(vbuffer
);
495 pipe_mutex_unlock(vlsurface
->device
->mutex
);
497 return VDP_STATUS_OK
;
501 BlendFactorToPipe(VdpOutputSurfaceRenderBlendFactor factor
)
504 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO
:
505 return PIPE_BLENDFACTOR_ZERO
;
506 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE
:
507 return PIPE_BLENDFACTOR_ONE
;
508 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_COLOR
:
509 return PIPE_BLENDFACTOR_SRC_COLOR
;
510 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_COLOR
:
511 return PIPE_BLENDFACTOR_INV_SRC_COLOR
;
512 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA
:
513 return PIPE_BLENDFACTOR_SRC_ALPHA
;
514 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
:
515 return PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
516 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_DST_ALPHA
:
517 return PIPE_BLENDFACTOR_DST_ALPHA
;
518 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
:
519 return PIPE_BLENDFACTOR_INV_DST_ALPHA
;
520 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_DST_COLOR
:
521 return PIPE_BLENDFACTOR_DST_COLOR
;
522 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_DST_COLOR
:
523 return PIPE_BLENDFACTOR_INV_DST_COLOR
;
524 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA_SATURATE
:
525 return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
;
526 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_CONSTANT_COLOR
:
527 return PIPE_BLENDFACTOR_CONST_COLOR
;
528 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
:
529 return PIPE_BLENDFACTOR_INV_CONST_COLOR
;
530 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_CONSTANT_ALPHA
:
531 return PIPE_BLENDFACTOR_CONST_ALPHA
;
532 case VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
:
533 return PIPE_BLENDFACTOR_INV_CONST_ALPHA
;
536 return PIPE_BLENDFACTOR_ONE
;
541 BlendEquationToPipe(VdpOutputSurfaceRenderBlendEquation equation
)
544 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_SUBTRACT
:
545 return PIPE_BLEND_SUBTRACT
;
546 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_REVERSE_SUBTRACT
:
547 return PIPE_BLEND_REVERSE_SUBTRACT
;
548 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD
:
549 return PIPE_BLEND_ADD
;
550 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_MIN
:
551 return PIPE_BLEND_MIN
;
552 case VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_MAX
:
553 return PIPE_BLEND_MAX
;
556 return PIPE_BLEND_ADD
;
561 BlenderToPipe(struct pipe_context
*context
,
562 VdpOutputSurfaceRenderBlendState
const *blend_state
)
564 struct pipe_blend_state blend
;
566 memset(&blend
, 0, sizeof blend
);
567 blend
.independent_blend_enable
= 0;
570 blend
.rt
[0].blend_enable
= 1;
571 blend
.rt
[0].rgb_src_factor
= BlendFactorToPipe(blend_state
->blend_factor_source_color
);
572 blend
.rt
[0].rgb_dst_factor
= BlendFactorToPipe(blend_state
->blend_factor_destination_color
);
573 blend
.rt
[0].alpha_src_factor
= BlendFactorToPipe(blend_state
->blend_factor_source_alpha
);
574 blend
.rt
[0].alpha_dst_factor
= BlendFactorToPipe(blend_state
->blend_factor_destination_alpha
);
575 blend
.rt
[0].rgb_func
= BlendEquationToPipe(blend_state
->blend_equation_color
);
576 blend
.rt
[0].alpha_func
= BlendEquationToPipe(blend_state
->blend_equation_alpha
);
578 blend
.rt
[0].blend_enable
= 0;
581 blend
.logicop_enable
= 0;
582 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
583 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
586 return context
->create_blend_state(context
, &blend
);
589 static struct vertex4f
*
590 ColorsToPipe(VdpColor
const *colors
, uint32_t flags
, struct vertex4f result
[4])
593 struct vertex4f
*dst
= result
;
598 for (i
= 0; i
< 4; ++i
) {
599 dst
->x
= colors
->red
;
600 dst
->y
= colors
->green
;
601 dst
->z
= colors
->blue
;
602 dst
->w
= colors
->alpha
;
605 if (flags
& VDP_OUTPUT_SURFACE_RENDER_COLOR_PER_VERTEX
)
612 * Composite a sub-rectangle of a VdpOutputSurface into a sub-rectangle of
613 * another VdpOutputSurface; Output Surface object VdpOutputSurface.
616 vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface
,
617 VdpRect
const *destination_rect
,
618 VdpOutputSurface source_surface
,
619 VdpRect
const *source_rect
,
620 VdpColor
const *colors
,
621 VdpOutputSurfaceRenderBlendState
const *blend_state
,
624 vlVdpOutputSurface
*dst_vlsurface
;
625 vlVdpOutputSurface
*src_vlsurface
;
627 struct pipe_context
*context
;
628 struct vl_compositor
*compositor
;
629 struct vl_compositor_state
*cstate
;
631 struct u_rect src_rect
, dst_rect
;
633 struct vertex4f vlcolors
[4];
636 dst_vlsurface
= vlGetDataHTAB(destination_surface
);
638 return VDP_STATUS_INVALID_HANDLE
;
640 src_vlsurface
= vlGetDataHTAB(source_surface
);
642 return VDP_STATUS_INVALID_HANDLE
;
644 if (dst_vlsurface
->device
!= src_vlsurface
->device
)
645 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
647 pipe_mutex_lock(dst_vlsurface
->device
->mutex
);
648 vlVdpResolveDelayedRendering(dst_vlsurface
->device
, NULL
, NULL
);
650 context
= dst_vlsurface
->device
->context
;
651 compositor
= &dst_vlsurface
->device
->compositor
;
652 cstate
= &dst_vlsurface
->cstate
;
654 blend
= BlenderToPipe(context
, blend_state
);
656 vl_compositor_clear_layers(cstate
);
657 vl_compositor_set_layer_blend(cstate
, 0, blend
, false);
658 vl_compositor_set_rgba_layer(cstate
, compositor
, 0, src_vlsurface
->sampler_view
,
659 RectToPipe(source_rect
, &src_rect
), NULL
,
660 ColorsToPipe(colors
, flags
, vlcolors
));
661 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
662 vl_compositor_render(cstate
, compositor
, dst_vlsurface
->surface
, &dst_vlsurface
->dirty_area
, false);
664 context
->delete_blend_state(context
, blend
);
665 pipe_mutex_unlock(dst_vlsurface
->device
->mutex
);
667 return VDP_STATUS_OK
;
671 * Composite a sub-rectangle of a VdpBitmapSurface into a sub-rectangle of
672 * a VdpOutputSurface; Output Surface object VdpOutputSurface.
675 vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface
,
676 VdpRect
const *destination_rect
,
677 VdpBitmapSurface source_surface
,
678 VdpRect
const *source_rect
,
679 VdpColor
const *colors
,
680 VdpOutputSurfaceRenderBlendState
const *blend_state
,
683 vlVdpOutputSurface
*dst_vlsurface
;
684 vlVdpBitmapSurface
*src_vlsurface
;
686 struct pipe_context
*context
;
687 struct vl_compositor
*compositor
;
688 struct vl_compositor_state
*cstate
;
690 struct u_rect src_rect
, dst_rect
;
692 struct vertex4f vlcolors
[4];
695 dst_vlsurface
= vlGetDataHTAB(destination_surface
);
697 return VDP_STATUS_INVALID_HANDLE
;
699 src_vlsurface
= vlGetDataHTAB(source_surface
);
701 return VDP_STATUS_INVALID_HANDLE
;
703 if (dst_vlsurface
->device
!= src_vlsurface
->device
)
704 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
706 context
= dst_vlsurface
->device
->context
;
707 compositor
= &dst_vlsurface
->device
->compositor
;
708 cstate
= &dst_vlsurface
->cstate
;
710 pipe_mutex_lock(dst_vlsurface
->device
->mutex
);
711 vlVdpResolveDelayedRendering(dst_vlsurface
->device
, NULL
, NULL
);
713 blend
= BlenderToPipe(context
, blend_state
);
715 vl_compositor_clear_layers(cstate
);
716 vl_compositor_set_layer_blend(cstate
, 0, blend
, false);
717 vl_compositor_set_rgba_layer(cstate
, compositor
, 0, src_vlsurface
->sampler_view
,
718 RectToPipe(source_rect
, &src_rect
), NULL
,
719 ColorsToPipe(colors
, flags
, vlcolors
));
720 vl_compositor_set_layer_dst_area(cstate
, 0, RectToPipe(destination_rect
, &dst_rect
));
721 vl_compositor_render(cstate
, compositor
, dst_vlsurface
->surface
, &dst_vlsurface
->dirty_area
, false);
723 context
->delete_blend_state(context
, blend
);
724 pipe_mutex_unlock(dst_vlsurface
->device
->mutex
);
726 return VDP_STATUS_OK
;
729 struct pipe_resource
*vlVdpOutputSurfaceGallium(VdpOutputSurface surface
)
731 vlVdpOutputSurface
*vlsurface
;
733 vlsurface
= vlGetDataHTAB(surface
);
734 if (!vlsurface
|| !vlsurface
->surface
)
737 pipe_mutex_lock(vlsurface
->device
->mutex
);
738 vlVdpResolveDelayedRendering(vlsurface
->device
, NULL
, NULL
);
739 pipe_mutex_unlock(vlsurface
->device
->mutex
);
741 return vlsurface
->surface
->texture
;